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