1 #ifndef WINDOZE_HELPER_GROUP
2 #define WINDOZE_HELPER_GROUP
5 * Name : windoze_helper definitions
6 * Author : Chris Koeritz
7 * Copyright (c) 1994-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 \*****************************************************************************/
15 //! @file windoze_helper.h Aids in achievement of platform independence.
16 /*! @file windoze_helper.h
17 These definitions, inclusions and types are aimed at allowing our source
18 code to remain independent of the underlying windowing and operating
19 systems. Specifically, windows puts a lot of burden on the developer,
20 and this file exists to hide all that malarkey.
23 // gnarly headers that are needed for certain types of compilation...
25 //unix headers not needed in here for new purpose of file.
28 #ifdef __GNU_WINDOWS__
29 #include <sys/unistd.h>
34 #include <Intrinsic.h>
35 #include <StringDefs.h>
46 // #define FD_SETSIZE 1000
47 // if you don't set this, you can only select on a default of 64 sockets.
50 #define _WINSOCKAPI_ // make windows.h happy about winsock.
52 // include ms-windows headers only if we're not doing mfc; mfc has its own
53 // special way of including the headers.
64 // wrapper classes defined in the sequel...
66 // application_instance -- this program's application object; used mainly
69 // window_handle -- a wrapper for the root of all objects that can be
70 // referred to in the relevant windowing system.
72 #include <basis/definitions.h>
75 // the application_instance class is implemented very simply for unix;
76 // it's a stand-in since unix apps don't refer to an instance handle like
78 typedef void *application_instance;
80 // some definitions to quiet complaints from win32-based code.
82 #if defined(__alpha) || (defined(__HOS_AIX__) && defined(_LP64)) \
83 || defined(__sparcv9) || defined(__LP64__)
84 #define LONGINT_SIZE 8
86 #define LONGINT_SIZE 4
89 #if (LONGINT_SIZE == 4)
90 // be compatible with linux's definitions on this subject.
91 typedef unsigned long DWORD;
93 typedef unsigned int DWORD;
98 //temp; these just mimic function prototypes coming from non-portable code.
100 typedef void *BITMAPINFO;
101 typedef void *HBITMAP;
103 typedef void *RGBQUAD;
104 #define LoadBitmap(a, b) (a)
108 // windoze_helper definitions for the X windowing system.
109 #ifndef NO_XWINDOWS // protects regions with similar names.
111 typedef Widget window_handle;
112 //!< main way to access a windowing system object. should be a pointer.
114 typedef Colormap window_colormap;
115 //!< the windowing system representation of a pallette or colormap.
117 typedef XColor window_color;
118 //!< the system representation of color.
120 typedef XmString window_string;
121 //!< a special windowing system dependent kind of character string.
123 //is that really fixed?
124 const int MAXIMUM_COLOR_INTENSITY = 65535;
125 // largest valid value a color component (R, G or B) can have.
128 typedef void *window_handle;
134 typedef HINSTANCE application_instance;
135 // our moniker for an application's guts.
137 typedef HWND window_handle;
138 // our alias for window handles in win32.
141 namespace application {
143 // istring module_name(const void *module_handle = NULL_POINTER);
144 //!< returns the name of the module for the "module_handle" where supported.
145 /*!< if the handle is NULL_POINTER, then the program name is returned. */
148 // u_int system_error();
149 //!< gets the most recent system error reported on this thread.
151 // istring system_error_text(u_int error_to_show);
152 //!< returns the OS's string form of the "error_to_show".
153 /*!< this often comes from the value reported by system_error(). */
155 // istring null_device();
156 //!< returns the name of the system's NULL device.
157 /*!< this device is a black hole where output can be sent, never to be
158 seen again. this is /dev/null on unix and null: on win32. */
160 // timeval fill_timeval_ms(int milliseconds);
161 //!< returns a timeval system object that represents the "milliseconds".
162 /*!< if "milliseconds" is zero, then the returned timeval will
163 represent zero time passing (rather than infinite duration as some
164 functions assume). */
166 // this only really helps for win32.
167 extern application_instance _i_handle;
168 //!< dll_root.cpp defines this for all dlls.
169 #define DEFINE_INSTANCE_HANDLE application_instance application::_i_handle = 0
170 //!< some applications may need this to use rc_string and others.
171 /*!< if this macro is used, then the code is impervious to future
172 changes in how the instance handle works. */
173 #define SET_INSTANCE_HANDLE(value) application::_i_handle = value
174 //!< use this to change the instance handle for this dll or exe.
175 /*!< note that this should be done only once and by the main thread. */
176 #define GET_INSTANCE_HANDLE() application::_i_handle
177 //!< a handy macro that frees one from knowing the name of the handle.
179 ////////////////////////////////////////////////////////////////////////////
181 // Unix and Linux specific items are included here.
183 //// istring get_cmdline_from_proc();
184 //!< returns the command line that /proc has recorded for our process.
186 // char *itoa(int to_convert, char *buffer, int radix);
187 //!< turns the integer "to_convert" into a string stored in the "buffer".
188 /*!< this is needed on linux since there doesn't seem to be a builtin
189 version of it. the buffer must be long enough to hold the number's
190 textual representation! the buffer's length must also account for the
191 chosen "radix" (the base for the number system, where 10 is decimal,
192 16 is hexadecimal, etc). */
194 #define RGB(r, g, b) (b + (g << 8) + (r << 16))
195 //!< no idea if that's even approximately right.
198 // ms-windows of more modern types, i.e. win32.
201 // bool event_poll(MSG &message);
202 //!< tries to process one win32 event and retrieve the "message" from it.
203 /*!< this is a very general poll and will retrieve any message that's
204 available for the current thread. the message is actually processed
205 here also, by calling translate and dispatch. the returned structure
206 is mainly interesting for knowing what was done. */
208 //hmmm: is there an equivalent to this for unix?
209 // bool is_address_valid(const void *address, int size_expected,
210 // bool writable = false);
211 //!< checks that the address specified is a valid pointer.
212 /*! also tests that the address's allocated space has the
213 "size_expected". if "writable" is true, then the pointer is
214 checked for being writable as well as readable. */
216 #define BROADCAST_HANDLE HWND_BROADCAST
218 enum known_operating_systems {
219 WIN_95, WIN_NT, WIN_2K, WIN_XP, WIN_SRV2K3, WIN_VISTA,
221 WIN_7, WIN_8, WIN_10,
224 const char *opsystem_name(known_operating_systems which);
225 //!< returns the textual form of the known_operating_systems enum.
227 known_operating_systems determine_OS();
228 //!< returns the operating system that seems to be running currently.
229 /*!< note that WIN_95 also covers windows 98 and windows ME. */
231 // istring rc_string(u_int id, application_instance instance);
232 //!< acquires a string from a particular "instance".
233 /*!< the "id" is the resource identifier for the desired string in
236 // istring rc_string(u_int id);
237 //!< simplified from above function by not needing an "instance".
238 /*!< the "current" dynamic library or executable's resources are sought
241 // void show_wait_cursor();
242 //!< changes the cursor to the "wait" look, which is usually an hourglass.
243 // void show_normal_cursor();
244 //!< changes the cursor to "normal", which is usually a pointing arrow.
250 #endif // outer guard.