updates from orpheus for windoze build
[feisty_meow.git] / nucleus / library / application / windoze_helper.h
1 #ifndef WINDOZE_HELPER_GROUP
2 #define WINDOZE_HELPER_GROUP
3
4 /*
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 \*****************************************************************************/
14
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.
21 */
22
23 // gnarly headers that are needed for certain types of compilation...
24
25 //unix headers not needed in here for new purpose of file.
26 #ifndef _MSC_VER
27   #include <unistd.h>
28   #ifdef __GNU_WINDOWS__
29     #include <sys/unistd.h>
30   #endif
31 #endif
32 #ifndef NO_XWINDOWS
33   #ifdef __XWINDOWS__
34     #include <Intrinsic.h>
35     #include <StringDefs.h>
36     #include <Xm/Xm.h>
37     #include <Xlib.h>
38   #endif
39 #endif
40 #ifdef __WIN32__
41   #ifndef STRICT
42     #define STRICT
43   #endif
44   // winsock support...
45 //  #undef FD_SETSIZE
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>
49
50   // windows headers...
51 //noooo  #define _WINSOCKAPI_  // make windows.h happy about winsock.
52   #ifndef _AFXDLL
53     // include ms-windows headers only if we're not doing mfc; mfc has its own
54     // special way of including the headers.
55     #include <windows.h>
56   #else
57     #include <afx.h>
58     #include <afxwin.h>
59   #endif
60 #endif
61
62 // forward.
63 //class version;
64
65 // wrapper classes defined in the sequel...
66 //
67 //   application_instance -- this program's application object; used mainly
68 //       in ms-windows.
69 //
70 //   window_handle -- a wrapper for the root of all objects that can be
71 //       referred to in the relevant windowing system.
72
73 #include <basis/definitions.h>
74
75 #ifdef __UNIX__
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
78   // ms-windows does.
79   typedef void *application_instance;
80
81   // some definitions to quiet complaints from win32-based code.
82   #ifndef LONGINT_SIZE
83     #if defined(__alpha) || (defined(__HOS_AIX__) && defined(_LP64)) \
84         || defined(__sparcv9) || defined(__LP64__) 
85       #define LONGINT_SIZE 8
86     #else
87       #define LONGINT_SIZE 4
88     #endif
89   #endif
90   #if (LONGINT_SIZE == 4)
91     // be compatible with linux's definitions on this subject.
92     typedef unsigned long DWORD;
93   #else
94     typedef unsigned int DWORD;
95   #endif
96
97   typedef void *HANDLE;
98
99   //temp; these just mimic function prototypes coming from non-portable code.
100   typedef void *ATOM;
101   typedef void *BITMAPINFO;
102   typedef void *HBITMAP;
103   typedef void *HDC;
104   typedef void *RGBQUAD;
105   #define LoadBitmap(a, b) (a)
106   #define __stdcall 
107   #define afx_msg
108
109   // windoze_helper definitions for the X windowing system.
110   #ifndef NO_XWINDOWS  // protects regions with similar names.
111   #ifdef __XWINDOWS__
112     typedef Widget window_handle;
113       //!< main way to access a windowing system object.  should be a pointer.
114
115     typedef Colormap window_colormap;
116       //!< the windowing system representation of a pallette or colormap.
117
118     typedef XColor window_color;
119       //!< the system representation of color.
120
121     typedef XmString window_string;
122       //!< a special windowing system dependent kind of character string.
123
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.
127   #else
128     // no x-windows.
129     typedef void *window_handle;
130   #endif
131   #endif
132 #endif
133
134 #ifdef __WIN32__
135   typedef HINSTANCE application_instance;
136     // our moniker for an application's guts.
137
138   typedef HWND window_handle;
139     // our alias for window handles in win32.
140 #endif
141
142 namespace application {
143
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. */
147
148
149 //  u_int system_error();
150     //!< gets the most recent system error reported on this thread.
151
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(). */
155
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. */
160
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). */
166
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.
179
180 ////////////////////////////////////////////////////////////////////////////
181
182   // Unix and Linux specific items are included here.
183   #ifdef __UNIX__
184 ////    istring get_cmdline_from_proc();
185       //!< returns the command line that /proc has recorded for our process.
186
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). */
194
195     #define RGB(r, g, b) (b + (g << 8) + (r << 16))
196       //!< no idea if that's even approximately right.
197   #endif
198
199   // ms-windows of more modern types, i.e. win32.
200   #ifdef __WIN32__
201
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. */
208
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. */
216
217     #define BROADCAST_HANDLE HWND_BROADCAST
218
219     enum known_operating_systems {
220       WIN_95, WIN_NT, WIN_2K, WIN_XP, WIN_SRV2K3, WIN_VISTA, 
221 ///WIN_SRV2K8,
222       WIN_7, WIN_8, WIN_10,
223       UNKNOWN_OS
224     };
225     const char *opsystem_name(known_operating_systems which);
226       //!< returns the textual form of the known_operating_systems enum.
227
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. */
231
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
235       that "instance". */
236
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
240       for the "id". */
241
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.
246
247   #endif // win32.
248
249 } // namespace.
250
251 #endif // outer guard.
252