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