Home | History | Annotate | Download | only in window
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef UI_VIEWS_WINDOW_DIALOG_DELEGATE_H_
      6 #define UI_VIEWS_WINDOW_DIALOG_DELEGATE_H_
      7 
      8 #include "base/compiler_specific.h"
      9 #include "base/strings/string16.h"
     10 #include "ui/base/accessibility/accessibility_types.h"
     11 #include "ui/base/models/dialog_model.h"
     12 #include "ui/base/ui_base_types.h"
     13 #include "ui/views/widget/widget_delegate.h"
     14 
     15 namespace views {
     16 
     17 class DialogClientView;
     18 
     19 ///////////////////////////////////////////////////////////////////////////////
     20 //
     21 // DialogDelegate
     22 //
     23 //  DialogDelegate is an interface implemented by objects that wish to show a
     24 //  dialog box Window. The window that is displayed uses this interface to
     25 //  determine how it should be displayed and notify the delegate object of
     26 //  certain events.
     27 //
     28 ///////////////////////////////////////////////////////////////////////////////
     29 class VIEWS_EXPORT DialogDelegate : public ui::DialogModel,
     30                                     public WidgetDelegate {
     31  public:
     32   virtual ~DialogDelegate();
     33 
     34   // Create a |dialog| window Widget with the specified |context| or |parent|.
     35   static Widget* CreateDialogWidget(DialogDelegate* dialog,
     36                                     gfx::NativeWindow context,
     37                                     gfx::NativeWindow parent);
     38 
     39   // Override this function to display an extra view adjacent to the buttons.
     40   // Overrides may construct the view; this will only be called once per dialog.
     41   virtual View* CreateExtraView();
     42 
     43   // Override this function to display an extra view in the titlebar.
     44   // Overrides may construct the view; this will only be called once per dialog.
     45   // Note: this only works for new style dialogs.
     46   virtual View* CreateTitlebarExtraView();
     47 
     48   // Override this function to display a footnote view below the buttons.
     49   // Overrides may construct the view; this will only be called once per dialog.
     50   virtual View* CreateFootnoteView();
     51 
     52   // For Dialog boxes, if there is a "Cancel" button or no dialog button at all,
     53   // this is called when the user presses the "Cancel" button or the Esc key.
     54   // It can also be called on a close action if |Close| has not been
     55   // overridden. This function should return true if the window can be closed
     56   // after it returns, or false if it must remain open.
     57   virtual bool Cancel();
     58 
     59   // For Dialog boxes, this is called when the user presses the "OK" button,
     60   // or the Enter key. It can also be called on a close action if |Close|
     61   // has not been overridden. This function should return true if the window
     62   // can be closed after it returns, or false if it must remain open.
     63   // If |window_closing| is true, it means that this handler is
     64   // being called because the window is being closed (e.g.  by Window::Close)
     65   // and there is no Cancel handler, so Accept is being called instead.
     66   virtual bool Accept(bool window_closing);
     67   virtual bool Accept();
     68 
     69   // Called when the user closes the window without selecting an option,
     70   // e.g. by pressing the close button on the window or using a window manager
     71   // gesture. By default, this calls Accept() if the only button in the dialog
     72   // is Accept, Cancel() otherwise. This function should return true if the
     73   // window can be closed after it returns, or false if it must remain open.
     74   virtual bool Close();
     75 
     76   // Overridden from ui::DialogModel:
     77   virtual base::string16 GetDialogLabel() const OVERRIDE;
     78   virtual base::string16 GetDialogTitle() const OVERRIDE;
     79   virtual int GetDialogButtons() const OVERRIDE;
     80   virtual int GetDefaultDialogButton() const OVERRIDE;
     81   virtual bool ShouldDefaultButtonBeBlue() const OVERRIDE;
     82   virtual base::string16 GetDialogButtonLabel(
     83       ui::DialogButton button) const OVERRIDE;
     84   virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
     85 
     86   // Overridden from WidgetDelegate:
     87   virtual View* GetInitiallyFocusedView() OVERRIDE;
     88   virtual DialogDelegate* AsDialogDelegate() OVERRIDE;
     89   virtual ClientView* CreateClientView(Widget* widget) OVERRIDE;
     90   virtual NonClientFrameView* CreateNonClientFrameView(Widget* widget) OVERRIDE;
     91 
     92   // Create a frame view using the new dialog style.
     93   static NonClientFrameView* CreateDialogFrameView(Widget* widget);
     94   // The semi-transparent border and shadow of the new style frame view does not
     95   // work on child windows under Views/Win32. This is a kludge to get a
     96   // reasonable-looking opaque border for the dialog. Note that this does not
     97   // support arrows.
     98   //
     99   // TODO(wittman): Remove once WinAura is in place.
    100   static NonClientFrameView* CreateDialogFrameView(Widget* widget,
    101                                                    bool force_opaque_border);
    102 
    103   // Returns whether this particular dialog should use the new dialog style.
    104   virtual bool UseNewStyleForThisDialog() const;
    105 
    106   // Called when the window has been closed.
    107   virtual void OnClosed() {}
    108 
    109   // A helper for accessing the DialogClientView object contained by this
    110   // delegate's Window.
    111   const DialogClientView* GetDialogClientView() const;
    112   DialogClientView* GetDialogClientView();
    113 
    114  protected:
    115   // Overridden from WidgetDelegate:
    116   virtual ui::AccessibilityTypes::Role GetAccessibleWindowRole() const OVERRIDE;
    117 };
    118 
    119 // A DialogDelegate implementation that is-a View. Used to override GetWidget()
    120 // to call View's GetWidget() for the common case where a DialogDelegate
    121 // implementation is-a View. Note that DialogDelegateView is not owned by
    122 // view's hierarchy and is expected to be deleted on DeleteDelegate call.
    123 class VIEWS_EXPORT DialogDelegateView : public DialogDelegate,
    124                                         public View {
    125  public:
    126   DialogDelegateView();
    127   virtual ~DialogDelegateView();
    128 
    129   // Overridden from DialogDelegate:
    130   virtual void DeleteDelegate() OVERRIDE;
    131   virtual Widget* GetWidget() OVERRIDE;
    132   virtual const Widget* GetWidget() const OVERRIDE;
    133   virtual View* GetContentsView() OVERRIDE;
    134 
    135  private:
    136   DISALLOW_COPY_AND_ASSIGN(DialogDelegateView);
    137 };
    138 
    139 }  // namespace views
    140 
    141 #endif  // UI_VIEWS_WINDOW_DIALOG_DELEGATE_H_
    142