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
++)
80 wxFont
* pTextFont
= new wxFont( 10
93 } // end of wxChoice::Create
95 // ----------------------------------------------------------------------------
96 // adding/deleting items to/from the list
97 // ----------------------------------------------------------------------------
99 int wxChoice::DoAppend(
100 const wxString
& rsItem
104 SHORT nIndexType
= 0;
106 if (m_windowStyle
& wxLB_SORT
)
107 nIndexType
= LIT_SORTASCENDING
;
109 nIndexType
= LIT_END
;
110 nIndex
= (int)::WinSendMsg( GetHwnd()
113 ,(MPARAM
)rsItem
.c_str()
116 } // end of wxChoice::DoAppend
118 void wxChoice::Delete(
122 wxCHECK_RET( n
< GetCount(), wxT("invalid item index in wxChoice::Delete") );
123 ::WinSendMsg(GetHwnd(), LM_DELETEITEM
, (MPARAM
)n
, (MPARAM
)0);
124 } // end of wxChoice::Delete
126 void wxChoice::Clear()
129 ::WinSendMsg(GetHwnd(), LM_DELETEALL
, (MPARAM
)0, (MPARAM
)0);
130 } // end of wxChoice::Clear
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
136 int wxChoice::GetSelection() const
138 return((int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION
, (MPARAM
)LIT_FIRST
, (MPARAM
)0)));
139 } // end of wxChoice::GetSelection
141 void wxChoice::SetSelection(
145 ::WinSendMsg( GetHwnd()
150 } // end of wxChoice::SetSelection
152 // ----------------------------------------------------------------------------
153 // string list functions
154 // ----------------------------------------------------------------------------
156 int wxChoice::GetCount() const
158 return((int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMCOUNT
, (MPARAM
)0, (MPARAM
)0)));
159 } // end of wxChoice::GetCount
161 int wxChoice::FindString(
162 const wxString
& rsStr
170 nItemCount
= (int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMCOUNT
, (MPARAM
)0, (MPARAM
)0));
171 for (nPos
= 0; nPos
< nItemCount
; nPos
++)
173 nTextLength
= (int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH
, (MPARAM
)nPos
, (MPARAM
)0));
174 zStr
= new char[nTextLength
+ 1];
175 ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT
, MPFROM2SHORT((SHORT
)nPos
, (SHORT
)nTextLength
), (MPARAM
)zStr
);
176 if (rsStr
== (char*)zStr
)
184 } // end of wxChoice::FindString
186 void wxChoice::SetString(
188 , const wxString
& rsStr
191 wxFAIL_MSG(wxT("not implemented"));
193 #if 0 // should do this, but no Insert() so far
197 } // end of wxChoice::SetString
199 wxString
wxChoice::GetString(
207 nLen
= (size_t)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH
, (MPARAM
)n
, (MPARAM
)0));
210 zBuf
= new char[nLen
+ 1];
211 ::WinSendMsg( GetHwnd()
213 ,MPFROM2SHORT((SHORT
)n
, (SHORT
)nLen
)
220 } // end of wxChoice::GetString
222 // ----------------------------------------------------------------------------
224 // ----------------------------------------------------------------------------
226 void wxChoice::DoSetItemClientData(
231 ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE
, (MPARAM
)n
, MPFROMP(pClientData
));
232 } // end of wxChoice::DoSetItemClientData
234 void* wxChoice::DoGetItemClientData( int n
) const
238 rc
= ::WinSendMsg(GetHwnd(), LM_QUERYITEMHANDLE
, (MPARAM
)n
, (MPARAM
)0);
240 } // end of wxChoice::DoSetItemClientData
242 void wxChoice::DoSetItemClientObject(
244 , wxClientData
* pClientData
247 DoSetItemClientData( n
250 } // end of wxChoice::DoSetItemClientObject
252 wxClientData
* wxChoice::DoGetItemClientObject(
256 return (wxClientData
*)DoGetItemClientData(n
);
257 } // end of wxChoice::DoGetItemClientObject
259 // ----------------------------------------------------------------------------
260 // wxOS2 specific helpers
261 // ----------------------------------------------------------------------------
263 void wxChoice::DoSetSize(
272 // Ignore height parameter because height doesn't mean 'initially
273 // displayed' height, it refers to the drop-down menu as well. The
274 // wxWindows interpretation is different; also, getting the size returns
275 // the _displayed_ size (NOT the drop down menu size) so
276 // setting-getting-setting size would not work.
278 wxControl::DoSetSize( nX
284 } // end of wxChoice::DoSetSize
286 wxSize
wxChoice::DoGetBestSize() const
289 // Find the widest string
292 int nChoiceWidth
= 0;
293 int nItems
= GetCount();
297 for (int i
= 0; i
< nItems
; i
++)
299 wxString
sStr(GetString(i
));
305 if (nLineWidth
> nChoiceWidth
)
306 nChoiceWidth
= nLineWidth
;
310 // Give it some reasonable default value if there are no strings in the
313 if (nChoiceWidth
== 0L)
317 // The combobox should be larger than the widest string
319 wxGetCharSize( GetHWND()
324 nChoiceWidth
+= 5 * nCx
;
327 // Choice drop-down list depends on number of items (limited to 10)
329 size_t nStrings
= nItems
== 0 ? 10 : wxMin(10, nItems
) + 1;
330 int nChoiceHeight
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * nStrings
;
332 return wxSize( nChoiceWidth
335 } // end of wxChoice::DoGetBestSize
337 MRESULT
wxChoice::OS2WindowProc(
343 return wxWindow::OS2WindowProc( uMsg
347 } // end of wxChoice::OS2WindowProc
349 bool wxChoice::OS2Command(
351 , WXWORD
WXUNUSED(wId
)
354 if (uParam
!= LN_SELECT
)
357 // "selection changed" is the only event we're after
361 int n
= GetSelection();
365 wxCommandEvent
vEvent( wxEVT_COMMAND_CHOICE_SELECTED
370 vEvent
.SetEventObject(this);
371 vEvent
.SetString((char*)GetStringSelection().c_str());
372 if (HasClientObjectData())
373 vEvent
.SetClientObject(GetClientObject(n
));
374 else if (HasClientUntypedData())
375 vEvent
.SetClientData(GetClientData(n
));
376 ProcessCommand(vEvent
);
379 } // end of wxChoice::OS2Command
381 void wxChoice::Free()
383 if (HasClientObjectData())
385 size_t nCount
= GetCount();
387 for (size_t n
= 0; n
< nCount
; n
++)
389 delete GetClientObject(n
);
392 } // end of wxhoice::Free