]>
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"
29 #include "wx/ioswrap.h"
38 // ----------------------------------------------------------------------------
39 // Forward declaration
40 // ----------------------------------------------------------------------------
42 class WXDLLEXPORT wxProcess
;
43 class WXDLLEXPORT wxFrame
;
45 // FIXME should use wxStricmp() instead
47 #define stricmp strcasecmp
48 #define strnicmp strncasecmp
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
55 #define wxMax(a,b) (((a) > (b)) ? (a) : (b))
56 #define wxMin(a,b) (((a) < (b)) ? (a) : (b))
58 // ----------------------------------------------------------------------------
59 // String functions (deprecated, use wxString)
60 // ----------------------------------------------------------------------------
62 // Useful buffer (FIXME VZ: yeah, that is. To be removed!)
63 WXDLLEXPORT_DATA(extern wxChar
*) wxBuffer
;
65 // Make a copy of this string using 'new'
66 WXDLLEXPORT wxChar
* copystring(const wxChar
*s
);
68 // Matches string one within string two regardless of case
69 WXDLLEXPORT
bool StringMatch(wxChar
*one
, wxChar
*two
, bool subString
= TRUE
, bool exact
= FALSE
);
71 // A shorter way of using strcmp
72 #define wxStringEq(s1, s2) (s1 && s2 && (wxStrcmp(s1, s2) == 0))
74 // ----------------------------------------------------------------------------
75 // Miscellaneous functions
76 // ----------------------------------------------------------------------------
79 WXDLLEXPORT
void wxBell(void) ;
82 WXDLLEXPORT
int wxGetOsVersion(int *majorVsn
= (int *) NULL
,int *minorVsn
= (int *) NULL
) ;
84 // Return a string with the current date/time
85 WXDLLEXPORT wxString
wxNow();
87 // Don't synthesize KeyUp events holding down a key and producing
88 // KeyDown events with autorepeat. On by default and always on
90 WXDLLEXPORT
bool wxSetDetectableAutoRepeat( bool flag
);
92 // ----------------------------------------------------------------------------
93 // Window ID management
94 // ----------------------------------------------------------------------------
96 // Generate a unique ID
97 WXDLLEXPORT
long wxNewId();
98 #if !defined(NewId) && defined(WXWIN_COMPATIBILITY)
102 // Ensure subsequent IDs don't clash with this one
103 WXDLLEXPORT
void wxRegisterId(long id
);
104 #if !defined(RegisterId) && defined(WXWIN_COMPATIBILITY)
105 #define RegisterId wxRegisterId
108 // Return the current ID
109 WXDLLEXPORT
long wxGetCurrentId();
111 // ----------------------------------------------------------------------------
112 // Various conversions
113 // ----------------------------------------------------------------------------
115 WXDLLEXPORT_DATA(extern const wxChar
*) wxFloatToStringStr
;
116 WXDLLEXPORT_DATA(extern const wxChar
*) wxDoubleToStringStr
;
118 WXDLLEXPORT
void StringToFloat(wxChar
*s
, float *number
);
119 WXDLLEXPORT wxChar
* FloatToString(float number
, const wxChar
*fmt
= wxFloatToStringStr
);
120 WXDLLEXPORT
void StringToDouble(wxChar
*s
, double *number
);
121 WXDLLEXPORT wxChar
* DoubleToString(double number
, const wxChar
*fmt
= wxDoubleToStringStr
);
122 WXDLLEXPORT
void StringToInt(wxChar
*s
, int *number
);
123 WXDLLEXPORT
void StringToLong(wxChar
*s
, long *number
);
124 WXDLLEXPORT wxChar
* IntToString(int number
);
125 WXDLLEXPORT wxChar
* LongToString(long number
);
127 // Convert 2-digit hex number to decimal
128 WXDLLEXPORT
int wxHexToDec(const wxString
& buf
);
130 // Convert decimal integer to 2-character hex string
131 WXDLLEXPORT
void wxDecToHex(int dec
, wxChar
*buf
);
132 WXDLLEXPORT wxString
wxDecToHex(int dec
);
134 // ----------------------------------------------------------------------------
135 // Process management
136 // ----------------------------------------------------------------------------
138 // Execute another program. Returns 0 if there was an error, a PID otherwise.
139 WXDLLEXPORT
long wxExecute(wxChar
**argv
, bool sync
= FALSE
,
140 wxProcess
*process
= (wxProcess
*) NULL
);
141 WXDLLEXPORT
long wxExecute(const wxString
& command
, bool sync
= FALSE
,
142 wxProcess
*process
= (wxProcess
*) NULL
);
146 wxSIGNONE
= 0, // verify if the process exists under Unix
153 wxSIGIOT
= wxSIGABRT
, // another name
164 // further signals are different in meaning between different Unix systems
167 // the argument is ignored under Windows - the process is always killed
168 WXDLLEXPORT
int wxKill(long pid
, wxSignal sig
= wxSIGTERM
);
170 // Execute a command in an interactive shell window
171 // If no command then just the shell
172 WXDLLEXPORT
bool wxShell(const wxString
& command
= wxEmptyString
);
174 // Sleep for nSecs seconds under UNIX, do nothing under Windows
175 WXDLLEXPORT
void wxSleep(int nSecs
);
177 // Sleep for a given amount of milliseconds
178 WXDLLEXPORT
void wxUsleep(unsigned long milliseconds
);
180 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
181 WXDLLEXPORT
long wxGetFreeMemory();
183 // ----------------------------------------------------------------------------
184 // Network and username functions.
185 // ----------------------------------------------------------------------------
187 // NB: "char *" functions are deprecated, use wxString ones!
190 WXDLLEXPORT
bool wxGetEmailAddress(wxChar
*buf
, int maxSize
);
191 WXDLLEXPORT wxString
wxGetEmailAddress();
194 WXDLLEXPORT
bool wxGetHostName(wxChar
*buf
, int maxSize
);
195 WXDLLEXPORT wxString
wxGetHostName();
198 WXDLLEXPORT wxString
wxGetFullHostName();
200 // Get user ID e.g. jacs (this is known as login name under Unix)
201 WXDLLEXPORT
bool wxGetUserId(wxChar
*buf
, int maxSize
);
202 WXDLLEXPORT wxString
wxGetUserId();
204 // Get user name e.g. Julian Smart
205 WXDLLEXPORT
bool wxGetUserName(wxChar
*buf
, int maxSize
);
206 WXDLLEXPORT wxString
wxGetUserName();
208 // Get current Home dir and copy to dest (returns pstr->c_str())
209 WXDLLEXPORT
const wxChar
* wxGetHomeDir(wxString
*pstr
);
211 // Get the user's home dir (caller must copy --- volatile)
212 // returns NULL is no HOME dir is known
213 #if defined(__UNIX__) && wxUSE_UNICODE
214 WXDLLEXPORT
const wxMB2WXbuf
wxGetUserHome(const wxString
& user
= wxEmptyString
);
216 WXDLLEXPORT wxChar
* wxGetUserHome(const wxString
& user
= wxEmptyString
);
219 // ----------------------------------------------------------------------------
220 // Strip out any menu codes
221 // ----------------------------------------------------------------------------
223 WXDLLEXPORT wxChar
* wxStripMenuCodes(wxChar
*in
, wxChar
*out
= (wxChar
*) NULL
);
224 WXDLLEXPORT wxString
wxStripMenuCodes(const wxString
& str
);
226 // ----------------------------------------------------------------------------
228 // ----------------------------------------------------------------------------
230 // Find the window/widget with the given title or label.
231 // Pass a parent to begin the search from, or NULL to look through
233 WXDLLEXPORT wxWindow
* wxFindWindowByLabel(const wxString
& title
, wxWindow
*parent
= (wxWindow
*) NULL
);
235 // Find window by name, and if that fails, by label.
236 WXDLLEXPORT wxWindow
* wxFindWindowByName(const wxString
& name
, wxWindow
*parent
= (wxWindow
*) NULL
);
238 // Returns menu item id or -1 if none.
239 WXDLLEXPORT
int wxFindMenuItemId(wxFrame
*frame
, const wxString
& menuString
, const wxString
& itemString
);
241 // ----------------------------------------------------------------------------
242 // Message/event queue helpers
243 // ----------------------------------------------------------------------------
245 // Yield to other apps/messages
246 WXDLLEXPORT
bool wxYield();
248 // Yield to other apps/messages and disable user input
249 WXDLLEXPORT
bool wxSafeYield(wxWindow
*win
= NULL
);
251 // Enable or disable input to all top level windows
252 WXDLLEXPORT
void wxEnableTopLevelWindows(bool enable
= TRUE
);
254 // Check whether this window wants to process messages, e.g. Stop button
255 // in long calculations.
256 WXDLLEXPORT
bool wxCheckForInterrupt(wxWindow
*wnd
);
258 // Consume all events until no more left
259 WXDLLEXPORT
void wxFlushEvents();
261 // ----------------------------------------------------------------------------
263 // ----------------------------------------------------------------------------
265 // Set the cursor to the busy cursor for all windows
266 class WXDLLEXPORT wxCursor
;
267 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
268 WXDLLEXPORT
void wxBeginBusyCursor(wxCursor
*cursor
= wxHOURGLASS_CURSOR
);
270 // Restore cursor to normal
271 WXDLLEXPORT
void wxEndBusyCursor();
273 // TRUE if we're between the above two calls
274 WXDLLEXPORT
bool wxIsBusy();
276 // Convenience class so we can just create a wxBusyCursor object on the stack
277 class WXDLLEXPORT wxBusyCursor
280 wxBusyCursor(wxCursor
* cursor
= wxHOURGLASS_CURSOR
)
281 { wxBeginBusyCursor(cursor
); }
283 { wxEndBusyCursor(); }
286 // ----------------------------------------------------------------------------
287 // Error message functions used by wxWindows (deprecated, use wxLog)
288 // ----------------------------------------------------------------------------
290 // Format a message on the standard error (UNIX) or the debugging
292 WXDLLEXPORT
void wxDebugMsg(const wxChar
*fmt
...) ;
294 // Non-fatal error (continues)
295 WXDLLEXPORT_DATA(extern const wxChar
*) wxInternalErrorStr
;
296 WXDLLEXPORT
void wxError(const wxString
& msg
, const wxString
& title
= wxInternalErrorStr
);
298 // Fatal error (exits)
299 WXDLLEXPORT_DATA(extern const wxChar
*) wxFatalErrorStr
;
300 WXDLLEXPORT
void wxFatalError(const wxString
& msg
, const wxString
& title
= wxFatalErrorStr
);
302 // ----------------------------------------------------------------------------
303 // Reading and writing resources (eg WIN.INI, .Xdefaults)
304 // ----------------------------------------------------------------------------
307 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
= wxEmptyString
);
308 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
= wxEmptyString
);
309 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
= wxEmptyString
);
310 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
= wxEmptyString
);
312 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, wxChar
**value
, const wxString
& file
= wxEmptyString
);
313 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
= wxEmptyString
);
314 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
= wxEmptyString
);
315 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
= wxEmptyString
);
316 #endif // wxUSE_RESOURCES
318 void WXDLLEXPORT
wxGetMousePosition( int* x
, int* y
);
320 // MSW only: get user-defined resource from the .res file.
321 // Returns NULL or newly-allocated memory, so use delete[] to clean up.
323 WXDLLEXPORT
extern const wxChar
* wxUserResourceStr
;
324 WXDLLEXPORT wxChar
* wxLoadUserResource(const wxString
& resourceName
, const wxString
& resourceType
= wxUserResourceStr
);
326 // Implemented in utils.cpp: VC++, Win95 only. Sets up a console for standard
328 WXDLLEXPORT
void wxRedirectIOToConsole();
332 // ----------------------------------------------------------------------------
333 // Display and colorss (X only)
334 // ----------------------------------------------------------------------------
337 WXDisplay
*wxGetDisplay();
338 bool wxSetDisplay(const wxString
& display_name
);
339 wxString
wxGetDisplayName();
344 #include <X11/Xlib.h>
346 #define wxMAX_RGB 0xff
347 #define wxMAX_SV 1000
348 #define wxSIGN(x) ((x < 0) ? -x : x)
353 typedef struct wx_hsv
{
357 #define wxMax3(x,y,z) ((x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z))
358 #define wxMin3(x,y,z) ((x < y) ? ((x < z) ? x : z) : ((y < z) ? y : z))
360 void wxHSVToXColor(wxHSV
*hsv
,XColor
*xcolor
);
361 void wxXColorToHSV(wxHSV
*hsv
,XColor
*xcolor
);
362 void wxAllocNearestColor(Display
*display
,Colormap colormap
,XColor
*xcolor
);
363 void wxAllocColor(Display
*display
,Colormap colormap
,XColor
*xcolor
);