OSDN Git Service

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