OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
checklst.h
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Definition of class TCheckList, an ownerdrawn listbox to select multiple
7/// items
8// Portions Copyright (C) 1997, 98 by Dieter Windau from TCheckListBox class
9// EMail: dieter.windau@kvwl.de
10// Web: http://www.members.aol.com/SoftEngage
11//
12// Added new functionality from V 1.1 class of Dieter Windau -- 07/22/1998
13// Added Constructors to work with TCheckListItemArray -- 07/16/1998
14// Merged with OWL class and revised by Yura Bidus -- 06/17/1998
15//------------------------------------------------------------------------------
16
17#if !defined(OWL_CHECKLST_H)
18#define OWL_CHECKLST_H
19
20#include <owl/private/defs.h>
21#if defined(BI_HAS_PRAGMA_ONCE)
22# pragma once
23#endif
24
25#include <owl/listbox.h>
26#include <owl/checkbox.h>
27#include <owl/template.h>
28
29namespace owl {
30
31#include <owl/preclass.h>
32
33const int CheckList_BoxWidth = 15;
34
35/// \addtogroup newctrl
36/// @{
37
38//
39/// \class TCheckListItem
40/// Each item displayed and manipulated by TCheckList.
41//
43{
44 public:
46 TCheckListItem(const tstring&, uint state = BF_UNCHECKED, bool enabled = true);
47 TCheckListItem(const TCheckListItem& item);
48
50
51 // State management
52 //
53 bool IsChecked() const;
54 bool IsUnchecked() const;
55 bool IsIndeterminate() const;
56 bool IsEnabled() const;
57 uint GetState() const;
58 bool GetThreeStates() const;
59
60 void Toggle();
61 void Check();
62 void Uncheck();
63 void SetIndeterminate();
64 void SetThreeStates(bool);
65 void Enable();
66 void Disable();
67
68 // Text management
69 //
70 void SetText(const tstring& text);
71 const tstring& GetText();
72
73 // Data management
74 //
75 void SetData(UINT_PTR data);
76 UINT_PTR GetData();
77
78 // Comparison operators
79 //
80 bool operator ==(const TCheckListItem& d) const;
81 bool operator !=(const TCheckListItem& d) const;
82 bool operator < (const TCheckListItem& d) const;
83 bool operator > (const TCheckListItem& d) const;
84
85 private:
86 tstring Text;
87 uint State;
88 bool HasThreeStates;
89 bool Enabled;
90 UINT_PTR UserData;
91
92 friend class _OWLCLASS TCheckList;
93 friend int SortCheckList(const void *a, const void *b);
94};
95
97 : public TPtrArray<TCheckListItem*>
98{
99 public:
103};
104
107
108//
109/// \class TCheckList
110/// TCheckList is an owner-drawn list box to select multiple items. Derived from TListBox.
111//
113 : public TListBox
114{
115 public:
116
117 TCheckList(TWindow* parent, int id, int x, int y, int w, int h, TCheckListItem* = 0, int numItems = 0, TModule* = 0);
118 TCheckList(TWindow* parent, int id, int x, int y, int w, int h, TCheckListArray&, TModule* = 0);
119 TCheckList(TWindow* parent, int resourceId, TCheckListItem* = 0, int numItems = 0, TModule* = 0);
121 ~TCheckList() override;
122
123 public:
124
125 int AddItem(TCheckListItem* item);
126 int InsertItem(TCheckListItem* item, int idx);
127 TCheckListItem* DetachItem(int idx);
128 TCheckListItem* GetItem(int idx);
129
130 void ClearList() override;
131
132 /// Safe overload
133 //
135
136 protected:
137
138 // TWindow overrides
139 //
140 auto Transfer(void* buffer, TTransferDirection) -> uint override;
141 void SetupWindow() override;
142
143 // Owner draw messages
144 //
145 void ODAFocus(DRAWITEMSTRUCT&) override;
146 void ODASelect(DRAWITEMSTRUCT&) override;
147 void ODADrawEntire(DRAWITEMSTRUCT&) override;
148 void PaintItem(DRAWITEMSTRUCT&);
149 virtual void PaintText(TDC&, const TRect&, const tstring&);
150
151 // Event handlers
152 //
153 void EvLButtonDown(uint modKeys, const TPoint& point);
154 void EvChar(uint key, uint repeatCount, uint flags);
155 void Update();
156
157 private:
158 friend class TCheckListArray;
159 TCheckListArray Items;
160
162};
163
165{
166 public:
169
170 TCheckListItem* GetItem(int index);
171 TIntArray& GetSelIndices();
172
173 int AddString(const tstring& str, bool isSelected = false);
174 int AddStringItem(const tstring& str, UINT_PTR itemData, bool isSelected = false);
175 void Clear(bool del = true);
176
177 void Select(int index);
178 void SelectString(const tstring& str);
179 int GetSelCount() const;
180 void ResetSelections();
181
182 bool IsChecked(int index) const;
183 bool IsUnchecked(int index) const;
184 bool IsIndeterminate(int index) const;
185 bool IsEnabled(int index) const;
186 uint GetState(int index) const;
187 bool GetThreeStates(int index) const;
188
189 void Toggle(int index);
190 void Check(int index);
191 void Uncheck(int index);
192 void SetIndeterminate(int index);
193 void SetThreeStates(int index, bool enable = true);
194 void Enable(int index);
195 void Disable(int index);
196
197 int AddItem(TCheckListItem* item);
198 uint ItemCount();
199
202 TIntArray* SelIndices;
203};
204
205//
206/// \class TTabCheckList
207/// Represents an owner-drawn list box that can select multiple items with tabs.
208//
210 : public TCheckList
211{
212 public:
213
214 TTabCheckList(TWindow* parent, int id, int x, int y, int w, int h, TCheckListItem* items=0, int numItems=0, TModule* module = 0);
215 TTabCheckList(TWindow* parent, int id, int x, int y, int w, int h, TCheckListArray& items, TModule* module = 0);
216 TTabCheckList(TWindow* parent, int resourceId, TCheckListItem* items=0, int numItems=0, TModule* module = 0);
217 TTabCheckList(TWindow* parent, int resourceId, TCheckListArray& items, TModule* module = 0);
218
219 bool SetTabStops(int numTabs=0, int * tabs=0);
220
221 protected:
222 void SetupWindow();
223 virtual void PaintText(TDC& dc, const TRect& textRect, const tstring& text);
224 int GetAverageCharWidths();
225
226 protected:
228};
229
230/// @}
231
232#include <owl/posclass.h>
233
234//----------------------------------------------------------------------------
235// Inline Implementations
236//
237
238inline void
243
244//
245// TTabCheckList
246//
247
248//
249/// Creates a tabbed checklist.
250/// \note The constructor does not take ownership of the items. The lifetime and memory of the
251/// items must be handled by the caller, which must ensure the items outlive the checklist.
252//
253inline
254TTabCheckList::TTabCheckList(TWindow* parent, int id, int x, int y, int w, int h, TCheckListItem* items, int numItems, TModule* module)
255:
256 TCheckList(parent,id,x,y,w,h,items,numItems,module)
257{
259}
260
261//
262/// Creates a tabbed checklist.
263/// \note The constructor does not take ownership of the items. The lifetime and memory of the
264/// items must be handled by the caller, which must ensure the items outlive the checklist.
265//
266inline
267TTabCheckList::TTabCheckList(TWindow* parent, int id, int x, int y, int w, int h, TCheckListArray& items, TModule* module)
268:
269 TCheckList(parent,id,x,y,w,h,items,module)
270{
272}
273
274//
275/// Creates a tabbed checklist based on the given resource identifier.
276/// \note The constructor does not take ownership of the items. The lifetime and memory of the
277/// items must be handled by the caller, which must ensure the items outlive the checklist.
278//
279inline
281:
282 TCheckList(parent,resourceId,items,numItems,module)
283{
285}
286
287//
288/// Creates a tabbed checklist based on the given resource identifier.
289/// \note The constructor does not take ownership of the items. The lifetime and memory of the
290/// items must be handled by the caller, which must ensure the items outlive the checklist.
291//
292inline
294:
295 TCheckList(parent,resourceId,items,module)
296{
298}
299
300//
301/// Initializes the state of TCheckListItem.
302//
303inline
305:
306 State(BF_UNCHECKED),
307 HasThreeStates(false),
308 Enabled(true),
309 UserData(0)
310{
311}
312
313inline
315:
316 Text(item.Text),
317 State(item.State),
318 HasThreeStates(item.HasThreeStates),
319 Enabled(item.Enabled),
320 UserData(item.UserData)
321{
322}
323
324//
325/// Constructs the object with a text string and a starting state.
326//
327inline
329:
330 Text(text),
331 State(state),
332 HasThreeStates(ToBool(state == BF_GRAYED)),
333 Enabled(enabled),
334 UserData(0)
335{
336}
337
338inline bool
340{
341 return !(*this == d);
342}
343
344inline bool
346{
347 return Text < d.Text;
348}
349
350//
351/// Copies the text string.
352//
353inline void
355{
356 Text = text;
357}
358
359inline bool
361{
362 return Text > d.Text;
363}
364
365//
366/// Returns true if the item has been checked.
367//
368inline bool
370{
371 return ToBool(State == BF_CHECKED);
372}
373
374//
375/// Returns true if the item has been unchecked.
376//
377inline bool
379{
380 return ToBool(State == BF_UNCHECKED);
381}
382
383//
384/// Returns true if the item is in the indeterminate state.
385//
386inline bool
388{
389 return ToBool(State == BF_GRAYED);
390}
391
392//
393/// Returns the button state (BF_CHECKED, BF_UNCHECKED or BF_GRAYED).
394//
395inline uint
397{
398 return State;
399}
400
401//
402/// Returns true if the item has tree states.
403//
404inline bool
406{
407 return HasThreeStates;
408}
409
410//
411/// Returns true if the item is enabled.
412//
413inline bool
415{
416 return Enabled;
417}
418
419//
420/// Disables the item.
421//
422inline void
424{
425 Enabled = false;
426}
427
428//
429/// Enables the item.
430//
431inline void
433{
434 Enabled = true;
435}
436
437//
438/// Sets the user-defined data for this item.
439//
441{
442 UserData = data;
443}
444
445//
446/// Returns the user-defined data for this item.
447//
449{
450 return UserData;
451}
452
453//
454// Returns the item at the given index.
455//
457{
458 PRECONDITION(index < static_cast<int>(Items.size())); return Items[index];
459}
460
462{
463 return *SelIndices;
464}
465
466inline bool TCheckListData::IsChecked(int index) const
467{
468 PRECONDITION(index < static_cast<int>(Items.size()));
469 return Items[index]->IsChecked();
470}
471
472inline bool TCheckListData::IsUnchecked(int index) const
473{
474 PRECONDITION(index < static_cast<int>(Items.size()));
475 return Items[index]->IsUnchecked();
476}
477
478inline bool TCheckListData::IsIndeterminate(int index) const
479{
480 PRECONDITION(index < static_cast<int>(Items.size()));
481 return Items[index]->IsIndeterminate();
482}
483
484inline bool TCheckListData::IsEnabled(int index) const
485{
486 PRECONDITION(index < static_cast<int>(Items.size()));
487 return Items[index]->IsEnabled();
488}
489
490inline uint TCheckListData::GetState(int index) const
491{
492 PRECONDITION(index < static_cast<int>(Items.size()));
493 return Items[index]->GetState();
494}
495
496inline bool TCheckListData::GetThreeStates(int index) const
497{
498 PRECONDITION(index < static_cast<int>(Items.size()));
499 return Items[index]->GetThreeStates();
500}
501
502inline void TCheckListData::Toggle(int index)
503{
504 PRECONDITION(index < static_cast<int>(Items.size()));
505 Items[index]->Toggle();
506}
507
508inline void TCheckListData::Check(int index)
509{
510 PRECONDITION(index < static_cast<int>(Items.size()));
511 Items[index]->Check();
512}
513
514inline void TCheckListData::Uncheck(int index)
515{
516 PRECONDITION(index < static_cast<int>(Items.size()));
517 Items[index]->Uncheck();
518}
519
521{
522 PRECONDITION(index < static_cast<int>(Items.size()));
523 Items[index]->SetIndeterminate();
524}
525
526inline void TCheckListData::SetThreeStates(int index, bool enable)
527{
528 PRECONDITION(index < static_cast<int>(Items.size()));
529 Items[index]->SetThreeStates(enable);
530}
531
532inline void TCheckListData::Enable(int index)
533{
534 PRECONDITION(index < static_cast<int>(Items.size()));
535 Items[index]->Enable();
536}
537
538inline void TCheckListData::Disable(int index)
539{
540 PRECONDITION(index < static_cast<int>(Items.size()));
541 Items[index]->Disable();
542}
543
545{
546 return Items.Add(item);
547}
548
550{
551 return Items.size();
552}
553
554} // OWL namespace
555
556#endif // OWL_CHECKLIST_H
Definition of class TCheckBox.
#define PRECONDITION(condition)
Definition checks.h:227
TCheckListArray(int upper, int lower=0, int delta=0)
Definition checklst.h:100
uint GetState(int index) const
Definition checklst.h:490
bool IsChecked(int index) const
Definition checklst.h:466
void Check(int index)
Definition checklst.h:508
bool IsEnabled(int index) const
Definition checklst.h:484
int AddItem(TCheckListItem *item)
Definition checklst.h:544
void SetThreeStates(int index, bool enable=true)
Definition checklst.h:526
void Enable(int index)
Definition checklst.h:532
void SetIndeterminate(int index)
Definition checklst.h:520
bool IsIndeterminate(int index) const
Definition checklst.h:478
TCheckListItem * GetItem(int index)
Definition checklst.h:456
TIntArray & GetSelIndices()
Definition checklst.h:461
bool IsUnchecked(int index) const
Definition checklst.h:472
void Uncheck(int index)
Definition checklst.h:514
void Toggle(int index)
Definition checklst.h:502
void Disable(int index)
Definition checklst.h:538
bool GetThreeStates(int index) const
Definition checklst.h:496
TCheckList is an owner-drawn list box to select multiple items.
Definition checklst.h:114
virtual uint Transfer(TCheckListData &data, TTransferDirection direction)
Safe overload.
Definition checklst.h:134
virtual void PaintText(TDC &, const TRect &, const tstring &)
Definition checklst.h:239
Each item displayed and manipulated by TCheckList.
Definition checklst.h:43
bool IsEnabled() const
Returns true if the item is enabled.
Definition checklst.h:414
void Disable()
Disables the item.
Definition checklst.h:423
bool IsChecked() const
Returns true if the item has been checked.
Definition checklst.h:369
bool operator<(const TCheckListItem &d) const
Definition checklst.h:345
void Enable()
Enables the item.
Definition checklst.h:432
bool operator!=(const TCheckListItem &d) const
Definition checklst.h:339
TCheckListItem()
Initializes the state of TCheckListItem.
Definition checklst.h:304
bool IsUnchecked() const
Returns true if the item has been unchecked.
Definition checklst.h:378
bool operator>(const TCheckListItem &d) const
Definition checklst.h:360
void SetData(UINT_PTR data)
Sets the user-defined data for this item.
Definition checklst.h:440
uint GetState() const
Returns the button state (BF_CHECKED, BF_UNCHECKED or BF_GRAYED).
Definition checklst.h:396
UINT_PTR GetData()
Returns the user-defined data for this item.
Definition checklst.h:448
bool GetThreeStates() const
Returns true if the item has tree states.
Definition checklst.h:405
void SetText(const tstring &text)
Copies the text string.
Definition checklst.h:354
bool IsIndeterminate() const
Returns true if the item is in the indeterminate state.
Definition checklst.h:387
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
int DrawText(const tstring &str, int count, const TRect &, uint16 format=0)
Overload for const TRect& For obvious reasons, this overload does not support the DT_CALCRECT format ...
Definition dc.cpp:653
An interface object that represents a corresponding list box element.
Definition listbox.h:43
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
array of pointers of simple types
Definition template.h:830
Iterator for Pointer Container.
Definition template.h:543
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
Represents an owner-drawn list box that can select multiple items with tabs.
Definition checklst.h:211
TIntArray TabStops
Definition checklst.h:227
TTabCheckList(TWindow *parent, int id, int x, int y, int w, int h, TCheckListItem *items=0, int numItems=0, TModule *module=0)
Creates a tabbed checklist.
Definition checklst.h:254
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
bool ModifyStyle(uint32 offBits, uint32 onBits, uint swpFlags=0)
Modifies the style bits of the window.
Definition window.cpp:3591
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
TCheckListArray::Iterator TCheckListArrayIter
Definition checklst.h:105
TTransferDirection
The TTransferDirection enum describes the constants that the transfer function uses to determine how ...
Definition window.h:92
Definition of class TListBox and TlistBoxData.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
int SortCheckList(const void *a, const void *b)
Definition checklst.cpp:311
@ BF_UNCHECKED
Item is unchecked.
Definition checkbox.h:31
@ BF_GRAYED
Item is grayed.
Definition checkbox.h:30
@ BF_CHECKED
Item is checked.
Definition checkbox.h:29
bool ToBool(const T &t)
Definition defs.h:291
bool IsChecked(HWND ctrl)
Returns true if the given control has BST_CHECKED state.
Definition transfer.h:69
const int CheckList_BoxWidth
Definition checklst.h:33
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
bool IsIndeterminate(HWND ctrl)
Returns true if the given control has BST_INDETERMINATE state.
Definition transfer.h:81
bool IsUnchecked(HWND ctrl)
Returns true if the given control has BST_UNCHECKED state.
Definition transfer.h:75
#define protected_data
Definition defs.h:208
#define _OWLCLASS
Definition defs.h:338
Definition of container classes used and made available by OWL.