| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/ui/views/status_icons/status_tray_win.h" | 5 #include "chrome/browser/ui/views/status_icons/status_tray_win.h" |
| 6 | 6 |
| 7 #include "base/win/wrapped_window_proc.h" | 7 #include "base/win/wrapped_window_proc.h" |
| 8 #include "chrome/browser/ui/views/status_icons/status_icon_win.h" | 8 #include "chrome/browser/ui/views/status_icons/status_icon_win.h" |
| 9 #include "chrome/common/chrome_constants.h" | 9 #include "chrome/common/chrome_constants.h" |
| 10 #include "ui/base/win/hwnd_util.h" | 10 #include "ui/base/win/hwnd_util.h" |
| 11 #include "ui/gfx/screen.h" | 11 #include "ui/gfx/screen.h" |
| 12 | 12 |
| 13 static const UINT kStatusIconMessage = WM_APP + 1; | 13 static const UINT kStatusIconMessage = WM_APP + 1; |
| 14 | 14 |
| 15 StatusTrayWin::StatusTrayWin() | 15 StatusTrayWin::StatusTrayWin() |
| 16 : next_icon_id_(1) { | 16 : next_icon_id_(1), |
| 17 atom_(0), |
| 18 instance_(NULL), |
| 19 window_(NULL) { |
| 17 // Register our window class | 20 // Register our window class |
| 18 HINSTANCE hinst = GetModuleHandle(NULL); | 21 WNDCLASSEX window_class; |
| 19 WNDCLASSEX wc = {0}; | 22 base::win::InitializeWindowClass( |
| 20 wc.cbSize = sizeof(wc); | 23 chrome::kStatusTrayWindowClass, |
| 21 wc.lpfnWndProc = base::win::WrappedWindowProc<StatusTrayWin::WndProcStatic>; | 24 &base::win::WrappedWindowProc<StatusTrayWin::WndProcStatic>, |
| 22 wc.hInstance = hinst; | 25 0, 0, 0, NULL, NULL, NULL, NULL, NULL, |
| 23 wc.lpszClassName = chrome::kStatusTrayWindowClass; | 26 &window_class); |
| 24 ATOM clazz = RegisterClassEx(&wc); | 27 instance_ = window_class.hInstance; |
| 25 DCHECK(clazz); | 28 atom_ = RegisterClassEx(&window_class); |
| 29 CHECK(atom_); |
| 26 | 30 |
| 27 // If the taskbar is re-created after we start up, we have to rebuild all of | 31 // If the taskbar is re-created after we start up, we have to rebuild all of |
| 28 // our icons. | 32 // our icons. |
| 29 taskbar_created_message_ = RegisterWindowMessage(TEXT("TaskbarCreated")); | 33 taskbar_created_message_ = RegisterWindowMessage(TEXT("TaskbarCreated")); |
| 30 | 34 |
| 31 // Create an offscreen window for handling messages for the status icons. We | 35 // Create an offscreen window for handling messages for the status icons. We |
| 32 // create a hidden WS_POPUP window instead of an HWND_MESSAGE window, because | 36 // create a hidden WS_POPUP window instead of an HWND_MESSAGE window, because |
| 33 // only top-level windows such as popups can receive broadcast messages like | 37 // only top-level windows such as popups can receive broadcast messages like |
| 34 // "TaskbarCreated". | 38 // "TaskbarCreated". |
| 35 window_ = CreateWindow(chrome::kStatusTrayWindowClass, | 39 window_ = CreateWindow(MAKEINTATOM(atom_), |
| 36 0, WS_POPUP, 0, 0, 0, 0, 0, 0, hinst, 0); | 40 0, WS_POPUP, 0, 0, 0, 0, 0, 0, instance_, 0); |
| 37 ui::CheckWindowCreated(window_); | 41 ui::CheckWindowCreated(window_); |
| 38 ui::SetWindowUserData(window_, this); | 42 ui::SetWindowUserData(window_, this); |
| 39 } | 43 } |
| 40 | 44 |
| 41 LRESULT CALLBACK StatusTrayWin::WndProcStatic(HWND hwnd, | 45 LRESULT CALLBACK StatusTrayWin::WndProcStatic(HWND hwnd, |
| 42 UINT message, | 46 UINT message, |
| 43 WPARAM wparam, | 47 WPARAM wparam, |
| 44 LPARAM lparam) { | 48 LPARAM lparam) { |
| 45 StatusTrayWin* msg_wnd = reinterpret_cast<StatusTrayWin*>( | 49 StatusTrayWin* msg_wnd = reinterpret_cast<StatusTrayWin*>( |
| 46 GetWindowLongPtr(hwnd, GWLP_USERDATA)); | 50 GetWindowLongPtr(hwnd, GWLP_USERDATA)); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 } | 85 } |
| 82 return TRUE; | 86 return TRUE; |
| 83 } | 87 } |
| 84 } | 88 } |
| 85 return ::DefWindowProc(hwnd, message, wparam, lparam); | 89 return ::DefWindowProc(hwnd, message, wparam, lparam); |
| 86 } | 90 } |
| 87 | 91 |
| 88 StatusTrayWin::~StatusTrayWin() { | 92 StatusTrayWin::~StatusTrayWin() { |
| 89 if (window_) | 93 if (window_) |
| 90 DestroyWindow(window_); | 94 DestroyWindow(window_); |
| 91 UnregisterClass(chrome::kStatusTrayWindowClass, GetModuleHandle(NULL)); | 95 |
| 96 if (atom_) |
| 97 UnregisterClass(MAKEINTATOM(atom_), instance_); |
| 92 } | 98 } |
| 93 | 99 |
| 94 StatusIcon* StatusTrayWin::CreatePlatformStatusIcon() { | 100 StatusIcon* StatusTrayWin::CreatePlatformStatusIcon() { |
| 95 return new StatusIconWin(next_icon_id_++, window_, kStatusIconMessage); | 101 return new StatusIconWin(next_icon_id_++, window_, kStatusIconMessage); |
| 96 } | 102 } |
| 97 | 103 |
| 98 StatusTray* StatusTray::Create() { | 104 StatusTray* StatusTray::Create() { |
| 99 return new StatusTrayWin(); | 105 return new StatusTrayWin(); |
| 100 } | 106 } |
| OLD | NEW |