OWLNext
7.0
Borland's Object Windows Library for the modern age
Toggle main menu visibility
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
44
namespace
owl
{
45
46
//
47
// String types and functions
48
//
49
#if defined(_UNICODE)
50
51
typedef
wchar_t
tchar
;
52
typedef
wchar_t
utchar
;
53
typedef
std::wstring
tstring
;
54
55
template
<
class
T>
56
inline
auto
to_tstring
(
const
T& v) ->
tstring
57
{
return
std::to_wstring(v); }
58
59
template
<>
60
inline
auto
to_tstring
(
const
std::filesystem::path& p) ->
tstring
61
{
return
p.wstring(); }
62
63
inline
auto
to_tstring
(LPCSTR s) ->
tstring
64
{
USES_CONVERSION
;
return
A2W
(s); }
65
66
inline
auto
to_tstring
(LPCWSTR s) ->
tstring
67
{
return
s; }
68
69
inline
auto
to_tstring
(
const
std::string& s) ->
tstring
70
{
return
to_tstring
(s.c_str()); }
71
72
inline
auto
to_tstring
(std::wstring s) ->
tstring
73
{
return
std::move(s); }
74
75
#else
76
77
typedef
char
tchar
;
78
typedef
unsigned
char
utchar
;
79
typedef
std::string
tstring
;
80
81
template
<
class
T>
82
inline
auto
to_tstring
(
const
T& v) ->
tstring
83
{
return
std::to_string(v); }
84
85
template
<>
86
inline
auto
to_tstring
(
const
std::filesystem::path& p) ->
tstring
87
{
return
p.string(); }
88
89
inline
auto
to_tstring
(LPCSTR s) ->
tstring
90
{
return
s; }
91
92
inline
auto
to_tstring
(LPCWSTR s) ->
tstring
93
{
USES_CONVERSION
;
return
W2A
(s); }
94
95
inline
auto
to_tstring
(std::string s) ->
tstring
96
{
return
std::move(s); }
97
98
inline
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
227
namespace
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
235
class
_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
242
extern
void
InitGlobalModule
(HINSTANCE hInstance);
243
244
// Returns a reference to the global module object. This is the user application or DLL that contains the code invoking the function.
245
extern
TModule&
GetGlobalModule
();
246
247
}
// OWL namespace
248
249
//------------------------------------------------------------------------------
250
// Common utility functions
251
// TODO: Move to a more suitable home.
252
253
namespace
owl
{
254
255
//
256
// Integer byte, word and long word manipulation
257
//
258
inline
uint16
MkUint16
(
uint8
lo,
uint8
hi) {
259
return
uint16
(lo | (
uint16
(hi) << 8));
260
}
261
inline
uint32
MkUint32
(
uint16
lo,
uint16
hi) {
262
return
lo | (
uint32
(hi) << 16);
263
}
264
inline
uint16
LoUint16
(LRESULT r) {
265
return
LOWORD(r);
266
}
267
inline
int16
LoInt16
(LRESULT r) {
268
return
static_cast<
int16
>
(LOWORD(r));
269
}
270
inline
uint16
HiUint16
(LRESULT r) {
271
return
HIWORD(r);
272
}
273
inline
int16
HiInt16
(LRESULT r) {
274
return
static_cast<
int16
>
(HIWORD(r));
275
}
276
inline
uint8
LoUint8
(LRESULT r) {
277
return
LOBYTE(r);
278
}
279
inline
int8
LoInt8
(LRESULT r) {
280
return
static_cast<
int8
>
(LOBYTE(r));
281
}
282
inline
uint8
HiUint8
(LRESULT r) {
283
return
HIBYTE(r);
284
}
285
inline
int8
HiInt8
(LRESULT r) {
286
return
static_cast<
int8
>
(HIBYTE(r));
287
}
288
inline
uint16
SwapUint16
(
uint16
u16){
289
return
uint16
((u16 >> 8) | (u16 << 8));
290
}
291
inline
uint32
SwapUint32
(
uint32
u32){
292
return
MkUint32
(
SwapUint16
(
HiUint16
(u32)),
SwapUint16
(
LoUint16
(u32)));
293
}
294
295
//
296
/// Handy utility to avoid compiler warnings about unused parameters
297
//
298
template
<
class
T>
299
void
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
//
316
template
<
class
TGetText>
317
tstring
CopyText
(
int
size, TGetText get_text)
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
331
namespace
detail
332
{
333
template
<
class
T,
class
U,
bool
is_
int
eger>
334
struct
TIsRepresentable
;
335
336
template
<
class
T,
class
U>
337
struct
TIsRepresentable
<T, U, true>
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<
uint64
>
(v) <=
static_cast<
uint64
>
(TLimits::max())) :
351
static_cast<
int64
>
(v) >=
static_cast<
int64
>
(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
//
366
template
<
class
T,
class
U>
367
bool
IsRepresentable
(U v)
368
{
369
// Restrict implementation to integer arguments.
370
typedef
detail::TIsRepresentable<T, U, std::numeric_limits<T>::is_integer
> TImpl;
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
checks.h
Diagnostic macros for assertions and tracing.
version.h
Library version and build information header (template).
memory.h
Reliable platform independent header for common memory and string functions.
W2A
#define W2A(lpw)
Definition
memory.h:166
USES_CONVERSION
#define USES_CONVERSION
Definition
memory.h:71
A2W
#define A2W(lpa)
Definition
memory.h:138
owl::detail
Definition
defs.h:332
owl
Object Windows Library (OWLNext Core).
Definition
animctrl.h:22
owl::SwapUint16
uint16 SwapUint16(uint16 u16)
Definition
defs.h:288
owl::OWLGetModule
TModule & OWLGetModule()
Returns a reference to the global OWL module object. When linking dynamically to OWLNext,...
Definition
owl.cpp:52
owl::int64
__int64 int64
Definition
number.h:36
owl::LoInt8
int8 LoInt8(LRESULT r)
Definition
defs.h:279
owl::int8
signed char int8
Definition
number.h:28
owl::MkUint32
uint32 MkUint32(uint16 lo, uint16 hi)
Definition
defs.h:261
owl::HiUint16
uint16 HiUint16(LRESULT r)
Definition
defs.h:270
owl::uint8
unsigned char uint8
Definition
number.h:32
owl::uint32
unsigned long uint32
Definition
number.h:34
owl::tchar
char tchar
Definition
defs.h:77
owl::HiInt8
int8 HiInt8(LRESULT r)
Definition
defs.h:285
owl::InUse
void InUse(const T &arg)
Handy utility to avoid compiler warnings about unused parameters.
Definition
defs.h:299
owl::CopyText
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
owl::int16
signed short int16
Definition
number.h:29
owl::MkUint16
uint16 MkUint16(uint8 lo, uint8 hi)
Definition
defs.h:258
owl::SwapUint32
uint32 SwapUint32(uint32 u32)
Definition
defs.h:291
owl::LoUint16
uint16 LoUint16(LRESULT r)
Definition
defs.h:264
owl::IsRepresentable
bool IsRepresentable(U v)
Helper function for testing for integer truncations.
Definition
defs.h:367
owl::HiUint8
uint8 HiUint8(LRESULT r)
Definition
defs.h:282
owl::uint64
unsigned __int64 uint64
Definition
number.h:43
owl::uint16
unsigned short uint16
Definition
number.h:33
owl::tstring
std::string tstring
Definition
defs.h:79
owl::LoInt16
int16 LoInt16(LRESULT r)
Definition
defs.h:267
owl::InitGlobalModule
void InitGlobalModule(HINSTANCE hInstance)
Definition
global.cpp:36
owl::GetGlobalModule
TModule & GetGlobalModule()
Definition
global.cpp:48
owl::OWLGetVersion
uint32 OWLGetVersion()
Get version of OWL at runtime.
Definition
owl.cpp:43
owl::utchar
unsigned char utchar
Definition
defs.h:78
owl::to_tstring
auto to_tstring(const T &v) -> tstring
Definition
defs.h:82
owl::HiInt16
int16 HiInt16(LRESULT r)
Definition
defs.h:273
owl::LoUint8
uint8 LoUint8(LRESULT r)
Definition
defs.h:276
number.h
defs.h
_OWLFUNC
#define _OWLFUNC(p)
Definition
defs.h:341
_OWLCLASS
#define _OWLCLASS
Definition
defs.h:338
except.h
owl::detail::TIsRepresentable< T, U, true >::Call
static bool Call(U v)
Definition
defs.h:347
owl::detail::TIsRepresentable
Definition
defs.h:334
system.h
Definition of TSystem, a system information provider class.
wsysinc.h
Includes windowing system headers, with necessary macros defined.
include
owl
defs.h
Generated by
1.18.0