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