Merge branch 'scintilla-551'
[TortoiseGit.git] / src / Utils / MiscUI / FilterEdit.h
blob9ceef3d2673d90c2f4ed710182def90a197d887f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016-2017, 2020, 2023 - TortoiseGit
4 // Copyright (C) 2007-2008, 2020 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
21 #include <memory>
23 /**
24 * \ingroup Utils
25 * Validator interface for the Filter edit control CFilterEdit
27 class IFilterEditValidator
29 public:
30 virtual bool Validate(LPCWSTR string) = 0;
33 /**
34 * \ingroup Utils
35 * Filter edit control.
36 * An edit control with a 'close' button on the right which clears the text
37 * in the control, and an info button on the left (optional) where a context
38 * menu or other selection window can be shown.
39 * \image html "filterEdit.jpg"
41 * Example on how to show a context menu for the info button:
42 * \code
43 * LRESULT CFilterEditTestDlg::OnFilterContext(WPARAM wParam, LPARAM lParam)
44 * {
45 * auto rect = reinterpret_cast<LPRECT>(lParam);
46 * POINT point;
47 * point.x = rect->left;
48 * point.y = rect->bottom;
49 * CMenu popup;
50 * if (popup.CreatePopupMenu())
51 * {
52 * popup.AppendMenu(MF_STRING | MF_ENABLED, 1, L"string 1");
53 * popup.AppendMenu(MF_SEPARATOR, NULL);
54 * popup.AppendMenu(MF_STRING | MF_ENABLED, 2, L"string 2");
55 * popup.AppendMenu(MF_STRING | MF_ENABLED, 3, L"string 3");
56 * popup.AppendMenu(MF_STRING | MF_ENABLED, 4, L"string 4");
57 * popup.AppendMenu(MF_STRING | MF_ENABLED, 5, L"string 5");
58 * popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this);
59 * }
60 * return 0;
61 * }
62 * \endcode
64 class CFilterEdit : public CEdit
66 DECLARE_DYNAMIC(CFilterEdit)
67 public:
68 CFilterEdit();
69 virtual ~CFilterEdit();
71 static const UINT WM_FILTEREDIT_INFOCLICKED;
72 static const UINT WM_FILTEREDIT_CANCELCLICKED;
74 /**
75 * Sets the icons to show for the cancel button. The first icon represents
76 * the normal state, the second one when the button is pressed.
77 * if \c bShowAlways is true, then the cancel button is shown even if there
78 * is no text in the control.
80 * The \c cx96dpi and \c cy96dpi specifies width and height of icon in 96 DPI.
81 * Control will automatically scale icon according to current DPI.
83 * \note To catch the WM_FILTEREDIT_CANCELCLICKED notification, handle the message directly (or use the
84 * WM_MESSAGE() macro). The LPARAM parameter of the message contains the
85 * rectangle (pointer to RECT) of the info icon in screen coordinates.
87 BOOL SetCancelBitmaps(UINT uCancelNormal, UINT uCancelPressed, int cx96dpi, int cy96dpi, BOOL bShowAlways = FALSE);
89 /**
90 * Sets the info icon shown on the left.
91 * A notification is sent when the user clicks on that icon.
92 * The notification is either WM_FILTEREDIT_INFOCLICKED or the one
93 * set with SetButtonClickedMessageId().
95 * The \c cx96dpi and \c cy96dpi specifies width and height of icon in 96 DPI.
96 * Control will automatically scale icon according to current DPI.
98 * To catch the notification, handle the message directly (or use the
99 * WM_MESSAGE() macro). The LPARAM parameter of the message contains the
100 * rectangle (pointer to RECT) of the info icon in screen coordinates.
102 BOOL SetInfoIcon(UINT uInfo, int cx96dpi, int cy96dpi);
105 * Sets the info icon shown on the left.
106 * A notification is sent when the user clicks on that icon.
107 * The notification is either WM_FILTEREDIT_INFOCLICKED or the one
108 * set with SetButtonClickedMessageId().
110 * The \c cx96dpi and \c cy96dpi specifies width and height of icon in 96 DPI.
111 * Control will automatically scale icon according to current DPI.
113 * To catch the notification, handle the message directly (or use the
114 * WM_MESSAGE() macro). The LPARAM parameter of the message contains the
115 * rectangle (pointer to RECT) of the info icon in screen coordinates.
117 void SetButtonClickedMessageId(UINT iButtonClickedMessageId, UINT iCancelClickedMessageId);
120 * To provide a cue banner even though we require the edit control to be multi line
122 BOOL SetCueBanner(LPCWSTR lpcwText);
124 void SetValidator(IFilterEditValidator * pValidator) {m_pValidator = pValidator;}
125 void Redraw() { ResizeWindow(); }
127 void ValidateAndRedraw() { OnEnChange(); }
129 protected:
130 void PreSubclassWindow() override;
131 BOOL PreTranslateMessage(MSG* pMsg) override;
132 ULONG GetGestureStatus(CPoint ptTouch) override;
134 afx_msg BOOL OnEraseBkgnd(CDC* pDC);
135 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
136 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
137 afx_msg void OnSize(UINT nType, int cx, int cy);
138 afx_msg LRESULT OnSetFont(WPARAM wParam, LPARAM lParam);
139 afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
140 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
141 afx_msg BOOL OnEnChange();
142 afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/);
143 afx_msg LRESULT OnThemeChanged();
144 afx_msg void OnSetFocus(CWnd* pOldWnd);
145 afx_msg void OnPaint();
146 afx_msg void OnEnKillfocus();
147 afx_msg void OnEnSetfocus();
148 afx_msg LRESULT OnPaste(WPARAM wParam, LPARAM lParam);
149 DECLARE_MESSAGE_MAP()
152 void ResizeWindow();
153 CSize GetIconSize(HICON hIcon);
154 void Validate();
155 void DrawDimText();
156 HICON LoadDpiScaledIcon(UINT resourceId, int cx96dpi, int cy96dpi);
157 void SetTheme(bool bDark);
159 protected:
160 CAutoIcon m_hIconCancelNormal;
161 CAutoIcon m_hIconCancelPressed;
162 CAutoIcon m_hIconInfo;
163 CSize m_sizeCancelIcon;
164 CSize m_sizeInfoIcon;
165 CRect m_rcEditArea;
166 CRect m_rcButtonArea;
167 CRect m_rcInfoArea;
168 BOOL m_bShowCancelButtonAlways = FALSE;
169 BOOL m_bPressed = FALSE;
170 UINT m_iButtonClickedMessageId = WM_FILTEREDIT_INFOCLICKED;
171 UINT m_iCancelClickedMessageId = WM_FILTEREDIT_CANCELCLICKED;
172 COLORREF m_backColor;
173 CBrush m_brBack;
174 int m_themeCallbackId = 0;
175 IFilterEditValidator* m_pValidator = nullptr;
176 CString m_sCueBanner;