first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / 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 #ifdef __UNIX__
27   #include <unistd.h>
28 #endif
29 #ifndef NO_XWINDOWS
30   #ifdef __XWINDOWS__
31     #include <Intrinsic.h>
32     #include <StringDefs.h>
33     #include <Xm/Xm.h>
34     #include <Xlib.h>
35   #endif
36 #endif
37 #ifdef __WIN32__
38   #ifndef STRICT
39     #define STRICT
40   #endif
41   // windows headers...
42   #define _WINSOCKAPI_  // make windows.h happy about winsock.
43   #ifndef _AFXDLL
44     // include ms-windows headers only if we're not doing mfc; mfc has its own
45     // special way of including the headers.
46     #include <windows.h>
47   #else
48     #include <afx.h>
49     #include <afxwin.h>
50   #endif
51   // winsock support...
52   #undef FD_SETSIZE
53   #define FD_SETSIZE 1000
54     // if you don't set this, you can only select on a default of 64 sockets.
55   #include <winsock2.h>
56 #endif
57
58 // forward.
59 //class version;
60
61 // wrapper classes defined in the sequel...
62 //
63 //   application_instance -- this program's application object; used mainly
64 //       in ms-windows.
65 //
66 //   window_handle -- a wrapper for the root of all objects that can be
67 //       referred to in the relevant windowing system.
68
69 #include <basis/definitions.h>
70
71 #ifdef __UNIX__
72   // the application_instance class is implemented very simply for unix;
73   // it's a stand-in since unix apps don't refer to an instance handle like
74   // ms-windows does.
75   typedef void *application_instance;
76
77   // some definitions to quiet complaints from win32-based code.
78   #ifndef LONGINT_SIZE
79     #if defined(__alpha) || (defined(__HOS_AIX__) && defined(_LP64)) \
80         || defined(__sparcv9) || defined(__LP64__) 
81       #define LONGINT_SIZE 8
82     #else
83       #define LONGINT_SIZE 4
84     #endif
85   #endif
86   #if (LONGINT_SIZE == 4)
87     // be compatible with linux's definitions on this subject.
88     typedef unsigned long DWORD;
89   #else
90     typedef unsigned int DWORD;
91   #endif
92
93   typedef void *HANDLE;
94
95   //temp; these just mimic function prototypes coming from non-portable code.
96   typedef void *ATOM;
97   typedef void *BITMAPINFO;
98   typedef void *HBITMAP;
99   typedef void *HDC;
100   typedef void *RGBQUAD;
101   #define LoadBitmap(a, b) (a)
102   #define __stdcall 
103   #define afx_msg
104
105   // windoze_helper definitions for the X windowing system.
106   #ifndef NO_XWINDOWS  // protects regions with similar names.
107   #ifdef __XWINDOWS__
108     typedef Widget window_handle;
109       //!< main way to access a windowing system object.  should be a pointer.
110
111     typedef Colormap window_colormap;
112       //!< the windowing system representation of a pallette or colormap.
113
114     typedef XColor window_color;
115       //!< the system representation of color.
116
117     typedef XmString window_string;
118       //!< a special windowing system dependent kind of character string.
119
120 //is that really fixed?
121     const int MAXIMUM_COLOR_INTENSITY = 65535;
122       // largest valid value a color component (R, G or B) can have.
123   #else
124     // no x-windows.
125     typedef void *window_handle;
126   #endif
127   #endif
128 #endif
129
130 #ifdef __WIN32__
131   typedef HINSTANCE application_instance;
132     // our moniker for an application's guts.
133
134   typedef HWND window_handle;
135     // our alias for window handles in win32.
136 #endif
137
138 namespace application {
139
140 //  istring module_name(const void *module_handle = NIL);
141     //!< returns the name of the module for the "module_handle" where supported.
142     /*!< if the handle is NIL, then the program name is returned. */
143
144
145 //  u_int system_error();
146     //!< gets the most recent system error reported on this thread.
147
148 //  istring system_error_text(u_int error_to_show);
149     //!< returns the OS's string form of the "error_to_show".
150     /*!< this often comes from the value reported by system_error(). */
151
152 //  istring null_device();
153     //!< returns the name of the system's NULL device.
154     /*!< this device is a black hole where output can be sent, never to be
155     seen again.  this is /dev/null on unix and null: on win32. */
156
157 //  timeval fill_timeval_ms(int milliseconds);
158     //!< returns a timeval system object that represents the "milliseconds".
159     /*!< if "milliseconds" is zero, then the returned timeval will
160     represent zero time passing (rather than infinite duration as some
161     functions assume). */
162
163   // this only really helps for win32.
164   extern application_instance _i_handle;
165     //!< dll_root.cpp defines this for all dlls.
166   #define DEFINE_INSTANCE_HANDLE application_instance application::_i_handle = 0
167     //!< some applications may need this to use rc_string and others.
168     /*!< if this macro is used, then the code is impervious to future
169     changes in how the instance handle works. */
170   #define SET_INSTANCE_HANDLE(value) application::_i_handle = value
171     //!< use this to change the instance handle for this dll or exe.
172     /*!< note that this should be done only once and by the main thread. */
173   #define GET_INSTANCE_HANDLE() application::_i_handle
174     //!< a handy macro that frees one from knowing the name of the handle.
175
176 ////////////////////////////////////////////////////////////////////////////
177
178   // Unix and Linux specific items are included here.
179   #ifdef __UNIX__
180 ////    istring get_cmdline_from_proc();
181       //!< returns the command line that /proc has recorded for our process.
182
183 //    char *itoa(int to_convert, char *buffer, int radix);
184       //!< turns the integer "to_convert" into a string stored in the "buffer".
185       /*!< this is needed on linux since there doesn't seem to be a builtin
186       version of it.  the buffer must be long enough to hold the number's
187       textual representation!  the buffer's length must also account for the
188       chosen "radix" (the base for the number system, where 10 is decimal,
189       16 is hexadecimal, etc). */
190
191     #define RGB(r, g, b) (b + (g << 8) + (r << 16))
192       //!< no idea if that's even approximately right.
193   #endif
194
195   // ms-windows of more modern types, i.e. win32.
196   #ifdef __WIN32__
197
198 //    bool event_poll(MSG &message);
199       //!< tries to process one win32 event and retrieve the "message" from it.
200       /*!< this is a very general poll and will retrieve any message that's
201       available for the current thread.  the message is actually processed
202       here also, by calling translate and dispatch.  the returned structure
203       is mainly interesting for knowing what was done. */
204
205 //hmmm: is there an equivalent to this for unix?
206 //    bool is_address_valid(const void *address, int size_expected,
207 //            bool writable = false);
208       //!< checks that the address specified is a valid pointer.
209       /*! also tests that the address's allocated space has the
210       "size_expected".  if "writable" is true, then the pointer is
211       checked for being writable as well as readable. */
212
213     #define BROADCAST_HANDLE HWND_BROADCAST
214
215     enum known_operating_systems {
216       WIN_95, WIN_NT, WIN_2K, WIN_XP, WIN_SRV2K3, WIN_VISTA, WIN_SRV2K8,
217       UNKNOWN_OS
218     };
219     const char *opsystem_name(known_operating_systems which);
220       //!< returns the textual form of the known_operating_systems enum.
221
222     known_operating_systems determine_OS();
223       //!< returns the operating system that seems to be running currently.
224       /*!< note that WIN_95 also covers windows 98 and windows ME. */
225
226 //    istring rc_string(u_int id, application_instance instance);
227       //!< acquires a string from a particular "instance".
228       /*!< the "id" is the resource identifier for the desired string in
229       that "instance". */
230
231 //    istring rc_string(u_int id);
232       //!< simplified from above function by not needing an "instance".
233       /*!< the "current" dynamic library or executable's resources are sought
234       for the "id". */
235
236 //    void show_wait_cursor();
237       //!< changes the cursor to the "wait" look, which is usually an hourglass.
238 //    void show_normal_cursor();
239       //!< changes the cursor to "normal", which is usually a pointing arrow.
240
241   #endif // win32.
242
243 } // namespace.
244
245 #endif // outer guard.
246