]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/utils.cpp
The Great wxRegion Refactoring:
[wxWidgets.git] / src / mac / carbon / utils.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/carbon/utils.cpp
3// Purpose: Various utilities
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#include "wx/utils.h"
15
16#ifndef WX_PRECOMP
17 #include "wx/intl.h"
18 #include "wx/app.h"
19 #if wxUSE_GUI
20 #include "wx/toplevel.h"
21 #include "wx/font.h"
22 #endif
23#endif
24
25#include "wx/apptrait.h"
26
27#if wxUSE_GUI
28 #include "wx/mac/uma.h"
29#endif
30
31#include <ctype.h>
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <string.h>
36#include <stdarg.h>
37
38#include "MoreFilesX.h"
39
40#ifndef __DARWIN__
41 #include <Threads.h>
42 #include <Sound.h>
43#endif
44
45#if wxUSE_GUI
46#if TARGET_API_MAC_OSX
47 #include <CoreServices/CoreServices.h>
48#else
49 #include <DriverServices.h>
50 #include <Multiprocessing.h>
51#endif
52
53#ifdef __DARWIN__
54 #include <Carbon/Carbon.h>
55#else
56 #include <ATSUnicode.h>
57 #include <TextCommon.h>
58 #include <TextEncodingConverter.h>
59#endif
60#endif // wxUSE_GUI
61
62#include "wx/mac/private.h"
63
64#if defined(__MWERKS__) && wxUSE_UNICODE
65#if __MWERKS__ < 0x4100 || !defined(__DARWIN__)
66 #include <wtime.h>
67#endif
68#endif
69
70#if wxUSE_BASE
71
72// our OS version is the same in non GUI and GUI cases
73wxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn)
74{
75 long theSystem;
76 Gestalt(gestaltSystemVersion, &theSystem);
77
78 if ( majorVsn != NULL )
79 *majorVsn = (theSystem >> 8);
80
81 if ( minorVsn != NULL )
82 *minorVsn = (theSystem & 0xFF);
83
84#if defined( __DARWIN__ )
85 return wxOS_MAC_OSX_DARWIN;
86#else
87 return wxOS_MAC_OS;
88#endif
89}
90
91// ----------------------------------------------------------------------------
92// debugging support
93// ----------------------------------------------------------------------------
94
95#if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
96
97// MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
98
99#ifndef __MetroNubUtils__
100#include "MetroNubUtils.h"
101#endif
102
103#ifndef __GESTALT__
104#include <Gestalt.h>
105#endif
106
107#if TARGET_API_MAC_CARBON
108
109#include <CodeFragments.h>
110
111extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...);
112
113ProcPtr gCallUniversalProc_Proc = NULL;
114
115#endif
116
117static MetroNubUserEntryBlock* gMetroNubEntry = NULL;
118
119static long fRunOnce = false;
120
121
122Boolean IsMetroNubInstalled()
123{
124 if (!fRunOnce)
125 {
126 long result, value;
127
128 fRunOnce = true;
129 gMetroNubEntry = NULL;
130
131 if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000)
132 {
133 // look for MetroNub's Gestalt selector
134 if (Gestalt(kMetroNubUserSignature, &result) == noErr)
135 {
136#if TARGET_API_MAC_CARBON
137 if (gCallUniversalProc_Proc == NULL)
138 {
139 CFragConnectionID connectionID;
140 Ptr mainAddress;
141 Str255 errorString;
142 ProcPtr symbolAddress;
143 OSErr err;
144 CFragSymbolClass symbolClass;
145
146 symbolAddress = NULL;
147 err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag,
148 &connectionID, &mainAddress, errorString);
149
150 if (err != noErr)
151 {
152 gCallUniversalProc_Proc = NULL;
153 goto end;
154 }
155
156 err = FindSymbol(connectionID, "\pCallUniversalProc",
157 (Ptr *) &gCallUniversalProc_Proc, &symbolClass);
158
159 if (err != noErr)
160 {
161 gCallUniversalProc_Proc = NULL;
162 goto end;
163 }
164 }
165#endif
166
167 {
168 MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result;
169
170 // make sure the version of the API is compatible
171 if (block->apiLowVersion <= kMetroNubUserAPIVersion &&
172 kMetroNubUserAPIVersion <= block->apiHiVersion)
173 {
174 // success!
175 gMetroNubEntry = block;
176 }
177 }
178 }
179 }
180 }
181
182end:
183
184#if TARGET_API_MAC_CARBON
185 return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL);
186#else
187 return (gMetroNubEntry != NULL);
188#endif
189}
190
191Boolean IsMWDebuggerRunning()
192{
193 if (IsMetroNubInstalled())
194 return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning);
195
196 return false;
197}
198
199Boolean AmIBeingMWDebugged()
200{
201 if (IsMetroNubInstalled())
202 return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged);
203
204 return false;
205}
206
207extern bool WXDLLEXPORT wxIsDebuggerRunning()
208{
209 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
210}
211
212#else
213
214extern bool WXDLLEXPORT wxIsDebuggerRunning()
215{
216 return false;
217}
218
219#endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
220
221
222#ifndef __DARWIN__
223// defined in unix/utilsunx.cpp for Mac OS X
224
225// get full hostname (with domain name if possible)
226bool wxGetFullHostName(wxChar *buf, int maxSize)
227{
228 return wxGetHostName(buf, maxSize);
229}
230
231// Get user ID e.g. jacs
232bool wxGetUserId(wxChar *buf, int maxSize)
233{
234 return wxGetUserName( buf , maxSize );
235}
236
237const wxChar* wxGetHomeDir(wxString *pstr)
238{
239 *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder );
240 return pstr->c_str();
241}
242
243// Get hostname only (without domain name)
244bool wxGetHostName(wxChar *buf, int maxSize)
245{
246 // Gets Chooser name of user by examining a System resource.
247 buf[0] = 0;
248
249 const short kComputerNameID = -16413;
250
251 short oldResFile = CurResFile();
252 UseResFile(0);
253 StringHandle chooserName = (StringHandle)::GetString(kComputerNameID);
254 UseResFile(oldResFile);
255
256 if (chooserName && *chooserName)
257 {
258 HLock( (Handle) chooserName );
259 wxString name = wxMacMakeStringFromPascal( *chooserName );
260 HUnlock( (Handle) chooserName );
261 ReleaseResource( (Handle) chooserName );
262 wxStrncpy( buf , name , maxSize - 1 );
263 }
264
265 return true;
266}
267
268// Get user name e.g. Stefan Csomor
269bool wxGetUserName(wxChar *buf, int maxSize)
270{
271 // Gets Chooser name of user by examining a System resource.
272 buf[0] = 0;
273
274 const short kChooserNameID = -16096;
275
276 short oldResFile = CurResFile();
277 UseResFile(0);
278 StringHandle chooserName = (StringHandle)::GetString(kChooserNameID);
279 UseResFile(oldResFile);
280
281 if (chooserName && *chooserName)
282 {
283 HLock( (Handle) chooserName );
284 wxString name = wxMacMakeStringFromPascal( *chooserName );
285 HUnlock( (Handle) chooserName );
286 ReleaseResource( (Handle) chooserName );
287 wxStrncpy( buf , name , maxSize - 1 );
288 }
289
290 return true;
291}
292
293int wxKill(long pid, wxSignal sig , wxKillError *rc, int flags)
294{
295 // TODO
296 return 0;
297}
298
299WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value)
300{
301 // TODO : under classic there is no environement support, under X yes
302 return false;
303}
304
305// set the env var name to the given value, return true on success
306WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value)
307{
308 // TODO : under classic there is no environement support, under X yes
309 return false;
310}
311
312// Execute a program in an Interactive Shell
313bool wxShell(const wxString& command)
314{
315 // TODO
316 return false;
317}
318
319// Shutdown or reboot the PC
320bool wxShutdown(wxShutdownFlags wFlags)
321{
322 // TODO
323 return false;
324}
325
326// Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
327wxMemorySize wxGetFreeMemory()
328{
329 return (wxMemorySize)FreeMem();
330}
331
332#ifndef __DARWIN__
333
334void wxMicroSleep(unsigned long microseconds)
335{
336 AbsoluteTime wakeup = AddDurationToAbsolute( microseconds * durationMicrosecond , UpTime());
337 MPDelayUntil( & wakeup);
338}
339
340void wxMilliSleep(unsigned long milliseconds)
341{
342 AbsoluteTime wakeup = AddDurationToAbsolute( milliseconds, UpTime());
343 MPDelayUntil( & wakeup);
344}
345
346void wxSleep(int nSecs)
347{
348 wxMilliSleep(1000*nSecs);
349}
350
351#endif
352
353// Consume all events until no more left
354void wxFlushEvents()
355{
356}
357
358#endif // !__DARWIN__
359
360// Emit a beeeeeep
361void wxBell()
362{
363 SysBeep(30);
364}
365
366
367#endif // wxUSE_BASE
368
369#if wxUSE_GUI
370
371wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
372{
373 // We suppose that toolkit version is the same as OS version under Mac
374 wxGetOsVersion(verMaj, verMin);
375
376 return wxPORT_MAC;
377}
378
379// Reading and writing resources (eg WIN.INI, .Xdefaults)
380#if wxUSE_RESOURCES
381bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
382{
383 // TODO
384 return false;
385}
386
387bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file)
388{
389 wxString buf;
390 buf.Printf(wxT("%.4f"), value);
391
392 return wxWriteResource(section, entry, buf, file);
393}
394
395bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file)
396{
397 wxString buf;
398 buf.Printf(wxT("%ld"), value);
399
400 return wxWriteResource(section, entry, buf, file);
401}
402
403bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file)
404{
405 wxString buf;
406 buf.Printf(wxT("%d"), value);
407
408 return wxWriteResource(section, entry, buf, file);
409}
410
411bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file)
412{
413 // TODO
414 return false;
415}
416
417bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file)
418{
419 char *s = NULL;
420 bool succ = wxGetResource(section, entry, (char **)&s, file);
421 if (succ)
422 {
423 *value = (float)strtod(s, NULL);
424 delete[] s;
425 }
426
427 return succ;
428}
429
430bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file)
431{
432 char *s = NULL;
433 bool succ = wxGetResource(section, entry, (char **)&s, file);
434 if (succ)
435 {
436 *value = strtol(s, NULL, 10);
437 delete[] s;
438 }
439
440 return succ;
441}
442
443bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file)
444{
445 char *s = NULL;
446 bool succ = wxGetResource(section, entry, (char **)&s, file);
447 if (succ)
448 {
449 *value = (int)strtol(s, NULL, 10);
450 delete[] s;
451 }
452
453 return succ;
454}
455#endif // wxUSE_RESOURCES
456
457int gs_wxBusyCursorCount = 0;
458extern wxCursor gMacCurrentCursor;
459wxCursor gMacStoredActiveCursor;
460
461// Set the cursor to the busy cursor for all windows
462void wxBeginBusyCursor(const wxCursor *cursor)
463{
464 if (gs_wxBusyCursorCount++ == 0)
465 {
466 gMacStoredActiveCursor = gMacCurrentCursor;
467 cursor->MacInstall();
468 }
469 //else: nothing to do, already set
470}
471
472// Restore cursor to normal
473void wxEndBusyCursor()
474{
475 wxCHECK_RET( gs_wxBusyCursorCount > 0,
476 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
477
478 if (--gs_wxBusyCursorCount == 0)
479 {
480 gMacStoredActiveCursor.MacInstall();
481 gMacStoredActiveCursor = wxNullCursor;
482 }
483}
484
485// true if we're between the above two calls
486bool wxIsBusy()
487{
488 return (gs_wxBusyCursorCount > 0);
489}
490
491#endif // wxUSE_GUI
492
493#if wxUSE_BASE
494
495wxString wxMacFindFolderNoSeparator( short vol,
496 OSType folderType,
497 Boolean createFolder)
498{
499 FSRef fsRef;
500 wxString strDir;
501
502 if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr)
503 {
504 strDir = wxMacFSRefToPath( &fsRef );
505 }
506
507 return strDir;
508}
509
510wxString wxMacFindFolder( short vol,
511 OSType folderType,
512 Boolean createFolder)
513{
514 return wxMacFindFolderNoSeparator(vol, folderType, createFolder) + wxFILE_SEP_PATH;
515}
516
517#endif // wxUSE_BASE
518
519#if wxUSE_GUI
520
521// Check whether this window wants to process messages, e.g. Stop button
522// in long calculations.
523bool wxCheckForInterrupt(wxWindow *wnd)
524{
525 // TODO
526 return false;
527}
528
529void wxGetMousePosition( int* x, int* y )
530{
531 Point pt;
532
533 GetMouse( &pt );
534 LocalToGlobal( &pt );
535 *x = pt.h;
536 *y = pt.v;
537};
538
539// Return true if we have a colour display
540bool wxColourDisplay()
541{
542 return true;
543}
544
545// Returns depth of screen
546int wxDisplayDepth()
547{
548 Rect globRect;
549 SetRect(&globRect, -32760, -32760, 32760, 32760);
550 GDHandle theMaxDevice;
551
552 int theDepth = 8;
553 theMaxDevice = GetMaxDevice(&globRect);
554 if (theMaxDevice != NULL)
555 theDepth = (**(**theMaxDevice).gdPMap).pixelSize;
556
557 return theDepth;
558}
559
560// Get size of display
561void wxDisplaySize(int *width, int *height)
562{
563 BitMap screenBits;
564 GetQDGlobalsScreenBits( &screenBits );
565
566 if (width != NULL)
567 *width = screenBits.bounds.right - screenBits.bounds.left;
568
569 if (height != NULL)
570 *height = screenBits.bounds.bottom - screenBits.bounds.top;
571}
572
573void wxDisplaySizeMM(int *width, int *height)
574{
575 wxDisplaySize(width, height);
576 // on mac 72 is fixed (at least now;-)
577 float cvPt2Mm = 25.4 / 72;
578
579 if (width != NULL)
580 *width = int( *width * cvPt2Mm );
581
582 if (height != NULL)
583 *height = int( *height * cvPt2Mm );
584}
585
586void wxClientDisplayRect(int *x, int *y, int *width, int *height)
587{
588 Rect r;
589
590 GetAvailableWindowPositioningBounds( GetMainDevice() , &r );
591 if ( x )
592 *x = r.left;
593 if ( y )
594 *y = r.top;
595 if ( width )
596 *width = r.right - r.left;
597 if ( height )
598 *height = r.bottom - r.top;
599}
600
601wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
602{
603 return wxGenericFindWindowAtPoint(pt);
604}
605
606#endif // wxUSE_GUI
607
608#if wxUSE_BASE
609
610wxString wxGetOsDescription()
611{
612#ifdef WXWIN_OS_DESCRIPTION
613 // use configure generated description if available
614 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")"));
615#else
616 return wxT("MacOS"); //TODO:define further
617#endif
618}
619
620#ifndef __DARWIN__
621wxChar *wxGetUserHome (const wxString& user)
622{
623 // TODO
624 return NULL;
625}
626
627bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree)
628{
629 if ( path.empty() )
630 return false;
631
632 wxString p = path;
633 if (p[0u] == ':' )
634 p = wxGetCwd() + p;
635
636 int pos = p.Find(':');
637 if ( pos != wxNOT_FOUND )
638 p = p.Mid(1,pos);
639
640 p = p + wxT(":");
641
642 OSErr err = noErr;
643
644 FSRef fsRef;
645 err = wxMacPathToFSRef( p , &fsRef );
646 if ( noErr == err )
647 {
648 FSVolumeRefNum vRefNum;
649 err = FSGetVRefNum( &fsRef , &vRefNum );
650 if ( noErr == err )
651 {
652 UInt64 freeBytes , totalBytes;
653 err = FSGetVInfo( vRefNum , NULL , &freeBytes , &totalBytes );
654 if ( noErr == err )
655 {
656 if ( pTotal )
657 *pTotal = wxDiskspaceSize_t( totalBytes );
658 if ( pFree )
659 *pFree = wxDiskspaceSize_t( freeBytes );
660 }
661 }
662 }
663
664 return err == noErr;
665}
666#endif // !__DARWIN__
667
668//---------------------------------------------------------------------------
669// wxMac Specific utility functions
670//---------------------------------------------------------------------------
671
672void wxMacStringToPascal( const wxString&from , StringPtr to )
673{
674 wxCharBuffer buf = from.mb_str( wxConvLocal );
675 int len = strlen(buf);
676
677 if ( len > 255 )
678 len = 255;
679 to[0] = len;
680 memcpy( (char*) &to[1] , buf , len );
681}
682
683wxString wxMacMakeStringFromPascal( ConstStringPtr from )
684{
685 return wxString( (char*) &from[1] , wxConvLocal , from[0] );
686}
687
688// ----------------------------------------------------------------------------
689// Common Event Support
690// ----------------------------------------------------------------------------
691
692extern ProcessSerialNumber gAppProcess;
693
694void wxMacWakeUp()
695{
696 ProcessSerialNumber psn;
697 Boolean isSame;
698 psn.highLongOfPSN = 0;
699 psn.lowLongOfPSN = kCurrentProcess;
700 SameProcess( &gAppProcess , &psn , &isSame );
701 if ( isSame )
702 {
703#if TARGET_CARBON
704 OSStatus err = noErr;
705
706#if 0
707 // lead sometimes to race conditions, although all calls used should be thread safe ...
708 static wxMacCarbonEvent s_wakeupEvent;
709 if ( !s_wakeupEvent.IsValid() )
710 {
711 err = s_wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
712 kEventAttributeNone );
713 }
714 if ( err == noErr )
715 {
716
717 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent ) )
718 return;
719 s_wakeupEvent.SetCurrentTime();
720 err = PostEventToQueue(GetMainEventQueue(), s_wakeupEvent,
721 kEventPriorityHigh );
722 }
723#else
724 wxMacCarbonEvent wakeupEvent;
725 wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
726 kEventAttributeNone );
727 err = PostEventToQueue(GetMainEventQueue(), wakeupEvent,
728 kEventPriorityHigh );
729#endif
730#else
731 PostEvent( nullEvent , 0 );
732#endif
733 }
734 else
735 {
736 WakeUpProcess( &gAppProcess );
737 }
738}
739
740#endif // wxUSE_BASE
741
742#if wxUSE_GUI
743
744// ----------------------------------------------------------------------------
745// Native Struct Conversions
746// ----------------------------------------------------------------------------
747
748void wxMacRectToNative( const wxRect *wx , Rect *n )
749{
750 n->left = wx->x;
751 n->top = wx->y;
752 n->right = wx->x + wx->width;
753 n->bottom = wx->y + wx->height;
754}
755
756void wxMacNativeToRect( const Rect *n , wxRect* wx )
757{
758 wx->x = n->left;
759 wx->y = n->top;
760 wx->width = n->right - n->left;
761 wx->height = n->bottom - n->top;
762}
763
764void wxMacPointToNative( const wxPoint* wx , Point *n )
765{
766 n->h = wx->x;
767 n->v = wx->y;
768}
769
770void wxMacNativeToPoint( const Point *n , wxPoint* wx )
771{
772 wx->x = n->h;
773 wx->y = n->v;
774}
775
776// ----------------------------------------------------------------------------
777// Carbon Event Support
778// ----------------------------------------------------------------------------
779
780OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData)
781{
782 return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData );
783}
784
785OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData)
786{
787 return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData );
788}
789
790// ----------------------------------------------------------------------------
791// Control Access Support
792// ----------------------------------------------------------------------------
793
794wxMacControl::wxMacControl(wxWindow* peer , bool isRootControl )
795{
796 Init();
797 m_peer = peer;
798 m_isRootControl = isRootControl;
799}
800
801wxMacControl::wxMacControl( wxWindow* peer , ControlRef control )
802{
803 Init();
804 m_peer = peer;
805 m_controlRef = control;
806}
807
808wxMacControl::wxMacControl( wxWindow* peer , WXWidget control )
809{
810 Init();
811 m_peer = peer;
812 m_controlRef = (ControlRef) control;
813}
814
815wxMacControl::~wxMacControl()
816{
817}
818
819void wxMacControl::Init()
820{
821 m_peer = NULL;
822 m_controlRef = NULL;
823 m_needsFocusRect = false;
824 m_isRootControl = false;
825}
826
827void wxMacControl::Dispose()
828{
829 wxASSERT_MSG( IsValidControlHandle(m_controlRef) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
830
831 CFIndex count = CFGetRetainCount( m_controlRef ) ;
832 wxASSERT_MSG( count == 1 , wxT("Reference Count of native control was not 1 in Dispose") );
833
834 ::DisposeControl( m_controlRef );
835 m_controlRef = NULL;
836}
837
838void wxMacControl::SetReference( SInt32 data )
839{
840 SetControlReference( m_controlRef , data );
841}
842
843OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const
844{
845 return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize );
846}
847
848OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const
849{
850 return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize );
851}
852
853OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData)
854{
855 return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData );
856}
857
858OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions )
859{
860#if TARGET_API_MAC_OSX
861 return SendEventToEventTargetWithOptions( event,
862 HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions );
863#else
864 #pragma unused(inOptions)
865 return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) );
866#endif
867}
868
869OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions )
870{
871 wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess );
872
873 event.SetParameter<HICommand>(kEventParamDirectObject,command);
874
875 return SendEvent( event , inOptions );
876}
877
878OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions )
879{
880 HICommand command;
881
882 memset( &command, 0 , sizeof(command) );
883 command.commandID = commandID;
884 return SendHICommand( command , inOptions );
885}
886
887void wxMacControl::Flash( ControlPartCode part , UInt32 ticks )
888{
889 unsigned long finalTicks;
890
891 HiliteControl( m_controlRef , part );
892 Delay( ticks , &finalTicks );
893 HiliteControl( m_controlRef , kControlNoPart );
894}
895
896SInt32 wxMacControl::GetValue() const
897{
898 return ::GetControl32BitValue( m_controlRef );
899}
900
901SInt32 wxMacControl::GetMaximum() const
902{
903 return ::GetControl32BitMaximum( m_controlRef );
904}
905
906SInt32 wxMacControl::GetMinimum() const
907{
908 return ::GetControl32BitMinimum( m_controlRef );
909}
910
911void wxMacControl::SetValue( SInt32 v )
912{
913 ::SetControl32BitValue( m_controlRef , v );
914}
915
916void wxMacControl::SetMinimum( SInt32 v )
917{
918 ::SetControl32BitMinimum( m_controlRef , v );
919}
920
921void wxMacControl::SetMaximum( SInt32 v )
922{
923 ::SetControl32BitMaximum( m_controlRef , v );
924}
925
926void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum )
927{
928 ::SetControl32BitMinimum( m_controlRef , minimum );
929 ::SetControl32BitMaximum( m_controlRef , maximum );
930 ::SetControl32BitValue( m_controlRef , value );
931}
932
933OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart )
934{
935 return SetKeyboardFocus( GetControlOwner( m_controlRef ), m_controlRef, focusPart );
936}
937
938bool wxMacControl::HasFocus() const
939{
940 ControlRef control;
941 GetKeyboardFocus( GetUserFocusWindow() , &control );
942 return control == m_controlRef;
943}
944
945void wxMacControl::SetNeedsFocusRect( bool needs )
946{
947 m_needsFocusRect = needs;
948}
949
950bool wxMacControl::NeedsFocusRect() const
951{
952 return m_needsFocusRect;
953}
954
955void wxMacControl::VisibilityChanged(bool shown)
956{
957}
958
959void wxMacControl::SuperChangedPosition()
960{
961}
962
963void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle )
964{
965 m_font = font;
966 ControlFontStyleRec fontStyle;
967 if ( font.MacGetThemeFontID() != kThemeCurrentPortFont )
968 {
969 switch ( font.MacGetThemeFontID() )
970 {
971 case kThemeSmallSystemFont :
972 fontStyle.font = kControlFontSmallSystemFont;
973 break;
974
975 case 109 : // mini font
976 fontStyle.font = -5;
977 break;
978
979 case kThemeSystemFont :
980 fontStyle.font = kControlFontBigSystemFont;
981 break;
982
983 default :
984 fontStyle.font = kControlFontBigSystemFont;
985 break;
986 }
987
988 fontStyle.flags = kControlUseFontMask;
989 }
990 else
991 {
992 fontStyle.font = font.MacGetFontNum();
993 fontStyle.style = font.MacGetFontStyle();
994 fontStyle.size = font.MacGetFontSize();
995 fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask;
996 }
997
998 fontStyle.just = teJustLeft;
999 fontStyle.flags |= kControlUseJustMask;
1000 if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL )
1001 fontStyle.just = teJustCenter;
1002 else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT )
1003 fontStyle.just = teJustRight;
1004
1005
1006 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1007 // won't get grayed out by the system anymore
1008
1009 if ( foreground != *wxBLACK )
1010 {
1011 fontStyle.foreColor = MAC_WXCOLORREF( foreground.GetPixel() );
1012 fontStyle.flags |= kControlUseForeColorMask;
1013 }
1014
1015 ::SetControlFontStyle( m_controlRef , &fontStyle );
1016}
1017
1018void wxMacControl::SetBackground( const wxBrush &WXUNUSED(brush) )
1019{
1020 // TODO
1021 // setting up a color proc is not recommended anymore
1022}
1023
1024void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum )
1025{
1026 ::SetControl32BitMinimum( m_controlRef , minimum );
1027 ::SetControl32BitMaximum( m_controlRef , maximum );
1028}
1029
1030short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers )
1031{
1032 return HandleControlKey( m_controlRef , keyCode , charCode , modifiers );
1033}
1034
1035void wxMacControl::SetActionProc( ControlActionUPP actionProc )
1036{
1037 SetControlAction( m_controlRef , actionProc );
1038}
1039
1040void wxMacControl::SetViewSize( SInt32 viewSize )
1041{
1042 SetControlViewSize(m_controlRef , viewSize );
1043}
1044
1045SInt32 wxMacControl::GetViewSize() const
1046{
1047 return GetControlViewSize( m_controlRef );
1048}
1049
1050bool wxMacControl::IsVisible() const
1051{
1052 return IsControlVisible( m_controlRef );
1053}
1054
1055void wxMacControl::SetVisibility( bool visible , bool redraw )
1056{
1057 SetControlVisibility( m_controlRef , visible , redraw );
1058}
1059
1060bool wxMacControl::IsEnabled() const
1061{
1062#if TARGET_API_MAC_OSX
1063 return IsControlEnabled( m_controlRef );
1064#else
1065 return IsControlActive( m_controlRef );
1066#endif
1067}
1068
1069bool wxMacControl::IsActive() const
1070{
1071 return IsControlActive( m_controlRef );
1072}
1073
1074void wxMacControl::Enable( bool enable )
1075{
1076 if ( enable )
1077 EnableControl( m_controlRef );
1078 else
1079 DisableControl( m_controlRef );
1080}
1081
1082void wxMacControl::SetDrawingEnabled( bool enable )
1083{
1084 HIViewSetDrawingEnabled( m_controlRef , enable );
1085}
1086
1087bool wxMacControl::GetNeedsDisplay() const
1088{
1089 return HIViewGetNeedsDisplay( m_controlRef );
1090}
1091
1092void wxMacControl::SetNeedsDisplay( RgnHandle where )
1093{
1094 if ( !IsVisible() )
1095 return;
1096
1097 HIViewSetNeedsDisplayInRegion( m_controlRef , where , true );
1098}
1099
1100void wxMacControl::SetNeedsDisplay( Rect* where )
1101{
1102 if ( !IsVisible() )
1103 return;
1104
1105 if ( where != NULL )
1106 {
1107 RgnHandle update = NewRgn();
1108 RectRgn( update , where );
1109 HIViewSetNeedsDisplayInRegion( m_controlRef , update , true );
1110 DisposeRgn( update );
1111 }
1112 else
1113 HIViewSetNeedsDisplay( m_controlRef , true );
1114}
1115
1116void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to )
1117{
1118 HIPoint hiPoint;
1119
1120 hiPoint.x = pt->x;
1121 hiPoint.y = pt->y;
1122 HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef );
1123 pt->x = (int)hiPoint.x;
1124 pt->y = (int)hiPoint.y;
1125}
1126
1127void wxMacControl::SetRect( Rect *r )
1128{
1129 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1130 //CGPoint and CGSize, which have two floats each
1131 HIRect hir = { { r->left , r->top }, { r->right - r->left , r->bottom - r->top } };
1132 HIViewSetFrame ( m_controlRef , &hir );
1133 // eventuall we might have to do a SetVisibility( false , true );
1134 // before and a SetVisibility( true , true ); after
1135}
1136
1137void wxMacControl::GetRect( Rect *r )
1138{
1139 GetControlBounds( m_controlRef , r );
1140}
1141
1142void wxMacControl::GetRectInWindowCoords( Rect *r )
1143{
1144 UMAGetControlBoundsInWindowCoords( m_controlRef , r );
1145}
1146
1147void wxMacControl::GetBestRect( Rect *r )
1148{
1149 short baselineoffset;
1150
1151 GetBestControlRect( m_controlRef , r , &baselineoffset );
1152}
1153
1154void wxMacControl::SetLabel( const wxString &title )
1155{
1156 wxFontEncoding encoding;
1157
1158 if ( m_font.Ok() )
1159 encoding = m_font.GetEncoding();
1160 else
1161 encoding = wxFont::GetDefaultEncoding();
1162
1163 UMASetControlTitle( m_controlRef , title , encoding );
1164}
1165
1166void wxMacControl::GetFeatures( UInt32 * features )
1167{
1168 GetControlFeatures( m_controlRef , features );
1169}
1170
1171OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region )
1172{
1173 OSStatus err = GetControlRegion( m_controlRef , partCode , region );
1174 return err;
1175}
1176
1177OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other )
1178{
1179#if TARGET_API_MAC_OSX
1180 return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow,
1181 (other != NULL) ? other->m_controlRef : NULL);
1182#else
1183 return 0;
1184#endif
1185}
1186
1187#if TARGET_API_MAC_OSX
1188// SetNeedsDisplay would not invalidate the children
1189static void InvalidateControlAndChildren( HIViewRef control )
1190{
1191 HIViewSetNeedsDisplay( control , true );
1192 UInt16 childrenCount = 0;
1193 OSStatus err = CountSubControls( control , &childrenCount );
1194 if ( err == errControlIsNotEmbedder )
1195 return;
1196
1197 wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") );
1198
1199 for ( UInt16 i = childrenCount; i >=1; --i )
1200 {
1201 HIViewRef child;
1202
1203 err = GetIndexedSubControl( control , i , & child );
1204 if ( err == errControlIsNotEmbedder )
1205 return;
1206
1207 InvalidateControlAndChildren( child );
1208 }
1209}
1210#endif
1211
1212void wxMacControl::InvalidateWithChildren()
1213{
1214#if TARGET_API_MAC_OSX
1215 InvalidateControlAndChildren( m_controlRef );
1216#endif
1217}
1218
1219void wxMacControl::ScrollRect( wxRect *r , int dx , int dy )
1220{
1221 wxASSERT( r != NULL );
1222
1223 HIRect scrollarea = CGRectMake( r->x , r->y , r->width , r->height);
1224 HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy );
1225}
1226
1227OSType wxMacCreator = 'WXMC';
1228OSType wxMacControlProperty = 'MCCT';
1229
1230void wxMacControl::SetReferenceInNativeControl()
1231{
1232 void * data = this;
1233 verify_noerr( SetControlProperty ( m_controlRef ,
1234 wxMacCreator,wxMacControlProperty, sizeof(data), &data ) );
1235}
1236
1237wxMacControl* wxMacControl::GetReferenceFromNativeControl(ControlRef control)
1238{
1239 wxMacControl* ctl = NULL;
1240 UInt32 actualSize;
1241 if ( GetControlProperty( control ,wxMacCreator,wxMacControlProperty, sizeof(ctl) ,
1242 &actualSize , &ctl ) == noErr )
1243 {
1244 return ctl;
1245 }
1246 return NULL;
1247}
1248
1249// ============================================================================
1250// DataBrowser Wrapper
1251// ============================================================================
1252//
1253// basing on DataBrowserItemIDs
1254//
1255
1256pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
1257 ControlRef browser,
1258 DataBrowserItemID itemID,
1259 DataBrowserItemNotification message,
1260 DataBrowserItemDataRef itemData )
1261{
1262 wxMacDataBrowserControl* ctl = dynamic_cast<wxMacDataBrowserControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
1263 if ( ctl != 0 )
1264 {
1265 ctl->ItemNotification(itemID, message, itemData);
1266 }
1267}
1268
1269pascal OSStatus wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
1270 ControlRef browser,
1271 DataBrowserItemID itemID,
1272 DataBrowserPropertyID property,
1273 DataBrowserItemDataRef itemData,
1274 Boolean changeValue )
1275{
1276 OSStatus err = errDataBrowserPropertyNotSupported;
1277 wxMacDataBrowserControl* ctl = dynamic_cast<wxMacDataBrowserControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
1278 if ( ctl != 0 )
1279 {
1280 err = ctl->GetSetItemData(itemID, property, itemData, changeValue);
1281 }
1282 return err;
1283}
1284
1285pascal Boolean wxMacDataBrowserControl::DataBrowserCompareProc(
1286 ControlRef browser,
1287 DataBrowserItemID itemOneID,
1288 DataBrowserItemID itemTwoID,
1289 DataBrowserPropertyID sortProperty)
1290{
1291 wxMacDataBrowserControl* ctl = dynamic_cast<wxMacDataBrowserControl*>( wxMacControl::GetReferenceFromNativeControl( browser ) );
1292 if ( ctl != 0 )
1293 {
1294 return ctl->CompareItems(itemOneID, itemTwoID, sortProperty);
1295 }
1296 return false;
1297}
1298
1299DataBrowserItemDataUPP gDataBrowserItemDataUPP = NULL;
1300DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP = NULL;
1301DataBrowserItemCompareUPP gDataBrowserItemCompareUPP = NULL;
1302
1303wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow* peer, const wxPoint& pos, const wxSize& size, long style) : wxMacControl( peer )
1304{
1305 Rect bounds = wxMacGetBoundsForControl( peer, pos, size );
1306 OSStatus err = ::CreateDataBrowserControl(
1307 MAC_WXHWND(peer->MacGetTopLevelWindowRef()),
1308 &bounds, kDataBrowserListView, &m_controlRef );
1309 SetReferenceInNativeControl();
1310 verify_noerr( err );
1311 if ( gDataBrowserItemCompareUPP == NULL )
1312 gDataBrowserItemCompareUPP = NewDataBrowserItemCompareUPP(DataBrowserCompareProc);
1313 if ( gDataBrowserItemDataUPP == NULL )
1314 gDataBrowserItemDataUPP = NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc);
1315 if ( gDataBrowserItemNotificationUPP == NULL )
1316 {
1317 gDataBrowserItemNotificationUPP =
1318#if TARGET_API_MAC_OSX
1319 (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc);
1320#else
1321 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc);
1322#endif
1323 }
1324
1325 DataBrowserCallbacks callbacks;
1326 InitializeDataBrowserCallbacks( &callbacks, kDataBrowserLatestCallbacks );
1327
1328 callbacks.u.v1.itemDataCallback = gDataBrowserItemDataUPP;
1329 callbacks.u.v1.itemCompareCallback = gDataBrowserItemCompareUPP;
1330 callbacks.u.v1.itemNotificationCallback = gDataBrowserItemNotificationUPP;
1331 SetCallbacks( &callbacks );
1332
1333}
1334
1335OSStatus wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container,
1336 Boolean recurse,
1337 DataBrowserItemState state,
1338 UInt32 *numItems) const
1339{
1340 return GetDataBrowserItemCount( m_controlRef, container, recurse, state, numItems );
1341}
1342
1343OSStatus wxMacDataBrowserControl::GetItems( DataBrowserItemID container,
1344 Boolean recurse,
1345 DataBrowserItemState state,
1346 Handle items) const
1347{
1348 return GetDataBrowserItems( m_controlRef, container, recurse, state, items );
1349}
1350
1351OSStatus wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options )
1352{
1353 return SetDataBrowserSelectionFlags( m_controlRef, options );
1354}
1355
1356OSStatus wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc *columnDesc,
1357 DataBrowserTableViewColumnIndex position )
1358{
1359 return AddDataBrowserListViewColumn( m_controlRef, columnDesc, position );
1360}
1361
1362OSStatus wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id ){
1363 return GetDataBrowserTableViewColumnProperty( m_controlRef, position, id );
1364}
1365
1366OSStatus wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position )
1367{
1368 DataBrowserTableViewColumnID id;
1369 GetColumnIDFromIndex( position, &id );
1370 return RemoveDataBrowserTableViewColumn( m_controlRef, id );
1371}
1372
1373OSStatus wxMacDataBrowserControl::AutoSizeColumns()
1374{
1375 return AutoSizeDataBrowserListViewColumns(m_controlRef);
1376}
1377
1378OSStatus wxMacDataBrowserControl::SetHasScrollBars( bool horiz, bool vert )
1379{
1380 return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert );
1381}
1382
1383OSStatus wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle )
1384{
1385 return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle );
1386}
1387
1388OSStatus wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height)
1389{
1390 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
1391}
1392
1393OSStatus wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16 *height)
1394{
1395 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
1396}
1397
1398OSStatus wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks *callbacks)
1399{
1400 return SetDataBrowserCallbacks( m_controlRef, callbacks );
1401}
1402
1403OSStatus wxMacDataBrowserControl::UpdateItems(
1404 DataBrowserItemID container,
1405 UInt32 numItems,
1406 const DataBrowserItemID *items,
1407 DataBrowserPropertyID preSortProperty,
1408 DataBrowserPropertyID propertyID ) const
1409{
1410 return UpdateDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty, propertyID );
1411}
1412
1413bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item ) const
1414{
1415 return IsDataBrowserItemSelected( m_controlRef, item );
1416}
1417
1418OSStatus wxMacDataBrowserControl::AddItems(
1419 DataBrowserItemID container,
1420 UInt32 numItems,
1421 const DataBrowserItemID *items,
1422 DataBrowserPropertyID preSortProperty )
1423{
1424 return AddDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty );
1425}
1426
1427OSStatus wxMacDataBrowserControl::RemoveItems(
1428 DataBrowserItemID container,
1429 UInt32 numItems,
1430 const DataBrowserItemID *items,
1431 DataBrowserPropertyID preSortProperty )
1432{
1433 return RemoveDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty );
1434}
1435
1436OSStatus wxMacDataBrowserControl::RevealItem(
1437 DataBrowserItemID item,
1438 DataBrowserPropertyID propertyID,
1439 DataBrowserRevealOptions options ) const
1440{
1441 return RevealDataBrowserItem( m_controlRef, item, propertyID, options );
1442}
1443
1444OSStatus wxMacDataBrowserControl::SetSelectedItems(
1445 UInt32 numItems,
1446 const DataBrowserItemID *items,
1447 DataBrowserSetOption operation )
1448{
1449 return SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation );
1450}
1451
1452OSStatus wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const
1453{
1454 return GetDataBrowserSelectionAnchor( m_controlRef, first, last );
1455}
1456
1457OSStatus wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const
1458{
1459 return GetDataBrowserTableViewItemID( m_controlRef, row, item );
1460}
1461
1462OSStatus wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item, DataBrowserTableViewRowIndex * row ) const
1463{
1464 return GetDataBrowserTableViewItemRow( m_controlRef, item, row );
1465}
1466
1467OSStatus wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height )
1468{
1469 return SetDataBrowserTableViewRowHeight( m_controlRef , height );
1470}
1471
1472OSStatus wxMacDataBrowserControl::GetDefaultRowHeight( UInt16 * height ) const
1473{
1474 return GetDataBrowserTableViewRowHeight( m_controlRef, height );
1475}
1476
1477OSStatus wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item , UInt16 height)
1478{
1479 return SetDataBrowserTableViewItemRowHeight( m_controlRef, item , height );
1480}
1481
1482OSStatus wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const
1483{
1484 return GetDataBrowserTableViewItemRowHeight( m_controlRef, item , height);
1485}
1486
1487OSStatus wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const
1488{
1489 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
1490}
1491
1492OSStatus wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width )
1493{
1494 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
1495}
1496
1497OSStatus wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16 *width ) const
1498{
1499 return GetDataBrowserTableViewColumnWidth( m_controlRef , width );
1500}
1501
1502OSStatus wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width )
1503{
1504 return SetDataBrowserTableViewColumnWidth( m_controlRef , width );
1505}
1506
1507OSStatus wxMacDataBrowserControl::GetColumnCount(UInt32* numColumns) const
1508{
1509 return GetDataBrowserTableViewColumnCount( m_controlRef, numColumns);
1510}
1511
1512OSStatus wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column,
1513 UInt32 *position) const
1514{
1515 return GetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
1516}
1517
1518OSStatus wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column, UInt32 position)
1519{
1520 return SetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
1521}
1522
1523OSStatus wxMacDataBrowserControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const
1524{
1525 return GetDataBrowserScrollPosition( m_controlRef , top , left );
1526}
1527
1528OSStatus wxMacDataBrowserControl::SetScrollPosition( UInt32 top , UInt32 left )
1529{
1530 return SetDataBrowserScrollPosition( m_controlRef , top , left );
1531}
1532
1533OSStatus wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID *column ) const
1534{
1535 return GetDataBrowserSortProperty( m_controlRef , column );
1536}
1537
1538OSStatus wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column )
1539{
1540 return SetDataBrowserSortProperty( m_controlRef , column );
1541}
1542
1543OSStatus wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder *order ) const
1544{
1545 return GetDataBrowserSortOrder( m_controlRef , order );
1546}
1547
1548OSStatus wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order )
1549{
1550 return SetDataBrowserSortOrder( m_controlRef , order );
1551}
1552
1553OSStatus wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property,
1554 DataBrowserPropertyFlags *flags ) const
1555{
1556 return GetDataBrowserPropertyFlags( m_controlRef , property , flags );
1557}
1558
1559OSStatus wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property,
1560 DataBrowserPropertyFlags flags )
1561{
1562 return SetDataBrowserPropertyFlags( m_controlRef , property , flags );
1563}
1564
1565OSStatus wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property,
1566 DataBrowserListViewHeaderDesc *desc ) const
1567{
1568 return GetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
1569}
1570
1571OSStatus wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property,
1572 DataBrowserListViewHeaderDesc *desc )
1573{
1574 return SetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
1575}
1576
1577OSStatus wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property ,
1578 Boolean expandableRows )
1579{
1580 return SetDataBrowserListViewDisclosureColumn( m_controlRef, property, expandableRows);
1581}
1582
1583// ============================================================================
1584// Higher-level Databrowser
1585// ============================================================================
1586//
1587// basing on data item objects
1588//
1589
1590wxMacDataItem::wxMacDataItem()
1591{
1592 m_data = NULL;
1593 m_order = 0;
1594 m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
1595}
1596
1597wxMacDataItem::~wxMacDataItem()
1598{
1599}
1600
1601void wxMacDataItem::SetOrder( SInt32 order )
1602{
1603 m_order = order;
1604}
1605
1606SInt32 wxMacDataItem::GetOrder() const
1607{
1608 return m_order;
1609}
1610
1611void wxMacDataItem::SetData( void* data)
1612{
1613 m_data = data;
1614}
1615
1616void* wxMacDataItem::GetData() const
1617{
1618 return m_data;
1619}
1620
1621short wxMacDataItem::GetColumn()
1622{
1623 return m_colId;
1624}
1625
1626void wxMacDataItem::SetColumn( short col )
1627{
1628 m_colId = col;
1629}
1630
1631void wxMacDataItem::SetLabel( const wxString& str)
1632{
1633 m_label = str;
1634 m_cfLabel.Assign( str , wxLocale::GetSystemEncoding());
1635}
1636
1637const wxString& wxMacDataItem::GetLabel() const
1638{
1639 return m_label;
1640}
1641
1642bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *owner ,
1643 const wxMacDataItem* rhs,
1644 DataBrowserPropertyID sortProperty) const
1645{
1646 const wxMacDataItem* otherItem = dynamic_cast<const wxMacDataItem*>(rhs);
1647 bool retval = false;
1648
1649 if ( sortProperty == m_colId && owner->GetSortOrder() != SortOrder_None){
1650 retval = m_label.CmpNoCase( otherItem->m_label) < 0;
1651 }
1652
1653 else if ( owner->GetSortOrder() == SortOrder_None || sortProperty == kNumericOrderColumnId )
1654 retval = m_order < otherItem->m_order;
1655
1656 return retval;
1657}
1658
1659OSStatus wxMacDataItem::GetSetData( wxMacDataItemBrowserControl *owner ,
1660 DataBrowserPropertyID property,
1661 DataBrowserItemDataRef itemData,
1662 bool changeValue )
1663{
1664 OSStatus err = errDataBrowserPropertyNotSupported;
1665 if ( !changeValue )
1666 {
1667 if ( property == m_colId ){
1668 err = ::SetDataBrowserItemDataText( itemData, m_cfLabel );
1669 err = noErr;
1670 }
1671 else if ( property == kNumericOrderColumnId ){
1672 err = ::SetDataBrowserItemDataValue( itemData, m_order );
1673 err = noErr;
1674 }
1675 else{
1676 }
1677 }
1678 else
1679 {
1680 switch (property)
1681 {
1682 // no editable props here
1683 default:
1684 break;
1685 }
1686 }
1687
1688 return err;
1689}
1690
1691void wxMacDataItem::Notification(wxMacDataItemBrowserControl *owner ,
1692 DataBrowserItemNotification message,
1693 DataBrowserItemDataRef itemData ) const
1694{
1695}
1696
1697
1698wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style) :
1699 wxMacDataBrowserControl( peer, pos, size, style )
1700{
1701 m_suppressSelection = false;
1702 m_sortOrder = SortOrder_None;
1703 m_clientDataItemsType = wxClientData_None;
1704}
1705
1706ListSortOrder wxMacDataItemBrowserControl::GetSortOrder() const
1707{
1708 return m_sortOrder;
1709}
1710
1711void wxMacDataItemBrowserControl::SetSortOrder(const ListSortOrder sort)
1712{
1713 m_sortOrder = sort;
1714}
1715
1716wxMacDataItem* wxMacDataItemBrowserControl::CreateItem()
1717{
1718 return new wxMacDataItem();
1719}
1720
1721wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser)
1722{
1723 m_former = browser->SuppressSelection(true);
1724 m_browser = browser;
1725}
1726
1727wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1728{
1729 m_browser->SuppressSelection(m_former);
1730}
1731
1732bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress )
1733{
1734 bool former = m_suppressSelection;
1735 m_suppressSelection = suppress;
1736
1737 return former;
1738}
1739
1740Boolean wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID,
1741 DataBrowserItemID itemTwoID,
1742 DataBrowserPropertyID sortProperty)
1743{
1744 wxMacDataItem* itemOne = (wxMacDataItem*) itemOneID;
1745 wxMacDataItem* itemTwo = (wxMacDataItem*) itemTwoID;
1746 return CompareItems( itemOne , itemTwo , sortProperty );
1747}
1748
1749Boolean wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem* itemOne,
1750 const wxMacDataItem* itemTwo,
1751 DataBrowserPropertyID sortProperty)
1752{
1753 Boolean retval = false;
1754 if ( itemOne != NULL )
1755 retval = itemOne->IsLessThan( this , itemTwo , sortProperty);
1756 return retval;
1757}
1758
1759OSStatus wxMacDataItemBrowserControl::GetSetItemData(
1760 DataBrowserItemID itemID,
1761 DataBrowserPropertyID property,
1762 DataBrowserItemDataRef itemData,
1763 Boolean changeValue )
1764{
1765 wxMacDataItem* item = (wxMacDataItem*) itemID;
1766 return GetSetItemData(item, property, itemData , changeValue );
1767}
1768
1769OSStatus wxMacDataItemBrowserControl::GetSetItemData(
1770 wxMacDataItem* item,
1771 DataBrowserPropertyID property,
1772 DataBrowserItemDataRef itemData,
1773 Boolean changeValue )
1774{
1775 OSStatus err = errDataBrowserPropertyNotSupported;
1776 switch( property )
1777 {
1778 case kDataBrowserContainerIsClosableProperty :
1779 case kDataBrowserContainerIsSortableProperty :
1780 case kDataBrowserContainerIsOpenableProperty :
1781 // right now default behaviour on these
1782 break;
1783 default :
1784
1785 if ( item != NULL ){
1786 err = item->GetSetData( this, property , itemData , changeValue );
1787 }
1788 break;
1789
1790 }
1791 return err;
1792}
1793
1794void wxMacDataItemBrowserControl::ItemNotification(
1795 DataBrowserItemID itemID,
1796 DataBrowserItemNotification message,
1797 DataBrowserItemDataRef itemData)
1798{
1799 wxMacDataItem* item = (wxMacDataItem*) itemID;
1800 ItemNotification( item , message, itemData);
1801}
1802
1803void wxMacDataItemBrowserControl::ItemNotification(
1804 const wxMacDataItem* item,
1805 DataBrowserItemNotification message,
1806 DataBrowserItemDataRef itemData)
1807{
1808 if (item != NULL)
1809 item->Notification( this, message, itemData);
1810}
1811
1812unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem* container,
1813 bool recurse , DataBrowserItemState state) const
1814{
1815 UInt32 numItems = 0;
1816 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID)container,
1817 recurse, state, &numItems ) );
1818 return numItems;
1819}
1820
1821unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem* container,
1822 bool recurse ) const
1823{
1824 return GetItemCount( container, recurse, kDataBrowserItemIsSelected );
1825
1826}
1827
1828void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem* container,
1829 bool recurse , DataBrowserItemState state, wxArrayMacDataItemPtr &items) const
1830{
1831 Handle handle = NewHandle(0);
1832 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID)container ,
1833 recurse , state, handle) );
1834
1835 int itemCount = GetHandleSize(handle)/sizeof(DataBrowserItemID);
1836 HLock( handle );
1837 wxMacDataItemPtr* itemsArray = (wxMacDataItemPtr*) *handle;
1838 for ( int i = 0; i < itemCount; ++i)
1839 {
1840 items.Add(itemsArray[i]);
1841 }
1842 HUnlock( handle );
1843 DisposeHandle( handle );
1844}
1845
1846unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem* item) const
1847{
1848 DataBrowserTableViewRowIndex row;
1849 OSStatus err = GetItemRow( (DataBrowserItemID) item , &row);
1850 wxASSERT( err == noErr);
1851 return row;
1852}
1853
1854wxMacDataItem* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n) const
1855{
1856 DataBrowserItemID id;
1857 OSStatus err = GetItemID( (DataBrowserTableViewRowIndex) n , &id);
1858 wxASSERT( err == noErr);
1859 return (wxMacDataItem*) id;
1860}
1861
1862void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem *container,
1863 const wxMacDataItem *item , DataBrowserPropertyID property) const
1864{
1865 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, 1,
1866 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty /* notSorted */, property ) );
1867}
1868
1869void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem *container,
1870 wxArrayMacDataItemPtr &itemArray , DataBrowserPropertyID property) const
1871{
1872 unsigned int noItems = itemArray.GetCount();
1873 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1874 for ( unsigned int i = 0; i < noItems; ++i )
1875 items[i] = (DataBrowserItemID) itemArray[i];
1876
1877 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, noItems,
1878 items, kDataBrowserItemNoProperty /* notSorted */, property ) );
1879 delete [] items;
1880}
1881
1882void wxMacDataItemBrowserControl::InsertColumn(int colId, DataBrowserPropertyType colType,
1883 const wxString& title, SInt16 just, int defaultWidth)
1884{
1885 DataBrowserListViewColumnDesc columnDesc;
1886 columnDesc.headerBtnDesc.titleOffset = 0;
1887 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
1888
1889 columnDesc.headerBtnDesc.btnFontStyle.flags =
1890 kControlUseFontMask | kControlUseJustMask;
1891
1892 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
1893 columnDesc.headerBtnDesc.btnFontStyle.just = just;
1894 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
1895 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
1896
1897 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1898 // defined for other modes?
1899 wxFontEncoding enc;
1900 if ( m_font.Ok() )
1901 enc = m_font.GetEncoding();
1902 else
1903 enc = wxLocale::GetSystemEncoding();
1904 wxMacCFStringHolder cfTitle;
1905 cfTitle.Assign( title, enc );
1906 columnDesc.headerBtnDesc.titleString = cfTitle;
1907
1908 columnDesc.headerBtnDesc.minimumWidth = 0;
1909 columnDesc.headerBtnDesc.maximumWidth = 30000;
1910
1911 columnDesc.propertyDesc.propertyID = (kMinColumnId + colId);
1912 columnDesc.propertyDesc.propertyType = colType;
1913 columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewDefaultColumnFlags | kDataBrowserListViewTypeSelectColumn;;
1914#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1915 columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewNoGapForIconInHeaderButton;
1916#endif
1917
1918 verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
1919
1920 if (defaultWidth > 0){
1921 SetColumnWidth(colId, defaultWidth);
1922 }
1923
1924}
1925
1926void wxMacDataItemBrowserControl::SetColumnWidth(int colId, int width)
1927{
1928 DataBrowserPropertyID id;
1929 GetColumnIDFromIndex(colId, &id);
1930 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id, width));
1931}
1932
1933int wxMacDataItemBrowserControl::GetColumnWidth(int colId)
1934{
1935 DataBrowserPropertyID id;
1936 GetColumnIDFromIndex(colId, &id);
1937 UInt16 result;
1938 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id, &result));
1939 return result;
1940}
1941
1942void wxMacDataItemBrowserControl::AddItem(wxMacDataItem *container, wxMacDataItem *item)
1943{
1944 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, 1,
1945 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ) );
1946}
1947
1948void wxMacDataItemBrowserControl::AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray )
1949{
1950 unsigned int noItems = itemArray.GetCount();
1951 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1952 for ( unsigned int i = 0; i < noItems; ++i )
1953 items[i] = (DataBrowserItemID) itemArray[i];
1954
1955 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, noItems,
1956 (DataBrowserItemID*) items, kDataBrowserItemNoProperty ) );
1957 delete [] items;
1958}
1959
1960void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem *container, wxMacDataItem* item)
1961{
1962 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 1,
1963 (UInt32*) &item, kDataBrowserItemNoProperty );
1964 verify_noerr( err );
1965}
1966
1967void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray)
1968{
1969 unsigned int noItems = itemArray.GetCount();
1970 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1971 for ( unsigned int i = 0; i < noItems; ++i )
1972 items[i] = (DataBrowserItemID) itemArray[i];
1973
1974 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, noItems,
1975 (UInt32*) items, kDataBrowserItemNoProperty );
1976 verify_noerr( err );
1977 delete [] items;
1978}
1979
1980void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem *container)
1981{
1982 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 0 , NULL , kDataBrowserItemNoProperty );
1983 verify_noerr( err );
1984}
1985
1986void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem* item , DataBrowserSetOption option)
1987{
1988 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID*) &item, option ));
1989}
1990
1991void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option)
1992{
1993 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL , option ));
1994}
1995
1996void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr &itemArray , DataBrowserSetOption option)
1997{
1998 unsigned int noItems = itemArray.GetCount();
1999 DataBrowserItemID *items = new DataBrowserItemID[noItems];
2000 for ( unsigned int i = 0; i < noItems; ++i )
2001 items[i] = (DataBrowserItemID) itemArray[i];
2002
2003 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems, (DataBrowserItemID*) items, option ));
2004 delete [] items;
2005}
2006
2007Boolean wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem* item) const
2008{
2009 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID) item);
2010}
2011
2012void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options)
2013{
2014 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID) item, kDataBrowserNoItem , options ) );
2015}
2016
2017void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const
2018{
2019 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID*) first, (DataBrowserItemID*) last) );
2020}
2021
2022wxClientDataType wxMacDataItemBrowserControl::GetClientDataType() const
2023{
2024 return m_clientDataItemsType;
2025}
2026void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType)
2027{
2028 m_clientDataItemsType = clientDataItemsType;
2029}
2030
2031unsigned int wxMacDataItemBrowserControl::MacGetCount() const
2032{
2033 return GetItemCount(wxMacDataBrowserRootContainer,false,kDataBrowserItemAnyState);
2034}
2035
2036void wxMacDataItemBrowserControl::MacDelete( unsigned int n )
2037{
2038 wxMacDataItem* item = (wxMacDataItem*)GetItemFromLine( n );
2039 RemoveItem( wxMacDataBrowserRootContainer, item );
2040}
2041
2042void wxMacDataItemBrowserControl::MacInsert( unsigned int n, const wxString& text, int column )
2043{
2044 wxMacDataItem* newItem = CreateItem();
2045 newItem->SetLabel( text );
2046 if ( column != -1 )
2047 newItem->SetColumn( kMinColumnId + column );
2048
2049 if ( m_sortOrder == SortOrder_None )
2050 {
2051 // increase the order of the lines to be shifted
2052 unsigned int lines = MacGetCount();
2053 for ( unsigned int i = n; i < lines; ++i)
2054 {
2055 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(i);
2056 iter->SetOrder( iter->GetOrder() + 1 );
2057 }
2058
2059 SInt32 frontLineOrder = 0;
2060 if ( n > 0 )
2061 {
2062 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(n-1);
2063 frontLineOrder = iter->GetOrder();
2064 }
2065 newItem->SetOrder( frontLineOrder + 1 );
2066 }
2067
2068 AddItem( wxMacDataBrowserRootContainer, newItem );
2069}
2070
2071void wxMacDataItemBrowserControl::MacInsert( unsigned int n, const wxArrayString& items, int column )
2072{
2073 size_t itemsCount = items.GetCount();
2074 if ( itemsCount == 0 )
2075 return;
2076
2077 SInt32 frontLineOrder = 0;
2078
2079 if ( m_sortOrder == SortOrder_None )
2080 {
2081 // increase the order of the lines to be shifted
2082 unsigned int lines = MacGetCount();
2083 for ( unsigned int i = n; i < lines; ++i)
2084 {
2085 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(i);
2086 iter->SetOrder( iter->GetOrder() + itemsCount );
2087 }
2088 if ( n > 0 )
2089 {
2090 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(n-1);
2091 frontLineOrder = iter->GetOrder();
2092 }
2093 }
2094
2095 wxArrayMacDataItemPtr ids;
2096 ids.SetCount( itemsCount );
2097
2098 for ( unsigned int i = 0; i < itemsCount; ++i )
2099 {
2100 wxMacDataItem* item = CreateItem();
2101 item->SetLabel( items[i]);
2102 if ( column != -1 )
2103 item->SetColumn( kMinColumnId + column );
2104
2105 if ( m_sortOrder == SortOrder_None )
2106 item->SetOrder( frontLineOrder + 1 + i );
2107
2108 ids[i] = item;
2109 }
2110
2111 AddItems( wxMacDataBrowserRootContainer, ids );
2112}
2113
2114int wxMacDataItemBrowserControl::MacAppend( const wxString& text)
2115{
2116 wxMacDataItem* item = CreateItem();
2117 item->SetLabel( text );
2118 if ( m_sortOrder == SortOrder_None )
2119 {
2120 unsigned int lines = MacGetCount();
2121 if ( lines == 0 )
2122 item->SetOrder( 1 );
2123 else
2124 {
2125 wxMacDataItem* frontItem = (wxMacDataItem*) GetItemFromLine(lines-1);
2126 item->SetOrder( frontItem->GetOrder() + 1 );
2127 }
2128 }
2129 AddItem( wxMacDataBrowserRootContainer, item );
2130
2131 return GetLineFromItem(item);
2132}
2133
2134void wxMacDataItemBrowserControl::MacClear()
2135{
2136 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
2137 RemoveAllItems(wxMacDataBrowserRootContainer);
2138}
2139
2140void wxMacDataItemBrowserControl::MacDeselectAll()
2141{
2142 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
2143 SetSelectedAllItems( kDataBrowserItemsRemove );
2144}
2145
2146void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n, bool select, bool multi )
2147{
2148 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n);
2149 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
2150
2151 if ( IsItemSelected( item ) != select )
2152 {
2153 if ( select )
2154 SetSelectedItem( item, multi ? kDataBrowserItemsAdd : kDataBrowserItemsAssign );
2155 else
2156 SetSelectedItem( item, kDataBrowserItemsRemove );
2157 }
2158
2159 MacScrollTo( n );
2160}
2161
2162bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n ) const
2163{
2164 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n);
2165 return IsItemSelected( item );
2166}
2167
2168int wxMacDataItemBrowserControl::MacGetSelection() const
2169{
2170 wxMacDataItemPtr first, last;
2171 GetSelectionAnchor( &first, &last );
2172
2173 if ( first != NULL )
2174 {
2175 return GetLineFromItem( first );
2176 }
2177
2178 return -1;
2179}
2180
2181int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt& aSelections ) const
2182{
2183 aSelections.Empty();
2184 wxArrayMacDataItemPtr selectedItems;
2185 GetItems( wxMacDataBrowserRootContainer, false , kDataBrowserItemIsSelected, selectedItems);
2186
2187 int count = selectedItems.GetCount();
2188
2189 for ( int i = 0; i < count; ++i)
2190 {
2191 aSelections.Add(GetLineFromItem(selectedItems[i]));
2192 }
2193
2194 return count;
2195}
2196
2197void wxMacDataItemBrowserControl::MacSetString( unsigned int n, const wxString& text )
2198{
2199 // as we don't store the strings we only have to issue a redraw
2200 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n);
2201 item->SetLabel( text );
2202 UpdateItem( wxMacDataBrowserRootContainer, item , kTextColumnId );
2203}
2204
2205wxString wxMacDataItemBrowserControl::MacGetString( unsigned int n ) const
2206{
2207 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
2208 return item->GetLabel();
2209}
2210
2211void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n, void * data)
2212{
2213 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n);
2214 item->SetData( data );
2215 // not displayed, therefore no Update infos to DataBrowser
2216}
2217
2218void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n) const
2219{
2220 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
2221 return item->GetData();
2222}
2223
2224void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n )
2225{
2226 RevealItem( GetItemFromLine( n) , kDataBrowserRevealWithoutSelecting );
2227}
2228
2229
2230
2231//
2232// Tab Control
2233//
2234
2235OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable )
2236{
2237 return ::SetTabEnabled( m_controlRef , tabNo , enable );
2238}
2239
2240//
2241// Quartz Support
2242//
2243
2244#ifdef __WXMAC_OSX__
2245// snippets from Sketch Sample from Apple :
2246
2247#define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
2248
2249/*
2250 This function locates, opens, and returns the profile reference for the calibrated
2251 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
2252 with the profile reference this function returns.
2253*/
2254CMProfileRef wxMacOpenGenericProfile()
2255{
2256 static CMProfileRef cachedRGBProfileRef = NULL;
2257
2258 // we only create the profile reference once
2259 if (cachedRGBProfileRef == NULL)
2260 {
2261 CMProfileLocation loc;
2262
2263 loc.locType = cmPathBasedProfile;
2264 strcpy(loc.u.pathLoc.path, kGenericRGBProfilePathStr);
2265
2266 verify_noerr( CMOpenProfile(&cachedRGBProfileRef, &loc) );
2267 }
2268
2269 // clone the profile reference so that the caller has their own reference, not our cached one
2270 if (cachedRGBProfileRef)
2271 CMCloneProfileRef(cachedRGBProfileRef);
2272
2273 return cachedRGBProfileRef;
2274}
2275
2276/*
2277 Return the generic RGB color space. This is a 'get' function and the caller should
2278 not release the returned value unless the caller retains it first. Usually callers
2279 of this routine will immediately use the returned colorspace with CoreGraphics
2280 so they typically do not need to retain it themselves.
2281
2282 This function creates the generic RGB color space once and hangs onto it so it can
2283 return it whenever this function is called.
2284*/
2285
2286CGColorSpaceRef wxMacGetGenericRGBColorSpace()
2287{
2288 static wxMacCFRefHolder<CGColorSpaceRef> genericRGBColorSpace;
2289
2290 if (genericRGBColorSpace == NULL)
2291 {
2292 if ( UMAGetSystemVersion() >= 0x1040 )
2293 {
2294 genericRGBColorSpace.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
2295 }
2296 else
2297 {
2298 CMProfileRef genericRGBProfile = wxMacOpenGenericProfile();
2299
2300 if (genericRGBProfile)
2301 {
2302 genericRGBColorSpace.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile) );
2303
2304 wxASSERT_MSG( genericRGBColorSpace != NULL, wxT("couldn't create the generic RGB color space") );
2305
2306 // we opened the profile so it is up to us to close it
2307 CMCloseProfile(genericRGBProfile);
2308 }
2309 }
2310 }
2311
2312 return genericRGBColorSpace;
2313}
2314#endif
2315
2316wxMacPortSaver::wxMacPortSaver( GrafPtr port )
2317{
2318 ::GetPort( &m_port );
2319 ::SetPort( port );
2320}
2321
2322wxMacPortSaver::~wxMacPortSaver()
2323{
2324 ::SetPort( m_port );
2325}
2326
2327#endif // wxUSE_GUI