X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/312ebad4cd1fad97a79aaed7102611df88806410..8b4457965a0c0d0ef828dbf7cca3d2f947083054:/src/os2/choice.cpp?ds=sidebyside diff --git a/src/os2/choice.cpp b/src/os2/choice.cpp index 5e4d3e4ad2..a6264e0f8d 100644 --- a/src/os2/choice.cpp +++ b/src/os2/choice.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: choice.cpp +// Name: src/os2/choice.cpp // Purpose: wxChoice // Author: David Webster // Modified by: @@ -12,8 +12,6 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" -#include "wx/defs.h" - #if wxUSE_CHOICE #ifndef WX_PRECOMP @@ -94,18 +92,11 @@ bool wxChoice::Create( { Append(asChoices[i]); } - wxFont* pTextFont = new wxFont( 10 - ,wxMODERN - ,wxNORMAL - ,wxNORMAL - ); - SetFont(*pTextFont); SetSize( rPos.x ,rPos.y ,rSize.x ,rSize.y ); - delete pTextFont; return true; } // end of wxChoice::Create @@ -132,19 +123,16 @@ int wxChoice::DoAppend( return nIndex; } // end of wxChoice::DoAppend -int wxChoice::DoInsert( - const wxString& rsItem, - int pos -) +int wxChoice::DoInsert( const wxString& rsItem, int pos ) { wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into sorted list")); - wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index")); + wxCHECK_MSG(IsValidInsert(pos), -1, wxT("invalid index")); - if (pos == GetCount()) + if ((size_t)pos == GetCount()) return DoAppend(rsItem); - int nIndex; - LONG nIndexType = 0; + int nIndex; + LONG nIndexType = 0; if (m_windowStyle & wxLB_SORT) nIndexType = LIT_SORTASCENDING; @@ -158,11 +146,9 @@ int wxChoice::DoInsert( return nIndex; } // end of wxChoice::DoInsert -void wxChoice::Delete( - int n -) +void wxChoice::Delete( int n ) { - wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") ); + wxCHECK_RET( IsValid(n), wxT("invalid item index in wxChoice::Delete") ); ::WinSendMsg(GetHwnd(), LM_DELETEITEM, (MPARAM)n, (MPARAM)0); } // end of wxChoice::Delete @@ -196,43 +182,15 @@ void wxChoice::SetSelection( // string list functions // ---------------------------------------------------------------------------- -int wxChoice::GetCount() const +size_t wxChoice::GetCount() const { - return((int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMCOUNT, (MPARAM)0, (MPARAM)0))); + return((size_t)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMCOUNT, (MPARAM)0, (MPARAM)0))); } // end of wxChoice::GetCount -int wxChoice::FindString( - const wxString& rsStr -) const +void wxChoice::SetString( int n, const wxString& rsStr ) { - int nPos; - int nTextLength; - PSZ zStr; - int nItemCount; - - nItemCount = (int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMCOUNT, (MPARAM)0, (MPARAM)0)); - for (nPos = 0; nPos < nItemCount; nPos++) - { - nTextLength = (int)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH, (MPARAM)nPos, (MPARAM)0)); - zStr = new char[nTextLength + 1]; - ::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXT, MPFROM2SHORT((SHORT)nPos, (SHORT)nTextLength), (MPARAM)zStr); - if (rsStr == (char*)zStr) - { - delete [] zStr; - break; - } - delete [] zStr; - } - return nPos; -} // end of wxChoice::FindString - -void wxChoice::SetString( - int n -, const wxString& rsStr -) -{ - LONG nIndexType = 0; - void* pData; + LONG nIndexType = 0; + void* pData; if ( m_clientDataItemsType != wxClientData_None ) { @@ -263,18 +221,16 @@ void wxChoice::SetString( } } // end of wxChoice::SetString -wxString wxChoice::GetString( - int n -) const +wxString wxChoice::GetString(int n) const { - int nLen = 0; - wxString sStr = ""; - char* zBuf; + int nLen = 0; + wxString sStr = wxEmptyString; + wxChar* zBuf; nLen = (size_t)LONGFROMMR(::WinSendMsg(GetHwnd(), LM_QUERYITEMTEXTLENGTH, (MPARAM)n, (MPARAM)0)); if (nLen != LIT_ERROR && nLen > 0) { - zBuf = new char[nLen + 1]; + zBuf = new wxChar[nLen + 1]; ::WinSendMsg( GetHwnd() ,LM_QUERYITEMTEXT ,MPFROM2SHORT((SHORT)n, (SHORT)nLen) @@ -327,13 +283,11 @@ wxClientData* wxChoice::DoGetItemClientObject( // wxOS2 specific helpers // ---------------------------------------------------------------------------- -void wxChoice::DoSetSize( - int nX -, int nY -, int nWidth -, int nHeight -, int nSizeFlags -) +void wxChoice::DoSetSize(int nX, + int nY, + int nWidth, + int WXUNUSED(nHeight), + int nSizeFlags) { // // Ignore height parameter because height doesn't mean 'initially @@ -345,7 +299,7 @@ void wxChoice::DoSetSize( wxControl::DoSetSize( nX ,nY ,nWidth - ,-1 + ,wxDefaultCoord ,nSizeFlags ); } // end of wxChoice::DoSetSize @@ -355,20 +309,18 @@ wxSize wxChoice::DoGetBestSize() const // // Find the widest string // - int nLineWidth; - int nChoiceWidth = 0; - int nItems = GetCount(); - int nCx; - int nCy; + int nLineWidth; + int nChoiceWidth = 0; + int nCx; + int nCy; + wxFont vFont = (wxFont)GetFont(); - for (int i = 0; i < nItems; i++) - { - wxString sStr(GetString(i)); + const size_t nItems = GetCount(); - GetTextExtent( sStr - ,&nLineWidth - ,NULL - ); + for (size_t i = 0; i < nItems; i++) + { + wxString sStr(GetString(i)); + GetTextExtent( sStr, &nLineWidth, NULL ); if (nLineWidth > nChoiceWidth) nChoiceWidth = nLineWidth; } @@ -383,11 +335,7 @@ wxSize wxChoice::DoGetBestSize() const // // The combobox should be larger than the widest string // - wxGetCharSize( GetHWND() - ,&nCx - ,&nCy - ,(wxFont*)&GetFont() - ); + wxGetCharSize( GetHWND(), &nCx, &nCy, &vFont ); nChoiceWidth += 5 * nCx; // @@ -435,7 +383,7 @@ bool wxChoice::OS2Command( vEvent.SetInt(n); vEvent.SetEventObject(this); - vEvent.SetString((char*)GetStringSelection().c_str()); + vEvent.SetString(GetStringSelection()); if (HasClientObjectData()) vEvent.SetClientObject(GetClientObject(n)); else if (HasClientUntypedData()) @@ -449,7 +397,7 @@ void wxChoice::Free() { if (HasClientObjectData()) { - size_t nCount = GetCount(); + const size_t nCount = GetCount(); for (size_t n = 0; n < nCount; n++) {