Gray C++ Libraries  0.0.2
A set of C++ libraries for MSVC, GNU on Windows, WinCE, Linux
cXListBox.h
Go to the documentation of this file.
1 //
4 //
5 #ifndef _INC_cXListBox_H
6 #define _INC_cXListBox_H
7 #pragma once
8 
9 #include "cXCheckBox.h"
10 #include "cXButton.h"
11 #include "cXScrollBar.h"
12 
13 namespace GrayGUI
14 {
15  typedef cXCheckBox cXListItem; // same thing.
16  typedef cXCheckBoxPtr cXListItemPtr; // same thing.
17 
18  class cXListBox : public cXWindowText
19  {
23  friend class cXComboBox;
24  typedef cXWindowText SUPER_t;
25  public:
26  cXListBox(cXWindow* pParent, DLGID_t id, bool bCheckSelected = true, bool bCollapsable = false);
27  virtual ~cXListBox();
28  virtual bool InitXWindow(void);
29  virtual HRESULT DisposeThis();
30 
31  virtual bool OnMouseWheel(MBUTTON_TYPE uButton, PIXELS_t x, PIXELS_t y, short nWheelChange);
32  virtual bool OnChar(VK_TYPE vKey);
33  virtual bool OnCommand(DLGID_t id, cXWindow* pCtrl, WORD wNotify);
34 
35  virtual void OnContextMenu(cXMenu* pMenu, cXWindow* pCtrl);
36  virtual void OnScroll(int iPos, cXWindow* pCtrl);
37  virtual void OnSize(UINT uType, PIXELS_t cx, PIXELS_t cy);
38 
39  int get_ItemCount(void) const
40  {
41  return m_aChildren.GetSize();
42  }
43  void AddNewItemCtrl(cXListItem* pItem, int index = -1, bool bUpdate = true);
44  cXListItemPtr AddNewItem(const GChar_t* pszCaption, cVariant& vData = cVariant());
45  bool RemoveListAt(int i);
46  void RemoveListItem(cXListItem* Item);
47  void RemoveListAll();
48  void ClearItems();
49  void UpdateItemOrder(bool bReSize);
50  bool UpdateScroller(bool bSetSize);
51  void UpdateChildren();
52  void UpdateView();
53  void QSort();
54  int FindString(cString strItem, bool bPartialMatch = false) const;
55  cXListItemPtr FindStringPtr(cString strItem, bool bPartialMatch = false) const;
57 
58  // Display of items.
60  {
61  return m_lListItemHeight; // from g_XStylePrefs.GetFontSize(FONTSCALE_Medium)
62  }
63  void put_ItemHeight(PIXELS_t lHeight)
64  {
65  m_lListItemHeight = lHeight;
67  }
68  void ScrollToTop(int nItem);
69  void ScrollToView(int nItem);
70 
71  // Selection of items.
73  {
74  return m_pSelectedItem;
75  }
76  int get_SelectedID() const
77  {
78  // should be same as m_nSelectedItem. USE DLGID_t??
79  if (m_pSelectedItem == nullptr)
80  return -1;
81  return m_pSelectedItem->get_DlgID();
82  }
84  {
85  if (m_pSelectedItem == nullptr)
86  return cVariant();
87  return m_pSelectedItem->get_UserData();
88  }
89  void put_Selected(cXListItem* pSelect);
90  void put_SelectedItem(int nItem);
91  void put_SelectedItemString(cString strItem, bool bPartialMatch = false);
92 
93  cXListItemPtr GetItemAt(long iSlot);
94  void put_ColorType(bool bColorType)
95  {
96  m_bColorType = bColorType;
97  }
98  int get_MaxItemsCanShow() const
99  {
100  // given the size of the window . how many elements can i show?
101  return m_iMaxItemsCanShow;
102  }
103 
105  {
106  return m_pScrollBar;
107  }
108 
110  {
111  return m_pScrollBar->get_Width();
112  }
113 
114  void DrawListItemsOpaque(void);
115 
116  virtual void put_BackAlpha(COLOR_ELEM_t bAlpha);
117 
118  bool get_CheckSelected() const
119  {
120  return m_bCheckSelected;
121  }
122  void put_CheckSelected(bool bCheckSelected)
123  {
124  if (m_bCheckSelected == bCheckSelected)
125  return;
126  m_bCheckSelected = bCheckSelected;
127  }
128  int get_TopDisplay() const
129  {
130  return m_iTopDisplay;
131  }
132 
133  int get_ItemsExpanded() const
134  {
135  // How many items are actually expanded now, for the scroll bar.
136  return m_iItemsExpanded;
137  }
138 
139  void put_ExpandedAll(bool bExpandAll);
140 
141  void put_Collapsable(bool bCollapsable);
142  bool get_Collapsable(void) const
143  {
144  return m_bCollapsable;
145  }
146 
147  protected:
148  void SetItemAlpha(cXListItem* pItem, bool bSelect, int iAlpha);
149  void SetItemState(cXListItem* pItem, bool bSelect);
150 
151  bool get_WantScrollBar() const;
152  void UpdateMaxItemsCanShow();
153  int FindNextExpanded(int iDelta) const;
154 
155  public:
157 
158  protected:
160 
161  int m_iTopDisplay; // item currently at the top of the window.
162  int m_iMaxItemsCanShow; // number of items i can show at once. given OnSize()
164 
165  int m_nSelectedItem; // enum id of the selected item.
167 
169  bool m_bCheckSelected; // whether the list treats selected items as checkboxes or buttons
170 
171  // NOT YET WORKING! ??? // with a truth value that we'll later read?
172  // bool m_bAllowMultiSelect;
173 
174  // All collapsability code now in cXListBox
175  bool m_bCollapsable; //denotes this listbox as being collapable. inserts cXListItemHeaders.
176  int m_iItemsExpanded; //size of list, collapsed states considered. Updated from UpdateItemOrder
177  };
178 
180 };
181 
182 #endif
INT32 HRESULT
_WIN32 style error codes. INT32
Definition: SysTypes.h:465
int VK_TYPE
a type of physical key in _WIN32. "#define VK_UP" etc. NOT the same as a scan code.
Definition: cInputBase.h:27
Definition: cXCheckBox.h:14
Definition: cXComboBox.h:19
Definition: cXListBox.h:19
int get_ItemsExpanded() const
Definition: cXListBox.h:133
cXListItemPtr m_pSelectedItem
Definition: cXListBox.h:166
void put_Collapsable(bool bCollapsable)
Definition: cXListBox.cpp:550
bool m_bCheckSelected
Definition: cXListBox.h:169
cXListItemPtr GetItemAt(long iSlot)
Definition: cXListBox.cpp:48
PIXELS_t m_lListItemHeight
Definition: cXListBox.h:163
void ClearItems()
Definition: cXListBox.cpp:53
bool get_Collapsable(void) const
Definition: cXListBox.h:142
void SetItemState(cXListItem *pItem, bool bSelect)
Definition: cXListBox.cpp:307
int m_iMaxItemsCanShow
Definition: cXListBox.h:162
virtual bool OnCommand(DLGID_t id, cXWindow *pCtrl, WORD wNotify)
Definition: cXListBox.cpp:618
cXListItemPtr get_ItemUnderCursor() const
Definition: cXListBox.cpp:84
void ScrollToView(int nItem)
Definition: cXListBox.cpp:259
void RemoveListAll()
Definition: cXListBox.cpp:495
int m_nSelectedItem
Definition: cXListBox.h:165
cXListItemPtr FindStringPtr(cString strItem, bool bPartialMatch=false) const
Definition: cXListBox.cpp:404
cXListBox(cXWindow *pParent, DLGID_t id, bool bCheckSelected=true, bool bCollapsable=false)
Definition: cXListBox.cpp:20
void UpdateItemOrder(bool bReSize)
Definition: cXListBox.cpp:106
cArraySortName< cXListItem > m_aChildren
Definition: cXListBox.h:156
PIXELS_t get_ItemHeight() const
Definition: cXListBox.h:59
virtual bool InitXWindow(void)
Definition: cXListBox.cpp:708
bool m_bCollapsable
Definition: cXListBox.h:175
virtual void OnContextMenu(cXMenu *pMenu, cXWindow *pCtrl)
Definition: cXListBox.cpp:666
int get_MaxItemsCanShow() const
Definition: cXListBox.h:98
void put_ItemHeight(PIXELS_t lHeight)
Definition: cXListBox.h:63
virtual void OnSize(UINT uType, PIXELS_t cx, PIXELS_t cy)
Definition: cXListBox.cpp:689
void SetItemAlpha(cXListItem *pItem, bool bSelect, int iAlpha)
Definition: cXListBox.cpp:291
PIXELS_t get_ScrollBarWidth() const
Definition: cXListBox.h:109
int FindNextExpanded(int iDelta) const
Definition: cXListBox.cpp:574
void put_SelectedItem(int nItem)
Definition: cXListBox.cpp:555
bool RemoveListAt(int i)
Definition: cXListBox.cpp:502
void put_Selected(cXListItem *pSelect)
Definition: cXListBox.cpp:330
bool UpdateScroller(bool bSetSize)
Definition: cXListBox.cpp:174
cXListItemPtr AddNewItem(const GChar_t *pszCaption, cVariant &vData=cVariant())
Definition: cXListBox.cpp:474
bool get_WantScrollBar() const
Definition: cXListBox.cpp:72
virtual HRESULT DisposeThis()
utility
Definition: cXListBox.cpp:40
int m_iItemsExpanded
Definition: cXListBox.h:176
void QSort()
Definition: cXListBox.cpp:236
void put_ExpandedAll(bool bExpandAll)
Definition: cXListBox.cpp:530
virtual void put_BackAlpha(COLOR_ELEM_t bAlpha)
Definition: cXListBox.cpp:363
virtual void OnScroll(int iPos, cXWindow *pCtrl)
Definition: cXListBox.cpp:680
void RemoveListItem(cXListItem *Item)
Definition: cXListBox.cpp:513
bool get_CheckSelected() const
Definition: cXListBox.h:118
int get_ItemCount(void) const
Definition: cXListBox.h:39
bool m_bColorType
Definition: cXListBox.h:168
int m_iTopDisplay
Definition: cXListBox.h:161
void ScrollToTop(int nItem)
Definition: cXListBox.cpp:242
cXScrollBarPtr get_ScrollBar() const
Definition: cXListBox.h:104
void DrawListItemsOpaque(void)
Definition: cXListBox.cpp:60
int FindString(cString strItem, bool bPartialMatch=false) const
Definition: cXListBox.cpp:377
virtual ~cXListBox()
Definition: cXListBox.cpp:36
virtual bool OnChar(VK_TYPE vKey)
Definition: cXListBox.cpp:604
void put_SelectedItemString(cString strItem, bool bPartialMatch=false)
Definition: cXListBox.cpp:569
cVariant get_SelectedItemData(void) const
Definition: cXListBox.h:83
void UpdateView()
Definition: cXListBox.cpp:281
void UpdateChildren()
Definition: cXListBox.cpp:221
void put_CheckSelected(bool bCheckSelected)
Definition: cXListBox.h:122
cXScrollBarPtr m_pScrollBar
Definition: cXListBox.h:159
virtual bool OnMouseWheel(MBUTTON_TYPE uButton, PIXELS_t x, PIXELS_t y, short nWheelChange)
Definition: cXListBox.cpp:696
void UpdateMaxItemsCanShow()
Definition: cXListBox.cpp:101
void put_ColorType(bool bColorType)
Definition: cXListBox.h:94
cXListItemPtr get_Selected() const
Definition: cXListBox.h:72
int get_SelectedID() const
Definition: cXListBox.h:76
int get_TopDisplay() const
Definition: cXListBox.h:128
void AddNewItemCtrl(cXListItem *pItem, int index=-1, bool bUpdate=true)
Definition: cXListBox.cpp:412
Definition: cXMenu.h:17
Definition: cXWindow.h:484
Definition: cXWindow.h:94
Definition: cVariant.h:26
Definition: cArraySortRef.h:199
Definition: cRefPtr.h:225
Definition: GrayGUI.cpp:11
cXCheckBox cXListItem
Definition: cXListBox.h:15
cRefPtr< cXListBox > cXListBoxPtr
Definition: cXComboBox.h:15
cXCheckBoxPtr cXListItemPtr
Definition: cXListBox.h:16
UINT DLGID_t
old window format this was a WORD, EX format this is UINT32.
Definition: cResDialog.h:68
BYTE COLOR_ELEM_t
A single 8 bit color element. alpha, red, green, or blue intensity as 0-255.
Definition: cColorRef.h:34
MBUTTON_TYPE
Definition: cInputBase.h:40
class __DECL_IMPORT cVariant
Definition: cJSONWriter.h:19
int PIXELS_t
Count of pixels in a dimension of some image/surface.
Definition: cSurfaceInfo.h:20
char GChar_t
My version of TCHAR, _TCHAR.
Definition: StrConst.h:26
uint16 index
Definition: sample3.cpp:29