]> git.saurik.com Git - wxWidgets.git/blame - src/mac/utils.cpp
Added wxCommandEvent::IsSeection for listbox,
[wxWidgets.git] / src / mac / utils.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: utils.cpp
3// Purpose: Various utilities
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13// Note: this is done in utilscmn.cpp now.
14// #pragma implementation
15// #pragma implementation "utils.h"
16#endif
17
18#include "wx/setup.h"
19#include "wx/utils.h"
20#include "wx/app.h"
2f1ae414 21#include "wx/mac/uma.h"
e9576ca5
SC
22
23#include <ctype.h>
24
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <stdarg.h>
29
2f1ae414
SC
30// get full hostname (with domain name if possible)
31bool wxGetFullHostName(wxChar *buf, int maxSize)
32{
33 return wxGetHostName(buf, maxSize);
34}
35
36// Get hostname only (without domain name)
e9576ca5
SC
37bool wxGetHostName(char *buf, int maxSize)
38{
39 // TODO
40 return FALSE;
41}
42
43// Get user ID e.g. jacs
44bool wxGetUserId(char *buf, int maxSize)
45{
46 // TODO
47 return FALSE;
48}
49
50// Get user name e.g. AUTHOR
51bool wxGetUserName(char *buf, int maxSize)
52{
53 // TODO
54 return FALSE;
55}
56
57int wxKill(long pid, int sig)
58{
59 // TODO
60 return 0;
61}
62
63//
64// Execute a program in an Interactive Shell
65//
66bool wxShell(const wxString& command)
67{
68 // TODO
69 return FALSE;
70}
71
72// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
73long wxGetFreeMemory()
74{
75 // TODO
76 return 0;
77}
78
79void wxSleep(int nSecs)
80{
81 // TODO
82}
83
84// Consume all events until no more left
85void wxFlushEvents()
86{
87}
88
89// Output a debug message, in a system dependent fashion.
90void wxDebugMsg(const char *fmt ...)
91{
92 va_list ap;
93 static char buffer[512];
94
95 if (!wxTheApp->GetWantDebugOutput())
96 return ;
97
98 va_start(ap, fmt);
99
100 // wvsprintf(buffer,fmt,ap) ;
101 // TODO: output buffer
102
103 va_end(ap);
104}
105
106// Non-fatal error: pop up message box and (possibly) continue
107void wxError(const wxString& msg, const wxString& title)
108{
109 // TODO
110 wxExit();
111}
112
113// Fatal error: pop up message box and abort
114void wxFatalError(const wxString& msg, const wxString& title)
115{
116 // TODO
117}
118
119// Emit a beeeeeep
120void wxBell()
121{
122 // TODO
123}
124
125int wxGetOsVersion(int *majorVsn, int *minorVsn)
126{
127 // TODO
128 return 0;
129}
130
131// Reading and writing resources (eg WIN.INI, .Xdefaults)
132#if wxUSE_RESOURCES
133bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
134{
135 // TODO
136 return FALSE;
137}
138
139bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file)
140{
141 char buf[50];
142 sprintf(buf, "%.4f", value);
143 return wxWriteResource(section, entry, buf, file);
144}
145
146bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file)
147{
148 char buf[50];
149 sprintf(buf, "%ld", value);
150 return wxWriteResource(section, entry, buf, file);
151}
152
153bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file)
154{
155 char buf[50];
156 sprintf(buf, "%d", value);
157 return wxWriteResource(section, entry, buf, file);
158}
159
160bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
161{
162 // TODO
163 return FALSE;
164}
165
166bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file)
167{
168 char *s = NULL;
169 bool succ = wxGetResource(section, entry, (char **)&s, file);
170 if (succ)
171 {
172 *value = (float)strtod(s, NULL);
173 delete[] s;
174 return TRUE;
175 }
176 else return FALSE;
177}
178
179bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file)
180{
181 char *s = NULL;
182 bool succ = wxGetResource(section, entry, (char **)&s, file);
183 if (succ)
184 {
185 *value = strtol(s, NULL, 10);
186 delete[] s;
187 return TRUE;
188 }
189 else return FALSE;
190}
191
192bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file)
193{
194 char *s = NULL;
195 bool succ = wxGetResource(section, entry, (char **)&s, file);
196 if (succ)
197 {
198 *value = (int)strtol(s, NULL, 10);
199 delete[] s;
200 return TRUE;
201 }
202 else return FALSE;
203}
204#endif // wxUSE_RESOURCES
205
519cb848
SC
206int wxBusyCursorCount = 0;
207extern CursHandle gMacCurrentCursor ;
208CursHandle gMacStoredActiveCursor = NULL ;
e9576ca5
SC
209
210// Set the cursor to the busy cursor for all windows
211void wxBeginBusyCursor(wxCursor *cursor)
212{
213 wxBusyCursorCount ++;
214 if (wxBusyCursorCount == 1)
215 {
519cb848
SC
216 gMacStoredActiveCursor = gMacCurrentCursor ;
217 ::SetCursor( *::GetCursor( watchCursor ) ) ;
e9576ca5
SC
218 }
219 else
220 {
221 // TODO
222 }
223}
224
225// Restore cursor to normal
226void wxEndBusyCursor()
227{
228 if (wxBusyCursorCount == 0)
229 return;
230
231 wxBusyCursorCount --;
232 if (wxBusyCursorCount == 0)
233 {
519cb848
SC
234 if ( gMacStoredActiveCursor )
235 ::SetCursor( *gMacStoredActiveCursor ) ;
236 else
2f1ae414
SC
237 {
238 Cursor MacArrow ;
239 ::SetCursor( GetQDGlobalsArrow( &MacArrow ) ) ;
240 }
519cb848 241 gMacStoredActiveCursor = NULL ;
e9576ca5
SC
242 }
243}
244
245// TRUE if we're between the above two calls
246bool wxIsBusy()
247{
248 return (wxBusyCursorCount > 0);
249}
250
2f1ae414
SC
251wxString wxMacFindFolder( short vol,
252 OSType folderType,
253 Boolean createFolder)
254{
255 short vRefNum ;
256 long dirID ;
257 wxString strDir ;
258
259 if ( FindFolder( vol, folderType, createFolder, &vRefNum, &dirID) == noErr)
260 {
261 FSSpec file ;
262 if ( FSMakeFSSpec( vRefNum , dirID , "\p" , &file ) == noErr )
263 {
264 strDir = wxMacFSSpec2UnixFilename( &file ) + "/" ;
265 }
266 }
267 return strDir ;
268}
269
e9576ca5
SC
270char *wxGetUserHome (const wxString& user)
271{
272 // TODO
273 return NULL;
274}
275
276// Check whether this window wants to process messages, e.g. Stop button
277// in long calculations.
278bool wxCheckForInterrupt(wxWindow *wnd)
279{
280 // TODO
281 return FALSE;
282}
283
284void wxGetMousePosition( int* x, int* y )
285{
519cb848
SC
286 Point pt ;
287
288 GetMouse( &pt ) ;
289 LocalToGlobal( &pt ) ;
290 *x = pt.h ;
291 *y = pt.v ;
e9576ca5
SC
292};
293
294// Return TRUE if we have a colour display
295bool wxColourDisplay()
296{
e9576ca5
SC
297 return TRUE;
298}
299
300// Returns depth of screen
301int wxDisplayDepth()
302{
2f1ae414
SC
303 Rect globRect ;
304 SetRect(&globRect, -32760, -32760, 32760, 32760);
305 GDHandle theMaxDevice;
306
307 int theDepth = 8;
308 theMaxDevice = GetMaxDevice(&globRect);
309 if (theMaxDevice != nil)
310 theDepth = (**(**theMaxDevice).gdPMap).pixelSize;
519cb848 311
2f1ae414 312 return theDepth ;
e9576ca5
SC
313}
314
315// Get size of display
316void wxDisplaySize(int *width, int *height)
317{
2f1ae414
SC
318 BitMap screenBits;
319 GetQDGlobalsScreenBits( &screenBits );
320
321 *width = screenBits.bounds.right - screenBits.bounds.left ;
322 *height = screenBits.bounds.bottom - screenBits.bounds.top ;
323 #if TARGET_CARBON
324 SInt16 mheight ;
325 GetThemeMenuBarHeight( &mheight ) ;
326 *height -= mheight ;
327#else
328 *height -= LMGetMBarHeight() ;
329 #endif
e9576ca5
SC
330}
331
57591e0e
JS
332wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
333{
334 return wxGenericFindWindowAtPoint(pt);
335}