]>
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"
37 /*steve: these two are not known under VMS */
46 #define stricmp strcasecmp
47 #define strnicmp strncasecmp
50 // Forward declaration
51 class WXDLLEXPORT wxFrame
;
53 // Stupid ASCII macros
54 #define wxToUpper(C) (((C) >= 'a' && (C) <= 'z')? (C) - 'a' + 'A': (C))
55 #define wxToLower(C) (((C) >= 'A' && (C) <= 'Z')? (C) - 'A' + 'a': (C))
57 // Return a string with the current date/time
58 WXDLLEXPORT wxString
wxNow(void);
60 // Make a copy of this string using 'new'
61 WXDLLEXPORT
char* copystring(const char *s
);
63 // Generate a unique ID
64 WXDLLEXPORT
long wxNewId(void);
67 // Ensure subsequent IDs don't clash with this one
68 WXDLLEXPORT
void wxRegisterId(long id
);
69 #define RegisterId wxRegisterId
71 // Return the current ID
72 WXDLLEXPORT
long wxGetCurrentId(void);
75 WXDLLEXPORT_DATA(extern char*) wxBuffer
;
77 WXDLLEXPORT_DATA(extern const char*) wxFloatToStringStr
;
78 WXDLLEXPORT_DATA(extern const char*) wxDoubleToStringStr
;
80 // Various conversions
81 WXDLLEXPORT
void StringToFloat(char *s
, float *number
);
82 WXDLLEXPORT
char* FloatToString(float number
, const char *fmt
= wxFloatToStringStr
);
83 WXDLLEXPORT
void StringToDouble(char *s
, double *number
);
84 WXDLLEXPORT
char* DoubleToString(double number
, const char *fmt
= wxDoubleToStringStr
);
85 WXDLLEXPORT
void StringToInt(char *s
, int *number
);
86 WXDLLEXPORT
void StringToLong(char *s
, long *number
);
87 WXDLLEXPORT
char* IntToString(int number
);
88 WXDLLEXPORT
char* LongToString(long number
);
90 // Matches string one within string two regardless of case
91 WXDLLEXPORT
bool StringMatch(char *one
, char *two
, bool subString
= TRUE
, bool exact
= FALSE
);
93 // A shorter way of using strcmp
94 #define wxStringEq(s1, s2) (s1 && s2 && (strcmp(s1, s2) == 0))
96 // Convert 2-digit hex number to decimal
97 WXDLLEXPORT
int wxHexToDec(const wxString
& buf
);
99 // Convert decimal integer to 2-character hex string
100 WXDLLEXPORT
void wxDecToHex(int dec
, char *buf
);
101 WXDLLEXPORT wxString
wxDecToHex(int dec
);
103 // Execute another program. Returns 0 if there was an error, a PID otherwise.
104 WXDLLEXPORT
long wxExecute(char **argv
, bool sync
= FALSE
,
105 wxProcess
*process
= (wxProcess
*) NULL
);
106 WXDLLEXPORT
long wxExecute(const wxString
& command
, bool sync
= FALSE
,
107 wxProcess
*process
= (wxProcess
*) NULL
);
111 WXDLLEXPORT
int wxKill(long pid
, int sig
=wxSIGTERM
);
113 // Execute a command in an interactive shell window
114 // If no command then just the shell
115 WXDLLEXPORT
bool wxShell(const wxString
& command
= wxEmptyString
);
117 // Sleep for nSecs seconds under UNIX, do nothing under Windows
118 WXDLLEXPORT
void wxSleep(int nSecs
);
120 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
121 WXDLLEXPORT
long wxGetFreeMemory(void);
123 // Consume all events until no more left
124 WXDLLEXPORT
void wxFlushEvents(void);
127 * Network and username functions.
132 WXDLLEXPORT
bool wxGetEmailAddress(char *buf
, int maxSize
);
135 WXDLLEXPORT
bool wxGetHostName(char *buf
, int maxSize
);
136 WXDLLEXPORT
bool wxGetHostName(wxString
& buf
);
138 // Get user ID e.g. jacs
139 WXDLLEXPORT
bool wxGetUserId(char *buf
, int maxSize
);
140 WXDLLEXPORT
bool wxGetUserId(wxString
& buf
);
142 // Get user name e.g. Julian Smart
143 WXDLLEXPORT
bool wxGetUserName(char *buf
, int maxSize
);
144 WXDLLEXPORT
bool wxGetUserName(wxString
& buf
);
147 * Strip out any menu codes
149 WXDLLEXPORT
char* wxStripMenuCodes(char *in
, char *out
= (char *) NULL
);
150 WXDLLEXPORT wxString
wxStripMenuCodes(const wxString
& str
);
152 // Find the window/widget with the given title or label.
153 // Pass a parent to begin the search from, or NULL to look through
155 WXDLLEXPORT wxWindow
* wxFindWindowByLabel(const wxString
& title
, wxWindow
*parent
= (wxWindow
*) NULL
);
157 // Find window by name, and if that fails, by label.
158 WXDLLEXPORT wxWindow
* wxFindWindowByName(const wxString
& name
, wxWindow
*parent
= (wxWindow
*) NULL
);
160 // Returns menu item id or -1 if none.
161 WXDLLEXPORT
int wxFindMenuItemId(wxFrame
*frame
, const wxString
& menuString
, const wxString
& itemString
);
164 #if (!defined(__MINMAX_DEFINED) && !defined(max))
165 #define max(a,b) (((a) > (b)) ? (a) : (b))
166 #define min(a,b) (((a) < (b)) ? (a) : (b))
167 #define __MINMAX_DEFINED 1
171 #define wxMax(a,b) (((a) > (b)) ? (a) : (b))
172 #define wxMin(a,b) (((a) < (b)) ? (a) : (b))
174 // Yield to other apps/messages
175 WXDLLEXPORT
bool wxYield(void);
177 // Format a message on the standard error (UNIX) or the debugging
179 WXDLLEXPORT
void wxDebugMsg(const char *fmt
...) ;
182 WXDLLEXPORT
void wxBell(void) ;
185 WXDLLEXPORT
int wxGetOsVersion(int *majorVsn
= (int *) NULL
,int *minorVsn
= (int *) NULL
) ;
187 // Set the cursor to the busy cursor for all windows
188 class WXDLLEXPORT wxCursor
;
189 WXDLLEXPORT_DATA(extern wxCursor
*) wxHOURGLASS_CURSOR
;
190 WXDLLEXPORT
void wxBeginBusyCursor(wxCursor
*cursor
= wxHOURGLASS_CURSOR
);
192 // Restore cursor to normal
193 WXDLLEXPORT
void wxEndBusyCursor(void);
195 // TRUE if we're between the above two calls
196 WXDLLEXPORT
bool wxIsBusy(void);
198 // Convenience class so we can just create a wxBusyCursor object on the stack
199 class WXDLLEXPORT wxBusyCursor
202 inline wxBusyCursor(wxCursor
* cursor
= wxHOURGLASS_CURSOR
) { wxBeginBusyCursor(cursor
); }
203 inline ~wxBusyCursor() { wxEndBusyCursor(); }
206 /* Error message functions used by wxWindows */
208 // Non-fatal error (continues)
209 WXDLLEXPORT_DATA(extern const char*) wxInternalErrorStr
;
210 WXDLLEXPORT
void wxError(const wxString
& msg
, const wxString
& title
= wxInternalErrorStr
);
212 // Fatal error (exits)
213 WXDLLEXPORT_DATA(extern const char*) wxFatalErrorStr
;
214 WXDLLEXPORT
void wxFatalError(const wxString
& msg
, const wxString
& title
= wxFatalErrorStr
);
216 // Reading and writing resources (eg WIN.INI, .Xdefaults)
218 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
= wxEmptyString
);
219 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
= wxEmptyString
);
220 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
= wxEmptyString
);
221 WXDLLEXPORT
bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
= wxEmptyString
);
223 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
= wxEmptyString
);
224 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
= wxEmptyString
);
225 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
= wxEmptyString
);
226 WXDLLEXPORT
bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
= wxEmptyString
);
227 #endif // wxUSE_RESOURCES
229 // Get current Home dir and copy to dest (returns pstr->c_str())
230 WXDLLEXPORT
const char* wxGetHomeDir(wxString
*pstr
);
232 // Get the user's home dir (caller must copy--- volatile)
233 // returns NULL is no HOME dir is known
234 WXDLLEXPORT
char* wxGetUserHome(const wxString
& user
= wxEmptyString
);
236 // Check whether this window wants to process messages, e.g. Stop button
237 // in long calculations.
238 WXDLLEXPORT
bool wxCheckForInterrupt(wxWindow
*wnd
);
240 void WXDLLEXPORT
wxGetMousePosition( int* x
, int* y
);
242 // MSW only: get user-defined resource from the .res file.
243 // Returns NULL or newly-allocated memory, so use delete[] to clean up.
245 WXDLLEXPORT
extern const char* wxUserResourceStr
;
246 WXDLLEXPORT
char* wxLoadUserResource(const wxString
& resourceName
, const wxString
& resourceType
= wxUserResourceStr
);
248 // Implemented in utils.cpp: VC++, Win95 only. Sets up a console for standard
250 WXDLLEXPORT
void wxRedirectIOToConsole();
256 WXDisplay
*wxGetDisplay();
257 bool wxSetDisplay(const wxString
& display_name
);
258 wxString
wxGetDisplayName();
263 #include <X11/Xlib.h>
265 #define wxMAX_RGB 0xff
266 #define wxMAX_SV 1000
267 #define wxSIGN(x) ((x < 0) ? -x : x)
272 typedef struct wx_hsv
{
276 #define wxMax3(x,y,z) ((x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z))
277 #define wxMin3(x,y,z) ((x < y) ? ((x < z) ? x : z) : ((y < z) ? y : z))
279 #define wxMax2(x,y) ((x > y) ? x : y)
280 #define wxMin2(x,y) ((x < y) ? x : y)
282 void wxHSVToXColor(wxHSV
*hsv
,XColor
*xcolor
);
283 void wxXColorToHSV(wxHSV
*hsv
,XColor
*xcolor
);
284 void wxAllocNearestColor(Display
*display
,Colormap colormap
,XColor
*xcolor
);
285 void wxAllocColor(Display
*display
,Colormap colormap
,XColor
*xcolor
);