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