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 virtual ~wxMacDataBrowserCheckListControl();
42 virtual wxMacDataItem
* CreateItem();
44 virtual bool MacIsChecked(unsigned int n
) const;
45 virtual void MacCheck(unsigned int n
, bool bCheck
= true);
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 control
->SetClientDataType( m_clientDataItemsType
);
91 MacPostControlCreate(pos
,size
);
93 InsertItems( n
, choices
, 0 );
95 // Needed because it is a wxControlWithItems
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 return dynamic_cast<wxMacCheckListControl
*>(m_peer
);
130 const short kCheckboxColumnId
= 1026;
132 wxMacDataBrowserCheckListControl::wxMacDataBrowserCheckListControl( wxListBox
*peer
, const wxPoint
& pos
, const wxSize
& size
, long style
)
133 : wxMacDataBrowserListControl( peer
, pos
, size
, style
)
135 OSStatus err
= noErr
;
137 DataBrowserListViewColumnDesc columnDesc
;
138 columnDesc
.headerBtnDesc
.titleOffset
= 0;
139 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
141 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
142 kControlUseFontMask
| kControlUseJustMask
;
144 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlNoContent
;
145 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= teFlushDefault
;
146 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
147 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
148 columnDesc
.headerBtnDesc
.titleString
= NULL
;
150 columnDesc
.headerBtnDesc
.minimumWidth
= 30;
151 columnDesc
.headerBtnDesc
.maximumWidth
= 30;
153 columnDesc
.propertyDesc
.propertyID
= kCheckboxColumnId
;
154 columnDesc
.propertyDesc
.propertyType
= kDataBrowserCheckboxType
;
155 columnDesc
.propertyDesc
.propertyFlags
=
156 kDataBrowserPropertyIsMutable
157 | kDataBrowserTableViewSelectionColumn
158 | kDataBrowserDefaultPropertyFlags
;
160 err
= AddColumn( &columnDesc
, 0 );
164 wxMacDataBrowserCheckListControl::~wxMacDataBrowserCheckListControl()
169 class wxMacCheckListBoxItem
: public wxMacListBoxItem
172 wxMacCheckListBoxItem()
177 virtual ~wxMacCheckListBoxItem()
181 virtual OSStatus
GetSetData( wxMacDataItemBrowserControl
*owner
,
182 DataBrowserPropertyID property
,
183 DataBrowserItemDataRef itemData
,
186 OSStatus err
= errDataBrowserPropertyNotSupported
;
188 wxCheckListBox
*checklist
= wxDynamicCast( owner
->GetPeer() , wxCheckListBox
);
189 wxCHECK_MSG( checklist
!= NULL
, errDataBrowserPropertyNotSupported
, wxT("wxCheckListBox expected"));
195 case kCheckboxColumnId
:
196 verify_noerr(SetDataBrowserItemDataButtonValue( itemData
, m_isChecked
? kThemeButtonOn
: kThemeButtonOff
));
200 case kDataBrowserItemIsEditableProperty
:
201 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData
, true ));
213 case kCheckboxColumnId
:
215 // we have to change this behind the back, since Check() would be triggering another update round
216 bool newVal
= !m_isChecked
;
217 verify_noerr(SetDataBrowserItemDataButtonValue( itemData
, newVal
? kThemeButtonOn
: kThemeButtonOff
));
218 m_isChecked
= newVal
;
221 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, checklist
->GetId() );
222 event
.SetInt( owner
->GetLineFromItem( this ) );
223 event
.SetEventObject( checklist
);
224 checklist
->GetEventHandler()->ProcessEvent( event
);
233 if ( err
== errDataBrowserPropertyNotSupported
)
234 err
= wxMacListBoxItem::GetSetData( owner
, property
, itemData
, changeValue
);
239 void Check( bool check
)
243 bool IsChecked() const
252 wxMacDataItem
* wxMacDataBrowserCheckListControl::CreateItem()
254 return new wxMacCheckListBoxItem();
257 void wxMacDataBrowserCheckListControl::MacCheck( unsigned int n
, bool bCheck
)
259 wxMacCheckListBoxItem
* item
= dynamic_cast<wxMacCheckListBoxItem
*>( GetItemFromLine( n
) );
260 item
->Check( bCheck
);
261 UpdateItem(wxMacDataBrowserRootContainer
, item
, kCheckboxColumnId
);
264 bool wxMacDataBrowserCheckListControl::MacIsChecked( unsigned int n
) const
266 wxMacCheckListBoxItem
* item
= dynamic_cast<wxMacCheckListBoxItem
*>( GetItemFromLine( n
) );
267 return item
->IsChecked();
272 #endif // wxUSE_CHECKLISTBOX