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