-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrowserPopupDlg.cpp
116 lines (87 loc) · 2.78 KB
/
BrowserPopupDlg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// BrowserPopupDlg.cpp : implementation file
//
#include "stdafx.h"
#include "BrowserPopupDlg.hpp"
#include "JSHook.hpp"
// CBrowserPopupDlg dialog
IMPLEMENT_DYNAMIC(CBrowserPopupDlg, CBrowserHostDlg)
CBrowserPopupDlg::CBrowserPopupDlg(CComObject<JSHook>* hook, std::vector<CBrowserPopupDlg*> *popups, CWnd* pParent /*=NULL*/)
: CBrowserHostDlg(IDC_EXPLORER, CBrowserPopupDlg::IDD, pParent),
m_hook(hook), m_popups(popups), m_waitingForBlankDoc(false), m_isFinished(false) {
}
CBrowserPopupDlg::~CBrowserPopupDlg() {
}
void CBrowserPopupDlg::DoDataExchange(CDataExchange* pDX) {
CBrowserHostDlg::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CBrowserPopupDlg, CBrowserHostDlg)
ON_WM_SIZE()
END_MESSAGE_MAP()
// CBrowserPopupDlg message handlers
BOOL CBrowserPopupDlg::OnInitDialog() {
CBrowserHostDlg::OnInitDialog();
repositionExplorer();
return TRUE;
}
void CBrowserPopupDlg::OnSize(UINT nType, int cx, int cy) {
CBrowserHostDlg::OnSize(nType, cx, cy);
repositionExplorer();
}
void CBrowserPopupDlg::repositionExplorer() {
CRect rect;
GetClientRect(&rect);
::MoveWindow(getExplorerHwnd(), 0, 0, rect.Width(), rect.Height(), true);
}
bool CBrowserPopupDlg::isFinished() {
return m_isFinished;
}
void CBrowserPopupDlg::requestClose() {
if (m_waitingForBlankDoc) return;
Navigate(L"about:blank");
ShowWindow(SW_HIDE);
m_waitingForBlankDoc = true;
}
CComObject<JSHook>* CBrowserPopupDlg::getHook() {
return m_hook;
}
bool CBrowserPopupDlg::isHookActive() {
return !m_waitingForBlankDoc;
}
void CBrowserPopupDlg::onTitleChange(LPCTSTR lpszText) {
CStringW title(lpszText);
if (title.IsEmpty())
SetWindowText(CStringW(L"Drip"));
else
SetWindowText(CStringW(L"Drip - ") + CStringW(lpszText));
}
void CBrowserPopupDlg::onWindowSetHeight(long height) {
CRect clientRect, windowRect;
GetClientRect(&clientRect);
GetWindowRect(&windowRect);
windowRect.bottom += height - clientRect.Height();
MoveWindow(&windowRect);
}
void CBrowserPopupDlg::onWindowSetWidth(long width) {
CRect clientRect, windowRect;
GetClientRect(&clientRect);
GetWindowRect(&windowRect);
windowRect.right += width - clientRect.Width();
MoveWindow(&windowRect);
}
void CBrowserPopupDlg::onOuterDocumentLoad(MSHTML::IHTMLDocument2Ptr doc) {
if (m_waitingForBlankDoc)
m_isFinished = true;
// For some reason, the control does not seem to be resizeable until after the page has loaded
//
repositionExplorer();
}
void CBrowserPopupDlg::onNewWindow(CBrowserHostDlg** ppDlg) {
CBrowserPopupDlg *dlg = new CBrowserPopupDlg(m_hook,m_popups,this);
dlg->Create(CBrowserPopupDlg::IDD);
dlg->ShowWindow(SW_SHOW);
m_popups->push_back(dlg);
*ppDlg = dlg;
}
void CBrowserPopupDlg::onClosing() {
requestClose();
}