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