OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
tabctrl.cpp
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/// Implementation of classes TTabItem and TTabControl.
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9
10#include <owl/tabctrl.h>
11#include <owl/uihelper.h>
12#include <owl/dc.h>
13#include <owl/gdiobjec.h>
14
15#if defined(__BORLANDC__)
16# pragma option -w-ccc // Disable "Condition is always true/false"
17#endif
18
19namespace owl {
20
22DIAG_DECLARE_GROUP(OwlCommCtrl); // Common Controls diagnostic group
23
24// Let the compiler know that the following template instances will be defined elsewhere.
25//#pragma option -Jgx
26
27//
28// Constants used in OWL's implementation of Tab Controls
29//
30const int InitSize = 5; // Initial size of Tab Collection
31const int InitDelta = 5; // Inc. when expanding collection
32const int HorzPad = 6; // Pad on each side of tab label
33const int VertPad = 4; // Pad above/below each tab label
34const int HorzSelInc = 1; // Inc. for selected tab
35const int VertSelInc = 1; // Inc. for selected tab
36const int HorzMargin = 3; // Margin on left/right of control
37const int VertMargin = 3; // Margin above control
38const int ClientMargin = 2; // Inner margin of tab's client area
39const int ID_Updown = 0x100; // Ctl. identifier of scroller;
40
41//
42/// The item is initialized with the state of an actual tab in
43/// a created tab control.
44//
47{
48 PRECONDITION(ctl.GetHandle());
49
50 // When retrieving text, a buffer and length must be supplied
51 //
53
54 mask = msk;
55 if (buffer && buffLen)
57
58 ctl.GetItem(index, *this);
59}
60
61//
62/// The tab item's label field is initialized to the specified buffer and extra
63/// parameter set to the 'param' parameter.
64//
66{
67 mask = 0;
68 iImage = -1;
69
71 SetLabel(str, buffLen);
72}
73
74//
75/// The tab item is initialized with the IMAGELIST index and the extra parameter
76/// specified.
77//
79{
80 mask = 0;
81 pszText = nullptr;
82 cchTextMax = 0;
83
86}
87
88//
89/// The tab item is initialized with the IMAGELIST index and label specified.
90//
92{
93 mask = 0;
95 SetLabel(str);
96}
97
98//
99// Initializes the structure member representing the tab's text
100//
101void
103{
104 pszText = CONST_CAST(LPTSTR, str);
105 cchTextMax = len ? len : static_cast<int>(::_tcslen(str));
106 mask |= TCIF_TEXT;
107}
108
109// Version 4.70
110void
112{
113 dwState = state;
114 dwStateMask = m;
115}
116
117//----------------------------------------------------------------------------
122
123
124//
125/// Constructor for TTabControl. Initializes its data fields using parameters passed
126/// and default values by default. A TabControl associated with the TTabControl
127/// will:
128/// - be visible upon creation
129/// - display only one row of tabs.
130//
132 int id,
133 int x, int y, int w, int h,
134 TModule* module)
135:
136 TControl(parent, id, nullptr, x, y, w, h, module)
137{
140}
141
142//
143/// Constructor for a TTabControl object associated with a Tab Control specified in
144/// a dialog resource.
145//
147 int resourceId,
148 TModule* module)
149:
150 TControl(parent, resourceId, module)
151{
153}
154
155//
156/// Constructor for a TTabControl object to be associated with
157/// an already created Tab Control.
158//
164
165//
166/// Cleans up if underlying Tab support was provided by ObjectWindows.
167//
171
172//
173/// Returns the class name of the underlying control associated with the TTabControl
174/// object.
179
180//
181/// Transfer is not implemented in TTabControl, given that each item interacts with
182/// settings outside of the TC_ITEM members. (For example, the image index points to
183/// the ImageList).
184//
185uint
186TTabControl::Transfer(void* /*buffer*/, TTransferDirection /*direction*/)
187{
188 TRACEX(OwlCommCtrl, 0, "TTabControl::Transfer is not implemented");
189 return 0;
190}
191
192//
193/// Keep TWindow from rerouting this message - it must be left as is
194/// for the tab control as it may originate from the control's spin.
195//
196void
201
202//
203/// Keeps TWindow from rerouting this message.It must be left as is for the tab
204/// control, as it may originate from the control's spin.
205//
206void
211
212
213
214//
215/// Inserts a new tab with the caption 'tabText' at the
216/// specified 'index'. Returns the index of the new tab, if successful.
217//
218int
220{
221 return Insert(TTabItem(tabText), index);
222}
223
224
225
226
227//
228// If the 'clientInWindowOut' parameter is false, this method calculates the
229// display area of a tab control's display from a window rectangle specified by the
230// 'rect' parameter. Otherwise, the method calculates the window rectangle that
231// would correspond to the display area specified by the 'rect' parameter. The
232// 'rect' parameter receives the newly computed rectangle.
233//
234void
239
240//
241/// Inserts a new tab described by the 'item' parameter to the tab control at the
242/// position specified by the 'index' parameter. The return value is the index of
243/// the new tab or -1 in case of error.
244//
245int
247{
248 return Insert(item, GetCount());
249}
250
251//
252// Adds a new tab with the 'tabText' caption to the tab control Returns the index
253// of the new tab, if successful or -1 otherwise.
254//
255int
260
261//
262// Inserts a new tab described by the 'item' parameter to the tab
263// control at the position specified by the 'index' parameter.
264// The return value is the index of the new tab or -1 in case of error.
265//
266int
267TTabControl::Insert(const TTabItem& item, int index)
268{
269 return static_cast<int>(SendMessage(TCM_INSERTITEM, index, TParam2((const TC_ITEM *)(&item))));
270}
271
272//
273// Removes the item at the position specified by the 'index' parameter.
274// Returns 'true' if successful or 'false' otherwise.
275//
276bool
278{
279 return SendMessage(TCM_DELETEITEM, index) != 0;
280}
281
282//
283// Removes all items from the tab control. Returns 'true' if successful or
284// 'false' otherwise.
285//
286bool
291
292//
293// Returns the number of tab items in the tab control.
294//
295int
297{
298 return static_cast<int>(CONST_CAST(TTabControl*, this)->SendMessage(TCM_GETITEMCOUNT));
299}
300
301//
302// Retrieves the current number of rows in the tab control.
303// NOTE: Only tabs with the TCS_MULTILINE style can have multiple rows.
304//
305int
307{
308 return static_cast<int>(CONST_CAST(TTabControl*, this)->SendMessage(TCM_GETROWCOUNT));
309}
310
311//
312// Returns the index of the currently selected tab item in the tab control.
313// Returns -1 if no tab is selected.
314//
315int
317{
318 return static_cast<int>(CONST_CAST(TTabControl*, this)->SendMessage(TCM_GETCURSEL));
319}
320
321//
322// Selects the tab item at the position specified by the 'index' parameter.
323// The return value is the index of the previously selected tab item if
324// successful or -1 otherwise.
325// NOTE: A tab control does not send TCN_SELCHANGING or TCN_SELCHANGE
326// notifications when a tab item is selected via this method.
327//
328int
330{
331 return static_cast<int>(SendMessage(TCM_SETCURSEL, index));
332}
333
334//
335// Retrieves information about the tab at the position specified by
336// the 'index' parameter. Returns true if successful or false otherwise.
337// NOTE: The 'mask' member of the 'item' structure specifies which
338// attributes of the tab to return. When spefying TCIF_TEXT, item's
339// pszText member must point to a valid buffer and cchTextMax must
340// specify the size of the buffer.
341//
342bool
343TTabControl::GetItem(int index, TTabItem& item) const
344{
345 return CONST_CAST(TTabControl*, this)->SendMessage(TCM_GETITEM, index, TParam2((TC_ITEM *)&item)) != 0;
346}
347
348//
349// Retrieves the bounding rectangle of a tab within a tab control.
350// Returns true if successful or false otherwise.
351// NOTE: 'rect' receives the position in viewport coordinates.
352//
353bool
355{
356 return CONST_CAST(TTabControl*, this)->SendMessage(TCM_GETITEMRECT, index, TParam2((LPRECT)&rect)) != 0;
357}
358
359//
360// Sets some or all of a tab's attributes. The 'mask' member of the
361// 'item' parameter specifies which attributes to set.
362// Returns true if successful or false otherwise.
363//
364bool
365TTabControl::SetItem(int index, const TTabItem& item)
366{
367 return SendMessage(TCM_SETITEM, index, TParam2((const TC_ITEM *)&item)) != 0;
368}
369
370//
371// Sets the number of bytes per tab reserved for application-defined
372// data in a tab control. Returns true if successful or false otherwise.
373// NOTE: This method should be invoked only when the tab control does not
374// contain any tabs.
375//
376bool
381
382//
383// Sets the size (width/height) of tabs in a fixed-width or owner-draw
384// tab control. Returns a TSize object containing the old width and height.
385//
386TSize
388{
389 DWORD r = static_cast<DWORD>(SendMessage(TCM_SETITEMSIZE, 0, MkParam2(size.cx, size.cy)));
390 return TSize(r);
391}
392
393//
394// Sets the amount of space around each tab's icon and label in a tab
395// control.
396//
397void
399{
400 SendMessage(TCM_SETPADDING, 0, MkParam2(size.cx, size.cy));
401}
402
403//
404// Retrieves the ImageList associated with a tab control. Returns 0 if
405// unsuccessful.
406//
409{
410 return (HIMAGELIST)CONST_CAST(TTabControl*, this)->SendMessage(TCM_GETIMAGELIST);
411}
412
413//
414// Assigns an imagelist to the tab control. Returns the handle of the
415// previous imagelist or 0 if there is no previous image list.
416//
422
423//
424// Removes the image at the position specified by 'index' from the
425// imagelist associated with the tab control.
426// NOTE: The tab automatically updates each tab's image index so each
427// tab remains associated with the same image it had been.
428//
429void
431{
433}
434
435//
436// Retrieves the handle of the tooltip control associated with the
437// tab control. Returns 0 if unsuccessful.
438//
444
445//
446// Assigns a tooltip control to the tab control.
447//
448void
453
454//
455// Determines the index of the tab which is at the location
456// specified in the 'pt' member of the 'htInfo' parameter.
457// Returns -1 if no tab is at the specified position.
458//
459int
461{
462 return static_cast<int>(SendMessage(TCM_HITTEST, 0, TParam2((TC_HITTESTINFO *)&htInfo)));
463}
464
465//----------------------------------------------------------------------------
466
467
468} // OWL namespace
469/* ========================================================================== */
470
#define PRECONDITION(condition)
Definition checks.h:227
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
#define TRACEX(group, level, message)
Definition checks.h:263
TControl unifies its derived control classes, such as TScrollBar, TControlGadget, and TButton.
Definition control.h:38
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
TTabControl encapsulates the tab control - a window that provides a user interface analogous to divid...
Definition tabctrl.h:91
int GetCount() const
Definition tabctrl.cpp:296
int GetSel() const
Definition tabctrl.cpp:316
void RemoveImage(int index)
Definition tabctrl.cpp:430
HIMAGELIST GetImageList() const
Definition tabctrl.cpp:408
bool Delete(int index)
Definition tabctrl.cpp:277
int SetSel(int index)
Definition tabctrl.cpp:329
TTabControl(TWindow *parent, int id, int x, int y, int w, int h, TModule *module=0)
Constructor for TTabControl.
Definition tabctrl.cpp:131
void AdjustRect(bool clientInWindowOut, TRect &rect)
Definition tabctrl.cpp:235
void SetPadding(const TSize &size)
Definition tabctrl.cpp:398
void EvHScroll(uint scrollCode, uint thumbPos, THandle hWndCtl)
Keeps TWindow from rerouting this message.It must be left as is for the tab control,...
Definition tabctrl.cpp:207
void SetToolTips(HWND toolTip)
Definition tabctrl.cpp:449
bool SetItem(int index, const TTabItem &item)
Definition tabctrl.cpp:365
auto Transfer(void *buffer, TTransferDirection) -> uint override
Transfer is not implemented in TTabControl, given that each item interacts with settings outside of t...
Definition tabctrl.cpp:186
~TTabControl() override
Cleans up if underlying Tab support was provided by ObjectWindows.
Definition tabctrl.cpp:168
TSize SetItemSize(const TSize &size)
Definition tabctrl.cpp:387
auto GetWindowClassName() -> TWindowClassName override
Returns the class name of the underlying control associated with the TTabControl object.
Definition tabctrl.cpp:175
int HitTest(TTabHitTestInfo &)
Definition tabctrl.cpp:460
int Insert(const TTabItem &, int index)
Definition tabctrl.cpp:267
bool GetItem(int index, TTabItem &item) const
Definition tabctrl.cpp:343
bool GetItemRect(int index, TRect &rect) const
Definition tabctrl.cpp:354
void EvVScroll(uint scrollCode, uint thumbPos, THandle hWndCtl)
Keep TWindow from rerouting this message - it must be left as is for the tab control as it may origin...
Definition tabctrl.cpp:197
HIMAGELIST SetImageList(HIMAGELIST)
Definition tabctrl.cpp:418
HWND GetToolTips() const
Definition tabctrl.cpp:440
int GetRowCount() const
Definition tabctrl.cpp:306
bool SetItemExtra(int extra)
Definition tabctrl.cpp:377
int Add(const TTabItem &)
Inserts a new tab described by the 'item' parameter to the tab control at the position specified by t...
Definition tabctrl.cpp:246
TTabHitTestInfo is a thin [very thin] wrapper around the TC_HITTESTINFO structure.
Definition tabctrl.h:80
TTabItem encapsulates the attributes of a single tab within a tab control.
Definition tabctrl.h:46
TTabItem(uint mask)
Constructor for a Tab Item: This constructor is useful when creating a TabItem (TC_ITEM) structure wh...
Definition tabctrl.h:197
void SetState(uint32 state, uint32 mask)
Definition tabctrl.cpp:111
void SetParam(TParam2 lp)
Sets the user-defined data associated with the tab represented by this item structure.
Definition tabctrl.h:228
void SetIcon(int imageIndex)
Sets the index of the image assiciated with the tab represented by this item structure.
Definition tabctrl.h:218
void SetLabel(LPCTSTR str, int len=0)
Definition tabctrl.cpp:102
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 IsWindow() const
Returns true if an HWND is being used.
Definition window.h:2040
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
#define _tcslen
Definition cygwin.h:74
Definition of GDI DC encapsulation classes: TDC, TWindowDC, TScreenDC, TDesktopDC,...
#define DEFINE_RESPONSE_TABLE1(cls, base)
Macro to define a response table for a class with one base.
Definition eventhan.h:492
Definition of abstract GDI object class and derived classes.
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
const int InitDelta
Definition tabctrl.cpp:31
const int HorzSelInc
Definition tabctrl.cpp:34
void InitializeCommonControls(uint controlFlags)
Wrapper for the Windows API function InitCommmonControlsEx.
Definition commctrl.cpp:19
const int VertSelInc
Definition tabctrl.cpp:35
EV_WM_HSCROLL
Definition notetab.cpp:55
const int InitSize
Definition tabctrl.cpp:30
const int ClientMargin
Definition tabctrl.cpp:38
unsigned long uint32
Definition number.h:34
const int HorzPad
Definition tabctrl.cpp:32
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
TParam2 MkParam2(const T1 &lo, const T2 &hi)
Definition dispatch.h:65
OWL_DIAGINFO
Definition animctrl.cpp:14
END_RESPONSE_TABLE
Definition button.cpp:26
const int ID_Updown
Definition tabctrl.cpp:39
const int VertPad
Definition tabctrl.cpp:33
EV_WM_VSCROLL
Definition scrollba.cpp:18
unsigned int uint
Definition number.h:25
const int VertMargin
Definition tabctrl.cpp:37
const int HorzMargin
Definition tabctrl.cpp:36
#define CONST_CAST(targetType, object)
Definition defs.h:273
Definition of class TTabItem and TTabControl.
Definition of the UI Helper Classes: TUIHandle, TUIBorder, TUIFace, TUIPart.