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