]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/utils.cpp
applied SourceForge patch #419884 from Marc Newsam
[wxWidgets.git] / src / mac / carbon / utils.cpp
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"
21 #include "wx/mac/uma.h"
22
23 #include <ctype.h>
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdarg.h>
29
30 #ifndef __UNIX__
31 // defined in unix/utilsunx.cpp for Mac OS X
32
33 // get full hostname (with domain name if possible)
34 bool wxGetFullHostName(wxChar *buf, int maxSize)
35 {
36 return wxGetHostName(buf, maxSize);
37 }
38
39 // Get hostname only (without domain name)
40 bool wxGetHostName(char *buf, int maxSize)
41 {
42 // TODO
43 return FALSE;
44 }
45
46 // Get user ID e.g. jacs
47 bool wxGetUserId(char *buf, int maxSize)
48 {
49 // TODO
50 return FALSE;
51 }
52
53 const wxChar* wxGetHomeDir(wxString *pstr)
54 {
55 *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ) ;
56 return pstr->c_str() ;
57 }
58
59
60
61 // Get user name e.g. AUTHOR
62 bool wxGetUserName(char *buf, int maxSize)
63 {
64 // TODO
65 return FALSE;
66 }
67
68 int wxKill(long pid, int sig)
69 {
70 // TODO
71 return 0;
72 }
73
74 //
75 // Execute a program in an Interactive Shell
76 //
77 bool 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)
84 long wxGetFreeMemory()
85 {
86 // TODO
87 return 0;
88 }
89
90 void wxSleep(int nSecs)
91 {
92 // TODO
93 }
94
95 // Consume all events until no more left
96 void wxFlushEvents()
97 {
98 }
99
100 // Output a debug message, in a system dependent fashion.
101 void 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
118 void wxError(const wxString& msg, const wxString& title)
119 {
120 // TODO
121 wxExit();
122 }
123
124 // Fatal error: pop up message box and abort
125 void wxFatalError(const wxString& msg, const wxString& title)
126 {
127 // TODO
128 }
129 #endif // !__UNIX__
130
131 // Emit a beeeeeep
132 void wxBell()
133 {
134 // TODO
135 }
136
137 int 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
145 bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
146 {
147 // TODO
148 return FALSE;
149 }
150
151 bool 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
158 bool 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
165 bool 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
172 bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
173 {
174 // TODO
175 return FALSE;
176 }
177
178 bool 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
191 bool 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
204 bool 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
218 int wxBusyCursorCount = 0;
219 extern CursHandle gMacCurrentCursor ;
220 CursHandle gMacStoredActiveCursor = NULL ;
221
222 // Set the cursor to the busy cursor for all windows
223 void wxBeginBusyCursor(wxCursor *cursor)
224 {
225 wxBusyCursorCount ++;
226 if (wxBusyCursorCount == 1)
227 {
228 gMacStoredActiveCursor = gMacCurrentCursor ;
229 ::SetCursor( *::GetCursor( watchCursor ) ) ;
230 }
231 else
232 {
233 // TODO
234 }
235 }
236
237 // Restore cursor to normal
238 void wxEndBusyCursor()
239 {
240 if (wxBusyCursorCount == 0)
241 return;
242
243 wxBusyCursorCount --;
244 if (wxBusyCursorCount == 0)
245 {
246 if ( gMacStoredActiveCursor )
247 ::SetCursor( *gMacStoredActiveCursor ) ;
248 else
249 {
250 Cursor MacArrow ;
251 ::SetCursor( GetQDGlobalsArrow( &MacArrow ) ) ;
252 }
253 gMacStoredActiveCursor = NULL ;
254 }
255 }
256
257 // TRUE if we're between the above two calls
258 bool wxIsBusy()
259 {
260 return (wxBusyCursorCount > 0);
261 }
262
263 #ifndef __UNIX__
264 wxString wxMacFindFolder( short vol,
265 OSType folderType,
266 Boolean createFolder)
267 {
268 short vRefNum ;
269 long dirID ;
270 wxString strDir ;
271
272 if ( FindFolder( vol, folderType, createFolder, &vRefNum, &dirID) == noErr)
273 {
274 FSSpec file ;
275 if ( FSMakeFSSpec( vRefNum , dirID , "\p" , &file ) == noErr )
276 {
277 strDir = wxMacFSSpec2UnixFilename( &file ) + "/" ;
278 }
279 }
280 return strDir ;
281 }
282 #endif
283
284 #ifndef __UNIX__
285 char *wxGetUserHome (const wxString& user)
286 {
287 // TODO
288 return NULL;
289 }
290 #endif
291
292 // Check whether this window wants to process messages, e.g. Stop button
293 // in long calculations.
294 bool wxCheckForInterrupt(wxWindow *wnd)
295 {
296 // TODO
297 return FALSE;
298 }
299
300 void wxGetMousePosition( int* x, int* y )
301 {
302 Point pt ;
303
304 GetMouse( &pt ) ;
305 LocalToGlobal( &pt ) ;
306 *x = pt.h ;
307 *y = pt.v ;
308 };
309
310 // Return TRUE if we have a colour display
311 bool wxColourDisplay()
312 {
313 return TRUE;
314 }
315
316 // Returns depth of screen
317 int wxDisplayDepth()
318 {
319 Rect globRect ;
320 SetRect(&globRect, -32760, -32760, 32760, 32760);
321 GDHandle theMaxDevice;
322
323 int theDepth = 8;
324 theMaxDevice = GetMaxDevice(&globRect);
325 if (theMaxDevice != nil)
326 theDepth = (**(**theMaxDevice).gdPMap).pixelSize;
327
328 return theDepth ;
329 }
330
331 // Get size of display
332 void wxDisplaySize(int *width, int *height)
333 {
334 BitMap screenBits;
335 GetQDGlobalsScreenBits( &screenBits );
336
337 *width = screenBits.bounds.right - screenBits.bounds.left ;
338 *height = screenBits.bounds.bottom - screenBits.bounds.top ;
339 #if TARGET_CARBON
340 SInt16 mheight ;
341 GetThemeMenuBarHeight( &mheight ) ;
342 *height -= mheight ;
343 #else
344 *height -= LMGetMBarHeight() ;
345 #endif
346 }
347
348 void wxDisplaySizeMM(int *width, int *height)
349 {
350 wxDisplaySize(width, height);
351 }
352
353 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
354 {
355 // This is supposed to return desktop dimensions minus any window
356 // manager panels, menus, taskbars, etc. If there is a way to do that
357 // for this platform please fix this function, otherwise it defaults
358 // to the entire desktop.
359 if (x) *x = 0;
360 if (y) *y = 0;
361 wxDisplaySize(width, height);
362 }
363
364 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
365 {
366 return wxGenericFindWindowAtPoint(pt);
367 }