]>
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 // ----------------------------------------------------------------------------
88 // Window ID management
89 // ----------------------------------------------------------------------------
91 // Generate a unique ID
92 WXDLLEXPORT
long wxNewId();
93 #if !defined(NewId) && defined(WXWIN_COMPATIBILITY)
97 // Ensure subsequent IDs don't clash with this one
98 WXDLLEXPORT
void wxRegisterId(long id
);
99 #if !defined(RegisterId) && defined(WXWIN_COMPATIBILITY)
100 #define RegisterId wxRegisterId
103 // Return the current ID
104 WXDLLEXPORT
long wxGetCurrentId();
106 // ----------------------------------------------------------------------------
107 // Various conversions
108 // ----------------------------------------------------------------------------
110 WXDLLEXPORT_DATA(extern const wxChar
*) wxFloatToStringStr
;
111 WXDLLEXPORT_DATA(extern const wxChar
*) wxDoubleToStringStr
;
113 WXDLLEXPORT
void StringToFloat(wxChar
*s
, float *number
);
114 WXDLLEXPORT wxChar
* FloatToString(float number
, const wxChar
*fmt
= wxFloatToStringStr
);
115 WXDLLEXPORT
void StringToDouble(wxChar
*s
, double *number
);
116 WXDLLEXPORT wxChar
* DoubleToString(double number
, const wxChar
*fmt
= wxDoubleToStringStr
);
117 WXDLLEXPORT
void StringToInt(wxChar
*s
, int *number
);
118 WXDLLEXPORT
void StringToLong(wxChar
*s
, long *number
);
119 WXDLLEXPORT wxChar
* IntToString(int number
);
120 WXDLLEXPORT wxChar
* LongToString(long number
);
122 // Convert 2-digit hex number to decimal
123 WXDLLEXPORT
int wxHexToDec(const wxString
& buf
);
125 // Convert decimal integer to 2-character hex string
126 WXDLLEXPORT
void wxDecToHex(int dec
, wxChar
*buf
);
127 WXDLLEXPORT wxString
wxDecToHex(int dec
);
129 // ----------------------------------------------------------------------------
130 // Process management
131 // ----------------------------------------------------------------------------
133 // Execute another program. Returns 0 if there was an error, a PID otherwise.
134 WXDLLEXPORT
long wxExecute(wxChar
**argv
, bool sync
= FALSE
,
135 wxProcess
*process
= (wxProcess
*) NULL
);
136 WXDLLEXPORT
long wxExecute(const wxString
& command
, bool sync
= FALSE
,
137 wxProcess
*process
= (wxProcess
*) NULL
);
141 wxSIGNONE
= 0, // verify if the process exists under Unix
148 wxSIGIOT
= wxSIGABRT
, // another name
159 // further signals are different in meaning between different Unix systems
162 // the argument is ignored under Windows - the process is always killed
163 WXDLLEXPORT
int wxKill(long pid
, wxSignal sig
= wxSIGTERM
);
165 // Execute a command in an interactive shell window
166 // If no command then just the shell
167 WXDLLEXPORT
bool wxShell(const wxString
& command
= wxEmptyString
);
169 // Sleep for nSecs seconds under UNIX, do nothing under Windows
170 WXDLLEXPORT
void wxSleep(int nSecs
);
172 // Sleep for a given amount of milliseconds
173 WXDLLEXPORT
void wxUsleep(unsigned long milliseconds
);
175 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
176 WXDLLEXPORT
long wxGetFreeMemory();
178 // ----------------------------------------------------------------------------
179 // Network and username functions.
180 // ----------------------------------------------------------------------------
182 // NB: "char *" functions are deprecated, use wxString ones!
185 WXDLLEXPORT
bool wxGetEmailAddress(wxChar
*buf
, int maxSize
);
186 WXDLLEXPORT wxString
wxGetEmailAddress();
189 WXDLLEXPORT
bool wxGetHostName(wxChar
*buf
, int maxSize
);
190 WXDLLEXPORT wxString
wxGetHostName();
193 WXDLLEXPORT wxString
wxGetFullHostName();
195 // Get user ID e.g. jacs (this is known as login name under Unix)
196 WXDLLEXPORT
bool wxGetUserId(wxChar
*buf
, int maxSize
);
197 WXDLLEXPORT wxString
wxGetUserId();
199 // Get user name e.g. Julian Smart
200 WXDLLEXPORT
bool wxGetUserName(wxChar
*buf
, int maxSize
);
201 WXDLLEXPORT wxString
wxGetUserName();
203 // Get current Home dir and copy to dest (returns pstr->c_str())
204 WXDLLEXPORT
const wxChar
* wxGetHomeDir(wxString
*pstr
);
206 // Get the user's home dir (caller must copy --- volatile)
207 // returns NULL is no HOME dir is known
208 WXDLLEXPORT wxChar
* wxGetUserHome(const wxString
& user
= wxEmptyString
);
210 // ----------------------------------------------------------------------------
211 // Strip out any menu codes
212 // ----------------------------------------------------------------------------
214 WXDLLEXPORT wxChar
* wxStripMenuCodes(wxChar
*in
, wxChar
*out
= (wxChar
*) NULL
);
215 WXDLLEXPORT wxString
wxStripMenuCodes(const wxString
& str
);
217 // ----------------------------------------------------------------------------
219 // ----------------------------------------------------------------------------
221 // Find the window/widget with the given title or label.
222 // Pass a parent to begin the search from, or NULL to look through
224 WXDLLEXPORT wxWindow
* wxFindWindowByLabel(const wxString
& title
, wxWindow
*parent
= (wxWindow
*) NULL
);
226 // Find window by name, and if that fails, by label.
227 WXDLLEXPORT wxWindow
* wxFindWindowByName(const wxString
& name
, wxWindow
*parent
= (wxWindow
*) NULL
);
229 // Returns menu item id or -1 if none.
230 WXDLLEXPORT
int wxFindMenuItemId(wxFrame
*frame
, const wxString
& menuString
, const wxString
& itemString
);
232 // ----------------------------------------------------------------------------
233 // Message/event queue helpers
234 // ----------------------------------------------------------------------------
236 // Yield to other apps/messages
237 WXDLLEXPORT
bool wxYield();
239 // Yield to other apps/messages and disable user input
240 WXDLLEXPORT
bool wxSafeYield(wxWindow
*win
= NULL
);
242 // Enable or disable input to all top level windows
243 WXDLLEXPORT
void wxEnableTopLevelWindows(bool enable
= TRUE
);
245 // Check whether this window wants to process messages, e.g. Stop button
246 // in long calculations.
247 WXDLLEXPORT
bool wxCheckForInterrupt(wxWindow
*wnd
);
249 // Consume all events until no more left
250 WXDLLEXPORT
void wxFlushEvents();
252 // ----------------------------------------------------------------------------
254 // ----------------------------------------------------------------------------
256 // Set the cursor to the busy cursor for all windows
257 class WXDLLEXPORT wxCursor
;
258 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
259 WXDLLEXPORT
void wxBeginBusyCursor(wxCursor
*cursor
= wxHOURGLASS_CURSOR
);
261 // Restore cursor to normal
262 WXDLLEXPORT
void wxEndBusyCursor();
264 // TRUE if we're between the above two calls
265 WXDLLEXPORT
bool wxIsBusy();
267 // Convenience class so we can just create a wxBusyCursor object on the stack
268 class WXDLLEXPORT wxBusyCursor
271 wxBusyCursor(wxCursor
* cursor
= wxHOURGLASS_CURSOR
)
272 { wxBeginBusyCursor(cursor
); }
274 { wxEndBusyCursor(); }
277 // ----------------------------------------------------------------------------
278 // Error message functions used by wxWindows (deprecated, use wxLog)
279 // ----------------------------------------------------------------------------
281 // Format a message on the standard error (UNIX) or the debugging
283 WXDLLEXPORT
void wxDebugMsg(const wxChar
*fmt
...) ;
285 // Non-fatal error (continues)
286 WXDLLEXPORT_DATA(extern const wxChar
*) wxInternalErrorStr
;
287 WXDLLEXPORT
void wxError(const wxString
& msg
, const wxString
& title
= wxInternalErrorStr
);
289 // Fatal error (exits)
290 WXDLLEXPORT_DATA(extern const wxChar
*) wxFatalErrorStr
;
291 WXDLLEXPORT
void wxFatalError(const wxString
& msg
, const wxString
& title
= wxFatalErrorStr
);
293 // ----------------------------------------------------------------------------
294 // Reading and writing resources (eg WIN.INI, .Xdefaults)
295 // ----------------------------------------------------------------------------
298 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
= wxEmptyString
);
299 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
= wxEmptyString
);
300 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
= wxEmptyString
);
301 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
= wxEmptyString
);
303 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, wxChar
**value
, const wxString
& file
= wxEmptyString
);
304 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
= wxEmptyString
);
305 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
= wxEmptyString
);
306 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
= wxEmptyString
);
307 #endif // wxUSE_RESOURCES
309 void WXDLLEXPORT
wxGetMousePosition( int* x
, int* y
);
311 // MSW only: get user-defined resource from the .res file.
312 // Returns NULL or newly-allocated memory, so use delete[] to clean up.
314 WXDLLEXPORT
extern const wxChar
* wxUserResourceStr
;
315 WXDLLEXPORT wxChar
* wxLoadUserResource(const wxString
& resourceName
, const wxString
& resourceType
= wxUserResourceStr
);
317 // Implemented in utils.cpp: VC++, Win95 only. Sets up a console for standard
319 WXDLLEXPORT
void wxRedirectIOToConsole();
323 // ----------------------------------------------------------------------------
324 // Display and colorss (X only)
325 // ----------------------------------------------------------------------------
328 WXDisplay
*wxGetDisplay();
329 bool wxSetDisplay(const wxString
& display_name
);
330 wxString
wxGetDisplayName();
335 #include <X11/Xlib.h>
337 #define wxMAX_RGB 0xff
338 #define wxMAX_SV 1000
339 #define wxSIGN(x) ((x < 0) ? -x : x)
344 typedef struct wx_hsv
{
348 #define wxMax3(x,y,z) ((x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z))
349 #define wxMin3(x,y,z) ((x < y) ? ((x < z) ? x : z) : ((y < z) ? y : z))
351 void wxHSVToXColor(wxHSV
*hsv
,XColor
*xcolor
);
352 void wxXColorToHSV(wxHSV
*hsv
,XColor
*xcolor
);
353 void wxAllocNearestColor(Display
*display
,Colormap colormap
,XColor
*xcolor
);
354 void wxAllocColor(Display
*display
,Colormap colormap
,XColor
*xcolor
);