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
picker.h
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// ObjectWindows, Copyright (c) 1998 by Yura Bidus.
3//
4// Used ideas from Chris Maunder, Alexander Bischofberger, Dieter Windau,
5// Joseph Parrello,
6//
7// THIS CLASS AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
8// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
9// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
10// PARTICULAR PURPOSE.
11/// \file
12/// Definition of classes TPickerCell, TColorCell, TBitmapCell, TTextCell,
13/// TGridPicker, TPopupPicker, TColorPicker, TPickerGadget,
14/// TColorPickerGadget and TBitmapPickerGadget
15//------------------------------------------------------------------------------
16
17#if !defined(OWL_PICKER_H) // Sentry, use file only if it's not already included.
18#define OWL_PICKER_H
19
20#include <owl/private/defs.h>
21#if defined(BI_HAS_PRAGMA_ONCE)
22# pragma once
23#endif
24
25
26// Macro defining class name (usable in resource definition)
27//
28#if !defined(OWL_PICKER)
29#if defined(UNICODE)
30# define OWL_PICKER L"OWL_Picker"
31#else
32# define OWL_PICKER "OWL_Picker"
33#endif
34#endif
35
36#if !defined(RC_INVOKED)
37
38#include <owl/bitset.h>
39#include <owl/buttonga.h>
40#include <owl/popupgad.h>
41
42
43namespace owl {
44
45
46//
47#include <owl/preclass.h>
48
49class _OWLCLASS TGridPicker;
50class _OWLCLASS TCelArray;
51class _OWLCLASS TTooltip;
52
53/// \addtogroup newctrl
54/// @{
55/// \class TPickerCell
56// ~~~~~ ~~~~~~~~~~~
57/// bsabstract base class
58//
59class _OWLCLASS TPickerCell: public TBitFlags<uint> {
60 public:
61//FMM
63 /// Cell border styles. These match TIUBorder's TStyles exactly
64 //
66 None, ///< No border painted at all
67 Plain, ///< Plain plain window frame
68 Raised, ///< Status field style raised
69 Recessed, ///< Status field style recessed
70 Embossed, ///< Grouping raised emboss bead
71 Grooved, ///< Grouping groove
72 ButtonUp, ///< Button in up position
73 ButtonDn, ///< Button in down position
74 WndRaised, ///< Raised window outer+inner edge
75 WndRecessed, ///< Input field & other window recessed
76 WellSet, ///< Well option set (auto grows + 1)
77 Flat, ///< Use flat style
78 };
79
80 TPickerCell(int id=0,TBorderStyle borderStyle = Flat);
81 virtual ~TPickerCell();
82
83 virtual void Paint(TDC& dc, TRect* r=0, bool drawbrd = true);
84 virtual void PaintCell(TDC& dc, TRect& rect) = 0; // abstract function
85 virtual void PaintBorder(TDC& dc, TRect& rect);
86
87 virtual void EnterMouse();
88 virtual void LeaveMouse();
89 virtual void Select(bool sel=true);
90
91 // get/set
92 int GetId();
93 void SetId(int id);
94 TRect& GetBounds();
95
96 void SetBorderStyle(TBorderStyle bs);
97 TBorderStyle GetBorderStyle() const;
98
99 // query desired bounds
100 virtual void QueryBounds(TRect& rect);
101 virtual bool PtIn(const TPoint& pt);
102
103 protected:
105 csMouseIn = 0x0001,
106 csSelected = 0x0002,
107 };
108
109 virtual void SetParent(TGridPicker* parent);
110
111 protected:
113 int Id;
115 TBorderStyle BorderStyle; // Style of border to use
116
117 friend class _OWLCLASS TGridPicker;
118};
119
120//
121/// \class TColorCell
122// ~~~~~ ~~~~~~~~~~
123//
125 public:
126 TColorCell(int id=0, const TColor& clr=TColor::None,TBorderStyle borderStyle = Flat);
127
128 virtual void PaintCell(TDC& dc, TRect& rect);
129 void SetColor(const TColor& clr);
130 const TColor& GetColor() const;
131
132 protected:
134};
135
136//
137/// \class TBitmapCell
138// ~~~~~ ~~~~~~~~~~~
139//
141 public:
142 TBitmapCell(int id=0, TCelArray* array=0, int index=0,TBorderStyle borderStyle = Flat);
143 virtual ~TBitmapCell();
144
145 virtual void PaintCell(TDC& dc, TRect& rect);
146 virtual void QueryBounds(TRect& rect);
147 void SetIndex(int index);
148 int GetIndex();
149 void SetCelArray(TCelArray* array, TAutoDelete=NoAutoDelete);
150 TCelArray* GetCelArray();
151
152 protected:
154 int Index;
156};
157
158
159//
160/// \class TTextCell
161// ~~~~~ ~~~~~~~~~
162//
164 public:
165 TTextCell(int id=0, const tstring& text = tstring(), TBorderStyle borderStyle = Flat);
166
167 virtual void PaintCell(TDC& dc, TRect& rect);
168 void SetText(const tstring& text);
169 const tstring& GetText() const;
170 void SetFormat(uint format);
171 uint GetFormat() const;
172
173 protected:
176};
177
178
179class TPickerCellArray;
180// TIPtrArray<TPickerCell*> Cells;
181
182//
183/// \class TGridPicker
184// ~~~~~ ~~~~~~~~~~~~
185//
186class _OWLCLASS TGridPicker : public TControl, public TBitFlags<uint> {
187 public:
188 enum TPickerStyles{ // Have to be exactly as TCellState
189 psTrackMouse = 0x0001,
190 psShrinkToCells = 0x0002,
191 psFlatSyle = 0x0004,
192 psMessageTips = 0x0008,
193 psLocalTips = 0x0010,
194 };
195
196 TGridPicker(TWindow* parent,
197 int id,
198 int x, int y, int w=0, int h=0,
199 TModule* module = 0);
200 TGridPicker(TWindow* parent,
201 int resourceId,
202 TModule* module = 0);
203 ~TGridPicker() override;
204
205 void SetSelection(int sel = 0);
206 int GetSelection();
207 TPickerCell* GetSelectedCell();
208 int GetFocus();
209 TPickerCell* GetFocusedCell(); // return focused cell
210 TPickerCell* GetDefaultCell(); // return child of default cell
211 TPickerCell* GetCustomCell(); // return child of default custom cell
212
213 void SetColumns(int colmn = 4);
214 int GetColumns();
215
216 void SetFont(const TFont& font);
217 TFont* GetFont();
218
219 void SetTarget(TWindow* wnd);
220 TWindow* GetTarget();
221
222 void AddCell(TPickerCell* cells, bool select = false);
223 TPickerCell* RemoveCell(int loc);
224
225 // styles
226 void ModifyPopStyle(uint off, uint on);
227 uint GetPopStyle();
228 virtual bool IsFlatStyle();
229 void EnableDefault(LPCTSTR text=0, int resId = 0, TPickerCell* cl=0); // =0 disables it
230
231 void EnableDefault(const tstring& text, int resId = 0, TPickerCell* cl = 0)
232 {EnableDefault(text.c_str(), resId, cl);}
233
234 void EnableButton(LPCTSTR text=0, int resId = 0, TPickerCell* cl=0); // =0 disables it
235
236 void EnableButton(const tstring& text, int resId = 0, TPickerCell* cl = 0)
237 {EnableButton(text.c_str(), resId, cl);}
238
239 // Retrieves/assigns tooltip of/to window
240 //
241 auto GetTooltip() const -> TTooltip* override;
242 void EnableTooltip(bool enable = true) override;
243 void SetTooltip(TTooltip* tooltip);
244
245 // Changes the margins and initiates a layout session
246 void SetMargins(const TMargins& margins);
247 // relayout cells - called internally
248 virtual void Layout();
249
250 protected:
251 enum TCellState{ // publip the same as TPickerStyles
252 ppTrackMouse = 0x0001,
253 ppShrCells = 0x0002,
254 ppFlatStyle = 0x0004,
255 ppMessageTips = 0x0008,
256 ppShowTipsCell= 0x0010,
257
258 // internal usage
259 ppFocus = 0x0040,
260 ppPushed = 0x0080,
261 ppShowDefItem = 0x0100,
262 ppShowCustItem= 0x0200,
263 ppButtonSel = 0x0400,
264 ppCustomOpen = 0x0800,
265 ppSelected = 0x1000,
266 };
267
268 // inherited virtuals
269 auto GetWindowClassName() -> TWindowClassName override;
270 void GetWindowClass(WNDCLASS&) override;
271 void Paint(TDC&, bool erase, TRect&) override;
272 void SetupWindow() override;
273 auto PreProcessMsg(MSG&) -> bool override;
274
275 protected: // event handlers
276 //JJH - removed, no definition provided
277 #if !defined(STRIP_UNDEFINED)
278 uint EvGetDlgCode(const MSG* msg) { return TControl::EvGetDlgCode(msg); }
279 void EvActivateApp(bool active, DWORD threadId) { TControl::EvActivateApp(active, threadId); }
280 #endif
281 void EvSetFocus(THandle hWndLostFocus);
282 void EvKillFocus(THandle hWndGetFocus);
283 void EvLButtonDown(uint modKeys, const TPoint& point);
284 void EvLButtonDblClk(uint modKeys, const TPoint& point);
285 void EvLButtonUp(uint modKeys, const TPoint& point);
286 void EvMouseMove(uint modKeys, const TPoint& point);
287 void EvKeyDown(uint key, uint repeatCount, uint flags);
288 void EvKeyUp(uint key, uint repeatCount, uint flags);
289 void EvCancelMode();
290
291 // New Virtuals
292 /// set bounds for cell
293 virtual void SetBounds(TPickerCell& cell, const TRect& rect);
294 /// load tiptext from resource
295 virtual tstring LoadTipText(int resId);
296 /// send WM_MENUSELECT and WM_ENTERIDLE to frame window
297 virtual void SetStatusBarMessage(int id);
298 /// paint divider
299 virtual void PaintDivider(TDC& dc, const TRect& rect);
300 /// call user defined custom box if pressed custom button
301 virtual bool CallCustomBox();
302 /// notify parent on event -> BN_CLICKED and BN_HILITE
303 virtual void NotifyParent(uint code);
304 /// do noting here
305 virtual void ExitPicker(bool status = false);
306
307 // Internal Utility functions
308 void InitPicker();
309 void ClearCapture();
310 int Contains(const TPoint& point);
311 void GetCellRect(TRect& rect);
312 void ClearCell();
313 void RefocusCell(int loc);
314 void ApplyChanges();
315
316 // for derived classes
317 int Add(TPickerCell* cell);
318 TPickerCell* Remove(int loc);
319 TPickerCell* GetCell(int loc);
320 uint Size();
321
322 protected:
323 // TIPtrArray<TPickerCell*> Cells;
324 TPickerCellArray* Cells;
327 int NRows;
334
336};
337
338//
339/// \class TPopupPicker
340// ~~~~~ ~~~~~~~~~~~~
341//
343 public:
344 TPopupPicker(TWindow* parent,
345 int id,
346 int x, int y, int w=0, int h=0,
347 TModule* module = 0);
348 TPopupPicker(TWindow* parent,
349 int resourceId,
350 TModule* module = 0);
351
352 virtual bool ShowPicker(TPoint& p, TRect& rect);
353 void Paint(TDC&, bool erase, TRect&) override;
354
355 protected:
356 void EvActivateApp(bool active, DWORD taskId);
357 void EvKillFocus(THandle hWndGetFocus );
358 void EvLButtonDown(uint modKeys, const TPoint& point);
359 void GetWindowClass(WNDCLASS&) override;
360 void ExitPicker(bool status = false) override;
361
363};
364
365//
366// class TColorPicker
367// ~~~~~ ~~~~~~~~~~~~
368//
370 public:
371 TColorPicker(TWindow* parent,
372 int id,
373 int x, int y, int w=0, int h=0,
374 TModule* module = 0);
375 TColorPicker(TWindow* parent,
376 int resourceId,
377 TModule* module = 0);
379
380 // Virtual functions overriding
381 void Paint(TDC&, bool erase, TRect&) override;
382 void SetupWindow() override;
383 void NotifyParent(uint code) override;
384
385 void SetCustomColors(TColor* colors);
386 const TColor& GetCustomColor() const;
387
388 // Event handlers
389 protected:
390 void EvPaletteChanged(HWND hWndPalChg);
391 bool EvQueryNewPalette();
392
393 auto CallCustomBox() -> bool override;
394
396 TColor CustomColor;
397 TPalette* Palette;
398 TColor* CustomColors;
399 TPalette* WorkPalette;
400 bool PaletteRealized;
401
403};
404
405//
406// class TPickerGadget
407// ~~~~~ ~~~~~~~~~~~~~
408//
410 public:
413 TStyle style = sBitmapText,
414 TPopupType poptype = DownArrowAction,
415 TType type = Command,
416 bool enabled = false,
417 TState state = Up,
418 bool sharedGlyph = false,
419 uint numChars = 4);
420 virtual ~TPickerGadget();
421
422 virtual void PopupAction();
423 TGridPicker* GetPicker();
424 TPickerCell* GetSelCel();
425
426 protected:
427 virtual void Created();
428 virtual void Inserted();
429
430 // call on exit from Picker if not canceled
431 virtual void GetSelection();
432
433 protected:
435 TPickerCell* Selected; ///< currect selected cell
436};
437
438
439//
440// class TColorPickerGadget
441// ~~~~~ ~~~~~~~~~~~~~~~~~~
442//
444 public:
447 TStyle style = sBitmapText,
448 TPopupType poptype = DownArrowAction,
449 TType type = Command,
450 bool enabled = false,
451 TState state = Up,
452 bool sharedGlyph = false,
453 uint numChars = 4);
454 protected:
455 virtual void GetSelection();
456
457 virtual void PaintFace(TDC& dc, const TRect& rect);
458
459 // helper function
460 virtual void GetFillRect(TRect& rect, const TRect& faceRect);
461
462 protected:
463 TColor ColorSel; ///< currect selected color
464};
465
466//
467/// \class TBitmapPickerGadget
468// ~~~~~ ~~~~~~~~~~~~~~~~~~~
469//
471 public:
474 TStyle style = sBitmapText,
475 TPopupType poptype = DownArrowAction,
476 TType type = Command,
477 bool enabled = false,
478 TState state = Up,
479 bool sharedGlyph = false,
480 uint numChars = 4);
481
482 protected:
483 // override virtuals
484 virtual void BuildCelArray();
485 virtual void GetSelection();
486
487 // utility to copy bitmap into CellArray
488 void CopyCellBitmap();
489};
490
491/// @}
492
493#include <owl/posclass.h>
494
495//
496// Inlines
497//
498
499//
500// class TPickerCell
501// ~~~~~ ~~~~~~~~~~~
502//
503inline
505:
506 Id(id), Parent(nullptr)
507{
509}
510
511//
512inline
516
517//
518inline int
520{
521 return Id;
522}
523
524//
525inline void
527{
528 Id = id;
529}
530
531//
532inline TRect&
534{
535 return Bounds;
536}
537
538//
539inline bool
541{
542 return Bounds.Contains(pt);
543}
544
545//
546inline void
548{
549 Parent=parent;
550}
551
552//
553/// Return the borderstyle the cell is using
554//
557{
558 return BorderStyle;
559}
560
561//
562// class TColorCell
563// ~~~~~ ~~~~~~~~~~
564//
565inline
571
572//
573inline void
575{
576 Color = clr;
577}
578
579//
580inline const TColor&
582{
583 return Color;
584}
585
586//
587// class TBitmapCell
588// ~~~~~ ~~~~~~~~~~~
589//
590inline void
592{
593 Index = index;
594}
595
596//
597inline int
599{
600 return Index;
601}
602
603//
604inline TCelArray*
606{
607 return CelArray;
608}
609
610//
611// class TTextCell
612// ~~~~~ ~~~~~~~~~
613//
614inline
622
623//
624inline void
626{
627 Text = text;
628}
629
630//
631inline const tstring&
633{
634 return Text;
635}
636
637//
638inline void
643
644//
645inline uint
647{
648 return Format;
649}
650
651//
652// class TGridPicker
653// ~~~~~ ~~~~~~~~~~~~
654//
655inline int
657{
658 return Selected-3;
659}
660
661//
662inline TTooltip*
664{
665 return Tooltip;
666}
667
668//
669inline TPickerCell*
674
675//
676inline int
678{
679 return Focused-3;
680}
681
682//
683inline TPickerCell*
688
689//
690inline int
692{
693 return NColumns;
694}
695
696//
697inline TFont*
699{
700 return Font;
701}
702
703//
704inline uint
709
710//
711inline bool
716
717//
718inline void
720{
721 cell.Bounds = rect;
722}
723
724inline void
729
730inline TWindow*
732{
733 return Target;
734}
735
736//
737// class TColorPicker
738// ~~~~~ ~~~~~~~~~~~~
739
740//
741inline const TColor&
743{
744 return CustomColor;
745}
746
747//
748// class TPickerGadget
749// ~~~~~ ~~~~~~~~~~~~~
750//
751inline TGridPicker*
753{
754 return Picker;
755}
756//
757inline TPickerCell*
759{
760 return Selected;
761}
762
763//==============================================================================
764
765} // OWL namespace
766
767#endif // RC_INVOKED
768
769#endif // OWL_PICKER_H
770
Definition of a bit set and a character set.
Definition of class TButtonGadget.
For example:
Definition bitset.h:143
bool IsSet(uint t) const
Return true of the ON bits of the parameter are currently enabled.
Definition bitset.h:198
TCelArray * CelArray
Definition picker.h:153
TCelArray * GetCelArray()
Definition picker.h:605
void SetIndex(int index)
Definition picker.h:591
bool ShouldDelete
Definition picker.h:155
TState
TState enumerates the three button positions during which the button can be pressed: up (0),...
Definition buttonga.h:80
TType
Enumerates the types of button gadgets.
Definition buttonga.h:69
TStyle
TStyle contains values that defines how gadget will be displayed:
Definition btntextg.h:62
TCelArray is a horizontal array of cels (a unit of animation) created by slicing a portion of or an e...
Definition celarray.h:35
TColorCell(int id=0, const TColor &clr=TColor::None, TBorderStyle borderStyle=Flat)
Definition picker.h:566
const TColor & GetColor() const
Definition picker.h:581
void SetColor(const TColor &clr)
Definition picker.h:574
TColor Color
Definition picker.h:133
Class wrapper for management of color values.
Definition color.h:245
TColor ColorSel
currect selected color
Definition picker.h:463
const TColor & GetCustomColor() const
Definition picker.h:742
TControl unifies its derived control classes, such as TScrollBar, TControlGadget, and TButton.
Definition control.h:38
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
TFont derived from TGdiObject provides constructors for creating font objects from explicit informati...
Definition gdiobjec.h:296
TPickerCellArray * Cells
Definition picker.h:324
TTooltip * Tooltip
Definition picker.h:333
TWindow * GetTarget()
Definition picker.h:731
void EvActivateApp(bool active, DWORD threadId)
Definition picker.h:279
virtual void SetBounds(TPickerCell &cell, const TRect &rect)
set bounds for cell
Definition picker.h:719
uint GetPopStyle()
Definition picker.h:705
TPickerCell * GetFocusedCell()
Definition picker.h:684
TFont * GetFont()
Definition picker.h:698
DECLARE_RESPONSE_TABLE(TGridPicker)
TFont * Font
Definition picker.h:331
void EnableButton(const tstring &text, int resId=0, TPickerCell *cl=0)
Definition picker.h:236
uint EvGetDlgCode(const MSG *msg)
Definition picker.h:278
TPickerCell * GetCell(int loc)
Definition picker.cpp:605
TMargins Margins
Definition picker.h:330
int GetSelection()
Definition picker.h:656
void SetTarget(TWindow *wnd)
Definition picker.h:725
TWindow * Target
Definition picker.h:332
void EnableDefault(const tstring &text, int resId=0, TPickerCell *cl=0)
Definition picker.h:231
virtual bool IsFlatStyle()
Definition picker.h:712
auto GetTooltip() const -> TTooltip *override
Definition picker.h:663
TPickerCell * GetSelectedCell()
Definition picker.h:670
int GetColumns()
Definition picker.h:691
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TPalette is the GDI Palette class derived from TGdiObject.
Definition gdiobjec.h:413
bsabstract base class
Definition picker.h:59
void SetBorderStyle(TBorderStyle bs)
Definition picker.cpp:89
TRect & GetBounds()
Definition picker.h:533
virtual void SetParent(TGridPicker *parent)
Definition picker.h:547
TBorderStyle
Cell border styles. These match TIUBorder's TStyles exactly.
Definition picker.h:65
@ Recessed
Status field style recessed.
Definition picker.h:69
@ Raised
Status field style raised.
Definition picker.h:68
@ WellSet
Well option set (auto grows + 1)
Definition picker.h:76
@ WndRaised
Raised window outer+inner edge.
Definition picker.h:74
@ Embossed
Grouping raised emboss bead.
Definition picker.h:70
@ None
No border painted at all.
Definition picker.h:66
@ ButtonDn
Button in down position.
Definition picker.h:73
@ Plain
Plain plain window frame.
Definition picker.h:67
@ Flat
Use flat style.
Definition picker.h:77
@ WndRecessed
Input field & other window recessed.
Definition picker.h:75
@ Grooved
Grouping groove.
Definition picker.h:71
@ ButtonUp
Button in up position.
Definition picker.h:72
TBorderStyle GetBorderStyle() const
Return the borderstyle the cell is using.
Definition picker.h:556
virtual bool PtIn(const TPoint &pt)
Definition picker.h:540
void SetId(int id)
Definition picker.h:526
virtual void PaintCell(TDC &dc, TRect &rect)=0
TPickerCell(int id=0, TBorderStyle borderStyle=Flat)
Definition picker.h:504
virtual ~TPickerCell()
Definition picker.h:513
TGridPicker * Parent
Definition picker.h:114
TBorderStyle BorderStyle
Definition picker.h:115
TPopupPicker * Picker
Definition picker.h:434
TPickerCell * Selected
currect selected cell
Definition picker.h:435
TGridPicker * GetPicker()
Definition picker.h:752
TPickerCell * GetSelCel()
Definition picker.h:758
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
DECLARE_RESPONSE_TABLE(TPopupPicker)
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
bool Contains(const TPoint &point) const
Returns true if the given point lies within this rectangle; otherwise, it returns false.
Definition geometry.h:1200
TTextCell(int id=0, const tstring &text=tstring(), TBorderStyle borderStyle=Flat)
Definition picker.h:615
void SetFormat(uint format)
Definition picker.h:639
void SetText(const tstring &text)
Definition picker.h:625
uint GetFormat() const
Definition picker.h:646
const tstring & GetText() const
Definition picker.h:632
tstring Text
Definition picker.h:174
TTooltip encapsulates a tooltip window - i.e.
Definition tooltip.h:175
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
HWND THandle
TWindow encapsulates an HWND.
Definition window.h:418
#define DECLARE_RESPONSE_TABLE(cls)
Definition eventhan.h:436
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
@ NoAutoDelete
Definition gdibase.h:70
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
#define protected_data
Definition defs.h:208
#define _OWLCLASS
Definition defs.h:338
Definition of classes TPopupButtonGadget and TPopupMenuGadget.
Used by the TGadgetWindow and TGadget classes, TMargins contains the measurements of the margins for ...
Definition gadget.h:54