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