]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/utils.cpp
minor fixes; replace references to Windows95 with references to wxMSW where possible
[wxWidgets.git] / src / osx / carbon / utils.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/utils.cpp
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
12
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
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
41 #include "wx/osx/private.h"
42 #if wxUSE_GUI
43 #include "wx/osx/private/timer.h"
44 #endif // wxUSE_GUI
45
46 #include "wx/evtloop.h"
47
48 #if defined(__MWERKS__) && wxUSE_UNICODE
49 #if __MWERKS__ < 0x4100
50 #include <wtime.h>
51 #endif
52 #endif
53
54 #if wxUSE_BASE
55
56 // Emit a beeeeeep
57 void 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
65 AlertSoundPlay();
66 #else
67 {
68 }
69 #endif
70 }
71
72 #endif // wxUSE_BASE
73
74 #if wxUSE_GUI
75
76 wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
77 {
78 return new wxOSXTimerImpl(timer);
79 }
80
81 int gs_wxBusyCursorCount = 0;
82 extern wxCursor gMacCurrentCursor;
83 wxCursor gMacStoredActiveCursor;
84
85 // Set the cursor to the busy cursor for all windows
86 void wxBeginBusyCursor(const wxCursor *cursor)
87 {
88 if (gs_wxBusyCursorCount++ == 0)
89 {
90 gMacStoredActiveCursor = gMacCurrentCursor;
91 cursor->MacInstall();
92
93 wxSetCursor(*cursor);
94 }
95 //else: nothing to do, already set
96 }
97
98 // Restore cursor to normal
99 void wxEndBusyCursor()
100 {
101 wxCHECK_RET( gs_wxBusyCursorCount > 0,
102 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
103
104 if (--gs_wxBusyCursorCount == 0)
105 {
106 gMacStoredActiveCursor.MacInstall();
107 gMacStoredActiveCursor = wxNullCursor;
108
109 wxSetCursor(wxNullCursor);
110 }
111 }
112
113 // true if we're between the above two calls
114 bool wxIsBusy()
115 {
116 return (gs_wxBusyCursorCount > 0);
117 }
118
119 #endif // wxUSE_GUI
120
121 #if wxUSE_BASE
122
123 wxString wxMacFindFolderNoSeparator( short vol,
124 OSType folderType,
125 Boolean createFolder)
126 {
127 FSRef fsRef;
128 wxString strDir;
129
130 if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr)
131 {
132 strDir = wxMacFSRefToPath( &fsRef );
133 }
134
135 return strDir;
136 }
137
138 wxString wxMacFindFolder( short vol,
139 OSType folderType,
140 Boolean createFolder)
141 {
142 return wxMacFindFolderNoSeparator(vol, folderType, createFolder) + wxFILE_SEP_PATH;
143 }
144
145 #endif // wxUSE_BASE
146
147 #if wxUSE_GUI
148
149 void wxGetMousePosition( int* x, int* y )
150 {
151 Point pt;
152 GetGlobalMouse(&pt);
153 if ( x )
154 *x = pt.h;
155 if ( y )
156 *y = pt.v;
157 };
158
159 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
160 {
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
185 }
186
187 #endif // wxUSE_GUI
188
189 #if wxUSE_BASE
190 // ----------------------------------------------------------------------------
191 // Common Event Support
192 // ----------------------------------------------------------------------------
193
194 void wxMacWakeUp()
195 {
196 OSStatus err = noErr;
197
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 )
208 {
209
210 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent ) )
211 return;
212 s_wakeupEvent.SetCurrentTime();
213 err = PostEventToQueue(GetMainEventQueue(), s_wakeupEvent,
214 kEventPriorityHigh );
215 }
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
234 void 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;
240 }
241
242 void wxMacNativeToRect( const Rect *n , wxRect* wx )
243 {
244 wx->x = n->left;
245 wx->y = n->top;
246 wx->width = n->right - n->left;
247 wx->height = n->bottom - n->top;
248 }
249
250 void wxMacPointToNative( const wxPoint* wx , Point *n )
251 {
252 n->h = wx->x;
253 n->v = wx->y;
254 }
255
256 void wxMacNativeToPoint( const Point *n , wxPoint* wx )
257 {
258 wx->x = n->h;
259 wx->y = n->v;
260 }
261
262 // ----------------------------------------------------------------------------
263 // Carbon Event Support
264 // ----------------------------------------------------------------------------
265
266 OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData)
267 {
268 return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData );
269 }
270
271 OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData)
272 {
273 return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData );
274 }
275
276 // ----------------------------------------------------------------------------
277 // Control Access Support
278 // ----------------------------------------------------------------------------
279
280
281 // ============================================================================
282 // DataBrowser Wrapper
283 // ============================================================================
284 //
285 // basing on DataBrowserItemIDs
286 //
287
288 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl , wxMacControl )
289
290 pascal 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
303 pascal 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
319 pascal 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
333 DataBrowserItemDataUPP gDataBrowserItemDataUPP = NULL;
334 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP = NULL;
335 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP = NULL;
336
337 wxMacDataBrowserControl::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
369 OSStatus 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
377 OSStatus 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
385 OSStatus wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options )
386 {
387 return SetDataBrowserSelectionFlags( m_controlRef, options );
388 }
389
390 OSStatus wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc *columnDesc,
391 DataBrowserTableViewColumnIndex position )
392 {
393 return AddDataBrowserListViewColumn( m_controlRef, columnDesc, position );
394 }
395
396 OSStatus wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id ){
397 return GetDataBrowserTableViewColumnProperty( m_controlRef, position, id );
398 }
399
400 OSStatus wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position )
401 {
402 DataBrowserTableViewColumnID id;
403 GetColumnIDFromIndex( position, &id );
404 return RemoveDataBrowserTableViewColumn( m_controlRef, id );
405 }
406
407 OSStatus wxMacDataBrowserControl::AutoSizeColumns()
408 {
409 return AutoSizeDataBrowserListViewColumns(m_controlRef);
410 }
411
412 OSStatus wxMacDataBrowserControl::SetHasScrollBars( bool horiz, bool vert )
413 {
414 return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert );
415 }
416
417 OSStatus wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle )
418 {
419 return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle );
420 }
421
422 OSStatus wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height)
423 {
424 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
425 }
426
427 OSStatus wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16 *height)
428 {
429 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
430 }
431
432 OSStatus wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks *callbacks)
433 {
434 return SetDataBrowserCallbacks( m_controlRef, callbacks );
435 }
436
437 OSStatus 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
447 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item ) const
448 {
449 return IsDataBrowserItemSelected( m_controlRef, item );
450 }
451
452 OSStatus 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
461 OSStatus 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
470 OSStatus wxMacDataBrowserControl::RevealItem(
471 DataBrowserItemID item,
472 DataBrowserPropertyID propertyID,
473 DataBrowserRevealOptions options ) const
474 {
475 return RevealDataBrowserItem( m_controlRef, item, propertyID, options );
476 }
477
478 OSStatus wxMacDataBrowserControl::SetSelectedItems(
479 UInt32 numItems,
480 const DataBrowserItemID *items,
481 DataBrowserSetOption operation )
482 {
483 return SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation );
484 }
485
486 OSStatus wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const
487 {
488 return GetDataBrowserSelectionAnchor( m_controlRef, first, last );
489 }
490
491 OSStatus wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const
492 {
493 return GetDataBrowserTableViewItemID( m_controlRef, row, item );
494 }
495
496 OSStatus wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item, DataBrowserTableViewRowIndex * row ) const
497 {
498 return GetDataBrowserTableViewItemRow( m_controlRef, item, row );
499 }
500
501 OSStatus wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height )
502 {
503 return SetDataBrowserTableViewRowHeight( m_controlRef , height );
504 }
505
506 OSStatus wxMacDataBrowserControl::GetDefaultRowHeight( UInt16 * height ) const
507 {
508 return GetDataBrowserTableViewRowHeight( m_controlRef, height );
509 }
510
511 OSStatus wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item , UInt16 height)
512 {
513 return SetDataBrowserTableViewItemRowHeight( m_controlRef, item , height );
514 }
515
516 OSStatus wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const
517 {
518 return GetDataBrowserTableViewItemRowHeight( m_controlRef, item , height);
519 }
520
521 OSStatus wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const
522 {
523 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
524 }
525
526 OSStatus wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width )
527 {
528 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
529 }
530
531 OSStatus wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16 *width ) const
532 {
533 return GetDataBrowserTableViewColumnWidth( m_controlRef , width );
534 }
535
536 OSStatus wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width )
537 {
538 return SetDataBrowserTableViewColumnWidth( m_controlRef , width );
539 }
540
541 OSStatus wxMacDataBrowserControl::GetColumnCount(UInt32* numColumns) const
542 {
543 return GetDataBrowserTableViewColumnCount( m_controlRef, numColumns);
544 }
545
546 OSStatus wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column,
547 DataBrowserTableViewColumnIndex *position) const
548 {
549 return GetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
550 }
551
552 OSStatus wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position)
553 {
554 return SetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
555 }
556
557 OSStatus wxMacDataBrowserControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const
558 {
559 return GetDataBrowserScrollPosition( m_controlRef , top , left );
560 }
561
562 OSStatus wxMacDataBrowserControl::SetScrollPosition( UInt32 top , UInt32 left )
563 {
564 return SetDataBrowserScrollPosition( m_controlRef , top , left );
565 }
566
567 OSStatus wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID *column ) const
568 {
569 return GetDataBrowserSortProperty( m_controlRef , column );
570 }
571
572 OSStatus wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column )
573 {
574 return SetDataBrowserSortProperty( m_controlRef , column );
575 }
576
577 OSStatus wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder *order ) const
578 {
579 return GetDataBrowserSortOrder( m_controlRef , order );
580 }
581
582 OSStatus wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order )
583 {
584 return SetDataBrowserSortOrder( m_controlRef , order );
585 }
586
587 OSStatus wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property,
588 DataBrowserPropertyFlags *flags ) const
589 {
590 return GetDataBrowserPropertyFlags( m_controlRef , property , flags );
591 }
592
593 OSStatus wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property,
594 DataBrowserPropertyFlags flags )
595 {
596 return SetDataBrowserPropertyFlags( m_controlRef , property , flags );
597 }
598
599 OSStatus wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property,
600 DataBrowserListViewHeaderDesc *desc ) const
601 {
602 return GetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
603 }
604
605 OSStatus wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property,
606 DataBrowserListViewHeaderDesc *desc )
607 {
608 return SetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
609 }
610
611 OSStatus 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
624 wxMacDataItem::wxMacDataItem()
625 {
626 // m_data = NULL;
627
628 m_order = 0;
629 // m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
630 }
631
632 wxMacDataItem::~wxMacDataItem()
633 {
634 }
635
636 void wxMacDataItem::SetOrder( SInt32 order )
637 {
638 m_order = order;
639 }
640
641 SInt32 wxMacDataItem::GetOrder() const
642 {
643 return m_order;
644 }
645 /*
646 void wxMacDataItem::SetData( void* data)
647 {
648 m_data = data;
649 }
650
651 void* wxMacDataItem::GetData() const
652 {
653 return m_data;
654 }
655
656 short wxMacDataItem::GetColumn()
657 {
658 return m_colId;
659 }
660
661 void wxMacDataItem::SetColumn( short col )
662 {
663 m_colId = col;
664 }
665
666 void wxMacDataItem::SetLabel( const wxString& str)
667 {
668 m_label = str;
669 m_cfLabel = wxCFStringRef( str , wxLocale::GetSystemEncoding());
670 }
671
672 const wxString& wxMacDataItem::GetLabel() const
673 {
674 return m_label;
675 }
676 */
677
678 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *WXUNUSED(owner) ,
679 const wxMacDataItem* rhs,
680 DataBrowserPropertyID sortProperty) const
681 {
682 bool retval = false;
683
684 if ( sortProperty == kNumericOrderColumnId )
685 retval = m_order < rhs->m_order;
686
687 return retval;
688 }
689
690 OSStatus wxMacDataItem::GetSetData( wxMacDataItemBrowserControl *WXUNUSED(owner) ,
691 DataBrowserPropertyID property,
692 DataBrowserItemDataRef itemData,
693 bool changeValue )
694 {
695 OSStatus err = errDataBrowserPropertyNotSupported;
696 if ( !changeValue )
697 {
698 if ( property == kNumericOrderColumnId )
699 {
700 err = ::SetDataBrowserItemDataValue( itemData, m_order );
701 err = noErr;
702 }
703 }
704
705 return err;
706 }
707
708 void wxMacDataItem::Notification(wxMacDataItemBrowserControl *WXUNUSED(owner) ,
709 DataBrowserItemNotification WXUNUSED(message),
710 DataBrowserItemDataRef WXUNUSED(itemData) ) const
711 {
712 }
713
714 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl , wxMacDataBrowserControl )
715
716 wxMacDataItemBrowserControl::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
724 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser)
725 {
726 m_former = browser->SuppressSelection(true);
727 m_browser = browser;
728 }
729
730 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
731 {
732 m_browser->SuppressSelection(m_former);
733 }
734
735 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress )
736 {
737 bool former = m_suppressSelection;
738 m_suppressSelection = suppress;
739
740 return former;
741 }
742
743 Boolean 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
752 Boolean 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
762 OSStatus 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
772 OSStatus 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
797 void wxMacDataItemBrowserControl::ItemNotification(
798 DataBrowserItemID itemID,
799 DataBrowserItemNotification message,
800 DataBrowserItemDataRef itemData)
801 {
802 wxMacDataItem* item = (wxMacDataItem*) itemID;
803 ItemNotification( item , message, itemData);
804 }
805
806 void 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
815 unsigned 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
824 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem* container,
825 bool recurse ) const
826 {
827 return GetItemCount( container, recurse, kDataBrowserItemIsSelected );
828
829 }
830
831 void 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
849 unsigned 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
857 wxMacDataItem* 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
865 void 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
872 void 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
885 void 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
927 void wxMacDataItemBrowserControl::SetColumnWidth(int colId, int width)
928 {
929 DataBrowserPropertyID id;
930 GetColumnIDFromIndex(colId, &id);
931 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id, width));
932 }
933
934 int 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
943 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem *container, wxMacDataItem *item)
944 {
945 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, 1,
946 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ) );
947 }
948
949 void 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
961 void 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
968 void 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
981 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem *container)
982 {
983 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 0 , NULL , kDataBrowserItemNoProperty );
984 verify_noerr( err );
985 }
986
987 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem* item , DataBrowserSetOption option)
988 {
989 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID*) &item, option ));
990 }
991
992 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option)
993 {
994 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL , option ));
995 }
996
997 void 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
1008 Boolean wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem* item) const
1009 {
1010 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID) item);
1011 }
1012
1013 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options)
1014 {
1015 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID) item, kDataBrowserNoItem , options ) );
1016 }
1017
1018 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const
1019 {
1020 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID*) first, (DataBrowserItemID*) last) );
1021 }
1022
1023 wxClientDataType wxMacDataItemBrowserControl::GetClientDataType() const
1024 {
1025 return m_clientDataItemsType;
1026 }
1027 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType)
1028 {
1029 m_clientDataItemsType = clientDataItemsType;
1030 }
1031
1032 void wxMacDataItemBrowserControl::MacDelete( unsigned int n )
1033 {
1034 wxMacDataItem* item = (wxMacDataItem*)GetItemFromLine( n );
1035 RemoveItem( wxMacDataBrowserRootContainer, item );
1036 }
1037
1038 void wxMacDataItemBrowserControl::MacInsert( unsigned int n, wxMacDataItem* item)
1039 {
1040 if ( m_sortOrder == SortOrder_None )
1041 {
1042
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);
1048 iter->SetOrder( iter->GetOrder() + 1 );
1049 }
1050
1051 #if 0
1052 // I don't understand what this code is supposed to do, RR.
1053 SInt32 frontLineOrder = 0;
1054 if ( n > 0 )
1055 {
1056 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(n-1);
1057 frontLineOrder = iter->GetOrder()+1;
1058 }
1059 #else
1060 item->SetOrder( n );
1061 #endif
1062 }
1063
1064 AddItem( wxMacDataBrowserRootContainer, item );
1065 }
1066
1067 void wxMacDataItemBrowserControl::MacClear()
1068 {
1069 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
1070 RemoveAllItems(wxMacDataBrowserRootContainer);
1071 }
1072
1073 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1074 {
1075 return GetItemCount(wxMacDataBrowserRootContainer,false,kDataBrowserItemAnyState);
1076 }
1077
1078 #endif // wxUSE_GUI
1079