]>
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
[],
67 # if defined(__VISAGECPP__)
68 const wxValidator
* validator
,
70 const wxValidator
& validator
,
77 SetValidator(validator
);
79 if (parent
) parent
->AddChild(this);
80 SetBackgroundColour(parent
->GetBackgroundColour()) ;
81 SetForegroundColour(parent
->GetForegroundColour()) ;
83 m_windowStyle
= style
;
86 m_windowId
= (int)NewControlId();
96 long msStyle = WS_CHILD | WS_TABSTOP | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
99 if (m_windowStyle & wxCB_READONLY)
100 msStyle |= CBS_DROPDOWNLIST;
101 else if (m_windowStyle & wxCB_SIMPLE)
102 msStyle |= CBS_SIMPLE; // A list (shown always) and edit control
104 msStyle |= CBS_DROPDOWN;
106 if (m_windowStyle & wxCB_SORT)
110 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
112 // Even with extended styles, need to combine with WS_BORDER
113 // for them to look right.
114 if ( want3D || wxStyleHasBorder(m_windowStyle) )
115 msStyle |= WS_BORDER;
117 m_hWnd = (WXHWND)::CreateWindowEx(exStyle, wxT("COMBOBOX"), NULL,
119 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
120 wxGetInstance(), NULL);
122 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create combobox") );
124 // Subclass again for purposes of dialog editing mode
127 SetFont(parent->GetFont());
129 for (i = 0; i < n; i++)
136 SetSize(x, y, width, height);
137 if ( !value.IsEmpty() )
145 void wxComboBox::SetValue(const wxString
& value
)
147 // If newlines are denoted by just 10, must stick 13 in front.
149 int len
= value
.Length();
151 for (i
= 0; i
< len
; i
++)
153 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
158 wxChar
*tmp
= new wxChar
[len
+ singletons
+ 1];
160 for (i
= 0; i
< len
; i
++)
162 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
171 // SetWindowText(GetHwnd(), tmp);
175 // SetWindowText(GetHwnd(), value);
178 // Clipboard operations
179 void wxComboBox::Copy()
181 HWND hWnd
= GetHwnd();
182 // SendMessage(hWnd, WM_COPY, 0, 0L);
185 void wxComboBox::Cut()
187 HWND hWnd
= GetHwnd();
188 // SendMessage(hWnd, WM_CUT, 0, 0L);
191 void wxComboBox::Paste()
193 HWND hWnd
= GetHwnd();
194 // SendMessage(hWnd, WM_PASTE, 0, 0L);
197 void wxComboBox::SetEditable(bool editable
)
199 // Can't implement in MSW?
200 // HWND hWnd = GetHwnd();
201 // SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
204 void wxComboBox::SetInsertionPoint(long pos
)
207 HWND hWnd = GetHwnd();
208 SendMessage(hWnd, EM_SETSEL, pos, pos);
209 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
211 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing);
215 void wxComboBox::SetInsertionPointEnd()
218 long pos = GetLastPosition();
219 SetInsertionPoint(pos);
223 long wxComboBox::GetInsertionPoint() const
226 DWORD Pos=(DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
232 long wxComboBox::GetLastPosition() const
235 HWND hWnd = GetHwnd();
237 // Will always return a number > 0 (according to docs)
238 int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
240 // This gets the char index for the _beginning_ of the last line
241 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)(noLines-1), (LPARAM)0L);
243 // Get number of characters in the last line. We'll add this to the character
244 // index for the last line, 1st position.
245 int lineLength = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0L);
247 return (long)(charIndex + lineLength);
252 void wxComboBox::Replace(long from
, long to
, const wxString
& value
)
255 HWND hWnd
= GetHwnd();
256 long fromChar
= from
;
259 // Set selection and remove it
260 // SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
261 // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
263 // Now replace with 'value', by pasting.
264 wxSetClipboardData(wxDF_TEXT
, (wxObject
*)(const wxChar
*)value
, 0, 0);
266 // Paste into edit control
267 // SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L);
271 void wxComboBox::Remove(long from
, long to
)
273 HWND hWnd
= GetHwnd();
274 long fromChar
= from
;
277 // Cut all selected text
278 // SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
279 // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
282 void wxComboBox::SetSelection(long from
, long to
)
284 HWND hWnd
= GetHwnd();
285 long fromChar
= from
;
287 // if from and to are both -1, it means
288 // (in wxWindows) that all text should be selected.
289 // This translates into Windows convention
290 if ((from
== -1) && (to
== -1))
296 // SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)fromChar, (LPARAM)toChar);
297 // SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
300 void wxComboBox::DoSetSize(int x
, int y
,
301 int width
, int height
,
304 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);