Unbreak RefBroweser context menu
[TortoiseGit.git] / src / TortoiseProc / ResizableColumnsListCtrl.h
blob5cf58328ffdd7e808ab2e3521a09e4caeb220c87
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #pragma once
20 #include "ColumnManager.h"
22 template <typename BaseType> class CResizableColumnsListCtrl : public BaseType
24 public:
25 CResizableColumnsListCtrl()
26 : BaseType()
27 , m_ColumnManager(this)
28 , m_bAllowHiding(true)
31 DECLARE_MESSAGE_MAP()
33 protected:
34 void OnDestroy()
36 SaveColumnWidths();
37 BaseType::OnDestroy();
40 void OnHeaderDblClick(NMHDR* pNMHDR, LRESULT* pResult)
42 m_ColumnManager.OnHeaderDblClick(pNMHDR, pResult);
44 *pResult = FALSE;
47 void OnColumnResized(NMHDR* pNMHDR, LRESULT* pResult)
49 m_ColumnManager.OnColumnResized(pNMHDR, pResult);
51 *pResult = FALSE;
54 void OnColumnMoved(NMHDR* pNMHDR, LRESULT* pResult)
56 m_ColumnManager.OnColumnMoved(pNMHDR, pResult);
58 Invalidate(FALSE);
61 void OnContextMenuHeader(CWnd* pWnd, CPoint point)
63 m_ColumnManager.OnContextMenuHeader(pWnd, point, !!IsGroupViewEnabled());
66 void OnContextMenu(CWnd* pWnd, CPoint point)
68 if (pWnd == GetHeaderCtrl() && m_bAllowHiding)
69 OnContextMenuHeader(pWnd, point);
70 else if (pWnd == this && m_ContextMenuHandler)
71 m_ContextMenuHandler(point);
74 // prevent users from extending our hidden (size 0) columns
75 void OnHdnBegintrack(NMHDR* pNMHDR, LRESULT* pResult)
77 m_ColumnManager.OnHdnBegintrack(pNMHDR, pResult);
80 // prevent any function from extending our hidden (size 0) columns
81 void OnHdnItemchanging(NMHDR* pNMHDR, LRESULT* pResult)
83 if (!m_ColumnManager.OnHdnItemchanging(pNMHDR, pResult))
84 Default();
87 typedef std::function<void(CPoint point)> ContextMenuHandler;
88 ContextMenuHandler m_ContextMenuHandler;
90 public:
91 void Init()
93 CRegDWORD regFullRowSelect(L"Software\\TortoiseGit\\FullRowSelect", TRUE);
94 DWORD exStyle = LVS_EX_HEADERDRAGDROP;
95 if (DWORD(regFullRowSelect))
96 exStyle |= LVS_EX_FULLROWSELECT;
97 SetExtendedStyle(GetExtendedStyle() | exStyle);
100 void SetListContextMenuHandler(ContextMenuHandler pContextMenuHandler)
102 m_ContextMenuHandler = pContextMenuHandler;
105 void AdjustColumnWidths()
107 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount() - 1;
108 for (int col = 0; col <= maxcol; col++)
109 SetColumnWidth(col, m_ColumnManager.GetWidth(col, true));
111 virtual void SaveColumnWidths()
113 int maxcol = ((CHeaderCtrl*)(GetDlgItem(0)))->GetItemCount() - 1;
114 for (int col = 0; col <= maxcol; col++)
115 if (m_ColumnManager.IsVisible(col))
116 m_ColumnManager.ColumnResized(col);
118 m_ColumnManager.WriteSettings();
121 bool m_bAllowHiding;
122 ColumnManager m_ColumnManager;
125 BEGIN_TEMPLATE_MESSAGE_MAP(CResizableColumnsListCtrl, BaseType, BaseType)
126 ON_NOTIFY(HDN_BEGINTRACKA, 0, OnHdnBegintrack)
127 ON_NOTIFY(HDN_BEGINTRACKW, 0, OnHdnBegintrack)
128 ON_NOTIFY(HDN_ENDTRACK, 0, OnColumnResized)
129 ON_NOTIFY(HDN_ENDDRAG, 0, OnColumnMoved)
130 ON_NOTIFY(HDN_DIVIDERDBLCLICK, 0, OnHeaderDblClick)
131 ON_NOTIFY(HDN_ITEMCHANGINGA, 0, OnHdnItemchanging)
132 ON_NOTIFY(HDN_ITEMCHANGINGW, 0, OnHdnItemchanging)
133 ON_WM_DESTROY()
134 ON_WM_CONTEXTMENU()
135 END_MESSAGE_MAP()