OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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 #include "chrome/views/window/window_gtk.h" |
| 6 |
| 7 #include "app/l10n_util.h" |
| 8 #include "base/gfx/rect.h" |
| 9 #include "chrome/views/window/custom_frame_view.h" |
| 10 #include "chrome/views/window/non_client_view.h" |
| 11 #include "chrome/views/window/window_delegate.h" |
| 12 |
| 13 namespace views { |
| 14 |
| 15 WindowGtk::~WindowGtk() { |
| 16 } |
| 17 |
| 18 // static |
| 19 Window* Window::CreateChromeWindow(gfx::NativeWindow parent, |
| 20 const gfx::Rect& bounds, |
| 21 WindowDelegate* window_delegate) { |
| 22 WindowGtk* window = new WindowGtk(window_delegate); |
| 23 window->GetNonClientView()->SetFrameView(window->CreateFrameViewForWindow()); |
| 24 window->Init(bounds); |
| 25 return window; |
| 26 } |
| 27 |
| 28 gfx::Rect WindowGtk::GetBounds() const { |
| 29 gfx::Rect bounds; |
| 30 WidgetGtk::GetBounds(&bounds, true); |
| 31 return bounds; |
| 32 } |
| 33 |
| 34 gfx::Rect WindowGtk::GetNormalBounds() const { |
| 35 NOTIMPLEMENTED(); |
| 36 return GetBounds(); |
| 37 } |
| 38 |
| 39 void WindowGtk::SetBounds(const gfx::Rect& bounds) { |
| 40 // TODO: this may need to set an initial size if not showing. |
| 41 // TODO: need to constrain based on screen size. |
| 42 gtk_window_resize(GTK_WINDOW(GetNativeView()), bounds.width(), |
| 43 bounds.height()); |
| 44 |
| 45 gtk_window_move(GTK_WINDOW(GetNativeView()), bounds.x(), bounds.y()); |
| 46 } |
| 47 |
| 48 void WindowGtk::SetBounds(const gfx::Rect& bounds, |
| 49 gfx::NativeWindow other_window) { |
| 50 // TODO: need to deal with other_window. |
| 51 SetBounds(bounds); |
| 52 } |
| 53 |
| 54 void WindowGtk::Show() { |
| 55 gtk_widget_show_all(GetNativeView()); |
| 56 } |
| 57 |
| 58 void WindowGtk::Activate() { |
| 59 NOTIMPLEMENTED(); |
| 60 } |
| 61 |
| 62 void WindowGtk::Close() { |
| 63 NOTIMPLEMENTED(); |
| 64 } |
| 65 |
| 66 void WindowGtk::Maximize() { |
| 67 gtk_window_maximize(GetNativeWindow()); |
| 68 } |
| 69 |
| 70 void WindowGtk::Minimize() { |
| 71 gtk_window_iconify(GetNativeWindow()); |
| 72 } |
| 73 |
| 74 void WindowGtk::Restore() { |
| 75 NOTIMPLEMENTED(); |
| 76 } |
| 77 |
| 78 bool WindowGtk::IsActive() const { |
| 79 return gtk_window_is_active(GetNativeWindow()); |
| 80 } |
| 81 |
| 82 bool WindowGtk::IsVisible() const { |
| 83 return GTK_WIDGET_VISIBLE(GetNativeView()); |
| 84 } |
| 85 |
| 86 bool WindowGtk::IsMaximized() const { |
| 87 NOTIMPLEMENTED(); |
| 88 return false; |
| 89 } |
| 90 |
| 91 bool WindowGtk::IsMinimized() const { |
| 92 NOTIMPLEMENTED(); |
| 93 return false; |
| 94 } |
| 95 |
| 96 void WindowGtk::SetFullscreen(bool fullscreen) { |
| 97 NOTIMPLEMENTED(); |
| 98 } |
| 99 |
| 100 bool WindowGtk::IsFullscreen() const { |
| 101 NOTIMPLEMENTED(); |
| 102 return false; |
| 103 } |
| 104 |
| 105 void WindowGtk::EnableClose(bool enable) { |
| 106 gtk_window_set_deletable(GetNativeWindow(), enable); |
| 107 } |
| 108 |
| 109 void WindowGtk::DisableInactiveRendering() { |
| 110 NOTIMPLEMENTED(); |
| 111 } |
| 112 |
| 113 void WindowGtk::UpdateWindowTitle() { |
| 114 // If the non-client view is rendering its own title, it'll need to relayout |
| 115 // now. |
| 116 non_client_view_->Layout(); |
| 117 |
| 118 // Update the native frame's text. We do this regardless of whether or not |
| 119 // the native frame is being used, since this also updates the taskbar, etc. |
| 120 std::wstring window_title = window_delegate_->GetWindowTitle(); |
| 121 std::wstring localized_text; |
| 122 if (l10n_util::AdjustStringForLocaleDirection(window_title, &localized_text)) |
| 123 window_title.assign(localized_text); |
| 124 |
| 125 gtk_window_set_title(GetNativeWindow(), WideToUTF8(window_title).c_str()); |
| 126 } |
| 127 |
| 128 void WindowGtk::UpdateWindowIcon() { |
| 129 NOTIMPLEMENTED(); |
| 130 } |
| 131 |
| 132 NonClientFrameView* WindowGtk::CreateFrameViewForWindow() { |
| 133 // TODO(erg): Always use a custom frame view? Are there cases where we let |
| 134 // the window manager deal with the X11 equivalent of the "non-client" area? |
| 135 return new CustomFrameView(this); |
| 136 } |
| 137 |
| 138 void WindowGtk::UpdateFrameAfterFrameChange() { |
| 139 NOTIMPLEMENTED(); |
| 140 } |
| 141 |
| 142 WindowDelegate* WindowGtk::GetDelegate() const { |
| 143 return window_delegate_; |
| 144 } |
| 145 |
| 146 NonClientView* WindowGtk::GetNonClientView() const { |
| 147 return non_client_view_; |
| 148 } |
| 149 |
| 150 ClientView* WindowGtk::GetClientView() const { |
| 151 return non_client_view_->client_view(); |
| 152 } |
| 153 |
| 154 gfx::NativeWindow WindowGtk::GetNativeWindow() const { |
| 155 return GTK_WINDOW(GetNativeView()); |
| 156 } |
| 157 |
| 158 WindowGtk::WindowGtk(WindowDelegate* window_delegate) |
| 159 : WidgetGtk(TYPE_WINDOW), |
| 160 is_modal_(false), |
| 161 is_always_on_top_(false), |
| 162 window_delegate_(window_delegate), |
| 163 non_client_view_(new NonClientView(this)) { |
| 164 window_delegate_->window_.reset(this); |
| 165 } |
| 166 |
| 167 void WindowGtk::Init(const gfx::Rect& bounds) { |
| 168 // We call this after initializing our members since our implementations of |
| 169 // assorted WidgetWin functions may be called during initialization. |
| 170 is_modal_ = window_delegate_->IsModal(); |
| 171 if (is_modal_) { |
| 172 // TODO(erg): Fix once modality works. |
| 173 // BecomeModal(); |
| 174 } |
| 175 is_always_on_top_ = window_delegate_->IsAlwaysOnTop(); |
| 176 |
| 177 WidgetGtk::Init(bounds, true); |
| 178 |
| 179 // Create the ClientView, add it to the NonClientView and add the |
| 180 // NonClientView to the RootView. This will cause everything to be parented. |
| 181 non_client_view_->set_client_view(window_delegate_->CreateClientView(this)); |
| 182 WidgetGtk::SetContentsView(non_client_view_); |
| 183 |
| 184 UpdateWindowTitle(); |
| 185 |
| 186 // SetInitialBounds(bounds); |
| 187 // InitAlwaysOnTopState(); |
| 188 |
| 189 // if (!IsAppWindow()) { |
| 190 // notification_registrar_.Add( |
| 191 // this, |
| 192 // NotificationType::ALL_APPWINDOWS_CLOSED, |
| 193 // NotificationService::AllSources()); |
| 194 // } |
| 195 |
| 196 // ResetWindowRegion(false); |
| 197 } |
| 198 |
| 199 } // namespace views |
OLD | NEW |