]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/osx/carbon/utils.cpp
Spell contributor name correctly.
[wxWidgets.git] / src / osx / carbon / utils.cpp
... / ...
CommitLineData
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
57void 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
76wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
77{
78 return new wxOSXTimerImpl(timer);
79}
80
81int gs_wxBusyCursorCount = 0;
82extern wxCursor gMacCurrentCursor;
83wxCursor gMacStoredActiveCursor;
84
85// Set the cursor to the busy cursor for all windows
86void 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
99void 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
114bool wxIsBusy()
115{
116 return (gs_wxBusyCursorCount > 0);
117}
118
119#endif // wxUSE_GUI
120
121#if wxUSE_BASE
122
123wxString 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
138wxString 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
158void 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
168void 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
203void 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
243void 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
251void 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
259void wxMacPointToNative( const wxPoint* wx , Point *n )
260{
261 n->h = wx->x;
262 n->v = wx->y;
263}
264
265void 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
275OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData)
276{
277 return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData );
278}
279
280OSStatus 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
297IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl , wxMacControl )
298
299pascal 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
312pascal 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
328pascal 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
342DataBrowserItemDataUPP gDataBrowserItemDataUPP = NULL;
343DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP = NULL;
344DataBrowserItemCompareUPP gDataBrowserItemCompareUPP = NULL;
345
346wxMacDataBrowserControl::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
378OSStatus 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
386OSStatus 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
394OSStatus wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options )
395{
396 return SetDataBrowserSelectionFlags( m_controlRef, options );
397}
398
399OSStatus wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc *columnDesc,
400 DataBrowserTableViewColumnIndex position )
401{
402 return AddDataBrowserListViewColumn( m_controlRef, columnDesc, position );
403}
404
405OSStatus wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id )
406{
407 return GetDataBrowserTableViewColumnProperty( m_controlRef, position, id );
408}
409
410OSStatus wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position )
411{
412 DataBrowserTableViewColumnID id;
413 GetColumnIDFromIndex( position, &id );
414 return RemoveDataBrowserTableViewColumn( m_controlRef, id );
415}
416
417OSStatus wxMacDataBrowserControl::AutoSizeColumns()
418{
419 return AutoSizeDataBrowserListViewColumns(m_controlRef);
420}
421
422OSStatus wxMacDataBrowserControl::SetHasScrollBars( bool horiz, bool vert )
423{
424 return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert );
425}
426
427OSStatus wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle )
428{
429 return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle );
430}
431
432OSStatus wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height)
433{
434 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
435}
436
437OSStatus wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16 *height)
438{
439 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
440}
441
442OSStatus wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks *callbacks)
443{
444 return SetDataBrowserCallbacks( m_controlRef, callbacks );
445}
446
447OSStatus 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
457bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item ) const
458{
459 return IsDataBrowserItemSelected( m_controlRef, item );
460}
461
462OSStatus 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
471OSStatus 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
480OSStatus wxMacDataBrowserControl::RevealItem(
481 DataBrowserItemID item,
482 DataBrowserPropertyID propertyID,
483 DataBrowserRevealOptions options ) const
484{
485 return RevealDataBrowserItem( m_controlRef, item, propertyID, options );
486}
487
488OSStatus wxMacDataBrowserControl::SetSelectedItems(
489 UInt32 numItems,
490 const DataBrowserItemID *items,
491 DataBrowserSetOption operation )
492{
493 return SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation );
494}
495
496OSStatus wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const
497{
498 return GetDataBrowserSelectionAnchor( m_controlRef, first, last );
499}
500
501OSStatus wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const
502{
503 return GetDataBrowserTableViewItemID( m_controlRef, row, item );
504}
505
506OSStatus wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item, DataBrowserTableViewRowIndex * row ) const
507{
508 return GetDataBrowserTableViewItemRow( m_controlRef, item, row );
509}
510
511OSStatus wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height )
512{
513 return SetDataBrowserTableViewRowHeight( m_controlRef , height );
514}
515
516OSStatus wxMacDataBrowserControl::GetDefaultRowHeight( UInt16 * height ) const
517{
518 return GetDataBrowserTableViewRowHeight( m_controlRef, height );
519}
520
521OSStatus wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item , UInt16 height)
522{
523 return SetDataBrowserTableViewItemRowHeight( m_controlRef, item , height );
524}
525
526OSStatus wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const
527{
528 return GetDataBrowserTableViewItemRowHeight( m_controlRef, item , height);
529}
530
531OSStatus wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const
532{
533 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
534}
535
536OSStatus wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width )
537{
538 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
539}
540
541OSStatus wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16 *width ) const
542{
543 return GetDataBrowserTableViewColumnWidth( m_controlRef , width );
544}
545
546OSStatus wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width )
547{
548 return SetDataBrowserTableViewColumnWidth( m_controlRef , width );
549}
550
551OSStatus wxMacDataBrowserControl::GetColumnCount(UInt32* numColumns) const
552{
553 return GetDataBrowserTableViewColumnCount( m_controlRef, numColumns);
554}
555
556OSStatus wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column,
557 DataBrowserTableViewColumnIndex *position) const
558{
559 return GetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
560}
561
562OSStatus wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position)
563{
564 return SetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
565}
566
567OSStatus wxMacDataBrowserControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const
568{
569 return GetDataBrowserScrollPosition( m_controlRef , top , left );
570}
571
572OSStatus wxMacDataBrowserControl::SetScrollPosition( UInt32 top , UInt32 left )
573{
574 return SetDataBrowserScrollPosition( m_controlRef , top , left );
575}
576
577OSStatus wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID *column ) const
578{
579 return GetDataBrowserSortProperty( m_controlRef , column );
580}
581
582OSStatus wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column )
583{
584 return SetDataBrowserSortProperty( m_controlRef , column );
585}
586
587OSStatus wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder *order ) const
588{
589 return GetDataBrowserSortOrder( m_controlRef , order );
590}
591
592OSStatus wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order )
593{
594 return SetDataBrowserSortOrder( m_controlRef , order );
595}
596
597OSStatus wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property,
598 DataBrowserPropertyFlags *flags ) const
599{
600 return GetDataBrowserPropertyFlags( m_controlRef , property , flags );
601}
602
603OSStatus wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property,
604 DataBrowserPropertyFlags flags )
605{
606 return SetDataBrowserPropertyFlags( m_controlRef , property , flags );
607}
608
609OSStatus wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property,
610 DataBrowserListViewHeaderDesc *desc ) const
611{
612 return GetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
613}
614
615OSStatus wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property,
616 DataBrowserListViewHeaderDesc *desc )
617{
618 return SetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
619}
620
621OSStatus wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property ,
622 Boolean expandableRows )
623{
624 return SetDataBrowserListViewDisclosureColumn( m_controlRef, property, expandableRows);
625}
626
627OSStatus wxMacDataBrowserControl::GetItemPartBounds( DataBrowserItemID item, DataBrowserPropertyID property, DataBrowserPropertyPart part, Rect * bounds )
628{
629 return GetDataBrowserItemPartBounds( m_controlRef, item, property, part, bounds);
630}
631
632// ============================================================================
633// Higher-level Databrowser
634// ============================================================================
635//
636// basing on data item objects
637//
638
639wxMacDataItem::wxMacDataItem()
640{
641// m_data = NULL;
642
643 m_order = 0;
644// m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
645}
646
647wxMacDataItem::~wxMacDataItem()
648{
649}
650
651void wxMacDataItem::SetOrder( SInt32 order )
652{
653 m_order = order;
654}
655
656SInt32 wxMacDataItem::GetOrder() const
657{
658 return m_order;
659}
660/*
661void wxMacDataItem::SetData( void* data)
662{
663 m_data = data;
664}
665
666void* wxMacDataItem::GetData() const
667{
668 return m_data;
669}
670
671short wxMacDataItem::GetColumn()
672{
673 return m_colId;
674}
675
676void wxMacDataItem::SetColumn( short col )
677{
678 m_colId = col;
679}
680
681void wxMacDataItem::SetLabel( const wxString& str)
682{
683 m_label = str;
684 m_cfLabel = wxCFStringRef( str , wxLocale::GetSystemEncoding());
685}
686
687const wxString& wxMacDataItem::GetLabel() const
688{
689 return m_label;
690}
691*/
692
693bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *WXUNUSED(owner) ,
694 const wxMacDataItem* rhs,
695 DataBrowserPropertyID sortProperty) const
696{
697 bool retval = false;
698
699 if ( sortProperty == kNumericOrderColumnId )
700 retval = m_order < rhs->m_order;
701
702 return retval;
703}
704
705OSStatus wxMacDataItem::GetSetData( wxMacDataItemBrowserControl *WXUNUSED(owner) ,
706 DataBrowserPropertyID property,
707 DataBrowserItemDataRef itemData,
708 bool changeValue )
709{
710 OSStatus err = errDataBrowserPropertyNotSupported;
711 if ( !changeValue )
712 {
713 if ( property == kNumericOrderColumnId )
714 {
715 err = ::SetDataBrowserItemDataValue( itemData, m_order );
716 err = noErr;
717 }
718 }
719
720 return err;
721}
722
723void wxMacDataItem::Notification(wxMacDataItemBrowserControl *WXUNUSED(owner) ,
724 DataBrowserItemNotification WXUNUSED(message),
725 DataBrowserItemDataRef WXUNUSED(itemData) ) const
726{
727}
728
729IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl , wxMacDataBrowserControl )
730
731wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style) :
732 wxMacDataBrowserControl( peer, pos, size, style )
733{
734 m_suppressSelection = false;
735 m_sortOrder = SortOrder_None;
736 m_clientDataItemsType = wxClientData_None;
737}
738
739wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser)
740{
741 m_former = browser->SuppressSelection(true);
742 m_browser = browser;
743}
744
745wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
746{
747 m_browser->SuppressSelection(m_former);
748}
749
750bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress )
751{
752 bool former = m_suppressSelection;
753 m_suppressSelection = suppress;
754
755 return former;
756}
757
758Boolean wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID,
759 DataBrowserItemID itemTwoID,
760 DataBrowserPropertyID sortProperty)
761{
762 wxMacDataItem* itemOne = (wxMacDataItem*) itemOneID;
763 wxMacDataItem* itemTwo = (wxMacDataItem*) itemTwoID;
764
765 Boolean retval = false;
766 if ( itemOne != NULL )
767 retval = itemOne->IsLessThan( this , itemTwo , sortProperty);
768 return retval;
769}
770
771OSStatus wxMacDataItemBrowserControl::GetSetItemData(
772 DataBrowserItemID itemID,
773 DataBrowserPropertyID property,
774 DataBrowserItemDataRef itemData,
775 Boolean changeValue )
776{
777 wxMacDataItem* item = (wxMacDataItem*) itemID;
778 OSStatus err = errDataBrowserPropertyNotSupported;
779 switch( property )
780 {
781 case kDataBrowserContainerIsClosableProperty :
782 case kDataBrowserContainerIsSortableProperty :
783 case kDataBrowserContainerIsOpenableProperty :
784 // right now default behaviour on these
785 break;
786 default :
787
788 if ( item != NULL ){
789 err = item->GetSetData( this, property , itemData , changeValue );
790 }
791 break;
792
793 }
794 return err;
795}
796
797void wxMacDataItemBrowserControl::ItemNotification(
798 DataBrowserItemID itemID,
799 DataBrowserItemNotification message,
800 DataBrowserItemDataRef itemData)
801{
802 wxMacDataItem* item = (wxMacDataItem*) itemID;
803 if (item != NULL)
804 item->Notification( this, message, itemData);
805}
806
807unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem* container,
808 bool recurse , DataBrowserItemState state) const
809{
810 ItemCount numItems = 0;
811 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID)container,
812 recurse, state, &numItems ) );
813 return numItems;
814}
815
816unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem* container,
817 bool recurse ) const
818{
819 return GetItemCount( container, recurse, kDataBrowserItemIsSelected );
820
821}
822
823void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem* container,
824 bool recurse , DataBrowserItemState state, wxArrayMacDataItemPtr &items) const
825{
826 Handle handle = NewHandle(0);
827 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID)container ,
828 recurse , state, handle) );
829
830 int itemCount = GetHandleSize(handle)/sizeof(DataBrowserItemID);
831 HLock( handle );
832 wxMacDataItemPtr* itemsArray = (wxMacDataItemPtr*) *handle;
833 for ( int i = 0; i < itemCount; ++i)
834 {
835 items.Add(itemsArray[i]);
836 }
837 HUnlock( handle );
838 DisposeHandle( handle );
839}
840
841unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem* item) const
842{
843 DataBrowserTableViewRowIndex row;
844 OSStatus err = GetItemRow( (DataBrowserItemID) item , &row);
845 wxCHECK( err == noErr, (unsigned)-1 );
846 return row;
847}
848
849wxMacDataItem* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n) const
850{
851 DataBrowserItemID id;
852 OSStatus err = GetItemID( (DataBrowserTableViewRowIndex) n , &id);
853 wxCHECK( err == noErr, NULL );
854 return (wxMacDataItem*) id;
855}
856
857void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem *container,
858 const wxMacDataItem *item , DataBrowserPropertyID property) const
859{
860 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, 1,
861 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty /* notSorted */, property ) );
862}
863
864void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem *container,
865 wxArrayMacDataItemPtr &itemArray , DataBrowserPropertyID property) const
866{
867 unsigned int noItems = itemArray.GetCount();
868 DataBrowserItemID *items = new DataBrowserItemID[noItems];
869 for ( unsigned int i = 0; i < noItems; ++i )
870 items[i] = (DataBrowserItemID) itemArray[i];
871
872 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, noItems,
873 items, kDataBrowserItemNoProperty /* notSorted */, property ) );
874 delete [] items;
875}
876
877static int column_id_counter = 0;
878
879void wxMacDataItemBrowserControl::InsertColumn(int col, DataBrowserPropertyType colType,
880 const wxString& title, SInt16 just, int defaultWidth)
881{
882 DataBrowserListViewColumnDesc columnDesc;
883 columnDesc.headerBtnDesc.titleOffset = 0;
884 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
885
886 columnDesc.headerBtnDesc.btnFontStyle.flags =
887 kControlUseFontMask | kControlUseJustMask;
888
889 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
890 columnDesc.headerBtnDesc.btnFontStyle.just = just;
891 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
892 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
893
894 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
895 // defined for other modes?
896 wxFontEncoding enc;
897 if ( m_font.Ok() )
898 enc = m_font.GetEncoding();
899 else
900 enc = wxLocale::GetSystemEncoding();
901 wxCFStringRef cfTitle( title, enc );
902 columnDesc.headerBtnDesc.titleString = cfTitle;
903
904 columnDesc.headerBtnDesc.minimumWidth = 0;
905 columnDesc.headerBtnDesc.maximumWidth = 30000;
906
907 DataBrowserPropertyID id = kMinColumnId + column_id_counter;
908 column_id_counter++;
909
910 columnDesc.propertyDesc.propertyID = id;
911 columnDesc.propertyDesc.propertyType = colType;
912 columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn;
913 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
914 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
915
916 verify_noerr( AddColumn( &columnDesc, col ) );
917
918 if (defaultWidth > 0){
919 SetColumnWidth(col, defaultWidth);
920 }
921}
922
923void wxMacDataItemBrowserControl::SetColumnWidth(int colId, int width)
924{
925 DataBrowserPropertyID id;
926 GetColumnIDFromIndex(colId, &id);
927 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id, width));
928}
929
930int wxMacDataItemBrowserControl::GetColumnWidth(int colId)
931{
932 DataBrowserPropertyID id;
933 GetColumnIDFromIndex(colId, &id);
934 UInt16 result;
935 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id, &result));
936 return result;
937}
938
939void wxMacDataItemBrowserControl::AddItem(wxMacDataItem *container, wxMacDataItem *item)
940{
941 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, 1,
942 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ) );
943}
944
945void wxMacDataItemBrowserControl::AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray )
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::AddItems( (DataBrowserItemID)container, noItems,
953 (DataBrowserItemID*) items, kDataBrowserItemNoProperty ) );
954 delete [] items;
955}
956
957void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem *container, wxMacDataItem* item)
958{
959 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 1,
960 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty );
961 verify_noerr( err );
962}
963
964void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray)
965{
966 unsigned int noItems = itemArray.GetCount();
967 DataBrowserItemID *items = new DataBrowserItemID[noItems];
968 for ( unsigned int i = 0; i < noItems; ++i )
969 items[i] = (DataBrowserItemID) itemArray[i];
970
971 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, noItems,
972 (DataBrowserItemID*) items, kDataBrowserItemNoProperty );
973 verify_noerr( err );
974 delete [] items;
975}
976
977void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem *container)
978{
979 SetScrollPosition(0, 0);
980 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 0 , NULL , kDataBrowserItemNoProperty );
981 verify_noerr( err );
982}
983
984void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem* item , DataBrowserSetOption option)
985{
986 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID*) &item, option ));
987}
988
989void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option)
990{
991 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL , option ));
992}
993
994void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr &itemArray , DataBrowserSetOption option)
995{
996 unsigned int noItems = itemArray.GetCount();
997 DataBrowserItemID *items = new DataBrowserItemID[noItems];
998 for ( unsigned int i = 0; i < noItems; ++i )
999 items[i] = (DataBrowserItemID) itemArray[i];
1000
1001 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems, (DataBrowserItemID*) items, option ));
1002 delete [] items;
1003}
1004
1005Boolean wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem* item) const
1006{
1007 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID) item);
1008}
1009
1010void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options)
1011{
1012 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID) item, kDataBrowserNoItem , options ) );
1013}
1014
1015void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const
1016{
1017 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID*) first, (DataBrowserItemID*) last) );
1018}
1019
1020wxClientDataType wxMacDataItemBrowserControl::GetClientDataType() const
1021{
1022 return m_clientDataItemsType;
1023}
1024void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType)
1025{
1026 m_clientDataItemsType = clientDataItemsType;
1027}
1028
1029void wxMacDataItemBrowserControl::MacDelete( unsigned int n )
1030{
1031 wxMacDataItem* item = (wxMacDataItem*)GetItemFromLine( n );
1032 RemoveItem( wxMacDataBrowserRootContainer, item );
1033}
1034
1035void wxMacDataItemBrowserControl::MacInsert( unsigned int n, wxMacDataItem* item)
1036{
1037 if ( m_sortOrder == SortOrder_None )
1038 {
1039
1040 // increase the order of the lines to be shifted
1041 unsigned int lines = MacGetCount();
1042 for ( unsigned int i = n; i < lines; ++i)
1043 {
1044 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(i);
1045 iter->SetOrder( iter->GetOrder() + 1 );
1046 }
1047
1048#if 0
1049 // I don't understand what this code is supposed to do, RR.
1050 SInt32 frontLineOrder = 0;
1051 if ( n > 0 )
1052 {
1053 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(n-1);
1054 frontLineOrder = iter->GetOrder()+1;
1055 }
1056#else
1057 item->SetOrder( n );
1058#endif
1059 }
1060
1061 AddItem( wxMacDataBrowserRootContainer, item );
1062}
1063
1064void wxMacDataItemBrowserControl::MacClear()
1065{
1066 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
1067 RemoveAllItems(wxMacDataBrowserRootContainer);
1068}
1069
1070unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1071{
1072 return GetItemCount(wxMacDataBrowserRootContainer,false,kDataBrowserItemAnyState);
1073}
1074
1075#endif // wxUSE_GUI
1076