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