Chromium Code Reviews| Index: remoting/host/disconnect_window_win.cc |
| diff --git a/remoting/host/disconnect_window_win.cc b/remoting/host/disconnect_window_win.cc |
| index abe739a34b8b7c6204959171d242babf90443542..e4da93987e83f650131f8402bcc26f57ab89caa0 100644 |
| --- a/remoting/host/disconnect_window_win.cc |
| +++ b/remoting/host/disconnect_window_win.cc |
| @@ -10,6 +10,9 @@ |
| #include "base/logging.h" |
| #include "base/string_util.h" |
| #include "base/utf_string_conversions.h" |
| +#include "base/win/scoped_gdi_object.h" |
| +#include "base/win/scoped_hdc.h" |
| +#include "base/win/scoped_select_object.h" |
| #include "remoting/host/chromoting_host.h" |
| // TODO(wez): The DisconnectWindow isn't plugin-specific, so shouldn't have |
| // a dependency on the plugin's resource header. |
| @@ -28,6 +31,7 @@ |
| extern HMODULE g_hModule; |
| const int DISCONNECT_HOTKEY_ID = 1000; |
| +const int kWindowBorderRadius = 14; |
| namespace remoting { |
| @@ -53,6 +57,7 @@ private: |
| remoting::ChromotingHost* host_; |
| HWND hwnd_; |
| bool has_hotkey_; |
| + base::win::ScopedGDIObject<HPEN> border_pen_; |
| DISALLOW_COPY_AND_ASSIGN(DisconnectWindowWin); |
| }; |
| @@ -60,7 +65,9 @@ private: |
| DisconnectWindowWin::DisconnectWindowWin() |
| : host_(NULL), |
| hwnd_(NULL), |
| - has_hotkey_(false) { |
| + has_hotkey_(false), |
| + border_pen_(CreatePen(PS_SOLID, 5, |
| + RGB(0.13 * 255, 0.69 * 255, 0.11 * 255))) { |
|
Wez
2011/10/20 20:28:58
nit: Is this the preferred way to express RGB valu
Jamie
2011/10/20 23:56:54
The fractions are copied from Dave's Mac implement
|
| } |
| DisconnectWindowWin::~DisconnectWindowWin() { |
| @@ -86,17 +93,11 @@ BOOL CALLBACK DisconnectWindowWin::DialogProc(HWND hwnd, UINT msg, |
| BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg, |
| WPARAM wParam, LPARAM lParam) { |
| switch (msg) { |
| - case WM_HOTKEY: |
| - ShutdownHost(); |
| - EndDialog(0); |
| - return TRUE; |
| + // Ignore close messages. |
| case WM_CLOSE: |
| - // Ignore close messages. |
| - return TRUE; |
| - case WM_DESTROY: |
| - // Ensure we don't try to use the HWND anymore. |
| - hwnd_ = NULL; |
| return TRUE; |
| + |
| + // Handle the Disconnect button. |
| case WM_COMMAND: |
| switch (LOWORD(wParam)) { |
| case IDC_DISCONNECT: |
| @@ -104,6 +105,40 @@ BOOL DisconnectWindowWin::OnDialogMessage(HWND hwnd, UINT msg, |
| EndDialog(LOWORD(wParam)); |
| return TRUE; |
| } |
| + return FALSE; |
| + |
| + // Ensure we don't try to use the HWND anymore. |
| + case WM_DESTROY: |
| + hwnd_ = NULL; |
| + return TRUE; |
| + |
| + // Handle the disconnect hot-key. |
| + case WM_HOTKEY: |
| + ShutdownHost(); |
| + EndDialog(0); |
| + return TRUE; |
| + |
| + // Let the window be draggable by its client area by responding |
| + // that the entire window is the title bar. |
|
Wez
2011/10/20 20:28:58
Does this affect focus or clickability of widgets
Jamie
2011/10/20 23:56:54
No.
|
| + case WM_NCHITTEST: |
| + SetWindowLong(hwnd, DWL_MSGRESULT, HTCAPTION); |
| + return TRUE; |
| + |
| + case WM_PAINT: |
| + { |
| + PAINTSTRUCT ps; |
| + HDC hdc = BeginPaint(hwnd_, &ps); |
| + RECT rect; |
| + GetClientRect(hwnd_, &rect); |
| + { |
| + base::win::ScopedSelectObject border(hdc, border_pen_); |
| + base::win::ScopedSelectObject brush(hdc, GetStockObject(NULL_BRUSH)); |
| + RoundRect(hdc, rect.left, rect.top, rect.right - 1, rect.bottom - 1, |
| + kWindowBorderRadius, kWindowBorderRadius); |
| + } |
| + EndPaint(hwnd_, &ps); |
| + return TRUE; |
| + } |
| } |
| return FALSE; |
| } |
| @@ -135,8 +170,19 @@ void DisconnectWindowWin::ShutdownHost() { |
| host_->Shutdown(NULL); |
| } |
| +static int GetControlTextWidth(HWND control) { |
| + WCHAR text[256]; |
| + GetWindowText(control, text, arraysize(text)); |
|
Wez
2011/10/20 20:28:58
Check the return value of GetWindowText(), otherwi
Jamie
2011/10/20 23:56:54
Done.
|
| + base::win::ScopedGetDC dc(control); |
| + base::win::ScopedSelectObject font( |
| + dc, (HFONT)SendMessage(control, WM_GETFONT, 0, 0)); |
| + RECT rect = {0, 0, 0, 0}; |
| + DrawText(dc, text, -1, &rect, DT_CALCRECT|DT_SINGLELINE); |
| + return rect.right; |
| +} |
| + |
| void DisconnectWindowWin::SetStrings(const UiStrings& strings, |
| - const std::string& username) { |
| + const std::string& username) { |
| SetWindowText(hwnd_, strings.product_name.c_str()); |
| HWND hwndButton = GetDlgItem(hwnd_, IDC_DISCONNECT); |
| @@ -144,13 +190,46 @@ void DisconnectWindowWin::SetStrings(const UiStrings& strings, |
| const WCHAR* label = |
| has_hotkey_ ? strings.disconnect_button_text_plus_shortcut.c_str() |
| : strings.disconnect_button_text.c_str(); |
| + int button_old_required_width = GetControlTextWidth(hwndButton); |
| SetWindowText(hwndButton, label); |
| + int button_new_required_width = GetControlTextWidth(hwndButton); |
| HWND hwndSharingWith = GetDlgItem(hwnd_, IDC_DISCONNECT_SHARINGWITH); |
| CHECK(hwndSharingWith); |
| string16 text = ReplaceStringPlaceholders( |
| strings.disconnect_message, UTF8ToUTF16(username), NULL); |
| + int label_old_required_width = GetControlTextWidth(hwndSharingWith); |
| SetWindowText(hwndSharingWith, text.c_str()); |
| + int label_new_required_width = GetControlTextWidth(hwndSharingWith); |
| + |
| + int label_width_delta = label_new_required_width - label_old_required_width; |
| + int button_width_delta = |
| + button_new_required_width - button_old_required_width; |
| + |
| + RECT label_rect; |
| + GetClientRect(hwndSharingWith, &label_rect); |
| + SetWindowPos(hwndSharingWith, NULL, 0, 0, |
| + label_rect.right + label_width_delta, label_rect.bottom, |
| + SWP_NOMOVE|SWP_NOZORDER); |
| + |
| + RECT button_rect; |
| + GetWindowRect(hwndButton, &button_rect); |
| + POINT button_point = { button_rect.left, button_rect.top }; |
| + ScreenToClient(hwnd_, &button_point); |
| + SetWindowPos(hwndButton, NULL, |
| + button_point.x + label_width_delta, button_point.y, |
| + (button_rect.right - button_rect.left) + button_width_delta, |
| + button_rect.bottom - button_rect.top, SWP_NOZORDER); |
| + |
| + RECT window_rect; |
| + GetWindowRect(hwnd_, &window_rect); |
| + int width = (window_rect.right - window_rect.left) + |
| + button_width_delta + label_width_delta; |
| + int height = window_rect.bottom - window_rect.top; |
| + SetWindowPos(hwnd_, NULL, 0, 0, width, height, SWP_NOMOVE|SWP_NOZORDER); |
| + HRGN rgn = CreateRoundRectRgn(0, 0, width, height, kWindowBorderRadius, |
| + kWindowBorderRadius); |
| + SetWindowRgn(hwnd_, rgn, TRUE); |
| } |
| void DisconnectWindowWin::Hide() { |