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