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.
48 // #include <winsock2.h>
51 //noooo #define _WINSOCKAPI_ // make windows.h happy about winsock.
53 // include ms-windows headers only if we're not doing mfc; mfc has its own
54 // special way of including the headers.
65 // wrapper classes defined in the sequel...
67 // application_instance -- this program's application object; used mainly
70 // window_handle -- a wrapper for the root of all objects that can be
71 // referred to in the relevant windowing system.
73 #include <basis/definitions.h>
76 // the application_instance class is implemented very simply for unix;
77 // it's a stand-in since unix apps don't refer to an instance handle like
79 typedef void *application_instance;
81 // some definitions to quiet complaints from win32-based code.
83 #if defined(__alpha) || (defined(__HOS_AIX__) && defined(_LP64)) \
84 || defined(__sparcv9) || defined(__LP64__)
85 #define LONGINT_SIZE 8
87 #define LONGINT_SIZE 4
90 #if (LONGINT_SIZE == 4)
91 // be compatible with linux's definitions on this subject.
92 typedef unsigned long DWORD;
94 typedef unsigned int DWORD;
99 //temp; these just mimic function prototypes coming from non-portable code.
101 typedef void *BITMAPINFO;
102 typedef void *HBITMAP;
104 typedef void *RGBQUAD;
105 #define LoadBitmap(a, b) (a)
109 // windoze_helper definitions for the X windowing system.
110 #ifndef NO_XWINDOWS // protects regions with similar names.
112 typedef Widget window_handle;
113 //!< main way to access a windowing system object. should be a pointer.
115 typedef Colormap window_colormap;
116 //!< the windowing system representation of a pallette or colormap.
118 typedef XColor window_color;
119 //!< the system representation of color.
121 typedef XmString window_string;
122 //!< a special windowing system dependent kind of character string.
124 //is that really fixed?
125 const int MAXIMUM_COLOR_INTENSITY = 65535;
126 // largest valid value a color component (R, G or B) can have.
129 typedef void *window_handle;
135 typedef HINSTANCE application_instance;
136 // our moniker for an application's guts.
138 typedef HWND window_handle;
139 // our alias for window handles in win32.
142 namespace application {
144 // istring module_name(const void *module_handle = NULL_POINTER);
145 //!< returns the name of the module for the "module_handle" where supported.
146 /*!< if the handle is NULL_POINTER, then the program name is returned. */
149 // u_int system_error();
150 //!< gets the most recent system error reported on this thread.
152 // istring system_error_text(u_int error_to_show);
153 //!< returns the OS's string form of the "error_to_show".
154 /*!< this often comes from the value reported by system_error(). */
156 // istring null_device();
157 //!< returns the name of the system's NULL device.
158 /*!< this device is a black hole where output can be sent, never to be
159 seen again. this is /dev/null on unix and null: on win32. */
161 // timeval fill_timeval_ms(int milliseconds);
162 //!< returns a timeval system object that represents the "milliseconds".
163 /*!< if "milliseconds" is zero, then the returned timeval will
164 represent zero time passing (rather than infinite duration as some
165 functions assume). */
167 // this only really helps for win32.
168 extern application_instance _i_handle;
169 //!< dll_root.cpp defines this for all dlls.
170 #define DEFINE_INSTANCE_HANDLE application_instance application::_i_handle = 0
171 //!< some applications may need this to use rc_string and others.
172 /*!< if this macro is used, then the code is impervious to future
173 changes in how the instance handle works. */
174 #define SET_INSTANCE_HANDLE(value) application::_i_handle = value
175 //!< use this to change the instance handle for this dll or exe.
176 /*!< note that this should be done only once and by the main thread. */
177 #define GET_INSTANCE_HANDLE() application::_i_handle
178 //!< a handy macro that frees one from knowing the name of the handle.
180 ////////////////////////////////////////////////////////////////////////////
182 // Unix and Linux specific items are included here.
184 //// istring get_cmdline_from_proc();
185 //!< returns the command line that /proc has recorded for our process.
187 // char *itoa(int to_convert, char *buffer, int radix);
188 //!< turns the integer "to_convert" into a string stored in the "buffer".
189 /*!< this is needed on linux since there doesn't seem to be a builtin
190 version of it. the buffer must be long enough to hold the number's
191 textual representation! the buffer's length must also account for the
192 chosen "radix" (the base for the number system, where 10 is decimal,
193 16 is hexadecimal, etc). */
195 #define RGB(r, g, b) (b + (g << 8) + (r << 16))
196 //!< no idea if that's even approximately right.
199 // ms-windows of more modern types, i.e. win32.
202 // bool event_poll(MSG &message);
203 //!< tries to process one win32 event and retrieve the "message" from it.
204 /*!< this is a very general poll and will retrieve any message that's
205 available for the current thread. the message is actually processed
206 here also, by calling translate and dispatch. the returned structure
207 is mainly interesting for knowing what was done. */
209 //hmmm: is there an equivalent to this for unix?
210 // bool is_address_valid(const void *address, int size_expected,
211 // bool writable = false);
212 //!< checks that the address specified is a valid pointer.
213 /*! also tests that the address's allocated space has the
214 "size_expected". if "writable" is true, then the pointer is
215 checked for being writable as well as readable. */
217 #define BROADCAST_HANDLE HWND_BROADCAST
219 enum known_operating_systems {
220 WIN_95, WIN_NT, WIN_2K, WIN_XP, WIN_SRV2K3, WIN_VISTA,
222 WIN_7, WIN_8, WIN_10,
225 const char *opsystem_name(known_operating_systems which);
226 //!< returns the textual form of the known_operating_systems enum.
228 known_operating_systems determine_OS();
229 //!< returns the operating system that seems to be running currently.
230 /*!< note that WIN_95 also covers windows 98 and windows ME. */
232 // istring rc_string(u_int id, application_instance instance);
233 //!< acquires a string from a particular "instance".
234 /*!< the "id" is the resource identifier for the desired string in
237 // istring rc_string(u_int id);
238 //!< simplified from above function by not needing an "instance".
239 /*!< the "current" dynamic library or executable's resources are sought
242 // void show_wait_cursor();
243 //!< changes the cursor to the "wait" look, which is usually an hourglass.
244 // void show_normal_cursor();
245 //!< changes the cursor to "normal", which is usually a pointing arrow.
251 #endif // outer guard.