PageRenderTime 26ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/views/window/window_delegate.h

https://github.com/akesling/chromium
C Header | 143 lines | 65 code | 30 blank | 48 comment | 0 complexity | 7c35318148ca3ed76e4466be2efa6e15 MD5 | raw file
  1. // Copyright (c) 2006-2008 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. #ifndef VIEWS_WINDOW_WINDOW_DELEGATE_H_
  5. #define VIEWS_WINDOW_WINDOW_DELEGATE_H_
  6. #include <string>
  7. #include "base/scoped_ptr.h"
  8. class SkBitmap;
  9. namespace gfx {
  10. class Rect;
  11. }
  12. // TODO(maruel): Remove once gfx::Rect is used instead.
  13. namespace WTL {
  14. class CRect;
  15. }
  16. using WTL::CRect;
  17. namespace views {
  18. class ClientView;
  19. class DialogDelegate;
  20. class View;
  21. class Window;
  22. ///////////////////////////////////////////////////////////////////////////////
  23. //
  24. // WindowDelegate
  25. //
  26. // WindowDelegate is an interface implemented by objects that wish to show a
  27. // Window. The window that is displayed uses this interface to determine how
  28. // it should be displayed and notify the delegate object of certain events.
  29. //
  30. ///////////////////////////////////////////////////////////////////////////////
  31. class WindowDelegate {
  32. public:
  33. WindowDelegate();
  34. virtual ~WindowDelegate();
  35. virtual DialogDelegate* AsDialogDelegate() { return NULL; }
  36. // Returns true if the window can ever be resized.
  37. virtual bool CanResize() const {
  38. return false;
  39. }
  40. // Returns true if the window can ever be maximized.
  41. virtual bool CanMaximize() const {
  42. return false;
  43. }
  44. // Returns true if the dialog should be displayed modally to the window that
  45. // opened it. Only windows with WindowType == DIALOG can be modal.
  46. virtual bool IsModal() const {
  47. return false;
  48. }
  49. // Returns the text to be displayed in the window title.
  50. virtual std::wstring GetWindowTitle() const {
  51. return L"";
  52. }
  53. // Returns the view that should have the focus when the dialog is opened. If
  54. // NULL no view is focused.
  55. virtual View* GetInitiallyFocusedView() { return NULL; }
  56. // Returns true if the window should show a title in the title bar.
  57. virtual bool ShouldShowWindowTitle() const {
  58. return true;
  59. }
  60. // Returns the icon to be displayed in the window.
  61. virtual SkBitmap GetWindowIcon();
  62. // Returns true if a window icon should be shown.
  63. virtual bool ShouldShowWindowIcon() const {
  64. return false;
  65. }
  66. // Execute a command in the window's controller. Returns true if the command
  67. // was handled, false if it was not.
  68. virtual bool ExecuteWindowsCommand(int command_id) { return false; }
  69. // Returns the window's name identifier. Used to identify this window for
  70. // state restoration.
  71. virtual std::wstring GetWindowName() const {
  72. return std::wstring();
  73. }
  74. // Saves the window's bounds and maximized states. By default this uses the
  75. // process' local state keyed by window name (See GetWindowName above). This
  76. // behavior can be overridden to provide additional functionality.
  77. virtual void SaveWindowPlacement(const gfx::Rect& bounds, bool maximized);
  78. // Retrieves the window's bounds and maximized states.
  79. // This behavior can be overridden to provide additional functionality.
  80. virtual bool GetSavedWindowBounds(gfx::Rect* bounds) const;
  81. virtual bool GetSavedMaximizedState(bool* maximized) const;
  82. // Called when the window closes.
  83. virtual void WindowClosing() { }
  84. // Called when the window is destroyed. No events must be sent or received
  85. // after this point. The delegate can use this opportunity to delete itself at
  86. // this time if necessary.
  87. virtual void DeleteDelegate() { }
  88. // Returns the View that is contained within this Window.
  89. virtual View* GetContentsView() {
  90. return NULL;
  91. }
  92. // Called by the Window to create the Client View used to host the contents
  93. // of the window.
  94. virtual ClientView* CreateClientView(Window* window);
  95. // An accessor to the Window this delegate is bound to.
  96. Window* window() const { return window_.get(); }
  97. protected:
  98. // Releases the Window* we maintain. This should be done by a delegate in its
  99. // WindowClosing handler if it intends to be re-cycled to be used on a
  100. // different Window.
  101. void ReleaseWindow();
  102. private:
  103. friend class WindowGtk;
  104. friend class WindowWin;
  105. // This is a little unusual. We use a scoped_ptr here because it's
  106. // initialized to NULL automatically. We do this because we want to allow
  107. // people using this helper to not have to call a ctor on this object.
  108. // Instead we just release the owning ref this pointer has when we are
  109. // destroyed.
  110. scoped_ptr<Window> window_;
  111. };
  112. } // namespace views
  113. #endif // VIEWS_WINDOW_WINDOW_DELEGATE_H_