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