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
colmnhdr.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1995, 1996 by Borland International, All Rights Reserved
4//
5//----------------------------------------------------------------------------
6#include <owl/pch.h>
7
8#if !defined(OWL_COLMNHDR_H)
9#include <owl/colmnhdr.h>
10#endif
11
12namespace owl {
13
16
17//
18// Default size of string and bitmap items, both measured in pixels
19//
20
21/// Default size of string item.
23
24/// Default size of bitmap item.
26
27
28/// API to allow user to update ObjectWindows' default string size.
29/// \note Since the variable maintaining that information is shared
30/// by every instance of this class, use this function with
31/// caution.
32//
33void
35{
36 DefStringItemSize = size;
37}
38
39//
40/// API to allow the user to update ObjectWindows' default bitmap
41/// item size.
42/// \note Since the variable maintaining that information is shared
43/// by every instance of this class, use this function with
44/// caution.
45void
47{
48 DefBitmapItemSize = size;
49}
50
51//
52/// Constructs a THdrItem object for an item consisting of
53/// both a string and a bitmapped image.
54/// Defaults to left alignment and the DefStringItemSize.
55//
63
64//
65/// Constructs a THdrItem object for an item which has a string
66/// Defaults to left alignment and the DefStringItemSize.
67//
74
75//
76/// Constructs a THdrItem object for an item which has a bitmapped image
77/// Defaults to left alignment and DefBitmapItemSize.
78//
85
86//
87/// Constructs an 'empty' THdrItem with the specified 'msk' enabled.
88/// This flavour of the constructor is mainly used to construct an object
89/// which is used to retrieve information about an existing item.
90//
92 : HD_ITEM{msk}
93{}
94
95//
96/// Constructs an 'empty' THdrItem with the specified 'msk' enabled.
97/// This flavour of the constructor is mainly used to construct an object
98/// which is used to retrieve information about an existing item. 'buffer'
99/// specifies a location which will receive the text of the item and 'len'
100/// specifies the size of the buffer.
101//
103 : HD_ITEM{msk, 0, buffer, nullptr, len}
104{}
105
106//
107/// Sets the alignment of the contents of the item.
108//
114
115//
116/// Sets the text of the HeaderItem object.
117/// \note The format flags is not updated to contain any alignment flags
118//
119void
121{
123 fmt |= (HDF_STRING);
124 pszText = CONST_CAST(LPTSTR, str);
125 cchTextMax = static_cast<int>(::_tcslen(str)+1); // This is probably superfluous,
126 // albeit harmless
127}
128
129//
130/// Sets the bitmap handle of the HeaderItem object.
131/// \note The format flags is not updated to contain any alignment flags
132//
133void
140
141//
142/// Sets the width of the item
143//
144void
146{
147 cxy = width;
148 mask &= ~HDI_HEIGHT;
149 mask |= HDI_WIDTH;
150}
151
152//
153/// Sets the height of the item
154//
155void
157{
158 cxy = height;
159 mask &= ~HDI_WIDTH;
160 mask |= HDI_HEIGHT;
161}
162
163//
164/// Sets the application-defined item data attached to this item object
165//
166void
172
173//
174/// Version 4.70. Zero-based index of an image within the image list
175//
176void
178{
179 iImage = item;
180 mask |= HDI_IMAGE;
181
182}
183
184//
185/// Version 4.70. Order in which the item appears within the header control,
186/// from left to right.
187//
188void
190{
191 iOrder = order;
192 mask |= HDI_ORDER;
193}
194//----------------------------------------------------------------------------
195
196//
197/// Constructor for TColumnHeader
198//
199/// Initializes its data fields using parameters passed and default values.
200/// By default, a ColumnHeader associated with the TColumnHeader will:
201/// - be visible upon creation
202/// - have a border, divider tracks
203/// - be a horizontal header window
204//
206 int id,
207 int x, int y, int w, int h,
208 TModule* module)
209:
210 TControl(parent, id, nullptr, x, y, w, h, module)
211{
213
214 // By default we'll use the native implementation if it's available
215 // here's a strange: although Win95 defines HDS_HORZ, it is defined as '0',
216 // which would indicate that the only column headings supported are horizontal
217 // headings. Also, there is no HDS_VERT.
218 // In any case, we explicitly 'test' for HDS_HORZ in the code below and we
219 // try to forsee what could happen if (and when) HDS_VERT gets defined.
220 Attr.Style |= HDS_HORZ;
221 TRACEX(OwlCommCtrl, OWL_CDLEVEL, "TColumnHeader constructed @" << (void*)this);
222}
223
224//
225/// Constructor of a ColumnHeader object which aliases a control found
226/// within a dialog.
227//
229 int resourceId,
230 TModule* module)
231:
232 TControl(parent, resourceId, module)
233{
235 TRACEX(OwlCommCtrl, OWL_CDLEVEL, "TColumnHeader constructed from resource @" << (void*)this);
236}
237
238
242
243
244//
245/// Returns the class name of the underlying control associated with
246/// the TColumnHeader object.
247/// \note The logic used depends on the availability of native
248/// Common Control support. In the case where OWL provides
249/// the underlying support, we'll specify a TColumnHeader -specific
250/// classname although that's not necessary [it eases debugging]
251//
256
257//
258/// If successful this method returns the number of items in the
259/// header control. In case of failure it returns -1.
260//
261int
263{
264 return static_cast<int>(CONST_CAST(TColumnHeader*,this)->SendMessage(HDM_GETITEMCOUNT));
265}
266
267//
268/// This method retrieves the size and position of a header control
269/// within a given rectangle. It determines the appropriate dimensions
270/// of a new header control that is to occupy the given rectangle.
271/// Upon entry the 'boundingRect' parameter specifies the rectangle
272/// within which the columnHeader must lie. The control then updates
273/// the WINDOWPOS structure to contain the desired/appropriate dimensions
274/// for the control to occupy within the specified rectangle.
275//
276bool
278{
280 hdl.prc = &boundingRect;
281 hdl.pwpos = &wp;
282 return SendMessage(HDM_LAYOUT, 0, TParam2(&hdl)) != 0;
283}
284
285//
286/// This method repositions the columnHeader control within the client area
287/// of its parent window by taking advantage of the columnHeader's ability
288/// to specify its desired/appropriate position from a specified bounding
289/// rectangle. This method assumes that the control will occupy the full
290/// width of the client area of its parent.
291//
292bool
294{
297 if (Layout(rect, wp)) {
298 SetWindowPos(wp.hwndInsertAfter, wp.x, wp.y, wp.cx, wp.cy,
299 wp.flags|swpFlags);
300 return true;
301 }
302 return false;
303}
304
305//
306/// Adds a new item to the column header.
307/// The following illustrates a typical use of the 'Add' method:
308/// \code
309/// THdrItem hdrItem("&Employee Names");
310/// hdr.Add(hdrItem);
311/// \endcode
312int
314{
315 return Insert(item, GetCount());
316}
317
318//
319/// Inserts a new item after the specified location, 'index', in the column Header
320/// control. The new item is inserted at the end of the header control if index is
321/// greater than or equal to the number of items in the control. If index is zero,
322/// the new item is inserted at the beginning of the header control. The following
323/// illustrates a typical use of the 'Insert' method:
324/// \code
325/// THdrItem hdrItem(GetModule().LoadBitmap(IDB_COMPANYLOGO));
326/// hdr.Insert(hdrItem, 0);
327/// \endcode
328/// If the operation succeeds, the return value is the index of the new item. If the
329/// operation fails, the return value is - 1.
330//
331int
332TColumnHeader::Insert(const THdrItem& item, int index)
333{
334 return SendMessage(HDM_INSERTITEM, index, TParam2(&item)) != 0;
335
336}
337
338//
339/// Deletes the item at the specified 'index' from the header control.
340//
341bool
343{
344 return SendMessage(HDM_DELETEITEM, index) != FALSE;
345}
346
347//
348/// Retrieves information about the item at the specified index by filling
349/// out the 'itemInfo' structure passed in. The 'msk' contains one or more
350/// HDI_xxxx constants and can be used to specify which information should
351/// be copied.
352//
353bool
355{
356 itemInfo.mask |= msk;
357 return SendMessage(HDM_GETITEM, index, TParam2(&itemInfo)) != 0;
358}
359
360//
361/// Updates the attribute(s) a the item at the specified 'index'. The
362/// 'itemInfo' structure contains the new attributes of the item.
363//
364bool
366{
367 return SendMessage(HDM_SETITEM, index, TParam2(&itemInfo)) != 0;
368}
369
370//
371/// Transfers are not implemented for ColumnHeaders. Simply return 0.
372//
373
374uint
375TColumnHeader::Transfer(void* /*buffer*/, TTransferDirection /*direction*/)
376{
377 TRACEX(OwlCommCtrl, OWL_CDLEVEL, "TColumnHeader::Transfer is not"\
378 "implemented!");
379 return 0;
380}
381
382//
383/// Tests a point to determine which header item, if any, is at the
384/// specified point.
385/// Returns the index of the item at the specified position, if any, or � 1
386/// otherwise. ht contains the position to test and receives information about the
387/// results of the test.
388/// \note The coordinates are specified via the 'pt' member of the
389/// THeaderHitTestInfo parameter.
390//
391int
393{
394 return static_cast<int>(SendMessage(HDM_HITTEST, 0, TParam2(&ht)));
395}
396
397
398} // OWL namespace
399
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
#define TRACEX(group, level, message)
Definition checks.h:263
TColumnHeader encapsulates the 'header control', a window usually positioned above columns of text or...
Definition colmnhdr.h:116
bool Layout(TRect &boundingRect, WINDOWPOS &winPos)
This method retrieves the size and position of a header control within a given rectangle.
Definition colmnhdr.cpp:277
uint Transfer(void *buffer, TTransferDirection direction)
Transfers are not implemented for ColumnHeaders. Simply return 0.
Definition colmnhdr.cpp:375
bool Delete(int index)
Deletes the item at the specified 'index' from the header control.
Definition colmnhdr.cpp:342
int Add(const THdrItem &item)
Adds a new item to the column header.
Definition colmnhdr.cpp:313
bool SetItem(const THdrItem &itemInfo, int index)
Updates the attribute(s) a the item at the specified 'index'.
Definition colmnhdr.cpp:365
int Insert(const THdrItem &item, int index)
Inserts a new item after the specified location, 'index', in the column Header control.
Definition colmnhdr.cpp:332
bool GetItem(THdrItem &, int index, uint mask=0)
Retrieves information about the item at the specified index by filling out the 'itemInfo' structure p...
Definition colmnhdr.cpp:354
virtual auto GetWindowClassName() -> TWindowClassName
Returns the class name of the underlying control associated with the TColumnHeader object.
Definition colmnhdr.cpp:252
int HitTest(THeaderHitTestInfo &ht)
Tests a point to determine which header item, if any, is at the specified point.
Definition colmnhdr.cpp:392
int GetCount() const
If successful this method returns the number of items in the header control.
Definition colmnhdr.cpp:262
TColumnHeader(TWindow *parent, int id, int x, int y, int w, int h, TModule *module=0)
Constructor for TColumnHeader.
Definition colmnhdr.cpp:205
TControl unifies its derived control classes, such as TScrollBar, TControlGadget, and TButton.
Definition control.h:38
THdrItem contains information about an item in a header control.
Definition colmnhdr.h:40
void SetImage(int item)
Version 4.70. Zero-based index of an image within the image list.
Definition colmnhdr.cpp:177
void SetHeight(int cy)
Sets the height of the item.
Definition colmnhdr.cpp:156
static int DefStringItemSize
Default size of string item.
Definition colmnhdr.h:93
void SetOrder(int order)
Version 4.70.
Definition colmnhdr.cpp:189
void SetWidth(int cx)
Sets the width of the item.
Definition colmnhdr.cpp:145
void SetBitmap(HBITMAP hbm)
Sets the bitmap handle of the HeaderItem object.
Definition colmnhdr.cpp:134
static void SetDefBitmapSize(int size)
API to allow the user to update ObjectWindows' default bitmap item size.
Definition colmnhdr.cpp:46
void SetText(LPCTSTR str)
Sets the text of the HeaderItem object.
Definition colmnhdr.cpp:120
TAlign
Format flags that determines how the contents (text and/or bitmap) will be layed out.
Definition colmnhdr.h:47
void SetAlignment(TAlign)
Methods to set the data members of the HD_ITEM structure.
Definition colmnhdr.cpp:109
static int DefBitmapItemSize
Default size of bitmap item.
Definition colmnhdr.h:94
THdrItem(LPCTSTR str, TAlign=aLeft)
Constructs a THdrItem object for an item which has a string Defaults to left alignment and the DefStr...
Definition colmnhdr.cpp:68
static void SetDefStringSize(int size)
API to allow user to update ObjectWindows' default string size.
Definition colmnhdr.cpp:34
void SetItemData(TParam2 data)
Sets the application-defined item data attached to this item object.
Definition colmnhdr.cpp:167
THeaderHitTestInfo contains hittest information for the header control.
Definition colmnhdr.h:104
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
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
bool SetWindowPos(HWND hWndInsertAfter, const TRect &rect, uint flags)
Changes the size of the window pointed to by rect.
Definition window.h:2809
TWindow * GetParentO() const
Return the OWL's parent for this window.
Definition window.h:2006
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
Definition window.cpp:3288
void GetClientRect(TRect &rect) const
Gets the coordinates of the window's client area and then copies them into the object referred to by ...
Definition window.cpp:3624
Definition of class TColumnHeader and helper classes.
#define _tcslen
Definition cygwin.h:74
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
void InitializeCommonControls(uint controlFlags)
Wrapper for the Windows API function InitCommmonControlsEx.
Definition commctrl.cpp:19
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
OWL_DIAGINFO
Definition animctrl.cpp:14
unsigned int uint
Definition number.h:25
#define OWL_CDLEVEL
Definition defs.h:171
#define CONST_CAST(targetType, object)
Definition defs.h:273