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