OWLNext    7.0
Borland's Object Windows Library for the modern age
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
combobex.h
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1998 by Yura Bidus, All Rights Reserved
4//
5/// \file
6/// Definition of class TComboBoxEx.
7//----------------------------------------------------------------------------
8
9#if !defined(OWL_COMBOBEX_H)
10#define OWL_COMBOBEX_H
11
12#include <owl/private/defs.h>
13#if defined(BI_HAS_PRAGMA_ONCE)
14# pragma once
15#endif
16
17#include <owl/control.h>
18#include <owl/commctrl.h>
19#include <owl/combobox.h>
20#include <owl/property.h>
21
22namespace owl {
23
24class _OWLCLASS TImageList;
25class _OWLCLASS TComboBoxEx;
26class _OWLCLASS TComboBoxExData;
27
28#include <owl/preclass.h>
29
30/// \addtogroup newctrl
31/// @{
32
33//
34/// \class TComboBoxExItem
35/// Encapsulates an item in an extended combo box (COMBOBOXEXITEM).
36//
38{
39 public:
40
42 TComboBoxExItem(const tstring& str, INT_PTR item = -1,int image = -1);
43 TComboBoxExItem(const tstring& str, INT_PTR item,int image, int selectedImage, int overlayImage = -1, int indent = -1, LPARAM param = 0);
46
47 /// \name Comparison operators for templates
48 /// @{
49 bool operator <(const TComboBoxExItem& item) {return this < &item;}
50 bool operator ==(const TComboBoxExItem& item) {return this == &item;}
51 /// @}
52
53 /// \name Properties
54 /// @{
55 TProperty<int> Mask; ///< Band image index (into rebar image list): don't use -1
56 TProperty<INT_PTR> Item; ///< == -1 to add at end
57 TObjProperty<tstring> Text; ///< Band text label
58 TProperty<int> Image; ///< The item image
59 TProperty<int> Selected; ///< The item selected image
60 TProperty<int> Overlay; ///< Band colors
61 TProperty<int> Indent; ///< Band colors
62 TProperty<LPARAM> Param; ///< Additional data
63 /// @}
64
65 protected:
66
67 /// Initialises all data members to zero
68 //
69 void Init();
70
71 /// Initializes native item with this.
72 //
73 void InitItem(COMBOBOXEXITEM& item, uint tsize = 0) const;
74
75 /// Initializes this with native item.
76 //
77 void ReFillItem(const COMBOBOXEXITEM& item);
78
79 friend class _OWLCLASS TComboBoxEx;
80};
81
82//
83/// \class TComboBoxEx
84//
85/// ComboBoxEx controls are combo box controls that provide native support for item images.
86//
88 : public TComboBox
89{
90 public:
91
92 TComboBoxEx(TWindow* parent, int id, int x, int y, int w, int h, uint32 style, uint textLimit, TModule* module = 0);
93 TComboBoxEx(TWindow* parent, int resourceId, uint textLen = 0, TModule* module = 0);
94 TComboBoxEx(THandle hWnd, TModule* module = 0);
95 ~TComboBoxEx() override;
96
97 HWND GetEditControl();
98 HWND GetComboBoxCtrl();
99 bool HasEditChanged();
100
101 uint32 GetExtendedStyle() const;
102 uint32 SetExtendedStyle(uint32 mask, uint32 style);
103
104 TImageList* GetImageList();
105 void SetImageList(TImageList* list, TAutoDelete = AutoDelete);
106
107 void SetUnicode(bool unicode);
108 bool GetUnicode();
109
110 int DeleteItem(int index);
111 bool GetItem(TComboBoxExItem& item, INT_PTR index=-1);
112 TComboBoxExItem GetItem(INT_PTR index);
113 int InsertItem(const TComboBoxExItem& item);
114 bool SetItem(const TComboBoxExItem& item, INT_PTR index=-1);
115
116 /// Safe overload
117 //
120
121 protected:
122
123 // Override TWindow virtual member functions
124 //
125 auto Transfer(void* buffer, TTransferDirection) -> uint override;
126 auto GetWindowClassName() -> TWindowClassName override;
127 void SetupWindow() override;
128
129 // Override TControl
130 //
131 void DeleteItem(DELETEITEMSTRUCT&) override;
132
133 // Do nothing handlers
134 //
135 int EvCompareItem(uint ctrlId, const COMPAREITEMSTRUCT& comp);
136 void EvDeleteItem(uint ctrlId, const DELETEITEMSTRUCT& del);
137 void EvDrawItem(uint ctrlId, const DRAWITEMSTRUCT& draw);
138 void EvMeasureItem(uint ctrlId, MEASUREITEMSTRUCT & meas);
139
141
142 TImageList* ImageList;
143 bool ShouldDelete;
144
145 private:
146
147 // Hidden to prevent accidental copying or assignment
148 //
149 TComboBoxEx(const TComboBoxEx&);
151
153};
154
155
157typedef TComboBoxExItemArray::Iterator TComboBoxExItemArrayIter;
158
159//
160/// \class TComboBoxExData
161//
163{
164 public:
167
168 int AddItem(const TComboBoxExItem& item);
169 int DeleteItem(int index);
170 TComboBoxExItem& GetItem(int index);
171
172 void Clear();
173 uint Size();
174 void Select(int index);
175 void SelectString(LPCTSTR str);
176 void SelectString(const tstring& str) {SelectString(str.c_str());}
177 tstring& GetSelection();
178 const tstring& GetSelection() const;
179 int GetSelIndex() const;
180 int GetSelCount() const;
181 void ResetSelections();
182
183 int GetSelStringLength() const;
184 void GetSelString(LPTSTR buffer, int bufferSize) const;
185 const tstring& GetSelString() const {return Selection;}
186
187 protected:
191};
192
193/// @}
194
195#include <owl/posclass.h>
196
197//
198// inlines
199//
200
201//
204 return reinterpret_cast<HWND>(SendMessage(CBEM_GETEDITCONTROL,0));
205}
206
207//
210 return reinterpret_cast<HWND>(SendMessage(CBEM_GETCOMBOCONTROL, 0));
211}
212
213//
216 return static_cast<uint32>(CONST_CAST(TComboBoxEx*,this)->SendMessage(CBEM_GETEXTENDEDSTYLE, 0));
217}
218
219//
224
225//
226inline int TComboBoxEx::DeleteItem(int index){
228 return static_cast<int>(SendMessage(CBEM_DELETEITEM, TParam1(index)));
229}
230
231//
236
237//
239 return ImageList;
240}
241
242//
247
248//
253
254//
258
259//
261 return static_cast<int>(DefaultProcessing());
262}
263
264//
268
269//
273
274//
278
279//
280/// Selects an item at a given index.
281//
282inline void TComboBoxExData::Select(int index){
283 SelIndex = index;
285}
286
287//
289 return SelIndex;
290}
291
292//
296
298 return Selection;
299}
300
301//
303 return SelIndex == CB_ERR ? 0 : 1;
304}
305
306//
309 Selection = _T("");
310}
311
312//
313/// Returns the length of the selection string excluding the terminating 0
314//
316 return static_cast<int>(Selection.length());
317}
318
319
320
321} // OWL namespace
322
323#endif // OWL_COMBOBEX_H
#define PRECONDITION(condition)
Definition checks.h:227
void Select(int index)
Selects an item at a given index.
Definition combobex.h:282
int GetSelStringLength() const
Returns the length of the selection string excluding the terminating 0.
Definition combobex.h:315
int GetSelIndex() const
Definition combobex.h:288
TComboBoxExItemArray * Items
Definition combobex.h:188
TComboBoxExItem & GetItem(int index)
Definition combobex.cpp:418
int GetSelCount() const
Definition combobex.h:302
const tstring & GetSelString() const
Definition combobex.h:185
tstring & GetSelection()
Definition combobex.h:293
void SelectString(const tstring &str)
Definition combobex.h:176
ComboBoxEx controls are combo box controls that provide native support for item images.
Definition combobex.h:89
int EvCompareItem(uint ctrlId, const COMPAREITEMSTRUCT &comp)
Definition combobex.h:260
bool GetUnicode()
Definition combobex.h:249
void EvDeleteItem(uint ctrlId, const DELETEITEMSTRUCT &del)
Definition combobex.h:265
uint32 GetExtendedStyle() const
Definition combobex.h:214
TImageList * GetImageList()
Definition combobex.h:238
void Transfer(TComboBoxExData &data, TTransferDirection op)
Safe overload.
Definition combobex.h:118
void SetUnicode(bool unicode)
Definition combobex.h:243
int DeleteItem(int index)
Definition combobex.h:226
HWND GetComboBoxCtrl()
Definition combobex.h:208
HWND GetEditControl()
Definition combobex.h:202
void EvDrawItem(uint ctrlId, const DRAWITEMSTRUCT &draw)
Definition combobex.h:270
bool HasEditChanged()
Definition combobex.h:232
void EvMeasureItem(uint ctrlId, MEASUREITEMSTRUCT &meas)
Definition combobex.h:275
uint32 SetExtendedStyle(uint32 mask, uint32 style)
Definition combobex.h:220
Encapsulates an item in an extended combo box (COMBOBOXEXITEM).
Definition combobex.h:38
TProperty< int > Selected
The item selected image.
Definition combobex.h:59
TObjProperty< tstring > Text
Band text label.
Definition combobex.h:57
TProperty< int > Mask
Band image index (into rebar image list): don't use -1.
Definition combobex.h:55
TProperty< int > Overlay
Band colors.
Definition combobex.h:60
TProperty< LPARAM > Param
Additional data.
Definition combobex.h:62
TProperty< int > Indent
Band colors.
Definition combobex.h:61
TProperty< INT_PTR > Item
== -1 to add at end
Definition combobex.h:56
TProperty< int > Image
The item image.
Definition combobex.h:58
You can use TComboBox to create a combo box or a combo box control in a parent TWindow,...
Definition combobox.h:47
TImageList is a wrapper class for the ImageList common "control".
Definition imagelst.h:64
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
Type-safe encapsulation of a Windows class name, a union between ATOM and LPCTSTR.
Definition module.h:47
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
TResult DefaultProcessing()
Handles default processing of events, which includes continued processing of menu/accelerators comman...
Definition window.cpp:852
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
Definition window.cpp:3288
HWND THandle
TWindow encapsulates an HWND.
Definition window.h:418
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
Definition of class TComboBox and TComboBoxData the base class for all combobox controls.
Definition of classes for CommonControl encapsulation.
Definition of class TControl.
#define _T(x)
Definition cygwin.h:51
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
@ AutoDelete
Definition gdibase.h:70
TComboBoxExItemArray::Iterator TComboBoxExItemArrayIter
Definition combobex.h:157
TObjectArray< TComboBoxExItem > TComboBoxExItemArray
Definition combobex.h:156
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
Definition window.h:92
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned long uint32
Definition number.h:34
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
#define protected_data
Definition defs.h:208
#define CONST_CAST(targetType, object)
Definition defs.h:273
#define _OWLCLASS
Definition defs.h:338
Credits: The Property pattern is taken from "Patterns in Practice: A Property Template for C++",...