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