]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/combobox.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxComboBox class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/combobox.h"
14 // For compilers that support precompilation, includes "wx.h".
15 #include "wx/wxprec.h"
23 #include "wx/combobox.h"
24 #include "wx/clipbrd.h"
25 #include "wx/os2/private.h"
27 #if !USE_SHARED_LIBRARY
28 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
)
31 bool wxComboBox::OS2Command(WXUINT param
, WXWORD
WXUNUSED(id
))
35 if (param == CBN_SELCHANGE)
37 wxCommandEvent event(wxEVT_COMMAND_COMBOBOX_SELECTED, m_windowId);
38 event.SetInt(GetSelection());
39 event.SetEventObject(this);
40 event.SetString(GetStringSelection());
41 ProcessCommand(event);
45 else if (param == CBN_EDITCHANGE)
47 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, m_windowId);
48 event.SetString(GetValue());
49 event.SetEventObject(this);
50 ProcessCommand(event);
60 bool wxComboBox::Create(wxWindow
*parent
, wxWindowID id
,
61 const wxString
& value
,
64 int n
, const wxString choices
[],
66 const wxValidator
& validator
,
70 SetValidator(validator
);
71 if (parent
) parent
->AddChild(this);
72 SetBackgroundColour(parent
->GetBackgroundColour()) ;
73 SetForegroundColour(parent
->GetForegroundColour()) ;
75 m_windowStyle
= style
;
78 m_windowId
= (int)NewControlId();
88 long msStyle = WS_CHILD | WS_TABSTOP | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
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
96 msStyle |= CBS_DROPDOWN;
98 if (m_windowStyle & wxCB_SORT)
102 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
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;
109 m_hWnd = (WXHWND)::CreateWindowEx(exStyle, wxT("COMBOBOX"), NULL,
111 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
112 wxGetInstance(), NULL);
114 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create combobox") );
116 // Subclass again for purposes of dialog editing mode
119 SetFont(parent->GetFont());
121 for (i = 0; i < n; i++)
128 SetSize(x, y, width, height);
129 if ( !value.IsEmpty() )
137 void wxComboBox::SetValue(const wxString
& value
)
139 // If newlines are denoted by just 10, must stick 13 in front.
141 int len
= value
.Length();
143 for (i
= 0; i
< len
; i
++)
145 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
150 wxChar
*tmp
= new wxChar
[len
+ singletons
+ 1];
152 for (i
= 0; i
< len
; i
++)
154 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
163 // SetWindowText(GetHwnd(), tmp);
167 // SetWindowText(GetHwnd(), value);
170 // Clipboard operations
171 void wxComboBox::Copy()
173 HWND hWnd
= GetHwnd();
174 // SendMessage(hWnd, WM_COPY, 0, 0L);
177 void wxComboBox::Cut()
179 HWND hWnd
= GetHwnd();
180 // SendMessage(hWnd, WM_CUT, 0, 0L);
183 void wxComboBox::Paste()
185 HWND hWnd
= GetHwnd();
186 // SendMessage(hWnd, WM_PASTE, 0, 0L);
189 void wxComboBox::SetEditable(bool editable
)
191 // Can't implement in MSW?
192 // HWND hWnd = GetHwnd();
193 // SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
196 void wxComboBox::SetInsertionPoint(long pos
)
199 HWND hWnd = GetHwnd();
200 SendMessage(hWnd, EM_SETSEL, pos, pos);
201 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
203 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing);
207 void wxComboBox::SetInsertionPointEnd()
210 long pos = GetLastPosition();
211 SetInsertionPoint(pos);
215 long wxComboBox::GetInsertionPoint() const
218 DWORD Pos=(DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
224 long wxComboBox::GetLastPosition() const
227 HWND hWnd = GetHwnd();
229 // Will always return a number > 0 (according to docs)
230 int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
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);
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);
239 return (long)(charIndex + lineLength);
244 void wxComboBox::Replace(long from
, long to
, const wxString
& value
)
247 HWND hWnd
= GetHwnd();
248 long fromChar
= from
;
251 // Set selection and remove it
252 // SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
253 // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
255 // Now replace with 'value', by pasting.
256 wxSetClipboardData(wxDF_TEXT
, (wxObject
*)(const wxChar
*)value
, 0, 0);
258 // Paste into edit control
259 // SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L);
263 void wxComboBox::Remove(long from
, long to
)
265 HWND hWnd
= GetHwnd();
266 long fromChar
= from
;
269 // Cut all selected text
270 // SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
271 // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
274 void wxComboBox::SetSelection(long from
, long to
)
276 HWND hWnd
= GetHwnd();
277 long fromChar
= from
;
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))
288 // SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)fromChar, (LPARAM)toChar);
289 // SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
292 void wxComboBox::DoSetSize(int x
, int y
,
293 int width
, int height
,
296 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);