]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/checklst.cpp
cleanup - reformatting
[wxWidgets.git] / src / mac / 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 #include "wx/arrstr.h"
21
22 #include "wx/mac/uma.h"
23
24 #ifndef __DARWIN__
25 #include <Appearance.h>
26 #endif
27
28 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
29
30 BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
31 END_EVENT_TABLE()
32
33 void wxCheckListBox::Init()
34 {
35 }
36
37 bool wxCheckListBox::Create(
38 wxWindow *parent,
39 wxWindowID id,
40 const wxPoint &pos,
41 const wxSize &size,
42 const wxArrayString& choices,
43 long style,
44 const wxValidator& validator,
45 const wxString &name )
46 {
47 wxCArrayString chs( choices );
48
49 return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name );
50 }
51
52 bool wxCheckListBox::Create(
53 wxWindow *parent,
54 wxWindowID id,
55 const wxPoint& pos,
56 const wxSize& size,
57 int n,
58 const wxString choices[],
59 long style,
60 const wxValidator& validator,
61 const wxString& name )
62 {
63 m_macIsUserPane = false;
64
65 wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
66 wxT("only one of listbox selection modes can be specified") );
67
68 if ( !wxListBoxBase::Create( parent, id, pos, size, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
69 return false;
70
71 // this will be increased by our Append command
72 m_noItems = 0;
73
74 m_peer = (wxMacControl*) CreateMacListControl(pos , size , style );
75
76 MacPostControlCreate(pos,size);
77
78 InsertItems( n , choices , 0 );
79
80 // Needed because it is a wxControlWithItems
81 SetBestSize( size );
82
83 return true;
84 }
85
86 // ----------------------------------------------------------------------------
87 // wxCheckListBox functions
88 // ----------------------------------------------------------------------------
89
90 bool wxCheckListBox::IsChecked(unsigned int item) const
91 {
92 wxCHECK_MSG( IsValid(item), false,
93 wxT("invalid index in wxCheckListBox::IsChecked") );
94
95 return m_checks[item] != 0;
96 }
97
98 void wxCheckListBox::Check(unsigned int item, bool check)
99 {
100 wxCHECK_RET( IsValid(item),
101 wxT("invalid index in wxCheckListBox::Check") );
102
103 bool isChecked = m_checks[item] != 0;
104 if ( check != isChecked )
105 {
106 m_checks[item] = check;
107 MacUpdateLine( item );
108 }
109 }
110
111 // ----------------------------------------------------------------------------
112 // methods forwarded to wxCheckListBox
113 // ----------------------------------------------------------------------------
114
115 void wxCheckListBox::Delete(unsigned int n)
116 {
117 wxCHECK_RET( IsValid(n), wxT("invalid index in wxCheckListBox::Delete") );
118
119 wxListBox::Delete( n );
120 m_checks.RemoveAt( n );
121 }
122
123 int wxCheckListBox::DoAppend(const wxString& item)
124 {
125 int pos = wxListBox::DoAppend( item );
126
127 // the item is initially unchecked
128 m_checks.Insert( false, pos );
129
130 return pos;
131 }
132
133 void wxCheckListBox::DoInsertItems(const wxArrayString& items, unsigned int pos)
134 {
135 wxListBox::DoInsertItems( items, pos );
136
137 unsigned int count = items.GetCount();
138 for ( unsigned int n = 0; n < count; n++ )
139 {
140 m_checks.Insert( false, pos + n );
141 }
142 }
143
144 void wxCheckListBox::DoSetItems(const wxArrayString& items, void **clientData)
145 {
146 // call it first as it does DoClear()
147 wxListBox::DoSetItems( items, clientData );
148
149 unsigned int count = items.GetCount();
150 for ( unsigned int n = 0; n < count; n++ )
151 {
152 m_checks.Add( false );
153 }
154 }
155
156 void wxCheckListBox::DoClear()
157 {
158 m_checks.Empty();
159 }
160
161 #endif // wxUSE_CHECKLISTBOX