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