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     SHORT                           nIndexType 
= 0; 
 193     ::WinSendMsg(GetHwnd(), LM_DELETEITEM
, (MPARAM
)n
, 0); 
 195     if (m_windowStyle 
& wxLB_SORT
) 
 196         nIndexType 
= LIT_SORTASCENDING
; 
 198         nIndexType 
= LIT_END
; 
 199     ::WinSendMsg( GetHwnd() 
 202                  ,(MPARAM
)rsStr
.c_str() 
 204 } // end of wxChoice::SetString 
 206 wxString 
wxChoice::GetString( 
 214     nLen 
= (size_t)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH
, (MPARAM
)n
, (MPARAM
)0)); 
 217         zBuf 
= new char[nLen 
+ 1]; 
 218         ::WinSendMsg( GetHwnd() 
 220                      ,MPFROM2SHORT((SHORT
)n
, (SHORT
)nLen
) 
 227 } // end of wxChoice::GetString 
 229 // ---------------------------------------------------------------------------- 
 231 // ---------------------------------------------------------------------------- 
 233 void wxChoice::DoSetItemClientData( 
 238     ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE
, (MPARAM
)n
, MPFROMP(pClientData
)); 
 239 } // end of wxChoice::DoSetItemClientData 
 241 void* wxChoice::DoGetItemClientData( int n 
) const 
 245     rc 
= ::WinSendMsg(GetHwnd(), LM_QUERYITEMHANDLE
, (MPARAM
)n
, (MPARAM
)0); 
 247 } // end of wxChoice::DoSetItemClientData 
 249 void wxChoice::DoSetItemClientObject( 
 251 , wxClientData
*                     pClientData
 
 254     DoSetItemClientData( n
 
 257 } // end of wxChoice::DoSetItemClientObject 
 259 wxClientData
* wxChoice::DoGetItemClientObject( 
 263     return (wxClientData 
*)DoGetItemClientData(n
); 
 264 } // end of wxChoice::DoGetItemClientObject 
 266 // ---------------------------------------------------------------------------- 
 267 // wxOS2 specific helpers 
 268 // ---------------------------------------------------------------------------- 
 270 void wxChoice::DoSetSize( 
 279     // Ignore height parameter because height doesn't mean 'initially 
 280     // displayed' height, it refers to the drop-down menu as well. The 
 281     // wxWindows interpretation is different; also, getting the size returns 
 282     // the _displayed_ size (NOT the drop down menu size) so 
 283     // setting-getting-setting size would not work. 
 285     wxControl::DoSetSize( nX
 
 291 } // end of wxChoice::DoSetSize 
 293 wxSize 
wxChoice::DoGetBestSize() const 
 296     // Find the widest string 
 299     int                             nChoiceWidth 
= 0; 
 300     int                             nItems 
= GetCount(); 
 304     for (int i 
= 0; i 
< nItems
; i
++) 
 306         wxString                    
sStr(GetString(i
)); 
 312         if (nLineWidth 
> nChoiceWidth
) 
 313             nChoiceWidth 
= nLineWidth
; 
 317     // Give it some reasonable default value if there are no strings in the 
 320     if (nChoiceWidth 
== 0L) 
 324     // The combobox should be larger than the widest string 
 326     wxGetCharSize( GetHWND() 
 331     nChoiceWidth 
+= 5 * nCx
; 
 334     // Choice drop-down list depends on number of items (limited to 10) 
 336     size_t                          nStrings 
= nItems 
== 0 ? 10 : wxMin(10, nItems
) + 1; 
 337     int                             nChoiceHeight 
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * nStrings
; 
 339     return wxSize( nChoiceWidth
 
 342 } // end of wxChoice::DoGetBestSize 
 344 MRESULT 
wxChoice::OS2WindowProc( 
 350     return wxWindow::OS2WindowProc( uMsg
 
 354 } // end of wxChoice::OS2WindowProc 
 356 bool wxChoice::OS2Command( 
 358 , WXWORD                            
WXUNUSED(wId
) 
 361     if (uParam 
!= LN_SELECT
) 
 364         // "selection changed" is the only event we're after 
 368     int                             n 
= GetSelection(); 
 372         wxCommandEvent              
vEvent( wxEVT_COMMAND_CHOICE_SELECTED
 
 377         vEvent
.SetEventObject(this); 
 378         vEvent
.SetString((char*)GetStringSelection().c_str()); 
 379         if (HasClientObjectData()) 
 380             vEvent
.SetClientObject(GetClientObject(n
)); 
 381         else if (HasClientUntypedData()) 
 382             vEvent
.SetClientData(GetClientData(n
)); 
 383         ProcessCommand(vEvent
); 
 386 } // end of wxChoice::OS2Command 
 388 void wxChoice::Free() 
 390     if (HasClientObjectData()) 
 392         size_t                      nCount 
= GetCount(); 
 394         for (size_t n 
= 0; n 
< nCount
; n
++) 
 396             delete GetClientObject(n
); 
 399 } // end of wxhoice::Free