| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VIEWS_WINDOW_DIALOG_DELEGATE_H_ | 5 #ifndef VIEWS_WINDOW_DIALOG_DELEGATE_H_ |
| 6 #define VIEWS_WINDOW_DIALOG_DELEGATE_H_ | 6 #define VIEWS_WINDOW_DIALOG_DELEGATE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "ui/base/message_box_flags.h" | 9 #include "ui/base/message_box_flags.h" |
| 10 #include "views/accessibility/accessibility_types.h" | 10 #include "views/accessibility/accessibility_types.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 // DialogDelegate | 22 // DialogDelegate |
| 23 // | 23 // |
| 24 // DialogDelegate is an interface implemented by objects that wish to show a | 24 // DialogDelegate is an interface implemented by objects that wish to show a |
| 25 // dialog box Window. The window that is displayed uses this interface to | 25 // dialog box Window. The window that is displayed uses this interface to |
| 26 // determine how it should be displayed and notify the delegate object of | 26 // determine how it should be displayed and notify the delegate object of |
| 27 // certain events. | 27 // certain events. |
| 28 // | 28 // |
| 29 /////////////////////////////////////////////////////////////////////////////// | 29 /////////////////////////////////////////////////////////////////////////////// |
| 30 class DialogDelegate : public WindowDelegate { | 30 class DialogDelegate : public WindowDelegate { |
| 31 public: | 31 public: |
| 32 virtual DialogDelegate* AsDialogDelegate() { return this; } | 32 virtual DialogDelegate* AsDialogDelegate(); |
| 33 | 33 |
| 34 // Returns a mask specifying which of the available DialogButtons are visible | 34 // Returns a mask specifying which of the available DialogButtons are visible |
| 35 // for the dialog. Note: If an OK button is provided, you should provide a | 35 // for the dialog. Note: If an OK button is provided, you should provide a |
| 36 // CANCEL button. A dialog box with just an OK button is frowned upon and | 36 // CANCEL button. A dialog box with just an OK button is frowned upon and |
| 37 // considered a very special case, so if you're planning on including one, | 37 // considered a very special case, so if you're planning on including one, |
| 38 // you should reconsider, or beng says there will be stabbings. | 38 // you should reconsider, or beng says there will be stabbings. |
| 39 // | 39 // |
| 40 // To use the extra button you need to override GetDialogButtons() | 40 // To use the extra button you need to override GetDialogButtons() |
| 41 virtual int GetDialogButtons() const { | 41 virtual int GetDialogButtons() const; |
| 42 return ui::MessageBoxFlags::DIALOGBUTTON_OK | | |
| 43 ui::MessageBoxFlags::DIALOGBUTTON_CANCEL; | |
| 44 } | |
| 45 | 42 |
| 46 // Returns whether accelerators are enabled on the button. This is invoked | 43 // Returns whether accelerators are enabled on the button. This is invoked |
| 47 // when an accelerator is pressed, not at construction time. This | 44 // when an accelerator is pressed, not at construction time. This |
| 48 // returns true. | 45 // returns true. |
| 49 virtual bool AreAcceleratorsEnabled( | 46 virtual bool AreAcceleratorsEnabled( |
| 50 ui::MessageBoxFlags::DialogButton button) { | 47 ui::MessageBoxFlags::DialogButton button); |
| 51 return true; | |
| 52 } | |
| 53 | 48 |
| 54 // Returns the label of the specified DialogButton. | 49 // Returns the label of the specified DialogButton. |
| 55 virtual std::wstring GetDialogButtonLabel( | 50 virtual std::wstring GetDialogButtonLabel( |
| 56 ui::MessageBoxFlags::DialogButton button) const { | 51 ui::MessageBoxFlags::DialogButton button) const; |
| 57 // empty string results in defaults for | |
| 58 // ui::MessageBoxFlags::DIALOGBUTTON_OK, | |
| 59 // ui::MessageBoxFlags::DIALOGBUTTON_CANCEL. | |
| 60 return L""; | |
| 61 } | |
| 62 | 52 |
| 63 // Override this function if with a view which will be shown in the same | 53 // Override this function if with a view which will be shown in the same |
| 64 // row as the OK and CANCEL buttons but flush to the left and extending | 54 // row as the OK and CANCEL buttons but flush to the left and extending |
| 65 // up to the buttons. | 55 // up to the buttons. |
| 66 virtual View* GetExtraView() { return NULL; } | 56 virtual View* GetExtraView(); |
| 67 | 57 |
| 68 // Returns whether the height of the extra view should be at least as tall as | 58 // Returns whether the height of the extra view should be at least as tall as |
| 69 // the buttons. The default (false) is to give the extra view it's preferred | 59 // the buttons. The default (false) is to give the extra view it's preferred |
| 70 // height. By returning true the height becomes | 60 // height. By returning true the height becomes |
| 71 // max(extra_view preferred height, buttons preferred height). | 61 // max(extra_view preferred height, buttons preferred height). |
| 72 virtual bool GetSizeExtraViewHeightToButtons() { return false; } | 62 virtual bool GetSizeExtraViewHeightToButtons(); |
| 73 | 63 |
| 74 // Returns the default dialog button. This should not be a mask as only | 64 // Returns the default dialog button. This should not be a mask as only |
| 75 // one button should ever be the default button. Return | 65 // one button should ever be the default button. Return |
| 76 // ui::MessageBoxFlags::DIALOGBUTTON_NONE if there is no default. Default | 66 // ui::MessageBoxFlags::DIALOGBUTTON_NONE if there is no default. Default |
| 77 // behavior is to return ui::MessageBoxFlags::DIALOGBUTTON_OK or | 67 // behavior is to return ui::MessageBoxFlags::DIALOGBUTTON_OK or |
| 78 // ui::MessageBoxFlags::DIALOGBUTTON_CANCEL (in that order) if they are | 68 // ui::MessageBoxFlags::DIALOGBUTTON_CANCEL (in that order) if they are |
| 79 // present, ui::MessageBoxFlags::DIALOGBUTTON_NONE otherwise. | 69 // present, ui::MessageBoxFlags::DIALOGBUTTON_NONE otherwise. |
| 80 virtual int GetDefaultDialogButton() const; | 70 virtual int GetDefaultDialogButton() const; |
| 81 | 71 |
| 82 // Returns whether the specified dialog button is enabled. | 72 // Returns whether the specified dialog button is enabled. |
| 83 virtual bool IsDialogButtonEnabled( | 73 virtual bool IsDialogButtonEnabled( |
| 84 ui::MessageBoxFlags::DialogButton button) const { | 74 ui::MessageBoxFlags::DialogButton button) const; |
| 85 return true; | |
| 86 } | |
| 87 | 75 |
| 88 // Returns whether the specified dialog button is visible. | 76 // Returns whether the specified dialog button is visible. |
| 89 virtual bool IsDialogButtonVisible( | 77 virtual bool IsDialogButtonVisible( |
| 90 ui::MessageBoxFlags::DialogButton button) const { | 78 ui::MessageBoxFlags::DialogButton button) const; |
| 91 return true; | |
| 92 } | |
| 93 | 79 |
| 94 // For Dialog boxes, if there is a "Cancel" button, this is called when the | 80 // For Dialog boxes, if there is a "Cancel" button, this is called when the |
| 95 // user presses the "Cancel" button or the Close button on the window or | 81 // user presses the "Cancel" button or the Close button on the window or |
| 96 // in the system menu, or presses the Esc key. This function should return | 82 // in the system menu, or presses the Esc key. This function should return |
| 97 // true if the window can be closed after it returns, or false if it must | 83 // true if the window can be closed after it returns, or false if it must |
| 98 // remain open. | 84 // remain open. |
| 99 virtual bool Cancel() { return true; } | 85 virtual bool Cancel(); |
| 100 | 86 |
| 101 // For Dialog boxes, this is called when the user presses the "OK" button, | 87 // For Dialog boxes, this is called when the user presses the "OK" button, |
| 102 // or the Enter key. Can also be called on Esc key or close button | 88 // or the Enter key. Can also be called on Esc key or close button |
| 103 // presses if there is no "Cancel" button. This function should return | 89 // presses if there is no "Cancel" button. This function should return |
| 104 // true if the window can be closed after the window can be closed after | 90 // true if the window can be closed after the window can be closed after |
| 105 // it returns, or false if it must remain open. If |window_closing| is | 91 // it returns, or false if it must remain open. If |window_closing| is |
| 106 // true, it means that this handler is being called because the window is | 92 // true, it means that this handler is being called because the window is |
| 107 // being closed (e.g. by Window::Close) and there is no Cancel handler, | 93 // being closed (e.g. by Window::Close) and there is no Cancel handler, |
| 108 // so Accept is being called instead. | 94 // so Accept is being called instead. |
| 109 virtual bool Accept(bool window_closing) { return Accept(); } | 95 virtual bool Accept(bool window_closing); |
| 110 virtual bool Accept() { return true; } | 96 virtual bool Accept(); |
| 111 | 97 |
| 112 // Overridden from WindowDelegate: | 98 // Overridden from WindowDelegate: |
| 113 virtual View* GetInitiallyFocusedView(); | 99 virtual View* GetInitiallyFocusedView(); |
| 114 | 100 |
| 115 // Overridden from WindowDelegate: | 101 // Overridden from WindowDelegate: |
| 116 virtual ClientView* CreateClientView(Window* window); | 102 virtual ClientView* CreateClientView(Window* window); |
| 117 | 103 |
| 118 // Called when the window has been closed. | 104 // Called when the window has been closed. |
| 119 virtual void OnClose() {} | 105 virtual void OnClose() {} |
| 120 | 106 |
| 121 // A helper for accessing the DialogClientView object contained by this | 107 // A helper for accessing the DialogClientView object contained by this |
| 122 // delegate's Window. | 108 // delegate's Window. |
| 123 DialogClientView* GetDialogClientView() const; | 109 DialogClientView* GetDialogClientView() const; |
| 124 | 110 |
| 125 private: | 111 private: |
| 126 // Overridden from WindowDelegate: | 112 // Overridden from WindowDelegate: |
| 127 AccessibilityTypes::Role accessible_role() const { | 113 virtual AccessibilityTypes::Role accessible_role() const; |
| 128 return AccessibilityTypes::ROLE_DIALOG; | |
| 129 } | |
| 130 }; | 114 }; |
| 131 | 115 |
| 132 } // namespace views | 116 } // namespace views |
| 133 | 117 |
| 134 #endif // VIEWS_WINDOW_DIALOG_DELEGATE_H_ | 118 #endif // VIEWS_WINDOW_DIALOG_DELEGATE_H_ |
| OLD | NEW |