]> git.saurik.com Git - wxWidgets.git/blame - include/wx/utils.h
tried to implement division of wxLongLongs - doesn't work at all, will finish tonight
[wxWidgets.git] / include / wx / utils.h
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: utils.h
3// Purpose: Miscellaneous utilities
4// Author: Julian Smart
5// Modified by:
6// Created: 29/01/98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Julian Smart
3f4a0c5b 9// Licence: wxWindows license
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_UTILSH__
13#define _WX_UTILSH__
c801d85f 14
d6b9496a
VZ
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
c801d85f 19#ifdef __GNUG__
d6b9496a 20 #pragma interface "utils.h"
c801d85f
KB
21#endif
22
23#include "wx/setup.h"
24#include "wx/object.h"
25#include "wx/list.h"
c801d85f
KB
26#include "wx/filefn.h"
27
c801d85f 28#ifdef __X__
d6b9496a
VZ
29 #include <dirent.h>
30 #include <unistd.h>
c801d85f
KB
31#endif
32
33#include <stdio.h>
34
d6b9496a
VZ
35// ----------------------------------------------------------------------------
36// Forward declaration
37// ----------------------------------------------------------------------------
38
39class WXDLLEXPORT wxProcess;
40class WXDLLEXPORT wxFrame;
e4b4d60e 41class WXDLLEXPORT wxWindow;
d6b9496a
VZ
42
43// FIXME should use wxStricmp() instead
717b9bf2 44#if defined(__GNUWIN32__)
d6b9496a
VZ
45 #define stricmp strcasecmp
46 #define strnicmp strncasecmp
c801d85f
KB
47#endif
48
d6b9496a
VZ
49// ----------------------------------------------------------------------------
50// Macros
51// ----------------------------------------------------------------------------
c801d85f 52
d6b9496a
VZ
53#define wxMax(a,b) (((a) > (b)) ? (a) : (b))
54#define wxMin(a,b) (((a) < (b)) ? (a) : (b))
c801d85f 55
d6b9496a
VZ
56// ----------------------------------------------------------------------------
57// String functions (deprecated, use wxString)
58// ----------------------------------------------------------------------------
59
60// Useful buffer (FIXME VZ: yeah, that is. To be removed!)
9d2f3c71 61WXDLLEXPORT_DATA(extern wxChar*) wxBuffer;
c801d85f
KB
62
63// Make a copy of this string using 'new'
9d2f3c71 64WXDLLEXPORT wxChar* copystring(const wxChar *s);
c801d85f 65
d6b9496a 66// Matches string one within string two regardless of case
9d2f3c71 67WXDLLEXPORT bool StringMatch(wxChar *one, wxChar *two, bool subString = TRUE, bool exact = FALSE);
d6b9496a
VZ
68
69// A shorter way of using strcmp
9d2f3c71 70#define wxStringEq(s1, s2) (s1 && s2 && (wxStrcmp(s1, s2) == 0))
d6b9496a
VZ
71
72// ----------------------------------------------------------------------------
73// Miscellaneous functions
74// ----------------------------------------------------------------------------
75
76// Sound the bell
e90c1d2a 77WXDLLEXPORT void wxBell();
d6b9496a 78
bdc72a22
VZ
79// Get OS description as a user-readable string
80WXDLLEXPORT wxString wxGetOsDescription();
81
d6b9496a 82// Get OS version
bdc72a22
VZ
83WXDLLEXPORT int wxGetOsVersion(int *majorVsn = (int *) NULL,
84 int *minorVsn = (int *) NULL);
d6b9496a
VZ
85
86// Return a string with the current date/time
87WXDLLEXPORT wxString wxNow();
88
e90c1d2a 89#if wxUSE_GUI
63cc5d9d
RR
90// Don't synthesize KeyUp events holding down a key and producing
91// KeyDown events with autorepeat. On by default and always on
92// in wxMSW.
f0492f7d
RR
93WXDLLEXPORT bool wxSetDetectableAutoRepeat( bool flag );
94
d6b9496a
VZ
95// ----------------------------------------------------------------------------
96// Window ID management
97// ----------------------------------------------------------------------------
98
c801d85f 99// Generate a unique ID
afb74891 100WXDLLEXPORT long wxNewId();
d6b9496a
VZ
101#if !defined(NewId) && defined(WXWIN_COMPATIBILITY)
102 #define NewId wxNewId
103#endif
c801d85f
KB
104
105// Ensure subsequent IDs don't clash with this one
184b5d99 106WXDLLEXPORT void wxRegisterId(long id);
d6b9496a
VZ
107#if !defined(RegisterId) && defined(WXWIN_COMPATIBILITY)
108 #define RegisterId wxRegisterId
109#endif
c801d85f
KB
110
111// Return the current ID
afb74891 112WXDLLEXPORT long wxGetCurrentId();
c801d85f 113
e90c1d2a
VZ
114#endif // wxUSE_GUI
115
d6b9496a
VZ
116// ----------------------------------------------------------------------------
117// Various conversions
118// ----------------------------------------------------------------------------
c801d85f 119
9d2f3c71
OK
120WXDLLEXPORT_DATA(extern const wxChar*) wxFloatToStringStr;
121WXDLLEXPORT_DATA(extern const wxChar*) wxDoubleToStringStr;
c801d85f 122
9d2f3c71
OK
123WXDLLEXPORT void StringToFloat(wxChar *s, float *number);
124WXDLLEXPORT wxChar* FloatToString(float number, const wxChar *fmt = wxFloatToStringStr);
125WXDLLEXPORT void StringToDouble(wxChar *s, double *number);
126WXDLLEXPORT wxChar* DoubleToString(double number, const wxChar *fmt = wxDoubleToStringStr);
127WXDLLEXPORT void StringToInt(wxChar *s, int *number);
128WXDLLEXPORT void StringToLong(wxChar *s, long *number);
129WXDLLEXPORT wxChar* IntToString(int number);
130WXDLLEXPORT wxChar* LongToString(long number);
c801d85f 131
c801d85f 132// Convert 2-digit hex number to decimal
184b5d99 133WXDLLEXPORT int wxHexToDec(const wxString& buf);
c801d85f
KB
134
135// Convert decimal integer to 2-character hex string
9d2f3c71 136WXDLLEXPORT void wxDecToHex(int dec, wxChar *buf);
184b5d99 137WXDLLEXPORT wxString wxDecToHex(int dec);
c801d85f 138
d6b9496a
VZ
139// ----------------------------------------------------------------------------
140// Process management
141// ----------------------------------------------------------------------------
142
c801d85f 143// Execute another program. Returns 0 if there was an error, a PID otherwise.
9d2f3c71 144WXDLLEXPORT long wxExecute(wxChar **argv, bool sync = FALSE,
c67daf87 145 wxProcess *process = (wxProcess *) NULL);
184b5d99 146WXDLLEXPORT long wxExecute(const wxString& command, bool sync = FALSE,
c67daf87 147 wxProcess *process = (wxProcess *) NULL);
c801d85f 148
d6b9496a
VZ
149enum wxSignal
150{
151 wxSIGNONE = 0, // verify if the process exists under Unix
152 wxSIGHUP,
153 wxSIGINT,
154 wxSIGQUIT,
155 wxSIGILL,
156 wxSIGTRAP,
157 wxSIGABRT,
158 wxSIGIOT = wxSIGABRT, // another name
159 wxSIGEMT,
160 wxSIGFPE,
161 wxSIGKILL,
162 wxSIGBUS,
163 wxSIGSEGV,
164 wxSIGSYS,
165 wxSIGPIPE,
166 wxSIGALRM,
167 wxSIGTERM
168
169 // further signals are different in meaning between different Unix systems
170};
c801d85f 171
d6b9496a
VZ
172// the argument is ignored under Windows - the process is always killed
173WXDLLEXPORT int wxKill(long pid, wxSignal sig = wxSIGTERM);
c801d85f
KB
174
175// Execute a command in an interactive shell window
176// If no command then just the shell
62448488 177WXDLLEXPORT bool wxShell(const wxString& command = wxEmptyString);
c801d85f 178
b568d04f 179// Sleep for nSecs seconds
184b5d99 180WXDLLEXPORT void wxSleep(int nSecs);
c801d85f 181
afb74891
VZ
182// Sleep for a given amount of milliseconds
183WXDLLEXPORT void wxUsleep(unsigned long milliseconds);
184
c801d85f 185// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
afb74891 186WXDLLEXPORT long wxGetFreeMemory();
c801d85f 187
d6b9496a
VZ
188// ----------------------------------------------------------------------------
189// Network and username functions.
190// ----------------------------------------------------------------------------
c801d85f 191
d6b9496a 192// NB: "char *" functions are deprecated, use wxString ones!
c801d85f
KB
193
194// Get eMail address
9d2f3c71 195WXDLLEXPORT bool wxGetEmailAddress(wxChar *buf, int maxSize);
d6b9496a 196WXDLLEXPORT wxString wxGetEmailAddress();
c801d85f
KB
197
198// Get hostname.
9d2f3c71 199WXDLLEXPORT bool wxGetHostName(wxChar *buf, int maxSize);
d6b9496a
VZ
200WXDLLEXPORT wxString wxGetHostName();
201
202// Get FQDN
203WXDLLEXPORT wxString wxGetFullHostName();
96c5bd7f 204WXDLLEXPORT bool wxGetFullHostName(wxChar *buf, int maxSize);
c801d85f 205
d6b9496a 206// Get user ID e.g. jacs (this is known as login name under Unix)
9d2f3c71 207WXDLLEXPORT bool wxGetUserId(wxChar *buf, int maxSize);
d6b9496a 208WXDLLEXPORT wxString wxGetUserId();
c801d85f
KB
209
210// Get user name e.g. Julian Smart
9d2f3c71 211WXDLLEXPORT bool wxGetUserName(wxChar *buf, int maxSize);
d6b9496a
VZ
212WXDLLEXPORT wxString wxGetUserName();
213
214// Get current Home dir and copy to dest (returns pstr->c_str())
c51deffc 215WXDLLEXPORT wxString wxGetHomeDir();
9d2f3c71 216WXDLLEXPORT const wxChar* wxGetHomeDir(wxString *pstr);
d6b9496a
VZ
217
218// Get the user's home dir (caller must copy --- volatile)
219// returns NULL is no HOME dir is known
61ef57fc
OK
220#if defined(__UNIX__) && wxUSE_UNICODE
221WXDLLEXPORT const wxMB2WXbuf wxGetUserHome(const wxString& user = wxEmptyString);
222#else
9d2f3c71 223WXDLLEXPORT wxChar* wxGetUserHome(const wxString& user = wxEmptyString);
61ef57fc 224#endif
d6b9496a 225
e90c1d2a
VZ
226#if wxUSE_GUI // GUI only things from now on
227
d6b9496a 228// ----------------------------------------------------------------------------
974e8d94 229// Menu accelerators related things
d6b9496a 230// ----------------------------------------------------------------------------
c801d85f 231
9d2f3c71 232WXDLLEXPORT wxChar* wxStripMenuCodes(wxChar *in, wxChar *out = (wxChar *) NULL);
184b5d99 233WXDLLEXPORT wxString wxStripMenuCodes(const wxString& str);
c801d85f 234
974e8d94
VZ
235#if wxUSE_ACCEL
236class WXDLLEXPORT wxAcceleratorEntry;
237WXDLLEXPORT wxAcceleratorEntry *wxGetAccelFromString(const wxString& label);
238#endif // wxUSE_ACCEL
239
d6b9496a
VZ
240// ----------------------------------------------------------------------------
241// Window search
242// ----------------------------------------------------------------------------
243
c801d85f
KB
244// Find the window/widget with the given title or label.
245// Pass a parent to begin the search from, or NULL to look through
246// all windows.
184b5d99 247WXDLLEXPORT wxWindow* wxFindWindowByLabel(const wxString& title, wxWindow *parent = (wxWindow *) NULL);
c801d85f
KB
248
249// Find window by name, and if that fails, by label.
184b5d99 250WXDLLEXPORT wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent = (wxWindow *) NULL);
c801d85f
KB
251
252// Returns menu item id or -1 if none.
184b5d99 253WXDLLEXPORT int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString);
c801d85f 254
d6b9496a
VZ
255// ----------------------------------------------------------------------------
256// Message/event queue helpers
257// ----------------------------------------------------------------------------
c801d85f
KB
258
259// Yield to other apps/messages
afb74891 260WXDLLEXPORT bool wxYield();
c801d85f 261
ead7ce10
KB
262// Yield to other apps/messages and disable user input
263WXDLLEXPORT bool wxSafeYield(wxWindow *win = NULL);
264
95dee651
KB
265// Enable or disable input to all top level windows
266WXDLLEXPORT void wxEnableTopLevelWindows(bool enable = TRUE);
267
d6b9496a
VZ
268// Check whether this window wants to process messages, e.g. Stop button
269// in long calculations.
270WXDLLEXPORT bool wxCheckForInterrupt(wxWindow *wnd);
271
272// Consume all events until no more left
273WXDLLEXPORT void wxFlushEvents();
274
275// ----------------------------------------------------------------------------
276// Cursors
277// ----------------------------------------------------------------------------
c801d85f
KB
278
279// Set the cursor to the busy cursor for all windows
280class WXDLLEXPORT wxCursor;
281WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
184b5d99 282WXDLLEXPORT void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
e2a6f233 283
c801d85f 284// Restore cursor to normal
afb74891 285WXDLLEXPORT void wxEndBusyCursor();
d6b9496a 286
c801d85f 287// TRUE if we're between the above two calls
afb74891 288WXDLLEXPORT bool wxIsBusy();
c801d85f 289
e2a6f233
JS
290// Convenience class so we can just create a wxBusyCursor object on the stack
291class WXDLLEXPORT wxBusyCursor
292{
afb74891
VZ
293public:
294 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR)
295 { wxBeginBusyCursor(cursor); }
296 ~wxBusyCursor()
297 { wxEndBusyCursor(); }
e2a6f233
JS
298};
299
d6b9496a
VZ
300// ----------------------------------------------------------------------------
301// Error message functions used by wxWindows (deprecated, use wxLog)
302// ----------------------------------------------------------------------------
303
304// Format a message on the standard error (UNIX) or the debugging
305// stream (Windows)
bdc72a22 306WXDLLEXPORT void wxDebugMsg(const wxChar *fmt ...);
c801d85f
KB
307
308// Non-fatal error (continues)
9d2f3c71 309WXDLLEXPORT_DATA(extern const wxChar*) wxInternalErrorStr;
184b5d99 310WXDLLEXPORT void wxError(const wxString& msg, const wxString& title = wxInternalErrorStr);
c801d85f
KB
311
312// Fatal error (exits)
9d2f3c71 313WXDLLEXPORT_DATA(extern const wxChar*) wxFatalErrorStr;
184b5d99 314WXDLLEXPORT void wxFatalError(const wxString& msg, const wxString& title = wxFatalErrorStr);
c801d85f 315
d6b9496a 316// ----------------------------------------------------------------------------
c801d85f 317// Reading and writing resources (eg WIN.INI, .Xdefaults)
d6b9496a
VZ
318// ----------------------------------------------------------------------------
319
47d67540 320#if wxUSE_RESOURCES
62448488
JS
321WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file = wxEmptyString);
322WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file = wxEmptyString);
323WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file = wxEmptyString);
324WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file = wxEmptyString);
325
9d2f3c71 326WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, wxChar **value, const wxString& file = wxEmptyString);
62448488
JS
327WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file = wxEmptyString);
328WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file = wxEmptyString);
329WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file = wxEmptyString);
47d67540 330#endif // wxUSE_RESOURCES
c801d85f 331
c801d85f
KB
332void WXDLLEXPORT wxGetMousePosition( int* x, int* y );
333
334// MSW only: get user-defined resource from the .res file.
335// Returns NULL or newly-allocated memory, so use delete[] to clean up.
2049ba38 336#ifdef __WXMSW__
9d2f3c71
OK
337WXDLLEXPORT extern const wxChar* wxUserResourceStr;
338WXDLLEXPORT wxChar* wxLoadUserResource(const wxString& resourceName, const wxString& resourceType = wxUserResourceStr);
c030b70f
JS
339
340// Implemented in utils.cpp: VC++, Win95 only. Sets up a console for standard
341// input/output
342WXDLLEXPORT void wxRedirectIOToConsole();
343
d6b9496a
VZ
344#endif // MSW
345
346// ----------------------------------------------------------------------------
347// Display and colorss (X only)
348// ----------------------------------------------------------------------------
c801d85f 349
d111a89a
VZ
350#ifdef __WXGTK__
351 void *wxGetDisplay();
352#endif
353
c801d85f 354#ifdef __X__
d6b9496a
VZ
355 WXDisplay *wxGetDisplay();
356 bool wxSetDisplay(const wxString& display_name);
357 wxString wxGetDisplayName();
d111a89a 358#endif // X or GTK+
c801d85f
KB
359
360#ifdef __X__
361
338dd992
JJ
362#ifdef __VMS__ // Xlib.h for VMS is not (yet) compatible with C++
363 // The resulting warnings are switched off here
364#pragma message disable nosimpint
365#endif
c801d85f 366#include <X11/Xlib.h>
338dd992
JJ
367#ifdef __VMS__
368#pragma message enable nosimpint
369#endif
c801d85f
KB
370
371#define wxMAX_RGB 0xff
372#define wxMAX_SV 1000
373#define wxSIGN(x) ((x < 0) ? -x : x)
374#define wxH_WEIGHT 4
375#define wxS_WEIGHT 1
376#define wxV_WEIGHT 2
377
378typedef struct wx_hsv {
379 int h,s,v;
380 } wxHSV;
d6b9496a 381
c801d85f
KB
382#define wxMax3(x,y,z) ((x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z))
383#define wxMin3(x,y,z) ((x < y) ? ((x < z) ? x : z) : ((y < z) ? y : z))
384
c801d85f
KB
385void wxHSVToXColor(wxHSV *hsv,XColor *xcolor);
386void wxXColorToHSV(wxHSV *hsv,XColor *xcolor);
387void wxAllocNearestColor(Display *display,Colormap colormap,XColor *xcolor);
388void wxAllocColor(Display *display,Colormap colormap,XColor *xcolor);
389
390#endif //__X__
391
e90c1d2a
VZ
392#endif // wxUSE_GUI
393
c801d85f 394#endif
34138703 395 // _WX_UTILSH__