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