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" 
  21 #include "wx/os2/private.h" 
  23 IMPLEMENT_DYNAMIC_CLASS(wxChoice
, wxControl
) 
  25 bool wxChoice::Create( 
  31 , const wxString                    asChoices
[] 
  34 , const wxValidator
&                rValidator
 
  36 , const wxString
&                   rsName
 
  41     if (!OS2CreateControl( pParent
 
  52     lSstyle 
= CBS_DROPDOWNLIST 
| 
  56     if (lStyle 
& wxCLIP_SIBLINGS 
) 
  57         lSstyle 
|= WS_CLIPSIBLINGS
; 
  59     wxASSERT_MSG( !(lStyle 
& wxCB_DROPDOWN
) && 
  60                   !(lStyle 
& wxCB_READONLY
) && 
  61                   !(lStyle 
& wxCB_SIMPLE
), 
  62                   wxT("this style flag is ignored by wxChoice, you " 
  63                      "probably want to use a wxComboBox") ); 
  65     if (!OS2CreateControl( wxT("COMBOBOX") 
  71     // A choice/combobox normally has a white background (or other, depending 
  72     // on global settings) rather than inheriting the parent's background colour. 
  74     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
)); 
  75     for (int i 
= 0; i 
< n
; i
++) 
  86 } // end of wxChoice::Create 
  88 // ---------------------------------------------------------------------------- 
  89 // adding/deleting items to/from the list 
  90 // ---------------------------------------------------------------------------- 
  92 int wxChoice::DoAppend( 
  93   const wxString
&                   rsItem
 
  99     if (m_windowStyle 
& wxLB_SORT
) 
 100         nIndexType 
= LIT_SORTASCENDING
; 
 102         nIndexType 
= LIT_END
; 
 103     nIndex 
= (int)::WinSendMsg( GetHwnd() 
 106                                ,(MPARAM
)rsItem
.c_str() 
 109 } // end of wxChoice::DoAppend 
 111 void wxChoice::Delete( 
 115     wxCHECK_RET( n 
< GetCount(), wxT("invalid item index in wxChoice::Delete") ); 
 116     ::WinSendMsg(GetHwnd(), LM_DELETEITEM
, (MPARAM
)n
, (MPARAM
)0); 
 117 } // end of wxChoice::Delete 
 119 void wxChoice::Clear() 
 122     ::WinSendMsg(GetHwnd(), LM_DELETEALL
, (MPARAM
)0, (MPARAM
)0); 
 123 } // end of wxChoice::Clear 
 125 // ---------------------------------------------------------------------------- 
 127 // ---------------------------------------------------------------------------- 
 129 int wxChoice::GetSelection() const 
 131     return((int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYSELECTION
, (MPARAM
)LIT_FIRST
, (MPARAM
)0))); 
 132 } // end of wxChoice::GetSelection 
 134 void wxChoice::SetSelection( 
 138     ::WinSendMsg( GetHwnd() 
 143 } // end of wxChoice::SetSelection 
 145 // ---------------------------------------------------------------------------- 
 146 // string list functions 
 147 // ---------------------------------------------------------------------------- 
 149 int wxChoice::GetCount() const 
 151     return((int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMCOUNT
, (MPARAM
)0, (MPARAM
)0))); 
 152 } // end of wxChoice::GetCount 
 154 int wxChoice::FindString( 
 155   const wxString
&                   rsStr
 
 163     nItemCount 
= (int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMCOUNT
, (MPARAM
)0, (MPARAM
)0)); 
 164     for (nPos 
= 0; nPos 
< nItemCount
; nPos
++) 
 166         nTextLength 
= (int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH
, (MPARAM
)nPos
, (MPARAM
)0)); 
 167         zStr 
= new char[nTextLength 
+ 1]; 
 168         ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT
, MPFROM2SHORT((SHORT
)nPos
, (SHORT
)nTextLength
), (MPARAM
)zStr
); 
 169         if (rsStr 
== (char*)zStr
) 
 177 } // end of wxChoice::FindString 
 179 void wxChoice::SetString( 
 181 , const wxString
&                   rsStr
 
 184     wxFAIL_MSG(wxT("not implemented")); 
 186 #if 0 // should do this, but no Insert() so far 
 190 } // end of wxChoice::SetString 
 192 wxString 
wxChoice::GetString( 
 200     nLen 
= (size_t)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH
, (MPARAM
)n
, (MPARAM
)0)); 
 203         zBuf 
= new char[nLen 
+ 1]; 
 204         ::WinSendMsg( GetHwnd() 
 206                      ,MPFROM2SHORT((SHORT
)n
, (SHORT
)nLen
) 
 213 } // end of wxChoice::GetString 
 215 // ---------------------------------------------------------------------------- 
 217 // ---------------------------------------------------------------------------- 
 219 void wxChoice::DoSetItemClientData( 
 224     ::WinSendMsg(GetHwnd(), LM_SETITEMHANDLE
, (MPARAM
)n
, MPFROMP(pClientData
)); 
 225 } // end of wxChoice::DoSetItemClientData 
 227 void* wxChoice::DoGetItemClientData( int n 
) const 
 231     rc 
= ::WinSendMsg(GetHwnd(), LM_QUERYITEMHANDLE
, (MPARAM
)n
, (MPARAM
)0); 
 233 } // end of wxChoice::DoSetItemClientData 
 235 void wxChoice::DoSetItemClientObject( 
 237 , wxClientData
*                     pClientData
 
 240     DoSetItemClientData( n
 
 243 } // end of wxChoice::DoSetItemClientObject 
 245 wxClientData
* wxChoice::DoGetItemClientObject( 
 249     return (wxClientData 
*)DoGetItemClientData(n
); 
 250 } // end of wxChoice::DoGetItemClientObject 
 252 // ---------------------------------------------------------------------------- 
 253 // wxOS2 specific helpers 
 254 // ---------------------------------------------------------------------------- 
 256 void wxChoice::DoSetSize( 
 265     // Ignore height parameter because height doesn't mean 'initially 
 266     // displayed' height, it refers to the drop-down menu as well. The 
 267     // wxWindows interpretation is different; also, getting the size returns 
 268     // the _displayed_ size (NOT the drop down menu size) so 
 269     // setting-getting-setting size would not work. 
 271     wxControl::DoSetSize( nX
 
 277 } // end of wxChoice::DoSetSize 
 279 wxSize 
wxChoice::DoGetBestSize() const 
 282     // Find the widest string 
 285     int                             nChoiceWidth 
= 0; 
 286     int                             nItems 
= GetCount(); 
 290     for (int i 
= 0; i 
< nItems
; i
++) 
 292         wxString                    
sStr(GetString(i
)); 
 298         if (nLineWidth 
> nChoiceWidth
) 
 299             nChoiceWidth 
= nLineWidth
; 
 303     // Give it some reasonable default value if there are no strings in the 
 306     if (nChoiceWidth 
== 0L) 
 310     // The combobox should be larger than the widest string 
 312     wxGetCharSize( GetHWND() 
 317     nChoiceWidth 
+= 5 * nCx
; 
 320     // Choice drop-down list depends on number of items (limited to 10) 
 322     size_t                          nStrings 
= nItems 
== 0 ? 10 : wxMin(10, nItems
) + 1; 
 323     int                             nChoiceHeight 
= EDIT_HEIGHT_FROM_CHAR_HEIGHT(nCy
) * nStrings
; 
 325     return wxSize( nChoiceWidth
 
 328 } // end of wxChoice::DoGetBestSize 
 330 MRESULT 
wxChoice::OS2WindowProc( 
 336     return wxWindow::OS2WindowProc( uMsg
 
 340 } // end of wxChoice::OS2WindowProc 
 342 bool wxChoice::OS2Command( 
 344 , WXWORD                            
WXUNUSED(wId
) 
 347     if (uParam 
!= LN_SELECT
) 
 350         // "selection changed" is the only event we're after 
 354     int                             n 
= GetSelection(); 
 358         wxCommandEvent              
vEvent( wxEVT_COMMAND_CHOICE_SELECTED
 
 363         vEvent
.SetEventObject(this); 
 364         vEvent
.SetString((char*)GetStringSelection().c_str()); 
 365         if (HasClientObjectData()) 
 366             vEvent
.SetClientObject(GetClientObject(n
)); 
 367         else if (HasClientUntypedData()) 
 368             vEvent
.SetClientData(GetClientData(n
)); 
 369         ProcessCommand(vEvent
); 
 372 } // end of wxChoice::OS2Command 
 374 void wxChoice::Free() 
 376     if (HasClientObjectData()) 
 378         size_t                      nCount 
= GetCount(); 
 380         for (size_t n 
= 0; n 
< nCount
; n
++) 
 382             delete GetClientObject(n
); 
 385 } // end of wxhoice::Free