]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/listctrl.cpp
VTK wrapper of vtkRenderWindow for wxPython. Tested on MSW so far.
[wxWidgets.git] / src / msw / listctrl.cpp
index 1470b9659cac1d24aba2735c399c91cbcba5fc6c..e6a6f0f08e505453d59514ec0275697e267e1cb9 100644 (file)
@@ -39,7 +39,7 @@
 
 #include "wx/msw/private.h"
 
 
 #include "wx/msw/private.h"
 
-#ifdef __GNUWIN32__
+#if defined(__GNUWIN32__) && !defined(wxUSE_NORLANDER_HEADERS)
     #include "wx/msw/gnuwin32/extra.h"
 #else
     #include <commctrl.h>
     #include "wx/msw/gnuwin32/extra.h"
 #else
     #include <commctrl.h>
@@ -149,7 +149,7 @@ bool wxListCtrl::DoCreateControl(int x, int y, int w, int h)
     // Create the ListView control.
     m_hWnd = (WXHWND)CreateWindowEx(exStyle,
                                     WC_LISTVIEW,
     // Create the ListView control.
     m_hWnd = (WXHWND)CreateWindowEx(exStyle,
                                     WC_LISTVIEW,
-                                    _T(""),
+                                    wxT(""),
                                     wstyle,
                                     x, y, w, h,
                                     GetWinHwnd(GetParent()),
                                     wstyle,
                                     x, y, w, h,
                                     GetWinHwnd(GetParent()),
@@ -159,7 +159,7 @@ bool wxListCtrl::DoCreateControl(int x, int y, int w, int h)
 
     if ( !m_hWnd )
     {
 
     if ( !m_hWnd )
     {
-        wxLogError(_T("Can't create list control window."));
+        wxLogError(wxT("Can't create list control window."));
 
         return FALSE;
     }
 
         return FALSE;
     }
@@ -174,8 +174,7 @@ bool wxListCtrl::DoCreateControl(int x, int y, int w, int h)
     }
 #endif // ListView_SetExtendedListViewStyle
 
     }
 #endif // ListView_SetExtendedListViewStyle
 
-    wxSystemSettings settings;
-    SetBackgroundColour(settings.GetSystemColour(wxSYS_COLOUR_WINDOW));
+    SetBackgroundColour(wxSystemSettings::GetSystemColour(wxSYS_COLOUR_WINDOW));
     SetForegroundColour(GetParent()->GetForegroundColour());
 
     SubclassWin(m_hWnd);
     SetForegroundColour(GetParent()->GetForegroundColour());
 
     SubclassWin(m_hWnd);
@@ -498,11 +497,7 @@ wxTextCtrl* wxListCtrl::GetEditControl(void) const
 bool wxListCtrl::GetItem(wxListItem& info) const
 {
     LV_ITEM lvItem;
 bool wxListCtrl::GetItem(wxListItem& info) const
 {
     LV_ITEM lvItem;
-#ifdef __GNUWIN32__
-    memset(&lvItem, 0, sizeof(lvItem));
-#else
-    ZeroMemory(&lvItem, sizeof(lvItem)); // must set all fields to 0
-#endif
+    wxZeroMemory(lvItem);
 
     lvItem.iItem = info.m_itemId;
     lvItem.iSubItem = info.m_col;
 
     lvItem.iItem = info.m_itemId;
     lvItem.iSubItem = info.m_col;
@@ -872,7 +867,7 @@ bool wxListCtrl::DeleteAllColumns()
         m_colCount--;
     }
 
         m_colCount--;
     }
 
-    wxASSERT_MSG( m_colCount == 0, _T("no columns should be left") );
+    wxASSERT_MSG( m_colCount == 0, wxT("no columns should be left") );
 
     return TRUE;
 }
 
     return TRUE;
 }
@@ -1117,7 +1112,7 @@ long wxListCtrl::InsertColumn(long col, wxListItem& item)
     }
     else
     {
     }
     else
     {
-        wxLogDebug(_T("Failed to insert the column '%s' into listview!"),
+        wxLogDebug(wxT("Failed to insert the column '%s' into listview!"),
                    lvCol.pszText);
     }
 
                    lvCol.pszText);
     }
 
@@ -1198,7 +1193,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
     switch ( hdr1->code )
     {
         case LVN_BEGINRDRAG:
     switch ( hdr1->code )
     {
         case LVN_BEGINRDRAG:
-            eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
+        eventType = wxEVT_COMMAND_LIST_BEGIN_RDRAG;
             // fall through
 
         case LVN_BEGINDRAG:
             // fall through
 
         case LVN_BEGINDRAG:
@@ -1231,13 +1226,21 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
                 event.m_col = hdr->iSubItem;
                 break;
             }
                 event.m_col = hdr->iSubItem;
                 break;
             }
+
         case LVN_DELETEALLITEMS:
         case LVN_DELETEALLITEMS:
-            {
-                eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
-                //      NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
-                event.m_itemIndex = -1;
-                break;
-            }
+            // what's the sense of generating a wxWin event for this when
+            // it's absolutely not portable?
+#if 0
+            eventType = wxEVT_COMMAND_LIST_DELETE_ALL_ITEMS;
+            event.m_itemIndex = -1;
+#endif // 0
+
+            // return TRUE to suppress all additional LVN_DELETEITEM
+            // notifications - this makes deleting all items from a list ctrl
+            // much faster
+            *result = TRUE;
+            return TRUE;
+
         case LVN_DELETEITEM:
             {
                 eventType = wxEVT_COMMAND_LIST_DELETE_ITEM;
         case LVN_DELETEITEM:
             {
                 eventType = wxEVT_COMMAND_LIST_DELETE_ITEM;
@@ -1249,9 +1252,9 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
             {
                 eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
                 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
             {
                 eventType = wxEVT_COMMAND_LIST_END_LABEL_EDIT;
                 LV_DISPINFO *info = (LV_DISPINFO *)lParam;
-                wxConvertFromMSWListItem(this, event.m_item, info->item, GetHwnd());
+                wxConvertFromMSWListItem(this, event.m_item, info->item);
                 if ( info->item.pszText == NULL || info->item.iItem == -1 )
                 if ( info->item.pszText == NULL || info->item.iItem == -1 )
-                    event.m_cancelled = TRUE;
+                    return FALSE;
                 break;
             }
         case LVN_GETDISPINFO:
                 break;
             }
         case LVN_GETDISPINFO:
@@ -1334,9 +1337,65 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
             }
 
             // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
             }
 
             // else translate it into wxEVT_COMMAND_LIST_ITEM_ACTIVATED event
-            eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
+            {
+                eventType = wxEVT_COMMAND_LIST_ITEM_ACTIVATED;
+                NM_LISTVIEW* hdr = (NM_LISTVIEW*)lParam;
+                event.m_itemIndex = hdr->iItem;
+            }
             break;
 
             break;
 
+        case NM_RCLICK:
+        /* TECH NOTE: NM_RCLICK isn't really good enough here. We want to
+           subclass and check for the actual WM_RBUTTONDOWN message, because
+           NM_RCLICK waits for the WM_RBUTTONUP message as well before firing off.
+           We want to have notify events for both down -and- up. */
+        {
+            // if the user processes it in wxEVT_COMMAND_RIGHT_CLICK(), don't do
+            // anything else
+            if ( wxControl::MSWOnNotify(idCtrl, lParam, result) ) {
+                return TRUE;
+            }
+
+            // else translate it into wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK event
+            LV_HITTESTINFO lvhti;
+            wxZeroMemory(lvhti);
+
+            ::GetCursorPos(&(lvhti.pt));
+            ::ScreenToClient(GetHwnd(),&(lvhti.pt));
+            if ( ListView_HitTest(GetHwnd(),&lvhti) != -1 )
+            {
+                // older headers don't have this symbol
+#ifndef LVHT_ONITEM
+    #define LVHT_ONITEM \
+                (LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON)
+#endif
+                if ( lvhti.flags & LVHT_ONITEM )
+                {
+                    eventType = wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK;
+                    event.m_itemIndex = lvhti.iItem;
+                }
+            }
+        }
+            break;
+
+        /*
+          case NM_MCLICK: // ***** THERE IS NO NM_MCLICK. Subclass anyone? ******
+          {
+          // if the user processes it in wxEVT_COMMAND_MIDDLE_CLICK(), don't do
+          // anything else
+          if ( wxControl::MSWOnNotify(idCtrl, lParam, result) )
+          {
+          return TRUE;
+          }
+
+          // else translate it into wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK event
+          eventType = wxEVT_COMMAND_LIST_ITEM_MIDDLE_CLICK;
+          NMITEMACTIVATE* hdr = (NMITEMACTIVATE*)lParam;
+          event.m_itemIndex = hdr->iItem;
+          }
+          break;
+        */
+
         case LVN_SETDISPINFO:
             {
                 eventType = wxEVT_COMMAND_LIST_SET_INFO;
         case LVN_SETDISPINFO:
             {
                 eventType = wxEVT_COMMAND_LIST_SET_INFO;
@@ -1355,18 +1414,29 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
     if ( !GetEventHandler()->ProcessEvent(event) )
         return FALSE;
 
     if ( !GetEventHandler()->ProcessEvent(event) )
         return FALSE;
 
-    if (hdr1->code == LVN_GETDISPINFO)
+    switch ((int)hdr1->code)
     {
     {
-        LV_DISPINFO *info = (LV_DISPINFO *)lParam;
-        if ( info->item.mask & LVIF_TEXT )
-        {
-            if ( !event.m_item.m_text.IsNull() )
+        case LVN_GETDISPINFO:
             {
             {
-                info->item.pszText = AddPool(event.m_item.m_text);
-                info->item.cchTextMax = wxStrlen(info->item.pszText) + 1;
+                LV_DISPINFO *info = (LV_DISPINFO *)lParam;
+                if ( info->item.mask & LVIF_TEXT )
+                {
+                    if ( !event.m_item.m_text.IsNull() )
+                    {
+                        info->item.pszText = AddPool(event.m_item.m_text);
+                        info->item.cchTextMax = wxStrlen(info->item.pszText) + 1;
+                    }
+                }
+                //    wxConvertToMSWListItem(this, event.m_item, info->item);
+                break;
             }
             }
-        }
-        //    wxConvertToMSWListItem(this, event.m_item, info->item);
+        case LVN_ENDLABELEDIT:
+            {
+                *result = event.IsAllowed();
+                return TRUE;
+            }
+        default:
+            break;
     }
 
     *result = !event.IsAllowed();
     }
 
     *result = !event.IsAllowed();
@@ -1561,6 +1631,7 @@ wxListEvent::wxListEvent(wxEventType commandType, int id)
 {
     m_code = 0;
     m_itemIndex = 0;
 {
     m_code = 0;
     m_itemIndex = 0;
+    m_oldItemIndex = 0;
     m_col = 0;
     m_cancelled = FALSE;
 }
     m_col = 0;
     m_cancelled = FALSE;
 }