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