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"
20 #include "wx/arrstr.h"
22 #include "wx/mac/uma.h"
25 #include <Appearance.h>
28 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox
, wxListBox
)
30 BEGIN_EVENT_TABLE(wxCheckListBox
, wxListBox
)
33 class wxMacDataBrowserCheckListControl
: public wxMacDataBrowserListControl
, public wxMacCheckListControl
36 wxMacDataBrowserCheckListControl( wxListBox
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
37 ~wxMacDataBrowserCheckListControl();
39 virtual wxMacListBoxItem
* CreateItem();
41 virtual bool MacIsChecked(unsigned int n
) const;
42 virtual void MacCheck(unsigned int n
, bool bCheck
= true);
45 void wxCheckListBox::Init()
49 bool wxCheckListBox::Create(
54 const wxArrayString
& choices
,
56 const wxValidator
& validator
,
57 const wxString
&name
)
59 wxCArrayString
chs( choices
);
61 return Create( parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(), style
, validator
, name
);
64 bool wxCheckListBox::Create(
70 const wxString choices
[],
72 const wxValidator
& validator
,
73 const wxString
& name
)
75 m_macIsUserPane
= false;
77 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
78 wxT("only one of listbox selection modes can be specified") );
80 if ( !wxListBoxBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
83 // this will be increased by our Append command
84 wxMacDataBrowserCheckListControl
* control
= new wxMacDataBrowserCheckListControl( this, pos
, size
, style
);
85 control
->SetClientDataType( m_clientDataItemsType
);
88 MacPostControlCreate(pos
,size
);
90 InsertItems( n
, choices
, 0 );
92 // Needed because it is a wxControlWithItems
98 // ----------------------------------------------------------------------------
99 // wxCheckListBox functions
100 // ----------------------------------------------------------------------------
102 bool wxCheckListBox::IsChecked(unsigned int item
) const
104 wxCHECK_MSG( IsValid(item
), false,
105 wxT("invalid index in wxCheckListBox::IsChecked") );
107 return GetPeer()->MacIsChecked( item
);
110 void wxCheckListBox::Check(unsigned int item
, bool check
)
112 wxCHECK_RET( IsValid(item
),
113 wxT("invalid index in wxCheckListBox::Check") );
115 bool isChecked
= GetPeer()->MacIsChecked( item
);
116 if ( check
!= isChecked
)
118 GetPeer()->MacCheck( item
, check
);
122 wxMacCheckListControl
* wxCheckListBox::GetPeer() const
124 return dynamic_cast<wxMacCheckListControl
*>(m_peer
);
127 const short kCheckboxColumnId
= 1026;
129 wxMacDataBrowserCheckListControl::wxMacDataBrowserCheckListControl( wxListBox
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
130 : wxMacDataBrowserListControl( peer
, pos
, size
, style
)
132 OSStatus err
= noErr
;
134 DataBrowserListViewColumnDesc columnDesc
;
135 columnDesc
.headerBtnDesc
.titleOffset
= 0;
136 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
138 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
139 kControlUseFontMask
| kControlUseJustMask
;
141 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlNoContent
;
142 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
143 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
144 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
145 columnDesc
.headerBtnDesc
.titleString
= NULL
;
147 columnDesc
.headerBtnDesc
.minimumWidth
= 30;
148 columnDesc
.headerBtnDesc
.maximumWidth
= 30;
150 columnDesc
.propertyDesc
.propertyID
= kCheckboxColumnId
;
151 columnDesc
.propertyDesc
.propertyType
= kDataBrowserCheckboxType
;
152 columnDesc
.propertyDesc
.propertyFlags
=
153 kDataBrowserPropertyIsMutable
154 | kDataBrowserTableViewSelectionColumn
155 | kDataBrowserDefaultPropertyFlags
;
157 err
= AddColumn( &columnDesc
, 0 );
161 wxMacDataBrowserCheckListControl::~wxMacDataBrowserCheckListControl()
166 class wxMacCheckListBoxItem
: public wxMacListBoxItem
169 wxMacCheckListBoxItem()
174 ~wxMacCheckListBoxItem()
178 virtual OSStatus
GetSetData( wxMacDataItemBrowserControl
*owner
,
179 DataBrowserPropertyID property
,
180 DataBrowserItemDataRef itemData
,
183 OSStatus err
= errDataBrowserPropertyNotSupported
;
185 wxCheckListBox
*checklist
= wxDynamicCast( owner
->GetPeer() , wxCheckListBox
);
186 wxCHECK_MSG( checklist
!= NULL
, errDataBrowserPropertyNotSupported
, wxT("wxCheckListBox expected"));
192 case kCheckboxColumnId
:
193 verify_noerr(SetDataBrowserItemDataButtonValue( itemData
, m_isChecked
? kThemeButtonOn
: kThemeButtonOff
));
197 case kDataBrowserItemIsEditableProperty
:
198 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
210 case kCheckboxColumnId
:
212 // we have to change this behind the back, since Check() would be triggering another update round
213 bool newVal
= !m_isChecked
;
214 verify_noerr(SetDataBrowserItemDataButtonValue( itemData
, newVal
? kThemeButtonOn
: kThemeButtonOff
));
215 m_isChecked
= newVal
;
218 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, checklist
->GetId() );
219 event
.SetInt( owner
->GetLineFromItem( this ) );
220 event
.SetEventObject( checklist
);
221 checklist
->GetEventHandler()->ProcessEvent( event
);
230 if ( err
== errDataBrowserPropertyNotSupported
)
231 err
= wxMacListBoxItem::GetSetData( owner
, property
, itemData
, changeValue
);
236 void Check( bool check
)
240 bool IsChecked() const
249 wxMacListBoxItem
* wxMacDataBrowserCheckListControl::CreateItem()
251 return new wxMacCheckListBoxItem();
254 void wxMacDataBrowserCheckListControl::MacCheck( unsigned int n
, bool bCheck
)
256 wxMacCheckListBoxItem
* item
= dynamic_cast<wxMacCheckListBoxItem
*>( GetItemFromLine( n
) );
257 item
->Check( bCheck
);
258 UpdateItem(wxMacDataBrowserRootContainer
, item
, kCheckboxColumnId
);
261 bool wxMacDataBrowserCheckListControl::MacIsChecked( unsigned int n
) const
263 wxMacCheckListBoxItem
* item
= dynamic_cast<wxMacCheckListBoxItem
*>( GetItemFromLine( n
) );
264 return item
->IsChecked();
269 #endif // wxUSE_CHECKLISTBOX