]>
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 const wxValidator
& validator
,
73 SetValidator(validator
);
75 if (parent
) parent
->AddChild(this);
76 SetBackgroundColour(parent
->GetBackgroundColour()) ;
77 SetForegroundColour(parent
->GetForegroundColour()) ;
79 m_windowStyle
= style
;
82 m_windowId
= (int)NewControlId();
92 long msStyle = WS_CHILD | WS_TABSTOP | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
95 if (m_windowStyle & wxCB_READONLY)
96 msStyle |= CBS_DROPDOWNLIST;
97 else if (m_windowStyle & wxCB_SIMPLE)
98 msStyle |= CBS_SIMPLE; // A list (shown always) and edit control
100 msStyle |= CBS_DROPDOWN;
102 if (m_windowStyle & wxCB_SORT)
106 WXDWORD exStyle = Determine3DEffects(WS_EX_CLIENTEDGE, &want3D) ;
108 // Even with extended styles, need to combine with WS_BORDER
109 // for them to look right.
110 if ( want3D || wxStyleHasBorder(m_windowStyle) )
111 msStyle |= WS_BORDER;
113 m_hWnd = (WXHWND)::CreateWindowEx(exStyle, wxT("COMBOBOX"), NULL,
115 0, 0, 0, 0, (HWND) parent->GetHWND(), (HMENU)m_windowId,
116 wxGetInstance(), NULL);
118 wxCHECK_MSG( m_hWnd, FALSE, wxT("Failed to create combobox") );
120 // Subclass again for purposes of dialog editing mode
123 SetFont(parent->GetFont());
125 for (i = 0; i < n; i++)
132 SetSize(x, y, width, height);
133 if ( !value.IsEmpty() )
141 void wxComboBox::SetValue(const wxString
& value
)
143 // If newlines are denoted by just 10, must stick 13 in front.
145 int len
= value
.Length();
147 for (i
= 0; i
< len
; i
++)
149 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
154 wxChar
*tmp
= new wxChar
[len
+ singletons
+ 1];
156 for (i
= 0; i
< len
; i
++)
158 if ((i
> 0) && (value
[i
] == 10) && (value
[i
-1] != 13))
167 // SetWindowText(GetHwnd(), tmp);
171 // SetWindowText(GetHwnd(), value);
174 // Clipboard operations
175 void wxComboBox::Copy()
177 HWND hWnd
= GetHwnd();
178 // SendMessage(hWnd, WM_COPY, 0, 0L);
181 void wxComboBox::Cut()
183 HWND hWnd
= GetHwnd();
184 // SendMessage(hWnd, WM_CUT, 0, 0L);
187 void wxComboBox::Paste()
189 HWND hWnd
= GetHwnd();
190 // SendMessage(hWnd, WM_PASTE, 0, 0L);
193 void wxComboBox::SetEditable(bool editable
)
195 // Can't implement in MSW?
196 // HWND hWnd = GetHwnd();
197 // SendMessage(hWnd, EM_SETREADONLY, (WPARAM)!editable, (LPARAM)0L);
200 void wxComboBox::SetInsertionPoint(long pos
)
203 HWND hWnd = GetHwnd();
204 SendMessage(hWnd, EM_SETSEL, pos, pos);
205 SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
207 SendMessage(hWnd, EM_REPLACESEL, 0, (LPARAM)nothing);
211 void wxComboBox::SetInsertionPointEnd()
214 long pos = GetLastPosition();
215 SetInsertionPoint(pos);
219 long wxComboBox::GetInsertionPoint() const
222 DWORD Pos=(DWORD)SendMessage(GetHwnd(), EM_GETSEL, 0, 0L);
228 long wxComboBox::GetLastPosition() const
231 HWND hWnd = GetHwnd();
233 // Will always return a number > 0 (according to docs)
234 int noLines = (int)SendMessage(hWnd, EM_GETLINECOUNT, (WPARAM)0, (LPARAM)0L);
236 // This gets the char index for the _beginning_ of the last line
237 int charIndex = (int)SendMessage(hWnd, EM_LINEINDEX, (WPARAM)(noLines-1), (LPARAM)0L);
239 // Get number of characters in the last line. We'll add this to the character
240 // index for the last line, 1st position.
241 int lineLength = (int)SendMessage(hWnd, EM_LINELENGTH, (WPARAM)charIndex, (LPARAM)0L);
243 return (long)(charIndex + lineLength);
248 void wxComboBox::Replace(long from
, long to
, const wxString
& value
)
251 HWND hWnd
= GetHwnd();
252 long fromChar
= from
;
255 // Set selection and remove it
256 // SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
257 // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
259 // Now replace with 'value', by pasting.
260 wxSetClipboardData(wxDF_TEXT
, (wxObject
*)(const wxChar
*)value
, 0, 0);
262 // Paste into edit control
263 // SendMessage(hWnd, WM_PASTE, (WPARAM)0, (LPARAM)0L);
267 void wxComboBox::Remove(long from
, long to
)
269 HWND hWnd
= GetHwnd();
270 long fromChar
= from
;
273 // Cut all selected text
274 // SendMessage(hWnd, CB_SETEDITSEL, fromChar, toChar);
275 // SendMessage(hWnd, WM_CUT, (WPARAM)0, (LPARAM)0);
278 void wxComboBox::SetSelection(long from
, long to
)
280 HWND hWnd
= GetHwnd();
281 long fromChar
= from
;
283 // if from and to are both -1, it means
284 // (in wxWindows) that all text should be selected.
285 // This translates into Windows convention
286 if ((from
== -1) && (to
== -1))
292 // SendMessage(hWnd, CB_SETEDITSEL, (WPARAM)fromChar, (LPARAM)toChar);
293 // SendMessage(hWnd, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
296 void wxComboBox::DoSetSize(int x
, int y
,
297 int width
, int height
,
300 wxControl::DoSetSize(x
, y
, width
, height
, sizeFlags
);