]>
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 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "utils.h"
20 #include "wx/object.h"
22 #include "wx/window.h"
23 #include "wx/filefn.h"
24 #include "wx/process.h"
26 #include "wx/ioswrap.h"
30 /*steve: these two are not known under VMS */
39 #define stricmp strcasecmp
40 #define strnicmp strncasecmp
43 // Forward declaration
44 class WXDLLEXPORT wxFrame
;
46 // Stupid ASCII macros
47 #define wxToUpper(C) (((C) >= 'a' && (C) <= 'z')? (C) - 'a' + 'A': (C))
48 #define wxToLower(C) (((C) >= 'A' && (C) <= 'Z')? (C) - 'A' + 'a': (C))
50 // Return a string with the current date/time
51 WXDLLEXPORT wxString
wxNow(void);
53 // Make a copy of this string using 'new'
54 WXDLLEXPORT
char* copystring(const char *s
);
56 // Generate a unique ID
57 WXDLLEXPORT
long wxNewId(void);
60 // Ensure subsequent IDs don't clash with this one
61 WXDLLEXPORT
void wxRegisterId(long id
);
62 #define RegisterId wxRegisterId
64 // Return the current ID
65 WXDLLEXPORT
long wxGetCurrentId(void);
68 WXDLLEXPORT_DATA(extern char*) wxBuffer
;
70 WXDLLEXPORT_DATA(extern const char*) wxFloatToStringStr
;
71 WXDLLEXPORT_DATA(extern const char*) wxDoubleToStringStr
;
73 // Various conversions
74 WXDLLEXPORT
void StringToFloat(char *s
, float *number
);
75 WXDLLEXPORT
char* FloatToString(float number
, const char *fmt
= wxFloatToStringStr
);
76 WXDLLEXPORT
void StringToDouble(char *s
, double *number
);
77 WXDLLEXPORT
char* DoubleToString(double number
, const char *fmt
= wxDoubleToStringStr
);
78 WXDLLEXPORT
void StringToInt(char *s
, int *number
);
79 WXDLLEXPORT
void StringToLong(char *s
, long *number
);
80 WXDLLEXPORT
char* IntToString(int number
);
81 WXDLLEXPORT
char* LongToString(long number
);
83 // Matches string one within string two regardless of case
84 WXDLLEXPORT
bool StringMatch(char *one
, char *two
, bool subString
= TRUE
, bool exact
= FALSE
);
86 // A shorter way of using strcmp
87 #define wxStringEq(s1, s2) (s1 && s2 && (strcmp(s1, s2) == 0))
89 // Convert 2-digit hex number to decimal
90 WXDLLEXPORT
int wxHexToDec(const wxString
& buf
);
92 // Convert decimal integer to 2-character hex string
93 WXDLLEXPORT
void wxDecToHex(int dec
, char *buf
);
94 WXDLLEXPORT wxString
wxDecToHex(int dec
);
96 // Execute another program. Returns 0 if there was an error, a PID otherwise.
97 WXDLLEXPORT
long wxExecute(char **argv
, bool sync
= FALSE
,
98 wxProcess
*process
= (wxProcess
*) NULL
);
99 WXDLLEXPORT
long wxExecute(const wxString
& command
, bool sync
= FALSE
,
100 wxProcess
*process
= (wxProcess
*) NULL
);
104 WXDLLEXPORT
int wxKill(long pid
, int sig
=wxSIGTERM
);
106 // Execute a command in an interactive shell window
107 // If no command then just the shell
108 WXDLLEXPORT
bool wxShell(const wxString
& command
= wxEmptyString
);
110 // Sleep for nSecs seconds under UNIX, do nothing under Windows
111 WXDLLEXPORT
void wxSleep(int nSecs
);
113 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
114 WXDLLEXPORT
long wxGetFreeMemory(void);
116 // Consume all events until no more left
117 WXDLLEXPORT
void wxFlushEvents(void);
120 * Network and username functions.
125 WXDLLEXPORT
bool wxGetEmailAddress(char *buf
, int maxSize
);
128 WXDLLEXPORT
bool wxGetHostName(char *buf
, int maxSize
);
129 WXDLLEXPORT
bool wxGetHostName(wxString
& buf
);
131 // Get user ID e.g. jacs
132 WXDLLEXPORT
bool wxGetUserId(char *buf
, int maxSize
);
133 WXDLLEXPORT
bool wxGetUserId(wxString
& buf
);
135 // Get user name e.g. Julian Smart
136 WXDLLEXPORT
bool wxGetUserName(char *buf
, int maxSize
);
137 WXDLLEXPORT
bool wxGetUserName(wxString
& buf
);
140 * Strip out any menu codes
142 WXDLLEXPORT
char* wxStripMenuCodes(char *in
, char *out
= (char *) NULL
);
143 WXDLLEXPORT wxString
wxStripMenuCodes(const wxString
& str
);
145 // Find the window/widget with the given title or label.
146 // Pass a parent to begin the search from, or NULL to look through
148 WXDLLEXPORT wxWindow
* wxFindWindowByLabel(const wxString
& title
, wxWindow
*parent
= (wxWindow
*) NULL
);
150 // Find window by name, and if that fails, by label.
151 WXDLLEXPORT wxWindow
* wxFindWindowByName(const wxString
& name
, wxWindow
*parent
= (wxWindow
*) NULL
);
153 // Returns menu item id or -1 if none.
154 WXDLLEXPORT
int wxFindMenuItemId(wxFrame
*frame
, const wxString
& menuString
, const wxString
& itemString
);
157 #if (!defined(__MINMAX_DEFINED) && !defined(max))
158 #define max(a,b) (((a) > (b)) ? (a) : (b))
159 #define min(a,b) (((a) < (b)) ? (a) : (b))
160 #define __MINMAX_DEFINED 1
164 #define wxMax(a,b) (((a) > (b)) ? (a) : (b))
165 #define wxMin(a,b) (((a) < (b)) ? (a) : (b))
167 // Yield to other apps/messages
168 WXDLLEXPORT
bool wxYield(void);
170 // Format a message on the standard error (UNIX) or the debugging
172 WXDLLEXPORT
void wxDebugMsg(const char *fmt
...) ;
175 WXDLLEXPORT
void wxBell(void) ;
178 WXDLLEXPORT
int wxGetOsVersion(int *majorVsn
= (int *) NULL
,int *minorVsn
= (int *) NULL
) ;
180 // Set the cursor to the busy cursor for all windows
181 class WXDLLEXPORT wxCursor
;
182 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
183 WXDLLEXPORT
void wxBeginBusyCursor(wxCursor
*cursor
= wxHOURGLASS_CURSOR
);
185 // Restore cursor to normal
186 WXDLLEXPORT
void wxEndBusyCursor(void);
188 // TRUE if we're between the above two calls
189 WXDLLEXPORT
bool wxIsBusy(void);
191 // Convenience class so we can just create a wxBusyCursor object on the stack
192 class WXDLLEXPORT wxBusyCursor
195 inline wxBusyCursor(wxCursor
* cursor
= wxHOURGLASS_CURSOR
) { wxBeginBusyCursor(cursor
); }
196 inline ~wxBusyCursor() { wxEndBusyCursor(); }
199 /* Error message functions used by wxWindows */
201 // Non-fatal error (continues)
202 WXDLLEXPORT_DATA(extern const char*) wxInternalErrorStr
;
203 WXDLLEXPORT
void wxError(const wxString
& msg
, const wxString
& title
= wxInternalErrorStr
);
205 // Fatal error (exits)
206 WXDLLEXPORT_DATA(extern const char*) wxFatalErrorStr
;
207 WXDLLEXPORT
void wxFatalError(const wxString
& msg
, const wxString
& title
= wxFatalErrorStr
);
209 // Reading and writing resources (eg WIN.INI, .Xdefaults)
211 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
= wxEmptyString
);
212 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
= wxEmptyString
);
213 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
= wxEmptyString
);
214 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
= wxEmptyString
);
216 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
= wxEmptyString
);
217 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
= wxEmptyString
);
218 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
= wxEmptyString
);
219 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
= wxEmptyString
);
220 #endif // wxUSE_RESOURCES
222 // Get current Home dir and copy to dest (returns pstr->c_str())
223 WXDLLEXPORT
const char* wxGetHomeDir(wxString
*pstr
);
225 // Get the user's home dir (caller must copy--- volatile)
226 // returns NULL is no HOME dir is known
227 WXDLLEXPORT
char* wxGetUserHome(const wxString
& user
= wxEmptyString
);
229 // Check whether this window wants to process messages, e.g. Stop button
230 // in long calculations.
231 WXDLLEXPORT
bool wxCheckForInterrupt(wxWindow
*wnd
);
233 void WXDLLEXPORT
wxGetMousePosition( int* x
, int* y
);
235 // MSW only: get user-defined resource from the .res file.
236 // Returns NULL or newly-allocated memory, so use delete[] to clean up.
238 WXDLLEXPORT
extern const char* wxUserResourceStr
;
239 WXDLLEXPORT
char* wxLoadUserResource(const wxString
& resourceName
, const wxString
& resourceType
= wxUserResourceStr
);
241 // Implemented in utils.cpp: VC++, Win95 only. Sets up a console for standard
243 WXDLLEXPORT
void wxRedirectIOToConsole();
249 WXDisplay
*wxGetDisplay();
250 bool wxSetDisplay(const wxString
& display_name
);
251 wxString
wxGetDisplayName();
256 #include <X11/Xlib.h>
258 #define wxMAX_RGB 0xff
259 #define wxMAX_SV 1000
260 #define wxSIGN(x) ((x < 0) ? -x : x)
265 typedef struct wx_hsv
{
269 #define wxMax3(x,y,z) ((x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z))
270 #define wxMin3(x,y,z) ((x < y) ? ((x < z) ? x : z) : ((y < z) ? y : z))
272 #define wxMax2(x,y) ((x > y) ? x : y)
273 #define wxMin2(x,y) ((x < y) ? x : y)
275 void wxHSVToXColor(wxHSV
*hsv
,XColor
*xcolor
);
276 void wxXColorToHSV(wxHSV
*hsv
,XColor
*xcolor
);
277 void wxAllocNearestColor(Display
*display
,Colormap colormap
,XColor
*xcolor
);
278 void wxAllocColor(Display
*display
,Colormap colormap
,XColor
*xcolor
);