]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/utils.cpp
moved splines rendering code into wxDCBase
[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 wxString 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
282 #ifndef __UNIX__
283 char *wxGetUserHome (const wxString& user)
284 {
285 // TODO
286 return NULL;
287 }
288 #endif
289
290 // Check whether this window wants to process messages, e.g. Stop button
291 // in long calculations.
292 bool wxCheckForInterrupt(wxWindow *wnd)
293 {
294 // TODO
295 return FALSE;
296 }
297
298 void wxGetMousePosition( int* x, int* y )
299 {
300 Point pt ;
301
302 GetMouse( &pt ) ;
303 LocalToGlobal( &pt ) ;
304 *x = pt.h ;
305 *y = pt.v ;
306 };
307
308 // Return TRUE if we have a colour display
309 bool wxColourDisplay()
310 {
311 return TRUE;
312 }
313
314 // Returns depth of screen
315 int wxDisplayDepth()
316 {
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;
325
326 return theDepth ;
327 }
328
329 // Get size of display
330 void wxDisplaySize(int *width, int *height)
331 {
332 BitMap screenBits;
333 GetQDGlobalsScreenBits( &screenBits );
334
335 *width = screenBits.bounds.right - screenBits.bounds.left ;
336 *height = screenBits.bounds.bottom - screenBits.bounds.top ;
337 #if TARGET_CARBON
338 SInt16 mheight ;
339 GetThemeMenuBarHeight( &mheight ) ;
340 *height -= mheight ;
341 #else
342 *height -= LMGetMBarHeight() ;
343 #endif
344 }
345
346 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
347 {
348 return wxGenericFindWindowAtPoint(pt);
349 }