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