Index: chrome_frame/turndown_prompt/turndown_prompt_window.cc |
diff --git a/chrome_frame/turndown_prompt/turndown_prompt_window.cc b/chrome_frame/turndown_prompt/turndown_prompt_window.cc |
index 851f1c01add6c2e9f2102b0825fc48d5d48af7f2..01d8baefb4f5db2de82f1e069a95e6ae5ae4d7ab 100644 |
--- a/chrome_frame/turndown_prompt/turndown_prompt_window.cc |
+++ b/chrome_frame/turndown_prompt/turndown_prompt_window.cc |
@@ -13,6 +13,7 @@ |
#include "chrome_frame/simple_resource_loader.h" |
#include "chrome_frame/utils.h" |
#include "grit/chrome_frame_dialogs.h" |
+#include "grit/chrome_frame_resources.h" |
#include "grit/chromium_strings.h" |
// atlctrlx.h requires 'min' and 'max' macros, the definition of which conflicts |
@@ -22,6 +23,34 @@ |
#include <minmax.h> // NOLINT |
#include <atlctrlx.h> // NOLINT |
+namespace { |
+const uint32 kBitmapImageSize = 18; |
+} // namespace |
+ |
+// WTL's CBitmapButton's drawing code is horribly broken when using transparent |
+// images (specifically, it doesn't clear the background between redraws). |
+// Fix it here. |
+class CFBitmapButton: public CBitmapButtonImpl<CFBitmapButton> |
+{ |
+ public: |
+ DECLARE_WND_SUPERCLASS(_T("WTL_BitmapButton"), GetWndClassName()) |
+ |
+ CFBitmapButton() : |
grt (UTC plus 2)
2013/07/22 16:07:27
CFBitmapButton()
: CBitmapButtonImpl<CFBitma
robertshield
2013/07/22 19:58:57
Done.
|
+ CBitmapButtonImpl<CFBitmapButton>(BMPBTN_AUTOSIZE | BMPBTN_HOVER, NULL) {} |
+ |
+ // "Overridden" from CBitmapButtonImpl via template hackery. See |
+ // CBitmapButtonImpl::OnPaint() in atlctrlx.h for details. |
+ void DoPaint(CDCHandle dc) { |
+ RECT rc; |
+ GetClientRect(&rc); |
+ dc.FillRect(&rc, (HBRUSH)(COLOR_BTNFACE+1)); |
grt (UTC plus 2)
2013/07/22 16:07:27
reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1)
robertshield
2013/07/22 19:58:57
Done.
|
+ |
+ // Call original implementation. |
+ CBitmapButtonImpl<CFBitmapButton>::DoPaint(dc); |
+ } |
+}; |
+ |
+// static |
base::WeakPtr<TurndownPromptWindow> TurndownPromptWindow::CreateInstance( |
InfobarContent::Frame* frame, |
UrlLauncher* url_launcher, |
@@ -48,6 +77,8 @@ base::WeakPtr<TurndownPromptWindow> TurndownPromptWindow::CreateInstance( |
instance->link_->SetHyperLinkExtendedStyle(HLINK_NOTIFYBUTTON, |
HLINK_NOTIFYBUTTON); |
+ SetupBitmapButton(instance); |
+ |
// Substitute the proper text given the current IE version. |
CWindow text = instance->GetDlgItem(IDC_TD_PROMPT_MESSAGE); |
string16 prompt_text(GetPromptText()); |
@@ -57,6 +88,53 @@ base::WeakPtr<TurndownPromptWindow> TurndownPromptWindow::CreateInstance( |
return instance; |
} |
+// static |
+void TurndownPromptWindow::SetupBitmapButton( |
+ const base::WeakPtr<TurndownPromptWindow>& instance) { |
grt (UTC plus 2)
2013/07/22 16:07:27
since this function doesn't store |instance| for l
robertshield
2013/07/22 19:58:57
Done.
|
+ CWindow close_window = instance->GetDlgItem(IDDISMISS); |
+ instance->close_button_.reset(new CFBitmapButton()); |
+ |
+ // Set the resource instance to the current dll which contains the bitmap. |
+ HINSTANCE old_res_module = _AtlBaseModule.GetResourceInstance(); |
+ HINSTANCE this_module = _AtlBaseModule.GetModuleInstance(); |
+ _AtlBaseModule.SetResourceInstance(this_module); |
+ |
+ HBITMAP close_bitmap = static_cast<HBITMAP>( |
+ LoadImage(this_module, MAKEINTRESOURCE(IDB_TURNDOWN_PROMPT_CLOSE_BUTTON), |
+ IMAGE_BITMAP, 0, 0, 0)); |
+ |
+ // Restore the module's resource instance. |
+ _AtlBaseModule.SetResourceInstance(old_res_module); |
+ |
+ // Create the image list with the appropriate size and colour mask. |
+ instance->close_button_->m_ImageList.Create(kBitmapImageSize, |
+ kBitmapImageSize, |
+ ILC_COLOR8|ILC_MASK, 4, 0); |
grt (UTC plus 2)
2013/07/22 16:07:27
ILC_COLOR8 | ILC_MASK
robertshield
2013/07/22 19:58:57
Done.
|
+ instance->close_button_->m_ImageList.Add(close_bitmap, RGB(255,0,255)); |
grt (UTC plus 2)
2013/07/22 16:07:27
255, 0, 255
robertshield
2013/07/22 19:58:57
Done.
|
+ instance->close_button_->m_ImageList.SetBkColor(CLR_NONE); |
+ |
+ // Configure the button states and initialize the button. |
+ instance->close_button_->SetImages(0, 1, 2, 3); |
grt (UTC plus 2)
2013/07/22 16:07:27
4, 5, 6, 7, 8
who do we appreciate
robertshield
ro
robertshield
2013/07/22 19:58:57
\o/
|
+ instance->close_button_->SubclassWindow(close_window); |
+ |
+ // The CDialogResize() implementation incorrectly captures the size |
+ // of the bitmap image button. Reset it here to ensure that resizing works |
+ // as desired. |
+ |
+ // Find the resize data. The parameters here must match the resize map in |
+ // turndown_prompt_window.h. |
+ _AtlDlgResizeData resize_params = { IDDISMISS, DLSZ_CENTER_Y | DLSZ_MOVE_X }; |
+ int resize_index = instance->m_arrData.Find(resize_params); |
+ DCHECK(resize_index > -1 && resize_index < instance->m_arrData.GetSize()); |
+ |
+ // Fiddle CDialogResize's internal data to fix up the size for the image |
+ // control. |
+ _AtlDlgResizeData& resize_data = instance->m_arrData[resize_index]; |
+ resize_data.m_rect.right = resize_data.m_rect.left + kBitmapImageSize; |
+ resize_data.m_rect.top = 0; |
+ resize_data.m_rect.bottom = kBitmapImageSize; |
+} |
+ |
TurndownPromptWindow::TurndownPromptWindow( |
InfobarContent::Frame* frame, |
UrlLauncher* url_launcher, |
@@ -74,6 +152,7 @@ void TurndownPromptWindow::OnFinalMessage(HWND) { |
} |
void TurndownPromptWindow::OnDestroy() { |
+ close_button_->m_ImageList.Destroy(); |
frame_ = NULL; |
} |