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

OpenGL

开发平台:

Visual C++

  1. /////////////////////////////////////////////////////////////////////
  2. // MyTreeDlgBar.cpp : implementation of the CMyTreeDlgBar floating 
  3. //   toolbar class
  4. //
  5. // ModelMagic 3D and 'glOOP' (OpenGL Object Oriented Programming library)
  6. // Copyright (c) Craig Fahrnbach 1997, 1999
  7. //
  8. // OpenGL is a registered trademark of Silicon Graphics
  9. //
  10. //
  11. // This program is provided for educational and personal use only and
  12. // is provided without guarantee or warrantee expressed or implied.
  13. //
  14. // Commercial use is strickly prohibited without written permission
  15. // from ImageWare Development.
  16. //
  17. /////////////////////////////////////////////////////////////////////////////
  18. #include "stdafx.h"
  19. #include "ModelMagic3D.h"
  20. ////////////////////////////////////////////////////////////////////
  21. // CMyTreeDlgBar Construction/Destruction
  22.  
  23. BOOL CMyTreeDlgBar::Create( CWnd* pParentWnd,
  24.     UINT nStyle,
  25. UINT nID, BOOL bChange)
  26. {
  27. if(!CDialogBar::Create(pParentWnd, CMyTreeDlgBar::IDD, nStyle, nID))
  28. return FALSE;
  29. m_bChangeDockedSize = bChange;
  30. m_sizeFloating = m_sizeDocked = m_sizeDefault;
  31. return TRUE;
  32. }
  33.  
  34. ////////////////////////////////////////////////////////////////////
  35. // Overloaded functions
  36.  
  37. CSize CMyTreeDlgBar::CalcDynamicLayout(int nLength, DWORD nMode)
  38. {
  39.     // Return default if it is being docked or floated
  40.     if ((nMode & LM_VERTDOCK) || (nMode & LM_HORZDOCK))
  41.     {
  42.         if (nMode & LM_STRETCH) // if not docked stretch to fit
  43.             return CSize((nMode & LM_HORZ) ? 32767 : m_sizeDocked.cx,
  44.                          (nMode & LM_HORZ) ? m_sizeDocked.cy : 32767);
  45.           else
  46.             return m_sizeDocked;
  47.     }
  48.     if (nMode & LM_MRUWIDTH)
  49.         return m_sizeFloating;
  50.     // In all other cases, accept the dynamic length
  51.     if (nMode & LM_LENGTHY)
  52.         return CSize(m_sizeFloating.cx, (m_bChangeDockedSize) ?
  53.                      m_sizeFloating.cy = m_sizeDocked.cy = nLength :
  54.                      m_sizeFloating.cy = nLength);
  55.      else
  56.         return CSize((m_bChangeDockedSize) ?
  57.                      m_sizeFloating.cx = m_sizeDocked.cx = nLength :
  58.                      m_sizeFloating.cx = nLength, m_sizeFloating.cy);
  59. }
  60. BEGIN_MESSAGE_MAP(CMyTreeDlgBar, CDialogBar)
  61.     //{{AFX_MSG_MAP(CMyTreeDlgBar)
  62. ON_WM_SIZE()
  63. ON_WM_CREATE()
  64. ON_WM_DESTROY()
  65. ON_WM_PALETTECHANGED()
  66. ON_WM_QUERYNEWPALETTE()
  67. ON_WM_PAINT()
  68. //}}AFX_MSG_MAP
  69. // USER defined messages
  70. END_MESSAGE_MAP()
  71. /////////////////////////////////////////////////////////////////////
  72. // CMyTreeDlgBar custom functions
  73. /////////////////////////////////////////////////////////////////////
  74. void CMyTreeDlgBar::DisplayTree(C3dWorld* pWorld)
  75. {
  76. m_TreeCtrl.DeleteAllItems();
  77. if(pWorld) {
  78. m_TreeCtrl.FillTree(pWorld);
  79. m_TreeCtrl.ExpandAllItems();
  80. }
  81. }
  82. void CMyTreeDlgBar::ClearTree()
  83. {
  84. m_TreeCtrl.DeleteAllItems();
  85. }
  86. void CMyTreeDlgBar::InsertObject(C3dObject* pObject)
  87. {
  88. m_TreeCtrl.InsertObject(pObject);
  89. }
  90. HTREEITEM CMyTreeDlgBar::FindObject(C3dObject* pObject)
  91. {
  92. return m_TreeCtrl.FindObject(pObject);
  93. }
  94. void CMyTreeDlgBar::SelectItem(HTREEITEM hItem)
  95. {
  96. m_TreeCtrl.SelectItem(hItem);
  97. }
  98. void CMyTreeDlgBar::DisplaySelected(C3dObject* pObject)
  99. {
  100. if(pObject)
  101. SelectItem(FindObject(pObject));
  102. }
  103. /////////////////////////////////////////////////////////////////////
  104. // CMyTreeDlgBar message handlers
  105. /////////////////////////////////////////////////////////////////////
  106. void CMyTreeDlgBar::OnSize(UINT nType, int cx, int cy) 
  107. {
  108. CDialogBar::OnSize(nType, cx, cy);
  109. // Get the handle of the CTreeCtrl window and set
  110. // its size
  111. HWND hTree = m_TreeCtrl.GetSafeHwnd();
  112. if(hTree) {
  113. m_TreeCtrl.SetWindowPos(NULL, 0+10, 0+10,
  114. cx-20, cy-20, SWP_NOZORDER | SWP_NOACTIVATE);
  115. }
  116. }
  117. int CMyTreeDlgBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  118. {
  119. if (CDialogBar::OnCreate(lpCreateStruct) == -1)
  120. return -1;
  121. // Get the last setting of the window position from
  122. // the ini file and restore
  123. WINDOWPLACEMENT wp;
  124. if (ReadWindowPlacement(&wp, "Settings", "TreeDlgWndPos"))
  125. SetWindowPlacement(&wp);
  126. // Create the Tree Control
  127. RECT rect = {0, 0, 0, 0};
  128. if(!m_TreeCtrl.Create(WS_BORDER | WS_THICKFRAME |
  129.   TVS_HASLINES | TVS_LINESATROOT |
  130.   TVS_HASBUTTONS | TVS_EDITLABELS |
  131.   TVS_SHOWSELALWAYS | TVS_DISABLEDRAGDROP,
  132.   rect,
  133.   this,
  134.   0))
  135. return -1;
  136. m_TreeCtrl.ShowWindow(SW_SHOW);
  137. return 0;
  138. }
  139. void CMyTreeDlgBar::OnDestroy() 
  140. {
  141. CDialogBar::OnDestroy();
  142. // Save the state of our CDialogBar derived class window
  143. WINDOWPLACEMENT wp;
  144. wp.length = sizeof wp;
  145. if (GetWindowPlacement(&wp))
  146. {
  147. wp.flags = 0;
  148. if (IsZoomed())
  149. wp.flags |= WPF_RESTORETOMAXIMIZED;
  150. // and write it to the .INI file
  151. WriteWindowPlacement(&wp, "Settings", "TreeDlgWndPos");
  152. }
  153. }
  154. void CMyTreeDlgBar::OnPaint() 
  155. {
  156. CPaintDC dc(this); // device context for painting
  157. // TODO: Add your message handler code here
  158. // Do not call CDialogBar::OnPaint() for painting messages
  159. }