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