]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
fb5246be | 2 | // Name: src/mac/carbon/utils.cpp |
e9576ca5 | 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 |
88a7a4e1 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
e9576ca5 | 14 | #include "wx/utils.h" |
88a7a4e1 WS |
15 | |
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/intl.h" | |
670f9935 | 18 | #include "wx/app.h" |
88a7a4e1 WS |
19 | #endif |
20 | ||
2bf2d09e | 21 | #include "wx/apptrait.h" |
b6ed2b86 VZ |
22 | |
23 | #if wxUSE_GUI | |
24 | #include "wx/mac/uma.h" | |
9d8aca48 | 25 | #include "wx/font.h" |
90753016 | 26 | #include "wx/toplevel.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 | 38 | #ifndef __DARWIN__ |
8638e69b DS |
39 | #include <Threads.h> |
40 | #include <Sound.h> | |
66a09d47 SC |
41 | #endif |
42 | ||
7d9bf1f1 | 43 | #if wxUSE_GUI |
29d91661 | 44 | #if TARGET_API_MAC_OSX |
8638e69b | 45 | #include <CoreServices/CoreServices.h> |
29d91661 | 46 | #else |
8638e69b DS |
47 | #include <DriverServices.h> |
48 | #include <Multiprocessing.h> | |
29d91661 SC |
49 | #endif |
50 | ||
768c6e8b | 51 | #ifdef __DARWIN__ |
8638e69b | 52 | #include <Carbon/Carbon.h> |
768c6e8b | 53 | #else |
8638e69b DS |
54 | #include <ATSUnicode.h> |
55 | #include <TextCommon.h> | |
56 | #include <TextEncodingConverter.h> | |
768c6e8b | 57 | #endif |
7d9bf1f1 | 58 | #endif // wxUSE_GUI |
427ff662 | 59 | |
8638e69b | 60 | #include "wx/mac/private.h" |
a434b43f VZ |
61 | |
62 | #if defined(__MWERKS__) && wxUSE_UNICODE | |
6cce68ea | 63 | #if __MWERKS__ < 0x4100 || !defined(__DARWIN__) |
a434b43f VZ |
64 | #include <wtime.h> |
65 | #endif | |
6cce68ea | 66 | #endif |
a434b43f | 67 | |
659b3e8b VZ |
68 | // --------------------------------------------------------------------------- |
69 | // code used in both base and GUI compilation | |
70 | // --------------------------------------------------------------------------- | |
71 | ||
72 | // our OS version is the same in non GUI and GUI cases | |
73 | static int DoGetOSVersion(int *majorVsn, int *minorVsn) | |
74 | { | |
6cce68ea | 75 | long theSystem; |
659b3e8b VZ |
76 | |
77 | // are there x-platform conventions ? | |
78 | ||
6cce68ea | 79 | Gestalt(gestaltSystemVersion, &theSystem); |
8638e69b | 80 | if (minorVsn != NULL) |
6cce68ea | 81 | *minorVsn = (theSystem & 0xFF); |
8638e69b DS |
82 | |
83 | if (majorVsn != NULL) | |
6cce68ea | 84 | *majorVsn = (theSystem >> 8); |
8638e69b | 85 | |
659b3e8b VZ |
86 | #ifdef __DARWIN__ |
87 | return wxMAC_DARWIN; | |
88 | #else | |
89 | return wxMAC; | |
90 | #endif | |
91 | } | |
92 | ||
ee8bf34f RD |
93 | |
94 | #if wxUSE_BASE | |
95 | ||
e5a9c663 SC |
96 | // ---------------------------------------------------------------------------- |
97 | // debugging support | |
98 | // ---------------------------------------------------------------------------- | |
99 | ||
e2fccedf | 100 | #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400) |
e5a9c663 SC |
101 | |
102 | // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds... | |
103 | ||
104 | #ifndef __MetroNubUtils__ | |
105 | #include "MetroNubUtils.h" | |
106 | #endif | |
107 | ||
108 | #ifndef __GESTALT__ | |
109 | #include <Gestalt.h> | |
110 | #endif | |
111 | ||
112 | #if TARGET_API_MAC_CARBON | |
113 | ||
8638e69b | 114 | #include <CodeFragments.h> |
e5a9c663 | 115 | |
8638e69b | 116 | extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...); |
e5a9c663 | 117 | |
8638e69b | 118 | ProcPtr gCallUniversalProc_Proc = NULL; |
e5a9c663 SC |
119 | |
120 | #endif | |
121 | ||
122 | static MetroNubUserEntryBlock* gMetroNubEntry = NULL; | |
123 | ||
124 | static long fRunOnce = false; | |
125 | ||
e5a9c663 SC |
126 | |
127 | Boolean IsMetroNubInstalled() | |
128 | { | |
129 | if (!fRunOnce) | |
130 | { | |
131 | long result, value; | |
132 | ||
133 | fRunOnce = true; | |
134 | gMetroNubEntry = NULL; | |
135 | ||
136 | if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000) | |
137 | { | |
8638e69b | 138 | // look for MetroNub's Gestalt selector |
e5a9c663 SC |
139 | if (Gestalt(kMetroNubUserSignature, &result) == noErr) |
140 | { | |
8638e69b | 141 | #if TARGET_API_MAC_CARBON |
e5a9c663 SC |
142 | if (gCallUniversalProc_Proc == NULL) |
143 | { | |
144 | CFragConnectionID connectionID; | |
145 | Ptr mainAddress; | |
146 | Str255 errorString; | |
147 | ProcPtr symbolAddress; | |
148 | OSErr err; | |
149 | CFragSymbolClass symbolClass; | |
150 | ||
151 | symbolAddress = NULL; | |
152 | err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag, | |
153 | &connectionID, &mainAddress, errorString); | |
154 | ||
155 | if (err != noErr) | |
156 | { | |
157 | gCallUniversalProc_Proc = NULL; | |
158 | goto end; | |
159 | } | |
160 | ||
161 | err = FindSymbol(connectionID, "\pCallUniversalProc", | |
162 | (Ptr *) &gCallUniversalProc_Proc, &symbolClass); | |
163 | ||
164 | if (err != noErr) | |
165 | { | |
166 | gCallUniversalProc_Proc = NULL; | |
167 | goto end; | |
168 | } | |
169 | } | |
8638e69b | 170 | #endif |
e5a9c663 SC |
171 | |
172 | { | |
173 | MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result; | |
174 | ||
8638e69b | 175 | // make sure the version of the API is compatible |
e5a9c663 SC |
176 | if (block->apiLowVersion <= kMetroNubUserAPIVersion && |
177 | kMetroNubUserAPIVersion <= block->apiHiVersion) | |
8638e69b DS |
178 | { |
179 | // success! | |
88a7a4e1 | 180 | gMetroNubEntry = block; |
8638e69b | 181 | } |
e5a9c663 | 182 | } |
e5a9c663 SC |
183 | } |
184 | } | |
185 | } | |
186 | ||
187 | end: | |
188 | ||
189 | #if TARGET_API_MAC_CARBON | |
190 | return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL); | |
191 | #else | |
192 | return (gMetroNubEntry != NULL); | |
193 | #endif | |
194 | } | |
195 | ||
e5a9c663 SC |
196 | Boolean IsMWDebuggerRunning() |
197 | { | |
198 | if (IsMetroNubInstalled()) | |
199 | return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning); | |
e5a9c663 | 200 | |
8638e69b DS |
201 | return false; |
202 | } | |
e5a9c663 SC |
203 | |
204 | Boolean AmIBeingMWDebugged() | |
205 | { | |
206 | if (IsMetroNubInstalled()) | |
207 | return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged); | |
8638e69b DS |
208 | |
209 | return false; | |
e5a9c663 SC |
210 | } |
211 | ||
212 | extern bool WXDLLEXPORT wxIsDebuggerRunning() | |
213 | { | |
214 | return IsMWDebuggerRunning() && AmIBeingMWDebugged(); | |
215 | } | |
216 | ||
217 | #else | |
218 | ||
219 | extern bool WXDLLEXPORT wxIsDebuggerRunning() | |
220 | { | |
221 | return false; | |
222 | } | |
223 | ||
224 | #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400) | |
225 | ||
a434b43f | 226 | |
f5c6eb5c | 227 | #ifndef __DARWIN__ |
03e11df5 GD |
228 | // defined in unix/utilsunx.cpp for Mac OS X |
229 | ||
2f1ae414 SC |
230 | // get full hostname (with domain name if possible) |
231 | bool wxGetFullHostName(wxChar *buf, int maxSize) | |
232 | { | |
233 | return wxGetHostName(buf, maxSize); | |
234 | } | |
235 | ||
8638e69b DS |
236 | // Get user ID e.g. jacs |
237 | bool wxGetUserId(wxChar *buf, int maxSize) | |
238 | { | |
6cce68ea | 239 | return wxGetUserName( buf , maxSize ); |
8638e69b DS |
240 | } |
241 | ||
242 | const wxChar* wxGetHomeDir(wxString *pstr) | |
243 | { | |
6cce68ea SC |
244 | *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ); |
245 | return pstr->c_str(); | |
8638e69b DS |
246 | } |
247 | ||
2f1ae414 | 248 | // Get hostname only (without domain name) |
427ff662 | 249 | bool wxGetHostName(wxChar *buf, int maxSize) |
e9576ca5 | 250 | { |
e40298d5 | 251 | // Gets Chooser name of user by examining a System resource. |
6cce68ea | 252 | buf[0] = 0; |
e40298d5 JS |
253 | |
254 | const short kComputerNameID = -16413; | |
5be55d56 | 255 | |
6cce68ea | 256 | short oldResFile = CurResFile(); |
e40298d5 JS |
257 | UseResFile(0); |
258 | StringHandle chooserName = (StringHandle)::GetString(kComputerNameID); | |
259 | UseResFile(oldResFile); | |
260 | ||
261 | if (chooserName && *chooserName) | |
262 | { | |
6cce68ea SC |
263 | HLock( (Handle) chooserName ); |
264 | wxString name = wxMacMakeStringFromPascal( *chooserName ); | |
265 | HUnlock( (Handle) chooserName ); | |
266 | ReleaseResource( (Handle) chooserName ); | |
267 | wxStrncpy( buf , name , maxSize - 1 ); | |
e40298d5 | 268 | } |
0a67a93b | 269 | |
9d8aca48 | 270 | return true; |
e9576ca5 SC |
271 | } |
272 | ||
a31a5f85 | 273 | // Get user name e.g. Stefan Csomor |
427ff662 | 274 | bool wxGetUserName(wxChar *buf, int maxSize) |
e9576ca5 | 275 | { |
e40298d5 | 276 | // Gets Chooser name of user by examining a System resource. |
6cce68ea | 277 | buf[0] = 0; |
e40298d5 JS |
278 | |
279 | const short kChooserNameID = -16096; | |
5be55d56 | 280 | |
6cce68ea | 281 | short oldResFile = CurResFile(); |
e40298d5 JS |
282 | UseResFile(0); |
283 | StringHandle chooserName = (StringHandle)::GetString(kChooserNameID); | |
284 | UseResFile(oldResFile); | |
285 | ||
286 | if (chooserName && *chooserName) | |
287 | { | |
6cce68ea SC |
288 | HLock( (Handle) chooserName ); |
289 | wxString name = wxMacMakeStringFromPascal( *chooserName ); | |
290 | HUnlock( (Handle) chooserName ); | |
291 | ReleaseResource( (Handle) chooserName ); | |
292 | wxStrncpy( buf , name , maxSize - 1 ); | |
e40298d5 | 293 | } |
0a67a93b | 294 | |
9d8aca48 | 295 | return true; |
e9576ca5 SC |
296 | } |
297 | ||
e0f6b731 | 298 | int wxKill(long pid, wxSignal sig , wxKillError *rc, int flags) |
e9576ca5 SC |
299 | { |
300 | // TODO | |
301 | return 0; | |
302 | } | |
303 | ||
5dbb17e2 SC |
304 | WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value) |
305 | { | |
e40298d5 | 306 | // TODO : under classic there is no environement support, under X yes |
6cce68ea | 307 | return false; |
5dbb17e2 SC |
308 | } |
309 | ||
9d8aca48 | 310 | // set the env var name to the given value, return true on success |
5dbb17e2 SC |
311 | WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value) |
312 | { | |
e40298d5 | 313 | // TODO : under classic there is no environement support, under X yes |
6cce68ea | 314 | return false; |
5dbb17e2 SC |
315 | } |
316 | ||
e9576ca5 | 317 | // Execute a program in an Interactive Shell |
e9576ca5 SC |
318 | bool wxShell(const wxString& command) |
319 | { | |
320 | // TODO | |
9d8aca48 | 321 | return false; |
e9576ca5 SC |
322 | } |
323 | ||
5be55d56 | 324 | // Shutdown or reboot the PC |
f6ba47d9 VZ |
325 | bool wxShutdown(wxShutdownFlags wFlags) |
326 | { | |
327 | // TODO | |
9d8aca48 | 328 | return false; |
f6ba47d9 VZ |
329 | } |
330 | ||
e9576ca5 | 331 | // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) |
9d8aca48 | 332 | wxMemorySize wxGetFreeMemory() |
e9576ca5 | 333 | { |
6cce68ea | 334 | return (wxMemorySize)FreeMem(); |
0a67a93b SC |
335 | } |
336 | ||
7f7b52b4 SC |
337 | #ifndef __DARWIN__ |
338 | ||
339 | void wxMicroSleep(unsigned long microseconds) | |
0a67a93b | 340 | { |
9d8aca48 WS |
341 | AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime()); |
342 | MPDelayUntil( & wakeup); | |
7f7b52b4 SC |
343 | } |
344 | ||
345 | void wxMilliSleep(unsigned long milliseconds) | |
346 | { | |
9d8aca48 WS |
347 | AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime()); |
348 | MPDelayUntil( & wakeup); | |
e9576ca5 SC |
349 | } |
350 | ||
351 | void wxSleep(int nSecs) | |
352 | { | |
7f7b52b4 | 353 | wxMilliSleep(1000*nSecs); |
e9576ca5 SC |
354 | } |
355 | ||
7f7b52b4 SC |
356 | #endif |
357 | ||
e9576ca5 SC |
358 | // Consume all events until no more left |
359 | void wxFlushEvents() | |
360 | { | |
361 | } | |
362 | ||
f5c6eb5c | 363 | #endif // !__DARWIN__ |
e9576ca5 SC |
364 | |
365 | // Emit a beeeeeep | |
366 | void wxBell() | |
367 | { | |
0a67a93b | 368 | SysBeep(30); |
e9576ca5 SC |
369 | } |
370 | ||
324899f6 | 371 | wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo() |
29c99ad3 | 372 | { |
a8eaaeb2 | 373 | static wxToolkitInfo info; |
8638e69b | 374 | |
66b6b57c | 375 | info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); |
a8eaaeb2 | 376 | info.name = _T("wxBase"); |
8638e69b | 377 | |
324899f6 | 378 | return info; |
29c99ad3 VZ |
379 | } |
380 | ||
b6ed2b86 VZ |
381 | #endif // wxUSE_BASE |
382 | ||
383 | #if wxUSE_GUI | |
536732e4 | 384 | |
324899f6 | 385 | wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() |
29c99ad3 | 386 | { |
a8eaaeb2 | 387 | static wxToolkitInfo info; |
8638e69b | 388 | |
66b6b57c | 389 | info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); |
a8eaaeb2 VS |
390 | info.shortName = _T("mac"); |
391 | info.name = _T("wxMac"); | |
8638e69b | 392 | |
a8eaaeb2 VS |
393 | #ifdef __WXUNIVERSAL__ |
394 | info.shortName << _T("univ"); | |
395 | info.name << _T("/wxUniversal"); | |
396 | #endif | |
8638e69b | 397 | |
324899f6 | 398 | return info; |
29c99ad3 VZ |
399 | } |
400 | ||
e9576ca5 SC |
401 | // Reading and writing resources (eg WIN.INI, .Xdefaults) |
402 | #if wxUSE_RESOURCES | |
403 | bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file) | |
404 | { | |
405 | // TODO | |
9d8aca48 | 406 | return false; |
e9576ca5 SC |
407 | } |
408 | ||
409 | bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file) | |
410 | { | |
427ff662 SC |
411 | wxString buf; |
412 | buf.Printf(wxT("%.4f"), value); | |
413 | ||
e40298d5 | 414 | return wxWriteResource(section, entry, buf, file); |
e9576ca5 SC |
415 | } |
416 | ||
417 | bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file) | |
418 | { | |
427ff662 SC |
419 | wxString buf; |
420 | buf.Printf(wxT("%ld"), value); | |
421 | ||
e40298d5 | 422 | return wxWriteResource(section, entry, buf, file); |
e9576ca5 SC |
423 | } |
424 | ||
425 | bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file) | |
426 | { | |
427ff662 SC |
427 | wxString buf; |
428 | buf.Printf(wxT("%d"), value); | |
429 | ||
e40298d5 | 430 | return wxWriteResource(section, entry, buf, file); |
e9576ca5 SC |
431 | } |
432 | ||
433 | bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file) | |
434 | { | |
435 | // TODO | |
9d8aca48 | 436 | return false; |
e9576ca5 SC |
437 | } |
438 | ||
439 | bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file) | |
440 | { | |
e40298d5 JS |
441 | char *s = NULL; |
442 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
443 | if (succ) | |
444 | { | |
445 | *value = (float)strtod(s, NULL); | |
446 | delete[] s; | |
e40298d5 | 447 | } |
8638e69b DS |
448 | |
449 | return succ; | |
e9576ca5 SC |
450 | } |
451 | ||
452 | bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file) | |
453 | { | |
e40298d5 JS |
454 | char *s = NULL; |
455 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
456 | if (succ) | |
457 | { | |
458 | *value = strtol(s, NULL, 10); | |
459 | delete[] s; | |
e40298d5 | 460 | } |
8638e69b DS |
461 | |
462 | return succ; | |
e9576ca5 SC |
463 | } |
464 | ||
465 | bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file) | |
466 | { | |
e40298d5 JS |
467 | char *s = NULL; |
468 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
469 | if (succ) | |
470 | { | |
471 | *value = (int)strtol(s, NULL, 10); | |
472 | delete[] s; | |
e40298d5 | 473 | } |
8638e69b DS |
474 | |
475 | return succ; | |
e9576ca5 SC |
476 | } |
477 | #endif // wxUSE_RESOURCES | |
478 | ||
6b57b49a | 479 | int gs_wxBusyCursorCount = 0; |
6cce68ea SC |
480 | extern wxCursor gMacCurrentCursor; |
481 | wxCursor gMacStoredActiveCursor; | |
e9576ca5 SC |
482 | |
483 | // Set the cursor to the busy cursor for all windows | |
f516d986 | 484 | void wxBeginBusyCursor(const wxCursor *cursor) |
e9576ca5 | 485 | { |
e40298d5 JS |
486 | if (gs_wxBusyCursorCount++ == 0) |
487 | { | |
6cce68ea SC |
488 | gMacStoredActiveCursor = gMacCurrentCursor; |
489 | cursor->MacInstall(); | |
e40298d5 JS |
490 | } |
491 | //else: nothing to do, already set | |
e9576ca5 SC |
492 | } |
493 | ||
494 | // Restore cursor to normal | |
495 | void wxEndBusyCursor() | |
496 | { | |
6b57b49a | 497 | wxCHECK_RET( gs_wxBusyCursorCount > 0, |
e40298d5 | 498 | wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") ); |
5be55d56 | 499 | |
e40298d5 JS |
500 | if (--gs_wxBusyCursorCount == 0) |
501 | { | |
6cce68ea SC |
502 | gMacStoredActiveCursor.MacInstall(); |
503 | gMacStoredActiveCursor = wxNullCursor; | |
e40298d5 | 504 | } |
e9576ca5 SC |
505 | } |
506 | ||
9d8aca48 | 507 | // true if we're between the above two calls |
e9576ca5 SC |
508 | bool wxIsBusy() |
509 | { | |
e40298d5 | 510 | return (gs_wxBusyCursorCount > 0); |
ec5d7799 | 511 | } |
e9576ca5 | 512 | |
2dbc444a RD |
513 | #endif // wxUSE_GUI |
514 | ||
515 | #if wxUSE_BASE | |
516 | ||
17af82fb | 517 | wxString wxMacFindFolderNoSeparator( short vol, |
e40298d5 JS |
518 | OSType folderType, |
519 | Boolean createFolder) | |
2f1ae414 | 520 | { |
6cce68ea SC |
521 | FSRef fsRef; |
522 | wxString strDir; | |
5be55d56 | 523 | |
a2b77260 | 524 | if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr) |
17af82fb VZ |
525 | { |
526 | strDir = wxMacFSRefToPath( &fsRef ); | |
527 | } | |
a2b77260 | 528 | |
6cce68ea | 529 | return strDir; |
2f1ae414 SC |
530 | } |
531 | ||
17af82fb VZ |
532 | wxString wxMacFindFolder( short vol, |
533 | OSType folderType, | |
534 | Boolean createFolder) | |
535 | { | |
536 | return wxMacFindFolderNoSeparator(vol, folderType, createFolder) + wxFILE_SEP_PATH; | |
537 | } | |
538 | ||
2dbc444a RD |
539 | #endif // wxUSE_BASE |
540 | ||
541 | #if wxUSE_GUI | |
542 | ||
e9576ca5 SC |
543 | // Check whether this window wants to process messages, e.g. Stop button |
544 | // in long calculations. | |
545 | bool wxCheckForInterrupt(wxWindow *wnd) | |
546 | { | |
547 | // TODO | |
9d8aca48 | 548 | return false; |
e9576ca5 SC |
549 | } |
550 | ||
551 | void wxGetMousePosition( int* x, int* y ) | |
552 | { | |
6cce68ea | 553 | Point pt; |
ec5d7799 | 554 | |
6cce68ea SC |
555 | GetMouse( &pt ); |
556 | LocalToGlobal( &pt ); | |
557 | *x = pt.h; | |
558 | *y = pt.v; | |
e9576ca5 SC |
559 | }; |
560 | ||
9d8aca48 | 561 | // Return true if we have a colour display |
e9576ca5 SC |
562 | bool wxColourDisplay() |
563 | { | |
9d8aca48 | 564 | return true; |
e9576ca5 SC |
565 | } |
566 | ||
567 | // Returns depth of screen | |
568 | int wxDisplayDepth() | |
569 | { | |
6cce68ea | 570 | Rect globRect; |
e40298d5 JS |
571 | SetRect(&globRect, -32760, -32760, 32760, 32760); |
572 | GDHandle theMaxDevice; | |
2f1ae414 | 573 | |
e40298d5 JS |
574 | int theDepth = 8; |
575 | theMaxDevice = GetMaxDevice(&globRect); | |
8638e69b | 576 | if (theMaxDevice != NULL) |
e40298d5 | 577 | theDepth = (**(**theMaxDevice).gdPMap).pixelSize; |
ec5d7799 | 578 | |
6cce68ea | 579 | return theDepth; |
e9576ca5 SC |
580 | } |
581 | ||
582 | // Get size of display | |
583 | void wxDisplaySize(int *width, int *height) | |
584 | { | |
e40298d5 JS |
585 | BitMap screenBits; |
586 | GetQDGlobalsScreenBits( &screenBits ); | |
5be55d56 | 587 | |
8638e69b | 588 | if (width != NULL) |
6cce68ea | 589 | *width = screenBits.bounds.right - screenBits.bounds.left; |
8638e69b DS |
590 | |
591 | if (height != NULL) | |
6cce68ea | 592 | *height = screenBits.bounds.bottom - screenBits.bounds.top; |
e9576ca5 SC |
593 | } |
594 | ||
5fde6fcc GD |
595 | void wxDisplaySizeMM(int *width, int *height) |
596 | { | |
5b028d57 | 597 | wxDisplaySize(width, height); |
6cce68ea | 598 | // on mac 72 is fixed (at least now;-) |
5b028d57 | 599 | float cvPt2Mm = 25.4 / 72; |
e8ca7105 | 600 | |
8638e69b | 601 | if (width != NULL) |
e8ca7105 | 602 | *width = int( *width * cvPt2Mm ); |
8638e69b DS |
603 | |
604 | if (height != NULL) | |
e8ca7105 | 605 | *height = int( *height * cvPt2Mm ); |
5fde6fcc GD |
606 | } |
607 | ||
ec5d7799 RD |
608 | void wxClientDisplayRect(int *x, int *y, int *width, int *height) |
609 | { | |
6cce68ea | 610 | Rect r; |
8638e69b | 611 | |
6cce68ea | 612 | GetAvailableWindowPositioningBounds( GetMainDevice() , &r ); |
ee658398 | 613 | if ( x ) |
6cce68ea | 614 | *x = r.left; |
ee658398 | 615 | if ( y ) |
6cce68ea | 616 | *y = r.top; |
ee658398 | 617 | if ( width ) |
6cce68ea | 618 | *width = r.right - r.left; |
ee658398 | 619 | if ( height ) |
6cce68ea | 620 | *height = r.bottom - r.top; |
ec5d7799 RD |
621 | } |
622 | ||
57591e0e JS |
623 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) |
624 | { | |
625 | return wxGenericFindWindowAtPoint(pt); | |
626 | } | |
5dbb17e2 | 627 | |
b6ed2b86 VZ |
628 | #endif // wxUSE_GUI |
629 | ||
630 | #if wxUSE_BASE | |
631 | ||
5dbb17e2 SC |
632 | wxString wxGetOsDescription() |
633 | { | |
6e73695c GD |
634 | #ifdef WXWIN_OS_DESCRIPTION |
635 | // use configure generated description if available | |
5f3f0f17 | 636 | return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")")); |
6e73695c | 637 | #else |
6cce68ea | 638 | return wxT("MacOS"); //TODO:define further |
6e73695c GD |
639 | #endif |
640 | } | |
641 | ||
b6ed2b86 VZ |
642 | #ifndef __DARWIN__ |
643 | wxChar *wxGetUserHome (const wxString& user) | |
644 | { | |
645 | // TODO | |
646 | return NULL; | |
647 | } | |
648 | ||
7ba7c4e6 | 649 | bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree) |
b6ed2b86 VZ |
650 | { |
651 | if ( path.empty() ) | |
9d8aca48 | 652 | return false; |
b6ed2b86 | 653 | |
6cce68ea | 654 | wxString p = path; |
8638e69b | 655 | if (p[0u] == ':' ) |
6cce68ea | 656 | p = wxGetCwd() + p; |
b6ed2b86 | 657 | |
6cce68ea | 658 | int pos = p.Find(':'); |
8638e69b | 659 | if ( pos != wxNOT_FOUND ) |
6cce68ea | 660 | p = p.Mid(1,pos); |
b6ed2b86 | 661 | |
6cce68ea | 662 | p = p + wxT(":"); |
b6ed2b86 | 663 | |
6cce68ea | 664 | OSErr err = noErr; |
9d8aca48 | 665 | |
6cce68ea SC |
666 | FSRef fsRef; |
667 | err = wxMacPathToFSRef( p , &fsRef ); | |
a2b77260 SC |
668 | if ( noErr == err ) |
669 | { | |
6cce68ea SC |
670 | FSVolumeRefNum vRefNum; |
671 | err = FSGetVRefNum( &fsRef , &vRefNum ); | |
a2b77260 SC |
672 | if ( noErr == err ) |
673 | { | |
6cce68ea SC |
674 | UInt64 freeBytes , totalBytes; |
675 | err = FSGetVInfo( vRefNum , NULL , &freeBytes , &totalBytes ); | |
a2b77260 SC |
676 | if ( noErr == err ) |
677 | { | |
9d8aca48 | 678 | if ( pTotal ) |
6cce68ea | 679 | *pTotal = wxDiskspaceSize_t( totalBytes ); |
a2b77260 | 680 | if ( pFree ) |
6cce68ea | 681 | *pFree = wxDiskspaceSize_t( freeBytes ); |
a2b77260 SC |
682 | } |
683 | } | |
b6ed2b86 | 684 | } |
9d8aca48 | 685 | |
6cce68ea | 686 | return err == noErr; |
b6ed2b86 VZ |
687 | } |
688 | #endif // !__DARWIN__ | |
689 | ||
3d963f81 SC |
690 | //--------------------------------------------------------------------------- |
691 | // wxMac Specific utility functions | |
692 | //--------------------------------------------------------------------------- | |
693 | ||
5be55d56 | 694 | void wxMacStringToPascal( const wxString&from , StringPtr to ) |
427ff662 | 695 | { |
6cce68ea SC |
696 | wxCharBuffer buf = from.mb_str( wxConvLocal ); |
697 | int len = strlen(buf); | |
427ff662 SC |
698 | |
699 | if ( len > 255 ) | |
6cce68ea SC |
700 | len = 255; |
701 | to[0] = len; | |
702 | memcpy( (char*) &to[1] , buf , len ); | |
427ff662 SC |
703 | } |
704 | ||
5be55d56 | 705 | wxString wxMacMakeStringFromPascal( ConstStringPtr from ) |
427ff662 | 706 | { |
6cce68ea | 707 | return wxString( (char*) &from[1] , wxConvLocal , from[0] ); |
427ff662 SC |
708 | } |
709 | ||
73280e05 SC |
710 | // ---------------------------------------------------------------------------- |
711 | // Common Event Support | |
712 | // ---------------------------------------------------------------------------- | |
713 | ||
6cce68ea | 714 | extern ProcessSerialNumber gAppProcess; |
73280e05 SC |
715 | |
716 | void wxMacWakeUp() | |
717 | { | |
6cce68ea SC |
718 | ProcessSerialNumber psn; |
719 | Boolean isSame; | |
720 | psn.highLongOfPSN = 0; | |
721 | psn.lowLongOfPSN = kCurrentProcess; | |
722 | SameProcess( &gAppProcess , &psn , &isSame ); | |
73280e05 SC |
723 | if ( isSame ) |
724 | { | |
725 | #if TARGET_CARBON | |
6cce68ea | 726 | OSStatus err = noErr; |
8638e69b | 727 | |
41ab357e SC |
728 | #if 0 |
729 | // lead sometimes to race conditions, although all calls used should be thread safe ... | |
6cce68ea | 730 | static wxMacCarbonEvent s_wakeupEvent; |
8dfef0c2 | 731 | if ( !s_wakeupEvent.IsValid() ) |
d6c69b17 | 732 | { |
8dfef0c2 | 733 | err = s_wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(), |
6cce68ea | 734 | kEventAttributeNone ); |
d6c69b17 | 735 | } |
8dfef0c2 | 736 | if ( err == noErr ) |
73280e05 | 737 | { |
88a7a4e1 | 738 | |
8dfef0c2 | 739 | if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent ) ) |
6cce68ea SC |
740 | return; |
741 | s_wakeupEvent.SetCurrentTime(); | |
d6c69b17 | 742 | err = PostEventToQueue(GetMainEventQueue(), s_wakeupEvent, |
41ab357e | 743 | kEventPriorityHigh ); |
8dfef0c2 | 744 | } |
41ab357e | 745 | #else |
6cce68ea | 746 | wxMacCarbonEvent wakeupEvent; |
41ab357e | 747 | wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(), |
6cce68ea | 748 | kEventAttributeNone ); |
41ab357e SC |
749 | err = PostEventToQueue(GetMainEventQueue(), wakeupEvent, |
750 | kEventPriorityHigh ); | |
751 | #endif | |
73280e05 | 752 | #else |
6cce68ea | 753 | PostEvent( nullEvent , 0 ); |
73280e05 SC |
754 | #endif |
755 | } | |
756 | else | |
757 | { | |
6cce68ea | 758 | WakeUpProcess( &gAppProcess ); |
73280e05 SC |
759 | } |
760 | } | |
761 | ||
d13ea1bd RD |
762 | #endif // wxUSE_BASE |
763 | ||
764 | #if wxUSE_GUI | |
765 | ||
1f1c8bd4 SC |
766 | // ---------------------------------------------------------------------------- |
767 | // Native Struct Conversions | |
768 | // ---------------------------------------------------------------------------- | |
769 | ||
fb5246be | 770 | void wxMacRectToNative( const wxRect *wx , Rect *n ) |
1f1c8bd4 | 771 | { |
6cce68ea SC |
772 | n->left = wx->x; |
773 | n->top = wx->y; | |
774 | n->right = wx->x + wx->width; | |
775 | n->bottom = wx->y + wx->height; | |
1f1c8bd4 SC |
776 | } |
777 | ||
fb5246be | 778 | void wxMacNativeToRect( const Rect *n , wxRect* wx ) |
1f1c8bd4 | 779 | { |
6cce68ea SC |
780 | wx->x = n->left; |
781 | wx->y = n->top; | |
782 | wx->width = n->right - n->left; | |
783 | wx->height = n->bottom - n->top; | |
1f1c8bd4 SC |
784 | } |
785 | ||
fb5246be | 786 | void wxMacPointToNative( const wxPoint* wx , Point *n ) |
1f1c8bd4 | 787 | { |
6cce68ea SC |
788 | n->h = wx->x; |
789 | n->v = wx->y; | |
1f1c8bd4 SC |
790 | } |
791 | ||
fb5246be | 792 | void wxMacNativeToPoint( const Point *n , wxPoint* wx ) |
1f1c8bd4 | 793 | { |
6cce68ea SC |
794 | wx->x = n->h; |
795 | wx->y = n->v; | |
1f1c8bd4 | 796 | } |
d13ea1bd | 797 | |
facd6764 SC |
798 | // ---------------------------------------------------------------------------- |
799 | // Carbon Event Support | |
800 | // ---------------------------------------------------------------------------- | |
801 | ||
facd6764 SC |
802 | OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) |
803 | { | |
6cce68ea | 804 | return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData ); |
facd6764 SC |
805 | } |
806 | ||
21fd5529 | 807 | OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData) |
facd6764 | 808 | { |
6cce68ea | 809 | return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData ); |
facd6764 SC |
810 | } |
811 | ||
86d8b744 SC |
812 | // ---------------------------------------------------------------------------- |
813 | // Control Access Support | |
814 | // ---------------------------------------------------------------------------- | |
815 | ||
1f1c8bd4 | 816 | wxMacControl::wxMacControl(wxWindow* peer , bool isRootControl ) |
9b89f11a | 817 | { |
6cce68ea SC |
818 | Init(); |
819 | m_peer = peer; | |
820 | m_isRootControl = isRootControl; | |
821 | m_isCompositing = peer->MacGetTopLevelWindow()->MacUsesCompositing(); | |
9b89f11a SC |
822 | } |
823 | ||
fb5246be | 824 | wxMacControl::wxMacControl( wxWindow* peer , ControlRef control ) |
9b89f11a | 825 | { |
6cce68ea SC |
826 | Init(); |
827 | m_peer = peer; | |
828 | m_isCompositing = peer->MacGetTopLevelWindow()->MacUsesCompositing(); | |
829 | m_controlRef = control; | |
9b89f11a SC |
830 | } |
831 | ||
832 | wxMacControl::wxMacControl( wxWindow* peer , WXWidget control ) | |
833 | { | |
6cce68ea SC |
834 | Init(); |
835 | m_peer = peer; | |
836 | m_isCompositing = peer->MacGetTopLevelWindow()->MacUsesCompositing(); | |
837 | m_controlRef = (ControlRef) control; | |
9b89f11a SC |
838 | } |
839 | ||
840 | wxMacControl::~wxMacControl() | |
841 | { | |
842 | } | |
843 | ||
844 | void wxMacControl::Init() | |
845 | { | |
6cce68ea SC |
846 | m_peer = NULL; |
847 | m_controlRef = NULL; | |
848 | m_needsFocusRect = false; | |
849 | m_isCompositing = false; | |
850 | m_isRootControl = false; | |
9b89f11a SC |
851 | } |
852 | ||
5ca0d812 SC |
853 | void wxMacControl::Dispose() |
854 | { | |
6cce68ea SC |
855 | ::DisposeControl( m_controlRef ); |
856 | m_controlRef = NULL; | |
5ca0d812 SC |
857 | } |
858 | ||
9d8aca48 | 859 | void wxMacControl::SetReference( SInt32 data ) |
5ca0d812 | 860 | { |
6cce68ea | 861 | SetControlReference( m_controlRef , data ); |
5ca0d812 SC |
862 | } |
863 | ||
29d91661 | 864 | OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const |
86d8b744 | 865 | { |
6cce68ea | 866 | return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize ); |
86d8b744 SC |
867 | } |
868 | ||
29d91661 | 869 | OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const |
86d8b744 | 870 | { |
6cce68ea | 871 | return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize ); |
86d8b744 SC |
872 | } |
873 | ||
874 | OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData) | |
875 | { | |
6cce68ea | 876 | return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData ); |
86d8b744 SC |
877 | } |
878 | ||
8638e69b | 879 | OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions ) |
21fd5529 | 880 | { |
e996f509 | 881 | #if TARGET_API_MAC_OSX |
9d8aca48 | 882 | return SendEventToEventTargetWithOptions( event, |
8638e69b | 883 | HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions ); |
e996f509 | 884 | #else |
9d8aca48 | 885 | #pragma unused(inOptions) |
6cce68ea | 886 | return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) ); |
e996f509 | 887 | #endif |
21fd5529 SC |
888 | } |
889 | ||
9d8aca48 | 890 | OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions ) |
21fd5529 | 891 | { |
6cce68ea | 892 | wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess ); |
8638e69b | 893 | |
6cce68ea | 894 | event.SetParameter<HICommand>(kEventParamDirectObject,command); |
8638e69b | 895 | |
6cce68ea | 896 | return SendEvent( event , inOptions ); |
21fd5529 SC |
897 | } |
898 | ||
9d8aca48 | 899 | OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions ) |
21fd5529 | 900 | { |
6cce68ea | 901 | HICommand command; |
8638e69b | 902 | |
6cce68ea SC |
903 | memset( &command, 0 , sizeof(command) ); |
904 | command.commandID = commandID; | |
905 | return SendHICommand( command , inOptions ); | |
21fd5529 SC |
906 | } |
907 | ||
9d8aca48 | 908 | void wxMacControl::Flash( ControlPartCode part , UInt32 ticks ) |
21fd5529 | 909 | { |
6cce68ea | 910 | unsigned long finalTicks; |
8638e69b | 911 | |
6cce68ea SC |
912 | HiliteControl( m_controlRef , part ); |
913 | Delay( ticks , &finalTicks ); | |
914 | HiliteControl( m_controlRef , kControlNoPart ); | |
21fd5529 SC |
915 | } |
916 | ||
7f7b52b4 | 917 | SInt32 wxMacControl::GetValue() const |
9d8aca48 | 918 | { |
6cce68ea | 919 | return ::GetControl32BitValue( m_controlRef ); |
7f7b52b4 SC |
920 | } |
921 | ||
922 | SInt32 wxMacControl::GetMaximum() const | |
9d8aca48 | 923 | { |
6cce68ea | 924 | return ::GetControl32BitMaximum( m_controlRef ); |
7f7b52b4 SC |
925 | } |
926 | ||
927 | SInt32 wxMacControl::GetMinimum() const | |
9d8aca48 | 928 | { |
6cce68ea | 929 | return ::GetControl32BitMinimum( m_controlRef ); |
7f7b52b4 SC |
930 | } |
931 | ||
9d8aca48 WS |
932 | void wxMacControl::SetValue( SInt32 v ) |
933 | { | |
6cce68ea | 934 | ::SetControl32BitValue( m_controlRef , v ); |
7f7b52b4 SC |
935 | } |
936 | ||
9d8aca48 WS |
937 | void wxMacControl::SetMinimum( SInt32 v ) |
938 | { | |
6cce68ea | 939 | ::SetControl32BitMinimum( m_controlRef , v ); |
7f7b52b4 SC |
940 | } |
941 | ||
9d8aca48 WS |
942 | void wxMacControl::SetMaximum( SInt32 v ) |
943 | { | |
6cce68ea | 944 | ::SetControl32BitMaximum( m_controlRef , v ); |
7f7b52b4 SC |
945 | } |
946 | ||
947 | void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) | |
948 | { | |
6cce68ea SC |
949 | ::SetControl32BitMinimum( m_controlRef , minimum ); |
950 | ::SetControl32BitMaximum( m_controlRef , maximum ); | |
951 | ::SetControl32BitValue( m_controlRef , value ); | |
7f7b52b4 SC |
952 | } |
953 | ||
9d8aca48 | 954 | OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart ) |
5ca0d812 | 955 | { |
6cce68ea | 956 | return SetKeyboardFocus( GetControlOwner( m_controlRef ), m_controlRef, focusPart ); |
5ca0d812 SC |
957 | } |
958 | ||
9d8aca48 | 959 | bool wxMacControl::HasFocus() const |
5ca0d812 | 960 | { |
6cce68ea SC |
961 | ControlRef control; |
962 | GetKeyboardFocus( GetUserFocusWindow() , &control ); | |
963 | return control == m_controlRef; | |
5ca0d812 SC |
964 | } |
965 | ||
fb5246be | 966 | void wxMacControl::SetNeedsFocusRect( bool needs ) |
9b89f11a | 967 | { |
6cce68ea | 968 | m_needsFocusRect = needs; |
9b89f11a SC |
969 | } |
970 | ||
9d8aca48 | 971 | bool wxMacControl::NeedsFocusRect() const |
5ca0d812 | 972 | { |
6cce68ea | 973 | return m_needsFocusRect; |
5ca0d812 SC |
974 | } |
975 | ||
9d8aca48 | 976 | void wxMacControl::VisibilityChanged(bool shown) |
29d91661 SC |
977 | { |
978 | } | |
979 | ||
89a66f11 SC |
980 | void wxMacControl::SuperChangedPosition() |
981 | { | |
982 | } | |
983 | ||
9d8aca48 | 984 | void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) |
29d91661 | 985 | { |
6cce68ea | 986 | m_font = font; |
9d8aca48 WS |
987 | ControlFontStyleRec fontStyle; |
988 | if ( font.MacGetThemeFontID() != kThemeCurrentPortFont ) | |
989 | { | |
8638e69b | 990 | switch ( font.MacGetThemeFontID() ) |
9d8aca48 | 991 | { |
8638e69b | 992 | case kThemeSmallSystemFont : |
6cce68ea SC |
993 | fontStyle.font = kControlFontSmallSystemFont; |
994 | break; | |
8638e69b DS |
995 | |
996 | case 109 : // mini font | |
6cce68ea SC |
997 | fontStyle.font = -5; |
998 | break; | |
8638e69b DS |
999 | |
1000 | case kThemeSystemFont : | |
6cce68ea SC |
1001 | fontStyle.font = kControlFontBigSystemFont; |
1002 | break; | |
8638e69b DS |
1003 | |
1004 | default : | |
6cce68ea SC |
1005 | fontStyle.font = kControlFontBigSystemFont; |
1006 | break; | |
9d8aca48 | 1007 | } |
8638e69b | 1008 | |
6cce68ea | 1009 | fontStyle.flags = kControlUseFontMask; |
9d8aca48 WS |
1010 | } |
1011 | else | |
1012 | { | |
6cce68ea SC |
1013 | fontStyle.font = font.MacGetFontNum(); |
1014 | fontStyle.style = font.MacGetFontStyle(); | |
1015 | fontStyle.size = font.MacGetFontSize(); | |
1016 | fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask; | |
9d8aca48 | 1017 | } |
29d91661 | 1018 | |
6cce68ea SC |
1019 | fontStyle.just = teJustLeft; |
1020 | fontStyle.flags |= kControlUseJustMask; | |
29d91661 | 1021 | if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL ) |
6cce68ea | 1022 | fontStyle.just = teJustCenter; |
29d91661 | 1023 | else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT ) |
6cce68ea | 1024 | fontStyle.just = teJustRight; |
29d91661 | 1025 | |
9d8aca48 | 1026 | |
29d91661 SC |
1027 | // we only should do this in case of a non-standard color, as otherwise 'disabled' controls |
1028 | // won't get grayed out by the system anymore | |
9d8aca48 | 1029 | |
29d91661 SC |
1030 | if ( foreground != *wxBLACK ) |
1031 | { | |
6cce68ea SC |
1032 | fontStyle.foreColor = MAC_WXCOLORREF( foreground.GetPixel() ); |
1033 | fontStyle.flags |= kControlUseForeColorMask; | |
29d91661 | 1034 | } |
9d8aca48 WS |
1035 | |
1036 | ::SetControlFontStyle( m_controlRef , &fontStyle ); | |
29d91661 SC |
1037 | } |
1038 | ||
9d8aca48 | 1039 | void wxMacControl::SetBackground( const wxBrush &WXUNUSED(brush) ) |
7ea087b7 | 1040 | { |
9d8aca48 | 1041 | // TODO |
7ea087b7 SC |
1042 | // setting up a color proc is not recommended anymore |
1043 | } | |
1044 | ||
7f7b52b4 SC |
1045 | void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum ) |
1046 | { | |
6cce68ea SC |
1047 | ::SetControl32BitMinimum( m_controlRef , minimum ); |
1048 | ::SetControl32BitMaximum( m_controlRef , maximum ); | |
7f7b52b4 SC |
1049 | } |
1050 | ||
8638e69b | 1051 | short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ) |
5ca0d812 | 1052 | { |
6cce68ea | 1053 | return HandleControlKey( m_controlRef , keyCode , charCode , modifiers ); |
5ca0d812 SC |
1054 | } |
1055 | ||
1056 | void wxMacControl::SetActionProc( ControlActionUPP actionProc ) | |
1057 | { | |
6cce68ea | 1058 | SetControlAction( m_controlRef , actionProc ); |
5ca0d812 SC |
1059 | } |
1060 | ||
1061 | void wxMacControl::SetViewSize( SInt32 viewSize ) | |
1062 | { | |
6cce68ea | 1063 | SetControlViewSize(m_controlRef , viewSize ); |
5ca0d812 SC |
1064 | } |
1065 | ||
1066 | SInt32 wxMacControl::GetViewSize() const | |
1067 | { | |
6cce68ea | 1068 | return GetControlViewSize( m_controlRef ); |
5ca0d812 SC |
1069 | } |
1070 | ||
9d8aca48 | 1071 | bool wxMacControl::IsVisible() const |
5ca0d812 | 1072 | { |
6cce68ea | 1073 | return IsControlVisible( m_controlRef ); |
5ca0d812 SC |
1074 | } |
1075 | ||
9d8aca48 | 1076 | void wxMacControl::SetVisibility( bool visible , bool redraw ) |
5ca0d812 | 1077 | { |
6cce68ea | 1078 | SetControlVisibility( m_controlRef , visible , redraw ); |
5ca0d812 SC |
1079 | } |
1080 | ||
9d8aca48 | 1081 | bool wxMacControl::IsEnabled() const |
5ca0d812 SC |
1082 | { |
1083 | #if TARGET_API_MAC_OSX | |
6cce68ea | 1084 | return IsControlEnabled( m_controlRef ); |
5ca0d812 | 1085 | #else |
6cce68ea | 1086 | return IsControlActive( m_controlRef ); |
5ca0d812 SC |
1087 | #endif |
1088 | } | |
1089 | ||
9d8aca48 | 1090 | bool wxMacControl::IsActive() const |
5ca0d812 | 1091 | { |
6cce68ea | 1092 | return IsControlActive( m_controlRef ); |
5ca0d812 SC |
1093 | } |
1094 | ||
9d8aca48 | 1095 | void wxMacControl::Enable( bool enable ) |
5ca0d812 SC |
1096 | { |
1097 | #if TARGET_API_MAC_OSX | |
1098 | if ( enable ) | |
6cce68ea | 1099 | EnableControl( m_controlRef ); |
5ca0d812 | 1100 | else |
6cce68ea | 1101 | DisableControl( m_controlRef ); |
5ca0d812 SC |
1102 | #else |
1103 | if ( enable ) | |
6cce68ea | 1104 | ActivateControl( m_controlRef ); |
5ca0d812 | 1105 | else |
6cce68ea | 1106 | DeactivateControl( m_controlRef ); |
5ca0d812 SC |
1107 | #endif |
1108 | } | |
1109 | ||
9d8aca48 | 1110 | void wxMacControl::SetDrawingEnabled( bool enable ) |
5ca0d812 SC |
1111 | { |
1112 | #if TARGET_API_MAC_OSX | |
6cce68ea | 1113 | HIViewSetDrawingEnabled( m_controlRef , enable ); |
5ca0d812 SC |
1114 | #endif |
1115 | } | |
1116 | ||
23ad132c | 1117 | #if TARGET_API_MAC_OSX |
9d8aca48 | 1118 | bool wxMacControl::GetNeedsDisplay() const |
5ca0d812 SC |
1119 | { |
1120 | #if TARGET_API_MAC_OSX | |
92346151 SC |
1121 | if ( m_isCompositing ) |
1122 | { | |
6cce68ea | 1123 | return HIViewGetNeedsDisplay( m_controlRef ); |
fb5246be WS |
1124 | } |
1125 | else | |
5ca0d812 | 1126 | #endif |
fb5246be WS |
1127 | { |
1128 | if ( !IsVisible() ) | |
6cce68ea | 1129 | return false; |
fb5246be | 1130 | |
6cce68ea SC |
1131 | Rect controlBounds; |
1132 | GetControlBounds( m_controlRef, &controlBounds ); | |
1133 | RgnHandle rgn = NewRgn(); | |
1134 | GetWindowRegion ( GetControlOwner( m_controlRef ) , kWindowUpdateRgn , rgn ); | |
1135 | Boolean intersect = RectInRgn ( &controlBounds , rgn ); | |
1136 | DisposeRgn( rgn ); | |
8638e69b | 1137 | |
6cce68ea | 1138 | return intersect; |
fb5246be | 1139 | } |
5ca0d812 | 1140 | } |
1f1c8bd4 | 1141 | #endif |
5ca0d812 | 1142 | |
1f1c8bd4 | 1143 | void wxMacControl::SetNeedsDisplay( RgnHandle where ) |
5ca0d812 | 1144 | { |
1f1c8bd4 | 1145 | if ( !IsVisible() ) |
6cce68ea | 1146 | return; |
fb5246be | 1147 | |
5ca0d812 | 1148 | #if TARGET_API_MAC_OSX |
1f1c8bd4 SC |
1149 | if ( m_isCompositing ) |
1150 | { | |
6cce68ea | 1151 | HIViewSetNeedsDisplayInRegion( m_controlRef , where , true ); |
1f1c8bd4 | 1152 | } |
5ca0d812 | 1153 | else |
5ca0d812 | 1154 | #endif |
1f1c8bd4 | 1155 | { |
6cce68ea SC |
1156 | Rect controlBounds; |
1157 | GetControlBounds( m_controlRef, &controlBounds ); | |
1158 | RgnHandle update = NewRgn(); | |
1159 | CopyRgn( where , update ); | |
1160 | OffsetRgn( update , controlBounds.left , controlBounds.top ); | |
1161 | InvalWindowRgn( GetControlOwner( m_controlRef) , update ); | |
1f1c8bd4 | 1162 | } |
5ca0d812 | 1163 | } |
1f1c8bd4 SC |
1164 | |
1165 | void wxMacControl::SetNeedsDisplay( Rect* where ) | |
1166 | { | |
1167 | if ( !IsVisible() ) | |
6cce68ea | 1168 | return; |
1f1c8bd4 SC |
1169 | |
1170 | #if TARGET_API_MAC_OSX | |
1171 | if ( m_isCompositing ) | |
1172 | { | |
1173 | if ( where != NULL ) | |
1174 | { | |
6cce68ea SC |
1175 | RgnHandle update = NewRgn(); |
1176 | RectRgn( update , where ); | |
1177 | HIViewSetNeedsDisplayInRegion( m_controlRef , update , true ); | |
1178 | DisposeRgn( update ); | |
1f1c8bd4 SC |
1179 | } |
1180 | else | |
6cce68ea | 1181 | HIViewSetNeedsDisplay( m_controlRef , true ); |
1f1c8bd4 SC |
1182 | } |
1183 | else | |
23ad132c | 1184 | #endif |
1f1c8bd4 | 1185 | { |
6cce68ea | 1186 | Rect controlBounds; |
8638e69b | 1187 | |
6cce68ea | 1188 | GetControlBounds( m_controlRef, &controlBounds ); |
1f1c8bd4 SC |
1189 | if ( where ) |
1190 | { | |
6cce68ea SC |
1191 | Rect whereLocal = *where; |
1192 | OffsetRect( &whereLocal , controlBounds.left , controlBounds.top ); | |
1193 | SectRect( &controlBounds , &whereLocal, &controlBounds ); | |
1f1c8bd4 | 1194 | } |
8638e69b | 1195 | |
6cce68ea | 1196 | InvalWindowRect( GetControlOwner( m_controlRef) , &controlBounds ); |
1f1c8bd4 SC |
1197 | } |
1198 | } | |
5ca0d812 | 1199 | |
9d8aca48 | 1200 | void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to ) |
5ca0d812 SC |
1201 | { |
1202 | #if TARGET_API_MAC_OSX | |
9b89f11a SC |
1203 | if ( from->m_peer->MacGetTopLevelWindow()->MacUsesCompositing() ) |
1204 | { | |
6cce68ea | 1205 | HIPoint hiPoint; |
8638e69b | 1206 | |
6cce68ea SC |
1207 | hiPoint.x = pt->x; |
1208 | hiPoint.y = pt->y; | |
1209 | HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef ); | |
1210 | pt->x = (int)hiPoint.x; | |
1211 | pt->y = (int)hiPoint.y; | |
9b89f11a SC |
1212 | } |
1213 | else | |
5ca0d812 | 1214 | #endif |
9b89f11a | 1215 | { |
6cce68ea | 1216 | Rect fromRect, toRect; |
8638e69b | 1217 | |
6cce68ea SC |
1218 | GetControlBounds( from->m_controlRef , &fromRect ); |
1219 | GetControlBounds( to->m_controlRef , &toRect ); | |
1f1c8bd4 | 1220 | if ( from->m_isRootControl ) |
6cce68ea | 1221 | fromRect.left = fromRect.top = 0; |
1f1c8bd4 | 1222 | if ( to->m_isRootControl ) |
6cce68ea | 1223 | toRect.left = toRect.top = 0; |
fb5246be | 1224 | |
6cce68ea SC |
1225 | pt->x = pt->x + fromRect.left - toRect.left; |
1226 | pt->y = pt->y + fromRect.top - toRect.top; | |
9b89f11a | 1227 | } |
5ca0d812 SC |
1228 | } |
1229 | ||
9d8aca48 | 1230 | void wxMacControl::SetRect( Rect *r ) |
5ca0d812 SC |
1231 | { |
1232 | #if TARGET_API_MAC_OSX | |
9b89f11a SC |
1233 | if ( m_isCompositing ) |
1234 | { | |
1235 | //A HIRect is actually a CGRect on OSX - which consists of two structures - | |
1236 | //CGPoint and CGSize, which have two floats each | |
6cce68ea SC |
1237 | HIRect hir = { { r->left , r->top }, { r->right - r->left , r->bottom - r->top } }; |
1238 | HIViewSetFrame ( m_controlRef , &hir ); | |
1239 | // eventuall we might have to do a SetVisibility( false , true ); | |
1240 | // before and a SetVisibility( true , true ); after | |
9b89f11a SC |
1241 | } |
1242 | else | |
5ca0d812 | 1243 | #endif |
9b89f11a | 1244 | { |
6cce68ea | 1245 | bool vis = IsVisible(); |
1f1c8bd4 SC |
1246 | if ( vis ) |
1247 | { | |
6cce68ea SC |
1248 | Rect former; |
1249 | GetControlBounds( m_controlRef , &former ); | |
1250 | InvalWindowRect( GetControlOwner( m_controlRef ) , &former ); | |
1f1c8bd4 | 1251 | } |
fb5246be | 1252 | |
6cce68ea | 1253 | Rect controlBounds = *r; |
fb5246be | 1254 | |
92346151 SC |
1255 | // since the rect passed in is always (even in non-compositing) relative |
1256 | // to the (native) parent, we have to adjust to window relative here | |
6cce68ea | 1257 | wxMacControl* parent = m_peer->GetParent()->GetPeer(); |
8638e69b | 1258 | if ( !parent->m_isRootControl ) |
1f1c8bd4 | 1259 | { |
6cce68ea SC |
1260 | Rect superRect; |
1261 | GetControlBounds( parent->m_controlRef , &superRect ); | |
1262 | OffsetRect( &controlBounds , superRect.left , superRect.top ); | |
1f1c8bd4 | 1263 | } |
fb5246be | 1264 | |
6cce68ea | 1265 | SetControlBounds( m_controlRef , &controlBounds ); |
1f1c8bd4 | 1266 | if ( vis ) |
6cce68ea | 1267 | InvalWindowRect( GetControlOwner( m_controlRef ) , &controlBounds ); |
9b89f11a | 1268 | } |
5ca0d812 SC |
1269 | } |
1270 | ||
9d8aca48 | 1271 | void wxMacControl::GetRect( Rect *r ) |
5ca0d812 | 1272 | { |
6cce68ea | 1273 | GetControlBounds( m_controlRef , r ); |
8638e69b | 1274 | if ( !m_isCompositing ) |
9b89f11a | 1275 | { |
fb5246be | 1276 | // correct the case of the root control |
1f1c8bd4 SC |
1277 | if ( m_isRootControl ) |
1278 | { | |
6cce68ea SC |
1279 | WindowRef wr = GetControlOwner( m_controlRef ); |
1280 | GetWindowBounds( wr , kWindowContentRgn , r ); | |
1281 | r->right -= r->left; | |
1282 | r->bottom -= r->top; | |
1283 | r->left = 0; | |
1284 | r->top = 0; | |
1f1c8bd4 | 1285 | } |
fb5246be | 1286 | else |
1f1c8bd4 | 1287 | { |
6cce68ea | 1288 | wxMacControl* parent = m_peer->GetParent()->GetPeer(); |
8638e69b | 1289 | if ( !parent->m_isRootControl ) |
1f1c8bd4 | 1290 | { |
6cce68ea SC |
1291 | Rect superRect; |
1292 | GetControlBounds( parent->m_controlRef , &superRect ); | |
1293 | OffsetRect( r , -superRect.left , -superRect.top ); | |
1f1c8bd4 SC |
1294 | } |
1295 | } | |
9b89f11a | 1296 | } |
5ca0d812 SC |
1297 | } |
1298 | ||
9d8aca48 | 1299 | void wxMacControl::GetRectInWindowCoords( Rect *r ) |
5ca0d812 | 1300 | { |
6cce68ea | 1301 | UMAGetControlBoundsInWindowCoords( m_controlRef , r ); |
5ca0d812 SC |
1302 | } |
1303 | ||
9d8aca48 | 1304 | void wxMacControl::GetBestRect( Rect *r ) |
5ca0d812 | 1305 | { |
6cce68ea | 1306 | short baselineoffset; |
8638e69b | 1307 | |
6cce68ea | 1308 | GetBestControlRect( m_controlRef , r , &baselineoffset ); |
5ca0d812 SC |
1309 | } |
1310 | ||
fb5246be | 1311 | void wxMacControl::SetLabel( const wxString &title ) |
5ca0d812 | 1312 | { |
10a59880 RD |
1313 | wxFontEncoding encoding; |
1314 | ||
1315 | if ( m_font.Ok() ) | |
1316 | encoding = m_font.GetEncoding(); | |
1317 | else | |
1318 | encoding = wxFont::GetDefaultEncoding(); | |
9d8aca48 | 1319 | |
6cce68ea | 1320 | UMASetControlTitle( m_controlRef , title , encoding ); |
5ca0d812 SC |
1321 | } |
1322 | ||
1323 | void wxMacControl::GetFeatures( UInt32 * features ) | |
1324 | { | |
6cce68ea | 1325 | GetControlFeatures( m_controlRef , features ); |
5ca0d812 SC |
1326 | } |
1327 | ||
9d8aca48 | 1328 | OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region ) |
5ca0d812 | 1329 | { |
6cce68ea | 1330 | OSStatus err = GetControlRegion( m_controlRef , partCode , region ); |
8638e69b | 1331 | if ( !m_isCompositing ) |
1f1c8bd4 SC |
1332 | { |
1333 | if ( !m_isRootControl ) | |
1334 | { | |
6cce68ea | 1335 | Rect r; |
8638e69b | 1336 | |
6cce68ea | 1337 | GetControlBounds(m_controlRef, &r ); |
1f1c8bd4 | 1338 | if ( !EmptyRgn( region ) ) |
6cce68ea | 1339 | OffsetRgn( region , -r.left , -r.top ); |
1f1c8bd4 SC |
1340 | } |
1341 | } | |
8638e69b | 1342 | |
6cce68ea | 1343 | return err; |
5ca0d812 SC |
1344 | } |
1345 | ||
9d8aca48 | 1346 | OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other ) |
5ca0d812 SC |
1347 | { |
1348 | #if TARGET_API_MAC_OSX | |
9d8aca48 | 1349 | return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow, |
6cce68ea | 1350 | (other != NULL) ? other->m_controlRef : NULL); |
5ca0d812 | 1351 | #else |
6cce68ea | 1352 | return 0; |
5ca0d812 SC |
1353 | #endif |
1354 | } | |
1355 | ||
5ca0d812 SC |
1356 | #if TARGET_API_MAC_OSX |
1357 | // SetNeedsDisplay would not invalidate the children | |
1358 | static void InvalidateControlAndChildren( HIViewRef control ) | |
1359 | { | |
6cce68ea SC |
1360 | HIViewSetNeedsDisplay( control , true ); |
1361 | UInt16 childrenCount = 0; | |
1362 | OSStatus err = CountSubControls( control , &childrenCount ); | |
5ca0d812 | 1363 | if ( err == errControlIsNotEmbedder ) |
6cce68ea | 1364 | return; |
8638e69b | 1365 | |
6cce68ea | 1366 | wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") ); |
5ca0d812 | 1367 | |
6cce68ea | 1368 | for ( UInt16 i = childrenCount; i >=1; --i ) |
5ca0d812 | 1369 | { |
6cce68ea | 1370 | HIViewRef child; |
8638e69b | 1371 | |
6cce68ea | 1372 | err = GetIndexedSubControl( control , i , & child ); |
5ca0d812 | 1373 | if ( err == errControlIsNotEmbedder ) |
6cce68ea | 1374 | return; |
8638e69b | 1375 | |
6cce68ea | 1376 | InvalidateControlAndChildren( child ); |
5ca0d812 SC |
1377 | } |
1378 | } | |
1379 | #endif | |
1380 | ||
9d8aca48 | 1381 | void wxMacControl::InvalidateWithChildren() |
5ca0d812 SC |
1382 | { |
1383 | #if TARGET_API_MAC_OSX | |
6cce68ea | 1384 | InvalidateControlAndChildren( m_controlRef ); |
5ca0d812 SC |
1385 | #endif |
1386 | } | |
1387 | ||
fb5246be | 1388 | void wxMacControl::ScrollRect( wxRect *r , int dx , int dy ) |
5ca0d812 | 1389 | { |
6cce68ea | 1390 | wxASSERT( r != NULL ); |
8638e69b | 1391 | |
5ca0d812 | 1392 | #if TARGET_API_MAC_OSX |
fb5246be WS |
1393 | if ( m_isCompositing ) |
1394 | { | |
6cce68ea SC |
1395 | HIRect scrollarea = CGRectMake( r->x , r->y , r->width , r->height); |
1396 | HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy ); | |
fb5246be WS |
1397 | } |
1398 | else | |
5ca0d812 | 1399 | #endif |
fb5246be | 1400 | { |
6cce68ea SC |
1401 | Rect bounds; |
1402 | ||
1403 | GetControlBounds( m_controlRef , &bounds ); | |
1404 | bounds.left += r->x; | |
1405 | bounds.top += r->y; | |
1406 | bounds.bottom = bounds.top + r->height; | |
1407 | bounds.right = bounds.left + r->width; | |
1408 | wxMacWindowClipper clip( m_peer ); | |
1409 | RgnHandle updateRgn = NewRgn(); | |
1410 | ::ScrollRect( &bounds , dx , dy , updateRgn ); | |
1411 | InvalWindowRgn( GetControlOwner( m_controlRef ) , updateRgn ); | |
8638e69b | 1412 | DisposeRgn( updateRgn ); |
fb5246be | 1413 | } |
5ca0d812 SC |
1414 | } |
1415 | ||
6cce68ea SC |
1416 | OSType wxMacCreator = 'WXMC'; |
1417 | OSType wxMacControlProperty = 'MCCT'; | |
1418 | ||
88a7a4e1 | 1419 | void wxMacControl::SetReferenceInNativeControl() |
6cce68ea SC |
1420 | { |
1421 | void * data = this; | |
1422 | verify_noerr( SetControlProperty ( m_controlRef , | |
1423 | wxMacCreator,wxMacControlProperty, sizeof(data), &data ) ); | |
1424 | } | |
1425 | ||
88a7a4e1 | 1426 | wxMacControl* wxMacControl::GetReferenceFromNativeControl(ControlRef control) |
6cce68ea SC |
1427 | { |
1428 | wxMacControl* ctl = NULL; | |
1429 | UInt32 actualSize; | |
1430 | if ( GetControlProperty( control ,wxMacCreator,wxMacControlProperty, sizeof(ctl) , | |
1431 | &actualSize , &ctl ) == noErr ) | |
1432 | { | |
1433 | return ctl; | |
1434 | } | |
1435 | return NULL; | |
1436 | } | |
1437 | ||
1438 | // ============================================================================ | |
1439 | // DataBrowser Wrapper | |
1440 | // ============================================================================ | |
1441 | // | |
1442 | // basing on DataBrowserItemIDs | |
1443 | // | |
1444 | ||
1445 | pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc( | |
1446 | ControlRef browser, | |
1447 | DataBrowserItemID itemID, | |
1448 | DataBrowserItemNotification message, | |
1449 | DataBrowserItemDataRef itemData ) | |
1450 | { | |
1451 | wxMacDataBrowserControl* ctl = dynamic_cast<wxMacDataBrowserControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) ); | |
1452 | if ( ctl != 0 ) | |
1453 | { | |
1454 | ctl->ItemNotification(itemID, message, itemData); | |
1455 | } | |
1456 | } | |
1457 | ||
1458 | pascal OSStatus wxMacDataBrowserControl::DataBrowserGetSetItemDataProc( | |
1459 | ControlRef browser, | |
1460 | DataBrowserItemID itemID, | |
1461 | DataBrowserPropertyID property, | |
1462 | DataBrowserItemDataRef itemData, | |
1463 | Boolean changeValue ) | |
1464 | { | |
1465 | OSStatus err = errDataBrowserPropertyNotSupported; | |
1466 | ||
1467 | wxMacDataBrowserControl* ctl = dynamic_cast<wxMacDataBrowserControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) ); | |
1468 | if ( ctl != 0 ) | |
1469 | { | |
1470 | err = ctl->GetSetItemData(itemID, property, itemData, changeValue); | |
1471 | } | |
1472 | return err; | |
1473 | } | |
1474 | ||
1475 | pascal Boolean wxMacDataBrowserControl::DataBrowserCompareProc( | |
88a7a4e1 WS |
1476 | ControlRef browser, |
1477 | DataBrowserItemID itemOneID, | |
1478 | DataBrowserItemID itemTwoID, | |
1479 | DataBrowserPropertyID sortProperty) | |
6cce68ea SC |
1480 | { |
1481 | wxMacDataBrowserControl* ctl = dynamic_cast<wxMacDataBrowserControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) ); | |
1482 | if ( ctl != 0 ) | |
1483 | { | |
1484 | return ctl->CompareItems(itemOneID, itemTwoID, sortProperty); | |
1485 | } | |
1486 | return false; | |
1487 | } | |
1488 | ||
1489 | DataBrowserItemDataUPP gDataBrowserItemDataUPP = NULL; | |
1490 | DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP = NULL; | |
1491 | DataBrowserItemCompareUPP gDataBrowserItemCompareUPP = NULL; | |
1492 | ||
1493 | wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow* peer, const wxPoint& pos, const wxSize& size, long style) : wxMacControl( peer ) | |
88a7a4e1 | 1494 | { |
6cce68ea SC |
1495 | Rect bounds = wxMacGetBoundsForControl( peer, pos, size ); |
1496 | OSStatus err = ::CreateDataBrowserControl( | |
1497 | MAC_WXHWND(peer->MacGetTopLevelWindowRef()), | |
1498 | &bounds, kDataBrowserListView, &m_controlRef ); | |
1499 | SetReferenceInNativeControl(); | |
1500 | verify_noerr( err ); | |
1501 | if ( gDataBrowserItemCompareUPP == NULL ) | |
1502 | gDataBrowserItemCompareUPP = NewDataBrowserItemCompareUPP(DataBrowserCompareProc); | |
1503 | if ( gDataBrowserItemDataUPP == NULL ) | |
1504 | gDataBrowserItemDataUPP = NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc); | |
1505 | if ( gDataBrowserItemNotificationUPP == NULL ) | |
1506 | { | |
1507 | gDataBrowserItemNotificationUPP = | |
1508 | #if TARGET_API_MAC_OSX | |
1509 | (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc); | |
1510 | #else | |
1511 | NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc); | |
1512 | #endif | |
1513 | } | |
1514 | ||
1515 | DataBrowserCallbacks callbacks; | |
1516 | InitializeDataBrowserCallbacks( &callbacks, kDataBrowserLatestCallbacks ); | |
1517 | ||
1518 | callbacks.u.v1.itemDataCallback = gDataBrowserItemDataUPP; | |
1519 | callbacks.u.v1.itemCompareCallback = gDataBrowserItemCompareUPP; | |
1520 | callbacks.u.v1.itemNotificationCallback = gDataBrowserItemNotificationUPP; | |
1521 | SetCallbacks( &callbacks ); | |
1522 | ||
1523 | } | |
1524 | ||
1525 | OSStatus wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container, | |
1526 | Boolean recurse, | |
1527 | DataBrowserItemState state, | |
88a7a4e1 | 1528 | UInt32 *numItems) const |
6cce68ea | 1529 | { |
88a7a4e1 | 1530 | return GetDataBrowserItemCount( m_controlRef, container, recurse, state, numItems ); |
6cce68ea SC |
1531 | } |
1532 | ||
1533 | OSStatus wxMacDataBrowserControl::GetItems( DataBrowserItemID container, | |
1534 | Boolean recurse, | |
1535 | DataBrowserItemState state, | |
88a7a4e1 | 1536 | Handle items) const |
6cce68ea | 1537 | { |
88a7a4e1 | 1538 | return GetDataBrowserItems( m_controlRef, container, recurse, state, items ); |
6cce68ea SC |
1539 | } |
1540 | ||
1541 | OSStatus wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options ) | |
1542 | { | |
1543 | return SetDataBrowserSelectionFlags( m_controlRef, options ); | |
1544 | } | |
1545 | ||
1546 | OSStatus wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc *columnDesc, | |
1547 | DataBrowserTableViewColumnIndex position ) | |
1548 | { | |
1549 | return AddDataBrowserListViewColumn( m_controlRef, columnDesc, position ); | |
1550 | } | |
1551 | ||
1552 | OSStatus wxMacDataBrowserControl::AutoSizeColumns() | |
1553 | { | |
1554 | return AutoSizeDataBrowserListViewColumns(m_controlRef); | |
1555 | } | |
1556 | ||
1557 | OSStatus wxMacDataBrowserControl::SetHasScrollBars( bool horiz, bool vert ) | |
1558 | { | |
1559 | return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert ); | |
1560 | } | |
1561 | ||
1562 | OSStatus wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) | |
1563 | { | |
1564 | return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle ); | |
1565 | } | |
1566 | ||
1567 | OSStatus wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height) | |
1568 | { | |
1569 | return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height ); | |
1570 | } | |
1571 | ||
1572 | OSStatus wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16 *height) | |
1573 | { | |
1574 | return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height ); | |
1575 | } | |
1576 | ||
1577 | OSStatus wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks *callbacks) | |
1578 | { | |
1579 | return SetDataBrowserCallbacks( m_controlRef, callbacks ); | |
1580 | } | |
1581 | ||
88a7a4e1 | 1582 | OSStatus wxMacDataBrowserControl::UpdateItems( |
6cce68ea SC |
1583 | DataBrowserItemID container, |
1584 | UInt32 numItems, | |
1585 | const DataBrowserItemID *items, | |
1586 | DataBrowserPropertyID preSortProperty, | |
1587 | DataBrowserPropertyID propertyID ) const | |
1588 | { | |
1589 | return UpdateDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty, propertyID ); | |
1590 | } | |
1591 | ||
1592 | bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item ) const | |
1593 | { | |
1594 | return IsDataBrowserItemSelected( m_controlRef, item ); | |
1595 | } | |
1596 | ||
1597 | OSStatus wxMacDataBrowserControl::AddItems( | |
1598 | DataBrowserItemID container, | |
1599 | UInt32 numItems, | |
1600 | const DataBrowserItemID *items, | |
1601 | DataBrowserPropertyID preSortProperty ) | |
1602 | { | |
1603 | return AddDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty ); | |
1604 | } | |
1605 | ||
1606 | OSStatus wxMacDataBrowserControl::RemoveItems( | |
1607 | DataBrowserItemID container, | |
1608 | UInt32 numItems, | |
1609 | const DataBrowserItemID *items, | |
1610 | DataBrowserPropertyID preSortProperty ) | |
1611 | { | |
1612 | return RemoveDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty ); | |
1613 | } | |
1614 | ||
1615 | OSStatus wxMacDataBrowserControl::RevealItem( | |
1616 | DataBrowserItemID item, | |
1617 | DataBrowserPropertyID propertyID, | |
1618 | DataBrowserRevealOptions options ) const | |
1619 | { | |
1620 | return RevealDataBrowserItem( m_controlRef, item, propertyID, options ); | |
1621 | } | |
1622 | ||
1623 | OSStatus wxMacDataBrowserControl::SetSelectedItems( | |
1624 | UInt32 numItems, | |
1625 | const DataBrowserItemID *items, | |
1626 | DataBrowserSetOption operation ) | |
1627 | { | |
1628 | return SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation ); | |
1629 | } | |
1630 | ||
1631 | OSStatus wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const | |
1632 | { | |
1633 | return GetDataBrowserSelectionAnchor( m_controlRef, first, last ); | |
1634 | } | |
1635 | ||
1636 | OSStatus wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const | |
1637 | { | |
1638 | return GetDataBrowserTableViewItemID( m_controlRef, row, item ); | |
1639 | } | |
1640 | ||
1641 | OSStatus wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item, DataBrowserTableViewRowIndex * row ) const | |
1642 | { | |
1643 | return GetDataBrowserTableViewItemRow( m_controlRef, item, row ); | |
1644 | } | |
1645 | ||
88a7a4e1 | 1646 | OSStatus wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height ) |
6cce68ea | 1647 | { |
88a7a4e1 | 1648 | return SetDataBrowserTableViewRowHeight( m_controlRef , height ); |
6cce68ea SC |
1649 | } |
1650 | ||
88a7a4e1 | 1651 | OSStatus wxMacDataBrowserControl::GetDefaultRowHeight( UInt16 * height ) const |
6cce68ea | 1652 | { |
88a7a4e1 | 1653 | return GetDataBrowserTableViewRowHeight( m_controlRef, height ); |
6cce68ea | 1654 | } |
88a7a4e1 WS |
1655 | |
1656 | OSStatus wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item , UInt16 height) | |
6cce68ea SC |
1657 | { |
1658 | return SetDataBrowserTableViewItemRowHeight( m_controlRef, item , height ); | |
1659 | } | |
1660 | ||
88a7a4e1 | 1661 | OSStatus wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const |
6cce68ea SC |
1662 | { |
1663 | return GetDataBrowserTableViewItemRowHeight( m_controlRef, item , height); | |
1664 | } | |
1665 | ||
88a7a4e1 | 1666 | OSStatus wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const |
6cce68ea SC |
1667 | { |
1668 | return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width ); | |
1669 | } | |
1670 | ||
88a7a4e1 | 1671 | OSStatus wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width ) |
6cce68ea SC |
1672 | { |
1673 | return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width ); | |
1674 | } | |
1675 | ||
88a7a4e1 | 1676 | OSStatus wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16 *width ) const |
6cce68ea SC |
1677 | { |
1678 | return GetDataBrowserTableViewColumnWidth( m_controlRef , width ); | |
1679 | } | |
1680 | ||
88a7a4e1 | 1681 | OSStatus wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width ) |
6cce68ea SC |
1682 | { |
1683 | return SetDataBrowserTableViewColumnWidth( m_controlRef , width ); | |
1684 | } | |
1685 | ||
88a7a4e1 | 1686 | OSStatus wxMacDataBrowserControl::GetColumnCount(UInt32* numColumns) const |
6cce68ea SC |
1687 | { |
1688 | return GetDataBrowserTableViewColumnCount( m_controlRef, numColumns); | |
1689 | } | |
1690 | ||
88a7a4e1 | 1691 | OSStatus wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column, |
6cce68ea SC |
1692 | UInt32 *position) const |
1693 | { | |
1694 | return GetDataBrowserTableViewColumnPosition( m_controlRef , column , position); | |
1695 | } | |
1696 | ||
88a7a4e1 | 1697 | OSStatus wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column, UInt32 position) |
6cce68ea SC |
1698 | { |
1699 | return SetDataBrowserTableViewColumnPosition( m_controlRef , column , position); | |
1700 | } | |
1701 | ||
88a7a4e1 | 1702 | OSStatus wxMacDataBrowserControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const |
6cce68ea SC |
1703 | { |
1704 | return GetDataBrowserScrollPosition( m_controlRef , top , left ); | |
1705 | } | |
1706 | ||
88a7a4e1 | 1707 | OSStatus wxMacDataBrowserControl::SetScrollPosition( UInt32 top , UInt32 left ) |
6cce68ea SC |
1708 | { |
1709 | return SetDataBrowserScrollPosition( m_controlRef , top , left ); | |
1710 | } | |
1711 | ||
88a7a4e1 | 1712 | OSStatus wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID *column ) const |
6cce68ea SC |
1713 | { |
1714 | return GetDataBrowserSortProperty( m_controlRef , column ); | |
1715 | } | |
1716 | ||
88a7a4e1 | 1717 | OSStatus wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column ) |
6cce68ea SC |
1718 | { |
1719 | return SetDataBrowserSortProperty( m_controlRef , column ); | |
1720 | } | |
88a7a4e1 WS |
1721 | |
1722 | OSStatus wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder *order ) const | |
6cce68ea SC |
1723 | { |
1724 | return GetDataBrowserSortOrder( m_controlRef , order ); | |
1725 | } | |
1726 | ||
88a7a4e1 | 1727 | OSStatus wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order ) |
6cce68ea SC |
1728 | { |
1729 | return SetDataBrowserSortOrder( m_controlRef , order ); | |
1730 | } | |
1731 | ||
88a7a4e1 WS |
1732 | OSStatus wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property, |
1733 | DataBrowserPropertyFlags *flags ) const | |
6cce68ea SC |
1734 | { |
1735 | return GetDataBrowserPropertyFlags( m_controlRef , property , flags ); | |
1736 | } | |
1737 | ||
88a7a4e1 WS |
1738 | OSStatus wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property, |
1739 | DataBrowserPropertyFlags flags ) | |
6cce68ea SC |
1740 | { |
1741 | return SetDataBrowserPropertyFlags( m_controlRef , property , flags ); | |
1742 | } | |
1743 | ||
88a7a4e1 WS |
1744 | OSStatus wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property, |
1745 | DataBrowserListViewHeaderDesc *desc ) const | |
6cce68ea SC |
1746 | { |
1747 | return GetDataBrowserListViewHeaderDesc( m_controlRef , property , desc ); | |
1748 | } | |
1749 | ||
88a7a4e1 WS |
1750 | OSStatus wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property, |
1751 | DataBrowserListViewHeaderDesc *desc ) | |
6cce68ea | 1752 | { |
88a7a4e1 | 1753 | return SetDataBrowserListViewHeaderDesc( m_controlRef , property , desc ); |
6cce68ea SC |
1754 | } |
1755 | ||
88a7a4e1 WS |
1756 | OSStatus wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property , |
1757 | Boolean expandableRows ) | |
6cce68ea SC |
1758 | { |
1759 | return SetDataBrowserListViewDisclosureColumn( m_controlRef, property, expandableRows); | |
1760 | } | |
1761 | ||
1762 | // ============================================================================ | |
88a7a4e1 | 1763 | // Higher-level Databrowser |
6cce68ea SC |
1764 | // ============================================================================ |
1765 | // | |
1766 | // basing on data item objects | |
1767 | // | |
1768 | ||
1769 | wxMacDataItem::wxMacDataItem() | |
88a7a4e1 | 1770 | { |
6cce68ea SC |
1771 | } |
1772 | ||
88a7a4e1 WS |
1773 | wxMacDataItem::~wxMacDataItem() |
1774 | { | |
6cce68ea | 1775 | } |
88a7a4e1 WS |
1776 | |
1777 | bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *owner , | |
1778 | const wxMacDataItem*, | |
6cce68ea SC |
1779 | DataBrowserPropertyID property) const |
1780 | { | |
1781 | return false; | |
1782 | } | |
1783 | ||
88a7a4e1 | 1784 | OSStatus wxMacDataItem::GetSetData(wxMacDataItemBrowserControl *owner , |
6cce68ea SC |
1785 | DataBrowserPropertyID property, |
1786 | DataBrowserItemDataRef itemData, | |
88a7a4e1 | 1787 | bool changeValue ) |
6cce68ea SC |
1788 | { |
1789 | return errDataBrowserPropertyNotSupported; | |
1790 | } | |
1791 | ||
88a7a4e1 | 1792 | void wxMacDataItem::Notification(wxMacDataItemBrowserControl *owner , |
6cce68ea SC |
1793 | DataBrowserItemNotification message, |
1794 | DataBrowserItemDataRef itemData ) const | |
1795 | { | |
1796 | } | |
1797 | ||
1798 | ||
88a7a4e1 | 1799 | wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style) : |
6cce68ea | 1800 | wxMacDataBrowserControl( peer, pos, size, style ) |
88a7a4e1 | 1801 | { |
6cce68ea SC |
1802 | m_suppressSelection = false; |
1803 | } | |
88a7a4e1 WS |
1804 | |
1805 | wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser) | |
6cce68ea SC |
1806 | { |
1807 | m_former = browser->SuppressSelection(true); | |
1808 | m_browser = browser; | |
1809 | } | |
1810 | ||
1811 | wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor() | |
1812 | { | |
1813 | m_browser->SuppressSelection(m_former); | |
1814 | } | |
1815 | ||
1816 | bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress ) | |
1817 | { | |
1818 | bool former = m_suppressSelection; | |
1819 | m_suppressSelection = suppress; | |
1820 | ||
1821 | return former; | |
1822 | } | |
1823 | ||
88a7a4e1 WS |
1824 | Boolean wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID, |
1825 | DataBrowserItemID itemTwoID, | |
1826 | DataBrowserPropertyID sortProperty) | |
6cce68ea SC |
1827 | { |
1828 | wxMacDataItem* itemOne = (wxMacDataItem*) itemOneID; | |
1829 | wxMacDataItem* itemTwo = (wxMacDataItem*) itemTwoID; | |
1830 | return CompareItems( itemOne , itemTwo , sortProperty ); | |
1831 | } | |
1832 | ||
88a7a4e1 WS |
1833 | Boolean wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem* itemOne, |
1834 | const wxMacDataItem* itemTwo, | |
1835 | DataBrowserPropertyID sortProperty) | |
6cce68ea SC |
1836 | { |
1837 | Boolean retval = false; | |
1838 | if ( itemOne != NULL ) | |
1839 | retval = itemOne->IsLessThan( this , itemTwo , sortProperty); | |
1840 | return retval; | |
1841 | } | |
1842 | ||
1843 | OSStatus wxMacDataItemBrowserControl::GetSetItemData( | |
1844 | DataBrowserItemID itemID, | |
1845 | DataBrowserPropertyID property, | |
1846 | DataBrowserItemDataRef itemData, | |
88a7a4e1 | 1847 | Boolean changeValue ) |
6cce68ea SC |
1848 | { |
1849 | wxMacDataItem* item = (wxMacDataItem*) itemID; | |
1850 | return GetSetItemData(item, property, itemData , changeValue ); | |
1851 | } | |
1852 | ||
1853 | OSStatus wxMacDataItemBrowserControl::GetSetItemData( | |
1854 | wxMacDataItem* item, | |
1855 | DataBrowserPropertyID property, | |
1856 | DataBrowserItemDataRef itemData, | |
88a7a4e1 | 1857 | Boolean changeValue ) |
6cce68ea SC |
1858 | { |
1859 | OSStatus err = errDataBrowserPropertyNotSupported; | |
1860 | switch( property ) | |
1861 | { | |
1862 | case kDataBrowserContainerIsClosableProperty : | |
1863 | case kDataBrowserContainerIsSortableProperty : | |
1864 | case kDataBrowserContainerIsOpenableProperty : | |
1865 | // right now default behaviour on these | |
1866 | break; | |
1867 | default : | |
1868 | if ( item != NULL ) | |
1869 | err = item->GetSetData( this, property , itemData , changeValue ); | |
1870 | break; | |
88a7a4e1 | 1871 | |
6cce68ea SC |
1872 | } |
1873 | return err; | |
1874 | } | |
1875 | ||
1876 | void wxMacDataItemBrowserControl::ItemNotification( | |
1877 | DataBrowserItemID itemID, | |
1878 | DataBrowserItemNotification message, | |
88a7a4e1 | 1879 | DataBrowserItemDataRef itemData) |
6cce68ea | 1880 | { |
88a7a4e1 | 1881 | wxMacDataItem* item = (wxMacDataItem*) itemID; |
6cce68ea SC |
1882 | ItemNotification( item , message, itemData); |
1883 | } | |
1884 | ||
1885 | void wxMacDataItemBrowserControl::ItemNotification( | |
1886 | const wxMacDataItem* item, | |
1887 | DataBrowserItemNotification message, | |
88a7a4e1 | 1888 | DataBrowserItemDataRef itemData) |
6cce68ea SC |
1889 | { |
1890 | if (item != NULL) | |
1891 | item->Notification( this, message, itemData); | |
1892 | } | |
1893 | ||
88a7a4e1 WS |
1894 | unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem* container, |
1895 | bool recurse , DataBrowserItemState state) const | |
6cce68ea SC |
1896 | { |
1897 | UInt32 numItems = 0; | |
88a7a4e1 WS |
1898 | verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID)container, |
1899 | recurse, state, &numItems ) ); | |
6cce68ea SC |
1900 | return numItems; |
1901 | } | |
1902 | ||
88a7a4e1 WS |
1903 | void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem* container, |
1904 | bool recurse , DataBrowserItemState state, wxArrayMacDataItemPtr &items) const | |
6cce68ea SC |
1905 | { |
1906 | Handle handle = NewHandle(0); | |
88a7a4e1 WS |
1907 | verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID)container , |
1908 | recurse , state, handle) ); | |
6cce68ea SC |
1909 | |
1910 | int itemCount = GetHandleSize(handle)/sizeof(DataBrowserItemID); | |
1911 | HLock( handle ); | |
1912 | wxMacDataItemPtr* itemsArray = (wxMacDataItemPtr*) *handle; | |
1913 | for ( int i = 0; i < itemCount; ++i) | |
1914 | { | |
1915 | items.Add(itemsArray[i]); | |
1916 | } | |
1917 | HUnlock( handle ); | |
1918 | DisposeHandle( handle ); | |
1919 | } | |
1920 | ||
1921 | unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem* item) const | |
1922 | { | |
1923 | DataBrowserTableViewRowIndex row; | |
1924 | OSStatus err = GetItemRow( (DataBrowserItemID) item , &row); | |
1925 | wxASSERT( err == noErr); | |
1926 | return row; | |
1927 | } | |
1928 | ||
1929 | wxMacDataItem* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n) const | |
1930 | { | |
1931 | DataBrowserItemID id; | |
1932 | OSStatus err = GetItemID( (DataBrowserTableViewRowIndex) n , &id); | |
1933 | wxASSERT( err == noErr); | |
88a7a4e1 | 1934 | return (wxMacDataItem*) id; |
6cce68ea SC |
1935 | } |
1936 | ||
88a7a4e1 | 1937 | void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem *container, |
6cce68ea SC |
1938 | const wxMacDataItem *item , DataBrowserPropertyID property) const |
1939 | { | |
88a7a4e1 | 1940 | verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, 1, |
6cce68ea SC |
1941 | (DataBrowserItemID*) &item, kDataBrowserItemNoProperty /* notSorted */, property ) ); |
1942 | } | |
1943 | ||
88a7a4e1 | 1944 | void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem *container, |
6cce68ea SC |
1945 | wxArrayMacDataItemPtr &itemArray , DataBrowserPropertyID property) const |
1946 | { | |
1947 | unsigned int noItems = itemArray.GetCount(); | |
1948 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1949 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1950 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1951 | ||
88a7a4e1 | 1952 | verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, noItems, |
6cce68ea SC |
1953 | items, kDataBrowserItemNoProperty /* notSorted */, property ) ); |
1954 | delete [] items; | |
1955 | } | |
1956 | ||
1957 | void wxMacDataItemBrowserControl::AddItem(wxMacDataItem *container, wxMacDataItem *item) | |
1958 | { | |
88a7a4e1 | 1959 | verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, 1, |
6cce68ea SC |
1960 | (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ) ); |
1961 | } | |
1962 | ||
88a7a4e1 | 1963 | void wxMacDataItemBrowserControl::AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray ) |
6cce68ea SC |
1964 | { |
1965 | unsigned int noItems = itemArray.GetCount(); | |
1966 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1967 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1968 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1969 | ||
88a7a4e1 | 1970 | verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, noItems, |
6cce68ea SC |
1971 | (DataBrowserItemID*) items, kDataBrowserItemNoProperty ) ); |
1972 | delete [] items; | |
1973 | } | |
1974 | ||
88a7a4e1 | 1975 | void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem *container, wxMacDataItem* item) |
6cce68ea | 1976 | { |
88a7a4e1 | 1977 | OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 1, |
6cce68ea SC |
1978 | (UInt32*) &item, kDataBrowserItemNoProperty ); |
1979 | verify_noerr( err ); | |
1980 | } | |
1981 | ||
88a7a4e1 | 1982 | void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray) |
6cce68ea SC |
1983 | { |
1984 | unsigned int noItems = itemArray.GetCount(); | |
1985 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
1986 | for ( unsigned int i = 0; i < noItems; ++i ) | |
1987 | items[i] = (DataBrowserItemID) itemArray[i]; | |
1988 | ||
88a7a4e1 | 1989 | OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, noItems, |
6cce68ea SC |
1990 | (UInt32*) items, kDataBrowserItemNoProperty ); |
1991 | verify_noerr( err ); | |
1992 | delete [] items; | |
1993 | } | |
1994 | ||
88a7a4e1 | 1995 | void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem *container) |
6cce68ea SC |
1996 | { |
1997 | OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 0 , NULL , kDataBrowserItemNoProperty ); | |
1998 | verify_noerr( err ); | |
1999 | } | |
2000 | ||
88a7a4e1 | 2001 | void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem* item , DataBrowserSetOption option) |
6cce68ea SC |
2002 | { |
2003 | verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID*) &item, option )); | |
2004 | } | |
2005 | ||
88a7a4e1 | 2006 | void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option) |
6cce68ea SC |
2007 | { |
2008 | verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL , option )); | |
2009 | } | |
2010 | ||
88a7a4e1 | 2011 | void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr &itemArray , DataBrowserSetOption option) |
6cce68ea SC |
2012 | { |
2013 | unsigned int noItems = itemArray.GetCount(); | |
2014 | DataBrowserItemID *items = new DataBrowserItemID[noItems]; | |
2015 | for ( unsigned int i = 0; i < noItems; ++i ) | |
2016 | items[i] = (DataBrowserItemID) itemArray[i]; | |
2017 | ||
2018 | verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems, (DataBrowserItemID*) items, option )); | |
2019 | delete [] items; | |
2020 | } | |
2021 | ||
2022 | Boolean wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem* item) const | |
2023 | { | |
2024 | return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID) item); | |
2025 | } | |
2026 | ||
88a7a4e1 | 2027 | void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options) |
6cce68ea SC |
2028 | { |
2029 | verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID) item, kDataBrowserNoItem , options ) ); | |
2030 | } | |
2031 | ||
88a7a4e1 | 2032 | void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const |
6cce68ea | 2033 | { |
88a7a4e1 | 2034 | verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID*) first, (DataBrowserItemID*) last) ); |
6cce68ea SC |
2035 | } |
2036 | ||
88a7a4e1 | 2037 | |
6cce68ea | 2038 | |
5ca0d812 SC |
2039 | // |
2040 | // Tab Control | |
2041 | // | |
9d8aca48 WS |
2042 | |
2043 | OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable ) | |
5ca0d812 | 2044 | { |
6cce68ea | 2045 | return ::SetTabEnabled( m_controlRef , tabNo , enable ); |
5ca0d812 | 2046 | } |
9d8aca48 | 2047 | |
30e77b5c SC |
2048 | // |
2049 | // Quartz Support | |
2050 | // | |
2051 | ||
2052 | #ifdef __WXMAC_OSX__ | |
2053 | // snippets from Sketch Sample from Apple : | |
2054 | ||
8638e69b DS |
2055 | #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc" |
2056 | ||
30e77b5c | 2057 | /* |
fb5246be | 2058 | This function locates, opens, and returns the profile reference for the calibrated |
30e77b5c SC |
2059 | Generic RGB color space. It is up to the caller to call CMCloseProfile when done |
2060 | with the profile reference this function returns. | |
2061 | */ | |
8638e69b | 2062 | CMProfileRef wxMacOpenGenericProfile() |
30e77b5c SC |
2063 | { |
2064 | static CMProfileRef cachedRGBProfileRef = NULL; | |
fb5246be | 2065 | |
30e77b5c SC |
2066 | // we only create the profile reference once |
2067 | if (cachedRGBProfileRef == NULL) | |
2068 | { | |
fb5246be WS |
2069 | CMProfileLocation loc; |
2070 | ||
2071 | loc.locType = cmPathBasedProfile; | |
2072 | strcpy(loc.u.pathLoc.path, kGenericRGBProfilePathStr); | |
2073 | ||
2074 | verify_noerr( CMOpenProfile(&cachedRGBProfileRef, &loc) ); | |
30e77b5c SC |
2075 | } |
2076 | ||
8638e69b | 2077 | // clone the profile reference so that the caller has their own reference, not our cached one |
30e77b5c | 2078 | if (cachedRGBProfileRef) |
fb5246be | 2079 | CMCloneProfileRef(cachedRGBProfileRef); |
30e77b5c SC |
2080 | |
2081 | return cachedRGBProfileRef; | |
2082 | } | |
2083 | ||
2084 | /* | |
2085 | Return the generic RGB color space. This is a 'get' function and the caller should | |
2086 | not release the returned value unless the caller retains it first. Usually callers | |
2087 | of this routine will immediately use the returned colorspace with CoreGraphics | |
2088 | so they typically do not need to retain it themselves. | |
fb5246be | 2089 | |
30e77b5c SC |
2090 | This function creates the generic RGB color space once and hangs onto it so it can |
2091 | return it whenever this function is called. | |
2092 | */ | |
2093 | ||
2094 | CGColorSpaceRef wxMacGetGenericRGBColorSpace() | |
2095 | { | |
6cce68ea | 2096 | static wxMacCFRefHolder<CGColorSpaceRef> genericRGBColorSpace; |
fb5246be | 2097 | |
8638e69b DS |
2098 | if (genericRGBColorSpace == NULL) |
2099 | { | |
26a2f914 | 2100 | if ( UMAGetSystemVersion() >= 0x1040 ) |
fb5246be | 2101 | { |
6cce68ea | 2102 | genericRGBColorSpace.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) ); |
fb5246be | 2103 | } |
26a2f914 SC |
2104 | else |
2105 | { | |
2106 | CMProfileRef genericRGBProfile = wxMacOpenGenericProfile(); | |
8638e69b | 2107 | |
26a2f914 SC |
2108 | if (genericRGBProfile) |
2109 | { | |
6cce68ea | 2110 | genericRGBColorSpace.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile) ); |
8638e69b | 2111 | |
6cce68ea | 2112 | wxASSERT_MSG( genericRGBColorSpace != NULL, wxT("couldn't create the generic RGB color space") ); |
8638e69b | 2113 | |
26a2f914 | 2114 | // we opened the profile so it is up to us to close it |
88a7a4e1 | 2115 | CMCloseProfile(genericRGBProfile); |
26a2f914 SC |
2116 | } |
2117 | } | |
8638e69b DS |
2118 | } |
2119 | ||
30e77b5c SC |
2120 | return genericRGBColorSpace; |
2121 | } | |
2122 | #endif | |
2123 | ||
54ce9ebb JS |
2124 | wxMacPortSaver::wxMacPortSaver( GrafPtr port ) |
2125 | { | |
6cce68ea SC |
2126 | ::GetPort( &m_port ); |
2127 | ::SetPort( port ); | |
54ce9ebb JS |
2128 | } |
2129 | ||
2130 | wxMacPortSaver::~wxMacPortSaver() | |
2131 | { | |
6cce68ea | 2132 | ::SetPort( m_port ); |
54ce9ebb JS |
2133 | } |
2134 | ||
b6ed2b86 | 2135 | #endif // wxUSE_GUI |