1 /////////////////////////////////////////////////////////////////////////////
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"
16 #include "wx/choice.h"
19 #include "wx/settings.h"
22 #include "wx/os2/private.h"
24 IMPLEMENT_DYNAMIC_CLASS(wxChoice
, wxControl
)
26 bool wxChoice::Create(
32 , const wxString asChoices
[]
35 , const wxValidator
& rValidator
37 , const wxString
& rsName
42 if (!OS2CreateControl( pParent
53 lSstyle
= CBS_DROPDOWNLIST
|
57 if (lStyle
& wxCLIP_SIBLINGS
)
58 lSstyle
|= WS_CLIPSIBLINGS
;
60 wxASSERT_MSG( !(lStyle
& wxCB_DROPDOWN
) &&
61 !(lStyle
& wxCB_READONLY
) &&
62 !(lStyle
& wxCB_SIMPLE
),
63 wxT("this style flag is ignored by wxChoice, you "
64 "probably want to use a wxComboBox") );
66 if (!OS2CreateControl( wxT("COMBOBOX")
72 // A choice/combobox normally has a white background (or other, depending
73 // on global settings) rather than inheriting the parent's background colour.
75 SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
76 for (int i
= 0; i
< n
; i
++)
87 } // end of wxChoice::Create
89 // ----------------------------------------------------------------------------
90 // adding/deleting items to/from the list
91 // ----------------------------------------------------------------------------
93 int wxChoice::DoAppend(
94 const wxString
& rsItem
100 if (m_windowStyle
& wxLB_SORT
)
101 nIndexType
= LIT_SORTASCENDING
;
103 nIndexType
= LIT_END
;
104 nIndex
= (int)::WinSendMsg( GetHwnd()
107 ,(MPARAM
)rsItem
.c_str()
110 } // end of wxChoice::DoAppend
112 void wxChoice::Delete(
116 wxCHECK_RET( n
< GetCount(), wxT("invalid item index in wxChoice::Delete") );
117 ::WinSendMsg(GetHwnd(), LM_DELETEITEM
, (MPARAM
)n
, (MPARAM
)0);
118 } // end of wxChoice::Delete
120 void wxChoice::Clear()
123 ::WinSendMsg(GetHwnd(), LM_DELETEALL
, (MPARAM
)0, (MPARAM
)0);
124 } // end of wxChoice::Clear
126 // ----------------------------------------------------------------------------
128 // ----------------------------------------------------------------------------
130 int wxChoice::GetSelection() const
132 return((int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION
, (MPARAM
)LIT_FIRST
, (MPARAM
)0)));
133 } // end of wxChoice::GetSelection
135 void wxChoice::SetSelection(
139 ::WinSendMsg( GetHwnd()
144 } // end of wxChoice::SetSelection
146 // ----------------------------------------------------------------------------
147 // string list functions
148 // ----------------------------------------------------------------------------
150 int wxChoice::GetCount() const
152 return((int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMCOUNT
, (MPARAM
)0, (MPARAM
)0)));
153 } // end of wxChoice::GetCount
155 int wxChoice::FindString(
156 const wxString
& rsStr
164 nItemCount
= (int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMCOUNT
, (MPARAM
)0, (MPARAM
)0));
165 for (nPos
= 0; nPos
< nItemCount
; nPos
++)
167 nTextLength
= (int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH
, (MPARAM
)nPos
, (MPARAM
)0));
168 zStr
= new char[nTextLength
+ 1];
169 ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT
, MPFROM2SHORT((SHORT
)nPos
, (SHORT
)nTextLength
), (MPARAM
)zStr
);
170 if (rsStr
== (char*)zStr
)
178 } // end of wxChoice::FindString
180 void wxChoice::SetString(
182 , const wxString
& rsStr
185 wxFAIL_MSG(wxT("not implemented"));
187 #if 0 // should do this, but no Insert() so far
191 } // end of wxChoice::SetString
193 wxString
wxChoice::GetString(
201 nLen
= (size_t)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH
, (MPARAM
)n
, (MPARAM
)0));
204 zBuf
= new char[nLen
+ 1];
205 ::WinSendMsg( GetHwnd()
207 ,MPFROM2SHORT((SHORT
)n
, (SHORT
)nLen
)
214 } // end of wxChoice::GetString
216 // ----------------------------------------------------------------------------
218 // ----------------------------------------------------------------------------
220 void wxChoice::DoSetItemClientData(
225 ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE
, (MPARAM
)n
, MPFROMP(pClientData
));
226 } // end of wxChoice::DoSetItemClientData
228 void* wxChoice::DoGetItemClientData( int n
) const
232 rc
= ::WinSendMsg(GetHwnd(), LM_QUERYITEMHANDLE
, (MPARAM
)n
, (MPARAM
)0);
234 } // end of wxChoice::DoSetItemClientData
236 void wxChoice::DoSetItemClientObject(
238 , wxClientData
* pClientData
241 DoSetItemClientData( n
244 } // end of wxChoice::DoSetItemClientObject
246 wxClientData
* wxChoice::DoGetItemClientObject(
250 return (wxClientData
*)DoGetItemClientData(n
);
251 } // end of wxChoice::DoGetItemClientObject
253 // ----------------------------------------------------------------------------
254 // wxOS2 specific helpers
255 // ----------------------------------------------------------------------------
257 void wxChoice::DoSetSize(
266 // Ignore height parameter because height doesn't mean 'initially
267 // displayed' height, it refers to the drop-down menu as well. The
268 // wxWindows interpretation is different; also, getting the size returns
269 // the _displayed_ size (NOT the drop down menu size) so
270 // setting-getting-setting size would not work.
272 wxControl::DoSetSize( nX
278 } // end of wxChoice::DoSetSize
280 wxSize
wxChoice::DoGetBestSize() const
283 // Find the widest string
286 int nChoiceWidth
= 0;
287 int nItems
= GetCount();
291 for (int i
= 0; i
< nItems
; i
++)
293 wxString
sStr(GetString(i
));
299 if (nLineWidth
> nChoiceWidth
)
300 nChoiceWidth
= nLineWidth
;
304 // Give it some reasonable default value if there are no strings in the
307 if (nChoiceWidth
== 0L)
311 // The combobox should be larger than the widest string
313 wxGetCharSize( GetHWND()
318 nChoiceWidth
+= 5 * nCx
;
321 // Choice drop-down list depends on number of items (limited to 10)
323 size_t nStrings
= nItems
== 0 ? 10 : wxMin(10, nItems
) + 1;
324 int nChoiceHeight
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * nStrings
;
326 return wxSize( nChoiceWidth
329 } // end of wxChoice::DoGetBestSize
331 MRESULT
wxChoice::OS2WindowProc(
337 return wxWindow::OS2WindowProc( uMsg
341 } // end of wxChoice::OS2WindowProc
343 bool wxChoice::OS2Command(
345 , WXWORD
WXUNUSED(wId
)
348 if (uParam
!= LN_SELECT
)
351 // "selection changed" is the only event we're after
355 int n
= GetSelection();
359 wxCommandEvent
vEvent( wxEVT_COMMAND_CHOICE_SELECTED
364 vEvent
.SetEventObject(this);
365 vEvent
.SetString((char*)GetStringSelection().c_str());
366 if (HasClientObjectData())
367 vEvent
.SetClientObject(GetClientObject(n
));
368 else if (HasClientUntypedData())
369 vEvent
.SetClientData(GetClientData(n
));
370 ProcessCommand(vEvent
);
373 } // end of wxChoice::OS2Command
375 void wxChoice::Free()
377 if (HasClientObjectData())
379 size_t nCount
= GetCount();
381 for (size_t n
= 0; n
< nCount
; n
++)
383 delete GetClientObject(n
);
386 } // end of wxhoice::Free