X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/84882850e5e71939d541c1788b8446576a41ca30..64ea838d8f4d1853b7d850db93ee565e901d099a:/src/os2/checklst.cpp diff --git a/src/os2/checklst.cpp b/src/os2/checklst.cpp index 45004b7486..6773983e9f 100644 --- a/src/os2/checklst.cpp +++ b/src/os2/checklst.cpp @@ -18,22 +18,33 @@ #if wxUSE_CHECKLISTBOX && wxUSE_OWNER_DRAWN -#include "wx/object.h" -#include "wx/colour.h" -#include "wx/font.h" -#include "wx/bitmap.h" -#include "wx/window.h" -#include "wx/listbox.h" -#include "wx/ownerdrw.h" -#include "wx/settings.h" -#include "wx/dcmemory.h" -#include "wx/dcscreen.h" #include "wx/checklst.h" -#include "wx/log.h" + +#ifndef WX_PRECOMP + #include "wx/object.h" + #include "wx/log.h" + #include "wx/window.h" + #include "wx/dcmemory.h" + #include "wx/dcscreen.h" + #include "wx/settings.h" + #include "wx/listbox.h" + #include "wx/bitmap.h" + #include "wx/colour.h" + #include "wx/font.h" +#endif + +#include "wx/os2/dc.h" +#include "wx/ownerdrw.h" #define INCL_PM #include +// ---------------------------------------------------------------------------- +// constants for base class +// ---------------------------------------------------------------------------- + +static const int CHECK_MARK_WIDTH = 15; + // ---------------------------------------------------------------------------- // private functions // ---------------------------------------------------------------------------- @@ -45,8 +56,6 @@ // implementation // ============================================================================ -IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox) - // ---------------------------------------------------------------------------- // declaration and implementation of wxCheckListBoxItem class // ---------------------------------------------------------------------------- @@ -58,9 +67,7 @@ public: // // ctor // - wxCheckListBoxItem( wxCheckListBox* pParent, - size_t nIndex - ); + wxCheckListBoxItem(wxCheckListBox* pParent, size_t nIndex); // // Drawing functions @@ -78,6 +85,8 @@ public: void Check(bool bCheck); void Toggle(void) { Check(!IsChecked()); } + virtual wxString GetName() const { return m_pParent->GetString(m_nIndex); } + private: bool m_bChecked; wxCheckListBox* m_pParent; @@ -86,8 +95,7 @@ private: -wxCheckListBoxItem::wxCheckListBoxItem ( wxCheckListBox* pParent, - size_t nIndex) +wxCheckListBoxItem::wxCheckListBoxItem(wxCheckListBox* pParent, size_t nIndex) :wxOwnerDrawn( wxEmptyString, true /* checkable */ ) { m_bChecked = false; @@ -99,7 +107,7 @@ wxCheckListBoxItem::wxCheckListBoxItem ( wxCheckListBox* pParent, // done in OnMeasure while they are used only in OnDraw and we // know that there will always be OnMeasure before OnDraw // - SetMarginWidth(GetDefaultMarginWidth()); + SetMarginWidth(CHECK_MARK_WIDTH); } // end of wxCheckListBoxItem::wxCheckListBoxItem @@ -111,7 +119,9 @@ bool wxCheckListBoxItem::OnDrawItem ( wxDC& rDc, { wxRect vRect = rRect; - ::WinQueryWindowRect( m_pParent->GetHWND(), &rDc.m_vRclPaint ); + + wxPMDCImpl *impl = (wxPMDCImpl*) rDc.GetImpl(); + ::WinQueryWindowRect( m_pParent->GetHWND(), &impl->m_vRclPaint ); if (IsChecked()) eStat = (wxOwnerDrawn::wxODStatus)(eStat | wxOwnerDrawn::wxODChecked); @@ -124,7 +134,7 @@ bool wxCheckListBoxItem::OnDrawItem ( wxDC& rDc, vRect.y -= 3; if (wxOwnerDrawn::OnDrawItem( rDc, vRect, eAct, eStat)) { - size_t nCheckWidth = GetDefaultMarginWidth(); + size_t nCheckWidth = CHECK_MARK_WIDTH; size_t nCheckHeight = m_pParent->GetItemHeight(); int nParentHeight; int nX = rRect.GetX(); @@ -166,8 +176,8 @@ bool wxCheckListBoxItem::OnDrawItem ( wxDC& rDc, // HBITMAP hChkBmp = ::WinGetSysBitmap( HWND_DESKTOP, SBMP_MENUCHECK ); POINTL vPoint = {nX, nOldY + 3}; - - ::WinDrawBitmap( rDc.GetHPS(), + wxPMDCImpl *impl = (wxPMDCImpl*) rDc.GetImpl(); + ::WinDrawBitmap( impl->GetHPS(), hChkBmp, NULL, &vPoint, @@ -184,7 +194,7 @@ bool wxCheckListBoxItem::OnDrawItem ( wxDC& rDc, // // Change the state of the item and redraw it // -void wxCheckListBoxItem::Check ( bool bCheck ) +void wxCheckListBoxItem::Check( bool bCheck ) { m_bChecked = bCheck; @@ -270,9 +280,9 @@ wxCheckListBox::wxCheckListBox ( wxWindow* pParent, lStyle | wxLB_OWNERDRAW, rVal, rsName ); } // end of wxCheckListBox::wxCheckListBox -void wxCheckListBox::Delete( int n ) +void wxCheckListBox::Delete(unsigned int n) { - wxCHECK_RET( n >= 0 && n < m_nNumItems, + wxCHECK_RET( IsValid(n), wxT("invalid index in wxCheckListBox::Delete") ); wxListBox::Delete(n); @@ -283,28 +293,9 @@ void wxCheckListBox::Delete( int n ) m_aItems.RemoveAt(n); } // end of wxCheckListBox::Delete -void wxCheckListBox::DoInsertItems(const wxArrayString& items, int pos) -{ - // pos is validated in wxListBox - wxListBox::DoInsertItems( items, pos ); - int n = items.GetCount(); - for (int i = 0; i < n; i++) - { - wxOwnerDrawn* pNewItem = CreateItem((size_t)(pos + i)); - - pNewItem->SetName(items[i]); - m_aItems.Insert(pNewItem, (size_t)(pos + i)); - ::WinSendMsg( (HWND)GetHWND(), - LM_SETITEMHANDLE, - (MPARAM)(i + pos), - MPFROMP(pNewItem) - ); - } -} // end of wxCheckListBox::InsertItems - bool wxCheckListBox::SetFont ( const wxFont& rFont ) { - for (size_t i = 0; i < m_aItems.GetCount(); i++) + for (unsigned int i = 0; i < m_aItems.GetCount(); i++) m_aItems[i]->SetFont(rFont); wxListBox::SetFont(rFont); return true; @@ -320,7 +311,7 @@ bool wxCheckListBox::SetFont ( const wxFont& rFont ) // // Create a check list box item // -wxOwnerDrawn* wxCheckListBox::CreateItem ( size_t nIndex ) +wxOwnerDrawn* wxCheckListBox::CreateItem(size_t nIndex) { wxCheckListBoxItem* pItem = new wxCheckListBoxItem( this, nIndex ); return pItem; @@ -348,7 +339,7 @@ long wxCheckListBox::OS2OnMeasure ( WXMEASUREITEMSTRUCT* pItem ) // // Add place for the check mark // - pStruct->rclItem.xRight += wxOwnerDrawn::GetDefaultMarginWidth(); + pStruct->rclItem.xRight += CHECK_MARK_WIDTH; return long(MRFROM2SHORT((USHORT)m_nItemHeight, (USHORT)(pStruct->rclItem.xRight - pStruct->rclItem.xLeft))); } return 0L; @@ -360,12 +351,12 @@ long wxCheckListBox::OS2OnMeasure ( WXMEASUREITEMSTRUCT* pItem ) // Check items // ----------- // -bool wxCheckListBox::IsChecked ( size_t uiIndex) const +bool wxCheckListBox::IsChecked(unsigned int uiIndex) const { return GetItem(uiIndex)->IsChecked(); } // end of wxCheckListBox::IsChecked -void wxCheckListBox::Check ( size_t uiIndex, bool bCheck ) +void wxCheckListBox::Check(unsigned int uiIndex, bool bCheck) { GetItem(uiIndex)->Check(bCheck); } // end of wxCheckListBox::Check @@ -389,7 +380,7 @@ void wxCheckListBox::OnLeftClick ( wxMouseEvent& rEvent ) // // Clicking on the item selects it, clicking on the checkmark toggles // - if (rEvent.GetX() <= wxOwnerDrawn::GetDefaultMarginWidth()) + if (rEvent.GetX() <= CHECK_MARK_WIDTH) { int nParentHeight; wxScreenDC vDc; @@ -408,7 +399,7 @@ void wxCheckListBox::OnLeftClick ( wxMouseEvent& rEvent ) size_t nItem = (size_t)(nY / vHeight); - if (nItem < (size_t)m_nNumItems) + if (nItem < m_nNumItems) GetItem(nItem)->Toggle(); // // else: it's not an error, just click outside of client zone