///////////////////////////////////////////////////////////////////////////////
// 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
// RCS-ID: $Id$
// Copyright: (c) Wlodzimierz Skiba
-// License: wxWindows licence
+// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
-
// ============================================================================
// declarations
// ============================================================================
// 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"
#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 <commctrl.h> "properly"
#endif
#include "wx/spinbutt.h" // for wxSpinnerBestSize
-#include <commctrl.h>
-#include "wx/msw/missing.h"
-#include "wx/msw/winundef.h"
-
-#if wxUSE_CHOICE && defined(__SMARTPHONE__)
-
-#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 )
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,
+ wxT("wxChoice has incorrect buddy HWND!") );
+
+ return choice;
+}
+
// ----------------------------------------------------------------------------
// creation
// ----------------------------------------------------------------------------
WXDWORD msStyle = MSWGetStyle(GetWindowStyle(), & exStyle) ;
wxSize sizeText(size), sizeBtn(size);
- sizeBtn.x = GetBestSpinerSize(IsVertical(style)).x;
-
- sizeBtn.x;
+ sizeBtn.x = GetBestSpinnerSize(IsVertical(style)).x;
if ( sizeText.x == wxDefaultCoord )
{
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);
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
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
sizeText.y = EDIT_HEIGHT_FROM_CHAR_HEIGHT(cy);
}
- SetBestSize(size);
+ SetInitialSize(size);
(void)::ShowWindow(GetBuddyHwnd(), SW_SHOW);
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();
+ 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)"));
- }
+ const bool append = pos == GetCount();
+ const unsigned msg = append ? LB_ADDSTRING : LB_INSERTSTRING;
+ if ( append )
+ pos = 0;
- return n;
-}
-
-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)"));
- }
-
- return n;
-}
+ n = MSWInsertOrAppendItem(pos, items[i], msg);
+ if ( !append )
+ pos++;
-void wxChoice::Delete(int n)
-{
- wxCHECK_RET( n < GetCount(), wxT("invalid item index in wxChoice::Delete") );
-
- if ( HasClientObjectData() )
- {
- delete GetClientObject(n);
+ AssignNewItemClientData(n, clientData, i, type);
}
- SendMessage(GetBuddyHwnd(), LB_DELETESTRING, n, 0);
+ return n;
}
-void wxChoice::Clear()
+void wxChoice::DoDeleteOneItem(unsigned int n)
{
- Free();
+ wxCHECK_RET( IsValid(n), wxT("invalid item index in wxChoice::Delete") );
- SendMessage(GetBuddyHwnd(), LB_RESETCONTENT, 0, 0);
+ ::SendMessage(GetBuddyHwnd(), LB_DELETESTRING, n, 0);
}
-void wxChoice::Free()
+void wxChoice::DoClear()
{
- if ( HasClientObjectData() )
- {
- size_t count = GetCount();
- for ( size_t n = 0; n < count; n++ )
- {
- delete GetClientObject(n);
- }
- }
+ ::SendMessage(GetBuddyHwnd(), LB_RESETCONTENT, 0, 0);
}
// ----------------------------------------------------------------------------
int wxChoice::GetSelection() const
{
- return (int)SendMessage(GetBuddyHwnd(), LB_GETCURSEL, 0, 0);
+ return (int)::SendMessage(GetBuddyHwnd(), LB_GETCURSEL, 0, 0);
}
void wxChoice::SetSelection(int n)
{
- SendMessage(GetBuddyHwnd(), LB_SETCURSEL, n, 0);
+ ::SendMessage(GetBuddyHwnd(), LB_SETCURSEL, n, 0);
}
// ----------------------------------------------------------------------------
// 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
{
- int pos = (int)SendMessage(GetBuddyHwnd(), LB_FINDSTRINGEXACT,
+ // 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
//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);
// 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 )
}
}
-void* wxChoice::DoGetItemClientData( int n ) const
+void* wxChoice::DoGetItemClientData(unsigned int n) const
{
- LPARAM rc = SendMessage(GetHwnd(), LB_GETITEMDATA, n, 0);
+ LPARAM rc = ::SendMessage(GetHwnd(), LB_GETITEMDATA, n, 0);
if ( rc == LB_ERR )
{
wxLogLastError(wxT("LB_GETITEMDATA"));
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
// ----------------------------------------------------------------------------
wxSize wxChoice::DoGetBestSize() const
{
- wxSize sizeBtn = GetBestSpinerSize(IsVertical(GetWindowStyle()));
+ wxSize sizeBtn = GetBestSpinnerSize(IsVertical(GetWindowStyle()));
sizeBtn.x += DEFAULT_ITEM_WIDTH + MARGIN_BETWEEN;
int y;
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 )
{
- wxLogDebug(_T("not enough space for wxSpinCtrl!"));
+ wxLogDebug(wxT("not enough space for wxSpinCtrl!"));
}
if ( !::MoveWindow(GetBuddyHwnd(), x, y, widthText, height, TRUE) )
wxConstCast(this, wxChoice)->m_hWnd = hWnd;
}
-#endif // wxUSE_CHOICE && __SMARTPHONE__
+#endif // wxUSE_CHOICE && __SMARTPHONE__ && __WXWINCE__