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