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