WTL Controls
Back to the WTL Controls Home Page.
ODComboBox.h
Go to the documentation of this file.
1 #pragma once
2 #include "stdafx.h"
3 //--------------------------------------------------------------------------------------
4 //--------------------------------------------------------------------------------------
5 //
6 //
7 // WTL Control Library
8 // by
9 // Bright Ideas Software®
10 // Copyright © 2018 by Bright Ideas Software.
11 //
12 //
13 //
14 //--------------------------------------------------------------------------------------
15 //--------------------------------------------------------------------------------------
16 
17 namespace BIS_WTL_CONTROLS
18 {
19 
20  //----------------------------------------------------------------------------------------------
56  class CODComboBox : public CWindowImpl<CODComboBox, CComboBox>
57  , public COwnerDraw<CODComboBox>
58  {
59 
61  private:
62  //----------------------------------------------------------------------------------------------
69  class CODComboItem
70  {
71 
72  public:
73 
74  CODComboItem() noexcept;
75  CODComboItem(std::basic_string<TCHAR> text, COLORREF text_color, COLORREF back_color, HFONT font, int height,
76  CHorzAlignment horz, CVertAlignment vert, bool wrap, bool use_ellipsis);
77 
78  virtual ~CODComboItem();
79 
80  void UpdateBrush();
81 
82  CString m_Text;
83  COLORREF m_BackColor;
84  COLORREF m_TextColor;
85  HFONT m_Font;
86  HBRUSH m_Brush;
87  int m_iItemHeight;
88  CHorzAlignment m_HorzAlign;
89  CVertAlignment m_VertAlign;
90  bool m_bWrap;
91  bool m_bUseEllipsis;
92 
93  };
95 
96 
97  public:
98 
100  DECLARE_WND_SUPERCLASS(_T("CODComboBox"), CComboBox::GetWndClassName())
101 
102 
103 
104 
105  CODComboBox() noexcept;
106  virtual ~CODComboBox();
107 
108  void SubclassComboBox(HWND wnd);
109  void UnSubclassComboBox();
110 
111  void SetAutoAdjustDropRectWidth(bool value);
112  bool GetAutoAdjustDropRectWidth() const;
113 
114  void SetMaxDropDownWidth(int value);
115  int GetMaxDropDownWidth() const;
116 
117  void UpdateControlHeight();
118  void UpdateDropDownWidth();
119 
120 
121 
122  bool ODAddItem();
123  bool ODAddItem(std::basic_string<TCHAR> text, COLORREF text_color, COLORREF back_color, HFONT font, int height,
124  CHorzAlignment horz, CVertAlignment vert, bool wrap, bool use_ellipsis);
125 
126  bool ODInsertItem(int index);
127  bool ODInsertItem(int index, std::basic_string<TCHAR> text, COLORREF text_color, COLORREF back_color, HFONT font, int height,
128  CHorzAlignment horz, CVertAlignment vert, bool wrap, bool use_ellipsis);
129 
130  bool ODRemoveItem(int index);
131 
132  void SetODItemText(int index, std::basic_string<TCHAR> text);
133  std::basic_string<TCHAR> GetODItemText(int index) const;
134 
135  void SetODItemBackColor(int index, COLORREF color);
136  COLORREF GetODItemBackColor(int index) const;
137 
138  void SetODItemTextColor(int index, COLORREF color);
139  COLORREF GetODItemTextColor(int index) const;
140 
141  void SetODItemFont(int index, HFONT font);
142  HFONT GetODItemFont(int index) const;
143 
144  void SetODItemHeight(int index, int height);
145  int GetODItemHeight(int index) const;
146 
147  void SetODItemHorzAlignment(int index, CHorzAlignment value);
148  CHorzAlignment GetODItemHorzAlignment(int index) const;
149 
150  void SetODItemVertAlignment(int index, CVertAlignment value);
151  CVertAlignment GetODItemVertAlignment(int index) const;
152 
153  void SetODItemWordWrap(int index, bool wrap);
154  bool GetODItemWordWrap(int index) const;
155 
156  void SetODItemUseEllipsis(int index, bool ellipsis);
157  bool GetODItemUseEllipsis(int index) const;
158 
160  void DeleteItem( LPDELETEITEMSTRUCT lpDeleteItemStruct);
161  int CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct);
162  void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
163  void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
165 
166  private:
167 
168 
169  bool m_bAutoAdjustDropWidth;
170  int m_iMaxDropDownWidth;
171 
172  HWND m_wndControl;
173  HWND m_wndListBox;
174 
175  CWindow m_ControlWnd;
176  CListBox m_ListBox;
177 
178  CODComboItem* GetAndVerifyItemData(int index) const;
179 
180  UINT GetTextFormat(CODComboItem* item);
181 
182 
183  BEGIN_MSG_MAP_EX(CODComboBox)
184  CHAIN_MSG_MAP_ALT(COwnerDraw<CODComboBox>, 1)
185  DEFAULT_REFLECTION_HANDLER()
186  END_MSG_MAP()
187 
188 
189 
190  };
191  //----------------------------------------------------------------------------------------------
192 };
bool GetAutoAdjustDropRectWidth() const
Default: true.
Definition: ODComboBox.cpp:175
int GetODItemHeight(int index) const
Default: The height of the control portion of the combobox at the time the CODComboItem is instantiat...
Definition: ODComboBox.cpp:556
void SetODItemUseEllipsis(int index, bool ellipsis)
Modify the UseEllipsis state of the selected combobox item.
Definition: ODComboBox.cpp:722
CVertAlignment GetODItemVertAlignment(int index) const
DefaultL: vaMiddle.
Definition: ODComboBox.cpp:628
void SetODItemBackColor(int index, COLORREF color)
Modify the background color of the selected combobox item.
Definition: ODComboBox.cpp:464
HFONT GetODItemFont(int index) const
Default: The font assigned to the combo box when the CODComboItem object is instantiated.
Definition: ODComboBox.cpp:518
void SetMaxDropDownWidth(int value)
Sets the upper limit to the width of the dropdown list, if it is being automatically adjusted...
Definition: ODComboBox.cpp:219
CHorzAlignment GetODItemHorzAlignment(int index) const
Default: haLeft.
Definition: ODComboBox.cpp:592
CVertAlignment
Control vertical placement of text in control window.
Definition: WTL_Controls.h:47
void SetODItemHeight(int index, int height)
Modify the height of the selected combobox item.
Definition: ODComboBox.cpp:575
bool ODAddItem()
Add new item to the end of the list box.
Definition: ODComboBox.cpp:235
bool GetODItemWordWrap(int index) const
Default: false.
Definition: ODComboBox.cpp:664
void SubclassComboBox(HWND wnd)
Subclass a combobox control.
Definition: ODComboBox.cpp:121
void SetODItemFont(int index, HFONT font)
Modify the font assigned to the selected combobox item.
Definition: ODComboBox.cpp:537
COLORREF GetODItemBackColor(int index) const
Default: COLOR_WINDOW.
Definition: ODComboBox.cpp:445
void UpdateDropDownWidth()
Force an update of the width of the drop down list.
Definition: ODComboBox.cpp:741
void SetODItemVertAlignment(int index, CVertAlignment value)
Modify the vertical text aligment of the selected combobox item.
Definition: ODComboBox.cpp:647
bool ODInsertItem(int index)
Insert an item.
Definition: ODComboBox.cpp:311
void SetODItemText(int index, std::basic_string< TCHAR > text)
Modify the text associated with a combobox item.
Definition: ODComboBox.cpp:426
int GetMaxDropDownWidth() const
Default: 400 pixels.
Definition: ODComboBox.cpp:205
void SetODItemHorzAlignment(int index, CHorzAlignment value)
Modify the horizontal text alignment of the selected combobox item.
Definition: ODComboBox.cpp:611
CHorzAlignment
Control horizontal placement of text in control window.
Definition: WTL_Controls.h:42
void UnSubclassComboBox()
Un-subclass main and component windows; free GDI resources.
Definition: ODComboBox.cpp:148
An owner-drawn combo box featuring textual content with per-item colors and fonts.
Definition: ODComboBox.h:56
void SetODItemWordWrap(int index, bool wrap)
Modify the WordWrap state of the selected combobox item.
Definition: ODComboBox.cpp:685
COLORREF GetODItemTextColor(int index) const
Default: COLOR_WINDOWTEXT.
Definition: ODComboBox.cpp:482
std::basic_string< TCHAR > GetODItemText(int index) const
Default: "".
Definition: ODComboBox.cpp:407
bool ODRemoveItem(int index)
Deletes an item from the drop-down list.
Definition: ODComboBox.cpp:389
bool GetODItemUseEllipsis(int index) const
Default: true.
Definition: ODComboBox.cpp:702
void UpdateControlHeight()
Update the combobox height to accomodate all content.
Definition: ODComboBox.cpp:784
void SetAutoAdjustDropRectWidth(bool value)
Change the AutoAdjustRectWidth state.
Definition: ODComboBox.cpp:190
void SetODItemTextColor(int index, COLORREF color)
Modify the text color of the selected combobox item.
Definition: ODComboBox.cpp:501