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
drawitem.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/// Definitions of classes TDrawItemProxy, TDrawItem,TButtonTextDrawItem,
7/// TDrawMenuItem, TDrawMenuItemProxy. Owner draw family.
8//
9// Note this classes stil under development!!!!!!!!!!!!!!!
10//
11//----------------------------------------------------------------------------
12
13#if !defined(OWL_DRAWITEM_H) // Sentry, use file only if it's not already included.
14#define OWL_DRAWITEM_H
15
16#include <owl/private/defs.h>
17#if defined(BI_HAS_PRAGMA_ONCE)
18# pragma once
19#endif
20
21#include <owl/dc.h>
22#include <owl/gdiobjec.h>
23#include <owl/celarray.h>
24#include <owl/wsyscls.h>
25
26namespace owl {
27
28#include <owl/preclass.h>
29
30/// \addtogroup newctrl
31/// @{
32
33
34
35//
36/// \class TDrawItemProxy
37// ~~~~~ ~~~~~~~~~~~~~~
38/// Proxy parent for TDrawItem.
39//
41 public:
43 public:
45 virtual ~TDrawItemProxy();
46
47 void SetFont(TFont* font);
48 virtual TFont* GetFont() { return Font; }
49 void SetCelArray(TCelArray* celarray, TAutoDelete del=AutoDelete);
50 void SetCelArray(TResId resId, uint count, TModule* module = &GetGlobalModule());
51 virtual TCelArray* GetCelArray() { return CelArray; }
52 void RegisterItem(TDrawItem* item); ///< For automatic deletion of items
53 TDrawItemArray& GetItems();
54
55 // Data members -- will become private
56 //
58 TFont* Font;
59 TCelArray* CelArray;
60 bool DeleteCel; ///< true if CelArray should be deleted.
61 TDrawItemArray* ItemArray;
62};
63
64//
65//
66/// \class TButtonTextDrawItem
67// ~~~~~ ~~~~~~~~~~~~~~~~~~~
68//
69//
71 public:
72 /// TAlign contains values that defines how text will be layed out.
73 enum TAlign
74 {
75 aLeft, ///< Aligns the text at the left edge of the bounding rectangle.
76 aCenter, ///< Aligns the text horizontally at the center of the bounding rectangle.
77 aRight ///< Aligns the text at the right edge of the bounding rectangle.
78 };
79
80 /// TStyle contains values that defines how the button will be displayed
81 enum TStyle
82 {
83 sNone=0, ///< Neither text or bitmap is displayed.
84 sBitmap=0x001, ///< Only the bitmap is displayed.
85 sText=0x002, ///< Only text is displayed.
86 sBitmapText=0x003 ///< Both text and bitmap are displayed.
87 };
88
89 /// TLayoutStyle contains values that defines how a bitmap and text will be layed out.
91 {
92 lTextLeft, ///< Text left, bitmap right.
93 lTextTop, ///< Text top, bitmap bottom.
94 lTextRight, ///< Text right, bitmap left.
95 lTextBottom ///< Text bottom, bitmap top.
96 };
97
98 enum TSeparator {sepNoBitmap=-2,sepUseBitmap=-1};
99
100
103
104 // get/set
105 LPCTSTR GetText() const;
106 void SetText(LPCTSTR text);
107 void SetText(const tstring& text) {SetText(text.c_str());}
108 int GetIndex() const;
109 void SetIndex(int index);
110 TStyle GetStyle() const;
111 void SetStyle(const TStyle style);
112 TAlign GetAlign() const;
113 void SetAlign(const TAlign align);
114 TLayoutStyle GetLayoutStyle() const;
115 void SetLayoutStyle(const TLayoutStyle style);
116
117 // usually it uses Proxy CelArray and Font
118 void SetFont(TFont* font);
119 virtual TFont* GetFont() { return Font; }
120 void SetCelArray(TCelArray* celarray, TAutoDelete del=AutoDelete);
121 void SetCelArray(TResId resId, uint count, TModule* module = &GetGlobalModule());
122 virtual TCelArray* GetCelArray() { return CelArray; }
123
124 // overriden virtuals
125 virtual void Draw(DRAWITEMSTRUCT & drawItem);
126 virtual void Measure(MEASUREITEMSTRUCT & drawItem);
127 virtual int Compare(COMPAREITEMSTRUCT & drawItem);
128
129 // new virtuals
130 virtual void Paint(TDC& rc, TRect& rect);
131 virtual void Layout(const TRect& src, TRect& textRect, TRect& bmpRect);
132 virtual void PaintBorder(TDC& rc, TRect& rect);
133 virtual void PaintText(TDC& rc, TRect& rect);
134 virtual void PaintBitmap(TDC& rc, TRect& rect);
135 virtual TColor GetBkColor();
136 virtual TColor GetTextColor();
137
138/// Returns true if (Flags & ODS_DISABLED)==0; false otherwise.
139 bool IsEnabled() { return (Flags&ODS_DISABLED)==0; }
140
141/// Returns true if (Flags & ODS_SELECTED)==0; false otherwise.
142 bool IsSelected() { return (Flags&ODS_SELECTED)!=0; }
143
144/// Returns true if (Flags & ODS_FOCUS)==0; false otherwise.
145 bool IsFocused() { return (Flags&ODS_FOCUS)!=0; }
146
147/// Returns true if (Flags & ODS_GRAYED)==0; false otherwise.
148 bool IsGrayed() { return (Flags&ODS_GRAYED)!=0; }
149
150/// Returns true if (Flags & ODS_CHECKED)==0; false otherwise.
151 bool IsChecked() { return (Flags&ODS_CHECKED)!=0; }
152
153 // helpers
154 virtual void GetTextSize(TSize& size);
155 virtual void GetButtonSize(TSize& btnSize);
156
157 // Data members -- will become private
158 //
160 LPTSTR Text; ///< new'd copy of the text for this gadget
161 int Index; ///< Index of Bitmap in Proxy CellArray if >= 0
162 TAlign Align; ///< Alignment: left, center or right
163 TStyle Style; ///< Style Bitmap, Text, Bitmap and Text
164 TLayoutStyle LayoutStyle;///< Layout style
165
166 //
167 uint Flags;
168
169 //
170 TFont* Font; ///< Local if overriding ?? I need this?
171 TCelArray* CelArray; ///< Local if overriding ?? I need this?
172 bool DeleteCel; ///< Local
173 TDrawItemProxy* Proxy; ///< Proxy
174};
175
176
177//
178//
179// class TDrawMenuItem
180// ~~~~~ ~~~~~~~~~~~~~
181/// Derived from TButtonTextDrawItem, the TDrawMenuItem class is used for owner
182/// drawn menus.
183//
185 public:
186/// Prototype for a function used to paint the check image of a menu item.
187 typedef void (TDrawMenuItem::*TCheckPainter)(TDC& dc, TRect& rect);
188
189 public:
191 TDrawMenuItem(TDrawItemProxy* proxy, int cmdId, int index, const tstring& title);
192//FMM DECLARE_CASTABLE line inserted
194 virtual void PaintBitmap(TDC& dc, TRect& rect);
195 virtual void PaintText(TDC& rc, TRect& rect);
196 virtual void GetTextSize(TSize& size);
197 virtual void GetButtonSize(TSize& btnSize);
198 virtual TColor GetBkColor();
199 virtual TColor GetTextColor();
200 virtual void PaintCheckFace(TDC& dc, TRect& rect);
201
202 int GetCmdId();
203 void SetCheckPainter(TCheckPainter painter);
204
205 void PaintCheck_None(TDC& dc, TRect& rect);
206 void PaintCheck_3Angle(TDC& dc, TRect& rect);
207 void PaintCheck_Arrow(TDC& dc, TRect& rect);
208 void PaintCheck_Box(TDC& dc, TRect& rect);
209 void PaintCheck_Diamond(TDC& dc, TRect& rect);
210 void PaintCheck_Dot(TDC& dc, TRect& rect);
211 void PaintCheck_Plus(TDC& dc, TRect& rect);
212 void PaintCheck_V(TDC& dc, TRect& rect);
213 void PaintCheck_X(TDC& dc, TRect& rect);
214
215 // Data members -- will become private
216 //
218 int CmdId;
219 TCheckPainter CheckPainter;
220};
221
222//
223//
224/// \class TDrawMenuItemProxy
225// ~~~~~ ~~~~~~~~~~~~~~~~~~
226/// Derived from TDrawItemProxy, TDrawMenuItemProxy is a proxy parent for
227/// TDrawMenuItem.
228//
230 public:
231 /// Container of TDrawItem's.
233
234 public:
236 virtual ~TDrawMenuItemProxy();
237
238 TDrawItem* FindItem(uint cmdId);
239 void RemapMenu(HMENU hMenu);
240 bool EvMenuChar(uint uChar, uint, HMENU hMenu, TParam2& param);
241
242 protected:
243 int GetIndex(int cmdId);
244 virtual TDrawItem* CreateItem(uint itemId, const tstring& text);
245 static TFont* CreateProxyMenuFont();
246
247 protected:
248/// Array of id's.
250
251 private:
252/// Level of recursion when remapping menu.
253 int iRecurse;
254};
255
256/// @}
257
258#include <owl/posclass.h>
259
260//-------------------------------------------------------------------------
261//
262// Inlines
263//
264//
265
266//
267/// Returns ItemArray.
268//
270{
271 return *ItemArray;
272}
273//
274/// Returns Text, the text do display on the button.
275//
277{
278 return Text;
279}
280//
281/// Returns Index, the index of Bitmap in the Proxy CellArray or -1.
282//
284{
285 return Index;
286}
287//
288/// Returns Style: Bitmap only, Text only, or Bitmap and Text.
289//
291{
292 return Style;
293}
294//
295/// Sets Style to style.
296//
297inline void TButtonTextDrawItem::SetStyle(const TStyle style)
298{
299 Style = style;
300}
301//
302/// Returns Align.
303//
305{
306 return Align;
307}
308//
309/// Sets Align to align.
310//
312{
313 Align = align;
314}
315//
316/// Returns LayoutStyle.
317//
319{
320 return LayoutStyle;
321}
322//
323/// Sets LayoutStyle to style.
324//
326{
327 LayoutStyle = style;
328}
329//
330/// Set the routine to be used to paint the check mark.
331//
332inline void TDrawMenuItem::SetCheckPainter(TCheckPainter painter)
333{
334 CheckPainter = painter;
335 Index = CheckPainter ? -3 : -1;
336}
337//
338/// Returns CmdId.
339//
341{
342 return CmdId;
343}
344//
345
346} // OWL namespace
347
348#endif // OWL_DRAWITEM_H sentry.
Definition of a bitmap Cel array class.
bool IsSelected()
Returns true if (Flags & ODS_SELECTED)==0; false otherwise.
Definition drawitem.h:142
TLayoutStyle
TLayoutStyle contains values that defines how a bitmap and text will be layed out.
Definition drawitem.h:91
@ lTextTop
Text top, bitmap bottom.
Definition drawitem.h:93
@ lTextRight
Text right, bitmap left.
Definition drawitem.h:94
@ lTextLeft
Text left, bitmap right.
Definition drawitem.h:92
virtual TFont * GetFont()
Definition drawitem.h:119
TStyle GetStyle() const
Returns Style: Bitmap only, Text only, or Bitmap and Text.
Definition drawitem.h:290
TAlign GetAlign() const
Returns Align.
Definition drawitem.h:304
bool IsChecked()
Returns true if (Flags & ODS_CHECKED)==0; false otherwise.
Definition drawitem.h:151
void SetText(const tstring &text)
Definition drawitem.h:107
void SetStyle(const TStyle style)
Sets Style to style.
Definition drawitem.h:297
virtual TCelArray * GetCelArray()
Definition drawitem.h:122
bool IsGrayed()
Returns true if (Flags & ODS_GRAYED)==0; false otherwise.
Definition drawitem.h:148
bool IsFocused()
Returns true if (Flags & ODS_FOCUS)==0; false otherwise.
Definition drawitem.h:145
TLayoutStyle GetLayoutStyle() const
Returns LayoutStyle.
Definition drawitem.h:318
void SetLayoutStyle(const TLayoutStyle style)
Sets LayoutStyle to style.
Definition drawitem.h:325
TAlign
TAlign contains values that defines how text will be layed out.
Definition drawitem.h:74
@ aLeft
Aligns the text at the left edge of the bounding rectangle.
Definition drawitem.h:75
@ aCenter
Aligns the text horizontally at the center of the bounding rectangle.
Definition drawitem.h:76
TStyle
TStyle contains values that defines how the button will be displayed.
Definition drawitem.h:82
int GetIndex() const
Returns Index, the index of Bitmap in the Proxy CellArray or -1.
Definition drawitem.h:283
bool IsEnabled()
Returns true if (Flags & ODS_DISABLED)==0; false otherwise.
Definition drawitem.h:139
void SetAlign(const TAlign align)
Sets Align to align.
Definition drawitem.h:311
LPCTSTR GetText() const
Returns Text, the text do display on the button.
Definition drawitem.h:276
TCelArray is a horizontal array of cels (a unit of animation) created by slicing a portion of or an e...
Definition celarray.h:35
Class wrapper for management of color values.
Definition color.h:245
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
Proxy parent for TDrawItem.
Definition drawitem.h:40
virtual TCelArray * GetCelArray()
Definition drawitem.h:51
virtual TFont * GetFont()
Definition drawitem.h:48
TIPtrArray< TDrawItem * > TDrawItemArray
Definition drawitem.h:42
TDrawItemArray & GetItems()
Returns ItemArray.
Definition drawitem.h:269
Derived from TButtonTextDrawItem, the TDrawMenuItem class is used for owner drawn menus.
Definition drawitem.h:184
void SetCheckPainter(TCheckPainter painter)
Set the routine to be used to paint the check mark.
Definition drawitem.h:332
int GetCmdId()
Returns CmdId.
Definition drawitem.h:340
Derived from TDrawItemProxy, TDrawMenuItemProxy is a proxy parent for TDrawMenuItem.
Definition drawitem.h:229
TUIntAray * Array
Array of id's.
Definition drawitem.h:249
TTypedArray< uint, uint, TStandardAllocator > TUIntAray
Container of TDrawItem's.
Definition drawitem.h:232
TFont derived from TGdiObject provides constructors for creating font objects from explicit informati...
Definition gdiobjec.h:296
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
The tagSIZE struct is defined as.
Definition geometry.h:234
Definition of GDI DC encapsulation classes: TDC, TWindowDC, TScreenDC, TDesktopDC,...
Definition of abstract GDI object class and derived classes.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
TModule & GetGlobalModule()
Definition global.cpp:48
#define protected_data
Definition defs.h:208
#define _OWLCLASS
Definition defs.h:338
Classes for window system structure and type encapsulation.