X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/71908213057690d5452f72b2b9c8e62b53357170..eea4d01c65f9b29baa1193db762b4c6b8144af24:/src/univ/checklst.cpp diff --git a/src/univ/checklst.cpp b/src/univ/checklst.cpp index 5a1c9c0cd5..4e2d6f857c 100644 --- a/src/univ/checklst.cpp +++ b/src/univ/checklst.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: univ/checklst.cpp +// Name: src/univ/checklst.cpp // Purpose: wxCheckListBox implementation // Author: Vadim Zeitlin // Modified by: @@ -17,10 +17,6 @@ // headers // ---------------------------------------------------------------------------- -#ifdef __GNUG__ - #pragma implementation "checklst.h" -#endif - #include "wx/wxprec.h" #ifdef __BORLANDC__ @@ -29,11 +25,11 @@ #if wxUSE_CHECKLISTBOX +#include "wx/checklst.h" + #ifndef WX_PRECOMP #include "wx/log.h" - #include "wx/dcclient.h" - #include "wx/checklst.h" #include "wx/validate.h" #endif @@ -41,12 +37,26 @@ #include "wx/univ/inphand.h" #include "wx/univ/theme.h" +// ---------------------------------------------------------------------------- +// wxStdCheckListBoxInputHandler +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxStdCheckListboxInputHandler : public wxStdInputHandler +{ +public: + wxStdCheckListboxInputHandler(wxInputHandler *inphand); + + virtual bool HandleKey(wxInputConsumer *consumer, + const wxKeyEvent& event, + bool pressed); + virtual bool HandleMouse(wxInputConsumer *consumer, + const wxMouseEvent& event); +}; + // ============================================================================ // implementation of wxCheckListBox // ============================================================================ -IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox) - // ---------------------------------------------------------------------------- // creation // ---------------------------------------------------------------------------- @@ -55,6 +65,35 @@ void wxCheckListBox::Init() { } +wxCheckListBox::wxCheckListBox(wxWindow *parent, + wxWindowID id, + const wxPoint &pos, + const wxSize &size, + const wxArrayString& choices, + long style, + const wxValidator& validator, + const wxString &name) +{ + Init(); + + Create(parent, id, pos, size, choices, style, validator, name); +} + +bool wxCheckListBox::Create(wxWindow *parent, + wxWindowID id, + const wxPoint &pos, + const wxSize &size, + const wxArrayString& choices, + long style, + const wxValidator& validator, + const wxString &name) +{ + wxCArrayString chs(choices); + + return Create(parent, id, pos, size, chs.GetCount(), chs.GetStrings(), + style, validator, name); +} + bool wxCheckListBox::Create(wxWindow *parent, wxWindowID id, const wxPoint &pos, @@ -67,29 +106,29 @@ bool wxCheckListBox::Create(wxWindow *parent, { if ( !wxListBox::Create(parent, id, pos, size, n, choices, style, validator, name) ) - return FALSE; + return false; CreateInputHandler(wxINP_HANDLER_CHECKLISTBOX); - return TRUE; + return true; } // ---------------------------------------------------------------------------- // wxCheckListBox functions // ---------------------------------------------------------------------------- -bool wxCheckListBox::IsChecked(size_t item) const +bool wxCheckListBox::IsChecked(unsigned int item) const { - wxCHECK_MSG( item < m_checks.GetCount(), FALSE, - _T("invalid index in wxCheckListBox::IsChecked") ); + wxCHECK_MSG( IsValid(item), false, + wxT("invalid index in wxCheckListBox::IsChecked") ); return m_checks[item] != 0; } -void wxCheckListBox::Check(size_t item, bool check) +void wxCheckListBox::Check(unsigned int item, bool check) { - wxCHECK_RET( item < m_checks.GetCount(), - _T("invalid index in wxCheckListBox::Check") ); + wxCHECK_RET( IsValid(item), + wxT("invalid index in wxCheckListBox::Check") ); // intermediate var is needed to avoid compiler warning with VC++ bool isChecked = m_checks[item] != 0; @@ -105,46 +144,16 @@ void wxCheckListBox::Check(size_t item, bool check) // methods forwarded to wxListBox // ---------------------------------------------------------------------------- -void wxCheckListBox::Delete(int n) +void wxCheckListBox::DoDeleteOneItem(unsigned int n) { - wxCHECK_RET( n < GetCount(), _T("invalid index in wxListBox::Delete") ); - - wxListBox::Delete(n); + wxListBox::DoDeleteOneItem(n); m_checks.RemoveAt(n); } -int wxCheckListBox::DoAppend(const wxString& item) -{ - int pos = wxListBox::DoAppend(item); - - // the item is initially unchecked - m_checks.Insert(FALSE, pos); - - return pos; -} - -void wxCheckListBox::DoInsertItems(const wxArrayString& items, int pos) -{ - wxListBox::DoInsertItems(items, pos); - - size_t count = items.GetCount(); - for ( size_t n = 0; n < count; n++ ) - { - m_checks.Insert(FALSE, pos + n); - } -} - -void wxCheckListBox::DoSetItems(const wxArrayString& items, void **clientData) +void wxCheckListBox::OnItemInserted(unsigned int pos) { - // call it first as it does DoClear() - wxListBox::DoSetItems(items, clientData); - - size_t count = items.GetCount(); - for ( size_t n = 0; n < count; n++ ) - { - m_checks.Add(FALSE); - } + m_checks.Insert(false, pos); } void wxCheckListBox::DoClear() @@ -198,7 +207,15 @@ bool wxCheckListBox::PerformAction(const wxControlAction& action, return wxListBox::PerformAction(action, numArg, strArg); } - return TRUE; + return true; +} + +/* static */ +wxInputHandler *wxCheckListBox::GetStdInputHandler(wxInputHandler *handlerDef) +{ + static wxStdCheckListboxInputHandler s_handler(handlerDef); + + return &s_handler; } // ---------------------------------------------------------------------------- @@ -207,30 +224,30 @@ bool wxCheckListBox::PerformAction(const wxControlAction& action, wxStdCheckListboxInputHandler:: wxStdCheckListboxInputHandler(wxInputHandler *inphand) - : wxStdListboxInputHandler(inphand) + : wxStdInputHandler(wxListBox::GetStdInputHandler(inphand)) { } -bool wxStdCheckListboxInputHandler::HandleKey(wxControl *control, +bool wxStdCheckListboxInputHandler::HandleKey(wxInputConsumer *consumer, const wxKeyEvent& event, bool pressed) { if ( pressed && (event.GetKeyCode() == WXK_SPACE) ) - control->PerformAction(wxACTION_CHECKLISTBOX_TOGGLE); + consumer->PerformAction(wxACTION_CHECKLISTBOX_TOGGLE); - return wxStdListboxInputHandler::HandleKey(control, event, pressed); + return wxStdInputHandler::HandleKey(consumer, event, pressed); } -bool wxStdCheckListboxInputHandler::HandleMouse(wxControl *control, +bool wxStdCheckListboxInputHandler::HandleMouse(wxInputConsumer *consumer, const wxMouseEvent& event) { if ( event.LeftDown() || event.LeftDClick() ) { - wxCheckListBox *lbox = wxStaticCast(control, wxCheckListBox); + wxCheckListBox *lbox = wxStaticCast(consumer->GetInputWindow(), wxCheckListBox); int x, y; wxPoint pt = event.GetPosition(); - pt -= control->GetClientAreaOrigin(); + pt -= consumer->GetInputWindow()->GetClientAreaOrigin(); lbox->CalcUnscrolledPosition(pt.x, pt.y, &x, &y); wxRenderer *renderer = lbox->GetRenderer(); @@ -240,15 +257,15 @@ bool wxStdCheckListboxInputHandler::HandleMouse(wxControl *control, if ( x >= 0 && x < renderer->GetCheckBitmapSize().x && item >= 0 && - item < lbox->GetCount() ) + (unsigned int)item < lbox->GetCount() ) { lbox->PerformAction(wxACTION_CHECKLISTBOX_TOGGLE, item); - return TRUE; + return true; } } - return wxStdListboxInputHandler::HandleMouse(control, event); + return wxStdInputHandler::HandleMouse(consumer, event); } #endif // wxUSE_CHECKLISTBOX