]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/utils.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Miscellaneous utilities
4 // Author: Julian Smart
8 // Copyright: (c) 1998 Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
20 #pragma interface "utils.h"
24 #include "wx/object.h"
26 #include "wx/window.h"
27 #include "wx/filefn.h"
36 // ----------------------------------------------------------------------------
37 // Forward declaration
38 // ----------------------------------------------------------------------------
40 class WXDLLEXPORT wxProcess
;
41 class WXDLLEXPORT wxFrame
;
43 // FIXME should use wxStricmp() instead
45 #define stricmp strcasecmp
46 #define strnicmp strncasecmp
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 #define wxMax(a,b) (((a) > (b)) ? (a) : (b))
54 #define wxMin(a,b) (((a) < (b)) ? (a) : (b))
56 // ----------------------------------------------------------------------------
57 // String functions (deprecated, use wxString)
58 // ----------------------------------------------------------------------------
60 // Useful buffer (FIXME VZ: yeah, that is. To be removed!)
61 WXDLLEXPORT_DATA(extern wxChar
*) wxBuffer
;
63 // Make a copy of this string using 'new'
64 WXDLLEXPORT wxChar
* copystring(const wxChar
*s
);
66 // Matches string one within string two regardless of case
67 WXDLLEXPORT
bool StringMatch(wxChar
*one
, wxChar
*two
, bool subString
= TRUE
, bool exact
= FALSE
);
69 // A shorter way of using strcmp
70 #define wxStringEq(s1, s2) (s1 && s2 && (wxStrcmp(s1, s2) == 0))
72 // ----------------------------------------------------------------------------
73 // Miscellaneous functions
74 // ----------------------------------------------------------------------------
77 WXDLLEXPORT
void wxBell(void) ;
80 WXDLLEXPORT
int wxGetOsVersion(int *majorVsn
= (int *) NULL
,int *minorVsn
= (int *) NULL
) ;
82 // Return a string with the current date/time
83 WXDLLEXPORT wxString
wxNow();
85 // Don't synthesize KeyUp events holding down a key and producing
86 // KeyDown events with autorepeat. On by default and always on
88 WXDLLEXPORT
bool wxSetDetectableAutoRepeat( bool flag
);
90 // ----------------------------------------------------------------------------
91 // Window ID management
92 // ----------------------------------------------------------------------------
94 // Generate a unique ID
95 WXDLLEXPORT
long wxNewId();
96 #if !defined(NewId) && defined(WXWIN_COMPATIBILITY)
100 // Ensure subsequent IDs don't clash with this one
101 WXDLLEXPORT
void wxRegisterId(long id
);
102 #if !defined(RegisterId) && defined(WXWIN_COMPATIBILITY)
103 #define RegisterId wxRegisterId
106 // Return the current ID
107 WXDLLEXPORT
long wxGetCurrentId();
109 // ----------------------------------------------------------------------------
110 // Various conversions
111 // ----------------------------------------------------------------------------
113 WXDLLEXPORT_DATA(extern const wxChar
*) wxFloatToStringStr
;
114 WXDLLEXPORT_DATA(extern const wxChar
*) wxDoubleToStringStr
;
116 WXDLLEXPORT
void StringToFloat(wxChar
*s
, float *number
);
117 WXDLLEXPORT wxChar
* FloatToString(float number
, const wxChar
*fmt
= wxFloatToStringStr
);
118 WXDLLEXPORT
void StringToDouble(wxChar
*s
, double *number
);
119 WXDLLEXPORT wxChar
* DoubleToString(double number
, const wxChar
*fmt
= wxDoubleToStringStr
);
120 WXDLLEXPORT
void StringToInt(wxChar
*s
, int *number
);
121 WXDLLEXPORT
void StringToLong(wxChar
*s
, long *number
);
122 WXDLLEXPORT wxChar
* IntToString(int number
);
123 WXDLLEXPORT wxChar
* LongToString(long number
);
125 // Convert 2-digit hex number to decimal
126 WXDLLEXPORT
int wxHexToDec(const wxString
& buf
);
128 // Convert decimal integer to 2-character hex string
129 WXDLLEXPORT
void wxDecToHex(int dec
, wxChar
*buf
);
130 WXDLLEXPORT wxString
wxDecToHex(int dec
);
132 // ----------------------------------------------------------------------------
133 // Process management
134 // ----------------------------------------------------------------------------
136 // Execute another program. Returns 0 if there was an error, a PID otherwise.
137 WXDLLEXPORT
long wxExecute(wxChar
**argv
, bool sync
= FALSE
,
138 wxProcess
*process
= (wxProcess
*) NULL
);
139 WXDLLEXPORT
long wxExecute(const wxString
& command
, bool sync
= FALSE
,
140 wxProcess
*process
= (wxProcess
*) NULL
);
144 wxSIGNONE
= 0, // verify if the process exists under Unix
151 wxSIGIOT
= wxSIGABRT
, // another name
162 // further signals are different in meaning between different Unix systems
165 // the argument is ignored under Windows - the process is always killed
166 WXDLLEXPORT
int wxKill(long pid
, wxSignal sig
= wxSIGTERM
);
168 // Execute a command in an interactive shell window
169 // If no command then just the shell
170 WXDLLEXPORT
bool wxShell(const wxString
& command
= wxEmptyString
);
172 // Sleep for nSecs seconds under UNIX, do nothing under Windows
173 WXDLLEXPORT
void wxSleep(int nSecs
);
175 // Sleep for a given amount of milliseconds
176 WXDLLEXPORT
void wxUsleep(unsigned long milliseconds
);
178 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
179 WXDLLEXPORT
long wxGetFreeMemory();
181 // ----------------------------------------------------------------------------
182 // Network and username functions.
183 // ----------------------------------------------------------------------------
185 // NB: "char *" functions are deprecated, use wxString ones!
188 WXDLLEXPORT
bool wxGetEmailAddress(wxChar
*buf
, int maxSize
);
189 WXDLLEXPORT wxString
wxGetEmailAddress();
192 WXDLLEXPORT
bool wxGetHostName(wxChar
*buf
, int maxSize
);
193 WXDLLEXPORT wxString
wxGetHostName();
196 WXDLLEXPORT wxString
wxGetFullHostName();
197 WXDLLEXPORT
bool wxGetFullHostName(wxChar
*buf
, int maxSize
);
199 // Get user ID e.g. jacs (this is known as login name under Unix)
200 WXDLLEXPORT
bool wxGetUserId(wxChar
*buf
, int maxSize
);
201 WXDLLEXPORT wxString
wxGetUserId();
203 // Get user name e.g. Julian Smart
204 WXDLLEXPORT
bool wxGetUserName(wxChar
*buf
, int maxSize
);
205 WXDLLEXPORT wxString
wxGetUserName();
207 // Get current Home dir and copy to dest (returns pstr->c_str())
208 WXDLLEXPORT
const wxChar
* wxGetHomeDir(wxString
*pstr
);
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
213 WXDLLEXPORT
const wxMB2WXbuf
wxGetUserHome(const wxString
& user
= wxEmptyString
);
215 WXDLLEXPORT wxChar
* wxGetUserHome(const wxString
& user
= wxEmptyString
);
218 // ----------------------------------------------------------------------------
219 // Strip out any menu codes
220 // ----------------------------------------------------------------------------
222 WXDLLEXPORT wxChar
* wxStripMenuCodes(wxChar
*in
, wxChar
*out
= (wxChar
*) NULL
);
223 WXDLLEXPORT wxString
wxStripMenuCodes(const wxString
& str
);
225 // ----------------------------------------------------------------------------
227 // ----------------------------------------------------------------------------
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
232 WXDLLEXPORT wxWindow
* wxFindWindowByLabel(const wxString
& title
, wxWindow
*parent
= (wxWindow
*) NULL
);
234 // Find window by name, and if that fails, by label.
235 WXDLLEXPORT wxWindow
* wxFindWindowByName(const wxString
& name
, wxWindow
*parent
= (wxWindow
*) NULL
);
237 // Returns menu item id or -1 if none.
238 WXDLLEXPORT
int wxFindMenuItemId(wxFrame
*frame
, const wxString
& menuString
, const wxString
& itemString
);
240 // ----------------------------------------------------------------------------
241 // Message/event queue helpers
242 // ----------------------------------------------------------------------------
244 // Yield to other apps/messages
245 WXDLLEXPORT
bool wxYield();
247 // Yield to other apps/messages and disable user input
248 WXDLLEXPORT
bool wxSafeYield(wxWindow
*win
= NULL
);
250 // Enable or disable input to all top level windows
251 WXDLLEXPORT
void wxEnableTopLevelWindows(bool enable
= TRUE
);
253 // Check whether this window wants to process messages, e.g. Stop button
254 // in long calculations.
255 WXDLLEXPORT
bool wxCheckForInterrupt(wxWindow
*wnd
);
257 // Consume all events until no more left
258 WXDLLEXPORT
void wxFlushEvents();
260 // ----------------------------------------------------------------------------
262 // ----------------------------------------------------------------------------
264 // Set the cursor to the busy cursor for all windows
265 class WXDLLEXPORT wxCursor
;
266 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
267 WXDLLEXPORT
void wxBeginBusyCursor(wxCursor
*cursor
= wxHOURGLASS_CURSOR
);
269 // Restore cursor to normal
270 WXDLLEXPORT
void wxEndBusyCursor();
272 // TRUE if we're between the above two calls
273 WXDLLEXPORT
bool wxIsBusy();
275 // Convenience class so we can just create a wxBusyCursor object on the stack
276 class WXDLLEXPORT wxBusyCursor
279 wxBusyCursor(wxCursor
* cursor
= wxHOURGLASS_CURSOR
)
280 { wxBeginBusyCursor(cursor
); }
282 { wxEndBusyCursor(); }
285 // ----------------------------------------------------------------------------
286 // Error message functions used by wxWindows (deprecated, use wxLog)
287 // ----------------------------------------------------------------------------
289 // Format a message on the standard error (UNIX) or the debugging
291 WXDLLEXPORT
void wxDebugMsg(const wxChar
*fmt
...) ;
293 // Non-fatal error (continues)
294 WXDLLEXPORT_DATA(extern const wxChar
*) wxInternalErrorStr
;
295 WXDLLEXPORT
void wxError(const wxString
& msg
, const wxString
& title
= wxInternalErrorStr
);
297 // Fatal error (exits)
298 WXDLLEXPORT_DATA(extern const wxChar
*) wxFatalErrorStr
;
299 WXDLLEXPORT
void wxFatalError(const wxString
& msg
, const wxString
& title
= wxFatalErrorStr
);
301 // ----------------------------------------------------------------------------
302 // Reading and writing resources (eg WIN.INI, .Xdefaults)
303 // ----------------------------------------------------------------------------
306 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
= wxEmptyString
);
307 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
= wxEmptyString
);
308 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
= wxEmptyString
);
309 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
= wxEmptyString
);
311 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, wxChar
**value
, const wxString
& file
= wxEmptyString
);
312 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
= wxEmptyString
);
313 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
= wxEmptyString
);
314 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
= wxEmptyString
);
315 #endif // wxUSE_RESOURCES
317 void WXDLLEXPORT
wxGetMousePosition( int* x
, int* y
);
319 // MSW only: get user-defined resource from the .res file.
320 // Returns NULL or newly-allocated memory, so use delete[] to clean up.
322 WXDLLEXPORT
extern const wxChar
* wxUserResourceStr
;
323 WXDLLEXPORT wxChar
* wxLoadUserResource(const wxString
& resourceName
, const wxString
& resourceType
= wxUserResourceStr
);
325 // Implemented in utils.cpp: VC++, Win95 only. Sets up a console for standard
327 WXDLLEXPORT
void wxRedirectIOToConsole();
331 // ----------------------------------------------------------------------------
332 // Display and colorss (X only)
333 // ----------------------------------------------------------------------------
336 WXDisplay
*wxGetDisplay();
337 bool wxSetDisplay(const wxString
& display_name
);
338 wxString
wxGetDisplayName();
343 #include <X11/Xlib.h>
345 #define wxMAX_RGB 0xff
346 #define wxMAX_SV 1000
347 #define wxSIGN(x) ((x < 0) ? -x : x)
352 typedef struct wx_hsv
{
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))
359 void wxHSVToXColor(wxHSV
*hsv
,XColor
*xcolor
);
360 void wxXColorToHSV(wxHSV
*hsv
,XColor
*xcolor
);
361 void wxAllocNearestColor(Display
*display
,Colormap colormap
,XColor
*xcolor
);
362 void wxAllocColor(Display
*display
,Colormap colormap
,XColor
*xcolor
);