]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/checklst.cpp
cleanup
[wxWidgets.git] / src / mac / carbon / checklst.cpp
CommitLineData
e9576ca5 1///////////////////////////////////////////////////////////////////////////////
c18353e5 2// Name: src/mac/carbon/checklst.cpp
e9576ca5 3// Purpose: implementation of wxCheckListBox class
a31a5f85 4// Author: Stefan Csomor
3dee36ae 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5 10///////////////////////////////////////////////////////////////////////////////
c18353e5
DS
11//
12// new DataBrowser-based version
e9576ca5 13
e9576ca5 14
a8e9860d 15#include "wx/wxprec.h"
e9576ca5 16
55d60746
GD
17#if wxUSE_CHECKLISTBOX
18
b698c8e9 19#include "wx/checklst.h"
aaa6d89a
WS
20
21#ifndef WX_PRECOMP
22 #include "wx/arrstr.h"
23#endif
b698c8e9 24
dbfc5b97 25#include "wx/mac/uma.h"
c18353e5 26
dbfc5b97
SC
27IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
28
d058c153
SC
29BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
30END_EVENT_TABLE()
dbfc5b97 31
6cce68ea
SC
32class wxMacDataBrowserCheckListControl : public wxMacDataBrowserListControl , public wxMacCheckListControl
33{
34public:
35 wxMacDataBrowserCheckListControl( wxListBox *peer, const wxPoint& pos, const wxSize& size, long style );
bf9a1615 36 wxMacDataBrowserCheckListControl() {}
d3c7fc99 37 virtual ~wxMacDataBrowserCheckListControl();
6cce68ea 38
9ce05df4 39 virtual wxMacDataItem* CreateItem();
aaa6d89a 40
6cce68ea
SC
41 virtual bool MacIsChecked(unsigned int n) const;
42 virtual void MacCheck(unsigned int n, bool bCheck = true);
bf9a1615 43 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserCheckListControl)
6cce68ea
SC
44};
45
bf9a1615
SC
46IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserCheckListControl , wxMacDataBrowserListControl )
47
dbfc5b97
SC
48void wxCheckListBox::Init()
49{
50}
51
c18353e5
DS
52bool wxCheckListBox::Create(
53 wxWindow *parent,
54 wxWindowID id,
55 const wxPoint &pos,
56 const wxSize &size,
57 const wxArrayString& choices,
58 long style,
59 const wxValidator& validator,
60 const wxString &name )
584ad2a3 61{
c18353e5 62 wxCArrayString chs( choices );
584ad2a3 63
c18353e5 64 return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name );
584ad2a3
MB
65}
66
c18353e5
DS
67bool wxCheckListBox::Create(
68 wxWindow *parent,
69 wxWindowID id,
70 const wxPoint& pos,
71 const wxSize& size,
72 int n,
73 const wxString choices[],
74 long style,
75 const wxValidator& validator,
76 const wxString& name )
dbfc5b97 77{
c18353e5 78 m_macIsUserPane = false;
d058c153
SC
79
80 wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
c18353e5 81 wxT("only one of listbox selection modes can be specified") );
3dee36ae 82
c18353e5 83 if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
b45ed7a2
VZ
84 return false;
85
c18353e5 86 // this will be increased by our Append command
6cce68ea 87 wxMacDataBrowserCheckListControl* control = new wxMacDataBrowserCheckListControl( this, pos, size, style );
6239ee05 88 // TODO CHECK control->SetClientDataType( m_clientDataItemsType );
6cce68ea 89 m_peer = control;
dbfc5b97 90
b4726a58 91 MacPostControlCreate(pos,size);
3dee36ae 92
aaa6d89a 93 InsertItems( n , choices , 0 );
dbfc5b97 94
c18353e5 95 // Needed because it is a wxControlWithItems
170acdc9 96 SetInitialSize( size );
3dee36ae
WS
97
98 return true;
dbfc5b97 99}
e9576ca5
SC
100
101// ----------------------------------------------------------------------------
dbfc5b97 102// wxCheckListBox functions
e9576ca5
SC
103// ----------------------------------------------------------------------------
104
aa61d352 105bool wxCheckListBox::IsChecked(unsigned int item) const
dbfc5b97 106{
aa61d352 107 wxCHECK_MSG( IsValid(item), false,
c18353e5 108 wxT("invalid index in wxCheckListBox::IsChecked") );
dbfc5b97 109
6cce68ea 110 return GetPeer()->MacIsChecked( item );
dbfc5b97
SC
111}
112
aa61d352 113void wxCheckListBox::Check(unsigned int item, bool check)
dbfc5b97 114{
aa61d352 115 wxCHECK_RET( IsValid(item),
c18353e5 116 wxT("invalid index in wxCheckListBox::Check") );
dbfc5b97 117
6cce68ea 118 bool isChecked = GetPeer()->MacIsChecked( item );
dbfc5b97
SC
119 if ( check != isChecked )
120 {
6cce68ea 121 GetPeer()->MacCheck( item , check );
dbfc5b97
SC
122 }
123}
124
aaa6d89a
WS
125wxMacCheckListControl* wxCheckListBox::GetPeer() const
126{
bf9a1615
SC
127 wxMacDataBrowserCheckListControl *lb = wxDynamicCast(m_peer,wxMacDataBrowserCheckListControl);
128 return lb ? wx_static_cast(wxMacCheckListControl*,lb) : 0 ;
6cce68ea 129}
dbfc5b97 130
6cce68ea 131const short kCheckboxColumnId = 1026;
e9576ca5 132
6cce68ea
SC
133wxMacDataBrowserCheckListControl::wxMacDataBrowserCheckListControl( wxListBox *peer, const wxPoint& pos, const wxSize& size, long style)
134 : wxMacDataBrowserListControl( peer, pos, size, style )
135{
136 OSStatus err = noErr;
137
138 DataBrowserListViewColumnDesc columnDesc;
139 columnDesc.headerBtnDesc.titleOffset = 0;
140 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
141
142 columnDesc.headerBtnDesc.btnFontStyle.flags =
143 kControlUseFontMask | kControlUseJustMask;
144
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;
150
151 columnDesc.headerBtnDesc.minimumWidth = 30;
152 columnDesc.headerBtnDesc.maximumWidth = 30;
153
154 columnDesc.propertyDesc.propertyID = kCheckboxColumnId;
155 columnDesc.propertyDesc.propertyType = kDataBrowserCheckboxType;
156 columnDesc.propertyDesc.propertyFlags =
157 kDataBrowserPropertyIsMutable
158 | kDataBrowserTableViewSelectionColumn
159 | kDataBrowserDefaultPropertyFlags;
aaa6d89a 160
6cce68ea
SC
161 err = AddColumn( &columnDesc, 0 );
162 verify_noerr( err );
dbfc5b97
SC
163}
164
6cce68ea 165wxMacDataBrowserCheckListControl::~wxMacDataBrowserCheckListControl()
e9576ca5 166{
aaa6d89a 167
e9576ca5
SC
168}
169
6cce68ea 170class wxMacCheckListBoxItem : public wxMacListBoxItem
e9576ca5 171{
6cce68ea
SC
172public :
173 wxMacCheckListBoxItem()
174 {
175 m_isChecked = false;
176 }
aaa6d89a 177
d3c7fc99 178 virtual ~wxMacCheckListBoxItem()
6cce68ea
SC
179 {
180 }
aaa6d89a 181
6cce68ea
SC
182 virtual OSStatus GetSetData( wxMacDataItemBrowserControl *owner ,
183 DataBrowserPropertyID property,
184 DataBrowserItemDataRef itemData,
aaa6d89a 185 bool changeValue )
6cce68ea
SC
186 {
187 OSStatus err = errDataBrowserPropertyNotSupported;
188
189 wxCheckListBox *checklist = wxDynamicCast( owner->GetPeer() , wxCheckListBox );
190 wxCHECK_MSG( checklist != NULL , errDataBrowserPropertyNotSupported , wxT("wxCheckListBox expected"));
191
192 if ( !changeValue )
193 {
194 switch (property)
195 {
196 case kCheckboxColumnId:
197 verify_noerr(SetDataBrowserItemDataButtonValue( itemData, m_isChecked ? kThemeButtonOn : kThemeButtonOff ));
198 err = noErr;
199 break;
200
201 case kDataBrowserItemIsEditableProperty:
202 verify_noerr(SetDataBrowserItemDataBooleanValue( itemData, true ));
203 err = noErr;
204 break;
205
206 default:
207 break;
208 }
209 }
210 else
211 {
212 switch (property)
213 {
214 case kCheckboxColumnId:
215 {
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;
220 err = noErr;
221
222 wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, checklist->GetId() );
223 event.SetInt( owner->GetLineFromItem( this ) );
224 event.SetEventObject( checklist );
aaa6d89a 225 checklist->GetEventHandler()->ProcessEvent( event );
6cce68ea
SC
226 }
227 break;
228
229 default:
230 break;
231 }
232 }
233
234 if ( err == errDataBrowserPropertyNotSupported )
235 err = wxMacListBoxItem::GetSetData( owner , property, itemData , changeValue);
236
237 return err;
238 }
dbfc5b97 239
aaa6d89a 240 void Check( bool check )
dbfc5b97 241 {
6cce68ea 242 m_isChecked = check;
dbfc5b97 243 }
aaa6d89a 244 bool IsChecked() const
6cce68ea 245 {
aaa6d89a 246 return m_isChecked;
6cce68ea
SC
247 }
248
249protected :
250 bool m_isChecked;
251};
e9576ca5 252
9ce05df4 253wxMacDataItem* wxMacDataBrowserCheckListControl::CreateItem()
dbfc5b97 254{
6cce68ea
SC
255 return new wxMacCheckListBoxItem();
256}
dbfc5b97 257
aaa6d89a 258void wxMacDataBrowserCheckListControl::MacCheck( unsigned int n, bool bCheck)
6cce68ea 259{
bf9a1615 260 wxMacCheckListBoxItem* item = wx_static_cast(wxMacCheckListBoxItem*, GetItemFromLine( n) );
6cce68ea
SC
261 item->Check( bCheck);
262 UpdateItem(wxMacDataBrowserRootContainer, item , kCheckboxColumnId);
dbfc5b97 263}
e9576ca5 264
aaa6d89a 265bool wxMacDataBrowserCheckListControl::MacIsChecked( unsigned int n) const
e9576ca5 266{
bf9a1615 267 wxMacCheckListBoxItem * item = wx_static_cast( wxMacCheckListBoxItem*, GetItemFromLine( n ) );
aaa6d89a 268 return item->IsChecked();
e9576ca5
SC
269}
270
6cce68ea
SC
271
272
dbfc5b97 273#endif // wxUSE_CHECKLISTBOX