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