]> git.saurik.com Git - wxWidgets.git/blame - src/os2/combobox.cpp
added common regex
[wxWidgets.git] / src / os2 / combobox.cpp
CommitLineData
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 26
0e320a79 27IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
0e320a79 28
37f214d5 29bool wxComboBox::OS2Command(WXUINT param, WXWORD WXUNUSED(id))
0e320a79 30{
37f214d5
DW
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);
0e320a79 40
37f214d5
DW
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);
0e320a79
DW
49
50 return TRUE;
37f214d5
DW
51 }
52 else
53 return FALSE;
54*/
55 return FALSE;
0e320a79
DW
56}
57
37f214d5
DW
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,
5d4b632b 64#if wxUSE_VALIDATORS
37f214d5 65 const wxValidator& validator,
5d4b632b 66#endif
37f214d5 67 const wxString& name)
0e320a79 68{
37f214d5 69 SetName(name);
5d4b632b 70#if wxUSE_VALIDATORS
37f214d5 71 SetValidator(validator);
5d4b632b 72#endif
37f214d5
DW
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;
0e320a79
DW
137}
138
139void wxComboBox::SetValue(const wxString& value)
140{
37f214d5
DW
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);
0e320a79
DW
170}
171
172// Clipboard operations
173void wxComboBox::Copy()
174{
37f214d5
DW
175 HWND hWnd = GetHwnd();
176// SendMessage(hWnd, WM_COPY, 0, 0L);
0e320a79
DW
177}
178
179void wxComboBox::Cut()
180{
37f214d5
DW
181 HWND hWnd = GetHwnd();
182// SendMessage(hWnd, WM_CUT, 0, 0L);
0e320a79
DW
183}
184
185void wxComboBox::Paste()
186{
37f214d5
DW
187 HWND hWnd = GetHwnd();
188// SendMessage(hWnd, WM_PASTE, 0, 0L);
0e320a79
DW
189}
190
191void wxComboBox::SetEditable(bool editable)
192{
37f214d5
DW
193 // Can't implement in MSW?
194// HWND hWnd = GetHwnd();
195// SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
0e320a79
DW
196}
197
198void wxComboBox::SetInsertionPoint(long pos)
199{
37f214d5
DW
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*/
0e320a79
DW
207}
208
209void wxComboBox::SetInsertionPointEnd()
210{
37f214d5
DW
211/*
212 long pos = GetLastPosition();
213 SetInsertionPoint(pos);
214*/
0e320a79
DW
215}
216
217long wxComboBox::GetInsertionPoint() const
218{
37f214d5
DW
219/*
220 DWORD Pos=(DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
221 return Pos&0xFFFF;
222*/
223 return 0;
0e320a79
DW
224}
225
226long wxComboBox::GetLastPosition() const
227{
37f214d5
DW
228/*
229 HWND hWnd = GetHwnd();
0e320a79 230
37f214d5
DW
231 // Will always return a number > 0 (according to docs)
232 int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
0e320a79 233
37f214d5
DW
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);
0e320a79 236
37f214d5
DW
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);
0e320a79 240
37f214d5
DW
241 return (long)(charIndex + lineLength);
242*/
243 return 0;
0e320a79
DW
244}
245
37f214d5 246void wxComboBox::Replace(long from, long to, const wxString& value)
0e320a79 247{
37f214d5
DW
248#if wxUSE_CLIPBOARD
249 HWND hWnd = GetHwnd();
250 long fromChar = from;
251 long toChar = to;
0e320a79 252
37f214d5
DW
253 // Set selection and remove it
254// SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
255// SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
0e320a79 256
37f214d5
DW
257 // Now replace with 'value', by pasting.
258 wxSetClipboardData(wxDF_TEXT, (wxObject *)(const wxChar *)value, 0, 0);
0e320a79 259
37f214d5
DW
260 // Paste into edit control
261// SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L);
262#endif
0e320a79
DW
263}
264
37f214d5 265void wxComboBox::Remove(long from, long to)
0e320a79 266{
37f214d5
DW
267 HWND hWnd = GetHwnd();
268 long fromChar = from;
269 long toChar = to;
0e320a79 270
37f214d5
DW
271 // Cut all selected text
272// SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
273// SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
0e320a79
DW
274}
275
37f214d5 276void wxComboBox::SetSelection(long from, long to)
0e320a79 277{
37f214d5
DW
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);
0e320a79
DW
292}
293
37f214d5
DW
294void wxComboBox::DoSetSize(int x, int y,
295 int width, int height,
296 int sizeFlags)
0e320a79 297{
37f214d5 298 wxControl::DoSetSize(x, y, width, height, sizeFlags);
0e320a79 299}
37f214d5
DW
300
301#endif
302 // wxUSE_COMBOBOX
303