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