-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainDlg.cpp
283 lines (235 loc) · 13.4 KB
/
MainDlg.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
// MainDlg.cpp : implementation of the CMainDlg class
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MainDlg.h"
#include "tabctrlex/SBrowserTab.h"
#include "SMiniblink.h"
LONG wndCount = 0;
#define MAX_BROWSER_TABS 10
CMainDlg::CMainDlg() : SHostWnd(_T("LAYOUT:XML_MAINWND")),m_pWebTab(NULL),m_pTabWebPage(NULL),m_pAddEt(NULL),iPage(0),m_bAutoCreate(true)
{
m_bLayoutInited = FALSE;
}
CMainDlg::~CMainDlg()
{
}
int CMainDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
SetMsgHandled(FALSE);
return 0;
}
BOOL CMainDlg::OnInitDialog(HWND hWnd, LPARAM lParam)
{
m_bLayoutInited = TRUE;
LONG count = InterlockedIncrement(&wndCount);
ModifyStyle(WS_BORDER, 0);
HRESULT hr = ::RegisterDragDrop(m_hWnd, GetDropTarget());
m_pWebTab = FindChildByName2<SBrowserTabCtrl>(L"WebBrowserTab");
m_pWebTab->RegisterHost(SHostFactory<CMainDlg>());
m_pTabWebPage = FindChildByName2<SRelTabCtrl>(L"tab_webpage");
SASSERT(m_pTabWebPage);
m_pWebTab->SetTabCtrl(m_pTabWebPage);
m_pAddEt = FindChildByName2<SEdit>(L"edt_address");
if(m_bAutoCreate)
m_pWebTab->InsertTab(_T("csdn"), _T("https://blog.csdn.net/weolar/article/details/80458523"), 0);
return 0;
}
void CMainDlg::SetAutoNewCreateTab(bool bAutoCreate)
{
m_bAutoCreate=bAutoCreate;
}
void CMainDlg::InsertTab(SBrowserTab * tab, STabPage * page)
{
if ((tab != NULL) && m_pWebTab != NULL)
{
if (m_pWebTab->InsertTabEx(tab, page))
++iPage;
OnUpdateWebBrowserTab();
}
}
bool CMainDlg::CreateHostWnd()
{
return ::IsWindow(Create(NULL)) == TRUE;
}
void CMainDlg::InitDialog()
{
SendMessage(WM_INITDIALOG);
}
void CMainDlg::SetPos(CPoint &curPos)
{
RECT rc;
SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)&rc, 0);
if (curPos.y > rc.bottom - 100)
{
curPos.y = rc.bottom - 100;
}
if (curPos.x > rc.right - 300)
{
curPos.x = rc.right - 300;
}
SetWindowPos(NULL, curPos.x - 100, curPos.y, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
}
void CMainDlg::OnUpdateWebBrowserTab()
{
if (m_pWebTab) {
CRect rcMain = GetWindowRect();
SStringW strPos;
if ((iPage * 200 + 36) < (rcMain.Width() - 10)) {
strPos.Format(_T("5,-30,%d,@30"), iPage * 200 + 36 + 75);
m_pWebTab->SetAttribute(_T("pos"), strPos);
}
else {
m_pWebTab->SetAttribute(_T("pos"), _T("5,-30,-5,@30"));
}
RequestRelayout(m_pWebTab->GetSwnd(),TRUE);
}
}
void CMainDlg::OnWebBrowserTabNew(EventArgs * pEvt)
{
EventBrowserTabNew *pEvtTabNew = (EventBrowserTabNew*)pEvt;
iPage++;
SStringT strTitle;
if (iPage > MAX_BROWSER_TABS) {
m_pWebTab->RemoveTab(iPage - 1);
iPage--;
return;
}
SBrowserTab *pEdgeTab = (SBrowserTab*)pEvtTabNew->pNewTab;
if (pEvtTabNew->pszTitle == NULL) {
strTitle = SStringT().Format(_T("新建标签页-%d"), iPage);
}
else {
strTitle = SStringT().Format(_T("%s"), pEvtTabNew->pszTitle);
}
pEdgeTab->SetTitle(strTitle);
pEvtTabNew->pNewTab->SetAttribute(L"tip", S_CT2W(strTitle));
if (m_pWebTab == NULL)
return;
int nPageCount = m_pWebTab->GetTabCount();
//m_pWebTab->SetCurSel(iPage - 1);
SStringT strPage;
strPage.Format(_T("(<page title=\"InsertItem\" id=\"%d\"><wkeWebkit size=\"full,full\" colorBkgnd=\"#ffffff\" id=\"%d\"/></page>)"), pEdgeTab->GetTabID(),pEdgeTab->GetTabID());
if (m_pTabWebPage == NULL)
return;
int nIndex = m_pTabWebPage->InsertItem(strPage);
if (nIndex != -1)
{
pEvtTabNew->pData;
SStringT strTitle;
SWkeWebkit *pWebHostWnd = (m_pTabWebPage->FindChildByID(pEdgeTab->GetTabID()))->FindChildByID2<SWkeWebkit>(pEdgeTab->GetTabID());
SASSERT(pWebHostWnd);
pWebHostWnd->LoadUrl((LPCTSTR)pEvtTabNew->pData);
m_pTabWebPage->SetCurSel(nIndex);
}
OnUpdateWebBrowserTab();
}
void CMainDlg::OnWebBrowserTabDel(EventArgs * pEvt)
{
EventBrowserTabClose *pEvtTabClose = (EventBrowserTabClose*)pEvt;
if (m_pWebTab) {
m_pTabWebPage->RemoveItem(m_pTabWebPage->GetIndexById(pEvtTabClose->iCloseTabId));
}
}
void CMainDlg::OnWebBrowserTabSel(EventArgs * pEvt)
{
EventBrowserTabSelChanged *pEvtTabChange = (EventBrowserTabSelChanged*)pEvt;
m_pTabWebPage->SetCurSelById(m_pWebTab->GetTabIdByIndex(pEvtTabChange->iNewSel));
SWkeWebkit *pWebHostWnd =GetCurMB();
m_pAddEt->SetWindowText(pWebHostWnd->GetUrl());
}
void CMainDlg::OnWkeTitleChanged(EventArgs * pEvt)
{
EventBrowserTitleChanged* pEv = (EventBrowserTitleChanged*)pEvt;
m_pWebTab->UpdateTabTitle(pEv->iId, pEv->pszTitle);
}
void CMainDlg::OnWkeUrlChanged(EventArgs * pEvt)
{
EventBrowserUrlChanged* pEv = (EventBrowserUrlChanged*)pEvt;
if (m_pWebTab->GetSelTabId()== pEv->iId)
{
//m_pAddEt->SetWindowText(pEv->pszUrl);
}
}
void CMainDlg::OnWkeNewNav(EventArgs * pEvt)
{
EventBrowserNewNav *pEv = (EventBrowserNewNav*)pEvt;
m_pWebTab->InsertTab(_T("new"), (void*)pEv->pszUrl, -1);
pEv->pRetView = GetCurMB()->GetWebView();
}
void CMainDlg::OnGoAddress()
{
SWkeWebkit *pWebHostWnd = GetCurMB();
pWebHostWnd->StopLoading();
pWebHostWnd->LoadUrl(m_pAddEt->GetWindowText());
}
void CMainDlg::OnGoAddress(EventArgs * pEvt)
{
OnGoAddress();
}
void CMainDlg::OnRefresh()
{
SWkeWebkit *pWebHostWnd = GetCurMB();
pWebHostWnd->ReLoad();
}
void CMainDlg::OnGoBack()
{
SWkeWebkit *pWebHostWnd = GetCurMB();
pWebHostWnd->GoBack();
}
void CMainDlg::OnGoForward()
{
SWkeWebkit *pWebHostWnd = GetCurMB();
pWebHostWnd->GoForward();
}
inline SWkeWebkit * CMainDlg::GetCurMB()
{
SWindow* pPage = (STabPage *)m_pTabWebPage->GetPage(m_pTabWebPage->GetCurSel());
return pPage->FindChildByID2<SWkeWebkit>(pPage->GetID());;
}
//*/
//TODO:消息映射
void CMainDlg::OnClose()
{
if (m_pWebTab->GetTabCount() > 1) {
if (SMessageBox(GetHostHwnd(), L"还有其它标签未关闭,确定要退出吗?",L"提示",MB_OKCANCEL) != IDOK)
return;
}
m_pWebTab->CloseAllTab();
SNativeWnd::DestroyWindow();
if (InterlockedDecrement(&wndCount) == 0)
{
PostQuitMessage(0);
}
}
void CMainDlg::OnMaximize()
{
SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE);
}
void CMainDlg::OnRestore()
{
SendMessage(WM_SYSCOMMAND, SC_RESTORE);
}
void CMainDlg::OnMinimize()
{
SendMessage(WM_SYSCOMMAND, SC_MINIMIZE);
}
void CMainDlg::OnSize(UINT nType, CSize size)
{
SetMsgHandled(FALSE);
if (!m_bLayoutInited) return;
SWindow *pBtnMax = FindChildByName(L"btn_max");
SWindow *pBtnRestore = FindChildByName(L"btn_restore");
if(!pBtnMax || !pBtnRestore) return;
if (nType == SIZE_MAXIMIZED)
{
pBtnRestore->SetVisible(TRUE);
pBtnMax->SetVisible(FALSE);
}
else if (nType == SIZE_RESTORED)
{
pBtnRestore->SetVisible(FALSE);
pBtnMax->SetVisible(TRUE);
}
OnUpdateWebBrowserTab();
}