]> git.saurik.com Git - wxWidgets.git/blame - include/wx/utils.h
no message
[wxWidgets.git] / include / wx / utils.h
CommitLineData
c801d85f
KB
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
34138703
JS
12#ifndef _WX_UTILSH__
13#define _WX_UTILSH__
c801d85f
KB
14
15#ifdef __GNUG__
16#pragma interface "utils.h"
17#endif
18
19#include "wx/setup.h"
20#include "wx/object.h"
21#include "wx/list.h"
22#include "wx/window.h"
23#include "wx/filefn.h"
cf447356 24#include "wx/process.h"
c801d85f 25
47d67540 26#if wxUSE_IOSTREAMH
c801d85f
KB
27#include <iostream.h>
28#else
29#include <iostream>
fbc535ff
JS
30# ifdef _MSC_VER
31 using namespace std;
32# endif
c801d85f
KB
33#endif
34
35#ifdef __X__
36#ifndef __VMS__
37/*steve: these two are not known under VMS */
38#include <dirent.h>
39#include <unistd.h>
40#endif
41#endif
42
43#include <stdio.h>
44
45#ifdef __GNUWIN32__
46#define stricmp strcasecmp
47#define strnicmp strncasecmp
48#endif
49
50// Forward declaration
51class WXDLLEXPORT wxFrame;
52
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))
56
57// Return a string with the current date/time
58wxString WXDLLEXPORT wxNow(void);
59
60// Make a copy of this string using 'new'
61char* WXDLLEXPORT copystring(const char *s);
62
63// Generate a unique ID
64long WXDLLEXPORT wxNewId(void);
65#define NewId wxNewId
66
67// Ensure subsequent IDs don't clash with this one
68void WXDLLEXPORT wxRegisterId(long id);
69#define RegisterId wxRegisterId
70
71// Return the current ID
72long WXDLLEXPORT wxGetCurrentId(void);
73
74// Useful buffer
75WXDLLEXPORT_DATA(extern char*) wxBuffer;
76
77WXDLLEXPORT_DATA(extern const char*) wxFloatToStringStr;
78WXDLLEXPORT_DATA(extern const char*) wxDoubleToStringStr;
79
80// Various conversions
81void WXDLLEXPORT StringToFloat(char *s, float *number);
82char* WXDLLEXPORT FloatToString(float number, const char *fmt = wxFloatToStringStr);
83void WXDLLEXPORT StringToDouble(char *s, double *number);
84char* WXDLLEXPORT DoubleToString(double number, const char *fmt = wxDoubleToStringStr);
85void WXDLLEXPORT StringToInt(char *s, int *number);
86void WXDLLEXPORT StringToLong(char *s, long *number);
87char* WXDLLEXPORT IntToString(int number);
88char* WXDLLEXPORT LongToString(long number);
89
90// Matches string one within string two regardless of case
91bool WXDLLEXPORT StringMatch(char *one, char *two, bool subString = TRUE, bool exact = FALSE);
92
93// A shorter way of using strcmp
94#define wxStringEq(s1, s2) (s1 && s2 && (strcmp(s1, s2) == 0))
95
96// Convert 2-digit hex number to decimal
fd71308f 97int WXDLLEXPORT wxHexToDec(const wxString& buf);
c801d85f
KB
98
99// Convert decimal integer to 2-character hex string
100void WXDLLEXPORT wxDecToHex(int dec, char *buf);
fd71308f 101wxString WXDLLEXPORT wxDecToHex(int dec);
c801d85f
KB
102
103// Execute another program. Returns 0 if there was an error, a PID otherwise.
1b826605 104long WXDLLEXPORT wxExecute(char **argv, bool sync = FALSE,
c67daf87 105 wxProcess *process = (wxProcess *) NULL);
1b826605 106long WXDLLEXPORT wxExecute(const wxString& command, bool sync = FALSE,
c67daf87 107 wxProcess *process = (wxProcess *) NULL);
c801d85f
KB
108
109#define wxSIGTERM 1
110
111int WXDLLEXPORT wxKill(long pid, int sig=wxSIGTERM);
112
113// Execute a command in an interactive shell window
114// If no command then just the shell
115bool WXDLLEXPORT wxShell(const wxString& command = "");
116
117// Sleep for nSecs seconds under UNIX, do nothing under Windows
118void WXDLLEXPORT wxSleep(int nSecs);
119
120// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
121long WXDLLEXPORT wxGetFreeMemory(void);
122
123// Consume all events until no more left
124void WXDLLEXPORT wxFlushEvents(void);
125
126/*
127 * Network and username functions.
128 *
129 */
130
131// Get eMail address
132bool WXDLLEXPORT wxGetEmailAddress(char *buf, int maxSize);
133
134// Get hostname.
135bool WXDLLEXPORT wxGetHostName(char *buf, int maxSize);
136
137// Get user ID e.g. jacs
138bool WXDLLEXPORT wxGetUserId(char *buf, int maxSize);
139
140// Get user name e.g. Julian Smart
141bool WXDLLEXPORT wxGetUserName(char *buf, int maxSize);
142
143/*
144 * Strip out any menu codes
145 */
c67daf87 146char* WXDLLEXPORT wxStripMenuCodes(char *in, char *out = (char *) NULL);
c801d85f
KB
147
148// Find the window/widget with the given title or label.
149// Pass a parent to begin the search from, or NULL to look through
150// all windows.
c67daf87 151wxWindow* WXDLLEXPORT wxFindWindowByLabel(const wxString& title, wxWindow *parent = (wxWindow *) NULL);
c801d85f
KB
152
153// Find window by name, and if that fails, by label.
c67daf87 154wxWindow* WXDLLEXPORT wxFindWindowByName(const wxString& name, wxWindow *parent = (wxWindow *) NULL);
c801d85f
KB
155
156// Returns menu item id or -1 if none.
157int WXDLLEXPORT wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString);
158
159// A debugging stream buffer.
160// Under Windows, this writes to the Windows debug output.
161// Under other platforms, it writes to cerr.
162
163// ALl this horrible gubbins required for Borland, because the calling
164// convention needs to be the same as for streambuf.
165// Thanks to Gerhard.Vogt@embl-heidelberg.de for this solution.
166
167#if defined(__BORLANDC__) && defined(__BCOPT__) && !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
168#pragma option -po-
169#endif
170
171// Can't export a class derived from a non-export class
172#if !defined(_WINDLL) && !defined(WXUSINGDLL)
173
e55ad60e
RR
174// #ifdef new
175// #undef new
176// #endif
c801d85f
KB
177
178class WXDLLEXPORT wxDebugStreamBuf: public streambuf
179{
180 public:
181 wxDebugStreamBuf(void);
182 ~wxDebugStreamBuf(void) {}
183
184 int overflow(int i);
185 inline int underflow(void) { return EOF; }
186 int sync(void);
187};
188
47d67540 189// #if WXDEBUG && wxUSE_GLOBAL_MEMORY_OPERATORS
e55ad60e
RR
190// #define new WXDEBUG_NEW
191// #endif
c801d85f
KB
192
193#endif
194
195#if defined(__BORLANDC__) && defined(__BCOPT__) && !defined(_RTL_ALLOW_po) && !defined(__FLAT__)
196#pragma option -po.
197#endif
198
199/*
200#if (!defined(__MINMAX_DEFINED) && !defined(max))
201#define max(a,b) (((a) > (b)) ? (a) : (b))
202#define min(a,b) (((a) < (b)) ? (a) : (b))
203#define __MINMAX_DEFINED 1
204#endif
205*/
206#define wxMax(a,b) (((a) > (b)) ? (a) : (b))
207#define wxMin(a,b) (((a) < (b)) ? (a) : (b))
208
209// Yield to other apps/messages
210bool WXDLLEXPORT wxYield(void);
211
212// Format a message on the standard error (UNIX) or the debugging
213// stream (Windows)
214void WXDLLEXPORT wxDebugMsg(const char *fmt ...) ;
215
216// Sound the bell
217void WXDLLEXPORT wxBell(void) ;
218
219// Get OS version
c67daf87 220int WXDLLEXPORT wxGetOsVersion(int *majorVsn= (int *) NULL,int *minorVsn= (int *) NULL) ;
c801d85f
KB
221
222// Set the cursor to the busy cursor for all windows
223class WXDLLEXPORT wxCursor;
224WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
225void WXDLLEXPORT wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
226
227// Restore cursor to normal
228void WXDLLEXPORT wxEndBusyCursor(void);
229
230// TRUE if we're between the above two calls
231bool WXDLLEXPORT wxIsBusy(void);
232
233/* Error message functions used by wxWindows */
234
235// Non-fatal error (continues)
236WXDLLEXPORT_DATA(extern const char*) wxInternalErrorStr;
237void WXDLLEXPORT wxError(const wxString& msg, const wxString& title = wxInternalErrorStr);
238
239// Fatal error (exits)
240WXDLLEXPORT_DATA(extern const char*) wxFatalErrorStr;
241void WXDLLEXPORT wxFatalError(const wxString& msg, const wxString& title = wxFatalErrorStr);
242
243// Reading and writing resources (eg WIN.INI, .Xdefaults)
47d67540 244#if wxUSE_RESOURCES
c801d85f
KB
245bool WXDLLEXPORT wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file = "");
246bool WXDLLEXPORT wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file = "");
247bool WXDLLEXPORT wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file = "");
248bool WXDLLEXPORT wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file = "");
249
250bool WXDLLEXPORT wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file = "");
251bool WXDLLEXPORT wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file = "");
252bool WXDLLEXPORT wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file = "");
253bool WXDLLEXPORT wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file = "");
47d67540 254#endif // wxUSE_RESOURCES
c801d85f 255
7c3c5ecc
VZ
256// Get current Home dir and copy to dest (returns pstr->c_str())
257const char* WXDLLEXPORT wxGetHomeDir(wxString *pstr);
258
c801d85f
KB
259// Get the user's home dir (caller must copy--- volatile)
260// returns NULL is no HOME dir is known
261char* WXDLLEXPORT wxGetUserHome(const wxString& user = "");
262
263// Check whether this window wants to process messages, e.g. Stop button
264// in long calculations.
265bool WXDLLEXPORT wxCheckForInterrupt(wxWindow *wnd);
266
267void WXDLLEXPORT wxGetMousePosition( int* x, int* y );
268
269// MSW only: get user-defined resource from the .res file.
270// Returns NULL or newly-allocated memory, so use delete[] to clean up.
2049ba38 271#ifdef __WXMSW__
c801d85f
KB
272extern const char* WXDLLEXPORT wxUserResourceStr;
273char* WXDLLEXPORT wxLoadUserResource(const wxString& resourceName, const wxString& resourceType = wxUserResourceStr);
274#endif
275
276// X only
277#ifdef __X__
46ccb510 278WXDisplay *wxGetDisplay();
c801d85f 279bool wxSetDisplay(const wxString& display_name);
46ccb510 280wxString wxGetDisplayName();
c801d85f
KB
281#endif
282
283#ifdef __X__
284
285#include <X11/Xlib.h>
286
287#define wxMAX_RGB 0xff
288#define wxMAX_SV 1000
289#define wxSIGN(x) ((x < 0) ? -x : x)
290#define wxH_WEIGHT 4
291#define wxS_WEIGHT 1
292#define wxV_WEIGHT 2
293
294typedef struct wx_hsv {
295 int h,s,v;
296 } wxHSV;
297
298#define wxMax3(x,y,z) ((x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z))
299#define wxMin3(x,y,z) ((x < y) ? ((x < z) ? x : z) : ((y < z) ? y : z))
300
301#define wxMax2(x,y) ((x > y) ? x : y)
302#define wxMin2(x,y) ((x < y) ? x : y)
303
304void wxHSVToXColor(wxHSV *hsv,XColor *xcolor);
305void wxXColorToHSV(wxHSV *hsv,XColor *xcolor);
306void wxAllocNearestColor(Display *display,Colormap colormap,XColor *xcolor);
307void wxAllocColor(Display *display,Colormap colormap,XColor *xcolor);
308
309#endif //__X__
310
311#endif
34138703 312 // _WX_UTILSH__