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