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"
27 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox
, wxListBox
)
29 BEGIN_EVENT_TABLE(wxCheckListBox
, wxListBox
)
32 class wxMacDataBrowserCheckListControl
: public wxMacDataBrowserListControl
, public wxMacCheckListControl
35 wxMacDataBrowserCheckListControl( wxListBox
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
);
36 wxMacDataBrowserCheckListControl() {}
37 virtual ~wxMacDataBrowserCheckListControl();
39 virtual wxMacDataItem
* CreateItem();
41 virtual bool MacIsChecked(unsigned int n
) const;
42 virtual void MacCheck(unsigned int n
, bool bCheck
= true);
43 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserCheckListControl
)
46 IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserCheckListControl
, wxMacDataBrowserListControl
)
48 void wxCheckListBox::Init()
52 bool wxCheckListBox::Create(
57 const wxArrayString
& choices
,
59 const wxValidator
& validator
,
60 const wxString
&name
)
62 wxCArrayString
chs( choices
);
64 return Create( parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(), style
, validator
, name
);
67 bool wxCheckListBox::Create(
73 const wxString choices
[],
75 const wxValidator
& validator
,
76 const wxString
& name
)
78 m_macIsUserPane
= false;
80 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
81 wxT("only one of listbox selection modes can be specified") );
83 if ( !wxListBoxBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
86 // this will be increased by our Append command
87 wxMacDataBrowserCheckListControl
* control
= new wxMacDataBrowserCheckListControl( this, pos
, size
, style
);
88 // TODO CHECK control->SetClientDataType( m_clientDataItemsType );
91 MacPostControlCreate(pos
,size
);
93 InsertItems( n
, choices
, 0 );
95 // Needed because it is a wxControlWithItems
96 SetInitialSize( size
);
101 // ----------------------------------------------------------------------------
102 // wxCheckListBox functions
103 // ----------------------------------------------------------------------------
105 bool wxCheckListBox::IsChecked(unsigned int item
) const
107 wxCHECK_MSG( IsValid(item
), false,
108 wxT("invalid index in wxCheckListBox::IsChecked") );
110 return GetPeer()->MacIsChecked( item
);
113 void wxCheckListBox::Check(unsigned int item
, bool check
)
115 wxCHECK_RET( IsValid(item
),
116 wxT("invalid index in wxCheckListBox::Check") );
118 bool isChecked
= GetPeer()->MacIsChecked( item
);
119 if ( check
!= isChecked
)
121 GetPeer()->MacCheck( item
, check
);
125 wxMacCheckListControl
* wxCheckListBox::GetPeer() const
127 wxMacDataBrowserCheckListControl
*lb
= wxDynamicCast(m_peer
,wxMacDataBrowserCheckListControl
);
128 return lb
? wx_static_cast(wxMacCheckListControl
*,lb
) : 0 ;
131 const short kCheckboxColumnId
= 1026;
133 wxMacDataBrowserCheckListControl::wxMacDataBrowserCheckListControl( wxListBox
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
134 : wxMacDataBrowserListControl( peer
, pos
, size
, style
)
136 OSStatus err
= noErr
;
138 DataBrowserListViewColumnDesc columnDesc
;
139 columnDesc
.headerBtnDesc
.titleOffset
= 0;
140 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
142 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
143 kControlUseFontMask
| kControlUseJustMask
;
145 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlNoContent
;
146 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
147 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
148 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
149 columnDesc
.headerBtnDesc
.titleString
= NULL
;
151 columnDesc
.headerBtnDesc
.minimumWidth
= 30;
152 columnDesc
.headerBtnDesc
.maximumWidth
= 30;
154 columnDesc
.propertyDesc
.propertyID
= kCheckboxColumnId
;
155 columnDesc
.propertyDesc
.propertyType
= kDataBrowserCheckboxType
;
156 columnDesc
.propertyDesc
.propertyFlags
=
157 kDataBrowserPropertyIsMutable
158 | kDataBrowserTableViewSelectionColumn
159 | kDataBrowserDefaultPropertyFlags
;
161 err
= AddColumn( &columnDesc
, 0 );
165 wxMacDataBrowserCheckListControl::~wxMacDataBrowserCheckListControl()
170 class wxMacCheckListBoxItem
: public wxMacListBoxItem
173 wxMacCheckListBoxItem()
178 virtual ~wxMacCheckListBoxItem()
182 virtual OSStatus
GetSetData( wxMacDataItemBrowserControl
*owner
,
183 DataBrowserPropertyID property
,
184 DataBrowserItemDataRef itemData
,
187 OSStatus err
= errDataBrowserPropertyNotSupported
;
189 wxCheckListBox
*checklist
= wxDynamicCast( owner
->GetPeer() , wxCheckListBox
);
190 wxCHECK_MSG( checklist
!= NULL
, errDataBrowserPropertyNotSupported
, wxT("wxCheckListBox expected"));
196 case kCheckboxColumnId
:
197 verify_noerr(SetDataBrowserItemDataButtonValue( itemData
, m_isChecked
? kThemeButtonOn
: kThemeButtonOff
));
201 case kDataBrowserItemIsEditableProperty
:
202 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
214 case kCheckboxColumnId
:
216 // we have to change this behind the back, since Check() would be triggering another update round
217 bool newVal
= !m_isChecked
;
218 verify_noerr(SetDataBrowserItemDataButtonValue( itemData
, newVal
? kThemeButtonOn
: kThemeButtonOff
));
219 m_isChecked
= newVal
;
222 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, checklist
->GetId() );
223 event
.SetInt( owner
->GetLineFromItem( this ) );
224 event
.SetEventObject( checklist
);
225 checklist
->HandleWindowEvent( event
);
234 if ( err
== errDataBrowserPropertyNotSupported
)
235 err
= wxMacListBoxItem::GetSetData( owner
, property
, itemData
, changeValue
);
240 void Check( bool check
)
244 bool IsChecked() const
253 wxMacDataItem
* wxMacDataBrowserCheckListControl::CreateItem()
255 return new wxMacCheckListBoxItem();
258 void wxMacDataBrowserCheckListControl::MacCheck( unsigned int n
, bool bCheck
)
260 wxMacCheckListBoxItem
* item
= wx_static_cast(wxMacCheckListBoxItem
*, GetItemFromLine( n
) );
261 item
->Check( bCheck
);
262 UpdateItem(wxMacDataBrowserRootContainer
, item
, kCheckboxColumnId
);
265 bool wxMacDataBrowserCheckListControl::MacIsChecked( unsigned int n
) const
267 wxMacCheckListBoxItem
* item
= wx_static_cast( wxMacCheckListBoxItem
*, GetItemFromLine( n
) );
268 return item
->IsChecked();
273 #endif // wxUSE_CHECKLISTBOX