1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/carbon/checklst.cpp 
   3 // Purpose:     implementation of wxCheckListBox class 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 // new DataBrowser-based version 
  15 #include "wx/wxprec.h" 
  17 #if wxUSE_CHECKLISTBOX 
  19 #include "wx/checklst.h" 
  22     #include "wx/arrstr.h" 
  25 #include "wx/mac/uma.h" 
  28 #include <Appearance.h> 
  31 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox
, wxListBox
) 
  33 BEGIN_EVENT_TABLE(wxCheckListBox
, wxListBox
) 
  36 class wxMacDataBrowserCheckListControl 
: public wxMacDataBrowserListControl 
, public wxMacCheckListControl
 
  39     wxMacDataBrowserCheckListControl( wxListBox 
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style 
); 
  40     wxMacDataBrowserCheckListControl() {} 
  41     virtual ~wxMacDataBrowserCheckListControl(); 
  43     virtual wxMacDataItem
* CreateItem(); 
  45     virtual bool            MacIsChecked(unsigned int n
) const; 
  46     virtual void            MacCheck(unsigned int n
, bool bCheck 
= true); 
  47     DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserCheckListControl
) 
  50 IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserCheckListControl 
, wxMacDataBrowserListControl 
) 
  52 void wxCheckListBox::Init() 
  56 bool wxCheckListBox::Create( 
  61     const wxArrayString
& choices
, 
  63     const wxValidator
& validator
, 
  64     const wxString 
&name 
) 
  66     wxCArrayString 
chs( choices 
); 
  68     return Create( parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(), style
, validator
, name 
); 
  71 bool wxCheckListBox::Create( 
  77    const wxString choices
[], 
  79    const wxValidator
& validator
, 
  80    const wxString
& name 
) 
  82     m_macIsUserPane 
= false; 
  84     wxASSERT_MSG( !(style 
& wxLB_MULTIPLE
) || !(style 
& wxLB_EXTENDED
), 
  85                   wxT("only one of listbox selection modes can be specified") ); 
  87     if ( !wxListBoxBase::Create( parent
, id
, pos
, size
, style 
& ~(wxHSCROLL 
| wxVSCROLL
), validator
, name 
) ) 
  90     // this will be increased by our Append command 
  91     wxMacDataBrowserCheckListControl
* control 
= new wxMacDataBrowserCheckListControl( this, pos
, size
, style 
); 
  92     control
->SetClientDataType( m_clientDataItemsType 
); 
  95     MacPostControlCreate(pos
,size
); 
  97     InsertItems( n 
, choices 
, 0 ); 
  99     // Needed because it is a wxControlWithItems 
 100     SetInitialSize( size 
); 
 105 // ---------------------------------------------------------------------------- 
 106 // wxCheckListBox functions 
 107 // ---------------------------------------------------------------------------- 
 109 bool wxCheckListBox::IsChecked(unsigned int item
) const 
 111     wxCHECK_MSG( IsValid(item
), false, 
 112                  wxT("invalid index in wxCheckListBox::IsChecked") ); 
 114     return GetPeer()->MacIsChecked( item 
); 
 117 void wxCheckListBox::Check(unsigned int item
, bool check
) 
 119     wxCHECK_RET( IsValid(item
), 
 120                  wxT("invalid index in wxCheckListBox::Check") ); 
 122     bool isChecked 
= GetPeer()->MacIsChecked( item 
); 
 123     if ( check 
!= isChecked 
) 
 125         GetPeer()->MacCheck( item 
, check 
); 
 129 wxMacCheckListControl
* wxCheckListBox::GetPeer() const 
 131     wxMacDataBrowserCheckListControl 
*lb 
= wxDynamicCast(m_peer
,wxMacDataBrowserCheckListControl
); 
 132     return lb 
? wx_static_cast(wxMacCheckListControl
*,lb
) : 0 ; 
 135 const short kCheckboxColumnId 
= 1026; 
 137 wxMacDataBrowserCheckListControl::wxMacDataBrowserCheckListControl( wxListBox 
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) 
 138     : wxMacDataBrowserListControl( peer
, pos
, size
, style 
) 
 140     OSStatus err 
= noErr
; 
 142     DataBrowserListViewColumnDesc columnDesc
; 
 143     columnDesc
.headerBtnDesc
.titleOffset 
= 0; 
 144     columnDesc
.headerBtnDesc
.version 
= kDataBrowserListViewLatestHeaderDesc
; 
 146     columnDesc
.headerBtnDesc
.btnFontStyle
.flags 
= 
 147         kControlUseFontMask 
| kControlUseJustMask
; 
 149     columnDesc
.headerBtnDesc
.btnContentInfo
.contentType 
= kControlNoContent
; 
 150     columnDesc
.headerBtnDesc
.btnFontStyle
.just 
= teFlushDefault
; 
 151     columnDesc
.headerBtnDesc
.btnFontStyle
.font 
= kControlFontViewSystemFont
; 
 152     columnDesc
.headerBtnDesc
.btnFontStyle
.style 
= normal
; 
 153     columnDesc
.headerBtnDesc
.titleString 
= NULL
; 
 155     columnDesc
.headerBtnDesc
.minimumWidth 
= 30; 
 156     columnDesc
.headerBtnDesc
.maximumWidth 
= 30; 
 158     columnDesc
.propertyDesc
.propertyID 
= kCheckboxColumnId
; 
 159     columnDesc
.propertyDesc
.propertyType 
= kDataBrowserCheckboxType
; 
 160     columnDesc
.propertyDesc
.propertyFlags 
= 
 161         kDataBrowserPropertyIsMutable
 
 162         | kDataBrowserTableViewSelectionColumn
 
 163         | kDataBrowserDefaultPropertyFlags
; 
 165     err 
= AddColumn( &columnDesc
, 0 ); 
 169 wxMacDataBrowserCheckListControl::~wxMacDataBrowserCheckListControl() 
 174 class wxMacCheckListBoxItem 
: public wxMacListBoxItem
 
 177     wxMacCheckListBoxItem() 
 182     virtual ~wxMacCheckListBoxItem() 
 186     virtual OSStatus 
GetSetData( wxMacDataItemBrowserControl 
*owner 
, 
 187         DataBrowserPropertyID property
, 
 188         DataBrowserItemDataRef itemData
, 
 191         OSStatus err 
= errDataBrowserPropertyNotSupported
; 
 193         wxCheckListBox 
*checklist 
= wxDynamicCast( owner
->GetPeer() , wxCheckListBox 
); 
 194         wxCHECK_MSG( checklist 
!= NULL 
, errDataBrowserPropertyNotSupported 
, wxT("wxCheckListBox expected")); 
 200                 case kCheckboxColumnId
: 
 201                     verify_noerr(SetDataBrowserItemDataButtonValue( itemData
, m_isChecked 
? kThemeButtonOn 
: kThemeButtonOff 
)); 
 205                 case kDataBrowserItemIsEditableProperty
: 
 206                     verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true )); 
 218             case kCheckboxColumnId
: 
 220                     // we have to change this behind the back, since Check() would be triggering another update round 
 221                     bool newVal 
= !m_isChecked
; 
 222                     verify_noerr(SetDataBrowserItemDataButtonValue( itemData
, newVal 
? kThemeButtonOn 
: kThemeButtonOff 
)); 
 223                     m_isChecked 
= newVal
; 
 226                     wxCommandEvent 
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, checklist
->GetId() ); 
 227                     event
.SetInt( owner
->GetLineFromItem( this ) ); 
 228                     event
.SetEventObject( checklist 
); 
 229                     checklist
->GetEventHandler()->ProcessEvent( event 
); 
 238         if ( err 
== errDataBrowserPropertyNotSupported 
) 
 239             err 
= wxMacListBoxItem::GetSetData( owner 
, property
, itemData 
, changeValue
); 
 244     void Check( bool check 
) 
 248     bool IsChecked() const 
 257 wxMacDataItem
* wxMacDataBrowserCheckListControl::CreateItem() 
 259     return new wxMacCheckListBoxItem(); 
 262 void wxMacDataBrowserCheckListControl::MacCheck( unsigned int n
, bool bCheck
) 
 264     wxMacCheckListBoxItem
* item 
= wx_static_cast(wxMacCheckListBoxItem
*, GetItemFromLine( n
) ); 
 265     item
->Check( bCheck
); 
 266     UpdateItem(wxMacDataBrowserRootContainer
, item 
, kCheckboxColumnId
); 
 269 bool wxMacDataBrowserCheckListControl::MacIsChecked( unsigned int n
) const 
 271     wxMacCheckListBoxItem 
* item 
= wx_static_cast( wxMacCheckListBoxItem
*, GetItemFromLine( n 
) ); 
 272     return item
->IsChecked(); 
 277 #endif // wxUSE_CHECKLISTBOX