X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/39fc096d5a40b85488a43226aa49c887ae86f45f..ba53bf083e768a770a7011d0ba0143484a8d3a33:/src/msw/wince/choicece.cpp diff --git a/src/msw/wince/choicece.cpp b/src/msw/wince/choicece.cpp index 59971875c4..5540dcca03 100644 --- a/src/msw/wince/choicece.cpp +++ b/src/msw/wince/choicece.cpp @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// // Name: src/msw/wince/choicece.cpp -// Purpose: wxChoice implementation for Smartphones +// Purpose: wxChoice implementation for smart phones driven by WinCE // Author: Wlodzimierz ABX Skiba // Modified by: // Created: 29.07.2004 @@ -9,7 +9,6 @@ // License: wxWindows licence /////////////////////////////////////////////////////////////////////////////// - // ============================================================================ // declarations // ============================================================================ @@ -18,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) - #pragma implementation "choicece.h" -#endif - // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -29,18 +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__) - #if wxUSE_EXTENDED_RTTI // TODO #else @@ -109,6 +102,22 @@ LRESULT APIENTRY _EXPORT wxBuddyChoiceWndProc(HWND hwnd, hwnd, message, wParam, lParam); } +wxChoice *wxChoice::GetChoiceForListBox(WXHWND hwndBuddy) +{ + wxChoice *choice = (wxChoice *)wxGetWindowUserData((HWND)hwndBuddy); + + int i = ms_allChoiceSpins.Index(choice); + + if ( i == wxNOT_FOUND ) + return NULL; + + // sanity check + wxASSERT_MSG( choice->m_hwndBuddy == hwndBuddy, + _T("wxChoice has incorrect buddy HWND!") ); + + return choice; +} + // ---------------------------------------------------------------------------- // creation // ---------------------------------------------------------------------------- @@ -149,7 +158,7 @@ bool wxChoice::CreateAndInit(wxWindow *parent, WXDWORD msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ; wxSize sizeText(size), sizeBtn(size); - sizeBtn.x = GetBestSpinerSize(IsVertical(style)).x; + sizeBtn.x = GetBestSpinnerSize(IsVertical(style)).x; if ( sizeText.x == wxDefaultCoord ) { @@ -212,7 +221,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 @@ -284,9 +293,36 @@ WXDWORD wxChoice::MSWGetStyle(long style, WXDWORD *exstyle) const if ( style & wxCB_SORT ) msStyle |= LBS_SORT; + msStyle |= LBS_NOTIFY; + return msStyle; } +bool wxChoice::MSWCommand(WXUINT param, WXWORD WXUNUSED(id)) +{ + if ( param != LBN_SELCHANGE) + { + // "selection changed" is the only event we're after + return false; + } + + int n = GetSelection(); + if (n > -1) + { + wxCommandEvent event(wxEVT_COMMAND_CHOICE_SELECTED, m_windowId); + event.SetInt(n); + event.SetEventObject(this); + event.SetString(GetStringSelection()); + if ( HasClientObjectData() ) + event.SetClientObject( GetClientObject(n) ); + else if ( HasClientUntypedData() ) + event.SetClientData( GetClientData(n) ); + ProcessCommand(event); + } + + return true; +} + wxChoice::~wxChoice() { Free(); @@ -308,10 +344,10 @@ int wxChoice::DoAppend(const wxString& item) return n; } -int wxChoice::DoInsert(const wxString& item, int pos) +int wxChoice::DoInsert(const wxString& item, unsigned int pos) { wxCHECK_MSG(!(GetWindowStyle() & wxCB_SORT), -1, wxT("can't insert into choice")); - wxCHECK_MSG((pos>=0) && (pos<=GetCount()), -1, wxT("invalid index")); + wxCHECK_MSG(IsValidInsert(pos), -1, wxT("invalid index")); int n = (int)::SendMessage(GetBuddyHwnd(), LB_INSERTSTRING, pos, (LPARAM)item.c_str()); if ( n == LB_ERR ) @@ -322,9 +358,9 @@ int wxChoice::DoInsert(const wxString& item, int pos) return n; } -void wxChoice::Delete(int n) +void wxChoice::Delete(unsigned int n) { - wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") ); + wxCHECK_RET( IsValid(n), wxT("invalid item index in wxChoice::Delete") ); if ( HasClientObjectData() ) { @@ -345,8 +381,8 @@ void wxChoice::Free() { if ( HasClientObjectData() ) { - size_t count = GetCount(); - for ( size_t n = 0; n < count; n++ ) + unsigned int count = GetCount(); + for ( unsigned int n = 0; n < count; n++ ) { delete GetClientObject(n); } @@ -371,22 +407,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 @@ -413,7 +453,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); @@ -439,7 +479,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 ) @@ -448,7 +488,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 ) @@ -462,12 +502,12 @@ void* wxChoice::DoGetItemClientData( int n ) const return (void *)rc; } -void wxChoice::DoSetItemClientObject( int n, wxClientData* clientData ) +void wxChoice::DoSetItemClientObject(unsigned int n, wxClientData* clientData) { DoSetItemClientData(n, clientData); } -wxClientData* wxChoice::DoGetItemClientObject( int n ) const +wxClientData* wxChoice::DoGetItemClientObject(unsigned int n) const { return (wxClientData *)DoGetItemClientData(n); } @@ -478,7 +518,7 @@ wxClientData* wxChoice::DoGetItemClientObject( int n ) const wxSize wxChoice::DoGetBestSize() const { - wxSize sizeBtn = GetBestSpinerSize(IsVertical(GetWindowStyle())); + wxSize sizeBtn = GetBestSpinnerSize(IsVertical(GetWindowStyle())); sizeBtn.x += DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN; int y; @@ -501,7 +541,7 @@ wxSize wxChoice::DoGetBestSize() const void wxChoice::DoMoveWindow(int x, int y, int width, int height) { - int widthBtn = GetBestSpinerSize(IsVertical(GetWindowStyle())).x; + int widthBtn = GetBestSpinnerSize(IsVertical(GetWindowStyle())).x; int widthText = width - widthBtn - MARGIN_BETWEEN; if ( widthText <= 0 ) { @@ -545,4 +585,4 @@ void wxChoice::DoGetPosition(int *x, int *y) const wxConstCast(this, wxChoice)->m_hWnd = hWnd; } -#endif // wxUSE_CHOICE && __SMARTPHONE__ +#endif // wxUSE_CHOICE && __SMARTPHONE__ && __WXWINCE__