OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
coolbar.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1998 by Bidus Yura, All Rights Reserved
4//
5/// \file
6/// Implementation of the TCoolBar class
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9
10#include <owl/coolbar.h>
11#include <owl/imagelst.h>
12#include <owl/tooltip.h>
13#include <owl/functor.h>
14#include <stdio.h>
15
16namespace owl {
17
19DIAG_DECLARE_GROUP(OwlCommCtrl); // CommonCtrl Diagnostic group
20
21static uint32
22SizeOfReBarBandInfo(REBARBANDINFO& info)
23{
24 info.cbSize = sizeof(REBARBANDINFO);
25 return info.cbSize;
26}
27
28//
29// Constructor of TCoolBar control
30//
31TCoolBar::TCoolBar(TWindow* parent, int id, int x, int y, int w, int h,
32 TModule* module)
33:
34 TControl(parent, id, _T(""), x, y, w, h, module),
35 BgColor(GETPUTOBJMFUNCTOR(TColor,TCoolBar,GetBgColor,SetBgColor)),
36 TextColor(GETPUTOBJMFUNCTOR(TColor,TCoolBar,GetTextColor,SetTextColor)),
37 ColorScheme(GETPUTOBJMFUNCTOR(TColorScheme,TCoolBar,GetColorScheme,SetColorScheme)),
38 Palette(FPalette,PUTMFUNCTOR(TPalette*,TCoolBar,SetPalette)),
39 Buddy(FBuddy,PUTMFUNCTOR(TWindow*,TCoolBar,SetBuddy)),
40 Tooltip(FTooltip,PUTMFUNCTOR(TTooltip*,TCoolBar,SetTooltip)),
41 Unicode(GETPUTMFUNCTOR(bool,TCoolBar,GetUnicode,SetUnicode)),
43{
44 // Modify the style to some reasonable defaults...
45 // ... this comes from the Microsoft example by Nancy Winnick Cluts
48 RBS_VARHEIGHT | // This style is trashed by TDecoratedFrame::Insert
49 RBS_BANDBORDERS; // This style is trashed by TDecoratedFrame::Insert
50 //WS_BORDER; // This style must be added after TDecoratedFrame::Insert
51 Init();
52}
53
54
56:
57 TControl(parent, resourceId, module),
58 BgColor(GETPUTOBJMFUNCTOR(TColor,TCoolBar,GetBgColor,SetBgColor)),
59 TextColor(GETPUTOBJMFUNCTOR(TColor,TCoolBar,GetTextColor,SetTextColor)),
60 ColorScheme(GETPUTOBJMFUNCTOR(TColorScheme,TCoolBar,GetColorScheme,SetColorScheme)),
61 Palette(FPalette,PUTMFUNCTOR(TPalette*,TCoolBar,SetPalette)),
62 Buddy(FBuddy,PUTMFUNCTOR(TWindow*,TCoolBar,SetBuddy)),
63 Tooltip(FTooltip,PUTMFUNCTOR(TTooltip*,TCoolBar,SetTooltip)),
64 Unicode(GETPUTMFUNCTOR(bool,TCoolBar,GetUnicode,SetUnicode)),
66{
67 Init();
68}
69
70//
71//
72// Destructor
74{
75 if(ShouldDelete)
76 delete FBandImages;
77 delete FColorScheme;
78 delete FPalette;
79 delete FBands;
80 //delete FTooltip; //???????????????????
81}
82
83//
84//
85//
86void
88{
90
91 // Initialise the image list pointer
93 FBandImages = nullptr;
94 FBuddy = nullptr;
95 FPalette = nullptr;
96 FColorScheme = nullptr;
99 FTooltip = nullptr;
100}
101
102// Return the proper class name.
103// Windows class: REBARCLASSNAME is defined in commctrl.h
108
109//
110//
111//
112void
114{
116
118
119 // Initialise the rebar.
120 // This would typically be used to associate an image list with
121 // the rebar. It is not clear yet whether the rebar cleans up this
122 // image list itself. If I use a TImageList for this who deletes it?
123 // If me is the handle still valid? My treatment seems to work.
124
125 Info.fMask &= ~RBIM_IMAGELIST;
126 Info.himl = nullptr;
127 if(FBandImages)
130 if(FColorScheme)
132 if(FPalette)
138 if(FBuddy && FBuddy->GetHandle())
140 if(FTooltip){
141 FTooltip->SetParent(this);
142 if(!FTooltip->GetHandle())
143 FTooltip->Create();
145 }
146 for(int i = 0; i < static_cast<int>(FBands->Size()); i++){
148 (*FBands)[i]->SetupData(this, info);
150 }
151}
152
153//#define RB_INSERTBANDA (WM_USER + 1)
154//#define RB_INSERTBANDW (WM_USER + 10)
155//Message RB_INSERTBAND
156//Description Inserts a band into a rebar.
157//wParam UINT - the zero-based index of the place to insert the band; -1 signifies
158// that the band will be added to the end
159//lParam LPREBARINFO [???] - pointer to a structure containing information about the band
160//Returns 0 if successful; non-zero otherwise
161bool
163{
164 uint idx = index;
165 if(index == static_cast<uint>(-1)) //JJH added static_cast
166 idx = FBands->Add(band);
167 else
168 FBands->AddAt(band, index);
169 if (GetHandle()){
171 (*FBands)[idx]->SetupData(this, info);
172 return SendMessage(RB_INSERTBAND, index, TParam2(&info)) == 0;
173 }
174 return true;
175}
176
177
178//#define RB_DELETEBAND (WM_USER + 2)
179//Message RB_DELETEBAND
180//Description Removes a band from the rebar.
181//wParam UINT - the zero-based index of the band to delete
182//lParam 0 (not used)
183//Returns 0 if successful; non-zero otherwise
184bool
186{
187 FBands->Destroy(index);
188 if (GetHandle())
189 return SendMessage(RB_DELETEBAND, index)==0;
190 return true;
191}
192
193//#define RB_GETBARINFO (WM_USER + 3)
194//Message RB_GETBARINFO
195//Description Retrieves information about the rebar control and the image list it may use.
196//wParam 0 (not used)
197//lParam LPREBARINFO - pointer to a structure containing rebar information
198//Returns 0 if successful; non-zero otherwise
199bool
201{
202 if (GetHandle())
203 return SendMessage(RB_GETBARINFO, 0, TParam2(&info))==0;
204 info = Info;
205 return true;
206}
207
208//#define RB_SETBARINFO (WM_USER + 4)
209//Message RB_SETBARINFO
210//Description Sets information about the rebar.
211//wParam 0
212//lParam LPREBARINFO - pointer to a structure containing new rebar information
213//Returns 0 if successful; non-zero otherwise
214bool
216{
217 Info = info;
218 Info.fMask &= ~RBIM_IMAGELIST;
219 Info.himl = nullptr;
220 if(FBandImages)
221 Info.SetImageList(*FBandImages); // Sets NULL aswell to use no images.
222 if (GetHandle())
223 return SendMessage(RB_SETBARINFO, 0, TParam2(&Info))==0;
224 return true;
225}
226
227//#define RB_SETPARENT (WM_USER + 7)
228//Message RB_SETPARENT
229//Description Sets the window that will receive rebar notification messages. Note that this
230// message does not actually set the parent of the Rebar control. When you call
231// GetParent, you will still get the handle to the original parent window that was
232// specified when the Rebar control was created.
233//wParam HWND - handle to the new parent window
234//lParam 0
235//Returns HWND - handle to the previous parent window; NULL if there is no previous parent
236void
243
244void
246{
247 if(GetHandle())
248 SendMessage(RB_SETTOOLTIPS, TParam1(tip->GetHandle()));
249 delete FTooltip;
250 FTooltip = tip;
251}
252
253//#define RB_GETBANDCOUNT (WM_USER + 12)
254//Message RB_GETBANDCOUNT
255//Description Returns the number of bands in the rebar.
256//wParam 0 (not used)
257//lParam 0 (not used)
258//Returns UINT - Number of bands in the rebar
259uint
261{
262 if(GetHandle())
263 return static_cast<uint>(SendMessage(RB_GETBANDCOUNT));
264 return FBands->Size();
265}
266
267//
268//
269//
270void
272{
273 // This is intended to change the imagelist after creation...
274 // ... as yet untested.
275 // Delete the old image list and assign the new one.
276 if(ShouldDelete)
277 delete FBandImages;
278 Info.fMask &= ~RBIM_IMAGELIST;
279 Info.himl = nullptr;
282 if(FBandImages)
283 Info.SetImageList(*FBandImages); // Sets NULL aswell to use no images.
284
285 if (GetHandle())
287}
288
289//
290//
291//
292bool
294{
295 // Check the existing style
296 bool result = GetStyle() & (uint32)RBS_BANDBORDERS;
297 if(result)
299 else
301
302 // Set the window position to force a redraw - the "+ 1" seems to do the trick
303 if(GetHandle()){
305 SetWindowPos(nullptr,0,0,rect.Width(),rect.Height()+1,SWP_NOZORDER|SWP_NOCOPYBITS);
306 }
307
308 // Return the new setting
309 return !result;
310}
311
312
313//
314//
315//
316bool
318{
319 // Check the existing style
320 bool result = GetStyle() & (uint32)RBS_VARHEIGHT;
321 if(result)
323 else
325
326 // Set the window position to force a full redraw. The "+ 1" seems to do the trick
327 if(GetHandle()){
329 SetWindowPos(nullptr,0,0,rec.Width(),rec.Height()+1,SWP_NOZORDER|SWP_NOCOPYBITS);
330 }
331 // Return the new setting
332 return !result;
333}
334
335
336//
337//
338//
339bool
341{
342 // Check the existing style
343 bool result = GetStyle() & (uint32)WS_BORDER;
344 if (result)
345 ModifyStyle(WS_BORDER, 0, 0);
346 else
347 ModifyStyle(0, WS_BORDER, 0);
348
349 // Set the window position to force a full redraw. The "+ 1" seems to do the trick
350 if(GetHandle()){
352 SetWindowPos(nullptr,0,0,rec.Width(),rec.Height()+1,SWP_NOZORDER|SWP_NOCOPYBITS);
353 // Tell the parent window to layout again - I don't know why it does not
354 // do this itself re the border
355 if(Parent){
357 Parent->HandleMessage(WM_NOTIFY, GetId(), reinterpret_cast<TParam2>(&notify));
358 }
359 }
360 // Return the new setting
361 return !result;
362}
363
364void
373//
374//
375//
385//
386//
387//
388void
396//
397// TCoolBand
398// ~~~~~~~~~
399//
400
402{
403 Init();
404}
405
407{
408 Init();
409 Id = id;
410 Text(str);
411 Child = child;
412 Style = style;
413}
414
415//
416//
417//
419{
420 //delete Bitmap;
421}
422
423//
424//
425//
426void
428{
429 Child = nullptr;
430 //Bitmap = 0;
433 Style = 0;
434 Width = 0;
435 MinSize = TSize(-1,-1);
436 Id = -1;
437 ImageIndex = -1;
438 Mask = 0;
439}
440//
441//
442//
443void
445{
446 memset(&info, 0, sizeof(REBARBANDINFO));
447 SizeOfReBarBandInfo(info);
448
449 if(Mask)
450 info.fMask = Mask;
451
452 if(Child){
453 //Child()->SetBkgndColor(TColor::Transparent);
454 //Child()->ModifyExStyle(0,WS_EX_TRANSPARENT);
455 if(!Child()->GetHandle())
456 Child()->Create();
457 info.fMask |= RBBIM_CHILD;
458 info.hwndChild = Child()->GetHandle();
459 }
460 if(Bitmap){
461 info.fMask |= RBBIM_BACKGROUND;
462 info.hbmBack = Bitmap->GetHandle();
463 }
464 if(TColor::None != FgColor){
465 info.fMask |= RBBIM_COLORS;
466 info.clrFore = FgColor();
467 }
468 if(TColor::None != BgColor){
469 info.fMask |= RBBIM_COLORS;
470 info.clrBack = BgColor();
471 }
472 if(Style){
473 info.fMask |= RBBIM_STYLE;
474 info.fStyle = Style;
475 }
476 if(Width != uint(-1)){
477 info.fMask |= RBBIM_SIZE;
478 info.cx = Width;
479 }
480 if(MinSize() != TSize(-1,-1)){
481 info.fMask |= RBBIM_CHILDSIZE;
482 info.cxMinChild = MinSize().cx;
483 info.cyMinChild = MinSize().cy;
484 }
485 if(Id != -1){
486 info.fMask |= RBBIM_ID;
487 info.wID = Id;
488 }
489 if(ImageIndex != -1){
490 info.fMask |= RBBIM_IMAGE;
491 info.iImage = ImageIndex;
492 }
493 if(!Text().empty()){
494 info.fMask |= RBBIM_TEXT;
495 info.lpText = (tchar*)Text().c_str();
496 info.cch = static_cast<UINT>(Text().length());
497 }
498 Parent = parent;
499}
500} // OWL namespace
501/* ========================================================================== */
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
Class wrapper for management of color values.
Definition color.h:245
static const TColor None
not-a-color
Definition color.h:318
TControl unifies its derived control classes, such as TScrollBar, TControlGadget, and TButton.
Definition control.h:38
TProperty< uint > Width
Width of the band: don't use -1.
Definition coolbar.h:49
TObjProperty< TBitmap > Bitmap
The band's background bitmap.
Definition coolbar.h:44
TObjProperty< TColor > FgColor
Band colors -.
Definition coolbar.h:45
TProperty< TWindow * > Child
Handle of the band's child window.
Definition coolbar.h:47
TProperty< int > Id
The band's ID number: don't use -1.
Definition coolbar.h:51
void SetupData(TCoolBar *parent, REBARBANDINFO &info)
Definition coolbar.cpp:444
TCoolBar * Parent
Definition coolbar.h:75
TObjProperty< TSize > MinSize
Minimum size of the band's child window don't use TSize(-1,-1)
Definition coolbar.h:50
TProperty< uint > Style
Band style flags.
Definition coolbar.h:48
TObjProperty< tstring > Text
Band text label.
Definition coolbar.h:43
TProperty< uint > Mask
Mask indicating which other members are valid.
Definition coolbar.h:53
TProperty< int > ImageIndex
Band image index (into rebar image list): don't use -1.
Definition coolbar.h:52
TObjProperty< TColor > BgColor
Definition coolbar.h:46
This simple implementation does no more than encapsulte the messages which can be sent to the rebar c...
Definition coolbar.h:85
TTooltip * FTooltip
Definition coolbar.h:163
bool Insert(TCoolBand *band, uint index=-1)
Definition coolbar.cpp:162
bool GetInfo(TRebarInfo &info)
Definition coolbar.cpp:200
void SetPalette(TPalette *palette)
Definition coolbar.cpp:389
TCoolBandArray * FBands
Definition coolbar.h:154
TColor FTextColor
Definition coolbar.h:158
void Init()
Definition coolbar.cpp:87
TColor FBgColor
Definition coolbar.h:157
void SetBuddy(TWindow *buddy)
Definition coolbar.cpp:237
TColorScheme & GetColorScheme()
Definition coolbar.cpp:377
void SetImageList(TImageList *list, TAutoDelete=AutoDelete)
Definition coolbar.cpp:271
bool Delete(uint index=0)
Definition coolbar.cpp:185
TRebarInfo Info
Definition coolbar.h:155
bool ToggleBorder()
Definition coolbar.cpp:340
void SetColorScheme(const TColorScheme &clr)
Definition coolbar.cpp:365
bool SetInfo(TRebarInfo &info)
Definition coolbar.cpp:215
void SetTooltip(TTooltip *tip)
Definition coolbar.cpp:245
bool ToggleVarHeight()
Definition coolbar.cpp:317
TImageList * FBandImages
Definition coolbar.h:159
bool ToggleBandBorders()
Definition coolbar.cpp:293
TPalette * FPalette
Definition coolbar.h:162
TColorScheme * FColorScheme
Definition coolbar.h:161
TCoolBar(TWindow *parent, int id, int x, int y, int w, int h, TModule *module=0)
Definition coolbar.cpp:31
bool ShouldDelete
Definition coolbar.h:160
virtual auto GetWindowClassName() -> owl::TWindowClassName
Definition coolbar.cpp:104
uint GetBandCount()
Definition coolbar.cpp:260
void SetupWindow()
Definition coolbar.cpp:113
TWindow * FBuddy
Definition coolbar.h:156
TImageList is a wrapper class for the ImageList common "control".
Definition imagelst.h:64
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TNotify is a thin wrapper around the NMHDR structure.
Definition commctrl.h:91
TPalette is the GDI Palette class derived from TGdiObject.
Definition gdiobjec.h:413
HPALETTE GetHandle() const
Returns the handle of the palette.
Definition gdiobjec.h:1222
void SetImageList(HIMAGELIST Images)
Definition commctrl.h:1797
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
The tagSIZE struct is defined as.
Definition geometry.h:234
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
virtual void SetParent(TWindow *newParent)
Sets the parent for the specified window by setting Parent to the specified new Parent window object.
Definition window.cpp:738
bool SetWindowPos(HWND hWndInsertAfter, const TRect &rect, uint flags)
Changes the size of the window pointed to by rect.
Definition window.h:2809
virtual bool Create()
Creates the window interface element to be associated with this ObjectWindows interface element.
Definition window.cpp:2399
int GetId() const
Returns Attr.Id, the ID used to find the window in a specified parent's child list.
Definition window.h:1881
TRect GetWindowRect() const
Gets the screen coordinates of the window's rectangle.
Definition window.h:2257
bool ModifyStyle(uint32 offBits, uint32 onBits, uint swpFlags=0)
Modifies the style bits of the window.
Definition window.cpp:3591
uint32 GetStyle() const
Gets the style bits of the underlying window or the 'Style' member of the attribute structure associa...
Definition window.cpp:3558
TResult SendMessage(TMsgId, TParam1=0, TParam2=0) const
Sends a message (msg) to a specified window or windows.
Definition window.cpp:3288
virtual void SetupWindow()
Performs setup following creation of an associated MS-Windows window.
Definition window.cpp:2575
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
Definition of class TCoolBar.
#define _T(x)
Definition cygwin.h:51
C++ Functor template implementation.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
@ AutoDelete
Definition gdibase.h:70
TIPtrArray< TCoolBand * > TCoolBandArray
Definition coolbar.h:78
#define GETOBJMFUNCTOR(T, type, memberFunc)
Definition property.h:623
#define PUTMFUNCTOR(T, type, memberFunc)
Definition property.h:617
#define GETPUTOBJMFUNCTOR(T, type, memberGet, memberPut)
Definition property.h:627
#define GETPUTMFUNCTOR(T, type, memberGet, memberPut)
Definition property.h:619
Definition of class TImageList, an ImageList Common Control wrapper.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
void InitializeCommonControls(uint controlFlags)
Wrapper for the Windows API function InitCommmonControlsEx.
Definition commctrl.cpp:19
unsigned long uint32
Definition number.h:34
LPARAM TParam2
Second parameter type.
Definition dispatch.h:55
WPARAM TParam1
First parameter type.
Definition dispatch.h:54
OWL_DIAGINFO
Definition animctrl.cpp:14
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
Definition of the TTooltip class and helper objects.