MyCoordPropSheet.cpp
上传用户:cding2008
上传日期:2007-01-03
资源大小:1812k
文件大小:8k
源码类别:

OpenGL

开发平台:

Visual C++

  1. /////////////////////////////////////////////////////////////////////////////
  2. // MyCoordPropSheet.cpp : implementation file
  3. //
  4. // ModelMagic 3D and 'glOOP' (OpenGL Object Oriented Programming library)
  5. // Copyright (c) Craig Fahrnbach 1997, 1999
  6. //
  7. // OpenGL is a registered trademark of Silicon Graphics
  8. //
  9. //
  10. // This program is provided for educational and personal use only and
  11. // is provided without guarantee or warrantee expressed or implied.
  12. //
  13. // Commercial use is strickly prohibited without written permission
  14. // from ImageWare Development.
  15. //
  16. /////////////////////////////////////////////////////////////////////////////
  17. #include "stdafx.h"
  18. #include "ModelMagic3D.h"
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. ////////////////////////////////////////////////////////////////////
  25. // CMyCoordPropSheet globals
  26. // RECT {left, top, right, bottom };
  27. static RECT SheetRect = {  2,   6, 140, 175};
  28. static RECT TabOffsetRect = {  2,   4,   2,  41};
  29. static RECT PageOffsetRect = {  2,   4,   2,   4};
  30. static RECT ApplyButtonRect = { 40, 140,  95, 160};
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CMyCoordPropSheet
  33. IMPLEMENT_DYNAMIC(CMyCoordPropSheet, CPropertySheet)
  34. /////////////////////////////////////////////////////////////////////////////
  35. // CMyCoordPropSheet dialog message map
  36. BEGIN_MESSAGE_MAP(CMyCoordPropSheet, CPropertySheet)
  37. //{{AFX_MSG_MAP(CMyCoordPropSheet)
  38. ON_WM_CREATE()
  39. ON_WM_DESTROY()
  40. ON_BN_CLICKED(IDC_APPLY, OnApply)
  41. //}}AFX_MSG_MAP
  42. // USER defined messages
  43. ON_MESSAGE( PSM_CHANGED, OnPageChanged)
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CMyCoordPropSheet dialog construction
  47. CMyCoordPropSheet::CMyCoordPropSheet(CWnd* pWndParent)
  48. : CPropertySheet(AFX_IDS_APP_TITLE, pWndParent)
  49. {
  50. // Initialize our member variables
  51. m_pButtonApply = NULL;
  52. m_bPageOriginDirty = FALSE;
  53. m_bPageRotationDirty = FALSE;
  54. m_bPageScaleDirty = FALSE;
  55. m_bPageTranslateDirty = FALSE;
  56. // Add our CPropertyPage derived class pages
  57. AddPage(&m_CoordPagePosition);
  58. AddPage(&m_CoordPageRotation);
  59. AddPage(&m_CoordPageTranslate);
  60. AddPage(&m_CoordPageScale);
  61. }
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CMyCoordPropSheet procedures
  64. CRect CMyCoordPropSheet::CalcTabCtrlPosn(int cx, int cy)
  65. {
  66. CRect Crect;
  67. int borderSize = 10;
  68. // Get the pointer to the Tab Control
  69. CTabCtrl* pTab = GetTabControl();
  70. if(pTab)
  71. {
  72. RECT rect;
  73. // Get the size of the CTabCtrl item and the number of
  74. // rows to be displayed.
  75. pTab->GetItemRect( 0, &rect);
  76. int rows = pTab->GetRowCount();
  77. // Calculate the size and position of the CTabCtrl
  78. Crect.left   = borderSize;
  79. Crect.right  = cx-borderSize;
  80. Crect.top    = rows*(rect.bottom-rect.top)+borderSize;
  81. Crect.bottom = cy-borderSize;
  82. }
  83. return Crect;
  84. }
  85. /////////////////////////////////////////////////////////////////////////////
  86. // CMyCoordPropSheet user mapped message handlers
  87. long CMyCoordPropSheet::OnPageChanged(WPARAM wParam, LPARAM lParam)
  88. {
  89. // This message is sent to the CPropertySheet when the CPropertyPage
  90. // derived class member(s) call  SetModified(TRUE);
  91. // Get the handle of the page which changed
  92. HWND hWnd = (HWND)wParam;
  93. ASSERT(hWnd);
  94. // Set the appropriate 'dirty' flag
  95. if(hWnd == m_CoordPagePosition.m_hWnd)
  96. m_bPageOriginDirty = TRUE;
  97. if(hWnd == m_CoordPageRotation.m_hWnd)
  98. m_bPageRotationDirty = TRUE;
  99. if(hWnd == m_CoordPageScale.m_hWnd)
  100. m_bPageScaleDirty = TRUE;
  101. if(hWnd == m_CoordPageTranslate.m_hWnd)
  102. m_bPageTranslateDirty = TRUE;
  103. // Enable the 'Apply' button
  104. m_pButtonApply->EnableWindow(TRUE);
  105. return 0L;
  106. }
  107. /////////////////////////////////////////////////////////////////////////////
  108. // CMyCoordPropSheet message handlers
  109. int CMyCoordPropSheet::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  110. {
  111. if (CPropertySheet::OnCreate(lpCreateStruct) == -1)
  112. return -1;
  113. //*
  114. // Create a font for our Apply button
  115. HFONT hFont = ::CreateFont(-8, // nHeight
  116. 0, // nWidth
  117. 0, // nEscapement
  118. 0, // nOrientation
  119. FW_NORMAL, // nWeight
  120. FALSE, // bItalic
  121. FALSE, // bUnderline
  122. 0, // cStrikeOut
  123. ANSI_CHARSET, // nCharSet
  124. OUT_DEFAULT_PRECIS, // nOutPrecision
  125. CLIP_DEFAULT_PRECIS,// nClipPrecision
  126. DEFAULT_QUALITY, // nQuality
  127. DEFAULT_PITCH | // nPitchAndFamily
  128. FF_SWISS,
  129. "MS Sans Serif"); // lpszFacename
  130. // Set the CPropertySheet's font
  131. SendMessage(WM_SETFONT, (WPARAM)hFont, 0L);
  132. // Create the Apply button
  133. m_pButtonApply = new CButton();
  134. if (!m_pButtonApply->Create("Apply", // lpszWindowName
  135. WS_CHILD | // dwStyle
  136. BS_PUSHBUTTON,
  137. ApplyButtonRect, // rect
  138. this, // CWnd* pParentWnd
  139. IDC_APPLY)) // UINT  nID
  140. {
  141. delete m_pButtonApply;
  142. m_pButtonApply = NULL;
  143. return -1;
  144. }
  145. // Set this CButton's font
  146. m_pButtonApply->SendMessage(WM_SETFONT, (WPARAM)hFont, 0L);
  147. // Show the 'Apply' button
  148. m_pButtonApply->ShowWindow(SW_SHOW);
  149. //*/
  150. return 0;
  151. }
  152. void CMyCoordPropSheet::OnDestroy() 
  153. {
  154. CPropertySheet::OnDestroy();
  155. if(m_pButtonApply)
  156. {
  157. // Destroy the button and delete the class
  158. m_pButtonApply->DestroyWindow();
  159. delete m_pButtonApply;
  160. }
  161. }
  162. BOOL CMyCoordPropSheet::OnInitDialog()
  163. {
  164.     CPropertySheet::OnInitDialog();
  165.  
  166.     RECT rc;
  167. // resize the sheet
  168. MoveWindow (&SheetRect);
  169.  
  170. // resize the CTabCtrl
  171. CTabCtrl* pTab = GetTabControl ();
  172. ASSERT (pTab);
  173.     // store tab size in m_TabRect
  174. m_TabRect.left   = TabOffsetRect.left;
  175. m_TabRect.right  = SheetRect.right-TabOffsetRect.right;
  176. m_TabRect.top    = TabOffsetRect.top;
  177. m_TabRect.bottom = SheetRect.bottom-TabOffsetRect.bottom;
  178.     pTab->MoveWindow (&m_TabRect);
  179. // Get the new CTabCtrl size and number of rows
  180. pTab->GetItemRect( 0, &rc);
  181. int rows = pTab->GetRowCount();
  182.     // resize the page
  183.     CPropertyPage* pPage = GetActivePage ();
  184.     ASSERT (pPage);
  185.     // store page size in m_PageRect
  186. m_PageRect.left   =  m_TabRect.left+PageOffsetRect.left;
  187. m_PageRect.right  =  m_TabRect.right-PageOffsetRect.right;
  188. m_PageRect.top    = (m_TabRect.top+PageOffsetRect.top)+(rows*(rc.bottom-rc.top));
  189. m_PageRect.bottom =  m_TabRect.bottom-PageOffsetRect.bottom;
  190.     pPage->MoveWindow (&m_PageRect);
  191. // Now that the CPropertySheet and CPropertyPages are correctly
  192. // positioned, show the windows
  193. ShowWindow(SW_SHOW);
  194. // Disable the 'Apply' button
  195. m_pButtonApply->EnableWindow(FALSE);
  196. return TRUE;  // return TRUE unless you set the focus to a control
  197.               // EXCEPTION: OCX Property Pages should return FALSE
  198. }
  199. void CMyCoordPropSheet::OnApply() 
  200. {
  201. // Get the appropriate Property Page(s) dialog data and
  202. // copy to the object
  203. if(m_bPageOriginDirty)
  204. m_CoordPagePosition.GetDialogData();
  205. if(m_bPageRotationDirty)
  206. m_CoordPageRotation.GetDialogData();
  207. if(m_bPageScaleDirty)
  208. m_CoordPageScale.GetDialogData();
  209. if(m_bPageTranslateDirty)
  210. // Get the Property Page dialog data and copy to the object
  211. m_CoordPageTranslate.GetDialogData();
  212. // Now that the data has been saved, disable the 'Apply' button
  213. m_pButtonApply->EnableWindow(FALSE);
  214. // Get a pointer to our Main Frame
  215. CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
  216. ASSERT_VALID(pFrame);
  217. if(pFrame->m_pActiveView)
  218. {
  219. // Get a pointer to our active view's document
  220. CMyglDoc* pDoc = (CMyglDoc*)pFrame->m_pActiveView->GetDocument();
  221. ASSERT_VALID(pDoc);
  222. // Get a pointer to our document's 3dWorld
  223. C3dWorld* pWorld = pDoc->m_pWorld;
  224. ASSERT_VALID(pWorld);
  225. // Set the document as modified...
  226. pDoc->SetModifiedFlag(TRUE);
  227. if(pWorld->m_pSelectedObj)
  228. // Force a rebuild of the selected objects display list
  229. pWorld->m_pSelectedObj->m_bBuildLists = TRUE;
  230. // Force a repaint of the window
  231. pDoc->UpdateAllViews(NULL);
  232. }
  233. }