]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/osx/carbon/utils.cpp
add the wxFont(const wxSize& pixelSize, ...) ctor to all ports; add some wxCHECK_MSGs...
[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
627// ============================================================================
628// Higher-level Databrowser
629// ============================================================================
630//
631// basing on data item objects
632//
633
634wxMacDataItem::wxMacDataItem()
635{
636// m_data = NULL;
637
638 m_order = 0;
639// m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
640}
641
642wxMacDataItem::~wxMacDataItem()
643{
644}
645
646void wxMacDataItem::SetOrder( SInt32 order )
647{
648 m_order = order;
649}
650
651SInt32 wxMacDataItem::GetOrder() const
652{
653 return m_order;
654}
655/*
656void wxMacDataItem::SetData( void* data)
657{
658 m_data = data;
659}
660
661void* wxMacDataItem::GetData() const
662{
663 return m_data;
664}
665
666short wxMacDataItem::GetColumn()
667{
668 return m_colId;
669}
670
671void wxMacDataItem::SetColumn( short col )
672{
673 m_colId = col;
674}
675
676void wxMacDataItem::SetLabel( const wxString& str)
677{
678 m_label = str;
679 m_cfLabel = wxCFStringRef( str , wxLocale::GetSystemEncoding());
680}
681
682const wxString& wxMacDataItem::GetLabel() const
683{
684 return m_label;
685}
686*/
687
688bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *WXUNUSED(owner) ,
689 const wxMacDataItem* rhs,
690 DataBrowserPropertyID sortProperty) const
691{
692 bool retval = false;
693
694 if ( sortProperty == kNumericOrderColumnId )
695 retval = m_order < rhs->m_order;
696
697 return retval;
698}
699
700OSStatus wxMacDataItem::GetSetData( wxMacDataItemBrowserControl *WXUNUSED(owner) ,
701 DataBrowserPropertyID property,
702 DataBrowserItemDataRef itemData,
703 bool changeValue )
704{
705 OSStatus err = errDataBrowserPropertyNotSupported;
706 if ( !changeValue )
707 {
708 if ( property == kNumericOrderColumnId )
709 {
710 err = ::SetDataBrowserItemDataValue( itemData, m_order );
711 err = noErr;
712 }
713 }
714
715 return err;
716}
717
718void wxMacDataItem::Notification(wxMacDataItemBrowserControl *WXUNUSED(owner) ,
719 DataBrowserItemNotification WXUNUSED(message),
720 DataBrowserItemDataRef WXUNUSED(itemData) ) const
721{
722}
723
724IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl , wxMacDataBrowserControl )
725
726wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style) :
727 wxMacDataBrowserControl( peer, pos, size, style )
728{
729 m_suppressSelection = false;
730 m_sortOrder = SortOrder_None;
731 m_clientDataItemsType = wxClientData_None;
732}
733
734wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser)
735{
736 m_former = browser->SuppressSelection(true);
737 m_browser = browser;
738}
739
740wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
741{
742 m_browser->SuppressSelection(m_former);
743}
744
745bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress )
746{
747 bool former = m_suppressSelection;
748 m_suppressSelection = suppress;
749
750 return former;
751}
752
753Boolean wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID,
754 DataBrowserItemID itemTwoID,
755 DataBrowserPropertyID sortProperty)
756{
757 wxMacDataItem* itemOne = (wxMacDataItem*) itemOneID;
758 wxMacDataItem* itemTwo = (wxMacDataItem*) itemTwoID;
759 return CompareItems( itemOne , itemTwo , sortProperty );
760}
761
762Boolean wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem* itemOne,
763 const wxMacDataItem* itemTwo,
764 DataBrowserPropertyID sortProperty)
765{
766 Boolean retval = false;
767 if ( itemOne != NULL )
768 retval = itemOne->IsLessThan( this , itemTwo , sortProperty);
769 return retval;
770}
771
772OSStatus wxMacDataItemBrowserControl::GetSetItemData(
773 DataBrowserItemID itemID,
774 DataBrowserPropertyID property,
775 DataBrowserItemDataRef itemData,
776 Boolean changeValue )
777{
778 wxMacDataItem* item = (wxMacDataItem*) itemID;
779 return GetSetItemData(item, property, itemData , changeValue );
780}
781
782OSStatus wxMacDataItemBrowserControl::GetSetItemData(
783 wxMacDataItem* item,
784 DataBrowserPropertyID property,
785 DataBrowserItemDataRef itemData,
786 Boolean changeValue )
787{
788 OSStatus err = errDataBrowserPropertyNotSupported;
789 switch( property )
790 {
791 case kDataBrowserContainerIsClosableProperty :
792 case kDataBrowserContainerIsSortableProperty :
793 case kDataBrowserContainerIsOpenableProperty :
794 // right now default behaviour on these
795 break;
796 default :
797
798 if ( item != NULL ){
799 err = item->GetSetData( this, property , itemData , changeValue );
800 }
801 break;
802
803 }
804 return err;
805}
806
807void wxMacDataItemBrowserControl::ItemNotification(
808 DataBrowserItemID itemID,
809 DataBrowserItemNotification message,
810 DataBrowserItemDataRef itemData)
811{
812 wxMacDataItem* item = (wxMacDataItem*) itemID;
813 ItemNotification( item , message, itemData);
814}
815
816void wxMacDataItemBrowserControl::ItemNotification(
817 const wxMacDataItem* item,
818 DataBrowserItemNotification message,
819 DataBrowserItemDataRef itemData)
820{
821 if (item != NULL)
822 item->Notification( this, message, itemData);
823}
824
825unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem* container,
826 bool recurse , DataBrowserItemState state) const
827{
828 ItemCount numItems = 0;
829 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID)container,
830 recurse, state, &numItems ) );
831 return numItems;
832}
833
834unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem* container,
835 bool recurse ) const
836{
837 return GetItemCount( container, recurse, kDataBrowserItemIsSelected );
838
839}
840
841void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem* container,
842 bool recurse , DataBrowserItemState state, wxArrayMacDataItemPtr &items) const
843{
844 Handle handle = NewHandle(0);
845 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID)container ,
846 recurse , state, handle) );
847
848 int itemCount = GetHandleSize(handle)/sizeof(DataBrowserItemID);
849 HLock( handle );
850 wxMacDataItemPtr* itemsArray = (wxMacDataItemPtr*) *handle;
851 for ( int i = 0; i < itemCount; ++i)
852 {
853 items.Add(itemsArray[i]);
854 }
855 HUnlock( handle );
856 DisposeHandle( handle );
857}
858
859unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem* item) const
860{
861 DataBrowserTableViewRowIndex row;
862 OSStatus err = GetItemRow( (DataBrowserItemID) item , &row);
863 wxCHECK( err == noErr, (unsigned)-1 );
864 return row;
865}
866
867wxMacDataItem* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n) const
868{
869 DataBrowserItemID id;
870 OSStatus err = GetItemID( (DataBrowserTableViewRowIndex) n , &id);
871 wxCHECK( err == noErr, NULL );
872 return (wxMacDataItem*) id;
873}
874
875void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem *container,
876 const wxMacDataItem *item , DataBrowserPropertyID property) const
877{
878 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, 1,
879 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty /* notSorted */, property ) );
880}
881
882void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem *container,
883 wxArrayMacDataItemPtr &itemArray , DataBrowserPropertyID property) const
884{
885 unsigned int noItems = itemArray.GetCount();
886 DataBrowserItemID *items = new DataBrowserItemID[noItems];
887 for ( unsigned int i = 0; i < noItems; ++i )
888 items[i] = (DataBrowserItemID) itemArray[i];
889
890 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, noItems,
891 items, kDataBrowserItemNoProperty /* notSorted */, property ) );
892 delete [] items;
893}
894
895static int column_id_counter = 0;
896
897void wxMacDataItemBrowserControl::InsertColumn(int col, DataBrowserPropertyType colType,
898 const wxString& title, SInt16 just, int defaultWidth)
899{
900 DataBrowserListViewColumnDesc columnDesc;
901 columnDesc.headerBtnDesc.titleOffset = 0;
902 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
903
904 columnDesc.headerBtnDesc.btnFontStyle.flags =
905 kControlUseFontMask | kControlUseJustMask;
906
907 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
908 columnDesc.headerBtnDesc.btnFontStyle.just = just;
909 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
910 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
911
912 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
913 // defined for other modes?
914 wxFontEncoding enc;
915 if ( m_font.Ok() )
916 enc = m_font.GetEncoding();
917 else
918 enc = wxLocale::GetSystemEncoding();
919 wxCFStringRef cfTitle( title, enc );
920 columnDesc.headerBtnDesc.titleString = cfTitle;
921
922 columnDesc.headerBtnDesc.minimumWidth = 0;
923 columnDesc.headerBtnDesc.maximumWidth = 30000;
924
925 DataBrowserPropertyID id = kMinColumnId + column_id_counter;
926 column_id_counter++;
927
928 columnDesc.propertyDesc.propertyID = id;
929 columnDesc.propertyDesc.propertyType = colType;
930 columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn;
931 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
932 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
933
934 verify_noerr( AddColumn( &columnDesc, col ) );
935
936 if (defaultWidth > 0){
937 SetColumnWidth(col, defaultWidth);
938 }
939}
940
941void wxMacDataItemBrowserControl::SetColumnWidth(int colId, int width)
942{
943 DataBrowserPropertyID id;
944 GetColumnIDFromIndex(colId, &id);
945 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id, width));
946}
947
948int wxMacDataItemBrowserControl::GetColumnWidth(int colId)
949{
950 DataBrowserPropertyID id;
951 GetColumnIDFromIndex(colId, &id);
952 UInt16 result;
953 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id, &result));
954 return result;
955}
956
957void wxMacDataItemBrowserControl::AddItem(wxMacDataItem *container, wxMacDataItem *item)
958{
959 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, 1,
960 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ) );
961}
962
963void wxMacDataItemBrowserControl::AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray )
964{
965 unsigned int noItems = itemArray.GetCount();
966 DataBrowserItemID *items = new DataBrowserItemID[noItems];
967 for ( unsigned int i = 0; i < noItems; ++i )
968 items[i] = (DataBrowserItemID) itemArray[i];
969
970 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, noItems,
971 (DataBrowserItemID*) items, kDataBrowserItemNoProperty ) );
972 delete [] items;
973}
974
975void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem *container, wxMacDataItem* item)
976{
977 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 1,
978 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty );
979 verify_noerr( err );
980}
981
982void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray)
983{
984 unsigned int noItems = itemArray.GetCount();
985 DataBrowserItemID *items = new DataBrowserItemID[noItems];
986 for ( unsigned int i = 0; i < noItems; ++i )
987 items[i] = (DataBrowserItemID) itemArray[i];
988
989 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, noItems,
990 (DataBrowserItemID*) items, kDataBrowserItemNoProperty );
991 verify_noerr( err );
992 delete [] items;
993}
994
995void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem *container)
996{
997 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 0 , NULL , kDataBrowserItemNoProperty );
998 verify_noerr( err );
999}
1000
1001void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem* item , DataBrowserSetOption option)
1002{
1003 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID*) &item, option ));
1004}
1005
1006void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option)
1007{
1008 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL , option ));
1009}
1010
1011void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr &itemArray , DataBrowserSetOption option)
1012{
1013 unsigned int noItems = itemArray.GetCount();
1014 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1015 for ( unsigned int i = 0; i < noItems; ++i )
1016 items[i] = (DataBrowserItemID) itemArray[i];
1017
1018 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems, (DataBrowserItemID*) items, option ));
1019 delete [] items;
1020}
1021
1022Boolean wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem* item) const
1023{
1024 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID) item);
1025}
1026
1027void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options)
1028{
1029 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID) item, kDataBrowserNoItem , options ) );
1030}
1031
1032void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const
1033{
1034 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID*) first, (DataBrowserItemID*) last) );
1035}
1036
1037wxClientDataType wxMacDataItemBrowserControl::GetClientDataType() const
1038{
1039 return m_clientDataItemsType;
1040}
1041void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType)
1042{
1043 m_clientDataItemsType = clientDataItemsType;
1044}
1045
1046void wxMacDataItemBrowserControl::MacDelete( unsigned int n )
1047{
1048 wxMacDataItem* item = (wxMacDataItem*)GetItemFromLine( n );
1049 RemoveItem( wxMacDataBrowserRootContainer, item );
1050}
1051
1052void wxMacDataItemBrowserControl::MacInsert( unsigned int n, wxMacDataItem* item)
1053{
1054 if ( m_sortOrder == SortOrder_None )
1055 {
1056
1057 // increase the order of the lines to be shifted
1058 unsigned int lines = MacGetCount();
1059 for ( unsigned int i = n; i < lines; ++i)
1060 {
1061 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(i);
1062 iter->SetOrder( iter->GetOrder() + 1 );
1063 }
1064
1065#if 0
1066 // I don't understand what this code is supposed to do, RR.
1067 SInt32 frontLineOrder = 0;
1068 if ( n > 0 )
1069 {
1070 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(n-1);
1071 frontLineOrder = iter->GetOrder()+1;
1072 }
1073#else
1074 item->SetOrder( n );
1075#endif
1076 }
1077
1078 AddItem( wxMacDataBrowserRootContainer, item );
1079}
1080
1081void wxMacDataItemBrowserControl::MacClear()
1082{
1083 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
1084 RemoveAllItems(wxMacDataBrowserRootContainer);
1085}
1086
1087unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1088{
1089 return GetItemCount(wxMacDataBrowserRootContainer,false,kDataBrowserItemAnyState);
1090}
1091
1092#endif // wxUSE_GUI
1093