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
uiface.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/// Implements TUIFace
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/defs.h>
10#include <owl/uihelper.h>
11#include <owl/gdiobjec.h>
12
13#if defined(BI_MULTI_THREAD_RTL)
14#include <owl/thread.h>
15#endif
16
17
18
19namespace owl {
20
22
23const long RopPSDPxax = 0x00B8074AL; //
24const long RopDSPDxax = 0x00E20746L; //
25
26struct TUIFaceData
28 : public TLocalObject
29#endif
30{
31 TUIFaceData()
33 DitherColor(TColor::Sys3dHilight)
34 {
35 }
36 ~TUIFaceData()
37 {
38 }
39
40 THatch8x8Brush& GetDitherBrush();
41 TBitmap& GetGlyphMask(const TSize& minSize);
42
43 THatch8x8Brush Brush;
44 TColor DitherColor;
45 TSize MaskSize; // Current mask size
46 TPointer<TBitmap> MaskBm; // Current mask bm
47
48#if defined(BI_MULTI_THREAD_RTL)
49// TMRSWSection Lock;
50#endif
51};
52
53//
54// Static instance of the colors
55//
56static TUIFaceData& GetUIFaceData()
57{
58#if defined(BI_MULTI_THREAD_RTL)
60 return uiFaceData.Get();
61#else
62 static TUIFaceData uiFaceData;
63 return uiFaceData;
64#endif
65};
66
67namespace
68{
69 //
70 // Ensure singleton initialization at start-up (single-threaded, safe).
71 //
72 TUIFaceData& InitUIFaceData = GetUIFaceData();
73}
74
75#if defined(BI_MULTI_THREAD_RTL)
76#define LOCKBRUSH //TMRSWSection::TLock Lock(GetUIFaceData().Lock);
77#else
78#define LOCKBRUSH
79#endif
80
81
82THatch8x8Brush& TUIFaceData::GetDitherBrush()
83{
85
86 // Reconstruct the brush in case the system colors have changed
87 // since the brush was constructed
88 //
89 if (DitherColor != TColor::Sys3dHilight) {
92 DitherColor = TColor::Sys3dHilight;
93 }
94 return Brush;
95}
96//
97TBitmap& TUIFaceData::GetGlyphMask(const TSize& minSize)
98{
100 // Start off with no bitmap, allocate below with requested or default size
101 //
102 // (Re)allocate mask bitmap if we need a bigger one
103 //
104 if (minSize.cx > MaskSize.cx || minSize.cy > MaskSize.cy) {
105 if (MaskSize.cx < minSize.cx)
106 MaskSize.cx = minSize.cx;
107 if (MaskSize.cy < minSize.cy)
108 MaskSize.cy = minSize.cy;
109 MaskBm = new TBitmap(MaskSize.cx, MaskSize.cy, 1, 1, nullptr);
110 }
111 return *MaskBm;
112}
113
114/// Internal static helper function that can be used alone.
115//
116/// Return a brush created using a hatched [checkerboard] pattern of the button
117/// highlight color. This brush is commonly used for rendering 'indeterminate'
118/// or 'mixed-value' appearances.
119///
120/// \note Automatically reconstructs the brush if the relevant system color
121/// changed during a session...
122//
123THatch8x8Brush&
125{
126 // Return ref. to static brush
127 //
128 return GetUIFaceData().GetDitherBrush();
129}
130
131/// Internal static helper function that can be used alone.
132//
133/// Return a reference to a static monochrome bitmap. The optional TSize
134/// pointer allows the routine to ensure that the bitmap is big enough for a
135/// given use.
136//
137TBitmap&
139{
140 return GetUIFaceData().GetGlyphMask(minSize);
141}
142
143/// Internal static helper function that can be used alone.
144//
145/// Build a monochrome mask bitmap for the glyph that has 1's where color
146/// maskedColor is and 0's everywhere else.
147///
148/// \note Assumes DC's are already setup - i.e. maskDC has the destination
149/// monochrome bitmap selected in it and glyphDC has the image selected
150/// in it..
151//
152void
154 TDC& glyphDC, const TRect& glyphRect,
155 const TColor& maskedColor)
156{
157 maskDC.PatBlt(0, 0, maskSize.cx, maskSize.cy, WHITENESS);
158 if (maskedColor != TColor::None) {
159 TColor bkColor = glyphDC.SetBkColor(maskedColor);
160 maskDC.BitBlt(maskDst.x, maskDst.y, glyphRect.Width(), glyphRect.Height(),
161 glyphDC, glyphRect.left, glyphRect.top, SRCCOPY);
162 glyphDC.SetBkColor(bkColor);
163 }
164}
165
166/// Internal static helper function that can be used alone.
167//
168/// Paint onto a given DC withing a given rect using a monochrome BM in a dc as
169/// a stencil and an arbitrary brush
170//
171void
185
186/// Internal static helper function that can be used alone.
187//
188/// Tiles the rectangle with a even dithered (checkerboard) pattern
189/// maskDC determines the stencil area of dither
190//
191void
196
197/// Internal static helper function that can be used alone.
198//
199/// An extension to ::DrawText that draws etched text by writing twice, the
200/// first one offset down & right in a light color, and the second not offset
201//
202int
203TUIFace::DrawTextEtched(TDC& dc, const tstring& str, int count,
204 const TRect& rect, uint16 format)
205{
206 int mode = dc.SetBkMode(TRANSPARENT);
208 int height = dc.DrawText(str, count, rect.OffsetBy(1, 1), format);
209 if (!(format & DT_CALCRECT)) {
211 height = dc.DrawText(str, count, rect, format);
212 }
214 dc.SetBkMode(mode);
215 return height;
216}
217
218//
219/// Internal bitmap painting function
220//
221void
223 TDC& dc, const TRect& faceRect, const TPoint& dstPoint,
224 TState state, bool pressed, bool fillFace,
225 const TColor& maskColor, const TColor& fillColor)
226{
227 // Select our glyph in a working memory DC.
228 //
230 memDC.SetTextColor(TColor::Black);
231 memDC.SetBkColor(TColor::White);
232
233 // Calculate the glyph's destination rect.
234 // Calculate the rect to fill in, depending on fill-face flag.
235 //
236 TRect glyphDstRect(faceRect.TopLeft() + dstPoint, glyphSrcRect.Size());
239
240 // When the glyph is down, offset it's origin one pixel to the lower right.
241 // Make sure the glyph rect doesn't hang outside the face.
242 //
243 if (pressed || state == Down) {
244 dstPt.Offset(1,1);
245 glyphDstRect.Offset(1,1);
247 }
248
249 // Build the mask. The mask is always the size of the face, while
250 // the glyph may be offset (given by dstPt) within the mask.
251 //
255
256 // Draw according the specified state.
257 //
258 if (state == Disabled)
259 {
260 // Convert the highlight color to 1's on the mask.
261 // This in effect makes all the highlighted (white) areas transparent
262 // and hence more readable.
263 //
264 memDC.SetBkColor(TColor::Sys3dHilight);
265 maskDC.BitBlt(glyphSrcRect, memDC, TPoint(0,0), SRCPAINT);
266
267 // Gray the image using the standard button shadow color.
268 // (glyphDstRect in dc <-- dstPt in maskDC)
269 //
274 dc.SetBkColor(bg);
275 }
276 else // not Disabled
277 {
278 // Do a transparent blit using the mask.
279 // (glyphDstRect in dc <-- glyphSrcRect.TopLeft in memDC/mask)
280 //
281 const uint32 DSTCOPY = 0x00AA0029; // Undocumented ROP
282 dc.MaskBlt
283 (
285 memDC, glyphSrcRect.TopLeft(),
286 mask, dstPt,
288 );
289 }
290
291 // Do any filling determined by the state and fill arguments.
292 //
293 if (state == Indeterm)
294 {
295 // Dither the background everywhere except where the glyph is.
296 // (faceRect in dc <-- masked dithering)
297 //
299 }
300 else if (fillFace && fillColor != TColor::None)
301 {
302 // Fill background around mask with given button face color.
303 // (faceRect in dc <-- masked fill)
304 //
307 }
308
309 maskDC.RestoreBitmap();
310}
311
312
313/// Internal static helper function that can be used alone.
314void
316 TDC& dc, const TRect& faceRect, const TPoint& dstPt,
317 TState state, bool pressed, bool fillFace,
318 const TColor& maskColor, const TColor& fillColor)
319{
320 // Note that this code will not work for a B/W icon!
321 //
322 const auto i = icon.GetInfo();
323 PaintBm(i.Color, glyphSrcRect,dc, faceRect, dstPt, state, pressed, fillFace,
325}
326
327//
328/// Internal static helper function that can be used alone.
329//
330void
332 const TPoint& dstPnt, TState state, bool pressed,
333 bool fillFace, const TColor& fillColor, uint16 format)
334{
337
338 int mode = dstDC.SetBkMode(fillFace ? OPAQUE : TRANSPARENT);
339
340 if(pressed || state == Down){
341 dstPt.Offset(1,1);
342 textDstRect.left++;
343 if(format & DT_CENTER)
344 textDstRect.left++;
345 textDstRect.top++;
346 if(format & DT_VCENTER)
347 textDstRect.top++;
348 }
349
350 // Draw according the specified state
351 //
352 switch (state) {
353
354 case Normal: {
356 if (fillFace){
357 bkColor = dstDC.SetBkColor(fillColor);
358 dstDC.TextRect(faceRect);
359 }
360 dstDC.DrawText(text,-1, textDstRect, format);
361 if (fillFace)
362 dstDC.SetBkColor(bkColor);
363 break;
364 }
365
366 case Down: {
367
368 dstDC.SetBkMode(TRANSPARENT);
369
370 TColor bkColor = dstDC.GetBkColor();
371 if (fillFace){
372 bkColor = dstDC.SetBkColor(fillColor);
373 if(pressed)
374 dstDC.TextRect(faceRect);
375 }
376
377 // Build a mask of the glyph & dither the background around the glyph
378 //
379 if(!pressed){
380
386 dstDC.DrawText(text, -1, textDstRect, format);
387 }
388 else
389 dstDC.DrawText(text, -1, textDstRect, format);
390
391 if (fillFace)
392 dstDC.SetBkColor(bkColor);
393 break;
394 }
395
396 case Indeterm: {
398 if (fillFace){
399 bkColor = dstDC.SetBkColor(fillColor);
400 dstDC.TextRect(faceRect);
401 }
402 dstDC.GrayString(TBrush(dstDC.GetTextColor()),nullptr,text, -1, textDstRect);
403 if (fillFace)
404 dstDC.SetBkColor(bkColor);
405 break;
406 }
407
408 case Disabled: {
410 if (fillFace){
411 bkColor = dstDC.SetBkColor(fillColor);
412 dstDC.TextRect(faceRect);
413 }
415 if (fillFace)
416 dstDC.SetBkColor(bkColor);
417 break;
418 }
419 case Default:
420 dstDC.DrawText(text,-1, textDstRect, format);
421 break;
422 }
423 dstDC.SetBkMode(mode);
424}
425
426//
427/// Paint the face of a button onto a DC.
428/// Assumes the entire bitmap is the face.
429//
430void
431TUIFace::Paint(TDC& dc, const TPoint& pt, TState state, bool pressed,
432 bool fillFace)
433{
434 if (SourceType==sText)
435 PaintText(Text, dc, Rect, pt, state, pressed, fillFace, FillColor, static_cast<uint16>(Format));
436 else if (SourceType==sBitmap)
437 PaintBm(*Bm, TRect(TPoint(0,0),Bm->Size()), dc, Rect, pt, state, pressed,
438 fillFace, BkgndColor, FillColor);
439 else if (SourceType==sIcon)
440 PaintIcon(*Icon, TRect(TPoint(0,0),Bm->Size()), dc, Rect, pt, state, pressed,
441 fillFace, BkgndColor, FillColor);
442}
443
444//
445/// Paint a portion of the source bitmap onto a DC.
446/// This allows one bitmap to be the source for multiple TUIFaces.
447//
448void
449TUIFace::Paint(TDC& dc, const TRect& srcRect, const TPoint& pt, TState state,
450 bool pressed, bool fillFace)
451{
452 if (SourceType==sText)
453 PaintText(Text, dc, Rect, pt, state, pressed, fillFace, FillColor, static_cast<uint16>(Format));
454 else if (SourceType==sBitmap)
455 PaintBm(*Bm, srcRect, dc, Rect, pt, state, pressed,
456 fillFace, BkgndColor, FillColor);
457 else if (SourceType==sIcon)
458 PaintIcon(*Icon, srcRect, dc, Rect, pt, state, pressed,
459 fillFace, BkgndColor, FillColor);
460}
461
462#if !defined(BI_COMP_GNUC)
463#pragma warn -par
464#endif
465//
466/// Encapsulates and emulate the 32-bit DrawState API.
467//
468bool
470 int x, int y, int cx, int cy, uint flags)
471{
472 static bool hasDrawState = true;
473
474 // Try once to see if the API call is available. If not, do ourselves.
475 //
476 if (hasDrawState) {
477 if (::DrawState(dc, hbr, nullptr, lp, wp, x, y, cx, cy, flags))
478 return true;
479 if (::GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
480 hasDrawState = false; // No DrawState(). Don't try again, just emulate
481 else
482 return false; // Some other error, just return
483 }
484
485 return false;
486}
487#if !defined(BI_COMP_GNUC)
488#pragma warn .par
489#endif
490
491/// Internal static helper function that can be used alone.
492//
493// !CQ needs updating
494/// Paint the mask onto a DC.
495//
496void
498 const TColor& maskColor)
499{
500 // Create a DC to hold the image bitmap
501 //
503 memDC.SelectObject(glyph);
504
505 // Create a DC to hold an "AND mask" of image and build the mask
506 //
508 maskDC.SelectObject(GetGlyphMask(glyph.Size()));
509
510 // Rectangle to hold mask of glyph
511 //
512 TRect maskRect(TPoint(0,0), glyph.Size());
513
514 // Build the mask
515 //
517
518 // Make sure area under highlight color ends up fill color
519 //
520 // dc.TextRect(maskRect, FillColor);
521
522 // Inactivate mask--convert the highlight color to 1's on existing mask
523 //
524 memDC.SetBkColor(TColor::Sys3dHilight);
525 maskDC.BitBlt(maskRect, memDC, maskRect.TopLeft(), SRCPAINT);
526
527 dc.BitBlt(TRect(pt, maskRect.Size()), maskDC, TPoint(0,0));
528}
529
530//
531/// Paint the mask onto a DC.
532//
533void
535{
536 // ::DrawState()...
537
538 if(SourceType==sBitmap)
539 PaintMaskBm(*Bm, dc, pt, BkgndColor);
540 //else if (SourceType==sText)
541 // PaintMaskText(Text, dc, pt);
542}
543
544
545} // OWL namespace
546/* ========================================================================== */
TBitmap is the GDI bitmap class derived from TGdiObject.
Definition gdiobjec.h:510
TSize Size() const
The width and height of the bitmap in pixels.
Definition bitmap.cpp:300
The GDI Brush class is derived from TGdiObject.
Definition gdiobjec.h:180
Class wrapper for management of color values.
Definition color.h:245
static const TColor Sys3dHilight
The symbolic system color value for highlighted 3-dimensional display elements (for edges facing the ...
Definition color.h:344
static const TColor None
not-a-color
Definition color.h:318
static const TColor Sys3dShadow
The symbolic system color value for the shadow regions of 3-dimensional display elements (for edges f...
Definition color.h:340
static const TColor Sys3dFace
The symbolic system color value for the face color of 3-dimensional display elements.
Definition color.h:339
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
void SelectObject(const TBrush &brush)
Selects the given GDI brush object into this DC.
Definition dc.cpp:113
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
void RestoreBrush()
Restores the original GDI brush object to this DC.
Definition dc.cpp:233
bool BitBlt(int dstX, int dstY, int w, int h, const TDC &srcDC, int srcX, int srcY, uint32 rop=SRCCOPY)
Performs a bit-block transfer from srcDc (the given source DC) to this DC (the destination DC).
Definition dc.h:2421
virtual TColor SetTextColor(const TColor &color)
Sets the current text color of this DC to the given color value.
Definition dc.cpp:417
int SetBkMode(int mode)
Sets the background mode to the given mode argument, which can be either OPAQUE or TRANSPARENT.
Definition dc.h:1116
bool MaskBlt(const TRect &dst, const TDC &srcDC, const TPoint &src, const TBitmap &maskBm, const TPoint &maskPos, uint32 rop=SRCCOPY)
Copies a bitmap from the given source DC to this DC.
Definition dc.h:2576
int DrawText(const tstring &str, int count, const TRect &, uint16 format=0)
Overload for const TRect& For obvious reasons, this overload does not support the DT_CALCRECT format ...
Definition dc.cpp:653
Derived from TBrush, THatch8x8Brush defines a small, 8x8, monochrome, configurable hatch brush.
Definition gdiobjec.h:250
static const uint8 Hatch11F1[8]
The static array Hatch11F1[8] holds the logical hatched brush pattern of one pixel on and one pixel o...
Definition gdiobjec.h:272
void Reconstruct(const uint8 hatch[], const TColor &fgColor, const TColor &bgColor)
Reconstructs the hatched brush with a new pattern or new set of colors.
Definition brush.cpp:463
TIcon, derived from TGdiObject, represents the GDI object icon class.
Definition gdiobjec.h:670
A device context (DC) class derived from TCreatedDC, TMemoryDC provides access to a memory DC.
Definition dc.h:784
TPoint is a support class, derived from tagPOINT.
Definition geometry.h:87
TRect is a mathematical class derived from tagRect.
Definition geometry.h:308
The tagSIZE struct is defined as.
Definition geometry.h:234
static TBitmap & GetGlyphMask(const TSize &minSize)
Internal static helper function that can be used alone.
Definition uiface.cpp:138
void PaintMask(TDC &dc, const TPoint &pt)
Paint the mask onto a DC.
Definition uiface.cpp:534
static bool Draw(TDC &dc, HBRUSH hbr, LPARAM lp, WPARAM wp, int x, int y, int cx, int cy, uint flags)
Encapsulates and emulate the 32-bit DrawState API.
Definition uiface.cpp:469
static THatch8x8Brush & GetDitherBrush()
Internal static helper function that can be used alone.
Definition uiface.cpp:124
static int DrawTextEtched(TDC &dc, const tstring &str, int count, const TRect &rect, uint16 format)
Internal static helper function that can be used alone.
Definition uiface.cpp:203
static void PaintMaskBm(const TBitmap &glyph, TDC &dc, const TPoint &pt, const TColor &maskColor)
Internal static helper function that can be used alone.
Definition uiface.cpp:497
static void FillBackground(TDC &dc, TDC &maskDC, const TRect &dstRect, const TBrush &brush)
Internal static helper function that can be used alone.
Definition uiface.cpp:172
static void DitherBackground(TDC &dc, TDC &maskDC, const TRect &dstRect)
Internal static helper function that can be used alone.
Definition uiface.cpp:192
TState
Enumeration describing the state of the bitmap to be drawn.
Definition uihelper.h:372
@ Disabled
Disabled or Unavailable state (embossed 3d no color)
Definition uihelper.h:376
@ Indeterm
Indeterminant, or mixed-value state.
Definition uihelper.h:375
@ Default
Default btn state (bold)
Definition uihelper.h:377
@ Down
Down or Option set state (hilit background, +1,+1)
Definition uihelper.h:374
@ Normal
Normal state.
Definition uihelper.h:373
static void PaintText(const tstring &text, TDC &dc, const TRect &faceRect, const TPoint &dstPt, TState state, bool pressed, bool fillFace, const TColor &fillColor, uint16 format)
Internal static helper function that can be used alone.
Definition uiface.cpp:331
void Paint(TDC &dc, const TPoint &dstPt, TState state, bool pressed, bool fillFace=true)
Paint the face of a button onto a DC.
Definition uiface.cpp:431
static void PaintIcon(const TIcon &icon, const TRect &glyphSrcRect, TDC &dc, const TRect &faceRect, const TPoint &dstPt, TState state, bool pressed, bool fillFace, const TColor &maskColor, const TColor &fillColor)
Internal static helper function that can be used alone.
Definition uiface.cpp:315
static void BuildMask(TDC &maskDC, const TPoint &maskDst, const TSize &maskSize, TDC &glyphDC, const TRect &glyphRect, const TColor &maskColor)
Internal static helper function that can be used alone.
Definition uiface.cpp:153
static void PaintBm(const TBitmap &glyph, const TRect &glyphSrcRect, TDC &dc, const TRect &faceRect, const TPoint &dstPt, TState state, bool pressed, bool fillFace, const TColor &maskColor, const TColor &fillColor)
Internal bitmap painting function.
Definition uiface.cpp:222
Definition of abstract GDI object class and derived classes.
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
const long RopDSPDxax
Definition glyphbtn.cpp:32
const long RopPSDPxax
Definition uiface.cpp:23
OWL_DIAGINFO
Definition animctrl.cpp:14
std::string tstring
Definition defs.h:79
unsigned int uint
Definition number.h:25
General definitions used by all ObjectWindows programs.
#define CONST_CAST(targetType, object)
Definition defs.h:273
#define LOCKBRUSH
Definition uiface.cpp:78
Definition of the UI Helper Classes: TUIHandle, TUIBorder, TUIFace, TUIPart.