Allow to move item past last item
[TortoiseGit.git] / src / Utils / MiscUI / MessageBox.h
blob1350381a35bfad3e813e2ee84d44c65634125b25
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013-2016 - TortoiseGit
4 // Copyright (C) 2003-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.
20 #pragma once
22 #include "dlgtemplate.h"
23 #include "cursor.h"
25 #define IDC_MESSAGEBOX_BUTTON1 101
26 #define IDC_MESSAGEBOX_BUTTON2 102
27 #define IDC_MESSAGEBOX_BUTTON3 103
28 #define IDC_MESSAGEBOX_CHECKBOX 104
30 #define MESSAGEBOX_BUTTONMARGIN 5
31 #define MESSAGEBOX_ICONMARGIN 15
32 #define MESSAGEBOX_BORDERMARGINX 10
33 #define MESSAGEBOX_BORDERMARGINY 10
34 #define MESSAGEBOX_TEXTBUTTONMARGIN 15
35 #define MESSAGEBOX_BUTTONCHECKMARGIN 5
36 #define MESSAGEBOX_BUTTONX 20
37 #define MESSAGEBOX_BUTTONY 5
39 /**
40 * \ingroup Utils
41 * Implements an enhanced MessageBox().\n
43 * You can use CMessageBox::Show() as a replacement for the Platform SDK version of
44 * MessageBox(). Most of the flags are supported (param uType):\n
45 * To indicate the buttons displayed in the message box, specify one of the following values:
46 * <TABLE>
47 * <TR VALIGN="top">
48 * <TH align=left width=39%>Value</TH>
49 * <TH align=left width=61%>Meaning</TH>
50 * </TR>
52 * <TR VALIGN="top">
53 * <TD width=39%>MB_ABORTRETRYIGNORE</TD>
54 * <TD width=61%>The message box contains three push buttons: <B>Abort</B>, <B>Retry</B>, and <B>Ignore</B>.</TD>
55 * </TR>
57 * <TR VALIGN="top">
58 * <TD width=39%>MB_CANCELTRYCONTINUE</TD>
59 * <TD width=61%>The message box contains three push buttons: <B>Cancel</B>, <B>Try Again</B>, <B>Continue</B>. Use this message box type instead of MB_ABORTRETRYIGNORE.</TD>
60 * </TR>
62 * <TR VALIGN="top">
63 * <TD width=39%>MB_OK</TD>
64 * <TD width=61%>The message box contains one push button: <B>OK</B>. This is the default.</TD>
65 * </TR>
67 * <TR VALIGN="top">
68 * <TD width=39%>MB_OKCANCEL</TD>
69 * <TD width=61%>The message box contains two push buttons: <B>OK</B> and <B>Cancel</B>.</TD>
70 * </TR>
72 * <TR VALIGN="top">
73 * <TD width=39%>MB_RETRYCANCEL</TD>
74 * <TD width=61%>The message box contains two push buttons: <B>Retry</B> and <B>Cancel</B>.</TD>
75 * </TR>
77 * <TR VALIGN="top">
78 * <TD width=39%>MB_YESNO</TD>
79 * <TD width=61%>The message box contains two push buttons: <B>Yes</B> and <B>No</B>.</TD>
80 * </TR>
82 * <TR VALIGN="top">
83 * <TD width=39%>MB_YESNOCANCEL</TD>
84 * <TD width=61%>The message box contains three push buttons: <B>Yes</B>, <B>No</B>, and <B>Cancel</B>.</TD>
85 * </TR>
86 * </TABLE>
87 * To display an icon in the message box, specify one of the following values
88 * <TABLE>
90 * <TR VALIGN="top">
91 * <TH align=left width=38%>Value</TH>
92 * <TH align=left width=62%>Meaning</TH>
93 * </TR>
95 * <TR VALIGN="top">
96 * <TD width=38%>MB_ICONEXCLAMATION, <BR>
97 * MB_ICONWARNING</TD>
98 * <TD width=62%>An exclamation-point icon appears in the message box.</TD>
99 * </TR>
101 * <TR VALIGN="top">
102 * <TD width=38%>MB_ICONINFORMATION, MB_ICONASTERISK</TD>
103 * <TD width=62%>An icon consisting of a lowercase letter <I>i</I> in a circle appears in the message box.</TD>
104 * </TR>
106 * <TR VALIGN="top">
107 * <TD width=38%>MB_ICONQUESTION</TD>
108 * <TD width=62%>A question-mark icon appears in the message box.</TD>
109 * </TR>
111 * <TR VALIGN="top">
112 * <TD width=38%>MB_ICONSTOP, <BR>
113 * MB_ICONERROR, <BR>
114 * MB_ICONHAND</TD>
115 * <TD width=62%>A stop-sign icon appears in the message box.</TD>
116 * </TR>
117 * </TABLE>
118 * To indicate the default button, specify one of the following values
119 * <TABLE>
121 * <TR VALIGN="top">
122 * <TH align=left width=39%>Value</TH>
123 * <TH align=left width=61%>Meaning</TH>
124 * </TR>
126 * <TR VALIGN="top">
127 * <TD width=39%>MB_DEFBUTTON1</TD>
128 * <TD width=61%>The first button is the default button.
129 * <P>MB_DEFBUTTON1 is the default unless MB_DEFBUTTON2, MB_DEFBUTTON3, or MB_DEFBUTTON4 is specified.</P>
130 * </TD>
131 * </TR>
133 * <TR VALIGN="top">
134 * <TD width=39%>MB_DEFBUTTON2</TD>
135 * <TD width=61%>The second button is the default button.</TD>
136 * </TR>
138 * <TR VALIGN="top">
139 * <TD width=39%>MB_DEFBUTTON3</TD>
140 * <TD width=61%>The third button is the default button.</TD>
141 * </TR>
143 * <TR VALIGN="top">
144 * <TD width=39%>MB_DEFBUTTON4</TD>
145 * <TD width=61%>The fourth button is the default button.</TD>
146 * </TR>
147 * </TABLE>
149 * <b>return values:</b>\n
150 * <TABLE>
152 * <TR VALIGN="top">
153 * <TH align=left width=22%>Value</TH>
154 * <TH align=left width=78%>Meaning</TH>
155 * </TR>
157 * <TR VALIGN="top">
158 * <TD width=22%>IDABORT</TD>
159 * <TD width=78%><B>Abort</B> button was selected.</TD>
160 * </TR>
162 * <TR VALIGN="top">
163 * <TD width=22%>IDCANCEL</TD>
164 * <TD width=78%><B>Cancel</B> button was selected.</TD>
165 * </TR>
167 * <TR VALIGN="top">
168 * <TD width=22%>IDCONTINUE</TD>
169 * <TD width=78%><B>Continue</B> button was selected.</TD>
170 * </TR>
172 * <TR VALIGN="top">
173 * <TD width=22%>IDIGNORE</TD>
174 * <TD width=78%><B>Ignore</B> button was selected.</TD>
175 * </TR>
177 * <TR VALIGN="top">
178 * <TD width=22%>IDNO</TD>
179 * <TD width=78%><B>No</B> button was selected.</TD>
180 * </TR>
182 * <TR VALIGN="top">
183 * <TD width=22%>IDOK</TD>
184 * <TD width=78%><B>OK</B> button was selected.</TD>
185 * </TR>
187 * <TR VALIGN="top">
188 * <TD width=22%>IDRETRY</TD>
189 * <TD width=78%><B>Retry</B> button was selected.</TD>
190 * </TR>
192 * <TR VALIGN="top">
193 * <TD width=22%>IDTRYAGAIN</TD>
194 * <TD width=78%><B>Try Again</B> button was selected.</TD>
195 * </TR>
197 * <TR VALIGN="top">
198 * <TD width=22%>IDYES</TD>
199 * <TD width=78%><B>Yes</B> button was selected.</TD>
200 * </TR>
201 * </TABLE>
202 * If a message box has a <B>Cancel</B> button, the function returns the IDCANCEL value
203 * if either the ESC key is pressed or the <B>Cancel</B> button is selected. If the
204 * message box has no <B>Cancel</B> button, pressing ESC has no effect.
206 * To get I18L you can define the following strings in your resource string table:\n
207 * - IDS_MSGBOX_ABORT
208 * - IDS_MSGBOX_RETRY
209 * - IDS_MSGBOX_IGNORE
210 * - IDS_MSGBOX_CANCEL
211 * - IDS_MSGBOX_TRYAGAIN
212 * - IDS_MSGBOX_CONTINUE
213 * - IDS_MSGBOX_OK
214 * - IDS_MSGBOX_YES
215 * - IDS_MSGBOX_NO
216 * - IDS_MSGBOX_DONOTSHOWAGAIN
218 * It is also possible to set the button texts for each one of the three buttons.
219 * Use the corresponding method provided for this.
220 * \image html "CMessageBox_3.jpg"
222 * For the "Do not show again" functionality you can define the registry base path
223 * for storing the return values with\n
224 * \code
225 * #define XMESSAGEBOX_APPREGPATH "Software\\MyApplication\\MsgDialogs\\"
226 * \endcode
227 * if you don't do that define then CMessageBox will use the default path "Software\\YourApplicationName\\"
229 class CMessageBox : public CDialog
231 public:
232 CMessageBox(void);
233 ~CMessageBox(void);
235 * Shows a message box. Use this as a replacement for the usual ::MessageBox() calls.
236 * Most of the flags of the Platform SDK version are supported. See the class descriptions
237 * for details.
238 * \param hWnd handle to the parent window or nullptr
239 * \param lpMessage the message string to show on the message box
240 * \param lpCaption the dialog title
241 * \param uType see class description for details
242 * \param sHelpPath if uType has MB_HELP, the path for the help file
243 * \return see class descriptions for details
245 static UINT Show(HWND hWnd, LPCTSTR lpMessage, LPCTSTR lpCaption, UINT uType, LPCTSTR sHelpPath = nullptr);
247 * Shows a message box.
248 * \param hWnd handle to the parent window or nullptr
249 * \param nMessage resource ID of the message string
250 * \param nCaption resource ID of the title string
251 * \param uType see class description for details
252 * \param sHelpPath if uType has MB_HELP, this is the path of the help file to use
253 * \return see class description for details
255 static UINT Show(HWND hWnd, UINT nMessage, UINT nCaption, UINT uType, LPCTSTR sHelpPath = nullptr);
257 * Shows a message box.
258 * \param hWnd handle to the parent window or nullptr
259 * \param nMessage resource ID of the message string
260 * \param nCaption resource ID of the title string
261 * \param uType see class description for details
262 * \param nHelpID if uType has MB_HELP, this is the help ID to use
263 * \return see class description for details
265 static UINT Show(HWND hWnd, UINT nMessage, UINT nCaption, UINT uType, UINT nHelpID);
267 * Shows a message box with a checkbox. If the user checks it then the next time
268 * the message box isn't shown anymore - the method simply returns the same value as
269 * the last time. Use this to give the user the possibility to ignore specific message
270 * boxes ("Do not show again"-checkbox).
271 * \param hWnd handle to the parent window or nullptr
272 * \param lpMessage the message string to show on the message box
273 * \param lpCaption the dialog title
274 * \param uType see class description for details
275 * \param lpRegistry a value string to store the return value of this specific message box. Put nullptr or empty if you do not use registry.
276 * Each one of your message boxes must have it's own value string! Examples for such values
277 * might be "WarnOverwrite", "InformAboutMissingMailSubject", ...
278 * \param lpCheckMessage the message to show on the checkbox label. If this parameter is omitted
279 * then it defaults to "do not show again" or the string with resource ID IDS_MSGBOX_DONOTSHOWAGAIN.
280 * \param bChecked get and set checkbox check state. This is optional.
281 * \return see class description for details
283 static UINT ShowCheck(HWND hWnd, LPCTSTR lpMessage, LPCTSTR lpCaption, UINT uType, LPCTSTR lpRegistry, LPCTSTR lpCheckMessage = nullptr, BOOL *bChecked = nullptr);
285 * Shows a message box with a checkbox. If the user checks it then the next time
286 * the message box isn't shown anymore - the method simply returns the same value as
287 * the last time. Use this to give the user the possibility to ignore specific message
288 * boxes ("Do not show again"-checkbox).
289 * \param hWnd handle to the parent window or nullptr
290 * \param nMessage resource ID of the message string
291 * \param nCaption resource ID of the title string
292 * \param uType see class description for details
293 * \param lpRegistry a value string to store the return value of this specific message box. Put nullptr or empty if you do not use registry.
294 * Each one of your message boxes must have it's own value string! Examples for such values
295 * might be "WarnOverwrite", "InformAboutMissingMailSubject", ...
296 * \param nCheckMessage resource ID of the checkbox string
297 * \param bChecked get and set checkbox check state. This is optional.
298 * \return see class description for details
300 static UINT ShowCheck(HWND hWnd, UINT nMessage, UINT nCaption, UINT uType, LPCTSTR lpRegistry, UINT nCheckMessage, BOOL* bChecked = nullptr);
303 * Shows a message box with user defined button texts.
304 * \param hWnd handle to the parent window or nullptr
305 * \param lpMessage the message string
306 * \param lpCaption the title string
307 * \param nDef number of the default button (1,2 or 3)
308 * \param icon an icon loaded with MAKEINTRESOURCE() or one of
309 * the system default icons.
310 * \param lpButton1 text for the first button
311 * \param lpButton2 text for the second button
312 * \param lpButton3 text for the third button
313 * \return the number of the button pressed (1,2 or 3)
315 static UINT Show(HWND hWnd, LPCTSTR lpMessage, LPCTSTR lpCaption, int nDef, LPCTSTR icon, LPCTSTR lpButton1, LPCTSTR lpButton2 = nullptr, LPCTSTR lpButton3 = nullptr);
317 * Shows a message box with user defined button texts.
318 * \param hWnd handle to the parent window or nullptr
319 * \param nMessage resource ID of the message string
320 * \param nCaption resource ID of the title string
321 * \param nDef number of the default button (1,2 or 3)
322 * \param icon an icon loaded with MAKEINTRESOURCE() or one of
323 * the system default icons.
324 * \param nButton1 resource ID of the text for the first button
325 * \param nButton2 resource ID of the text for the second button
326 * \param nButton3 resource ID of the text for the third button
327 * \return the number of the button pressed (1,2 or 3)
329 static UINT Show(HWND hWnd, UINT nMessage, UINT nCaption, int nDef, LPCTSTR icon, UINT nButton1, UINT nButton2 = NULL, UINT nButton3 = NULL);
331 * Shows a message box with user defined button texts and a checkbox.
332 * \param hWnd handle to the parent window or nullptr
333 * \param lpMessage the message string
334 * \param lpCaption the title string
335 * \param nDef number of the default button (1,2 or 3)
336 * \param icon an icon loaded with MAKEINTRESOURCE() or one
337 * of the system default icons
338 * \param lpButton1 string for the first button
339 * \param lpButton2 string for the second button
340 * \param lpButton3 string for the third button
341 * \param lpRegistry a value string to store the return value of this specific message box. Put nullptr or empty if you do not use registry.
342 * Each one of your message boxes must have it's own value string! Examples for such values
343 * might be "WarnOverwrite", "InformAboutMissingMailSubject", ...
344 * \param lpCheckMessage the message to show on the checkbox label. If this parameter is omitted
345 * then it defaults to "do not show again" or the string with resource ID IDS_MSGBOX_DONOTSHOWAGAIN.
346 * \param bChecked get and set checkbox check state. This is optional.
347 * \return the number of the button pressed (1,2 or 3)
349 static UINT ShowCheck(HWND hWnd, LPCTSTR lpMessage, LPCTSTR lpCaption, int nDef, LPCTSTR icon, LPCTSTR lpButton1, LPCTSTR lpButton2, LPCTSTR lpButton3, LPCTSTR lpRegistry, LPCTSTR lpCheckMessage = nullptr, BOOL* bChecked = nullptr);
351 * Shows a message box with user defined button texts and a checkbox.
352 * \param hWnd handle to the parent window or nullptr
353 * \param nMessage resource ID of the message string
354 * \param nCaption resource ID of the title string
355 * \param nDef number of the default button (1,2 or 3)
356 * \param icon an icon loaded with MAKEINTRESOURCE() or one
357 * of the system default icons
358 * \param nButton1 resource ID of string for the first button
359 * \param nButton2 resource ID of string for the second button
360 * \param nButton3 resource ID of string for the third button
361 * \param lpRegistry a value string to store the return value of this specific message box. Put nullptr or empty if you do not use registry.
362 * Each one of your message boxes must have it's own value string! Examples for such values
363 * might be "WarnOverwrite", "InformAboutMissingMailSubject", ...
364 * \param nCheckMessage resource ID of the checkbox string
365 * \param bChecked get and set checkbox check state. This is optional.
366 * \return the number of the button pressed (1,2 or 3)
368 static UINT ShowCheck(HWND hWnd, UINT nMessage, UINT nCaption, int nDef, LPCTSTR icon, UINT nButton1, UINT nButton2, UINT nButton3, LPCTSTR lpRegistry, UINT nCheckMessage = NULL, BOOL* bChecked = nullptr);
371 * Removes the registry key
373 static bool RemoveRegistryKey(LPCTSTR lpRegistry);
375 protected:
377 * Stores the value in the registry
378 * \param sValue the value name
379 * \param value DWORD to store
381 static void SetRegistryValue(const CString& sValue, DWORD value);
383 * Shows the modal dialog
384 * \param pWnd handle to the parent window or nullptr
385 * \param title message box title
386 * \param msg message to show
387 * \param nDefaultButton number of the default button
388 * \return the value stored in the member variables for the buttons (m_uButtonXRet)
389 * of the button pressed
391 UINT GoModal(CWnd * pWnd, const CString& title, const CString& msg, int nDefaultButton);
394 * Fills in the member variables according to the uType parameter
396 int FillBoxStandard(UINT uType);
399 * Calculates the size of the string in pixels
400 * \param str the string to check the size
402 CSize GetTextSize(const CString& str);
404 * Returns the size of the icon
406 CSize GetIconSize(HICON hIcon);
408 * Returns the size of all four buttons (three pushbuttons and the checkbox).
409 * Also resizes the buttons accordingly and fills in m_szAllButtons and m_szButtons.
411 CSize GetButtonSize();
413 void SetHelpPath(LPCTSTR sHelpPath) {m_sHelpPath = sHelpPath;}
415 LOGFONT m_LogFont;
416 CCursor m_Cursor;
417 CString m_sMessage;
418 HICON m_hIcon;
419 BOOL m_bDestroyIcon;
420 int m_nDefButton;
421 CString m_sButton1;
422 CString m_sButton2;
423 CString m_sButton3;
424 CString m_sCheckbox;
425 CString m_sHelpPath;
426 UINT m_uButton1Ret;
427 UINT m_uButton2Ret;
428 UINT m_uButton3Ret;
429 UINT m_uCancelRet;
430 UINT m_uType;
431 CSize m_szIcon;
432 CSize m_szAllButtons;
433 CSize m_szButtons;
434 CSize m_szText;
436 BOOL m_bShowCheck;
437 CString m_sRegistryValue;
439 CString m_i18l; //only used if some strings are defined for internationalization
441 public:
442 DECLARE_MESSAGE_MAP()
443 afx_msg void OnPaint();
444 afx_msg void OnButton1();
445 afx_msg void OnButton2();
446 afx_msg void OnButton3();
447 virtual BOOL OnInitDialog();
449 BOOL m_bChecked;
450 protected:
451 virtual void OnCancel();
452 virtual BOOL PreTranslateMessage(MSG* pMsg);