]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/utils.cpp
Removed plot.cpp.
[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 // get full hostname (with domain name if possible)
31 bool wxGetFullHostName(wxChar *buf, int maxSize)
32 {
33 return wxGetHostName(buf, maxSize);
34 }
35
36 // Get hostname only (without domain name)
37 bool wxGetHostName(char *buf, int maxSize)
38 {
39 // TODO
40 return FALSE;
41 }
42
43 // Get user ID e.g. jacs
44 bool wxGetUserId(char *buf, int maxSize)
45 {
46 // TODO
47 return FALSE;
48 }
49
50 // Get user name e.g. AUTHOR
51 bool wxGetUserName(char *buf, int maxSize)
52 {
53 // TODO
54 return FALSE;
55 }
56
57 int wxKill(long pid, int sig)
58 {
59 // TODO
60 return 0;
61 }
62
63 //
64 // Execute a program in an Interactive Shell
65 //
66 bool 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)
73 long wxGetFreeMemory()
74 {
75 // TODO
76 return 0;
77 }
78
79 void wxSleep(int nSecs)
80 {
81 // TODO
82 }
83
84 // Consume all events until no more left
85 void wxFlushEvents()
86 {
87 }
88
89 // Output a debug message, in a system dependent fashion.
90 void 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
107 void wxError(const wxString& msg, const wxString& title)
108 {
109 // TODO
110 wxExit();
111 }
112
113 // Fatal error: pop up message box and abort
114 void wxFatalError(const wxString& msg, const wxString& title)
115 {
116 // TODO
117 }
118
119 // Emit a beeeeeep
120 void wxBell()
121 {
122 // TODO
123 }
124
125 int 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
133 bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
134 {
135 // TODO
136 return FALSE;
137 }
138
139 bool 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
146 bool 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
153 bool 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
160 bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
161 {
162 // TODO
163 return FALSE;
164 }
165
166 bool 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
179 bool 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
192 bool 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
206 int wxBusyCursorCount = 0;
207 extern CursHandle gMacCurrentCursor ;
208 CursHandle gMacStoredActiveCursor = NULL ;
209
210 // Set the cursor to the busy cursor for all windows
211 void wxBeginBusyCursor(wxCursor *cursor)
212 {
213 wxBusyCursorCount ++;
214 if (wxBusyCursorCount == 1)
215 {
216 gMacStoredActiveCursor = gMacCurrentCursor ;
217 ::SetCursor( *::GetCursor( watchCursor ) ) ;
218 }
219 else
220 {
221 // TODO
222 }
223 }
224
225 // Restore cursor to normal
226 void wxEndBusyCursor()
227 {
228 if (wxBusyCursorCount == 0)
229 return;
230
231 wxBusyCursorCount --;
232 if (wxBusyCursorCount == 0)
233 {
234 if ( gMacStoredActiveCursor )
235 ::SetCursor( *gMacStoredActiveCursor ) ;
236 else
237 {
238 Cursor MacArrow ;
239 ::SetCursor( GetQDGlobalsArrow( &MacArrow ) ) ;
240 }
241 gMacStoredActiveCursor = NULL ;
242 }
243 }
244
245 // TRUE if we're between the above two calls
246 bool wxIsBusy()
247 {
248 return (wxBusyCursorCount > 0);
249 }
250
251 wxString 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
270 char *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.
278 bool wxCheckForInterrupt(wxWindow *wnd)
279 {
280 // TODO
281 return FALSE;
282 }
283
284 void wxGetMousePosition( int* x, int* y )
285 {
286 Point pt ;
287
288 GetMouse( &pt ) ;
289 LocalToGlobal( &pt ) ;
290 *x = pt.h ;
291 *y = pt.v ;
292 };
293
294 // Return TRUE if we have a colour display
295 bool wxColourDisplay()
296 {
297 return TRUE;
298 }
299
300 // Returns depth of screen
301 int wxDisplayDepth()
302 {
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;
311
312 return theDepth ;
313 }
314
315 // Get size of display
316 void wxDisplaySize(int *width, int *height)
317 {
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
330 }
331
332 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
333 {
334 return wxGenericFindWindowAtPoint(pt);
335 }