]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/utils.cpp
include <string>
[wxWidgets.git] / src / osx / carbon / utils.cpp
CommitLineData
489468fe
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/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
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
SC
54//
55// TODO BEGIN move to utils_osx.cpp
56//
57
489468fe
SC
58#if wxUSE_BASE
59
b2680ced
SC
60extern bool WXDLLEXPORT wxIsDebuggerRunning()
61{
62 // TODO : try to find out ...
63 return false;
64}
65
66#if wxOSX_USE_COCOA_OR_CARBON
67
489468fe
SC
68// our OS version is the same in non GUI and GUI cases
69wxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn)
70{
71 SInt32 theSystem;
72 Gestalt(gestaltSystemVersion, &theSystem);
73
74 if ( majorVsn != NULL )
75 *majorVsn = (theSystem >> 8);
76
77 if ( minorVsn != NULL )
78 *minorVsn = (theSystem & 0xFF);
79
489468fe 80 return wxOS_MAC_OSX_DARWIN;
489468fe
SC
81}
82
b2680ced 83#include <sys/utsname.h>
489468fe 84
b2680ced 85wxString wxGetOsDescription()
489468fe 86{
b2680ced
SC
87 struct utsname name;
88 uname(&name);
89 return wxString::Format(_T("Mac OS X (%s %s %s)"),
90 wxString::FromAscii(name.sysname).c_str(),
91 wxString::FromAscii(name.release).c_str(),
92 wxString::FromAscii(name.machine).c_str());
489468fe
SC
93}
94
b2680ced 95#endif // wxOSX_USE_COCOA_OR_CARBON
489468fe 96
489468fe 97
b2680ced
SC
98//---------------------------------------------------------------------------
99// wxMac Specific utility functions
100//---------------------------------------------------------------------------
489468fe 101
b2680ced 102void wxMacStringToPascal( const wxString&from , StringPtr to )
489468fe 103{
b2680ced
SC
104 wxCharBuffer buf = from.mb_str( wxConvLocal );
105 int len = strlen(buf);
489468fe 106
b2680ced
SC
107 if ( len > 255 )
108 len = 255;
109 to[0] = len;
110 memcpy( (char*) &to[1] , buf , len );
489468fe
SC
111}
112
b2680ced 113wxString wxMacMakeStringFromPascal( ConstStringPtr from )
489468fe 114{
b2680ced 115 return wxString( (char*) &from[1] , wxConvLocal , from[0] );
489468fe
SC
116}
117
118#endif // wxUSE_BASE
119
120#if wxUSE_GUI
121
122// Check whether this window wants to process messages, e.g. Stop button
123// in long calculations.
124bool wxCheckForInterrupt(wxWindow *WXUNUSED(wnd))
125{
126 // TODO
127 return false;
128}
129
489468fe
SC
130// Return true if we have a colour display
131bool wxColourDisplay()
132{
133 return true;
134}
135
b2680ced 136#if wxOSX_USE_COCOA_OR_CARBON
489468fe
SC
137// Returns depth of screen
138int wxDisplayDepth()
139{
489468fe 140 int theDepth = (int) CGDisplayBitsPerPixel(CGMainDisplayID());
489468fe 141 return theDepth;
489468fe
SC
142}
143
144// Get size of display
145void wxDisplaySize(int *width, int *height)
146{
147 // TODO adapt for multi-displays
148 CGRect bounds = CGDisplayBounds(CGMainDisplayID());
149 if ( width )
150 *width = (int)bounds.size.width ;
151 if ( height )
152 *height = (int)bounds.size.height;
153}
b2680ced 154#endif
489468fe
SC
155
156void wxDisplaySizeMM(int *width, int *height)
157{
158 wxDisplaySize(width, height);
159 // on mac 72 is fixed (at least now;-)
b2680ced 160 double cvPt2Mm = 25.4 / 72;
489468fe
SC
161
162 if (width != NULL)
163 *width = int( *width * cvPt2Mm );
164
165 if (height != NULL)
166 *height = int( *height * cvPt2Mm );
167}
168
489468fe 169
b2680ced 170wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
489468fe 171{
b2680ced
SC
172 // We suppose that toolkit version is the same as OS version under Mac
173 wxGetOsVersion(verMaj, verMin);
489468fe 174
b2680ced 175 return wxPORT_OSX;
489468fe
SC
176}
177
b2680ced 178wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
489468fe 179{
b2680ced 180 return new wxEventLoop;
489468fe 181}
489468fe 182
b2680ced 183wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
489468fe 184{
b2680ced 185 return wxGenericFindWindowAtPoint(pt);
489468fe
SC
186}
187
b2680ced
SC
188/*
189 Return the generic RGB color space. This is a 'get' function and the caller should
190 not release the returned value unless the caller retains it first. Usually callers
191 of this routine will immediately use the returned colorspace with CoreGraphics
192 so they typically do not need to retain it themselves.
489468fe 193
b2680ced
SC
194 This function creates the generic RGB color space once and hangs onto it so it can
195 return it whenever this function is called.
196*/
489468fe 197
b2680ced 198CGColorSpaceRef wxMacGetGenericRGBColorSpace()
489468fe 199{
b2680ced 200 static wxCFRef<CGColorSpaceRef> genericRGBColorSpace;
489468fe 201
b2680ced 202 if (genericRGBColorSpace == NULL)
489468fe 203 {
b2680ced
SC
204#if wxOSX_USE_IPHONE
205 genericRGBColorSpace.reset( CGColorSpaceCreateDeviceRGB() );
489468fe 206#else
b2680ced 207 genericRGBColorSpace.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) );
489468fe 208#endif
489468fe
SC
209 }
210
b2680ced 211 return genericRGBColorSpace;
489468fe
SC
212}
213
b2680ced 214#if wxOSX_USE_COCOA_OR_CARBON
489468fe 215
b2680ced 216CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush )
489468fe 217{
b2680ced
SC
218 CGColorRef color ;
219 HIThemeBrushCreateCGColor( brush, &color );
220 return color;
489468fe
SC
221}
222
b2680ced 223#endif // wxOSX_USE_COCOA_OR_CARBON
489468fe 224
b2680ced 225IMPLEMENT_ABSTRACT_CLASS( wxWidgetImpl , wxObject )
489468fe 226
b2680ced 227wxWidgetImpl::wxWidgetImpl( wxWindowMac* peer , bool isRootControl )
489468fe 228{
b2680ced
SC
229 Init();
230 m_isRootControl = isRootControl;
231 m_wxPeer = peer;
489468fe
SC
232}
233
b2680ced 234wxWidgetImpl::wxWidgetImpl()
489468fe 235{
b2680ced 236 Init();
489468fe
SC
237}
238
b2680ced 239wxWidgetImpl::~wxWidgetImpl()
489468fe 240{
489468fe
SC
241}
242
b2680ced 243void wxWidgetImpl::Init()
489468fe 244{
b2680ced
SC
245 m_isRootControl = false;
246 m_wxPeer = NULL;
247 m_needsFocusRect = false;
489468fe
SC
248}
249
b2680ced 250void wxWidgetImpl::Destroy()
489468fe 251{
489468fe
SC
252}
253
b2680ced 254void wxWidgetImpl::SetNeedsFocusRect( bool needs )
489468fe 255{
b2680ced 256 m_needsFocusRect = needs;
489468fe
SC
257}
258
b2680ced 259bool wxWidgetImpl::NeedsFocusRect() const
489468fe 260{
b2680ced 261 return m_needsFocusRect;
489468fe
SC
262}
263
b2680ced 264#endif // wxUSE_GUI
489468fe 265
b2680ced
SC
266//
267// TODO END move to utils_osx.cpp
268//
489468fe 269
b2680ced
SC
270//
271// carbon version
272//
489468fe 273
b2680ced 274#if wxOSX_USE_CARBON
489468fe 275
b2680ced 276#if wxUSE_BASE
489468fe 277
b2680ced
SC
278// Emit a beeeeeep
279void wxBell()
280{
281#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
282 if ( AudioServicesPlayAlertSound != NULL )
283 AudioServicesPlayAlertSound(kUserPreferredAlert);
284 else
285#endif
286#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
287 SysBeep(30);
288#else
489468fe 289 {
489468fe 290 }
b2680ced 291#endif
489468fe
SC
292}
293
b2680ced 294#endif // wxUSE_BASE
489468fe 295
b2680ced 296#if wxUSE_GUI
489468fe 297
b2680ced 298wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
489468fe 299{
b2680ced 300 return new wxCarbonTimerImpl(timer);
489468fe
SC
301}
302
b2680ced
SC
303int gs_wxBusyCursorCount = 0;
304extern wxCursor gMacCurrentCursor;
305wxCursor gMacStoredActiveCursor;
306
307// Set the cursor to the busy cursor for all windows
308void wxBeginBusyCursor(const wxCursor *cursor)
489468fe 309{
b2680ced
SC
310 if (gs_wxBusyCursorCount++ == 0)
311 {
312 gMacStoredActiveCursor = gMacCurrentCursor;
313 cursor->MacInstall();
314
315 wxSetCursor(*cursor);
316 }
317 //else: nothing to do, already set
489468fe
SC
318}
319
b2680ced
SC
320// Restore cursor to normal
321void wxEndBusyCursor()
489468fe 322{
b2680ced
SC
323 wxCHECK_RET( gs_wxBusyCursorCount > 0,
324 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
489468fe 325
b2680ced 326 if (--gs_wxBusyCursorCount == 0)
489468fe 327 {
b2680ced
SC
328 gMacStoredActiveCursor.MacInstall();
329 gMacStoredActiveCursor = wxNullCursor;
330
331 wxSetCursor(wxNullCursor);
489468fe
SC
332 }
333}
334
b2680ced
SC
335// true if we're between the above two calls
336bool wxIsBusy()
489468fe 337{
b2680ced 338 return (gs_wxBusyCursorCount > 0);
489468fe
SC
339}
340
b2680ced
SC
341#endif // wxUSE_GUI
342
343#if wxUSE_BASE
344
345wxString wxMacFindFolderNoSeparator( short vol,
346 OSType folderType,
347 Boolean createFolder)
489468fe 348{
b2680ced
SC
349 FSRef fsRef;
350 wxString strDir;
489468fe 351
b2680ced
SC
352 if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr)
353 {
354 strDir = wxMacFSRefToPath( &fsRef );
355 }
489468fe 356
b2680ced 357 return strDir;
489468fe
SC
358}
359
b2680ced
SC
360wxString wxMacFindFolder( short vol,
361 OSType folderType,
362 Boolean createFolder)
489468fe 363{
b2680ced 364 return wxMacFindFolderNoSeparator(vol, folderType, createFolder) + wxFILE_SEP_PATH;
489468fe
SC
365}
366
b2680ced
SC
367#endif // wxUSE_BASE
368
369#if wxUSE_GUI
370
371void wxGetMousePosition( int* x, int* y )
489468fe 372{
b2680ced
SC
373 Point pt;
374 GetGlobalMouse(&pt);
375 if ( x )
376 *x = pt.h;
377 if ( y )
378 *y = pt.v;
379};
489468fe 380
b2680ced 381void wxClientDisplayRect(int *x, int *y, int *width, int *height)
489468fe 382{
b2680ced
SC
383#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
384 HIRect bounds ;
385 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal,
386 &bounds);
387 if ( x )
388 *x = bounds.origin.x;
389 if ( y )
390 *y = bounds.origin.y;
391 if ( width )
392 *width = bounds.size.width;
393 if ( height )
394 *height = bounds.size.height;
395#else
396 Rect r;
397 GetAvailableWindowPositioningBounds( GetMainDevice() , &r );
398 if ( x )
399 *x = r.left;
400 if ( y )
401 *y = r.top;
402 if ( width )
403 *width = r.right - r.left;
404 if ( height )
405 *height = r.bottom - r.top;
406#endif
489468fe
SC
407}
408
b2680ced
SC
409#endif // wxUSE_GUI
410
411#if wxUSE_BASE
412// ----------------------------------------------------------------------------
413// Common Event Support
414// ----------------------------------------------------------------------------
489468fe 415
b2680ced
SC
416void wxMacWakeUp()
417{
418 OSStatus err = noErr;
489468fe 419
b2680ced
SC
420#if wxOSX_USE_CARBON
421#if 0
422 // lead sometimes to race conditions, although all calls used should be thread safe ...
423 static wxMacCarbonEvent s_wakeupEvent;
424 if ( !s_wakeupEvent.IsValid() )
425 {
426 err = s_wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
427 kEventAttributeNone );
428 }
429 if ( err == noErr )
489468fe 430 {
489468fe 431
b2680ced 432 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent ) )
489468fe 433 return;
b2680ced
SC
434 s_wakeupEvent.SetCurrentTime();
435 err = PostEventToQueue(GetMainEventQueue(), s_wakeupEvent,
436 kEventPriorityHigh );
489468fe 437 }
b2680ced
SC
438#else
439 wxMacCarbonEvent wakeupEvent;
440 wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
441 kEventAttributeNone );
442 err = PostEventToQueue(GetMainEventQueue(), wakeupEvent,
443 kEventPriorityHigh );
444#endif
445#endif
446}
447
448#endif // wxUSE_BASE
449
450#if wxUSE_GUI
451
452// ----------------------------------------------------------------------------
453// Native Struct Conversions
454// ----------------------------------------------------------------------------
455
456void wxMacRectToNative( const wxRect *wx , Rect *n )
457{
458 n->left = wx->x;
459 n->top = wx->y;
460 n->right = wx->x + wx->width;
461 n->bottom = wx->y + wx->height;
489468fe
SC
462}
463
b2680ced 464void wxMacNativeToRect( const Rect *n , wxRect* wx )
489468fe 465{
b2680ced
SC
466 wx->x = n->left;
467 wx->y = n->top;
468 wx->width = n->right - n->left;
469 wx->height = n->bottom - n->top;
489468fe
SC
470}
471
b2680ced 472void wxMacPointToNative( const wxPoint* wx , Point *n )
489468fe 473{
b2680ced
SC
474 n->h = wx->x;
475 n->v = wx->y;
476}
489468fe 477
b2680ced
SC
478void wxMacNativeToPoint( const Point *n , wxPoint* wx )
479{
480 wx->x = n->h;
481 wx->y = n->v;
489468fe
SC
482}
483
b2680ced
SC
484// ----------------------------------------------------------------------------
485// Carbon Event Support
486// ----------------------------------------------------------------------------
489468fe 487
b2680ced 488OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData)
489468fe 489{
b2680ced 490 return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData );
489468fe
SC
491}
492
b2680ced 493OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData)
489468fe 494{
b2680ced 495 return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData );
489468fe
SC
496}
497
b2680ced
SC
498// ----------------------------------------------------------------------------
499// Control Access Support
500// ----------------------------------------------------------------------------
501
502
489468fe
SC
503// ============================================================================
504// DataBrowser Wrapper
505// ============================================================================
506//
507// basing on DataBrowserItemIDs
508//
509
510IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl , wxMacControl )
511
512pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
513 ControlRef browser,
514 DataBrowserItemID itemID,
515 DataBrowserItemNotification message,
516 DataBrowserItemDataRef itemData )
517{
518 wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl);
519 if ( ctl != 0 )
520 {
521 ctl->ItemNotification(itemID, message, itemData);
522 }
523}
524
525pascal OSStatus wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
526 ControlRef browser,
527 DataBrowserItemID itemID,
528 DataBrowserPropertyID property,
529 DataBrowserItemDataRef itemData,
530 Boolean changeValue )
531{
532 OSStatus err = errDataBrowserPropertyNotSupported;
533 wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl);
534 if ( ctl != 0 )
535 {
536 err = ctl->GetSetItemData(itemID, property, itemData, changeValue);
537 }
538 return err;
539}
540
541pascal Boolean wxMacDataBrowserControl::DataBrowserCompareProc(
542 ControlRef browser,
543 DataBrowserItemID itemOneID,
544 DataBrowserItemID itemTwoID,
545 DataBrowserPropertyID sortProperty)
546{
547 wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl);
548 if ( ctl != 0 )
549 {
550 return ctl->CompareItems(itemOneID, itemTwoID, sortProperty);
551 }
552 return false;
553}
554
555DataBrowserItemDataUPP gDataBrowserItemDataUPP = NULL;
556DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP = NULL;
557DataBrowserItemCompareUPP gDataBrowserItemCompareUPP = NULL;
558
559wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow* peer,
560 const wxPoint& pos,
561 const wxSize& size,
562 long WXUNUSED(style))
563 : wxMacControl( peer )
564{
565 Rect bounds = wxMacGetBoundsForControl( peer, pos, size );
566 OSStatus err = ::CreateDataBrowserControl(
567 MAC_WXHWND(peer->MacGetTopLevelWindowRef()),
568 &bounds, kDataBrowserListView, &m_controlRef );
569 SetReferenceInNativeControl();
570 verify_noerr( err );
571 if ( gDataBrowserItemCompareUPP == NULL )
572 gDataBrowserItemCompareUPP = NewDataBrowserItemCompareUPP(DataBrowserCompareProc);
573 if ( gDataBrowserItemDataUPP == NULL )
574 gDataBrowserItemDataUPP = NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc);
575 if ( gDataBrowserItemNotificationUPP == NULL )
576 {
577 gDataBrowserItemNotificationUPP =
578 (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc);
579 }
580
581 DataBrowserCallbacks callbacks;
582 InitializeDataBrowserCallbacks( &callbacks, kDataBrowserLatestCallbacks );
583
584 callbacks.u.v1.itemDataCallback = gDataBrowserItemDataUPP;
585 callbacks.u.v1.itemCompareCallback = gDataBrowserItemCompareUPP;
586 callbacks.u.v1.itemNotificationCallback = gDataBrowserItemNotificationUPP;
587 SetCallbacks( &callbacks );
588
589}
590
591OSStatus wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container,
592 Boolean recurse,
593 DataBrowserItemState state,
594 ItemCount *numItems) const
595{
596 return GetDataBrowserItemCount( m_controlRef, container, recurse, state, numItems );
597}
598
599OSStatus wxMacDataBrowserControl::GetItems( DataBrowserItemID container,
600 Boolean recurse,
601 DataBrowserItemState state,
602 Handle items) const
603{
604 return GetDataBrowserItems( m_controlRef, container, recurse, state, items );
605}
606
607OSStatus wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options )
608{
609 return SetDataBrowserSelectionFlags( m_controlRef, options );
610}
611
612OSStatus wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc *columnDesc,
613 DataBrowserTableViewColumnIndex position )
614{
615 return AddDataBrowserListViewColumn( m_controlRef, columnDesc, position );
616}
617
618OSStatus wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id ){
619 return GetDataBrowserTableViewColumnProperty( m_controlRef, position, id );
620}
621
622OSStatus wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position )
623{
624 DataBrowserTableViewColumnID id;
625 GetColumnIDFromIndex( position, &id );
626 return RemoveDataBrowserTableViewColumn( m_controlRef, id );
627}
628
629OSStatus wxMacDataBrowserControl::AutoSizeColumns()
630{
631 return AutoSizeDataBrowserListViewColumns(m_controlRef);
632}
633
634OSStatus wxMacDataBrowserControl::SetHasScrollBars( bool horiz, bool vert )
635{
636 return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert );
637}
638
639OSStatus wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle )
640{
641 return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle );
642}
643
644OSStatus wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height)
645{
646 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
647}
648
649OSStatus wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16 *height)
650{
651 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
652}
653
654OSStatus wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks *callbacks)
655{
656 return SetDataBrowserCallbacks( m_controlRef, callbacks );
657}
658
659OSStatus wxMacDataBrowserControl::UpdateItems(
660 DataBrowserItemID container,
661 UInt32 numItems,
662 const DataBrowserItemID *items,
663 DataBrowserPropertyID preSortProperty,
664 DataBrowserPropertyID propertyID ) const
665{
666 return UpdateDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty, propertyID );
667}
668
669bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item ) const
670{
671 return IsDataBrowserItemSelected( m_controlRef, item );
672}
673
674OSStatus wxMacDataBrowserControl::AddItems(
675 DataBrowserItemID container,
676 UInt32 numItems,
677 const DataBrowserItemID *items,
678 DataBrowserPropertyID preSortProperty )
679{
680 return AddDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty );
681}
682
683OSStatus wxMacDataBrowserControl::RemoveItems(
684 DataBrowserItemID container,
685 UInt32 numItems,
686 const DataBrowserItemID *items,
687 DataBrowserPropertyID preSortProperty )
688{
689 return RemoveDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty );
690}
691
692OSStatus wxMacDataBrowserControl::RevealItem(
693 DataBrowserItemID item,
694 DataBrowserPropertyID propertyID,
695 DataBrowserRevealOptions options ) const
696{
697 return RevealDataBrowserItem( m_controlRef, item, propertyID, options );
698}
699
700OSStatus wxMacDataBrowserControl::SetSelectedItems(
701 UInt32 numItems,
702 const DataBrowserItemID *items,
703 DataBrowserSetOption operation )
704{
705 return SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation );
706}
707
708OSStatus wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const
709{
710 return GetDataBrowserSelectionAnchor( m_controlRef, first, last );
711}
712
713OSStatus wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const
714{
715 return GetDataBrowserTableViewItemID( m_controlRef, row, item );
716}
717
718OSStatus wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item, DataBrowserTableViewRowIndex * row ) const
719{
720 return GetDataBrowserTableViewItemRow( m_controlRef, item, row );
721}
722
723OSStatus wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height )
724{
725 return SetDataBrowserTableViewRowHeight( m_controlRef , height );
726}
727
728OSStatus wxMacDataBrowserControl::GetDefaultRowHeight( UInt16 * height ) const
729{
730 return GetDataBrowserTableViewRowHeight( m_controlRef, height );
731}
732
733OSStatus wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item , UInt16 height)
734{
735 return SetDataBrowserTableViewItemRowHeight( m_controlRef, item , height );
736}
737
738OSStatus wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const
739{
740 return GetDataBrowserTableViewItemRowHeight( m_controlRef, item , height);
741}
742
743OSStatus wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const
744{
745 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
746}
747
748OSStatus wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width )
749{
750 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
751}
752
753OSStatus wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16 *width ) const
754{
755 return GetDataBrowserTableViewColumnWidth( m_controlRef , width );
756}
757
758OSStatus wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width )
759{
760 return SetDataBrowserTableViewColumnWidth( m_controlRef , width );
761}
762
763OSStatus wxMacDataBrowserControl::GetColumnCount(UInt32* numColumns) const
764{
765 return GetDataBrowserTableViewColumnCount( m_controlRef, numColumns);
766}
767
768OSStatus wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column,
769 DataBrowserTableViewColumnIndex *position) const
770{
771 return GetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
772}
773
774OSStatus wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position)
775{
776 return SetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
777}
778
779OSStatus wxMacDataBrowserControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const
780{
781 return GetDataBrowserScrollPosition( m_controlRef , top , left );
782}
783
784OSStatus wxMacDataBrowserControl::SetScrollPosition( UInt32 top , UInt32 left )
785{
786 return SetDataBrowserScrollPosition( m_controlRef , top , left );
787}
788
789OSStatus wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID *column ) const
790{
791 return GetDataBrowserSortProperty( m_controlRef , column );
792}
793
794OSStatus wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column )
795{
796 return SetDataBrowserSortProperty( m_controlRef , column );
797}
798
799OSStatus wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder *order ) const
800{
801 return GetDataBrowserSortOrder( m_controlRef , order );
802}
803
804OSStatus wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order )
805{
806 return SetDataBrowserSortOrder( m_controlRef , order );
807}
808
809OSStatus wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property,
810 DataBrowserPropertyFlags *flags ) const
811{
812 return GetDataBrowserPropertyFlags( m_controlRef , property , flags );
813}
814
815OSStatus wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property,
816 DataBrowserPropertyFlags flags )
817{
818 return SetDataBrowserPropertyFlags( m_controlRef , property , flags );
819}
820
821OSStatus wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property,
822 DataBrowserListViewHeaderDesc *desc ) const
823{
824 return GetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
825}
826
827OSStatus wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property,
828 DataBrowserListViewHeaderDesc *desc )
829{
830 return SetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
831}
832
833OSStatus wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property ,
834 Boolean expandableRows )
835{
836 return SetDataBrowserListViewDisclosureColumn( m_controlRef, property, expandableRows);
837}
838
839// ============================================================================
840// Higher-level Databrowser
841// ============================================================================
842//
843// basing on data item objects
844//
845
846wxMacDataItem::wxMacDataItem()
847{
848 m_data = NULL;
849
850 m_order = 0;
851 m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
852}
853
854wxMacDataItem::~wxMacDataItem()
855{
856}
857
858void wxMacDataItem::SetOrder( SInt32 order )
859{
860 m_order = order;
861}
862
863SInt32 wxMacDataItem::GetOrder() const
864{
865 return m_order;
866}
867
868void wxMacDataItem::SetData( void* data)
869{
870 m_data = data;
871}
872
873void* wxMacDataItem::GetData() const
874{
875 return m_data;
876}
877
878short wxMacDataItem::GetColumn()
879{
880 return m_colId;
881}
882
883void wxMacDataItem::SetColumn( short col )
884{
885 m_colId = col;
886}
887
888void wxMacDataItem::SetLabel( const wxString& str)
889{
890 m_label = str;
891 m_cfLabel = wxCFStringRef( str , wxLocale::GetSystemEncoding());
892}
893
894const wxString& wxMacDataItem::GetLabel() const
895{
896 return m_label;
897}
898
899bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *WXUNUSED(owner) ,
900 const wxMacDataItem* rhs,
901 DataBrowserPropertyID sortProperty) const
902{
903 const wxMacDataItem* otherItem = wx_const_cast(wxMacDataItem*,rhs);
904 bool retval = false;
905
906 if ( sortProperty == m_colId ){
907 retval = m_label.CmpNoCase( otherItem->m_label) < 0;
908 }
909
910 else if ( sortProperty == kNumericOrderColumnId )
911 retval = m_order < otherItem->m_order;
912
913 return retval;
914}
915
916OSStatus wxMacDataItem::GetSetData( wxMacDataItemBrowserControl *WXUNUSED(owner) ,
917 DataBrowserPropertyID property,
918 DataBrowserItemDataRef itemData,
919 bool changeValue )
920{
921 OSStatus err = errDataBrowserPropertyNotSupported;
922 if ( !changeValue )
923 {
924 if ( property == m_colId ){
925 err = ::SetDataBrowserItemDataText( itemData, m_cfLabel );
926 err = noErr;
927 }
928 else if ( property == kNumericOrderColumnId ){
929 err = ::SetDataBrowserItemDataValue( itemData, m_order );
930 err = noErr;
931 }
932 else{
933 }
934 }
935 else
936 {
937 switch (property)
938 {
939 // no editable props here
940 default:
941 break;
942 }
943 }
944
945 return err;
946}
947
948void wxMacDataItem::Notification(wxMacDataItemBrowserControl *WXUNUSED(owner) ,
949 DataBrowserItemNotification WXUNUSED(message),
950 DataBrowserItemDataRef WXUNUSED(itemData) ) const
951{
952}
953
954IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl , wxMacDataBrowserControl )
955
956wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style) :
957 wxMacDataBrowserControl( peer, pos, size, style )
958{
959 m_suppressSelection = false;
960 m_sortOrder = SortOrder_None;
961 m_clientDataItemsType = wxClientData_None;
962}
963
964wxMacDataItem* wxMacDataItemBrowserControl::CreateItem()
965{
966 return new wxMacDataItem();
967}
968
969wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser)
970{
971 m_former = browser->SuppressSelection(true);
972 m_browser = browser;
973}
974
975wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
976{
977 m_browser->SuppressSelection(m_former);
978}
979
980bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress )
981{
982 bool former = m_suppressSelection;
983 m_suppressSelection = suppress;
984
985 return former;
986}
987
988Boolean wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID,
989 DataBrowserItemID itemTwoID,
990 DataBrowserPropertyID sortProperty)
991{
992 wxMacDataItem* itemOne = (wxMacDataItem*) itemOneID;
993 wxMacDataItem* itemTwo = (wxMacDataItem*) itemTwoID;
994 return CompareItems( itemOne , itemTwo , sortProperty );
995}
996
997Boolean wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem* itemOne,
998 const wxMacDataItem* itemTwo,
999 DataBrowserPropertyID sortProperty)
1000{
1001 Boolean retval = false;
1002 if ( itemOne != NULL )
1003 retval = itemOne->IsLessThan( this , itemTwo , sortProperty);
1004 return retval;
1005}
1006
1007OSStatus wxMacDataItemBrowserControl::GetSetItemData(
1008 DataBrowserItemID itemID,
1009 DataBrowserPropertyID property,
1010 DataBrowserItemDataRef itemData,
1011 Boolean changeValue )
1012{
1013 wxMacDataItem* item = (wxMacDataItem*) itemID;
1014 return GetSetItemData(item, property, itemData , changeValue );
1015}
1016
1017OSStatus wxMacDataItemBrowserControl::GetSetItemData(
1018 wxMacDataItem* item,
1019 DataBrowserPropertyID property,
1020 DataBrowserItemDataRef itemData,
1021 Boolean changeValue )
1022{
1023 OSStatus err = errDataBrowserPropertyNotSupported;
1024 switch( property )
1025 {
1026 case kDataBrowserContainerIsClosableProperty :
1027 case kDataBrowserContainerIsSortableProperty :
1028 case kDataBrowserContainerIsOpenableProperty :
1029 // right now default behaviour on these
1030 break;
1031 default :
1032
1033 if ( item != NULL ){
1034 err = item->GetSetData( this, property , itemData , changeValue );
1035 }
1036 break;
1037
1038 }
1039 return err;
1040}
1041
1042void wxMacDataItemBrowserControl::ItemNotification(
1043 DataBrowserItemID itemID,
1044 DataBrowserItemNotification message,
1045 DataBrowserItemDataRef itemData)
1046{
1047 wxMacDataItem* item = (wxMacDataItem*) itemID;
1048 ItemNotification( item , message, itemData);
1049}
1050
1051void wxMacDataItemBrowserControl::ItemNotification(
1052 const wxMacDataItem* item,
1053 DataBrowserItemNotification message,
1054 DataBrowserItemDataRef itemData)
1055{
1056 if (item != NULL)
1057 item->Notification( this, message, itemData);
1058}
1059
1060unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem* container,
1061 bool recurse , DataBrowserItemState state) const
1062{
1063 ItemCount numItems = 0;
1064 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID)container,
1065 recurse, state, &numItems ) );
1066 return numItems;
1067}
1068
1069unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem* container,
1070 bool recurse ) const
1071{
1072 return GetItemCount( container, recurse, kDataBrowserItemIsSelected );
1073
1074}
1075
1076void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem* container,
1077 bool recurse , DataBrowserItemState state, wxArrayMacDataItemPtr &items) const
1078{
1079 Handle handle = NewHandle(0);
1080 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID)container ,
1081 recurse , state, handle) );
1082
1083 int itemCount = GetHandleSize(handle)/sizeof(DataBrowserItemID);
1084 HLock( handle );
1085 wxMacDataItemPtr* itemsArray = (wxMacDataItemPtr*) *handle;
1086 for ( int i = 0; i < itemCount; ++i)
1087 {
1088 items.Add(itemsArray[i]);
1089 }
1090 HUnlock( handle );
1091 DisposeHandle( handle );
1092}
1093
1094unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem* item) const
1095{
1096 DataBrowserTableViewRowIndex row;
1097 OSStatus err = GetItemRow( (DataBrowserItemID) item , &row);
1098 wxCHECK( err == noErr, (unsigned)-1 );
1099 return row;
1100}
1101
1102wxMacDataItem* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n) const
1103{
1104 DataBrowserItemID id;
1105 OSStatus err = GetItemID( (DataBrowserTableViewRowIndex) n , &id);
1106 wxCHECK( err == noErr, NULL );
1107 return (wxMacDataItem*) id;
1108}
1109
1110void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem *container,
1111 const wxMacDataItem *item , DataBrowserPropertyID property) const
1112{
1113 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, 1,
1114 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty /* notSorted */, property ) );
1115}
1116
1117void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem *container,
1118 wxArrayMacDataItemPtr &itemArray , DataBrowserPropertyID property) const
1119{
1120 unsigned int noItems = itemArray.GetCount();
1121 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1122 for ( unsigned int i = 0; i < noItems; ++i )
1123 items[i] = (DataBrowserItemID) itemArray[i];
1124
1125 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, noItems,
1126 items, kDataBrowserItemNoProperty /* notSorted */, property ) );
1127 delete [] items;
1128}
1129
1130void wxMacDataItemBrowserControl::InsertColumn(int colId, DataBrowserPropertyType colType,
1131 const wxString& title, SInt16 just, int defaultWidth)
1132{
1133 DataBrowserListViewColumnDesc columnDesc;
1134 columnDesc.headerBtnDesc.titleOffset = 0;
1135 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
1136
1137 columnDesc.headerBtnDesc.btnFontStyle.flags =
1138 kControlUseFontMask | kControlUseJustMask;
1139
1140 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
1141 columnDesc.headerBtnDesc.btnFontStyle.just = just;
1142 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
1143 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
1144
1145 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1146 // defined for other modes?
1147 wxFontEncoding enc;
1148 if ( m_font.Ok() )
1149 enc = m_font.GetEncoding();
1150 else
1151 enc = wxLocale::GetSystemEncoding();
1152 wxCFStringRef cfTitle( title, enc );
1153 columnDesc.headerBtnDesc.titleString = cfTitle;
1154
1155 columnDesc.headerBtnDesc.minimumWidth = 0;
1156 columnDesc.headerBtnDesc.maximumWidth = 30000;
1157
1158 columnDesc.propertyDesc.propertyID = (kMinColumnId + colId);
1159 columnDesc.propertyDesc.propertyType = colType;
1160 columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn;
1161 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
1162 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
1163
1164 verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
1165
1166 if (defaultWidth > 0){
1167 SetColumnWidth(colId, defaultWidth);
1168 }
1169
1170}
1171
1172void wxMacDataItemBrowserControl::SetColumnWidth(int colId, int width)
1173{
1174 DataBrowserPropertyID id;
1175 GetColumnIDFromIndex(colId, &id);
1176 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id, width));
1177}
1178
1179int wxMacDataItemBrowserControl::GetColumnWidth(int colId)
1180{
1181 DataBrowserPropertyID id;
1182 GetColumnIDFromIndex(colId, &id);
1183 UInt16 result;
1184 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id, &result));
1185 return result;
1186}
1187
1188void wxMacDataItemBrowserControl::AddItem(wxMacDataItem *container, wxMacDataItem *item)
1189{
1190 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, 1,
1191 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ) );
1192}
1193
1194void wxMacDataItemBrowserControl::AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray )
1195{
1196 unsigned int noItems = itemArray.GetCount();
1197 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1198 for ( unsigned int i = 0; i < noItems; ++i )
1199 items[i] = (DataBrowserItemID) itemArray[i];
1200
1201 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, noItems,
1202 (DataBrowserItemID*) items, kDataBrowserItemNoProperty ) );
1203 delete [] items;
1204}
1205
1206void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem *container, wxMacDataItem* item)
1207{
1208 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 1,
1209 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty );
1210 verify_noerr( err );
1211}
1212
1213void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray)
1214{
1215 unsigned int noItems = itemArray.GetCount();
1216 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1217 for ( unsigned int i = 0; i < noItems; ++i )
1218 items[i] = (DataBrowserItemID) itemArray[i];
1219
1220 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, noItems,
1221 (DataBrowserItemID*) items, kDataBrowserItemNoProperty );
1222 verify_noerr( err );
1223 delete [] items;
1224}
1225
1226void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem *container)
1227{
1228 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 0 , NULL , kDataBrowserItemNoProperty );
1229 verify_noerr( err );
1230}
1231
1232void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem* item , DataBrowserSetOption option)
1233{
1234 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID*) &item, option ));
1235}
1236
1237void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option)
1238{
1239 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL , option ));
1240}
1241
1242void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr &itemArray , DataBrowserSetOption option)
1243{
1244 unsigned int noItems = itemArray.GetCount();
1245 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1246 for ( unsigned int i = 0; i < noItems; ++i )
1247 items[i] = (DataBrowserItemID) itemArray[i];
1248
1249 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems, (DataBrowserItemID*) items, option ));
1250 delete [] items;
1251}
1252
1253Boolean wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem* item) const
1254{
1255 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID) item);
1256}
1257
1258void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options)
1259{
1260 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID) item, kDataBrowserNoItem , options ) );
1261}
1262
1263void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const
1264{
1265 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID*) first, (DataBrowserItemID*) last) );
1266}
1267
1268wxClientDataType wxMacDataItemBrowserControl::GetClientDataType() const
1269{
1270 return m_clientDataItemsType;
1271}
1272void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType)
1273{
1274 m_clientDataItemsType = clientDataItemsType;
1275}
1276
1277unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1278{
1279 return GetItemCount(wxMacDataBrowserRootContainer,false,kDataBrowserItemAnyState);
1280}
1281
1282void wxMacDataItemBrowserControl::MacDelete( unsigned int n )
1283{
1284 wxMacDataItem* item = (wxMacDataItem*)GetItemFromLine( n );
1285 RemoveItem( wxMacDataBrowserRootContainer, item );
1286}
1287
1288void wxMacDataItemBrowserControl::MacInsert( unsigned int n,
1289 const wxArrayStringsAdapter& items,
1290 int column )
1291{
1292 size_t itemsCount = items.GetCount();
1293 if ( itemsCount == 0 )
1294 return;
1295
1296 SInt32 frontLineOrder = 0;
1297
1298 if ( m_sortOrder == SortOrder_None )
1299 {
1300 // increase the order of the lines to be shifted
1301 unsigned int lines = MacGetCount();
1302 for ( unsigned int i = n; i < lines; ++i)
1303 {
1304 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(i);
1305 iter->SetOrder( iter->GetOrder() + itemsCount );
1306 }
1307 if ( n > 0 )
1308 {
1309 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(n-1);
1310 frontLineOrder = iter->GetOrder();
1311 }
1312 }
1313
1314 wxArrayMacDataItemPtr ids;
1315 ids.SetCount( itemsCount );
1316
1317 for ( unsigned int i = 0; i < itemsCount; ++i )
1318 {
1319 wxMacDataItem* item = CreateItem();
1320 item->SetLabel( items[i]);
1321 if ( column != -1 )
1322 item->SetColumn( kMinColumnId + column );
1323
1324 if ( m_sortOrder == SortOrder_None )
1325 item->SetOrder( frontLineOrder + 1 + i );
1326
1327 ids[i] = item;
1328 }
1329
1330 AddItems( wxMacDataBrowserRootContainer, ids );
1331}
1332
1333int wxMacDataItemBrowserControl::MacAppend( const wxString& text)
1334{
1335 wxMacDataItem* item = CreateItem();
1336 item->SetLabel( text );
1337 if ( m_sortOrder == SortOrder_None )
1338 {
1339 unsigned int lines = MacGetCount();
1340 if ( lines == 0 )
1341 item->SetOrder( 1 );
1342 else
1343 {
1344 wxMacDataItem* frontItem = (wxMacDataItem*) GetItemFromLine(lines-1);
1345 item->SetOrder( frontItem->GetOrder() + 1 );
1346 }
1347 }
1348 AddItem( wxMacDataBrowserRootContainer, item );
1349
1350 return GetLineFromItem(item);
1351}
1352
1353void wxMacDataItemBrowserControl::MacClear()
1354{
1355 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
1356 RemoveAllItems(wxMacDataBrowserRootContainer);
1357}
1358
1359void wxMacDataItemBrowserControl::MacDeselectAll()
1360{
1361 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
1362 SetSelectedAllItems( kDataBrowserItemsRemove );
1363}
1364
1365void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n, bool select, bool multi )
1366{
1367 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n);
1368 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
1369
1370 if ( IsItemSelected( item ) != select )
1371 {
1372 if ( select )
1373 SetSelectedItem( item, multi ? kDataBrowserItemsAdd : kDataBrowserItemsAssign );
1374 else
1375 SetSelectedItem( item, kDataBrowserItemsRemove );
1376 }
1377
1378 MacScrollTo( n );
1379}
1380
1381bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n ) const
1382{
1383 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n);
1384 return IsItemSelected( item );
1385}
1386
1387int wxMacDataItemBrowserControl::MacGetSelection() const
1388{
1389 wxMacDataItemPtr first, last;
1390 GetSelectionAnchor( &first, &last );
1391
1392 if ( first != NULL )
1393 {
1394 return GetLineFromItem( first );
1395 }
1396
1397 return -1;
1398}
1399
1400int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt& aSelections ) const
1401{
1402 aSelections.Empty();
1403 wxArrayMacDataItemPtr selectedItems;
1404 GetItems( wxMacDataBrowserRootContainer, false , kDataBrowserItemIsSelected, selectedItems);
1405
1406 int count = selectedItems.GetCount();
1407
1408 for ( int i = 0; i < count; ++i)
1409 {
1410 aSelections.Add(GetLineFromItem(selectedItems[i]));
1411 }
1412
1413 return count;
1414}
1415
1416void wxMacDataItemBrowserControl::MacSetString( unsigned int n, const wxString& text )
1417{
1418 // as we don't store the strings we only have to issue a redraw
1419 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n);
1420 item->SetLabel( text );
1421 UpdateItem( wxMacDataBrowserRootContainer, item , kTextColumnId );
1422}
1423
1424wxString wxMacDataItemBrowserControl::MacGetString( unsigned int n ) const
1425{
1426 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
1427 return item->GetLabel();
1428}
1429
1430void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n, void * data)
1431{
1432 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n);
1433 item->SetData( data );
1434 // not displayed, therefore no Update infos to DataBrowser
1435}
1436
1437void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n) const
1438{
1439 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
1440 return item->GetData();
1441}
1442
1443void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n )
1444{
1445 UInt32 top , left ;
1446 GetScrollPosition( &top , &left ) ;
1447 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
1448
1449 // there is a bug in RevealItem that leads to situations
1450 // in large lists, where the item does not get scrolled
1451 // into sight, so we do a pre-scroll if necessary
1452 UInt16 height ;
1453 GetRowHeight( (DataBrowserItemID) item , &height ) ;
1454 UInt32 linetop = n * ((UInt32) height );
1455 UInt32 linebottom = linetop + height;
1456 Rect rect ;
b2680ced 1457 GetControlBounds( m_controlRef, &rect );
489468fe
SC
1458
1459 if ( linetop < top || linebottom > (top + rect.bottom - rect.top ) )
1460 SetScrollPosition( wxMax( n-2, 0 ) * ((UInt32)height) , left ) ;
1461
1462 RevealItem( item , kDataBrowserRevealWithoutSelecting );
1463}
1464
489468fe
SC
1465#endif // wxUSE_GUI
1466
b2680ced 1467#endif // wxOSX_USE_CARBON