]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: utils.cpp | |
3 | // Purpose: Various utilities | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | // Note: this is done in utilscmn.cpp now. | |
e9576ca5 SC |
14 | // #pragma implementation "utils.h" |
15 | #endif | |
16 | ||
17 | #include "wx/setup.h" | |
18 | #include "wx/utils.h" | |
19 | #include "wx/app.h" | |
2bf2d09e | 20 | #include "wx/apptrait.h" |
b6ed2b86 VZ |
21 | |
22 | #if wxUSE_GUI | |
23 | #include "wx/mac/uma.h" | |
9d8aca48 | 24 | #include "wx/font.h" |
fe929141 | 25 | #else |
9d8aca48 | 26 | #include "wx/intl.h" |
b6ed2b86 | 27 | #endif |
e9576ca5 SC |
28 | |
29 | #include <ctype.h> | |
30 | ||
31 | #include <stdio.h> | |
32 | #include <stdlib.h> | |
33 | #include <string.h> | |
34 | #include <stdarg.h> | |
35 | ||
a2b77260 | 36 | #include "MoreFilesX.h" |
518af45b | 37 | |
66a09d47 SC |
38 | #ifndef __DARWIN__ |
39 | #include <Threads.h> | |
40 | #include <Sound.h> | |
41 | #endif | |
42 | ||
7d9bf1f1 | 43 | #if wxUSE_GUI |
29d91661 SC |
44 | #if TARGET_API_MAC_OSX |
45 | #include <CoreServices/CoreServices.h> | |
46 | #else | |
47 | #include <DriverServices.h> | |
48 | #include <Multiprocessing.h> | |
49 | #endif | |
50 | ||
7f0c3a63 SC |
51 | #include <ATSUnicode.h> |
52 | #include <TextCommon.h> | |
53 | #include <TextEncodingConverter.h> | |
7d9bf1f1 | 54 | #endif // wxUSE_GUI |
427ff662 | 55 | |
8aa701ed | 56 | #include "wx/mac/private.h" // includes mac headers |
a434b43f VZ |
57 | |
58 | #if defined(__MWERKS__) && wxUSE_UNICODE | |
59 | #include <wtime.h> | |
60 | #endif | |
61 | ||
659b3e8b VZ |
62 | // --------------------------------------------------------------------------- |
63 | // code used in both base and GUI compilation | |
64 | // --------------------------------------------------------------------------- | |
65 | ||
66 | // our OS version is the same in non GUI and GUI cases | |
67 | static int DoGetOSVersion(int *majorVsn, int *minorVsn) | |
68 | { | |
69 | long theSystem ; | |
70 | ||
71 | // are there x-platform conventions ? | |
72 | ||
73 | Gestalt(gestaltSystemVersion, &theSystem) ; | |
74 | if (minorVsn != NULL) { | |
75 | *minorVsn = (theSystem & 0xFF ) ; | |
76 | } | |
77 | if (majorVsn != NULL) { | |
78 | *majorVsn = (theSystem >> 8 ) ; | |
79 | } | |
80 | #ifdef __DARWIN__ | |
81 | return wxMAC_DARWIN; | |
82 | #else | |
83 | return wxMAC; | |
84 | #endif | |
85 | } | |
86 | ||
ee8bf34f RD |
87 | |
88 | #if wxUSE_BASE | |
89 | ||
e5a9c663 SC |
90 | // ---------------------------------------------------------------------------- |
91 | // debugging support | |
92 | // ---------------------------------------------------------------------------- | |
93 | ||
94 | #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400) | |
95 | ||
96 | // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds... | |
97 | ||
98 | #ifndef __MetroNubUtils__ | |
99 | #include "MetroNubUtils.h" | |
100 | #endif | |
101 | ||
102 | #ifndef __GESTALT__ | |
103 | #include <Gestalt.h> | |
104 | #endif | |
105 | ||
106 | #if TARGET_API_MAC_CARBON | |
107 | ||
108 | #include <CodeFragments.h> | |
109 | ||
110 | extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...); | |
111 | ||
112 | ProcPtr gCallUniversalProc_Proc = NULL; | |
113 | ||
114 | #endif | |
115 | ||
116 | static MetroNubUserEntryBlock* gMetroNubEntry = NULL; | |
117 | ||
118 | static long fRunOnce = false; | |
119 | ||
120 | /* --------------------------------------------------------------------------- | |
121 | IsMetroNubInstalled | |
122 | --------------------------------------------------------------------------- */ | |
123 | ||
124 | Boolean IsMetroNubInstalled() | |
125 | { | |
126 | if (!fRunOnce) | |
127 | { | |
128 | long result, value; | |
129 | ||
130 | fRunOnce = true; | |
131 | gMetroNubEntry = NULL; | |
132 | ||
133 | if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000) | |
134 | { | |
135 | /* look for MetroNub's Gestalt selector */ | |
136 | if (Gestalt(kMetroNubUserSignature, &result) == noErr) | |
137 | { | |
138 | ||
139 | #if TARGET_API_MAC_CARBON | |
140 | if (gCallUniversalProc_Proc == NULL) | |
141 | { | |
142 | CFragConnectionID connectionID; | |
143 | Ptr mainAddress; | |
144 | Str255 errorString; | |
145 | ProcPtr symbolAddress; | |
146 | OSErr err; | |
147 | CFragSymbolClass symbolClass; | |
148 | ||
149 | symbolAddress = NULL; | |
150 | err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag, | |
151 | &connectionID, &mainAddress, errorString); | |
152 | ||
153 | if (err != noErr) | |
154 | { | |
155 | gCallUniversalProc_Proc = NULL; | |
156 | goto end; | |
157 | } | |
158 | ||
159 | err = FindSymbol(connectionID, "\pCallUniversalProc", | |
160 | (Ptr *) &gCallUniversalProc_Proc, &symbolClass); | |
161 | ||
162 | if (err != noErr) | |
163 | { | |
164 | gCallUniversalProc_Proc = NULL; | |
165 | goto end; | |
166 | } | |
167 | } | |
168 | #endif | |
169 | ||
170 | { | |
171 | MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result; | |
172 | ||
173 | /* make sure the version of the API is compatible */ | |
174 | if (block->apiLowVersion <= kMetroNubUserAPIVersion && | |
175 | kMetroNubUserAPIVersion <= block->apiHiVersion) | |
176 | gMetroNubEntry = block; /* success! */ | |
177 | } | |
178 | ||
179 | } | |
180 | } | |
181 | } | |
182 | ||
183 | end: | |
184 | ||
185 | #if TARGET_API_MAC_CARBON | |
186 | return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL); | |
187 | #else | |
188 | return (gMetroNubEntry != NULL); | |
189 | #endif | |
190 | } | |
191 | ||
192 | /* --------------------------------------------------------------------------- | |
193 | IsMWDebuggerRunning [v1 API] | |
194 | --------------------------------------------------------------------------- */ | |
195 | ||
196 | Boolean IsMWDebuggerRunning() | |
197 | { | |
198 | if (IsMetroNubInstalled()) | |
199 | return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning); | |
200 | else | |
201 | return false; | |
202 | } | |
203 | ||
204 | /* --------------------------------------------------------------------------- | |
205 | AmIBeingMWDebugged [v1 API] | |
206 | --------------------------------------------------------------------------- */ | |
207 | ||
208 | Boolean AmIBeingMWDebugged() | |
209 | { | |
210 | if (IsMetroNubInstalled()) | |
211 | return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged); | |
212 | else | |
213 | return false; | |
214 | } | |
215 | ||
216 | extern bool WXDLLEXPORT wxIsDebuggerRunning() | |
217 | { | |
218 | return IsMWDebuggerRunning() && AmIBeingMWDebugged(); | |
219 | } | |
220 | ||
221 | #else | |
222 | ||
223 | extern bool WXDLLEXPORT wxIsDebuggerRunning() | |
224 | { | |
225 | return false; | |
226 | } | |
227 | ||
228 | #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400) | |
229 | ||
a434b43f | 230 | |
f5c6eb5c | 231 | #ifndef __DARWIN__ |
03e11df5 GD |
232 | // defined in unix/utilsunx.cpp for Mac OS X |
233 | ||
2f1ae414 SC |
234 | // get full hostname (with domain name if possible) |
235 | bool wxGetFullHostName(wxChar *buf, int maxSize) | |
236 | { | |
237 | return wxGetHostName(buf, maxSize); | |
238 | } | |
239 | ||
240 | // Get hostname only (without domain name) | |
427ff662 | 241 | bool wxGetHostName(wxChar *buf, int maxSize) |
e9576ca5 | 242 | { |
e40298d5 JS |
243 | // Gets Chooser name of user by examining a System resource. |
244 | ||
245 | const short kComputerNameID = -16413; | |
5be55d56 | 246 | |
e40298d5 JS |
247 | short oldResFile = CurResFile() ; |
248 | UseResFile(0); | |
249 | StringHandle chooserName = (StringHandle)::GetString(kComputerNameID); | |
250 | UseResFile(oldResFile); | |
251 | ||
252 | if (chooserName && *chooserName) | |
253 | { | |
427ff662 SC |
254 | HLock( (Handle) chooserName ) ; |
255 | wxString name = wxMacMakeStringFromPascal( *chooserName ) ; | |
256 | HUnlock( (Handle) chooserName ) ; | |
257 | ReleaseResource( (Handle) chooserName ) ; | |
258 | wxStrncpy( buf , name , maxSize - 1 ) ; | |
e40298d5 JS |
259 | } |
260 | else | |
261 | buf[0] = 0 ; | |
0a67a93b | 262 | |
9d8aca48 | 263 | return true; |
e9576ca5 SC |
264 | } |
265 | ||
266 | // Get user ID e.g. jacs | |
427ff662 | 267 | bool wxGetUserId(wxChar *buf, int maxSize) |
e9576ca5 | 268 | { |
0a67a93b | 269 | return wxGetUserName( buf , maxSize ) ; |
e9576ca5 SC |
270 | } |
271 | ||
5b781a67 SC |
272 | const wxChar* wxGetHomeDir(wxString *pstr) |
273 | { | |
e40298d5 JS |
274 | *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ) ; |
275 | return pstr->c_str() ; | |
5b781a67 SC |
276 | } |
277 | ||
a31a5f85 | 278 | // Get user name e.g. Stefan Csomor |
427ff662 | 279 | bool wxGetUserName(wxChar *buf, int maxSize) |
e9576ca5 | 280 | { |
e40298d5 JS |
281 | // Gets Chooser name of user by examining a System resource. |
282 | ||
283 | const short kChooserNameID = -16096; | |
5be55d56 | 284 | |
e40298d5 JS |
285 | short oldResFile = CurResFile() ; |
286 | UseResFile(0); | |
287 | StringHandle chooserName = (StringHandle)::GetString(kChooserNameID); | |
288 | UseResFile(oldResFile); | |
289 | ||
290 | if (chooserName && *chooserName) | |
291 | { | |
427ff662 SC |
292 | HLock( (Handle) chooserName ) ; |
293 | wxString name = wxMacMakeStringFromPascal( *chooserName ) ; | |
294 | HUnlock( (Handle) chooserName ) ; | |
295 | ReleaseResource( (Handle) chooserName ) ; | |
296 | wxStrncpy( buf , name , maxSize - 1 ) ; | |
e40298d5 JS |
297 | } |
298 | else | |
299 | buf[0] = 0 ; | |
0a67a93b | 300 | |
9d8aca48 | 301 | return true; |
e9576ca5 SC |
302 | } |
303 | ||
e0f6b731 | 304 | int wxKill(long pid, wxSignal sig , wxKillError *rc, int flags) |
e9576ca5 SC |
305 | { |
306 | // TODO | |
307 | return 0; | |
308 | } | |
309 | ||
5dbb17e2 SC |
310 | WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value) |
311 | { | |
e40298d5 JS |
312 | // TODO : under classic there is no environement support, under X yes |
313 | return false ; | |
5dbb17e2 SC |
314 | } |
315 | ||
9d8aca48 | 316 | // set the env var name to the given value, return true on success |
5dbb17e2 SC |
317 | WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value) |
318 | { | |
e40298d5 JS |
319 | // TODO : under classic there is no environement support, under X yes |
320 | return false ; | |
5dbb17e2 SC |
321 | } |
322 | ||
e9576ca5 SC |
323 | // |
324 | // Execute a program in an Interactive Shell | |
325 | // | |
326 | bool wxShell(const wxString& command) | |
327 | { | |
328 | // TODO | |
9d8aca48 | 329 | return false; |
e9576ca5 SC |
330 | } |
331 | ||
5be55d56 | 332 | // Shutdown or reboot the PC |
f6ba47d9 VZ |
333 | bool wxShutdown(wxShutdownFlags wFlags) |
334 | { | |
335 | // TODO | |
9d8aca48 | 336 | return false; |
f6ba47d9 VZ |
337 | } |
338 | ||
8ea92b4d WS |
339 | wxPowerType wxGetPowerType() |
340 | { | |
341 | // TODO | |
342 | return wxPOWER_UNKNOWN; | |
343 | } | |
344 | ||
345 | wxBatteryState wxGetBatteryState() | |
346 | { | |
347 | // TODO | |
348 | return wxBATTERY_UNKNOWN_STATE; | |
349 | } | |
350 | ||
e9576ca5 | 351 | // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) |
9d8aca48 | 352 | wxMemorySize wxGetFreeMemory() |
e9576ca5 | 353 | { |
9d8aca48 | 354 | return (wxMemorySize)FreeMem() ; |
0a67a93b SC |
355 | } |
356 | ||
7f7b52b4 SC |
357 | #ifndef __DARWIN__ |
358 | ||
359 | void wxMicroSleep(unsigned long microseconds) | |
0a67a93b | 360 | { |
9d8aca48 WS |
361 | AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime()); |
362 | MPDelayUntil( & wakeup); | |
7f7b52b4 SC |
363 | } |
364 | ||
365 | void wxMilliSleep(unsigned long milliseconds) | |
366 | { | |
9d8aca48 WS |
367 | AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime()); |
368 | MPDelayUntil( & wakeup); | |
e9576ca5 SC |
369 | } |
370 | ||
371 | void wxSleep(int nSecs) | |
372 | { | |
7f7b52b4 | 373 | wxMilliSleep(1000*nSecs); |
e9576ca5 SC |
374 | } |
375 | ||
7f7b52b4 SC |
376 | #endif |
377 | ||
e9576ca5 SC |
378 | // Consume all events until no more left |
379 | void wxFlushEvents() | |
380 | { | |
381 | } | |
382 | ||
f5c6eb5c | 383 | #endif // !__DARWIN__ |
e9576ca5 SC |
384 | |
385 | // Emit a beeeeeep | |
386 | void wxBell() | |
387 | { | |
0a67a93b | 388 | SysBeep(30); |
e9576ca5 SC |
389 | } |
390 | ||
324899f6 | 391 | wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo() |
29c99ad3 | 392 | { |
a8eaaeb2 | 393 | static wxToolkitInfo info; |
66b6b57c | 394 | info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); |
a8eaaeb2 | 395 | info.name = _T("wxBase"); |
324899f6 | 396 | return info; |
29c99ad3 VZ |
397 | } |
398 | ||
b6ed2b86 VZ |
399 | #endif // wxUSE_BASE |
400 | ||
401 | #if wxUSE_GUI | |
536732e4 | 402 | |
324899f6 | 403 | wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() |
29c99ad3 | 404 | { |
a8eaaeb2 | 405 | static wxToolkitInfo info; |
66b6b57c | 406 | info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); |
a8eaaeb2 VS |
407 | info.shortName = _T("mac"); |
408 | info.name = _T("wxMac"); | |
409 | #ifdef __WXUNIVERSAL__ | |
410 | info.shortName << _T("univ"); | |
411 | info.name << _T("/wxUniversal"); | |
412 | #endif | |
324899f6 | 413 | return info; |
29c99ad3 VZ |
414 | } |
415 | ||
e9576ca5 SC |
416 | // Reading and writing resources (eg WIN.INI, .Xdefaults) |
417 | #if wxUSE_RESOURCES | |
418 | bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file) | |
419 | { | |
420 | // TODO | |
9d8aca48 | 421 | return false; |
e9576ca5 SC |
422 | } |
423 | ||
424 | bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file) | |
425 | { | |
427ff662 SC |
426 | wxString buf; |
427 | buf.Printf(wxT("%.4f"), value); | |
428 | ||
e40298d5 | 429 | return wxWriteResource(section, entry, buf, file); |
e9576ca5 SC |
430 | } |
431 | ||
432 | bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file) | |
433 | { | |
427ff662 SC |
434 | wxString buf; |
435 | buf.Printf(wxT("%ld"), value); | |
436 | ||
e40298d5 | 437 | return wxWriteResource(section, entry, buf, file); |
e9576ca5 SC |
438 | } |
439 | ||
440 | bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file) | |
441 | { | |
427ff662 SC |
442 | wxString buf; |
443 | buf.Printf(wxT("%d"), value); | |
444 | ||
e40298d5 | 445 | return wxWriteResource(section, entry, buf, file); |
e9576ca5 SC |
446 | } |
447 | ||
448 | bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file) | |
449 | { | |
450 | // TODO | |
9d8aca48 | 451 | return false; |
e9576ca5 SC |
452 | } |
453 | ||
454 | bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file) | |
455 | { | |
e40298d5 JS |
456 | char *s = NULL; |
457 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
458 | if (succ) | |
459 | { | |
460 | *value = (float)strtod(s, NULL); | |
461 | delete[] s; | |
9d8aca48 | 462 | return true; |
e40298d5 | 463 | } |
9d8aca48 | 464 | else return false; |
e9576ca5 SC |
465 | } |
466 | ||
467 | bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file) | |
468 | { | |
e40298d5 JS |
469 | char *s = NULL; |
470 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
471 | if (succ) | |
472 | { | |
473 | *value = strtol(s, NULL, 10); | |
474 | delete[] s; | |
9d8aca48 | 475 | return true; |
e40298d5 | 476 | } |
9d8aca48 | 477 | else return false; |
e9576ca5 SC |
478 | } |
479 | ||
480 | bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file) | |
481 | { | |
e40298d5 JS |
482 | char *s = NULL; |
483 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
484 | if (succ) | |
485 | { | |
486 | *value = (int)strtol(s, NULL, 10); | |
487 | delete[] s; | |
9d8aca48 | 488 | return true; |
e40298d5 | 489 | } |
9d8aca48 | 490 | else return false; |
e9576ca5 SC |
491 | } |
492 | #endif // wxUSE_RESOURCES | |
493 | ||
6b57b49a | 494 | int gs_wxBusyCursorCount = 0; |
e40298d5 JS |
495 | extern wxCursor gMacCurrentCursor ; |
496 | wxCursor gMacStoredActiveCursor ; | |
e9576ca5 SC |
497 | |
498 | // Set the cursor to the busy cursor for all windows | |
499 | void wxBeginBusyCursor(wxCursor *cursor) | |
500 | { | |
e40298d5 JS |
501 | if (gs_wxBusyCursorCount++ == 0) |
502 | { | |
503 | gMacStoredActiveCursor = gMacCurrentCursor ; | |
504 | cursor->MacInstall() ; | |
505 | } | |
506 | //else: nothing to do, already set | |
e9576ca5 SC |
507 | } |
508 | ||
509 | // Restore cursor to normal | |
510 | void wxEndBusyCursor() | |
511 | { | |
6b57b49a | 512 | wxCHECK_RET( gs_wxBusyCursorCount > 0, |
e40298d5 | 513 | wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") ); |
5be55d56 | 514 | |
e40298d5 JS |
515 | if (--gs_wxBusyCursorCount == 0) |
516 | { | |
517 | gMacStoredActiveCursor.MacInstall() ; | |
518 | gMacStoredActiveCursor = wxNullCursor ; | |
519 | } | |
e9576ca5 SC |
520 | } |
521 | ||
9d8aca48 | 522 | // true if we're between the above two calls |
e9576ca5 SC |
523 | bool wxIsBusy() |
524 | { | |
e40298d5 | 525 | return (gs_wxBusyCursorCount > 0); |
ec5d7799 | 526 | } |
e9576ca5 | 527 | |
2dbc444a RD |
528 | #endif // wxUSE_GUI |
529 | ||
530 | #if wxUSE_BASE | |
531 | ||
e7e1b01e | 532 | wxString wxMacFindFolder( short vol, |
e40298d5 JS |
533 | OSType folderType, |
534 | Boolean createFolder) | |
2f1ae414 | 535 | { |
9d8aca48 | 536 | FSRef fsRef ; |
2d4e4f80 | 537 | wxString strDir ; |
5be55d56 | 538 | |
a2b77260 | 539 | if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr) |
814af667 | 540 | strDir = wxMacFSRefToPath( &fsRef ) + wxFILE_SEP_PATH ; |
a2b77260 | 541 | |
2d4e4f80 | 542 | return strDir ; |
2f1ae414 SC |
543 | } |
544 | ||
2dbc444a RD |
545 | #endif // wxUSE_BASE |
546 | ||
547 | #if wxUSE_GUI | |
548 | ||
e9576ca5 SC |
549 | // Check whether this window wants to process messages, e.g. Stop button |
550 | // in long calculations. | |
551 | bool wxCheckForInterrupt(wxWindow *wnd) | |
552 | { | |
553 | // TODO | |
9d8aca48 | 554 | return false; |
e9576ca5 SC |
555 | } |
556 | ||
557 | void wxGetMousePosition( int* x, int* y ) | |
558 | { | |
519cb848 | 559 | Point pt ; |
ec5d7799 | 560 | |
519cb848 SC |
561 | GetMouse( &pt ) ; |
562 | LocalToGlobal( &pt ) ; | |
563 | *x = pt.h ; | |
564 | *y = pt.v ; | |
e9576ca5 SC |
565 | }; |
566 | ||
9d8aca48 | 567 | // Return true if we have a colour display |
e9576ca5 SC |
568 | bool wxColourDisplay() |
569 | { | |
9d8aca48 | 570 | return true; |
e9576ca5 SC |
571 | } |
572 | ||
573 | // Returns depth of screen | |
574 | int wxDisplayDepth() | |
575 | { | |
e40298d5 JS |
576 | Rect globRect ; |
577 | SetRect(&globRect, -32760, -32760, 32760, 32760); | |
578 | GDHandle theMaxDevice; | |
2f1ae414 | 579 | |
e40298d5 JS |
580 | int theDepth = 8; |
581 | theMaxDevice = GetMaxDevice(&globRect); | |
582 | if (theMaxDevice != nil) | |
583 | theDepth = (**(**theMaxDevice).gdPMap).pixelSize; | |
ec5d7799 | 584 | |
e40298d5 | 585 | return theDepth ; |
e9576ca5 SC |
586 | } |
587 | ||
588 | // Get size of display | |
589 | void wxDisplaySize(int *width, int *height) | |
590 | { | |
e40298d5 JS |
591 | BitMap screenBits; |
592 | GetQDGlobalsScreenBits( &screenBits ); | |
5be55d56 VZ |
593 | |
594 | if (width != NULL) { | |
e8ca7105 GD |
595 | *width = screenBits.bounds.right - screenBits.bounds.left ; |
596 | } | |
5be55d56 | 597 | if (height != NULL) { |
e8ca7105 GD |
598 | *height = screenBits.bounds.bottom - screenBits.bounds.top ; |
599 | } | |
e9576ca5 SC |
600 | } |
601 | ||
5fde6fcc GD |
602 | void wxDisplaySizeMM(int *width, int *height) |
603 | { | |
5b028d57 SC |
604 | wxDisplaySize(width, height); |
605 | // on mac 72 is fixed (at least now ;-) | |
606 | float cvPt2Mm = 25.4 / 72; | |
e8ca7105 | 607 | |
5be55d56 | 608 | if (width != NULL) { |
e8ca7105 GD |
609 | *width = int( *width * cvPt2Mm ); |
610 | } | |
5be55d56 | 611 | if (height != NULL) { |
e8ca7105 GD |
612 | *height = int( *height * cvPt2Mm ); |
613 | } | |
5fde6fcc GD |
614 | } |
615 | ||
ec5d7799 RD |
616 | void wxClientDisplayRect(int *x, int *y, int *width, int *height) |
617 | { | |
ee658398 SC |
618 | Rect r ; |
619 | GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ; | |
620 | if ( x ) | |
621 | *x = r.left ; | |
622 | if ( y ) | |
623 | *y = r.top ; | |
624 | if ( width ) | |
625 | *width = r.right - r.left ; | |
626 | if ( height ) | |
627 | *height = r.bottom - r.top ; | |
ec5d7799 RD |
628 | } |
629 | ||
57591e0e JS |
630 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) |
631 | { | |
632 | return wxGenericFindWindowAtPoint(pt); | |
633 | } | |
5dbb17e2 | 634 | |
b6ed2b86 VZ |
635 | #endif // wxUSE_GUI |
636 | ||
637 | #if wxUSE_BASE | |
638 | ||
5dbb17e2 SC |
639 | wxString wxGetOsDescription() |
640 | { | |
6e73695c GD |
641 | #ifdef WXWIN_OS_DESCRIPTION |
642 | // use configure generated description if available | |
5f3f0f17 | 643 | return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")")); |
6e73695c | 644 | #else |
427ff662 | 645 | return wxT("MacOS") ; //TODO:define further |
6e73695c GD |
646 | #endif |
647 | } | |
648 | ||
b6ed2b86 VZ |
649 | #ifndef __DARWIN__ |
650 | wxChar *wxGetUserHome (const wxString& user) | |
651 | { | |
652 | // TODO | |
653 | return NULL; | |
654 | } | |
655 | ||
656 | bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree) | |
657 | { | |
658 | if ( path.empty() ) | |
9d8aca48 | 659 | return false; |
b6ed2b86 VZ |
660 | |
661 | wxString p = path ; | |
71111c40 | 662 | if (p[0u] == ':' ) { |
b6ed2b86 VZ |
663 | p = wxGetCwd() + p ; |
664 | } | |
665 | ||
666 | int pos = p.Find(':') ; | |
667 | if ( pos != wxNOT_FOUND ) { | |
668 | p = p.Mid(1,pos) ; | |
669 | } | |
670 | ||
671 | p = p + wxT(":") ; | |
672 | ||
a2b77260 | 673 | OSErr err = noErr ; |
9d8aca48 | 674 | |
a2b77260 SC |
675 | FSRef fsRef ; |
676 | err = wxMacPathToFSRef( p , &fsRef ) ; | |
677 | if ( noErr == err ) | |
678 | { | |
679 | FSVolumeRefNum vRefNum ; | |
680 | err = FSGetVRefNum( &fsRef , &vRefNum ) ; | |
681 | if ( noErr == err ) | |
682 | { | |
683 | UInt64 freeBytes , totalBytes ; | |
684 | err = FSGetVInfo( vRefNum , NULL , &freeBytes , &totalBytes ) ; | |
685 | if ( noErr == err ) | |
686 | { | |
9d8aca48 | 687 | if ( pTotal ) |
a2b77260 SC |
688 | *pTotal = wxLongLong( totalBytes ) ; |
689 | if ( pFree ) | |
690 | *pFree = wxLongLong( freeBytes ) ; | |
691 | } | |
692 | } | |
b6ed2b86 | 693 | } |
9d8aca48 | 694 | |
b6ed2b86 VZ |
695 | return err == noErr ; |
696 | } | |
697 | #endif // !__DARWIN__ | |
698 | ||
3d963f81 SC |
699 | //--------------------------------------------------------------------------- |
700 | // wxMac Specific utility functions | |
701 | //--------------------------------------------------------------------------- | |
702 | ||
5be55d56 | 703 | void wxMacStringToPascal( const wxString&from , StringPtr to ) |
427ff662 | 704 | { |
939fba6c | 705 | wxCharBuffer buf = from.mb_str( wxConvLocal ) ; |
427ff662 SC |
706 | int len = strlen(buf) ; |
707 | ||
708 | if ( len > 255 ) | |
709 | len = 255 ; | |
710 | to[0] = len ; | |
711 | memcpy( (char*) &to[1] , buf , len ) ; | |
712 | } | |
713 | ||
5be55d56 | 714 | wxString wxMacMakeStringFromPascal( ConstStringPtr from ) |
427ff662 | 715 | { |
939fba6c | 716 | return wxString( (char*) &from[1] , wxConvLocal , from[0] ) ; |
427ff662 SC |
717 | } |
718 | ||
e50d5284 | 719 | |
73280e05 SC |
720 | // ---------------------------------------------------------------------------- |
721 | // Common Event Support | |
722 | // ---------------------------------------------------------------------------- | |
723 | ||
d13ea1bd | 724 | |
73280e05 SC |
725 | extern ProcessSerialNumber gAppProcess ; |
726 | ||
727 | void wxMacWakeUp() | |
728 | { | |
729 | ProcessSerialNumber psn ; | |
730 | Boolean isSame ; | |
731 | psn.highLongOfPSN = 0 ; | |
732 | psn.lowLongOfPSN = kCurrentProcess ; | |
733 | SameProcess( &gAppProcess , &psn , &isSame ) ; | |
734 | if ( isSame ) | |
735 | { | |
736 | #if TARGET_CARBON | |
8dfef0c2 SC |
737 | static wxMacCarbonEvent s_wakeupEvent ; |
738 | OSStatus err = noErr ; | |
739 | if ( !s_wakeupEvent.IsValid() ) | |
d6c69b17 | 740 | { |
8dfef0c2 SC |
741 | err = s_wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(), |
742 | kEventAttributeNone ) ; | |
d6c69b17 | 743 | } |
8dfef0c2 | 744 | if ( err == noErr ) |
73280e05 | 745 | { |
8dfef0c2 | 746 | if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent ) ) |
9d8aca48 | 747 | return ; |
8dfef0c2 | 748 | s_wakeupEvent.SetTime(0) ; |
d6c69b17 | 749 | err = PostEventToQueue(GetMainEventQueue(), s_wakeupEvent, |
73280e05 | 750 | kEventPriorityHigh); |
8dfef0c2 | 751 | } |
73280e05 SC |
752 | #else |
753 | PostEvent( nullEvent , 0 ) ; | |
754 | #endif | |
755 | } | |
756 | else | |
757 | { | |
758 | WakeUpProcess( &gAppProcess ) ; | |
759 | } | |
760 | } | |
761 | ||
d13ea1bd RD |
762 | #endif // wxUSE_BASE |
763 | ||
764 | #if wxUSE_GUI | |
765 | ||
766 | ||
facd6764 SC |
767 | // ---------------------------------------------------------------------------- |
768 | // Carbon Event Support | |
769 | // ---------------------------------------------------------------------------- | |
770 | ||
771 | ||
772 | OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) | |
773 | { | |
9d8aca48 | 774 | return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ) ; |
facd6764 SC |
775 | } |
776 | ||
21fd5529 | 777 | OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData) |
facd6764 | 778 | { |
9d8aca48 | 779 | return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ) ; |
facd6764 SC |
780 | } |
781 | ||
86d8b744 SC |
782 | // ---------------------------------------------------------------------------- |
783 | // Control Access Support | |
784 | // ---------------------------------------------------------------------------- | |
785 | ||
5ca0d812 SC |
786 | void wxMacControl::Dispose() |
787 | { | |
788 | ::DisposeControl( m_controlRef ) ; | |
789 | m_controlRef = NULL ; | |
790 | } | |
791 | ||
9d8aca48 | 792 | void wxMacControl::SetReference( SInt32 data ) |
5ca0d812 SC |
793 | { |
794 | SetControlReference( m_controlRef , data ) ; | |
795 | } | |
796 | ||
29d91661 | 797 | OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const |
86d8b744 | 798 | { |
9d8aca48 | 799 | return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ) ; |
86d8b744 SC |
800 | } |
801 | ||
29d91661 | 802 | OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const |
86d8b744 | 803 | { |
9d8aca48 | 804 | return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ) ; |
86d8b744 SC |
805 | } |
806 | ||
807 | OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData) | |
808 | { | |
9d8aca48 | 809 | return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData ) ; |
86d8b744 SC |
810 | } |
811 | ||
9d8aca48 | 812 | OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions ) |
21fd5529 | 813 | { |
e996f509 | 814 | #if TARGET_API_MAC_OSX |
9d8aca48 WS |
815 | return SendEventToEventTargetWithOptions( event, |
816 | HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions ); | |
e996f509 | 817 | #else |
9d8aca48 | 818 | #pragma unused(inOptions) |
e996f509 SC |
819 | return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) ) ; |
820 | #endif | |
21fd5529 SC |
821 | } |
822 | ||
9d8aca48 | 823 | OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions ) |
21fd5529 SC |
824 | { |
825 | wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess ) ; | |
826 | event.SetParameter<HICommand>(kEventParamDirectObject,command) ; | |
9d8aca48 | 827 | return SendEvent( event , inOptions ) ; |
21fd5529 SC |
828 | } |
829 | ||
9d8aca48 | 830 | OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions ) |
21fd5529 SC |
831 | { |
832 | HICommand command ; | |
833 | memset( &command, 0 , sizeof(command) ) ; | |
834 | command.commandID = commandID ; | |
835 | return SendHICommand( command , inOptions ) ; | |
836 | } | |
837 | ||
9d8aca48 | 838 | void wxMacControl::Flash( ControlPartCode part , UInt32 ticks ) |
21fd5529 SC |
839 | { |
840 | HiliteControl( m_controlRef , part ) ; | |
841 | unsigned long finalTicks ; | |
842 | Delay( ticks , &finalTicks ) ; | |
843 | HiliteControl( m_controlRef , kControlNoPart ) ; | |
844 | } | |
845 | ||
7f7b52b4 | 846 | SInt32 wxMacControl::GetValue() const |
9d8aca48 WS |
847 | { |
848 | return ::GetControl32BitValue( m_controlRef ) ; | |
7f7b52b4 SC |
849 | } |
850 | ||
851 | SInt32 wxMacControl::GetMaximum() const | |
9d8aca48 WS |
852 | { |
853 | return ::GetControl32BitMaximum( m_controlRef ) ; | |
7f7b52b4 SC |
854 | } |
855 | ||
856 | SInt32 wxMacControl::GetMinimum() const | |
9d8aca48 WS |
857 | { |
858 | return ::GetControl32BitMinimum( m_controlRef ) ; | |
7f7b52b4 SC |
859 | } |
860 | ||
9d8aca48 WS |
861 | void wxMacControl::SetValue( SInt32 v ) |
862 | { | |
863 | ::SetControl32BitValue( m_controlRef , v ) ; | |
7f7b52b4 SC |
864 | } |
865 | ||
9d8aca48 WS |
866 | void wxMacControl::SetMinimum( SInt32 v ) |
867 | { | |
868 | ::SetControl32BitMinimum( m_controlRef , v ) ; | |
7f7b52b4 SC |
869 | } |
870 | ||
9d8aca48 WS |
871 | void wxMacControl::SetMaximum( SInt32 v ) |
872 | { | |
7f7b52b4 SC |
873 | ::SetControl32BitMaximum( m_controlRef , v ) ; |
874 | } | |
875 | ||
876 | void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) | |
877 | { | |
878 | ::SetControl32BitMinimum( m_controlRef , minimum ) ; | |
9d8aca48 | 879 | ::SetControl32BitMaximum( m_controlRef , maximum ) ; |
7f7b52b4 SC |
880 | ::SetControl32BitValue( m_controlRef , value ) ; |
881 | } | |
882 | ||
9d8aca48 | 883 | OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart ) |
5ca0d812 | 884 | { |
9d8aca48 | 885 | return SetKeyboardFocus( GetControlOwner( m_controlRef ) , |
5ca0d812 SC |
886 | m_controlRef , focusPart ) ; |
887 | } | |
888 | ||
9d8aca48 | 889 | bool wxMacControl::HasFocus() const |
5ca0d812 SC |
890 | { |
891 | ControlRef control ; | |
892 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; | |
893 | return control == m_controlRef ; | |
894 | } | |
895 | ||
9d8aca48 | 896 | bool wxMacControl::NeedsFocusRect() const |
5ca0d812 SC |
897 | { |
898 | return false ; | |
899 | } | |
900 | ||
9d8aca48 | 901 | void wxMacControl::VisibilityChanged(bool shown) |
29d91661 SC |
902 | { |
903 | } | |
904 | ||
9d8aca48 | 905 | void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) |
29d91661 SC |
906 | { |
907 | m_font = font ; | |
9d8aca48 WS |
908 | ControlFontStyleRec fontStyle; |
909 | if ( font.MacGetThemeFontID() != kThemeCurrentPortFont ) | |
910 | { | |
911 | switch( font.MacGetThemeFontID() ) | |
912 | { | |
913 | case kThemeSmallSystemFont : fontStyle.font = kControlFontSmallSystemFont ; break ; | |
914 | case 109 /*mini font */ : fontStyle.font = -5 ; break ; | |
915 | case kThemeSystemFont : fontStyle.font = kControlFontBigSystemFont ; break ; | |
916 | default : fontStyle.font = kControlFontBigSystemFont ; break ; | |
917 | } | |
918 | fontStyle.flags = kControlUseFontMask ; | |
919 | } | |
920 | else | |
921 | { | |
922 | fontStyle.font = font.MacGetFontNum() ; | |
923 | fontStyle.style = font.MacGetFontStyle() ; | |
924 | fontStyle.size = font.MacGetFontSize() ; | |
925 | fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask ; | |
926 | } | |
29d91661 SC |
927 | |
928 | fontStyle.just = teJustLeft ; | |
929 | fontStyle.flags |= kControlUseJustMask ; | |
930 | if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL ) | |
931 | fontStyle.just = teJustCenter ; | |
932 | else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT ) | |
933 | fontStyle.just = teJustRight ; | |
934 | ||
9d8aca48 | 935 | |
29d91661 SC |
936 | // we only should do this in case of a non-standard color, as otherwise 'disabled' controls |
937 | // won't get grayed out by the system anymore | |
9d8aca48 | 938 | |
29d91661 SC |
939 | if ( foreground != *wxBLACK ) |
940 | { | |
941 | fontStyle.foreColor = MAC_WXCOLORREF(foreground.GetPixel() ) ; | |
942 | fontStyle.flags |= kControlUseForeColorMask ; | |
943 | } | |
9d8aca48 WS |
944 | |
945 | ::SetControlFontStyle( m_controlRef , &fontStyle ); | |
29d91661 SC |
946 | } |
947 | ||
9d8aca48 | 948 | void wxMacControl::SetBackground( const wxBrush &WXUNUSED(brush) ) |
7ea087b7 | 949 | { |
9d8aca48 | 950 | // TODO |
7ea087b7 SC |
951 | // setting up a color proc is not recommended anymore |
952 | } | |
953 | ||
7f7b52b4 SC |
954 | void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum ) |
955 | { | |
956 | ::SetControl32BitMinimum( m_controlRef , minimum ) ; | |
9d8aca48 | 957 | ::SetControl32BitMaximum( m_controlRef , maximum ) ; |
7f7b52b4 SC |
958 | } |
959 | ||
9d8aca48 | 960 | short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ) |
5ca0d812 SC |
961 | { |
962 | return HandleControlKey( m_controlRef , keyCode , charCode , modifiers ) ; | |
963 | } | |
964 | ||
965 | void wxMacControl::SetActionProc( ControlActionUPP actionProc ) | |
966 | { | |
967 | SetControlAction( m_controlRef , actionProc ) ; | |
968 | } | |
969 | ||
970 | void wxMacControl::SetViewSize( SInt32 viewSize ) | |
971 | { | |
972 | SetControlViewSize(m_controlRef , viewSize ) ; | |
973 | } | |
974 | ||
975 | SInt32 wxMacControl::GetViewSize() const | |
976 | { | |
977 | return GetControlViewSize( m_controlRef ) ; | |
978 | } | |
979 | ||
9d8aca48 | 980 | bool wxMacControl::IsVisible() const |
5ca0d812 SC |
981 | { |
982 | return IsControlVisible( m_controlRef ) ; | |
983 | } | |
984 | ||
9d8aca48 | 985 | void wxMacControl::SetVisibility( bool visible , bool redraw ) |
5ca0d812 SC |
986 | { |
987 | SetControlVisibility( m_controlRef , visible , redraw ) ; | |
988 | } | |
989 | ||
9d8aca48 | 990 | bool wxMacControl::IsEnabled() const |
5ca0d812 SC |
991 | { |
992 | #if TARGET_API_MAC_OSX | |
993 | return IsControlEnabled( m_controlRef ) ; | |
994 | #else | |
995 | return IsControlActive( m_controlRef ) ; | |
996 | #endif | |
997 | } | |
998 | ||
9d8aca48 | 999 | bool wxMacControl::IsActive() const |
5ca0d812 SC |
1000 | { |
1001 | return IsControlActive( m_controlRef ) ; | |
1002 | } | |
1003 | ||
9d8aca48 | 1004 | void wxMacControl::Enable( bool enable ) |
5ca0d812 SC |
1005 | { |
1006 | #if TARGET_API_MAC_OSX | |
1007 | if ( enable ) | |
1008 | EnableControl( m_controlRef ) ; | |
1009 | else | |
1010 | DisableControl( m_controlRef ) ; | |
1011 | #else | |
1012 | if ( enable ) | |
1013 | ActivateControl( m_controlRef ) ; | |
1014 | else | |
1015 | DeactivateControl( m_controlRef ) ; | |
1016 | #endif | |
1017 | } | |
1018 | ||
9d8aca48 | 1019 | void wxMacControl::SetDrawingEnabled( bool enable ) |
5ca0d812 SC |
1020 | { |
1021 | #if TARGET_API_MAC_OSX | |
1022 | HIViewSetDrawingEnabled( m_controlRef , enable ) ; | |
1023 | #endif | |
1024 | } | |
1025 | ||
9d8aca48 | 1026 | bool wxMacControl::GetNeedsDisplay() const |
5ca0d812 SC |
1027 | { |
1028 | #if TARGET_API_MAC_OSX | |
1029 | return HIViewGetNeedsDisplay( m_controlRef ) ; | |
1030 | #else | |
1031 | return false ; | |
1032 | #endif | |
1033 | } | |
1034 | ||
9d8aca48 | 1035 | void wxMacControl::SetNeedsDisplay( bool needsDisplay , RgnHandle where ) |
5ca0d812 SC |
1036 | { |
1037 | #if TARGET_API_MAC_OSX | |
1038 | if ( where != NULL ) | |
1039 | HIViewSetNeedsDisplayInRegion( m_controlRef , where , needsDisplay ) ; | |
1040 | else | |
1041 | HIViewSetNeedsDisplay( m_controlRef , needsDisplay ) ; | |
1042 | #endif | |
1043 | } | |
1044 | ||
9d8aca48 | 1045 | void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to ) |
5ca0d812 SC |
1046 | { |
1047 | #if TARGET_API_MAC_OSX | |
1048 | HIPoint hiPoint ; | |
1049 | hiPoint.x = pt->x ; | |
1050 | hiPoint.y = pt->y ; | |
1051 | HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef ) ; | |
6ea4a266 VZ |
1052 | pt->x = (int)hiPoint.x ; |
1053 | pt->y = (int)hiPoint.y ; | |
5ca0d812 SC |
1054 | #endif |
1055 | } | |
1056 | ||
9d8aca48 | 1057 | void wxMacControl::SetRect( Rect *r ) |
5ca0d812 SC |
1058 | { |
1059 | #if TARGET_API_MAC_OSX | |
9d8aca48 WS |
1060 | //A HIRect is actually a CGRect on OSX - which consists of two structures - |
1061 | //CGPoint and CGSize, which have two floats each | |
af4fc79b | 1062 | HIRect hir = { { r->left , r->top }, { r->right - r->left , r->bottom - r->top } } ; |
5ca0d812 SC |
1063 | HIViewSetFrame ( m_controlRef , &hir ) ; |
1064 | #else | |
1065 | SetControlBounds( m_controlRef , r ) ; | |
1066 | #endif | |
1067 | ||
1068 | } | |
1069 | ||
9d8aca48 | 1070 | void wxMacControl::GetRect( Rect *r ) |
5ca0d812 SC |
1071 | { |
1072 | GetControlBounds( m_controlRef , r ) ; | |
1073 | } | |
1074 | ||
9d8aca48 | 1075 | void wxMacControl::GetRectInWindowCoords( Rect *r ) |
5ca0d812 SC |
1076 | { |
1077 | UMAGetControlBoundsInWindowCoords( m_controlRef , r ) ; | |
1078 | } | |
1079 | ||
9d8aca48 | 1080 | void wxMacControl::GetBestRect( Rect *r ) |
5ca0d812 | 1081 | { |
5ca0d812 SC |
1082 | short baselineoffset ; |
1083 | GetBestControlRect( m_controlRef , r , &baselineoffset ) ; | |
1084 | } | |
1085 | ||
9d8aca48 | 1086 | void wxMacControl::SetTitle( const wxString &title ) |
5ca0d812 | 1087 | { |
10a59880 RD |
1088 | wxFontEncoding encoding; |
1089 | ||
1090 | if ( m_font.Ok() ) | |
1091 | encoding = m_font.GetEncoding(); | |
1092 | else | |
1093 | encoding = wxFont::GetDefaultEncoding(); | |
9d8aca48 | 1094 | |
10a59880 | 1095 | UMASetControlTitle( m_controlRef , title , encoding ) ; |
5ca0d812 SC |
1096 | } |
1097 | ||
1098 | void wxMacControl::GetFeatures( UInt32 * features ) | |
1099 | { | |
1100 | GetControlFeatures( m_controlRef , features ) ; | |
1101 | } | |
1102 | ||
9d8aca48 | 1103 | OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region ) |
5ca0d812 SC |
1104 | { |
1105 | return GetControlRegion( m_controlRef , partCode , region ) ; | |
1106 | } | |
1107 | ||
9d8aca48 | 1108 | OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other ) |
5ca0d812 SC |
1109 | { |
1110 | #if TARGET_API_MAC_OSX | |
9d8aca48 | 1111 | return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow, |
5ca0d812 SC |
1112 | (other != NULL) ? other->m_controlRef : NULL) ; |
1113 | #else | |
1114 | return 0 ; | |
1115 | #endif | |
1116 | } | |
1117 | ||
1118 | ||
1119 | #if TARGET_API_MAC_OSX | |
1120 | // SetNeedsDisplay would not invalidate the children | |
1121 | static void InvalidateControlAndChildren( HIViewRef control ) | |
1122 | { | |
1123 | HIViewSetNeedsDisplay( control , true ) ; | |
1124 | UInt16 childrenCount = 0 ; | |
9d8aca48 | 1125 | OSStatus err = CountSubControls( control , &childrenCount ) ; |
5ca0d812 SC |
1126 | if ( err == errControlIsNotEmbedder ) |
1127 | return ; | |
1128 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; | |
1129 | ||
1130 | for ( UInt16 i = childrenCount ; i >=1 ; --i ) | |
1131 | { | |
1132 | HIViewRef child ; | |
1133 | err = GetIndexedSubControl( control , i , & child ) ; | |
1134 | if ( err == errControlIsNotEmbedder ) | |
1135 | return ; | |
1136 | InvalidateControlAndChildren( child ) ; | |
1137 | } | |
1138 | } | |
1139 | #endif | |
1140 | ||
9d8aca48 | 1141 | void wxMacControl::InvalidateWithChildren() |
5ca0d812 SC |
1142 | { |
1143 | #if TARGET_API_MAC_OSX | |
1144 | InvalidateControlAndChildren( m_controlRef ) ; | |
1145 | #endif | |
1146 | } | |
1147 | ||
9d8aca48 | 1148 | void wxMacControl::ScrollRect( const wxRect &r , int dx , int dy ) |
5ca0d812 SC |
1149 | { |
1150 | #if TARGET_API_MAC_OSX | |
1151 | HIRect scrollarea = CGRectMake( r.x , r.y , r.width , r.height) ; | |
1152 | HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy ) ; | |
1153 | #endif | |
1154 | } | |
1155 | ||
1156 | ||
1157 | // SetNeedsDisplay would not invalidate the children | |
1158 | ||
1159 | // | |
1160 | // Databrowser | |
1161 | // | |
1162 | ||
9d8aca48 | 1163 | OSStatus wxMacControl::SetSelectionFlags( DataBrowserSelectionFlags options ) |
5ca0d812 SC |
1164 | { |
1165 | return SetDataBrowserSelectionFlags( m_controlRef , options ) ; | |
1166 | } | |
1167 | ||
1168 | OSStatus wxMacControl::AddListViewColumn( DataBrowserListViewColumnDesc *columnDesc, | |
9d8aca48 | 1169 | DataBrowserTableViewColumnIndex position ) |
5ca0d812 SC |
1170 | { |
1171 | return AddDataBrowserListViewColumn( m_controlRef , columnDesc, position ) ; | |
1172 | } | |
1173 | ||
1174 | OSStatus wxMacControl::AutoSizeListViewColumns() | |
1175 | { | |
1176 | return AutoSizeDataBrowserListViewColumns(m_controlRef) ; | |
1177 | } | |
1178 | ||
9d8aca48 | 1179 | OSStatus wxMacControl::SetHasScrollBars( bool horiz , bool vert ) |
5ca0d812 SC |
1180 | { |
1181 | return SetDataBrowserHasScrollBars( m_controlRef , horiz , vert ) ; | |
1182 | } | |
1183 | ||
1184 | OSStatus wxMacControl::SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) | |
1185 | { | |
1186 | return SetDataBrowserTableViewHiliteStyle( m_controlRef , hiliteStyle ) ; | |
1187 | } | |
1188 | ||
9d8aca48 | 1189 | OSStatus wxMacControl::SetListViewHeaderBtnHeight(UInt16 height) |
5ca0d812 SC |
1190 | { |
1191 | return SetDataBrowserListViewHeaderBtnHeight( m_controlRef ,height ) ; | |
1192 | } | |
1193 | ||
9d8aca48 | 1194 | OSStatus wxMacControl::SetCallbacks(const DataBrowserCallbacks * callbacks) |
5ca0d812 SC |
1195 | { |
1196 | return SetDataBrowserCallbacks( m_controlRef , callbacks ) ; | |
1197 | } | |
1198 | ||
1199 | OSStatus wxMacControl::UpdateItems( DataBrowserItemID container, UInt32 numItems, | |
9d8aca48 | 1200 | const DataBrowserItemID* items, |
5ca0d812 | 1201 | DataBrowserPropertyID preSortProperty, |
9d8aca48 | 1202 | DataBrowserPropertyID propertyID ) |
5ca0d812 SC |
1203 | { |
1204 | return UpdateDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty, propertyID ) ; | |
1205 | } | |
1206 | ||
9d8aca48 | 1207 | bool wxMacControl::IsItemSelected( DataBrowserItemID item ) |
5ca0d812 SC |
1208 | { |
1209 | return IsDataBrowserItemSelected( m_controlRef , item ) ; | |
1210 | } | |
1211 | ||
1212 | OSStatus wxMacControl::AddItems( DataBrowserItemID container, UInt32 numItems, | |
9d8aca48 WS |
1213 | const DataBrowserItemID* items, |
1214 | DataBrowserPropertyID preSortProperty ) | |
5ca0d812 SC |
1215 | { |
1216 | return AddDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty ) ; | |
1217 | } | |
1218 | ||
1219 | OSStatus wxMacControl::RemoveItems( DataBrowserItemID container, UInt32 numItems, | |
9d8aca48 WS |
1220 | const DataBrowserItemID* items, |
1221 | DataBrowserPropertyID preSortProperty ) | |
5ca0d812 SC |
1222 | { |
1223 | return RemoveDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty ) ; | |
1224 | } | |
1225 | ||
1226 | OSStatus wxMacControl::RevealItem( DataBrowserItemID item, | |
1227 | DataBrowserPropertyID propertyID, | |
9d8aca48 | 1228 | DataBrowserRevealOptions options ) |
5ca0d812 SC |
1229 | { |
1230 | return RevealDataBrowserItem( m_controlRef , item , propertyID , options ) ; | |
1231 | } | |
1232 | ||
1233 | OSStatus wxMacControl::SetSelectedItems(UInt32 numItems, | |
1234 | const DataBrowserItemID * items, | |
9d8aca48 | 1235 | DataBrowserSetOption operation ) |
5ca0d812 SC |
1236 | { |
1237 | return SetDataBrowserSelectedItems( m_controlRef , numItems , items, operation ) ; | |
1238 | } | |
1239 | ||
9d8aca48 | 1240 | OSStatus wxMacControl::GetSelectionAnchor( DataBrowserItemID * first, DataBrowserItemID * last ) |
c020f421 SC |
1241 | { |
1242 | return GetDataBrowserSelectionAnchor( m_controlRef , first , last ) ; | |
1243 | } | |
1244 | ||
5ca0d812 SC |
1245 | // |
1246 | // Tab Control | |
1247 | // | |
9d8aca48 WS |
1248 | |
1249 | OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable ) | |
5ca0d812 SC |
1250 | { |
1251 | return ::SetTabEnabled( m_controlRef , tabNo , enable ) ; | |
1252 | } | |
9d8aca48 | 1253 | |
b6ed2b86 VZ |
1254 | #endif // wxUSE_GUI |
1255 |