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