Re-validate log filter expression after toggling Regex option
[TortoiseGit.git] / src / Utils / MiscUI / FilterEdit.h
blob0f19ba3e31c6719dd8fc918e4490b951eefaa663
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008 - TortoiseSVN
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 <memory>
22 #define WM_FILTEREDIT_INFOCLICKED (WM_USER + 102)
23 #define WM_FILTEREDIT_CANCELCLICKED (WM_USER + 101)
25 /**
26 * \ingroup Utils
27 * Validator interface for the Filter edit control CFilterEdit
29 class IFilterEditValidator
31 public:
32 virtual bool Validate(LPCTSTR string) = 0;
35 /**
36 * \ingroup Utils
37 * Filter edit control.
38 * An edit control with a 'close' button on the right which clears the text
39 * in the control, and an info button on the left (optional) where a context
40 * menu or other selection window can be shown.
41 * \image html "filterEdit.jpg"
43 * Example on how to show a context menu for the info button:
44 * \code
45 * LRESULT CFilterEditTestDlg::OnFilterContext(WPARAM wParam, LPARAM lParam)
46 * {
47 * RECT * rect = (LPRECT)lParam;
48 * POINT point;
49 * point.x = rect->left;
50 * point.y = rect->bottom;
51 * CMenu popup;
52 * if (popup.CreatePopupMenu())
53 * {
54 * popup.AppendMenu(MF_STRING | MF_ENABLED, 1, _T("string 1"));
55 * popup.AppendMenu(MF_SEPARATOR, NULL);
56 * popup.AppendMenu(MF_STRING | MF_ENABLED, 2, _T("string 2"));
57 * popup.AppendMenu(MF_STRING | MF_ENABLED, 3, _T("string 3"));
58 * popup.AppendMenu(MF_STRING | MF_ENABLED, 4, _T("string 4"));
59 * popup.AppendMenu(MF_STRING | MF_ENABLED, 5, _T("string 5"));
60 * popup.TrackPopupMenu(TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY, point.x, point.y, this, 0);
61 * }
62 * return 0;
63 * }
64 * \endcode
66 class CFilterEdit : public CEdit
68 DECLARE_DYNAMIC(CFilterEdit)
69 public:
70 CFilterEdit();
71 virtual ~CFilterEdit();
73 /**
74 * Sets the icons to show for the cancel button. The first icon represents
75 * the normal state, the second one when the button is pressed.
76 * if \c bShowAlways is true, then the cancel button is shown even if there
77 * is no text in the control.
78 * \note To catch the WM_FILTEREDIT_CANCELCLICKED notification, handle the message directly (or use the
79 * WM_MESSAGE() macro). The LPARAM parameter of the message contains the
80 * rectangle (pointer to RECT) of the info icon in screen coordinates.
82 BOOL SetCancelBitmaps(UINT uCancelNormal, UINT uCancelPressed, BOOL bShowAlways = FALSE);
84 /**
85 * Sets the info icon shown on the left.
86 * A notification is sent when the user clicks on that icon.
87 * The notification is either WM_FILTEREDIT_INFOCLICKED or the one
88 * set with SetButtonClickedMessageId().
90 * To catch the notification, handle the message directly (or use the
91 * WM_MESSAGE() macro). The LPARAM parameter of the message contains the
92 * rectangle (pointer to RECT) of the info icon in screen coordinates.
94 BOOL SetInfoIcon(UINT uInfo);
96 /**
97 * Sets the message Id which is sent when the user clicks on the info
98 * button.
100 void SetButtonClickedMessageId(UINT iButtonClickedMessageId, UINT iCancelClickedMessageId);
103 * To provide a cue banner even though we require the edit control to be multi line
105 BOOL SetCueBanner(LPCWSTR lpcwText);
107 void SetValidator(IFilterEditValidator * pValidator) {m_pValidator = pValidator;}
109 void ValidateAndRedraw();
110 protected:
111 virtual void PreSubclassWindow( );
112 virtual BOOL PreTranslateMessage( MSG* pMsg );
114 afx_msg BOOL OnEraseBkgnd(CDC* pDC);
115 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
116 afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
117 afx_msg void OnSize(UINT nType, int cx, int cy);
118 afx_msg LRESULT OnSetFont(WPARAM wParam, LPARAM lParam);
119 afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
120 afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
121 afx_msg BOOL OnEnChange();
122 afx_msg HBRUSH CtlColor(CDC* /*pDC*/, UINT /*nCtlColor*/);
123 afx_msg void OnPaint();
124 afx_msg void OnEnKillfocus();
125 afx_msg void OnEnSetfocus();
126 afx_msg LRESULT OnPaste(WPARAM wParam, LPARAM lParam);
127 DECLARE_MESSAGE_MAP()
130 void ResizeWindow();
131 CSize GetIconSize(HICON hIcon);
132 void Validate();
133 void DrawDimText();
135 protected:
136 HICON m_hIconCancelNormal;
137 HICON m_hIconCancelPressed;
138 HICON m_hIconInfo;
139 CSize m_sizeCancelIcon;
140 CSize m_sizeInfoIcon;
141 CRect m_rcEditArea;
142 CRect m_rcButtonArea;
143 CRect m_rcInfoArea;
144 BOOL m_bShowCancelButtonAlways;
145 BOOL m_bPressed;
146 UINT m_iButtonClickedMessageId;
147 UINT m_iCancelClickedMessageId;
148 COLORREF m_backColor;
149 HBRUSH m_brBack;
150 IFilterEditValidator * m_pValidator;
151 std::unique_ptr<TCHAR[]> m_pCueBanner;