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