HierarchyView.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: HierarchyView.h //////////////////////////////////////////////////////
  24. //-----------------------------------------------------------------------------
  25. //
  26. // Westwood Studios Pacific.
  27. //
  28. // Confidential Information
  29. // Copyright (C) 2001 - All Rights Reserved
  30. //
  31. //-----------------------------------------------------------------------------
  32. //
  33. // Project: GUIEdit
  34. //
  35. // File name: HierarchyView.h
  36. //
  37. // Created: Colin Day, July 2001
  38. //
  39. // Desc: Manipulation the widows heirarchy through the tree
  40. //
  41. //-----------------------------------------------------------------------------
  42. ///////////////////////////////////////////////////////////////////////////////
  43. #pragma once
  44. #ifndef __HIERARCHYVIEW_H_
  45. #define __HIERARCHYVIEW_H_
  46. // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
  47. #include <windows.h>
  48. #include <commctrl.h>
  49. // USER INCLUDES //////////////////////////////////////////////////////////////
  50. #include "Lib/BaseType.h"
  51. #include "GameClient/GameWindow.h"
  52. // FORWARD REFERENCES /////////////////////////////////////////////////////////
  53. ///////////////////////////////////////////////////////////////////////////////
  54. // TYPE DEFINES ///////////////////////////////////////////////////////////////
  55. ///////////////////////////////////////////////////////////////////////////////
  56. // Add slight improvement to load times -- was 2:30, now 0:02 for test case.
  57. #define USE_FAST_FIND_ITEM 1
  58. // HierarchyOption ------------------------------------------------------------
  59. //-----------------------------------------------------------------------------
  60. typedef enum
  61. {
  62. HIERARCHY_ADD_AT_TOP,
  63. HIERARCHY_ADD_AT_BOTTOM,
  64. } HierarchyOption;
  65. // HierarchyView --------------------------------------------------------------
  66. /** This view allows users to manipulate the windows hierarchy using
  67. * a tree view control */
  68. //-----------------------------------------------------------------------------
  69. class HierarchyView
  70. {
  71. public:
  72. HierarchyView( void );
  73. ~HierarchyView( void );
  74. void init( void );
  75. void reset( void );
  76. void shutdown( void );
  77. char *getWindowTreeName( GameWindow *window );
  78. void addWindow( GameWindow *window, HierarchyOption option ); ///< add a window to the view
  79. void removeWindow( GameWindow *window ); ///< remove window from tree
  80. void bringWindowToTop( GameWindow *window ); ///< bring window to top of parent list
  81. void updateWindowName( GameWindow *window ); ///< update tree entry based on name
  82. void selectWindow( GameWindow *window ); ///< select window
  83. HWND getTreeHandle( void ); ///< get the tree control handle
  84. HWND getHierarchyHandle( void ); ///< get window handle for the whole dialog
  85. void setDialogPos( ICoord2D *pos );
  86. void getDialogPos( ICoord2D *pos );
  87. void setDialogSize( ICoord2D *size );
  88. void getDialogSize( ICoord2D *size );
  89. void setDragWindow( GameWindow *window );
  90. void setDragTarget( GameWindow *window );
  91. GameWindow *getDragWindow( void );
  92. GameWindow *getDragTarget( void );
  93. void moveWindowAheadOf( GameWindow *window, GameWindow *aheadOf ); ///< move hierarchy representation
  94. void moveWindowChildOf( GameWindow *window, GameWindow *parent ); ///< move hierarchy representation
  95. Bool validateDragDropOperation( GameWindow *source, GameWindow *target );
  96. void setPopupTarget( GameWindow *window ); ///< set target for popup menu
  97. GameWindow *getPopupTarget( void ); ///< get the popup target window
  98. HTREEITEM treePointToItem( Int x, Int y ); ///< translate mouse pos to item location
  99. GameWindow *getWindowFromItem( HTREEITEM treeItem ); ///< get game window from user data in the tree item
  100. protected:
  101. static LRESULT CALLBACK dialogProc( HWND hWndDialog, UINT message,
  102. WPARAM wParam, LPARAM lParam );
  103. void addWindowToTree( GameWindow *window, HTREEITEM treeParent,
  104. HierarchyOption option, Bool addChildren,
  105. Bool addSiblings ); ///< workhorse for addWindow()
  106. HTREEITEM findItemEntry( HTREEITEM node, GameWindow *window ); ///< workhorse for findTreeEntry
  107. HTREEITEM findTreeEntry( GameWindow *window ); ///< return entry if in tree
  108. HWND m_dialog; ///< window handle for our control dialog
  109. HWND m_tree; ///< window handle for the tree control
  110. GameWindow *m_dragWindow; ///< for drag drop operations
  111. GameWindow *m_dragTarget; ///< target for drag and drop operations while mouse is moving
  112. GameWindow *m_popupTarget; ///< the target for right mouse popup menus
  113. #if USE_FAST_FIND_ITEM
  114. typedef const GameWindow* ConstGameWindowPtr;
  115. // use special class for hashing, since std::hash won't compile for arbitrary ptrs
  116. struct hashConstGameWindowPtr
  117. {
  118. size_t operator()(ConstGameWindowPtr p) const
  119. {
  120. std::hash<UnsignedInt> hasher;
  121. return hasher((UnsignedInt)p);
  122. }
  123. };
  124. typedef std::hash_map< ConstGameWindowPtr, HTREEITEM, hashConstGameWindowPtr, std::equal_to<ConstGameWindowPtr> > TreeHash;
  125. TreeHash m_treeHash; ///< Speed up the search with a nice hash.
  126. #endif
  127. }; // end HierarchyView
  128. ///////////////////////////////////////////////////////////////////////////////
  129. // INLINING ///////////////////////////////////////////////////////////////////
  130. ///////////////////////////////////////////////////////////////////////////////
  131. inline HWND HierarchyView::getTreeHandle( void ) { return m_tree; }
  132. inline HWND HierarchyView::getHierarchyHandle( void ) { return m_dialog; }
  133. inline void HierarchyView::setDragWindow( GameWindow *window ) { m_dragWindow = window; }
  134. inline void HierarchyView::setDragTarget( GameWindow *window ) { m_dragTarget = window; }
  135. inline GameWindow *HierarchyView::getDragWindow( void ) { return m_dragWindow; }
  136. inline GameWindow *HierarchyView::getDragTarget( void ) { return m_dragTarget; }
  137. inline void HierarchyView::setPopupTarget( GameWindow *window ) { m_popupTarget = window; }
  138. inline GameWindow *HierarchyView::getPopupTarget( void ) { return m_popupTarget; }
  139. // EXTERNALS //////////////////////////////////////////////////////////////////
  140. extern HierarchyView *TheHierarchyView; ///< singleton for our view
  141. #endif // __CONTROLPALETTE_H_