]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/utils.cpp
Applied #10858: wxListCtrl on Mac does not route Freeze/Thaw/Update to m_genericImpl
[wxWidgets.git] / src / osx / carbon / utils.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/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
13 #include "wx/wxprec.h"
14
15 #include "wx/utils.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/intl.h"
19 #include "wx/app.h"
20 #if wxUSE_GUI
21 #include "wx/toplevel.h"
22 #include "wx/font.h"
23 #endif
24 #endif
25
26 #include "wx/apptrait.h"
27
28 #include <ctype.h>
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <stdarg.h>
34
35 // #include "MoreFilesX.h"
36
37 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
38 #include <AudioToolbox/AudioServices.h>
39 #endif
40
41 #include "wx/osx/private.h"
42 #if wxUSE_GUI
43 #include "wx/osx/private/timer.h"
44 #endif // wxUSE_GUI
45
46 #include "wx/evtloop.h"
47
48 #if defined(__MWERKS__) && wxUSE_UNICODE
49 #if __MWERKS__ < 0x4100
50 #include <wtime.h>
51 #endif
52 #endif
53
54 #if wxUSE_BASE
55
56 // Emit a beeeeeep
57 void wxBell()
58 {
59 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
60 if ( AudioServicesPlayAlertSound != NULL )
61 AudioServicesPlayAlertSound(kUserPreferredAlert);
62 else
63 #endif
64 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
65 AlertSoundPlay();
66 #else
67 {
68 }
69 #endif
70 }
71
72 #endif // wxUSE_BASE
73
74 #if wxUSE_GUI
75
76 wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
77 {
78 return new wxOSXTimerImpl(timer);
79 }
80
81 int gs_wxBusyCursorCount = 0;
82 extern wxCursor gMacCurrentCursor;
83 wxCursor gMacStoredActiveCursor;
84
85 // Set the cursor to the busy cursor for all windows
86 void wxBeginBusyCursor(const wxCursor *cursor)
87 {
88 if (gs_wxBusyCursorCount++ == 0)
89 {
90 gMacStoredActiveCursor = gMacCurrentCursor;
91 cursor->MacInstall();
92
93 wxSetCursor(*cursor);
94 }
95 //else: nothing to do, already set
96 }
97
98 // Restore cursor to normal
99 void wxEndBusyCursor()
100 {
101 wxCHECK_RET( gs_wxBusyCursorCount > 0,
102 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
103
104 if (--gs_wxBusyCursorCount == 0)
105 {
106 gMacStoredActiveCursor.MacInstall();
107 gMacStoredActiveCursor = wxNullCursor;
108
109 wxSetCursor(wxNullCursor);
110 }
111 }
112
113 // true if we're between the above two calls
114 bool wxIsBusy()
115 {
116 return (gs_wxBusyCursorCount > 0);
117 }
118
119 #endif // wxUSE_GUI
120
121 #if wxUSE_BASE
122
123 wxString wxMacFindFolderNoSeparator( short vol,
124 OSType folderType,
125 Boolean createFolder)
126 {
127 FSRef fsRef;
128 wxString strDir;
129
130 if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr)
131 {
132 strDir = wxMacFSRefToPath( &fsRef );
133 }
134
135 return strDir;
136 }
137
138 wxString wxMacFindFolder( short vol,
139 OSType folderType,
140 Boolean createFolder)
141 {
142 return wxMacFindFolderNoSeparator(vol, folderType, createFolder) + wxFILE_SEP_PATH;
143 }
144
145 #endif // wxUSE_BASE
146
147
148 // ============================================================================
149 // GUI-only functions from now on
150 // ============================================================================
151
152 #if wxUSE_GUI
153
154 // ----------------------------------------------------------------------------
155 // Miscellaneous functions
156 // ----------------------------------------------------------------------------
157
158 void wxGetMousePosition( int* x, int* y )
159 {
160 Point pt;
161 GetGlobalMouse(&pt);
162 if ( x )
163 *x = pt.h;
164 if ( y )
165 *y = pt.v;
166 };
167
168 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
169 {
170 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
171 HIRect bounds ;
172 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal,
173 &bounds);
174 if ( x )
175 *x = bounds.origin.x;
176 if ( y )
177 *y = bounds.origin.y;
178 if ( width )
179 *width = bounds.size.width;
180 if ( height )
181 *height = bounds.size.height;
182 #else
183 Rect r;
184 GetAvailableWindowPositioningBounds( GetMainDevice() , &r );
185 if ( x )
186 *x = r.left;
187 if ( y )
188 *y = r.top;
189 if ( width )
190 *width = r.right - r.left;
191 if ( height )
192 *height = r.bottom - r.top;
193 #endif
194 }
195
196 #endif // wxUSE_GUI
197
198 #if wxUSE_BASE
199 // ----------------------------------------------------------------------------
200 // Common Event Support
201 // ----------------------------------------------------------------------------
202
203 void wxMacWakeUp()
204 {
205 OSStatus err = noErr;
206
207 #if wxOSX_USE_CARBON
208 #if 0
209 // lead sometimes to race conditions, although all calls used should be thread safe ...
210 static wxMacCarbonEvent s_wakeupEvent;
211 if ( !s_wakeupEvent.IsValid() )
212 {
213 err = s_wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
214 kEventAttributeNone );
215 }
216 if ( err == noErr )
217 {
218
219 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent ) )
220 return;
221 s_wakeupEvent.SetCurrentTime();
222 err = PostEventToQueue(GetMainEventQueue(), s_wakeupEvent,
223 kEventPriorityHigh );
224 }
225 #else
226 wxMacCarbonEvent wakeupEvent;
227 wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
228 kEventAttributeNone );
229 err = PostEventToQueue(GetMainEventQueue(), wakeupEvent,
230 kEventPriorityHigh );
231 #endif
232 #endif
233 }
234
235 #endif // wxUSE_BASE
236
237 #if wxUSE_GUI
238
239 // ----------------------------------------------------------------------------
240 // Native Struct Conversions
241 // ----------------------------------------------------------------------------
242
243 void wxMacRectToNative( const wxRect *wx , Rect *n )
244 {
245 n->left = wx->x;
246 n->top = wx->y;
247 n->right = wx->x + wx->width;
248 n->bottom = wx->y + wx->height;
249 }
250
251 void wxMacNativeToRect( const Rect *n , wxRect* wx )
252 {
253 wx->x = n->left;
254 wx->y = n->top;
255 wx->width = n->right - n->left;
256 wx->height = n->bottom - n->top;
257 }
258
259 void wxMacPointToNative( const wxPoint* wx , Point *n )
260 {
261 n->h = wx->x;
262 n->v = wx->y;
263 }
264
265 void wxMacNativeToPoint( const Point *n , wxPoint* wx )
266 {
267 wx->x = n->h;
268 wx->y = n->v;
269 }
270
271 // ----------------------------------------------------------------------------
272 // Carbon Event Support
273 // ----------------------------------------------------------------------------
274
275 OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData)
276 {
277 return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData );
278 }
279
280 OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData)
281 {
282 return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData );
283 }
284
285 // ----------------------------------------------------------------------------
286 // Control Access Support
287 // ----------------------------------------------------------------------------
288
289
290 // ============================================================================
291 // DataBrowser Wrapper
292 // ============================================================================
293 //
294 // basing on DataBrowserItemIDs
295 //
296
297 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl , wxMacControl )
298
299 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
300 ControlRef browser,
301 DataBrowserItemID itemID,
302 DataBrowserItemNotification message,
303 DataBrowserItemDataRef itemData )
304 {
305 wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl);
306 if ( ctl != 0 )
307 {
308 ctl->ItemNotification(itemID, message, itemData);
309 }
310 }
311
312 pascal OSStatus wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
313 ControlRef browser,
314 DataBrowserItemID itemID,
315 DataBrowserPropertyID property,
316 DataBrowserItemDataRef itemData,
317 Boolean changeValue )
318 {
319 OSStatus err = errDataBrowserPropertyNotSupported;
320 wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl);
321 if ( ctl != 0 )
322 {
323 err = ctl->GetSetItemData(itemID, property, itemData, changeValue);
324 }
325 return err;
326 }
327
328 pascal Boolean wxMacDataBrowserControl::DataBrowserCompareProc(
329 ControlRef browser,
330 DataBrowserItemID itemOneID,
331 DataBrowserItemID itemTwoID,
332 DataBrowserPropertyID sortProperty)
333 {
334 wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl);
335 if ( ctl != 0 )
336 {
337 return ctl->CompareItems(itemOneID, itemTwoID, sortProperty);
338 }
339 return false;
340 }
341
342 DataBrowserItemDataUPP gDataBrowserItemDataUPP = NULL;
343 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP = NULL;
344 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP = NULL;
345
346 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow* peer,
347 const wxPoint& pos,
348 const wxSize& size,
349 long WXUNUSED(style))
350 : wxMacControl( peer )
351 {
352 Rect bounds = wxMacGetBoundsForControl( peer, pos, size );
353 OSStatus err = ::CreateDataBrowserControl(
354 MAC_WXHWND(peer->MacGetTopLevelWindowRef()),
355 &bounds, kDataBrowserListView, &m_controlRef );
356 SetReferenceInNativeControl();
357 verify_noerr( err );
358 if ( gDataBrowserItemCompareUPP == NULL )
359 gDataBrowserItemCompareUPP = NewDataBrowserItemCompareUPP(DataBrowserCompareProc);
360 if ( gDataBrowserItemDataUPP == NULL )
361 gDataBrowserItemDataUPP = NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc);
362 if ( gDataBrowserItemNotificationUPP == NULL )
363 {
364 gDataBrowserItemNotificationUPP =
365 (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc);
366 }
367
368 DataBrowserCallbacks callbacks;
369 InitializeDataBrowserCallbacks( &callbacks, kDataBrowserLatestCallbacks );
370
371 callbacks.u.v1.itemDataCallback = gDataBrowserItemDataUPP;
372 callbacks.u.v1.itemCompareCallback = gDataBrowserItemCompareUPP;
373 callbacks.u.v1.itemNotificationCallback = gDataBrowserItemNotificationUPP;
374 SetCallbacks( &callbacks );
375
376 }
377
378 OSStatus wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container,
379 Boolean recurse,
380 DataBrowserItemState state,
381 ItemCount *numItems) const
382 {
383 return GetDataBrowserItemCount( m_controlRef, container, recurse, state, numItems );
384 }
385
386 OSStatus wxMacDataBrowserControl::GetItems( DataBrowserItemID container,
387 Boolean recurse,
388 DataBrowserItemState state,
389 Handle items) const
390 {
391 return GetDataBrowserItems( m_controlRef, container, recurse, state, items );
392 }
393
394 OSStatus wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options )
395 {
396 return SetDataBrowserSelectionFlags( m_controlRef, options );
397 }
398
399 OSStatus wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc *columnDesc,
400 DataBrowserTableViewColumnIndex position )
401 {
402 return AddDataBrowserListViewColumn( m_controlRef, columnDesc, position );
403 }
404
405 OSStatus wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id )
406 {
407 return GetDataBrowserTableViewColumnProperty( m_controlRef, position, id );
408 }
409
410 OSStatus wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position )
411 {
412 DataBrowserTableViewColumnID id;
413 GetColumnIDFromIndex( position, &id );
414 return RemoveDataBrowserTableViewColumn( m_controlRef, id );
415 }
416
417 OSStatus wxMacDataBrowserControl::AutoSizeColumns()
418 {
419 return AutoSizeDataBrowserListViewColumns(m_controlRef);
420 }
421
422 OSStatus wxMacDataBrowserControl::SetHasScrollBars( bool horiz, bool vert )
423 {
424 return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert );
425 }
426
427 OSStatus wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle )
428 {
429 return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle );
430 }
431
432 OSStatus wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height)
433 {
434 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
435 }
436
437 OSStatus wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16 *height)
438 {
439 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
440 }
441
442 OSStatus wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks *callbacks)
443 {
444 return SetDataBrowserCallbacks( m_controlRef, callbacks );
445 }
446
447 OSStatus wxMacDataBrowserControl::UpdateItems(
448 DataBrowserItemID container,
449 UInt32 numItems,
450 const DataBrowserItemID *items,
451 DataBrowserPropertyID preSortProperty,
452 DataBrowserPropertyID propertyID ) const
453 {
454 return UpdateDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty, propertyID );
455 }
456
457 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item ) const
458 {
459 return IsDataBrowserItemSelected( m_controlRef, item );
460 }
461
462 OSStatus wxMacDataBrowserControl::AddItems(
463 DataBrowserItemID container,
464 UInt32 numItems,
465 const DataBrowserItemID *items,
466 DataBrowserPropertyID preSortProperty )
467 {
468 return AddDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty );
469 }
470
471 OSStatus wxMacDataBrowserControl::RemoveItems(
472 DataBrowserItemID container,
473 UInt32 numItems,
474 const DataBrowserItemID *items,
475 DataBrowserPropertyID preSortProperty )
476 {
477 return RemoveDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty );
478 }
479
480 OSStatus wxMacDataBrowserControl::RevealItem(
481 DataBrowserItemID item,
482 DataBrowserPropertyID propertyID,
483 DataBrowserRevealOptions options ) const
484 {
485 return RevealDataBrowserItem( m_controlRef, item, propertyID, options );
486 }
487
488 OSStatus wxMacDataBrowserControl::SetSelectedItems(
489 UInt32 numItems,
490 const DataBrowserItemID *items,
491 DataBrowserSetOption operation )
492 {
493 return SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation );
494 }
495
496 OSStatus wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const
497 {
498 return GetDataBrowserSelectionAnchor( m_controlRef, first, last );
499 }
500
501 OSStatus wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const
502 {
503 return GetDataBrowserTableViewItemID( m_controlRef, row, item );
504 }
505
506 OSStatus wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item, DataBrowserTableViewRowIndex * row ) const
507 {
508 return GetDataBrowserTableViewItemRow( m_controlRef, item, row );
509 }
510
511 OSStatus wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height )
512 {
513 return SetDataBrowserTableViewRowHeight( m_controlRef , height );
514 }
515
516 OSStatus wxMacDataBrowserControl::GetDefaultRowHeight( UInt16 * height ) const
517 {
518 return GetDataBrowserTableViewRowHeight( m_controlRef, height );
519 }
520
521 OSStatus wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item , UInt16 height)
522 {
523 return SetDataBrowserTableViewItemRowHeight( m_controlRef, item , height );
524 }
525
526 OSStatus wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const
527 {
528 return GetDataBrowserTableViewItemRowHeight( m_controlRef, item , height);
529 }
530
531 OSStatus wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const
532 {
533 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
534 }
535
536 OSStatus wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width )
537 {
538 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
539 }
540
541 OSStatus wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16 *width ) const
542 {
543 return GetDataBrowserTableViewColumnWidth( m_controlRef , width );
544 }
545
546 OSStatus wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width )
547 {
548 return SetDataBrowserTableViewColumnWidth( m_controlRef , width );
549 }
550
551 OSStatus wxMacDataBrowserControl::GetColumnCount(UInt32* numColumns) const
552 {
553 return GetDataBrowserTableViewColumnCount( m_controlRef, numColumns);
554 }
555
556 OSStatus wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column,
557 DataBrowserTableViewColumnIndex *position) const
558 {
559 return GetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
560 }
561
562 OSStatus wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position)
563 {
564 return SetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
565 }
566
567 OSStatus wxMacDataBrowserControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const
568 {
569 return GetDataBrowserScrollPosition( m_controlRef , top , left );
570 }
571
572 OSStatus wxMacDataBrowserControl::SetScrollPosition( UInt32 top , UInt32 left )
573 {
574 return SetDataBrowserScrollPosition( m_controlRef , top , left );
575 }
576
577 OSStatus wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID *column ) const
578 {
579 return GetDataBrowserSortProperty( m_controlRef , column );
580 }
581
582 OSStatus wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column )
583 {
584 return SetDataBrowserSortProperty( m_controlRef , column );
585 }
586
587 OSStatus wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder *order ) const
588 {
589 return GetDataBrowserSortOrder( m_controlRef , order );
590 }
591
592 OSStatus wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order )
593 {
594 return SetDataBrowserSortOrder( m_controlRef , order );
595 }
596
597 OSStatus wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property,
598 DataBrowserPropertyFlags *flags ) const
599 {
600 return GetDataBrowserPropertyFlags( m_controlRef , property , flags );
601 }
602
603 OSStatus wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property,
604 DataBrowserPropertyFlags flags )
605 {
606 return SetDataBrowserPropertyFlags( m_controlRef , property , flags );
607 }
608
609 OSStatus wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property,
610 DataBrowserListViewHeaderDesc *desc ) const
611 {
612 return GetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
613 }
614
615 OSStatus wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property,
616 DataBrowserListViewHeaderDesc *desc )
617 {
618 return SetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
619 }
620
621 OSStatus wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property ,
622 Boolean expandableRows )
623 {
624 return SetDataBrowserListViewDisclosureColumn( m_controlRef, property, expandableRows);
625 }
626
627 // ============================================================================
628 // Higher-level Databrowser
629 // ============================================================================
630 //
631 // basing on data item objects
632 //
633
634 wxMacDataItem::wxMacDataItem()
635 {
636 // m_data = NULL;
637
638 m_order = 0;
639 // m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
640 }
641
642 wxMacDataItem::~wxMacDataItem()
643 {
644 }
645
646 void wxMacDataItem::SetOrder( SInt32 order )
647 {
648 m_order = order;
649 }
650
651 SInt32 wxMacDataItem::GetOrder() const
652 {
653 return m_order;
654 }
655 /*
656 void wxMacDataItem::SetData( void* data)
657 {
658 m_data = data;
659 }
660
661 void* wxMacDataItem::GetData() const
662 {
663 return m_data;
664 }
665
666 short wxMacDataItem::GetColumn()
667 {
668 return m_colId;
669 }
670
671 void wxMacDataItem::SetColumn( short col )
672 {
673 m_colId = col;
674 }
675
676 void wxMacDataItem::SetLabel( const wxString& str)
677 {
678 m_label = str;
679 m_cfLabel = wxCFStringRef( str , wxLocale::GetSystemEncoding());
680 }
681
682 const wxString& wxMacDataItem::GetLabel() const
683 {
684 return m_label;
685 }
686 */
687
688 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *WXUNUSED(owner) ,
689 const wxMacDataItem* rhs,
690 DataBrowserPropertyID sortProperty) const
691 {
692 bool retval = false;
693
694 if ( sortProperty == kNumericOrderColumnId )
695 retval = m_order < rhs->m_order;
696
697 return retval;
698 }
699
700 OSStatus wxMacDataItem::GetSetData( wxMacDataItemBrowserControl *WXUNUSED(owner) ,
701 DataBrowserPropertyID property,
702 DataBrowserItemDataRef itemData,
703 bool changeValue )
704 {
705 OSStatus err = errDataBrowserPropertyNotSupported;
706 if ( !changeValue )
707 {
708 if ( property == kNumericOrderColumnId )
709 {
710 err = ::SetDataBrowserItemDataValue( itemData, m_order );
711 err = noErr;
712 }
713 }
714
715 return err;
716 }
717
718 void wxMacDataItem::Notification(wxMacDataItemBrowserControl *WXUNUSED(owner) ,
719 DataBrowserItemNotification WXUNUSED(message),
720 DataBrowserItemDataRef WXUNUSED(itemData) ) const
721 {
722 }
723
724 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl , wxMacDataBrowserControl )
725
726 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style) :
727 wxMacDataBrowserControl( peer, pos, size, style )
728 {
729 m_suppressSelection = false;
730 m_sortOrder = SortOrder_None;
731 m_clientDataItemsType = wxClientData_None;
732 }
733
734 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser)
735 {
736 m_former = browser->SuppressSelection(true);
737 m_browser = browser;
738 }
739
740 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
741 {
742 m_browser->SuppressSelection(m_former);
743 }
744
745 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress )
746 {
747 bool former = m_suppressSelection;
748 m_suppressSelection = suppress;
749
750 return former;
751 }
752
753 Boolean wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID,
754 DataBrowserItemID itemTwoID,
755 DataBrowserPropertyID sortProperty)
756 {
757 wxMacDataItem* itemOne = (wxMacDataItem*) itemOneID;
758 wxMacDataItem* itemTwo = (wxMacDataItem*) itemTwoID;
759
760 Boolean retval = false;
761 if ( itemOne != NULL )
762 retval = itemOne->IsLessThan( this , itemTwo , sortProperty);
763 return retval;
764 }
765
766 OSStatus wxMacDataItemBrowserControl::GetSetItemData(
767 DataBrowserItemID itemID,
768 DataBrowserPropertyID property,
769 DataBrowserItemDataRef itemData,
770 Boolean changeValue )
771 {
772 wxMacDataItem* item = (wxMacDataItem*) itemID;
773 OSStatus err = errDataBrowserPropertyNotSupported;
774 switch( property )
775 {
776 case kDataBrowserContainerIsClosableProperty :
777 case kDataBrowserContainerIsSortableProperty :
778 case kDataBrowserContainerIsOpenableProperty :
779 // right now default behaviour on these
780 break;
781 default :
782
783 if ( item != NULL ){
784 err = item->GetSetData( this, property , itemData , changeValue );
785 }
786 break;
787
788 }
789 return err;
790 }
791
792 void wxMacDataItemBrowserControl::ItemNotification(
793 DataBrowserItemID itemID,
794 DataBrowserItemNotification message,
795 DataBrowserItemDataRef itemData)
796 {
797 wxMacDataItem* item = (wxMacDataItem*) itemID;
798 if (item != NULL)
799 item->Notification( this, message, itemData);
800 }
801
802 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem* container,
803 bool recurse , DataBrowserItemState state) const
804 {
805 ItemCount numItems = 0;
806 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID)container,
807 recurse, state, &numItems ) );
808 return numItems;
809 }
810
811 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem* container,
812 bool recurse ) const
813 {
814 return GetItemCount( container, recurse, kDataBrowserItemIsSelected );
815
816 }
817
818 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem* container,
819 bool recurse , DataBrowserItemState state, wxArrayMacDataItemPtr &items) const
820 {
821 Handle handle = NewHandle(0);
822 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID)container ,
823 recurse , state, handle) );
824
825 int itemCount = GetHandleSize(handle)/sizeof(DataBrowserItemID);
826 HLock( handle );
827 wxMacDataItemPtr* itemsArray = (wxMacDataItemPtr*) *handle;
828 for ( int i = 0; i < itemCount; ++i)
829 {
830 items.Add(itemsArray[i]);
831 }
832 HUnlock( handle );
833 DisposeHandle( handle );
834 }
835
836 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem* item) const
837 {
838 DataBrowserTableViewRowIndex row;
839 OSStatus err = GetItemRow( (DataBrowserItemID) item , &row);
840 wxCHECK( err == noErr, (unsigned)-1 );
841 return row;
842 }
843
844 wxMacDataItem* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n) const
845 {
846 DataBrowserItemID id;
847 OSStatus err = GetItemID( (DataBrowserTableViewRowIndex) n , &id);
848 wxCHECK( err == noErr, NULL );
849 return (wxMacDataItem*) id;
850 }
851
852 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem *container,
853 const wxMacDataItem *item , DataBrowserPropertyID property) const
854 {
855 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, 1,
856 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty /* notSorted */, property ) );
857 }
858
859 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem *container,
860 wxArrayMacDataItemPtr &itemArray , DataBrowserPropertyID property) const
861 {
862 unsigned int noItems = itemArray.GetCount();
863 DataBrowserItemID *items = new DataBrowserItemID[noItems];
864 for ( unsigned int i = 0; i < noItems; ++i )
865 items[i] = (DataBrowserItemID) itemArray[i];
866
867 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, noItems,
868 items, kDataBrowserItemNoProperty /* notSorted */, property ) );
869 delete [] items;
870 }
871
872 static int column_id_counter = 0;
873
874 void wxMacDataItemBrowserControl::InsertColumn(int col, DataBrowserPropertyType colType,
875 const wxString& title, SInt16 just, int defaultWidth)
876 {
877 DataBrowserListViewColumnDesc columnDesc;
878 columnDesc.headerBtnDesc.titleOffset = 0;
879 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
880
881 columnDesc.headerBtnDesc.btnFontStyle.flags =
882 kControlUseFontMask | kControlUseJustMask;
883
884 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
885 columnDesc.headerBtnDesc.btnFontStyle.just = just;
886 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
887 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
888
889 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
890 // defined for other modes?
891 wxFontEncoding enc;
892 if ( m_font.Ok() )
893 enc = m_font.GetEncoding();
894 else
895 enc = wxLocale::GetSystemEncoding();
896 wxCFStringRef cfTitle( title, enc );
897 columnDesc.headerBtnDesc.titleString = cfTitle;
898
899 columnDesc.headerBtnDesc.minimumWidth = 0;
900 columnDesc.headerBtnDesc.maximumWidth = 30000;
901
902 DataBrowserPropertyID id = kMinColumnId + column_id_counter;
903 column_id_counter++;
904
905 columnDesc.propertyDesc.propertyID = id;
906 columnDesc.propertyDesc.propertyType = colType;
907 columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn;
908 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
909 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
910
911 verify_noerr( AddColumn( &columnDesc, col ) );
912
913 if (defaultWidth > 0){
914 SetColumnWidth(col, defaultWidth);
915 }
916 }
917
918 void wxMacDataItemBrowserControl::SetColumnWidth(int colId, int width)
919 {
920 DataBrowserPropertyID id;
921 GetColumnIDFromIndex(colId, &id);
922 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id, width));
923 }
924
925 int wxMacDataItemBrowserControl::GetColumnWidth(int colId)
926 {
927 DataBrowserPropertyID id;
928 GetColumnIDFromIndex(colId, &id);
929 UInt16 result;
930 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id, &result));
931 return result;
932 }
933
934 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem *container, wxMacDataItem *item)
935 {
936 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, 1,
937 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ) );
938 }
939
940 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray )
941 {
942 unsigned int noItems = itemArray.GetCount();
943 DataBrowserItemID *items = new DataBrowserItemID[noItems];
944 for ( unsigned int i = 0; i < noItems; ++i )
945 items[i] = (DataBrowserItemID) itemArray[i];
946
947 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, noItems,
948 (DataBrowserItemID*) items, kDataBrowserItemNoProperty ) );
949 delete [] items;
950 }
951
952 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem *container, wxMacDataItem* item)
953 {
954 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 1,
955 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty );
956 verify_noerr( err );
957 }
958
959 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray)
960 {
961 unsigned int noItems = itemArray.GetCount();
962 DataBrowserItemID *items = new DataBrowserItemID[noItems];
963 for ( unsigned int i = 0; i < noItems; ++i )
964 items[i] = (DataBrowserItemID) itemArray[i];
965
966 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, noItems,
967 (DataBrowserItemID*) items, kDataBrowserItemNoProperty );
968 verify_noerr( err );
969 delete [] items;
970 }
971
972 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem *container)
973 {
974 SetScrollPosition(0, 0);
975 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 0 , NULL , kDataBrowserItemNoProperty );
976 verify_noerr( err );
977 }
978
979 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem* item , DataBrowserSetOption option)
980 {
981 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID*) &item, option ));
982 }
983
984 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option)
985 {
986 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL , option ));
987 }
988
989 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr &itemArray , DataBrowserSetOption option)
990 {
991 unsigned int noItems = itemArray.GetCount();
992 DataBrowserItemID *items = new DataBrowserItemID[noItems];
993 for ( unsigned int i = 0; i < noItems; ++i )
994 items[i] = (DataBrowserItemID) itemArray[i];
995
996 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems, (DataBrowserItemID*) items, option ));
997 delete [] items;
998 }
999
1000 Boolean wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem* item) const
1001 {
1002 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID) item);
1003 }
1004
1005 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options)
1006 {
1007 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID) item, kDataBrowserNoItem , options ) );
1008 }
1009
1010 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const
1011 {
1012 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID*) first, (DataBrowserItemID*) last) );
1013 }
1014
1015 wxClientDataType wxMacDataItemBrowserControl::GetClientDataType() const
1016 {
1017 return m_clientDataItemsType;
1018 }
1019 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType)
1020 {
1021 m_clientDataItemsType = clientDataItemsType;
1022 }
1023
1024 void wxMacDataItemBrowserControl::MacDelete( unsigned int n )
1025 {
1026 wxMacDataItem* item = (wxMacDataItem*)GetItemFromLine( n );
1027 RemoveItem( wxMacDataBrowserRootContainer, item );
1028 }
1029
1030 void wxMacDataItemBrowserControl::MacInsert( unsigned int n, wxMacDataItem* item)
1031 {
1032 if ( m_sortOrder == SortOrder_None )
1033 {
1034
1035 // increase the order of the lines to be shifted
1036 unsigned int lines = MacGetCount();
1037 for ( unsigned int i = n; i < lines; ++i)
1038 {
1039 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(i);
1040 iter->SetOrder( iter->GetOrder() + 1 );
1041 }
1042
1043 #if 0
1044 // I don't understand what this code is supposed to do, RR.
1045 SInt32 frontLineOrder = 0;
1046 if ( n > 0 )
1047 {
1048 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(n-1);
1049 frontLineOrder = iter->GetOrder()+1;
1050 }
1051 #else
1052 item->SetOrder( n );
1053 #endif
1054 }
1055
1056 AddItem( wxMacDataBrowserRootContainer, item );
1057 }
1058
1059 void wxMacDataItemBrowserControl::MacClear()
1060 {
1061 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
1062 RemoveAllItems(wxMacDataBrowserRootContainer);
1063 }
1064
1065 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1066 {
1067 return GetItemCount(wxMacDataBrowserRootContainer,false,kDataBrowserItemAnyState);
1068 }
1069
1070 #endif // wxUSE_GUI
1071