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