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