]> git.saurik.com Git - wxWidgets.git/blob - contrib/samples/applet/combobox.cpp
another attempt to fix wxPanel/wxFrame::m_winLastFocused handling
[wxWidgets.git] / contrib / samples / applet / combobox.cpp
1 /****************************************************************************
2 *
3 * wxWindows HTML Applet Package
4 *
5 * ========================================================================
6 *
7 * The contents of this file are subject to the wxWindows licence; you
8 * may not use this file except in compliance with the License. You may
9 * obtain a copy of the License at http://www.wxwindows.org/licence.htm
10 *
11 * Software distributed under the License is distributed on an
12 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
13 * implied. See the License for the specific language governing
14 * rights and limitations under the License.
15 *
16 * The Original Code is Copyright (C) 2001 SciTech Software, Inc.
17 *
18 * The Initial Developer of the Original Code is SciTech Software, Inc.
19 * All Rights Reserved.
20 *
21 * ========================================================================
22 *
23 * Language: ANSI C++
24 * Environment: Any
25 *
26 * Description: Combobox wrapper. This file implements the custom
27 * combo boxes used for this sample program.
28 *
29 ****************************************************************************/
30
31 // For compilers that support precompilation, includes "wx/wx.h".
32 #include <wx/wxprec.h>
33 #ifdef __BORLANDC__
34 #pragma hdrstop
35 #endif
36
37 #include "wx/wx.h"
38 #include "combobox.h"
39
40 /*------------------------- Implementation --------------------------------*/
41
42 ComboBox::ComboBox(
43 wxWindow *parent,
44 int listid,
45 int textid)
46 : m_Parent(parent), m_ListBoxId(listid), m_TextCtrlId(textid)
47 {
48 m_ListBox = wxDynamicCast(m_Parent->FindWindow(listid),wxListBox);
49 m_TextCtrl = wxDynamicCast(m_Parent->FindWindow(textid),wxTextCtrl);
50 }
51
52 int ComboBox::GetListBoxId()
53 {
54 return m_ListBoxId;
55 }
56
57 int ComboBox::GetSelection()
58 {
59 return m_ListBox->GetSelection();
60 }
61
62 wxString ComboBox::GetStringSelection()
63 {
64 return m_ListBox->GetStringSelection();
65 }
66
67 bool ComboBox::SetStringSelection(const wxString& s, bool select)
68 {
69 select = TRUE;
70 select = m_ListBox->SetStringSelection(s, select);
71 m_TextCtrl->SetValue(GetStringSelection());
72 return select;
73 }
74
75 void ComboBox::Select(int n)
76 {
77 m_ListBox->Select(n);
78 m_TextCtrl->SetValue(GetStringSelection());
79 }
80
81 void ComboBox::Deselect(int n)
82 {
83 m_ListBox->Deselect(n);
84 }
85
86 void ComboBox::Insert(const wxString& item, int pos)
87 {
88 m_ListBox->Insert(item,pos);
89 }
90
91 void ComboBox::Insert(const wxString& item, int pos, void *clientData)
92 {
93 m_ListBox->Insert(item, pos, clientData);
94 }
95
96 void ComboBox::Insert(const wxString& item, int pos, wxClientData *clientData)
97 {
98 m_ListBox->Insert(item, pos, clientData);
99 }
100
101 void ComboBox::InsertItems(int nItems, const wxString *items, int pos)
102 {
103 m_ListBox->InsertItems(nItems, items, pos);
104 }
105
106 void ComboBox::InsertItems(const wxArrayString& items, int pos)
107 {
108 m_ListBox->InsertItems(items, pos);
109 }
110
111 void ComboBox::Set(int n, const wxString* items, void **clientData)
112 {
113 m_ListBox->Set(n, items, clientData);
114 m_TextCtrl->SetValue(GetStringSelection());
115 }
116
117 void ComboBox::Set(const wxArrayString& items, void **clientData)
118 {
119 m_ListBox->Set(items, clientData);
120 m_TextCtrl->SetValue(GetStringSelection());
121 }
122
123 int ComboBox::FindString(const wxString &s)
124 {
125 return (m_ListBox->FindString(s));
126 }
127
128 void ComboBox::SetFirstItem(int n)
129 {
130 m_ListBox->SetFirstItem(n);
131 m_TextCtrl->SetValue(GetStringSelection());
132 }
133
134 void ComboBox::SetFirstItem(const wxString &s)
135 {
136 m_ListBox->SetFirstItem(s);
137 m_TextCtrl->SetValue(GetStringSelection());
138 }
139
140 void ComboBox::Append(const wxString &item)
141 {
142 m_ListBox->Append(item);
143 m_TextCtrl->SetValue(GetStringSelection());
144 }
145
146 void ComboBox::Append(const wxString& item, void *clientData)
147 {
148 m_ListBox->Append(item, clientData);
149 m_TextCtrl->SetValue(GetStringSelection());
150 }
151
152 void ComboBox::Append(const wxString& item, wxClientData *clientData)
153 {
154 m_ListBox->Append(item, clientData);
155 m_TextCtrl->SetValue(GetStringSelection());
156 }
157
158 void ComboBox::Clear()
159 {
160 m_ListBox->Clear();
161 m_TextCtrl->SetValue(GetStringSelection());
162 }
163
164 void ComboBox::Delete(int n)
165 {
166 m_ListBox->Delete(n);
167 m_TextCtrl->SetValue(GetStringSelection());
168 }
169
170 void ComboBox::OnChange(wxCommandEvent &)
171 {
172 m_TextCtrl->SetValue(GetStringSelection());
173 }
174