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