MainFrm.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:40k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "Styler.h"
  5. #include "ComboBoxSearch.h"
  6. #include "InetTools.h"
  7. #include "MainFrm.h"
  8. #include "StylerView.h"
  9. #include "ChildFrm.h"
  10. #include "FilterDialog.h"
  11. #include "PopupFilter.h"
  12. #include "MouseManager.h"
  13. #include "OptionsDialog.h"
  14. #include "CWebBrowser2.h"
  15.  
  16. #include "ControlFavorites.h"
  17.  
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #endif  
  21. CStringArray CMainFrame::m_arrEncodingPage;
  22. BOOL CMainFrame::m_bConfirmCloseAll = FALSE;
  23. BOOL CMainFrame::m_bConfirmExit = FALSE;
  24. BOOL CMainFrame::m_bOneInstance = FALSE;
  25. int CMainFrame::m_nStartup = STARTUP_HOME;
  26. BOOL CMainFrame::m_bRestoreWindowPos = FALSE;
  27. XTPPaintTheme  CMainFrame::m_themeCurrent = xtpThemeRibbon;
  28. #define ID_TOGGLE_DOCK 0xDDEE
  29.  
  30.  
  31. // CMainFrame   
  32.   
  33. IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
  34. BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
  35. ON_WM_CREATE()
  36.  
  37. ON_XTP_EXECUTE(ID_GOTO_URL, OnGotoUrl)
  38. ON_UPDATE_COMMAND_UI(ID_GOTO_URL, OnUpdateGotoUrl)
  39. ON_XTP_EXECUTE(ID_FAVORITE_LINK, OnFavorite)
  40. ON_XTP_EXECUTE(ID_OPENALLFOLDERITEMS, OnOpenAllItems)
  41. ON_COMMAND(ID_ORGANIZE_FAV, OnOrganizeFavorites)
  42. ON_COMMAND(ID_FILE_WORKOFFLINE, OnFileWorkoffline)
  43. ON_UPDATE_COMMAND_UI(ID_FILE_WORKOFFLINE, OnUpdateFileWorkoffline)
  44. ON_COMMAND(ID_WINDOW_CLOSE_ALL, OnWindowCloseAll)
  45. ON_UPDATE_COMMAND_UI(ID_WINDOW_CLOSE_ALL, OnUpdateWindowCloseAll)
  46. ON_COMMAND(ID_TOOLS_IMAGESFILTER, OnToolsImagesfilter)
  47. ON_COMMAND(ID_TOOLS_POPUPFILTER, OnToolsPopupfilter)
  48. ON_COMMAND(ID_TOGGLE_DOCK, OnToggleDock)
  49. ON_COMMAND(ID_TOOLS_SWITCHTHEME, OnSwitchTheme)
  50. ON_UPDATE_COMMAND_UI(ID_WINDOW_CASCADE, OnDisableMenu)
  51. ON_UPDATE_COMMAND_UI(ID_WINDOW_TILE_HORZ, OnDisableMenu)
  52. ON_COMMAND(ID_VIEW_FULLSCREEN, OnViewFullscreen)
  53. ON_UPDATE_COMMAND_UI(ID_VIEW_FULLSCREEN, OnUpdateViewFullscreen)
  54. ON_COMMAND(ID_FILE_NEW_CURRENT, OnFileNewCurrent)
  55. ON_UPDATE_COMMAND_UI(ID_FILE_NEW_CURRENT, OnUpdateFileNewCurrent)
  56. ON_COMMAND(ID_FILE_NEW_BLANK, OnFileNewBlank)
  57. ON_WM_SETTINGCHANGE()
  58. ON_COMMAND(ID_EXPLORER_SEARCH, OnExploreSearch)
  59. ON_COMMAND(ID_EXPLORER_HISTORY, OnExploreHistory)
  60. ON_COMMAND(ID_EXPLORER_SOURCE, OnExploreSource)
  61. ON_COMMAND(ID_EXPLORER_FOLDER, OnExploreFolder)
  62. ON_COMMAND(ID_EXPLORER_NOTEPAD, OnExploreNotepad)
  63. ON_COMMAND(ID_TOOLS_STRUCTURE, OnToolsStructure)
  64. ON_UPDATE_COMMAND_UI(ID_TOOLS_STRUCTURE, OnUpdateToolsStructure)
  65. ON_COMMAND(ID_VIEW_ENCODING_AUTOSELECT, OnViewEncodingAuto)
  66. ON_UPDATE_COMMAND_UI(ID_VIEW_ENCODING_AUTOSELECT, OnUpdateViewEncodingAuto)
  67. //ON_COMMAND(ID_TOOLBAR_GO, OnGotoUrl)
  68. ON_WM_CLOSE()
  69. ON_COMMAND(ID_TOOLS_DEFAULTBROWSER, OnSetDefault)
  70. ON_COMMAND(ID_TOOLS_STYLEROPTIONS, OnStylerOptions)
  71. ON_MESSAGE(WM_USER_SHELL_OPEN, OnShellOpen) 
  72. ON_XTP_EXECUTE(ID_GOTO_SEARCH, OnGotoSearch)
  73. ON_UPDATE_COMMAND_UI(ID_INDICATOR, OnUpdateIndicator)
  74. ON_WM_DESTROY()
  75. ON_MESSAGE(WM_XTP_PRETRANSLATEMOUSEMSG, OnTabbarMouseMsg)
  76. ON_COMMAND(ID_SEARCH_LIST, OnSearchList)
  77. ON_MESSAGE(XTPWM_DOCKINGPANE_NOTIFY, OnDockingPaneNotify)
  78. ON_COMMAND_RANGE(ID_THEME_DEFAULT, ID_THEME_RIBBON, OnTheme)
  79. ON_UPDATE_COMMAND_UI_RANGE(ID_THEME_DEFAULT, ID_THEME_RIBBON, OnUpdateTheme)
  80. ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
  81. ON_XTP_CREATECONTROL()
  82. ON_MESSAGE(WM_XTP_CONTROLRBUTTONUP, OnControlRButtonUp)
  83. END_MESSAGE_MAP()
  84. // CMainFrame construction/destruction
  85. CMainFrame::CMainFrame()
  86. {
  87. m_pSession = NULL;
  88. m_bShowStructure = FALSE;
  89. m_hEncoding = 0;
  90. m_hFavorites = 0;
  91. m_bFullScreen = FALSE;
  92. XTAuxData().UpdateSysMetrics();
  93. TCHAR szStylesPath[_MAX_PATH];
  94. VERIFY(::GetModuleFileName(
  95. AfxGetApp()->m_hInstance, szStylesPath, _MAX_PATH));
  96. m_strStylesPath = szStylesPath;
  97. int nIndex  = m_strStylesPath.ReverseFind(_T('\'));
  98. if (nIndex > 0) {
  99. m_strStylesPath = m_strStylesPath.Left(nIndex);
  100. }
  101. else {
  102. m_strStylesPath.Empty();
  103. }
  104. m_strStylesPath += _T("\Styles\");
  105. }
  106. CMainFrame::~CMainFrame()
  107. {
  108. if (m_bShowStructure)
  109. {
  110. CInetTools::SetStyleSheet(FALSE, FALSE);
  111. }
  112. UninitialNameSpace();
  113. }
  114. static UINT uHideCmds[] =
  115. {
  116. ID_FILE_PRINT,
  117. ID_FILE_PRINT_PREVIEW,
  118. ID_FILE_PRINT_SETUP,
  119. ID_FILE_PROPERTIES,
  120. ID_VIEW_SOURCE,
  121. ID_VIEW_FULLSCREEN,
  122. ID_TOOLS_STRUCTURE,
  123. ID_TOOLS_DEFAULTBROWSER,
  124. ID_SHOWIMAGES
  125. };  
  126.  
  127. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  128. {
  129. if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
  130. return -1;
  131. if (!m_wndStatusBar.Create(this))
  132. {
  133. TRACE0("Failed to create status barn");
  134. return -1;      // fail to create
  135. }
  136. m_wndStatusBar.AddIndicator(0);
  137. m_wndStatusBar.SetPaneStyle(0, SBPS_STRETCH);
  138. m_wndStatusBar.AddIndicator(new CIndicatorStatusBarPane(), ID_INDICATOR);
  139. m_wndStatusBar.SetPaneInfo(1, ID_INDICATOR, SBPS_NORMAL, 95);
  140. m_wndStatusBar.AddIndicator(ID_EMPTY);
  141. m_wndStatusBar.SetPaneInfo(2, ID_EMPTY, SBPS_NORMAL, 245);
  142. if (!InitCommandBars())
  143. return -1;
  144. //XTPOffice2007Images()->SetHandle(_T("Styles\Office2007Gray.dll"));
  145. XTPImageManager()->SetMaskColor(RGB(0, 255, 0));
  146. XTPImageManager()->SetIcons(IDR_MENUBAR);
  147. CXTPCommandBars* pCommandBars = GetCommandBars();
  148. CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
  149. pMenuBar->SetFlags(xtpFlagHideMinimizeBox | xtpFlagHideMaximizeBox | xtpFlagIgnoreSetMenuMessage);
  150. //SetMenu(0);
  151. CXTPToolBar* pCommandBar = (CXTPToolBar*)pCommandBars->Add(_T("Standard"), xtpBarTop);
  152. if (!pCommandBar ||
  153. !pCommandBar->LoadToolBar(IDR_MAINFRAME))
  154. {
  155. TRACE0("Failed to create toolbarn");
  156. return -1;
  157. }
  158. CXTPToolBar* pSearchBar = (CXTPToolBar*)pCommandBars->Add(_T("Search"), xtpBarTop);
  159. if (!pSearchBar ||
  160. !pSearchBar->LoadToolBar(IDR_SEARCH))
  161. {
  162. TRACE0("Failed to create toolbarn");
  163. return -1;
  164. }
  165. DockRightOf(pSearchBar, pCommandBar);
  166. pCommandBar = (CXTPToolBar*)pCommandBars->Add(_T("Switch Theme"), xtpBarTop);
  167. if (!pCommandBar ||
  168. !pCommandBar->LoadToolBar(IDR_SWITCH))
  169. {
  170. TRACE0("Failed to create toolbarn");
  171. return -1;
  172. }
  173. DockRightOf(pCommandBar, pSearchBar);
  174. m_paneManager.InstallDockingPanes(this);
  175. CXTPDockingPane* A = m_paneManager.CreatePane(IDS_TITLE_HIS, CRect(0, 0,200, 120), xtpPaneDockLeft);
  176. CXTPDockingPane* B = m_paneManager.CreatePane(IDS_TITLE_SHELL, CRect(0, 0,200, 120), xtpPaneDockBottom, A);
  177. CXTPDockingPane* C = m_paneManager.CreatePane(IDS_TITLE_NOTEPAD, CRect(0, 0,200, 120), xtpPaneDockRight);
  178. CXTPDockingPane* D = m_paneManager.CreatePane(IDS_TITLE_SOURCE, CRect(0, 0,200, 120), xtpPaneDockBottom, C);
  179. CXTPDockingPane* E = m_paneManager.CreatePane(IDS_TITLE_SEARCH, CRect(0, 0,200, 120), xtpPaneDockBottom, D);
  180. m_paneManager.AttachPane(B, A);
  181. m_paneManager.AttachPane(C, A);
  182. m_paneManager.AttachPane(D, A);
  183. m_paneManager.AttachPane(E, A);
  184. A->Hide();
  185. CXTPDockingPaneLayout layout(&m_paneManager);
  186. if (layout.Load(_T("Standard")))
  187. m_paneManager.SetLayout(&layout);
  188. VERIFY(m_MTIClientWnd.Attach(this, TRUE));
  189. m_MTIClientWnd.LoadState();
  190. m_MTIClientWnd.EnableToolTips();
  191. m_MTIClientWnd.SetFlags(xtpWorkspaceHideClose | xtpWorkspaceHideArrows | xtpWorkspaceShowCloseSelectedTab);
  192. InitialNameSpace();
  193. BuildEncodingMenu();
  194. XTPPaintManager()->RefreshMetrics();
  195. RefreshIcons();
  196. CXTPCommandBarsOptions* pOptions = pCommandBars->GetCommandBarsOptions();
  197. pOptions->bAlwaysShowFullMenus = FALSE;
  198. pCommandBars->HideCommands(uHideCmds, _countof(uHideCmds));
  199. pOptions->ShowKeyboardCues(xtpKeyboardCuesShowWindowsDefault);
  200. pCommandBars->GetToolTipContext()->SetStyle(xtpToolTipOffice); 
  201. pCommandBars->GetShortcutManager()->SetAccelerators(IDR_MAINFRAME);
  202. SetTheme(m_themeCurrent);
  203. LoadCommandBars(_T("CommandBarsv2"));
  204. return 0;
  205. }
  206. static LPCTSTR RegisterSimilarClass(LPCTSTR lpszNewClassName,
  207. LPCTSTR lpszOldClassName, UINT nIDResource)
  208. {
  209. HINSTANCE hInst = AfxGetInstanceHandle();
  210. WNDCLASS wc;
  211. if (!::GetClassInfo(hInst, lpszOldClassName, &wc)) 
  212. {
  213. TRACE(_T("Can't find window class %sn"), lpszOldClassName);
  214. return NULL;
  215. }
  216. wc.lpszClassName = lpszNewClassName;
  217. wc.hIcon = ::LoadIcon(hInst, MAKEINTRESOURCE(nIDResource));
  218. if (!AfxRegisterClass(&wc)) 
  219. {
  220. TRACE(_T("Unable to register window class%sn"), lpszNewClassName);
  221. return NULL;
  222. }
  223. return lpszNewClassName;
  224. }
  225. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  226. {
  227. if (!CMDIFrameWnd::PreCreateWindow(cs))
  228. return FALSE;
  229. static LPCTSTR lpszClass = NULL;
  230. if (lpszClass == NULL) 
  231. lpszClass = RegisterSimilarClass(_T("StylerMainWindow"), cs.lpszClass, IDR_MAINFRAME);
  232. if (lpszClass == NULL)
  233. return FALSE;
  234. cs.lpszClass = lpszClass;
  235. return TRUE;
  236. }
  237. // CMainFrame diagnostics
  238. #ifdef _DEBUG
  239. void CMainFrame::AssertValid() const
  240. {
  241. CMDIFrameWnd::AssertValid();
  242. }
  243. void CMainFrame::Dump(CDumpContext& dc) const
  244. {
  245. CMDIFrameWnd::Dump(dc);
  246. }
  247. #endif //_DEBUG
  248. void CMainFrame::SetAddress(LPCTSTR lpszUrl)
  249. {
  250. CXTPControlComboBox* pCombo = GetAddressCombo();
  251. if (pCombo)
  252. {
  253. pCombo->SetEditText(lpszUrl);
  254. }
  255. }
  256. void OpenWindow(CString strUrl, BOOL bActivate, BOOL bReplaceBlank)
  257. {
  258. if (bReplaceBlank)
  259. {
  260. CChildFrame* pFrame = (CChildFrame*)((CMainFrame*)AfxGetMainWnd())->MDIGetActive();
  261. if (pFrame)
  262. {
  263. CStylerView* pView = (CStylerView*)pFrame->GetActiveView();
  264. if (pView->GetDocument()->GetCurrentUrl() == ABOUTBLANK)
  265. {
  266. pView->GetDocument()->SetUrl(strUrl);
  267. pView->Navigate(strUrl);
  268. return;
  269. }
  270. }
  271. }
  272. CWinApp* pApp = AfxGetApp();
  273. // Get the correct document template.
  274. POSITION pos = pApp->GetFirstDocTemplatePosition();
  275. CDocTemplate* pDocTemplate = pApp->GetNextDocTemplate( pos );
  276. CStylerDoc* pStylerDoc = (CStylerDoc*)pDocTemplate->CreateNewDocument();
  277. pStylerDoc->SetUrl(strUrl);
  278. // Create a new frame.
  279. CFrameWnd* pFrame = pDocTemplate->CreateNewFrame(
  280. pStylerDoc,
  281. (CFrameWnd*)AfxGetMainWnd() );
  282. // Activate the frame.
  283. if (!bActivate) ((CChildFrame*)pFrame)->m_bActivate = FALSE;
  284. pDocTemplate->InitialUpdateFrame( pFrame, NULL );
  285. CStylerView* pView = (CStylerView*)pFrame->GetActiveView();
  286. // Pass pointer of WebBrowser object.
  287. pView->SetRegisterAsBrowser( TRUE );
  288. pView->GetDocument()->SetUrl(strUrl);
  289. pView->Navigate(strUrl);
  290. }
  291. void CommonNavigate(CMDIChildWnd* pFrame, CString& strUrl)
  292. {
  293. if (pFrame == NULL)
  294. OpenWindow(strUrl);
  295. else
  296. {
  297. CStylerView* pView = (CStylerView*)pFrame->GetActiveView();
  298. if (pView)
  299. {
  300. pView->SetLoading(TRUE);
  301. pView->GetDocument()->SetUrl(strUrl);
  302. pView->Navigate(strUrl);
  303. }
  304. }
  305. }
  306. void CMainFrame::OnGotoUrl(NMHDR* pNMHDR, LRESULT* pResult)
  307. {
  308. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  309. CXTPControlComboBox* pCombo = (CXTPControlComboBox*)tagNMCONTROL->pControl;
  310. ASSERT(pCombo);
  311. ASSERT(pCombo->GetType() == xtpControlComboBox);
  312. CString strUrl = pCombo->GetEditText();
  313. strUrl.TrimLeft();
  314. if (strUrl.IsEmpty())
  315. return;
  316. int nIndex = strUrl.Find(' ');
  317. if (nIndex != -1)
  318. {
  319. CString strKeyword = strUrl.Left(nIndex);
  320. CString strSearch = strUrl.Mid(nIndex + 1);
  321. strSearch.TrimLeft();
  322. for (int i = 0; i < CPageSearch::m_arrEngines.GetSize(); i++)
  323. {
  324. CPageSearch::ENGINE& engine = CPageSearch::m_arrEngines[i];
  325. if (engine.strKeyword.CompareNoCase(strKeyword) == 0)
  326. {
  327. strUrl = engine.strSearch;
  328. strUrl.Replace(_T("%s"), strSearch);
  329. CommonNavigate(MDIGetActive(), strUrl);
  330. pCombo->SetEditText(strUrl);
  331. return;
  332. }
  333. }
  334. nIndex = strUrl.Find(':');
  335. if(nIndex >= 0) strUrl.Replace('\','/');
  336. else strUrl = _T("http://") + strUrl;
  337. CommonNavigate(MDIGetActive(), strUrl);
  338. if (strUrl.Right(1) == _T("/"))
  339. strUrl.Delete(strUrl.GetLength() - 1);
  340. if (pCombo->FindStringExact(0, strUrl) == CB_ERR)
  341. pCombo->InsertString(0, strUrl);
  342. *pResult = 1;
  343. }
  344. void CMainFrame::OnGotoSearch(NMHDR* pNMHDR, LRESULT* pResult)
  345. {
  346. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  347. CComboBoxSearch* pCombo = (CComboBoxSearch*)tagNMCONTROL->pControl;
  348. ASSERT(pCombo);
  349. ASSERT(pCombo->GetType() == xtpControlComboBox);
  350. int nSearch = pCombo->m_nCurrentEngine;
  351. CString strSearch = pCombo->GetEditText();
  352. if (!strSearch.IsEmpty() && nSearch >= 0 && nSearch < CPageSearch::m_arrEngines.GetSize())
  353. {
  354. CPageSearch::ENGINE& engine = CPageSearch::m_arrEngines[nSearch ];
  355. if (engine.strTitle == strSearch)
  356. return;
  357. CString strUrl = engine.strSearch;
  358. strUrl.Replace(_T("%s"), strSearch);
  359. OpenWindow(strUrl, TRUE, TRUE);
  360. }
  361. *pResult = 1;
  362. }
  363. void CMainFrame::OnWindowCloseAll()
  364. {
  365. if (m_bConfirmCloseAll)
  366. {
  367. if (AfxMessageBox(IDS_CONFIRM_CLOSEALL,  MB_YESNO | MB_ICONQUESTION ) != IDYES)
  368. return;
  369. }
  370. AfxGetApp()->CloseAllDocuments(FALSE); 
  371. }
  372. void CMainFrame::OnUpdateWindowCloseAll(CCmdUI *pCmdUI)
  373. {
  374. pCmdUI->Enable((CChildFrame*)MDIGetActive() != NULL);
  375. }
  376. void CMainFrame::OnUpdateGotoUrl(CCmdUI *pCmdUI)
  377. {
  378. pCmdUI->Enable();
  379. }
  380. void CMainFrame::OnEmptyCommand()
  381. {
  382. }
  383. void CMainFrame::OnFavorite(NMHDR* pNMHDR, LRESULT* pResult)
  384. {
  385. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  386. OpenWindow(tagNMCONTROL->pControl->GetParameter(), TRUE, TRUE);
  387. *pResult = 1;
  388. }
  389. void CMainFrame::OnOpenAllItems(NMHDR* pNMHDR, LRESULT* pResult)
  390. {
  391. NMXTPCONTROL* tagNMCONTROL = (NMXTPCONTROL*)pNMHDR;
  392. CString strPath = tagNMCONTROL->pControl->GetParameter();
  393. WIN32_FIND_DATA wfd;
  394. HANDLE h;
  395. h = FindFirstFile(strPath + _T("*.*"), &wfd);
  396. if(h != INVALID_HANDLE_VALUE)
  397. {
  398. do
  399. {
  400. CString strFile = wfd.cFileName;
  401. if((wfd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM))==0 &&
  402. strFile.Right(4).CompareNoCase(_T(".url")) == 0)
  403. {
  404. TCHAR buf[INTERNET_MAX_PATH_LENGTH];
  405. ::GetPrivateProfileString(_T("InternetShortcut"), _T("URL"),
  406. _T(""), buf, INTERNET_MAX_PATH_LENGTH,
  407. strPath + strFile);
  408. OpenWindow(buf);
  409. }
  410. } while(FindNextFile(h, &wfd));
  411. FindClose(h);
  412. *pResult = 1;
  413. }
  414. void CMainFrame::OnOrganizeFavorites()
  415. {
  416. CInetTools::MtlOrganizeFavorite(GetSafeHwnd());
  417. }
  418. void CMainFrame::OnFileWorkoffline()
  419. {
  420. CInetTools::MtlSetGlobalOffline(!CInetTools::MtlIsGlobalOffline());
  421. }
  422. void CMainFrame::OnUpdateFileWorkoffline(CCmdUI *pCmdUI)
  423. {
  424. pCmdUI->SetCheck(CInetTools::MtlIsGlobalOffline());
  425. }
  426. void CMainFrame::OnToolsImagesfilter()
  427. {
  428. CFilterDialog fd;
  429. fd.DoModal();
  430. }
  431. void CMainFrame::OnToggleDock(void)
  432. {
  433. if (m_MTIClientWnd.GetPaintManager()->GetPosition() != xtpTabPositionTop)
  434. m_MTIClientWnd.GetPaintManager()->SetPosition(xtpTabPositionTop);
  435. else
  436. m_MTIClientWnd.GetPaintManager()->SetPosition(xtpTabPositionBottom);
  437. m_MTIClientWnd.SaveState();
  438. RecalcLayout(TRUE);
  439. }
  440. void CMainFrame::OnDisableMenu(CCmdUI *pCmdUI)
  441. {
  442. pCmdUI->Enable(FALSE);
  443. }
  444. void CMainFrame::OnViewFullscreen()
  445. {
  446. if (!m_bFullScreen)
  447. {
  448. GetWindowRect(&m_rcMainFrame);
  449. ModifyStyle(WS_CAPTION, 0);
  450. // Now resize the main window
  451. int cxScrn   = ::GetSystemMetrics(SM_CXSCREEN);
  452. int cyScrn   = ::GetSystemMetrics(SM_CYSCREEN);
  453. int cxBorder = ::GetSystemMetrics(SM_CXBORDER);
  454. int cyBorder = ::GetSystemMetrics(SM_CYBORDER);
  455. SetWindowPos(NULL, -cxBorder, -cyBorder, cxScrn + cxBorder * 2, 
  456. cyScrn + cyBorder * 2, SWP_NOZORDER);
  457. RecalcLayout(TRUE);
  458. m_bFullScreen = TRUE;
  459. } else
  460. {
  461. ModifyStyle(0, WS_CAPTION);
  462. MoveWindow(&m_rcMainFrame);
  463. RecalcLayout(TRUE);
  464. m_bFullScreen = FALSE;
  465. }
  466. }
  467. void CMainFrame::OnUpdateViewFullscreen(CCmdUI *pCmdUI)
  468. {
  469. pCmdUI->SetCheck(m_bFullScreen);
  470. }
  471. void CMainFrame::OnFileNewBlank()
  472. {
  473. OpenWindow(ABOUTBLANK);
  474. CXTPControlComboBox* pCombo = GetAddressCombo();
  475. if (pCombo) pCombo->GetEditCtrl()->SetFocus();
  476. }
  477. void CMainFrame::OnFileNewCurrent()
  478. {
  479. CChildFrame* wndBrowserFrame = (CChildFrame*)MDIGetActive();
  480. if (wndBrowserFrame && wndBrowserFrame->GetActiveView())
  481. {
  482. CString str = ((CStylerView*)wndBrowserFrame->GetActiveView())->GetLocationURL();
  483. OpenWindow(str);
  484. }
  485. void CMainFrame::OnUpdateFileNewCurrent(CCmdUI *pCmdUI)
  486. {
  487. pCmdUI->Enable((CChildFrame*)MDIGetActive() != NULL);
  488. }
  489. void CMainFrame::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
  490. {
  491. CRect rcC;
  492. GetClientRect(&rcC);
  493. CMDIFrameWnd::OnSettingChange(uFlags, lpszSection);
  494. RecalcLayout(FALSE);
  495. RedrawWindow(FALSE);
  496. }
  497. void CMainFrame::OnToolsStructure()
  498. {
  499. m_bShowStructure = !m_bShowStructure;
  500. CInetTools::SetStyleSheet(m_bShowStructure, TRUE);
  501. CChildFrame* wndBrowserFrame = (CChildFrame*)MDIGetActive();
  502. if (wndBrowserFrame && wndBrowserFrame->GetActiveView())
  503. {
  504. ((CStylerView*)wndBrowserFrame->GetActiveView())->Refresh();
  505. }
  506. }
  507. void CMainFrame::OnUpdateToolsStructure(CCmdUI *pCmdUI)
  508. {
  509. pCmdUI->SetCheck(m_bShowStructure);
  510. }
  511. void CMainFrame::InitialNameSpace()
  512. {
  513. if(CoInternetGetSession(0, &m_pSession, 0)==S_OK)
  514. {
  515. m_pFilter = (CFilterContent*)CFilterContent::CreateObject();
  516. m_pSession->RegisterNameSpace((LPCLASSFACTORY)m_pFilter->GetInterface(&IID_IClassFactory), 
  517. CLSID_FilterContent, L"http", 0, NULL, 0);
  518. }
  519. }
  520. void CMainFrame::UninitialNameSpace()
  521. {
  522. if(m_pSession!=NULL)
  523. {
  524. m_pSession->UnregisterNameSpace((LPCLASSFACTORY)m_pFilter->GetInterface(&IID_IClassFactory), L"http");
  525. m_pSession->Release();
  526. m_pSession = NULL;
  527. ASSERT(m_pFilter);
  528. m_pFilter->InternalRelease();
  529. m_pFilter = NULL;
  530. }
  531. }
  532. void LoadEncoding(CMenu* pMenu)
  533. {
  534. CMainFrame::m_arrEncodingPage.RemoveAll();
  535. TCHAR chReturn[100];
  536. CString strLine;
  537. int nIndex = 0;
  538. CString strPath = GetModuleDir();
  539. strLine.Format(_T("line%i"), nIndex);
  540. BOOL bPrevSeparator = FALSE;
  541. int nID = ID_VIEW_ENCODING_FIRST;
  542. while (GetPrivateProfileString(_T("Encoding"), strLine, _T(""), chReturn, 100, strPath + _T("encoding.ini")) > 0)
  543. {
  544. CString strReturn(chReturn);
  545. if (!strReturn.IsEmpty())
  546. {
  547. int n = strReturn.Find(',');
  548. if (n != -1)
  549. {
  550. CString strPage = strReturn.Left(n);
  551. strPage.TrimLeft(); strPage.TrimRight();
  552. CString strDesc = strReturn.Right(strReturn.GetLength() - n - 1);
  553. strDesc.TrimLeft(); strDesc.TrimRight();
  554. if (!strDesc.IsEmpty() && !strPage.IsEmpty())
  555. {
  556. if (bPrevSeparator && nID != ID_VIEW_ENCODING_FIRST)
  557. pMenu->AppendMenu(MF_SEPARATOR);
  558. pMenu->AppendMenu(MF_STRING, nID++, strDesc);
  559. CMainFrame::m_arrEncodingPage.Add(strPage);
  560. bPrevSeparator = FALSE;
  561. } else
  562. bPrevSeparator = TRUE;
  563. }
  564. strLine.Format(_T("line%i"), ++nIndex);
  565. }
  566. }
  567. void CMainFrame::OnViewEncodingAuto() 
  568. {
  569. DWORD           sz;
  570. HKEY            hKey;
  571. DWORD           dwSize = sizeof(DWORD);
  572. if(RegOpenKey(HKEY_CURRENT_USER, _T("Software\Microsoft\Internet Explorer\International"), &hKey) != ERROR_SUCCESS)
  573. {
  574. TRACE0("Global settings not foundn");
  575. return ;
  576. }
  577. if(RegQueryValueEx(hKey, _T("AutoDetect"), NULL, NULL, (LPBYTE)&sz, &dwSize) == ERROR_SUCCESS)
  578. {
  579. //set new offline value
  580. m_bAutoSelect = sz = !(BOOL)sz;
  581. } else
  582. m_bAutoSelect = sz = !m_bAutoSelect;
  583. RegSetValueEx(hKey, _T("AutoDetect"), NULL, REG_DWORD, (LPBYTE)(&sz), dwSize);
  584. CChildFrame* wndBrowserFrame = (CChildFrame*)MDIGetActive();
  585. if (wndBrowserFrame && wndBrowserFrame->GetActiveView())
  586. {
  587. ((CStylerView*)(wndBrowserFrame->GetActiveView()))->Refresh2(1);
  588. RegCloseKey(hKey);
  589. }
  590. void CMainFrame::BuildEncodingMenu()
  591. {
  592. /*CXTPControl* pControl = GetCommandBars()->FindControl(xtpControlButton, ID_VIEW_ENCODING, FALSE, TRUE);
  593. ASSERT(pControl);
  594. if (pControl)
  595. {
  596. CMenu menuPopup;
  597. menuPopup.CreatePopupMenu();
  598. LoadEncoding(&menuPopup);
  599. if (menuPopup.GetMenuItemCount())
  600. {
  601. menuPopup.InsertMenu(0, MF_BYPOSITION | MF_STRING,  ID_VIEW_ENCODING_AUTOSELECT, "Auto Select");
  602. menuPopup.InsertMenu(1, MF_BYPOSITION | MF_SEPARATOR);
  603. CXTPControlPopup* pPopup = (CXTPControlPopup*)pControl->GetControls()->SetControlType(pControl, xtpControlPopup);
  604. pPopup->SetCommandBar(&menuPopup);
  605. pPopup->SetID(0);
  606. }
  607. }*/
  608. m_bAutoSelect = FALSE;
  609. HKEY hKey;
  610. if(RegOpenKey(HKEY_CURRENT_USER, _T("Software\Microsoft\Internet Explorer\International"), &hKey) == ERROR_SUCCESS)
  611. {
  612. DWORD dwSize = sizeof(m_bAutoSelect);
  613. RegQueryValueEx(hKey, _T("AutoDetect"), NULL, NULL, (LPBYTE)&m_bAutoSelect, &dwSize);
  614. RegCloseKey(hKey);
  615. }
  616. }
  617. void CMainFrame::OnUpdateViewEncodingAuto(CCmdUI *pCmdUI)
  618. {
  619. pCmdUI->SetCheck(m_bAutoSelect);
  620. }
  621. void CMainFrame::OnToolsPopupfilter()
  622. {
  623. CPopupFilter fd;
  624. fd.DoModal();
  625. }
  626. void CMainFrame::OnClose() 
  627. {
  628. if (m_bConfirmExit && MDIGetActive())
  629. {
  630. if (AfxMessageBox(IDS_CONFIRM_CLOSEALL,  MB_YESNO | MB_ICONQUESTION ) != IDYES)
  631. return;
  632. }
  633. CComboBoxURL* pComboURL = DYNAMIC_DOWNCAST(CComboBoxURL, GetAddressCombo());
  634. if (pComboURL) pComboURL->SaveTypedURL();
  635. if (m_nStartup == STARTUP_LASTVISITED)
  636. {
  637. CString strPopups;
  638. int nIndex = AFX_IDM_FIRST_MDICHILD;
  639. CWnd* pMDIClient = CWnd::FromHandle(m_hWndMDIClient);
  640. CChildFrame* pWnd = (CChildFrame*) pMDIClient->GetDlgItem(nIndex);
  641. while (pWnd)
  642. {
  643. CStylerView* pView = (CStylerView*)pWnd->GetActiveView();
  644. ASSERT(pView);
  645. if (pView) strPopups += pView->GetDocument()->GetCurrentUrl() + _T(";");
  646. pWnd = (CChildFrame*) pMDIClient->GetDlgItem(++nIndex);
  647. }
  648. AfxGetApp()->WriteProfileString(_T("MainFrame"), _T("LastVisited"), strPopups);
  649. }
  650. CWindowPlacement(this, _T("Main Frame")).SaveWindowPos();
  651. SaveCommandBars(_T("CommandBarsv2"));
  652. CMDIFrameWnd::OnClose();
  653. }
  654. void SetDefault(LPCTSTR lpszKey, BOOL = TRUE)
  655. {
  656. HKEY            hKey, hSubKey, hSubKey2;
  657. if(RegOpenKey(HKEY_CLASSES_ROOT, lpszKey, &hKey) == ERROR_SUCCESS)
  658. {
  659. DWORD dwRes;
  660. TCHAR lpszModule[_MAX_PATH];
  661. HINSTANCE hInstance = AfxGetInstanceHandle();
  662. RegSetValueEx(hKey, _T(""), NULL, REG_SZ, (LPBYTE)(_T("Styler")), 7 * sizeof(TCHAR));
  663. //open
  664. RegCreateKeyEx(hKey, _T("open"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,  &hSubKey, &dwRes);
  665. RegCreateKeyEx(hSubKey, _T("command"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,  &hSubKey2, &dwRes);
  666. if (GetModuleFileName(hInstance, lpszModule + 1, _MAX_PATH))
  667. {
  668. *lpszModule = _T('"');
  669. #if (_MSC_VER > 1310) // VS2005
  670. _tcscat_s(lpszModule, _MAX_PATH, _T("" "%1""));
  671. #else
  672. _tcscat(lpszModule, _T("" "%1""));
  673. #endif
  674. RegSetValueEx(hSubKey2, _T(""), NULL, REG_SZ, (LPBYTE)(lpszModule), ((int)_tcsclen(lpszModule) + 1) * sizeof(TCHAR));
  675. }
  676. RegCloseKey(hSubKey);
  677. RegCloseKey(hSubKey2);
  678. //myie
  679. RegCreateKeyEx(hKey, _T("Styler"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,  &hSubKey, &dwRes);
  680. RegCloseKey(hKey);
  681. RegCreateKeyEx(hSubKey, _T("command"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,  &hKey, &dwRes);
  682. if (GetModuleFileName(hInstance, lpszModule+1, _MAX_PATH))
  683. {
  684. *lpszModule = _T('"');
  685. #if (_MSC_VER > 1310) // VS2005
  686. _tcscat_s(lpszModule, _MAX_PATH, _T("" "%1""));
  687. #else
  688. _tcscat(lpszModule, _T("" "%1""));
  689. #endif
  690. RegSetValueEx(hKey, _T(""), NULL, REG_SZ, (LPBYTE)(lpszModule), ((int)_tcsclen(lpszModule) + 1) * sizeof(TCHAR));
  691. }
  692. RegCloseKey(hSubKey);
  693. RegCloseKey(hKey);
  694. }
  695. }
  696. void CMainFrame::OnSetDefault()
  697. {
  698. SetDefault(_T("htmlfile\shell"));
  699. SetDefault(_T("InternetShortcut\shell"));
  700. SetDefault(_T("mhtmlfile\shell"));
  701. SetDefault( _T("http\shell"));
  702. SetDefault( _T("https\shell"));
  703. SetDefault( _T("file\shell"));
  704. SetDefault( _T("ftp\shell"));
  705. }
  706. void CMainFrame::Properties(int nPage)
  707. {
  708. COptionsDialog od;
  709. CPageGeneral pageGeneral;
  710. int nDocking = pageGeneral.m_nDocking = m_MTIClientWnd.GetPaintManager()->GetPosition()==xtpTabPositionBottom? 1 : 0;
  711. pageGeneral.m_bConfirmExit = m_bConfirmExit;
  712. pageGeneral.m_bConfirmCloseAll = m_bConfirmCloseAll;
  713. pageGeneral.m_bOneInstance = m_bOneInstance;
  714. pageGeneral.m_nStartup = m_nStartup;
  715. pageGeneral.m_bRestoreWindowPos = m_bRestoreWindowPos;
  716. od.AddPage(&pageGeneral);
  717. CPageKeyboard pageKeyboard;
  718. od.AddPage(&pageKeyboard);
  719. CPageMouse pageMouse;
  720. od.AddPage(&pageMouse);
  721. CPageSearch pageSearch;
  722. od.AddPage(&pageSearch);
  723. od.SetActivePage(nPage);
  724. if (od.DoModal() == IDOK)
  725. {
  726. if (pageGeneral.m_nDocking != nDocking)
  727. OnToggleDock();
  728. m_bConfirmExit = pageGeneral.m_bConfirmExit;
  729. m_bConfirmCloseAll = pageGeneral.m_bConfirmCloseAll;
  730. m_bOneInstance = pageGeneral.m_bOneInstance;
  731. m_nStartup = pageGeneral.m_nStartup;
  732. m_bRestoreWindowPos = pageGeneral.m_bRestoreWindowPos;
  733. Save();
  734. }
  735. }
  736. void CMainFrame::OnSearchList()
  737. {
  738. Properties(3);
  739. }
  740. void CMainFrame::OnStylerOptions()
  741. {
  742. Properties(0);
  743. }
  744. void CMainFrame::Load()
  745. {
  746. m_bConfirmExit = AfxGetApp()->GetProfileInt(_T("MainFrame"), _T("ConfirmExit"), m_bConfirmExit);
  747. m_bConfirmCloseAll = AfxGetApp()->GetProfileInt(_T("MainFrame"), _T("ConfirmCloseAll"), m_bConfirmCloseAll);
  748. m_bOneInstance = AfxGetApp()->GetProfileInt(_T("MainFrame"), _T("OneInstance"), m_bOneInstance);
  749. m_nStartup = AfxGetApp()->GetProfileInt(_T("MainFrame"), _T("Startup"), m_nStartup);
  750. m_bRestoreWindowPos = AfxGetApp()->GetProfileInt(_T("MainFrame"), _T("RestoreWindowPos"), m_bRestoreWindowPos);
  751. m_themeCurrent = (XTPPaintTheme)AfxGetApp()->GetProfileInt(_T("MainFrame"), _T("Theme"), m_themeCurrent);
  752. }
  753. void CMainFrame::Save()
  754. {
  755. AfxGetApp()->WriteProfileInt(_T("MainFrame"), _T("ConfirmExit"), m_bConfirmExit);
  756. AfxGetApp()->WriteProfileInt(_T("MainFrame"), _T("ConfirmCloseAll"), m_bConfirmCloseAll);
  757. AfxGetApp()->WriteProfileInt(_T("MainFrame"), _T("OneInstance"), m_bOneInstance);
  758. AfxGetApp()->WriteProfileInt(_T("MainFrame"), _T("Startup"), m_nStartup);
  759. AfxGetApp()->WriteProfileInt(_T("MainFrame"), _T("RestoreWindowPos"), m_bRestoreWindowPos);
  760. AfxGetApp()->WriteProfileInt(_T("MainFrame"), _T("Theme"), m_themeCurrent);
  761. }
  762. LRESULT CMainFrame::OnShellOpen(WPARAM, LPARAM)
  763. {
  764. try
  765. {
  766. HANDLE hMapping = CreateFileMapping( INVALID_HANDLE_VALUE, NULL,
  767. PAGE_READWRITE, 0, 2560, _T("STYLERSHARE"));
  768. if (hMapping == NULL)
  769. {
  770. TRACE(_T("Fail to create share memory!"));
  771. return FALSE;
  772. }
  773. LPTSTR lpData = (LPTSTR) MapViewOfFile(hMapping,FILE_MAP_ALL_ACCESS,0,0,0);
  774. if (lpData == NULL)
  775. {
  776. TRACE(_T("MapViewOfFile Fail"));
  777. CloseHandle(hMapping);
  778. return FALSE;
  779. }
  780. CString strURL = lpData;
  781. UnmapViewOfFile(lpData);
  782. CloseHandle(hMapping);
  783. TCHAR buf[INTERNET_MAX_PATH_LENGTH];
  784. if(strURL.Right(4).CompareNoCase(_T(".url")) == 0)
  785. {
  786. ::GetPrivateProfileString(_T("InternetShortcut"), _T("URL"),
  787. _T(""), buf, INTERNET_MAX_PATH_LENGTH, strURL);
  788. strURL =  buf;
  789. }
  790. OpenWindow(strURL);
  791. }
  792. catch(...)
  793. {
  794. }
  795. return TRUE;
  796. }
  797. void CMainFrame::OpenLastVisited()
  798. {
  799. CString strBuffer = AfxGetApp()->GetProfileString(_T("MainFrame"), _T("LastVisited"));
  800. if (!strBuffer.IsEmpty())
  801. {
  802. LPTSTR pBuffer = strBuffer.GetBuffer(0);
  803. TCHAR* lpszContext = 0;
  804. TCHAR* token = STRTOK_S(pBuffer, _T(";"), &lpszContext);
  805. while (token)
  806. {
  807. OpenWindow(token);
  808. token = STRTOK_S( NULL, _T(";"), &lpszContext);
  809. }
  810. }
  811. }
  812. void CMainFrame::OnUpdateIndicator(CCmdUI *pCmdUI)
  813. {
  814. ASSERT_KINDOF(CXTPStatusBar, pCmdUI->m_pOther);
  815. ((CIndicatorStatusBar*) pCmdUI->m_pOther)->SetProgress(0);
  816. }
  817. void CMainFrame::OnDestroy()
  818. {
  819. CXTPDockingPaneLayout layout(&m_paneManager);
  820. m_paneManager.GetLayout(&layout);
  821. layout.Save(_T("Standard"));
  822. m_MTIClientWnd.Detach();
  823. CMDIFrameWnd::OnDestroy();
  824. }
  825. CXTPControlComboBox* GetAddressCombo()
  826. {
  827.  return (CXTPControlComboBox*) GetMainFrame()->GetCommandBars()->FindControl(xtpControlComboBox, ID_GOTO_URL, FALSE, FALSE);
  828. }
  829. void CMainFrame::SetDockingPaneIcon(UINT nIDPane, UINT nIDIcon)
  830. {
  831. CXTPImageManagerIcon* pIcon = XTPImageManager()->GetImage(nIDIcon);
  832. m_paneManager.SetIcon(nIDPane, pIcon->GetIcon());
  833. }
  834. void CMainFrame::RefreshIcons()
  835. {
  836. XTPImageManager()->SetIcons(IDR_MAINFRAME, IDR_MAINFRAME);
  837. XTPImageManager()->SetIcons(IDR_SEARCH, IDR_SEARCH);
  838. XTPImageManager()->SetIcons(IDR_MENUBAR, IDR_MENUBAR);
  839. XTPPaintManager()->GetIconsInfo()->bUseDisabledIcons = TRUE;
  840. SetDockingPaneIcon(IDS_TITLE_SOURCE, ID_EXPLORER_SOURCE);
  841. SetDockingPaneIcon(IDS_TITLE_SHELL, ID_EXPLORER_FOLDER);
  842. SetDockingPaneIcon(IDS_TITLE_HIS, ID_EXPLORER_HISTORY);
  843. SetDockingPaneIcon(IDS_TITLE_NOTEPAD, ID_EXPLORER_NOTEPAD);
  844. SetDockingPaneIcon(IDS_TITLE_SEARCH, ID_EXPLORER_SEARCH);
  845. }
  846. void CMainFrame::SetTheme(XTPPaintTheme theme)
  847. {
  848. m_themeCurrent = theme;
  849. m_paneManager.SetTheme(
  850. m_themeCurrent == xtpThemeOffice2000 ? xtpPaneThemeDefault: 
  851. m_themeCurrent == xtpThemeOfficeXP ? xtpPaneThemeOffice: 
  852. m_themeCurrent == xtpThemeOffice2003 ? xtpPaneThemeOffice2003: 
  853. m_themeCurrent == xtpThemeOffice2007 ? xtpPaneThemeOffice2007: 
  854. m_themeCurrent == xtpThemeRibbon ? xtpPaneThemeOffice2007: 
  855. m_themeCurrent == xtpThemeWhidbey ? xtpPaneThemeVisualStudio2005: 
  856. xtpPaneThemeNativeWinXP);
  857. CXTPPaintManager::SetTheme(theme);
  858. EnableOffice2007Frame(theme == xtpThemeRibbon || theme == xtpThemeOffice2007 ? GetCommandBars() : 0);
  859. if (theme == xtpThemeOffice2000 || theme == xtpThemeNativeWinXP)
  860. {
  861. ((CXTPDefaultTheme*)XTPPaintManager())->m_bSelectImageInPopupBar = TRUE;
  862. ((CXTPDefaultTheme*)XTPPaintManager())->m_bThickCheckMark = TRUE;
  863. XTPPaintManager()->GetIconsInfo()->bUseFadedIcons = FALSE;
  864. }
  865. if (m_themeCurrent == xtpThemeRibbon)
  866. {
  867. m_MTIClientWnd.UpdateContents();
  868. m_MTIClientWnd.GetPaintManager()->SetAppearance(xtpTabAppearancePropertyPage2007);
  869. m_MTIClientWnd.GetPaintManager()->m_rcButtonMargin.SetRect(2, 2, 2, 2);
  870. }
  871. XTPPaintManager()->GetIconsInfo()->bUseDisabledIcons = TRUE;
  872. RecalcLayout(FALSE);
  873. GetCommandBars()->RedrawCommandBars();
  874. RedrawWindow();
  875. }
  876. void CMainFrame::OnTheme(UINT nTheme)
  877. {
  878. SetTheme((XTPPaintTheme)(nTheme - ID_THEME_DEFAULT));
  879. }
  880. void CMainFrame::OnUpdateTheme(CCmdUI *pCmdUI)
  881. {
  882. pCmdUI->SetCheck(int(pCmdUI->m_nID - ID_THEME_DEFAULT) == m_themeCurrent? TRUE: FALSE);
  883. }
  884. void CMainFrame::OnSwitchTheme()
  885. {
  886. if (m_themeCurrent == xtpThemeRibbon) 
  887. SetTheme(xtpThemeOffice2000); 
  888. else
  889. SetTheme((XTPPaintTheme)(m_themeCurrent + 1));
  890. }
  891. LRESULT CMainFrame::OnTabbarMouseMsg(WPARAM wParam,LPARAM lParam)
  892. {
  893. CPoint point = CPoint((DWORD)lParam);
  894. CXTPTabManagerItem* pItem =  m_MTIClientWnd.HitTest(point);
  895. if (pItem)
  896. {
  897. CWnd* pFrame = CWnd::FromHandle(pItem->GetHandle());
  898. if (GetActiveFrame() != pFrame)
  899. {
  900. MDIActivate(pFrame);
  901. m_MTIClientWnd.Refresh();
  902. }
  903. int nCommand = CMouseManager::FindMouseCommand(MOUSE_AREA_TAB, (DWORD)wParam);
  904. if (nCommand != -1)
  905. {
  906. PostMessage(WM_COMMAND, nCommand);
  907. return TRUE;
  908. }
  909. if (wParam == WM_RBUTTONDOWN)
  910. {
  911. CMenu menuPopup;
  912. menuPopup.LoadMenu(IDR_WORKSPACE_POPUP);
  913. m_MTIClientWnd.WorkspaceToScreen(&point);
  914. CXTPCommandBars::TrackPopupMenu(menuPopup.GetSubMenu(0), TPM_RIGHTBUTTON, point.x, point.y, this);
  915. m_MTIClientWnd.Refresh();
  916. return TRUE;
  917. }
  918. return FALSE;
  919. }
  920. int nCommand = CMouseManager::FindMouseCommand(MOUSE_AREA_TABBAR, (DWORD)wParam);
  921. if (nCommand != -1)
  922. {
  923. PostMessage(WM_COMMAND, nCommand);
  924. return TRUE;
  925. }
  926. if (wParam == WM_RBUTTONDOWN)
  927. {
  928. CMenu menuPopup;
  929. menuPopup.CreatePopupMenu();
  930. menuPopup.AppendMenu(MF_STRING, ID_WINDOW_CLOSE_ALL, _T("&Close All"));
  931. menuPopup.AppendMenu(MF_STRING, ID_TOGGLE_DOCK, _T("&Toggle Docking"));
  932. m_MTIClientWnd.WorkspaceToScreen(&point);
  933. CXTPCommandBars::TrackPopupMenu(&menuPopup, TPM_RIGHTBUTTON, point.x, point.y, AfxGetMainWnd());
  934. m_MTIClientWnd.Refresh();
  935. return TRUE;
  936. }
  937. return FALSE;
  938. }
  939. LRESULT CMainFrame::OnDockingPaneNotify(WPARAM wParam, LPARAM lParam)
  940. {
  941. if (wParam != XTP_DPN_SHOWWINDOW)
  942. {
  943. return FALSE;
  944. }
  945. CXTPDockingPane* pPane = (CXTPDockingPane*)lParam;
  946. if (!pPane->IsValid())
  947. {
  948. //int nIndex = pPane->GetID() - IDS_TITLE_SEARCH;
  949. switch(pPane->GetID()) 
  950. {
  951. case IDS_TITLE_HIS:
  952. if (!m_bars.wndHistory.GetWindow()->m_hWnd)
  953. {
  954. m_bars.wndHistory.Create(this);
  955. m_bars.wndHistory.Initialize();
  956. }
  957. pPane->Attach(m_bars.wndHistory.GetWindow());
  958. break;
  959. case IDS_TITLE_SHELL:
  960. if (!m_bars.wndShell.m_hWnd)
  961. {
  962. m_bars.wndShell.Create(WS_VISIBLE|WS_CHILD, CRect(0,0,0,0), this, 100);
  963. m_bars.wndShell.Init();
  964. }
  965. pPane->Attach(&m_bars.wndShell);
  966. break;
  967. case IDS_TITLE_NOTEPAD:
  968. if (!m_bars.wndNotepad.m_hWnd)
  969. {
  970. m_bars.wndNotepad.Create(this);
  971. }
  972. pPane->Attach(&m_bars.wndNotepad);
  973. break;
  974. case IDS_TITLE_SOURCE:
  975. if (!m_bars.wndSource.m_hWnd)
  976. {
  977. m_bars.wndSource.Create(this);
  978. }
  979. {
  980. CChildFrame* wndBrowserFrame = (CChildFrame*)MDIGetActive();
  981. if (wndBrowserFrame && wndBrowserFrame->GetActiveView())
  982. {
  983. m_bars.wndSource.Refresh((CStylerView*)wndBrowserFrame->GetActiveView(), TRUE);
  984. }
  985. }
  986. pPane->Attach(&m_bars.wndSource);
  987. break;
  988. case IDS_TITLE_SEARCH:
  989. if (!m_bars.wndSearch.m_hWnd)
  990. {
  991. m_bars.wndSearch.Create(_T("STATIC"), _T(""), WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, CRect(0, 0, 0, 0), this, 0);
  992. m_bars.wndSearch.OnViewSearch();
  993. }
  994. pPane->Attach(&m_bars.wndSearch);
  995. break;
  996. }
  997. }
  998. return TRUE;
  999. }
  1000. void CMainFrame::OnExploreSearch()
  1001. {
  1002. m_paneManager.ShowPane(IDS_TITLE_SEARCH);
  1003. }
  1004. void CMainFrame::OnExploreHistory()
  1005. {
  1006. m_paneManager.ShowPane(IDS_TITLE_HIS);
  1007. }
  1008. void CMainFrame::OnExploreFolder()
  1009. {
  1010. m_paneManager.ShowPane(IDS_TITLE_SHELL);
  1011. }
  1012. void CMainFrame::OnExploreSource()
  1013. {
  1014. m_paneManager.ShowPane(IDS_TITLE_SOURCE);
  1015. }
  1016. void CMainFrame::OnExploreNotepad()
  1017. {
  1018. m_paneManager.ShowPane(IDS_TITLE_NOTEPAD);
  1019. }
  1020. void CMainFrame::OnCustomize()
  1021. {
  1022. CXTPCustomizeSheet cs(GetCommandBars());
  1023. CXTPCustomizeOptionsPage pageOptions(&cs);
  1024. cs.AddPage(&pageOptions);
  1025. CXTPCustomizeCommandsPage* pCommands = cs.GetCommandsPage();
  1026. pCommands->AddCategories(IDR_CUSTOMIZE);
  1027. pCommands->InsertAllCommandsCategory();
  1028. pCommands->InsertBuiltInMenus(IDR_MAINFRAME);
  1029. pCommands->InsertNewMenuCategory();
  1030. cs.DoModal();
  1031. }
  1032. LRESULT CMainFrame::OnControlRButtonUp(WPARAM, LPARAM lParam)
  1033. {
  1034. CXTPControl* pControl = (CXTPControl*)lParam;
  1035. if (pControl->GetID() == ID_FAVORITE_LINK)
  1036. {
  1037. CControlFavoriteLink* pLink = DYNAMIC_DOWNCAST(CControlFavoriteLink, pControl);
  1038. if (!pLink)
  1039. return FALSE;
  1040. CMenu menu;
  1041. menu.LoadMenu(IDR_MENU_FAVORITE_LINK);
  1042. CPoint pt;
  1043. GetCursorPos(&pt);
  1044. UINT nReturn = CXTPCommandBars::TrackPopupMenu(menu.GetSubMenu(0), TPM_NONOTIFY|TPM_RECURSE|TPM_RETURNCMD, pt.x, pt.y, this);
  1045. switch (nReturn)
  1046. {
  1047. case ID_LINK_OPEN:
  1048. XTPMouseManager()->SendTrackLost();
  1049. pControl->OnExecute();
  1050. break;
  1051. case ID_LINK_PROPERTIES:
  1052. XTPMouseManager()->SendTrackLost();
  1053. ShellExecute(m_hWnd, _T("properties"), pLink->m_strFileName, NULL, NULL, SW_SHOWNORMAL);
  1054. break;
  1055. }
  1056. return TRUE;
  1057. }
  1058. return FALSE;
  1059. }
  1060. int CMainFrame::OnCreateControl(LPCREATECONTROLSTRUCT lpCreateControl)
  1061. {
  1062. class CXTPControlFriendly: public CXTPControl
  1063. {
  1064. friend class CMainFrame;
  1065. };
  1066. if (lpCreateControl->bToolBar)
  1067. {
  1068. CXTPToolBar* pToolBar = DYNAMIC_DOWNCAST(CXTPToolBar, lpCreateControl->pCommandBar);
  1069. if (!pToolBar)
  1070. return FALSE;
  1071. if (lpCreateControl->nID == ID_TOOLS_SWITCHTHEME && pToolBar->GetBarID() == IDR_SWITCH)
  1072. {
  1073. lpCreateControl->buttonStyle = xtpButtonCaption;
  1074. lpCreateControl->controlType = xtpControlSplitButtonPopup;
  1075. return TRUE;
  1076. }
  1077. if (pToolBar->GetBarID() == IDR_MAINFRAME &&
  1078. (
  1079. lpCreateControl->nID == ID_EDIT_CUT ||
  1080. lpCreateControl->nID == ID_EDIT_COPY ||
  1081. lpCreateControl->nID == ID_EDIT_PASTE ||
  1082. lpCreateControl->nID == ID_EXPLORER_SOURCE ||
  1083. lpCreateControl->nID == ID_EXPLORER_FOLDER ||
  1084. lpCreateControl->nID == ID_EXPLORER_HISTORY ||
  1085. lpCreateControl->nID == ID_EXPLORER_NOTEPAD))
  1086. {
  1087. CXTPControlButton* pButton = (CXTPControlButton*)CXTPControlButton::CreateObject();
  1088. pButton->SetHideFlags(xtpHideCustomize);
  1089. lpCreateControl->pControl = pButton;
  1090. return TRUE;
  1091. }
  1092. if (lpCreateControl->nID == ID_GOTO_URL && pToolBar->GetBarID() == IDR_MAINFRAME)
  1093. {
  1094. CComboBoxURL* pComboAddress = new CComboBoxURL(GetCommandBars());
  1095. pComboAddress->UpdateComboBox();
  1096. pComboAddress->SetWidth(350);
  1097. pComboAddress->SetDropDownListStyle();
  1098. pComboAddress->EnableShellAutoComplete();
  1099. lpCreateControl->pControl = pComboAddress;
  1100. return TRUE;
  1101. }
  1102. if (lpCreateControl->nID == ID_GOTO_SEARCH && pToolBar->GetBarID() == IDR_SEARCH)
  1103. {
  1104. CComboBoxSearch* pComboSearch = new CComboBoxSearch(GetCommandBars());
  1105. pComboSearch->SetStyle(xtpComboLabel);
  1106. pComboSearch->SetDropDownListStyle();
  1107. pComboSearch->SetWidth(150);
  1108. pComboSearch->SetFlags(xtpFlagManualUpdate);
  1109. lpCreateControl->pControl = pComboSearch;
  1110. return TRUE;
  1111. }
  1112. if (lpCreateControl->nID == ID_LINKS && pToolBar->GetBarID() == IDR_MAINFRAME)
  1113. {
  1114. CXTPControlPopup* pLinks = CXTPControlPopup::CreateControlPopup(xtpControlButtonPopup);
  1115. pLinks->SetFlags(xtpFlagManualUpdate);
  1116. CXTPPopupBar* pPopup = CXTPPopupBar::CreatePopupBar(GetCommandBars());
  1117. CString strFavoriteDir;
  1118. CInetTools::GetFavoriteFolder(strFavoriteDir);
  1119. pPopup->GetControls()->Add(new CControlFavoriteFolder(strFavoriteDir), ID_FAVORITES_EX);
  1120. pLinks->SetCommandBar(pPopup);
  1121. pPopup->InternalRelease();
  1122. lpCreateControl->pControl = pLinks;
  1123.  
  1124. return TRUE;
  1125. }
  1126. else
  1127. {
  1128. if (lpCreateControl->nID == ID_FAVORITES_EX)
  1129. {
  1130. CString strFavoriteDir;
  1131. CInetTools::GetFavoriteFolder(strFavoriteDir);
  1132. lpCreateControl->pControl = new CControlFavoriteFolder(strFavoriteDir);
  1133. return TRUE;
  1134.  
  1135. }
  1136. }
  1137. if (lpCreateControl->nID == ID_VIEW_ENCODING)
  1138. {
  1139. CXTPControlPopup* pControl = CXTPControlPopup::CreateControlPopup(lpCreateControl->bToolBar? xtpControlButtonPopup: xtpControlPopup);
  1140. CMenu menuPopup;
  1141. menuPopup.CreatePopupMenu();
  1142. LoadEncoding(&menuPopup);
  1143. if (menuPopup.GetMenuItemCount())
  1144. {
  1145. menuPopup.InsertMenu(0, MF_BYPOSITION | MF_STRING,  ID_VIEW_ENCODING_AUTOSELECT, _T("Auto Select"));
  1146. menuPopup.InsertMenu(1, MF_BYPOSITION | MF_SEPARATOR);
  1147. pControl->SetCommandBar(&menuPopup);
  1148. pControl->SetFlags(xtpFlagManualUpdate);
  1149. } else
  1150. {
  1151. CXTPPopupBar* pPopupBar = CXTPPopupBar::CreatePopupBar(GetCommandBars());
  1152. pControl->SetCommandBar(pPopupBar);
  1153. pPopupBar->InternalRelease();
  1154. pControl->SetVisible(FALSE);
  1155. }
  1156. if (lpCreateControl->bToolBar)
  1157. pControl->SetHideFlags(xtpHideCustomize);
  1158. lpCreateControl->pControl = pControl;
  1159. return TRUE;
  1160. }
  1161. return FALSE;
  1162. }
  1163. CWindowPlacement::CWindowPlacement(CWnd* pOwner, CString strEntry)
  1164. {
  1165. ASSERT(!strEntry.IsEmpty() && pOwner);
  1166. m_pOwner = pOwner;
  1167. m_strEntry = strEntry;
  1168. }
  1169. void CWindowPlacement::ShowWindow(int nCmdShow, BOOL bRestore)
  1170. {
  1171. if (bRestore )
  1172.     {
  1173.         WINDOWPLACEMENT* lpwndpl;
  1174.         UINT nBytes;
  1175.         if ( AfxGetApp()->GetProfileBinary( m_strEntry,
  1176.                  _T("WndPlacement"), ( LPBYTE* )&lpwndpl, &nBytes ) )
  1177.         {
  1178.             // Only restore if window intersects the screen
  1179. if ( CRect().IntersectRect(&lpwndpl->rcNormalPosition, CXTPWindowRect(GetDesktopWindow()) ) )
  1180.             {
  1181.                 if (lpwndpl->showCmd == SW_MAXIMIZE) 
  1182. nCmdShow = SW_MAXIMIZE;
  1183.                 m_pOwner->SetWindowPlacement( lpwndpl );
  1184.             }
  1185.             delete lpwndpl;
  1186.         }
  1187.     }
  1188. m_pOwner->ShowWindow(nCmdShow);
  1189. }
  1190. void CWindowPlacement::SaveWindowPos()
  1191. {
  1192. WINDOWPLACEMENT wndpl = { sizeof(WINDOWPLACEMENT) };
  1193. if ( m_pOwner->GetWindowPlacement( &wndpl ) )
  1194. {
  1195. AfxGetApp()->WriteProfileBinary( m_strEntry,
  1196. _T("WndPlacement"), ( LPBYTE )&wndpl, wndpl.length );
  1197. }
  1198. }