]> git.saurik.com Git - wxWidgets.git/blame - include/wx/utils.h
More wxMotif work, OGL enhancements, USE_ macro corrections, object.cpp delete
[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
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
34138703
JS
12#ifndef _WX_UTILSH__
13#define _WX_UTILSH__
c801d85f
KB
14
15#ifdef __GNUG__
16#pragma interface "utils.h"
17#endif
18
19#include "wx/setup.h"
20#include "wx/object.h"
21#include "wx/list.h"
22#include "wx/window.h"
23#include "wx/filefn.h"
cf447356 24#include "wx/process.h"
c801d85f 25
47d67540 26#if wxUSE_IOSTREAMH
c801d85f
KB
27#include <iostream.h>
28#else
29#include <iostream>
30#endif
31
32#ifdef __X__
33#ifndef __VMS__
34/*steve: these two are not known under VMS */
35#include <dirent.h>
36#include <unistd.h>
37#endif
38#endif
39
40#include <stdio.h>
41
42#ifdef __GNUWIN32__
43#define stricmp strcasecmp
44#define strnicmp strncasecmp
45#endif
46
47// Forward declaration
48class WXDLLEXPORT wxFrame;
49
50// Stupid ASCII macros
51#define wxToUpper(C) (((C) >= 'a' && (C) <= 'z')? (C) - 'a' + 'A': (C))
52#define wxToLower(C) (((C) >= 'A' && (C) <= 'Z')? (C) - 'A' + 'a': (C))
53
54// Return a string with the current date/time
55wxString WXDLLEXPORT wxNow(void);
56
57// Make a copy of this string using 'new'
58char* WXDLLEXPORT copystring(const char *s);
59
60// Generate a unique ID
61long WXDLLEXPORT wxNewId(void);
62#define NewId wxNewId
63
64// Ensure subsequent IDs don't clash with this one
65void WXDLLEXPORT wxRegisterId(long id);
66#define RegisterId wxRegisterId
67
68// Return the current ID
69long WXDLLEXPORT wxGetCurrentId(void);
70
71// Useful buffer
72WXDLLEXPORT_DATA(extern char*) wxBuffer;
73
74WXDLLEXPORT_DATA(extern const char*) wxFloatToStringStr;
75WXDLLEXPORT_DATA(extern const char*) wxDoubleToStringStr;
76
77// Various conversions
78void WXDLLEXPORT StringToFloat(char *s, float *number);
79char* WXDLLEXPORT FloatToString(float number, const char *fmt = wxFloatToStringStr);
80void WXDLLEXPORT StringToDouble(char *s, double *number);
81char* WXDLLEXPORT DoubleToString(double number, const char *fmt = wxDoubleToStringStr);
82void WXDLLEXPORT StringToInt(char *s, int *number);
83void WXDLLEXPORT StringToLong(char *s, long *number);
84char* WXDLLEXPORT IntToString(int number);
85char* WXDLLEXPORT LongToString(long number);
86
87// Matches string one within string two regardless of case
88bool WXDLLEXPORT StringMatch(char *one, char *two, bool subString = TRUE, bool exact = FALSE);
89
90// A shorter way of using strcmp
91#define wxStringEq(s1, s2) (s1 && s2 && (strcmp(s1, s2) == 0))
92
93// Convert 2-digit hex number to decimal
94int WXDLLEXPORT wxHexToDec(char *buf);
95
96// Convert decimal integer to 2-character hex string
97void WXDLLEXPORT wxDecToHex(int dec, char *buf);
98
99// Execute another program. Returns 0 if there was an error, a PID otherwise.
cf447356 100long WXDLLEXPORT wxExecute(char **argv, bool Async = FALSE,
c67daf87 101 wxProcess *process = (wxProcess *) NULL);
cf447356 102long WXDLLEXPORT wxExecute(const wxString& command, bool Async = FALSE,
c67daf87 103 wxProcess *process = (wxProcess *) NULL);
c801d85f
KB
104
105#define wxSIGTERM 1
106
107int WXDLLEXPORT wxKill(long pid, int sig=wxSIGTERM);
108
109// Execute a command in an interactive shell window
110// If no command then just the shell
111bool WXDLLEXPORT wxShell(const wxString& command = "");
112
113// Sleep for nSecs seconds under UNIX, do nothing under Windows
114void WXDLLEXPORT wxSleep(int nSecs);
115
116// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
117long WXDLLEXPORT wxGetFreeMemory(void);
118
119// Consume all events until no more left
120void WXDLLEXPORT wxFlushEvents(void);
121
122/*
123 * Network and username functions.
124 *
125 */
126
127// Get eMail address
128bool WXDLLEXPORT wxGetEmailAddress(char *buf, int maxSize);
129
130// Get hostname.
131bool WXDLLEXPORT wxGetHostName(char *buf, int maxSize);
132
133// Get user ID e.g. jacs
134bool WXDLLEXPORT wxGetUserId(char *buf, int maxSize);
135
136// Get user name e.g. Julian Smart
137bool WXDLLEXPORT wxGetUserName(char *buf, int maxSize);
138
139/*
140 * Strip out any menu codes
141 */
c67daf87 142char* WXDLLEXPORT wxStripMenuCodes(char *in, char *out = (char *) NULL);
c801d85f
KB
143
144// Find the window/widget with the given title or label.
145// Pass a parent to begin the search from, or NULL to look through
146// all windows.
c67daf87 147wxWindow* WXDLLEXPORT wxFindWindowByLabel(const wxString& title, wxWindow *parent = (wxWindow *) NULL);
c801d85f
KB
148
149// Find window by name, and if that fails, by label.
c67daf87 150wxWindow* WXDLLEXPORT wxFindWindowByName(const wxString& name, wxWindow *parent = (wxWindow *) NULL);
c801d85f
KB
151
152// Returns menu item id or -1 if none.
153int WXDLLEXPORT wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString);
154
155// A debugging stream buffer.
156// Under Windows, this writes to the Windows debug output.
157// Under other platforms, it writes to cerr.
158
159// ALl this horrible gubbins required for Borland, because the calling
160// convention needs to be the same as for streambuf.
161// Thanks to Gerhard.Vogt@embl-heidelberg.de for this solution.
162
163#if defined(__BORLANDC__) && defined(__BCOPT__) && !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
164#pragma option -po-
165#endif
166
167// Can't export a class derived from a non-export class
168#if !defined(_WINDLL) && !defined(WXUSINGDLL)
169
e55ad60e
RR
170// #ifdef new
171// #undef new
172// #endif
c801d85f
KB
173
174class WXDLLEXPORT wxDebugStreamBuf: public streambuf
175{
176 public:
177 wxDebugStreamBuf(void);
178 ~wxDebugStreamBuf(void) {}
179
180 int overflow(int i);
181 inline int underflow(void) { return EOF; }
182 int sync(void);
183};
184
47d67540 185// #if WXDEBUG && wxUSE_GLOBAL_MEMORY_OPERATORS
e55ad60e
RR
186// #define new WXDEBUG_NEW
187// #endif
c801d85f
KB
188
189#endif
190
191#if defined(__BORLANDC__) && defined(__BCOPT__) && !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
192#pragma option -po.
193#endif
194
195/*
196#if (!defined(__MINMAX_DEFINED) && !defined(max))
197#define max(a,b) (((a) > (b)) ? (a) : (b))
198#define min(a,b) (((a) < (b)) ? (a) : (b))
199#define __MINMAX_DEFINED 1
200#endif
201*/
202#define wxMax(a,b) (((a) > (b)) ? (a) : (b))
203#define wxMin(a,b) (((a) < (b)) ? (a) : (b))
204
205// Yield to other apps/messages
206bool WXDLLEXPORT wxYield(void);
207
208// Format a message on the standard error (UNIX) or the debugging
209// stream (Windows)
210void WXDLLEXPORT wxDebugMsg(const char *fmt ...) ;
211
212// Sound the bell
213void WXDLLEXPORT wxBell(void) ;
214
215// Get OS version
c67daf87 216int WXDLLEXPORT wxGetOsVersion(int *majorVsn= (int *) NULL,int *minorVsn= (int *) NULL) ;
c801d85f
KB
217
218// Set the cursor to the busy cursor for all windows
219class WXDLLEXPORT wxCursor;
220WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
221void WXDLLEXPORT wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
222
223// Restore cursor to normal
224void WXDLLEXPORT wxEndBusyCursor(void);
225
226// TRUE if we're between the above two calls
227bool WXDLLEXPORT wxIsBusy(void);
228
229/* Error message functions used by wxWindows */
230
231// Non-fatal error (continues)
232WXDLLEXPORT_DATA(extern const char*) wxInternalErrorStr;
233void WXDLLEXPORT wxError(const wxString& msg, const wxString& title = wxInternalErrorStr);
234
235// Fatal error (exits)
236WXDLLEXPORT_DATA(extern const char*) wxFatalErrorStr;
237void WXDLLEXPORT wxFatalError(const wxString& msg, const wxString& title = wxFatalErrorStr);
238
239// Reading and writing resources (eg WIN.INI, .Xdefaults)
47d67540 240#if wxUSE_RESOURCES
c801d85f
KB
241bool WXDLLEXPORT wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file = "");
242bool WXDLLEXPORT wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file = "");
243bool WXDLLEXPORT wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file = "");
244bool WXDLLEXPORT wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file = "");
245
246bool WXDLLEXPORT wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file = "");
247bool WXDLLEXPORT wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file = "");
248bool WXDLLEXPORT wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file = "");
249bool WXDLLEXPORT wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file = "");
47d67540 250#endif // wxUSE_RESOURCES
c801d85f 251
7c3c5ecc
VZ
252// Get current Home dir and copy to dest (returns pstr->c_str())
253const char* WXDLLEXPORT wxGetHomeDir(wxString *pstr);
254
c801d85f
KB
255// Get the user's home dir (caller must copy--- volatile)
256// returns NULL is no HOME dir is known
257char* WXDLLEXPORT wxGetUserHome(const wxString& user = "");
258
259// Check whether this window wants to process messages, e.g. Stop button
260// in long calculations.
261bool WXDLLEXPORT wxCheckForInterrupt(wxWindow *wnd);
262
263void WXDLLEXPORT wxGetMousePosition( int* x, int* y );
264
265// MSW only: get user-defined resource from the .res file.
266// Returns NULL or newly-allocated memory, so use delete[] to clean up.
2049ba38 267#ifdef __WXMSW__
c801d85f
KB
268extern const char* WXDLLEXPORT wxUserResourceStr;
269char* WXDLLEXPORT wxLoadUserResource(const wxString& resourceName, const wxString& resourceType = wxUserResourceStr);
270#endif
271
272// X only
273#ifdef __X__
46ccb510 274WXDisplay *wxGetDisplay();
c801d85f 275bool wxSetDisplay(const wxString& display_name);
46ccb510 276wxString wxGetDisplayName();
c801d85f
KB
277#endif
278
279#ifdef __X__
280
281#include <X11/Xlib.h>
282
283#define wxMAX_RGB 0xff
284#define wxMAX_SV 1000
285#define wxSIGN(x) ((x < 0) ? -x : x)
286#define wxH_WEIGHT 4
287#define wxS_WEIGHT 1
288#define wxV_WEIGHT 2
289
290typedef struct wx_hsv {
291 int h,s,v;
292 } wxHSV;
293
294#define wxMax3(x,y,z) ((x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z))
295#define wxMin3(x,y,z) ((x < y) ? ((x < z) ? x : z) : ((y < z) ? y : z))
296
297#define wxMax2(x,y) ((x > y) ? x : y)
298#define wxMin2(x,y) ((x < y) ? x : y)
299
300void wxHSVToXColor(wxHSV *hsv,XColor *xcolor);
301void wxXColorToHSV(wxHSV *hsv,XColor *xcolor);
302void wxAllocNearestColor(Display *display,Colormap colormap,XColor *xcolor);
303void wxAllocColor(Display *display,Colormap colormap,XColor *xcolor);
304
305#endif //__X__
306
307#endif
34138703 308 // _WX_UTILSH__