]> git.saurik.com Git - wxWidgets.git/blob - src/osx/carbon/checklst.cpp
fixing an incorrect conversion path from utf8 to plain ascii instead of unicode,...
[wxWidgets.git] / src / osx / carbon / checklst.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/checklst.cpp
3 // Purpose: implementation of wxCheckListBox class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11 //
12 // new DataBrowser-based version
13
14
15 #include "wx/wxprec.h"
16
17 #if wxUSE_CHECKLISTBOX
18
19 #include "wx/checklst.h"
20
21 #ifndef WX_PRECOMP
22 #include "wx/arrstr.h"
23 #endif
24
25 #include "wx/osx/uma.h"
26
27 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
28
29 BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
30 END_EVENT_TABLE()
31
32 class wxMacDataBrowserCheckListControl : public wxMacDataBrowserListControl , public wxMacCheckListControl
33 {
34 public:
35 wxMacDataBrowserCheckListControl( wxListBox *peer, const wxPoint& pos, const wxSize& size, long style );
36 wxMacDataBrowserCheckListControl() {}
37 virtual ~wxMacDataBrowserCheckListControl();
38
39 virtual wxMacDataItem* CreateItem();
40
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)
44 };
45
46 IMPLEMENT_DYNAMIC_CLASS( wxMacDataBrowserCheckListControl , wxMacDataBrowserListControl )
47
48 void wxCheckListBox::Init()
49 {
50 }
51
52 bool 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 )
61 {
62 wxCArrayString chs( choices );
63
64 return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name );
65 }
66
67 bool 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 )
77 {
78 m_macIsUserPane = false;
79
80 wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
81 wxT("only one of listbox selection modes can be specified") );
82
83 if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
84 return false;
85
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 );
89 m_peer = control;
90
91 MacPostControlCreate(pos,size);
92
93 InsertItems( n , choices , 0 );
94
95 // Needed because it is a wxControlWithItems
96 SetInitialSize( size );
97
98 return true;
99 }
100
101 // ----------------------------------------------------------------------------
102 // wxCheckListBox functions
103 // ----------------------------------------------------------------------------
104
105 bool wxCheckListBox::IsChecked(unsigned int item) const
106 {
107 wxCHECK_MSG( IsValid(item), false,
108 wxT("invalid index in wxCheckListBox::IsChecked") );
109
110 return GetPeer()->MacIsChecked( item );
111 }
112
113 void wxCheckListBox::Check(unsigned int item, bool check)
114 {
115 wxCHECK_RET( IsValid(item),
116 wxT("invalid index in wxCheckListBox::Check") );
117
118 bool isChecked = GetPeer()->MacIsChecked( item );
119 if ( check != isChecked )
120 {
121 GetPeer()->MacCheck( item , check );
122 }
123 }
124
125 wxMacCheckListControl* wxCheckListBox::GetPeer() const
126 {
127 wxMacDataBrowserCheckListControl *lb = wxDynamicCast(m_peer,wxMacDataBrowserCheckListControl);
128 return lb ? wx_static_cast(wxMacCheckListControl*,lb) : 0 ;
129 }
130
131 const short kCheckboxColumnId = 1026;
132
133 wxMacDataBrowserCheckListControl::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;
160
161 err = AddColumn( &columnDesc, 0 );
162 verify_noerr( err );
163 }
164
165 wxMacDataBrowserCheckListControl::~wxMacDataBrowserCheckListControl()
166 {
167
168 }
169
170 class wxMacCheckListBoxItem : public wxMacListBoxItem
171 {
172 public :
173 wxMacCheckListBoxItem()
174 {
175 m_isChecked = false;
176 }
177
178 virtual ~wxMacCheckListBoxItem()
179 {
180 }
181
182 virtual OSStatus GetSetData( wxMacDataItemBrowserControl *owner ,
183 DataBrowserPropertyID property,
184 DataBrowserItemDataRef itemData,
185 bool changeValue )
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 );
225 checklist->HandleWindowEvent( event );
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 }
239
240 void Check( bool check )
241 {
242 m_isChecked = check;
243 }
244 bool IsChecked() const
245 {
246 return m_isChecked;
247 }
248
249 protected :
250 bool m_isChecked;
251 };
252
253 wxMacDataItem* wxMacDataBrowserCheckListControl::CreateItem()
254 {
255 return new wxMacCheckListBoxItem();
256 }
257
258 void wxMacDataBrowserCheckListControl::MacCheck( unsigned int n, bool bCheck)
259 {
260 wxMacCheckListBoxItem* item = wx_static_cast(wxMacCheckListBoxItem*, GetItemFromLine( n) );
261 item->Check( bCheck);
262 UpdateItem(wxMacDataBrowserRootContainer, item , kCheckboxColumnId);
263 }
264
265 bool wxMacDataBrowserCheckListControl::MacIsChecked( unsigned int n) const
266 {
267 wxMacCheckListBoxItem * item = wx_static_cast( wxMacCheckListBoxItem*, GetItemFromLine( n ) );
268 return item->IsChecked();
269 }
270
271
272
273 #endif // wxUSE_CHECKLISTBOX