Removal of previous wxValidtor code for wxOS2
[wxWidgets.git] / src / os2 / combobox.cpp
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 const wxValidator& validator,
68 #endif
69 const wxString& name)
70 {
71 SetName(name);
72 #if wxUSE_VALIDATORS
73 SetValidator(validator);
74 #endif
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;
139 }
140
141 void wxComboBox::SetValue(const wxString& value)
142 {
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);
172 }
173
174 // Clipboard operations
175 void wxComboBox::Copy()
176 {
177 HWND hWnd = GetHwnd();
178 // SendMessage(hWnd, WM_COPY, 0, 0L);
179 }
180
181 void wxComboBox::Cut()
182 {
183 HWND hWnd = GetHwnd();
184 // SendMessage(hWnd, WM_CUT, 0, 0L);
185 }
186
187 void wxComboBox::Paste()
188 {
189 HWND hWnd = GetHwnd();
190 // SendMessage(hWnd, WM_PASTE, 0, 0L);
191 }
192
193 void wxComboBox::SetEditable(bool editable)
194 {
195 // Can't implement in MSW?
196 // HWND hWnd = GetHwnd();
197 // SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
198 }
199
200 void wxComboBox::SetInsertionPoint(long pos)
201 {
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 */
209 }
210
211 void wxComboBox::SetInsertionPointEnd()
212 {
213 /*
214 long pos = GetLastPosition();
215 SetInsertionPoint(pos);
216 */
217 }
218
219 long wxComboBox::GetInsertionPoint() const
220 {
221 /*
222 DWORD Pos=(DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
223 return Pos&0xFFFF;
224 */
225 return 0;
226 }
227
228 long wxComboBox::GetLastPosition() const
229 {
230 /*
231 HWND hWnd = GetHwnd();
232
233 // Will always return a number > 0 (according to docs)
234 int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
235
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);
238
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);
242
243 return (long)(charIndex + lineLength);
244 */
245 return 0;
246 }
247
248 void wxComboBox::Replace(long from, long to, const wxString& value)
249 {
250 #if wxUSE_CLIPBOARD
251 HWND hWnd = GetHwnd();
252 long fromChar = from;
253 long toChar = to;
254
255 // Set selection and remove it
256 // SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
257 // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
258
259 // Now replace with 'value', by pasting.
260 wxSetClipboardData(wxDF_TEXT, (wxObject *)(const wxChar *)value, 0, 0);
261
262 // Paste into edit control
263 // SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L);
264 #endif
265 }
266
267 void wxComboBox::Remove(long from, long to)
268 {
269 HWND hWnd = GetHwnd();
270 long fromChar = from;
271 long toChar = to;
272
273 // Cut all selected text
274 // SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
275 // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
276 }
277
278 void wxComboBox::SetSelection(long from, long to)
279 {
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);
294 }
295
296 void wxComboBox::DoSetSize(int x, int y,
297 int width, int height,
298 int sizeFlags)
299 {
300 wxControl::DoSetSize(x, y, width, height, sizeFlags);
301 }
302
303 #endif
304 // wxUSE_COMBOBOX
305