]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: utils.cpp | |
3 | // Purpose: Various utilities | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | // Note: this is done in utilscmn.cpp now. | |
14 | // #pragma implementation "utils.h" | |
15 | #endif | |
16 | ||
17 | #include "wx/setup.h" | |
18 | #include "wx/utils.h" | |
19 | #include "wx/app.h" | |
20 | #include "wx/apptrait.h" | |
21 | ||
22 | #if wxUSE_GUI | |
23 | #include "wx/mac/uma.h" | |
24 | #include "wx/font.h" | |
25 | #else | |
26 | #include "wx/intl.h" | |
27 | #endif | |
28 | ||
29 | #include <ctype.h> | |
30 | ||
31 | #include <stdio.h> | |
32 | #include <stdlib.h> | |
33 | #include <string.h> | |
34 | #include <stdarg.h> | |
35 | ||
36 | #include "MoreFilesX.h" | |
37 | ||
38 | #ifndef __DARWIN__ | |
39 | #include <Threads.h> | |
40 | #include <Sound.h> | |
41 | #endif | |
42 | ||
43 | #if TARGET_API_MAC_OSX | |
44 | #include <CoreServices/CoreServices.h> | |
45 | #else | |
46 | #include <DriverServices.h> | |
47 | #include <Multiprocessing.h> | |
48 | #endif | |
49 | ||
50 | #include <ATSUnicode.h> | |
51 | #include <TextCommon.h> | |
52 | #include <TextEncodingConverter.h> | |
53 | ||
54 | #include "wx/mac/private.h" // includes mac headers | |
55 | ||
56 | #if defined(__MWERKS__) && wxUSE_UNICODE | |
57 | #include <wtime.h> | |
58 | #endif | |
59 | ||
60 | // --------------------------------------------------------------------------- | |
61 | // code used in both base and GUI compilation | |
62 | // --------------------------------------------------------------------------- | |
63 | ||
64 | // our OS version is the same in non GUI and GUI cases | |
65 | static int DoGetOSVersion(int *majorVsn, int *minorVsn) | |
66 | { | |
67 | long theSystem ; | |
68 | ||
69 | // are there x-platform conventions ? | |
70 | ||
71 | Gestalt(gestaltSystemVersion, &theSystem) ; | |
72 | if (minorVsn != NULL) { | |
73 | *minorVsn = (theSystem & 0xFF ) ; | |
74 | } | |
75 | if (majorVsn != NULL) { | |
76 | *majorVsn = (theSystem >> 8 ) ; | |
77 | } | |
78 | #ifdef __DARWIN__ | |
79 | return wxMAC_DARWIN; | |
80 | #else | |
81 | return wxMAC; | |
82 | #endif | |
83 | } | |
84 | ||
85 | ||
86 | #if wxUSE_BASE | |
87 | ||
88 | // ---------------------------------------------------------------------------- | |
89 | // debugging support | |
90 | // ---------------------------------------------------------------------------- | |
91 | ||
92 | #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400) | |
93 | ||
94 | // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds... | |
95 | ||
96 | #ifndef __MetroNubUtils__ | |
97 | #include "MetroNubUtils.h" | |
98 | #endif | |
99 | ||
100 | #ifndef __GESTALT__ | |
101 | #include <Gestalt.h> | |
102 | #endif | |
103 | ||
104 | #if TARGET_API_MAC_CARBON | |
105 | ||
106 | #include <CodeFragments.h> | |
107 | ||
108 | extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...); | |
109 | ||
110 | ProcPtr gCallUniversalProc_Proc = NULL; | |
111 | ||
112 | #endif | |
113 | ||
114 | static MetroNubUserEntryBlock* gMetroNubEntry = NULL; | |
115 | ||
116 | static long fRunOnce = false; | |
117 | ||
118 | /* --------------------------------------------------------------------------- | |
119 | IsMetroNubInstalled | |
120 | --------------------------------------------------------------------------- */ | |
121 | ||
122 | Boolean IsMetroNubInstalled() | |
123 | { | |
124 | if (!fRunOnce) | |
125 | { | |
126 | long result, value; | |
127 | ||
128 | fRunOnce = true; | |
129 | gMetroNubEntry = NULL; | |
130 | ||
131 | if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000) | |
132 | { | |
133 | /* look for MetroNub's Gestalt selector */ | |
134 | if (Gestalt(kMetroNubUserSignature, &result) == noErr) | |
135 | { | |
136 | ||
137 | #if TARGET_API_MAC_CARBON | |
138 | if (gCallUniversalProc_Proc == NULL) | |
139 | { | |
140 | CFragConnectionID connectionID; | |
141 | Ptr mainAddress; | |
142 | Str255 errorString; | |
143 | ProcPtr symbolAddress; | |
144 | OSErr err; | |
145 | CFragSymbolClass symbolClass; | |
146 | ||
147 | symbolAddress = NULL; | |
148 | err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag, | |
149 | &connectionID, &mainAddress, errorString); | |
150 | ||
151 | if (err != noErr) | |
152 | { | |
153 | gCallUniversalProc_Proc = NULL; | |
154 | goto end; | |
155 | } | |
156 | ||
157 | err = FindSymbol(connectionID, "\pCallUniversalProc", | |
158 | (Ptr *) &gCallUniversalProc_Proc, &symbolClass); | |
159 | ||
160 | if (err != noErr) | |
161 | { | |
162 | gCallUniversalProc_Proc = NULL; | |
163 | goto end; | |
164 | } | |
165 | } | |
166 | #endif | |
167 | ||
168 | { | |
169 | MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result; | |
170 | ||
171 | /* make sure the version of the API is compatible */ | |
172 | if (block->apiLowVersion <= kMetroNubUserAPIVersion && | |
173 | kMetroNubUserAPIVersion <= block->apiHiVersion) | |
174 | gMetroNubEntry = block; /* success! */ | |
175 | } | |
176 | ||
177 | } | |
178 | } | |
179 | } | |
180 | ||
181 | end: | |
182 | ||
183 | #if TARGET_API_MAC_CARBON | |
184 | return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL); | |
185 | #else | |
186 | return (gMetroNubEntry != NULL); | |
187 | #endif | |
188 | } | |
189 | ||
190 | /* --------------------------------------------------------------------------- | |
191 | IsMWDebuggerRunning [v1 API] | |
192 | --------------------------------------------------------------------------- */ | |
193 | ||
194 | Boolean IsMWDebuggerRunning() | |
195 | { | |
196 | if (IsMetroNubInstalled()) | |
197 | return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning); | |
198 | else | |
199 | return false; | |
200 | } | |
201 | ||
202 | /* --------------------------------------------------------------------------- | |
203 | AmIBeingMWDebugged [v1 API] | |
204 | --------------------------------------------------------------------------- */ | |
205 | ||
206 | Boolean AmIBeingMWDebugged() | |
207 | { | |
208 | if (IsMetroNubInstalled()) | |
209 | return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged); | |
210 | else | |
211 | return false; | |
212 | } | |
213 | ||
214 | extern bool WXDLLEXPORT wxIsDebuggerRunning() | |
215 | { | |
216 | return IsMWDebuggerRunning() && AmIBeingMWDebugged(); | |
217 | } | |
218 | ||
219 | #else | |
220 | ||
221 | extern bool WXDLLEXPORT wxIsDebuggerRunning() | |
222 | { | |
223 | return false; | |
224 | } | |
225 | ||
226 | #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400) | |
227 | ||
228 | ||
229 | #ifndef __DARWIN__ | |
230 | // defined in unix/utilsunx.cpp for Mac OS X | |
231 | ||
232 | // get full hostname (with domain name if possible) | |
233 | bool wxGetFullHostName(wxChar *buf, int maxSize) | |
234 | { | |
235 | return wxGetHostName(buf, maxSize); | |
236 | } | |
237 | ||
238 | // Get hostname only (without domain name) | |
239 | bool wxGetHostName(wxChar *buf, int maxSize) | |
240 | { | |
241 | // Gets Chooser name of user by examining a System resource. | |
242 | ||
243 | const short kComputerNameID = -16413; | |
244 | ||
245 | short oldResFile = CurResFile() ; | |
246 | UseResFile(0); | |
247 | StringHandle chooserName = (StringHandle)::GetString(kComputerNameID); | |
248 | UseResFile(oldResFile); | |
249 | ||
250 | if (chooserName && *chooserName) | |
251 | { | |
252 | HLock( (Handle) chooserName ) ; | |
253 | wxString name = wxMacMakeStringFromPascal( *chooserName ) ; | |
254 | HUnlock( (Handle) chooserName ) ; | |
255 | ReleaseResource( (Handle) chooserName ) ; | |
256 | wxStrncpy( buf , name , maxSize - 1 ) ; | |
257 | } | |
258 | else | |
259 | buf[0] = 0 ; | |
260 | ||
261 | return TRUE; | |
262 | } | |
263 | ||
264 | // Get user ID e.g. jacs | |
265 | bool wxGetUserId(wxChar *buf, int maxSize) | |
266 | { | |
267 | return wxGetUserName( buf , maxSize ) ; | |
268 | } | |
269 | ||
270 | const wxChar* wxGetHomeDir(wxString *pstr) | |
271 | { | |
272 | *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ) ; | |
273 | return pstr->c_str() ; | |
274 | } | |
275 | ||
276 | // Get user name e.g. Stefan Csomor | |
277 | bool wxGetUserName(wxChar *buf, int maxSize) | |
278 | { | |
279 | // Gets Chooser name of user by examining a System resource. | |
280 | ||
281 | const short kChooserNameID = -16096; | |
282 | ||
283 | short oldResFile = CurResFile() ; | |
284 | UseResFile(0); | |
285 | StringHandle chooserName = (StringHandle)::GetString(kChooserNameID); | |
286 | UseResFile(oldResFile); | |
287 | ||
288 | if (chooserName && *chooserName) | |
289 | { | |
290 | HLock( (Handle) chooserName ) ; | |
291 | wxString name = wxMacMakeStringFromPascal( *chooserName ) ; | |
292 | HUnlock( (Handle) chooserName ) ; | |
293 | ReleaseResource( (Handle) chooserName ) ; | |
294 | wxStrncpy( buf , name , maxSize - 1 ) ; | |
295 | } | |
296 | else | |
297 | buf[0] = 0 ; | |
298 | ||
299 | return TRUE; | |
300 | } | |
301 | ||
302 | int wxKill(long pid, wxSignal sig , wxKillError *rc ) | |
303 | { | |
304 | // TODO | |
305 | return 0; | |
306 | } | |
307 | ||
308 | WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value) | |
309 | { | |
310 | // TODO : under classic there is no environement support, under X yes | |
311 | return false ; | |
312 | } | |
313 | ||
314 | // set the env var name to the given value, return TRUE on success | |
315 | WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value) | |
316 | { | |
317 | // TODO : under classic there is no environement support, under X yes | |
318 | return false ; | |
319 | } | |
320 | ||
321 | // | |
322 | // Execute a program in an Interactive Shell | |
323 | // | |
324 | bool wxShell(const wxString& command) | |
325 | { | |
326 | // TODO | |
327 | return FALSE; | |
328 | } | |
329 | ||
330 | // Shutdown or reboot the PC | |
331 | bool wxShutdown(wxShutdownFlags wFlags) | |
332 | { | |
333 | // TODO | |
334 | return FALSE; | |
335 | } | |
336 | ||
337 | // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) | |
338 | long wxGetFreeMemory() | |
339 | { | |
340 | return FreeMem() ; | |
341 | } | |
342 | ||
343 | #ifndef __DARWIN__ | |
344 | ||
345 | void wxMicroSleep(unsigned long microseconds) | |
346 | { | |
347 | AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime()); | |
348 | MPDelayUntil( & wakeup); | |
349 | } | |
350 | ||
351 | void wxMilliSleep(unsigned long milliseconds) | |
352 | { | |
353 | AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime()); | |
354 | MPDelayUntil( & wakeup); | |
355 | } | |
356 | ||
357 | void wxSleep(int nSecs) | |
358 | { | |
359 | wxMilliSleep(1000*nSecs); | |
360 | } | |
361 | ||
362 | #endif | |
363 | ||
364 | // Consume all events until no more left | |
365 | void wxFlushEvents() | |
366 | { | |
367 | } | |
368 | ||
369 | #endif // !__DARWIN__ | |
370 | ||
371 | // Emit a beeeeeep | |
372 | void wxBell() | |
373 | { | |
374 | SysBeep(30); | |
375 | } | |
376 | ||
377 | wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo() | |
378 | { | |
379 | static wxToolkitInfo info; | |
380 | info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); | |
381 | info.name = _T("wxBase"); | |
382 | return info; | |
383 | } | |
384 | ||
385 | #endif // wxUSE_BASE | |
386 | ||
387 | #if wxUSE_GUI | |
388 | ||
389 | wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() | |
390 | { | |
391 | static wxToolkitInfo info; | |
392 | info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); | |
393 | info.shortName = _T("mac"); | |
394 | info.name = _T("wxMac"); | |
395 | #ifdef __WXUNIVERSAL__ | |
396 | info.shortName << _T("univ"); | |
397 | info.name << _T("/wxUniversal"); | |
398 | #endif | |
399 | return info; | |
400 | } | |
401 | ||
402 | // Reading and writing resources (eg WIN.INI, .Xdefaults) | |
403 | #if wxUSE_RESOURCES | |
404 | bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file) | |
405 | { | |
406 | // TODO | |
407 | return FALSE; | |
408 | } | |
409 | ||
410 | bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file) | |
411 | { | |
412 | wxString buf; | |
413 | buf.Printf(wxT("%.4f"), value); | |
414 | ||
415 | return wxWriteResource(section, entry, buf, file); | |
416 | } | |
417 | ||
418 | bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file) | |
419 | { | |
420 | wxString buf; | |
421 | buf.Printf(wxT("%ld"), value); | |
422 | ||
423 | return wxWriteResource(section, entry, buf, file); | |
424 | } | |
425 | ||
426 | bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file) | |
427 | { | |
428 | wxString buf; | |
429 | buf.Printf(wxT("%d"), value); | |
430 | ||
431 | return wxWriteResource(section, entry, buf, file); | |
432 | } | |
433 | ||
434 | bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file) | |
435 | { | |
436 | // TODO | |
437 | return FALSE; | |
438 | } | |
439 | ||
440 | bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file) | |
441 | { | |
442 | char *s = NULL; | |
443 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
444 | if (succ) | |
445 | { | |
446 | *value = (float)strtod(s, NULL); | |
447 | delete[] s; | |
448 | return TRUE; | |
449 | } | |
450 | else return FALSE; | |
451 | } | |
452 | ||
453 | bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file) | |
454 | { | |
455 | char *s = NULL; | |
456 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
457 | if (succ) | |
458 | { | |
459 | *value = strtol(s, NULL, 10); | |
460 | delete[] s; | |
461 | return TRUE; | |
462 | } | |
463 | else return FALSE; | |
464 | } | |
465 | ||
466 | bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file) | |
467 | { | |
468 | char *s = NULL; | |
469 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
470 | if (succ) | |
471 | { | |
472 | *value = (int)strtol(s, NULL, 10); | |
473 | delete[] s; | |
474 | return TRUE; | |
475 | } | |
476 | else return FALSE; | |
477 | } | |
478 | #endif // wxUSE_RESOURCES | |
479 | ||
480 | int gs_wxBusyCursorCount = 0; | |
481 | extern wxCursor gMacCurrentCursor ; | |
482 | wxCursor gMacStoredActiveCursor ; | |
483 | ||
484 | // Set the cursor to the busy cursor for all windows | |
485 | void wxBeginBusyCursor(wxCursor *cursor) | |
486 | { | |
487 | if (gs_wxBusyCursorCount++ == 0) | |
488 | { | |
489 | gMacStoredActiveCursor = gMacCurrentCursor ; | |
490 | cursor->MacInstall() ; | |
491 | } | |
492 | //else: nothing to do, already set | |
493 | } | |
494 | ||
495 | // Restore cursor to normal | |
496 | void wxEndBusyCursor() | |
497 | { | |
498 | wxCHECK_RET( gs_wxBusyCursorCount > 0, | |
499 | wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") ); | |
500 | ||
501 | if (--gs_wxBusyCursorCount == 0) | |
502 | { | |
503 | gMacStoredActiveCursor.MacInstall() ; | |
504 | gMacStoredActiveCursor = wxNullCursor ; | |
505 | } | |
506 | } | |
507 | ||
508 | // TRUE if we're between the above two calls | |
509 | bool wxIsBusy() | |
510 | { | |
511 | return (gs_wxBusyCursorCount > 0); | |
512 | } | |
513 | ||
514 | #endif // wxUSE_GUI | |
515 | ||
516 | #if wxUSE_BASE | |
517 | ||
518 | wxString wxMacFindFolder( short vol, | |
519 | OSType folderType, | |
520 | Boolean createFolder) | |
521 | { | |
522 | FSRef fsRef ; | |
523 | wxString strDir ; | |
524 | ||
525 | if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr) | |
526 | strDir = wxMacFSRefToPath( &fsRef ) + wxFILE_SEP_PATH ; | |
527 | ||
528 | return strDir ; | |
529 | } | |
530 | ||
531 | #endif // wxUSE_BASE | |
532 | ||
533 | #if wxUSE_GUI | |
534 | ||
535 | // Check whether this window wants to process messages, e.g. Stop button | |
536 | // in long calculations. | |
537 | bool wxCheckForInterrupt(wxWindow *wnd) | |
538 | { | |
539 | // TODO | |
540 | return FALSE; | |
541 | } | |
542 | ||
543 | void wxGetMousePosition( int* x, int* y ) | |
544 | { | |
545 | Point pt ; | |
546 | ||
547 | GetMouse( &pt ) ; | |
548 | LocalToGlobal( &pt ) ; | |
549 | *x = pt.h ; | |
550 | *y = pt.v ; | |
551 | }; | |
552 | ||
553 | // Return TRUE if we have a colour display | |
554 | bool wxColourDisplay() | |
555 | { | |
556 | return TRUE; | |
557 | } | |
558 | ||
559 | // Returns depth of screen | |
560 | int wxDisplayDepth() | |
561 | { | |
562 | Rect globRect ; | |
563 | SetRect(&globRect, -32760, -32760, 32760, 32760); | |
564 | GDHandle theMaxDevice; | |
565 | ||
566 | int theDepth = 8; | |
567 | theMaxDevice = GetMaxDevice(&globRect); | |
568 | if (theMaxDevice != nil) | |
569 | theDepth = (**(**theMaxDevice).gdPMap).pixelSize; | |
570 | ||
571 | return theDepth ; | |
572 | } | |
573 | ||
574 | // Get size of display | |
575 | void wxDisplaySize(int *width, int *height) | |
576 | { | |
577 | BitMap screenBits; | |
578 | GetQDGlobalsScreenBits( &screenBits ); | |
579 | ||
580 | if (width != NULL) { | |
581 | *width = screenBits.bounds.right - screenBits.bounds.left ; | |
582 | } | |
583 | if (height != NULL) { | |
584 | *height = screenBits.bounds.bottom - screenBits.bounds.top ; | |
585 | } | |
586 | } | |
587 | ||
588 | void wxDisplaySizeMM(int *width, int *height) | |
589 | { | |
590 | wxDisplaySize(width, height); | |
591 | // on mac 72 is fixed (at least now ;-) | |
592 | float cvPt2Mm = 25.4 / 72; | |
593 | ||
594 | if (width != NULL) { | |
595 | *width = int( *width * cvPt2Mm ); | |
596 | } | |
597 | if (height != NULL) { | |
598 | *height = int( *height * cvPt2Mm ); | |
599 | } | |
600 | } | |
601 | ||
602 | void wxClientDisplayRect(int *x, int *y, int *width, int *height) | |
603 | { | |
604 | Rect r ; | |
605 | GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ; | |
606 | if ( x ) | |
607 | *x = r.left ; | |
608 | if ( y ) | |
609 | *y = r.top ; | |
610 | if ( width ) | |
611 | *width = r.right - r.left ; | |
612 | if ( height ) | |
613 | *height = r.bottom - r.top ; | |
614 | } | |
615 | ||
616 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) | |
617 | { | |
618 | return wxGenericFindWindowAtPoint(pt); | |
619 | } | |
620 | ||
621 | #endif // wxUSE_GUI | |
622 | ||
623 | #if wxUSE_BASE | |
624 | ||
625 | wxString wxGetOsDescription() | |
626 | { | |
627 | #ifdef WXWIN_OS_DESCRIPTION | |
628 | // use configure generated description if available | |
629 | return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")")); | |
630 | #else | |
631 | return wxT("MacOS") ; //TODO:define further | |
632 | #endif | |
633 | } | |
634 | ||
635 | #ifndef __DARWIN__ | |
636 | wxChar *wxGetUserHome (const wxString& user) | |
637 | { | |
638 | // TODO | |
639 | return NULL; | |
640 | } | |
641 | ||
642 | bool wxGetDiskSpace(const wxString& path, wxLongLong *pTotal, wxLongLong *pFree) | |
643 | { | |
644 | if ( path.empty() ) | |
645 | return FALSE; | |
646 | ||
647 | wxString p = path ; | |
648 | if (p[0u] == ':' ) { | |
649 | p = wxGetCwd() + p ; | |
650 | } | |
651 | ||
652 | int pos = p.Find(':') ; | |
653 | if ( pos != wxNOT_FOUND ) { | |
654 | p = p.Mid(1,pos) ; | |
655 | } | |
656 | ||
657 | p = p + wxT(":") ; | |
658 | ||
659 | OSErr err = noErr ; | |
660 | ||
661 | FSRef fsRef ; | |
662 | err = wxMacPathToFSRef( p , &fsRef ) ; | |
663 | if ( noErr == err ) | |
664 | { | |
665 | FSVolumeRefNum vRefNum ; | |
666 | err = FSGetVRefNum( &fsRef , &vRefNum ) ; | |
667 | if ( noErr == err ) | |
668 | { | |
669 | UInt64 freeBytes , totalBytes ; | |
670 | err = FSGetVInfo( vRefNum , NULL , &freeBytes , &totalBytes ) ; | |
671 | if ( noErr == err ) | |
672 | { | |
673 | if ( pTotal ) | |
674 | *pTotal = wxLongLong( totalBytes ) ; | |
675 | if ( pFree ) | |
676 | *pFree = wxLongLong( freeBytes ) ; | |
677 | } | |
678 | } | |
679 | } | |
680 | ||
681 | return err == noErr ; | |
682 | } | |
683 | #endif // !__DARWIN__ | |
684 | ||
685 | //--------------------------------------------------------------------------- | |
686 | // wxMac Specific utility functions | |
687 | //--------------------------------------------------------------------------- | |
688 | ||
689 | void wxMacStringToPascal( const wxString&from , StringPtr to ) | |
690 | { | |
691 | wxCharBuffer buf = from.mb_str( wxConvLocal ) ; | |
692 | int len = strlen(buf) ; | |
693 | ||
694 | if ( len > 255 ) | |
695 | len = 255 ; | |
696 | to[0] = len ; | |
697 | memcpy( (char*) &to[1] , buf , len ) ; | |
698 | } | |
699 | ||
700 | wxString wxMacMakeStringFromPascal( ConstStringPtr from ) | |
701 | { | |
702 | return wxString( (char*) &from[1] , wxConvLocal , from[0] ) ; | |
703 | } | |
704 | ||
705 | ||
706 | wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding) | |
707 | { | |
708 | TextEncodingBase enc = 0 ; | |
709 | if ( encoding == wxFONTENCODING_DEFAULT ) | |
710 | { | |
711 | #if wxUSE_GUI | |
712 | encoding = wxFont::GetDefaultEncoding() ; | |
713 | #else | |
714 | encoding = wxLocale::GetSystemEncoding() ; | |
715 | #endif | |
716 | } | |
717 | ||
718 | switch( encoding) | |
719 | { | |
720 | case wxFONTENCODING_ISO8859_1 : | |
721 | enc = kTextEncodingISOLatin1 ; | |
722 | break ; | |
723 | case wxFONTENCODING_ISO8859_2 : | |
724 | enc = kTextEncodingISOLatin2; | |
725 | break ; | |
726 | case wxFONTENCODING_ISO8859_3 : | |
727 | enc = kTextEncodingISOLatin3 ; | |
728 | break ; | |
729 | case wxFONTENCODING_ISO8859_4 : | |
730 | enc = kTextEncodingISOLatin4; | |
731 | break ; | |
732 | case wxFONTENCODING_ISO8859_5 : | |
733 | enc = kTextEncodingISOLatinCyrillic; | |
734 | break ; | |
735 | case wxFONTENCODING_ISO8859_6 : | |
736 | enc = kTextEncodingISOLatinArabic; | |
737 | break ; | |
738 | case wxFONTENCODING_ISO8859_7 : | |
739 | enc = kTextEncodingISOLatinGreek; | |
740 | break ; | |
741 | case wxFONTENCODING_ISO8859_8 : | |
742 | enc = kTextEncodingISOLatinHebrew; | |
743 | break ; | |
744 | case wxFONTENCODING_ISO8859_9 : | |
745 | enc = kTextEncodingISOLatin5; | |
746 | break ; | |
747 | case wxFONTENCODING_ISO8859_10 : | |
748 | enc = kTextEncodingISOLatin6; | |
749 | break ; | |
750 | case wxFONTENCODING_ISO8859_13 : | |
751 | enc = kTextEncodingISOLatin7; | |
752 | break ; | |
753 | case wxFONTENCODING_ISO8859_14 : | |
754 | enc = kTextEncodingISOLatin8; | |
755 | break ; | |
756 | case wxFONTENCODING_ISO8859_15 : | |
757 | enc = kTextEncodingISOLatin9; | |
758 | break ; | |
759 | ||
760 | case wxFONTENCODING_KOI8 : | |
761 | enc = kTextEncodingKOI8_R; | |
762 | break ; | |
763 | case wxFONTENCODING_ALTERNATIVE : // MS-DOS CP866 | |
764 | enc = kTextEncodingDOSRussian; | |
765 | break ; | |
766 | /* | |
767 | case wxFONTENCODING_BULGARIAN : | |
768 | enc = ; | |
769 | break ; | |
770 | */ | |
771 | case wxFONTENCODING_CP437 : | |
772 | enc =kTextEncodingDOSLatinUS ; | |
773 | break ; | |
774 | case wxFONTENCODING_CP850 : | |
775 | enc = kTextEncodingDOSLatin1; | |
776 | break ; | |
777 | case wxFONTENCODING_CP852 : | |
778 | enc = kTextEncodingDOSLatin2; | |
779 | break ; | |
780 | case wxFONTENCODING_CP855 : | |
781 | enc = kTextEncodingDOSCyrillic; | |
782 | break ; | |
783 | case wxFONTENCODING_CP866 : | |
784 | enc =kTextEncodingDOSRussian ; | |
785 | break ; | |
786 | case wxFONTENCODING_CP874 : | |
787 | enc = kTextEncodingDOSThai; | |
788 | break ; | |
789 | case wxFONTENCODING_CP932 : | |
790 | enc = kTextEncodingDOSJapanese; | |
791 | break ; | |
792 | case wxFONTENCODING_CP936 : | |
793 | enc =kTextEncodingDOSChineseSimplif ; | |
794 | break ; | |
795 | case wxFONTENCODING_CP949 : | |
796 | enc = kTextEncodingDOSKorean; | |
797 | break ; | |
798 | case wxFONTENCODING_CP950 : | |
799 | enc = kTextEncodingDOSChineseTrad; | |
800 | break ; | |
801 | ||
802 | case wxFONTENCODING_CP1250 : | |
803 | enc = kTextEncodingWindowsLatin2; | |
804 | break ; | |
805 | case wxFONTENCODING_CP1251 : | |
806 | enc =kTextEncodingWindowsCyrillic ; | |
807 | break ; | |
808 | case wxFONTENCODING_CP1252 : | |
809 | enc =kTextEncodingWindowsLatin1 ; | |
810 | break ; | |
811 | case wxFONTENCODING_CP1253 : | |
812 | enc = kTextEncodingWindowsGreek; | |
813 | break ; | |
814 | case wxFONTENCODING_CP1254 : | |
815 | enc = kTextEncodingWindowsLatin5; | |
816 | break ; | |
817 | case wxFONTENCODING_CP1255 : | |
818 | enc =kTextEncodingWindowsHebrew ; | |
819 | break ; | |
820 | case wxFONTENCODING_CP1256 : | |
821 | enc =kTextEncodingWindowsArabic ; | |
822 | break ; | |
823 | case wxFONTENCODING_CP1257 : | |
824 | enc = kTextEncodingWindowsBalticRim; | |
825 | break ; | |
826 | ||
827 | case wxFONTENCODING_UTF7 : | |
828 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ; | |
829 | break ; | |
830 | case wxFONTENCODING_UTF8 : | |
831 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ; | |
832 | break ; | |
833 | case wxFONTENCODING_EUC_JP : | |
834 | enc = kTextEncodingEUC_JP; | |
835 | break ; | |
836 | case wxFONTENCODING_UTF16BE : | |
837 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ; | |
838 | break ; | |
839 | case wxFONTENCODING_UTF16LE : | |
840 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ; | |
841 | break ; | |
842 | case wxFONTENCODING_UTF32BE : | |
843 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ; | |
844 | break ; | |
845 | case wxFONTENCODING_UTF32LE : | |
846 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ; | |
847 | break ; | |
848 | ||
849 | case wxFONTENCODING_MACROMAN : | |
850 | enc = kTextEncodingMacRoman ; | |
851 | break ; | |
852 | case wxFONTENCODING_MACJAPANESE : | |
853 | enc = kTextEncodingMacJapanese ; | |
854 | break ; | |
855 | case wxFONTENCODING_MACCHINESETRAD : | |
856 | enc = kTextEncodingMacChineseTrad ; | |
857 | break ; | |
858 | case wxFONTENCODING_MACKOREAN : | |
859 | enc = kTextEncodingMacKorean ; | |
860 | break ; | |
861 | case wxFONTENCODING_MACARABIC : | |
862 | enc = kTextEncodingMacArabic ; | |
863 | break ; | |
864 | case wxFONTENCODING_MACHEBREW : | |
865 | enc = kTextEncodingMacHebrew ; | |
866 | break ; | |
867 | case wxFONTENCODING_MACGREEK : | |
868 | enc = kTextEncodingMacGreek ; | |
869 | break ; | |
870 | case wxFONTENCODING_MACCYRILLIC : | |
871 | enc = kTextEncodingMacCyrillic ; | |
872 | break ; | |
873 | case wxFONTENCODING_MACDEVANAGARI : | |
874 | enc = kTextEncodingMacDevanagari ; | |
875 | break ; | |
876 | case wxFONTENCODING_MACGURMUKHI : | |
877 | enc = kTextEncodingMacGurmukhi ; | |
878 | break ; | |
879 | case wxFONTENCODING_MACGUJARATI : | |
880 | enc = kTextEncodingMacGujarati ; | |
881 | break ; | |
882 | case wxFONTENCODING_MACORIYA : | |
883 | enc = kTextEncodingMacOriya ; | |
884 | break ; | |
885 | case wxFONTENCODING_MACBENGALI : | |
886 | enc = kTextEncodingMacBengali ; | |
887 | break ; | |
888 | case wxFONTENCODING_MACTAMIL : | |
889 | enc = kTextEncodingMacTamil ; | |
890 | break ; | |
891 | case wxFONTENCODING_MACTELUGU : | |
892 | enc = kTextEncodingMacTelugu ; | |
893 | break ; | |
894 | case wxFONTENCODING_MACKANNADA : | |
895 | enc = kTextEncodingMacKannada ; | |
896 | break ; | |
897 | case wxFONTENCODING_MACMALAJALAM : | |
898 | enc = kTextEncodingMacMalayalam ; | |
899 | break ; | |
900 | case wxFONTENCODING_MACSINHALESE : | |
901 | enc = kTextEncodingMacSinhalese ; | |
902 | break ; | |
903 | case wxFONTENCODING_MACBURMESE : | |
904 | enc = kTextEncodingMacBurmese ; | |
905 | break ; | |
906 | case wxFONTENCODING_MACKHMER : | |
907 | enc = kTextEncodingMacKhmer ; | |
908 | break ; | |
909 | case wxFONTENCODING_MACTHAI : | |
910 | enc = kTextEncodingMacThai ; | |
911 | break ; | |
912 | case wxFONTENCODING_MACLAOTIAN : | |
913 | enc = kTextEncodingMacLaotian ; | |
914 | break ; | |
915 | case wxFONTENCODING_MACGEORGIAN : | |
916 | enc = kTextEncodingMacGeorgian ; | |
917 | break ; | |
918 | case wxFONTENCODING_MACARMENIAN : | |
919 | enc = kTextEncodingMacArmenian ; | |
920 | break ; | |
921 | case wxFONTENCODING_MACCHINESESIMP : | |
922 | enc = kTextEncodingMacChineseSimp ; | |
923 | break ; | |
924 | case wxFONTENCODING_MACTIBETAN : | |
925 | enc = kTextEncodingMacTibetan ; | |
926 | break ; | |
927 | case wxFONTENCODING_MACMONGOLIAN : | |
928 | enc = kTextEncodingMacMongolian ; | |
929 | break ; | |
930 | case wxFONTENCODING_MACETHIOPIC : | |
931 | enc = kTextEncodingMacEthiopic ; | |
932 | break ; | |
933 | case wxFONTENCODING_MACCENTRALEUR : | |
934 | enc = kTextEncodingMacCentralEurRoman ; | |
935 | break ; | |
936 | case wxFONTENCODING_MACVIATNAMESE : | |
937 | enc = kTextEncodingMacVietnamese ; | |
938 | break ; | |
939 | case wxFONTENCODING_MACARABICEXT : | |
940 | enc = kTextEncodingMacExtArabic ; | |
941 | break ; | |
942 | case wxFONTENCODING_MACSYMBOL : | |
943 | enc = kTextEncodingMacSymbol ; | |
944 | break ; | |
945 | case wxFONTENCODING_MACDINGBATS : | |
946 | enc = kTextEncodingMacDingbats ; | |
947 | break ; | |
948 | case wxFONTENCODING_MACTURKISH : | |
949 | enc = kTextEncodingMacTurkish ; | |
950 | break ; | |
951 | case wxFONTENCODING_MACCROATIAN : | |
952 | enc = kTextEncodingMacCroatian ; | |
953 | break ; | |
954 | case wxFONTENCODING_MACICELANDIC : | |
955 | enc = kTextEncodingMacIcelandic ; | |
956 | break ; | |
957 | case wxFONTENCODING_MACROMANIAN : | |
958 | enc = kTextEncodingMacRomanian ; | |
959 | break ; | |
960 | case wxFONTENCODING_MACCELTIC : | |
961 | enc = kTextEncodingMacCeltic ; | |
962 | break ; | |
963 | case wxFONTENCODING_MACGAELIC : | |
964 | enc = kTextEncodingMacGaelic ; | |
965 | break ; | |
966 | case wxFONTENCODING_MACKEYBOARD : | |
967 | enc = kTextEncodingMacKeyboardGlyphs ; | |
968 | break ; | |
969 | default : | |
970 | // to make gcc happy | |
971 | break ; | |
972 | } ; | |
973 | return enc ; | |
974 | } | |
975 | ||
976 | wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding) | |
977 | { | |
978 | wxFontEncoding enc = wxFONTENCODING_DEFAULT ; | |
979 | ||
980 | switch( encoding) | |
981 | { | |
982 | case kTextEncodingISOLatin1 : | |
983 | enc = wxFONTENCODING_ISO8859_1 ; | |
984 | break ; | |
985 | case kTextEncodingISOLatin2 : | |
986 | enc = wxFONTENCODING_ISO8859_2; | |
987 | break ; | |
988 | case kTextEncodingISOLatin3 : | |
989 | enc = wxFONTENCODING_ISO8859_3 ; | |
990 | break ; | |
991 | case kTextEncodingISOLatin4 : | |
992 | enc = wxFONTENCODING_ISO8859_4; | |
993 | break ; | |
994 | case kTextEncodingISOLatinCyrillic : | |
995 | enc = wxFONTENCODING_ISO8859_5; | |
996 | break ; | |
997 | case kTextEncodingISOLatinArabic : | |
998 | enc = wxFONTENCODING_ISO8859_6; | |
999 | break ; | |
1000 | case kTextEncodingISOLatinGreek : | |
1001 | enc = wxFONTENCODING_ISO8859_7; | |
1002 | break ; | |
1003 | case kTextEncodingISOLatinHebrew : | |
1004 | enc = wxFONTENCODING_ISO8859_8; | |
1005 | break ; | |
1006 | case kTextEncodingISOLatin5 : | |
1007 | enc = wxFONTENCODING_ISO8859_9; | |
1008 | break ; | |
1009 | case kTextEncodingISOLatin6 : | |
1010 | enc = wxFONTENCODING_ISO8859_10; | |
1011 | break ; | |
1012 | case kTextEncodingISOLatin7 : | |
1013 | enc = wxFONTENCODING_ISO8859_13; | |
1014 | break ; | |
1015 | case kTextEncodingISOLatin8 : | |
1016 | enc = wxFONTENCODING_ISO8859_14; | |
1017 | break ; | |
1018 | case kTextEncodingISOLatin9 : | |
1019 | enc =wxFONTENCODING_ISO8859_15 ; | |
1020 | break ; | |
1021 | ||
1022 | case kTextEncodingKOI8_R : | |
1023 | enc = wxFONTENCODING_KOI8; | |
1024 | break ; | |
1025 | /* | |
1026 | case : | |
1027 | enc = wxFONTENCODING_BULGARIAN; | |
1028 | break ; | |
1029 | */ | |
1030 | case kTextEncodingDOSLatinUS : | |
1031 | enc = wxFONTENCODING_CP437; | |
1032 | break ; | |
1033 | case kTextEncodingDOSLatin1 : | |
1034 | enc = wxFONTENCODING_CP850; | |
1035 | break ; | |
1036 | case kTextEncodingDOSLatin2 : | |
1037 | enc =wxFONTENCODING_CP852 ; | |
1038 | break ; | |
1039 | case kTextEncodingDOSCyrillic : | |
1040 | enc = wxFONTENCODING_CP855; | |
1041 | break ; | |
1042 | case kTextEncodingDOSRussian : | |
1043 | enc = wxFONTENCODING_CP866; | |
1044 | break ; | |
1045 | case kTextEncodingDOSThai : | |
1046 | enc =wxFONTENCODING_CP874 ; | |
1047 | break ; | |
1048 | case kTextEncodingDOSJapanese : | |
1049 | enc = wxFONTENCODING_CP932; | |
1050 | break ; | |
1051 | case kTextEncodingDOSChineseSimplif : | |
1052 | enc = wxFONTENCODING_CP936; | |
1053 | break ; | |
1054 | case kTextEncodingDOSKorean : | |
1055 | enc = wxFONTENCODING_CP949; | |
1056 | break ; | |
1057 | case kTextEncodingDOSChineseTrad : | |
1058 | enc = wxFONTENCODING_CP950; | |
1059 | break ; | |
1060 | ||
1061 | case kTextEncodingWindowsLatin2 : | |
1062 | enc = wxFONTENCODING_CP1250; | |
1063 | break ; | |
1064 | case kTextEncodingWindowsCyrillic : | |
1065 | enc = wxFONTENCODING_CP1251; | |
1066 | break ; | |
1067 | case kTextEncodingWindowsLatin1 : | |
1068 | enc = wxFONTENCODING_CP1252; | |
1069 | break ; | |
1070 | case kTextEncodingWindowsGreek : | |
1071 | enc = wxFONTENCODING_CP1253; | |
1072 | break ; | |
1073 | case kTextEncodingWindowsLatin5 : | |
1074 | enc = wxFONTENCODING_CP1254; | |
1075 | break ; | |
1076 | case kTextEncodingWindowsHebrew : | |
1077 | enc = wxFONTENCODING_CP1255; | |
1078 | break ; | |
1079 | case kTextEncodingWindowsArabic : | |
1080 | enc = wxFONTENCODING_CP1256; | |
1081 | break ; | |
1082 | case kTextEncodingWindowsBalticRim : | |
1083 | enc =wxFONTENCODING_CP1257 ; | |
1084 | break ; | |
1085 | case kTextEncodingEUC_JP : | |
1086 | enc = wxFONTENCODING_EUC_JP; | |
1087 | break ; | |
1088 | /* | |
1089 | case wxFONTENCODING_UTF7 : | |
1090 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ; | |
1091 | break ; | |
1092 | case wxFONTENCODING_UTF8 : | |
1093 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ; | |
1094 | break ; | |
1095 | case wxFONTENCODING_UTF16BE : | |
1096 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ; | |
1097 | break ; | |
1098 | case wxFONTENCODING_UTF16LE : | |
1099 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ; | |
1100 | break ; | |
1101 | case wxFONTENCODING_UTF32BE : | |
1102 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ; | |
1103 | break ; | |
1104 | case wxFONTENCODING_UTF32LE : | |
1105 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ; | |
1106 | break ; | |
1107 | */ | |
1108 | case kTextEncodingMacRoman : | |
1109 | enc = wxFONTENCODING_MACROMAN ; | |
1110 | break ; | |
1111 | case kTextEncodingMacJapanese : | |
1112 | enc = wxFONTENCODING_MACJAPANESE ; | |
1113 | break ; | |
1114 | case kTextEncodingMacChineseTrad : | |
1115 | enc = wxFONTENCODING_MACCHINESETRAD ; | |
1116 | break ; | |
1117 | case kTextEncodingMacKorean : | |
1118 | enc = wxFONTENCODING_MACKOREAN ; | |
1119 | break ; | |
1120 | case kTextEncodingMacArabic : | |
1121 | enc =wxFONTENCODING_MACARABIC ; | |
1122 | break ; | |
1123 | case kTextEncodingMacHebrew : | |
1124 | enc = wxFONTENCODING_MACHEBREW ; | |
1125 | break ; | |
1126 | case kTextEncodingMacGreek : | |
1127 | enc = wxFONTENCODING_MACGREEK ; | |
1128 | break ; | |
1129 | case kTextEncodingMacCyrillic : | |
1130 | enc = wxFONTENCODING_MACCYRILLIC ; | |
1131 | break ; | |
1132 | case kTextEncodingMacDevanagari : | |
1133 | enc = wxFONTENCODING_MACDEVANAGARI ; | |
1134 | break ; | |
1135 | case kTextEncodingMacGurmukhi : | |
1136 | enc = wxFONTENCODING_MACGURMUKHI ; | |
1137 | break ; | |
1138 | case kTextEncodingMacGujarati : | |
1139 | enc = wxFONTENCODING_MACGUJARATI ; | |
1140 | break ; | |
1141 | case kTextEncodingMacOriya : | |
1142 | enc =wxFONTENCODING_MACORIYA ; | |
1143 | break ; | |
1144 | case kTextEncodingMacBengali : | |
1145 | enc =wxFONTENCODING_MACBENGALI ; | |
1146 | break ; | |
1147 | case kTextEncodingMacTamil : | |
1148 | enc = wxFONTENCODING_MACTAMIL ; | |
1149 | break ; | |
1150 | case kTextEncodingMacTelugu : | |
1151 | enc = wxFONTENCODING_MACTELUGU ; | |
1152 | break ; | |
1153 | case kTextEncodingMacKannada : | |
1154 | enc = wxFONTENCODING_MACKANNADA ; | |
1155 | break ; | |
1156 | case kTextEncodingMacMalayalam : | |
1157 | enc = wxFONTENCODING_MACMALAJALAM ; | |
1158 | break ; | |
1159 | case kTextEncodingMacSinhalese : | |
1160 | enc = wxFONTENCODING_MACSINHALESE ; | |
1161 | break ; | |
1162 | case kTextEncodingMacBurmese : | |
1163 | enc = wxFONTENCODING_MACBURMESE ; | |
1164 | break ; | |
1165 | case kTextEncodingMacKhmer : | |
1166 | enc = wxFONTENCODING_MACKHMER ; | |
1167 | break ; | |
1168 | case kTextEncodingMacThai : | |
1169 | enc = wxFONTENCODING_MACTHAI ; | |
1170 | break ; | |
1171 | case kTextEncodingMacLaotian : | |
1172 | enc = wxFONTENCODING_MACLAOTIAN ; | |
1173 | break ; | |
1174 | case kTextEncodingMacGeorgian : | |
1175 | enc = wxFONTENCODING_MACGEORGIAN ; | |
1176 | break ; | |
1177 | case kTextEncodingMacArmenian : | |
1178 | enc = wxFONTENCODING_MACARMENIAN ; | |
1179 | break ; | |
1180 | case kTextEncodingMacChineseSimp : | |
1181 | enc = wxFONTENCODING_MACCHINESESIMP ; | |
1182 | break ; | |
1183 | case kTextEncodingMacTibetan : | |
1184 | enc = wxFONTENCODING_MACTIBETAN ; | |
1185 | break ; | |
1186 | case kTextEncodingMacMongolian : | |
1187 | enc = wxFONTENCODING_MACMONGOLIAN ; | |
1188 | break ; | |
1189 | case kTextEncodingMacEthiopic : | |
1190 | enc = wxFONTENCODING_MACETHIOPIC ; | |
1191 | break ; | |
1192 | case kTextEncodingMacCentralEurRoman: | |
1193 | enc = wxFONTENCODING_MACCENTRALEUR ; | |
1194 | break ; | |
1195 | case kTextEncodingMacVietnamese: | |
1196 | enc = wxFONTENCODING_MACVIATNAMESE ; | |
1197 | break ; | |
1198 | case kTextEncodingMacExtArabic : | |
1199 | enc = wxFONTENCODING_MACARABICEXT ; | |
1200 | break ; | |
1201 | case kTextEncodingMacSymbol : | |
1202 | enc = wxFONTENCODING_MACSYMBOL ; | |
1203 | break ; | |
1204 | case kTextEncodingMacDingbats : | |
1205 | enc = wxFONTENCODING_MACDINGBATS ; | |
1206 | break ; | |
1207 | case kTextEncodingMacTurkish : | |
1208 | enc = wxFONTENCODING_MACTURKISH ; | |
1209 | break ; | |
1210 | case kTextEncodingMacCroatian : | |
1211 | enc = wxFONTENCODING_MACCROATIAN ; | |
1212 | break ; | |
1213 | case kTextEncodingMacIcelandic : | |
1214 | enc = wxFONTENCODING_MACICELANDIC ; | |
1215 | break ; | |
1216 | case kTextEncodingMacRomanian : | |
1217 | enc = wxFONTENCODING_MACROMANIAN ; | |
1218 | break ; | |
1219 | case kTextEncodingMacCeltic : | |
1220 | enc = wxFONTENCODING_MACCELTIC ; | |
1221 | break ; | |
1222 | case kTextEncodingMacGaelic : | |
1223 | enc = wxFONTENCODING_MACGAELIC ; | |
1224 | break ; | |
1225 | case kTextEncodingMacKeyboardGlyphs : | |
1226 | enc = wxFONTENCODING_MACKEYBOARD ; | |
1227 | break ; | |
1228 | } ; | |
1229 | return enc ; | |
1230 | } | |
1231 | ||
1232 | ||
1233 | // | |
1234 | // CFStringRefs (Carbon only) | |
1235 | // | |
1236 | ||
1237 | #if TARGET_CARBON | |
1238 | ||
1239 | // converts this string into a carbon foundation string with optional pc 2 mac encoding | |
1240 | void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding ) | |
1241 | { | |
1242 | Release() ; | |
1243 | ||
1244 | wxString str = st ; | |
1245 | wxMacConvertNewlines13To10( &str ) ; | |
1246 | #if wxUSE_UNICODE | |
1247 | #if SIZEOF_WCHAR_T == 2 | |
1248 | m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault, | |
1249 | (UniChar*)str.wc_str() , str.Len() ); | |
1250 | #else | |
1251 | wxMBConvUTF16BE converter ; | |
1252 | size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ; | |
1253 | UniChar *unibuf = new UniChar[ unicharlen / sizeof(UniChar) + 1 ] ; | |
1254 | converter.WC2MB( (char*)unibuf , str.wc_str() , unicharlen ) ; | |
1255 | m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault , | |
1256 | unibuf , unicharlen / sizeof(UniChar) ) ; | |
1257 | delete[] unibuf ; | |
1258 | #endif | |
1259 | #else // not wxUSE_UNICODE | |
1260 | m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() , | |
1261 | wxMacGetSystemEncFromFontEnc( encoding ) ) ; | |
1262 | #endif | |
1263 | m_release = true ; | |
1264 | } | |
1265 | ||
1266 | wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding) | |
1267 | { | |
1268 | Size cflen = CFStringGetLength( m_cfs ) ; | |
1269 | size_t noChars ; | |
1270 | wxChar* buf = NULL ; | |
1271 | ||
1272 | #if wxUSE_UNICODE | |
1273 | #if SIZEOF_WCHAR_T == 2 | |
1274 | buf = new wxChar[ cflen + 1 ] ; | |
1275 | CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) buf ) ; | |
1276 | noChars = cflen ; | |
1277 | #else | |
1278 | UniChar* unibuf = new UniChar[ cflen + 1 ] ; | |
1279 | CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) unibuf ) ; | |
1280 | unibuf[cflen] = 0 ; | |
1281 | wxMBConvUTF16BE converter ; | |
1282 | noChars = converter.MB2WC( NULL , (const char*)unibuf , 0 ) ; | |
1283 | buf = new wxChar[ noChars + 1 ] ; | |
1284 | converter.MB2WC( buf , (const char*)unibuf , noChars ) ; | |
1285 | delete[] unibuf ; | |
1286 | #endif | |
1287 | #else | |
1288 | CFIndex cStrLen ; | |
1289 | CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) , | |
1290 | '?' , false , NULL , 0 , &cStrLen ) ; | |
1291 | buf = new wxChar[ cStrLen + 1 ] ; | |
1292 | CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) , | |
1293 | '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ; | |
1294 | noChars = cStrLen ; | |
1295 | #endif | |
1296 | ||
1297 | buf[noChars] = 0 ; | |
1298 | wxMacConvertNewlines10To13( buf ) ; | |
1299 | wxString result(buf) ; | |
1300 | delete[] buf ; | |
1301 | return result ; | |
1302 | } | |
1303 | ||
1304 | #endif //TARGET_CARBON | |
1305 | ||
1306 | void wxMacConvertNewlines13To10( char * data ) | |
1307 | { | |
1308 | char * buf = data ; | |
1309 | while( (buf=strchr(buf,0x0d)) != NULL ) | |
1310 | { | |
1311 | *buf = 0x0a ; | |
1312 | buf++ ; | |
1313 | } | |
1314 | } | |
1315 | ||
1316 | void wxMacConvertNewlines10To13( char * data ) | |
1317 | { | |
1318 | char * buf = data ; | |
1319 | while( (buf=strchr(buf,0x0a)) != NULL ) | |
1320 | { | |
1321 | *buf = 0x0d ; | |
1322 | buf++ ; | |
1323 | } | |
1324 | } | |
1325 | ||
1326 | void wxMacConvertNewlines13To10( wxString * data ) | |
1327 | { | |
1328 | size_t len = data->Length() ; | |
1329 | ||
1330 | if ( len == 0 || wxStrchr(data->c_str(),0x0d)==NULL) | |
1331 | return ; | |
1332 | ||
1333 | wxString temp(*data) ; | |
1334 | wxStringBuffer buf(*data,len ) ; | |
1335 | memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ; | |
1336 | ||
1337 | wxMacConvertNewlines13To10( buf ) ; | |
1338 | } | |
1339 | ||
1340 | void wxMacConvertNewlines10To13( wxString * data ) | |
1341 | { | |
1342 | size_t len = data->Length() ; | |
1343 | ||
1344 | if ( data->Length() == 0 || wxStrchr(data->c_str(),0x0a)==NULL) | |
1345 | return ; | |
1346 | ||
1347 | wxString temp(*data) ; | |
1348 | wxStringBuffer buf(*data,len ) ; | |
1349 | memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ; | |
1350 | wxMacConvertNewlines10To13( buf ) ; | |
1351 | } | |
1352 | ||
1353 | ||
1354 | #if wxUSE_UNICODE | |
1355 | void wxMacConvertNewlines13To10( wxChar * data ) | |
1356 | { | |
1357 | wxChar * buf = data ; | |
1358 | while( (buf=wxStrchr(buf,0x0d)) != NULL ) | |
1359 | { | |
1360 | *buf = 0x0a ; | |
1361 | buf++ ; | |
1362 | } | |
1363 | } | |
1364 | ||
1365 | void wxMacConvertNewlines10To13( wxChar * data ) | |
1366 | { | |
1367 | wxChar * buf = data ; | |
1368 | while( (buf=wxStrchr(buf,0x0a)) != NULL ) | |
1369 | { | |
1370 | *buf = 0x0d ; | |
1371 | buf++ ; | |
1372 | } | |
1373 | } | |
1374 | #endif | |
1375 | ||
1376 | // ---------------------------------------------------------------------------- | |
1377 | // Common Event Support | |
1378 | // ---------------------------------------------------------------------------- | |
1379 | ||
1380 | ||
1381 | extern ProcessSerialNumber gAppProcess ; | |
1382 | ||
1383 | void wxMacWakeUp() | |
1384 | { | |
1385 | ProcessSerialNumber psn ; | |
1386 | Boolean isSame ; | |
1387 | psn.highLongOfPSN = 0 ; | |
1388 | psn.lowLongOfPSN = kCurrentProcess ; | |
1389 | SameProcess( &gAppProcess , &psn , &isSame ) ; | |
1390 | if ( isSame ) | |
1391 | { | |
1392 | #if TARGET_CARBON | |
1393 | EventRef dummyEvent ; | |
1394 | OSStatus err = MacCreateEvent(nil, 'WXMC', 'WXMC', GetCurrentEventTime(), | |
1395 | kEventAttributeNone, &dummyEvent); | |
1396 | if (err == noErr) | |
1397 | { | |
1398 | err = PostEventToQueue(GetMainEventQueue(), dummyEvent, | |
1399 | kEventPriorityHigh); | |
1400 | } | |
1401 | #else | |
1402 | PostEvent( nullEvent , 0 ) ; | |
1403 | #endif | |
1404 | } | |
1405 | else | |
1406 | { | |
1407 | WakeUpProcess( &gAppProcess ) ; | |
1408 | } | |
1409 | } | |
1410 | ||
1411 | #endif // wxUSE_BASE | |
1412 | ||
1413 | #if wxUSE_GUI | |
1414 | ||
1415 | ||
1416 | // ---------------------------------------------------------------------------- | |
1417 | // Carbon Event Support | |
1418 | // ---------------------------------------------------------------------------- | |
1419 | ||
1420 | ||
1421 | OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) | |
1422 | { | |
1423 | return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ) ; | |
1424 | } | |
1425 | ||
1426 | OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData) | |
1427 | { | |
1428 | return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ) ; | |
1429 | } | |
1430 | ||
1431 | // ---------------------------------------------------------------------------- | |
1432 | // Control Access Support | |
1433 | // ---------------------------------------------------------------------------- | |
1434 | ||
1435 | void wxMacControl::Dispose() | |
1436 | { | |
1437 | ::DisposeControl( m_controlRef ) ; | |
1438 | m_controlRef = NULL ; | |
1439 | } | |
1440 | ||
1441 | void wxMacControl::SetReference( SInt32 data ) | |
1442 | { | |
1443 | SetControlReference( m_controlRef , data ) ; | |
1444 | } | |
1445 | ||
1446 | OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const | |
1447 | { | |
1448 | return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ) ; | |
1449 | } | |
1450 | ||
1451 | OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const | |
1452 | { | |
1453 | return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ) ; | |
1454 | } | |
1455 | ||
1456 | OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData) | |
1457 | { | |
1458 | return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData ) ; | |
1459 | } | |
1460 | ||
1461 | OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions ) | |
1462 | { | |
1463 | #if TARGET_API_MAC_OSX | |
1464 | return SendEventToEventTargetWithOptions( event, | |
1465 | HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions ); | |
1466 | #else | |
1467 | #pragma unused(inOptions) | |
1468 | return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) ) ; | |
1469 | #endif | |
1470 | } | |
1471 | ||
1472 | OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions ) | |
1473 | { | |
1474 | wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess ) ; | |
1475 | event.SetParameter<HICommand>(kEventParamDirectObject,command) ; | |
1476 | return SendEvent( event , inOptions ) ; | |
1477 | } | |
1478 | ||
1479 | OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions ) | |
1480 | { | |
1481 | HICommand command ; | |
1482 | memset( &command, 0 , sizeof(command) ) ; | |
1483 | command.commandID = commandID ; | |
1484 | return SendHICommand( command , inOptions ) ; | |
1485 | } | |
1486 | ||
1487 | void wxMacControl::Flash( ControlPartCode part , UInt32 ticks ) | |
1488 | { | |
1489 | HiliteControl( m_controlRef , part ) ; | |
1490 | unsigned long finalTicks ; | |
1491 | Delay( ticks , &finalTicks ) ; | |
1492 | HiliteControl( m_controlRef , kControlNoPart ) ; | |
1493 | } | |
1494 | ||
1495 | SInt32 wxMacControl::GetValue() const | |
1496 | { | |
1497 | return ::GetControl32BitValue( m_controlRef ) ; | |
1498 | } | |
1499 | ||
1500 | SInt32 wxMacControl::GetMaximum() const | |
1501 | { | |
1502 | return ::GetControl32BitMaximum( m_controlRef ) ; | |
1503 | } | |
1504 | ||
1505 | SInt32 wxMacControl::GetMinimum() const | |
1506 | { | |
1507 | return ::GetControl32BitMinimum( m_controlRef ) ; | |
1508 | } | |
1509 | ||
1510 | void wxMacControl::SetValue( SInt32 v ) | |
1511 | { | |
1512 | ::SetControl32BitValue( m_controlRef , v ) ; | |
1513 | } | |
1514 | ||
1515 | void wxMacControl::SetMinimum( SInt32 v ) | |
1516 | { | |
1517 | ::SetControl32BitMinimum( m_controlRef , v ) ; | |
1518 | } | |
1519 | ||
1520 | void wxMacControl::SetMaximum( SInt32 v ) | |
1521 | { | |
1522 | ::SetControl32BitMaximum( m_controlRef , v ) ; | |
1523 | } | |
1524 | ||
1525 | void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) | |
1526 | { | |
1527 | ::SetControl32BitMinimum( m_controlRef , minimum ) ; | |
1528 | ::SetControl32BitMaximum( m_controlRef , maximum ) ; | |
1529 | ::SetControl32BitValue( m_controlRef , value ) ; | |
1530 | } | |
1531 | ||
1532 | OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart ) | |
1533 | { | |
1534 | return SetKeyboardFocus( GetControlOwner( m_controlRef ) , | |
1535 | m_controlRef , focusPart ) ; | |
1536 | } | |
1537 | ||
1538 | bool wxMacControl::HasFocus() const | |
1539 | { | |
1540 | ControlRef control ; | |
1541 | GetKeyboardFocus( GetUserFocusWindow() , &control ) ; | |
1542 | return control == m_controlRef ; | |
1543 | } | |
1544 | ||
1545 | bool wxMacControl::NeedsFocusRect() const | |
1546 | { | |
1547 | return false ; | |
1548 | } | |
1549 | ||
1550 | void wxMacControl::VisibilityChanged(bool shown) | |
1551 | { | |
1552 | } | |
1553 | ||
1554 | void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) | |
1555 | { | |
1556 | m_font = font ; | |
1557 | ControlFontStyleRec fontStyle; | |
1558 | if ( font.MacGetThemeFontID() != kThemeCurrentPortFont ) | |
1559 | { | |
1560 | switch( font.MacGetThemeFontID() ) | |
1561 | { | |
1562 | case kThemeSmallSystemFont : fontStyle.font = kControlFontSmallSystemFont ; break ; | |
1563 | case 109 /*mini font */ : fontStyle.font = -5 ; break ; | |
1564 | case kThemeSystemFont : fontStyle.font = kControlFontBigSystemFont ; break ; | |
1565 | default : fontStyle.font = kControlFontBigSystemFont ; break ; | |
1566 | } | |
1567 | fontStyle.flags = kControlUseFontMask ; | |
1568 | } | |
1569 | else | |
1570 | { | |
1571 | fontStyle.font = font.MacGetFontNum() ; | |
1572 | fontStyle.style = font.MacGetFontStyle() ; | |
1573 | fontStyle.size = font.MacGetFontSize() ; | |
1574 | fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask ; | |
1575 | } | |
1576 | ||
1577 | fontStyle.just = teJustLeft ; | |
1578 | fontStyle.flags |= kControlUseJustMask ; | |
1579 | if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL ) | |
1580 | fontStyle.just = teJustCenter ; | |
1581 | else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT ) | |
1582 | fontStyle.just = teJustRight ; | |
1583 | ||
1584 | ||
1585 | // we only should do this in case of a non-standard color, as otherwise 'disabled' controls | |
1586 | // won't get grayed out by the system anymore | |
1587 | ||
1588 | if ( foreground != *wxBLACK ) | |
1589 | { | |
1590 | fontStyle.foreColor = MAC_WXCOLORREF(foreground.GetPixel() ) ; | |
1591 | fontStyle.flags |= kControlUseForeColorMask ; | |
1592 | } | |
1593 | ||
1594 | ::SetControlFontStyle( m_controlRef , &fontStyle ); | |
1595 | } | |
1596 | ||
1597 | void wxMacControl::SetBackground( const wxBrush &WXUNUSED(brush) ) | |
1598 | { | |
1599 | // TODO | |
1600 | // setting up a color proc is not recommended anymore | |
1601 | } | |
1602 | ||
1603 | void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum ) | |
1604 | { | |
1605 | ::SetControl32BitMinimum( m_controlRef , minimum ) ; | |
1606 | ::SetControl32BitMaximum( m_controlRef , maximum ) ; | |
1607 | } | |
1608 | ||
1609 | short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ) | |
1610 | { | |
1611 | return HandleControlKey( m_controlRef , keyCode , charCode , modifiers ) ; | |
1612 | } | |
1613 | ||
1614 | void wxMacControl::SetActionProc( ControlActionUPP actionProc ) | |
1615 | { | |
1616 | SetControlAction( m_controlRef , actionProc ) ; | |
1617 | } | |
1618 | ||
1619 | void wxMacControl::SetViewSize( SInt32 viewSize ) | |
1620 | { | |
1621 | SetControlViewSize(m_controlRef , viewSize ) ; | |
1622 | } | |
1623 | ||
1624 | SInt32 wxMacControl::GetViewSize() const | |
1625 | { | |
1626 | return GetControlViewSize( m_controlRef ) ; | |
1627 | } | |
1628 | ||
1629 | bool wxMacControl::IsVisible() const | |
1630 | { | |
1631 | return IsControlVisible( m_controlRef ) ; | |
1632 | } | |
1633 | ||
1634 | void wxMacControl::SetVisibility( bool visible , bool redraw ) | |
1635 | { | |
1636 | SetControlVisibility( m_controlRef , visible , redraw ) ; | |
1637 | } | |
1638 | ||
1639 | bool wxMacControl::IsEnabled() const | |
1640 | { | |
1641 | #if TARGET_API_MAC_OSX | |
1642 | return IsControlEnabled( m_controlRef ) ; | |
1643 | #else | |
1644 | return IsControlActive( m_controlRef ) ; | |
1645 | #endif | |
1646 | } | |
1647 | ||
1648 | bool wxMacControl::IsActive() const | |
1649 | { | |
1650 | return IsControlActive( m_controlRef ) ; | |
1651 | } | |
1652 | ||
1653 | void wxMacControl::Enable( bool enable ) | |
1654 | { | |
1655 | #if TARGET_API_MAC_OSX | |
1656 | if ( enable ) | |
1657 | EnableControl( m_controlRef ) ; | |
1658 | else | |
1659 | DisableControl( m_controlRef ) ; | |
1660 | #else | |
1661 | if ( enable ) | |
1662 | ActivateControl( m_controlRef ) ; | |
1663 | else | |
1664 | DeactivateControl( m_controlRef ) ; | |
1665 | #endif | |
1666 | } | |
1667 | ||
1668 | void wxMacControl::SetDrawingEnabled( bool enable ) | |
1669 | { | |
1670 | #if TARGET_API_MAC_OSX | |
1671 | HIViewSetDrawingEnabled( m_controlRef , enable ) ; | |
1672 | #endif | |
1673 | } | |
1674 | ||
1675 | bool wxMacControl::GetNeedsDisplay() const | |
1676 | { | |
1677 | #if TARGET_API_MAC_OSX | |
1678 | return HIViewGetNeedsDisplay( m_controlRef ) ; | |
1679 | #else | |
1680 | return false ; | |
1681 | #endif | |
1682 | } | |
1683 | ||
1684 | void wxMacControl::SetNeedsDisplay( bool needsDisplay , RgnHandle where ) | |
1685 | { | |
1686 | #if TARGET_API_MAC_OSX | |
1687 | if ( where != NULL ) | |
1688 | HIViewSetNeedsDisplayInRegion( m_controlRef , where , needsDisplay ) ; | |
1689 | else | |
1690 | HIViewSetNeedsDisplay( m_controlRef , needsDisplay ) ; | |
1691 | #endif | |
1692 | } | |
1693 | ||
1694 | void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to ) | |
1695 | { | |
1696 | #if TARGET_API_MAC_OSX | |
1697 | HIPoint hiPoint ; | |
1698 | hiPoint.x = pt->x ; | |
1699 | hiPoint.y = pt->y ; | |
1700 | HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef ) ; | |
1701 | pt->x = (int)hiPoint.x ; | |
1702 | pt->y = (int)hiPoint.y ; | |
1703 | #endif | |
1704 | } | |
1705 | ||
1706 | void wxMacControl::SetRect( Rect *r ) | |
1707 | { | |
1708 | #if TARGET_API_MAC_OSX | |
1709 | //A HIRect is actually a CGRect on OSX - which consists of two structures - | |
1710 | //CGPoint and CGSize, which have two floats each | |
1711 | HIRect hir = { { r->left , r->top }, { r->right - r->left , r->bottom - r->top } } ; | |
1712 | HIViewSetFrame ( m_controlRef , &hir ) ; | |
1713 | #else | |
1714 | SetControlBounds( m_controlRef , r ) ; | |
1715 | #endif | |
1716 | ||
1717 | } | |
1718 | ||
1719 | void wxMacControl::GetRect( Rect *r ) | |
1720 | { | |
1721 | GetControlBounds( m_controlRef , r ) ; | |
1722 | } | |
1723 | ||
1724 | void wxMacControl::GetRectInWindowCoords( Rect *r ) | |
1725 | { | |
1726 | UMAGetControlBoundsInWindowCoords( m_controlRef , r ) ; | |
1727 | } | |
1728 | ||
1729 | void wxMacControl::GetBestRect( Rect *r ) | |
1730 | { | |
1731 | short baselineoffset ; | |
1732 | GetBestControlRect( m_controlRef , r , &baselineoffset ) ; | |
1733 | } | |
1734 | ||
1735 | void wxMacControl::SetTitle( const wxString &title ) | |
1736 | { | |
1737 | wxFontEncoding encoding; | |
1738 | ||
1739 | if ( m_font.Ok() ) | |
1740 | encoding = m_font.GetEncoding(); | |
1741 | else | |
1742 | encoding = wxFont::GetDefaultEncoding(); | |
1743 | ||
1744 | UMASetControlTitle( m_controlRef , title , encoding ) ; | |
1745 | } | |
1746 | ||
1747 | void wxMacControl::GetFeatures( UInt32 * features ) | |
1748 | { | |
1749 | GetControlFeatures( m_controlRef , features ) ; | |
1750 | } | |
1751 | ||
1752 | OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region ) | |
1753 | { | |
1754 | return GetControlRegion( m_controlRef , partCode , region ) ; | |
1755 | } | |
1756 | ||
1757 | OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other ) | |
1758 | { | |
1759 | #if TARGET_API_MAC_OSX | |
1760 | return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow, | |
1761 | (other != NULL) ? other->m_controlRef : NULL) ; | |
1762 | #else | |
1763 | return 0 ; | |
1764 | #endif | |
1765 | } | |
1766 | ||
1767 | ||
1768 | #if TARGET_API_MAC_OSX | |
1769 | // SetNeedsDisplay would not invalidate the children | |
1770 | static void InvalidateControlAndChildren( HIViewRef control ) | |
1771 | { | |
1772 | HIViewSetNeedsDisplay( control , true ) ; | |
1773 | UInt16 childrenCount = 0 ; | |
1774 | OSStatus err = CountSubControls( control , &childrenCount ) ; | |
1775 | if ( err == errControlIsNotEmbedder ) | |
1776 | return ; | |
1777 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ) ; | |
1778 | ||
1779 | for ( UInt16 i = childrenCount ; i >=1 ; --i ) | |
1780 | { | |
1781 | HIViewRef child ; | |
1782 | err = GetIndexedSubControl( control , i , & child ) ; | |
1783 | if ( err == errControlIsNotEmbedder ) | |
1784 | return ; | |
1785 | InvalidateControlAndChildren( child ) ; | |
1786 | } | |
1787 | } | |
1788 | #endif | |
1789 | ||
1790 | void wxMacControl::InvalidateWithChildren() | |
1791 | { | |
1792 | #if TARGET_API_MAC_OSX | |
1793 | InvalidateControlAndChildren( m_controlRef ) ; | |
1794 | #endif | |
1795 | } | |
1796 | ||
1797 | void wxMacControl::ScrollRect( const wxRect &r , int dx , int dy ) | |
1798 | { | |
1799 | #if TARGET_API_MAC_OSX | |
1800 | HIRect scrollarea = CGRectMake( r.x , r.y , r.width , r.height) ; | |
1801 | HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy ) ; | |
1802 | #endif | |
1803 | } | |
1804 | ||
1805 | ||
1806 | // SetNeedsDisplay would not invalidate the children | |
1807 | ||
1808 | // | |
1809 | // Databrowser | |
1810 | // | |
1811 | ||
1812 | OSStatus wxMacControl::SetSelectionFlags( DataBrowserSelectionFlags options ) | |
1813 | { | |
1814 | return SetDataBrowserSelectionFlags( m_controlRef , options ) ; | |
1815 | } | |
1816 | ||
1817 | OSStatus wxMacControl::AddListViewColumn( DataBrowserListViewColumnDesc *columnDesc, | |
1818 | DataBrowserTableViewColumnIndex position ) | |
1819 | { | |
1820 | return AddDataBrowserListViewColumn( m_controlRef , columnDesc, position ) ; | |
1821 | } | |
1822 | ||
1823 | OSStatus wxMacControl::AutoSizeListViewColumns() | |
1824 | { | |
1825 | return AutoSizeDataBrowserListViewColumns(m_controlRef) ; | |
1826 | } | |
1827 | ||
1828 | OSStatus wxMacControl::SetHasScrollBars( bool horiz , bool vert ) | |
1829 | { | |
1830 | return SetDataBrowserHasScrollBars( m_controlRef , horiz , vert ) ; | |
1831 | } | |
1832 | ||
1833 | OSStatus wxMacControl::SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) | |
1834 | { | |
1835 | return SetDataBrowserTableViewHiliteStyle( m_controlRef , hiliteStyle ) ; | |
1836 | } | |
1837 | ||
1838 | OSStatus wxMacControl::SetListViewHeaderBtnHeight(UInt16 height) | |
1839 | { | |
1840 | return SetDataBrowserListViewHeaderBtnHeight( m_controlRef ,height ) ; | |
1841 | } | |
1842 | ||
1843 | OSStatus wxMacControl::SetCallbacks(const DataBrowserCallbacks * callbacks) | |
1844 | { | |
1845 | return SetDataBrowserCallbacks( m_controlRef , callbacks ) ; | |
1846 | } | |
1847 | ||
1848 | OSStatus wxMacControl::UpdateItems( DataBrowserItemID container, UInt32 numItems, | |
1849 | const DataBrowserItemID* items, | |
1850 | DataBrowserPropertyID preSortProperty, | |
1851 | DataBrowserPropertyID propertyID ) | |
1852 | { | |
1853 | return UpdateDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty, propertyID ) ; | |
1854 | } | |
1855 | ||
1856 | bool wxMacControl::IsItemSelected( DataBrowserItemID item ) | |
1857 | { | |
1858 | return IsDataBrowserItemSelected( m_controlRef , item ) ; | |
1859 | } | |
1860 | ||
1861 | OSStatus wxMacControl::AddItems( DataBrowserItemID container, UInt32 numItems, | |
1862 | const DataBrowserItemID* items, | |
1863 | DataBrowserPropertyID preSortProperty ) | |
1864 | { | |
1865 | return AddDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty ) ; | |
1866 | } | |
1867 | ||
1868 | OSStatus wxMacControl::RemoveItems( DataBrowserItemID container, UInt32 numItems, | |
1869 | const DataBrowserItemID* items, | |
1870 | DataBrowserPropertyID preSortProperty ) | |
1871 | { | |
1872 | return RemoveDataBrowserItems( m_controlRef , container, numItems, items, preSortProperty ) ; | |
1873 | } | |
1874 | ||
1875 | OSStatus wxMacControl::RevealItem( DataBrowserItemID item, | |
1876 | DataBrowserPropertyID propertyID, | |
1877 | DataBrowserRevealOptions options ) | |
1878 | { | |
1879 | return RevealDataBrowserItem( m_controlRef , item , propertyID , options ) ; | |
1880 | } | |
1881 | ||
1882 | OSStatus wxMacControl::SetSelectedItems(UInt32 numItems, | |
1883 | const DataBrowserItemID * items, | |
1884 | DataBrowserSetOption operation ) | |
1885 | { | |
1886 | return SetDataBrowserSelectedItems( m_controlRef , numItems , items, operation ) ; | |
1887 | } | |
1888 | ||
1889 | // | |
1890 | // Tab Control | |
1891 | // | |
1892 | ||
1893 | OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable ) | |
1894 | { | |
1895 | return ::SetTabEnabled( m_controlRef , tabNo , enable ) ; | |
1896 | } | |
1897 | ||
1898 | #endif // wxUSE_GUI | |
1899 |