]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: combobox.cpp | |
3 | // Purpose: wxComboBox class | |
4 | // Author: David Webster | |
5 | // Modified by: | |
6 | // Created: 10/13/99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) David Webster | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/combobox.h" | |
13 | ||
14 | // For compilers that support precompilation, includes "wx.h". | |
15 | #include "wx/wxprec.h" | |
16 | ||
17 | #ifndef WX_PRECOMP | |
18 | #include "wx/setup.h" | |
19 | #endif | |
20 | ||
21 | #if wxUSE_COMBOBOX | |
22 | ||
23 | #include "wx/combobox.h" | |
24 | #include "wx/clipbrd.h" | |
25 | #include "wx/os2/private.h" | |
26 | ||
27 | #if !USE_SHARED_LIBRARY | |
28 | IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl) | |
29 | #endif | |
30 | ||
31 | bool wxComboBox::OS2Command(WXUINT param, WXWORD WXUNUSED(id)) | |
32 | { | |
33 | // TODO: | |
34 | /* | |
35 | if (param == CBN_SELCHANGE) | |
36 | { | |
37 | wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId); | |
38 | event.SetInt(GetSelection()); | |
39 | event.SetEventObject(this); | |
40 | event.SetString(GetStringSelection()); | |
41 | ProcessCommand(event); | |
42 | ||
43 | return TRUE; | |
44 | } | |
45 | else if (param == CBN_EDITCHANGE) | |
46 | { | |
47 | wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId); | |
48 | event.SetString(GetValue()); | |
49 | event.SetEventObject(this); | |
50 | ProcessCommand(event); | |
51 | ||
52 | return TRUE; | |
53 | } | |
54 | else | |
55 | return FALSE; | |
56 | */ | |
57 | return FALSE; | |
58 | } | |
59 | ||
60 | bool wxComboBox::Create(wxWindow *parent, wxWindowID id, | |
61 | const wxString& value, | |
62 | const wxPoint& pos, | |
63 | const wxSize& size, | |
64 | int n, const wxString choices[], | |
65 | long style, | |
66 | #if wxUSE_VALIDATORS | |
67 | # if defined(__VISAGECPP__) | |
68 | const wxValidator* validator, | |
69 | # else | |
70 | const wxValidator& validator, | |
71 | # endif | |
72 | #endif | |
73 | const wxString& name) | |
74 | { | |
75 | SetName(name); | |
76 | #if wxUSE_VALIDATORS | |
77 | SetValidator(validator); | |
78 | #endif | |
79 | if (parent) parent->AddChild(this); | |
80 | SetBackgroundColour(parent->GetBackgroundColour()) ; | |
81 | SetForegroundColour(parent->GetForegroundColour()) ; | |
82 | ||
83 | m_windowStyle = style; | |
84 | ||
85 | if ( id == -1 ) | |
86 | m_windowId = (int)NewControlId(); | |
87 | else | |
88 | m_windowId = id; | |
89 | ||
90 | int x = pos.x; | |
91 | int y = pos.y; | |
92 | int width = size.x; | |
93 | int height = size.y; | |
94 | // TODO: | |
95 | /* | |
96 | long msStyle = WS_CHILD | WS_TABSTOP | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | | |
97 | CBS_NOINTEGRALHEIGHT; | |
98 | ||
99 | if (m_windowStyle & wxCB_READONLY) | |
100 | msStyle |= CBS_DROPDOWNLIST; | |
101 | else if (m_windowStyle & wxCB_SIMPLE) | |
102 | msStyle |= CBS_SIMPLE; // A list (shown always) and edit control | |
103 | else | |
104 | msStyle |= CBS_DROPDOWN; | |
105 | ||
106 | if (m_windowStyle & wxCB_SORT) | |
107 | msStyle |= CBS_SORT; | |
108 | ||
109 | bool want3D; | |
110 | WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ; | |
111 | ||
112 | // Even with extended styles, need to combine with WS_BORDER | |
113 | // for them to look right. | |
114 | if ( want3D || wxStyleHasBorder(m_windowStyle) ) | |
115 | msStyle |= WS_BORDER; | |
116 | ||
117 | m_hWnd = (WXHWND)::CreateWindowEx(exStyle, wxT("COMBOBOX"), NULL, | |
118 | msStyle, | |
119 | 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId, | |
120 | wxGetInstance(), NULL); | |
121 | ||
122 | wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create combobox") ); | |
123 | ||
124 | // Subclass again for purposes of dialog editing mode | |
125 | SubclassWin(m_hWnd); | |
126 | ||
127 | SetFont(parent->GetFont()); | |
128 | int i; | |
129 | for (i = 0; i < n; i++) | |
130 | { | |
131 | Append(choices[i]); | |
132 | } | |
133 | ||
134 | SetSelection(i); | |
135 | ||
136 | SetSize(x, y, width, height); | |
137 | if ( !value.IsEmpty() ) | |
138 | { | |
139 | SetValue(value); | |
140 | } | |
141 | */ | |
142 | return TRUE; | |
143 | } | |
144 | ||
145 | void wxComboBox::SetValue(const wxString& value) | |
146 | { | |
147 | // If newlines are denoted by just 10, must stick 13 in front. | |
148 | int singletons = 0; | |
149 | int len = value.Length(); | |
150 | int i; | |
151 | for (i = 0; i < len; i ++) | |
152 | { | |
153 | if ((i > 0) && (value[i] == 10) && (value[i-1] != 13)) | |
154 | singletons ++; | |
155 | } | |
156 | if (singletons > 0) | |
157 | { | |
158 | wxChar *tmp = new wxChar[len + singletons + 1]; | |
159 | int j = 0; | |
160 | for (i = 0; i < len; i ++) | |
161 | { | |
162 | if ((i > 0) && (value[i] == 10) && (value[i-1] != 13)) | |
163 | { | |
164 | tmp[j] = 13; | |
165 | j ++; | |
166 | } | |
167 | tmp[j] = value[i]; | |
168 | j ++; | |
169 | } | |
170 | tmp[j] = 0; | |
171 | // SetWindowText(GetHwnd(), tmp); | |
172 | delete[] tmp; | |
173 | } | |
174 | // else | |
175 | // SetWindowText(GetHwnd(), value); | |
176 | } | |
177 | ||
178 | // Clipboard operations | |
179 | void wxComboBox::Copy() | |
180 | { | |
181 | HWND hWnd = GetHwnd(); | |
182 | // SendMessage(hWnd, WM_COPY, 0, 0L); | |
183 | } | |
184 | ||
185 | void wxComboBox::Cut() | |
186 | { | |
187 | HWND hWnd = GetHwnd(); | |
188 | // SendMessage(hWnd, WM_CUT, 0, 0L); | |
189 | } | |
190 | ||
191 | void wxComboBox::Paste() | |
192 | { | |
193 | HWND hWnd = GetHwnd(); | |
194 | // SendMessage(hWnd, WM_PASTE, 0, 0L); | |
195 | } | |
196 | ||
197 | void wxComboBox::SetEditable(bool editable) | |
198 | { | |
199 | // Can't implement in MSW? | |
200 | // HWND hWnd = GetHwnd(); | |
201 | // SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L); | |
202 | } | |
203 | ||
204 | void wxComboBox::SetInsertionPoint(long pos) | |
205 | { | |
206 | /* | |
207 | HWND hWnd = GetHwnd(); | |
208 | SendMessage(hWnd, EM_SETSEL, pos, pos); | |
209 | SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0); | |
210 | char *nothing = ""; | |
211 | SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing); | |
212 | */ | |
213 | } | |
214 | ||
215 | void wxComboBox::SetInsertionPointEnd() | |
216 | { | |
217 | /* | |
218 | long pos = GetLastPosition(); | |
219 | SetInsertionPoint(pos); | |
220 | */ | |
221 | } | |
222 | ||
223 | long wxComboBox::GetInsertionPoint() const | |
224 | { | |
225 | /* | |
226 | DWORD Pos=(DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L); | |
227 | return Pos&0xFFFF; | |
228 | */ | |
229 | return 0; | |
230 | } | |
231 | ||
232 | long wxComboBox::GetLastPosition() const | |
233 | { | |
234 | /* | |
235 | HWND hWnd = GetHwnd(); | |
236 | ||
237 | // Will always return a number > 0 (according to docs) | |
238 | int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L); | |
239 | ||
240 | // This gets the char index for the _beginning_ of the last line | |
241 | int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)(noLines-1), (LPARAM)0L); | |
242 | ||
243 | // Get number of characters in the last line. We'll add this to the character | |
244 | // index for the last line, 1st position. | |
245 | int lineLength = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0L); | |
246 | ||
247 | return (long)(charIndex + lineLength); | |
248 | */ | |
249 | return 0; | |
250 | } | |
251 | ||
252 | void wxComboBox::Replace(long from, long to, const wxString& value) | |
253 | { | |
254 | #if wxUSE_CLIPBOARD | |
255 | HWND hWnd = GetHwnd(); | |
256 | long fromChar = from; | |
257 | long toChar = to; | |
258 | ||
259 | // Set selection and remove it | |
260 | // SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar); | |
261 | // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0); | |
262 | ||
263 | // Now replace with 'value', by pasting. | |
264 | wxSetClipboardData(wxDF_TEXT, (wxObject *)(const wxChar *)value, 0, 0); | |
265 | ||
266 | // Paste into edit control | |
267 | // SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L); | |
268 | #endif | |
269 | } | |
270 | ||
271 | void wxComboBox::Remove(long from, long to) | |
272 | { | |
273 | HWND hWnd = GetHwnd(); | |
274 | long fromChar = from; | |
275 | long toChar = to; | |
276 | ||
277 | // Cut all selected text | |
278 | // SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar); | |
279 | // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0); | |
280 | } | |
281 | ||
282 | void wxComboBox::SetSelection(long from, long to) | |
283 | { | |
284 | HWND hWnd = GetHwnd(); | |
285 | long fromChar = from; | |
286 | long toChar = to; | |
287 | // if from and to are both -1, it means | |
288 | // (in wxWindows) that all text should be selected. | |
289 | // This translates into Windows convention | |
290 | if ((from == -1) && (to == -1)) | |
291 | { | |
292 | fromChar = 0; | |
293 | toChar = -1; | |
294 | } | |
295 | ||
296 | // SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)fromChar, (LPARAM)toChar); | |
297 | // SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0); | |
298 | } | |
299 | ||
300 | void wxComboBox::DoSetSize(int x, int y, | |
301 | int width, int height, | |
302 | int sizeFlags) | |
303 | { | |
304 | wxControl::DoSetSize(x, y, width, height, sizeFlags); | |
305 | } | |
306 | ||
307 | #endif | |
308 | // wxUSE_COMBOBOX | |
309 |