+IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
+
+// ----------------------------------------------------------------------------
+// declaration and implementation of wxCheckListBoxItem class
+// ----------------------------------------------------------------------------
+
+class wxCheckListBoxItem : public wxOwnerDrawn
+{
+ friend class wxCheckListBox;
+public:
+ //
+ // ctor
+ //
+ wxCheckListBoxItem( wxCheckListBox* pParent,
+ size_t nIndex
+ );
+
+ //
+ // Drawing functions
+ //
+ virtual bool OnDrawItem( wxDC& rDc,
+ const wxRect& rRect,
+ wxODAction eAct,
+ wxODStatus eStat
+ );
+
+ //
+ // Simple accessors
+ //
+ bool IsChecked(void) const { return m_bChecked; }
+ void Check(bool bCheck);
+ void Toggle(void) { Check(!IsChecked()); }
+
+private:
+ bool m_bChecked;
+ wxCheckListBox* m_pParent;
+ size_t m_nIndex;
+}; // end of CLASS wxCheckListBoxItem
+
+
+
+wxCheckListBoxItem::wxCheckListBoxItem ( wxCheckListBox* pParent,
+ size_t nIndex)
+ :wxOwnerDrawn( wxEmptyString, true /* checkable */ )
+{
+ m_bChecked = false;
+ m_pParent = pParent;
+ m_nIndex = nIndex;
+
+ //
+ // We don't initialize m_nCheckHeight/Width vars because it's
+ // done in OnMeasure while they are used only in OnDraw and we
+ // know that there will always be OnMeasure before OnDraw
+ //
+ SetMarginWidth(GetDefaultMarginWidth());
+} // end of wxCheckListBoxItem::wxCheckListBoxItem
+
+
+
+bool wxCheckListBoxItem::OnDrawItem ( wxDC& rDc,
+ const wxRect& rRect,
+ wxODAction eAct,
+ wxODStatus eStat )
+{
+ wxRect vRect = rRect;
+
+ ::WinQueryWindowRect( m_pParent->GetHWND(), &rDc.m_vRclPaint );
+ if (IsChecked())
+ eStat = (wxOwnerDrawn::wxODStatus)(eStat | wxOwnerDrawn::wxODChecked);
+
+ //
+ // Unfortunately PM doesn't quite get the text position exact. We need to alter
+ // it down and to the right, just a little bit. The coords in rRect are OS/2
+ // coords not wxWidgets coords.
+ //
+ vRect.x += 5;
+ vRect.y -= 3;
+ if (wxOwnerDrawn::OnDrawItem( rDc, vRect, eAct, eStat))
+ {
+ size_t nCheckWidth = GetDefaultMarginWidth();
+ size_t nCheckHeight = m_pParent->GetItemHeight();
+ int nParentHeight;
+ int nX = rRect.GetX();
+ int nY = rRect.GetY();
+ int nOldY = nY;
+ wxColour vColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
+ wxPen vPenBack;
+ wxPen vPenPrev;
+
+ m_pParent->GetSize( NULL, &nParentHeight);
+
+ nY = nParentHeight - nY - nCheckHeight;
+ vPenBack = wxPen(vColour, 1, wxSOLID);
+
+ //
+ // Erase the 1-pixel border
+ //
+ rDc.SetPen(vPenBack);
+ rDc.DrawRectangle( nX, nY, nCheckWidth, nCheckHeight );
+
+ //
+ // Now we draw the smaller rectangle
+ //
+ nY++;
+ nCheckWidth -= 2;
+ nCheckHeight -= 2;
+
+ //
+ // Draw hollow gray rectangle
+ //
+ rDc.SetPen(*wxGREY_PEN);
+ rDc.DrawRectangle( nX, nY, nCheckWidth, nCheckHeight );
+
+ nX++;
+ if (IsChecked())
+ {
+ //
+ // Draw the check by loading the sys standard bitmap and drawing it
+ //
+ HBITMAP hChkBmp = ::WinGetSysBitmap( HWND_DESKTOP, SBMP_MENUCHECK );
+ POINTL vPoint = {nX, nOldY + 3};
+
+ ::WinDrawBitmap( rDc.GetHPS(),
+ hChkBmp,
+ NULL,
+ &vPoint,
+ NULL,
+ NULL,
+ DBM_NORMAL
+ );
+ }
+ return true;
+ }
+ return false;
+} // end of wxCheckListBoxItem::OnDrawItem
+
+//
+// Change the state of the item and redraw it
+//
+void wxCheckListBoxItem::Check ( bool bCheck )
+{
+ m_bChecked = bCheck;
+
+ //
+ // Index may be chanegd because new items were added/deleted
+ //
+ if (m_pParent->GetItemIndex(this) != (int)m_nIndex)
+ {
+ //
+ // Update it
+ //
+ int nIndex = m_pParent->GetItemIndex(this);
+
+ wxASSERT_MSG(nIndex != wxNOT_FOUND, wxT("what does this item do here?"));
+
+ m_nIndex = (size_t)nIndex;
+ }
+
+
+ wxCommandEvent vEvent( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED,m_pParent->GetId());
+
+ vEvent.SetInt(m_nIndex);
+ vEvent.SetEventObject(m_pParent);
+ m_pParent->ProcessCommand(vEvent);
+} // end of wxCheckListBoxItem::Check
+