OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
defs.h
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/// General definitions used by all ObjectWindows programs. Included directly
7/// by ObjectWindows source modules.
8//------------------------------------------------------------------------------
9
10#if !defined(OWL_DEFS_H)
11#define OWL_DEFS_H
12
13//------------------------------------------------------------------------------
14
15
16#if !defined(OWL_PRIVATE_DEFS_H)
17# include <owl/private/defs.h> // Supporting defines for app classes
18#endif
19
20#if defined(BI_HAS_PRAGMA_ONCE)
21# pragma once
22#endif
23
24//------------------------------------------------------------------------------
25// Get Winsys & Services headers common to all of Owl
26//
27
28#if !defined(OWL_PRIVATE_MEMORY_H)
29# include <owl/private/memory.h> // Common memory manipulation functions
30#endif
31
32#if !defined(OWL_PRIVATE_EXCEPT_H)
33# include <owl/private/except.h>
34#endif
35
36#include <owl/private/number.h>
37
38#include <tchar.h>
39#include <string>
40#include <limits>
41#include <type_traits>
42#include <filesystem>
43
44namespace owl {
45
46//
47// String types and functions
48//
49#if defined(_UNICODE)
50
51typedef wchar_t tchar;
52typedef wchar_t utchar;
53typedef std::wstring tstring;
54
55template <class T>
56inline auto to_tstring(const T& v) -> tstring
57{ return std::to_wstring(v); }
58
59template <>
60inline auto to_tstring(const std::filesystem::path& p) -> tstring
61{ return p.wstring(); }
62
63inline auto to_tstring(LPCSTR s) -> tstring
64{ USES_CONVERSION; return A2W(s); }
65
66inline auto to_tstring(LPCWSTR s) -> tstring
67{ return s; }
68
69inline auto to_tstring(const std::string& s) -> tstring
70{ return to_tstring(s.c_str()); }
71
72inline auto to_tstring(std::wstring s) -> tstring
73{ return std::move(s); }
74
75#else
76
77typedef char tchar;
78typedef unsigned char utchar;
79typedef std::string tstring;
80
81template <class T>
82inline auto to_tstring(const T& v) -> tstring
83{ return std::to_string(v); }
84
85template <>
86inline auto to_tstring(const std::filesystem::path& p) -> tstring
87{ return p.string(); }
88
89inline auto to_tstring(LPCSTR s) -> tstring
90{ return s; }
91
92inline auto to_tstring(LPCWSTR s) -> tstring
93{ USES_CONVERSION; return W2A(s); }
94
95inline auto to_tstring(std::string s) -> tstring
96{ return std::move(s); }
97
98inline auto to_tstring(const std::wstring& s) -> tstring
99{ return to_tstring(s.c_str()); }
100
101#endif
102
103} // OWL namespace
104
105#if !defined(_ttof)
106# if defined(UNICODE)
107# define _ttof _wtof
108# else
109# define _ttof atof
110# endif
111#endif
112
113#include <owl/private/checks.h> // Runtime diagnostic macros
114#include <owl/wsysinc.h> // Windowing system headers
115#include <owl/system.h>
116#include <owl/version.h> // OWL version # constants
117
118//------------------------------------------------------------------------------
119// Additional windows.h related defines & undefs for Owl compatibility
120//
121//extern HINSTANCE _hInstance;
122
123# undef GetNextWindow
124# undef GetWindowTask
125# define WM_SYSTEMERROR 0x0017
126# define WM_CTLCOLOR 0x0019
127# define HTASK HANDLE // allow users to use the same type in Win16 & Win32
128#undef SetWindowFont
129#undef GetWindowFont
130
131#if defined(_M_CEE) // this is defined when /clr flag is used
132
133#if !defined(GetWindowClassName)
134#ifdef UNICODE
135#define GetWindowClassName GetClassNameW
136#else
137#define GetWindowClassName GetClassNameA
138#endif // !UNICODE
139#endif
140
141#if !defined(SendMessage)
142#ifdef UNICODE
143#define SendMessage SendMessageW
144#else
145#define SendMessage SendMessageA
146#endif // !UNICODE
147#endif
148
149#if !defined(GetTextMetrics)
150#ifdef UNICODE
151#define GetTextMetrics GetTextMetricsW
152#else
153#define GetTextMetrics GetTextMetricsA
154#endif // !UNICODE
155#endif
156
157#if !defined(DrawText)
158#ifdef UNICODE
159#define DrawText DrawTextW
160#else
161#define DrawText DrawTextA
162#endif // !UNICODE
163#endif
164
165#endif
166
167//------------------------------------------------------------------------------
168// Owl settings for runtime diagnostics in owl.defs.h & classlib/checks.h
169//
170#define OWL_INI "OWL.INI"
171#define OWL_CDLEVEL 2
172#if !defined(OWL_DIAGINFO)
173# define OWL_DIAGINFO
174#endif
175
176
177//------------------------------------------------------------------------------
178// Strict data makes all data members private. Accessors must then be used
179// to access the data members. Public data makes some data public, some data
180// protected, and some private.
181//
182// Note that here may be exceptions to these rules where data members are
183// are explicitly declared public or protected.
184//
185// Unfortunately, the OWLNext source does not itself compile with any other
186// option than OWL_PUBLIC_DATA. So, for now, keep OWLNext members as they were
187// in OWL 5.
188//
189#if defined(OWL_STRICT_DATA) || defined(OWL_PROTECTED_DATA)
190# error OWLNext: OWL_STRICT_DATA and OWL_PROTECTED_DATA are not yet supported.
191#elif !defined(OWL_PUBLIC_DATA)
192# define OWL_PUBLIC_DATA
193#endif
194
195#if defined(OWL_STRICT_DATA)
196
197# define public_data private
198# define protected_data private
199
200#elif defined(OWL_PROTECTED_DATA)
201
202# define public_data protected
203# define protected_data protected
204
205#elif defined(OWL_PUBLIC_DATA)
206
207# define public_data public
208# define protected_data protected
209
210#else
211# error "OWLNext: No data member access option is defined."
212#endif
213
214//
215// Define a boolean flag to indicate if we compile in compatility mode or not.
216//
217#ifdef OWL5_COMPAT
218# define OWL_STRICT 0
219#else
220# define OWL_STRICT 1
221#endif
222
223//------------------------------------------------------------------------------
224// Common external Owl functions & data
225//
226
227namespace owl {
228
229/// Get version of OWL at runtime
230///
231/// Returns the version number of the ObjectWindows library. The version number is
232/// represented as an unsigned short.
233_OWLFUNC(uint32) OWLGetVersion(); ///< Get version of OWL at runtime
234
235class _OWLCLASS TModule;
236
237//
238/// Returns a reference to the global OWL module object. When linking dynamically to OWLNext, this is the module of the OWLNext DLL. When linking statically to OWLNext, it is the same as the one returned from GetGlobalModule.
239//
240_OWLFUNC(TModule&) OWLGetModule();
241
243
244// Returns a reference to the global module object. This is the user application or DLL that contains the code invoking the function.
245extern TModule& GetGlobalModule();
246
247} // OWL namespace
248
249//------------------------------------------------------------------------------
250// Common utility functions
251// TODO: Move to a more suitable home.
252
253namespace owl {
254
255//
256// Integer byte, word and long word manipulation
257//
259 return uint16(lo | (uint16(hi) << 8));
260}
262 return lo | (uint32(hi) << 16);
263}
265 return LOWORD(r);
266}
268 return static_cast<int16>(LOWORD(r));
269}
271 return HIWORD(r);
272}
274 return static_cast<int16>(HIWORD(r));
275}
277 return LOBYTE(r);
278}
280 return static_cast<int8>(LOBYTE(r));
281}
283 return HIBYTE(r);
284}
286 return static_cast<int8>(HIBYTE(r));
287}
289 return uint16((u16 >> 8) | (u16 << 8));
290}
294
295//
296/// Handy utility to avoid compiler warnings about unused parameters
297//
298template <class T>
299void InUse(const T& arg)
300{static_cast<void>(arg);}
301
302//
303/// Copies text from a C-string (null-terminated character array) into a string object,
304/// using a function or functor (function object) to do the actual copying.
305/// To be used by string-aware functions for copying text from C APIs to string objects.
306/// Usually a functor will be provided that wraps a C API function that provides the data.
307///
308/// \code
309/// int
310/// TGetText::operator()(LPTSTR buf, int buf_size)
311/// \endcode
312///
313/// should copy max (buf_size - 1) characters of text into buf and add a null-terminator.
314/// It should return the number of characters copied, excluding the null-terminator.
315//
316template<class TGetText>
318{
319 // This method makes no assumptions about the string implementation, other than what is
320 // required by C++98; in particular that &s[0] returns a pointer to contiguous data.
321 // Since there is no guarantee that the data is null-terminated, we must add room for the
322 // null-terminator and remove it afterwards.
323
324 tstring s;
325 s.resize(size + 1); // Add space for explicit null-terminator.
326 int n = get_text(&s[0], size + 1);
327 s.erase(n); // Trim the excess space, including the null-terminator.
328 return s;
329}
330
331namespace detail
332{
333 template <class T, class U, bool is_integer>
335
336 template <class T, class U>
338 {
339
340#if defined(__clang__)
341# pragma clang diagnostic push
342# pragma clang diagnostic ignored "-Wtautological-compare"
343#elif defined(BI_COMP_BORLANDC)
344# pragma warn -ccc // Disable warning "Condition is always true/false".
345#endif
346
347 static bool Call(U v)
348 {
349 typedef std::numeric_limits<T> TLimits;
350 return v >= 0 ? (static_cast<ULONG_PTR>(v) <= static_cast<ULONG_PTR>(TLimits::max())) :
351 static_cast<LONG_PTR>(v) >= static_cast<LONG_PTR>(TLimits::min());
352 }
353
354#if defined(__clang__)
355# pragma clang diagnostic pop
356#elif defined(BI_COMP_BORLANDC)
357# pragma warn .ccc // Restore warning "Condition is always true/false".
358#endif
359
360 };
361}
362
363//
364/// Helper function for testing for integer truncations.
365//
366template <class T, class U>
368{
369 // Restrict implementation to integer arguments.
371 return TImpl::Call(v);
372}
373
374} // OWL namespace
375
376//
377// Provide alias for old all-uppercase namespace name.
378//
379#if defined(OWL5_COMPAT)
380#define OWL owl
381#endif
382
383//
384// Disable Persistent Streams except in OWL5_COMPAT build mode.
385//
386#if !defined(OWL_PERSISTENT_STREAMS)
387# if defined(OWL5_COMPAT) && !defined(BI_NO_OBJ_STREAMING)
388# define OWL_PERSISTENT_STREAMS 1
389# else
390# define OWL_PERSISTENT_STREAMS 0
391# endif
392#endif
393
394#endif // OWL_DEFS_H
Diagnostic macros for assertions and tracing.
Library version and build information header (template).
Reliable platform independent header for common memory and string functions.
#define W2A(lpw)
Definition memory.h:166
#define USES_CONVERSION
Definition memory.h:71
#define A2W(lpa)
Definition memory.h:138
Object Windows Library (OWLNext Core)
Definition animctrl.h:22
uint16 SwapUint16(uint16 u16)
Definition defs.h:288
TModule & OWLGetModule()
Returns a reference to the global OWL module object. When linking dynamically to OWLNext,...
Definition owl.cpp:52
int8 LoInt8(LRESULT r)
Definition defs.h:279
signed char int8
Definition number.h:28
uint32 MkUint32(uint16 lo, uint16 hi)
Definition defs.h:261
uint16 HiUint16(LRESULT r)
Definition defs.h:270
unsigned char uint8
Definition number.h:32
unsigned long uint32
Definition number.h:34
char tchar
Definition defs.h:77
int8 HiInt8(LRESULT r)
Definition defs.h:285
void InUse(const T &arg)
Handy utility to avoid compiler warnings about unused parameters.
Definition defs.h:299
tstring CopyText(int size, TGetText get_text)
Copies text from a C-string (null-terminated character array) into a string object,...
Definition defs.h:317
signed short int16
Definition number.h:29
uint16 MkUint16(uint8 lo, uint8 hi)
Definition defs.h:258
uint32 SwapUint32(uint32 u32)
Definition defs.h:291
uint16 LoUint16(LRESULT r)
Definition defs.h:264
bool IsRepresentable(U v)
Helper function for testing for integer truncations.
Definition defs.h:367
uint8 HiUint8(LRESULT r)
Definition defs.h:282
unsigned short uint16
Definition number.h:33
std::string tstring
Definition defs.h:79
int16 LoInt16(LRESULT r)
Definition defs.h:267
void InitGlobalModule(HINSTANCE hInstance)
Definition global.cpp:36
TModule & GetGlobalModule()
Definition global.cpp:48
uint32 OWLGetVersion()
Get version of OWL at runtime.
Definition owl.cpp:43
unsigned char utchar
Definition defs.h:78
auto to_tstring(const T &v) -> tstring
Definition defs.h:82
int16 HiInt16(LRESULT r)
Definition defs.h:273
uint8 LoUint8(LRESULT r)
Definition defs.h:276
#define _OWLFUNC(p)
Definition defs.h:341
#define _OWLCLASS
Definition defs.h:338
Definition of TSystem, a system information provider class.
Includes windowing system headers, with necessary macros defined.