]> git.saurik.com Git - wxWidgets.git/blame - include/wx/utils.h
Added wxPrivateDropTarget
[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
184b5d99 58WXDLLEXPORT wxString wxNow(void);
c801d85f
KB
59
60// Make a copy of this string using 'new'
184b5d99 61WXDLLEXPORT char* copystring(const char *s);
c801d85f
KB
62
63// Generate a unique ID
184b5d99 64WXDLLEXPORT long wxNewId(void);
c801d85f
KB
65#define NewId wxNewId
66
67// Ensure subsequent IDs don't clash with this one
184b5d99 68WXDLLEXPORT void wxRegisterId(long id);
c801d85f
KB
69#define RegisterId wxRegisterId
70
71// Return the current ID
184b5d99 72WXDLLEXPORT long wxGetCurrentId(void);
c801d85f
KB
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
184b5d99
JS
81WXDLLEXPORT void StringToFloat(char *s, float *number);
82WXDLLEXPORT char* FloatToString(float number, const char *fmt = wxFloatToStringStr);
83WXDLLEXPORT void StringToDouble(char *s, double *number);
84WXDLLEXPORT char* DoubleToString(double number, const char *fmt = wxDoubleToStringStr);
85WXDLLEXPORT void StringToInt(char *s, int *number);
86WXDLLEXPORT void StringToLong(char *s, long *number);
87WXDLLEXPORT char* IntToString(int number);
88WXDLLEXPORT char* LongToString(long number);
c801d85f
KB
89
90// Matches string one within string two regardless of case
184b5d99 91WXDLLEXPORT bool StringMatch(char *one, char *two, bool subString = TRUE, bool exact = FALSE);
c801d85f
KB
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
184b5d99 97WXDLLEXPORT int wxHexToDec(const wxString& buf);
c801d85f
KB
98
99// Convert decimal integer to 2-character hex string
184b5d99
JS
100WXDLLEXPORT void wxDecToHex(int dec, char *buf);
101WXDLLEXPORT wxString wxDecToHex(int dec);
c801d85f
KB
102
103// Execute another program. Returns 0 if there was an error, a PID otherwise.
184b5d99 104WXDLLEXPORT long wxExecute(char **argv, bool sync = FALSE,
c67daf87 105 wxProcess *process = (wxProcess *) NULL);
184b5d99 106WXDLLEXPORT long wxExecute(const wxString& command, bool sync = FALSE,
c67daf87 107 wxProcess *process = (wxProcess *) NULL);
c801d85f
KB
108
109#define wxSIGTERM 1
110
184b5d99 111WXDLLEXPORT int wxKill(long pid, int sig=wxSIGTERM);
c801d85f
KB
112
113// Execute a command in an interactive shell window
114// If no command then just the shell
62448488 115WXDLLEXPORT bool wxShell(const wxString& command = wxEmptyString);
c801d85f
KB
116
117// Sleep for nSecs seconds under UNIX, do nothing under Windows
184b5d99 118WXDLLEXPORT void wxSleep(int nSecs);
c801d85f
KB
119
120// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
184b5d99 121WXDLLEXPORT long wxGetFreeMemory(void);
c801d85f
KB
122
123// Consume all events until no more left
184b5d99 124WXDLLEXPORT void wxFlushEvents(void);
c801d85f
KB
125
126/*
127 * Network and username functions.
128 *
129 */
130
131// Get eMail address
184b5d99 132WXDLLEXPORT bool wxGetEmailAddress(char *buf, int maxSize);
c801d85f
KB
133
134// Get hostname.
184b5d99 135WXDLLEXPORT bool wxGetHostName(char *buf, int maxSize);
c801d85f
KB
136
137// Get user ID e.g. jacs
184b5d99 138WXDLLEXPORT bool wxGetUserId(char *buf, int maxSize);
c801d85f
KB
139
140// Get user name e.g. Julian Smart
184b5d99 141WXDLLEXPORT bool wxGetUserName(char *buf, int maxSize);
c801d85f
KB
142
143/*
144 * Strip out any menu codes
145 */
184b5d99
JS
146WXDLLEXPORT char* wxStripMenuCodes(char *in, char *out = (char *) NULL);
147WXDLLEXPORT wxString wxStripMenuCodes(const wxString& str);
c801d85f
KB
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.
184b5d99 152WXDLLEXPORT wxWindow* wxFindWindowByLabel(const wxString& title, wxWindow *parent = (wxWindow *) NULL);
c801d85f
KB
153
154// Find window by name, and if that fails, by label.
184b5d99 155WXDLLEXPORT wxWindow* wxFindWindowByName(const wxString& name, wxWindow *parent = (wxWindow *) NULL);
c801d85f
KB
156
157// Returns menu item id or -1 if none.
184b5d99 158WXDLLEXPORT int wxFindMenuItemId(wxFrame *frame, const wxString& menuString, const wxString& itemString);
c801d85f 159
c801d85f
KB
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*/
d524867f 167
c801d85f
KB
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
184b5d99 172WXDLLEXPORT bool wxYield(void);
c801d85f
KB
173
174// Format a message on the standard error (UNIX) or the debugging
175// stream (Windows)
184b5d99 176WXDLLEXPORT void wxDebugMsg(const char *fmt ...) ;
c801d85f
KB
177
178// Sound the bell
184b5d99 179WXDLLEXPORT void wxBell(void) ;
c801d85f
KB
180
181// Get OS version
184b5d99 182WXDLLEXPORT int wxGetOsVersion(int *majorVsn= (int *) NULL,int *minorVsn= (int *) NULL) ;
c801d85f
KB
183
184// Set the cursor to the busy cursor for all windows
185class WXDLLEXPORT wxCursor;
186WXDLLEXPORT_DATA(extern wxCursor*) wxHOURGLASS_CURSOR;
184b5d99 187WXDLLEXPORT void wxBeginBusyCursor(wxCursor *cursor = wxHOURGLASS_CURSOR);
c801d85f
KB
188
189// Restore cursor to normal
184b5d99 190WXDLLEXPORT void wxEndBusyCursor(void);
c801d85f
KB
191
192// TRUE if we're between the above two calls
184b5d99 193WXDLLEXPORT bool wxIsBusy(void);
c801d85f
KB
194
195/* Error message functions used by wxWindows */
196
197// Non-fatal error (continues)
198WXDLLEXPORT_DATA(extern const char*) wxInternalErrorStr;
184b5d99 199WXDLLEXPORT void wxError(const wxString& msg, const wxString& title = wxInternalErrorStr);
c801d85f
KB
200
201// Fatal error (exits)
202WXDLLEXPORT_DATA(extern const char*) wxFatalErrorStr;
184b5d99 203WXDLLEXPORT void wxFatalError(const wxString& msg, const wxString& title = wxFatalErrorStr);
c801d85f
KB
204
205// Reading and writing resources (eg WIN.INI, .Xdefaults)
47d67540 206#if wxUSE_RESOURCES
62448488
JS
207WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file = wxEmptyString);
208WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file = wxEmptyString);
209WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file = wxEmptyString);
210WXDLLEXPORT bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file = wxEmptyString);
211
212WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file = wxEmptyString);
213WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file = wxEmptyString);
214WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file = wxEmptyString);
215WXDLLEXPORT bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file = wxEmptyString);
47d67540 216#endif // wxUSE_RESOURCES
c801d85f 217
7c3c5ecc 218// Get current Home dir and copy to dest (returns pstr->c_str())
184b5d99 219WXDLLEXPORT const char* wxGetHomeDir(wxString *pstr);
7c3c5ecc 220
c801d85f
KB
221// Get the user's home dir (caller must copy--- volatile)
222// returns NULL is no HOME dir is known
62448488 223WXDLLEXPORT char* wxGetUserHome(const wxString& user = wxEmptyString);
c801d85f
KB
224
225// Check whether this window wants to process messages, e.g. Stop button
226// in long calculations.
184b5d99 227WXDLLEXPORT bool wxCheckForInterrupt(wxWindow *wnd);
c801d85f
KB
228
229void WXDLLEXPORT wxGetMousePosition( int* x, int* y );
230
231// MSW only: get user-defined resource from the .res file.
232// Returns NULL or newly-allocated memory, so use delete[] to clean up.
2049ba38 233#ifdef __WXMSW__
184b5d99
JS
234WXDLLEXPORT extern const char* wxUserResourceStr;
235WXDLLEXPORT char* wxLoadUserResource(const wxString& resourceName, const wxString& resourceType = wxUserResourceStr);
c030b70f
JS
236
237// Implemented in utils.cpp: VC++, Win95 only. Sets up a console for standard
238// input/output
239WXDLLEXPORT void wxRedirectIOToConsole();
240
c801d85f
KB
241#endif
242
243// X only
244#ifdef __X__
46ccb510 245WXDisplay *wxGetDisplay();
c801d85f 246bool wxSetDisplay(const wxString& display_name);
46ccb510 247wxString wxGetDisplayName();
c801d85f
KB
248#endif
249
250#ifdef __X__
251
252#include <X11/Xlib.h>
253
254#define wxMAX_RGB 0xff
255#define wxMAX_SV 1000
256#define wxSIGN(x) ((x < 0) ? -x : x)
257#define wxH_WEIGHT 4
258#define wxS_WEIGHT 1
259#define wxV_WEIGHT 2
260
261typedef struct wx_hsv {
262 int h,s,v;
263 } wxHSV;
264
265#define wxMax3(x,y,z) ((x > y) ? ((x > z) ? x : z) : ((y > z) ? y : z))
266#define wxMin3(x,y,z) ((x < y) ? ((x < z) ? x : z) : ((y < z) ? y : z))
267
268#define wxMax2(x,y) ((x > y) ? x : y)
269#define wxMin2(x,y) ((x < y) ? x : y)
270
271void wxHSVToXColor(wxHSV *hsv,XColor *xcolor);
272void wxXColorToHSV(wxHSV *hsv,XColor *xcolor);
273void wxAllocNearestColor(Display *display,Colormap colormap,XColor *xcolor);
274void wxAllocColor(Display *display,Colormap colormap,XColor *xcolor);
275
276#endif //__X__
277
278#endif
34138703 279 // _WX_UTILSH__