MyCoordPropSheet.cpp
上传用户:cding2008
上传日期:2007-01-03
资源大小:1812k
文件大小:8k
- /////////////////////////////////////////////////////////////////////////////
- // MyCoordPropSheet.cpp : implementation file
- //
- // ModelMagic 3D and 'glOOP' (OpenGL Object Oriented Programming library)
- // Copyright (c) Craig Fahrnbach 1997, 1999
- //
- // OpenGL is a registered trademark of Silicon Graphics
- //
- //
- // This program is provided for educational and personal use only and
- // is provided without guarantee or warrantee expressed or implied.
- //
- // Commercial use is strickly prohibited without written permission
- // from ImageWare Development.
- //
- /////////////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "ModelMagic3D.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- ////////////////////////////////////////////////////////////////////
- // CMyCoordPropSheet globals
- // RECT {left, top, right, bottom };
- static RECT SheetRect = { 2, 6, 140, 175};
- static RECT TabOffsetRect = { 2, 4, 2, 41};
- static RECT PageOffsetRect = { 2, 4, 2, 4};
- static RECT ApplyButtonRect = { 40, 140, 95, 160};
- /////////////////////////////////////////////////////////////////////////////
- // CMyCoordPropSheet
- IMPLEMENT_DYNAMIC(CMyCoordPropSheet, CPropertySheet)
- /////////////////////////////////////////////////////////////////////////////
- // CMyCoordPropSheet dialog message map
- BEGIN_MESSAGE_MAP(CMyCoordPropSheet, CPropertySheet)
- //{{AFX_MSG_MAP(CMyCoordPropSheet)
- ON_WM_CREATE()
- ON_WM_DESTROY()
- ON_BN_CLICKED(IDC_APPLY, OnApply)
- //}}AFX_MSG_MAP
- // USER defined messages
- ON_MESSAGE( PSM_CHANGED, OnPageChanged)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyCoordPropSheet dialog construction
- CMyCoordPropSheet::CMyCoordPropSheet(CWnd* pWndParent)
- : CPropertySheet(AFX_IDS_APP_TITLE, pWndParent)
- {
- // Initialize our member variables
- m_pButtonApply = NULL;
- m_bPageOriginDirty = FALSE;
- m_bPageRotationDirty = FALSE;
- m_bPageScaleDirty = FALSE;
- m_bPageTranslateDirty = FALSE;
- // Add our CPropertyPage derived class pages
- AddPage(&m_CoordPagePosition);
- AddPage(&m_CoordPageRotation);
- AddPage(&m_CoordPageTranslate);
- AddPage(&m_CoordPageScale);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyCoordPropSheet procedures
- CRect CMyCoordPropSheet::CalcTabCtrlPosn(int cx, int cy)
- {
- CRect Crect;
- int borderSize = 10;
- // Get the pointer to the Tab Control
- CTabCtrl* pTab = GetTabControl();
- if(pTab)
- {
- RECT rect;
- // Get the size of the CTabCtrl item and the number of
- // rows to be displayed.
- pTab->GetItemRect( 0, &rect);
- int rows = pTab->GetRowCount();
-
- // Calculate the size and position of the CTabCtrl
- Crect.left = borderSize;
- Crect.right = cx-borderSize;
- Crect.top = rows*(rect.bottom-rect.top)+borderSize;
- Crect.bottom = cy-borderSize;
- }
- return Crect;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyCoordPropSheet user mapped message handlers
- long CMyCoordPropSheet::OnPageChanged(WPARAM wParam, LPARAM lParam)
- {
- // This message is sent to the CPropertySheet when the CPropertyPage
- // derived class member(s) call SetModified(TRUE);
- // Get the handle of the page which changed
- HWND hWnd = (HWND)wParam;
- ASSERT(hWnd);
- // Set the appropriate 'dirty' flag
- if(hWnd == m_CoordPagePosition.m_hWnd)
- m_bPageOriginDirty = TRUE;
- if(hWnd == m_CoordPageRotation.m_hWnd)
- m_bPageRotationDirty = TRUE;
- if(hWnd == m_CoordPageScale.m_hWnd)
- m_bPageScaleDirty = TRUE;
- if(hWnd == m_CoordPageTranslate.m_hWnd)
- m_bPageTranslateDirty = TRUE;
- // Enable the 'Apply' button
- m_pButtonApply->EnableWindow(TRUE);
- return 0L;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMyCoordPropSheet message handlers
- int CMyCoordPropSheet::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
- return -1;
- //*
- // Create a font for our Apply button
- HFONT hFont = ::CreateFont(-8, // nHeight
- 0, // nWidth
- 0, // nEscapement
- 0, // nOrientation
- FW_NORMAL, // nWeight
- FALSE, // bItalic
- FALSE, // bUnderline
- 0, // cStrikeOut
- ANSI_CHARSET, // nCharSet
- OUT_DEFAULT_PRECIS, // nOutPrecision
- CLIP_DEFAULT_PRECIS,// nClipPrecision
- DEFAULT_QUALITY, // nQuality
- DEFAULT_PITCH | // nPitchAndFamily
- FF_SWISS,
- "MS Sans Serif"); // lpszFacename
- // Set the CPropertySheet's font
- SendMessage(WM_SETFONT, (WPARAM)hFont, 0L);
- // Create the Apply button
- m_pButtonApply = new CButton();
- if (!m_pButtonApply->Create("Apply", // lpszWindowName
- WS_CHILD | // dwStyle
- BS_PUSHBUTTON,
- ApplyButtonRect, // rect
- this, // CWnd* pParentWnd
- IDC_APPLY)) // UINT nID
- {
- delete m_pButtonApply;
- m_pButtonApply = NULL;
- return -1;
- }
- // Set this CButton's font
- m_pButtonApply->SendMessage(WM_SETFONT, (WPARAM)hFont, 0L);
-
- // Show the 'Apply' button
- m_pButtonApply->ShowWindow(SW_SHOW);
- //*/
- return 0;
- }
- void CMyCoordPropSheet::OnDestroy()
- {
- CPropertySheet::OnDestroy();
-
- if(m_pButtonApply)
- {
- // Destroy the button and delete the class
- m_pButtonApply->DestroyWindow();
- delete m_pButtonApply;
- }
- }
- BOOL CMyCoordPropSheet::OnInitDialog()
- {
- CPropertySheet::OnInitDialog();
-
- RECT rc;
- // resize the sheet
- MoveWindow (&SheetRect);
-
- // resize the CTabCtrl
- CTabCtrl* pTab = GetTabControl ();
- ASSERT (pTab);
- // store tab size in m_TabRect
- m_TabRect.left = TabOffsetRect.left;
- m_TabRect.right = SheetRect.right-TabOffsetRect.right;
- m_TabRect.top = TabOffsetRect.top;
- m_TabRect.bottom = SheetRect.bottom-TabOffsetRect.bottom;
- pTab->MoveWindow (&m_TabRect);
- // Get the new CTabCtrl size and number of rows
- pTab->GetItemRect( 0, &rc);
- int rows = pTab->GetRowCount();
- // resize the page
- CPropertyPage* pPage = GetActivePage ();
- ASSERT (pPage);
- // store page size in m_PageRect
- m_PageRect.left = m_TabRect.left+PageOffsetRect.left;
- m_PageRect.right = m_TabRect.right-PageOffsetRect.right;
- m_PageRect.top = (m_TabRect.top+PageOffsetRect.top)+(rows*(rc.bottom-rc.top));
- m_PageRect.bottom = m_TabRect.bottom-PageOffsetRect.bottom;
- pPage->MoveWindow (&m_PageRect);
- // Now that the CPropertySheet and CPropertyPages are correctly
- // positioned, show the windows
- ShowWindow(SW_SHOW);
- // Disable the 'Apply' button
- m_pButtonApply->EnableWindow(FALSE);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CMyCoordPropSheet::OnApply()
- {
- // Get the appropriate Property Page(s) dialog data and
- // copy to the object
- if(m_bPageOriginDirty)
- m_CoordPagePosition.GetDialogData();
- if(m_bPageRotationDirty)
- m_CoordPageRotation.GetDialogData();
- if(m_bPageScaleDirty)
- m_CoordPageScale.GetDialogData();
- if(m_bPageTranslateDirty)
- // Get the Property Page dialog data and copy to the object
- m_CoordPageTranslate.GetDialogData();
- // Now that the data has been saved, disable the 'Apply' button
- m_pButtonApply->EnableWindow(FALSE);
- // Get a pointer to our Main Frame
- CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
- ASSERT_VALID(pFrame);
- if(pFrame->m_pActiveView)
- {
- // Get a pointer to our active view's document
- CMyglDoc* pDoc = (CMyglDoc*)pFrame->m_pActiveView->GetDocument();
- ASSERT_VALID(pDoc);
- // Get a pointer to our document's 3dWorld
- C3dWorld* pWorld = pDoc->m_pWorld;
- ASSERT_VALID(pWorld);
- // Set the document as modified...
- pDoc->SetModifiedFlag(TRUE);
- if(pWorld->m_pSelectedObj)
- // Force a rebuild of the selected objects display list
- pWorld->m_pSelectedObj->m_bBuildLists = TRUE;
- // Force a repaint of the window
- pDoc->UpdateAllViews(NULL);
- }
- }