X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8907154c1a8a6882c6797d1f16393ddfb23e7f3a..404b319a85dadd7decf7a5a5331020520031a41c:/src/msw/wince/choicece.cpp diff --git a/src/msw/wince/choicece.cpp b/src/msw/wince/choicece.cpp index edadc5f8e4..33d80aa13c 100644 --- a/src/msw/wince/choicece.cpp +++ b/src/msw/wince/choicece.cpp @@ -6,7 +6,7 @@ // Created: 29.07.2004 // RCS-ID: $Id$ // Copyright: (c) Wlodzimierz Skiba -// License: wxWindows licence +// Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -24,24 +24,16 @@ #pragma hdrstop #endif +#if wxUSE_CHOICE && defined(__SMARTPHONE__) && defined(__WXWINCE__) + +#include "wx/choice.h" + #ifndef WX_PRECOMP - #include "wx/choice.h" + #include "wx/msw/wrapcctl.h" // include "properly" #endif #include "wx/spinbutt.h" // for wxSpinnerBestSize -#include -#include "wx/msw/missing.h" -#include "wx/msw/winundef.h" - -#if wxUSE_CHOICE && defined(__SMARTPHONE__) && defined(__WXWINCE__) - -#if wxUSE_EXTENDED_RTTI -// TODO -#else -IMPLEMENT_DYNAMIC_CLASS(wxChoice, wxControl) -#endif - #define GetBuddyHwnd() (HWND)(m_hwndBuddy) #define IsVertical(wxStyle) ( (wxStyle & wxSP_HORIZONTAL) != wxSP_HORIZONTAL ) @@ -115,7 +107,7 @@ wxChoice *wxChoice::GetChoiceForListBox(WXHWND hwndBuddy) // sanity check wxASSERT_MSG( choice->m_hwndBuddy == hwndBuddy, - _T("wxChoice has incorrect buddy HWND!") ); + wxT("wxChoice has incorrect buddy HWND!") ); return choice; } @@ -171,7 +163,7 @@ bool wxChoice::CreateAndInit(wxWindow *parent, sizeText.x -= sizeBtn.x + MARGIN_BETWEEN; if ( sizeText.x <= 0 ) { - wxLogDebug(_T("not enough space for wxSpinCtrl!")); + wxLogDebug(wxT("not enough space for wxSpinCtrl!")); } wxPoint posBtn(pos); @@ -188,7 +180,7 @@ bool wxChoice::CreateAndInit(wxWindow *parent, m_hwndBuddy = (WXHWND)::CreateWindowEx ( exStyle, // sunken border - _T("LISTBOX"), // window class + wxT("LISTBOX"), // window class NULL, // no window title msStyle, // style (will be shown later) pos.x, pos.y, // position @@ -223,7 +215,7 @@ bool wxChoice::CreateAndInit(wxWindow *parent, if ( style & wxSP_WRAP ) spiner_style |= UDS_WRAP; - if ( !MSWCreateControl(UPDOWN_CLASS, spiner_style, posBtn, sizeBtn, _T(""), 0) ) + if ( !MSWCreateControl(UPDOWN_CLASS, spiner_style, posBtn, sizeBtn, wxEmptyString, 0) ) return false; // subclass the text ctrl to be able to intercept some events @@ -246,7 +238,7 @@ bool wxChoice::CreateAndInit(wxWindow *parent, sizeText.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy); } - SetBestSize(size); + SetInitialSize(size); (void)::ShowWindow(GetBuddyHwnd(), SW_SHOW); @@ -327,70 +319,52 @@ bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) wxChoice::~wxChoice() { - Free(); + Clear(); } // ---------------------------------------------------------------------------- // adding/deleting items to/from the list // ---------------------------------------------------------------------------- -int wxChoice::DoAppend(const wxString& item) +int wxChoice::DoInsertItems(const wxArrayStringsAdapter& items, + unsigned int pos, + void **clientData, + wxClientDataType type) { - int n = (int)::SendMessage(GetBuddyHwnd(), LB_ADDSTRING, 0, (LPARAM)item.c_str()); + MSWAllocStorage(items, LB_INITSTORAGE); - if ( n == LB_ERR ) - { - wxLogLastError(wxT("SendMessage(LB_ADDSTRING)")); - } - - return n; -} + const bool append = pos == GetCount(); + const unsigned msg = append ? LB_ADDSTRING : LB_INSERTSTRING; + if ( append ) + pos = 0; -int wxChoice::DoInsert(const wxString& item, int pos) -{ - wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into choice")); - wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index")); + int n = wxNOT_FOUND; - int n = (int)::SendMessage(GetBuddyHwnd(), LB_INSERTSTRING, pos, (LPARAM)item.c_str()); - if ( n == LB_ERR ) + const unsigned int numItems = items.GetCount(); + for ( unsigned int i = 0; i < numItems; ++i ) { - wxLogLastError(wxT("SendMessage(LB_INSERTSTRING)")); + n = MSWInsertOrAppendItem(pos, items[i], msg); + if ( !append ) + pos++; + + AssignNewItemClientData(n, clientData, i, type); } return n; } -void wxChoice::Delete(int n) +void wxChoice::DoDeleteOneItem(unsigned int n) { - wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") ); - - if ( HasClientObjectData() ) - { - delete GetClientObject(n); - } + wxCHECK_RET( IsValid(n), wxT("invalid item index in wxChoice::Delete") ); ::SendMessage(GetBuddyHwnd(), LB_DELETESTRING, n, 0); } -void wxChoice::Clear() +void wxChoice::DoClear() { - Free(); - ::SendMessage(GetBuddyHwnd(), LB_RESETCONTENT, 0, 0); } -void wxChoice::Free() -{ - if ( HasClientObjectData() ) - { - size_t count = GetCount(); - for ( size_t n = 0; n < count; n++ ) - { - delete GetClientObject(n); - } - } -} - // ---------------------------------------------------------------------------- // selection // ---------------------------------------------------------------------------- @@ -409,22 +383,26 @@ void wxChoice::SetSelection(int n) // string list functions // ---------------------------------------------------------------------------- -int wxChoice::GetCount() const +unsigned int wxChoice::GetCount() const { - return (int)::SendMessage(GetBuddyHwnd(), LB_GETCOUNT, 0, 0); + return (unsigned int)::SendMessage(GetBuddyHwnd(), LB_GETCOUNT, 0, 0); } -int wxChoice::FindString(const wxString& s) const +int wxChoice::FindString(const wxString& s, bool bCase) const { + // back to base class search for not native search type + if (bCase) + return wxItemContainerImmutable::FindString( s, bCase ); + int pos = (int)::SendMessage(GetBuddyHwnd(), LB_FINDSTRINGEXACT, (WPARAM)-1, (LPARAM)s.c_str()); return pos == LB_ERR ? wxNOT_FOUND : pos; } -void wxChoice::SetString(int n, const wxString& s) +void wxChoice::SetString(unsigned int n, const wxString& s) { - wxCHECK_RET( n >= 0 && n < GetCount(), + wxCHECK_RET( IsValid(n), wxT("invalid item index in wxChoice::SetString") ); // we have to delete and add back the string as there is no way to change a @@ -451,7 +429,7 @@ void wxChoice::SetString(int n, const wxString& s) //else: it's already NULL by default } -wxString wxChoice::GetString(int n) const +wxString wxChoice::GetString(unsigned int n) const { int len = (int)::SendMessage(GetBuddyHwnd(), LB_GETTEXTLEN, n, 0); @@ -477,7 +455,7 @@ wxString wxChoice::GetString(int n) const // client data // ---------------------------------------------------------------------------- -void wxChoice::DoSetItemClientData( int n, void* clientData ) +void wxChoice::DoSetItemClientData(unsigned int n, void* clientData) { if ( ::SendMessage(GetHwnd(), LB_SETITEMDATA, n, (LPARAM)clientData) == LB_ERR ) @@ -486,7 +464,7 @@ void wxChoice::DoSetItemClientData( int n, void* clientData ) } } -void* wxChoice::DoGetItemClientData( int n ) const +void* wxChoice::DoGetItemClientData(unsigned int n) const { LPARAM rc = ::SendMessage(GetHwnd(), LB_GETITEMDATA, n, 0); if ( rc == LB_ERR ) @@ -500,16 +478,6 @@ void* wxChoice::DoGetItemClientData( int n ) const return (void *)rc; } -void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData ) -{ - DoSetItemClientData(n, clientData); -} - -wxClientData* wxChoice::DoGetItemClientObject( int n ) const -{ - return (wxClientData *)DoGetItemClientData(n); -} - // ---------------------------------------------------------------------------- // size calculations // ---------------------------------------------------------------------------- @@ -543,7 +511,7 @@ void wxChoice::DoMoveWindow(int x, int y, int width, int height) int widthText = width - widthBtn - MARGIN_BETWEEN; if ( widthText <= 0 ) { - wxLogDebug(_T("not enough space for wxSpinCtrl!")); + wxLogDebug(wxT("not enough space for wxSpinCtrl!")); } if ( !::MoveWindow(GetBuddyHwnd(), x, y, widthText, height, TRUE) )