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