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