]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/utils.cpp
don't assert in SetSelection(wxNOT_FOUND), just clear text zone contents
[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 CFRelease(m_controlRef);
800 m_controlRef = NULL;
801 }
802
803 void wxMacControl::SetReference( URefCon data )
804 {
805 SetControlReference( m_controlRef , data );
806 }
807
808 OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const
809 {
810 return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize );
811 }
812
813 OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const
814 {
815 return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize );
816 }
817
818 OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData)
819 {
820 return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData );
821 }
822
823 OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions )
824 {
825 #if TARGET_API_MAC_OSX
826 return SendEventToEventTargetWithOptions( event,
827 HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions );
828 #else
829 #pragma unused(inOptions)
830 return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) );
831 #endif
832 }
833
834 OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions )
835 {
836 wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess );
837
838 event.SetParameter<HICommand>(kEventParamDirectObject,command);
839
840 return SendEvent( event , inOptions );
841 }
842
843 OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions )
844 {
845 HICommand command;
846
847 memset( &command, 0 , sizeof(command) );
848 command.commandID = commandID;
849 return SendHICommand( command , inOptions );
850 }
851
852 void wxMacControl::Flash( ControlPartCode part , UInt32 ticks )
853 {
854 unsigned long finalTicks;
855
856 HiliteControl( m_controlRef , part );
857 Delay( ticks , &finalTicks );
858 HiliteControl( m_controlRef , kControlNoPart );
859 }
860
861 SInt32 wxMacControl::GetValue() const
862 {
863 return ::GetControl32BitValue( m_controlRef );
864 }
865
866 SInt32 wxMacControl::GetMaximum() const
867 {
868 return ::GetControl32BitMaximum( m_controlRef );
869 }
870
871 SInt32 wxMacControl::GetMinimum() const
872 {
873 return ::GetControl32BitMinimum( m_controlRef );
874 }
875
876 void wxMacControl::SetValue( SInt32 v )
877 {
878 ::SetControl32BitValue( m_controlRef , v );
879 }
880
881 void wxMacControl::SetMinimum( SInt32 v )
882 {
883 ::SetControl32BitMinimum( m_controlRef , v );
884 }
885
886 void wxMacControl::SetMaximum( SInt32 v )
887 {
888 ::SetControl32BitMaximum( m_controlRef , v );
889 }
890
891 void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum )
892 {
893 ::SetControl32BitMinimum( m_controlRef , minimum );
894 ::SetControl32BitMaximum( m_controlRef , maximum );
895 ::SetControl32BitValue( m_controlRef , value );
896 }
897
898 OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart )
899 {
900 return SetKeyboardFocus( GetControlOwner( m_controlRef ), m_controlRef, focusPart );
901 }
902
903 bool wxMacControl::HasFocus() const
904 {
905 ControlRef control;
906 GetKeyboardFocus( GetUserFocusWindow() , &control );
907 return control == m_controlRef;
908 }
909
910 void wxMacControl::SetNeedsFocusRect( bool needs )
911 {
912 m_needsFocusRect = needs;
913 }
914
915 bool wxMacControl::NeedsFocusRect() const
916 {
917 return m_needsFocusRect;
918 }
919
920 void wxMacControl::VisibilityChanged(bool shown)
921 {
922 }
923
924 void wxMacControl::SuperChangedPosition()
925 {
926 }
927
928 void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle )
929 {
930 m_font = font;
931 ControlFontStyleRec fontStyle;
932 if ( font.MacGetThemeFontID() != kThemeCurrentPortFont )
933 {
934 switch ( font.MacGetThemeFontID() )
935 {
936 case kThemeSmallSystemFont :
937 fontStyle.font = kControlFontSmallSystemFont;
938 break;
939
940 case 109 : // mini font
941 fontStyle.font = -5;
942 break;
943
944 case kThemeSystemFont :
945 fontStyle.font = kControlFontBigSystemFont;
946 break;
947
948 default :
949 fontStyle.font = kControlFontBigSystemFont;
950 break;
951 }
952
953 fontStyle.flags = kControlUseFontMask;
954 }
955 else
956 {
957 fontStyle.font = font.MacGetFontNum();
958 fontStyle.style = font.MacGetFontStyle();
959 fontStyle.size = font.MacGetFontSize();
960 fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask;
961 }
962
963 fontStyle.just = teJustLeft;
964 fontStyle.flags |= kControlUseJustMask;
965 if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL )
966 fontStyle.just = teJustCenter;
967 else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT )
968 fontStyle.just = teJustRight;
969
970
971 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
972 // won't get grayed out by the system anymore
973
974 if ( foreground != *wxBLACK )
975 {
976 fontStyle.foreColor = MAC_WXCOLORREF( foreground.GetPixel() );
977 fontStyle.flags |= kControlUseForeColorMask;
978 }
979
980 ::SetControlFontStyle( m_controlRef , &fontStyle );
981 }
982
983 void wxMacControl::SetBackground( const wxBrush &WXUNUSED(brush) )
984 {
985 // TODO
986 // setting up a color proc is not recommended anymore
987 }
988
989 void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum )
990 {
991 ::SetControl32BitMinimum( m_controlRef , minimum );
992 ::SetControl32BitMaximum( m_controlRef , maximum );
993 }
994
995 short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers )
996 {
997 #ifndef __LP64__
998 return HandleControlKey( m_controlRef , keyCode , charCode , modifiers );
999 #else
1000 return 0;
1001 #endif
1002 }
1003
1004 void wxMacControl::SetActionProc( ControlActionUPP actionProc )
1005 {
1006 SetControlAction( m_controlRef , actionProc );
1007 }
1008
1009 void wxMacControl::SetViewSize( SInt32 viewSize )
1010 {
1011 SetControlViewSize(m_controlRef , viewSize );
1012 }
1013
1014 SInt32 wxMacControl::GetViewSize() const
1015 {
1016 return GetControlViewSize( m_controlRef );
1017 }
1018
1019 bool wxMacControl::IsVisible() const
1020 {
1021 return IsControlVisible( m_controlRef );
1022 }
1023
1024 void wxMacControl::SetVisibility( bool visible , bool redraw )
1025 {
1026 SetControlVisibility( m_controlRef , visible , redraw );
1027 }
1028
1029 bool wxMacControl::IsEnabled() const
1030 {
1031 #if TARGET_API_MAC_OSX
1032 return IsControlEnabled( m_controlRef );
1033 #else
1034 return IsControlActive( m_controlRef );
1035 #endif
1036 }
1037
1038 bool wxMacControl::IsActive() const
1039 {
1040 return IsControlActive( m_controlRef );
1041 }
1042
1043 void wxMacControl::Enable( bool enable )
1044 {
1045 if ( enable )
1046 EnableControl( m_controlRef );
1047 else
1048 DisableControl( m_controlRef );
1049 }
1050
1051 void wxMacControl::SetDrawingEnabled( bool enable )
1052 {
1053 HIViewSetDrawingEnabled( m_controlRef , enable );
1054 }
1055
1056 bool wxMacControl::GetNeedsDisplay() const
1057 {
1058 return HIViewGetNeedsDisplay( m_controlRef );
1059 }
1060
1061 void wxMacControl::SetNeedsDisplay( RgnHandle where )
1062 {
1063 if ( !IsVisible() )
1064 return;
1065
1066 HIViewSetNeedsDisplayInRegion( m_controlRef , where , true );
1067 }
1068
1069 void wxMacControl::SetNeedsDisplay( Rect* where )
1070 {
1071 if ( !IsVisible() )
1072 return;
1073
1074 if ( where != NULL )
1075 {
1076 RgnHandle update = NewRgn();
1077 RectRgn( update , where );
1078 HIViewSetNeedsDisplayInRegion( m_controlRef , update , true );
1079 DisposeRgn( update );
1080 }
1081 else
1082 HIViewSetNeedsDisplay( m_controlRef , true );
1083 }
1084
1085 void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to )
1086 {
1087 HIPoint hiPoint;
1088
1089 hiPoint.x = pt->x;
1090 hiPoint.y = pt->y;
1091 HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef );
1092 pt->x = (int)hiPoint.x;
1093 pt->y = (int)hiPoint.y;
1094 }
1095
1096 void wxMacControl::SetRect( Rect *r )
1097 {
1098 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1099 //CGPoint and CGSize, which have two floats each
1100 HIRect hir = { { r->left , r->top }, { r->right - r->left , r->bottom - r->top } };
1101 HIViewSetFrame ( m_controlRef , &hir );
1102 // eventuall we might have to do a SetVisibility( false , true );
1103 // before and a SetVisibility( true , true ); after
1104 }
1105
1106 void wxMacControl::GetRect( Rect *r )
1107 {
1108 GetControlBounds( m_controlRef , r );
1109 }
1110
1111 void wxMacControl::GetRectInWindowCoords( Rect *r )
1112 {
1113 UMAGetControlBoundsInWindowCoords( m_controlRef , r );
1114 }
1115
1116 void wxMacControl::GetBestRect( Rect *r )
1117 {
1118 short baselineoffset;
1119
1120 GetBestControlRect( m_controlRef , r , &baselineoffset );
1121 }
1122
1123 void wxMacControl::SetLabel( const wxString &title )
1124 {
1125 wxFontEncoding encoding;
1126
1127 if ( m_font.Ok() )
1128 encoding = m_font.GetEncoding();
1129 else
1130 encoding = wxFont::GetDefaultEncoding();
1131
1132 UMASetControlTitle( m_controlRef , title , encoding );
1133 }
1134
1135 void wxMacControl::GetFeatures( UInt32 * features )
1136 {
1137 GetControlFeatures( m_controlRef , features );
1138 }
1139
1140 OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region )
1141 {
1142 OSStatus err = GetControlRegion( m_controlRef , partCode , region );
1143 return err;
1144 }
1145
1146 OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other )
1147 {
1148 #if TARGET_API_MAC_OSX
1149 return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow,
1150 (other != NULL) ? other->m_controlRef : NULL);
1151 #else
1152 return 0;
1153 #endif
1154 }
1155
1156 #if TARGET_API_MAC_OSX
1157 // SetNeedsDisplay would not invalidate the children
1158 static void InvalidateControlAndChildren( HIViewRef control )
1159 {
1160 HIViewSetNeedsDisplay( control , true );
1161 UInt16 childrenCount = 0;
1162 OSStatus err = CountSubControls( control , &childrenCount );
1163 if ( err == errControlIsNotEmbedder )
1164 return;
1165
1166 wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") );
1167
1168 for ( UInt16 i = childrenCount; i >=1; --i )
1169 {
1170 HIViewRef child;
1171
1172 err = GetIndexedSubControl( control , i , & child );
1173 if ( err == errControlIsNotEmbedder )
1174 return;
1175
1176 InvalidateControlAndChildren( child );
1177 }
1178 }
1179 #endif
1180
1181 void wxMacControl::InvalidateWithChildren()
1182 {
1183 #if TARGET_API_MAC_OSX
1184 InvalidateControlAndChildren( m_controlRef );
1185 #endif
1186 }
1187
1188 void wxMacControl::ScrollRect( wxRect *r , int dx , int dy )
1189 {
1190 wxASSERT( r != NULL );
1191
1192 HIRect scrollarea = CGRectMake( r->x , r->y , r->width , r->height);
1193 HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy );
1194 }
1195
1196 OSType wxMacCreator = 'WXMC';
1197 OSType wxMacControlProperty = 'MCCT';
1198
1199 void wxMacControl::SetReferenceInNativeControl()
1200 {
1201 void * data = this;
1202 verify_noerr( SetControlProperty ( m_controlRef ,
1203 wxMacCreator,wxMacControlProperty, sizeof(data), &data ) );
1204 }
1205
1206 wxMacControl* wxMacControl::GetReferenceFromNativeControl(ControlRef control)
1207 {
1208 wxMacControl* ctl = NULL;
1209 ByteCount actualSize;
1210 if ( GetControlProperty( control ,wxMacCreator,wxMacControlProperty, sizeof(ctl) ,
1211 &actualSize , &ctl ) == noErr )
1212 {
1213 return ctl;
1214 }
1215 return NULL;
1216 }
1217
1218 // ============================================================================
1219 // DataBrowser Wrapper
1220 // ============================================================================
1221 //
1222 // basing on DataBrowserItemIDs
1223 //
1224
1225 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl , wxMacControl )
1226
1227 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
1228 ControlRef browser,
1229 DataBrowserItemID itemID,
1230 DataBrowserItemNotification message,
1231 DataBrowserItemDataRef itemData )
1232 {
1233 wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl);
1234 if ( ctl != 0 )
1235 {
1236 ctl->ItemNotification(itemID, message, itemData);
1237 }
1238 }
1239
1240 pascal OSStatus wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
1241 ControlRef browser,
1242 DataBrowserItemID itemID,
1243 DataBrowserPropertyID property,
1244 DataBrowserItemDataRef itemData,
1245 Boolean changeValue )
1246 {
1247 OSStatus err = errDataBrowserPropertyNotSupported;
1248 wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl);
1249 if ( ctl != 0 )
1250 {
1251 err = ctl->GetSetItemData(itemID, property, itemData, changeValue);
1252 }
1253 return err;
1254 }
1255
1256 pascal Boolean wxMacDataBrowserControl::DataBrowserCompareProc(
1257 ControlRef browser,
1258 DataBrowserItemID itemOneID,
1259 DataBrowserItemID itemTwoID,
1260 DataBrowserPropertyID sortProperty)
1261 {
1262 wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl);
1263 if ( ctl != 0 )
1264 {
1265 return ctl->CompareItems(itemOneID, itemTwoID, sortProperty);
1266 }
1267 return false;
1268 }
1269
1270 DataBrowserItemDataUPP gDataBrowserItemDataUPP = NULL;
1271 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP = NULL;
1272 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP = NULL;
1273
1274 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow* peer, const wxPoint& pos, const wxSize& size, long style) : wxMacControl( peer )
1275 {
1276 Rect bounds = wxMacGetBoundsForControl( peer, pos, size );
1277 OSStatus err = ::CreateDataBrowserControl(
1278 MAC_WXHWND(peer->MacGetTopLevelWindowRef()),
1279 &bounds, kDataBrowserListView, &m_controlRef );
1280 SetReferenceInNativeControl();
1281 verify_noerr( err );
1282 if ( gDataBrowserItemCompareUPP == NULL )
1283 gDataBrowserItemCompareUPP = NewDataBrowserItemCompareUPP(DataBrowserCompareProc);
1284 if ( gDataBrowserItemDataUPP == NULL )
1285 gDataBrowserItemDataUPP = NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc);
1286 if ( gDataBrowserItemNotificationUPP == NULL )
1287 {
1288 gDataBrowserItemNotificationUPP =
1289 #if TARGET_API_MAC_OSX
1290 (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc);
1291 #else
1292 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc);
1293 #endif
1294 }
1295
1296 DataBrowserCallbacks callbacks;
1297 InitializeDataBrowserCallbacks( &callbacks, kDataBrowserLatestCallbacks );
1298
1299 callbacks.u.v1.itemDataCallback = gDataBrowserItemDataUPP;
1300 callbacks.u.v1.itemCompareCallback = gDataBrowserItemCompareUPP;
1301 callbacks.u.v1.itemNotificationCallback = gDataBrowserItemNotificationUPP;
1302 SetCallbacks( &callbacks );
1303
1304 }
1305
1306 OSStatus wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container,
1307 Boolean recurse,
1308 DataBrowserItemState state,
1309 ItemCount *numItems) const
1310 {
1311 return GetDataBrowserItemCount( m_controlRef, container, recurse, state, numItems );
1312 }
1313
1314 OSStatus wxMacDataBrowserControl::GetItems( DataBrowserItemID container,
1315 Boolean recurse,
1316 DataBrowserItemState state,
1317 Handle items) const
1318 {
1319 return GetDataBrowserItems( m_controlRef, container, recurse, state, items );
1320 }
1321
1322 OSStatus wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options )
1323 {
1324 return SetDataBrowserSelectionFlags( m_controlRef, options );
1325 }
1326
1327 OSStatus wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc *columnDesc,
1328 DataBrowserTableViewColumnIndex position )
1329 {
1330 return AddDataBrowserListViewColumn( m_controlRef, columnDesc, position );
1331 }
1332
1333 OSStatus wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id ){
1334 return GetDataBrowserTableViewColumnProperty( m_controlRef, position, id );
1335 }
1336
1337 OSStatus wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position )
1338 {
1339 DataBrowserTableViewColumnID id;
1340 GetColumnIDFromIndex( position, &id );
1341 return RemoveDataBrowserTableViewColumn( m_controlRef, id );
1342 }
1343
1344 OSStatus wxMacDataBrowserControl::AutoSizeColumns()
1345 {
1346 return AutoSizeDataBrowserListViewColumns(m_controlRef);
1347 }
1348
1349 OSStatus wxMacDataBrowserControl::SetHasScrollBars( bool horiz, bool vert )
1350 {
1351 return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert );
1352 }
1353
1354 OSStatus wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle )
1355 {
1356 return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle );
1357 }
1358
1359 OSStatus wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height)
1360 {
1361 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
1362 }
1363
1364 OSStatus wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16 *height)
1365 {
1366 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
1367 }
1368
1369 OSStatus wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks *callbacks)
1370 {
1371 return SetDataBrowserCallbacks( m_controlRef, callbacks );
1372 }
1373
1374 OSStatus wxMacDataBrowserControl::UpdateItems(
1375 DataBrowserItemID container,
1376 UInt32 numItems,
1377 const DataBrowserItemID *items,
1378 DataBrowserPropertyID preSortProperty,
1379 DataBrowserPropertyID propertyID ) const
1380 {
1381 return UpdateDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty, propertyID );
1382 }
1383
1384 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item ) const
1385 {
1386 return IsDataBrowserItemSelected( m_controlRef, item );
1387 }
1388
1389 OSStatus wxMacDataBrowserControl::AddItems(
1390 DataBrowserItemID container,
1391 UInt32 numItems,
1392 const DataBrowserItemID *items,
1393 DataBrowserPropertyID preSortProperty )
1394 {
1395 return AddDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty );
1396 }
1397
1398 OSStatus wxMacDataBrowserControl::RemoveItems(
1399 DataBrowserItemID container,
1400 UInt32 numItems,
1401 const DataBrowserItemID *items,
1402 DataBrowserPropertyID preSortProperty )
1403 {
1404 return RemoveDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty );
1405 }
1406
1407 OSStatus wxMacDataBrowserControl::RevealItem(
1408 DataBrowserItemID item,
1409 DataBrowserPropertyID propertyID,
1410 DataBrowserRevealOptions options ) const
1411 {
1412 return RevealDataBrowserItem( m_controlRef, item, propertyID, options );
1413 }
1414
1415 OSStatus wxMacDataBrowserControl::SetSelectedItems(
1416 UInt32 numItems,
1417 const DataBrowserItemID *items,
1418 DataBrowserSetOption operation )
1419 {
1420 return SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation );
1421 }
1422
1423 OSStatus wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const
1424 {
1425 return GetDataBrowserSelectionAnchor( m_controlRef, first, last );
1426 }
1427
1428 OSStatus wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const
1429 {
1430 return GetDataBrowserTableViewItemID( m_controlRef, row, item );
1431 }
1432
1433 OSStatus wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item, DataBrowserTableViewRowIndex * row ) const
1434 {
1435 return GetDataBrowserTableViewItemRow( m_controlRef, item, row );
1436 }
1437
1438 OSStatus wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height )
1439 {
1440 return SetDataBrowserTableViewRowHeight( m_controlRef , height );
1441 }
1442
1443 OSStatus wxMacDataBrowserControl::GetDefaultRowHeight( UInt16 * height ) const
1444 {
1445 return GetDataBrowserTableViewRowHeight( m_controlRef, height );
1446 }
1447
1448 OSStatus wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item , UInt16 height)
1449 {
1450 return SetDataBrowserTableViewItemRowHeight( m_controlRef, item , height );
1451 }
1452
1453 OSStatus wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const
1454 {
1455 return GetDataBrowserTableViewItemRowHeight( m_controlRef, item , height);
1456 }
1457
1458 OSStatus wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const
1459 {
1460 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
1461 }
1462
1463 OSStatus wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width )
1464 {
1465 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
1466 }
1467
1468 OSStatus wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16 *width ) const
1469 {
1470 return GetDataBrowserTableViewColumnWidth( m_controlRef , width );
1471 }
1472
1473 OSStatus wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width )
1474 {
1475 return SetDataBrowserTableViewColumnWidth( m_controlRef , width );
1476 }
1477
1478 OSStatus wxMacDataBrowserControl::GetColumnCount(UInt32* numColumns) const
1479 {
1480 return GetDataBrowserTableViewColumnCount( m_controlRef, numColumns);
1481 }
1482
1483 OSStatus wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column,
1484 DataBrowserTableViewColumnIndex *position) const
1485 {
1486 return GetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
1487 }
1488
1489 OSStatus wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position)
1490 {
1491 return SetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
1492 }
1493
1494 OSStatus wxMacDataBrowserControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const
1495 {
1496 return GetDataBrowserScrollPosition( m_controlRef , top , left );
1497 }
1498
1499 OSStatus wxMacDataBrowserControl::SetScrollPosition( UInt32 top , UInt32 left )
1500 {
1501 return SetDataBrowserScrollPosition( m_controlRef , top , left );
1502 }
1503
1504 OSStatus wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID *column ) const
1505 {
1506 return GetDataBrowserSortProperty( m_controlRef , column );
1507 }
1508
1509 OSStatus wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column )
1510 {
1511 return SetDataBrowserSortProperty( m_controlRef , column );
1512 }
1513
1514 OSStatus wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder *order ) const
1515 {
1516 return GetDataBrowserSortOrder( m_controlRef , order );
1517 }
1518
1519 OSStatus wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order )
1520 {
1521 return SetDataBrowserSortOrder( m_controlRef , order );
1522 }
1523
1524 OSStatus wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property,
1525 DataBrowserPropertyFlags *flags ) const
1526 {
1527 return GetDataBrowserPropertyFlags( m_controlRef , property , flags );
1528 }
1529
1530 OSStatus wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property,
1531 DataBrowserPropertyFlags flags )
1532 {
1533 return SetDataBrowserPropertyFlags( m_controlRef , property , flags );
1534 }
1535
1536 OSStatus wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property,
1537 DataBrowserListViewHeaderDesc *desc ) const
1538 {
1539 return GetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
1540 }
1541
1542 OSStatus wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property,
1543 DataBrowserListViewHeaderDesc *desc )
1544 {
1545 return SetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
1546 }
1547
1548 OSStatus wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property ,
1549 Boolean expandableRows )
1550 {
1551 return SetDataBrowserListViewDisclosureColumn( m_controlRef, property, expandableRows);
1552 }
1553
1554 // ============================================================================
1555 // Higher-level Databrowser
1556 // ============================================================================
1557 //
1558 // basing on data item objects
1559 //
1560
1561 wxMacDataItem::wxMacDataItem()
1562 {
1563 m_data = NULL;
1564
1565 m_order = 0;
1566 m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
1567 }
1568
1569 wxMacDataItem::~wxMacDataItem()
1570 {
1571 }
1572
1573 void wxMacDataItem::SetOrder( SInt32 order )
1574 {
1575 m_order = order;
1576 }
1577
1578 SInt32 wxMacDataItem::GetOrder() const
1579 {
1580 return m_order;
1581 }
1582
1583 void wxMacDataItem::SetData( void* data)
1584 {
1585 m_data = data;
1586 }
1587
1588 void* wxMacDataItem::GetData() const
1589 {
1590 return m_data;
1591 }
1592
1593 short wxMacDataItem::GetColumn()
1594 {
1595 return m_colId;
1596 }
1597
1598 void wxMacDataItem::SetColumn( short col )
1599 {
1600 m_colId = col;
1601 }
1602
1603 void wxMacDataItem::SetLabel( const wxString& str)
1604 {
1605 m_label = str;
1606 m_cfLabel.Assign( str , wxLocale::GetSystemEncoding());
1607 }
1608
1609 const wxString& wxMacDataItem::GetLabel() const
1610 {
1611 return m_label;
1612 }
1613
1614 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *owner ,
1615 const wxMacDataItem* rhs,
1616 DataBrowserPropertyID sortProperty) const
1617 {
1618 const wxMacDataItem* otherItem = wx_const_cast(wxMacDataItem*,rhs);
1619 bool retval = false;
1620
1621 if ( sortProperty == m_colId ){
1622 retval = m_label.CmpNoCase( otherItem->m_label) < 0;
1623 }
1624
1625 else if ( sortProperty == kNumericOrderColumnId )
1626 retval = m_order < otherItem->m_order;
1627
1628 return retval;
1629 }
1630
1631 OSStatus wxMacDataItem::GetSetData( wxMacDataItemBrowserControl *owner ,
1632 DataBrowserPropertyID property,
1633 DataBrowserItemDataRef itemData,
1634 bool changeValue )
1635 {
1636 OSStatus err = errDataBrowserPropertyNotSupported;
1637 if ( !changeValue )
1638 {
1639 if ( property == m_colId ){
1640 err = ::SetDataBrowserItemDataText( itemData, m_cfLabel );
1641 err = noErr;
1642 }
1643 else if ( property == kNumericOrderColumnId ){
1644 err = ::SetDataBrowserItemDataValue( itemData, m_order );
1645 err = noErr;
1646 }
1647 else{
1648 }
1649 }
1650 else
1651 {
1652 switch (property)
1653 {
1654 // no editable props here
1655 default:
1656 break;
1657 }
1658 }
1659
1660 return err;
1661 }
1662
1663 void wxMacDataItem::Notification(wxMacDataItemBrowserControl *owner ,
1664 DataBrowserItemNotification message,
1665 DataBrowserItemDataRef itemData ) const
1666 {
1667 }
1668
1669 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl , wxMacDataBrowserControl )
1670
1671 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style) :
1672 wxMacDataBrowserControl( peer, pos, size, style )
1673 {
1674 m_suppressSelection = false;
1675 m_sortOrder = SortOrder_None;
1676 m_clientDataItemsType = wxClientData_None;
1677 }
1678
1679 wxMacDataItem* wxMacDataItemBrowserControl::CreateItem()
1680 {
1681 return new wxMacDataItem();
1682 }
1683
1684 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser)
1685 {
1686 m_former = browser->SuppressSelection(true);
1687 m_browser = browser;
1688 }
1689
1690 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1691 {
1692 m_browser->SuppressSelection(m_former);
1693 }
1694
1695 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress )
1696 {
1697 bool former = m_suppressSelection;
1698 m_suppressSelection = suppress;
1699
1700 return former;
1701 }
1702
1703 Boolean wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID,
1704 DataBrowserItemID itemTwoID,
1705 DataBrowserPropertyID sortProperty)
1706 {
1707 wxMacDataItem* itemOne = (wxMacDataItem*) itemOneID;
1708 wxMacDataItem* itemTwo = (wxMacDataItem*) itemTwoID;
1709 return CompareItems( itemOne , itemTwo , sortProperty );
1710 }
1711
1712 Boolean wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem* itemOne,
1713 const wxMacDataItem* itemTwo,
1714 DataBrowserPropertyID sortProperty)
1715 {
1716 Boolean retval = false;
1717 if ( itemOne != NULL )
1718 retval = itemOne->IsLessThan( this , itemTwo , sortProperty);
1719 return retval;
1720 }
1721
1722 OSStatus wxMacDataItemBrowserControl::GetSetItemData(
1723 DataBrowserItemID itemID,
1724 DataBrowserPropertyID property,
1725 DataBrowserItemDataRef itemData,
1726 Boolean changeValue )
1727 {
1728 wxMacDataItem* item = (wxMacDataItem*) itemID;
1729 return GetSetItemData(item, property, itemData , changeValue );
1730 }
1731
1732 OSStatus wxMacDataItemBrowserControl::GetSetItemData(
1733 wxMacDataItem* item,
1734 DataBrowserPropertyID property,
1735 DataBrowserItemDataRef itemData,
1736 Boolean changeValue )
1737 {
1738 OSStatus err = errDataBrowserPropertyNotSupported;
1739 switch( property )
1740 {
1741 case kDataBrowserContainerIsClosableProperty :
1742 case kDataBrowserContainerIsSortableProperty :
1743 case kDataBrowserContainerIsOpenableProperty :
1744 // right now default behaviour on these
1745 break;
1746 default :
1747
1748 if ( item != NULL ){
1749 err = item->GetSetData( this, property , itemData , changeValue );
1750 }
1751 break;
1752
1753 }
1754 return err;
1755 }
1756
1757 void wxMacDataItemBrowserControl::ItemNotification(
1758 DataBrowserItemID itemID,
1759 DataBrowserItemNotification message,
1760 DataBrowserItemDataRef itemData)
1761 {
1762 wxMacDataItem* item = (wxMacDataItem*) itemID;
1763 ItemNotification( item , message, itemData);
1764 }
1765
1766 void wxMacDataItemBrowserControl::ItemNotification(
1767 const wxMacDataItem* item,
1768 DataBrowserItemNotification message,
1769 DataBrowserItemDataRef itemData)
1770 {
1771 if (item != NULL)
1772 item->Notification( this, message, itemData);
1773 }
1774
1775 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem* container,
1776 bool recurse , DataBrowserItemState state) const
1777 {
1778 ItemCount numItems = 0;
1779 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID)container,
1780 recurse, state, &numItems ) );
1781 return numItems;
1782 }
1783
1784 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem* container,
1785 bool recurse ) const
1786 {
1787 return GetItemCount( container, recurse, kDataBrowserItemIsSelected );
1788
1789 }
1790
1791 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem* container,
1792 bool recurse , DataBrowserItemState state, wxArrayMacDataItemPtr &items) const
1793 {
1794 Handle handle = NewHandle(0);
1795 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID)container ,
1796 recurse , state, handle) );
1797
1798 int itemCount = GetHandleSize(handle)/sizeof(DataBrowserItemID);
1799 HLock( handle );
1800 wxMacDataItemPtr* itemsArray = (wxMacDataItemPtr*) *handle;
1801 for ( int i = 0; i < itemCount; ++i)
1802 {
1803 items.Add(itemsArray[i]);
1804 }
1805 HUnlock( handle );
1806 DisposeHandle( handle );
1807 }
1808
1809 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem* item) const
1810 {
1811 DataBrowserTableViewRowIndex row;
1812 OSStatus err = GetItemRow( (DataBrowserItemID) item , &row);
1813 wxASSERT( err == noErr);
1814 return row;
1815 }
1816
1817 wxMacDataItem* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n) const
1818 {
1819 DataBrowserItemID id;
1820 OSStatus err = GetItemID( (DataBrowserTableViewRowIndex) n , &id);
1821 wxASSERT( err == noErr);
1822 return (wxMacDataItem*) id;
1823 }
1824
1825 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem *container,
1826 const wxMacDataItem *item , DataBrowserPropertyID property) const
1827 {
1828 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, 1,
1829 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty /* notSorted */, property ) );
1830 }
1831
1832 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem *container,
1833 wxArrayMacDataItemPtr &itemArray , DataBrowserPropertyID property) const
1834 {
1835 unsigned int noItems = itemArray.GetCount();
1836 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1837 for ( unsigned int i = 0; i < noItems; ++i )
1838 items[i] = (DataBrowserItemID) itemArray[i];
1839
1840 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, noItems,
1841 items, kDataBrowserItemNoProperty /* notSorted */, property ) );
1842 delete [] items;
1843 }
1844
1845 void wxMacDataItemBrowserControl::InsertColumn(int colId, DataBrowserPropertyType colType,
1846 const wxString& title, SInt16 just, int defaultWidth)
1847 {
1848 DataBrowserListViewColumnDesc columnDesc;
1849 columnDesc.headerBtnDesc.titleOffset = 0;
1850 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
1851
1852 columnDesc.headerBtnDesc.btnFontStyle.flags =
1853 kControlUseFontMask | kControlUseJustMask;
1854
1855 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
1856 columnDesc.headerBtnDesc.btnFontStyle.just = just;
1857 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
1858 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
1859
1860 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1861 // defined for other modes?
1862 wxFontEncoding enc;
1863 if ( m_font.Ok() )
1864 enc = m_font.GetEncoding();
1865 else
1866 enc = wxLocale::GetSystemEncoding();
1867 wxMacCFStringHolder cfTitle;
1868 cfTitle.Assign( title, enc );
1869 columnDesc.headerBtnDesc.titleString = cfTitle;
1870
1871 columnDesc.headerBtnDesc.minimumWidth = 0;
1872 columnDesc.headerBtnDesc.maximumWidth = 30000;
1873
1874 columnDesc.propertyDesc.propertyID = (kMinColumnId + colId);
1875 columnDesc.propertyDesc.propertyType = colType;
1876 columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn;
1877 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1878 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
1879 #endif
1880 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1881 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
1882 #endif
1883
1884 verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
1885
1886 if (defaultWidth > 0){
1887 SetColumnWidth(colId, defaultWidth);
1888 }
1889
1890 }
1891
1892 void wxMacDataItemBrowserControl::SetColumnWidth(int colId, int width)
1893 {
1894 DataBrowserPropertyID id;
1895 GetColumnIDFromIndex(colId, &id);
1896 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id, width));
1897 }
1898
1899 int wxMacDataItemBrowserControl::GetColumnWidth(int colId)
1900 {
1901 DataBrowserPropertyID id;
1902 GetColumnIDFromIndex(colId, &id);
1903 UInt16 result;
1904 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id, &result));
1905 return result;
1906 }
1907
1908 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem *container, wxMacDataItem *item)
1909 {
1910 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, 1,
1911 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ) );
1912 }
1913
1914 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray )
1915 {
1916 unsigned int noItems = itemArray.GetCount();
1917 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1918 for ( unsigned int i = 0; i < noItems; ++i )
1919 items[i] = (DataBrowserItemID) itemArray[i];
1920
1921 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, noItems,
1922 (DataBrowserItemID*) items, kDataBrowserItemNoProperty ) );
1923 delete [] items;
1924 }
1925
1926 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem *container, wxMacDataItem* item)
1927 {
1928 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 1,
1929 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty );
1930 verify_noerr( err );
1931 }
1932
1933 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray)
1934 {
1935 unsigned int noItems = itemArray.GetCount();
1936 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1937 for ( unsigned int i = 0; i < noItems; ++i )
1938 items[i] = (DataBrowserItemID) itemArray[i];
1939
1940 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, noItems,
1941 (DataBrowserItemID*) items, kDataBrowserItemNoProperty );
1942 verify_noerr( err );
1943 delete [] items;
1944 }
1945
1946 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem *container)
1947 {
1948 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 0 , NULL , kDataBrowserItemNoProperty );
1949 verify_noerr( err );
1950 }
1951
1952 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem* item , DataBrowserSetOption option)
1953 {
1954 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID*) &item, option ));
1955 }
1956
1957 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option)
1958 {
1959 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL , option ));
1960 }
1961
1962 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr &itemArray , DataBrowserSetOption option)
1963 {
1964 unsigned int noItems = itemArray.GetCount();
1965 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1966 for ( unsigned int i = 0; i < noItems; ++i )
1967 items[i] = (DataBrowserItemID) itemArray[i];
1968
1969 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems, (DataBrowserItemID*) items, option ));
1970 delete [] items;
1971 }
1972
1973 Boolean wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem* item) const
1974 {
1975 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID) item);
1976 }
1977
1978 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options)
1979 {
1980 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID) item, kDataBrowserNoItem , options ) );
1981 }
1982
1983 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const
1984 {
1985 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID*) first, (DataBrowserItemID*) last) );
1986 }
1987
1988 wxClientDataType wxMacDataItemBrowserControl::GetClientDataType() const
1989 {
1990 return m_clientDataItemsType;
1991 }
1992 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType)
1993 {
1994 m_clientDataItemsType = clientDataItemsType;
1995 }
1996
1997 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1998 {
1999 return GetItemCount(wxMacDataBrowserRootContainer,false,kDataBrowserItemAnyState);
2000 }
2001
2002 void wxMacDataItemBrowserControl::MacDelete( unsigned int n )
2003 {
2004 wxMacDataItem* item = (wxMacDataItem*)GetItemFromLine( n );
2005 RemoveItem( wxMacDataBrowserRootContainer, item );
2006 }
2007
2008 void wxMacDataItemBrowserControl::MacInsert( unsigned int n, const wxString& text, int column )
2009 {
2010 wxMacDataItem* newItem = CreateItem();
2011 newItem->SetLabel( text );
2012 if ( column != -1 )
2013 newItem->SetColumn( kMinColumnId + column );
2014
2015 if ( m_sortOrder == SortOrder_None )
2016 {
2017 // increase the order of the lines to be shifted
2018 unsigned int lines = MacGetCount();
2019 for ( unsigned int i = n; i < lines; ++i)
2020 {
2021 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(i);
2022 iter->SetOrder( iter->GetOrder() + 1 );
2023 }
2024
2025 SInt32 frontLineOrder = 0;
2026 if ( n > 0 )
2027 {
2028 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(n-1);
2029 frontLineOrder = iter->GetOrder();
2030 }
2031 newItem->SetOrder( frontLineOrder + 1 );
2032 }
2033
2034 AddItem( wxMacDataBrowserRootContainer, newItem );
2035 }
2036
2037 void wxMacDataItemBrowserControl::MacInsert( unsigned int n, const wxArrayString& items, int column )
2038 {
2039 size_t itemsCount = items.GetCount();
2040 if ( itemsCount == 0 )
2041 return;
2042
2043 SInt32 frontLineOrder = 0;
2044
2045 if ( m_sortOrder == SortOrder_None )
2046 {
2047 // increase the order of the lines to be shifted
2048 unsigned int lines = MacGetCount();
2049 for ( unsigned int i = n; i < lines; ++i)
2050 {
2051 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(i);
2052 iter->SetOrder( iter->GetOrder() + itemsCount );
2053 }
2054 if ( n > 0 )
2055 {
2056 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(n-1);
2057 frontLineOrder = iter->GetOrder();
2058 }
2059 }
2060
2061 wxArrayMacDataItemPtr ids;
2062 ids.SetCount( itemsCount );
2063
2064 for ( unsigned int i = 0; i < itemsCount; ++i )
2065 {
2066 wxMacDataItem* item = CreateItem();
2067 item->SetLabel( items[i]);
2068 if ( column != -1 )
2069 item->SetColumn( kMinColumnId + column );
2070
2071 if ( m_sortOrder == SortOrder_None )
2072 item->SetOrder( frontLineOrder + 1 + i );
2073
2074 ids[i] = item;
2075 }
2076
2077 AddItems( wxMacDataBrowserRootContainer, ids );
2078 }
2079
2080 int wxMacDataItemBrowserControl::MacAppend( const wxString& text)
2081 {
2082 wxMacDataItem* item = CreateItem();
2083 item->SetLabel( text );
2084 if ( m_sortOrder == SortOrder_None )
2085 {
2086 unsigned int lines = MacGetCount();
2087 if ( lines == 0 )
2088 item->SetOrder( 1 );
2089 else
2090 {
2091 wxMacDataItem* frontItem = (wxMacDataItem*) GetItemFromLine(lines-1);
2092 item->SetOrder( frontItem->GetOrder() + 1 );
2093 }
2094 }
2095 AddItem( wxMacDataBrowserRootContainer, item );
2096
2097 return GetLineFromItem(item);
2098 }
2099
2100 void wxMacDataItemBrowserControl::MacClear()
2101 {
2102 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
2103 RemoveAllItems(wxMacDataBrowserRootContainer);
2104 }
2105
2106 void wxMacDataItemBrowserControl::MacDeselectAll()
2107 {
2108 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
2109 SetSelectedAllItems( kDataBrowserItemsRemove );
2110 }
2111
2112 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n, bool select, bool multi )
2113 {
2114 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n);
2115 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
2116
2117 if ( IsItemSelected( item ) != select )
2118 {
2119 if ( select )
2120 SetSelectedItem( item, multi ? kDataBrowserItemsAdd : kDataBrowserItemsAssign );
2121 else
2122 SetSelectedItem( item, kDataBrowserItemsRemove );
2123 }
2124
2125 MacScrollTo( n );
2126 }
2127
2128 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n ) const
2129 {
2130 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n);
2131 return IsItemSelected( item );
2132 }
2133
2134 int wxMacDataItemBrowserControl::MacGetSelection() const
2135 {
2136 wxMacDataItemPtr first, last;
2137 GetSelectionAnchor( &first, &last );
2138
2139 if ( first != NULL )
2140 {
2141 return GetLineFromItem( first );
2142 }
2143
2144 return -1;
2145 }
2146
2147 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt& aSelections ) const
2148 {
2149 aSelections.Empty();
2150 wxArrayMacDataItemPtr selectedItems;
2151 GetItems( wxMacDataBrowserRootContainer, false , kDataBrowserItemIsSelected, selectedItems);
2152
2153 int count = selectedItems.GetCount();
2154
2155 for ( int i = 0; i < count; ++i)
2156 {
2157 aSelections.Add(GetLineFromItem(selectedItems[i]));
2158 }
2159
2160 return count;
2161 }
2162
2163 void wxMacDataItemBrowserControl::MacSetString( unsigned int n, const wxString& text )
2164 {
2165 // as we don't store the strings we only have to issue a redraw
2166 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n);
2167 item->SetLabel( text );
2168 UpdateItem( wxMacDataBrowserRootContainer, item , kTextColumnId );
2169 }
2170
2171 wxString wxMacDataItemBrowserControl::MacGetString( unsigned int n ) const
2172 {
2173 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
2174 return item->GetLabel();
2175 }
2176
2177 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n, void * data)
2178 {
2179 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n);
2180 item->SetData( data );
2181 // not displayed, therefore no Update infos to DataBrowser
2182 }
2183
2184 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n) const
2185 {
2186 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
2187 return item->GetData();
2188 }
2189
2190 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n )
2191 {
2192 RevealItem( GetItemFromLine( n) , kDataBrowserRevealWithoutSelecting );
2193 }
2194
2195
2196
2197 //
2198 // Tab Control
2199 //
2200
2201 OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable )
2202 {
2203 return ::SetTabEnabled( m_controlRef , tabNo , enable );
2204 }
2205
2206 //
2207 // Quartz Support
2208 //
2209
2210 #ifdef __WXMAC_OSX__
2211 // snippets from Sketch Sample from Apple :
2212
2213 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
2214
2215 /*
2216 This function locates, opens, and returns the profile reference for the calibrated
2217 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
2218 with the profile reference this function returns.
2219 */
2220 CMProfileRef wxMacOpenGenericProfile()
2221 {
2222 static CMProfileRef cachedRGBProfileRef = NULL;
2223
2224 // we only create the profile reference once
2225 if (cachedRGBProfileRef == NULL)
2226 {
2227 CMProfileLocation loc;
2228
2229 loc.locType = cmPathBasedProfile;
2230 strcpy(loc.u.pathLoc.path, kGenericRGBProfilePathStr);
2231
2232 verify_noerr( CMOpenProfile(&cachedRGBProfileRef, &loc) );
2233 }
2234
2235 // clone the profile reference so that the caller has their own reference, not our cached one
2236 if (cachedRGBProfileRef)
2237 CMCloneProfileRef(cachedRGBProfileRef);
2238
2239 return cachedRGBProfileRef;
2240 }
2241
2242 /*
2243 Return the generic RGB color space. This is a 'get' function and the caller should
2244 not release the returned value unless the caller retains it first. Usually callers
2245 of this routine will immediately use the returned colorspace with CoreGraphics
2246 so they typically do not need to retain it themselves.
2247
2248 This function creates the generic RGB color space once and hangs onto it so it can
2249 return it whenever this function is called.
2250 */
2251
2252 CGColorSpaceRef wxMacGetGenericRGBColorSpace()
2253 {
2254 static wxMacCFRefHolder<CGColorSpaceRef> genericRGBColorSpace;
2255
2256 if (genericRGBColorSpace == NULL)
2257 {
2258 if ( UMAGetSystemVersion() >= 0x1040 )
2259 {
2260 genericRGBColorSpace.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
2261 }
2262 else
2263 {
2264 CMProfileRef genericRGBProfile = wxMacOpenGenericProfile();
2265
2266 if (genericRGBProfile)
2267 {
2268 genericRGBColorSpace.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile) );
2269
2270 wxASSERT_MSG( genericRGBColorSpace != NULL, wxT("couldn't create the generic RGB color space") );
2271
2272 // we opened the profile so it is up to us to close it
2273 CMCloseProfile(genericRGBProfile);
2274 }
2275 }
2276 }
2277
2278 return genericRGBColorSpace;
2279 }
2280 #endif
2281
2282 #ifndef __LP64__
2283
2284 wxMacPortSaver::wxMacPortSaver( GrafPtr port )
2285 {
2286 ::GetPort( &m_port );
2287 ::SetPort( port );
2288 }
2289
2290 wxMacPortSaver::~wxMacPortSaver()
2291 {
2292 ::SetPort( m_port );
2293 }
2294 #endif
2295
2296 void wxMacGlobalToLocal( WindowRef window , Point*pt )
2297 {
2298 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2299 HIPoint p = CGPointMake( pt->h, pt->v );
2300 HIViewRef contentView ;
2301 // TODO check toolbar offset
2302 HIViewFindByID( HIViewGetRoot( window ), kHIViewWindowContentID , &contentView) ;
2303 HIPointConvert( &p, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceView, contentView );
2304 pt->h = p.x;
2305 pt->v = p.y;
2306 #else
2307 QDGlobalToLocalPoint( GetWindowPort(window), pt ) ;
2308 #endif
2309 }
2310
2311 void wxMacLocalToGlobal( WindowRef window , Point*pt )
2312 {
2313 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2314 HIPoint p = CGPointMake( pt->h, pt->v );
2315 HIViewRef contentView ;
2316 // TODO check toolbar offset
2317 HIViewFindByID( HIViewGetRoot( window ), kHIViewWindowContentID , &contentView) ;
2318 HIPointConvert( &p, kHICoordSpaceView, contentView, kHICoordSpace72DPIGlobal, NULL );
2319 pt->h = p.x;
2320 pt->v = p.y;
2321 #else
2322 QDLocalToGlobalPoint( GetWindowPort(window), pt ) ;
2323 #endif
2324 }
2325
2326 #endif // wxUSE_GUI