Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1365 lines
37 KiB

  1. /******************************************************************************
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. Toolbar.cpp
  5. Abstract:
  6. This file contains the ActiveX control that makes Win32 ToolBars available to HTML.
  7. Revision History:
  8. Davide Massarenti (Dmassare) 03/04/2001
  9. created
  10. ******************************************************************************/
  11. #include "stdafx.h"
  12. #include <comctrlp.h>
  13. ////////////////////////////////////////////////////////////////////////////////
  14. #define HISTORY_MENU__LIMIT (10) // Just pick a limited number of items.
  15. ////////////////////////////////////////////////////////////////////////////////
  16. static const MPC::StringToBitField c_Images[] =
  17. {
  18. { L"BACK" , -1, 0, -1 },
  19. { L"FORWARD" , -1, 1, -1 },
  20. { L"HOME" , -1, 2, -1 },
  21. { L"INDEX" , -1, 3, -1 },
  22. { L"FAVORITES" , -1, 4, -1 },
  23. { L"HISTORY" , -1, 5, -1 },
  24. { L"SUPPORT" , -1, 6, -1 },
  25. { L"OPTIONS" , -1, 7, -1 },
  26. { L"ADDFAV" , -1, 8, -1 },
  27. { L"PRINT" , -1, 9, -1 },
  28. { L"LOCATE" , -1, 10, -1 },
  29. { L"LAYOUT_SMALL", -1, 11, -1 },
  30. { L"LAYOUT_LARGE", -1, 12, -1 },
  31. { NULL }
  32. };
  33. const MPC::StringToBitField CPCHToolBar::c_TypeLookup[] =
  34. {
  35. { L"BACK" , -1, CPCHToolBar::TYPE_back , -1 },
  36. { L"FORWARD" , -1, CPCHToolBar::TYPE_forward , -1 },
  37. { L"SEPARATOR", -1, CPCHToolBar::TYPE_separator, -1 },
  38. { L"GENERIC" , -1, CPCHToolBar::TYPE_generic , -1 },
  39. { NULL }
  40. };
  41. CFG_BEGIN_FIELDS_MAP(CPCHToolBar::Button)
  42. CFG_ATTRIBUTE ( L"ID" , wstring, m_strID ),
  43. CFG_ATTRIBUTE ( L"ACCESSKEY" , WCHAR , m_wch ),
  44. CFG_ATTRIBUTE ( L"ENABLED" , bool , m_fEnabled ),
  45. CFG_ATTRIBUTE ( L"VISIBLE" , bool , m_fVisible ),
  46. CFG_ATTRIBUTE ( L"HIDETEXT" , bool , m_fHideText ),
  47. CFG_ATTRIBUTE ( L"SYSTEMMENU" , bool , m_fSystemMenu ),
  48. CFG_ATTRIBUTE__BITFIELD( L"TYPE" , m_dwType , c_TypeLookup ),
  49. CFG_ELEMENT ( L"IMAGE_NORMAL" , wstring, m_strImage_Normal ),
  50. CFG_ELEMENT ( L"IMAGE_HOT" , wstring, m_strImage_Hot ),
  51. CFG_ELEMENT ( L"TEXT" , wstring, m_strText ),
  52. CFG_ELEMENT ( L"TOOLTIP" , wstring, m_strToolTip ),
  53. CFG_END_FIELDS_MAP()
  54. CFG_BEGIN_CHILD_MAP(CPCHToolBar::Button)
  55. CFG_END_CHILD_MAP()
  56. DEFINE_CFG_OBJECT(CPCHToolBar::Button,L"BUTTON")
  57. DEFINE_CONFIG_METHODS__NOCHILD(CPCHToolBar::Button)
  58. ////////////////////
  59. CFG_BEGIN_FIELDS_MAP(CPCHToolBar::Config)
  60. CFG_ATTRIBUTE( L"WIDTH" , long, m_lWidth ),
  61. CFG_ATTRIBUTE( L"HEIGHT" , long, m_lHeight ),
  62. CFG_ATTRIBUTE( L"ICONSIZE", long, m_lIconSize ),
  63. CFG_END_FIELDS_MAP()
  64. CFG_BEGIN_CHILD_MAP(CPCHToolBar::Config)
  65. CFG_CHILD(CPCHToolBar::Button)
  66. CFG_END_CHILD_MAP()
  67. DEFINE_CFG_OBJECT(CPCHToolBar::Config,L"TOOLBAR")
  68. DEFINE_CONFIG_METHODS_CREATEINSTANCE_SECTION(CPCHToolBar::Config,tag,defSubType)
  69. if(tag == _cfg_table_tags[0])
  70. {
  71. defSubType = &(*(m_lstButtons.insert( m_lstButtons.end() )));
  72. return S_OK;
  73. }
  74. DEFINE_CONFIG_METHODS_SAVENODE_SECTION(CPCHToolBar::Config,xdn)
  75. DEFINE_CONFIG_METHODS_END(CPCHToolBar::Config)
  76. ////////////////////////////////////////////////////////////////////////////////
  77. CPCHToolBar::Button::Button()
  78. {
  79. // MPC::wstring m_strID;
  80. m_wch = 0; // WCHAR m_wch;
  81. m_fEnabled = false; // bool m_fEnabled;
  82. m_fVisible = false; // bool m_fVisible;
  83. m_fHideText = false; // bool m_fHideText;
  84. m_fSystemMenu = false; // bool m_fSystemMenu;
  85. // MPC::wstring m_strType;
  86. //
  87. // MPC::wstring m_strImage_Normal;
  88. // MPC::wstring m_strImage_Hot;
  89. // MPC::wstring m_strText;
  90. // MPC::wstring m_strToolTip;
  91. //
  92. //
  93. m_idCmd = 0; // int m_idCmd;
  94. m_iImage_Normal = -1; // int m_iImage_Normal;
  95. m_iImage_Hot = -1; // int m_iImage_Hot;
  96. }
  97. void CPCHToolBar::Button::UpdateState( /*[in]*/ HWND hwndTB )
  98. {
  99. LRESULT lResult = ::SendMessageW( hwndTB, TB_GETSTATE, m_idCmd, 0 );
  100. lResult &= ~(TBSTATE_ENABLED | TBSTATE_INDETERMINATE | TBSTATE_HIDDEN);
  101. lResult |= (m_fEnabled ? TBSTATE_ENABLED : TBSTATE_INDETERMINATE);
  102. lResult |= (m_fVisible ? 0 : TBSTATE_HIDDEN );
  103. ::SendMessageW( hwndTB, TB_SETSTATE, m_idCmd, MAKELONG(lResult, 0) );
  104. }
  105. ////////////////////////////////////////////////////////////////////////////////
  106. CPCHToolBar::Config::Config()
  107. {
  108. // long m_lWidth;
  109. // long m_lHeight;
  110. // long m_lIconSize;
  111. //
  112. m_mode = TB_SELECTED; // TB_MODE m_mode;
  113. // ButtonList m_lstButtons;
  114. //
  115. m_himlNormal = NULL; // HIMAGELIST m_himlNormal;
  116. m_himlHot = NULL; // HIMAGELIST m_himlHot;
  117. if(CPCHOptions::s_GLOBAL)
  118. {
  119. m_mode = CPCHOptions::s_GLOBAL->TextLabels();
  120. }
  121. Reset();
  122. }
  123. CPCHToolBar::Button* CPCHToolBar::Config::LookupButton( /*[in]*/ LPCWSTR szID ,
  124. /*[in]*/ int idCmd )
  125. {
  126. for(ButtonIter it = m_lstButtons.begin(); it != m_lstButtons.end(); it++)
  127. {
  128. Button& bt = *it;
  129. if(szID != NULL && bt.m_strID == szID ) return &bt;
  130. if(idCmd != -1 && bt.m_idCmd == idCmd) return &bt;
  131. }
  132. return NULL;
  133. }
  134. void CPCHToolBar::Config::Reset()
  135. {
  136. (void)::ImageList_Destroy( m_himlNormal );
  137. (void)::ImageList_Destroy( m_himlHot );
  138. m_lWidth = 0; // long m_lWidth;
  139. m_lHeight = 0; // long m_lHeight;
  140. m_lIconSize = 24; // long m_lIconSize;
  141. m_fRTL = false; // bool m_fRTL;
  142. //
  143. m_lstButtons.clear(); // ButtonList m_lstButtons;
  144. //
  145. m_himlNormal = NULL; // HIMAGELIST m_himlNormal;
  146. m_himlHot = NULL; // HIMAGELIST m_himlHot;
  147. }
  148. HRESULT CPCHToolBar::Config::Load( /*[in]*/ LPCWSTR szBaseURL ,
  149. /*[in]*/ LPCWSTR szDefinition ,
  150. /*[in]*/ LPCWSTR szDir )
  151. {
  152. __HCP_FUNC_ENTRY( "CPCHToolBar::Config::Load" );
  153. HRESULT hr;
  154. CComPtr<IStream> stream;
  155. Reset();
  156. m_fRTL = (MPC::StrICmp( szDir, L"RTL" ) == 0);
  157. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::HTML::OpenStream( szBaseURL, szDefinition, stream ));
  158. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::Config::LoadStream( this, stream ));
  159. //
  160. // Load all the images.
  161. //
  162. {
  163. COLORREF crMask = RGB( 255, 0, 255 );
  164. LPCWSTR szDef;
  165. LPCWSTR szHot;
  166. int cx;
  167. if(m_lIconSize == 24)
  168. {
  169. szDef = MAKEINTRESOURCEW(IDB_TB_DEF_24);
  170. szHot = MAKEINTRESOURCEW(IDB_TB_HOT_24);
  171. cx = 24;
  172. }
  173. else
  174. {
  175. szDef = MAKEINTRESOURCEW(IDB_TB_DEF_16);
  176. szHot = MAKEINTRESOURCEW(IDB_TB_HOT_16);
  177. cx = 16;
  178. }
  179. m_himlNormal = ::ImageList_LoadImageW( ::GetModuleHandle( NULL ), szDef, cx, 0, crMask, IMAGE_BITMAP, LR_CREATEDIBSECTION );
  180. m_himlHot = ::ImageList_LoadImageW( ::GetModuleHandle( NULL ), szHot, cx, 0, crMask, IMAGE_BITMAP, LR_CREATEDIBSECTION );
  181. for(ButtonIter it = m_lstButtons.begin(); it != m_lstButtons.end(); it++)
  182. {
  183. Button& bt = *it;
  184. if(bt.m_strImage_Normal.size())
  185. {
  186. if(bt.m_strImage_Hot.length() == 0) bt.m_strImage_Hot = bt.m_strImage_Normal;
  187. __MPC_EXIT_IF_METHOD_FAILS(hr, MergeImage( szBaseURL, bt.m_strImage_Normal.c_str(), m_himlNormal, bt.m_iImage_Normal ));
  188. __MPC_EXIT_IF_METHOD_FAILS(hr, MergeImage( szBaseURL, bt.m_strImage_Hot .c_str(), m_himlHot , bt.m_iImage_Hot ));
  189. }
  190. }
  191. }
  192. hr = S_OK;
  193. __HCP_FUNC_CLEANUP;
  194. if(FAILED(hr)) Reset();
  195. __HCP_FUNC_EXIT(hr);
  196. }
  197. HRESULT CPCHToolBar::Config::CreateButtons( /*[in]*/ HWND hwndTB )
  198. {
  199. __HCP_FUNC_ENTRY( "CPCHToolBar::Config::CreateButtons" );
  200. HRESULT hr;
  201. TBBUTTON* tbs = NULL;
  202. int iNum = m_lstButtons.size();
  203. int iCmd = 1;
  204. //
  205. // Remove previous buttons.
  206. //
  207. {
  208. INT_PTR nCount = ::SendMessageW( hwndTB, TB_BUTTONCOUNT, 0, 0L );
  209. while(nCount-- > 0) ::SendMessageW( hwndTB, TB_DELETEBUTTON, nCount, 0L );
  210. }
  211. if(iNum)
  212. {
  213. TBBUTTON* ptr;
  214. ButtonIter it;
  215. __MPC_EXIT_IF_ALLOC_FAILS(hr, tbs, new TBBUTTON[iNum]);
  216. ::SendMessageW( hwndTB, TB_SETIMAGELIST , 0, (LPARAM)m_himlNormal );
  217. ::SendMessageW( hwndTB, TB_SETHOTIMAGELIST, 0, (LPARAM)m_himlHot );
  218. for(ptr = tbs, it = m_lstButtons.begin(); it != m_lstButtons.end(); ptr++, it++)
  219. {
  220. Button& bt = *it; ::ZeroMemory( ptr, sizeof(TBBUTTON) );
  221. bt.m_idCmd = iCmd++;
  222. ptr->iBitmap = I_IMAGECALLBACK;
  223. ptr->idCommand = bt.m_idCmd;
  224. ptr->fsState = (bt.m_fEnabled ? TBSTATE_ENABLED : TBSTATE_INDETERMINATE) | (bt.m_fVisible ? 0 : TBSTATE_HIDDEN) | TBSTATE_ELLIPSES;
  225. ptr->fsStyle |= BTNS_AUTOSIZE;
  226. if(bt.m_strText.size())
  227. {
  228. switch(m_mode)
  229. {
  230. case TB_NONE:
  231. break;
  232. case TB_SELECTED:
  233. if(bt.m_fHideText) break;
  234. case TB_ALL:
  235. ptr->iString = (INT_PTR)bt.m_strText.c_str();
  236. ptr->fsStyle |= BTNS_SHOWTEXT;
  237. break;
  238. }
  239. }
  240. switch(bt.m_dwType)
  241. {
  242. case TYPE_back : ptr->fsStyle |= BTNS_DROPDOWN; break;
  243. case TYPE_forward : ptr->fsStyle |= BTNS_DROPDOWN; break;
  244. case TYPE_separator: ptr->fsStyle |= BTNS_SEP ; ptr->fsStyle &= ~(BTNS_AUTOSIZE | BTNS_SHOWTEXT); break;
  245. case TYPE_generic : break;
  246. }
  247. }
  248. ::SendMessageW( hwndTB, TB_ADDBUTTONSW, iNum, (LPARAM)tbs );
  249. }
  250. ::SendMessageW( hwndTB, TB_AUTOSIZE, 0, 0 );
  251. hr = S_OK;
  252. __HCP_FUNC_CLEANUP;
  253. delete [] tbs;
  254. __HCP_FUNC_EXIT(hr);
  255. }
  256. void CPCHToolBar::Config::UpdateSize( /*[in]*/ HWND hwndTB, /*[in]*/ HWND hwndRB, /*[out]*/ SIZEL& ptIdeal )
  257. {
  258. REBARBANDINFOW rbbi; ::ZeroMemory( &rbbi, sizeof(rbbi) );
  259. RECT rcMax = { 0, 0, 0, 0 };
  260. for(ButtonIter it = m_lstButtons.begin(); it != m_lstButtons.end(); it++)
  261. {
  262. Button& bt = *it;
  263. RECT rc;
  264. if(::SendMessage( hwndTB, TB_GETRECT, bt.m_idCmd, (LPARAM)&rc ))
  265. {
  266. if(rcMax.left > rc.left ) rcMax.left = rc.left ;
  267. if(rcMax.right < rc.right ) rcMax.right = rc.right ;
  268. if(rcMax.top > rc.top ) rcMax.top = rc.top ;
  269. if(rcMax.bottom < rc.bottom) rcMax.bottom = rc.bottom;
  270. }
  271. }
  272. ptIdeal.cx = rcMax.right - rcMax.left;
  273. ptIdeal.cy = rcMax.bottom - rcMax.top;
  274. if(hwndRB)
  275. {
  276. rbbi.cbSize = sizeof(REBARBANDINFOW);
  277. rbbi.fMask = RBBIM_IDEALSIZE;
  278. ::SendMessage( hwndRB, RB_GETBANDINFOW, 0, (LPARAM)&rbbi );
  279. if(rbbi.cxIdeal != ptIdeal.cx)
  280. {
  281. rbbi.cxIdeal = ptIdeal.cx;
  282. ::SendMessage( hwndRB, RB_SETBANDINFOW, 0, (LPARAM)&rbbi );
  283. }
  284. }
  285. }
  286. HRESULT CPCHToolBar::Config::MergeImage( /*[in ]*/ LPCWSTR szBaseURL ,
  287. /*[in ]*/ LPCWSTR szRelativeURL ,
  288. /*[in ]*/ HIMAGELIST himl ,
  289. /*[out]*/ int& iImage )
  290. {
  291. __HCP_FUNC_ENTRY( "CPCHToolBar::Config::MergeImage" );
  292. HRESULT hr;
  293. HBITMAP hBMP = NULL;
  294. if(wcschr( szRelativeURL, '#' ))
  295. {
  296. DWORD dwImage = -1;
  297. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::ConvertStringToBitField( &szRelativeURL[1], dwImage, c_Images, /*fUseTilde*/false ));
  298. iImage = dwImage;
  299. }
  300. else
  301. {
  302. COLORREF crMask = RGB( 255, 0, 255 );
  303. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::HTML::DownloadBitmap( szBaseURL, szRelativeURL, crMask, hBMP ));
  304. iImage = ::ImageList_GetImageCount( himl );
  305. ::ImageList_AddMasked( himl, (HBITMAP)hBMP, crMask );
  306. }
  307. hr = S_OK;
  308. __HCP_FUNC_CLEANUP;
  309. if(hBMP) ::DeleteObject( hBMP );
  310. __HCP_FUNC_EXIT(hr);
  311. }
  312. ////////////////////////////////////////////////////////////////////////////////
  313. CPCHToolBar::CPCHToolBar()
  314. {
  315. m_bWindowOnly = TRUE; // Inherited from CComControlBase
  316. m_parent = NULL; // CPCHHelpCenterExternal* m_parent;
  317. m_hwndRB = NULL; // HWND m_hwndRB;
  318. m_hwndTB = NULL; // HWND m_hwndTB;
  319. //
  320. // Config m_cfg;
  321. m_fLoaded = false; // bool m_fLoaded;
  322. {
  323. SIZE ptIdeal;
  324. ptIdeal.cx = 30;
  325. ptIdeal.cy = 30;
  326. AtlPixelToHiMetric( &ptIdeal, &m_sizeExtent );
  327. }
  328. }
  329. CPCHToolBar::~CPCHToolBar()
  330. {
  331. }
  332. STDMETHODIMP CPCHToolBar::SetClientSite( IOleClientSite *pClientSite )
  333. {
  334. CComQIPtr<IServiceProvider> sp = pClientSite;
  335. if(m_parent)
  336. {
  337. CComQIPtr<IPCHHelpCenterExternalPrivate> hcep = m_parent;
  338. if(hcep)
  339. {
  340. hcep->RegisterForMessages( this, /*fRemove*/true );
  341. }
  342. }
  343. MPC::Release( (IUnknown*&)m_parent );
  344. if(sp && SUCCEEDED(sp->QueryService( SID_SElementBehaviorFactory, IID_IPCHHelpCenterExternal, (void **)&m_parent )))
  345. {
  346. CComQIPtr<IPCHHelpCenterExternalPrivate> hcep = m_parent;
  347. if(hcep)
  348. {
  349. hcep->RegisterForMessages( this, /*fRemove*/false );
  350. }
  351. }
  352. return IOleObjectImpl<CPCHToolBar>::SetClientSite( pClientSite );
  353. }
  354. STDMETHODIMP CPCHToolBar::GetExtent( DWORD dwDrawAspect, SIZEL *psizel )
  355. {
  356. if(SUCCEEDED(Config_Load()))
  357. {
  358. UpdateSize();
  359. if(m_cfg.m_lWidth || m_cfg.m_lHeight)
  360. {
  361. SIZE ptIdeal;
  362. SIZEL sizeExtent;
  363. ptIdeal.cx = m_cfg.m_lWidth;
  364. ptIdeal.cy = m_cfg.m_lHeight;
  365. AtlPixelToHiMetric( &ptIdeal, &sizeExtent );
  366. if(m_cfg.m_lWidth != 0) m_sizeExtent.cx = sizeExtent.cx;
  367. if(m_cfg.m_lHeight != 0) m_sizeExtent.cy = sizeExtent.cy;
  368. }
  369. }
  370. return IOleObjectImpl<CPCHToolBar>::GetExtent( dwDrawAspect, psizel );
  371. }
  372. /////////////////////////////////////////////////////////////////////////////
  373. static bool local_IsButtonObscured( /*[in]*/ HWND hwnd, /*[in]*/ RECT& rcSrc, /*[in]*/ UINT_PTR iCmd )
  374. {
  375. UINT_PTR iButton = (UINT_PTR)::SendMessage( hwnd, TB_COMMANDTOINDEX, iCmd, 0 );
  376. if(iButton != -1)
  377. {
  378. RECT rcItem;
  379. if(::SendMessage( hwnd, TB_GETITEMRECT, iButton, (LPARAM)&rcItem ))
  380. {
  381. if(rcSrc.left <= rcItem.left &&
  382. rcSrc.right >= rcItem.right &&
  383. rcSrc.top <= rcItem.top &&
  384. rcSrc.bottom >= rcItem.bottom )
  385. {
  386. return false;
  387. }
  388. }
  389. }
  390. return true;
  391. }
  392. BOOL CPCHToolBar::ProcessWindowMessage( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lResult, DWORD dwMsgMapID )
  393. {
  394. lResult = 0;
  395. switch(uMsg)
  396. {
  397. case WM_THEMECHANGED:
  398. case WM_SYSCOLORCHANGE:
  399. UpdateSize();
  400. break;
  401. case WM_SETTINGCHANGE:
  402. // (weizhao) Relay message to the toolbar control for appropriate handling of settings change.
  403. ::SendMessageW( m_hwndTB, uMsg, wParam, lParam);
  404. UpdateSize();
  405. break;
  406. case WM_NOTIFYFORMAT:
  407. if(lParam == NF_QUERY)
  408. {
  409. lResult = NFR_UNICODE;
  410. return TRUE;
  411. }
  412. break;
  413. case WM_CREATE:
  414. if(SUCCEEDED(Rebar_Create ()) &&
  415. SUCCEEDED(Toolbar_Create()) &&
  416. SUCCEEDED(Rebar_AddBand ()) )
  417. {
  418. ;
  419. }
  420. return TRUE;
  421. case WM_SIZE:
  422. {
  423. int nWidth = LOWORD(lParam); // width of client area
  424. int nHeight = HIWORD(lParam); // height of client area
  425. if(m_hwndRB)
  426. {
  427. RECT rc;
  428. int nClientWidth;
  429. int nClientHeight;
  430. ::GetClientRect( m_hwndRB, &rc );
  431. nClientWidth = rc.right - rc.left;
  432. nClientHeight = rc.bottom - rc.top;
  433. // resize the width of the toolbar
  434. if(nClientWidth != nWidth ||
  435. nClientHeight != nHeight )
  436. {
  437. ::SetWindowPos( m_hwndRB, NULL, 0, 0, nWidth, nHeight, SWP_NOZORDER|SWP_NOACTIVATE );
  438. }
  439. }
  440. if(m_parent) (void)m_parent->RefreshLayout();
  441. }
  442. return TRUE;
  443. case WM_DESTROY:
  444. m_hwndRB = NULL;
  445. m_hwndTB = NULL;
  446. return TRUE;
  447. case WM_COMMAND:
  448. switch( HIWORD(wParam) )
  449. {
  450. case BN_CLICKED:
  451. (void)Fire_onCommand( LOWORD(wParam) );
  452. return TRUE;
  453. }
  454. break;
  455. case WM_SYSCOMMAND:
  456. {
  457. for(Config::ButtonIter it = m_cfg.m_lstButtons.begin(); it != m_cfg.m_lstButtons.end(); it++)
  458. {
  459. Button& bt = *it;
  460. if(bt.m_idCmd == LOWORD(wParam))
  461. {
  462. (void)Fire_onCommand( LOWORD(wParam) );
  463. return TRUE;
  464. }
  465. }
  466. }
  467. break;
  468. case WM_NOTIFY:
  469. switch( ((LPNMHDR)lParam)->code )
  470. {
  471. case TBN_GETINFOTIPW:
  472. (void)OnTooltipRequest( (int)wParam, (LPNMTBGETINFOTIPW)lParam );
  473. return TRUE;
  474. case TBN_GETDISPINFOW:
  475. (void)OnDispInfoRequest( (int)wParam, (LPNMTBDISPINFOW)lParam );
  476. return TRUE;
  477. case TBN_DROPDOWN:
  478. (void)OnDropDown( (int)wParam, (LPNMTOOLBAR)lParam );
  479. return TRUE;
  480. case RBN_CHEVRONPUSHED:
  481. (void)OnChevron( (int)wParam, (LPNMREBARCHEVRON)lParam );
  482. return TRUE;
  483. }
  484. break;
  485. case WM_SYSCHAR:
  486. if(ProcessAccessKey( uMsg, wParam, lParam ))
  487. {
  488. lResult = TRUE;
  489. return TRUE;
  490. }
  491. break;
  492. }
  493. return CComControl<CPCHToolBar>::ProcessWindowMessage( hWnd, uMsg, wParam, lParam, lResult, dwMsgMapID );
  494. }
  495. BOOL CPCHToolBar::ProcessAccessKey( UINT uMsg, WPARAM wParam, LPARAM lParam )
  496. {
  497. if(m_hwndTB && ::IsWindowVisible( m_hwndTB ))
  498. {
  499. WCHAR rgBuf1[2]; rgBuf1[0] = (WCHAR)wParam; rgBuf1[1] = 0; ::CharUpperW( rgBuf1 );
  500. WCHAR rgBuf2[2]; rgBuf2[1] = 0;
  501. for(Config::ButtonIter it = m_cfg.m_lstButtons.begin(); it != m_cfg.m_lstButtons.end(); it++)
  502. {
  503. Button& bt = *it;
  504. rgBuf2[0] = bt.m_wch; ::CharUpperW( rgBuf2 );
  505. if(rgBuf1[0] == rgBuf2[0])
  506. {
  507. LRESULT lState = ::SendMessageW( m_hwndTB, TB_GETSTATE, bt.m_idCmd, 0 );
  508. if(!(lState & TBSTATE_HIDDEN ) &&
  509. (lState & TBSTATE_ENABLED) )
  510. {
  511. // (tnoonan) - it feels kinda cheesy to send mouse messages, but
  512. // I don't know of a cleaner way which will accomplish what we
  513. // want (like deal with split buttons, mutually exclusive
  514. // buttons, etc.).
  515. RECT rc;
  516. ::SendMessage( m_hwndTB, TB_GETRECT, bt.m_idCmd, (LPARAM)&rc );
  517. ::SendMessage( m_hwndTB, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(rc.left, rc.top) );
  518. ::SendMessage( m_hwndTB, WM_LBUTTONUP , 0 , MAKELONG(rc.left, rc.top) );
  519. return TRUE;
  520. }
  521. }
  522. }
  523. }
  524. return FALSE;
  525. }
  526. /////////////////////////////////////////////////////////////////////////////
  527. HRESULT CPCHToolBar::Fire_onCommand( /*[in]*/ Button* bt )
  528. {
  529. if(bt)
  530. {
  531. CComVariant pvars[2];
  532. pvars[1] = this;
  533. pvars[0] = bt->m_strID.c_str();
  534. (void)FireAsync_Generic( DISPID_PCH_TBE__ONCOMMAND, pvars, ARRAYSIZE( pvars ), NULL );
  535. }
  536. return S_OK;
  537. }
  538. HRESULT CPCHToolBar::Fire_onCommand( /*[in]*/ UINT_PTR iCmd )
  539. {
  540. return Fire_onCommand( m_cfg.LookupButton( NULL, iCmd ) );
  541. }
  542. ////////////////////
  543. HRESULT CPCHToolBar::OnTooltipRequest( int idCtrl, LPNMTBGETINFOTIPW tool )
  544. {
  545. Button* bt = m_cfg.LookupButton( NULL, tool->iItem );
  546. if(bt)
  547. {
  548. wcsncpy( tool->pszText, bt->m_strToolTip.c_str(), tool->cchTextMax - 1 );
  549. }
  550. return S_OK;
  551. }
  552. HRESULT CPCHToolBar::OnDispInfoRequest( int idCtrl, LPNMTBDISPINFOW info )
  553. {
  554. Button* bt = m_cfg.LookupButton( NULL, info->idCommand );
  555. if(bt)
  556. {
  557. if(info->dwMask & TBNF_IMAGE)
  558. {
  559. info->iImage = bt->m_iImage_Normal;
  560. }
  561. }
  562. return S_OK;
  563. }
  564. HRESULT CPCHToolBar::OnDropDown( int idCtrl, LPNMTOOLBAR tool )
  565. {
  566. __HCP_FUNC_ENTRY( "CPCHToolBar::OnDropDown" );
  567. HRESULT hr;
  568. Button* bt = m_cfg.LookupButton( NULL, tool->iItem );
  569. HMENU hMenu = NULL;
  570. if(bt)
  571. {
  572. if(m_parent)
  573. {
  574. CPCHHelpSession* hs = m_parent->HelpSession();
  575. if(hs && hs->IsTravelling() == false)
  576. {
  577. CPCHHelpSessionItem* item = hs->Current();
  578. if(item)
  579. {
  580. int iCount = 0;
  581. __MPC_EXIT_IF_CALL_RETURNS_NULL(hr, (hMenu = ::CreatePopupMenu()));
  582. while((item = (bt->m_dwType == TYPE_back ? item->Previous() : item->Next())))
  583. {
  584. if(iCount++ < HISTORY_MENU__LIMIT)
  585. {
  586. CComBSTR bstrTitle;
  587. __MPC_EXIT_IF_METHOD_FAILS(hr, item->get_Title( &bstrTitle ));
  588. if(bstrTitle.Length() == 0) MPC::LocalizeString( IDS_HELPCTR_HIST_NOTITLE, bstrTitle );
  589. __MPC_EXIT_IF_CALL_RETURNS_FALSE(hr, ::AppendMenuW( hMenu, MF_STRING, iCount, bstrTitle ));
  590. }
  591. }
  592. if(iCount)
  593. {
  594. ::MapWindowPoints( tool->hdr.hwndFrom, HWND_DESKTOP, (LPPOINT)&tool->rcButton, 2 );
  595. iCount = ::TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY,
  596. tool->rcButton.left, tool->rcButton.bottom, 0, m_hWnd, NULL );
  597. if(iCount != 0)
  598. {
  599. if(bt->m_dwType == TYPE_back) hs->Back ( iCount );
  600. else hs->Forward( iCount );
  601. }
  602. }
  603. }
  604. }
  605. }
  606. }
  607. hr = S_OK;
  608. __HCP_FUNC_CLEANUP;
  609. if(hMenu) ::DestroyMenu( hMenu );
  610. __HCP_FUNC_EXIT(hr);
  611. }
  612. HRESULT CPCHToolBar::OnChevron( int idCtrl, LPNMREBARCHEVRON chev )
  613. {
  614. __HCP_FUNC_ENTRY( "CPCHToolBar::OnChevron" );
  615. HRESULT hr;
  616. RECT rcSrc;
  617. HMENU hMenu = NULL;
  618. bool fFound = false;
  619. __MPC_EXIT_IF_CALL_RETURNS_NULL(hr, (hMenu = ::CreatePopupMenu()));
  620. ::GetClientRect( m_hwndTB, &rcSrc );
  621. for(Config::ButtonIter it = m_cfg.m_lstButtons.begin(); it != m_cfg.m_lstButtons.end(); it++)
  622. {
  623. Button& bt = *it;
  624. if(bt.m_fVisible && bt.m_fEnabled && bt.m_strText.size() && local_IsButtonObscured( m_hwndTB, rcSrc, bt.m_idCmd ))
  625. {
  626. __MPC_EXIT_IF_CALL_RETURNS_FALSE(hr, ::AppendMenuW( hMenu, MF_STRING, bt.m_idCmd, bt.m_strText.c_str() ));
  627. fFound = true;
  628. }
  629. }
  630. if(fFound)
  631. {
  632. int iSelected;
  633. ::MapWindowPoints( chev->hdr.hwndFrom, HWND_DESKTOP, (LPPOINT)&chev->rc, 2 );
  634. iSelected = ::TrackPopupMenu( hMenu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD | TPM_NONOTIFY, chev->rc.left, chev->rc.bottom, 0, m_hWnd, NULL );
  635. if(iSelected != 0)
  636. {
  637. (void)Fire_onCommand( iSelected );
  638. }
  639. }
  640. hr = S_OK;
  641. __HCP_FUNC_CLEANUP;
  642. if(hMenu) ::DestroyMenu( hMenu );
  643. __HCP_FUNC_EXIT(hr);
  644. }
  645. ////////////////////////////////////////////////////////////////////////////////
  646. void CPCHToolBar::UpdateSize()
  647. {
  648. if(m_hwndTB)
  649. {
  650. SIZE ptIdeal;
  651. SIZEL sizeExtent;
  652. m_cfg.UpdateSize( m_hwndTB, m_hwndRB, ptIdeal );
  653. AtlPixelToHiMetric( &ptIdeal, &sizeExtent );
  654. if(m_cfg.m_lHeight == 0) m_sizeExtent.cy = sizeExtent.cy;
  655. {
  656. CComPtr<IHTMLElement> elem;
  657. CComQIPtr<IHTMLElement2> elem2;
  658. if(SUCCEEDED(FindElementThroughThunking( elem )) && (elem2 = elem))
  659. {
  660. CComPtr<IHTMLCurrentStyle> style1;
  661. CComPtr<IHTMLStyle> style2;
  662. if(SUCCEEDED(elem2->get_currentStyle( &style1 )) && style1 &&
  663. SUCCEEDED(elem ->get_style ( &style2 )) && style2 )
  664. {
  665. CComVariant v1;
  666. CComVariant v2;
  667. WCHAR rgBuf[64]; swprintf( rgBuf, L"%ldpx", ptIdeal.cy );
  668. v2 = rgBuf;
  669. style1->get_height( &v1 );
  670. if(v1 != v2)
  671. {
  672. style2->put_height( v2 );
  673. }
  674. }
  675. }
  676. }
  677. if(m_parent && m_parent->Window())
  678. {
  679. HMENU hSys = NULL;
  680. for(Config::ButtonIter it = m_cfg.m_lstButtons.begin(); it != m_cfg.m_lstButtons.end(); it++)
  681. {
  682. Button& bt = *it;
  683. if(bt.m_fSystemMenu)
  684. {
  685. if(!hSys)
  686. {
  687. HMENU hTop;
  688. MENUITEMINFO mii;
  689. CComBSTR bstrTitle; MPC::LocalizeString( IDS_HELPCTR_SYSMENU_GOTO, bstrTitle );
  690. ::ZeroMemory( &mii, sizeof(mii) );
  691. mii.cbSize = sizeof(mii);
  692. mii.fMask = MIIM_ID | MIIM_STRING | MIIM_SUBMENU;
  693. mii.fType = MFT_STRING;
  694. mii.wID = 1;
  695. mii.dwTypeData = bstrTitle;
  696. mii.hSubMenu = hSys = ::CreatePopupMenu();
  697. (void) ::GetSystemMenu( m_parent->Window(), TRUE );
  698. hTop = ::GetSystemMenu( m_parent->Window(), FALSE );
  699. ::AppendMenuW ( hTop, MF_SEPARATOR, 0, 0 );
  700. ::InsertMenuItem( hTop, ::GetMenuItemCount(hTop), TRUE, &mii );
  701. }
  702. if(hSys)
  703. {
  704. switch(bt.m_dwType)
  705. {
  706. case TYPE_separator:
  707. (void)::AppendMenuW( hSys, MF_SEPARATOR, 0, 0 );
  708. break;
  709. case TYPE_back :
  710. case TYPE_forward:
  711. case TYPE_generic:
  712. (void)::AppendMenuW( hSys, MF_STRING | (bt.m_fEnabled ? 0 : MF_GRAYED), bt.m_idCmd, bt.m_strText.c_str() );
  713. break;
  714. }
  715. }
  716. }
  717. }
  718. }
  719. }
  720. }
  721. void CPCHToolBar::Config_Clear()
  722. {
  723. m_cfg.Reset();
  724. m_fLoaded = false;
  725. }
  726. HRESULT CPCHToolBar::Config_Load()
  727. {
  728. __HCP_FUNC_ENTRY( "CPCHToolBar::Config_Load" );
  729. HRESULT hr;
  730. if(!m_fLoaded)
  731. {
  732. CComPtr<IServiceProvider> sp;
  733. CComPtr<IHTMLDocument2> doc2;
  734. CComPtr<IHTMLDocument3> doc3;
  735. CComBSTR bstrBase;
  736. CComBSTR bstrDir;
  737. __MPC_EXIT_IF_METHOD_FAILS(hr, m_spAmbientDispatch->QueryInterface( IID_IServiceProvider, (void**)&sp ));
  738. __MPC_EXIT_IF_METHOD_FAILS(hr, sp->QueryService( SID_SContainerDispatch, IID_IHTMLDocument2, (void **)&doc2 ));
  739. __MPC_EXIT_IF_METHOD_FAILS(hr, doc2->get_URL( &bstrBase ));
  740. __MPC_EXIT_IF_METHOD_FAILS(hr, sp->QueryService( SID_SContainerDispatch, IID_IHTMLDocument3, (void **)&doc3 ));
  741. __MPC_EXIT_IF_METHOD_FAILS(hr, doc3->get_dir( &bstrDir ));
  742. Config_Clear();
  743. __MPC_EXIT_IF_METHOD_FAILS(hr, m_cfg.Load( bstrBase, m_bstrDefinition, bstrDir ));
  744. m_fLoaded = true;
  745. }
  746. hr = S_OK;
  747. __HCP_FUNC_CLEANUP;
  748. if(FAILED(hr))
  749. {
  750. Config_Clear();
  751. }
  752. __HCP_FUNC_EXIT(hr);
  753. }
  754. HRESULT CPCHToolBar::Toolbar_Create()
  755. {
  756. __HCP_FUNC_ENTRY( "CPCHToolBar::Toolbar_Create" );
  757. HRESULT hr;
  758. if(FAILED(Config_Load()))
  759. {
  760. ; // Empty toolbar...
  761. }
  762. __MPC_EXIT_IF_METHOD_FAILS(hr, Rebar_Create());
  763. if(m_hwndRB && !m_hwndTB)
  764. {
  765. DWORD dwStyle = WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS |
  766. TBSTYLE_TOOLTIPS | TBSTYLE_FLAT |
  767. CCS_NORESIZE | CCS_NODIVIDER | CCS_NOPARENTALIGN;
  768. DWORD dwStyleEx = TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS | TBSTYLE_EX_DOUBLEBUFFER;
  769. if(m_cfg.m_mode == TB_SELECTED)
  770. {
  771. dwStyle |= TBSTYLE_LIST;
  772. }
  773. m_hwndTB = ::CreateWindowEx( WS_EX_TOOLWINDOW, TOOLBARCLASSNAME, NULL, dwStyle, 0, 0, 0, 0, m_hwndRB, NULL, NULL, NULL );
  774. if(m_hwndTB == NULL)
  775. {
  776. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ::GetLastError());
  777. }
  778. ::SendMessageW( m_hwndTB, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON) , 0 );
  779. ::SendMessageW( m_hwndTB, TB_SETEXTENDEDSTYLE, dwStyleEx , dwStyleEx );
  780. ::SendMessageW( m_hwndTB, TB_SETMAXTEXTROWS , 1 , 0 );
  781. ::SendMessageW( m_hwndTB, TB_SETDROPDOWNGAP , ::GetSystemMetrics( SM_CXEDGE ) / 2, 0 );
  782. ::SendMessageW( m_hwndTB, CCM_SETVERSION , COMCTL32_VERSION , 0 );
  783. __MPC_EXIT_IF_METHOD_FAILS(hr, m_cfg.CreateButtons( m_hwndTB ));
  784. }
  785. hr = S_OK;
  786. __HCP_FUNC_CLEANUP;
  787. __HCP_FUNC_EXIT(hr);
  788. }
  789. HRESULT CPCHToolBar::Rebar_Create()
  790. {
  791. __HCP_FUNC_ENTRY( "CPCHToolBar::Rebar_Create" );
  792. HRESULT hr;
  793. if(m_hWnd && !m_hwndRB)
  794. {
  795. DWORD dwStyle = RBS_VARHEIGHT | RBS_BANDBORDERS | RBS_AUTOSIZE |
  796. WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS |
  797. CCS_NODIVIDER | CCS_NOPARENTALIGN;
  798. DWORD dwStyleEx = WS_EX_TOOLWINDOW;
  799. if(m_cfg.m_fRTL) dwStyleEx |= WS_EX_LAYOUTRTL;
  800. m_hwndRB = ::CreateWindowEx( dwStyleEx, REBARCLASSNAME, NULL, dwStyle, 0, 0, 24, 24, m_hWnd, NULL, NULL, NULL );
  801. if(m_hwndRB == NULL)
  802. {
  803. __MPC_SET_WIN32_ERROR_AND_EXIT(hr, ::GetLastError());
  804. }
  805. ::SendMessageW( m_hwndRB, RB_SETTEXTCOLOR, 0 , CLR_DEFAULT );
  806. ::SendMessageW( m_hwndRB, RB_SETBKCOLOR , 0 , CLR_DEFAULT );
  807. ::SendMessageW( m_hwndRB, CCM_SETVERSION , COMCTL32_VERSION, 0 );
  808. }
  809. hr = S_OK;
  810. __HCP_FUNC_CLEANUP;
  811. __HCP_FUNC_EXIT(hr);
  812. }
  813. HRESULT CPCHToolBar::Rebar_AddBand()
  814. {
  815. __HCP_FUNC_ENTRY( "CPCHToolBar::Rebar_AddBand" );
  816. HRESULT hr;
  817. if(m_hwndRB && m_hwndTB)
  818. {
  819. REBARBANDINFOW rbbi; ::ZeroMemory( &rbbi, sizeof(rbbi) );
  820. SIZE ptIdeal;
  821. m_cfg.UpdateSize( m_hwndTB, NULL, ptIdeal );
  822. rbbi.cbSize = sizeof(rbbi);
  823. rbbi.fMask = RBBIM_ID | RBBIM_CHILDSIZE | RBBIM_CHILD | RBBIM_SIZE | RBBIM_STYLE | RBBIM_IDEALSIZE;
  824. rbbi.fStyle = RBBS_NOGRIPPER | RBBS_USECHEVRON/* | RBBS_CHILDEDGE | RBBS_FIXEDBMP*/;
  825. rbbi.hwndChild = m_hwndTB;
  826. rbbi.cx = 0;
  827. rbbi.cxMinChild = 0;
  828. rbbi.cyMinChild = ptIdeal.cy;
  829. rbbi.cxIdeal = ptIdeal.cx;
  830. ::SendMessageW( m_hwndRB, RB_INSERTBANDW, 0, (LPARAM)&rbbi );
  831. ::SendMessageW( m_hwndRB, RB_SHOWBAND , 0, (LPARAM)TRUE );
  832. }
  833. hr = S_OK;
  834. __HCP_FUNC_EXIT(hr);
  835. }
  836. /////////////////////////////////////////////////////////////////////////////
  837. ////#define CH_PREFIX TEXT('&')
  838. ////
  839. ////static WCHAR local_GetAccelerator( LPCWSTR sz, BOOL bUseDefault )
  840. ////{
  841. //// WCHAR ch = (TCHAR)-1;
  842. //// LPCWSTR szAccel = sz;
  843. ////
  844. //// // then prefixes are allowed.... see if it has one
  845. //// do
  846. //// {
  847. //// szAccel = StrChrW( szAccel, CH_PREFIX );
  848. //// if(szAccel)
  849. //// {
  850. //// szAccel++;
  851. ////
  852. //// // handle having &&
  853. //// if(*szAccel != CH_PREFIX)
  854. //// {
  855. //// ch = *szAccel;
  856. //// }
  857. //// else
  858. //// {
  859. //// szAccel++;
  860. //// }
  861. //// }
  862. //// } while (szAccel && (ch == (WCHAR)-1));
  863. ////
  864. //// if((ch == (WCHAR)-1) && bUseDefault)
  865. //// {
  866. //// ch = *sz;
  867. //// }
  868. ////
  869. //// return ch;
  870. ////}
  871. BOOL CPCHToolBar::PreTranslateAccelerator( LPMSG pMsg, HRESULT& hRet )
  872. {
  873. // Give toolbar a chance.
  874. if(m_hwndTB)
  875. {
  876. if(::SendMessage( m_hwndTB, TB_TRANSLATEACCELERATOR, 0, (LPARAM)pMsg )) return TRUE;
  877. if(::SendMessage( m_hwndTB, WM_FORWARDMSG, 0, (LPARAM)pMsg )) return TRUE;
  878. //// if(pMsg->message == WM_SYSCHAR)
  879. //// {
  880. //// UINT idBtn;
  881. ////
  882. //// if(::SendMessage( m_hwndTB, TB_MAPACCELERATOR, pMsg->wParam, (LPARAM)&idBtn ))
  883. //// {
  884. //// WCHAR rgButtonText[MAX_PATH];
  885. ////
  886. //// // comctl says this one is the one, let's make sure we aren't getting
  887. //// // one of the unwanted "use the first letter" accelerators that it
  888. //// // will return.
  889. //// if((::SendMessage( m_hwndTB, TB_GETBUTTONTEXTW, idBtn, (LPARAM)rgButtonText ) > 0) &&
  890. //// (local_GetAccelerator( rgButtonText, FALSE ) != (WCHAR)-1))
  891. //// {
  892. //// // (tnoonan) - it feels kinda cheesy to send mouse messages, but
  893. //// // I don't know of a cleaner way which will accomplish what we
  894. //// // want (like deal with split buttons, mutually exclusive
  895. //// // buttons, etc.).
  896. //// RECT rc;
  897. ////
  898. //// ::SendMessage( m_hwndTB, TB_GETRECT, idBtn, (LPARAM)&rc );
  899. ////
  900. //// ::SendMessage( m_hwndTB, WM_LBUTTONDOWN, MK_LBUTTON, MAKELONG(rc.left, rc.top) );
  901. //// ::SendMessage( m_hwndTB, WM_LBUTTONUP , 0 , MAKELONG(rc.left, rc.top) );
  902. ////
  903. //// return TRUE;
  904. //// }
  905. //// }
  906. //// }
  907. }
  908. return CComControl<CPCHToolBar>::PreTranslateAccelerator( pMsg, hRet );
  909. }
  910. ////////////////////////////////////////////////////////////////////////////////
  911. ////////////////////////////////////////////////////////////////////////////////
  912. STDMETHODIMP CPCHToolBar::get_Definition( /*[out, retval]*/ BSTR *pVal )
  913. {
  914. return MPC::GetBSTR( m_bstrDefinition, pVal );
  915. }
  916. STDMETHODIMP CPCHToolBar::put_Definition( /*[in]*/ BSTR newVal )
  917. {
  918. Config_Clear();
  919. return MPC::PutBSTR( m_bstrDefinition, newVal );
  920. }
  921. STDMETHODIMP CPCHToolBar::get_Mode( /*[out, retval]*/ TB_MODE *pVal )
  922. {
  923. if(!pVal) return E_POINTER;
  924. *pVal = m_cfg.m_mode;
  925. return S_OK;
  926. }
  927. STDMETHODIMP CPCHToolBar::put_Mode( /*[in]*/ TB_MODE newVal )
  928. {
  929. bool fRecreate = false;
  930. switch(newVal)
  931. {
  932. case TB_ALL :
  933. case TB_SELECTED:
  934. case TB_NONE : break;
  935. default: return E_INVALIDARG;
  936. }
  937. //
  938. // Adjust style.
  939. //
  940. if(m_hwndRB && (m_cfg.m_mode != newVal))
  941. {
  942. ::DestroyWindow( m_hwndRB );
  943. m_hwndRB = NULL;
  944. m_hwndTB = NULL;
  945. fRecreate = true;
  946. }
  947. m_cfg.m_mode = newVal;
  948. if(fRecreate)
  949. {
  950. if(SUCCEEDED(Rebar_Create ()) &&
  951. SUCCEEDED(Toolbar_Create()) &&
  952. SUCCEEDED(Rebar_AddBand ()) &&
  953. m_hwndRB )
  954. {
  955. RECT rc;
  956. ::GetClientRect( m_hWnd, &rc );
  957. ::SetWindowPos( m_hwndRB, NULL, 0, 0, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER|SWP_NOACTIVATE );
  958. UpdateSize();
  959. }
  960. }
  961. return S_OK;
  962. }
  963. STDMETHODIMP CPCHToolBar::SetState( /*[in]*/ BSTR bstrText, /*[in]*/ VARIANT_BOOL fEnabled )
  964. {
  965. if(SUCCEEDED(Config_Load()))
  966. {
  967. Button* bt = m_cfg.LookupButton( bstrText, -1 );
  968. if(bt)
  969. {
  970. bt->m_fEnabled = (fEnabled == VARIANT_TRUE);
  971. bt->UpdateState( m_hwndTB );
  972. UpdateSize();
  973. }
  974. }
  975. return S_OK;
  976. }
  977. STDMETHODIMP CPCHToolBar::SetVisibility( /*[in]*/ BSTR bstrText, /*[in]*/ VARIANT_BOOL fVisible )
  978. {
  979. if(SUCCEEDED(Config_Load()))
  980. {
  981. Button* bt = m_cfg.LookupButton( bstrText, -1 );
  982. if(bt)
  983. {
  984. bt->m_fVisible = (fVisible == VARIANT_TRUE);
  985. bt->UpdateState( m_hwndTB );
  986. UpdateSize();
  987. }
  988. }
  989. return S_OK;
  990. }
  991. ////////////////////////////////////////////////////////////////////////////////
  992. //
  993. // This is ugly, but unless we find a better way to get the HTML element for our site it's our only hope..
  994. //
  995. HRESULT CPCHToolBar::FindElementThroughThunking( /*[out]*/ CComPtr<IHTMLElement>& elem )
  996. {
  997. __HCP_FUNC_ENTRY( "CPCHToolBar::FindElementThroughThunking" );
  998. HRESULT hr;
  999. CComPtr<IServiceProvider> sp;
  1000. CComPtr<IHTMLDocument2> doc2;
  1001. CComPtr<IHTMLElementCollection> coll;
  1002. MPC::HTML::IHTMLElementList lst;
  1003. elem.Release();
  1004. //
  1005. // Get Document element.
  1006. //
  1007. __MPC_EXIT_IF_METHOD_FAILS(hr, m_spAmbientDispatch->QueryInterface( IID_IServiceProvider, (void**)&sp ));
  1008. __MPC_EXIT_IF_METHOD_FAILS(hr, sp->QueryService( SID_SContainerDispatch, IID_IHTMLDocument2, (void **)&doc2 ));
  1009. //
  1010. // Get list of OBJECT elements.
  1011. //
  1012. MPC_SCRIPTHELPER_GET__DIRECT__NOTNULL(coll, doc2, all);
  1013. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::HTML::EnumerateCollection( lst, coll, L"<OBJECT" ));
  1014. //
  1015. // Try to locate ourself.
  1016. //
  1017. for(MPC::HTML::IHTMLElementIter it=lst.begin(); it != lst.end(); it++)
  1018. {
  1019. CComQIPtr<IPCHToolBarPrivate> tb = *it;
  1020. if(tb && SUCCEEDED(tb->SameObject( this )))
  1021. {
  1022. elem = *it;
  1023. break;
  1024. }
  1025. }
  1026. hr = S_OK;
  1027. __HCP_FUNC_CLEANUP;
  1028. MPC::ReleaseAll( lst );
  1029. __HCP_FUNC_EXIT(hr);
  1030. }