| OLD | NEW |
| (Empty) |
| 1 // Copyright 2011 Google Inc. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 // ======================================================================== | |
| 15 | |
| 16 #include "omaha/ui/yes_no_dialog.h" | |
| 17 #include "base/basictypes.h" | |
| 18 #include "omaha/base/debug.h" | |
| 19 #include "omaha/base/error.h" | |
| 20 #include "omaha/base/logging.h" | |
| 21 #include "omaha/base/window_utils.h" | |
| 22 #include "omaha/google_update/resource.h" | |
| 23 | |
| 24 namespace omaha { | |
| 25 | |
| 26 YesNoDialog::YesNoDialog(CMessageLoop* message_loop, HWND parent) | |
| 27 : message_loop_(message_loop), | |
| 28 parent_(parent), | |
| 29 yes_clicked_(false) { | |
| 30 ASSERT1(message_loop); | |
| 31 CORE_LOG(L3, (_T("[YesNoDialog::YesNoDialog]"))); | |
| 32 } | |
| 33 | |
| 34 | |
| 35 YesNoDialog::~YesNoDialog() { | |
| 36 CORE_LOG(L3, (_T("[YesNoDialog::~YesNoDialog]"))); | |
| 37 ASSERT1(!IsWindow()); | |
| 38 } | |
| 39 | |
| 40 HRESULT YesNoDialog::Initialize(const CString& yes_no_title, | |
| 41 const CString& yes_no_text) { | |
| 42 ASSERT1(!IsWindow()); | |
| 43 | |
| 44 if (!Create(parent_)) { | |
| 45 CORE_LOG(LE, (_T("[Failed to create YesNoDialog]"))); | |
| 46 return GOOPDATE_E_UI_INTERNAL_ERROR; | |
| 47 } | |
| 48 | |
| 49 VERIFY1(message_loop_->AddMessageFilter(this)); | |
| 50 | |
| 51 VERIFY1(SetWindowText(yes_no_title)); | |
| 52 VERIFY1(::SetWindowText(GetDlgItem(IDC_YES_NO_TEXT), yes_no_text)); | |
| 53 | |
| 54 CString yes; | |
| 55 VERIFY1(yes.LoadString(IDS_YES)); | |
| 56 CString no; | |
| 57 VERIFY1(no.LoadString(IDS_NO)); | |
| 58 | |
| 59 VERIFY1(::SetWindowText(GetDlgItem(IDOK), yes)); | |
| 60 VERIFY1(::SetWindowText(GetDlgItem(IDCANCEL), no)); | |
| 61 | |
| 62 HRESULT hr = WindowUtils::SetWindowIcon(m_hWnd, IDI_APP, address(hicon_)); | |
| 63 if (FAILED(hr)) { | |
| 64 CORE_LOG(LW, (_T("[Failed to SetWindowIcon][0x%x]"), hr)); | |
| 65 } | |
| 66 | |
| 67 return S_OK; | |
| 68 } | |
| 69 | |
| 70 HRESULT YesNoDialog::Show() { | |
| 71 ASSERT1(IsWindow()); | |
| 72 ASSERT1(!IsWindowVisible()); | |
| 73 | |
| 74 VERIFY1(CenterWindow(NULL)); | |
| 75 ShowWindow(SW_SHOWNORMAL); | |
| 76 | |
| 77 return S_OK; | |
| 78 } | |
| 79 | |
| 80 LRESULT YesNoDialog::OnClickedButton(WORD notify_code, | |
| 81 WORD id, | |
| 82 HWND wnd_ctl, | |
| 83 BOOL& handled) { // NOLINT | |
| 84 UNREFERENCED_PARAMETER(notify_code); | |
| 85 UNREFERENCED_PARAMETER(wnd_ctl); | |
| 86 | |
| 87 CORE_LOG(L3, (_T("[YesNoDialog::OnClickedButton]"))); | |
| 88 ASSERT1(id == IDOK || id == IDCANCEL); | |
| 89 | |
| 90 #pragma warning(push) | |
| 91 // C4061: enumerator 'xxx' in switch of enum 'yyy' is not explicitly handled | |
| 92 // by a case label. | |
| 93 #pragma warning(disable : 4061) | |
| 94 | |
| 95 switch (id) { | |
| 96 case IDOK: | |
| 97 yes_clicked_ = true; | |
| 98 break; | |
| 99 | |
| 100 case IDCANCEL: | |
| 101 yes_clicked_ = false; | |
| 102 break; | |
| 103 | |
| 104 default: | |
| 105 ASSERT1(false); | |
| 106 yes_clicked_ = false; | |
| 107 break; | |
| 108 } | |
| 109 #pragma warning(pop) | |
| 110 | |
| 111 handled = true; | |
| 112 SendMessage(WM_CLOSE, 0, 0); | |
| 113 | |
| 114 return 0; | |
| 115 } | |
| 116 | |
| 117 LRESULT YesNoDialog::OnClose(UINT message, | |
| 118 WPARAM wparam, | |
| 119 LPARAM lparam, | |
| 120 BOOL& handled) { | |
| 121 UNREFERENCED_PARAMETER(message); | |
| 122 UNREFERENCED_PARAMETER(wparam); | |
| 123 UNREFERENCED_PARAMETER(lparam); | |
| 124 | |
| 125 DestroyWindow(); | |
| 126 | |
| 127 handled = TRUE; | |
| 128 return 0; | |
| 129 } | |
| 130 | |
| 131 LRESULT YesNoDialog::OnNCDestroy(UINT message, | |
| 132 WPARAM wparam, | |
| 133 LPARAM lparam, | |
| 134 BOOL& handled) { | |
| 135 UNREFERENCED_PARAMETER(message); | |
| 136 UNREFERENCED_PARAMETER(wparam); | |
| 137 UNREFERENCED_PARAMETER(lparam); | |
| 138 | |
| 139 CORE_LOG(L3, (_T("[YesNoDialog::OnNCDestroy]"))); | |
| 140 VERIFY1(message_loop_->RemoveMessageFilter(this)); | |
| 141 | |
| 142 ::PostQuitMessage(0); | |
| 143 | |
| 144 handled = FALSE; // Let ATL default processing handle the WM_NCDESTROY. | |
| 145 return 0; | |
| 146 } | |
| 147 | |
| 148 } // namespace omaha | |
| 149 | |
| OLD | NEW |