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