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
floatfra.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 TFloatingFrame, a popup frame window that has a
7/// small title bar
8//----------------------------------------------------------------------------
9#include <owl/pch.h>
10#include <owl/floatfra.h>
11#include <owl/uimetric.h>
12
13using namespace std;
14
15namespace owl {
16
19
20
21//
22// Order is very important. Must make sure that TTinyCaption gets 1st crack
23// after us
24//
25DEFINE_RESPONSE_TABLE2(TFloatingFrame, TTinyCaption, TFrameWindow)
34
35//
36/// Constructs a TFloatingFrame object attached to the specified parent window. By
37/// default, the floating frame window doesn't shrink to fit the client window, and
38/// the floating palette style isn't enabled.
39/// Set popupPalette to true if you want to enable a floating palette style for the
40/// window. The floating palette is a popup window with a tiny caption, a standard
41/// window border, and a close box instead of a system menu box. There are no
42/// maximize or minimize buttons. A one pixel border is added around the client area
43/// in case a toolbox is implemented. This style must be turned on before the window
44/// is created. After the window is created, its style can't be changed.
45//
49 bool popupPalette, TModule* module)
50:
53 Margin(2, 2),
54 DragFrame(popupPalette)
55{
57}
58
59//
60/// String-aware overload
61//
64 const tstring& title,
66 bool shrinkToClient,
67 int captionHeight,
68 bool popupPalette,
69 TModule* module
70 )
73 Margin(2, 2),
74 DragFrame(popupPalette)
75{
77}
78
80{
81 if (popupPalette) {
83
84 // Use close box (true) for palettes, & calc dimensions w/ new styles
85 //
87
88 // Windows with a popup style ignore CW_USEDEFAULT style, so we will
89 // specify a default size
90 //
91 // Normal use will be to specify a client and allow frame to sizeToClient
92 // so this size will rarely be used.
93 //
94 Attr.X = Attr.Y = 0;
95 Attr.W = 100;
96 Attr.H = 50;
97 }
98 else
99 // No close box for this non-popupPalette style
100 //
102
103 // Assume we should look active since our app just created us.
104 // !CQ Could be a problem if our app is not active. Would have to wait until
105 // !CQ SetupWindow and then see if the Focus belonged to this app.
106 //
107 AppearActive = true;
108
109 // The only area exposed when erasing will be the caption, so use an
110 // inactive-caption color so that full-drag over paints the right color
111 //
113}
114
115//
116// Floating frames never route commands down to their children--just bubble it
117// up to the parent.
118//
119HWND
121{
122 TRACEX(OwlCmd, 1, "TFloatingFrame::GetCommandTarget - returns "
123 << (GetParentO() ? static_cast<void*>(GetParentO()->GetHandle()) : 0));
124 return GetParentO() ? HWND(*GetParentO()) : HWND(nullptr);
125}
126
127//
128// Change the receiver to be the framewindow not the floating frame window.
129//
130void
132{
133 if (GetParentO()) {
134 // Already being processed?
135 //
136 if (!commandEnabler.IsReceiver(GetParentO()->GetHandle())) {
137 // No, so forward it up to our parent
138 //
139 commandEnabler.SetReceiver(GetParentO()->GetHandle());
141 }
142 }
143}
144
145//
146/// Resolves ambiguous mixin reference by passing EvCommand first to the tiny
147/// caption and then to the frame bases.
148//
159
160//
161/// This is an example of a mix-in that does partial event handling. This function
162/// calls the 'do' function for the mixin instead of the 'Ev' function, to avoid
163/// duplicate default processing.
164//
165void
167{
169 return;
171
172 // Now we need to undo the activation that SysCommand/Size or Move has done
173 // to us. This does result in some flicker since we've already painted, but
174 // it would require more work to simulate the size/move to avoid the
175 // activation.
176 //
177 if ((cmdType & 0xFFF0) == SC_SIZE || (cmdType & 0xFFF0) == SC_MOVE)
179}
180
181//
182/// Handles WM_NCCALCSIZE to possibly add in the drag frame margins.
183//
184uint
186{
188
189 // Adjust margins for extra edge around palette
190 //
191 if (DragFrame && !IsIconic()) {
192 calcSize.rgrc[0].left += Margin.cx * TUIMetric::CxBorder;
193 calcSize.rgrc[0].top += Margin.cy * TUIMetric::CyBorder;
194 calcSize.rgrc[0].right -= Margin.cx * TUIMetric::CxBorder;
195 calcSize.rgrc[0].bottom -= Margin.cy * TUIMetric::CyBorder;
196 }
197
198 // Now invoke the TTinyCaption worker method to do the rest of the
199 // calculations
200 //
202
203 return er;
204}
205
206//
207/// Handles WM_NCPAINT to paint the non-client areas of this window.
208/// Implementation: This function only needs to paint the drag frame margins.
209/// TWindow (via DefWindowProc) automatically paints the borders, and TTinyCaption
210/// automatically paints the caption.
211//
213{
214 DefaultProcessing(); // Default border painting--no caption
215
216 // Paint our caption below with possible fake active look. arg is ignored.
217 //
218 EvNCActivate(true);
219
220 // If enabled, paint drag frame margins in 3d face color
221 //
222 if (DragFrame) {
223 TWindowDC dc(*static_cast<TWindow*>(this)); // Cast is an MSVC bug workaround Jogy: Is the workaround still needed?
224 TRect wr = GetWindowRect().InflatedBy(-Frame);
225 wr -= wr.TopLeft();
226 wr += Border;
227 wr.top = GetCaptionRect().bottom;
228 int mx = Margin.cx * Border.cx;
229 int my = Margin.cy * Border.cy;
230
232 dc.TextRect(wr.left, wr.top, wr.left+mx, wr.bottom); // left
233 dc.TextRect(wr.left+mx, wr.top, wr.right-mx, wr.top+my); // top
234 dc.TextRect(wr.right-mx, wr.top, wr.right, wr.bottom); // right
235 dc.TextRect(wr.left+mx, wr.bottom-my, wr.right-mx, wr.bottom); // bottom
236 }
237}
238
239//
240/// Returns where in the non-client area the mouse is. Delegates to tiny caption
241/// for the caption bar area, and when in DragFrame mode, makes the frame act like a
242/// caption for dragging.
243//
244uint
253
254//
255/// If the floating palette is not enabled, returns esPartial. Otherwise, sends a
256/// message to the floating palette that the mouse or the cursor has moved, and
257/// returns esComplete.
258//
261{
262 if (DragFrame && TCEnabled) {
263 TPoint clientOffs(0,0);
265 if (!GetClientRect().Contains(screenPt-clientOffs)) {
267 return esComplete;
268 }
269 }
270 return esPartial;
271}
272
273//
274// Handle WM_NCMOUSEACTIVATE in order to decline activation. Also, in order to'
275// take care of the user trying to activate this app, we activate the main
276// window.
277//
278uint
279TFloatingFrame::EvMouseActivate(HWND /*hWndTopLevel*/, uint /*hitTestCode*/, TMsgId)
280{
281 // Make our main window active if the current active is not in this
282 // process
283 // !CQ could call SetForegroundWindow(), where is it ?
284 //
285 if (!GetActiveWindow())
287 //GetApplication()->GetMainWindow()->SetActiveWindow();//??????????????????
288
289 EvNCActivate(true); // Make sure we look active
290 return MA_NOACTIVATE;
291}
292
293//
294// Handle WM_NCACTIVATE to paint the caption with our notion of active
295// appearance--either with our own caption paint routine, or with underlying
296// classes routine.
297//
298// The caption will apear active as long as this app is active.
299//
300bool
302{
303 if (!IsIconic()) {
304 if (TCEnabled)
305 PaintCaption(AppearActive);
306 else
307 DefWindowProc(WM_NCACTIVATE, AppearActive, 0);
308 }
309 return true;
310}
311
312//
313// Handle WM_ACTIVATEAPP to know & track when to appear active--that is
314// whenever this app is activated
315//
316void
318{
319 AppearActive = active;
320
321 EvNCActivate(AppearActive);
323}
324
325
327
328#if OWL_PERSISTENT_STREAMS
329
330//
331//
332//
333void*
334TFloatingFrame::Streamer::Read(ipstream& is, uint32 /*version*/) const
335{
336 TFloatingFrame* o = GetObject();
339 is >> o->Margin;
340 return o;
341}
342
343//
344//
345//
346void
347TFloatingFrame::Streamer::Write(opstream& os) const
348{
349 TFloatingFrame* o = GetObject();
350 WriteBaseObject((TFrameWindow*)o, os);
351 WriteBaseObject((TTinyCaption*)o, os);
352 os << o->Margin;
353}
354
355#endif
356
357} // OWL namespace
358
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
#define TRACEX(group, level, message)
Definition checks.h:263
TFrameWindow * GetMainWindow()
Return the current main window.
Definition applicat.h:592
static const TColor SysInactiveCaption
The symbolic system color value for the caption background of every inactive window.
Definition color.h:327
static const TColor Sys3dFace
The symbolic system color value for the face color of 3-dimensional display elements.
Definition color.h:339
Base class for an extensible interface for auto enabling/disabling of commands (menu items,...
Definition window.h:209
bool TextRect(int x1, int y1, int x2, int y2)
Fills the given rectangle, clipping any text to the rectangle.
Definition dc.h:1878
virtual TColor SetBkColor(const TColor &color)
Sets the current background color of this DC to the given color value or the nearest available.
Definition dc.cpp:405
Derived from TFrameWindow and TTinyCaption, TFloatingFrame implements a floating frame that can be po...
Definition floatfra.h:52
void EvActivateApp(bool active, DWORD taskId)
Definition floatfra.cpp:317
void Init(int captionHeight, bool popupPalette)
Definition floatfra.cpp:79
void EvNCPaint(HRGN)
Handles WM_NCPAINT to paint the non-client areas of this window.
Definition floatfra.cpp:212
void EvCommandEnable(TCommandEnabler &) override
Definition floatfra.cpp:131
void EvSysCommand(uint cmdType, const TPoint &p)
This is an example of a mix-in that does partial event handling.
Definition floatfra.cpp:166
uint EvNCHitTest(const TPoint &screenPt)
Returns where in the non-client area the mouse is.
Definition floatfra.cpp:245
auto EvCommand(uint id, HWND hWndCtl, uint notifyCode) -> TResult override
Resolves ambiguous mixin reference by passing EvCommand first to the tiny caption and then to the fra...
Definition floatfra.cpp:150
TEventStatus DoNCHitTest(const TPoint &screenPt, uint &evRes)
Event handler helper.
Definition floatfra.cpp:260
auto GetCommandTarget() -> HWND override
Definition floatfra.cpp:120
uint EvNCCalcSize(bool calcValidRects, NCCALCSIZE_PARAMS &calcSize)
Handles WM_NCCALCSIZE to possibly add in the drag frame margins.
Definition floatfra.cpp:185
bool EvNCActivate(bool active)
Definition floatfra.cpp:301
TFloatingFrame(TWindow *parent, LPCTSTR title=0, TWindow *clientWnd=0, bool shrinkToClient=false, int captionHeight=DefaultCaptionHeight, bool popupPalette=false, TModule *module=0)
Constructs a TFloatingFrame object attached to the specified parent window.
Definition floatfra.cpp:46
uint EvMouseActivate(HWND hTopLevel, uint hitCode, TMsgId)
Definition floatfra.cpp:279
Derived from TWindow, TFrameWindow controls such window-specific behavior as keyboard navigation and ...
Definition framewin.h:96
auto EvCommand(uint id, HWND hWndCtl, uint notifyCode) -> TResult override
Handle WM_COMMAND to provide extra processing for commands: Extra processing for commands: starts wit...
Definition framewin.cpp:387
ObjectWindows dynamic-link libraries (DLLs) construct an instance of TModule, which acts as an object...
Definition module.h:75
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
TRect InflatedBy(int dx, int dy) const
Returns a rectangle inflated by the given delta arguments.
Definition geometry.h:1281
Derived from TWindow, TTinyCaption is a mix-in class that handles a set of non-client events to produ...
Definition tinycapt.h:63
void PaintCaption(bool active)
Calls dc.SelectObject() to select the given rectangle and dc.PatBlt() to paint the tiny caption bar u...
Definition tinycapt.cpp:720
TEventStatus DoSysCommand(uint cmdType, const TPoint &p)
Handle WM_SYSCOMMAND to make sure that SC_KEYMENU and SC_MOUSEMENU bring up our sys menu at the right...
Definition tinycapt.cpp:534
void EnableTinyCaption(int ch=0, bool closeBox=false)
Pass closeBox=true to replace SystemMenu box with a box that will close window when clicked Used for ...
Definition tinycapt.cpp:75
TEventStatus DoNCHitTest(const TPoint &screenPt, uint &evRes)
If the caption bar is not enabled, returns esPartial.
Definition tinycapt.cpp:139
TRect GetCaptionRect()
Gets the area of the caption for changing or repainting.
Definition tinycapt.cpp:817
TEventStatus DoCommand(uint id, HWND hWndCtl, uint notifyCode, TResult &evRes)
Displays the system menu using ::TrackPopup so that TTinyCaption sends WM_COMMAND instead of WM_SYSCO...
Definition tinycapt.cpp:492
TEventStatus DoNCCalcSize(bool calcValidRects, NCCALCSIZE_PARAMS &calcSize, uint &evRes)
Return the size of our client area, leaving room for caption bar.
Definition tinycapt.cpp:237
static const TUIMetric CyBorder
Definition uimetric.h:40
static const TUIMetric CxBorder
Definition uimetric.h:39
Derived from TDC, TWindowDC is a device context (DC) class that provides access to the entire area ow...
Definition dc.h:588
TWindow, derived from TEventHandler and TStreamableBase, provides window-specific behavior and encaps...
Definition window.h:414
static HWND GetActiveWindow()
Retrieves the handle of the active window.
Definition window.h:2702
TApplication * GetApplication() const
Gets a pointer to the TApplication object associated with this.
Definition window.h:1855
void SetBkgndColor(TColor color, bool shouldUpdate=true)
Sets the background color for the window.
Definition window.h:1925
virtual void EvCommandEnable(TCommandEnabler &ce)
Called by WindowProc to handle WM_COMMAND_ENABLE messages, EvCommandEnable calls the CmXxxx command-h...
Definition window.cpp:1135
TRect GetWindowRect() const
Gets the screen coordinates of the window's rectangle.
Definition window.h:2257
virtual TResult DefWindowProc(TMsgId, TParam1, TParam2)
Virtual function provides final default processing for an incoming message Calls original window proc...
Definition window.cpp:1237
TWindow * GetParentO() const
Return the OWL's parent for this window.
Definition window.h:2006
bool IsIconic() const
Returns true if window is iconic or minimized.
Definition window.h:2628
void ClientToScreen(TPoint &point) const
Converts the client coordinates specified in point to screen coordinates for the new window.
Definition window.h:2248
HWND SetActiveWindow()
Activates a top-level window.
Definition window.h:2712
uint EvNCHitTest(const TPoint &)
The default message handler for WM_NCHITTEST.
Definition window.h:3869
TResult DefaultProcessing()
Handles default processing of events, which includes continued processing of menu/accelerators comman...
Definition window.cpp:852
TRect GetClientRect() const
Gets the coordinates of the window's client area (the area in a window you can use for drawing).
Definition window.h:2217
void EvSysCommand(uint cmdType, const TPoint &point)
Responds to a user-selected command from the System menu or when the user selects the maximize or min...
Definition window.h:4014
virtual TResult EvCommand(uint id, HWND hWndCtl, uint notifyCode)
WindowProc calls EvCommand to handle WM_COMMAND messages.
Definition window.cpp:999
uint EvNCCalcSize(bool calcValidRects, NCCALCSIZE_PARAMS &)
The default message handler for WM_NCCALCSIZE.
Definition window.h:3855
HWND THandle
TWindow encapsulates an HWND.
Definition window.h:418
HWND GetHandle() const
Returns the handle of the window.
Definition window.h:2020
ipstream, a specialized input stream derivative of pstream, is the base class for reading (extracting...
Definition objstrm.h:391
#define DEFINE_RESPONSE_TABLE2(cls, base1, base2)
Macro to define a response table for a class with two bases.
Definition eventhan.h:506
Definition of class TFloatingFrame.
void ReadBaseObject(Base *base, ipstream &in)
Definition objstrm.h:1159
#define IMPLEMENT_STREAMABLE2(cls, base1, base2)
Definition objstrm.h:1726
void WriteBaseObject(Base *base, opstream &out)
Definition objstrm.h:1150
TEventStatus
Mixin window event implementation return status.
Definition window.h:107
@ esPartial
Additional handlers may be invoked.
Definition window.h:108
@ esComplete
No additional handlers are needed.
Definition window.h:109
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
EV_WM_NCCALCSIZE
Definition docking.cpp:963
UINT TMsgId
Message ID type.
Definition dispatch.h:53
EV_WM_NCHITTEST
Definition floatfra.cpp:29
EV_WM_MOUSEACTIVATE
Definition floatfra.cpp:30
EV_WM_SYSCOMMAND
Definition floatfra.cpp:26
EV_WM_ACTIVATEAPP
Definition floatfra.cpp:32
EV_WM_NCACTIVATE
Definition floatfra.cpp:31
OWL_DIAGINFO
Definition animctrl.cpp:14
EV_WM_NCPAINT
Definition docking.cpp:964
END_RESPONSE_TABLE
Definition button.cpp:26
LRESULT TResult
Result type.
Definition dispatch.h:52
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
Definition of TUIMetric, a UI metrics provider class.