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