1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/combobox.cpp
3 // Purpose: wxComboBox class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
17 #include "wx/combobox.h"
20 #include "wx/settings.h"
23 #include "wx/clipbrd.h"
24 #include "wx/os2/private.h"
26 #define OWNER_DRAWN_LISTBOX_EXTRA_SPACE (1)
28 MRESULT EXPENTRY
wxComboEditWndProc( HWND hWnd
34 // The pointer to standard wnd proc
36 static WXFARPROC gfnWndprocEdit
= (WXFARPROC
)NULL
;
38 IMPLEMENT_DYNAMIC_CLASS(wxComboBox
, wxControl
)
40 bool wxComboBox::OS2Command( WXUINT uParam
, WXWORD
WXUNUSED(wId
) )
42 long lSel
= GetSelection();
50 wxCommandEvent
vEvent( wxEVT_COMMAND_COMBOBOX_SELECTED
, GetId() );
53 vEvent
.SetEventObject(this);
54 vEvent
.SetString(GetStringSelection());
56 ProcessCommand(vEvent
);
62 wxCommandEvent
vEvent( wxEVT_COMMAND_TEXT_UPDATED
, GetId() );
67 sValue
= GetStringSelection();
68 vEvent
.SetString(sValue
);
69 vEvent
.SetEventObject(this);
70 ProcessCommand(vEvent
);
75 // There is no return value for the CBN_ notifications, so always return
76 // false from here to pass the message to DefWindowProc()
79 } // end of wxComboBox::OS2Command
81 bool wxComboBox::Create(
84 , const wxString
& rsValue
87 , const wxArrayString
& asChoices
89 , const wxValidator
& rValidator
90 , const wxString
& rsName
93 wxCArrayString
chs(asChoices
);
95 return Create(pParent
, vId
, rsValue
, rPos
, rSize
, chs
.GetCount(),
96 chs
.GetStrings(), lStyle
, rValidator
, rsName
);
99 bool wxComboBox::Create(
102 , const wxString
& rsValue
103 , const wxPoint
& rPos
104 , const wxSize
& rSize
106 , const wxString asChoices
[]
108 , const wxValidator
& rValidator
109 , const wxString
& rsName
114 if (!CreateControl( pParent
125 // Get the right style
129 lSstyle
= WS_TABSTOP
|
132 // clipping siblings does not yet work
133 // if (lStyle & wxCLIP_SIBLINGS )
134 // lSstyle |= WS_CLIPSIBLINGS;
135 if (lStyle
& wxCB_READONLY
)
136 lSstyle
|= CBS_DROPDOWNLIST
;
137 else if (lStyle
& wxCB_SIMPLE
)
138 lSstyle
|= CBS_SIMPLE
; // A list (shown always) and edit control
140 lSstyle
|= CBS_DROPDOWN
;
143 if (!OS2CreateControl( wxT("COMBOBOX")
149 // A choice/combobox normally has a white background (or other, depending
150 // on global settings) rather than inheriting the parent's background colour.
152 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
154 for (int i
= 0; i
< n
; i
++)
156 Append(asChoices
[i
]);
165 // Set height to use with sizers i.e. without the dropdown listbox
166 wxFont vFont
= GetFont();
168 wxGetCharSize( GetHWND(), NULL
, &nEditHeight
, &vFont
);
169 nEditHeight
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(nEditHeight
);
170 SetInitialSize(wxSize(-1,nEditHeight
+4)); // +2x2 for the border
172 if (!rsValue
.empty())
176 gfnWndprocEdit
= (WXFARPROC
)::WinSubclassWindow( (HWND
)GetHwnd()
177 ,(PFNWP
)wxComboEditWndProc
179 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (ULONG
)this);
182 } // end of wxComboBox::Create
184 wxString
wxComboBox::GetValue() const
186 return HasFlag(wxCB_READONLY
) ? GetStringSelection()
187 : wxTextEntry::GetValue();
190 void wxComboBox::SetValue(const wxString
& value
)
192 if ( HasFlag(wxCB_READONLY
) )
193 SetStringSelection(value
);
195 wxTextEntry::SetValue(value
);
198 void wxComboBox::Clear()
201 if ( !HasFlag(wxCB_READONLY
) )
202 wxTextEntry::Clear();
205 bool wxComboBox::IsEditable() const
207 return !HasFlag(wxCB_READONLY
) && wxTextEntry::IsEditable();
210 bool wxComboBox::ProcessEditMsg(
219 vFlag
= SHORT1FROMMP(wParam
);
223 return (HandleChar( wParam
229 return (HandleKeyDown( wParam
234 return (HandleKeyUp( wParam
241 if (SHORT1FROMMP((MPARAM
)lParam
) == TRUE
)
242 return(HandleSetFocus((WXHWND
)(HWND
)wParam
));
244 return(HandleKillFocus((WXHWND
)(HWND
)wParam
));
247 } // end of wxComboBox::ProcessEditMsg
249 MRESULT EXPENTRY
wxComboEditWndProc(
259 // Forward some messages to the combobox
264 wxComboBox
* pCombo
= (wxComboBox
*)::WinQueryWindowULong( hWnd
268 if (pCombo
->ProcessEditMsg( uMessage
277 // TODO: Deal with tooltips here
280 return (gfnWndprocEdit(hWnd
, (ULONG
)uMessage
, (MPARAM
)wParam
, (MPARAM
)lParam
));
281 } // end of wxComboEditWndProc