| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- /*
- ** Command & Conquer Renegade(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** This program is free software: you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation, either version 3 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /***********************************************************************************************
- *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
- ***********************************************************************************************
- * *
- * Project Name : wwui *
- * *
- * $Archive:: /Commando/Code/wwui/treectrl.h $*
- * *
- * Author:: Patrick Smith *
- * *
- * $Modtime:: 9/18/01 1:47p $*
- * *
- * $Revision:: 2 $*
- * *
- *---------------------------------------------------------------------------------------------*
- * Functions: *
- * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
- #if defined(_MSC_VER)
- #pragma once
- #endif
- #ifndef __TREECTRL_H
- #define __TREECTRL_H
- #include "dialogcontrol.h"
- #include "vector.h"
- #include "render2dsentence.h"
- #include "scrollbarctrl.h"
- #include "listiconmgr.h"
- //////////////////////////////////////////////////////////////////////
- // Forward declarations
- //////////////////////////////////////////////////////////////////////
- class TreeItemClass;
- class TreeCtrlClass;
- //////////////////////////////////////////////////////////////////////
- // Typedefs
- //////////////////////////////////////////////////////////////////////
- typedef DynamicVectorClass<TreeItemClass *> TREE_ITEM_LIST;
- typedef int (CALLBACK *TREECTRL_SORT_CALLBACK) (TreeCtrlClass *tree_ctrl, TreeItemClass *item1, TreeItemClass *item2, uint32 user_param);
- //////////////////////////////////////////////////////////////////////
- //
- // TreeCtrlClass
- //
- //////////////////////////////////////////////////////////////////////
- class TreeCtrlClass : public DialogControlClass
- {
- public:
- ///////////////////////////////////////////////////////////////////
- // Public constants
- ///////////////////////////////////////////////////////////////////
- typedef enum
- {
- HIT_PLUS = 0,
- HIT_ICON,
- HIT_TEXT,
- } HITTYPE;
- static const char *ICON_FOLDER;
- static const char *ICON_FOLDER_OPEN;
- ///////////////////////////////////////////////////////////////////
- // Public constructors/destructors
- ///////////////////////////////////////////////////////////////////
- TreeCtrlClass (void);
- ~TreeCtrlClass (void);
- // RTTI.
- virtual TreeCtrlClass * As_TreeCtrlClass (void) { return this; }
- ///////////////////////////////////////////////////////////////////
- // Public methods
- ///////////////////////////////////////////////////////////////////
-
- //
- // Inherited
- //
- void Render (void);
- void On_VScroll (ScrollBarCtrlClass *, int, int new_position);
- //
- // Content control
- //
- TreeItemClass * Insert_Item (const WCHAR *name, const char *icon_name, const char *selected_icon_name, TreeItemClass *parent);
- void Delete_Item (TreeItemClass *item);
- void Delete_All_Items (void);
- void Select_Item (TreeItemClass *item);
- TreeItemClass * Get_Selected_Item (void);
- //
- // Sort support
- //
- void Sort_Children_Alphabetically (TreeItemClass *parent);
- void Sort_Children (TreeItemClass *parent, TREECTRL_SORT_CALLBACK sort_callback, uint32 user_param);
- //
- // Misc
- //
- TreeItemClass * Hit_Test (const Vector2 &mouse_pos, HITTYPE &type);
- void Ensure_Visible (TreeItemClass *tree_item);
- protected:
-
- ////////////////////////////////////////////////////////////////
- // Protected methods
- ////////////////////////////////////////////////////////////////
- void On_LButton_Down (const Vector2 &mouse_pos);
- void On_LButton_DblClk (const Vector2 &mouse_pos);
- void On_LButton_Up (const Vector2 &mouse_pos);
- void On_Mouse_Wheel (int direction);
- void On_Set_Cursor (const Vector2 &mouse_pos);
- void On_Set_Focus (void);
- void On_Kill_Focus (DialogControlClass *focus);
- bool On_Key_Down (uint32 key_id, uint32 key_data);
- void On_Create (void);
- void Update_Client_Rect (void);
- void On_Expanded (TreeItemClass *item);
- void Create_Control_Renderers (void);
- void Create_Text_Renderers (void);
- void Set_Scroll_Pos (int new_pos);
- void Update_Scroll_Bar_Visibility (void);
- int Count_Visible_Rows (void);
- int Count_Visible_Rows (TreeItemClass *item);
-
- TreeItemClass * Get_Prev_Sibling (TreeItemClass *item);
- TreeItemClass * Get_Next_Sibling (TreeItemClass *item);
- TreeItemClass * Find_Prev_Visible (TreeItemClass *item);
- TreeItemClass * Find_Next_Visible (TreeItemClass *item);
- TreeItemClass * Find_Top_Item (void);
- TreeItemClass * Find_Last_Visible_Item (void);
-
- bool Render_Item (TreeItemClass *item, float x_pos, float &y_pos, int &row_index, int level);
- static int __cdecl Sort_Callback (const void *elem1, const void *elem2);
- static int CALLBACK Alphabetic_Sort_Callback (TreeCtrlClass *tree_ctrl, TreeItemClass *item1, TreeItemClass *item2, uint32 user_param);
- ////////////////////////////////////////////////////////////////
- // Protected member data
- ////////////////////////////////////////////////////////////////
- Render2DClass HilightRenderer;
- Render2DSentenceClass TextRenderer;
- Render2DClass ControlRenderer;
- Render2DClass PlusRenderer;
- Render2DClass IconRenderer;
- TREE_ITEM_LIST ItemList;
- TreeItemClass * SelectedItem;
- ListIconMgrClass IconMgr;
- float RowHeight;
- int RowsPerPage;
- int ScrollPos;
- ScrollBarCtrlClass ScrollBarCtrl;
- bool IsScrollBarDisplayed;
- static TREECTRL_SORT_CALLBACK CurrentSortCallback;
- static TreeCtrlClass * CurrentSorter;
- static uint32 CurrentSortUserData;
- friend class TreeItemClass;
- };
- //////////////////////////////////////////////////////////////////////
- //
- // TreeItemClass
- //
- //////////////////////////////////////////////////////////////////////
- class TreeItemClass
- {
- public:
- ///////////////////////////////////////////////////////////////////
- // Public constructors/destructors
- ///////////////////////////////////////////////////////////////////
- TreeItemClass (TreeCtrlClass *ctrl) :
- TreeCtrl (ctrl),
- Parent (NULL),
- UserData (0),
- IsExpanded (false),
- NeedsChildren (false) {}
- virtual ~TreeItemClass (void) {}
- ///////////////////////////////////////////////////////////////////
- // Public methods
- ///////////////////////////////////////////////////////////////////
- //
- // Name access
- //
- void Set_Name (const WCHAR *name);
- const WCHAR * Get_Name (void) const { return Name; }
- //
- // Icon access
- //
- void Set_Icon (const char *texture_name);
- const char * Get_Icon (void) const { return IconName; }
- void Set_Selected_Icon (const char *texture_name);
- const char * Get_Selected_Icon (void) const { return SelectedIconName; }
- //
- // User data access
- //
- void Set_User_Data (uint32 data) { UserData = data; }
- uint32 Get_User_Data (void) const { return UserData; }
- //
- // Selection control
- //
- void Select (void) { TreeCtrl->Select_Item (this); }
- bool Is_Selected (void) { return (TreeCtrl->Get_Selected_Item () == this); }
- //
- // Expanded access
- //
- void Expand (bool onoff);
- bool Is_Expanded (void) const { return IsExpanded; }
- //
- // Child access
- //
- void Add_Child (TreeItemClass *child) { ChildList.Add (child); NeedsChildren = false; }
- void Remove_Child (int index) { ChildList.Delete (index); }
- void Remove_Child (TreeItemClass *child);
- bool Needs_Children (void) const { return NeedsChildren; }
- void Set_Needs_Children (bool onoff);
- int Get_Child_Count (void) const { return ChildList.Count (); }
- TreeItemClass * Get_Child (int index) { return ChildList[index]; }
- TREE_ITEM_LIST & Get_Child_List (void) { return ChildList; }
- TreeItemClass * Get_Last_Child (void);
- //
- // Parent access
- //
- TreeItemClass * Get_Prev_Child (TreeItemClass *child);
- TreeItemClass * Get_Next_Child (TreeItemClass *child);
- void Set_Parent (TreeItemClass *parent) { Parent = parent; }
- TreeItemClass * Get_Parent (void) const { return Parent; }
- //
- // Indent access
- //
- int Get_Indent_Level (void);
- protected:
-
- ////////////////////////////////////////////////////////////////
- // Protected methods
- ////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////
- // Protected member data
- ////////////////////////////////////////////////////////////////
- TreeCtrlClass * TreeCtrl;
- TreeItemClass * Parent;
- WideStringClass Name;
- StringClass IconName;
- StringClass SelectedIconName;
- uint32 UserData;
- TREE_ITEM_LIST ChildList;
- bool IsExpanded;
- bool NeedsChildren;
- };
- #endif //__TREECTRL_H
|