]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/checklst.cpp
Allow OS X Cocoa (or any OS X port) to override GetBestSize and provide a native...
[wxWidgets.git] / src / msw / checklst.cpp
index 3188137acaf1639fb14a6d06c516f3a29bf44a06..0769cb2f341e8ee3223041ae6341bee477d44014 100644 (file)
@@ -29,7 +29,7 @@
 #include "wx/checklst.h"
 
 #ifndef WX_PRECOMP
-    #include "wx/msw/wrapwin.h"
+    #include "wx/msw/wrapcctl.h"
     #include "wx/object.h"
     #include "wx/colour.h"
     #include "wx/font.h"
@@ -47,6 +47,7 @@
 
 #include "wx/renderer.h"
 #include "wx/msw/private.h"
+#include "wx/msw/dc.h"
 
 // ----------------------------------------------------------------------------
 // private functions
@@ -124,7 +125,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
 
 class wxCheckListBoxItem : public wxOwnerDrawn
 {
-friend class WXDLLEXPORT wxCheckListBox;
+friend class WXDLLIMPEXP_FWD_CORE wxCheckListBox;
 public:
     // ctor
     wxCheckListBoxItem(wxCheckListBox *pParent, size_t nIndex);
@@ -145,7 +146,7 @@ private:
     wxCheckListBox *m_pParent;
     size_t          m_nIndex;
 
-    DECLARE_NO_COPY_CLASS(wxCheckListBoxItem)
+    wxDECLARE_NO_COPY_CLASS(wxCheckListBoxItem);
 };
 
 wxCheckListBoxItem::wxCheckListBoxItem(wxCheckListBox *pParent, size_t nIndex)
@@ -174,8 +175,9 @@ bool wxCheckListBoxItem::OnDrawItem(wxDC& dc, const wxRect& rc,
     if ( !wxOwnerDrawn::OnDrawItem(dc, rc, act, stat) )
         return false;
 
+    wxMSWDCImpl *impl = (wxMSWDCImpl*) dc.GetImpl();
     // now draw the check mark part
-    HDC hdc = GetHdcOf(dc);
+    HDC hdc = GetHdcOf(*impl);
 
     int nBmpWidth  = ::GetSystemMetrics(SM_CXMENUCHECK),
         nBmpHeight = ::GetSystemMetrics(SM_CYMENUCHECK);
@@ -213,6 +215,9 @@ bool wxCheckListBoxItem::OnDrawItem(wxDC& dc, const wxRect& rc,
 
     ImageList_Destroy(himl);
 
+    if (stat & wxODHasFocus)
+        wxRendererNative::Get().DrawFocusRect(m_pParent, dc, rc);
+
     return true;
 }
 
@@ -251,6 +256,7 @@ void wxCheckListBoxItem::SendEvent()
     wxCommandEvent event(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, m_pParent->GetId());
     event.SetInt(m_nIndex);
     event.SetEventObject(m_pParent);
+    event.SetString(m_pParent->GetString(m_nIndex));
     m_pParent->ProcessCommand(event);
 }
 
@@ -374,14 +380,14 @@ bool wxCheckListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item)
 
 bool wxCheckListBox::IsChecked(unsigned int uiIndex) const
 {
-    wxCHECK_MSG( IsValid(uiIndex), false, _T("bad wxCheckListBox index") );
+    wxCHECK_MSG( IsValid(uiIndex), false, wxT("bad wxCheckListBox index") );
 
     return GetItem(uiIndex)->IsChecked();
 }
 
 void wxCheckListBox::Check(unsigned int uiIndex, bool bCheck)
 {
-    wxCHECK_RET( IsValid(uiIndex), _T("bad wxCheckListBox index") );
+    wxCHECK_RET( IsValid(uiIndex), wxT("bad wxCheckListBox index") );
 
     GetItem(uiIndex)->Check(bCheck);
 }
@@ -443,7 +449,7 @@ void wxCheckListBox::OnKeyDown(wxKeyEvent& event)
             wxCheckListBoxItem *item = GetItem(selections[i]);
             if ( !item )
             {
-                wxFAIL_MSG( _T("no wxCheckListBoxItem?") );
+                wxFAIL_MSG( wxT("no wxCheckListBoxItem?") );
                 continue;
             }
 
@@ -459,7 +465,7 @@ void wxCheckListBox::OnKeyDown(wxKeyEvent& event)
                     break;
 
                 default:
-                    wxFAIL_MSG( _T("what should this key do?") );
+                    wxFAIL_MSG( wxT("what should this key do?") );
             }
 
             // we should send an event as this has been done by the user and
@@ -482,9 +488,19 @@ void wxCheckListBox::OnLeftClick(wxMouseEvent& event)
 
         if ( nItem != wxNOT_FOUND )
         {
-            wxCheckListBoxItem *item = GetItem(nItem);
-            item->Toggle();
-            item->SendEvent();
+            // people expect to get "kill focus" event for the currently
+            // focused control before getting events from the other controls
+            // and, equally importantly, they may prevent the focus change from
+            // taking place at all (e.g. because the old control contents is
+            // invalid and needs to be corrected) in which case we shouldn't
+            // generate this event at all
+            SetFocus();
+            if ( FindFocus() == this )
+            {
+                wxCheckListBoxItem *item = GetItem(nItem);
+                item->Toggle();
+                item->SendEvent();
+            }
         }
         //else: it's not an error, just click outside of client zone
     }
@@ -495,20 +511,6 @@ void wxCheckListBox::OnLeftClick(wxMouseEvent& event)
     }
 }
 
-int wxCheckListBox::DoHitTestItem(wxCoord x, wxCoord y) const
-{
-    int nItem = (int)::SendMessage
-                             (
-                              (HWND)GetHWND(),
-                              LB_ITEMFROMPOINT,
-                              0,
-                              MAKELPARAM(x, y)
-                             );
-
-    return nItem >= (int)m_noItems ? wxNOT_FOUND : nItem;
-}
-
-
 wxSize wxCheckListBox::DoGetBestSize() const
 {
     wxSize best = wxListBox::DoGetBestSize();
@@ -517,4 +519,4 @@ wxSize wxCheckListBox::DoGetBestSize() const
     return best;
 }
 
-#endif
+#endif // wxUSE_CHECKLISTBOX