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
pen.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 TPen, an encapsulation of the GDI Pen object
7//----------------------------------------------------------------------------
8#include <owl/pch.h>
9#include <owl/gdiobjec.h>
10
11#if defined(__BORLANDC__)
12# pragma option -w-ccc // Disable "Condition is always true/false"
13#endif
14
15using namespace std;
16
17namespace owl {
18
20DIAG_DECLARE_GROUP(OwlGDI); // General GDI diagnostic group
21DIAG_DECLARE_GROUP(OwlGDIOrphan); // Orphan control tracing group
22
23//
24// Constructors
25//
26
27//
28/// Alias an existing pen handle. Assume ownership if autoDelete says so
29//
30/// Creates a TPen object and sets the Handle data member to the given borrowed
31/// handle. The ShouldDelete data member defaults to false, ensuring that the
32/// borrowed handle will not be deleted when the C++ object is destroyed.
33//
41
42//
43/// Basic pen constructor. Detect constructions of stock pens & get stock objects instead
44//
45/// Creates a TPen object with the given values. The width argument is in device
46/// units, but if set to 0, a 1-pixel width is assumed. Sets Handle with the given
47/// default values. If color is black or white, width is one, style is solid, a
48/// stock pen handle is returned. The values for style are listed in the following
49/// table.
50/// - \c \b PS_SOLID Creates a solid pen.
51/// - \c \b PS_DASH Creates a dashed pen. Valid only when the pen width is one or less in
52/// device units.
53/// - \c \b PS_DOT Creates a dotted pen. Valid only when the pen width is one or less in
54/// device units.
55/// - \c \b PS_DASHDOT Creates a pen with alternating dashes dots. Valid only when the pen
56/// width is one or less in device units.
57/// - \c \b PS_DASHDOTDOT Creates a pen with alternating dashes double-dots. Valid only when
58/// the pen width is one or less in device units.
59/// - \c \b PS_NULL Creates a null pen.
60/// - \c \b PS_INSIDEFRAME Creates a solid pen. When this pen is used in any GDI drawing
61/// function that takes a bounding rectangle, the dimensions of the figure will be
62/// shrunk so that it fits entirely in the bounding rectangle, taking into account
63/// the width of the pen.
64//
65TPen::TPen(const TColor& color, int width, int style)
66{
67 if (width == 1 && style == PS_SOLID &&
69 if (color == TColor::Black)
71 else
73 ShouldDelete = false;
74 return;
75 }
76 Handle = ::CreatePen(style, width, color);
77 WARNX(OwlGDI, !Handle, 0, "Cannot create TPen (" << color << " " << width <<
78 " " << style << ")");
79 CheckValid();
81}
82
83//
84/// Creates a TPen object from the given logPen values.
85//
87{
89 WARNX(OwlGDI, !Handle, 0, "Cannot create TPen from logPen @" << static_cast<const void*>(&logPen));
90 CheckValid();
92}
93
94#if defined(OWL5_COMPAT)
95
96//
97/// Creates a TPen object from the given logPen values.
98/// This overload is deprecated. Use the overload that takes a reference instead.
99//
100TPen::TPen(const LOGPEN * logPen)
101{
104 WARNX(OwlGDI, !Handle, 0, "Cannot create TPen from logPen @" << static_cast<const void*>(logPen));
105 CheckValid();
106 RefAdd(Handle, Pen);
107}
108
109#endif
110
111//
112/// Construct a copy of an existing pen. Contructed pen will share the handle
113/// unless NO_GDI_SHARE_HANDLES is defined, in which case a new handle is
114/// created
115//
117{
118#if !defined(NO_GDI_SHARE_HANDLES)
119 Handle = src.Handle;
120 RefAdd(Handle, Pen);
121#else
123
124 src.GetObject(logPen);
126 WARNX(OwlGDI, !Handle, 0, "Cannot create TPen from TPen @" <<
127 hex << uint32(LPVOID(&src)));
128 CheckValid();
129 RefAdd(Handle, Pen);
130#endif
131}
132
133//
134/// Creates a TPen object with the given values.
135//
137 uint32 styleCount, const uint32* style)
138{
139 LOGBRUSH logBrush = brush.GetObject();
140 Handle = ::ExtCreatePen(penStyle, width, &logBrush, styleCount, (const DWORD*)style);
141 WARNX(OwlGDI, !Handle, 0, "Cannot create TPen from brush " << static_cast<void*>(brush.GetHandle()));
142 CheckValid();
143 RefAdd(Handle, Pen);
144}
145
146//
147/// Creates a TPen object with the given values.
148//
150 uint32 styleCount, const uint32* style)
151{
152 Handle = ::ExtCreatePen(penStyle, width, (LPLOGBRUSH)&logBrush, styleCount, (const DWORD*)style);
153 WARNX(OwlGDI, !Handle, 0, "Cannot create TPen from logBrush @" << static_cast<const void*>(&logBrush));
154 CheckValid();
155 RefAdd(Handle, Pen);
156}
157
158//
159/// Retrieves information about this pen object and places it in the given LOGPEN structure.
160/// Throws TXGdi on failure.
161//
163{
165 bool r = TGdiObject::GetObject(sizeof(logPen), &logPen) != 0;
166 if (!r) throw TXGdi(IDS_GDIFAILURE, Handle);
167 return logPen;
168}
169
170} // OWL namespace
171/* ========================================================================== */
#define WARNX(group, condition, level, message)
Definition checks.h:277
#define PRECONDITION(condition)
Definition checks.h:227
#define DIAG_DECLARE_GROUP(group)
Definition checks.h:404
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 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
GdiObject is the root, pseudo-abstract base class for ObjectWindows' GDI (Graphics Device Interface) ...
Definition gdiobjec.h:68
void CheckValid(uint resId=IDS_GDIFAILURE)
Definition gdibase.cpp:49
int GetObject(int count, void *object) const
Retrieve the object's attributes into a buffer.
Definition gdiobjec.h:1051
bool ShouldDelete
Should object delete GDI handle in dtor?
Definition gdibase.h:82
static void RefAdd(HANDLE handle, TType type)
RefAdd adds a reference entry for the object with the given handle and type.
Definition gdiobjec.cpp:137
HANDLE Handle
GDI handle of this object.
Definition gdibase.h:81
TPen is derived from TGdiObject.
Definition gdiobjec.h:138
TPen(HPEN handle, TAutoDelete autoDelete=NoAutoDelete)
Alias an existing pen handle. Assume ownership if autoDelete says so.
Definition pen.cpp:34
LOGPEN GetObject() const
Retrieves information about this pen object and places it in the given LOGPEN structure.
Definition pen.cpp:162
Describes an exception resulting from GDI failures such as creating too many TWindow device contexts ...
Definition gdibase.h:52
Definition of abstract GDI object class and derived classes.
TAutoDelete
Flag for Handle ctors to control Handle deletion in dtor.
Definition gdibase.h:70
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
unsigned long uint32
Definition number.h:34
OWL_DIAGINFO
Definition animctrl.cpp:14