1
0

browserUiCommon.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. #include "main.h"
  2. #include "./browserUiCommon.h"
  3. #include "./browserUiInternal.h"
  4. #include "./toolbar.h"
  5. #include "./statusbar.h"
  6. #include "./curtain.h"
  7. #include "./browserHost.h"
  8. #include "./obj_ombrowser.h"
  9. #include "./ifc_omservice.h"
  10. #include "./ifc_omservicecommand.h"
  11. #include "./ifc_omtoolbarconfig.h"
  12. #include "./ifc_omstatusbarconfig.h"
  13. #include "./resource.h"
  14. #define IDC_OPERATIONWIDGET 0x1010
  15. static HACCEL commonTable = NULL;
  16. static HACCEL popupTable = NULL;
  17. static BOOL regiterUnload = TRUE;
  18. static void CALLBACK BrowserControl_OnPluginUnload()
  19. {
  20. if (NULL != commonTable)
  21. {
  22. DestroyAcceleratorTable(commonTable);
  23. commonTable = NULL;
  24. }
  25. if (NULL != popupTable)
  26. {
  27. DestroyAcceleratorTable(popupTable);
  28. popupTable = NULL;
  29. }
  30. }
  31. static HACCEL BrowserControl_LoadCommonAccel()
  32. {
  33. if (NULL != commonTable)
  34. return commonTable;
  35. commonTable = Plugin_LoadAccelerators(MAKEINTRESOURCE(IDR_BROWSERACCEL));
  36. if (FALSE != regiterUnload && NULL != commonTable)
  37. {
  38. Plugin_RegisterUnloadCallback(BrowserControl_OnPluginUnload);
  39. regiterUnload = FALSE;
  40. }
  41. return commonTable;
  42. }
  43. static HACCEL BrowserControl_LoadPoppupAccel()
  44. {
  45. if (NULL != popupTable)
  46. return popupTable;
  47. UINT cCommon, cPopup, cTotal = 0;
  48. HACCEL hCommon = Plugin_LoadAccelerators(MAKEINTRESOURCE(IDR_BROWSERACCEL));
  49. cCommon = (NULL != hCommon) ? CopyAcceleratorTable(hCommon, NULL, 0) : 0;
  50. HACCEL hPopup = Plugin_LoadAccelerators(MAKEINTRESOURCE(IDR_BROWSERPOPUPACCEL));
  51. cPopup = (NULL != hPopup) ? CopyAcceleratorTable(hPopup, NULL, 0) : 0;
  52. cTotal += (cCommon + cPopup);
  53. if (0 != cTotal)
  54. {
  55. ACCEL *pAccel = (ACCEL*)calloc(cTotal, sizeof(ACCEL));
  56. if (NULL != pAccel)
  57. {
  58. UINT copied = 0;
  59. if (NULL != hCommon)
  60. copied += CopyAcceleratorTable(hCommon, pAccel + copied, cTotal - copied);
  61. if (NULL != hPopup)
  62. copied += CopyAcceleratorTable(hPopup, pAccel + copied, cTotal - copied);
  63. if (0 != copied)
  64. popupTable = CreateAcceleratorTable(pAccel, copied);
  65. free(pAccel);
  66. }
  67. }
  68. if (NULL != hCommon)
  69. DestroyAcceleratorTable(hCommon);
  70. if (NULL != hPopup)
  71. DestroyAcceleratorTable(hPopup);
  72. if (FALSE != regiterUnload && NULL != popupTable)
  73. {
  74. Plugin_RegisterUnloadCallback(BrowserControl_OnPluginUnload);
  75. regiterUnload = FALSE;
  76. }
  77. return popupTable;
  78. }
  79. HACCEL BrowserControl_GetAccelTable(UINT tableType)
  80. {
  81. switch(tableType)
  82. {
  83. case ACCELTABLE_VIEW:
  84. return BrowserControl_LoadCommonAccel();
  85. case ACCELTABLE_POPUP:
  86. return BrowserControl_LoadPoppupAccel();
  87. }
  88. return NULL;
  89. }
  90. static void BrowserControl_ShowHistoryPopup(HWND hControl)
  91. {
  92. HWND hBrowser = BrowserControl_GetHost(hControl);
  93. if (NULL == hBrowser) return;
  94. UINT flags = TPM_LEFTALIGN;
  95. POINT pt = {0, 0};
  96. BOOL fUseHost = TRUE;;
  97. HWND hToolbar = BrowserControl_GetToolbar(hControl);
  98. DWORD toolbarStyle = (NULL != hToolbar) ? GetWindowStyle(hToolbar) : 0;
  99. if (NULL != hToolbar && 0 != (WS_VISIBLE & toolbarStyle))
  100. {
  101. fUseHost = FALSE;
  102. RECT toolbarRect;
  103. GetWindowRect(hToolbar, &toolbarRect);
  104. pt.x = toolbarRect.left + 2;
  105. if (0 != (TBS_BOTTOMDOCK & toolbarStyle))
  106. {
  107. pt.y = toolbarRect.top + 1;
  108. flags |= TPM_VERNEGANIMATION | TPM_BOTTOMALIGN;
  109. }
  110. else
  111. {
  112. pt.y = toolbarRect.bottom - 1;
  113. flags |= TPM_VERPOSANIMATION | TPM_TOPALIGN;
  114. }
  115. }
  116. if (FALSE != fUseHost)
  117. {
  118. RECT windowRect;
  119. GetClientRect(hControl, &windowRect);
  120. pt.x = windowRect.left;
  121. pt.y = windowRect.top;
  122. MapWindowPoints(hControl, HWND_DESKTOP, &pt, 1);
  123. flags |= TPM_VERPOSANIMATION | TPM_TOPALIGN;
  124. }
  125. if (NULL != hToolbar && 0 != (TBS_AUTOHIDE & toolbarStyle))
  126. SetWindowLongPtr(hToolbar, GWL_STYLE, toolbarStyle & ~TBS_AUTOHIDE);
  127. HWND hStatusbar = BrowserControl_GetStatusbar(hControl);
  128. DWORD statusStyle = (NULL != hStatusbar) ? GetWindowStyle(hStatusbar) : 0;
  129. if (NULL != hStatusbar && 0 == (WS_DISABLED & statusStyle))
  130. SetWindowLongPtr(hStatusbar, GWL_STYLE, WS_DISABLED | statusStyle);
  131. SendMessage(hBrowser, NBHM_SHOWHISTORYPOPUP, (WPARAM)flags, MAKELPARAM(pt.x, pt.y));
  132. if (NULL != hToolbar && 0 != (TBS_AUTOHIDE & toolbarStyle))
  133. {
  134. SetWindowLongPtr(hToolbar, GWL_STYLE, toolbarStyle);
  135. TRACKMOUSEEVENT tm;
  136. tm.cbSize = sizeof(TRACKMOUSEEVENT);
  137. tm.dwFlags = TME_LEAVE;
  138. tm.hwndTrack = hToolbar;
  139. TrackMouseEvent(&tm);
  140. }
  141. if (NULL != hStatusbar && 0 == (WS_DISABLED & statusStyle))
  142. SetWindowLongPtr(hStatusbar, GWL_STYLE, statusStyle);
  143. }
  144. static BOOL BrowserControl_ExecServiceCommand(HWND hControl, ifc_omservicecommand *command, const GUID *group, UINT id, ULONG_PTR arg)
  145. {
  146. if (NULL == command) return FALSE;
  147. HRESULT state = command->QueryState(hControl, group, id);
  148. if (CMDSTATE_ENABLED == state)
  149. {
  150. command->Exec(hControl, group, id, arg);
  151. return TRUE;
  152. }
  153. return (CMDSTATE_DISABLED == state) ? TRUE : FALSE;
  154. }
  155. BOOL BrowserControl_ProcessCommonCommand(HWND hControl, INT commandId)
  156. {
  157. if (NULL == hControl)
  158. return FALSE;
  159. UINT controlStyle = GetWindowStyle(hControl);
  160. ifc_omservice *service;
  161. if (0 != (NBCS_NOSERVICECOMMANDS & controlStyle) ||
  162. FALSE == BrowserControl_GetService(hControl, &service))
  163. {
  164. service = NULL;
  165. }
  166. ifc_omservicecommand *serviceCommand;
  167. if (NULL == service ||
  168. FAILED(service->QueryInterface(IFC_OmServiceCommand, (void**)&serviceCommand)))
  169. {
  170. serviceCommand = NULL;
  171. }
  172. BOOL fProcessed = FALSE;
  173. switch(commandId)
  174. {
  175. case ID_NAVIGATION_HOME:
  176. if (FALSE == BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_NAVIGATION, NAVCOMMAND_HOME, 0))
  177. BrowserControl_Navigate(hControl, NAVIGATE_HOME, 0L);
  178. fProcessed = TRUE;
  179. break;
  180. case ID_NAVIGATION_BACK:
  181. if (FALSE == BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_NAVIGATION, NAVCOMMAND_BACKFORWARD, FALSE))
  182. BrowserControl_Navigate(hControl, NAVIGATE_BACK, 0L);
  183. fProcessed = TRUE;
  184. break;
  185. case ID_NAVIGATION_FORWARD:
  186. if (FALSE == BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_NAVIGATION, NAVCOMMAND_BACKFORWARD, TRUE))
  187. BrowserControl_Navigate(hControl, NAVIGATE_FORWARD, 0L);
  188. fProcessed = TRUE;
  189. break;
  190. case ID_NAVIGATION_REFRESH:
  191. if (FALSE == BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_NAVIGATION, NAVCOMMAND_REFRESH, FALSE))
  192. BrowserControl_Navigate(hControl, NAVIGATE_REFRESH, 0L);
  193. fProcessed = TRUE;
  194. break;
  195. case ID_NAVIGATION_REFRESH_COMPLETELY:
  196. if (FALSE == BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_NAVIGATION, NAVCOMMAND_REFRESH, TRUE))
  197. BrowserControl_Navigate(hControl, NAVIGATE_REFRESH_COMPLETELY, 0L);
  198. fProcessed = TRUE;
  199. break;
  200. case ID_NAVIGATION_STOP:
  201. if (FALSE == BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_NAVIGATION, NAVCOMMAND_STOP, 0L))
  202. BrowserControl_Navigate(hControl, NAVIGATE_STOP, 0L);
  203. fProcessed = TRUE;
  204. break;
  205. case ID_NAVIGATION_HISTORY:
  206. if (FALSE == BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_NAVIGATION, NAVCOMMAND_HISTORY, 0L))
  207. BrowserControl_ShowHistoryPopup(hControl);
  208. fProcessed = TRUE;
  209. break;
  210. case ID_SERVICE_GETINFO:
  211. BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_SERVICE, SVCCOMMAND_SHOWINFO, 0);
  212. fProcessed = TRUE;
  213. break;
  214. case ID_SERVICE_REPORT:
  215. BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_SERVICE, SVCCOMMAND_REPORT, 0);
  216. fProcessed = TRUE;
  217. break;
  218. case ID_SERVICE_UNSUBSCRIBE:
  219. BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_SERVICE, SVCCOMMAND_UNSUBSCRIBE, 0);
  220. fProcessed = TRUE;
  221. break;
  222. case ID_RATING_VALUE_1:
  223. BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_SERVICE, SVCCOMMAND_RATE, 1);
  224. fProcessed = TRUE;
  225. break;
  226. case ID_RATING_VALUE_2:
  227. BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_SERVICE, SVCCOMMAND_RATE, 2);
  228. fProcessed = TRUE;
  229. break;
  230. case ID_RATING_VALUE_3:
  231. BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_SERVICE, SVCCOMMAND_RATE, 3);
  232. fProcessed = TRUE;
  233. break;
  234. case ID_RATING_VALUE_4:
  235. BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_SERVICE, SVCCOMMAND_RATE, 4);
  236. fProcessed = TRUE;
  237. break;
  238. case ID_RATING_VALUE_5:
  239. BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_SERVICE, SVCCOMMAND_RATE, 5);
  240. fProcessed = TRUE;
  241. break;
  242. case ID_WINDOW_CLOSE:
  243. if (FALSE != BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_WINDOW, WNDCOMMAND_CLOSE, 0))
  244. fProcessed = TRUE;
  245. break;
  246. case ID_WINDOW_FULLSCREEN:
  247. if (FALSE != BrowserControl_ExecServiceCommand(hControl, serviceCommand, &CMDGROUP_WINDOW, WNDCOMMAND_FULLSCREEN, 0))
  248. fProcessed = TRUE;
  249. break;
  250. case ID_ADDRESSBAR_ACTIVATE:
  251. {
  252. HWND hToolbar = BrowserControl_GetToolbar(hControl);
  253. if(NULL != hToolbar)
  254. {
  255. Toolbar_NextItem(hToolbar, TOOLITEM_ADDRESSBAR, TRUE);
  256. }
  257. }
  258. fProcessed = TRUE;
  259. break;
  260. case ID_ADDRESSBAR_CHANGED:
  261. {
  262. HWND hToolbar = BrowserControl_GetToolbar(hControl);
  263. if(NULL != hToolbar)
  264. {
  265. INT itemId = Toolbar_FindItem(hToolbar, TOOLITEM_ADDRESSBAR);
  266. if (ITEM_ERR != itemId)
  267. {
  268. size_t cchBufferMax;
  269. if (FALSE == Toolbar_GetTextLength(hToolbar, MAKEINTRESOURCE(itemId), &cchBufferMax))
  270. cchBufferMax = 8192;
  271. cchBufferMax++;
  272. LPWSTR pszBuffer = Plugin_MallocString(cchBufferMax);
  273. if (NULL != pszBuffer)
  274. {
  275. TBITEMINFO itemInfo;
  276. ZeroMemory(&itemInfo, sizeof(itemInfo));
  277. itemInfo.pszText = pszBuffer;
  278. itemInfo.cchText = (INT)cchBufferMax;
  279. if (FALSE != Toolbar_GetItemInfo(hToolbar, MAKEINTRESOURCE(itemId), &itemInfo))
  280. {
  281. if (FALSE == BrowserControl_ExecServiceCommand(hControl, serviceCommand,
  282. &CMDGROUP_ADDRESSBAR, ADDRESSCOMMAND_EXECUTE, (ULONG_PTR)itemInfo.pszText))
  283. {
  284. BrowserControl_Navigate(hControl, NAVIGATE_STOP, 0L);
  285. BrowserControl_Navigate(hControl, itemInfo.pszText, 0L);
  286. }
  287. }
  288. Plugin_FreeString(pszBuffer);
  289. }
  290. }
  291. }
  292. }
  293. fProcessed = TRUE;
  294. break;
  295. }
  296. if (NULL != serviceCommand)
  297. serviceCommand->Release();
  298. if (NULL != service)
  299. service->Release();
  300. return fProcessed;
  301. }
  302. BOOL BrowserControl_ProcessStatusbarCommand(HWND hControl, INT commandId)
  303. {
  304. HWND hStatusbar = BrowserControl_GetStatusbar(hControl);
  305. if (NULL == hStatusbar) return FALSE;
  306. BOOL fProcessed = FALSE;
  307. obj_ombrowser *browserManager;
  308. if (FALSE != BrowserControl_GetBrowserObject(hControl, &browserManager) && NULL != browserManager)
  309. {
  310. ifc_omstatusbarconfig *statusbarConfig;
  311. if (SUCCEEDED(browserManager->GetConfig(&IFC_OmStatusbarConfig, (void**)&statusbarConfig)))
  312. {
  313. UINT statusbarStyle = GetWindowStyle(hStatusbar);
  314. switch(commandId)
  315. {
  316. case SBN_ENABLECHANGED:
  317. statusbarConfig->EnableStatusbar(0 == (WS_DISABLED & statusbarStyle));
  318. fProcessed = TRUE;
  319. break;
  320. }
  321. statusbarConfig->Release();
  322. }
  323. browserManager->Release();
  324. }
  325. return fProcessed;
  326. }
  327. BOOL BrowserControl_ProcessToolbarCommand(HWND hControl, INT commandId)
  328. {
  329. HWND hToolbar = BrowserControl_GetToolbar(hControl);
  330. if (NULL == hToolbar) return FALSE;
  331. BOOL fProcessed = FALSE;
  332. obj_ombrowser *browserManager;
  333. if (FALSE != BrowserControl_GetBrowserObject(hControl, &browserManager) && NULL != browserManager)
  334. {
  335. ifc_omtoolbarconfig *toolbarConfig;
  336. if (SUCCEEDED(browserManager->GetConfig(&IFC_OmToolbarConfig, (void**)&toolbarConfig)))
  337. {
  338. UINT toolbarStyle = GetWindowStyle(hToolbar);
  339. switch(commandId)
  340. {
  341. case TBN_DOCKCHANGED:
  342. toolbarConfig->EnableBottomDock(0 != (TBS_BOTTOMDOCK & toolbarStyle));
  343. fProcessed = TRUE;
  344. break;
  345. case TBN_AUTOHIDECHANGED:
  346. toolbarConfig->EnableAutoHide(0 != (TBS_AUTOHIDE & toolbarStyle));
  347. fProcessed = TRUE;
  348. break;
  349. case TBN_TABSTOPCHANGED:
  350. toolbarConfig->EnableTabStop(0 != (TBS_TABSTOP & toolbarStyle));
  351. fProcessed = TRUE;
  352. break;
  353. }
  354. toolbarConfig->Release();
  355. }
  356. browserManager->Release();
  357. }
  358. return fProcessed;
  359. }
  360. BOOL BrowserControl_ProcessAppCommand(HWND hControl, INT commandId)
  361. {
  362. if (NULL == hControl)
  363. return FALSE;
  364. switch(commandId)
  365. {
  366. case APPCOMMAND_BROWSER_BACKWARD: BrowserControl_ProcessCommonCommand(hControl, ID_NAVIGATION_BACK); return TRUE;
  367. case APPCOMMAND_BROWSER_FORWARD: BrowserControl_ProcessCommonCommand(hControl, ID_NAVIGATION_FORWARD); return TRUE;
  368. case APPCOMMAND_BROWSER_HOME: BrowserControl_ProcessCommonCommand(hControl, ID_NAVIGATION_HOME); return TRUE;
  369. case APPCOMMAND_BROWSER_REFRESH: BrowserControl_ProcessCommonCommand(hControl, ID_NAVIGATION_REFRESH); return TRUE;
  370. case APPCOMMAND_BROWSER_STOP: BrowserControl_ProcessCommonCommand(hControl, ID_NAVIGATION_STOP); return TRUE;
  371. case APPCOMMAND_BROWSER_FAVORITES: return TRUE;
  372. case APPCOMMAND_BROWSER_SEARCH: return TRUE;
  373. }
  374. return FALSE;
  375. }
  376. HWND BrowserControl_GetOperationWidget(HWND hControl)
  377. {
  378. return GetDlgItem(hControl, IDC_OPERATIONWIDGET);
  379. }
  380. HWND BrowserControl_CreateOperationWidget(HWND hControl)
  381. {
  382. if (FALSE == Curtain_RegisterClass(Plugin_GetInstance()))
  383. return NULL;
  384. RECT rc;
  385. HWND hTarget = BrowserControl_GetHost(hControl);
  386. if (NULL == hTarget) hTarget = hControl;
  387. if (FALSE == GetWindowRect(hTarget, &rc))
  388. return NULL;
  389. MapWindowPoints(HWND_DESKTOP, hControl, (POINT*)&rc, 2);
  390. HWND hWidget = CreateWindowEx(WS_EX_NOPARENTNOTIFY | WS_EX_CONTROLPARENT,
  391. NWC_ONLINEMEDIACURTAIN, NULL, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS /*| WS_VISIBLE*/,
  392. rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, hControl,
  393. (HMENU)IDC_OPERATIONWIDGET, Plugin_GetInstance(), NULL);
  394. return hWidget;
  395. }
  396. BOOL BrowserControl_OnShowOperation(HWND hControl, OPERATIONINFO *poi)
  397. {
  398. if (NULL == poi) return FALSE;
  399. if (poi->cbSize != sizeof(OPERATIONINFO))
  400. return FALSE;
  401. BOOL updateSkin = FALSE;
  402. HWND hWidget = BrowserControl_GetOperationWidget(hControl);
  403. if (0 != (NBCOM_FLAGS & poi->mask))
  404. {
  405. if (0 != (NBCOF_SHOWWIDGET & poi->flags))
  406. {
  407. if (NULL == hWidget)
  408. {
  409. hWidget = BrowserControl_CreateOperationWidget(hControl);
  410. if (NULL != hWidget)
  411. updateSkin = TRUE;
  412. }
  413. }
  414. if (0 != (NBCOF_HIDEWIDGET & poi->flags))
  415. {
  416. if (NULL != hWidget)
  417. {
  418. DestroyWindow(hWidget);
  419. hWidget = NULL;
  420. SetWindowPos(hControl, NULL, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE |
  421. SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS | SWP_DEFERERASE);
  422. }
  423. }
  424. }
  425. if (0 != (NBCOM_TITLE & poi->mask))
  426. {
  427. if (NULL != hWidget)
  428. SetWindowText(hWidget, poi->title);
  429. }
  430. if (0 != (NBCOM_TEXT & poi->mask))
  431. {
  432. if (NULL != hWidget)
  433. Curtain_SetOperationText(hWidget, poi->text);
  434. }
  435. if (NULL != hWidget && 0 != (NBCOM_FLAGS & poi->mask) && 0 != (NBCOF_SHOWWIDGET & poi->flags))
  436. {
  437. if (FALSE != updateSkin)
  438. {
  439. PostMessage(hWidget, CWM_UPDATESKIN, 0, 0L);
  440. SetWindowPos(hControl, NULL, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOSIZE | SWP_NOMOVE |
  441. SWP_FRAMECHANGED | SWP_ASYNCWINDOWPOS | SWP_DEFERERASE);
  442. }
  443. ShowWindowAsync(hWidget, SW_SHOWNA);
  444. }
  445. return TRUE;
  446. }
  447. BOOL BrowserControl_UpdateLayout(HWND hControl, BOOL fRedraw, BOOL fFrame, HRGN updateRegion, const POINT *updateOffset)
  448. {
  449. RECT clientRect;
  450. if (!GetClientRect(hControl, &clientRect))
  451. return FALSE;
  452. UINT uFlags = SWP_NOZORDER | SWP_NOACTIVATE;
  453. if (FALSE == fRedraw) uFlags |= SWP_NOREDRAW;
  454. if (FALSE != fFrame) uFlags |= SWP_FRAMECHANGED;
  455. HWND hToolbar, hBrowser, hStatusbar, hWidget;
  456. BOOL toolbarSet = FALSE;
  457. TOOLBARLAYOUT layout;
  458. layout.prcParent = &clientRect;
  459. HDWP hdwp = BeginDeferWindowPos(2);
  460. if (NULL == hdwp) return FALSE;
  461. if (NULL != (hToolbar = BrowserControl_GetToolbar(hControl)))
  462. {
  463. if (Toolbar_Layout(hToolbar, &layout))
  464. {
  465. toolbarSet = TRUE;
  466. hdwp = DeferWindowPos(hdwp, hToolbar, layout.insertAfter, layout.toolbarRect.left, layout.toolbarRect.top,
  467. layout.toolbarRect.right - layout.toolbarRect.left,
  468. layout.toolbarRect.bottom - layout.toolbarRect.top, uFlags & ~SWP_NOZORDER);
  469. if (NULL == hdwp) return FALSE;
  470. }
  471. }
  472. if (FALSE == toolbarSet)
  473. CopyRect(&layout.clientRect, layout.prcParent);
  474. if (NULL != (hBrowser = BrowserControl_GetHost(hControl)))
  475. {
  476. if (0 != (NBHS_BROWSERREADY & GetWindowStyle(hBrowser)))
  477. {
  478. SetWindowPos(hBrowser, NULL, layout.clientRect.left, layout.clientRect.top,
  479. layout.clientRect.right - layout.clientRect.left, layout.clientRect.bottom - layout.clientRect.top,
  480. uFlags | SWP_ASYNCWINDOWPOS | SWP_DEFERERASE);
  481. }
  482. }
  483. if (NULL != (hWidget = BrowserControl_GetOperationWidget(hControl)))
  484. {
  485. HWND hInsertAfter;
  486. if (NULL != hBrowser) hInsertAfter = GetWindow(hBrowser, GW_HWNDPREV);
  487. else if( NULL != hToolbar) hInsertAfter = GetWindow(hBrowser, GW_HWNDPREV);
  488. else hInsertAfter = HWND_TOP;
  489. UINT flags;
  490. flags = uFlags;
  491. if (hInsertAfter != hWidget)
  492. flags &= ~SWP_NOZORDER;
  493. hdwp = DeferWindowPos(hdwp, hWidget, hInsertAfter, layout.clientRect.left, layout.clientRect.top,
  494. layout.clientRect.right - layout.clientRect.left, layout.clientRect.bottom - layout.clientRect.top, flags);
  495. if (NULL == hdwp) return FALSE;
  496. }
  497. EndDeferWindowPos(hdwp);
  498. if (NULL != (hStatusbar = BrowserControl_GetStatusbar(hControl)))
  499. Statusbar_SetParentRect(hStatusbar, &layout.clientRect);
  500. ////////////////////////////////////
  501. if (NULL != updateRegion)
  502. {
  503. RECT rect;
  504. HRGN rgnValid = NULL;
  505. if (NULL != hBrowser && 0 != (WS_VISIBLE & GetWindowStyle(hBrowser)) &&
  506. FALSE != GetWindowRect(hBrowser, &rect))
  507. {
  508. MapWindowPoints(HWND_DESKTOP, hControl, (POINT*)&rect, 2);
  509. rgnValid = CreateRectRgnIndirect(&rect);
  510. }
  511. if (NULL != rgnValid)
  512. {
  513. HRGN rgn = NULL;
  514. HWND szControls[] = {hToolbar, hStatusbar, hWidget};
  515. for (INT i = 0; i < ARRAYSIZE(szControls); i++)
  516. {
  517. if (NULL != szControls[i] && 0 != (WS_VISIBLE & GetWindowStyle(szControls[i])) &&
  518. FALSE != GetWindowRect(szControls[i], &rect))
  519. {
  520. MapWindowPoints(HWND_DESKTOP, hControl, (POINT*)&rect, 2);
  521. if (NULL == rgn) rgn = CreateRectRgnIndirect(&rect);
  522. else SetRectRgn(rgn, rect.left, rect.top, rect.right, rect.bottom);
  523. if (NULL != rgn)
  524. CombineRgn(rgnValid, rgnValid, rgn, RGN_DIFF);
  525. }
  526. }
  527. if (NULL != updateOffset)
  528. OffsetRgn(rgnValid, -updateOffset->x, -updateOffset->y);
  529. CombineRgn(updateRegion, updateRegion, rgnValid, RGN_DIFF);
  530. if (NULL != rgn) DeleteObject(rgn);
  531. DeleteObject(rgnValid);
  532. }
  533. }
  534. return TRUE;
  535. }
  536. BOOL BrowserControl_EnableChildren(HWND hControl, BOOL fEnable)
  537. {
  538. HWND hChild;
  539. if (NULL != (hChild = BrowserControl_GetHost(hControl)))
  540. PostMessage(hChild, NBHM_ENABLEWINDOW, 0, fEnable);
  541. if (NULL != (hChild = BrowserControl_GetToolbar(hControl)))
  542. EnableWindow(hChild, fEnable);
  543. if (NULL != (hChild = BrowserControl_GetStatusbar(hControl)))
  544. EnableWindow(hChild, fEnable);
  545. return TRUE;
  546. }
  547. BOOL BrowserControl_SetBlockedState(HWND hControl, BOOL fBlocked)
  548. {
  549. if (NULL == hControl)
  550. return FALSE;
  551. UINT prevStyle = BrowserControl_SetExtendedStyle(hControl, NBCS_EX_BLOCKNAVIGATION, (FALSE != fBlocked) ? NBCS_EX_BLOCKNAVIGATION : 0);
  552. if (FALSE != fBlocked)
  553. {
  554. if (0 == (NBCS_EX_BLOCKNAVIGATION & prevStyle))
  555. {
  556. BrowserControl_EnableChildren(hControl, FALSE);
  557. }
  558. }
  559. else
  560. {
  561. if (0 != (NBCS_EX_BLOCKNAVIGATION & prevStyle))
  562. {
  563. BrowserControl_EnableChildren(hControl, TRUE);
  564. }
  565. BrowserControl_NavigateStoredUrl(hControl);
  566. }
  567. return TRUE;
  568. }