OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
controlg.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1992, 1996 by Borland International, All Rights Reserved
4//
5/// \file
6/// Implementation of class TControlGadget.
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9
10#include <owl/controlg.h>
11#include <owl/gadgetwi.h>
12#include <owl/tooltip.h>
13
14namespace owl {
15
18
19//
20/// Creates a TControlGadget object associated with the specified TControl window.
21//
23:
24 TGadget(control.GetId(), border)
25{
26 Control = &control;
27 Control->ModifyStyle(0, WS_CLIPSIBLINGS); // Make sure relayout paints OK
28 TRACEX(OwlGadget, OWL_CDLEVEL, "TControlGadget constructed @" << (void*)this);
29}
30
31//
32/// Destroys a TControlGadget object and removes it from the associated window.
33//
35{
36 if(Control)
37 Control->Destroy(0);
38 delete Control;
39 TRACEX(OwlGadget, OWL_CDLEVEL, "TControlGadget destructed @" << (void*)this);
40}
41
42//
43/// Sets the visibility of this gadget and the encapsulated control.
44//
46{
48 auto c = GetControl();
49 if (c)
50 c->ShowWindow(visible ? SW_SHOW : SW_HIDE);
51}
52
53//
54/// Calls TGadget::SetBounds and passes the dimensions of the control gadget's
55/// rectangle. SetBounds informs the control gadget of a change in its bounding
56/// rectangle.
57//
58void
60{
61 TRACEX(OwlGadget, 1, "TControlGadget::SetBounds() enter @" << (void*)this <<
62 " bounds = " << bounds);
63
64 // Set the gadget bounds, then move & repaint the control
65 //
67 Control->SetWindowPos(nullptr, Bounds, SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOSIZE);
68
69 TRACEX(OwlGadget, 1, "TControlGadget::SetBounds() leave @" << (void*)this <<
70 " bounds = " << bounds);
71}
72
73//
74/// Calls TGadget::GetDesiredSize and passes the size of the control gadget. Use
75/// GetDesiredSize to find the size the control gadget needs to be in order to
76/// accommodate the borders and margins as well as the highest and widest control
77/// gadget.
78//
79void
81{
82 TRACEX(OwlGadget, 1, "TControlGadget::GetDesiredSize() enter @" << (void*)this <<
83 " size = " << size);
85
86 // !CQ get from Handle if created?
87 if(Control->GetHandle()){
88 TRect rect = Control->GetWindowRect();
89 if (ShrinkWrapWidth)
90 size.cx += rect.Width();
91 if (ShrinkWrapHeight)
92 size.cy += rect.Height();
93 }
94 else{
95 if (ShrinkWrapWidth)
96 size.cx += Control->GetWindowAttr().W;
97 if (ShrinkWrapHeight)
98 size.cy += Control->GetWindowAttr().H;
99 }
100 TRACEX(OwlGadget, 1, "TControlGadget::GetDesiredSize() leave @" << (void*)this <<
101 " size = " << size);
102}
103
104//
105/// Virtual called after the window holding a gadget has been created
106//
107void
109{
111 PRECONDITION(GetGadgetWindow()->GetHandle());
112
113 // Create control is necessary
114 //
115 Control->SetParent(GetGadgetWindow());
116 if (GetGadgetWindow()->GetHandle() && !Control->GetHandle()) {
117 Control->Create();
118 Control->ShowWindow(SW_SHOWNA);
119 }
120
121 // Register control with the tooltip window (if there's one)
122 //
124 if (tooltip) {
125 CHECK(tooltip->GetHandle());
126
127 // Register the control with the tooltip
128 //
129 if (Control->GetHandle()) {
130 TToolInfo toolInfo(GetGadgetWindow()->GetHandle(), Control->GetHandle());
131 tooltip->AddTool(toolInfo);
132 }
133 }
134}
135
136//
137/// Called when the control gadget is inserted in the parent window. Displays the
138/// window in its current size and position.
139//
140/// Override the Inserted() virtual to take the oportunity to make sure that the
141/// control window has been created and shown
142//
143void
145{
146 TRACEX(OwlGadget, 1, "TControlGadget::Inserted @" << (void*)this);
147 Control->SetParent(GetGadgetWindow());
148
149 if (GetGadgetWindow()->GetHandle())
150 {
151 if (!Control->GetHandle())
152 {
153 Control->Create();
154 }
155
156 Control->ShowWindow(SW_SHOWNA);
157 }
158}
159
160//
161/// Called when the control gadget is removed from the parent window.
162//
163/// Override the Remove() virtual to take the oportunity to unparent the
164/// control window from the owning Window
165//
166void
168{
169 TRACEX(OwlGadget, 1, "TControlGadget::Removed @" << (void*)this);
170 Control->ShowWindow(SW_HIDE); // Sirma Update
171 Control->SetParent(nullptr);
172 // Should we destroy the control at this point??
173 // Since it's no longer in the parent's child-list, there's a potential
174 // leak. However, the semantics of this function is 'Removed' - therefore
175 // one could be removing the control to be reinserted in another
176 // gadgetwindow.
177
178 // Unregister ourself with the tooltip window (if there's one)
179 //
180 if (GetGadgetWindow() && GetGadgetWindow()->GetHandle()) {
182 if (tooltip) {
183 CHECK(tooltip->GetHandle());
184
185 TToolInfo toolInfo(GetGadgetWindow()->GetHandle(), Control->GetHandle());
186 tooltip->DeleteTool(toolInfo);
187 }
188 }
189}
190
191//
192/// Invalidate a rectangle within this gadget by invalidating the rect in the
193/// control window in addition to the owning Window
194//
195void
197{
199 if (Control->GetHandle())
200 Control->InvalidateRect(rect, erase);
201}
202
203//
204/// Updates the client area of the specified window by immediately sending a
205/// WM_PAINT message.
206//
207void
209{
210 if (Control->GetHandle())
211 Control->UpdateWindow();
212}
213
214
215} // OWL namespace
216/* ========================================================================== */
#define CHECK(condition)
Definition checks.h:239
#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
void SetBounds(const TRect &) override
Calls TGadget::SetBounds and passes the dimensions of the control gadget's rectangle.
Definition controlg.cpp:59
TWindow * GetControl() const
Return the control that is simulating a gadget.
Definition controlg.h:80
void Inserted() override
Called when the control gadget is inserted in the parent window.
Definition controlg.cpp:144
void InvalidateRect(const TRect &rect, bool erase=true)
Invalidate a rectangle within this gadget by invalidating the rect in the control window in addition ...
Definition controlg.cpp:196
void Created() override
Virtual called after the window holding a gadget has been created.
Definition controlg.cpp:108
TControlGadget(TWindow &control, TBorderStyle=None)
Creates a TControlGadget object associated with the specified TControl window.
Definition controlg.cpp:22
void Removed() override
Called when the control gadget is removed from the parent window.
Definition controlg.cpp:167
void SetVisible(bool visible) override
Sets the visibility of this gadget and the encapsulated control.
Definition controlg.cpp:45
void Update()
Updates the client area of the specified window by immediately sending a WM_PAINT message.
Definition controlg.cpp:208
void GetDesiredSize(TSize &) override
Calls TGadget::GetDesiredSize and passes the size of the control gadget.
Definition controlg.cpp:80
~TControlGadget() override
Destroys a TControlGadget object and removes it from the associated window.
Definition controlg.cpp:34
TGadget is the base class for the following derived gadget classes:
Definition gadget.h:120
void InvalidateRect(const TRect &rect, bool erase=true)
Invalidate a rectangle in our containing window.
Definition gadget.cpp:392
TGadgetWindow * GetGadgetWindow()
Return a pointer to the owning or parent window for the gadget.
Definition gadget.h:536
virtual void SetBounds(const TRect &rect)
Called by the gadget window to inform the gadget of a change in its bounding rectangle.
Definition gadget.cpp:211
TBorderStyle
Gadget border styles.
Definition gadget.h:127
virtual void SetVisible(bool visible)
Changes the visibility of the gadget.
Definition gadget.h:466
virtual void GetDesiredSize(TSize &size)
Request by the gadget window to query the gadget's desired size.
Definition gadget.cpp:479
auto GetTooltip() const -> TTooltip *override
Returns Tooltip.
Definition gadgetwi.h:430
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
The tagSIZE struct is defined as.
Definition geometry.h:234
TToolInfo contains information about a particular tool (a tool is either a window or an application-d...
Definition tooltip.h:35
TTooltip encapsulates a tooltip window - i.e.
Definition tooltip.h:175
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 void Destroy(int retVal=0)
Destroys an MS-Windows element associated with the TWindow.
Definition window.cpp:2160
virtual bool Create()
Creates the window interface element to be associated with this ObjectWindows interface element.
Definition window.cpp:2399
virtual void InvalidateRect(const TRect &rect, bool erase=true)
Invalidates a specified client area.
Definition window.h:2834
TWindowAttr & GetWindowAttr()
Returns the TWindowAttr structure, which contains the window's creation attributes.
Definition window.h:1886
void GetWindowRect(TRect &rect) const
Gets the screen coordinates of the window's rectangle and copies them into rect.
Definition window.cpp:3609
bool ModifyStyle(uint32 offBits, uint32 onBits, uint swpFlags=0)
Modifies the style bits of the window.
Definition window.cpp:3591
void UpdateWindow()
Updates the client area of the specified window by immediately sending a WM_PAINT message.
Definition window.h:2901
virtual bool ShowWindow(int cmdShow)
Displays this TWindow in a given state.
Definition window.cpp:3713
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
Class TControlGadget definition.
Definition of TGadgetList, TGadgetWindow & TGadgetWindowFont A list holding gadgets,...
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
OWL_DIAGINFO
Definition animctrl.cpp:14
#define OWL_CDLEVEL
Definition defs.h:171
int W
width of the window
Definition window.h:341
int H
height of the window
Definition window.h:342
Definition of the TTooltip class and helper objects.