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
uihandle.cpp
Go to the documentation of this file.
1//----------------------------------------------------------------------------
2// ObjectWindows
3// Copyright (c) 1994, 1996 by Borland International, All Rights Reserved
4//
5//----------------------------------------------------------------------------
6#include <owl/pch.h>
7#include <owl/defs.h>
8#include <owl/uihelper.h>
9#include <owl/gdiobjec.h>
10
11#if defined(BI_MULTI_THREAD_RTL)
12#include <owl/thread.h>
13#endif
14
15namespace owl {
16
18
19
20struct THatchBrush
22 : public TLocalObject
23#endif
24{
25 THatchBrush():Brush(THatch8x8Brush::Hatch13F1)
26 {
27 }
28 ~THatchBrush()
29 {
30 }
31
32 THatch8x8Brush Brush;
33#if defined(BI_MULTI_THREAD_RTL)
34// TMRSWSection Lock;
35#endif
36};
37
38//
39// Static instance of the hatch brush
40//
41static THatchBrush& GetHatchBrush()
42{
43#if defined(BI_MULTI_THREAD_RTL)
45 return hatchBrush.Get();
46#else
47 static THatchBrush hatchBrush;
48 return hatchBrush;
49#endif
50};
51
52namespace
53{
54 //
55 // Ensure singleton initialization at start-up (single-threaded, safe).
56 //
57 THatchBrush& InitHashBrush = GetHatchBrush();
58}
59
60#if defined(BI_MULTI_THREAD_RTL)
61#define LOCKBRUSH //TMRSWSection::TLock Lock(GetHatchBrush().Lock);
62#else
63#define LOCKBRUSH
64#endif
65
66//
67/// Constructs a TUIHandle object for the specified frame, with eight grapples drawn
68/// in a hatched border and a default thickness of 5 pixels drawn to the inside.
69//
70TUIHandle::TUIHandle(const TRect& frame, uint style, int thickness)
71:
72 Frame(frame),
73 Style(style),
74 HandleBox(thickness, thickness)
75{
76}
77
78//
79/// Moves the rectangle relative to the values specified in dx and dy.
80//
81void
83{
84 Frame.Offset(dx, dy);
85}
86
87//
88/// Moves the rectangle to the given x and y coordinates.
89//
90void
91TUIHandle::MoveTo(int x, int y)
92{
93 Frame.Offset(x-Frame.left, y-Frame.top);
94}
95
96//
97/// Sets the size of the rectangle according to the measurements specified in w, the
98/// width, and h, the height.
99//
100void
102{
103 Frame.right = Frame.left + w;
104 Frame.bottom = Frame.top + h;
105}
106
107//
108/// Calculate the outside frame rectangle
109//
110/// GetBoundingRect returns a rectangle with the size adjusted according to the
111/// thickness. For example, if the handles are outside the rectangle,
112/// GetboundingRect returns a larger rectangle. The enum TStyle defines the
113/// positions of the handles (whether the handles are defined as HandlesIn or
114/// HandlesOut).
115TRect
117{
118 return (Style&HandlesOut) ? Frame.InflatedBy(HandleBox) : Frame;
119}
120
121//
122/// Compares a given point (point) to various parts of the rectangle. If the hit was
123/// outside the rectangle, HitTest returns Outside. If the hatched border handle of
124/// the rectangle was hit, returns MidCenter (inside). For any other hits, HitTest
125/// returns the location of the grapple that was hit. The enum TWhere defines the
126/// possible hit areas.
127//
130{
131 // Check first to see if point is a total miss
132 //
134 if (!outsideFrame.Contains(point))
135 return Outside;
136
137 // Next check to see if it is completely inside
138 //
139 TRect insideFrame = outsideFrame.InflatedBy(-HandleBox);
140 if (insideFrame.Contains(point))
141 return (Style & InsideSpecial) ? Inside : MidCenter;
142
143 // If no grapple are used, hit must be in move area
144 //
145 if (!(Style & Grapples))
146 return MidCenter;
147
148 // Determine which of the handles was hit. Calulate X and then Y parts
149 //
150 int where;
151 TPoint halfHandle(HandleBox.x/2, HandleBox.y/2);
152 if (point.x < insideFrame.left)
153 where = 0; //Left;
154 else if (point.x >= insideFrame.right)
155 where = 2; //Right;
156 else {
157 int center = insideFrame.left + insideFrame.Width()/2;
158 if (point.x >= center-halfHandle.x && point.x <= center+halfHandle.x)
159 where = 1; //Center;
160 else
161 return MidCenter;
162 }
163 if (point.y < insideFrame.top)
164 where += 0; //Top;
165 else if (point.y >= insideFrame.bottom)
166 where += 6; //Bottom;
167 else {
168 int middle = insideFrame.top + insideFrame.Height()/2;
169 if (point.y >= middle-halfHandle.y && point.y <= middle+halfHandle.y)
170 where += 3; //Middle;
171 else
172 return MidCenter;
173 }
174 return (TWhere)where;
175}
176
177//
178/// Helper function to convert a where code into a cursor shape Id
179//
180/// Returns the ID of a standard cursor that is appropriate for use over the
181/// location specified in the where parameter.
182//
183uint16
185{
186 static uint16 cursorId[] = {
187 32642, 32645, 32643, // SIZENWSE, SIZENS, SIZENESW
188 32644, 32512, 32644, // SIZEWE, ARROW, SIZEWE,
189 32643, 32645, 32642, // SIZENESW, SIZENS, SIZENWSE
190 };
191 if (where == Outside)
192 return 0;
193 if (where == Inside)
194 return 32513; // IBEAM
195 return cursorId[where];
196}
197
198//
199/// Paints the TUIHandle object onto the specified device context, dc.
200//
201void
203{
205
206 // Draw a frame rect outside of Frame if indicated by the style
207 //
208 if (Style & (Framed | DashFramed)) {
209 int oldRop2 = dc.GetROP2();
210 dc.SetROP2(R2_XORPEN);
211 TRect frame = Frame;
212 if (Style & Framed) {
214 dc.FrameRect(frame, frameBr);
215 }
216 else {
221 dc.Rectangle(frame);
222 dc.RestorePen();
223 }
224// dc.DrawFocusRect(Frame); // a useful dotted rect frame...
225 if (!(Style&HandlesOut))
226 outerRect.Inflate(-1, -1);
227 dc.SetROP2(oldRop2);
228 }
229
230 // Calculate the grapple box rectangle and the midpoint handle topleft offsets
231 //
232 TPoint grappleBox = (Style & Grapples) ? HandleBox : TPoint(0, 0);
233 int center = outerRect.Width()/2 - grappleBox.x/2;
234 int middle = outerRect.Height()/2 - grappleBox.y/2;
235
236 // Draw the 8 grapples if indicated by the style
237 //
238 if (Style & Grapples) {
239 const uint32 rop = DSTINVERT;
240 dc.PatBlt(outerRect.left, outerRect.top,
242 dc.PatBlt(outerRect.left+center, outerRect.top,
244 dc.PatBlt(outerRect.right-HandleBox.x, outerRect.top,
246
247 dc.PatBlt(outerRect.left, outerRect.top+middle,
249 dc.PatBlt(outerRect.right-HandleBox.x, outerRect.top+middle,
251
252 dc.PatBlt(outerRect.left, outerRect.bottom-HandleBox.y,
254 dc.PatBlt(outerRect.left+center, outerRect.bottom-HandleBox.y,
256 dc.PatBlt(outerRect.right-HandleBox.x, outerRect.bottom-HandleBox.y,
258 }
259
260 // Draw the hatched border or whole rect if indicated by the style
261 //
262 if (Style & (HatchBorder | HatchRect)) {
263 const uint32 rop = PATINVERT; // opposite color rop: 0x00A000C9L;
264 LOCKBRUSH //
265 dc.SelectObject(GetHatchBrush().Brush); //CQ set brush origin?
266 if (Style & HatchBorder) {
267 int center2 = outerRect.Width() - center - grappleBox.x;
268 int middle2 = outerRect.Height() - middle - grappleBox.y;
269
270 dc.PatBlt(outerRect.left+grappleBox.x, outerRect.top,
271 center-grappleBox.x, HandleBox.y, rop);
273 center2-grappleBox.x, HandleBox.y, rop);
274
275 dc.PatBlt(outerRect.left, outerRect.top+HandleBox.y,
276 HandleBox.x, middle-HandleBox.y, rop);
278 HandleBox.x, middle2-HandleBox.y, rop);
279
280 dc.PatBlt(outerRect.right-HandleBox.x, outerRect.top+HandleBox.y,
281 HandleBox.x, middle-HandleBox.y, rop);
282 dc.PatBlt(outerRect.right-HandleBox.x, outerRect.top+middle+grappleBox.y,
283 HandleBox.x, middle2-HandleBox.y, rop);
284
285 dc.PatBlt(outerRect.left+grappleBox.x, outerRect.bottom-HandleBox.y,
286 center-grappleBox.x, HandleBox.y, rop);
287 dc.PatBlt(outerRect.left+center+grappleBox.x, outerRect.bottom-HandleBox.y,
288 center2-grappleBox.x, HandleBox.y, rop);
289 }
290 else {
291 dc.PatBlt(outerRect, rop);
292 }
293 dc.RestoreBrush();
294 }
295}
296
297} // OWL namespace
298/* ========================================================================== */
299
The GDI Brush class is derived from TGdiObject.
Definition gdiobjec.h:180
static const TColor White
Static TColor object with fixed Value set by RGB(255, 255, 255).
Definition color.h:314
static const TColor Black
Static TColor object with fixed Value set by RGB(0, 0, 0).
Definition color.h:305
TDC is the root class for GDI DC wrappers.
Definition dc.h:64
bool FrameRect(int x1, int y1, int x2, int y2, const TBrush &brush)
Draws a border on this DC around the given rectangle, rect, using the given brush,...
Definition dc.h:1781
void SelectObject(const TBrush &brush)
Selects the given GDI brush object into this DC.
Definition dc.cpp:113
void RestorePen()
Restores the original GDI pen object to this DC.
Definition dc.cpp:220
int SetROP2(int mode)
Sets the current foreground mix mode mode of this DC to the given mode value and returns the previous...
Definition dc.h:1180
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
bool Rectangle(int x1, int y1, int x2, int y2)
Draws and fills a rectangle of the given size on this DC with the current pen and brush objects.
Definition dc.h:2298
void RestoreBrush()
Restores the original GDI brush object to this DC.
Definition dc.cpp:233
virtual void SelectStockObject(int index)
Selects into the DC a predefined stock pen, brush, font, or palette.
Definition dc.cpp:206
bool PatBlt(int x, int y, int w, int h, uint32 rop=PATCOPY)
Definition dc.h:2448
int GetROP2() const
Returns the current drawing (raster operation) mode of this DC.
Definition dc.h:1147
TPen is derived from TGdiObject.
Definition gdiobjec.h:138
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 & Offset(int dx, int dy)
Changes this rectangle so its corners are offset by the given delta values.
Definition geometry.cpp:114
TRect InflatedBy(int dx, int dy) const
Returns a rectangle inflated by the given delta arguments.
Definition geometry.h:1281
void Paint(TDC &dc) const
Paints the TUIHandle object onto the specified device context, dc.
Definition uihandle.cpp:202
void MoveTo(int x, int y)
Moves the rectangle to the given x and y coordinates.
Definition uihandle.cpp:91
static uint16 GetCursorId(TWhere where)
Helper function to convert a where code into a cursor shape Id.
Definition uihandle.cpp:184
TWhere
Enumeration describing the location of a grapple selection.
Definition uihelper.h:212
@ Outside
Hit completely outside the object.
Definition uihelper.h:222
@ MidCenter
Somewhere inside the rectangle.
Definition uihelper.h:217
@ Inside
Hit inside object, not on handles, & InsideSpecial is set.
Definition uihelper.h:223
void Size(int w, int h)
Sets the size of the rectangle according to the measurements specified in w, the width,...
Definition uihandle.cpp:101
TUIHandle(const TRect &frame, uint style=HandlesIn|Grapples|HatchBorder, int thickness=5)
Constructs a TUIHandle object for the specified frame, with eight grapples drawn in a hatched border ...
Definition uihandle.cpp:70
void Move(int dx, int dy)
Moves the rectangle relative to the values specified in dx and dy.
Definition uihandle.cpp:82
TRect GetBoundingRect() const
Calculate the outside frame rectangle.
Definition uihandle.cpp:116
@ Grapples
Eight grapple boxes are drawn.
Definition uihelper.h:238
@ DashFramed
Frame rect is drawn dashed.
Definition uihelper.h:237
@ HandlesOut
Handles on the outside of the rectangle.
Definition uihelper.h:235
@ HatchRect
Whole rect drawn hatched.
Definition uihelper.h:240
@ HatchBorder
Border handle area drawn hatched.
Definition uihelper.h:239
@ Framed
Frame rect is drawn solid.
Definition uihelper.h:236
@ InsideSpecial
Inside area hit-tested independently.
Definition uihelper.h:241
TWhere HitTest(const TPoint &point) const
Compares a given point (point) to various parts of the rectangle.
Definition uihandle.cpp:129
Definition of abstract GDI object class and derived classes.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
OWL_DIAGINFO
Definition animctrl.cpp:14
unsigned short uint16
Definition number.h:33
General definitions used by all ObjectWindows programs.
#define LOCKBRUSH
Definition uiface.cpp:78
Definition of the UI Helper Classes: TUIHandle, TUIBorder, TUIFace, TUIPart.