]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/osx/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/private.h" | |
26 | ||
27 | IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox) | |
28 | ||
29 | BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox) | |
30 | END_EVENT_TABLE() | |
31 | ||
32 | void wxCheckListBox::Init() | |
33 | { | |
34 | } | |
35 | ||
36 | bool wxCheckListBox::Create( | |
37 | wxWindow *parent, | |
38 | wxWindowID id, | |
39 | const wxPoint &pos, | |
40 | const wxSize &size, | |
41 | const wxArrayString& choices, | |
42 | long style, | |
43 | const wxValidator& validator, | |
44 | const wxString &name ) | |
45 | { | |
46 | wxCArrayString chs( choices ); | |
47 | ||
48 | return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name ); | |
49 | } | |
50 | ||
51 | bool wxCheckListBox::Create( | |
52 | wxWindow *parent, | |
53 | wxWindowID id, | |
54 | const wxPoint& pos, | |
55 | const wxSize& size, | |
56 | int n, | |
57 | const wxString choices[], | |
58 | long style, | |
59 | const wxValidator& validator, | |
60 | const wxString& name ) | |
61 | { | |
62 | m_macIsUserPane = false; | |
63 | ||
64 | wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED), | |
65 | wxT("only one of listbox selection modes can be specified") ); | |
66 | ||
67 | if ( !wxCheckListBoxBase::Create( parent, id, pos, size, n, choices, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) ) | |
68 | return false; | |
69 | ||
70 | int colwidth = 30; | |
71 | // TODO adapt the width according to the window variant | |
72 | m_checkColumn = GetListPeer()->InsertCheckColumn(0, wxEmptyString, true, wxALIGN_CENTER, colwidth); | |
73 | ||
74 | return true; | |
75 | } | |
76 | ||
77 | // ---------------------------------------------------------------------------- | |
78 | // wxCheckListBox functions | |
79 | // ---------------------------------------------------------------------------- | |
80 | ||
81 | // ---------------------------------------------------------------------------- | |
82 | // wxCheckListBox functions | |
83 | // ---------------------------------------------------------------------------- | |
84 | ||
85 | bool wxCheckListBox::IsChecked(unsigned int n) const | |
86 | { | |
87 | wxCHECK_MSG( IsValid(n), false, | |
88 | wxT("invalid index in wxCheckListBox::IsChecked") ); | |
89 | ||
90 | return m_checks[n] != 0; | |
91 | } | |
92 | ||
93 | void wxCheckListBox::Check(unsigned int n, bool check) | |
94 | { | |
95 | wxCHECK_RET( IsValid(n), | |
96 | wxT("invalid index in wxCheckListBox::Check") ); | |
97 | ||
98 | // intermediate var is needed to avoid compiler warning with VC++ | |
99 | bool isChecked = m_checks[n] != 0; | |
100 | if ( check != isChecked ) | |
101 | { | |
102 | m_checks[n] = check; | |
103 | ||
104 | GetListPeer()->UpdateLine(n); | |
105 | } | |
106 | } | |
107 | ||
108 | void wxCheckListBox::GetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value ) | |
109 | { | |
110 | if ( col == m_checkColumn ) | |
111 | value.Check( IsChecked( n ) ); | |
112 | else | |
113 | wxListBox::GetValueCallback( n, col, value ); | |
114 | } | |
115 | ||
116 | void wxCheckListBox::SetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value ) | |
117 | { | |
118 | if ( col == m_checkColumn ) | |
119 | { | |
120 | Check( n, value.IsChecked() ); | |
121 | ||
122 | wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, GetId() ); | |
123 | event.SetInt( n ); | |
124 | event.SetString( GetString( n ) ); | |
125 | event.SetEventObject( this ); | |
126 | HandleWindowEvent( event ); | |
127 | } | |
128 | } | |
129 | ||
130 | ||
131 | ||
132 | // ---------------------------------------------------------------------------- | |
133 | // methods forwarded to wxListBox | |
134 | // ---------------------------------------------------------------------------- | |
135 | ||
136 | void wxCheckListBox::OnItemInserted(unsigned int pos) | |
137 | { | |
138 | wxListBox::OnItemInserted(pos); | |
139 | ||
140 | m_checks.Insert(false, pos ); | |
141 | } | |
142 | ||
143 | void wxCheckListBox::DoDeleteOneItem(unsigned int n) | |
144 | { | |
145 | wxListBox::DoDeleteOneItem(n); | |
146 | ||
147 | m_checks.RemoveAt(n); | |
148 | } | |
149 | ||
150 | void wxCheckListBox::DoClear() | |
151 | { | |
152 | wxListBox::DoClear(); | |
153 | ||
154 | m_checks.Empty(); | |
155 | } | |
156 | ||
157 | #endif // wxUSE_CHECKLISTBOX |