]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/utils.h
Added a wxDataFormat::SetAtom() inline function.
[wxWidgets.git] / include / wx / utils.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: utils.h
3// Purpose: Miscellaneous utilities
4// Author: Julian Smart
5// Modified by:
6// Created: 29/01/98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Julian Smart
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_UTILSH__
13#define _WX_UTILSH__
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
19#ifdef __GNUG__
20 #pragma interface "utils.h"
21#endif
22
23#include "wx/setup.h"
24#include "wx/object.h"
25#include "wx/list.h"
26#include "wx/window.h"
27#include "wx/filefn.h"
28
29#include "wx/ioswrap.h"
30
31#ifdef __X__
32 #include <dirent.h>
33 #include <unistd.h>
34#endif
35
36#include <stdio.h>
37
38// ----------------------------------------------------------------------------
39// Forward declaration
40// ----------------------------------------------------------------------------
41
42class WXDLLEXPORT wxProcess;
43class WXDLLEXPORT wxFrame;
44
45// FIXME should use wxStricmp() instead
46#ifdef __GNUWIN32__
47 #define stricmp strcasecmp
48 #define strnicmp strncasecmp
49#endif
50
51// ----------------------------------------------------------------------------
52// Macros
53// ----------------------------------------------------------------------------
54
55#define wxMax(a,b) (((a) > (b)) ? (a) : (b))
56#define wxMin(a,b) (((a) < (b)) ? (a) : (b))
57
58// ----------------------------------------------------------------------------
59// String functions (deprecated, use wxString)
60// ----------------------------------------------------------------------------
61
62// Useful buffer (FIXME VZ: yeah, that is. To be removed!)
63WXDLLEXPORT_DATA(extern wxChar*) wxBuffer;
64
65// Make a copy of this string using 'new'
66WXDLLEXPORT wxChar* copystring(const wxChar *s);
67
68// Matches string one within string two regardless of case
69WXDLLEXPORT bool StringMatch(wxChar *one, wxChar *two, bool subString = TRUE, bool exact = FALSE);
70
71// A shorter way of using strcmp
72#define wxStringEq(s1, s2) (s1 && s2 && (wxStrcmp(s1, s2) == 0))
73
74// ----------------------------------------------------------------------------
75// Miscellaneous functions
76// ----------------------------------------------------------------------------
77
78// Sound the bell
79WXDLLEXPORT void wxBell(void) ;
80
81// Get OS version
82WXDLLEXPORT int wxGetOsVersion(int *majorVsn= (int *) NULL,int *minorVsn= (int *) NULL) ;
83
84// Return a string with the current date/time
85WXDLLEXPORT wxString wxNow();
86
87// ----------------------------------------------------------------------------
88// Window ID management
89// ----------------------------------------------------------------------------
90
91// Generate a unique ID
92WXDLLEXPORT long wxNewId();
93#if !defined(NewId) && defined(WXWIN_COMPATIBILITY)
94 #define NewId wxNewId
95#endif
96
97// Ensure subsequent IDs don't clash with this one
98WXDLLEXPORT void wxRegisterId(long id);
99#if !defined(RegisterId) && defined(WXWIN_COMPATIBILITY)
100 #define RegisterId wxRegisterId
101#endif
102
103// Return the current ID
104WXDLLEXPORT long wxGetCurrentId();
105
106// ----------------------------------------------------------------------------
107// Various conversions
108// ----------------------------------------------------------------------------
109
110WXDLLEXPORT_DATA(extern const wxChar*) wxFloatToStringStr;
111WXDLLEXPORT_DATA(extern const wxChar*) wxDoubleToStringStr;
112
113WXDLLEXPORT void StringToFloat(wxChar *s, float *number);
114WXDLLEXPORT wxChar* FloatToString(float number, const wxChar *fmt = wxFloatToStringStr);
115WXDLLEXPORT void StringToDouble(wxChar *s, double *number);
116WXDLLEXPORT wxChar* DoubleToString(double number, const wxChar *fmt = wxDoubleToStringStr);
117WXDLLEXPORT void StringToInt(wxChar *s, int *number);
118WXDLLEXPORT void StringToLong(wxChar *s, long *number);
119WXDLLEXPORT wxChar* IntToString(int number);
120WXDLLEXPORT wxChar* LongToString(long number);
121
122// Convert 2-digit hex number to decimal
123WXDLLEXPORT int wxHexToDec(const wxString& buf);
124
125// Convert decimal integer to 2-character hex string
126WXDLLEXPORT void wxDecToHex(int dec, wxChar *buf);
127WXDLLEXPORT wxString wxDecToHex(int dec);
128
129// ----------------------------------------------------------------------------
130// Process management
131// ----------------------------------------------------------------------------
132
133// Execute another program. Returns 0 if there was an error, a PID otherwise.
134WXDLLEXPORT long wxExecute(wxChar **argv, bool sync = FALSE,
135 wxProcess *process = (wxProcess *) NULL);
136WXDLLEXPORT long wxExecute(const wxString& command, bool sync = FALSE,
137 wxProcess *process = (wxProcess *) NULL);
138
139enum wxSignal
140{
141 wxSIGNONE = 0, // verify if the process exists under Unix
142 wxSIGHUP,
143 wxSIGINT,
144 wxSIGQUIT,
145 wxSIGILL,
146 wxSIGTRAP,
147 wxSIGABRT,
148 wxSIGIOT = wxSIGABRT, // another name
149 wxSIGEMT,
150 wxSIGFPE,
151 wxSIGKILL,
152 wxSIGBUS,
153 wxSIGSEGV,
154 wxSIGSYS,
155 wxSIGPIPE,
156 wxSIGALRM,
157 wxSIGTERM
158
159 // further signals are different in meaning between different Unix systems
160};
161
162// the argument is ignored under Windows - the process is always killed
163WXDLLEXPORT int wxKill(long pid, wxSignal sig = wxSIGTERM);
164
165// Execute a command in an interactive shell window
166// If no command then just the shell
167WXDLLEXPORT bool wxShell(const wxString& command = wxEmptyString);
168
169// Sleep for nSecs seconds under UNIX, do nothing under Windows
170WXDLLEXPORT void wxSleep(int nSecs);
171
172// Sleep for a given amount of milliseconds
173WXDLLEXPORT void wxUsleep(unsigned long milliseconds);
174
175// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
176WXDLLEXPORT long wxGetFreeMemory();
177
178// ----------------------------------------------------------------------------
179// Network and username functions.
180// ----------------------------------------------------------------------------
181
182// NB: "char *" functions are deprecated, use wxString ones!
183
184// Get eMail address
185WXDLLEXPORT bool wxGetEmailAddress(wxChar *buf, int maxSize);
186WXDLLEXPORT wxString wxGetEmailAddress();
187
188// Get hostname.
189WXDLLEXPORT bool wxGetHostName(wxChar *buf, int maxSize);
190WXDLLEXPORT wxString wxGetHostName();
191
192// Get FQDN
193WXDLLEXPORT wxString wxGetFullHostName();
194
195// Get user ID e.g. jacs (this is known as login name under Unix)
196WXDLLEXPORT bool wxGetUserId(wxChar *buf, int maxSize);
197WXDLLEXPORT wxString wxGetUserId();
198
199// Get user name e.g. Julian Smart
200WXDLLEXPORT bool wxGetUserName(wxChar *buf, int maxSize);
201WXDLLEXPORT wxString wxGetUserName();
202
203// Get current Home dir and copy to dest (returns pstr->c_str())
204WXDLLEXPORT const wxChar* wxGetHomeDir(wxString *pstr);
205
206// Get the user's home dir (caller must copy --- volatile)
207// returns NULL is no HOME dir is known
208#if defined(__UNIX__) && wxUSE_UNICODE
209WXDLLEXPORT const wxMB2WXbuf wxGetUserHome(const wxString& user = wxEmptyString);
210#else
211WXDLLEXPORT wxChar* wxGetUserHome(const wxString& user = wxEmptyString);
212#endif
213
214// ----------------------------------------------------------------------------
215// Strip out any menu codes
216// ----------------------------------------------------------------------------
217
218WXDLLEXPORT wxChar* wxStripMenuCodes(wxChar *in, wxChar *out = (wxChar *) NULL);
219WXDLLEXPORT wxString wxStripMenuCodes(const wxString& str);
220
221// ----------------------------------------------------------------------------
222// Window search
223// ----------------------------------------------------------------------------
224
225// Find the window/widget with the given title or label.
226// Pass a parent to begin the search from, or NULL to look through
227// all windows.
228WXDLLEXPORT wxWindow* wxFindWindowByLabel(const wxString& title, wxWindow *parent = (wxWindow *) NULL);
229
230// Find window by name, and if that fails, by label.
231WXDLLEXPORT wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent = (wxWindow *) NULL);
232
233// Returns menu item id or -1 if none.
234WXDLLEXPORT int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString);
235
236// ----------------------------------------------------------------------------
237// Message/event queue helpers
238// ----------------------------------------------------------------------------
239
240// Yield to other apps/messages
241WXDLLEXPORT bool wxYield();
242
243// Yield to other apps/messages and disable user input
244WXDLLEXPORT bool wxSafeYield(wxWindow *win = NULL);
245
246// Enable or disable input to all top level windows
247WXDLLEXPORT void wxEnableTopLevelWindows(bool enable = TRUE);
248
249// Check whether this window wants to process messages, e.g. Stop button
250// in long calculations.
251WXDLLEXPORT bool wxCheckForInterrupt(wxWindow *wnd);
252
253// Consume all events until no more left
254WXDLLEXPORT void wxFlushEvents();
255
256// ----------------------------------------------------------------------------
257// Cursors
258// ----------------------------------------------------------------------------
259
260// Set the cursor to the busy cursor for all windows
261class WXDLLEXPORT wxCursor;
262WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
263WXDLLEXPORT void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
264
265// Restore cursor to normal
266WXDLLEXPORT void wxEndBusyCursor();
267
268// TRUE if we're between the above two calls
269WXDLLEXPORT bool wxIsBusy();
270
271// Convenience class so we can just create a wxBusyCursor object on the stack
272class WXDLLEXPORT wxBusyCursor
273{
274public:
275 wxBusyCursor(wxCursor* cursor = wxHOURGLASS_CURSOR)
276 { wxBeginBusyCursor(cursor); }
277 ~wxBusyCursor()
278 { wxEndBusyCursor(); }
279};
280
281// ----------------------------------------------------------------------------
282// Error message functions used by wxWindows (deprecated, use wxLog)
283// ----------------------------------------------------------------------------
284
285// Format a message on the standard error (UNIX) or the debugging
286// stream (Windows)
287WXDLLEXPORT void wxDebugMsg(const wxChar *fmt ...) ;
288
289// Non-fatal error (continues)
290WXDLLEXPORT_DATA(extern const wxChar*) wxInternalErrorStr;
291WXDLLEXPORT void wxError(const wxString& msg, const wxString& title = wxInternalErrorStr);
292
293// Fatal error (exits)
294WXDLLEXPORT_DATA(extern const wxChar*) wxFatalErrorStr;
295WXDLLEXPORT void wxFatalError(const wxString& msg, const wxString& title = wxFatalErrorStr);
296
297// ----------------------------------------------------------------------------
298// Reading and writing resources (eg WIN.INI, .Xdefaults)
299// ----------------------------------------------------------------------------
300
301#if wxUSE_RESOURCES
302WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file = wxEmptyString);
303WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file = wxEmptyString);
304WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file = wxEmptyString);
305WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file = wxEmptyString);
306
307WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, wxChar **value, const wxString& file = wxEmptyString);
308WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file = wxEmptyString);
309WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file = wxEmptyString);
310WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file = wxEmptyString);
311#endif // wxUSE_RESOURCES
312
313void WXDLLEXPORT wxGetMousePosition( int* x, int* y );
314
315// MSW only: get user-defined resource from the .res file.
316// Returns NULL or newly-allocated memory, so use delete[] to clean up.
317#ifdef __WXMSW__
318WXDLLEXPORT extern const wxChar* wxUserResourceStr;
319WXDLLEXPORT wxChar* wxLoadUserResource(const wxString& resourceName, const wxString& resourceType = wxUserResourceStr);
320
321// Implemented in utils.cpp: VC++, Win95 only. Sets up a console for standard
322// input/output
323WXDLLEXPORT void wxRedirectIOToConsole();
324
325#endif // MSW
326
327// ----------------------------------------------------------------------------
328// Display and colorss (X only)
329// ----------------------------------------------------------------------------
330
331#ifdef __X__
332 WXDisplay *wxGetDisplay();
333 bool wxSetDisplay(const wxString& display_name);
334 wxString wxGetDisplayName();
335#endif
336
337#ifdef __X__
338
339#include <X11/Xlib.h>
340
341#define wxMAX_RGB 0xff
342#define wxMAX_SV 1000
343#define wxSIGN(x) ((x < 0) ? -x : x)
344#define wxH_WEIGHT 4
345#define wxS_WEIGHT 1
346#define wxV_WEIGHT 2
347
348typedef struct wx_hsv {
349 int h,s,v;
350 } wxHSV;
351
352#define wxMax3(x,y,z) ((x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z))
353#define wxMin3(x,y,z) ((x < y) ? ((x < z) ? x : z) : ((y < z) ? y : z))
354
355void wxHSVToXColor(wxHSV *hsv,XColor *xcolor);
356void wxXColorToHSV(wxHSV *hsv,XColor *xcolor);
357void wxAllocNearestColor(Display *display,Colormap colormap,XColor *xcolor);
358void wxAllocColor(Display *display,Colormap colormap,XColor *xcolor);
359
360#endif //__X__
361
362#endif
363 // _WX_UTILSH__