]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/checklst.cpp
wxGetFullHostName() implemented - it doesn't work though (and won't even
[wxWidgets.git] / src / msw / checklst.cpp
index dffc39d150503145995d8929b4891edef7adcff1..d0b312fb846153680c2f7e3bcdc4537bdbe5be4b 100644 (file)
@@ -40,6 +40,7 @@
 #include "wx/settings.h"
 #include "wx/dcmemory.h"
 #include "wx/msw/checklst.h"
+#include "wx/log.h"
 
 #include <windows.h>
 #include <windowsx.h>
@@ -100,7 +101,6 @@ wxCheckListBoxItem::wxCheckListBoxItem(wxCheckListBox *pParent, size_t nIndex)
   // know that there will always be OnMeasure before OnDraw
 
   // fix appearance
-  SetFont(wxSystemSettings::GetSystemFont(wxSYS_ANSI_VAR_FONT));
   SetMarginWidth(GetDefaultMarginWidth());
 }
 
@@ -226,11 +226,25 @@ void wxCheckListBoxItem::Check(bool check)
         m_nIndex = (size_t)index;
     }
 
-    size_t nHeight = m_pParent->GetItemHeight();
-    size_t y = m_nIndex * nHeight;
-    RECT rcUpdate = { 0, y, GetDefaultMarginWidth(), y + nHeight};
-    InvalidateRect((HWND)m_pParent->GetHWND(), &rcUpdate, FALSE);
-    
+    HWND hwndListbox = (HWND)m_pParent->GetHWND();
+
+    #ifdef __WIN32__
+        RECT rcUpdate;
+
+        if ( ::SendMessage(hwndListbox, LB_GETITEMRECT,
+                           m_nIndex, (LPARAM)&rcUpdate) == LB_ERR )
+        {
+            wxLogDebug("LB_GETITEMRECT failed");
+        }
+    #else // Win16
+        // FIXME this doesn't work if the listbox is scrolled!
+        size_t nHeight = m_pParent->GetItemHeight();
+        size_t y = m_nIndex * nHeight;
+        RECT rcUpdate = { 0, y, GetDefaultMarginWidth(), y + nHeight};
+    #endif  // Win32/16
+
+    InvalidateRect(hwndListbox, &rcUpdate, FALSE);
+
     wxCommandEvent event(wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, m_pParent->GetId());
     event.SetInt(m_nIndex);
     event.SetEventObject(m_pParent);
@@ -297,6 +311,16 @@ void wxCheckListBox::InsertItems(int nItems, const wxString items[], int pos)
     }
 }
 
+
+bool wxCheckListBox::SetFont( const wxFont &font )
+{
+    size_t i;
+    for (i=0; i < m_aItems.GetCount(); i++)
+        m_aItems[i]->SetFont(font);
+    wxListBox::SetFont(font);
+    return TRUE;
+}
+
 // create/retrieve item
 // --------------------
 
@@ -304,9 +328,6 @@ void wxCheckListBox::InsertItems(int nItems, const wxString items[], int pos)
 wxOwnerDrawn *wxCheckListBox::CreateItem(size_t nIndex)
 {
   wxCheckListBoxItem *pItem = new wxCheckListBoxItem(this, nIndex);
-  if ( m_windowFont.Ok() )
-    pItem->SetFont(m_windowFont);
-
   return pItem;
 }
 
@@ -350,15 +371,26 @@ void wxCheckListBox::OnChar(wxKeyEvent& event)
   if ( event.KeyCode() == WXK_SPACE )
     GetItem(GetSelection())->Toggle();
   else
-    wxListBox::OnChar(event);
+    event.Skip();
 }
 
 void wxCheckListBox::OnLeftClick(wxMouseEvent& event)
 {
   // clicking on the item selects it, clicking on the checkmark toggles
   if ( event.GetX() <= wxOwnerDrawn::GetDefaultMarginWidth() ) {
-    // FIXME better use LB_ITEMFROMPOINT perhaps?
-    size_t nItem = ((size_t)event.GetY()) / m_nItemHeight;
+    #ifdef __WIN32__
+      size_t nItem = (size_t)::SendMessage
+                               (
+                                (HWND)GetHWND(),
+                                LB_ITEMFROMPOINT,
+                                0,
+                                MAKELPARAM(event.GetX(), event.GetY())
+                               );
+    #else // Win16
+        // FIXME this doesn't work when the listbox is scrolled!
+        size_t nItem = ((size_t)event.GetY()) / m_nItemHeight;
+    #endif // Win32/16
+
     if ( nItem < (size_t)m_noItems )
       GetItem(nItem)->Toggle();
     //else: it's not an error, just click outside of client zone