1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2016-2017 - TortoiseGit
4 // Copyright (C) 2007-2008 - 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.
25 * Validator interface for the Filter edit control CFilterEdit
27 class IFilterEditValidator
30 virtual bool Validate(LPCTSTR string
) = 0;
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:
43 * LRESULT CFilterEditTestDlg::OnFilterContext(WPARAM wParam, LPARAM lParam)
45 * RECT * rect = (LPRECT)lParam;
47 * point.x = rect->left;
48 * point.y = rect->bottom;
50 * if (popup.CreatePopupMenu())
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);
64 class CFilterEdit
: public CEdit
66 DECLARE_DYNAMIC(CFilterEdit
)
69 virtual ~CFilterEdit();
71 static const UINT WM_FILTEREDIT_INFOCLICKED
;
72 static const UINT WM_FILTEREDIT_CANCELCLICKED
;
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
);
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 * To catch the notification, handle the message directly (or use the
96 * WM_MESSAGE() macro). The LPARAM parameter of the message contains the
97 * rectangle (pointer to RECT) of the info icon in screen coordinates.
99 BOOL
SetInfoIcon(UINT uInfo
, int cx96dpi
, int cy96dpi
);
102 * Sets the info icon shown on the left.
103 * A notification is sent when the user clicks on that icon.
104 * The notification is either WM_FILTEREDIT_INFOCLICKED or the one
105 * set with SetButtonClickedMessageId().
107 * The \c cx96dpi and \c cy96dpi specifies width and height of icon in 96 DPI.
108 * Control will automatically scale icon according to current DPI.
110 * To catch the notification, handle the message directly (or use the
111 * WM_MESSAGE() macro). The LPARAM parameter of the message contains the
112 * rectangle (pointer to RECT) of the info icon in screen coordinates.
114 void SetButtonClickedMessageId(UINT iButtonClickedMessageId
, UINT iCancelClickedMessageId
);
117 * To provide a cue banner even though we require the edit control to be multi line
119 BOOL
SetCueBanner(LPCWSTR lpcwText
);
121 void SetValidator(IFilterEditValidator
* pValidator
) {m_pValidator
= pValidator
;}
123 void ValidateAndRedraw();
125 virtual void PreSubclassWindow() override
;
126 virtual BOOL
PreTranslateMessage(MSG
* pMsg
) override
;
127 virtual ULONG
GetGestureStatus(CPoint ptTouch
) override
;
129 afx_msg BOOL
OnEraseBkgnd(CDC
* pDC
);
130 afx_msg
void OnLButtonUp(UINT nFlags
, CPoint point
);
131 afx_msg
int OnCreate(LPCREATESTRUCT lpCreateStruct
);
132 afx_msg
void OnSize(UINT nType
, int cx
, int cy
);
133 afx_msg LRESULT
OnSetFont(WPARAM wParam
, LPARAM lParam
);
134 afx_msg BOOL
OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
);
135 afx_msg
void OnLButtonDown(UINT nFlags
, CPoint point
);
136 afx_msg BOOL
OnEnChange();
137 afx_msg HBRUSH
CtlColor(CDC
* /*pDC*/, UINT
/*nCtlColor*/);
138 afx_msg
void OnPaint();
139 afx_msg
void OnEnKillfocus();
140 afx_msg
void OnEnSetfocus();
141 afx_msg LRESULT
OnPaste(WPARAM wParam
, LPARAM lParam
);
142 afx_msg
void OnSysColorChange();
143 DECLARE_MESSAGE_MAP()
147 CSize
GetIconSize(HICON hIcon
);
150 HICON
LoadDpiScaledIcon(UINT resourceId
, int cx96dpi
, int cy96dpi
);
153 HICON m_hIconCancelNormal
;
154 HICON m_hIconCancelPressed
;
156 CSize m_sizeCancelIcon
;
157 CSize m_sizeInfoIcon
;
159 CRect m_rcButtonArea
;
161 BOOL m_bShowCancelButtonAlways
;
163 UINT m_iButtonClickedMessageId
;
164 UINT m_iCancelClickedMessageId
;
165 COLORREF m_backColor
;
167 IFilterEditValidator
* m_pValidator
;
168 CString m_sCueBanner
;