]> git.saurik.com Git - wxWidgets.git/blame - src/os2/combobox.cpp
wxFontEnumerator mostly works for wxMSW
[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
DW
26
27#if !USE_SHARED_LIBRARY
28IMPLEMENT_DYNAMIC_CLASS(wxComboBox, wxControl)
29#endif
30
37f214d5 31bool 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
60bool 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)
0e320a79 68{
37f214d5
DW
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;
0e320a79
DW
135}
136
137void wxComboBox::SetValue(const wxString& value)
138{
37f214d5
DW
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);
0e320a79
DW
168}
169
170// Clipboard operations
171void wxComboBox::Copy()
172{
37f214d5
DW
173 HWND hWnd = GetHwnd();
174// SendMessage(hWnd, WM_COPY, 0, 0L);
0e320a79
DW
175}
176
177void wxComboBox::Cut()
178{
37f214d5
DW
179 HWND hWnd = GetHwnd();
180// SendMessage(hWnd, WM_CUT, 0, 0L);
0e320a79
DW
181}
182
183void wxComboBox::Paste()
184{
37f214d5
DW
185 HWND hWnd = GetHwnd();
186// SendMessage(hWnd, WM_PASTE, 0, 0L);
0e320a79
DW
187}
188
189void wxComboBox::SetEditable(bool editable)
190{
37f214d5
DW
191 // Can't implement in MSW?
192// HWND hWnd = GetHwnd();
193// SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
0e320a79
DW
194}
195
196void wxComboBox::SetInsertionPoint(long pos)
197{
37f214d5
DW
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*/
0e320a79
DW
205}
206
207void wxComboBox::SetInsertionPointEnd()
208{
37f214d5
DW
209/*
210 long pos = GetLastPosition();
211 SetInsertionPoint(pos);
212*/
0e320a79
DW
213}
214
215long wxComboBox::GetInsertionPoint() const
216{
37f214d5
DW
217/*
218 DWORD Pos=(DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
219 return Pos&0xFFFF;
220*/
221 return 0;
0e320a79
DW
222}
223
224long wxComboBox::GetLastPosition() const
225{
37f214d5
DW
226/*
227 HWND hWnd = GetHwnd();
0e320a79 228
37f214d5
DW
229 // Will always return a number > 0 (according to docs)
230 int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
0e320a79 231
37f214d5
DW
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);
0e320a79 234
37f214d5
DW
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);
0e320a79 238
37f214d5
DW
239 return (long)(charIndex + lineLength);
240*/
241 return 0;
0e320a79
DW
242}
243
37f214d5 244void wxComboBox::Replace(long from, long to, const wxString& value)
0e320a79 245{
37f214d5
DW
246#if wxUSE_CLIPBOARD
247 HWND hWnd = GetHwnd();
248 long fromChar = from;
249 long toChar = to;
0e320a79 250
37f214d5
DW
251 // Set selection and remove it
252// SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
253// SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
0e320a79 254
37f214d5
DW
255 // Now replace with 'value', by pasting.
256 wxSetClipboardData(wxDF_TEXT, (wxObject *)(const wxChar *)value, 0, 0);
0e320a79 257
37f214d5
DW
258 // Paste into edit control
259// SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L);
260#endif
0e320a79
DW
261}
262
37f214d5 263void wxComboBox::Remove(long from, long to)
0e320a79 264{
37f214d5
DW
265 HWND hWnd = GetHwnd();
266 long fromChar = from;
267 long toChar = to;
0e320a79 268
37f214d5
DW
269 // Cut all selected text
270// SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
271// SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
0e320a79
DW
272}
273
37f214d5 274void wxComboBox::SetSelection(long from, long to)
0e320a79 275{
37f214d5
DW
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);
0e320a79
DW
290}
291
37f214d5
DW
292void wxComboBox::DoSetSize(int x, int y,
293 int width, int height,
294 int sizeFlags)
0e320a79 295{
37f214d5 296 wxControl::DoSetSize(x, y, width, height, sizeFlags);
0e320a79 297}
37f214d5
DW
298
299#endif
300 // wxUSE_COMBOBOX
301