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