]> git.saurik.com Git - wxWidgets.git/blame - src/motif/checklst.cpp
Only give capture to wxPopupTransientWindow child if it's the only one.
[wxWidgets.git] / src / motif / checklst.cpp
CommitLineData
4bb6408c 1///////////////////////////////////////////////////////////////////////////////
11e62fe6 2// Name: src/motif/checklst.cpp
4bb6408c
JS
3// Purpose: implementation of wxCheckListBox class
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
4bb6408c 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
4bb6408c
JS
9///////////////////////////////////////////////////////////////////////////////
10
11// ============================================================================
12// headers & declarations
13// ============================================================================
14
1248b41f
MB
15// For compilers that support precompilation, includes "wx.h".
16#include "wx/wxprec.h"
17
aa61d352
VZ
18#if wxUSE_CHECKLISTBOX
19
4bb6408c 20#include "wx/checklst.h"
aaa6d89a
WS
21
22#ifndef WX_PRECOMP
23 #include "wx/arrstr.h"
24#endif
4bb6408c
JS
25
26// ============================================================================
6463b9f5 27// implementation
4bb6408c
JS
28// ============================================================================
29
4bb6408c
JS
30// ----------------------------------------------------------------------------
31// implementation of wxCheckListBox class
32// ----------------------------------------------------------------------------
33
34// define event table
35// ------------------
36BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
37END_EVENT_TABLE()
38
39// control creation
40// ----------------
41
ef41d80c
MB
42static const wxString prefixChecked = "[x] ";
43static const wxString prefixUnchecked = "[ ] ";
44static const char checkChar = 'x', uncheckChar = ' ';
45
46static inline const wxString& Prefix(bool checked)
47 { return checked ? prefixChecked : prefixUnchecked; }
48static inline bool IsChecked(const wxString& s)
49 { wxASSERT(s.length() >=4); return s[1] == checkChar; }
50
4bb6408c 51// def ctor: use Create() to really create the control
ef41d80c 52wxCheckListBox::wxCheckListBox() : wxCheckListBoxBase()
4bb6408c
JS
53{
54}
55
56// ctor which creates the associated control
57wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id,
58 const wxPoint& pos, const wxSize& size,
59 int nStrings, const wxString choices[],
60 long style, const wxValidator& val,
61 const wxString& name)
ef41d80c 62 : wxCheckListBoxBase()
4bb6408c 63{
ef41d80c
MB
64 Create(parent, id, pos, size, nStrings, choices,
65 style, val, name);
4bb6408c
JS
66}
67
584ad2a3
MB
68wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id,
69 const wxPoint& pos, const wxSize& size,
70 const wxArrayString& choices,
71 long style, const wxValidator& val,
72 const wxString& name)
73 : wxCheckListBoxBase()
74{
75 Create(parent, id, pos, size, choices,
76 style, val, name);
77}
78
ef41d80c 79bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id,
c266945c
JS
80 const wxPoint& pos,
81 const wxSize& size,
82 int n, const wxString choices[],
83 long style,
84 const wxValidator& validator,
ef41d80c
MB
85 const wxString& name)
86{
2b5f62a0
VZ
87 // wxListBox::Create calls set, which adds the prefixes
88 bool retVal = wxListBox::Create(parent, id, pos, size, n, choices,
ef41d80c 89 style, validator, name);
ef41d80c 90 return retVal;
11e62fe6 91}
ef41d80c 92
584ad2a3
MB
93bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id,
94 const wxPoint& pos,
95 const wxSize& size,
96 const wxArrayString& choices,
97 long style,
98 const wxValidator& validator,
99 const wxString& name)
100{
101 // wxListBox::Create calls set, which adds the prefixes
102 bool retVal = wxListBox::Create(parent, id, pos, size, choices,
103 style, validator, name);
104 return retVal;
11e62fe6 105}
584ad2a3 106
4bb6408c
JS
107// check items
108// -----------
109
aa61d352 110bool wxCheckListBox::IsChecked(unsigned int uiIndex) const
ef41d80c
MB
111{
112 return ::IsChecked(wxListBox::GetString(uiIndex));
113}
114
aa61d352 115void wxCheckListBox::Check(unsigned int uiIndex, bool bCheck)
4bb6408c 116{
ef41d80c
MB
117 wxString label = wxListBox::GetString(uiIndex);
118 if(::IsChecked(label) == bCheck) return;
119 label[1u] = bCheck ? checkChar : uncheckChar;
120 wxListBox::SetString(uiIndex, label);
4bb6408c
JS
121}
122
ef41d80c 123void wxCheckListBox::DoToggleItem( int n, int x )
4bb6408c 124{
105fbe1f 125 if( x > 0 && x < 23 )
ef41d80c
MB
126 {
127 wxString label = wxListBox::GetString(n);
128 label[1u] = (!::IsChecked(label)) ? checkChar : uncheckChar;
129 wxListBox::SetString(n, label);
130
ce7fe42e 131 wxCommandEvent event(wxEVT_CHECKLISTBOX, GetId());
ef41d80c
MB
132 if( HasClientObjectData() )
133 event.SetClientObject( GetClientObject(n) );
134 else if( HasClientUntypedData() )
135 event.SetClientData( GetClientData(n) );
687706f5 136 event.SetInt(n);
96be256b 137 event.SetExtraLong(true);
ef41d80c 138 event.SetEventObject(this);
aa61d352 139 event.SetString(GetString(n));
ef41d80c 140
937013e0 141 HandleWindowEvent(event);
ef41d80c 142 }
4bb6408c
JS
143}
144
11e62fe6 145int wxCheckListBox::FindString(const wxString& s, bool bCase) const
ef41d80c 146{
11e62fe6
WS
147 int n1 = wxListBox::FindString(Prefix(false) + s, bCase);
148 int n2 = wxListBox::FindString(Prefix(true) + s, bCase);
ef41d80c
MB
149 int min = wxMin(n1, n2), max = wxMax(n1, n2);
150
151 // why this works:
152 // n1 == -1, n2 == -1 => return -1 OK
153 // n1 != -1 || n2 != -1 => min == -1 => return the other one
154 // both != -1 => return the first one.
155 if( min == -1 ) return max;
156 return min;
157}
158
aa61d352 159void wxCheckListBox::SetString(unsigned int n, const wxString& s)
ef41d80c 160{
aa61d352 161 wxListBox::SetString(n, Prefix(IsChecked(n)) + s);
ef41d80c 162}
4bb6408c 163
aa61d352 164wxString wxCheckListBox::GetString(unsigned int n) const
ef41d80c
MB
165{
166 return wxListBox::GetString(n).substr(4);
167}
168
a236aa20
VZ
169int wxCheckListBox::DoInsertItems(const wxArrayStringsAdapter& items,
170 unsigned int pos,
171 void **clientData, wxClientDataType type)
ef41d80c
MB
172{
173 wxArrayString copy;
a236aa20
VZ
174 copy.reserve(pos);
175 for ( size_t i = 0; i < items.GetCount(); ++i )
176 copy.push_back( Prefix(false) + items[i] );
ef41d80c 177
a236aa20 178 return wxListBox::DoInsertItems(copy, pos, clientData, type);
ef41d80c 179}
aa61d352
VZ
180
181#endif // wxUSE_CHECKLISTBOX