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.

10767 lines
343 KiB

  1. #include "priv.h"
  2. #include "sccls.h"
  3. #include <varutil.h>
  4. #include "itbdrop.h"
  5. #include <urlhist.h>
  6. #include "autocomp.h"
  7. #include "itbar.h"
  8. #include "address.h"
  9. #include <winbase.h>
  10. #include "basebar.h"
  11. #include "shbrowse.h"
  12. #include "brand.h"
  13. #include "resource.h"
  14. #include "theater.h"
  15. #include "browmenu.h"
  16. #include "util.h"
  17. #include "droptgt.h"
  18. #include "legacy.h"
  19. #include "apithk.h"
  20. #include "shbrows2.h"
  21. #include "stdenum.h"
  22. #include "iehelpid.h"
  23. #include <tb_ids.h>
  24. #include "mediautil.h"
  25. #define WANT_CBANDSITE_CLASS
  26. #include "bandsite.h"
  27. #include "schedule.h"
  28. #include "uemapp.h"
  29. #include "mluisupp.h"
  30. #ifdef UNIX
  31. extern "C" const GUID CLSID_MsgBand;
  32. #endif
  33. // The edit button hackery needs to be moved to shdocvw. This define identifies this code.
  34. #define EDIT_HACK
  35. // Offset of the comctl32 default bitmaps
  36. #define OFFSET_HIST (MAX_TB_BUTTONS - 1 + 0) // 15
  37. #define OFFSET_STD (MAX_TB_BUTTONS - 1 + 6) // 21
  38. #define OFFSET_VIEW (MAX_TB_BUTTONS - 1 + 21) // 36
  39. // This is the offset in the toolbar for the Shell glyphs and the Shell toolbar labels
  40. #define SHELLTOOLBAR_OFFSET (MAX_TB_BUTTONS - 1 + 1) // 16
  41. #define FONTGLYPH_OFFSET (MAX_TB_BUTTONS - 1 + 38) // 53
  42. #define BRIEFCASEGLYPH_OFFSET (MAX_TB_BUTTONS - 1 + 34) // 49
  43. #define RNAUIGLYPH_OFFSET (MAX_TB_BUTTONS - 1 + 36) // 51
  44. #define WEBCHECKGLYPH_OFFSET (MAX_TB_BUTTONS - 1 + 42) // 57
  45. #ifdef EDIT_HACK
  46. #define EDITGLYPH_OFFSET (9)
  47. #endif
  48. #define IDT_UPDATETOOLBAR 0x1
  49. #define TIMEOUT_UPDATETOOLBAR 400
  50. const GUID CLSID_Separator = { 0x67077B90L, 0x4F9D, 0x11D0, 0xB8, 0x84, 0x00, 0xAA, 0x00, 0xB6, 0x01, 0x04 };
  51. extern HRESULT VariantClearLazy(VARIANTARG *pvarg);
  52. // How many CT_TABLE structures to allocated at a time.
  53. #define TBBMPLIST_CHUNK 5
  54. #define MAX_EXTERNAL_BAND_NAME_LEN 64
  55. #define MAX_TB_COMPRESSED_WIDTH 42
  56. // 16 is added to the the MAX_TB defines. This is added through the strings
  57. // in the RC file. This is done so that the localization folks can increase
  58. // or decrease the width of the toolbar buttons
  59. #define MAX_TB_WIDTH_LORES 38
  60. #define MAX_TB_WIDTH_HIRES 60
  61. // Dimensions of Coolbar Glyphs ..
  62. #define TB_SMBMP_CX 16
  63. #define TB_SMBMP_CY 16
  64. #define TB_BMP_CX 20
  65. #define TB_BMP_CY 20
  66. #define TB_BMP_CX_ALPHABITMAP 24
  67. #define TB_BMP_CY_ALPHABITMAP 24
  68. int g_iToolBarLargeIconWidth = TB_BMP_CX;
  69. int g_iToolBarLargeIconHeight = TB_BMP_CY;
  70. #define CX_SEPARATOR 6 // we override toolbar control's default separator width of 8
  71. #define DM_TBSITE 0
  72. #define DM_TBCMD 0
  73. #define DM_TBREF TF_SHDREF
  74. #define DM_LAYOUT 0
  75. #define DM_ITBAR 0
  76. #define TF_TBCUST 0x01000000
  77. #if CBIDX_LAST != 5
  78. #error Expected CBIDX_LAST to have value of 5
  79. #endif
  80. #if (FCIDM_EXTERNALBANDS_LAST - FCIDM_EXTERNALBANDS_FIRST + 1) < MAXEXTERNALBANDS
  81. #error Insufficient range for FCIDM_EXTERNALBANDS_FIRST to FCIDM_EXTERNALBANDS_LAST
  82. #endif
  83. __inline UINT EXTERNALBAND_VBF_BIT(UINT uiBandExt)
  84. {
  85. ASSERT(uiBandExt < MAXEXTERNALBANDS);
  86. // Formula: take 1, shift left by uiBandExt + 16
  87. // => a bit in range (0x80000000, 0x00010000)
  88. UINT uBit = 1 << (uiBandExt + 16);
  89. ASSERT(uBit & VBF_EXTERNALBANDS);
  90. return uBit;
  91. }
  92. __inline BOOL IS_EXTERNALBAND(int idBand)
  93. {
  94. return (InRange(idBand, CBIDX_EXTERNALFIRST, CBIDX_EXTERNALLAST));
  95. }
  96. __inline int MAP_TO_EXTERNAL(int idBand)
  97. {
  98. ASSERT(IS_EXTERNALBAND(idBand));
  99. // CBIDX_LAST is one-based, mapping is zero-based
  100. return (idBand - (1 + CBIDX_LAST));
  101. }
  102. // maximum number of menu items in the context menus for back and forward.
  103. #define MAX_NAV_MENUITEMS 9
  104. #define DEFAULT_SEARCH_GUID SRCID_SFileSearch //SRCID_SWebSearch
  105. #define SZ_PROP_CUSTDLG TEXT("Itbar custom dialog hwnd")
  106. #define REG_KEY_BANDSTATE TEXT("Software\\Microsoft\\Internet Explorer\\Toolbar")
  107. // MHTML Editing
  108. #define SZ_IE_DEFAULT_MHTML_EDITOR "Default MHTML Editor"
  109. #define REGSTR_PATH_DEFAULT_MHTML_EDITOR TSZIEPATH TEXT("\\") TEXT(SZ_IE_DEFAULT_MHTML_EDITOR)
  110. #define REGSTR_KEY_DEFAULT_MHTML_EDITOR TEXT(SZ_IE_DEFAULT_MHTML_EDITOR)
  111. DWORD DoNetConnect(HWND hwnd);
  112. DWORD DoNetDisconnect(HWND hwnd);
  113. void _LoadToolbarGlyphs(HWND hwnd, IMLCACHE *pimlCache, int cx, int idBmp,
  114. int iBitmapBaseIndex, BOOL bUseClassicGlyphs, HINSTANCE hInst);
  115. BOOL _UseSmallIcons();
  116. typedef struct tagTBBMP_LIST
  117. {
  118. HINSTANCE hInst;
  119. UINT_PTR uiResID;
  120. UINT uiOffset;
  121. BITBOOL fNormal:1;
  122. BITBOOL fHot:1;
  123. BITBOOL fDisabled:1;
  124. UINT uiCount;
  125. } TBBMP_LIST;
  126. typedef struct tagCMDMAP
  127. {
  128. GUID guidButtonGroup;
  129. UINT nCmdID;
  130. LPARAM lParam; // app's data
  131. } CMDMAP;
  132. typedef struct tagCMDMAPCUSTOMIZE
  133. {
  134. TBBUTTON btn;
  135. CMDMAP cm;
  136. } CMDMAPCUSTOMIZE;
  137. typedef struct {
  138. // the IOleCommandTarget info:
  139. GUID guid;
  140. UINT nCmdID;
  141. UINT fButtonState;
  142. } BUTTONSAVEINFO;
  143. #define TBSI_VERSION 7
  144. typedef struct {
  145. int cVersion;
  146. } TOOLBARSAVEINFO;
  147. typedef struct {
  148. HDSA hdsa;
  149. BITBOOL fAdjust:1;
  150. BITBOOL fDirty:1;
  151. } CUSTOMIZEINFO, *LPCUSTOMIZEINFO;
  152. //Current latest version.
  153. #define CBS_VERSION 17
  154. // NOTE: Be very careful changing COOLBARSAVE because _LoadUpgradeSettings makes
  155. // assumptions about the layout of the structure. To avoid breaking that
  156. // upgrade code, be sure you:
  157. //
  158. // - don't change the order of existing members
  159. // - always add new members to the end of the structure.
  160. // - update _LoadUpgradeSettings if appropriate
  161. //
  162. typedef struct tagCOOLBARSAVE
  163. {
  164. UINT cbVer;
  165. UINT uiMaxTBWidth;
  166. UINT uiMaxQLWidth;
  167. #ifdef UNIX
  168. BITBOOL fUnUsed : 28; // unused
  169. #endif
  170. BITBOOL fVertical : 1; // The bar is oriented vertically
  171. BITBOOL fNoText :1; // "NoText"
  172. BITBOOL fList : 1; // toolbar is TBSTYLE_LIST (text on right) + TBSTYLE_EX_MIXEDBUTTONS
  173. BITBOOL fAutoHide : 1; // Auto hide toolbar in theater mode
  174. BITBOOL fStatusBar : 1; // Status bar in theater mode
  175. BITBOOL fSaveInShellIntegrationMode : 1; // Did we save in shell integration mode?
  176. UINT uiVisible; // "Visible bands"
  177. UINT cyRebar;
  178. BANDSAVE bs[CBANDSMAX];
  179. CLSID aclsidExternalBands[ MAXEXTERNALBANDS ]; // Check classid
  180. CLSID clsidVerticalBar; //clsid of bar persisted within vertical band
  181. CLSID clsidHorizontalBar;
  182. } COOLBARSAVE, *LPCOOLBARSAVE;
  183. //Flags for dwFlags passed to UpdateToolbarDisplay()
  184. #define UTD_TEXTLABEL 0x00000001
  185. #define UTD_VISIBLE 0x00000002
  186. static const TCHAR c_szRegKeyCoolbar[] = TSZIEPATH TEXT("\\Toolbar");
  187. static const TCHAR c_szValueTheater[] = TEXT("Theater");
  188. typedef struct tagFOLDERSEARCHITEM
  189. {
  190. UINT idCmd;
  191. GUID guidSearch;
  192. int iIcon;
  193. WCHAR wszUrl[MAX_URL_STRING];
  194. WCHAR wszName[80]; // friendly name
  195. }FOLDERSEARCHITEM, *LPFOLDERSEARCHITEM;
  196. BOOL NavigateSearchBar(IWebBrowser2 *pwb2, LPCWSTR pwszUrl);
  197. BOOL _GetSearchHKEY(LPGUID lpguidSearch, HKEY *phkey);
  198. #define REG_SZ_STATIC TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FindExtensions\\Static")
  199. #define REG_SZ_SEARCH_GUID TEXT("SearchGUID")
  200. #define REG_SZ_SEARCH_URL TEXT("SearchGUID\\Url")
  201. #define VIEW_OFFSET (SHELLGLYPHS_OFFSET + HIST_MAX + STD_MAX)
  202. #define VIEW_ALLFOLDERS (VIEW_NETCONNECT + 14)
  203. static const TBBUTTON c_tbExplorer[] =
  204. {
  205. // override default toolbar width for separators; iBitmap member of
  206. // TBBUTTON struct is a union of bitmap index & separator width
  207. { 0, TBIDM_BACK , 0, BTNS_DROPDOWN | BTNS_SHOWTEXT, {0,0}, 0, 0 },
  208. { 1, TBIDM_FORWARD, 0, BTNS_DROPDOWN, {0,0}, 0, 1 },
  209. { 2, TBIDM_STOPDOWNLOAD, TBSTATE_ENABLED, BTNS_BUTTON, {0,0}, 0, 2 },
  210. { 3, TBIDM_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0,0}, 0, 3 },
  211. { 4, TBIDM_HOME, TBSTATE_ENABLED, BTNS_BUTTON, {0,0}, 0, 4 },
  212. { VIEW_PARENTFOLDER + VIEW_OFFSET, TBIDM_PREVIOUSFOLDER, TBSTATE_ENABLED, BTNS_BUTTON, {0,0}, 0, VIEW_PARENTFOLDER + VIEW_OFFSET },
  213. { VIEW_NETCONNECT + VIEW_OFFSET, TBIDM_CONNECT, TBSTATE_ENABLED, BTNS_BUTTON, {0,0}, 0, VIEW_NETCONNECT + VIEW_OFFSET },
  214. { VIEW_NETDISCONNECT + VIEW_OFFSET, TBIDM_DISCONNECT, TBSTATE_ENABLED, BTNS_BUTTON, {0,0}, 0, VIEW_NETDISCONNECT + VIEW_OFFSET },
  215. { CX_SEPARATOR, 0, TBSTATE_ENABLED, BTNS_SEP, {0,0}, 0, -1 },
  216. { 5, TBIDM_SEARCH, TBSTATE_ENABLED, BTNS_SHOWTEXT, {0,0}, 0, 5 },
  217. { VIEW_ALLFOLDERS + VIEW_OFFSET, TBIDM_ALLFOLDERS, TBSTATE_ENABLED, BTNS_SHOWTEXT, {0,0}, 0, VIEW_ALLFOLDERS + VIEW_OFFSET },
  218. { 6, TBIDM_FAVORITES, TBSTATE_ENABLED, BTNS_SHOWTEXT, {0,0}, 0, 6 },
  219. // IF YOU CHANGE THE ORDERING OF THIS, please change AddMediaBarButton to reflect this ordering.
  220. { 11, TBIDM_MEDIABAR, TBSTATE_ENABLED, BTNS_SHOWTEXT, {0,0}, 0, 11 },
  221. { 12, TBIDM_HISTORY, TBSTATE_ENABLED, 0/*BTNS_SHOWTEXT*/, {0,0}, 0, 12},
  222. { CX_SEPARATOR, 0, TBSTATE_ENABLED, BTNS_SEP, {0,0}, 0, -1 },
  223. #ifndef DISABLE_FULLSCREEN
  224. // IE UNIX : No theater mode for beta1
  225. { 14, TBIDM_THEATER, TBSTATE_ENABLED, BTNS_BUTTON, {0,0}, 0, 14 },
  226. #endif
  227. };
  228. // these IDs are the array indices into c_tbExplorer above
  229. // keep in sync, be aware there are ASSERTs to enforce them to be in sync
  230. #define TBXID_BACK 0
  231. #define TBXID_FORWARD 1
  232. #define TBXID_STOPDOWNLOAD 2
  233. #define TBXID_REFRESH 3
  234. #define TBXID_HOME 4
  235. #define TBXID_PREVIOUSFOLDER 5
  236. #define TBXID_CONNECT 6
  237. #define TBXID_DISCONNECT 7
  238. #define TBXID_SEPARATOR1 8
  239. #define TBXID_SEARCH 9
  240. #define TBXID_ALLFOLDERS 10
  241. #define TBXID_FAVORITES 11
  242. #define TBXID_MEDIABAR 12
  243. #define TBXID_HISTORY 13
  244. #define TBXID_SEPARATOR2 14
  245. #define TBXID_THEATER 15
  246. static const BROWSER_RESTRICTIONS c_rest[] = {
  247. REST_BTN_BACK,
  248. REST_BTN_FORWARD,
  249. REST_BTN_STOPDOWNLOAD,
  250. REST_BTN_REFRESH,
  251. REST_BTN_HOME,
  252. REST_BROWSER_NONE, // no policy for up
  253. REST_BROWSER_NONE, // no policy for map drive
  254. REST_BROWSER_NONE, // no policy for disconnect drive
  255. REST_BROWSER_NONE, // separator
  256. REST_BTN_SEARCH,
  257. REST_BTN_ALLFOLDERS,
  258. REST_BTN_FAVORITES,
  259. REST_BTN_MEDIABAR,
  260. REST_BTN_HISTORY,
  261. REST_BROWSER_NONE, // separator
  262. #ifndef DISABLE_FULLSCREEN
  263. REST_BTN_THEATER,
  264. #endif
  265. };
  266. // init flags to avoid multiple inits of toolbar and buttons
  267. #define TBBIF_REG_PATH TEXT("Software\\Microsoft\\Internet Explorer")
  268. #define TBBIF_REG_KEY TEXT("AddButtons")
  269. // defined flags as bitfield
  270. #define TBBIF_NONE 0
  271. #define TBBIF_XBAR 0x1 // reserved/used to distinguish pre IE6/RC1 where PersonalBar/xBar was configured
  272. #define TBBIF_MEDIA 0x2
  273. #define SUPERCLASS CBaseBar
  274. class CInternetToolbar :
  275. public CBaseBar,
  276. public IDockingWindow,
  277. public IObjectWithSite, // *not* CObjectWithSite (want _ptbSite)
  278. public IExplorerToolbar,
  279. public DWebBrowserEvents,
  280. public IPersistStreamInit,
  281. public IShellChangeNotify,
  282. public ISearchItems
  283. {
  284. public:
  285. // *** IUnknown ***
  286. virtual STDMETHODIMP QueryInterface(REFIID riid, void ** ppvObj);
  287. virtual STDMETHODIMP_(ULONG) AddRef(void) { return SUPERCLASS::AddRef(); };
  288. virtual STDMETHODIMP_(ULONG) Release(void){ return SUPERCLASS::Release(); };
  289. // *** IOleWindow methods ***
  290. virtual STDMETHODIMP GetWindow(HWND * lphwnd) { return SUPERCLASS::GetWindow(lphwnd);};
  291. virtual STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode) {return SUPERCLASS::ContextSensitiveHelp(fEnterMode);};
  292. // *** IDockingWindow methods ***
  293. virtual STDMETHODIMP ShowDW(BOOL fShow);
  294. virtual STDMETHODIMP CloseDW(DWORD dwReserved);
  295. virtual STDMETHODIMP ResizeBorderDW(LPCRECT prcBorder, IUnknown* punkToolbarSite, BOOL fReserved);
  296. // *** IObjectWithSite methods ***
  297. virtual STDMETHODIMP SetSite(IUnknown* punkSite);
  298. // is E_NOTIMPL ok?
  299. virtual STDMETHODIMP GetSite(REFIID riid, void** ppvSite) { ASSERT(0); return E_NOTIMPL; };
  300. // *** IInputObjectSite methods ***
  301. virtual STDMETHODIMP OnFocusChangeIS(IUnknown *punk, BOOL fSetFocus);
  302. // *** IInputObject methods ***
  303. virtual STDMETHODIMP TranslateAcceleratorIO(LPMSG lpMsg);
  304. // *** IServiceProvider methods ***
  305. virtual STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void** ppvObj);
  306. // *** IExplorerToolbar method ***
  307. virtual STDMETHODIMP SetCommandTarget(IUnknown* punkCmdTarget, const GUID* pguidButtonGroup, DWORD dwFlags);
  308. virtual STDMETHODIMP AddStdBrowserButtons(void);
  309. virtual STDMETHODIMP AddButtons(const GUID* pguidButtonGroup, UINT nButtons, const TBBUTTON * lpButtons);
  310. virtual STDMETHODIMP AddString(const GUID * pguidButtonGroup, HINSTANCE hInst, UINT_PTR uiResID, LONG_PTR *pOffset);
  311. virtual STDMETHODIMP GetButton(const GUID* pguidButtonGroup, UINT uiCommand, LPTBBUTTON lpButton);
  312. virtual STDMETHODIMP GetState(const GUID* pguidButtonGroup, UINT uiCommand, UINT * pfState);
  313. virtual STDMETHODIMP SetState(const GUID* pguidButtonGroup, UINT uiCommand, UINT fState);
  314. virtual STDMETHODIMP AddBitmap(const GUID * pguidButtonGroup, UINT uiBMPType, UINT uiCount, TBADDBITMAP * ptb,
  315. LRESULT * pOffset, COLORREF rgbMask);
  316. virtual STDMETHODIMP GetBitmapSize(UINT * uiID);
  317. virtual STDMETHODIMP SendToolbarMsg(const GUID * pguidButtonGroup, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT * plRes);
  318. virtual STDMETHODIMP SetImageList( const GUID* pguidCmdGroup, HIMAGELIST himlNormal, HIMAGELIST himlHot, HIMAGELIST himlDisabled);
  319. virtual STDMETHODIMP ModifyButton( const GUID * pguidButtonGroup, UINT uiCommand, LPTBBUTTON lpButton);
  320. // IOleCommandTarget
  321. virtual STDMETHODIMP QueryStatus(const GUID *pguidCmdGroup,
  322. ULONG cCmds, OLECMD rgCmds[], OLECMDTEXT *pcmdtext);
  323. virtual STDMETHODIMP Exec(const GUID *pguidCmdGroup,
  324. DWORD nCmdID, DWORD nCmdexecopt, VARIANTARG *pvarargIn,
  325. VARIANTARG *pvarargOut);
  326. // IPersistStreamInit
  327. STDMETHOD(GetClassID)(GUID *pguid);
  328. STDMETHOD(Load)(IStream *pStm);
  329. STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty);
  330. STDMETHOD(InitNew)(void);
  331. STDMETHOD(IsDirty)(void);
  332. STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize);
  333. /* IDispatch methods */
  334. virtual STDMETHODIMP GetTypeInfoCount(UINT *pctinfo);
  335. virtual STDMETHODIMP GetTypeInfo(UINT itinfo,LCID lcid,ITypeInfo **pptinfo);
  336. virtual STDMETHODIMP GetIDsOfNames(REFIID riid,OLECHAR **rgszNames,UINT cNames,
  337. LCID lcid, DISPID * rgdispid);
  338. virtual STDMETHODIMP Invoke(DISPID dispidMember,REFIID riid,LCID lcid,WORD wFlags,
  339. DISPPARAMS * pdispparams, VARIANT * pvarResult,
  340. EXCEPINFO * pexcepinfo,UINT * puArgErr);
  341. // IShellChangeNotify
  342. virtual STDMETHODIMP OnChange(LONG lEvent, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2);
  343. // CBaseBar overrides
  344. virtual LRESULT v_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  345. // *** ISearchItems methods ***
  346. virtual STDMETHODIMP GetDefaultSearchUrl(LPWSTR pwzUrl, UINT cch);
  347. CInternetToolbar();
  348. protected:
  349. virtual ~CInternetToolbar();
  350. static LRESULT CALLBACK SizableWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  351. void _OnCommand(WPARAM wParam, LPARAM lParam);
  352. BOOL _SendToToolband(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* plres);
  353. LRESULT _OnNotify(LPNMHDR pnmh);
  354. void _OnTooltipNeeded(LPTOOLTIPTEXT pnmTT);
  355. void _QueryStatusTip(IOleCommandTarget *pct, LPTOOLTIPTEXT pnmTT, UINT uiCmd, const GUID* pguid);
  356. BOOL _UpEnabled();
  357. void _UpdateCommonButton(int iCmd, UINT nCmdID);
  358. void _UpdateToolbar(BOOL fForce);
  359. void _UpdateToolbarNow();
  360. void _UpdateGroup(const GUID *pguidCmdGroup, int cnt, OLECMD rgcmds[], const GUID* pguidButton, const int buttonsInternal[]);
  361. void _CSHSetStatusBar(BOOL fOn);
  362. void _StartDownload();
  363. void _StopDownload(BOOL fClosing);
  364. void _SendDocCommand(UINT idCmd);
  365. BOOL _CompressBands(BOOL fCompress, UINT uRowsNew, BOOL fForceUpdate);
  366. void _TrackSliding(int x, int y);
  367. HRESULT _DoNavigateA(LPSTR pszURL,int iNewSelection);
  368. HRESULT _DoNavigateW(LPWSTR pwzURL,int iNewSelection);
  369. HRESULT _DoNavigate(BSTR bstrURL,int iNewSelection);
  370. void _Unadvise(void);
  371. LRESULT _OnBeginDrag(NMREBAR* pnm);
  372. void _InsertURL(LPTSTR pszURL);
  373. void _ShowContextMenu(HWND hwnd, LPARAM lParam, LPRECT prcExclude);
  374. BOOL _ShowBackForwardMenu(BOOL fForward, POINT pt, LPRECT prcExclude);
  375. // search helper methods
  376. BOOL _GetFolderSearchData();
  377. void _SetSearchStuff();
  378. BOOL _GetSearchUrl(LPWSTR pwszUrl, DWORD cch);
  379. HRESULT _GetFolderSearches(IFolderSearches **ppfs);
  380. void _ReloadButtons();
  381. void _UpdateToolsStyle(BOOL fList);
  382. void _InitBitmapDSA();
  383. void _ReloadBitmapDSA();
  384. void _InitForScreenSize();
  385. void _InitToolbar();
  386. BOOL _FoldersButtonAvailable();
  387. void _AdminMarkDefaultButtons(PTBBUTTON ptbb, UINT cButtons);
  388. void _MarkDefaultButtons(PTBBUTTON ptbb, UINT cButtons);
  389. void _AddCommonButtons();
  390. HRESULT _CreateBands();
  391. BOOL _ShowBands(UINT fVisible);
  392. HRESULT _ShowTools(PBANDSAVE pbs);
  393. HRESULT _ShowAddressBand(PBANDSAVE pbs);
  394. HRESULT _ShowExternalBand(PBANDSAVE pbs, int idBand );
  395. HRESULT _ShowLinks(PBANDSAVE pbs);
  396. HRESULT _ShowBrand(PBANDSAVE pbs);
  397. HRESULT _ShowMenu(PBANDSAVE pbs);
  398. void _ShowBandCommon(PBANDSAVE pbs, LPBANDITEMDATA pbid, BOOL fShow);
  399. void _EnsureAllBandsShown();
  400. HRESULT _GetMinRowHeight();
  401. HBITMAP _LoadBackBitmap();
  402. void _SetBackground();
  403. void _CommonHandleFileSysChange(LONG lEvent, LPITEMIDLIST* ppidl);
  404. LPITEMIDLIST _GetCurrentPidl(void);
  405. int _ConvertHwndToID(HWND hwnd);
  406. HRESULT _GetPersistedBand(const CLSID clsid, REFIID riid, void ** ppiface);
  407. // Multiple command target
  408. LRESULT _AddBitmapFromForeignModule(UINT uiGetMSG, UINT uiSetMSG, UINT uiCount, HINSTANCE hinst,
  409. UINT_PTR nID, COLORREF rgbMask);
  410. HRESULT _LoadDefaultSettings(void);
  411. HRESULT _LoadUpgradeSettings(ULONG cbRead);
  412. HRESULT _LoadDefaultWidths(void);
  413. void _TryLoadIE3Settings();
  414. HRESULT _UpdateToolbarDisplay(DWORD dwFlags, UINT uVisibleBands, BOOL fNoText, BOOL fPersist);
  415. void _UpdateBrandSize();
  416. void _ShowVisible(DWORD dwVisible, BOOL fPersist);
  417. void _BuildSaveStruct(COOLBARSAVE* pcs);
  418. void _RestoreSaveStruct(COOLBARSAVE* pcs);
  419. void _GetVisibleBrowserBar(UINT idBar, CLSID *pclsidOut);
  420. VOID _UpdateLocking();
  421. LPBANDITEMDATA _AddNewBand(IDeskBand* pdb, DWORD dwID);
  422. void _TheaterModeLayout(BOOL fEnter);
  423. HBITMAP _bmpBack; // this is the state we think the itbar is in
  424. static BMPCACHE s_bmpBackShell; // this is the state of the shell bmp cache
  425. static BMPCACHE s_bmpBackInternet; // this is the state of the internet bmp cache
  426. static IMLCACHE s_imlTBGlyphs;
  427. HWND _hwndMenu;
  428. HWND _hwndAddressBand;
  429. IDockingWindowSite* _ptbsite;
  430. IOleCommandTarget* _ptbsitect;
  431. IBrowserService* _pbs;
  432. IBrowserService2* _pbs2;
  433. IServiceProvider* _psp;
  434. IBandProxy * _pbp;
  435. BITBOOL _fCreatedBandProxy:1;
  436. BITBOOL _fBackEnabled:1;
  437. BITBOOL _fForwardEnabled:1;
  438. BITBOOL _fEditEnabled:1;
  439. BITBOOL _fShow:1;
  440. BITBOOL _fAnimating:1;
  441. BITBOOL _fCompressed:1;
  442. BITBOOL _fUserNavigated :1;
  443. BITBOOL _fAutoCompInitialized :1;
  444. BITBOOL _fDirty:1;
  445. BITBOOL _fUsingDefaultBands:1;
  446. BITBOOL _fTransitionToHTML:1;
  447. BITBOOL _fInitialPidlIsWeb:1;
  448. BITBOOL _fTheater: 1; // are we in theater mode? claim no border space
  449. BITBOOL _fAutoHide :1;
  450. BITBOOL _fRebarDragging :1;
  451. BITBOOL _fShellView:1; // are we in shell view or web view?
  452. BITBOOL _fNoShowMenu:1; // can show menu band?
  453. BITBOOL _fUpdateToolbarTimer:1;
  454. BITBOOL _fNeedUpdateToolbar:1;
  455. BITBOOL _fNavigateComplete:1;
  456. BITBOOL _fLoading:1; // are we still loading the bar?
  457. BITBOOL _fDestroyed:1; // Did we destroy our member varibles and are shutting down? If so, don't use the varibles. (Stress bug w/messages coming in)
  458. BITBOOL _fLockedToolbar:1;
  459. UINT _nVisibleBands; // bitmask of which bands are visible: VBF_*
  460. IWebBrowser2* _pdie;
  461. DWORD _dwcpCookie; // DIID_DWebBrowserEvents2
  462. int _xCapture;
  463. int _yCapture;
  464. // for multiple command target support
  465. HDSA _hdsaTBBMPs;
  466. UINT _uiMaxTBWidth;
  467. UINT _uiTBTextRows;
  468. UINT _uiTBDefaultTextRows;
  469. // search stuff
  470. HDPA _hdpaFSI; // folder search items
  471. GUID _guidCurrentSearch;
  472. GUID _guidDefaultSearch;
  473. COOLBARSAVE _cs; //Coolbar layout info from registry!
  474. BOOL _fDontSave; // force ourselves not to persist out the state.
  475. struct EXTERNALBANDINFO {
  476. CLSID clsid; // CLSID of the band
  477. LPWSTR pwszName; // Band name
  478. LPWSTR pwszHelp; // Band help text
  479. };
  480. EXTERNALBANDINFO _rgebi[ MAXEXTERNALBANDS ];
  481. void _LoadExternalBandInfo();
  482. TBBUTTON _tbExplorer[ARRAYSIZE(c_tbExplorer)];
  483. int _iButtons;
  484. #ifdef EDIT_HACK
  485. // Variables for customizing the edit button glyph
  486. HIMAGELIST _himlEdit; // Monochrome Image list for the edit button
  487. HIMAGELIST _himlEditHot; // Hot image list for edit button
  488. int _iEditIcon; // index of current edit icon
  489. int _cxEditGlyph; // cx of glyph size
  490. int _cyEditGlyph; // cx of glyph size
  491. // Functions for managing a custom edit glyph
  492. void _InitEditButtonStyle();
  493. void _SetEditGlyph(int iIcon);
  494. void _RefreshEditGlyph();
  495. void _UpdateEditButton();
  496. static HIMAGELIST _CreateGrayScaleImagelist(HBITMAP hbmpImage, HBITMAP hbmpMask);
  497. static BSTR _GetEditProgID(IHTMLDocument2* pHTMLDocument);
  498. //
  499. // We can have multiple edit verbs associated with a document. The following class
  500. // maintains a list of verbs.
  501. //
  502. #define FCIDM_EDITFIRST 2000
  503. #define FCIDM_EDITLAST 2100
  504. #define SZ_EDITVERB_PROP TEXT("CEditVerb_This")
  505. #define IL_EDITBUTTON 2 // Index of image list used for the edit button
  506. #define IL_SEARCHBUTTON 3 // || search button
  507. // MSAA Menu Info declarations.
  508. // These will eventually be incorporated into oleacc.h - but for the
  509. // moment, we declare them privately...
  510. #define MSAA_MENU_SIG 0xAA0DF00DL
  511. class CEditVerb
  512. {
  513. public:
  514. CEditVerb();
  515. ~CEditVerb();
  516. // Functions for managing the verbs
  517. BOOL Add(LPTSTR pszProgID);
  518. UINT GetSize() { return _nElements; }
  519. void RemoveAll();
  520. // Functions to access the default edit verb
  521. int GetIcon() { return (_nElements && _pVerb[_nDefault].fShowIcon) ? _GetVerb(_nDefault).iIcon : -1; }
  522. BOOL GetToolTip(LPTSTR pszToolTip, UINT cchMax, BOOL fStripAmpersands = TRUE);
  523. BOOL GetMenuText(LPTSTR pszText, UINT cchMax) { return GetToolTip(pszText, cchMax, FALSE); }
  524. void Edit(LPCTSTR pszUrl) { _Edit(pszUrl, _nDefault); }
  525. // Pop-up menu
  526. BOOL ShowEditMenu(POINT pt, HWND hwnd, LPTSTR pszUrl);
  527. // Get default editor from the registry
  528. void InitDefaultEditor(HKEY hkey = NULL);
  529. protected:
  530. struct MSAAMenuInfo
  531. {
  532. DWORD m_MSAASig; // Must be MSAA_MENU_SIG
  533. DWORD m_CharLen; // Length in characters of text, excluding terminating NUL
  534. LPWSTR m_pWStr; // Menu text, in UNICODE, with terminating UNICODE-NUL.
  535. };
  536. struct EDITVERB
  537. {
  538. MSAAMenuInfo m_MSAA; // MSAA info - must be first element.
  539. HKEY hkeyProgID; // Key the we shellexec
  540. BITBOOL fUseOpenVerb:1; // use open verb instead of edit
  541. BITBOOL fInit:1; // true if the data below has beed initialized
  542. BITBOOL fShowIcon:1; // true if icon should show up on button
  543. int iIcon; // cached icon index
  544. UINT idCmd; // menu id
  545. LPTSTR pszDesc; // executable name or document name
  546. LPTSTR pszMenuText; // Menu text
  547. LPTSTR pszExe; // Path of the exe used to edit
  548. };
  549. EDITVERB* _Add(HKEY hkeyProgID, BOOL fPermitOpenVerb, BOOL fCheckForOfficeApp, BOOL fShowIcon);
  550. EDITVERB& _GetVerb(UINT nIndex);
  551. void _FetchInfo(UINT nIndex);
  552. void _Edit(LPCTSTR pszUrl, UINT nIndex);
  553. LPCTSTR _GetDescription(EDITVERB& rVerb);
  554. void _SetMSAAMenuInfo(EDITVERB& rVerb);
  555. void _ClearMSAAMenuInfo(EDITVERB& rVerb);
  556. void _FormatMenuText(UINT nIndex);
  557. BOOL _IsUnique(EDITVERB& rNewVerb);
  558. BOOL _IsHtmlStub(LPCWSTR pszPath);
  559. LPCTSTR _GetExePath(EDITVERB& rVerb);
  560. LPCTSTR _GetDefaultEditor();
  561. void _InitDefaultMHTMLEditor();
  562. static LRESULT CALLBACK _WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  563. // Member data
  564. UINT _nElements; // number of edit verbs
  565. UINT _nDefault; // Default edit verb
  566. EDITVERB* _pVerb; // array of edit verbs
  567. WNDPROC _lpfnOldWndProc; // former wndProc
  568. LPWSTR _pszDefaultEditor; // Friendly name of default HTML editor
  569. BOOL _fInitEditor; // if we checked for a default editor
  570. };
  571. CEditVerb _aEditVerb;
  572. #endif
  573. // internal bandsite class
  574. class CBrowserToolsBand;
  575. class CITBandSite : public CBandSite
  576. {
  577. CITBandSite();
  578. virtual STDMETHODIMP Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut);
  579. virtual STDMETHODIMP AddBand(IUnknown *punk);
  580. virtual STDMETHODIMP HasFocusIO();
  581. protected:
  582. virtual void v_SetTabstop(LPREBARBANDINFO prbbi);
  583. BOOL _SetMinDimensions();
  584. friend class CInternetToolbar;
  585. friend class CBrowserToolsBand;
  586. virtual HRESULT _OnContextMenu(WPARAM wParm, LPARAM lParam);
  587. virtual HRESULT _Initialize(HWND hwndParent);
  588. };
  589. CITBandSite _bs;
  590. #define TOOLSBANDCLASS CInternetToolbar::CBrowserToolsBand
  591. class CBrowserToolsBand : public CToolbarBand
  592. {
  593. CMDMAP* _GetCmdMapByIndex(int nIndex) { return _GetCmdMap(nIndex, TRUE);};
  594. CMDMAP* _GetCmdMapByID(int id) { return _GetCmdMap(id, FALSE);};
  595. LRESULT _ToolsCustNotify (LPNMHDR pnmh); // Handle TBCustomization Notify
  596. BOOL _SaveRestoreToolbar(BOOL fSave);
  597. void _FreeCustomizeInfo();
  598. void _FreeCmdMap(CMDMAP*);
  599. BOOL _RemoveAllButtons();
  600. int _CommandFromIndex(UINT uIndex);
  601. HRESULT _ConvertCmd(const GUID* pguidButtonGroup, UINT id, GUID* pguidOut, UINT * pid);
  602. void _OnDeletingButton(TBNOTIFY* ptbn);
  603. LONG_PTR _AddString(LPWSTR pwstr);
  604. void _PreProcessButtonString(TBBUTTON *ptbn, DWORD dwFlags);
  605. void _PreProcessExternalTBButton(TBBUTTON *ptbn);
  606. UINT _ProcessExternalButtons(PTBBUTTON ptbb, UINT cButtons);
  607. void _GetButtons(IOleCommandTarget* pct, const GUID* pguid, HDSA hdsa);
  608. void _RecalcButtonWidths();
  609. void _AddMediaBarButton();
  610. void _UpdateTextSettings(INT_PTR ids);
  611. static BOOL_PTR CALLBACK _BtnAttrDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  612. static void _PopulateComboBox(HWND hwnd, const int iResource[], UINT cResources);
  613. static void _SetComboSelection(HWND hwnd, int iCurOption);
  614. void _SetDialogSelections(HWND hDlg, BOOL fSmallIcons);
  615. static void _PopulateDialog(HWND hDlg);
  616. void _OnBeginCustomize(LPNMTBCUSTOMIZEDLG pnm);
  617. BOOL _BuildButtonDSA();
  618. CMDMAPCUSTOMIZE* _GetCmdMapCustomize(GUID* guid, UINT nCmdID);
  619. virtual STDMETHODIMP Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut);
  620. virtual STDMETHODIMP GetClassID(CLSID *pClassID) {return E_NOTIMPL;};
  621. virtual STDMETHODIMP Load(IStream *pStm) {return E_NOTIMPL;};
  622. virtual STDMETHODIMP Save(IStream *pStm, BOOL fClearDirty) {return E_NOTIMPL;};
  623. // *** IUnknown ***
  624. virtual STDMETHODIMP_(ULONG) AddRef(void) { return CToolBand::AddRef(); };
  625. virtual STDMETHODIMP_(ULONG) Release(void){ return CToolBand::Release(); };
  626. virtual STDMETHODIMP QueryInterface(REFIID riid, void ** ppvObj);
  627. // *** IDeskBand methods ***
  628. virtual STDMETHODIMP GetBandInfo(DWORD dwBandID, DWORD fViewMode, DESKBANDINFO* pdbi);
  629. // *** IWinEventHandler methods ***
  630. virtual STDMETHODIMP OnWinEvent(HWND hwnd, UINT dwMsg, WPARAM wParam, LPARAM lParam, LRESULT* plres);
  631. // *** IDockingWindow methods ***
  632. virtual STDMETHODIMP CloseDW(DWORD dwReserved) { return S_OK;};
  633. // *** IInputObject methods ***
  634. virtual STDMETHODIMP TranslateAcceleratorIO(LPMSG lpMsg);
  635. protected:
  636. IOleCommandTarget* _CommandTargetFromCmdMap(CMDMAP* pcm);
  637. LRESULT _OnToolbarDropDown(TBNOTIFY *ptbn);
  638. virtual LRESULT _OnNotify(LPNMHDR pnmh);
  639. LRESULT _OnContextMenu(LPARAM lParam, WPARAM wParam);
  640. CMDMAP* _GetCmdMap(int i, BOOL fByIndex);
  641. void _OnEndCustomize();
  642. LRESULT _TryShowBackForwardMenu(DWORD dwItemSpec, LPPOINT ppt, LPRECT prcExclude);
  643. CBrowserToolsBand();
  644. void _FreeBtnsAdded();
  645. friend class CInternetToolbar;
  646. friend class CITBandSite;
  647. GUID _guidCurrentButtonGroup;
  648. IOleCommandTarget* _pctCurrentButtonGroup;
  649. LPTBBUTTON _pbtnsAdded;
  650. int _cBtnsAdded;
  651. DWORD _nNextCommandID;
  652. CUSTOMIZEINFO *_pcinfo;
  653. BITBOOL _fCustomize :1;
  654. BITBOOL _fNeedFreeCmdMapsAdded :1;
  655. };
  656. CBrowserToolsBand _btb;
  657. friend class CBrowserToolsBand;
  658. friend class CITBandSite;
  659. friend void CInternetToolbar_CleanUp();
  660. friend void CInternetToolbar_Preload();
  661. friend void ITBar_LoadToolbarGlyphs(HWND hwnd);
  662. };
  663. //
  664. // Gets the stream corresponding to the type of the given pidl
  665. // If the stream already doesn't exist, then it returns NULL.
  666. HRESULT _GetStreamName(DWORD dwITBS, LPTSTR pszName, DWORD cchSize)
  667. {
  668. HRESULT hr = S_OK;
  669. ASSERT(pszName);
  670. switch (dwITBS)
  671. {
  672. case ITBS_WEB:
  673. StrCpyN(pszName, TEXT("WebBrowser"), cchSize);
  674. break;
  675. case ITBS_SHELL:
  676. StrCpyN(pszName, TEXT("ShellBrowser"), cchSize);
  677. break;
  678. case ITBS_EXPLORER:
  679. StrCpyN(pszName, TEXT("Explorer"), cchSize);
  680. break;
  681. default:
  682. hr = E_FAIL;
  683. break;
  684. }
  685. if (FAILED(hr))
  686. pszName[0] = '\0';
  687. return hr;
  688. }
  689. //
  690. // Gets the stream corresponding to the type of the given pidl
  691. // If the stream already doesn't exist, then it returns NULL.
  692. IStream *GetRegStream(BOOL fInternet, LPCTSTR pszValue, DWORD grfMode)
  693. {
  694. IStream *pstm = NULL;
  695. HKEY hkToolbar;
  696. if (RegCreateKey(HKEY_CURRENT_USER, c_szRegKeyCoolbar, &hkToolbar) == ERROR_SUCCESS)
  697. {
  698. TCHAR szStreamName[MAX_PATH];
  699. if (SUCCEEDED(_GetStreamName(fInternet, szStreamName, ARRAYSIZE(szStreamName))))
  700. pstm = OpenRegStream(hkToolbar, szStreamName, pszValue, grfMode);
  701. RegCloseKey(hkToolbar);
  702. }
  703. return(pstm);
  704. }
  705. //
  706. // Gets the stream corresponding to the type of the given pidl
  707. // If the stream already doesn't exist, then it returns NULL.
  708. IStream *GetITBarStream(BOOL fInternet, DWORD grfMode)
  709. {
  710. return GetRegStream(fInternet, TEXT("ITBarLayout"), grfMode);
  711. }
  712. IMLCACHE CInternetToolbar::s_imlTBGlyphs = {NULL};
  713. BMPCACHE CInternetToolbar::s_bmpBackShell = {NULL};
  714. BMPCACHE CInternetToolbar::s_bmpBackInternet = {NULL};
  715. BOOL g_fSmallIcons = FALSE;
  716. void IMLCACHE_CleanUp(IMLCACHE * pimlCache, DWORD dwFlags)
  717. {
  718. for (int i = 0; i < CIMLISTS; i++)
  719. {
  720. if (pimlCache->arhimlPendingDelete[i])
  721. ImageList_Destroy(pimlCache->arhimlPendingDelete[i]);
  722. if ((dwFlags & IML_DESTROY) && pimlCache->arhiml[i])
  723. ImageList_Destroy(pimlCache->arhiml[i]);
  724. }
  725. }
  726. // DO NOT change the numbering of the following bitmap specs.
  727. // If you want to add new sizes, add them _after_ ITB_1616_HOT_HICOLOR
  728. #define ITB_2020_NORMAL 0
  729. #define ITB_2020_HOT 1
  730. #define ITB_1616_NORMAL 2
  731. #define ITB_1616_HOT 3
  732. #define ITB_2020_NORMAL_HICOLOR 4
  733. #define ITB_2020_HOT_HICOLOR 5
  734. #define ITB_1616_NORMAL_HICOLOR 6
  735. #define ITB_1616_HOT_HICOLOR 7
  736. void ITBar_LoadToolbarGlyphs(HWND hwnd)
  737. {
  738. int cx, idBmpType;
  739. int iBitmapBaseIndex;
  740. BOOL bUseClassicGlyphs = SHUseClassicToolbarGlyphs();
  741. HINSTANCE hInst;
  742. g_fSmallIcons = _UseSmallIcons();
  743. if (bUseClassicGlyphs)
  744. {
  745. g_iToolBarLargeIconWidth = TB_BMP_CX;
  746. g_iToolBarLargeIconHeight = TB_BMP_CY;
  747. iBitmapBaseIndex = IDB_SHSTD;
  748. hInst = HINST_THISDLL;
  749. }
  750. else
  751. {
  752. g_iToolBarLargeIconWidth = TB_BMP_CX_ALPHABITMAP;
  753. g_iToolBarLargeIconHeight = TB_BMP_CY_ALPHABITMAP;
  754. iBitmapBaseIndex = IDB_TB_SH_BASE;
  755. hInst = GetModuleHandle(TEXT("shell32.dll"));
  756. }
  757. if (g_fSmallIcons)
  758. {
  759. cx = TB_SMBMP_CX;
  760. idBmpType = ITB_1616_NORMAL;
  761. }
  762. else
  763. {
  764. cx = g_iToolBarLargeIconWidth;
  765. idBmpType = ITB_2020_NORMAL;
  766. }
  767. if (SHGetCurColorRes() > 8)
  768. idBmpType += DELTA_HICOLOR;
  769. _LoadToolbarGlyphs(hwnd, &CInternetToolbar::s_imlTBGlyphs, cx, idBmpType,
  770. iBitmapBaseIndex, bUseClassicGlyphs, hInst);
  771. }
  772. void CInternetToolbar_Preload()
  773. {
  774. ENTERCRITICAL;
  775. ITBar_LoadToolbarGlyphs(NULL);
  776. Brand_InitBrandContexts();
  777. LEAVECRITICAL;
  778. }
  779. void CInternetToolbar_CleanUp()
  780. {
  781. TraceMsg(DM_ITBAR, "CInternetToolbar_CleanUp: Destroying shared GDI objects");
  782. if (CInternetToolbar::s_bmpBackInternet.hbmp)
  783. DeleteObject(CInternetToolbar::s_bmpBackInternet.hbmp);
  784. if (CInternetToolbar::s_bmpBackShell.hbmp)
  785. DeleteObject(CInternetToolbar::s_bmpBackShell.hbmp);
  786. IMLCACHE_CleanUp(&CInternetToolbar::s_imlTBGlyphs, IML_DESTROY);
  787. }
  788. STDAPI CInternetToolbar_CreateInstance(IUnknown* pUnkOuter, IUnknown** ppunk, LPCOBJECTINFO poi)
  789. {
  790. // aggregation checking is handled in class factory
  791. CInternetToolbar *pitbar = new CInternetToolbar();
  792. if (pitbar)
  793. {
  794. *ppunk = SAFECAST(pitbar, IDockingWindow *);
  795. return S_OK;
  796. }
  797. return E_OUTOFMEMORY;
  798. }
  799. LRESULT CInternetToolbar::v_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  800. {
  801. if ( uMsg == WM_SYSCOLORCHANGE )
  802. {
  803. // refresh the back drop incase the colours have changed
  804. _SetBackground();
  805. }
  806. return SUPERCLASS::v_WndProc( hwnd, uMsg, wParam, lParam );
  807. }
  808. void CInternetToolbar::_LoadExternalBandInfo()
  809. {
  810. #ifdef DEBUG
  811. int i;
  812. // Should have been zero-initialized
  813. for (i = 0; i < ARRAYSIZE(_rgebi); i++)
  814. {
  815. ASSERT(IsEqualGUID(_rgebi[i].clsid, GUID_NULL));
  816. ASSERT(_rgebi[i].pwszName == NULL);
  817. ASSERT(_rgebi[i].pwszHelp == NULL);
  818. }
  819. #endif
  820. if ((!SHRegGetBoolUSValue(TEXT("SOFTWARE\\Microsoft\\Internet Explorer\\Main"), TEXT("Enable Browser Extensions"), FALSE, TRUE))
  821. || (GetSystemMetrics(SM_CLEANBOOT)!=0))
  822. {
  823. return;
  824. }
  825. HKEY hkey;
  826. DWORD dwClsidIndex = 0;
  827. if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, REG_KEY_BANDSTATE, 0, KEY_READ, &hkey) == ERROR_SUCCESS)
  828. {
  829. TCHAR tszReg[MAX_PATH];
  830. StrCpy(tszReg, TEXT("CLSID\\"));
  831. const int cchClsidPrefix = 6; // 6 = strlen("CLSID\\")
  832. LPTSTR ptszClsid = tszReg + cchClsidPrefix;
  833. DWORD cchClsid;
  834. for (DWORD dwIndex = 0;
  835. cchClsid = ARRAYSIZE(tszReg) - cchClsidPrefix,
  836. dwClsidIndex < ARRAYSIZE(_rgebi) &&
  837. RegEnumValue( hkey, dwIndex, ptszClsid, &cchClsid, NULL, NULL, NULL, NULL ) == ERROR_SUCCESS;
  838. dwIndex++)
  839. {
  840. CLSID clsid;
  841. // We want to ignore the radio toolband {8E718888-423F-11D2-876E-00A0C9082467}
  842. // without affecting its existing registration. Makes uninstall easier.
  843. if (GUIDFromString( ptszClsid, &clsid )
  844. && StrCmpI(ptszClsid, TEXT("{8E718888-423F-11D2-876E-00A0C9082467}")))
  845. {
  846. HKEY hkeyClsid;
  847. if (RegOpenKeyEx(HKEY_CLASSES_ROOT, tszReg, 0, KEY_READ, &hkeyClsid) == ERROR_SUCCESS)
  848. {
  849. // Don't save the CLSID until we're sure it worked
  850. _rgebi[dwClsidIndex].clsid = clsid;
  851. WCHAR wszBuf[MAX_PATH];
  852. // Get the name; use SHLoadRegUIString so the app can localize
  853. SHLoadRegUIStringW( hkeyClsid, L"", wszBuf, ARRAYSIZE(wszBuf) );
  854. Str_SetPtrW( &_rgebi[dwClsidIndex].pwszName, wszBuf);
  855. // Get the help; use SHLoadRegUIString so the app can localize
  856. SHLoadRegUIStringW( hkeyClsid, L"HelpText", wszBuf, ARRAYSIZE(wszBuf) );
  857. Str_SetPtrW( &_rgebi[dwClsidIndex].pwszHelp, wszBuf);
  858. RegCloseKey(hkeyClsid);
  859. dwClsidIndex++;
  860. }
  861. }
  862. }
  863. RegCloseKey( hkey );
  864. }
  865. }
  866. CInternetToolbar::CInternetToolbar() : CBaseBar(), _yCapture(-1), _iButtons(-1)
  867. #ifdef EDIT_HACK
  868. , _iEditIcon(-1), _cxEditGlyph(-1), _cyEditGlyph(-1)
  869. #endif
  870. {
  871. DllAddRef();
  872. if (GetSystemMetrics(SM_CXSCREEN) < 650)
  873. _uiMaxTBWidth = MAX_TB_WIDTH_LORES;
  874. else
  875. _uiMaxTBWidth = MAX_TB_WIDTH_HIRES;
  876. ASSERT(_fLoading == FALSE);
  877. ASSERT(_hwnd == NULL);
  878. ASSERT(_btb._guidCurrentButtonGroup == CLSID_NULL);
  879. _btb._nNextCommandID = 1000;
  880. DWORD dwResult = FALSE, dwType, dwcbData = sizeof(dwResult), dwDefault = TRUE;
  881. SHRegGetUSValue(c_szRegKeyCoolbar, TEXT("Locked"), &dwType, &dwResult, &dwcbData, FALSE, &dwDefault, sizeof(dwDefault));
  882. SHSetValue(HKEY_CURRENT_USER, c_szRegKeyCoolbar, TEXT("Locked"), REG_DWORD, &dwResult, sizeof(dwResult));
  883. _fLockedToolbar = dwResult;
  884. _LoadExternalBandInfo();
  885. }
  886. void CInternetToolbar::_Unadvise(void)
  887. {
  888. if(_dwcpCookie)
  889. {
  890. ConnectToConnectionPoint(NULL, DIID_DWebBrowserEvents2, FALSE, _pdie, &_dwcpCookie, NULL);
  891. }
  892. }
  893. int CALLBACK DeleteDPAPtrCB(void *pItem, void *pData)
  894. {
  895. if ( pItem )
  896. {
  897. ASSERT( ::LocalSize(pItem) == sizeof(FOLDERSEARCHITEM) );
  898. LocalFree(pItem);
  899. pItem = NULL;
  900. }
  901. return TRUE;
  902. }
  903. CInternetToolbar::~CInternetToolbar()
  904. {
  905. ATOMICRELEASE(_pdie);
  906. if(_pbp && _fCreatedBandProxy)
  907. {
  908. _pbp->SetSite(NULL);
  909. }
  910. if (IsWindow(_hwnd))
  911. {
  912. DestroyWindow(_hwnd);
  913. }
  914. ATOMICRELEASE(_pbp);
  915. ASSERT(!_ptbsite && !_ptbsitect && !_psp && !_pbs && !_pbs2);
  916. SetSite(NULL);
  917. if ( _hdpaFSI )
  918. {
  919. DPA_DestroyCallback(_hdpaFSI, DeleteDPAPtrCB, NULL);
  920. _hdpaFSI = NULL;
  921. }
  922. for (int i = 0; i < ARRAYSIZE(_rgebi); i++)
  923. {
  924. Str_SetPtrW( &_rgebi[i].pwszName, NULL);
  925. Str_SetPtrW( &_rgebi[i].pwszHelp, NULL);
  926. }
  927. TraceMsg(TF_SHDLIFE, "dtor CInternetToolbar %x", this);
  928. DllRelease();
  929. }
  930. #define IID_DWebBrowserEvents DIID_DWebBrowserEvents
  931. HRESULT CInternetToolbar::QueryInterface(REFIID riid, void ** ppvObj)
  932. {
  933. static const QITAB qit[] = {
  934. // perf: last tuned 980728
  935. QITABENTMULTI(CInternetToolbar, IDispatch, DWebBrowserEvents), // IID_IDispatch
  936. QITABENT(CInternetToolbar, IExplorerToolbar), // IID_IDispatch
  937. QITABENT(CInternetToolbar, IObjectWithSite), // IID_IObjectWithSite
  938. QITABENT(CInternetToolbar, IPersistStreamInit), // IID_IPersistStreamInit
  939. QITABENT(CInternetToolbar, IDockingWindow), // IID_IDockingWindow
  940. QITABENT(CInternetToolbar, DWebBrowserEvents), // IID_DWebBrowserEvents
  941. QITABENT(CInternetToolbar, IShellChangeNotify), // rare IID_IShellChangeNotify
  942. QITABENT(CInternetToolbar, ISearchItems), // rare IID_ISearchItems
  943. { 0 },
  944. };
  945. HRESULT hres = QISearch(this, qit, riid, ppvObj);
  946. if (FAILED(hres))
  947. hres = SUPERCLASS::QueryInterface(riid, ppvObj);
  948. return hres;
  949. }
  950. /* IDispatch methods */
  951. HRESULT CInternetToolbar::GetTypeInfoCount(UINT *pctinfo)
  952. {
  953. return(E_NOTIMPL);
  954. }
  955. HRESULT CInternetToolbar::GetTypeInfo(UINT itinfo,LCID lcid,ITypeInfo **pptinfo)
  956. {
  957. return(E_NOTIMPL);
  958. }
  959. HRESULT CInternetToolbar::GetIDsOfNames(REFIID riid,OLECHAR **rgszNames,UINT cNames,
  960. LCID lcid, DISPID * rgdispid)
  961. {
  962. return(E_NOTIMPL);
  963. }
  964. #if 0
  965. // NOTE - StevePro changed it so this code isnt called
  966. // this is a goodness, because it calls SHVerbExists() which
  967. // is a TCHAR API, that is actually compiled as an ANSI API
  968. // and since we are UNICODE it just always fails.
  969. // leaving this in so that we know about the issue of
  970. // frontpad.exe possibly needing to be disabled.
  971. BOOL _ShowEditForExtension(LPCTSTR pszExtension)
  972. {
  973. TCHAR szBuf[MAX_PATH];
  974. if (SHVerbExists(pszExtension, TEXT("edit"), szBuf))
  975. {
  976. // don't show it if it's just our own
  977. if (StrStrI(szBuf, TEXT("frontpad.exe")))
  978. {
  979. return FALSE;
  980. }
  981. return TRUE;
  982. }
  983. return FALSE;
  984. }
  985. #endif
  986. #ifdef EDIT_HACK
  987. //+-------------------------------------------------------------------------
  988. // This function scans the html document for META tags that indicate the
  989. // program that was used to create the HTML page. Examples are:
  990. //
  991. // <meta name="ProgID" content="word.document" >
  992. // <meta name="ProgID" content="excel.sheet" >
  993. //
  994. // If a match is found, the content of the first match is returned. This
  995. // progid is used to edit the document.
  996. //--------------------------------------------------------------------------
  997. BSTR CInternetToolbar::_GetEditProgID(IHTMLDocument2* pHTMLDocument)
  998. {
  999. BSTR bstrProgID = NULL;
  1000. //
  1001. // First get all document elements. Note that this is very fast in
  1002. // ie5 because the collection directly accesses the internal tree.
  1003. //
  1004. IHTMLElementCollection * pAllCollection;
  1005. if (SUCCEEDED(pHTMLDocument->get_all(&pAllCollection)))
  1006. {
  1007. IHTMLMetaElement* pMetaElement;
  1008. IHTMLBodyElement* pBodyElement;
  1009. IHTMLFrameSetElement* pFrameSetElement;
  1010. IDispatch* pDispItem;
  1011. //
  1012. // Now we scan the document for meta tags. Since these must reside in
  1013. // in the head, and since Trident always creates a body tag, we can
  1014. // stop looking when we hit the body.
  1015. //
  1016. // Note, the alternative of using pAllCollection->tags to return the
  1017. // collection of meta tags is likely more expensive because it will
  1018. // walk the whole tree (unless Trident optimizes this).
  1019. //
  1020. long lItemCnt;
  1021. VARIANT vEmpty;
  1022. V_VT(&vEmpty) = VT_EMPTY;
  1023. VARIANT vIndex;
  1024. V_VT(&vIndex) = VT_I4;
  1025. EVAL(SUCCEEDED(pAllCollection->get_length(&lItemCnt)));
  1026. for (long lItem = 0; lItem < lItemCnt; lItem++)
  1027. {
  1028. V_I4(&vIndex) = lItem;
  1029. if (S_OK == pAllCollection->item(vIndex, vEmpty, &pDispItem))
  1030. {
  1031. //
  1032. // First see if it's a meta tag
  1033. //
  1034. if (SUCCEEDED(pDispItem->QueryInterface(IID_PPV_ARG(IHTMLMetaElement, &pMetaElement))))
  1035. {
  1036. BSTR bstrName = NULL;
  1037. //
  1038. // We have a META element, check its NAME and CONTENT
  1039. //
  1040. if ( SUCCEEDED(pMetaElement->get_name(&bstrName)) && (bstrName != NULL) &&
  1041. (StrCmpIW(bstrName, OLESTR("ProgId")) == 0) &&
  1042. SUCCEEDED(pMetaElement->get_content(&bstrProgID)) && (bstrProgID != NULL)
  1043. )
  1044. {
  1045. // We got the ProgID, so terminate the search;
  1046. lItem = lItemCnt;
  1047. }
  1048. if (bstrName != NULL)
  1049. SysFreeString(bstrName);
  1050. pMetaElement->Release();
  1051. }
  1052. //
  1053. // Next check for the body tag
  1054. //
  1055. else if (SUCCEEDED(pDispItem->QueryInterface(IID_PPV_ARG(IHTMLBodyElement, &pBodyElement))))
  1056. {
  1057. // Found the body tag, so terminate the search
  1058. lItem = lItemCnt;
  1059. pBodyElement->Release();
  1060. }
  1061. //
  1062. // Finally, check for a frameset tag
  1063. //
  1064. else if (SUCCEEDED(pDispItem->QueryInterface(IID_PPV_ARG(IHTMLFrameSetElement, &pFrameSetElement))))
  1065. {
  1066. // Found a frameset tag, so terminate the search
  1067. lItem = lItemCnt;
  1068. pFrameSetElement->Release();
  1069. }
  1070. pDispItem->Release();
  1071. }
  1072. }
  1073. // Make sure that these don't have to be cleared (should not have been modified)
  1074. ASSERT(vEmpty.vt == VT_EMPTY);
  1075. ASSERT(vIndex.vt == VT_I4);
  1076. pAllCollection->Release();
  1077. }
  1078. return bstrProgID;
  1079. }
  1080. //+-------------------------------------------------------------------------
  1081. // Returns grey-scale image from the icon passed in.
  1082. //--------------------------------------------------------------------------
  1083. HIMAGELIST CInternetToolbar::_CreateGrayScaleImagelist(HBITMAP hbmpImage, HBITMAP hbmpMask)
  1084. {
  1085. // Determine the button dimensions
  1086. int cx = g_fSmallIcons ? TB_SMBMP_CX : g_iToolBarLargeIconWidth;
  1087. int cy = g_fSmallIcons ? TB_SMBMP_CY : g_iToolBarLargeIconHeight;
  1088. // Start with a 24 bit color image list
  1089. HIMAGELIST himlEdit = ImageList_Create(cx, cy, ILC_COLOR24 | ILC_MASK, 1, 1);
  1090. if (NULL == himlEdit)
  1091. {
  1092. return NULL;
  1093. }
  1094. ImageList_Add(himlEdit, hbmpImage, hbmpMask);
  1095. // Get the dib section from the image list
  1096. IMAGEINFO ii;
  1097. if (ImageList_GetImageInfo(himlEdit, 0, &ii))
  1098. {
  1099. DIBSECTION ds = {0};
  1100. if (GetObject(ii.hbmImage, sizeof(ds), &ds))
  1101. {
  1102. //
  1103. // Map each pixel to a monochrome equivalent.
  1104. //
  1105. BYTE* pBits = (BYTE*)ds.dsBm.bmBits;
  1106. BYTE* pScan = pBits;
  1107. int xWid = ds.dsBm.bmWidth;
  1108. int yHei = ds.dsBm.bmHeight;
  1109. long cbScan = ((xWid * 24 + 31) & ~31) / 8;
  1110. for (int y=0; y < yHei; ++y)
  1111. {
  1112. for (int x=0; x < xWid; ++x)
  1113. {
  1114. //
  1115. // Map to equivalent gray color by setting r,g,b to the same value.
  1116. // Using the average of r,g,b can be too dark, and using the max
  1117. // of r,g,b can be too bright. So, as a simple algorithm we use
  1118. // the average of the two schemes. This is cheaper than using true
  1119. // intensity matching.
  1120. //
  1121. BYTE nMax = max(max(pScan[0], pScan[1]), pScan[2]);
  1122. BYTE nAve = ((UINT)pScan[0] + pScan[1] + pScan[2])/3;
  1123. pScan[0] = pScan[1] = pScan[2] = ((UINT)nMax + nAve)/2;
  1124. // Increment to next pixel
  1125. pScan += 3;
  1126. }
  1127. // Increment to the next scan line
  1128. pBits += cbScan;
  1129. pScan = pBits;
  1130. }
  1131. }
  1132. }
  1133. return himlEdit;
  1134. }
  1135. //+-------------------------------------------------------------------------
  1136. // Returns image and mask bitmaps for the desired image list item
  1137. //--------------------------------------------------------------------------
  1138. BOOL MyImageList_GetBitmaps
  1139. (
  1140. HIMAGELIST himl, // image list to use
  1141. int iImage, // image to copy
  1142. int x, // x-offset to draw in bitmap
  1143. int y, // x-offset to draw in bitmap
  1144. int cx, // width of bitmap
  1145. int cy, // height of bitmap
  1146. HBITMAP* phbmpImage, // returned color bitmap
  1147. HBITMAP* phbmpMask // returned mask bitmap
  1148. )
  1149. {
  1150. ASSERT(phbmpImage);
  1151. ASSERT(phbmpMask);
  1152. BOOL fRet = FALSE;
  1153. HDC hdc = GetDC(NULL);
  1154. if (hdc)
  1155. {
  1156. HDC hdcDst = CreateCompatibleDC(hdc);
  1157. if (hdcDst)
  1158. {
  1159. HBITMAP hbmpImage = CreateCompatibleBitmap(hdc, cx, cy);
  1160. if (hbmpImage)
  1161. {
  1162. HBITMAP hbmpMask = CreateBitmap(cx, cy, 1, 1, NULL);
  1163. if (hbmpMask)
  1164. {
  1165. // Draw mask bitmap
  1166. HBITMAP hbmpOld = (HBITMAP)SelectObject(hdcDst, hbmpMask);
  1167. PatBlt(hdcDst, 0, 0, cx, cy, WHITENESS);
  1168. ImageList_Draw(himl, iImage, hdcDst, x, y, ILD_MASK);
  1169. // Draw image bitmap
  1170. SelectObject(hdcDst, hbmpImage);
  1171. ImageList_Draw(himl, iImage, hdcDst, x, y, ILD_NORMAL);
  1172. SelectObject(hdcDst, hbmpOld);
  1173. *phbmpImage = hbmpImage;
  1174. *phbmpMask = hbmpMask;
  1175. fRet = TRUE;
  1176. }
  1177. else
  1178. {
  1179. DeleteObject(hbmpImage);
  1180. }
  1181. }
  1182. DeleteDC(hdcDst);
  1183. }
  1184. ReleaseDC(NULL, hdc);
  1185. }
  1186. return fRet;
  1187. }
  1188. extern HBITMAP CreateMirroredBitmap( HBITMAP hbmOrig);
  1189. //+-------------------------------------------------------------------------
  1190. // Creates a special image list for the edit button and configures the edit
  1191. // button to use it. If the hIcon is -1, the edit button is reset to use
  1192. // it's default glyph.
  1193. //--------------------------------------------------------------------------
  1194. void CInternetToolbar::_SetEditGlyph
  1195. (
  1196. int iIcon // new edit button glyph, index into shell image cache
  1197. )
  1198. {
  1199. // If no toolbar, we just need to see if we need to free the old image lists.
  1200. if (_btb._hwnd == NULL)
  1201. {
  1202. if (iIcon == -1)
  1203. {
  1204. if (_himlEdit)
  1205. {
  1206. ImageList_Destroy(_himlEdit);
  1207. _himlEdit = NULL;
  1208. }
  1209. if (_himlEditHot)
  1210. {
  1211. ImageList_Destroy(_himlEditHot);
  1212. _himlEditHot = NULL;
  1213. }
  1214. }
  1215. else
  1216. {
  1217. // Can't set the glyph if no toolbar!
  1218. ASSERT(FALSE);
  1219. }
  1220. return;
  1221. }
  1222. // Determine the button dimensions
  1223. int cx = g_fSmallIcons ? TB_SMBMP_CX : g_iToolBarLargeIconWidth;
  1224. int cy = g_fSmallIcons ? TB_SMBMP_CY : g_iToolBarLargeIconHeight;
  1225. UINT uiCmd = -1;
  1226. // Dochost merges under one of two clsids, so have to check both
  1227. if (FAILED(_btb._ConvertCmd(&CLSID_InternetButtons, DVIDM_EDITPAGE, NULL, &uiCmd)) &&
  1228. FAILED(_btb._ConvertCmd(&CLSID_MSOButtons, DVIDM_EDITPAGE, NULL, &uiCmd)))
  1229. {
  1230. // The edit button is not on toolbar, so free the edit glyphs
  1231. iIcon = -1;
  1232. }
  1233. // If the current icon is already set, we are done
  1234. if ((_iEditIcon == iIcon) && (_cxEditGlyph == cx) && (_cyEditGlyph == cy))
  1235. {
  1236. if (_himlEdit)
  1237. {
  1238. // Set up the new image lists
  1239. SendMessage(_btb._hwnd, TB_SETIMAGELIST, IL_EDITBUTTON, (LPARAM)_himlEdit);
  1240. if (_himlEditHot)
  1241. {
  1242. SendMessage(_btb._hwnd, TB_SETHOTIMAGELIST, IL_EDITBUTTON, (LPARAM)_himlEditHot);
  1243. }
  1244. // Redirect the edit button to the new image list
  1245. TBBUTTONINFO tbi = {0};
  1246. tbi.cbSize = sizeof(tbi);
  1247. tbi.dwMask = TBIF_IMAGE;
  1248. tbi.iImage = MAKELONG(0, IL_EDITBUTTON);
  1249. SendMessage(_btb._hwnd, TB_SETBUTTONINFO, uiCmd, (LPARAM)&tbi);
  1250. }
  1251. return;
  1252. }
  1253. _iEditIcon = iIcon;
  1254. _cxEditGlyph = cx;
  1255. _cyEditGlyph = cy;
  1256. if (-1 == iIcon)
  1257. {
  1258. if (_himlEdit)
  1259. {
  1260. if (uiCmd != -1)
  1261. {
  1262. // Reset to the original edit glyph
  1263. TBBUTTONINFO tbi = {0};
  1264. tbi.cbSize = sizeof(tbi);
  1265. tbi.dwMask = TBIF_IMAGE;
  1266. tbi.iImage = EDITGLYPH_OFFSET;
  1267. SendMessage(_btb._hwnd, TB_SETBUTTONINFO, uiCmd, (LPARAM)&tbi);
  1268. }
  1269. // Destroy the custom edit glyphs. Note that we have to reset the primary image list
  1270. // or the image sizes are messed up.
  1271. SendMessage(_btb._hwnd, TB_SETIMAGELIST, IL_EDITBUTTON, (LPARAM)NULL);
  1272. ImageList_Destroy(_himlEdit);
  1273. _himlEdit = NULL;
  1274. }
  1275. if (_himlEditHot)
  1276. {
  1277. SendMessage(_btb._hwnd, TB_SETHOTIMAGELIST, IL_EDITBUTTON, (LPARAM)NULL);
  1278. ImageList_Destroy(_himlEditHot);
  1279. _himlEditHot = NULL;
  1280. }
  1281. }
  1282. else
  1283. {
  1284. // Get the image bitmaps
  1285. HBITMAP hbmpImage = NULL;
  1286. HBITMAP hbmpMask = NULL;
  1287. BOOL bMirrored = IS_WINDOW_RTL_MIRRORED(_btb._hwnd);
  1288. HIMAGELIST himlSmall;
  1289. int cxSmall;
  1290. int cySmall;
  1291. if (Shell_GetImageLists(NULL, &himlSmall) &&
  1292. ImageList_GetIconSize(himlSmall, &cxSmall, &cySmall) &&
  1293. MyImageList_GetBitmaps(himlSmall, iIcon, (cx - cxSmall)/2, (cy - cySmall)/2,
  1294. cx, cy, &hbmpImage, &hbmpMask))
  1295. {
  1296. if (bMirrored)
  1297. {
  1298. HBITMAP hbmpTemp;
  1299. hbmpTemp = CreateMirroredBitmap(hbmpImage);
  1300. if (hbmpTemp)
  1301. {
  1302. DeleteObject(hbmpImage);
  1303. hbmpImage = hbmpTemp;
  1304. }
  1305. hbmpTemp = CreateMirroredBitmap(hbmpMask);
  1306. if (hbmpTemp)
  1307. {
  1308. DeleteObject(hbmpMask);
  1309. hbmpMask = hbmpTemp;
  1310. }
  1311. }
  1312. // Create a monochrome glyph for the edit button
  1313. HIMAGELIST himlEdit = _CreateGrayScaleImagelist(hbmpImage, hbmpMask);
  1314. SendMessage(_btb._hwnd, TB_SETIMAGELIST, IL_EDITBUTTON, (LPARAM)himlEdit);
  1315. if (_himlEdit)
  1316. {
  1317. ImageList_Destroy(_himlEdit);
  1318. }
  1319. _himlEdit = himlEdit;
  1320. // Create a hot glyph for the edit button
  1321. HIMAGELIST himlEditHot = ImageList_Create(cx, cy, ILC_COLORDDB | ILC_MASK, 1, 1);
  1322. int nIndex = ImageList_Add(himlEditHot, hbmpImage, hbmpMask);
  1323. SendMessage(_btb._hwnd, TB_SETHOTIMAGELIST, IL_EDITBUTTON, (LPARAM)himlEditHot);
  1324. if (_himlEditHot)
  1325. {
  1326. ImageList_Destroy(_himlEditHot);
  1327. }
  1328. _himlEditHot = himlEditHot;
  1329. // Redirect the edit button to the new image list
  1330. if (_himlEdit)
  1331. {
  1332. TBBUTTONINFO tbi = {0};
  1333. tbi.cbSize = sizeof(tbi);
  1334. tbi.dwMask = TBIF_IMAGE;
  1335. tbi.iImage = MAKELONG(nIndex, IL_EDITBUTTON);
  1336. SendMessage(_btb._hwnd, TB_SETBUTTONINFO, uiCmd, (LPARAM)&tbi);
  1337. }
  1338. DeleteObject(hbmpImage);
  1339. DeleteObject(hbmpMask);
  1340. }
  1341. else
  1342. {
  1343. // Couldn't create images so use the default edit glyph
  1344. _SetEditGlyph(-1);
  1345. }
  1346. }
  1347. }
  1348. //+-------------------------------------------------------------------------
  1349. // Initializes the edit button to display a drop-down menu if there are
  1350. // multiple verbs. Also optionally displays a custion glyph.
  1351. //--------------------------------------------------------------------------
  1352. void CInternetToolbar::_InitEditButtonStyle()
  1353. {
  1354. // If we have or want a custon edit glyph, load it
  1355. _SetEditGlyph(_aEditVerb.GetIcon());
  1356. UINT uiCmd;
  1357. // Dochost merges under one of two clsids, so have to check both
  1358. if (SUCCEEDED(_btb._ConvertCmd(&CLSID_InternetButtons, DVIDM_EDITPAGE, NULL, &uiCmd)) ||
  1359. SUCCEEDED(_btb._ConvertCmd(&CLSID_MSOButtons, DVIDM_EDITPAGE, NULL, &uiCmd)))
  1360. {
  1361. ASSERT(uiCmd != -1);
  1362. // If multiple verbs, make the button a split button
  1363. TBBUTTONINFO tbi = {0};
  1364. tbi.cbSize = sizeof(tbi);
  1365. tbi.dwMask = TBIF_STYLE | TBIF_STATE;
  1366. tbi.fsState = 0;
  1367. if (_aEditVerb.GetSize() > 1)
  1368. {
  1369. tbi.fsStyle |= BTNS_DROPDOWN;
  1370. }
  1371. if (_aEditVerb.GetSize() > 0)
  1372. {
  1373. tbi.fsState = TBSTATE_ENABLED;
  1374. }
  1375. SendMessage(_btb._hwnd, TB_SETBUTTONINFO, uiCmd, (LPARAM)&tbi);
  1376. }
  1377. }
  1378. //+-------------------------------------------------------------------------
  1379. // If the edit button is displaying a custon glyph, this function reloads
  1380. // the glyph.
  1381. //--------------------------------------------------------------------------
  1382. void CInternetToolbar::_RefreshEditGlyph()
  1383. {
  1384. // If we have a custon edit glyph, reload it
  1385. if (_himlEdit)
  1386. {
  1387. // Refresh the edit glyph
  1388. _iEditIcon = -1;
  1389. _InitEditButtonStyle();
  1390. }
  1391. }
  1392. //+-------------------------------------------------------------------------
  1393. // Updates the edit button based on the document type currently loaded
  1394. //--------------------------------------------------------------------------
  1395. void CInternetToolbar::_UpdateEditButton()
  1396. {
  1397. _aEditVerb.RemoveAll();
  1398. _fEditEnabled = FALSE;
  1399. BOOL fNoEditSpecified = FALSE;
  1400. //
  1401. // First add editors associated with the url
  1402. //
  1403. BSTR bstrUrl = NULL;
  1404. _pdie->get_LocationURL(&bstrUrl);
  1405. if (bstrUrl)
  1406. {
  1407. LPTSTR pszExt;
  1408. //
  1409. // Find the cache file associated with the url. The file extension for this entry
  1410. // is based off of the mime type. (Note that get_mimeType on the document
  1411. // returns a frindly name that is hard to translate back to an actual mimetype.
  1412. // So we use the file extension instead.)
  1413. //
  1414. WCHAR szCacheFileName[MAX_PATH];
  1415. *szCacheFileName = 0;
  1416. if (FAILED(URLToCacheFile(bstrUrl, szCacheFileName, ARRAYSIZE(szCacheFileName))))
  1417. {
  1418. // If we can't get a file associated with the url, probably want to disable the edit button
  1419. // because most apps need a file to edit.
  1420. SysFreeString(bstrUrl);
  1421. return;
  1422. }
  1423. pszExt = PathFindExtension(szCacheFileName);
  1424. // bug 79055 - The cache has a bug where some html entries are not
  1425. // given a file extension. Too risky to fix for 5.x, so we'll just
  1426. // assume .htm for http if no extension is present.
  1427. if (L'\0' == *pszExt && GetUrlScheme(bstrUrl) == URL_SCHEME_HTTP)
  1428. {
  1429. StrCpyN(szCacheFileName, L".htm", ARRAYSIZE(szCacheFileName));
  1430. pszExt = szCacheFileName;
  1431. }
  1432. if (*pszExt)
  1433. {
  1434. _aEditVerb.Add(pszExt);
  1435. // If ".html", use the ".htm" editors too
  1436. if (StrCmpI(pszExt, L".html") == 0 )
  1437. {
  1438. // This is an html document, so add the .htm editors
  1439. if (!_aEditVerb.Add(TEXT(".htm")) && StrCmpI(pszExt, L".html") != 0)
  1440. {
  1441. _aEditVerb.Add(TEXT(".html"));
  1442. }
  1443. }
  1444. }
  1445. SysFreeString(bstrUrl);
  1446. }
  1447. //
  1448. // See if the feature to search the doc for the progid is enabled
  1449. //
  1450. static int fCheckDocForProgID = -1;
  1451. if (fCheckDocForProgID == -1)
  1452. {
  1453. fCheckDocForProgID = SHRegGetBoolUSValue(REGSTR_PATH_MAIN,
  1454. TEXT("CheckDocumentForProgID"), FALSE, TRUE) ? 1 : 0;
  1455. }
  1456. // Check for a meta tag that specifies a progid for editing this document
  1457. if (fCheckDocForProgID)
  1458. {
  1459. //
  1460. // Next see if this is an html document with a progid
  1461. //
  1462. IWebBrowser2* pWB2 = NULL;
  1463. IDispatch * pDispatch = NULL;
  1464. IHTMLDocument2 * pHTMLDocument = NULL;
  1465. // Get the html document currently loaded
  1466. if (_psp &&
  1467. SUCCEEDED(_psp->QueryService(SID_SWebBrowserApp, IID_PPV_ARG(IWebBrowser2, &pWB2))) &&
  1468. SUCCEEDED(pWB2->get_Document(&pDispatch)) &&
  1469. SUCCEEDED(pDispatch->QueryInterface(IID_PPV_ARG(IHTMLDocument2, &pHTMLDocument))))
  1470. {
  1471. //
  1472. // Check the current document for a META tag specifying the program to use to
  1473. // edit this file.
  1474. //
  1475. BSTR bstrProgID = _GetEditProgID(pHTMLDocument);
  1476. if (bstrProgID)
  1477. {
  1478. if (lstrcmpi(bstrProgID, TEXT("NoEdit")) == 0)
  1479. {
  1480. fNoEditSpecified = TRUE;
  1481. }
  1482. else
  1483. {
  1484. USES_CONVERSION;
  1485. _aEditVerb.Add(W2T(bstrProgID));
  1486. SysFreeString(bstrProgID);
  1487. }
  1488. }
  1489. }
  1490. SAFERELEASE(pWB2);
  1491. SAFERELEASE(pDispatch);
  1492. SAFERELEASE(pHTMLDocument);
  1493. }
  1494. if (!fNoEditSpecified)
  1495. {
  1496. _fEditEnabled = (_aEditVerb.GetSize() > 0);
  1497. }
  1498. // Update edit glyph, drop-down style, & enabled state
  1499. _InitEditButtonStyle();
  1500. }
  1501. #endif //EDIT_HACK
  1502. HRESULT CInternetToolbar::Invoke(DISPID dispidMember,REFIID riid,LCID lcid,WORD wFlags,
  1503. DISPPARAMS * pdispparams, VARIANT * pvarResult,
  1504. EXCEPINFO * pexcepinfo,UINT * puArgErr)
  1505. {
  1506. if(!pdispparams)
  1507. return E_INVALIDARG;
  1508. switch(dispidMember)
  1509. {
  1510. case DISPID_NAVIGATECOMPLETE2:
  1511. {
  1512. //
  1513. // Notify the brand and theater mode objects about whether we're in shell or
  1514. // web mode. Wait til now to do it (rather than doing it in SetCommandTarget)
  1515. // because they might want to ask the browser about the new pidl, which isn't
  1516. // yet filled in at SetCommandTarget time.
  1517. //
  1518. DWORD nCmdexecopt = _fShellView ? CITE_SHELL : CITE_INTERNET;
  1519. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID(CBIDX_BRAND);
  1520. if (pbid)
  1521. {
  1522. IUnknown_Exec(pbid->pdb, &CGID_PrivCITCommands, CITIDM_ONINTERNET, nCmdexecopt, NULL, NULL);
  1523. }
  1524. if (_fTheater)
  1525. {
  1526. IUnknown_Exec(_ptbsite, &CGID_Theater, THID_ONINTERNET, nCmdexecopt, NULL, NULL);
  1527. }
  1528. // If notification is not from a frame, set the _fNavigateComplete flag
  1529. for (DWORD i = 0; i < pdispparams->cArgs; i++)
  1530. {
  1531. if (pdispparams->rgvarg[i].vt == VT_DISPATCH)
  1532. {
  1533. // See who's sending us this event
  1534. IBrowserService* pbs = NULL;
  1535. HRESULT hr = IUnknown_QueryService(pdispparams->rgvarg[i].pdispVal, SID_SShellBrowser, IID_PPV_ARG(IBrowserService, &pbs));
  1536. if (pbs)
  1537. {
  1538. // We don't really need this interface, just its address
  1539. pbs->Release();
  1540. }
  1541. if (SUCCEEDED(hr) && pbs == _pbs)
  1542. {
  1543. // Notification did not come from a frame,
  1544. _fNavigateComplete = TRUE;
  1545. }
  1546. }
  1547. }
  1548. }
  1549. break;
  1550. case DISPID_BEFORENAVIGATE:
  1551. {
  1552. BOOL fWeb = FALSE;
  1553. ASSERT((pdispparams->rgvarg[5].vt == VT_BSTR) &&
  1554. (pdispparams->rgvarg[5].bstrVal != NULL));
  1555. PARSEDURL pu = { 0 };
  1556. USES_CONVERSION;
  1557. pu.cbSize = sizeof(pu);
  1558. ParseURL(W2T(pdispparams->rgvarg[5].bstrVal), &pu);
  1559. if ((URL_SCHEME_UNKNOWN != pu.nScheme) && (URL_SCHEME_FILE != pu.nScheme))
  1560. fWeb = TRUE;
  1561. UINT uiState = 0;
  1562. GetState(&CLSID_CommonButtons, TBIDM_STOPDOWNLOAD, &uiState);
  1563. if ((uiState & TBSTATE_HIDDEN) && fWeb)
  1564. {
  1565. _fTransitionToHTML = TRUE;
  1566. uiState &= ~TBSTATE_HIDDEN;
  1567. SetState(&CLSID_CommonButtons, TBIDM_STOPDOWNLOAD, uiState);
  1568. }
  1569. // Default to the edit button hidden
  1570. _fEditEnabled = FALSE;
  1571. }
  1572. break;
  1573. case DISPID_DOWNLOADBEGIN:// This is when we just started to navigate? No bits?
  1574. _StartDownload();
  1575. break;
  1576. case DISPID_DOWNLOADCOMPLETE: // we be done
  1577. _fTransitionToHTML = FALSE;
  1578. _StopDownload(FALSE);
  1579. break;
  1580. case DISPID_DOCUMENTCOMPLETE: // This is where we have all the bits
  1581. {
  1582. //
  1583. // Sometimes we get a premature document complete (for framesets). We can catch this
  1584. // by checking to see if we have received a DISPID_NAVIGATECOMPLETE2 event
  1585. // for the top window. We have to update the edit button here instead of in
  1586. // navigate complete because otherwise the document is not in the interactive
  1587. // state and our metatag search sees the previous document.
  1588. //
  1589. // REARCHITECT: Is it possible that this event came from a frame and the document is not
  1590. // interactive yet? Trident posts an interactive event right before calling us so
  1591. // we're probably ok. We don't want to wait for the document complete for the top window
  1592. // in framesets because it can take too long. Really need to sink DISPID_READYSTATECHANGE
  1593. // and wait for the document to go interactive.
  1594. //
  1595. if (_fNavigateComplete)
  1596. {
  1597. _fNavigateComplete = FALSE;
  1598. _UpdateEditButton();
  1599. }
  1600. break;
  1601. }
  1602. case DISPID_COMMANDSTATECHANGE:
  1603. BOOL fEnable;
  1604. if(!pdispparams || (pdispparams->cArgs != 2) ||
  1605. (pdispparams->rgvarg[0].vt != VT_BOOL) ||
  1606. (pdispparams->rgvarg[1].vt != VT_I4))
  1607. return E_INVALIDARG;
  1608. fEnable = (BOOL) pdispparams->rgvarg[0].boolVal;
  1609. UINT uiCmd;
  1610. switch (pdispparams->rgvarg[1].lVal)
  1611. {
  1612. case CSC_UPDATECOMMANDS:
  1613. // corresponds to OLECMDID_UPDATECOMMANDS from Exec()
  1614. _UpdateToolbar(FALSE);
  1615. break;
  1616. case CSC_NAVIGATEBACK:
  1617. _fBackEnabled = fEnable;
  1618. _btb._ConvertCmd(&CLSID_CommonButtons, TBIDM_BACK, NULL, &uiCmd);
  1619. SendMessage(_btb._hwnd, TB_ENABLEBUTTON, uiCmd, MAKELONG(fEnable, 0));
  1620. break;
  1621. case CSC_NAVIGATEFORWARD:
  1622. _fForwardEnabled = fEnable;
  1623. _btb._ConvertCmd(&CLSID_CommonButtons, TBIDM_FORWARD, NULL, &uiCmd);
  1624. SendMessage(_btb._hwnd, TB_ENABLEBUTTON, uiCmd, MAKELONG(fEnable, 0));
  1625. break;
  1626. default:
  1627. return(E_INVALIDARG);
  1628. }
  1629. // FEATURE need to handle the case of navigation failure and
  1630. // do some cleanup
  1631. }
  1632. return S_OK;
  1633. }
  1634. // *** IInputObjectSite methods ***
  1635. HRESULT CInternetToolbar::OnFocusChangeIS(IUnknown *punk, BOOL fSetFocus)
  1636. {
  1637. return IUnknown_OnFocusChangeIS(_ptbsite, SAFECAST(this, IInputObject*), fSetFocus);
  1638. }
  1639. //*** CInternetToolbar::IInputObject::* {
  1640. HRESULT CInternetToolbar::TranslateAcceleratorIO(LPMSG lpMsg)
  1641. {
  1642. LPBANDITEMDATA pbid;
  1643. if (_fShow)
  1644. {
  1645. if (lpMsg->message == WM_KEYDOWN)
  1646. {
  1647. switch (lpMsg->wParam)
  1648. {
  1649. case VK_F4:
  1650. Laddrband:
  1651. if (_nVisibleBands & VBF_ADDRESS)
  1652. {
  1653. pbid = _bs._GetBandItemDataStructByID(CBIDX_ADDRESS);
  1654. if (EVAL(pbid))
  1655. {
  1656. HRESULT hrT;
  1657. hrT = IUnknown_TranslateAcceleratorIO(pbid->pdb, lpMsg);
  1658. ASSERT(hrT == S_OK);
  1659. }
  1660. }
  1661. return S_OK; // (even if we just eat it)
  1662. }
  1663. }
  1664. else if(lpMsg->message == WM_SYSCHAR)
  1665. {
  1666. static CHAR szAccel[2] = "\0";
  1667. CHAR szChar [2] = "\0";
  1668. if ('\0' == szAccel[0])
  1669. MLLoadStringA(IDS_ADDRBAND_ACCELLERATOR, szAccel, ARRAYSIZE(szAccel));
  1670. szChar[0] = (CHAR)lpMsg->wParam;
  1671. if (lstrcmpiA(szChar,szAccel) == 0)
  1672. {
  1673. goto Laddrband;
  1674. }
  1675. }
  1676. return _bs.TranslateAcceleratorIO(lpMsg);
  1677. }
  1678. return S_FALSE;
  1679. }
  1680. // }
  1681. HRESULT CInternetToolbar::SetSite(IUnknown* punkSite)
  1682. {
  1683. ATOMICRELEASE(_ptbsite);
  1684. ATOMICRELEASE(_ptbsitect);
  1685. ATOMICRELEASE(_pbs);
  1686. ATOMICRELEASE(_pbs2);
  1687. ATOMICRELEASE(_psp);
  1688. _Unadvise();
  1689. ATOMICRELEASE(_pdie);
  1690. ASSERT(_ptbsite==NULL);
  1691. ASSERT(_ptbsitect==NULL);
  1692. ASSERT(_pbs==NULL);
  1693. ASSERT(_pbs2==NULL);
  1694. ASSERT(_pdie==NULL);
  1695. if (_pbp && _fCreatedBandProxy)
  1696. _pbp->SetSite(punkSite);
  1697. if (punkSite)
  1698. {
  1699. punkSite->QueryInterface(IID_PPV_ARG(IDockingWindowSite, &_ptbsite));
  1700. punkSite->QueryInterface(IID_PPV_ARG(IOleCommandTarget, &_ptbsitect));
  1701. punkSite->QueryInterface(IID_PPV_ARG(IBrowserService2, &_pbs2));
  1702. punkSite->QueryInterface(IID_PPV_ARG(IServiceProvider, &_psp));
  1703. if (_psp)
  1704. {
  1705. _psp->QueryService(SID_SWebBrowserApp, IID_PPV_ARG(IWebBrowser2, &_pdie));
  1706. _psp->QueryService(SID_SShellBrowser, IID_PPV_ARG(IBrowserService, &_pbs));
  1707. ASSERT(_pdie);
  1708. }
  1709. else
  1710. {
  1711. ASSERT(0);
  1712. }
  1713. }
  1714. else
  1715. {
  1716. SetClient(NULL);
  1717. }
  1718. return S_OK;
  1719. }
  1720. //***
  1721. //
  1722. void CInternetToolbar::_UpdateGroup(const GUID *pguidCmdGroup, int cnt,
  1723. OLECMD rgcmds[], const GUID* pguidButton, const int buttonsInternal[])
  1724. {
  1725. if (!IsEqualGUID(*pguidButton, CLSID_CommonButtons) &&
  1726. !IsEqualGUID(*pguidButton, _btb._guidCurrentButtonGroup))
  1727. return; // we don't have any buttons at this time, so no use checking
  1728. if (_ptbsitect)
  1729. {
  1730. _ptbsitect->QueryStatus(pguidCmdGroup, cnt, rgcmds, NULL);
  1731. // make sure stop is enabled while we are animating
  1732. if (_fAnimating && pguidCmdGroup == NULL && rgcmds[0].cmdID == OLECMDID_STOP)
  1733. {
  1734. rgcmds[0].cmdf = OLECMDF_ENABLED;
  1735. }
  1736. }
  1737. for (int i = 0; i < cnt; i++)
  1738. {
  1739. // do nothing if command is not available or not in our table
  1740. if (rgcmds[i].cmdf & OLECMDF_SUPPORTED)
  1741. {
  1742. UINT idBut;
  1743. if (SUCCEEDED(_btb._ConvertCmd(pguidButton, buttonsInternal[i], NULL, (UINT*)&idBut)))
  1744. {
  1745. SendMessage(_btb._hwnd, TB_ENABLEBUTTON, idBut,
  1746. (rgcmds[i].cmdf & OLECMDF_ENABLED) ? TRUE : FALSE);
  1747. SendMessage(_btb._hwnd, TB_CHECKBUTTON, idBut,
  1748. (rgcmds[i].cmdf & OLECMDF_LATCHED) ? TRUE : FALSE);
  1749. }
  1750. }
  1751. }
  1752. return;
  1753. }
  1754. void CInternetToolbar::_UpdateToolbar(BOOL fForce)
  1755. {
  1756. if (fForce || SHIsChildOrSelf(GetForegroundWindow(), _hwnd) == S_OK)
  1757. {
  1758. if (!_fUpdateToolbarTimer)
  1759. {
  1760. SetTimer(_hwnd, IDT_UPDATETOOLBAR, TIMEOUT_UPDATETOOLBAR, NULL);
  1761. _fUpdateToolbarTimer = TRUE;
  1762. _UpdateToolbarNow();
  1763. }
  1764. else
  1765. {
  1766. _fNeedUpdateToolbar = TRUE;
  1767. }
  1768. }
  1769. }
  1770. BOOL CInternetToolbar::_UpEnabled()
  1771. {
  1772. OLECMD rgcmd = { FCIDM_PREVIOUSFOLDER, 0 };
  1773. _ptbsitect->QueryStatus(&CGID_ShellBrowser, 1, &rgcmd, NULL);
  1774. return (rgcmd.cmdf & OLECMDF_ENABLED);
  1775. }
  1776. void CInternetToolbar::_UpdateCommonButton(int iCmd, UINT nCmdID)
  1777. {
  1778. switch (nCmdID)
  1779. {
  1780. case TBIDM_THEATER:
  1781. SendMessage(_btb._hwnd, TB_CHECKBUTTON, iCmd, _fTheater);
  1782. break;
  1783. case TBIDM_PREVIOUSFOLDER:
  1784. case TBIDM_BACK:
  1785. case TBIDM_FORWARD:
  1786. {
  1787. BOOL fEnabled;
  1788. switch (nCmdID)
  1789. {
  1790. case TBIDM_PREVIOUSFOLDER: fEnabled = _UpEnabled(); break;
  1791. case TBIDM_BACK: fEnabled = _fBackEnabled; break;
  1792. case TBIDM_FORWARD: fEnabled = _fForwardEnabled; break;
  1793. }
  1794. SendMessage(_btb._hwnd, TB_ENABLEBUTTON, iCmd, MAKELONG(fEnabled, 0));
  1795. }
  1796. break;
  1797. }
  1798. }
  1799. void CInternetToolbar::_UpdateToolbarNow()
  1800. {
  1801. _fNeedUpdateToolbar = FALSE;
  1802. {
  1803. // MUST not be static (due to ConvertCmd overwrite)
  1804. OLECMD rgcmds[] = {
  1805. { OLECMDID_STOP, 0 }, // NOTE: must be first
  1806. { OLECMDID_REFRESH, 0 },
  1807. };
  1808. static const int buttonsInternal[] = { // MUST be in same order as above array
  1809. TBIDM_STOPDOWNLOAD,
  1810. TBIDM_REFRESH,
  1811. };
  1812. _UpdateGroup(NULL, ARRAYSIZE(buttonsInternal), rgcmds, &CLSID_CommonButtons, buttonsInternal);
  1813. }
  1814. {
  1815. OLECMD rgcmds[] = {
  1816. { SBCMDID_SEARCHBAR, 0 },
  1817. { SBCMDID_FAVORITESBAR, 0 },
  1818. { SBCMDID_HISTORYBAR, 0 },
  1819. { SBCMDID_EXPLORERBAR, 0 },
  1820. { SBCMDID_MEDIABAR, 0 },
  1821. };
  1822. static const int buttonsInternal[] = { // MUST be in same order as above array
  1823. TBIDM_SEARCH,
  1824. TBIDM_FAVORITES,
  1825. TBIDM_HISTORY,
  1826. TBIDM_ALLFOLDERS,
  1827. TBIDM_MEDIABAR,
  1828. };
  1829. _UpdateGroup(&CGID_Explorer, ARRAYSIZE(buttonsInternal), rgcmds, &CLSID_CommonButtons, buttonsInternal);
  1830. }
  1831. int nButtons = (int) SendMessage(_btb._hwnd, TB_BUTTONCOUNT, 0, 0L);
  1832. for (int nIndex = 0; nIndex < nButtons; nIndex++)
  1833. {
  1834. CMDMAP* pcm = _btb._GetCmdMapByIndex(nIndex);
  1835. if (pcm)
  1836. {
  1837. int iCmd = _btb._CommandFromIndex(nIndex);
  1838. if (IsEqualGUID(pcm->guidButtonGroup, CLSID_CommonButtons))
  1839. {
  1840. _UpdateCommonButton(iCmd, pcm->nCmdID);
  1841. }
  1842. else
  1843. {
  1844. // NOTE (andrewgu): ie5.5 b#106047 - the two conditions below used to be ASSERTs,
  1845. // the second one was faulting under stress. if either one of these checks fails,
  1846. // the button is stale.
  1847. if (IsEqualGUID(pcm->guidButtonGroup, _btb._guidCurrentButtonGroup) &&
  1848. NULL != _btb._pctCurrentButtonGroup)
  1849. {
  1850. OLECMD ocButton;
  1851. ocButton.cmdID = pcm->nCmdID;
  1852. ocButton.cmdf = 0;
  1853. if (SUCCEEDED(_btb._pctCurrentButtonGroup->QueryStatus(&pcm->guidButtonGroup, 1, &ocButton, NULL)))
  1854. {
  1855. SendMessage(_btb._hwnd, TB_ENABLEBUTTON, iCmd,
  1856. (ocButton.cmdf & OLECMDF_ENABLED) ? TRUE : FALSE);
  1857. SendMessage(_btb._hwnd, TB_CHECKBUTTON, iCmd,
  1858. (ocButton.cmdf & OLECMDF_LATCHED) ? TRUE : FALSE);
  1859. }
  1860. }
  1861. }
  1862. }
  1863. }
  1864. if (_btb._hwnd)
  1865. {
  1866. _btb._BandInfoChanged();
  1867. }
  1868. }
  1869. void CInternetToolbar::_StartDownload()
  1870. {
  1871. UINT uiCmd;
  1872. if (SUCCEEDED(_btb._ConvertCmd(&CLSID_CommonButtons, TBIDM_STOPDOWNLOAD, NULL, &uiCmd)))
  1873. {
  1874. SendMessage(_btb._hwnd, TB_ENABLEBUTTON, uiCmd, MAKELONG(TRUE, 0));
  1875. _fAnimating = TRUE;
  1876. }
  1877. }
  1878. //
  1879. // Parameters:
  1880. // fClosing -- TRUE only if we are calling this from CloseDW member.
  1881. // In that case, we can skip all UI-update code.
  1882. //
  1883. void CInternetToolbar::_StopDownload(BOOL fClosing)
  1884. {
  1885. _fAnimating = FALSE;
  1886. }
  1887. HRESULT CInternetToolbar::CloseDW(DWORD dwReserved)
  1888. {
  1889. _fDestroyed = TRUE; // Stop using the member variables, they are invalid.
  1890. _StopDownload(TRUE);
  1891. ASSERT(!_btb._pcinfo);
  1892. ATOMICRELEASE(_btb._pctCurrentButtonGroup);
  1893. _btb._FreeBtnsAdded();
  1894. if (_btb._hwnd)
  1895. {
  1896. _btb._RemoveAllButtons();
  1897. SendMessage(_btb._hwnd, TB_SETIMAGELIST, 0, NULL);
  1898. SendMessage(_btb._hwnd, TB_SETHOTIMAGELIST, 0, NULL);
  1899. DSA_Destroy(_hdsaTBBMPs);
  1900. _hdsaTBBMPs = NULL; // So we don't try to re-destroy in _InitBitmapDSA()
  1901. }
  1902. #ifdef EDIT_HACK
  1903. _SetEditGlyph(-1);
  1904. #endif
  1905. _bs._Close();
  1906. SUPERCLASS::CloseDW(dwReserved);
  1907. _btb._hwnd = NULL;
  1908. // We advise during ShowDW, so unadvise here. Also, we hit a stress
  1909. // case where it seems that an event came in after closedw but before
  1910. // one of the other _Unadvise calls. This event percolated down to
  1911. // a reference to _hdsaCT which we freed above, causing a GPF.
  1912. //
  1913. _Unadvise();
  1914. return S_OK;
  1915. }
  1916. void CInternetToolbar::CITBandSite::v_SetTabstop(LPREBARBANDINFO prbbi)
  1917. {
  1918. // Don't set tabstops for all bands in the browser case. A band
  1919. // can still make itself a tabstop by setting WS_TABSTOP.
  1920. return;
  1921. }
  1922. BOOL CInternetToolbar::CITBandSite::_SetMinDimensions()
  1923. {
  1924. INT_PTR fRedraw = SendMessage(_hwnd, WM_SETREDRAW, FALSE, 0);
  1925. int icBands = (int) SendMessage( _hwnd, RB_GETBANDCOUNT, 0, 0 );
  1926. for (int i = 0; i < icBands; i++)
  1927. {
  1928. REBARBANDINFO rbbi;
  1929. rbbi.cbSize = sizeof(REBARBANDINFO);
  1930. rbbi.fMask = RBBIM_ID | RBBIM_CHILDSIZE;
  1931. if (SendMessage(_hwnd, RB_GETBANDINFO, i, (LPARAM) &rbbi))
  1932. {
  1933. LPBANDITEMDATA pbid = (LPBANDITEMDATA)_GetBandItemDataStructByID(rbbi.wID);
  1934. if (EVAL(pbid) && IS_VALID_HANDLE(pbid->hwnd, WND))
  1935. {
  1936. rbbi.cxMinChild = pbid->ptMinSize.x;
  1937. rbbi.cyMinChild = pbid->ptMinSize.y;
  1938. }
  1939. else
  1940. {
  1941. rbbi.cxMinChild = 0;
  1942. rbbi.cyMinChild = 0;
  1943. }
  1944. SendMessage(_hwnd, RB_SETBANDINFO, i, (LPARAM) &rbbi);
  1945. }
  1946. }
  1947. SendMessage(_hwnd, WM_SETREDRAW, fRedraw, 0);
  1948. return TRUE;
  1949. }
  1950. BOOL HimlCacheDirty(IMLCACHE* pimlCache, BOOL fSmallIcons)
  1951. {
  1952. if (fSmallIcons != pimlCache->fSmallIcons)
  1953. return TRUE;
  1954. COLORREF cr3D = GetSysColor(COLOR_3DFACE);
  1955. if (cr3D != pimlCache->cr3D)
  1956. return TRUE;
  1957. if (SHUseClassicToolbarGlyphs() != pimlCache->fUseClassicGlyphs)
  1958. return TRUE;
  1959. for (int i = 0; i < CIMLISTS; i++)
  1960. if (!pimlCache->arhiml[i])
  1961. return TRUE;
  1962. return FALSE;
  1963. }
  1964. #define SZ_REGKEY_SMALLICONS REGSTR_PATH_EXPLORER TEXT("\\SmallIcons")
  1965. #define SZ_REGVALUE_SMALLICONS TEXT("SmallIcons")
  1966. BOOL _DefaultToSmallIcons()
  1967. {
  1968. // We default to small icons if:
  1969. //
  1970. // This is NT 5, or the policy says to use small icons, or this is any
  1971. // of the Whistler servers (server, adv server, dtc)
  1972. return ((GetUIVersion() == 5) || SHRestricted2(REST_SMALLICONS, NULL, 0) ||
  1973. (IsOS(OS_WHISTLERORGREATER) && IsOS(OS_ANYSERVER)));
  1974. }
  1975. BOOL _UseSmallIcons()
  1976. {
  1977. BOOL fDefaultToSmall = _DefaultToSmallIcons();
  1978. return SHRegGetBoolUSValue(SZ_REGKEY_SMALLICONS, SZ_REGVALUE_SMALLICONS,
  1979. FALSE, fDefaultToSmall);
  1980. }
  1981. BOOL _UseMapNetDrvBtns()
  1982. {
  1983. #define SZ_REGKEY_ADVFOLDER TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced")
  1984. #define SZ_REGVALUE_MAPNETDRV TEXT("MapNetDrvBtn")
  1985. DWORD dwData = 0;
  1986. if (GetUIVersion() >= 4)
  1987. {
  1988. DWORD cbData = sizeof(dwData);
  1989. DWORD dwDefault = 0;
  1990. DWORD cbDefault = sizeof(dwDefault);
  1991. SHRegGetUSValue(SZ_REGKEY_ADVFOLDER, SZ_REGVALUE_MAPNETDRV, NULL,
  1992. &dwData, &cbData, FALSE, &dwDefault, cbDefault);
  1993. }
  1994. return dwData;
  1995. }
  1996. HIMAGELIST _LoadThemedToolbarGlyphs(int idBmpType, int iTemperature, int cx, COLORREF crMask, UINT uFlags, BOOL bUseClassicGlyphs, HINSTANCE hInst);
  1997. void _LoadToolbarGlyphs(HWND hwnd, IMLCACHE *pimlCache, int cx, int idBmpType,
  1998. int iBitmapBaseIndex, BOOL bUseClassicGlyphs, HINSTANCE hInst)
  1999. {
  2000. // set uMsg and uFlags for first iteration of loop (default state)
  2001. UINT uMsg = TB_SETIMAGELIST;
  2002. UINT uFlags = LR_CREATEDIBSECTION;
  2003. int i;
  2004. HBITMAP hBMP;
  2005. BOOL fSmallIcons = g_fSmallIcons;
  2006. if (HimlCacheDirty(pimlCache, fSmallIcons))
  2007. {
  2008. COLORREF cr3D = GetSysColor(COLOR_3DFACE);
  2009. COLORREF crMask = RGB( 255, 0, 255 );
  2010. #ifdef UNIX
  2011. if (SHGetCurColorRes() < 2 )
  2012. {
  2013. crMask = CLR_NONE;
  2014. }
  2015. #endif
  2016. ENTERCRITICAL;
  2017. if (!HimlCacheDirty(pimlCache, fSmallIcons) )
  2018. goto DontReload;
  2019. for (i = 0; i < CIMLISTS; i++)
  2020. {
  2021. if ((!pimlCache->arhiml[i]) || (cr3D != pimlCache->cr3D) ||
  2022. (fSmallIcons != pimlCache->fSmallIcons) || (bUseClassicGlyphs != pimlCache->fUseClassicGlyphs))
  2023. {
  2024. TraceMsg(DM_ITBAR, "_LoadToolbarGlyphs: Loading New Images");
  2025. if (pimlCache->arhimlPendingDelete[i])
  2026. ImageList_Destroy(pimlCache->arhimlPendingDelete[i]);
  2027. pimlCache->arhimlPendingDelete[i] = pimlCache->arhiml[i];
  2028. pimlCache->arhiml[i] = _LoadThemedToolbarGlyphs(idBmpType, i, cx, crMask, uFlags, bUseClassicGlyphs, hInst);
  2029. if (pimlCache->arhiml[i])
  2030. {
  2031. // add shell glyphs
  2032. int idShellBmp = iBitmapBaseIndex + idBmpType;
  2033. hBMP = (HBITMAP) LoadImage (hInst, MAKEINTRESOURCE(idShellBmp + i), IMAGE_BITMAP,
  2034. 0, 0, uFlags);
  2035. ImageList_AddMasked(pimlCache->arhiml[i], (HBITMAP)hBMP, crMask);
  2036. DeleteObject(hBMP);
  2037. }
  2038. }
  2039. }
  2040. pimlCache->cr3D = cr3D;
  2041. pimlCache->fSmallIcons = fSmallIcons;
  2042. pimlCache->fUseClassicGlyphs = bUseClassicGlyphs;
  2043. DontReload:
  2044. LEAVECRITICAL;
  2045. }
  2046. if (hwnd)
  2047. {
  2048. ASSERT(IS_VALID_HANDLE(hwnd, WND));
  2049. for (i = 0; i < CIMLISTS; i++)
  2050. {
  2051. SendMessage(hwnd, uMsg, 0, (LPARAM) pimlCache->arhiml[i]);
  2052. // set uMsg and uFlags for last iteration of loop (hot state)
  2053. uMsg = TB_SETHOTIMAGELIST;
  2054. uFlags = 0;
  2055. }
  2056. }
  2057. }
  2058. #ifdef THEME_BUTTONS
  2059. BOOL _GetThemeSetting(HKEY hkey, PDWORD pdwSetting)
  2060. {
  2061. ASSERT(pdwSetting);
  2062. BOOL fRet = FALSE;
  2063. DWORD dwType, dwcbData = sizeof(*pdwSetting);
  2064. *pdwSetting = 0;
  2065. if (ERROR_SUCCESS==SHGetValue(hkey,
  2066. c_szRegKeyCoolbar, TEXT("UseTheme"), &dwType, pdwSetting, &dwcbData))
  2067. {
  2068. // We going to assume that the data type and size is correct. This way, we can break
  2069. // into an error state.
  2070. fRet = TRUE;
  2071. // Acceptable values:
  2072. // 0: use IE6 icons
  2073. // 1: use IE5.5 icons
  2074. // 2: use themed icons
  2075. // other values are reserved.
  2076. if (*pdwSetting > 2)
  2077. {
  2078. *pdwSetting = 0;
  2079. }
  2080. }
  2081. return fRet;
  2082. }
  2083. HIMAGELIST _LoadThemedToolbarGlyphs(int idBmpType, int iTemperature, int cx, COLORREF crMask,
  2084. UINT uFlags, BOOL bUseClassicGlyphs, HINSTANCE hInst)
  2085. {
  2086. HIMAGELIST himl = NULL;
  2087. // Restriction goes here.
  2088. HKEY hkey = HKEY_CURRENT_USER;
  2089. DWORD dwSetting = 0;
  2090. if (!_GetThemeSetting(hkey, &dwSetting))
  2091. {
  2092. hkey = HKEY_LOCAL_MACHINE;
  2093. _GetThemeSetting(hkey, &dwSetting);
  2094. }
  2095. DWORD dwType, dwcbData;
  2096. if (dwSetting==2)
  2097. {
  2098. TCHAR szPath[MAX_PATH];
  2099. TCHAR szItem[] = TEXT("ITBx");
  2100. szItem[3] = TEXT('0') + idBmpType + iTemperature;
  2101. dwcbData = sizeof(szPath);
  2102. if ((ERROR_SUCCESS==SHGetValue(hkey,
  2103. c_szRegKeyCoolbar, szItem, &dwType, szPath, &dwcbData))
  2104. && (dwType==REG_SZ))
  2105. {
  2106. int nBmpIndex = PathParseIconLocation(szPath);
  2107. WCHAR szExpPath[MAX_PATH];
  2108. SHExpandEnvironmentStrings(szPath, szExpPath, ARRAYSIZE(szExpPath));
  2109. // If no resource id, assume it's a bmp file
  2110. if (nBmpIndex==0)
  2111. {
  2112. himl = CreateImageList(NULL,
  2113. szExpPath, cx, 0, crMask,
  2114. IMAGE_BITMAP, uFlags | LR_LOADFROMFILE,
  2115. !bUseClassicGlyphs);
  2116. }
  2117. // Otherwise, see if it's a resouce
  2118. if (!himl)
  2119. {
  2120. HINSTANCE hInst = LoadLibraryEx(szExpPath, NULL, LOAD_LIBRARY_AS_DATAFILE);
  2121. if (hInst)
  2122. {
  2123. himl = CreateImageList(hInst,
  2124. MAKEINTRESOURCE(nBmpIndex), cx, 0, crMask,
  2125. IMAGE_BITMAP, uFlags, !bUseClassicGlyphs);
  2126. FreeLibrary(hInst);
  2127. }
  2128. }
  2129. if (himl)
  2130. {
  2131. // You just can't trust anyone these days. If the graphics aren't the expected
  2132. // size, or there aren't the expected number, we're going to use the defaults
  2133. // ISSUE: 16 is a magic number. Do we have a constant anywhere? I can't find it.
  2134. int ecx, ecy;
  2135. if (!(ImageList_GetIconSize(himl, &ecx, &ecy)
  2136. && (ecx==ecy)
  2137. && (ecy==cx)
  2138. && (ImageList_GetImageCount(himl)==16)))
  2139. {
  2140. ImageList_Destroy(himl);
  2141. himl = NULL;
  2142. }
  2143. }
  2144. }
  2145. }
  2146. if (!himl)
  2147. {
  2148. // dwSetting must be 1 to get IE6 icons. If dwSetting isn't set to 1, then default
  2149. // either to the new Whistler icons or the default IE icons (as appropriate)
  2150. int iResource;
  2151. if (dwSetting == 1)
  2152. {
  2153. iResource = IDB_IE6_TOOLBAR;
  2154. }
  2155. else
  2156. {
  2157. if (bUseClassicGlyphs)
  2158. {
  2159. iResource = IDB_IETOOLBAR;
  2160. }
  2161. else
  2162. {
  2163. iResource = IDB_TB_IE_BASE;
  2164. }
  2165. }
  2166. iResource += (idBmpType + iTemperature);
  2167. himl = CreateImageList(hInst,
  2168. MAKEINTRESOURCE(iResource), cx, 0, crMask,
  2169. IMAGE_BITMAP, uFlags, !bUseClassicGlyphs);
  2170. }
  2171. return himl;
  2172. }
  2173. #else
  2174. HIMAGELIST _LoadThemedToolbarGlyphs(int idBmpType, int iTemperature, int cx, COLORREF crMask,
  2175. UINT uFlags, BOOL bUseClassicGlyphs, HINSTANCE hInst)
  2176. {
  2177. HIMAGELIST himl = NULL;
  2178. int iResource;
  2179. if (bUseClassicGlyphs)
  2180. {
  2181. iResource = IDB_IETOOLBAR;
  2182. }
  2183. else
  2184. {
  2185. iResource = IDB_TB_IE_BASE;
  2186. }
  2187. iResource += (idBmpType + iTemperature);
  2188. himl = CreateImageList(hInst,
  2189. MAKEINTRESOURCE(iResource), cx, 0, crMask,
  2190. IMAGE_BITMAP, uFlags, !bUseClassicGlyphs);
  2191. return himl;
  2192. }
  2193. #endif
  2194. void CInternetToolbar::_InitBitmapDSA()
  2195. {
  2196. DSA_Destroy(_hdsaTBBMPs);
  2197. _hdsaTBBMPs = DSA_Create(sizeof(TBBMP_LIST), TBBMPLIST_CHUNK);
  2198. if (_hdsaTBBMPs)
  2199. {
  2200. TBBMP_LIST tbl = { HINST_COMMCTRL, 0, 0, TRUE, TRUE, FALSE };
  2201. tbl.uiResID = IDB_STD_SMALL_COLOR;
  2202. tbl.uiOffset = OFFSET_STD;
  2203. DSA_AppendItem(_hdsaTBBMPs, &tbl);
  2204. tbl.uiResID = IDB_STD_LARGE_COLOR;
  2205. DSA_AppendItem(_hdsaTBBMPs, &tbl);
  2206. tbl.uiResID = IDB_VIEW_SMALL_COLOR;
  2207. tbl.uiOffset = OFFSET_VIEW;
  2208. DSA_AppendItem(_hdsaTBBMPs, &tbl);
  2209. tbl.uiResID = IDB_VIEW_LARGE_COLOR;
  2210. DSA_AppendItem(_hdsaTBBMPs, &tbl);
  2211. tbl.uiResID = IDB_HIST_SMALL_COLOR;
  2212. tbl.uiOffset = OFFSET_HIST;
  2213. DSA_AppendItem(_hdsaTBBMPs, &tbl);
  2214. tbl.uiResID = IDB_HIST_LARGE_COLOR;
  2215. DSA_AppendItem(_hdsaTBBMPs, &tbl);
  2216. }
  2217. }
  2218. void CInternetToolbar::_ReloadBitmapDSA()
  2219. {
  2220. if (_hdsaTBBMPs)
  2221. {
  2222. INT i = 6;
  2223. TBBMP_LIST * pTBBs = NULL;
  2224. int nCount = DSA_GetItemCount(_hdsaTBBMPs);
  2225. // We want to skip the first 6 entries in the DSA, which are added by InitBitmapDSA
  2226. for (int nIndex = 6; nIndex < nCount; nIndex++)
  2227. {
  2228. pTBBs = (TBBMP_LIST*)DSA_GetItemPtr(_hdsaTBBMPs, nIndex);
  2229. if (pTBBs)
  2230. {
  2231. HIMAGELIST himl = NULL;
  2232. if (pTBBs->fNormal)
  2233. {
  2234. himl = (HIMAGELIST)SendMessage(_btb._hwnd, TB_GETIMAGELIST, 0, 0L);
  2235. if (himl
  2236. && (pTBBs->uiOffset==ImageList_GetImageCount(himl)))
  2237. {
  2238. LRESULT lOffset = _AddBitmapFromForeignModule(TB_GETIMAGELIST, TB_SETIMAGELIST, pTBBs->uiCount, pTBBs->hInst, pTBBs->uiResID, RGB(192,192,192));
  2239. ASSERT(pTBBs->uiOffset==lOffset);
  2240. }
  2241. }
  2242. if (pTBBs->fHot)
  2243. {
  2244. himl = (HIMAGELIST)SendMessage(_btb._hwnd, TB_GETHOTIMAGELIST, 0, 0L);
  2245. if (himl
  2246. && (pTBBs->uiOffset==ImageList_GetImageCount(himl)))
  2247. {
  2248. LRESULT lOffset = _AddBitmapFromForeignModule(TB_GETHOTIMAGELIST, TB_SETHOTIMAGELIST, pTBBs->uiCount, pTBBs->hInst, pTBBs->uiResID, RGB(192,192,192));
  2249. ASSERT(pTBBs->uiOffset==lOffset);
  2250. }
  2251. }
  2252. if (pTBBs->fDisabled)
  2253. {
  2254. himl = (HIMAGELIST)SendMessage(_btb._hwnd, TB_GETDISABLEDIMAGELIST, 0, 0L);
  2255. if (himl
  2256. && (pTBBs->uiOffset==ImageList_GetImageCount(himl)))
  2257. {
  2258. LRESULT lOffset = _AddBitmapFromForeignModule(TB_GETDISABLEDIMAGELIST, TB_SETDISABLEDIMAGELIST, pTBBs->uiCount, pTBBs->hInst, pTBBs->uiResID, RGB(192,192,192));
  2259. ASSERT(pTBBs->uiOffset==lOffset);
  2260. }
  2261. }
  2262. }
  2263. }
  2264. }
  2265. }
  2266. void CInternetToolbar::_InitForScreenSize()
  2267. {
  2268. TCHAR szScratch[16];
  2269. if (GetSystemMetrics(SM_CXSCREEN) < 650)
  2270. {
  2271. MLLoadString(IDS_TB_WIDTH_EXTRA_LORES, szScratch, ARRAYSIZE(szScratch));
  2272. _uiMaxTBWidth = MAX_TB_WIDTH_LORES;
  2273. }
  2274. else
  2275. {
  2276. MLLoadString(IDS_TB_WIDTH_EXTRA_HIRES, szScratch, ARRAYSIZE(szScratch));
  2277. _uiMaxTBWidth = MAX_TB_WIDTH_HIRES;
  2278. }
  2279. _uiMaxTBWidth += StrToInt(szScratch) * WIDTH_FACTOR;
  2280. }
  2281. // removes all buttons marked hidden. returns the number
  2282. // of buttons left
  2283. int RemoveHiddenButtons(TBBUTTON* ptbn, int iCount)
  2284. {
  2285. int i;
  2286. int iTotal = 0;
  2287. TBBUTTON* ptbn1 = ptbn;
  2288. for (i = 0; i < iCount; i++, ptbn1++)
  2289. {
  2290. if (!(ptbn1->fsState & TBSTATE_HIDDEN))
  2291. {
  2292. if (ptbn1 != ptbn)
  2293. {
  2294. *ptbn = *ptbn1;
  2295. }
  2296. ptbn++;
  2297. iTotal++;
  2298. }
  2299. }
  2300. return iTotal;
  2301. }
  2302. #ifdef DEBUG
  2303. void _AssertRestrictionOrderIsCorrect()
  2304. {
  2305. COMPILETIME_ASSERT(ARRAYSIZE(c_tbExplorer) == ARRAYSIZE(c_rest));
  2306. for (UINT i = 0; i < ARRAYSIZE(c_tbExplorer); i++)
  2307. {
  2308. // If any of these rip, it means that c_rest and c_tbExplorer have
  2309. // gotten out of sync. Need to fix up c_rest to match c_tbExplorer.
  2310. switch (c_tbExplorer[i].idCommand)
  2311. {
  2312. case TBIDM_BACK: ASSERT(c_rest[i] == REST_BTN_BACK); break;
  2313. case TBIDM_FORWARD: ASSERT(c_rest[i] == REST_BTN_FORWARD); break;
  2314. case TBIDM_STOPDOWNLOAD: ASSERT(c_rest[i] == REST_BTN_STOPDOWNLOAD); break;
  2315. case TBIDM_REFRESH: ASSERT(c_rest[i] == REST_BTN_REFRESH); break;
  2316. case TBIDM_HOME: ASSERT(c_rest[i] == REST_BTN_HOME); break;
  2317. case TBIDM_SEARCH: ASSERT(c_rest[i] == REST_BTN_SEARCH); break;
  2318. case TBIDM_HISTORY: ASSERT(c_rest[i] == REST_BTN_HISTORY); break;
  2319. case TBIDM_FAVORITES: ASSERT(c_rest[i] == REST_BTN_FAVORITES); break;
  2320. case TBIDM_ALLFOLDERS: ASSERT(c_rest[i] == REST_BTN_ALLFOLDERS); break;
  2321. case TBIDM_THEATER: ASSERT(c_rest[i] == REST_BTN_THEATER); break;
  2322. case TBIDM_MEDIABAR: ASSERT(c_rest[i] == REST_BTN_MEDIABAR); break;
  2323. default: ASSERT(c_rest[i] == REST_BROWSER_NONE); break;
  2324. }
  2325. }
  2326. }
  2327. #endif
  2328. __inline BOOL CInternetToolbar::_FoldersButtonAvailable()
  2329. {
  2330. return (GetUIVersion() >= 4);
  2331. }
  2332. void CInternetToolbar::_AdminMarkDefaultButtons(PTBBUTTON ptbb, UINT cButtons)
  2333. {
  2334. // We only have policies for web buttons.
  2335. ASSERT(!_fShellView);
  2336. // Caller should have checked this.
  2337. ASSERT(SHRestricted2(REST_SPECIFYDEFAULTBUTTONS, NULL, 0));
  2338. // SHRestricted2 returns 0 if it can't find the policy. Assert that
  2339. // this lines up with RESTOPT_BTN_STATE_DEFAULT.
  2340. COMPILETIME_ASSERT(RESTOPT_BTN_STATE_DEFAULT == 0);
  2341. for (UINT i = 0; i < cButtons; i++)
  2342. {
  2343. if (c_rest[i] != 0)
  2344. {
  2345. DWORD dwRest = SHRestricted2(c_rest[i], NULL, 0);
  2346. ptbb[i].fsState = SHBtnStateFromRestriction(dwRest, ptbb[i].fsState);
  2347. }
  2348. }
  2349. // Folders button is not available on non-integrated platforms, so
  2350. // set state to hidden even if policy specifies that it should be shown.
  2351. ASSERT(c_tbExplorer[TBXID_ALLFOLDERS].idCommand == TBIDM_ALLFOLDERS);
  2352. if (!_FoldersButtonAvailable())
  2353. ptbb[TBXID_ALLFOLDERS].fsState |= TBSTATE_HIDDEN;
  2354. }
  2355. void CInternetToolbar::_MarkDefaultButtons(PTBBUTTON ptbb, UINT cButtons)
  2356. {
  2357. if (SHRestricted(REST_NONLEGACYSHELLMODE))
  2358. {
  2359. ASSERT(ptbb[TBXID_BACK].idCommand == TBIDM_BACK);
  2360. ptbb[TBXID_BACK].fsState |= TBSTATE_HIDDEN;
  2361. ASSERT(ptbb[TBXID_FORWARD].idCommand == TBIDM_FORWARD);
  2362. ptbb[TBXID_FORWARD].fsState |= TBSTATE_HIDDEN;
  2363. }
  2364. if (_fShellView)
  2365. {
  2366. ASSERT(c_tbExplorer[TBXID_STOPDOWNLOAD].idCommand == TBIDM_STOPDOWNLOAD);
  2367. ptbb[TBXID_STOPDOWNLOAD].fsState |= TBSTATE_HIDDEN;
  2368. ASSERT(c_tbExplorer[TBXID_REFRESH].idCommand == TBIDM_REFRESH);
  2369. ptbb[TBXID_REFRESH].fsState |= TBSTATE_HIDDEN;
  2370. ASSERT(c_tbExplorer[TBXID_HOME].idCommand == TBIDM_HOME);
  2371. ptbb[TBXID_HOME].fsState |= TBSTATE_HIDDEN;
  2372. ASSERT(c_tbExplorer[TBXID_SEARCH].idCommand == TBIDM_SEARCH);
  2373. ASSERT(c_tbExplorer[TBXID_HISTORY].idCommand == TBIDM_HISTORY);
  2374. ASSERT(c_tbExplorer[TBXID_SEPARATOR2].idCommand == 0); // (a separator)
  2375. if (GetUIVersion() < 5)
  2376. {
  2377. ptbb[TBXID_SEARCH].fsState |= TBSTATE_HIDDEN;
  2378. ptbb[TBXID_HISTORY].fsState |= TBSTATE_HIDDEN;
  2379. ptbb[TBXID_SEPARATOR2].fsState |= TBSTATE_HIDDEN;
  2380. }
  2381. else
  2382. {
  2383. if (GetUIVersion() > 5)
  2384. {
  2385. ptbb[TBXID_HISTORY].fsState |= TBSTATE_HIDDEN;
  2386. }
  2387. if (SHRestricted(REST_NOSHELLSEARCHBUTTON))
  2388. {
  2389. ptbb[TBXID_SEARCH].fsState |= TBSTATE_HIDDEN;
  2390. }
  2391. ASSERT(c_tbExplorer[TBXID_CONNECT].idCommand == TBIDM_CONNECT);
  2392. ASSERT(c_tbExplorer[TBXID_DISCONNECT].idCommand == TBIDM_DISCONNECT);
  2393. if (SHRestricted(REST_NONETCONNECTDISCONNECT))
  2394. {
  2395. ptbb[TBXID_CONNECT].fsState |= TBSTATE_HIDDEN;
  2396. ptbb[TBXID_DISCONNECT].fsState |= TBSTATE_HIDDEN;
  2397. }
  2398. }
  2399. ASSERT(c_tbExplorer[TBXID_FAVORITES].idCommand == TBIDM_FAVORITES);
  2400. ptbb[TBXID_FAVORITES].fsState |= TBSTATE_HIDDEN;
  2401. }
  2402. ASSERT(c_tbExplorer[TBXID_PREVIOUSFOLDER].idCommand == TBIDM_PREVIOUSFOLDER);
  2403. if (!_fShellView)
  2404. ptbb[TBXID_PREVIOUSFOLDER].fsState |= TBSTATE_HIDDEN;
  2405. ASSERT(c_tbExplorer[TBXID_CONNECT].idCommand == TBIDM_CONNECT);
  2406. ASSERT(c_tbExplorer[TBXID_DISCONNECT].idCommand == TBIDM_DISCONNECT);
  2407. if (!_fShellView || !_UseMapNetDrvBtns())
  2408. {
  2409. ptbb[TBXID_CONNECT].fsState |= TBSTATE_HIDDEN;
  2410. ptbb[TBXID_DISCONNECT].fsState |= TBSTATE_HIDDEN;
  2411. }
  2412. // If this TBIDM_ALLFOLDERS assertion rips, remember to fix up _AdminMarkDefaultButtons too.
  2413. ASSERT(c_tbExplorer[TBXID_ALLFOLDERS].idCommand == TBIDM_ALLFOLDERS);
  2414. if (!_fShellView || GetUIVersion() < 5)
  2415. ptbb[TBXID_ALLFOLDERS].fsState |= TBSTATE_HIDDEN;
  2416. ASSERT(c_tbExplorer[TBXID_THEATER].idCommand == TBIDM_THEATER);
  2417. ptbb[TBXID_THEATER].fsState |= TBSTATE_HIDDEN;
  2418. ASSERT(c_tbExplorer[TBXID_MEDIABAR].idCommand == TBIDM_MEDIABAR);
  2419. if (_fShellView || SHRestricted2W(REST_No_LaunchMediaBar, NULL, 0) || !CMediaBarUtil::IsWMP7OrGreaterCapable())
  2420. {
  2421. ptbb[TBXID_MEDIABAR].fsState |= TBSTATE_HIDDEN;
  2422. }
  2423. ASSERT(c_tbExplorer[TBXID_PREVIOUSFOLDER].idCommand == TBIDM_PREVIOUSFOLDER);
  2424. if (!_fShellView)
  2425. {
  2426. ptbb[TBXID_PREVIOUSFOLDER].fsState |= TBSTATE_HIDDEN;
  2427. }
  2428. }
  2429. void CInternetToolbar::_AddCommonButtons()
  2430. {
  2431. TBBUTTON tbExplorer[ARRAYSIZE(c_tbExplorer)];
  2432. memcpy(tbExplorer, c_tbExplorer, sizeof(TBBUTTON) * ARRAYSIZE(c_tbExplorer));
  2433. if (IS_BIDI_LOCALIZED_SYSTEM())
  2434. {
  2435. if (!SHUseClassicToolbarGlyphs())
  2436. {
  2437. tbExplorer[0].iBitmap = 1;
  2438. tbExplorer[1].iBitmap = 0;
  2439. }
  2440. }
  2441. _MarkDefaultButtons(tbExplorer, ARRAYSIZE(c_tbExplorer));
  2442. #ifdef DEBUG
  2443. _AssertRestrictionOrderIsCorrect();
  2444. #endif
  2445. if (!_fShellView && SHRestricted2(REST_SPECIFYDEFAULTBUTTONS, NULL, 0))
  2446. _AdminMarkDefaultButtons(tbExplorer, ARRAYSIZE(c_tbExplorer));
  2447. int iButtons = RemoveHiddenButtons(tbExplorer, ARRAYSIZE(tbExplorer));
  2448. for (int i = 0; i < iButtons; i++)
  2449. {
  2450. if (!(tbExplorer[i].fsStyle & BTNS_SEP))
  2451. {
  2452. CMDMAP* pcm = (CMDMAP*)LocalAlloc(LPTR, sizeof(CMDMAP));
  2453. if (pcm)
  2454. {
  2455. pcm->guidButtonGroup = CLSID_CommonButtons;
  2456. pcm->nCmdID = tbExplorer[i].idCommand;
  2457. tbExplorer[i].idCommand = _btb._nNextCommandID++;
  2458. tbExplorer[i].dwData = (LPARAM)pcm;
  2459. }
  2460. }
  2461. }
  2462. SendMessage(_btb._hwnd, TB_ADDBUTTONS, iButtons, (LPARAM) tbExplorer);
  2463. _btb._RecalcButtonWidths();
  2464. }
  2465. #define IS_LIST_STYLE(hwnd) (BOOLIFY(GetWindowLong(hwnd, GWL_STYLE) & TBSTYLE_LIST))
  2466. void CInternetToolbar::_UpdateToolsStyle(BOOL fList)
  2467. {
  2468. if (BOOLIFY(fList) != IS_LIST_STYLE(_btb._hwnd))
  2469. {
  2470. _fDirty = TRUE;
  2471. // toggle TBSTYLE_LIST
  2472. SHSetWindowBits(_btb._hwnd, GWL_STYLE, TBSTYLE_LIST, fList ? TBSTYLE_LIST : 0);
  2473. // toggle TBSTYLE_EX_MIXEDBUTTONS
  2474. SendMessage(_btb._hwnd, TB_SETEXTENDEDSTYLE, TBSTYLE_EX_MIXEDBUTTONS, fList ? TBSTYLE_EX_MIXEDBUTTONS : 0);
  2475. }
  2476. }
  2477. void CInternetToolbar::_InitToolbar()
  2478. {
  2479. TCHAR szShellTBText[1024]; // This should be enough
  2480. ZeroMemory(szShellTBText, sizeof(szShellTBText));
  2481. int nRows = _fCompressed ? 0 : _uiTBTextRows;
  2482. DWORD dwStyle = TBSTYLE_EX_DRAWDDARROWS | TBSTYLE_EX_HIDECLIPPEDBUTTONS;
  2483. if (IsOS(OS_WHISTLERORGREATER))
  2484. dwStyle |= TBSTYLE_EX_DOUBLEBUFFER;
  2485. // this tells the toolbar what version we are
  2486. SendMessage(_btb._hwnd, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0);
  2487. SendMessage(_btb._hwnd, TB_SETEXTENDEDSTYLE, dwStyle, dwStyle);
  2488. SendMessage(_btb._hwnd, TB_SETMAXTEXTROWS, nRows, 0L);
  2489. SendMessage(_btb._hwnd, TB_SETDROPDOWNGAP, GetSystemMetrics(SM_CXEDGE) / 2, 0);
  2490. SendMessage(_btb._hwnd, CCM_SETVERSION, COMCTL32_VERSION, 0);
  2491. _UpdateToolsStyle(_cs.fList);
  2492. _fDirty = FALSE; // _UpdateToolsStyle unfortunately sets this early on; but we can assume we're not dirty now.
  2493. ITBar_LoadToolbarGlyphs(_btb._hwnd);
  2494. _InitBitmapDSA();
  2495. _InitForScreenSize();
  2496. SendMessage(_btb._hwnd, TB_ADDSTRING, (WPARAM)MLGetHinst(), IDS_IE_TB_LABELS);
  2497. _AddCommonButtons();
  2498. INT_PTR nRet = SendMessage(_btb._hwnd, TB_ADDSTRING, (WPARAM)MLGetHinst(), IDS_SHELL_TB_LABELS);
  2499. #ifdef DEBUG
  2500. if (nRet != SHELLTOOLBAR_OFFSET)
  2501. TraceMsg(TF_ERROR, "CInternetToolbar::_InitToolbar -- nRet != SHELLTOOLBAR_OFFSET");
  2502. #endif
  2503. }
  2504. HRESULT CInternetToolbar::_ShowTools(PBANDSAVE pbs)
  2505. {
  2506. HRESULT hr = S_OK;
  2507. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID(CBIDX_TOOLS);
  2508. if (!pbid)
  2509. {
  2510. ASSERT(!_btb._hwnd);
  2511. _btb._hwnd = CreateWindowEx(WS_EX_TOOLWINDOW, TOOLBARCLASSNAME, NULL,
  2512. WS_CHILD | TBSTYLE_FLAT |
  2513. TBSTYLE_TOOLTIPS |
  2514. WS_CLIPCHILDREN |
  2515. WS_CLIPSIBLINGS | CCS_NODIVIDER | CCS_NOPARENTALIGN |
  2516. CCS_NORESIZE,
  2517. 0, 0, 0, 0, _bs._hwnd, (HMENU) FCIDM_TOOLBAR, HINST_THISDLL, NULL);
  2518. if (_btb._hwnd)
  2519. {
  2520. _InitToolbar();
  2521. pbid = _AddNewBand((IDeskBand*)&_btb, CBIDX_TOOLS);
  2522. }
  2523. if (!pbid)
  2524. return E_OUTOFMEMORY;
  2525. }
  2526. else
  2527. {
  2528. pbs = NULL;
  2529. }
  2530. _ShowBandCommon(pbs, pbid, _nVisibleBands & VBF_TOOLS);
  2531. return hr;
  2532. }
  2533. void CInternetToolbar::_ShowBandCommon(PBANDSAVE pbs, LPBANDITEMDATA pbid, BOOL fShow)
  2534. {
  2535. REBARBANDINFO rbbi;
  2536. pbid->fShow = BOOLIFY(fShow);
  2537. if (pbid->pdb)
  2538. {
  2539. pbid->pdb->ShowDW(pbid->fShow);
  2540. }
  2541. INT_PTR i = BandIDtoIndex(_bs._hwnd, pbid->dwBandID);
  2542. if (pbs)
  2543. {
  2544. rbbi.cbSize = sizeof(REBARBANDINFO);
  2545. rbbi.fMask = RBBIM_SIZE | RBBIM_STYLE;
  2546. // we just want to change the RBBS_BREAK bit
  2547. // assert that our caller doesn't expect to set any other bits
  2548. // ASSERT(!(pbs->fStyle & ~RBBS_BREAK)); <--- I hit this assert all the time
  2549. // get old style
  2550. SendMessage(_bs._hwnd, RB_GETBANDINFO, i, (LPARAM)&rbbi);
  2551. rbbi.fStyle = (rbbi.fStyle & ~RBBS_BREAK) | (pbs->fStyle & RBBS_BREAK);
  2552. rbbi.cx = pbs->cx;
  2553. SendMessage(_bs._hwnd, RB_SETBANDINFO, i, (LPARAM)&rbbi);
  2554. }
  2555. if ( pbid->dwModeFlags & DBIMF_BREAK )
  2556. {
  2557. rbbi.cbSize = sizeof(REBARBANDINFO);
  2558. rbbi.fMask = RBBIM_STYLE;
  2559. if (SendMessage(_bs._hwnd, RB_GETBANDINFO, i, (LPARAM) &rbbi))
  2560. {
  2561. // in theater mode we don't allow bands to have breaks
  2562. if ((rbbi.fStyle & RBBS_BREAK ) && _fTheater)
  2563. {
  2564. rbbi.fStyle &= ~RBBS_BREAK;
  2565. SendMessage(_bs._hwnd, RB_SETBANDINFO, i, (LPARAM) &rbbi);
  2566. }
  2567. }
  2568. }
  2569. SendMessage(_bs._hwnd, RB_SHOWBAND, i, pbid->fShow);
  2570. }
  2571. HRESULT CInternetToolbar::_GetPersistedBand(const CLSID clsid, REFIID riid, void ** ppiface)
  2572. {
  2573. HRESULT hr = E_FAIL;
  2574. TCHAR szStreamName[MAX_PATH];
  2575. if (SUCCEEDED(_GetStreamName(_fInitialPidlIsWeb, szStreamName, ARRAYSIZE(szStreamName))))
  2576. {
  2577. static BOOL fBrowserOnly = (WhichPlatform() != PLATFORM_INTEGRATED);
  2578. TCHAR szKey[MAX_PATH];
  2579. TCHAR szGUID[MAX_PATH];
  2580. wnsprintf(szKey, ARRAYSIZE(szKey), TEXT("Software\\Microsoft\\Internet Explorer\\Toolbar\\%s"), szStreamName);
  2581. SHStringFromGUID(clsid, szGUID, ARRAYSIZE(szGUID));
  2582. if (ERROR_SUCCESS == SHGetValue(HKEY_CURRENT_USER, szKey, szGUID, NULL, NULL, NULL))
  2583. {
  2584. // Was the stream saved by an Integrated shell and we are in browser only mode?
  2585. if ((_cs.fSaveInShellIntegrationMode) && fBrowserOnly)
  2586. {
  2587. // Yes, so we need to ignore the stream.
  2588. }
  2589. else
  2590. {
  2591. IStream * pstm = GetRegStream(_fInitialPidlIsWeb, szGUID, STGM_READ);
  2592. if (pstm)
  2593. {
  2594. hr = _bs.LoadFromStreamBS(pstm, riid, ppiface);
  2595. pstm->Release();
  2596. }
  2597. }
  2598. }
  2599. }
  2600. if (FAILED(hr))
  2601. {
  2602. hr = CoCreateInstance(clsid, NULL, CLSCTX_INPROC_SERVER, riid, ppiface);
  2603. if (SUCCEEDED(hr))
  2604. {
  2605. IPersistStreamInit * ppsi;
  2606. ((IUnknown *) *ppiface)->QueryInterface(IID_PPV_ARG(IPersistStreamInit, &ppsi));
  2607. if (ppsi)
  2608. {
  2609. ppsi->InitNew();
  2610. ppsi->Release();
  2611. }
  2612. }
  2613. }
  2614. return hr;
  2615. }
  2616. HRESULT CInternetToolbar::_ShowExternalBand( PBANDSAVE pbs, int idBand )
  2617. {
  2618. HRESULT hr;
  2619. if (IS_EXTERNALBAND(idBand))
  2620. {
  2621. int idBandExt = MAP_TO_EXTERNAL(idBand);
  2622. if (!IsEqualCLSID(_rgebi[idBandExt].clsid, GUID_NULL))
  2623. {
  2624. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID( idBand );
  2625. BOOL fIsVisible = _nVisibleBands & EXTERNALBAND_VBF_BIT(idBandExt);
  2626. if (!pbid && fIsVisible)
  2627. {
  2628. IDeskBand *pitbBand;
  2629. hr = _GetPersistedBand(_rgebi[idBandExt].clsid, IID_PPV_ARG(IDeskBand, &pitbBand));
  2630. if (SUCCEEDED(hr))
  2631. {
  2632. pbid = _AddNewBand( pitbBand, idBand );
  2633. pitbBand->Release();
  2634. }
  2635. if (!pbid)
  2636. return E_OUTOFMEMORY;
  2637. }
  2638. else
  2639. {
  2640. pbs = NULL;
  2641. if (!pbid)
  2642. return S_OK;
  2643. }
  2644. _ShowBandCommon(pbs, pbid, fIsVisible );
  2645. }
  2646. }
  2647. return S_OK;
  2648. }
  2649. HRESULT CInternetToolbar::_ShowAddressBand(PBANDSAVE pbs)
  2650. {
  2651. HRESULT hr = S_OK;
  2652. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID(CBIDX_ADDRESS);
  2653. if (!pbid)
  2654. {
  2655. if (_nVisibleBands & VBF_ADDRESS)
  2656. {
  2657. IDeskBand *pitbAddressBand;
  2658. hr = _GetPersistedBand(CLSID_AddressBand, IID_PPV_ARG(IDeskBand, &pitbAddressBand));
  2659. if (SUCCEEDED(hr))
  2660. {
  2661. pbid = _AddNewBand(pitbAddressBand, CBIDX_ADDRESS);
  2662. if (pbid)
  2663. {
  2664. _hwndAddressBand = pbid->hwnd;
  2665. if (!pbs)
  2666. {
  2667. for (int i = 0; i < CBANDSMAX; i++)
  2668. {
  2669. if (_cs.bs[i].wID == CBIDX_ADDRESS)
  2670. {
  2671. pbs = _cs.bs + i;
  2672. break;
  2673. }
  2674. }
  2675. }
  2676. }
  2677. pitbAddressBand->Release();
  2678. }
  2679. }
  2680. else
  2681. {
  2682. return S_OK;
  2683. }
  2684. if (!pbid)
  2685. return E_OUTOFMEMORY;
  2686. }
  2687. else
  2688. pbs = NULL;
  2689. _ShowBandCommon(pbs, pbid, _nVisibleBands & VBF_ADDRESS);
  2690. return S_OK;
  2691. }
  2692. LPBANDITEMDATA CInternetToolbar::_AddNewBand(IDeskBand* pdb, DWORD dwID)
  2693. {
  2694. if (SUCCEEDED(_bs._AddBandByID(pdb, dwID)))
  2695. {
  2696. return _bs._GetBandItemDataStructByID(dwID);
  2697. }
  2698. return NULL;
  2699. }
  2700. HRESULT CInternetToolbar::_ShowLinks(PBANDSAVE pbs)
  2701. {
  2702. HRESULT hr = S_OK;
  2703. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID(CBIDX_LINKS);
  2704. if (!pbid)
  2705. {
  2706. IDeskBand* pdbLinks = NULL;
  2707. // Check if custom link band GUID is present in the registry,
  2708. // and if so, do a full CoCreateInstance using this GUID.
  2709. // Otherwise, just do the normal internal call to the link's band factory.
  2710. if (_nVisibleBands & VBF_LINKS)
  2711. {
  2712. if (!_fInitialPidlIsWeb ||
  2713. FAILED(CreateFromRegKey(c_szRegKeyCoolbar, TEXT("QuickLinksCLSID"), IID_PPV_ARG(IDeskBand, &pdbLinks))))
  2714. {
  2715. hr = _GetPersistedBand(CLSID_QuickLinks, IID_PPV_ARG(IDeskBand, &pdbLinks));
  2716. IUnknown_Exec(pdbLinks, &CLSID_QuickLinks, QLCMD_SINGLELINE, 1, NULL, NULL);
  2717. }
  2718. }
  2719. else
  2720. {
  2721. return S_OK;
  2722. }
  2723. if (pdbLinks)
  2724. {
  2725. // mark it so ISFBand knows it's qlinks (for UAssist)
  2726. VARIANTARG v;
  2727. #ifdef DEBUG
  2728. {
  2729. // n.b. we overwrite old persisted guys (which should be -1)
  2730. IUnknown_Exec(pdbLinks, &CGID_ISFBand, ISFBID_PRIVATEID, 0, NULL, &v);
  2731. ASSERT(v.lVal == -1 || v.lVal == CSIDL_FAVORITES);
  2732. }
  2733. #endif
  2734. v.vt = VT_I4;
  2735. v.lVal = CSIDL_FAVORITES; // close enough for our purposes...
  2736. IUnknown_Exec(pdbLinks, &CGID_ISFBand, ISFBID_PRIVATEID, 0, &v, NULL);
  2737. pbid = _AddNewBand(pdbLinks, CBIDX_LINKS);
  2738. if (pbid && !pbs)
  2739. {
  2740. for (int i = 0; i < CBANDSMAX; i++)
  2741. {
  2742. if (_cs.bs[i].wID == CBIDX_LINKS)
  2743. {
  2744. pbs = _cs.bs + i;
  2745. break;
  2746. }
  2747. }
  2748. }
  2749. pdbLinks->Release();
  2750. }
  2751. if (!pbid)
  2752. return E_OUTOFMEMORY;
  2753. }
  2754. else
  2755. pbs = NULL;
  2756. _ShowBandCommon(pbs, pbid, _nVisibleBands & VBF_LINKS);
  2757. return hr;
  2758. }
  2759. HRESULT CInternetToolbar::_ShowMenu(PBANDSAVE pbs)
  2760. {
  2761. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID(CBIDX_MENU);
  2762. if (!pbid)
  2763. {
  2764. CFavoritesCallback* pfcb = new CFavoritesCallback();
  2765. if (pfcb)
  2766. {
  2767. IShellMenu* psm;
  2768. if (SUCCEEDED(CoCreateInstance(CLSID_MenuBand, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IShellMenu, &psm))))
  2769. {
  2770. VARIANTARG var;
  2771. if (SUCCEEDED(IUnknown_Exec(_pbs2, &CGID_Explorer, SBCMDID_GETCURRENTMENU, 0, NULL, &var)) &&
  2772. var.vt == VT_INT_PTR && var.byref)
  2773. {
  2774. IDeskBand* pdbMenu;
  2775. if (SUCCEEDED(psm->Initialize(pfcb, -1, ANCESTORDEFAULT, SMINIT_HORIZONTAL | SMINIT_TOPLEVEL)) &&
  2776. SUCCEEDED(psm->SetMenu((HMENU)var.byref, GetParent(_hwnd), SMSET_DONTOWN)) &&
  2777. SUCCEEDED(psm->QueryInterface(IID_PPV_ARG(IDeskBand, &pdbMenu))))
  2778. {
  2779. pbid = _AddNewBand(pdbMenu, CBIDX_MENU);
  2780. if (pbid)
  2781. {
  2782. // Tell the menuband we're not a real bar/bandsite/band
  2783. IUnknown_Exec(pbid->pdb, &CGID_MenuBand, MBANDCID_NOTAREALSITE, TRUE, NULL, NULL);
  2784. _bs.SetBandState(CBIDX_MENU, BSSF_NOTITLE, BSSF_NOTITLE);
  2785. _hwndMenu = pbid->hwnd;
  2786. }
  2787. pdbMenu->Release();
  2788. }
  2789. }
  2790. psm->Release();
  2791. }
  2792. pfcb->Release();
  2793. }
  2794. if (!pbid)
  2795. return E_OUTOFMEMORY;
  2796. }
  2797. else
  2798. pbs = NULL;
  2799. _ShowBandCommon(pbs, pbid, _nVisibleBands & VBF_MENU);
  2800. return S_OK;
  2801. }
  2802. HBITMAP CInternetToolbar::_LoadBackBitmap()
  2803. {
  2804. if (SHIsLowMemoryMachine(ILMM_IE4))
  2805. return NULL;
  2806. if (_fInitialPidlIsWeb)
  2807. {
  2808. static LPTSTR s_pszBitmapInternet = NULL;
  2809. return LoadToolbarBackBmp(&s_pszBitmapInternet, &s_bmpBackInternet, _fInitialPidlIsWeb);
  2810. }
  2811. else
  2812. {
  2813. static LPTSTR s_pszBitmapShell = NULL;
  2814. return LoadToolbarBackBmp(&s_pszBitmapShell, &s_bmpBackShell, _fInitialPidlIsWeb);
  2815. }
  2816. }
  2817. void CInternetToolbar::_SetBackground()
  2818. {
  2819. REBARBANDINFO rbbi;
  2820. HBITMAP hbmp;
  2821. // Theater mode doesn't allow bitmap customization, so don't bother loading one from the cache
  2822. if (_fTheater)
  2823. hbmp = NULL;
  2824. else
  2825. hbmp = _LoadBackBitmap();
  2826. // don't bother updating the bkcolor if we know we'll just set it to CLR_NONE below (otherwise rebar invalidates)
  2827. if (!hbmp)
  2828. SendMessage(_bs._hwnd, RB_SETBKCOLOR, 0, (LPARAM)GetSysColor(COLOR_BTNFACE));
  2829. // If we think we have a bitmap, or the cache thinks we have a bitmap, we have some work to do
  2830. if (_bmpBack || hbmp)
  2831. {
  2832. BOOL fRemove = (NULL!=_bmpBack && NULL==hbmp);
  2833. if (hbmp)
  2834. SendMessage(_bs._hwnd, RB_SETBKCOLOR, 0, (LPARAM)CLR_NONE);
  2835. _bmpBack = hbmp;
  2836. rbbi.cbSize = sizeof(REBARBANDINFO);
  2837. INT_PTR fRedraw = SendMessage(_bs._hwnd, WM_SETREDRAW, FALSE, 0);
  2838. INT icBands = (INT) SendMessage( _bs._hwnd, RB_GETBANDCOUNT, 0, 0 );
  2839. for (int i = 0; i < icBands; i++)
  2840. {
  2841. rbbi.fMask = RBBIM_ID | RBBIM_CHILD | RBBIM_BACKGROUND;
  2842. if (SendMessage(_bs._hwnd, RB_GETBANDINFO, i, (LPARAM) &rbbi))
  2843. {
  2844. if (rbbi.wID != CBIDX_BRAND && rbbi.hbmBack != hbmp)
  2845. {
  2846. rbbi.fMask = RBBIM_BACKGROUND;
  2847. rbbi.hbmBack = hbmp;
  2848. SendMessage(_bs._hwnd, RB_SETBANDINFO, i, (LPARAM) &rbbi);
  2849. InvalidateRect(rbbi.hwndChild, NULL, TRUE);
  2850. }
  2851. }
  2852. }
  2853. SendMessage(_bs._hwnd, WM_SETREDRAW, fRedraw, 0);
  2854. // When removing the background bitmap, we need to invalidate *outside*
  2855. // of the WM_SETREDRAW so we actually erase the background properly
  2856. //
  2857. if (fRemove)
  2858. InvalidateRect(_bs._hwnd, NULL, TRUE);
  2859. }
  2860. }
  2861. HRESULT CInternetToolbar::_ShowBrand(PBANDSAVE pbs)
  2862. {
  2863. REBARBANDINFO rbbi;
  2864. LPBANDITEMDATA pbid;
  2865. INT_PTR i;
  2866. HRESULT hr = S_OK;
  2867. BOOL fCreated = FALSE;
  2868. pbid = _bs._GetBandItemDataStructByID(CBIDX_BRAND);
  2869. if (!pbid)
  2870. {
  2871. IDeskBand *pdbBrandBand;
  2872. hr = CBrandBand_CreateInstance(NULL, (IUnknown **)&pdbBrandBand, NULL);
  2873. if (SUCCEEDED(hr))
  2874. {
  2875. pbid = _AddNewBand(pdbBrandBand, CBIDX_BRAND);
  2876. fCreated = TRUE;
  2877. pdbBrandBand->Release();
  2878. }
  2879. else
  2880. return hr;
  2881. }
  2882. if (!pbid)
  2883. return E_OUTOFMEMORY;
  2884. pbid->pdb->ShowDW(TRUE);
  2885. i = BandIDtoIndex(_bs._hwnd, CBIDX_BRAND);
  2886. if (fCreated)
  2887. {
  2888. // add these to ::IDeskBand::GetBandInfo()
  2889. rbbi.cbSize = sizeof(REBARBANDINFO);
  2890. rbbi.fMask = RBBIM_STYLE;
  2891. rbbi.fStyle = RBBS_FIXEDSIZE | RBBS_VARIABLEHEIGHT;
  2892. if (pbs)
  2893. {
  2894. rbbi.fMask |= RBBIM_SIZE;
  2895. rbbi.fStyle |= pbs->fStyle;
  2896. rbbi.cx = pbs->cx;
  2897. }
  2898. SendMessage(_bs._hwnd, RB_SETBANDINFO, i, (LPARAM)&rbbi);
  2899. // this can cause the band to move because a fixed size band
  2900. // is forced in a particular location.
  2901. // so we need to re-fetch the index
  2902. i = BandIDtoIndex(_bs._hwnd, CBIDX_BRAND);
  2903. }
  2904. SendMessage(_bs._hwnd, RB_SHOWBAND, i, _nVisibleBands & VBF_BRAND);
  2905. return S_OK;
  2906. }
  2907. void CInternetToolbar::_EnsureAllBandsShown()
  2908. {
  2909. if (_hwnd)
  2910. {
  2911. INT_PTR fRedraw = SendMessage(_bs._hwnd, WM_SETREDRAW, FALSE, 0);
  2912. _ShowMenu(NULL);
  2913. _ShowTools(NULL);
  2914. _ShowAddressBand(NULL);
  2915. _ShowLinks(NULL);
  2916. _ShowBrand(NULL);
  2917. for (int i = CBIDX_EXTERNALFIRST; i <= CBIDX_EXTERNALLAST; i++)
  2918. {
  2919. _ShowExternalBand( NULL, i );
  2920. }
  2921. _SetBackground();
  2922. _bs._SetMinDimensions();
  2923. _UpdateLocking();
  2924. SendMessage(_bs._hwnd, WM_SETREDRAW, fRedraw, 0);
  2925. }
  2926. }
  2927. BOOL CInternetToolbar::_ShowBands(UINT fVisible)
  2928. {
  2929. fVisible &= VBF_VALID;
  2930. if (fVisible == _nVisibleBands)
  2931. return(TRUE);
  2932. _nVisibleBands = fVisible;
  2933. _EnsureAllBandsShown();
  2934. ShowDW(_fShow);
  2935. return(TRUE);
  2936. }
  2937. HRESULT CInternetToolbar::_CreateBands()
  2938. {
  2939. HRESULT hr = S_OK;
  2940. if (!_hwnd && _ptbsite)
  2941. {
  2942. HWND hwndParent;
  2943. hr = _ptbsite->GetWindow(&hwndParent);
  2944. if (SUCCEEDED(hr))
  2945. {
  2946. TCHAR szScratch[16];
  2947. int i;
  2948. // Check if coolbar layout had already been loaded from the registry
  2949. if(_cs.cbVer != CBS_VERSION)
  2950. {
  2951. TraceMsg(DM_ITBAR, "CInternetToolbar::_CreateBands failed. Bad Version");
  2952. ASSERT(0);
  2953. return(S_FALSE);
  2954. }
  2955. _nVisibleBands = _cs.uiVisible;
  2956. _InitComCtl32(); // don't check result, if this fails our CreateWindows will fail
  2957. MLLoadString(IDS_WEB_TB_TEXTROWS, szScratch, ARRAYSIZE(szScratch));
  2958. _uiTBTextRows = _uiTBDefaultTextRows = StrToInt(szScratch);
  2959. _fCompressed = (_cs.fNoText != FALSE);
  2960. _hwnd = SHCreateWorkerWindow(SizableWndProc, hwndParent, 0, WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
  2961. (HMENU)FCIDM_REBAR, this);
  2962. if (!IS_VALID_HANDLE(_hwnd, WND))
  2963. {
  2964. _fDontSave = TRUE;
  2965. TraceMsg(TF_ERROR, "CInternetToolbar::_CreateBands() - _hwnd failed");
  2966. return E_OUTOFMEMORY;
  2967. }
  2968. // delay until now
  2969. // this sets up the parent child chain so that these children can
  2970. // queryservice through us
  2971. hr = SetClient(SAFECAST(&_bs, IInputObjectSite*));
  2972. if (SUCCEEDED(hr))
  2973. {
  2974. INT_PTR fRedraw = SendMessage(_bs._hwnd, WM_SETREDRAW, FALSE, 0);
  2975. for (i = 0; i < CBANDSMAX; i++)
  2976. {
  2977. hr = S_OK;
  2978. switch (_cs.bs[i].wID)
  2979. {
  2980. case CBIDX_TOOLS:
  2981. if(!SHRestricted2W(REST_NoToolBar, NULL, 0))
  2982. {
  2983. hr = _ShowTools(_cs.bs + i);
  2984. }
  2985. else
  2986. {
  2987. _nVisibleBands &= ~VBF_TOOLS;
  2988. }
  2989. break;
  2990. case CBIDX_ADDRESS:
  2991. if(!SHRestricted2W(REST_NoAddressBar, NULL, 0))
  2992. {
  2993. hr = _ShowAddressBand(_cs.bs + i);
  2994. }
  2995. else
  2996. {
  2997. _nVisibleBands &= ~VBF_ADDRESS;
  2998. }
  2999. break;
  3000. case CBIDX_LINKS:
  3001. if(!SHRestricted2W(REST_NoLinksBar, NULL, 0))
  3002. {
  3003. hr = _ShowLinks(_cs.bs + i);
  3004. }
  3005. else
  3006. {
  3007. _nVisibleBands &= ~VBF_LINKS;
  3008. }
  3009. break;
  3010. case CBIDX_BRAND:
  3011. hr = _ShowBrand(_cs.bs + i);
  3012. break;
  3013. case CBIDX_MENU:
  3014. hr = _ShowMenu(_cs.bs + i);
  3015. break;
  3016. // If there is no id associated, there's nothing more to restore.
  3017. case 0:
  3018. {
  3019. // Out of bands; stop loop.
  3020. i = CBANDSMAX;
  3021. break;
  3022. }
  3023. default:
  3024. if (IS_EXTERNALBAND(_cs.bs[i].wID))
  3025. {
  3026. for (DWORD j = 0; j < MAXEXTERNALBANDS; j++)
  3027. {
  3028. if (_cs.aclsidExternalBands[MAP_TO_EXTERNAL(_cs.bs[i].wID)] == _rgebi[j].clsid)
  3029. {
  3030. CLSID clsidTemp = _rgebi[j].clsid;
  3031. _rgebi[j].clsid = _rgebi[MAP_TO_EXTERNAL(_cs.bs[i].wID)].clsid;
  3032. _rgebi[MAP_TO_EXTERNAL(_cs.bs[i].wID)].clsid = clsidTemp;
  3033. hr = _ShowExternalBand(_cs.bs + i, _cs.bs[i].wID);
  3034. break;
  3035. }
  3036. }
  3037. }
  3038. break;
  3039. }
  3040. if (hr != S_OK)
  3041. {
  3042. TraceMsg(TF_ERROR, "CInternetToolbar::_CreateBands -- band ID %x creation failed", _cs.bs[i].wID);
  3043. // if band creation failed, we still go ahead and open the browser and do our normal stuff --
  3044. // including persisting the band state.
  3045. // unfortunately for the user who opens too many windows, they hit GDI limits and we can't
  3046. // create the bands and we fail, and then persist out that state. so all future windows
  3047. // are broken without the file menu etc. and the user cant get out.
  3048. _fDontSave = TRUE;
  3049. }
  3050. }
  3051. _SetBackground();
  3052. _bs._SetMinDimensions();
  3053. _UpdateLocking();
  3054. SendMessage(_bs._hwnd, WM_SETREDRAW, fRedraw, 0);
  3055. }
  3056. }
  3057. }
  3058. return hr;
  3059. }
  3060. HRESULT CInternetToolbar::ShowDW(BOOL fShow)
  3061. {
  3062. if ((g_dwProfileCAP & 0x00000008) && s_imlTBGlyphs.arhiml[0])
  3063. {
  3064. StartCAP();
  3065. }
  3066. HRESULT hres = _CreateBands();
  3067. if (FAILED(hres))
  3068. return hres;
  3069. if (!_nVisibleBands && fShow)
  3070. return(FALSE);
  3071. _fShow = fShow;
  3072. _bs.UIActivateDBC(fShow ? DBC_SHOW : DBC_HIDE);
  3073. ResizeBorderDW(NULL, NULL, FALSE);
  3074. ShowWindow(_hwnd, fShow ? SW_SHOW : SW_HIDE);
  3075. BOOL fConnect = (fShow && _dwcpCookie == 0);
  3076. if (fConnect || (!fShow && _dwcpCookie != 0))
  3077. {
  3078. ConnectToConnectionPoint(SAFECAST(this, IDockingWindow*), DIID_DWebBrowserEvents2, fConnect, _pdie, &_dwcpCookie, NULL);
  3079. }
  3080. return hres;
  3081. }
  3082. int ITBar_TrackPopupMenuEx(HMENU hmenu, UINT uFlags, int x, int y, HWND hwnd, LPRECT prcExclude)
  3083. {
  3084. TPMPARAMS tpm;
  3085. if (prcExclude)
  3086. {
  3087. tpm.cbSize = sizeof(TPMPARAMS);
  3088. CopyRect(&tpm.rcExclude, prcExclude);
  3089. }
  3090. return TrackPopupMenuEx(hmenu, uFlags, x, y, hwnd, prcExclude ? &tpm : NULL);
  3091. }
  3092. /*******************************************************************
  3093. NAME: CInternetToolbar::_ShowBackForwardMenu
  3094. SYNOPSIS:
  3095. NOTES:
  3096. ********************************************************************/
  3097. BOOL CInternetToolbar::_ShowBackForwardMenu(BOOL fForward, POINT pt, LPRECT prcExclude)
  3098. {
  3099. BOOL fRet = FALSE;
  3100. HMENU hmenuBF = CreatePopupMenu();
  3101. if (hmenuBF)
  3102. {
  3103. ASSERT(_pbs2);
  3104. ITravelLog *ptl;
  3105. _pbs2->GetTravelLog(&ptl);
  3106. if (NULL != ptl)
  3107. {
  3108. HRESULT hr;
  3109. hr = ptl->InsertMenuEntries(_pbs2, hmenuBF, 0, 1, MAX_NAV_MENUITEMS, fForward ? TLMENUF_FORE : TLMENUF_BACK);
  3110. if (S_OK == hr)
  3111. {
  3112. OLECMD cmd;
  3113. cmd.cmdID = SBCMDID_HISTORYBAR;
  3114. cmd.cmdf = 0;
  3115. ASSERT(NULL != _ptbsitect);
  3116. _ptbsitect->QueryStatus(&CGID_Explorer, 1, &cmd, NULL);
  3117. if (((cmd.cmdf & OLECMDF_ENABLED) && !(cmd.cmdf & OLECMDF_LATCHED)) &&
  3118. (1 /* MAX_NAV_MENUITEMS */ < ptl->CountEntries(_pbs2)))
  3119. {
  3120. static TCHAR s_szMenuText[MAX_PATH];
  3121. static int s_iMenuIcon = -1;
  3122. if (TEXT('\0') == s_szMenuText[0])
  3123. {
  3124. MLLoadString(IDS_MI_BACK_HISTORY, s_szMenuText, ARRAYSIZE(s_szMenuText));
  3125. ASSERT(TEXT('\0') != s_szMenuText[0]);
  3126. }
  3127. if (-1 == s_iMenuIcon)
  3128. {
  3129. IShellFolder *psfParent;
  3130. LPITEMIDLIST pidlHistory;
  3131. LPCITEMIDLIST pidlItem;
  3132. psfParent = NULL;
  3133. pidlHistory = NULL;
  3134. pidlItem = NULL;
  3135. SHGetSpecialFolderLocation(NULL, CSIDL_HISTORY, &pidlHistory);
  3136. if (NULL != pidlHistory)
  3137. {
  3138. SHBindToIDListParent(pidlHistory, IID_PPV_ARG(IShellFolder, &psfParent), &pidlItem);
  3139. if (NULL != psfParent)
  3140. {
  3141. ASSERT(NULL != pidlItem);
  3142. hr = SHMapPIDLToSystemImageListIndex(psfParent, pidlItem, &s_iMenuIcon);
  3143. if (FAILED(hr))
  3144. s_iMenuIcon = -1;
  3145. psfParent->Release();
  3146. }
  3147. ILFree(pidlHistory);
  3148. }
  3149. }
  3150. ULONG_PTR rgpData[2];
  3151. rgpData[0] = (ULONG_PTR)s_szMenuText;
  3152. rgpData[1] = s_iMenuIcon;
  3153. AppendMenu(hmenuBF, MF_SEPARATOR, -1, NULL);
  3154. AppendMenu(hmenuBF, MF_OWNERDRAW, FCIDM_VBBHISTORYBAND, (PCTSTR)rgpData);
  3155. }
  3156. // If any menu items were added, show the menu and navigate to it
  3157. #ifndef MAINWIN
  3158. int nIndex;
  3159. if (nIndex = ITBar_TrackPopupMenuEx (hmenuBF, TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD, pt.x, pt.y, _hwnd, prcExclude))
  3160. #else
  3161. // Because mainwin doesn't support win95 look and feel we are
  3162. // having a problem to keep the popup from dismissing when we
  3163. // pass NULL as noDismissal area.
  3164. RECT rect;
  3165. GetWindowRect( _hwnd, &rect );
  3166. if (nIndex = (int)TrackPopupMenu (hmenuBF,
  3167. TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RETURNCMD,
  3168. pt.x, pt.y, 0, _hwnd,
  3169. &rect))
  3170. #endif
  3171. {
  3172. if (FCIDM_VBBHISTORYBAND != nIndex)
  3173. {
  3174. ptl->Travel(_pbs2, (fForward ? nIndex : -nIndex));
  3175. }
  3176. else
  3177. {
  3178. VARIANTARG varOn;
  3179. varOn.vt = VT_I4;
  3180. varOn.lVal = 1;
  3181. _ptbsitect->Exec(&CGID_Explorer, SBCMDID_HISTORYBAR, OLECMDEXECOPT_DONTPROMPTUSER, &varOn, NULL);
  3182. }
  3183. }
  3184. }
  3185. ptl->Release();
  3186. }
  3187. DestroyMenu (hmenuBF);
  3188. }
  3189. return fRet;
  3190. }
  3191. // get per folder search items and default search
  3192. BOOL CInternetToolbar::_GetFolderSearchData()
  3193. {
  3194. int iInserted=0;
  3195. if (_pbs2)
  3196. {
  3197. LPCBASEBROWSERDATA pbbd;
  3198. if (SUCCEEDED(_pbs2->GetBaseBrowserData(&pbbd)) && (pbbd->_psfPending || pbbd->_psf))
  3199. {
  3200. IShellFolder2 * psf2;
  3201. IShellFolder* psf = pbbd->_psfPending ? pbbd->_psfPending : pbbd->_psf;
  3202. if (SUCCEEDED(psf->QueryInterface(IID_PPV_ARG(IShellFolder2, &psf2))))
  3203. {
  3204. LPENUMEXTRASEARCH penum;
  3205. GUID guid;
  3206. if (SUCCEEDED(psf2->GetDefaultSearchGUID(&guid)))
  3207. _guidDefaultSearch = guid;
  3208. // get per folder search items
  3209. if (_hdpaFSI && SUCCEEDED(psf2->EnumSearches(&penum)))
  3210. {
  3211. EXTRASEARCH xs;
  3212. while(penum->Next(1, &xs, NULL) == S_OK)
  3213. {
  3214. LPFOLDERSEARCHITEM pfsi = (LPFOLDERSEARCHITEM)LocalAlloc(LPTR, sizeof(FOLDERSEARCHITEM));
  3215. if (pfsi)
  3216. {
  3217. pfsi->idCmd = -1;
  3218. pfsi->guidSearch = xs.guidSearch;
  3219. StrCpyNW(pfsi->wszUrl, xs.wszUrl, ARRAYSIZE(pfsi->wszUrl));
  3220. StrCpyNW(pfsi->wszName, xs.wszFriendlyName, ARRAYSIZE(pfsi->wszName));
  3221. if (DPA_InsertPtr(_hdpaFSI, iInserted, pfsi) != -1)
  3222. iInserted++;
  3223. else
  3224. LocalFree(pfsi);
  3225. }
  3226. }
  3227. penum->Release();
  3228. }
  3229. psf2->Release();
  3230. }
  3231. }
  3232. }
  3233. return (iInserted > 0);
  3234. }
  3235. BOOL NavigateSearchBar(IWebBrowser2 *pwb2, LPCWSTR pwszUrl)
  3236. {
  3237. BOOL bRet = FALSE;
  3238. SA_BSTRGUID bstr;
  3239. InitFakeBSTR(&bstr, CLSID_SearchBand);
  3240. VARIANT var;
  3241. var.vt = VT_BSTR;
  3242. var.bstrVal = bstr.wsz;
  3243. // show a search bar
  3244. VARIANT varEmpty = {0};
  3245. if (SUCCEEDED(pwb2->ShowBrowserBar(&var, &varEmpty, &varEmpty)))
  3246. {
  3247. VARIANT varTargetFrame = {0};
  3248. VARIANT varFlags = {0};
  3249. StrCpyNW(bstr.wsz, pwszUrl, ARRAYSIZE(bstr.wsz));
  3250. bstr.cb = lstrlenW(bstr.wsz) * sizeof(WCHAR);
  3251. varFlags.vt = VT_I4;
  3252. varFlags.lVal = navBrowserBar;
  3253. var.vt = VT_BSTR;
  3254. var.bstrVal = bstr.wsz;
  3255. // navigate the search bar to the correct url
  3256. if (SUCCEEDED(pwb2->Navigate2(&var, &varFlags, &varTargetFrame, &varEmpty, &varEmpty)))
  3257. bRet = TRUE;
  3258. }
  3259. return bRet;
  3260. }
  3261. void RestrictItbarViewMenu(HMENU hmenu, IUnknown *punkBar )
  3262. {
  3263. BOOL fIsRestricted = SHRestricted2(REST_NOBANDCUSTOMIZE, NULL, 0);
  3264. if (fIsRestricted)
  3265. {
  3266. _EnableMenuItem(hmenu, FCIDM_VIEWLINKS, FALSE);
  3267. _EnableMenuItem(hmenu, FCIDM_VIEWMENU, FALSE);
  3268. _EnableMenuItem(hmenu, FCIDM_VIEWADDRESS, FALSE);
  3269. _EnableMenuItem(hmenu, FCIDM_VIEWTOOLS, FALSE);
  3270. }
  3271. for (int i = 0; i < MAXEXTERNALBANDS; i++)
  3272. {
  3273. OLECMD cmd = { CITIDM_VIEWEXTERNALBAND_FIRST + i, 0 };
  3274. OLECMDTEXTV<MAX_EXTERNAL_BAND_NAME_LEN> cmdtv;
  3275. OLECMDTEXT *pcmdText = &cmdtv;
  3276. pcmdText->cmdtextf = OLECMDTEXTF_NAME;
  3277. pcmdText->cwActual = 0;
  3278. pcmdText->cwBuf = MAX_EXTERNAL_BAND_NAME_LEN;
  3279. IUnknown_QueryStatus( punkBar, &CGID_PrivCITCommands, 1, &cmd, pcmdText );
  3280. if (cmd.cmdf & OLECMDF_SUPPORTED)
  3281. {
  3282. DWORD dwMenuCommand = FCIDM_EXTERNALBANDS_FIRST + i;
  3283. InsertMenu( hmenu, FCIDM_VIEWCONTEXTMENUSEP, MF_BYCOMMAND, dwMenuCommand, pcmdText->rgwz );
  3284. if (cmd.cmdf & OLECMDF_ENABLED)
  3285. {
  3286. _CheckMenuItem( hmenu, dwMenuCommand, TRUE );
  3287. }
  3288. if (fIsRestricted)
  3289. {
  3290. _EnableMenuItem( hmenu, dwMenuCommand, FALSE );
  3291. }
  3292. }
  3293. }
  3294. }
  3295. void CInternetToolbar::_ShowContextMenu(HWND hwnd, LPARAM lParam, LPRECT prcExclude)
  3296. {
  3297. // Bail if this context menu doesn't correspond to a band (fixes NT5 #181899)
  3298. POINT pt;
  3299. int iIndex = _bs._ContextMenuHittest(lParam, &pt);
  3300. int idBandActive = _bs._IndexToBandID(iIndex);
  3301. if (!InRange(idBandActive, CBIDX_FIRST, CBANDSMAX))
  3302. return;
  3303. // Bail if we can't find the resource
  3304. HMENU hmenuITB = LoadMenuPopup(MENU_ITOOLBAR);
  3305. if (!hmenuITB)
  3306. return;
  3307. UEMFireEvent(&UEMIID_SHELL, UEME_INSTRBROWSER, UEMF_INSTRUMENT, UIBW_UICONTEXT, idBandActive == -1 ? UIBL_CTXTITBBKGND : UIBL_CTXTITBITEM);
  3308. // Set the initial state of the menu
  3309. _CheckMenuItem (hmenuITB, FCIDM_VIEWTOOLS, _nVisibleBands & VBF_TOOLS);
  3310. _CheckMenuItem (hmenuITB, FCIDM_VIEWADDRESS, _nVisibleBands & VBF_ADDRESS);
  3311. _CheckMenuItem (hmenuITB, FCIDM_VIEWLINKS, _nVisibleBands & VBF_LINKS);
  3312. int cItemsBelowSep = 4;
  3313. // only in theater mode can we autohide
  3314. if (!_fTheater)
  3315. {
  3316. DeleteMenu(hmenuITB, FCIDM_VIEWAUTOHIDE, MF_BYCOMMAND);
  3317. cItemsBelowSep--;
  3318. if (_nVisibleBands & VBF_MENU || _fNoShowMenu)
  3319. DeleteMenu(hmenuITB, FCIDM_VIEWMENU, MF_BYCOMMAND);
  3320. }
  3321. else
  3322. {
  3323. if (_fNoShowMenu)
  3324. DeleteMenu(hmenuITB, FCIDM_VIEWMENU, MF_BYCOMMAND);
  3325. DeleteMenu(hmenuITB, FCIDM_VIEWTOOLS, MF_BYCOMMAND);
  3326. _CheckMenuItem (hmenuITB, FCIDM_VIEWAUTOHIDE, _fAutoHide);
  3327. _CheckMenuItem (hmenuITB, FCIDM_VIEWMENU, _nVisibleBands & VBF_MENU);
  3328. }
  3329. if (_fTheater || SHRestricted2(REST_NOBANDCUSTOMIZE, NULL, 0))
  3330. {
  3331. // No lock in theater mode or Windows Explorer
  3332. DeleteMenu(hmenuITB, FCIDM_VIEWLOCKTOOLBAR, MF_BYCOMMAND);
  3333. }
  3334. else
  3335. {
  3336. _CheckMenuItem(hmenuITB, FCIDM_VIEWLOCKTOOLBAR, _fLockedToolbar);
  3337. }
  3338. // if it was done via the keyboard, but focus wasn't on the tools band,
  3339. // then don't have customize menu option
  3340. // or if click didn't happen on the band
  3341. if (!(_btb._fCustomize && idBandActive == CBIDX_TOOLS))
  3342. {
  3343. DeleteMenu(hmenuITB, FCIDM_VIEWTOOLBARCUSTOMIZE, MF_BYCOMMAND);
  3344. cItemsBelowSep--;
  3345. }
  3346. BOOL fGoButtonAvailable =
  3347. WasOpenedAsBrowser(static_cast<IExplorerToolbar *>(this)) || (GetUIVersion() >= 5);
  3348. // Only show the go button item when you click on the address bar
  3349. if (idBandActive != CBIDX_ADDRESS || !fGoButtonAvailable)
  3350. {
  3351. DeleteMenu(hmenuITB, FCIDM_VIEWGOBUTTON, MF_BYCOMMAND);
  3352. cItemsBelowSep--;
  3353. }
  3354. else
  3355. {
  3356. BOOL fShowGoButton = SHRegGetBoolUSValue(REGSTR_PATH_MAIN,
  3357. TEXT("ShowGoButton"), FALSE, /*default*/TRUE);
  3358. _CheckMenuItem(hmenuITB, FCIDM_VIEWGOBUTTON, fShowGoButton);
  3359. }
  3360. if (_fTheater || _btb._fCustomize || SHRestricted2(REST_LOCKICONSIZE, NULL, 0))
  3361. {
  3362. DeleteMenu(hmenuITB, FCIDM_VIEWTEXTLABELS, MF_BYCOMMAND);
  3363. cItemsBelowSep--;
  3364. }
  3365. else
  3366. {
  3367. // If customize is unavailable, then there's no way for the user to
  3368. // turn list style on/off. In this case we want toggling text labels
  3369. // to work the way it did in IE4 -- that is, switch between "text on
  3370. // all buttons" and "text on no buttons". So, if we're in "selective
  3371. // text on right" mode, we say that labels are turned off. If the user
  3372. // picks this menu option, we'll go into "text on all buttons" mode.
  3373. BOOL fChecked = !_fCompressed && !IS_LIST_STYLE(_btb._hwnd);
  3374. _CheckMenuItem(hmenuITB, FCIDM_VIEWTEXTLABELS, fChecked);
  3375. }
  3376. if (!cItemsBelowSep)
  3377. DeleteMenu(hmenuITB, FCIDM_VIEWCONTEXTMENUSEP, MF_BYCOMMAND);
  3378. RestrictItbarViewMenu(hmenuITB, SAFECAST( this, IOleCommandTarget* ) );
  3379. ITBar_TrackPopupMenuEx(hmenuITB, TPM_LEFTBUTTON | TPM_RIGHTBUTTON, pt.x, pt.y, _hwnd, prcExclude);
  3380. // HACK: since the ITBar isn't a real bar/bandsite, we have to
  3381. // do this so any menuband that might be up can take back the
  3382. // mouse capture.
  3383. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID(CBIDX_MENU);
  3384. if (pbid)
  3385. IUnknown_Exec(pbid->pdb, &CGID_MenuBand, MBANDCID_RECAPTURE, 0, NULL, NULL);
  3386. DestroyMenu (hmenuITB);
  3387. }
  3388. void CInternetToolbar::_QueryStatusTip(IOleCommandTarget *pct, LPTOOLTIPTEXT pnmTT, UINT uiCmd, const GUID* pguid)
  3389. {
  3390. OLECMD rgcmd = { uiCmd, 0 };
  3391. OLECMDTEXTV<MAX_TOOLTIP_STRING> cmdtv;
  3392. OLECMDTEXT *pcmdText = &cmdtv;
  3393. pcmdText->cwBuf = MAX_TOOLTIP_STRING;
  3394. pcmdText->cmdtextf = OLECMDTEXTF_NAME;
  3395. pcmdText->rgwz[0] = 0;
  3396. pct->QueryStatus(pguid, 1, &rgcmd, pcmdText);
  3397. if (rgcmd.cmdf & OLECMDF_ENABLED)
  3398. {
  3399. SHUnicodeToTChar(pcmdText->rgwz, pnmTT->szText, MAX_TOOLTIP_STRING);
  3400. }
  3401. }
  3402. BOOL _IsDocHostGUID(const GUID* pguid)
  3403. {
  3404. // Dochost merges under one of two clsids, so have to check both
  3405. BOOL fRet = IsEqualGUID(*pguid, CLSID_InternetButtons) ||
  3406. IsEqualGUID(*pguid, CLSID_MSOButtons);
  3407. return fRet;
  3408. }
  3409. void _PruneAmpersands(LPTSTR psz)
  3410. {
  3411. //
  3412. // Collapse double ampersands in the string to single
  3413. // ampersands, and rip out single ampersands. e.g.,
  3414. //
  3415. // "AT&T" -> "ATT"
  3416. // "AT&&T" -> "AT&T"
  3417. //
  3418. // We need to do this to hack around the ToolTips control's
  3419. // annoying prefix behavior. When TTS_NOPREFIX is set
  3420. // (which is true of itbar's), TT leaves prefix characters
  3421. // alone completely. However when it is not set, besides just
  3422. // letting DrawText do it's prefix thing on the string, TT also
  3423. // pre-processes the string using an analogous version of the
  3424. // below function, collapsing double ampersands to single
  3425. // ampersands and ripping out single ampersands. This is so
  3426. // that that if you use menu text (e.g. "&File") as a tooltip,
  3427. // you won't get an underline. Unfortunately, the side effect
  3428. // is that you're in trouble if you really wanted an ampersand in
  3429. // the title (e.g. "AT&&T"), since the preprocessing turns "AT&&T"
  3430. // into "AT&T", which DrawText then renders with an underline.
  3431. //
  3432. // Thus we have to leave TTS_NOPREFIX set and mimic the DrawText
  3433. // preprocessing ourselves.
  3434. //
  3435. if (psz)
  3436. {
  3437. LPTSTR pszOut = psz;
  3438. BOOL fLastAmpSkipped = FALSE;
  3439. while (*psz)
  3440. {
  3441. if (*psz == TEXT('&'))
  3442. {
  3443. if (fLastAmpSkipped)
  3444. {
  3445. fLastAmpSkipped = FALSE;
  3446. *pszOut++ = *psz;
  3447. }
  3448. else
  3449. {
  3450. fLastAmpSkipped = TRUE;
  3451. }
  3452. }
  3453. else
  3454. {
  3455. *pszOut++ = *psz;
  3456. }
  3457. psz++;
  3458. }
  3459. *pszOut = TEXT('\0');
  3460. }
  3461. }
  3462. void CInternetToolbar::_OnTooltipNeeded(LPTOOLTIPTEXT pnmTT)
  3463. {
  3464. UINT uiCmd;
  3465. GUID guid;
  3466. ASSERT(pnmTT->hdr.hwndFrom == (HWND)SendMessage(_btb._hwnd, TB_GETTOOLTIPS, 0, 0));
  3467. // Make sure tooltips don't filter out ampersands
  3468. LONG lStyle = GetWindowLong(pnmTT->hdr.hwndFrom, GWL_STYLE);
  3469. if (!IsFlagSet(lStyle, TTS_NOPREFIX))
  3470. {
  3471. SetWindowLong(pnmTT->hdr.hwndFrom, GWL_STYLE, lStyle | TTS_NOPREFIX);
  3472. }
  3473. if (SUCCEEDED(_btb._ConvertCmd(NULL, (UINT)pnmTT->hdr.idFrom, &guid, &uiCmd)))
  3474. {
  3475. if (IsEqualGUID(guid, CLSID_CommonButtons))
  3476. {
  3477. switch (uiCmd)
  3478. {
  3479. case TBIDM_FORWARD:
  3480. case TBIDM_BACK:
  3481. if (_ptbsite)
  3482. {
  3483. IBrowserService *pbsvc;
  3484. if (SUCCEEDED(_ptbsite->QueryInterface(IID_PPV_ARG(IBrowserService, &pbsvc))))
  3485. {
  3486. // FEATURE raymondc - make ITravelLog UNICODE someday
  3487. ITravelLog *ptl;
  3488. pbsvc->GetTravelLog( &ptl );
  3489. if (ptl)
  3490. {
  3491. WCHAR szTemp[ARRAYSIZE(pnmTT->szText)];
  3492. if (uiCmd == TBIDM_BACK)
  3493. ptl->GetToolTipText(pbsvc, TLOG_BACK, 0, szTemp, ARRAYSIZE(szTemp));
  3494. else if (uiCmd == TBIDM_FORWARD)
  3495. ptl->GetToolTipText(pbsvc, TLOG_FORE, 0, szTemp, ARRAYSIZE(szTemp));
  3496. SHUnicodeToTChar(szTemp, pnmTT->szText, ARRAYSIZE(pnmTT->szText));
  3497. ptl->Release();
  3498. }
  3499. pbsvc->Release();
  3500. }
  3501. }
  3502. }
  3503. }
  3504. #ifdef EDIT_HACK
  3505. // Dochost merges under one of two clsids, so have to check both
  3506. else if (_IsDocHostGUID(&guid))
  3507. {
  3508. if (uiCmd == DVIDM_EDITPAGE)
  3509. {
  3510. _aEditVerb.GetToolTip(pnmTT->szText, ARRAYSIZE(pnmTT->szText));
  3511. }
  3512. else
  3513. {
  3514. // If the button text is hidden or truncated, we use that text for the tooltip.
  3515. TBBUTTONINFO tbbi = {0};
  3516. tbbi.cbSize = sizeof(TBBUTTONINFO);
  3517. tbbi.dwMask = TBIF_STYLE | TBIF_STATE;
  3518. SendMessage(_btb._hwnd, TB_GETBUTTONINFO, pnmTT->hdr.idFrom, (LPARAM)&tbbi);
  3519. if (_fCompressed ||
  3520. IS_LIST_STYLE(_btb._hwnd) && !(tbbi.fsStyle & BTNS_SHOWTEXT) ||
  3521. (tbbi.fsState & TBSTATE_ELLIPSES))
  3522. {
  3523. //
  3524. // Get the button text and fix up the ampersands so that the
  3525. // tooltip will look right
  3526. //
  3527. if (SendMessage(_btb._hwnd, TB_GETBUTTONTEXT, pnmTT->hdr.idFrom, (LPARAM)&pnmTT->szText))
  3528. {
  3529. _PruneAmpersands(pnmTT->szText);
  3530. }
  3531. }
  3532. }
  3533. }
  3534. #endif
  3535. }
  3536. }
  3537. LRESULT CInternetToolbar::_OnBeginDrag(NMREBAR *pnm)
  3538. {
  3539. if (SHRestricted2(REST_NOBANDCUSTOMIZE, NULL, 0) || _fLockedToolbar)
  3540. {
  3541. return 1;
  3542. }
  3543. if (_fTheater)
  3544. {
  3545. // if we're in theater mode, we do our own drag handling where we force
  3546. // all the mouse moves into the middle of the band, thereby disallowing
  3547. // the user to make a multi line rebar
  3548. SetCapture(_hwnd);
  3549. SendMessage(_bs._hwnd, RB_BEGINDRAG, pnm->uBand, (LPARAM)-2);
  3550. _fRebarDragging = TRUE;
  3551. return 1;
  3552. }
  3553. return SHRestricted2(REST_NoToolbarOptions, NULL, 0);
  3554. }
  3555. LRESULT CInternetToolbar::_OnNotify(LPNMHDR pnmh)
  3556. {
  3557. LRESULT lres = 0;
  3558. if (!_pdie)
  3559. return 0;
  3560. if (pnmh->code == TTN_NEEDTEXT && pnmh->hwndFrom == (HWND)SendMessage(_btb._hwnd, TB_GETTOOLTIPS, 0, 0))
  3561. {
  3562. _OnTooltipNeeded((LPTOOLTIPTEXT)pnmh);
  3563. return 0;
  3564. }
  3565. if(_SendToToolband(pnmh->hwndFrom, WM_NOTIFY,0, (LPARAM)pnmh, &lres))
  3566. return lres;
  3567. switch (pnmh->idFrom)
  3568. {
  3569. case FCIDM_REBAR:
  3570. switch (pnmh->code)
  3571. {
  3572. case RBN_BEGINDRAG:
  3573. return _OnBeginDrag((NMREBAR*)pnmh);
  3574. case RBN_HEIGHTCHANGE:
  3575. ResizeBorderDW(NULL, NULL, FALSE);
  3576. break;
  3577. case RBN_CHILDSIZE:
  3578. {
  3579. // make the brand always take the full height
  3580. NMREBARCHILDSIZE *pnm = (NMREBARCHILDSIZE*)pnmh;
  3581. if (pnm->wID == CBIDX_BRAND)
  3582. {
  3583. pnm->rcChild.top = pnm->rcBand.top;
  3584. pnm->rcChild.bottom = pnm->rcBand.bottom;
  3585. }
  3586. break;
  3587. }
  3588. case RBN_LAYOUTCHANGED:
  3589. //Because the layout has changed, remember to save later!
  3590. _fDirty = TRUE;
  3591. _UpdateBrandSize();
  3592. if (_ptbsitect)
  3593. _ptbsitect->Exec(&CGID_ShellBrowser, FCIDM_PERSISTTOOLBAR, 0, NULL, NULL);
  3594. break;
  3595. case RBN_GETOBJECT:
  3596. {
  3597. NMOBJECTNOTIFY *pnmon = (NMOBJECTNOTIFY *)pnmh;
  3598. if (IsEqualIID(*pnmon->piid, IID_IDropTarget))
  3599. {
  3600. HWND hwnd;
  3601. switch (pnmon->iItem)
  3602. {
  3603. case CBIDX_MENU:
  3604. case CBIDX_LINKS:
  3605. {
  3606. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID(pnmon->iItem);
  3607. if (pbid && pbid->pdb)
  3608. {
  3609. pnmon->hResult = pbid->pdb->QueryInterface(IID_IDropTarget, (void**)&pnmon->pObject);
  3610. }
  3611. break;
  3612. }
  3613. case CBIDX_TOOLS:
  3614. hwnd = _btb._hwnd;
  3615. pnmon->hResult = (HRESULT)SendMessage(hwnd, TB_GETOBJECT,
  3616. (WPARAM)&IID_IDropTarget, (LPARAM)&pnmon->pObject);
  3617. break;
  3618. case CBIDX_ADDRESS:
  3619. if (_ptbsite)
  3620. {
  3621. pnmon->hResult = _ptbsite->QueryInterface(IID_IDropTarget, (void**)&pnmon->pObject);
  3622. }
  3623. break;
  3624. }
  3625. }
  3626. ASSERT((SUCCEEDED(pnmon->hResult) && pnmon->pObject) ? (IS_VALID_CODE_PTR(pnmon->pObject, IUnknown)) : (pnmon->pObject == NULL));
  3627. return TRUE;
  3628. }
  3629. case RBN_CHEVRONPUSHED:
  3630. {
  3631. LPNMREBARCHEVRON pnmch = (LPNMREBARCHEVRON) pnmh;
  3632. if (pnmch->wID == CBIDX_TOOLS)
  3633. {
  3634. int idMenu = MENU_TBMENU;
  3635. // this must be the tools band (not enumerated in bandsite)
  3636. MapWindowPoints(pnmh->hwndFrom, HWND_DESKTOP, (LPPOINT)&pnmch->rc, 2);
  3637. if (!_btb._fCustomize)
  3638. idMenu = 0;
  3639. ToolbarMenu_Popup(_hwnd, &pnmch->rc, NULL, _btb._hwnd, idMenu, (DWORD)pnmch->lParamNM);
  3640. return TRUE;
  3641. }
  3642. _bs._OnNotify(pnmh);
  3643. break;
  3644. }
  3645. default:
  3646. return _bs._OnNotify(pnmh);
  3647. } // switch (pnmh->code)
  3648. break;
  3649. } // switch (pnmh->idFrom)
  3650. return 0;
  3651. }
  3652. /*******************************************************************
  3653. NAME: CInternetToolbar::_DoNavigateA
  3654. SYNOPSIS: Called when the user types in or selects a URL
  3655. to navigate to through the address bar
  3656. NOTES: This function calls the helper function _DoNavigate.
  3657. This is just here to convert the ANSI string to
  3658. a BSTR.
  3659. ********************************************************************/
  3660. HRESULT CInternetToolbar::_DoNavigateA(LPSTR pszURL, int iNewSelection)
  3661. {
  3662. ASSERT(pszURL); // must have valid URL to navigate to
  3663. LBSTR::CString strText;
  3664. LPTSTR pstrText = strText.GetBuffer( MAX_URL_STRING );
  3665. if ( strText.GetAllocLength() < MAX_URL_STRING )
  3666. {
  3667. TraceMsg( TF_WARNING, "CInternetToolbar::_DoNavigateA() - strText Allocation Failed!" );
  3668. return E_OUTOFMEMORY;
  3669. }
  3670. else
  3671. {
  3672. SHAnsiToUnicode( pszURL, pstrText, MAX_URL_STRING );
  3673. strText.ReleaseBuffer();
  3674. return _DoNavigate( strText, iNewSelection );
  3675. }
  3676. }
  3677. /*******************************************************************
  3678. NAME: CInternetToolbar::_DoNavigateW
  3679. SYNOPSIS: Called when the user types in or selects a URL
  3680. to navigate to through the address bar
  3681. NOTES: This function calls the helper function _DoNavigate.
  3682. This is just here to convert the Unicode string to
  3683. a BSTR.
  3684. ********************************************************************/
  3685. HRESULT CInternetToolbar::_DoNavigateW(LPWSTR pwzURL, int iNewSelection)
  3686. {
  3687. ASSERT(pwzURL); // must have valid URL to navigate to
  3688. LBSTR::CString strPath( pwzURL );
  3689. return _DoNavigate( strPath, iNewSelection );
  3690. }
  3691. /*******************************************************************
  3692. NAME: CInternetToolbar::_DoNavigate
  3693. SYNOPSIS: Called when the user types in or selects a URL
  3694. to navigate to through the address bar
  3695. ENTRY: bstrURL - string of URL to navigate to, in BSTR form
  3696. iNewSelection - index of current selection in address
  3697. bar combo box
  3698. ********************************************************************/
  3699. HRESULT CInternetToolbar::_DoNavigate(BSTR bstrURL,int iNewSelection)
  3700. {
  3701. HRESULT hr;
  3702. ASSERT(bstrURL); // must have valid URL to browse to
  3703. ASSERT(_pdie); // must have valid pointer to automation interface
  3704. VARIANTARG v;
  3705. VariantInit (&v);
  3706. v.vt = VT_I4;
  3707. v.lVal = navAllowAutosearch;
  3708. // call automation interface to make browser navigate to this URL
  3709. hr = _pdie->Navigate(bstrURL, &v, PVAREMPTY, PVAREMPTY, PVAREMPTY);
  3710. VariantClearLazy(&v);
  3711. return hr;
  3712. }
  3713. LPITEMIDLIST CInternetToolbar::_GetCurrentPidl(void)
  3714. {
  3715. LPITEMIDLIST pidl = NULL;
  3716. ASSERT(_pbs2);
  3717. if (_pbs2)
  3718. {
  3719. _pbs2->GetPidl(&pidl);
  3720. }
  3721. return pidl;
  3722. }
  3723. void CInternetToolbar::_CommonHandleFileSysChange(LONG lEvent, LPITEMIDLIST* ppidl)
  3724. {
  3725. // stuff that needs to be done tree or no tree
  3726. switch (lEvent)
  3727. {
  3728. // README:
  3729. // If you need to add events here, then you must change SHELLBROWSER_FSNOTIFY_FLAGS in
  3730. // shbrowse.cpp in order to get the notifications
  3731. case SHCNE_DRIVEREMOVED:
  3732. case SHCNE_MEDIAREMOVED:
  3733. case SHCNE_MEDIAINSERTED:
  3734. case SHCNE_DRIVEADD:
  3735. case SHCNE_UPDATEIMAGE:
  3736. case SHCNE_UPDATEITEM:
  3737. // Forward this command to CAddressBand::FileSysChange()
  3738. // by using IToolbandHelper::OnWinEvent().
  3739. {
  3740. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID(CBIDX_ADDRESS);
  3741. if (pbid)
  3742. {
  3743. // REVIEW: why don't we use IShellChangeNotify here?
  3744. //
  3745. IUnknown_FileSysChange(pbid->pdb, (DWORD)lEvent, (LPCITEMIDLIST*)ppidl);
  3746. }
  3747. }
  3748. break;
  3749. }
  3750. }
  3751. HRESULT CInternetToolbar::OnChange(LONG lEvent, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2)
  3752. {
  3753. LPITEMIDLIST ppidl[2] = {(LPITEMIDLIST)pidl1, (LPITEMIDLIST)pidl2};
  3754. _CommonHandleFileSysChange(lEvent, ppidl);
  3755. return S_OK;
  3756. }
  3757. void CInternetToolbar::_OnCommand(WPARAM wParam, LPARAM lParam)
  3758. {
  3759. if (!_pdie)
  3760. return;
  3761. HWND hwndControl = GET_WM_COMMAND_HWND(wParam, lParam);
  3762. UINT idCmd = GET_WM_COMMAND_ID(wParam, lParam);
  3763. // If this is a command from the toolbar, and it is not one of the StdBrowseButtons
  3764. // call Exec() on the appropriate CmdTarget
  3765. if (hwndControl == _btb._hwnd)
  3766. {
  3767. UINT uiInternalCmdID = idCmd;
  3768. // Convert to the real thing and get the guid
  3769. CMDMAP* pcm = _btb._GetCmdMapByID(idCmd);
  3770. IOleCommandTarget* pct = _btb._CommandTargetFromCmdMap(pcm);
  3771. if (pct)
  3772. {
  3773. VARIANTARG var;
  3774. var.vt = VT_I4;
  3775. var.lVal = uiInternalCmdID;
  3776. if (SHIsSameObject(_btb._pctCurrentButtonGroup, pct))
  3777. {
  3778. // give the browser a chance to pick this off in case
  3779. // focus doesn't belong to the view currently
  3780. if (SUCCEEDED(_ptbsitect->Exec(&IID_IExplorerToolbar, pcm->nCmdID, 0, NULL, &var)))
  3781. return;
  3782. }
  3783. UEMFireEvent(&UEMIID_BROWSER, UEME_UITOOLBAR, UEMF_XEVENT,
  3784. UIG_COMMON, (LPARAM)pcm->nCmdID);
  3785. pct->Exec(&pcm->guidButtonGroup, (DWORD)pcm->nCmdID, 0, NULL, &var);
  3786. }
  3787. return;
  3788. }
  3789. if (_SendToToolband(hwndControl, WM_COMMAND, wParam, lParam, NULL))
  3790. return;
  3791. // this switch block actually executes
  3792. switch(idCmd)
  3793. {
  3794. case FCIDM_VIEWTOOLBARCUSTOMIZE:
  3795. ASSERT(!SHRestricted2(REST_NOTOOLBARCUSTOMIZE, NULL, 0));
  3796. SendMessage (_btb._hwnd, TB_CUSTOMIZE, 0, 0L);
  3797. break;
  3798. case FCIDM_DRIVELIST:
  3799. _SendToToolband(_hwndAddressBand, WM_COMMAND, wParam, lParam, NULL);
  3800. break;
  3801. case FCIDM_VIEWADDRESS:
  3802. case FCIDM_VIEWTOOLS:
  3803. case FCIDM_VIEWMENU:
  3804. case FCIDM_VIEWLINKS:
  3805. if (!SHRestricted2(REST_NOBANDCUSTOMIZE, NULL, 0)
  3806. && !SHRestricted2(REST_NoToolbarOptions, NULL, 0))
  3807. {
  3808. DWORD dw = _nVisibleBands;
  3809. switch (idCmd)
  3810. {
  3811. case FCIDM_VIEWTOOLS:
  3812. dw ^= VBF_TOOLS;
  3813. break;
  3814. case FCIDM_VIEWMENU:
  3815. dw ^= VBF_MENU;
  3816. break;
  3817. case FCIDM_VIEWADDRESS:
  3818. dw ^= VBF_ADDRESS;
  3819. break;
  3820. case FCIDM_VIEWLINKS:
  3821. dw ^= VBF_LINKS;
  3822. break;
  3823. }
  3824. if ( !( dw & ~VBF_BRAND))
  3825. {
  3826. _pdie->put_ToolBar( FALSE );
  3827. }
  3828. _ShowVisible(dw, TRUE);
  3829. }
  3830. return;
  3831. case FCIDM_VIEWAUTOHIDE:
  3832. {
  3833. ASSERT(_fTheater);
  3834. _fAutoHide = !_fAutoHide;
  3835. VARIANTARG v = {0};
  3836. v.vt = VT_I4;
  3837. v.lVal = _fAutoHide;
  3838. IUnknown_Exec(_ptbsite, &CGID_Theater, THID_SETTOOLBARAUTOHIDE, 0, &v, NULL);
  3839. ResizeBorderDW(NULL, NULL, FALSE);
  3840. break;
  3841. }
  3842. case FCIDM_VIEWLOCKTOOLBAR:
  3843. {
  3844. _fLockedToolbar = !_fLockedToolbar;
  3845. DWORD dwResult = _fLockedToolbar;
  3846. SHSetValue(HKEY_CURRENT_USER, c_szRegKeyCoolbar, TEXT("Locked"), REG_DWORD, &dwResult, sizeof(dwResult));
  3847. _UpdateLocking();
  3848. break;
  3849. }
  3850. case FCIDM_VIEWTEXTLABELS:
  3851. if(!SHRestricted2(REST_NoToolbarOptions, NULL, 0))
  3852. {
  3853. if (!_btb._fCustomize && IS_LIST_STYLE(_btb._hwnd))
  3854. {
  3855. // If customize is unavailable, then there's no way for the user to
  3856. // turn list style on/off. In this case we want toggling text labels
  3857. // to work the way it did in IE4 -- that is, switch between "text on
  3858. // all buttons" and "text on no buttons". So, if we're in "selective
  3859. // text on right" mode, we say that labels are turned off. If the user
  3860. // picks this menu option, we'll go into "text on all buttons" mode.
  3861. _UpdateToolsStyle(FALSE);
  3862. // Make ourselves believe that text labels are turned off (so
  3863. // that _UpdateToolbarDisplay will turn them on)
  3864. _fCompressed = TRUE;
  3865. }
  3866. _UpdateToolbarDisplay(UTD_TEXTLABEL, 0, !_fCompressed, TRUE);
  3867. }
  3868. return;
  3869. case FCIDM_VIEWGOBUTTON:
  3870. _SendToToolband(_hwndAddressBand, WM_COMMAND, wParam, lParam, NULL);
  3871. break;
  3872. default:
  3873. if (InRange( idCmd, FCIDM_EXTERNALBANDS_FIRST, FCIDM_EXTERNALBANDS_LAST ))
  3874. {
  3875. if (!SHRestricted2(REST_NOBANDCUSTOMIZE, NULL, 0))
  3876. {
  3877. DWORD dw = _nVisibleBands;
  3878. dw ^= EXTERNALBAND_VBF_BIT(idCmd - FCIDM_EXTERNALBANDS_FIRST);
  3879. if ( !( dw & ~VBF_BRAND))
  3880. {
  3881. _pdie->put_ToolBar( FALSE );
  3882. }
  3883. _ShowVisible(dw, TRUE);
  3884. }
  3885. return;
  3886. }
  3887. break;
  3888. }
  3889. }
  3890. // get the doc property, then get the command target from that and do it
  3891. void CInternetToolbar::_SendDocCommand(UINT idCmd)
  3892. {
  3893. if (_ptbsitect)
  3894. {
  3895. VARIANTARG varIn;
  3896. VARIANTARG varOut;
  3897. VARIANTARG *pvarIn = &varIn;
  3898. VARIANTARG *pvarOut = &varOut;
  3899. VariantInit(&varIn);
  3900. VariantInit(&varOut);
  3901. switch (idCmd)
  3902. {
  3903. case OLECMDID_HIDETOOLBARS:
  3904. case OLECMDID_PRINT:
  3905. // word & excel barf if there are arguments passed to print
  3906. pvarIn = NULL;
  3907. pvarOut = NULL;
  3908. break;
  3909. case OLECMDID_ZOOM:
  3910. // get the zoom range
  3911. int iMax, iMin;
  3912. if (FAILED(_ptbsitect->Exec(NULL, OLECMDID_GETZOOMRANGE, OLECMDEXECOPT_DONTPROMPTUSER, NULL, &varOut)))
  3913. goto Bail;
  3914. if (varOut.vt == VT_I4)
  3915. {
  3916. iMin = (int)(short)LOWORD(varOut.lVal);
  3917. iMax = (int)(short)HIWORD(varOut.lVal);
  3918. }
  3919. else
  3920. goto Bail;
  3921. varOut.vt = VT_EMPTY; // return to VariantInit state
  3922. // get the current zoom depth
  3923. if (FAILED(_ptbsitect->Exec(NULL, OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER, NULL, &varIn)))
  3924. goto Bail;
  3925. if (varIn.vt == VT_I4)
  3926. {
  3927. varIn.lVal++;
  3928. if ((int)varIn.lVal > iMax)
  3929. {
  3930. varIn.lVal = iMin;
  3931. }
  3932. }
  3933. else
  3934. {
  3935. goto Bail;
  3936. }
  3937. break;
  3938. }
  3939. #ifdef FEATURE_IE40
  3940. _ptbsitect->Exec(NULL, idCmd, OLECMDEXECOPT_DONTPROMPTUSER, pvarIn, pvarOut);
  3941. #else
  3942. _ptbsitect->Exec(NULL, idCmd, OLECMDEXECOPT_PROMPTUSER, pvarIn, pvarOut);
  3943. #endif
  3944. Bail:
  3945. // if this fails, we should maybe do the invoke with a
  3946. // proper verb?
  3947. VariantClearLazy(&varIn);
  3948. VariantClearLazy(&varOut);
  3949. }
  3950. }
  3951. BOOL CInternetToolbar::_CompressBands(BOOL fCompress, UINT uRowsNew, BOOL fForceUpdate)
  3952. {
  3953. UINT_PTR uRowsOld = SendMessage(_btb._hwnd, TB_GETTEXTROWS, 0, 0L);
  3954. if (fCompress)
  3955. uRowsNew = 0;
  3956. if (!fForceUpdate && (uRowsOld == uRowsNew))
  3957. {
  3958. // same as what we've already got, blow it off
  3959. return FALSE;
  3960. }
  3961. _fCompressed = fCompress;
  3962. // Change the size of the Brand window and add ot remove the text
  3963. SendMessage(_btb._hwnd, TB_SETMAXTEXTROWS, uRowsNew, 0L);
  3964. UINT uWidthNew = _fCompressed ? MAX_TB_COMPRESSED_WIDTH : _uiMaxTBWidth;
  3965. SendMessage(_btb._hwnd, TB_SETBUTTONWIDTH, 0, (LPARAM) MAKELONG(0, uWidthNew));
  3966. _btb._BandInfoChanged();
  3967. _UpdateBrandSize();
  3968. _bs._SetMinDimensions();
  3969. return TRUE;
  3970. }
  3971. #define ABS(x) (((x) < 0) ? -(x) : (x))
  3972. void CInternetToolbar::_TrackSliding(int x, int y)
  3973. {
  3974. INT_PTR cBands = SendMessage(_bs._hwnd, RB_GETBANDCOUNT, 0, 0L);
  3975. INT_PTR cRows = SendMessage(_bs._hwnd, RB_GETROWCOUNT, 0, 0L);
  3976. INT_PTR cyHalfRow = SendMessage(_bs._hwnd, RB_GETROWHEIGHT, cBands-1, 0L) / 2;
  3977. RECT rc;
  3978. int cyBefore;
  3979. int c;
  3980. BOOL_PTR fChanged = FALSE;
  3981. // do this instead of GetClientRect so that we include borders
  3982. GetWindowRect(_bs._hwnd, &rc);
  3983. MapWindowPoints(HWND_DESKTOP, _bs._hwnd, (LPPOINT)&rc, 2);
  3984. cyBefore = rc.bottom - rc.top;
  3985. c = y - _yCapture;
  3986. rc.bottom = y;
  3987. // was there enough change?
  3988. if (ABS(c) <= cyHalfRow)
  3989. return;
  3990. if ((cRows == 1) || _fCompressed)
  3991. {
  3992. if (c < -cyHalfRow)
  3993. fChanged = _CompressBands(TRUE, 0, FALSE);
  3994. else
  3995. fChanged = _CompressBands(FALSE, _uiTBTextRows, FALSE);
  3996. }
  3997. if (!fChanged)
  3998. {
  3999. // if the compressing bands didn't change anything, try to fit it to size
  4000. fChanged = SendMessage(_bs._hwnd, RB_SIZETORECT, 0, (LPARAM)&rc);
  4001. }
  4002. // TODO: There is a drawing glitch when you resize from 3 bars (No Text) to 3 bars
  4003. // with text. The _yCapture gets set to a value greater than y. So on the
  4004. // next MOUSEMOVE it figures that the user moved up and switches from 3 bars with text
  4005. // to 2 bars with text.
  4006. if (fChanged)
  4007. {
  4008. _UpdateBrandSize();
  4009. GetWindowRect(_bs._hwnd, &rc);
  4010. _yCapture += (rc.bottom - rc.top) - cyBefore;
  4011. _fDirty = TRUE; //Since the band layout changed, set the dirty bit ON.
  4012. if (_ptbsitect)
  4013. _ptbsitect->Exec(&CGID_ShellBrowser, FCIDM_PERSISTTOOLBAR, 0, NULL, NULL);
  4014. }
  4015. }
  4016. void CInternetToolbar::_ShowVisible(DWORD dwVisibleBands, BOOL fPersist)
  4017. {
  4018. // PERF (scotth): is this even necessary now that we have a
  4019. // menu band always showing?
  4020. BOOL fShowInitial = (! (_nVisibleBands & ~VBF_BRAND));
  4021. _UpdateToolbarDisplay(UTD_VISIBLE, dwVisibleBands, _fCompressed, fPersist);
  4022. if (fShowInitial)
  4023. _pdie->put_ToolBar(TRUE);
  4024. }
  4025. HRESULT CInternetToolbar::_UpdateToolbarDisplay(DWORD dwFlags, UINT uVisibleBands, BOOL fNoText, BOOL fPersist)
  4026. {
  4027. _fDirty = TRUE; //Since we are making changes, set the dirty bit!
  4028. //Update the back bitmap
  4029. _SetBackground();
  4030. //Show the bands.
  4031. if(dwFlags & UTD_VISIBLE)
  4032. _ShowBands(uVisibleBands);
  4033. //Show/Hide the text.
  4034. if(dwFlags & UTD_TEXTLABEL)
  4035. _CompressBands(fNoText, _uiTBTextRows, TRUE);
  4036. _fDirty = TRUE; //Since we are making changes, set the dirty bit!
  4037. if (!_fTheater && fPersist && _ptbsitect)
  4038. _ptbsitect->Exec(&CGID_ShellBrowser, FCIDM_PERSISTTOOLBAR, 0, NULL, NULL);
  4039. return S_OK;
  4040. }
  4041. void CInternetToolbar::_UpdateBrandSize()
  4042. {
  4043. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID(CBIDX_BRAND);
  4044. if (pbid && ((_nVisibleBands & (VBF_TOOLS | VBF_BRAND)) == (VBF_TOOLS | VBF_BRAND)))
  4045. {
  4046. BOOL fMinAlways = _fCompressed;
  4047. if (!fMinAlways)
  4048. {
  4049. INT_PTR iTools = BandIDtoIndex(_bs._hwnd, CBIDX_TOOLS);
  4050. INT_PTR iBrand = BandIDtoIndex(_bs._hwnd, CBIDX_BRAND);
  4051. if (iBrand < iTools && !_fTheater)
  4052. fMinAlways = TRUE;
  4053. }
  4054. VARIANTARG v = {0};
  4055. v.vt = VT_I4;
  4056. v.lVal = fMinAlways;
  4057. IUnknown_Exec(pbid->pdb, &CGID_PrivCITCommands, CITIDM_BRANDSIZE, 0, &v, NULL);
  4058. }
  4059. }
  4060. LRESULT CALLBACK CInternetToolbar::SizableWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  4061. {
  4062. CInternetToolbar* pitbar = (CInternetToolbar*)GetWindowPtr0(hwnd); // GetWindowLong(hwnd, 0)
  4063. switch(uMsg)
  4064. {
  4065. case WM_SETCURSOR:
  4066. {
  4067. if (pitbar->_fLockedToolbar)
  4068. {
  4069. SetCursor(LoadCursor(NULL, IDC_ARROW));
  4070. return TRUE;
  4071. }
  4072. if ((HWND)wParam == hwnd && LOWORD(lParam) == HTCLIENT &&
  4073. !SHRestricted2(REST_NOBANDCUSTOMIZE, NULL, 0))
  4074. {
  4075. SetCursor(LoadCursor(NULL, IDC_SIZENS));
  4076. return TRUE;
  4077. }
  4078. goto DoDefault;
  4079. }
  4080. case WM_SYSCOLORCHANGE:
  4081. case WM_WININICHANGE:
  4082. if (FALSE == pitbar->_fDestroyed)
  4083. {
  4084. DWORD dwSection = SHIsExplorerIniChange(wParam, lParam);
  4085. BOOL fRebuild = (uMsg == WM_SYSCOLORCHANGE) ||
  4086. (dwSection == EICH_KWINEXPLSMICO) ||
  4087. (wParam == SPI_SETNONCLIENTMETRICS);
  4088. if (fRebuild)
  4089. {
  4090. pitbar->_InitForScreenSize();
  4091. ITBar_LoadToolbarGlyphs(pitbar->_btb._hwnd);
  4092. pitbar->_ReloadBitmapDSA();
  4093. pitbar->_SetSearchStuff();
  4094. pitbar->_ReloadButtons();
  4095. #ifdef EDIT_HACK
  4096. if (uMsg == WM_SYSCOLORCHANGE)
  4097. {
  4098. pitbar->_RefreshEditGlyph();
  4099. }
  4100. #endif
  4101. }
  4102. #ifdef EDIT_HACK
  4103. if (dwSection == EICH_KINET)
  4104. {
  4105. pitbar->_aEditVerb.InitDefaultEditor();
  4106. pitbar->_UpdateEditButton();
  4107. }
  4108. #endif
  4109. SendMessage(pitbar->_bs._hwnd, uMsg, wParam, lParam);
  4110. pitbar->_SendToToolband(HWND_BROADCAST, uMsg, wParam, lParam, NULL);
  4111. if (fRebuild)
  4112. {
  4113. pitbar->_SetBackground();
  4114. InvalidateRect(pitbar->_bs._hwnd, NULL, TRUE);
  4115. pitbar->_bs._SetMinDimensions();
  4116. }
  4117. }
  4118. break;
  4119. case WM_LBUTTONDOWN:
  4120. // RelayToToolTips(prb->hwndToolTips, hwnd, wMsg, wParam, lParam);
  4121. // Don't allow toolbar resizing in theater mode
  4122. if (!pitbar->_fTheater &&
  4123. !SHRestricted2(REST_NOBANDCUSTOMIZE, NULL, 0) &&
  4124. (!pitbar->_fLockedToolbar))
  4125. {
  4126. pitbar->_xCapture = GET_X_LPARAM(lParam);
  4127. pitbar->_yCapture = GET_Y_LPARAM(lParam);
  4128. SetCapture(hwnd);
  4129. }
  4130. break;
  4131. case WM_MOUSEMOVE:
  4132. // RelayToToolTips(prb->hwndToolTips, hwnd, wMsg, wParam, lParam);
  4133. if (pitbar->_yCapture != -1)
  4134. {
  4135. if (hwnd != GetCapture())
  4136. pitbar->_yCapture = -1;
  4137. else
  4138. pitbar->_TrackSliding(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
  4139. }
  4140. else if (pitbar->_fRebarDragging)
  4141. {
  4142. RECT rc;
  4143. POINT pt;
  4144. GetClientRect(pitbar->_bs._hwnd, &rc);
  4145. GetCursorPos(&pt);
  4146. MapWindowPoints(HWND_DESKTOP, pitbar->_bs._hwnd, &pt, 1);
  4147. rc.bottom /= 2;
  4148. if (pt.y > rc.bottom)
  4149. pt.y = rc.bottom;
  4150. SendMessage(pitbar->_bs._hwnd, RB_DRAGMOVE, 0, MAKELPARAM(pt.x, pt.y));
  4151. }
  4152. break;
  4153. case WM_LBUTTONUP:
  4154. case WM_RBUTTONUP:
  4155. // RelayToToolTips(prb->hwndToolTips, hwnd, wMsg, wParam, lParam);
  4156. pitbar->_yCapture = -1;
  4157. if (pitbar->_fRebarDragging)
  4158. {
  4159. pitbar->_fRebarDragging = FALSE;
  4160. SendMessage(pitbar->_bs._hwnd, RB_ENDDRAG, 0, 0);
  4161. }
  4162. if (GetCapture() == hwnd)
  4163. ReleaseCapture();
  4164. break;
  4165. case WM_CONTEXTMENU:
  4166. pitbar->_bs.OnWinEvent(pitbar->_hwnd, uMsg, wParam, lParam, NULL);
  4167. break;
  4168. case WM_VKEYTOITEM:
  4169. case WM_CHARTOITEM:
  4170. // We must swallow these messages to avoid infinit SendMessage
  4171. break;
  4172. case WM_NOTIFY:
  4173. // We must swallow these messages to avoid infinit SendMessage
  4174. return pitbar->_OnNotify((LPNMHDR)lParam);
  4175. case WM_NOTIFYFORMAT:
  4176. if (NF_QUERY == lParam)
  4177. return (DLL_IS_UNICODE ? NFR_UNICODE : NFR_ANSI);
  4178. break;
  4179. case WM_COMMAND:
  4180. pitbar->_OnCommand(wParam, lParam);
  4181. break;
  4182. case WM_ERASEBKGND:
  4183. {
  4184. HDC hdc = (HDC)wParam;
  4185. RECT rc;
  4186. GetClientRect(hwnd, &rc);
  4187. SHFillRectClr(hdc, &rc, (pitbar->_fTheater) ? RGB(0,0,0) : GetSysColor(COLOR_3DFACE));
  4188. break;
  4189. }
  4190. case WM_PALETTECHANGED:
  4191. //
  4192. // PERF: we could optimize this by realizing and checking the
  4193. // return value
  4194. //
  4195. // for now we will just invalidate ourselves and all children...
  4196. //
  4197. RedrawWindow(hwnd, NULL, NULL,
  4198. RDW_INVALIDATE | RDW_ERASE | RDW_ALLCHILDREN);
  4199. break;
  4200. case WM_MEASUREITEM:
  4201. {
  4202. PMEASUREITEMSTRUCT pmis;
  4203. ASSERT(NULL != lParam);
  4204. pmis = (PMEASUREITEMSTRUCT)lParam;
  4205. switch (pmis->itemID)
  4206. {
  4207. case FCIDM_VBBHISTORYBAND:
  4208. ASSERT(0 == wParam);
  4209. {
  4210. PULONG_PTR pData = (PULONG_PTR)pmis->itemData;
  4211. ASSERT(NULL != pData);
  4212. MeasureMenuItem(pmis, (PCTSTR)pData[0]);
  4213. }
  4214. break;
  4215. default:
  4216. goto DoDefault;
  4217. }
  4218. break;
  4219. }
  4220. case WM_DRAWITEM:
  4221. {
  4222. PDRAWITEMSTRUCT pdis;
  4223. ASSERT(NULL != lParam);
  4224. pdis = (PDRAWITEMSTRUCT)lParam;
  4225. switch (pdis->itemID)
  4226. {
  4227. case FCIDM_VBBHISTORYBAND:
  4228. ASSERT(0 == wParam);
  4229. {
  4230. PULONG_PTR pData = (PULONG_PTR)pdis->itemData;
  4231. ASSERT(NULL != pData);
  4232. DrawMenuItem(pdis, (PCTSTR)pData[0], (UINT) pData[1]);
  4233. }
  4234. break;
  4235. default:
  4236. goto DoDefault;
  4237. }
  4238. break;
  4239. }
  4240. case WM_MENUCHAR:
  4241. if (MF_POPUP == HIWORD(wParam))
  4242. {
  4243. MENUITEMINFO mii = { 0 };
  4244. mii.cbSize = sizeof(mii);
  4245. mii.fMask = MIIM_DATA | MIIM_TYPE;
  4246. GetMenuItemInfo((HMENU)lParam, FCIDM_VBBHISTORYBAND, FALSE, &mii);
  4247. if (TEXT('h') == LOWORD(wParam) || TEXT('H') == LOWORD(wParam))
  4248. {
  4249. return MAKELRESULT(FCIDM_VBBHISTORYBAND, MNC_EXECUTE);
  4250. }
  4251. }
  4252. break;
  4253. case WM_TIMER:
  4254. switch (wParam)
  4255. {
  4256. case IDT_UPDATETOOLBAR:
  4257. pitbar->_fUpdateToolbarTimer = FALSE;
  4258. KillTimer(hwnd, wParam);
  4259. if (pitbar->_fNeedUpdateToolbar)
  4260. pitbar->_UpdateToolbarNow();
  4261. break;
  4262. }
  4263. break;
  4264. case WM_DESTROY:
  4265. pitbar->_Unadvise(); // remove ref-loop with _pdie
  4266. TraceMsg(DM_TBREF, "CInternetToolbar::SizableWndProc() - Called RemoveProp. Called Release new _cRef=%d", pitbar->_cRef);
  4267. goto DoDefault;
  4268. DoDefault:
  4269. default:
  4270. return(DefWindowProcWrap(hwnd, uMsg, wParam, lParam));
  4271. }
  4272. return 0L;
  4273. }
  4274. HRESULT CInternetToolbar::ResizeBorderDW(LPCRECT prcBorder,
  4275. IUnknown* punkToolbarSite,
  4276. BOOL fReserved)
  4277. {
  4278. TraceMsg(DM_LAYOUT, "CITB::ResizeBorderDW called (_fShow==%d)", _fShow);
  4279. HRESULT hres = S_OK;
  4280. ASSERT(_ptbsite);
  4281. if (_ptbsite)
  4282. {
  4283. RECT rcRequest = { 0, 0, 0, 0 };
  4284. if (_fShow)
  4285. {
  4286. RECT rcRebar, rcBorder;
  4287. int cx,cy;
  4288. GetWindowRect(_bs._hwnd, &rcRebar);
  4289. cx = rcRebar.right - rcRebar.left;
  4290. cy = rcRebar.bottom - rcRebar.top;
  4291. int iExtra = 3;
  4292. if (_fTheater)
  4293. {
  4294. // 1 for the 1 pixel border on the bottom
  4295. iExtra = 1;
  4296. }
  4297. else if (_fLockedToolbar)
  4298. {
  4299. iExtra = 0;
  4300. }
  4301. TraceMsg(DM_LAYOUT, "CITB::ResizeBorderDW cy = %d", cy);
  4302. if (!prcBorder)
  4303. {
  4304. _ptbsite->GetBorderDW(SAFECAST(this, IDockingWindow*), &rcBorder);
  4305. prcBorder = &rcBorder;
  4306. }
  4307. cx = prcBorder->right - prcBorder->left;
  4308. SetWindowPos(_bs._hwnd, NULL, 0, 0,
  4309. cx, cy, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE);
  4310. GetWindowRect(_bs._hwnd, &rcRebar);
  4311. rcRequest.top = rcRebar.bottom - rcRebar.top + iExtra;
  4312. SetWindowPos(_hwnd, NULL, prcBorder->left, prcBorder->top,
  4313. rcRebar.right - rcRebar.left, rcRequest.top, SWP_NOZORDER | SWP_NOACTIVATE);
  4314. }
  4315. if (_fTheater && _fAutoHide)
  4316. {
  4317. // if we're in theater mode, then we should request no space
  4318. rcRequest.left = rcRequest.top = 0;
  4319. }
  4320. TraceMsg(DM_LAYOUT, "CITB::ResizeBorderDW calling RequstBS with %d,%d,%d,%d",
  4321. rcRequest.left, rcRequest.top, rcRequest.right, rcRequest.bottom);
  4322. _ptbsite->RequestBorderSpaceDW(SAFECAST(this, IDockingWindow*), &rcRequest);
  4323. TraceMsg(DM_LAYOUT, "CITB::ResizeBorderDW calling SetBS with %d,%d,%d,%d",
  4324. rcRequest.left, rcRequest.top, rcRequest.right, rcRequest.bottom);
  4325. _ptbsite->SetBorderSpaceDW(SAFECAST(this, IDockingWindow*), &rcRequest);
  4326. }
  4327. return hres;
  4328. }
  4329. HRESULT CInternetToolbar::QueryStatus(const GUID *pguidCmdGroup,
  4330. ULONG cCmds, OLECMD rgCmds[], OLECMDTEXT *pcmdtext)
  4331. {
  4332. HRESULT hr = OLECMDERR_E_UNKNOWNGROUP;
  4333. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID(CBIDX_ADDRESS);
  4334. if (pbid && pbid->pdb)
  4335. {
  4336. IOleCommandTarget *poct;
  4337. if (SUCCEEDED(pbid->pdb->QueryInterface(IID_PPV_ARG(IOleCommandTarget, &poct))))
  4338. {
  4339. hr = poct->QueryStatus(pguidCmdGroup, cCmds, rgCmds, pcmdtext);
  4340. poct->Release();
  4341. }
  4342. }
  4343. if (pguidCmdGroup && IsEqualGUID(CGID_PrivCITCommands, *pguidCmdGroup))
  4344. {
  4345. hr = S_OK;
  4346. for (ULONG i = 0 ; i < cCmds; i++)
  4347. {
  4348. rgCmds[i].cmdf = 0;
  4349. switch (rgCmds[i].cmdID)
  4350. {
  4351. case CITIDM_VIEWTOOLS:
  4352. if (_nVisibleBands & VBF_TOOLS)
  4353. rgCmds[i].cmdf = OLECMDF_ENABLED;
  4354. break;
  4355. case CITIDM_VIEWMENU:
  4356. if (_nVisibleBands & VBF_MENU)
  4357. rgCmds[i].cmdf = OLECMDF_ENABLED;
  4358. break;
  4359. case CITIDM_VIEWTOOLBARCUSTOMIZE:
  4360. if (_btb._fCustomize)
  4361. rgCmds[i].cmdf = OLECMDF_ENABLED;
  4362. break;
  4363. case CITIDM_VIEWAUTOHIDE:
  4364. if (_fAutoHide)
  4365. rgCmds[i].cmdf = OLECMDF_ENABLED;
  4366. break;
  4367. case CITIDM_VIEWLOCKTOOLBAR:
  4368. if (_fLockedToolbar)
  4369. rgCmds[i].cmdf = OLECMDF_ENABLED;
  4370. break;
  4371. case CITIDM_VIEWADDRESS:
  4372. if (_nVisibleBands & VBF_ADDRESS)
  4373. rgCmds[i].cmdf = OLECMDF_ENABLED;
  4374. break;
  4375. case CITIDM_VIEWLINKS:
  4376. if (_nVisibleBands & VBF_LINKS)
  4377. rgCmds[i].cmdf = OLECMDF_ENABLED;
  4378. break;
  4379. case CITIDM_TEXTLABELS:
  4380. if (!_fCompressed)
  4381. rgCmds[i].cmdf = OLECMDF_ENABLED;
  4382. break;
  4383. case CITIDM_EDITPAGE:
  4384. if (_fEditEnabled)
  4385. rgCmds[i].cmdf = OLECMDF_ENABLED;
  4386. #ifdef EDIT_HACK
  4387. // The tooltip text is also used for the menu
  4388. if (pcmdtext)
  4389. {
  4390. TCHAR szBuf[MAX_PATH];
  4391. if ((pcmdtext->cmdtextf == OLECMDTEXTF_NAME) &&
  4392. _aEditVerb.GetMenuText(szBuf, ARRAYSIZE(szBuf)))
  4393. {
  4394. SHTCharToUnicode(szBuf, pcmdtext->rgwz, pcmdtext->cwBuf);
  4395. pcmdtext->cwActual = lstrlenW(pcmdtext->rgwz) + 1;
  4396. }
  4397. else
  4398. {
  4399. pcmdtext->cwActual = 0;
  4400. }
  4401. }
  4402. #endif
  4403. break;
  4404. default:
  4405. if (InRange( rgCmds[i].cmdID, CITIDM_VIEWEXTERNALBAND_FIRST, CITIDM_VIEWEXTERNALBAND_LAST))
  4406. {
  4407. int iBand = rgCmds[i].cmdID - CITIDM_VIEWEXTERNALBAND_FIRST;
  4408. if (!IsEqualCLSID( _rgebi[iBand].clsid, GUID_NULL ))
  4409. {
  4410. rgCmds[i].cmdf |= OLECMDF_SUPPORTED;
  4411. if (_nVisibleBands & EXTERNALBAND_VBF_BIT( iBand ))
  4412. {
  4413. rgCmds[i].cmdf |= OLECMDF_ENABLED;
  4414. }
  4415. if (pcmdtext)
  4416. {
  4417. pcmdtext->rgwz[0] = TEXT('\0');
  4418. switch (pcmdtext->cmdtextf)
  4419. {
  4420. case OLECMDTEXTF_NAME:
  4421. if (_rgebi[iBand].pwszName)
  4422. Str_GetPtrW(_rgebi[iBand].pwszName, pcmdtext->rgwz, pcmdtext->cwBuf );
  4423. break;
  4424. case OLECMDTEXTF_STATUS:
  4425. if (_rgebi[iBand].pwszHelp)
  4426. Str_GetPtrW(_rgebi[iBand].pwszHelp, pcmdtext->rgwz, pcmdtext->cwBuf );
  4427. break;
  4428. default:
  4429. break;
  4430. }
  4431. pcmdtext->cwActual = lstrlen( pcmdtext->rgwz );
  4432. }
  4433. }
  4434. }
  4435. break;
  4436. }
  4437. }
  4438. }
  4439. return hr;
  4440. }
  4441. void CInternetToolbar::_RestoreSaveStruct(COOLBARSAVE* pcs)
  4442. {
  4443. REBARBANDINFO rbbi;
  4444. rbbi.cbSize = sizeof(REBARBANDINFO);
  4445. int i;
  4446. _fAutoHide = pcs->fAutoHide;
  4447. _ShowVisible(pcs->uiVisible, FALSE);
  4448. BOOL fAllowRetry = TRUE;
  4449. BOOL fNeedRetry = FALSE;
  4450. INT_PTR fRedraw = SendMessage(_bs._hwnd, WM_SETREDRAW, FALSE, 0);
  4451. Retry:
  4452. for (i = 0; i < CBANDSMAX; i++)
  4453. {
  4454. INT_PTR iIndex = SendMessage(_bs._hwnd, RB_IDTOINDEX, pcs->bs[i].wID, 0);
  4455. if (iIndex != -1)
  4456. {
  4457. SendMessage(_bs._hwnd, RB_MOVEBAND, iIndex, i);
  4458. rbbi.fMask = RBBIM_STYLE;
  4459. if (SendMessage(_bs._hwnd, RB_GETBANDINFO, i, (LPARAM) &rbbi))
  4460. {
  4461. rbbi.fMask = RBBIM_SIZE | RBBIM_STYLE;
  4462. rbbi.cx = pcs->bs[i].cx;
  4463. rbbi.fStyle = pcs->bs[i].fStyle;
  4464. SendMessage(_bs._hwnd, RB_SETBANDINFO, i, (LPARAM) &rbbi);
  4465. }
  4466. // the SetBandInfo could have potentially caused items to shift around
  4467. // verify that this didn't happen.
  4468. iIndex = SendMessage(_bs._hwnd, RB_IDTOINDEX, pcs->bs[i].wID, 0);
  4469. if (iIndex != i)
  4470. {
  4471. fNeedRetry = TRUE;
  4472. }
  4473. }
  4474. }
  4475. if (fAllowRetry && fNeedRetry)
  4476. {
  4477. fAllowRetry = FALSE;
  4478. goto Retry;
  4479. }
  4480. _CSHSetStatusBar(pcs->fStatusBar);
  4481. _UpdateToolsStyle(pcs->fList);
  4482. RECT rc;
  4483. GetWindowRect(_bs._hwnd, &rc);
  4484. SetWindowPos(_bs._hwnd, NULL, 0,0, RECTWIDTH(rc), pcs->cyRebar, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
  4485. SendMessage(_bs._hwnd, WM_SETREDRAW, fRedraw, 0);
  4486. }
  4487. void CInternetToolbar::_CSHSetStatusBar(BOOL fOn)
  4488. {
  4489. VARIANTARG v = { 0 };
  4490. v.vt = VT_I4;
  4491. v.lVal = fOn;
  4492. IUnknown_Exec(_ptbsite, &CGID_ShellBrowser, FCIDM_SETSTATUSBAR,
  4493. 0, &v, NULL);
  4494. }
  4495. void CInternetToolbar::_TheaterModeLayout(BOOL fEnter)
  4496. {
  4497. static const struct {
  4498. int id;
  4499. int cx;
  4500. } c_layout[] =
  4501. {
  4502. { CBIDX_TOOLS, 400 },
  4503. { CBIDX_MENU, 200 },
  4504. { CBIDX_ADDRESS, 300 },
  4505. { CBIDX_LINKS, 40 }
  4506. };
  4507. REBARBANDINFO rbbi;
  4508. rbbi.cbSize = sizeof(REBARBANDINFO);
  4509. BOOL_PTR fRedraw = SendMessage(_bs._hwnd, WM_SETREDRAW, FALSE, 0);
  4510. SHSetWindowBits(_bs._hwnd, GWL_STYLE, RBS_AUTOSIZE, 0);
  4511. if (fEnter)
  4512. {
  4513. _BuildSaveStruct(&_cs);
  4514. // turn off text labels
  4515. COOLBARSAVE cs;
  4516. DWORD dwType, cbSize = sizeof(COOLBARSAVE);
  4517. if (SHRegGetUSValue(c_szRegKeyCoolbar, c_szValueTheater, &dwType, (void*)&cs, &cbSize, FALSE, NULL, 0) == ERROR_SUCCESS &&
  4518. cs.cbVer == CBS_VERSION)
  4519. {
  4520. _RestoreSaveStruct(&cs);
  4521. _UpdateToolbarDisplay(UTD_TEXTLABEL, 0, TRUE, TRUE);
  4522. }
  4523. else
  4524. {
  4525. _UpdateToolbarDisplay(UTD_TEXTLABEL, 0, TRUE, TRUE);
  4526. _ShowVisible(VBF_TOOLS | VBF_BRAND, FALSE); // only show tools band by default
  4527. RECT rc = { 0, 0, GetSystemMetrics(SM_CXSCREEN), 20 }; // something arbitrarily small vertically
  4528. SendMessage(_bs._hwnd, RB_SIZETORECT, 0, (LPARAM)&rc);
  4529. int cBands = (int) SendMessage(_bs._hwnd, RB_GETBANDCOUNT, 0, 0L);
  4530. int i;
  4531. // strip off all blanks
  4532. rbbi.fMask = RBBIM_STYLE;
  4533. for (i = 0; i < cBands; i++)
  4534. {
  4535. if (SendMessage(_bs._hwnd, RB_GETBANDINFO, i, (LPARAM) &rbbi))
  4536. {
  4537. rbbi.fStyle &= ~RBBS_BREAK;
  4538. SendMessage(_bs._hwnd, RB_SETBANDINFO, i, (LPARAM) &rbbi);
  4539. }
  4540. }
  4541. // then move into the proper order and size
  4542. for (i = 0; i < ARRAYSIZE(c_layout); i++)
  4543. {
  4544. INT_PTR iIndex = SendMessage(_bs._hwnd, RB_IDTOINDEX, c_layout[i].id, 0);
  4545. if (iIndex != -1)
  4546. {
  4547. SendMessage(_bs._hwnd, RB_MOVEBAND, iIndex, i);
  4548. rbbi.fMask = RBBIM_SIZE;
  4549. rbbi.cx = c_layout[i].cx;
  4550. SendMessage(_bs._hwnd, RB_SETBANDINFO, i, (LPARAM) &rbbi);
  4551. }
  4552. }
  4553. _CSHSetStatusBar(FALSE); // default value in theater mode
  4554. }
  4555. SHSetWindowBits(_bs._hwnd, GWL_STYLE, RBS_BANDBORDERS | WS_BORDER, RBS_BANDBORDERS);
  4556. }
  4557. else
  4558. {
  4559. COOLBARSAVE cs;
  4560. _BuildSaveStruct(&cs);
  4561. SHRegSetUSValue(c_szRegKeyCoolbar, c_szValueTheater, REG_BINARY,
  4562. (void*)&cs, sizeof(COOLBARSAVE), SHREGSET_HKCU | SHREGSET_FORCE_HKCU);
  4563. _RestoreSaveStruct(&_cs);
  4564. _UpdateToolbarDisplay(UTD_TEXTLABEL, 0, _cs.fNoText, FALSE);
  4565. SHSetWindowBits(_bs._hwnd, GWL_STYLE, RBS_BANDBORDERS | WS_BORDER, RBS_BANDBORDERS | WS_BORDER);
  4566. }
  4567. _SetBackground();
  4568. SHSetWindowBits(_bs._hwnd, GWL_STYLE, RBS_AUTOSIZE, RBS_AUTOSIZE);
  4569. SendMessage(_bs._hwnd, WM_SETREDRAW, fRedraw, 0);
  4570. SetWindowPos(_bs._hwnd, NULL, 0, 0, 0, 0, SWP_FRAMECHANGED|SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
  4571. }
  4572. HRESULT CInternetToolbar::_GetMinRowHeight()
  4573. {
  4574. UINT iHeight = 0;
  4575. int icBands = (int) SendMessage( _bs._hwnd, RB_GETBANDCOUNT, 0, 0 );
  4576. for (int i = 0; i < icBands; i++)
  4577. {
  4578. REBARBANDINFO rbbi;
  4579. rbbi.cbSize = sizeof(REBARBANDINFO);
  4580. rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_STYLE;
  4581. if (SendMessage(_bs._hwnd, RB_GETBANDINFO, i, (LPARAM)&rbbi))
  4582. {
  4583. // go until the end of the row
  4584. if (rbbi.fStyle & RBBS_BREAK)
  4585. break;
  4586. if (!(rbbi.fStyle & RBBS_HIDDEN))
  4587. {
  4588. if (rbbi.cyMinChild > iHeight)
  4589. iHeight = rbbi.cyMinChild;
  4590. }
  4591. }
  4592. }
  4593. return ResultFromShort(iHeight);
  4594. }
  4595. BOOL IsBarRefreshable(IDeskBar* pdb)
  4596. {
  4597. ASSERT(pdb);
  4598. BOOL fIsRefreshable = TRUE;
  4599. VARIANT varClsid = {0};
  4600. if (SUCCEEDED(IUnknown_Exec(pdb, &CGID_DeskBarClient, DBCID_CLSIDOFBAR, 1, NULL, &varClsid)) && (varClsid.vt == VT_BSTR))
  4601. {
  4602. CLSID clsidBar;
  4603. //if the bar is hidden, it returns GUID_NULL, so don't refresh it
  4604. if ( GUIDFromString(varClsid.bstrVal, &clsidBar) &&
  4605. (IsEqualGUID(clsidBar, GUID_NULL)) )
  4606. {
  4607. fIsRefreshable = FALSE;
  4608. }
  4609. else
  4610. {
  4611. //APPHACK for office discussions band (and possibly others)
  4612. //CLSID\GUID\Instance
  4613. WCHAR wszKey[6+40+1+9];
  4614. DWORD dwValue, dwType=REG_DWORD, dwcbData = 4;
  4615. wnsprintf(wszKey, ARRAYSIZE(wszKey), L"CLSID\\%s\\Instance", varClsid.bstrVal);
  4616. if ( (SHGetValue(HKEY_CLASSES_ROOT, wszKey, L"DontRefresh", &dwType, &dwValue, &dwcbData) == ERROR_SUCCESS) &&
  4617. (dwValue != 0) )
  4618. {
  4619. fIsRefreshable = FALSE;
  4620. }
  4621. }
  4622. VariantClear(&varClsid);
  4623. }
  4624. return fIsRefreshable;
  4625. }
  4626. HRESULT CInternetToolbar::Exec(const GUID *pguidCmdGroup, DWORD nCmdID,
  4627. DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut)
  4628. {
  4629. HRESULT hr = OLECMDERR_E_UNKNOWNGROUP; // assume failure
  4630. if (!pguidCmdGroup)
  4631. {
  4632. goto Lother;
  4633. }
  4634. else if (IsEqualGUID(CLSID_CommonButtons, *pguidCmdGroup))
  4635. {
  4636. if (pvarargOut)
  4637. {
  4638. ASSERT(pvarargOut && pvarargOut->vt == VT_I4);
  4639. UINT uiInternalCmdID = pvarargOut->lVal;
  4640. if (nCmdID == TBIDM_SEARCH && uiInternalCmdID == -1)
  4641. _btb._ConvertCmd(pguidCmdGroup, nCmdID, NULL, &uiInternalCmdID);
  4642. switch (nCmdID)
  4643. {
  4644. case TBIDM_BACK:
  4645. case TBIDM_FORWARD:
  4646. case TBIDM_STOPDOWNLOAD:
  4647. case TBIDM_REFRESH:
  4648. case TBIDM_HOME:
  4649. case TBIDM_SEARCH:
  4650. case TBIDM_FAVORITES:
  4651. case TBIDM_HISTORY:
  4652. case TBIDM_ALLFOLDERS:
  4653. case TBIDM_MEDIABAR:
  4654. if (!SendMessage(_btb._hwnd, TB_ISBUTTONENABLED, uiInternalCmdID, 0))
  4655. return S_OK;
  4656. break;
  4657. }
  4658. if (nCmdexecopt == OLECMDEXECOPT_PROMPTUSER)
  4659. {
  4660. // the user hit the drop down
  4661. if (_ptbsitect && pvarargIn && pvarargIn->vt == VT_INT_PTR)
  4662. {
  4663. // v.vt = VT_I4;
  4664. POINT pt;
  4665. RECT* prc = (RECT*)pvarargIn->byref;
  4666. pt.x = prc->left;
  4667. pt.y = prc->bottom;
  4668. switch (nCmdID)
  4669. {
  4670. case TBIDM_BACK:
  4671. _ShowBackForwardMenu(FALSE, pt, prc);
  4672. break;
  4673. case TBIDM_FORWARD:
  4674. _ShowBackForwardMenu(TRUE, pt, prc);
  4675. break;
  4676. }
  4677. // VariantClearLazy(&v);
  4678. }
  4679. return S_OK;
  4680. }
  4681. switch(nCmdID)
  4682. {
  4683. case TBIDM_PREVIOUSFOLDER:
  4684. _ptbsitect->Exec(&CGID_ShellBrowser, FCIDM_PREVIOUSFOLDER, 0, NULL, NULL);
  4685. break;
  4686. case TBIDM_CONNECT:
  4687. DoNetConnect(_hwnd);
  4688. break;
  4689. case TBIDM_DISCONNECT:
  4690. DoNetDisconnect(_hwnd);
  4691. break;
  4692. case TBIDM_BACK:
  4693. _pdie->GoBack();
  4694. break;
  4695. case TBIDM_FORWARD:
  4696. _pdie->GoForward();
  4697. break;
  4698. case TBIDM_HOME:
  4699. _pdie->GoHome();
  4700. break;
  4701. case TBIDM_SEARCH:
  4702. if (_ptbsitect)
  4703. {
  4704. VARIANTARG vaOut = {0};
  4705. VARIANTARG* pvaOut = NULL;
  4706. LPITEMIDLIST pidl = NULL;
  4707. // i'm leaving this not #ifdefed out because it is used by explorer bar
  4708. // persistance (reljai)
  4709. //_SetSearchStuff initializes _guidDefaultSearch, which may or may not have
  4710. // been called yet
  4711. if (IsEqualGUID(_guidDefaultSearch, GUID_NULL))
  4712. _SetSearchStuff();
  4713. // see if what the state of search pane is, so we can toggle it...
  4714. OLECMD rgcmds[] = {{ SBCMDID_SEARCHBAR, 0 },};
  4715. if (_ptbsitect)
  4716. _ptbsitect->QueryStatus(&CGID_Explorer, ARRAYSIZE(rgcmds), rgcmds, NULL);
  4717. // not pressed, then show the pane
  4718. if (!(rgcmds[0].cmdf & OLECMDF_LATCHED))
  4719. {
  4720. WCHAR wszUrl[MAX_URL_STRING];
  4721. if (_GetSearchUrl(wszUrl, ARRAYSIZE(wszUrl)))
  4722. {
  4723. CLSID clsid;
  4724. if (GUIDFromString(wszUrl, &clsid))
  4725. {
  4726. IContextMenu* pcm;
  4727. if (SUCCEEDED(SHCoCreateInstance(NULL, &clsid, NULL, IID_PPV_ARG(IContextMenu, &pcm))))
  4728. {
  4729. CMINVOKECOMMANDINFO ici = {0};
  4730. CHAR szGuid[GUIDSTR_MAX];
  4731. BOOL bSetSite = TRUE;
  4732. ici.cbSize = sizeof(ici);
  4733. ici.hwnd = _hwnd;
  4734. ici.lpVerb = (LPSTR)MAKEINTRESOURCE(0);
  4735. ici.nShow = SW_NORMAL;
  4736. SHStringFromGUIDA(_guidDefaultSearch, szGuid, ARRAYSIZE(szGuid));
  4737. ici.lpParameters = szGuid;
  4738. // in case of rooted browser we need to open the search in the new window
  4739. // 'coz otherwise the pane opens in the same window and user starts search
  4740. // and browseobject (or someone) detects the rooted case and launches new
  4741. // browser for our search results view (which is blank because it cannot do
  4742. // search by itself and also there is not search pane) (reljai)
  4743. if (_pbs2)
  4744. {
  4745. LPITEMIDLIST pidl;
  4746. if (SUCCEEDED(_pbs2->GetPidl(&pidl)))
  4747. {
  4748. bSetSite = !ILIsRooted(pidl);
  4749. ILFree(pidl);
  4750. }
  4751. }
  4752. // if there is no site, InvokeCommand bellow will launch new browser w/ the
  4753. // search pane open
  4754. if (bSetSite)
  4755. IUnknown_SetSite(pcm, _psp);
  4756. hr = pcm->InvokeCommand(&ici);
  4757. if (bSetSite)
  4758. IUnknown_SetSite(pcm, NULL);
  4759. pcm->Release();
  4760. }
  4761. break;
  4762. }
  4763. //_guidCurrentSearch = _guidDefaultSearch;//done on set state
  4764. IECreateFromPathW(wszUrl, &pidl);
  4765. // convert pidl into VARIANT
  4766. // way to pass the pidl, so...
  4767. InitVariantFromIDList(&vaOut, pidl);
  4768. pvaOut = &vaOut;
  4769. }
  4770. }
  4771. hr = _ptbsitect->Exec(&CGID_Explorer, SBCMDID_SEARCHBAR, OLECMDEXECOPT_DONTPROMPTUSER, NULL, pvaOut); // vaIn:NULL means toggle
  4772. ASSERT(SUCCEEDED(hr));
  4773. if (pvaOut)
  4774. VariantClear(pvaOut);
  4775. ILFree(pidl);
  4776. }
  4777. else
  4778. {
  4779. TraceMsg(DM_ERROR, "CITBar::Exec: no IOleCommandTarget!");
  4780. }
  4781. break;
  4782. case TBIDM_FAVORITES:
  4783. case TBIDM_HISTORY:
  4784. case TBIDM_ALLFOLDERS:
  4785. case TBIDM_MEDIABAR:
  4786. if (_ptbsitect)
  4787. {
  4788. static const int tbtab[] = {
  4789. TBIDM_FAVORITES , TBIDM_HISTORY , TBIDM_ALLFOLDERS , TBIDM_MEDIABAR ,
  4790. };
  4791. static const int cttab[] = {
  4792. SBCMDID_FAVORITESBAR, SBCMDID_HISTORYBAR, SBCMDID_EXPLORERBAR, SBCMDID_MEDIABAR,
  4793. };
  4794. HRESULT hres;
  4795. int idCT;
  4796. idCT = SHSearchMapInt(tbtab, cttab, ARRAYSIZE(tbtab), nCmdID);
  4797. hres = _ptbsitect->Exec(&CGID_Explorer, idCT, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL); // vaIn:NULL means toggle
  4798. ASSERT(SUCCEEDED(hres));
  4799. }
  4800. else
  4801. {
  4802. TraceMsg(DM_ERROR, "CITBar::Exec: no IOleCommandTarget!");
  4803. }
  4804. break;
  4805. case TBIDM_THEATER:
  4806. {
  4807. VARIANT_BOOL b;
  4808. if (SUCCEEDED(_pdie->get_TheaterMode(&b)))
  4809. _pdie->put_TheaterMode( b == VARIANT_TRUE ? VARIANT_FALSE : VARIANT_TRUE);
  4810. break;
  4811. }
  4812. case TBIDM_STOPDOWNLOAD:
  4813. if (_fTransitionToHTML)
  4814. {
  4815. UINT uiState;
  4816. _fTransitionToHTML = FALSE;
  4817. if (SUCCEEDED(GetState(&CLSID_CommonButtons, TBIDM_STOPDOWNLOAD, &uiState)))
  4818. {
  4819. uiState |= TBSTATE_HIDDEN;
  4820. SetState(&CLSID_CommonButtons, TBIDM_STOPDOWNLOAD, uiState);
  4821. }
  4822. SendMessage(_hwndAddressBand, CB_SETEDITSEL, NULL, (LPARAM)MAKELONG(-1,0));
  4823. }
  4824. _pdie->Stop();
  4825. break;
  4826. case TBIDM_REFRESH:
  4827. {
  4828. VARIANT v = {0};
  4829. v.vt = VT_I4;
  4830. v.lVal = (GetAsyncKeyState(VK_CONTROL) < 0) ?
  4831. OLECMDIDF_REFRESH_COMPLETELY|OLECMDIDF_REFRESH_PROMPTIFOFFLINE :
  4832. OLECMDIDF_REFRESH_NO_CACHE|OLECMDIDF_REFRESH_PROMPTIFOFFLINE;
  4833. _pdie->Refresh2(&v);
  4834. if (_hwndAddressBand)
  4835. {
  4836. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID(CBIDX_ADDRESS);
  4837. if (pbid && pbid->pdb)
  4838. {
  4839. IAddressBand *pab = NULL;
  4840. if (SUCCEEDED(pbid->pdb->QueryInterface(IID_PPV_ARG(IAddressBand, &pab))))
  4841. {
  4842. VARIANTARG varType = {0};
  4843. varType.vt = VT_I4;
  4844. varType.lVal = OLECMD_REFRESH_TOPMOST;
  4845. pab->Refresh(&varType);
  4846. pab->Release();
  4847. }
  4848. }
  4849. }
  4850. // pass this to vert and horz bars
  4851. IDockingWindowFrame *psb;
  4852. if (_psp && SUCCEEDED(_psp->QueryService(SID_STopLevelBrowser, IID_PPV_ARG(IDockingWindowFrame, &psb))))
  4853. {
  4854. IDeskBar* pdb;
  4855. if (SUCCEEDED(psb->FindToolbar(INFOBAR_TBNAME, IID_PPV_ARG(IDeskBar, &pdb))) && pdb &&
  4856. IsBarRefreshable(pdb))
  4857. {
  4858. IUnknown_Exec(pdb, NULL, OLECMDID_REFRESH, OLECMDIDF_REFRESH_NORMAL|OLECMDIDF_REFRESH_PROMPTIFOFFLINE, NULL, NULL);
  4859. pdb->Release();
  4860. }
  4861. if (SUCCEEDED(psb->FindToolbar(COMMBAR_TBNAME, IID_PPV_ARG(IDeskBar, &pdb))) && pdb &&
  4862. IsBarRefreshable(pdb))
  4863. {
  4864. IUnknown_Exec(pdb, NULL, OLECMDID_REFRESH, OLECMDIDF_REFRESH_NORMAL|OLECMDIDF_REFRESH_PROMPTIFOFFLINE, NULL, NULL);
  4865. pdb->Release();
  4866. }
  4867. psb->Release();
  4868. }
  4869. }
  4870. break;
  4871. }
  4872. }
  4873. }
  4874. else if (IsEqualGUID(IID_IExplorerToolbar, *pguidCmdGroup))
  4875. {
  4876. switch (nCmdID)
  4877. {
  4878. case ETCMDID_GETBUTTONS:
  4879. {
  4880. if (_iButtons == -1)
  4881. {
  4882. // haven't initialized yet
  4883. _iButtons = ARRAYSIZE(c_tbExplorer);
  4884. memcpy(_tbExplorer, c_tbExplorer, sizeof(TBBUTTON) * ARRAYSIZE(c_tbExplorer));
  4885. if (IS_BIDI_LOCALIZED_SYSTEM())
  4886. {
  4887. if (!SHUseClassicToolbarGlyphs())
  4888. {
  4889. _tbExplorer[0].iBitmap = 1;
  4890. _tbExplorer[1].iBitmap = 0;
  4891. }
  4892. }
  4893. if (GetUIVersion() < 5)
  4894. {
  4895. // we don't want up button and network drive buttons available
  4896. // on < nt5 shell (by trident pm design)
  4897. // no customization in shell view on < nt5
  4898. ASSERT(!_fShellView);
  4899. ASSERT(c_tbExplorer[TBXID_PREVIOUSFOLDER].idCommand == TBIDM_PREVIOUSFOLDER);
  4900. _tbExplorer[TBXID_PREVIOUSFOLDER].fsState |= TBSTATE_HIDDEN;
  4901. ASSERT(c_tbExplorer[TBXID_CONNECT].idCommand == TBIDM_CONNECT);
  4902. _tbExplorer[TBXID_CONNECT].fsState |= TBSTATE_HIDDEN;
  4903. ASSERT(c_tbExplorer[TBXID_DISCONNECT].idCommand == TBIDM_DISCONNECT);
  4904. _tbExplorer[TBXID_DISCONNECT].fsState |= TBSTATE_HIDDEN;
  4905. ASSERT(c_tbExplorer[TBXID_ALLFOLDERS].idCommand == TBIDM_ALLFOLDERS);
  4906. if (!_FoldersButtonAvailable())
  4907. _tbExplorer[TBXID_ALLFOLDERS].fsState |= TBSTATE_HIDDEN;
  4908. }
  4909. else
  4910. {
  4911. ASSERT(c_tbExplorer[TBXID_SEARCH].idCommand == TBIDM_SEARCH);
  4912. if (_fShellView && SHRestricted(REST_NOSHELLSEARCHBUTTON))
  4913. _tbExplorer[TBXID_SEARCH].fsState |= TBSTATE_HIDDEN;
  4914. ASSERT(c_tbExplorer[TBXID_CONNECT].idCommand == TBIDM_CONNECT);
  4915. ASSERT(c_tbExplorer[TBXID_DISCONNECT].idCommand == TBIDM_DISCONNECT);
  4916. if (SHRestricted(REST_NONETCONNECTDISCONNECT))
  4917. {
  4918. _tbExplorer[TBXID_CONNECT].fsState |= TBSTATE_HIDDEN;
  4919. _tbExplorer[TBXID_DISCONNECT].fsState |= TBSTATE_HIDDEN;
  4920. }
  4921. }
  4922. ASSERT(_tbExplorer[TBXID_MEDIABAR].idCommand == TBIDM_MEDIABAR);
  4923. if (_fShellView || SHRestricted2W(REST_No_LaunchMediaBar, NULL, 0) || !CMediaBarUtil::IsWMP7OrGreaterCapable())
  4924. {
  4925. _tbExplorer[TBXID_MEDIABAR].fsState |= TBSTATE_HIDDEN;
  4926. }
  4927. ASSERT(_tbExplorer[TBXID_PREVIOUSFOLDER].idCommand == TBIDM_PREVIOUSFOLDER);
  4928. if (!_fShellView)
  4929. {
  4930. _tbExplorer[TBXID_PREVIOUSFOLDER].fsState |= TBSTATE_HIDDEN;
  4931. }
  4932. _iButtons = RemoveHiddenButtons(_tbExplorer, ARRAYSIZE(_tbExplorer));
  4933. }
  4934. pvarargOut->vt = VT_BYREF;
  4935. pvarargOut->byref = (void*)_tbExplorer;
  4936. *pvarargIn->plVal = _iButtons;
  4937. }
  4938. return S_OK;
  4939. }
  4940. }
  4941. else if (IsEqualGUID(CGID_PrivCITCommands, *pguidCmdGroup))
  4942. {
  4943. DWORD dw;
  4944. hr = S_OK;
  4945. switch (nCmdID)
  4946. {
  4947. case CITIDM_GETFOLDERSEARCHES:
  4948. {
  4949. hr = E_INVALIDARG;
  4950. if (pvarargOut)
  4951. {
  4952. IFolderSearches *pfs;
  4953. hr = _GetFolderSearches(&pfs);
  4954. if (SUCCEEDED(hr))
  4955. {
  4956. VariantClear(pvarargOut);
  4957. pvarargOut->vt = VT_UNKNOWN;
  4958. pvarargOut->punkVal = pfs;
  4959. }
  4960. }
  4961. }
  4962. break;
  4963. case CITIDM_SET_DIRTYBIT:
  4964. _fDirty = BOOLIFY(nCmdexecopt);
  4965. break;
  4966. case CITIDM_GETMINROWHEIGHT:
  4967. hr = _GetMinRowHeight();
  4968. break;
  4969. case CITIDM_VIEWTOOLBARCUSTOMIZE:
  4970. _OnCommand(GET_WM_COMMAND_MPS(FCIDM_VIEWTOOLBARCUSTOMIZE, _hwnd, 0));
  4971. break;
  4972. case CITIDM_TEXTLABELS:
  4973. _OnCommand(GET_WM_COMMAND_MPS(FCIDM_VIEWTEXTLABELS, _hwnd, 0));
  4974. break;
  4975. case CITIDM_EDITPAGE:
  4976. // FEATURE: temp code -- edit code moving to dochost.cpp
  4977. _btb.Exec(&CLSID_InternetButtons, DVIDM_EDITPAGE, 0, NULL, NULL);
  4978. break;
  4979. case CITIDM_ONINTERNET:
  4980. switch (nCmdexecopt)
  4981. {
  4982. case CITE_INTERNET:
  4983. _fInitialPidlIsWeb = TRUE;
  4984. _fShellView = !_fInitialPidlIsWeb;
  4985. break;
  4986. case CITE_SHELL:
  4987. _fInitialPidlIsWeb = FALSE;
  4988. _fShellView = !_fInitialPidlIsWeb;
  4989. break;
  4990. case CITE_QUERY:
  4991. return ResultFromScode(_fShellView ? CITE_SHELL : CITE_INTERNET);
  4992. break;
  4993. }
  4994. return ResultFromScode(_fInitialPidlIsWeb ? CITE_INTERNET : CITE_SHELL);
  4995. case CITIDM_VIEWTOOLS:
  4996. _OnCommand(GET_WM_COMMAND_MPS(FCIDM_VIEWTOOLS, _hwnd, 0));
  4997. break;
  4998. case CITIDM_VIEWAUTOHIDE:
  4999. _OnCommand(GET_WM_COMMAND_MPS(FCIDM_VIEWAUTOHIDE, _hwnd, 0));
  5000. break;
  5001. case CITIDM_VIEWLOCKTOOLBAR:
  5002. _OnCommand(GET_WM_COMMAND_MPS(FCIDM_VIEWLOCKTOOLBAR, _hwnd, 0));
  5003. break;
  5004. case CITIDM_VIEWADDRESS:
  5005. _OnCommand(GET_WM_COMMAND_MPS(FCIDM_VIEWADDRESS, _hwnd, 0));
  5006. break;
  5007. case CITIDM_VIEWLINKS:
  5008. _OnCommand(GET_WM_COMMAND_MPS(FCIDM_VIEWLINKS, _hwnd, 0));
  5009. break;
  5010. case CITIDM_VIEWMENU:
  5011. _OnCommand(GET_WM_COMMAND_MPS(FCIDM_VIEWMENU, _hwnd, 0));
  5012. break;
  5013. case CITIDM_SHOWTOOLS:
  5014. dw = VBF_TOOLS;
  5015. goto ShowABand;
  5016. case CITIDM_SHOWADDRESS:
  5017. dw = VBF_ADDRESS;
  5018. goto ShowABand;
  5019. case CITIDM_SHOWLINKS:
  5020. dw = VBF_LINKS;
  5021. goto ShowABand;
  5022. #ifdef UNIX
  5023. case CITIDM_SHOWBRAND:
  5024. dw = VBF_BRAND;
  5025. goto ShowABand;
  5026. #endif
  5027. case CITIDM_SHOWMENU:
  5028. dw = VBF_MENU;
  5029. ShowABand:
  5030. if (nCmdexecopt)
  5031. dw |= _nVisibleBands; // Set
  5032. else
  5033. dw = (_nVisibleBands & ~dw); // Clear
  5034. _ShowVisible(dw, TRUE);
  5035. _fUsingDefaultBands = FALSE;
  5036. break;
  5037. case CITIDM_DISABLESHOWMENU:
  5038. _fNoShowMenu = BOOLIFY(nCmdexecopt);
  5039. break;
  5040. case CITIDM_STATUSCHANGED:
  5041. _fDirty = TRUE;
  5042. if (_ptbsitect)
  5043. _ptbsitect->Exec(&CGID_ShellBrowser, FCIDM_PERSISTTOOLBAR, 0, NULL, NULL);
  5044. break;
  5045. case CITIDM_THEATER:
  5046. if (_fShow)
  5047. {
  5048. // IF YOU SEE HTIS ASSERT, TRY TO REMEMBER WHAT YOU DID AND CALL CHEE
  5049. ASSERT(_fTheater || _nVisibleBands & VBF_MENU);
  5050. switch (nCmdexecopt)
  5051. {
  5052. case THF_ON:
  5053. _fTheater = TRUE;
  5054. ResizeBorderDW(NULL, NULL, FALSE);
  5055. _TheaterModeLayout(TRUE);
  5056. // theater has its own brand, so needs to know whether we're in shell or web view so it can show the right brand
  5057. IUnknown_Exec(_ptbsite, &CGID_Theater, THID_ONINTERNET, _fShellView ? CITE_SHELL : CITE_INTERNET, NULL, NULL);
  5058. // pass back _fAutoHide
  5059. pvarargOut->vt = VT_I4;
  5060. pvarargOut->lVal = _fAutoHide;
  5061. goto notify_bands;
  5062. case THF_OFF:
  5063. _fTheater = FALSE;
  5064. ResizeBorderDW(NULL, NULL, FALSE);
  5065. _TheaterModeLayout(FALSE);
  5066. // position everything properly (needed after reparenting)
  5067. SendMessage(_hwnd, RB_PRIV_RESIZE, 0, 0);
  5068. goto notify_bands;
  5069. notify_bands:
  5070. {
  5071. int icBands = (int) SendMessage( _bs._hwnd, RB_GETBANDCOUNT, 0, 0 );
  5072. for (int i = 0; i < icBands; i++)
  5073. {
  5074. REBARBANDINFO rbbi;
  5075. rbbi.cbSize = sizeof(REBARBANDINFO);
  5076. rbbi.fMask = RBBIM_ID;
  5077. if (SendMessage(_bs._hwnd, RB_GETBANDINFO, i, (LPARAM) &rbbi))
  5078. {
  5079. LPBANDITEMDATA pbid = (LPBANDITEMDATA)_bs._GetBandItemDataStructByID(rbbi.wID);
  5080. if (pbid)
  5081. IUnknown_Exec(pbid->pdb, pguidCmdGroup, CITIDM_THEATER, nCmdexecopt, NULL, NULL);
  5082. }
  5083. }
  5084. }
  5085. break;
  5086. case THF_UNHIDE:
  5087. // position everything properly (needed after reparenting)
  5088. SendMessage(_hwnd, RB_PRIV_RESIZE, 0, 0);
  5089. break;
  5090. }
  5091. // IF YOU SEE HTIS ASSERT, TRY TO REMEMBER WHAT YOU DID AND CALL CHEE
  5092. ASSERT(_fTheater || _nVisibleBands & VBF_MENU);
  5093. }
  5094. break;
  5095. case CITIDM_VIEWEXTERNALBAND_BYCLASSID:
  5096. if ((pvarargIn->vt == VT_BSTR) && pvarargIn->bstrVal)
  5097. {
  5098. CLSID clsid;
  5099. if (GUIDFromString( pvarargIn->bstrVal, &clsid ))
  5100. {
  5101. hr = E_FAIL;
  5102. for (DWORD i = 0; i < MAXEXTERNALBANDS; i++)
  5103. {
  5104. if (clsid == _rgebi[i].clsid)
  5105. {
  5106. DWORD dw = _nVisibleBands;
  5107. DWORD dwBit = EXTERNALBAND_VBF_BIT( i );
  5108. dw = (nCmdexecopt) ? dw | dwBit : dw & ~dwBit;
  5109. if ( !( dw & ~VBF_BRAND))
  5110. {
  5111. _pdie->put_ToolBar( FALSE );
  5112. }
  5113. _ShowVisible(dw, TRUE);
  5114. _fUsingDefaultBands = FALSE;
  5115. hr = S_OK;
  5116. break;
  5117. }
  5118. }
  5119. }
  5120. }
  5121. break;
  5122. default:
  5123. if (InRange( nCmdID, CITIDM_VIEWEXTERNALBAND_FIRST, CITIDM_VIEWEXTERNALBAND_LAST ))
  5124. {
  5125. _OnCommand(GET_WM_COMMAND_MPS( nCmdID - CITIDM_VIEWEXTERNALBAND_FIRST + FCIDM_EXTERNALBANDS_FIRST, _hwnd, 0));
  5126. break;
  5127. }
  5128. ASSERT(0);
  5129. break;
  5130. }
  5131. }
  5132. else
  5133. {
  5134. Lother:
  5135. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID(CBIDX_ADDRESS);
  5136. if (pbid)
  5137. {
  5138. hr = IUnknown_Exec(pbid->pdb, pguidCmdGroup, nCmdID, nCmdexecopt, pvarargIn, pvarargOut);
  5139. }
  5140. }
  5141. return hr;
  5142. }
  5143. BOOL _GetSearchHKEY(REFGUID guidSearch, HKEY *phkey)
  5144. {
  5145. HKEY hkey;
  5146. BOOL bRet = FALSE;
  5147. if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_SZ_STATIC, 0, KEY_READ, &hkey) == ERROR_SUCCESS)
  5148. {
  5149. TCHAR szExt[MAX_PATH];//extension key name
  5150. DWORD cchExt = ARRAYSIZE(szExt);
  5151. int iExt;
  5152. BOOL bNoUrl = FALSE; // true iff guidSearch is found and there is no Url subkey
  5153. for (iExt=0;
  5154. !bRet && RegEnumKeyEx(hkey, iExt, szExt, &cchExt, NULL, NULL, NULL, NULL) == ERROR_SUCCESS;
  5155. cchExt = ARRAYSIZE(szExt), iExt++)
  5156. {
  5157. HKEY hkeyExt; // static extension key
  5158. if (RegOpenKeyEx(hkey, szExt, 0, KEY_READ, &hkeyExt) == ERROR_SUCCESS)
  5159. {
  5160. int i;
  5161. TCHAR szSubKey[32];
  5162. HKEY hkeySub;
  5163. for (i = 0; !bRet && (wnsprintf(szSubKey, ARRAYSIZE(szSubKey), TEXT("%d"), i),
  5164. RegOpenKey(hkeyExt, szSubKey, &hkeySub) == ERROR_SUCCESS);
  5165. i++)
  5166. {
  5167. TCHAR szSearchGuid[GUIDSTR_MAX];
  5168. DWORD cb;
  5169. DWORD dwType;
  5170. cb = sizeof(szSearchGuid);
  5171. if (SHGetValue(hkeySub, REG_SZ_SEARCH_GUID, NULL, &dwType, (BYTE*)szSearchGuid, &cb) == ERROR_SUCCESS)
  5172. {
  5173. GUID guid;
  5174. if (GUIDFromString(szSearchGuid, &guid) &&
  5175. IsEqualGUID(guid, guidSearch))
  5176. {
  5177. HKEY hkeyTmp;
  5178. if (RegOpenKey(hkeySub, REG_SZ_SEARCH_URL, &hkeyTmp) == ERROR_SUCCESS)
  5179. RegCloseKey(hkeyTmp);
  5180. else
  5181. bNoUrl = TRUE;
  5182. bRet = TRUE;
  5183. }
  5184. }
  5185. if (!bRet || bNoUrl)
  5186. RegCloseKey(hkeySub);
  5187. else
  5188. *phkey = hkeySub;
  5189. }
  5190. if (!bNoUrl)
  5191. RegCloseKey(hkeyExt);
  5192. else
  5193. {
  5194. ASSERT(bRet);
  5195. *phkey = hkeyExt;
  5196. }
  5197. }
  5198. }
  5199. RegCloseKey(hkey);
  5200. }
  5201. return bRet;
  5202. }
  5203. HRESULT CInternetToolbar::GetDefaultSearchUrl(LPWSTR pwszUrl, UINT cch)
  5204. {
  5205. HRESULT hr = E_FAIL;
  5206. if (GetDefaultInternetSearchUrlW(pwszUrl, cch, TRUE))
  5207. hr = S_OK;
  5208. return hr;
  5209. }
  5210. void WINAPI CopyEnumElement(void *pDest, const void *pSource, DWORD dwSize)
  5211. {
  5212. if (!pDest)
  5213. return;
  5214. memcpy(pDest, pSource, dwSize);
  5215. }
  5216. class CFolderSearches : public IFolderSearches
  5217. {
  5218. public:
  5219. // *** IUnknown ***
  5220. STDMETHODIMP QueryInterface(REFIID riid, void ** ppvObj);
  5221. STDMETHODIMP_(ULONG) AddRef(void);
  5222. STDMETHODIMP_(ULONG) Release(void);
  5223. // *** IFolderSearches ***
  5224. STDMETHODIMP EnumSearches(IEnumUrlSearch **ppenum);
  5225. STDMETHODIMP DefaultSearch(GUID *pguid);
  5226. CFolderSearches(GUID *pguid, int iCount, URLSEARCH *pUrlSearch);
  5227. ~CFolderSearches();
  5228. private:
  5229. LONG _cRef;
  5230. int _iCount;
  5231. GUID _guidDefault;
  5232. URLSEARCH *_pUrlSearch;
  5233. };
  5234. CFolderSearches::CFolderSearches(GUID *pguid, int iCount, URLSEARCH *pUrlSearch)
  5235. {
  5236. _cRef = 1;
  5237. _iCount = iCount;
  5238. _guidDefault = *pguid;
  5239. _pUrlSearch = pUrlSearch;
  5240. }
  5241. CFolderSearches::~CFolderSearches()
  5242. {
  5243. if (_pUrlSearch)
  5244. LocalFree(_pUrlSearch);
  5245. }
  5246. HRESULT CFolderSearches::QueryInterface(REFIID riid, void **ppvObj)
  5247. {
  5248. static const QITAB qit[] =
  5249. {
  5250. QITABENT(CFolderSearches, IFolderSearches),
  5251. { 0 },
  5252. };
  5253. return QISearch(this, qit, riid, ppvObj);
  5254. }
  5255. ULONG CFolderSearches::AddRef()
  5256. {
  5257. return ++_cRef;
  5258. }
  5259. ULONG CFolderSearches::Release()
  5260. {
  5261. if (--_cRef > 0)
  5262. return _cRef;
  5263. delete this;
  5264. return 0;
  5265. }
  5266. HRESULT CFolderSearches::EnumSearches(IEnumUrlSearch **ppenum)
  5267. {
  5268. HRESULT hres = E_OUTOFMEMORY;
  5269. *ppenum = (IEnumUrlSearch *)new CStandardEnum(IID_IEnumUrlSearch, FALSE,
  5270. _iCount, sizeof(URLSEARCH), _pUrlSearch, CopyEnumElement);
  5271. if (*ppenum)
  5272. {
  5273. _pUrlSearch = NULL;
  5274. _iCount = 0;
  5275. hres = S_OK;
  5276. }
  5277. return hres;
  5278. }
  5279. HRESULT CFolderSearches::DefaultSearch(GUID *pguid)
  5280. {
  5281. *pguid = _guidDefault;
  5282. return S_OK;
  5283. }
  5284. HRESULT CInternetToolbar::_GetFolderSearches(IFolderSearches **ppfs)
  5285. {
  5286. HRESULT hres = E_FAIL;
  5287. *ppfs = NULL;
  5288. if (_hdpaFSI)
  5289. {
  5290. LPURLSEARCH pUrlSearch = NULL;
  5291. int iCount = 0;
  5292. int cFSIs = DPA_GetPtrCount(_hdpaFSI);
  5293. hres = E_OUTOFMEMORY;
  5294. if (cFSIs > 0
  5295. && ((pUrlSearch = (LPURLSEARCH)LocalAlloc(LPTR, sizeof(URLSEARCH)*cFSIs)) != NULL))
  5296. {
  5297. LPFOLDERSEARCHITEM pfsi;
  5298. int i;
  5299. // insert per folder items
  5300. for (i = 0; i < cFSIs && (pfsi = (LPFOLDERSEARCHITEM)DPA_GetPtr(_hdpaFSI, i)) != NULL; i++)
  5301. {
  5302. CLSID clsid;
  5303. // check if Url is actually a GUID. if yes we cannot enumerate it because
  5304. // we need Title/Url pair.
  5305. if (!GUIDFromStringW(pfsi->wszUrl, &clsid))
  5306. {
  5307. lstrcpynW(pUrlSearch[iCount].wszName, pfsi->wszName, ARRAYSIZE(pUrlSearch[iCount].wszName));
  5308. lstrcpynW(pUrlSearch[iCount].wszUrl, pfsi->wszUrl, ARRAYSIZE(pUrlSearch[iCount].wszUrl));
  5309. iCount++;
  5310. }
  5311. }
  5312. }
  5313. *ppfs = new CFolderSearches(&_guidDefaultSearch, iCount, pUrlSearch);
  5314. if (*ppfs)
  5315. hres = S_OK;
  5316. else
  5317. LocalFree(pUrlSearch);
  5318. }
  5319. return hres;
  5320. }
  5321. BOOL CInternetToolbar::_GetSearchUrl(LPWSTR pwszUrl, DWORD cch)
  5322. {
  5323. BOOL bRet = FALSE;
  5324. HKEY hkey;
  5325. if (pwszUrl)
  5326. {
  5327. pwszUrl[0] = L'\0';
  5328. // if we are looking for web search url bypass the registry lookup and the
  5329. // per folder items and go straight to GetDefaultSearchUrl which call
  5330. // GetSearchAssistantUrlW
  5331. if (!IsEqualGUID(_guidDefaultSearch, SRCID_SWebSearch))
  5332. {
  5333. // _GetSearchHKEY looks in the registry where shell search items are registered
  5334. // if we have old shell32 then we don't display shell search items so we should
  5335. // not look in the registry
  5336. if (GetUIVersion() >= 5 && _GetSearchHKEY(_guidDefaultSearch, &hkey))
  5337. {
  5338. DWORD cb = cch*sizeof(TCHAR);
  5339. TCHAR szGuid[GUIDSTR_MAX];
  5340. DWORD cbGuid = sizeof(szGuid);
  5341. // is there a url key
  5342. if (SHGetValueW(hkey, REG_SZ_SEARCH_URL, NULL, NULL, pwszUrl, &cb) == ERROR_SUCCESS)
  5343. bRet = TRUE;
  5344. // no? try the default value, maybe it's the clsid
  5345. else if (SHGetValueW(hkey, NULL, NULL, NULL, szGuid, &cbGuid) == ERROR_SUCCESS)
  5346. {
  5347. GUID guid;
  5348. // is it a valid guid string
  5349. if (GUIDFromString(szGuid, &guid))
  5350. {
  5351. StrCpyNW(pwszUrl, szGuid, cch);
  5352. bRet = TRUE;
  5353. }
  5354. }
  5355. RegCloseKey(hkey);
  5356. }
  5357. // maybe it's one of the per-folder items...
  5358. else if (_hdpaFSI) //FSI = folder search items
  5359. {
  5360. int i;
  5361. LPFOLDERSEARCHITEM pfsi;
  5362. for (i=0; (pfsi = (LPFOLDERSEARCHITEM)DPA_GetPtr(_hdpaFSI, i)) != NULL; i++)
  5363. {
  5364. if (IsEqualGUID(_guidDefaultSearch, pfsi->guidSearch))
  5365. {
  5366. StrCpyNW(pwszUrl, pfsi->wszUrl, cch);
  5367. bRet = TRUE;
  5368. break;
  5369. }
  5370. }
  5371. }
  5372. }
  5373. if (!bRet)
  5374. bRet = SUCCEEDED(GetDefaultSearchUrl(pwszUrl, cch));
  5375. }
  5376. return bRet;
  5377. }
  5378. void CInternetToolbar::_SetSearchStuff()
  5379. {
  5380. UINT uiState;
  5381. BOOL bChecked = FALSE;
  5382. if (SUCCEEDED(GetState(&CLSID_CommonButtons, TBIDM_SEARCH, &uiState)))
  5383. bChecked = uiState & TBSTATE_CHECKED;
  5384. if (!_hdpaFSI)
  5385. {
  5386. _hdpaFSI = DPA_Create(2);
  5387. }
  5388. else
  5389. {
  5390. DPA_EnumCallback(_hdpaFSI, DeleteDPAPtrCB, NULL); // delete all ptrs
  5391. DPA_DeleteAllPtrs(_hdpaFSI); // now tell hdpa to forget about them
  5392. }
  5393. // this is bogus -- _fShellView is always FALSE when using automation
  5394. if (_fShellView)
  5395. _guidDefaultSearch = SRCID_SFileSearch;
  5396. else
  5397. _guidDefaultSearch = SRCID_SWebSearch;
  5398. // get per folder search items and the default search (if any)
  5399. // and insert them to _himlSrc
  5400. _GetFolderSearchData();
  5401. if (!bChecked)
  5402. {
  5403. _guidCurrentSearch = _guidDefaultSearch;
  5404. }
  5405. }
  5406. //
  5407. // CInternetToolbar::SetCommandTarget()
  5408. //
  5409. // This function sets the current command target and button group. A client calls this
  5410. // before merging in buttons with the AddButtons method.
  5411. //
  5412. // There are a couple of tricky things about this function.
  5413. //
  5414. // NTRAID#NTBUG9-196149-2000/12/11-AIDANL Hide Address Bar by default in explorer for Per/Pro
  5415. // We no longer allow dwFlags to set links, address, tools, brand, relying on
  5416. // CInternetToolbar::_LoadDefaultSettings() for those settings.
  5417. //
  5418. // One is that the client can pass some flags (dwFlags param) specifying the bands it wants
  5419. // showing by default (menu, links, address, tools, brand, external). But we don't let them change
  5420. // the state of the menu band. And, if another client has already set the default bands, we
  5421. // don't let them change the state of any of the bands.
  5422. //
  5423. // The other is that we do some stuff to figure out if the caller is just another instantiation of the same
  5424. // client. If we think this is a new client (new guidButtonGroup), we flush the toolbar and return S_OK.
  5425. // But if we think this is the same client reincarnated (same guidButtonGroup and non-NULL command target),
  5426. // we return S_FALSE without flushing the toolbar. This is done for performance. A new dochost is instantiated
  5427. // on each navigation, but its toolbar buttons never change, so don't bother remerging its toolbar buttons.
  5428. //
  5429. HRESULT CInternetToolbar::SetCommandTarget(IUnknown* punkCmdTarget, const GUID* pguidButtonGroup, DWORD dwFlags)
  5430. {
  5431. if (!pguidButtonGroup || !punkCmdTarget || IsEqualGUID(CLSID_CommonButtons, *pguidButtonGroup))
  5432. return E_INVALIDARG;
  5433. // RAID 196149 - disallow changes to links, address, tools, brand, instead use _cs.uiVisible for these settings
  5434. dwFlags = dwFlags & ~(VBF_LINKS| VBF_ADDRESS | VBF_TOOLS | VBF_BRAND);
  5435. dwFlags |= (_cs.uiVisible & (VBF_LINKS| VBF_ADDRESS | VBF_TOOLS | VBF_BRAND));
  5436. // this should not change the menu bit or external bands.
  5437. dwFlags |= (_nVisibleBands & (VBF_MENU | VBF_EXTERNALBANDS));
  5438. _btb._fCustomize = !((dwFlags & VBF_NOCUSTOMIZE) || SHRestricted2(REST_NOTOOLBARCUSTOMIZE, NULL, 0));
  5439. // if the new button group is the internet button group, then we're
  5440. // in internet mode; else we're in shell mode
  5441. _fShellView = !(_IsDocHostGUID(pguidButtonGroup));
  5442. _SetSearchStuff();
  5443. HRESULT hr = S_FALSE;
  5444. BOOL fNewButtonGroup = !IsEqualGUID(*pguidButtonGroup, _btb._guidCurrentButtonGroup);
  5445. BOOL fNewCommandTarget = !SHIsSameObject(_btb._pctCurrentButtonGroup, punkCmdTarget);
  5446. // when changing button groups we need to invalidate our cache of buttons for customization
  5447. // why? well, with browse in separate process not turned on, navigating from shell to web
  5448. // reuses the toolbar and some buttons may be disabled for shell but not for browser and vice versa.
  5449. if (fNewButtonGroup)
  5450. _iButtons = -1;
  5451. if (fNewButtonGroup || fNewCommandTarget)
  5452. {
  5453. if (_btb._pctCurrentButtonGroup)
  5454. _btb._pctCurrentButtonGroup->Exec(&IID_IExplorerToolbar, ETCMDID_NEWCOMMANDTARGET, 0, NULL, NULL);
  5455. _btb._guidCurrentButtonGroup = *pguidButtonGroup;
  5456. ATOMICRELEASE(_btb._pctCurrentButtonGroup);
  5457. punkCmdTarget->QueryInterface(IID_PPV_ARG(IOleCommandTarget, &_btb._pctCurrentButtonGroup));
  5458. // A new view can tell us how many rows of text it NEEDs.
  5459. // if it doesn't specify, we give it the default. (stored in _uiDefaultTBTextRows)
  5460. if (dwFlags & VBF_ONELINETEXT )
  5461. _uiTBTextRows = 1;
  5462. else if (dwFlags & VBF_TWOLINESTEXT)
  5463. _uiTBTextRows = 2;
  5464. else
  5465. _uiTBTextRows = _uiTBDefaultTextRows;
  5466. _CompressBands(_fCompressed, _uiTBTextRows, FALSE);
  5467. if (fNewButtonGroup)
  5468. {
  5469. // new button group; flush toolbar
  5470. _btb._RemoveAllButtons();
  5471. hr = S_OK;
  5472. }
  5473. if (_fUsingDefaultBands && !_fTheater)
  5474. _fUsingDefaultBands = FALSE;
  5475. else
  5476. dwFlags = _nVisibleBands;
  5477. if (dwFlags)
  5478. _ShowBands(dwFlags);
  5479. }
  5480. return hr;
  5481. }
  5482. HRESULT CInternetToolbar::AddStdBrowserButtons()
  5483. {
  5484. //
  5485. // code to add browser buttons has moved to CDocObjectHost::_AddButtons
  5486. //
  5487. ASSERT(0);
  5488. return E_NOTIMPL;
  5489. }
  5490. void CInternetToolbar::_ReloadButtons()
  5491. {
  5492. if (!IsEqualGUID(_btb._guidCurrentButtonGroup, CLSID_CommonButtons) &&
  5493. _btb._pctCurrentButtonGroup)
  5494. {
  5495. HRESULT hres = _btb._pctCurrentButtonGroup->Exec(&IID_IExplorerToolbar, ETCMDID_RELOADBUTTONS, 0, NULL, NULL);
  5496. if (FAILED(hres))
  5497. AddButtons(&_btb._guidCurrentButtonGroup, _btb._cBtnsAdded, _btb._pbtnsAdded);
  5498. #ifdef EDIT_HACK
  5499. _InitEditButtonStyle();
  5500. #endif
  5501. _UpdateToolbar(TRUE);
  5502. }
  5503. }
  5504. // The cmdTarget should have already added the Imagelists and the strings.
  5505. HRESULT CInternetToolbar::AddButtons(const GUID* pguidButtonGroup, UINT nNewButtons, const TBBUTTON * lpButtons)
  5506. {
  5507. if (!pguidButtonGroup || !IsEqualGUID(*pguidButtonGroup, _btb._guidCurrentButtonGroup))
  5508. return E_INVALIDARG;
  5509. if (!IsWindow(_btb._hwnd))
  5510. return E_FAIL;
  5511. LPTBBUTTON lpTBCopy = (LPTBBUTTON)LocalAlloc(LPTR, nNewButtons * sizeof(TBBUTTON));
  5512. if (!lpTBCopy)
  5513. return E_OUTOFMEMORY;
  5514. _CreateBands();
  5515. _btb._RemoveAllButtons();
  5516. memcpy(lpTBCopy, lpButtons, sizeof(TBBUTTON) * nNewButtons);
  5517. nNewButtons = _btb._ProcessExternalButtons(lpTBCopy, nNewButtons);
  5518. // Free the old button array
  5519. _btb._FreeBtnsAdded();
  5520. _btb._pbtnsAdded = lpTBCopy;
  5521. _btb._cBtnsAdded = nNewButtons;
  5522. if (_btb._fCustomize && _btb._SaveRestoreToolbar(FALSE))
  5523. {
  5524. // Customization mechanism filled the toolbar for us
  5525. //
  5526. // The customization mechanism allocated its own set of
  5527. // cmdmaps for the buttons, which means that we need to
  5528. // free those hanging off _pbtnsAdded when _pbtnsAdded is
  5529. // freed.
  5530. //
  5531. _btb._fNeedFreeCmdMapsAdded = TRUE;
  5532. _btb._RecalcButtonWidths();
  5533. #ifdef EDIT_HACK
  5534. //
  5535. // If we had a custom edit glyph, reload it so that we
  5536. // don't momentarily flash the default glyph during
  5537. // navigation. We'll update it again when we get a
  5538. // DISPID_DOCUMENTCOMPLETE event.
  5539. //
  5540. _RefreshEditGlyph();
  5541. #endif //EDIT_HACK
  5542. if (!_fShellView)
  5543. {
  5544. _btb._AddMediaBarButton();
  5545. }
  5546. }
  5547. else
  5548. {
  5549. // No customization found for this button group
  5550. //
  5551. // We're adding the button array to toolbar directly,
  5552. // and the cmdmaps get freed on TBN_DELETINGBUTTON, so
  5553. // we shouldn't also try to free them when _pbtnsAdded
  5554. // is freed.
  5555. //
  5556. _btb._fNeedFreeCmdMapsAdded = FALSE;
  5557. _AddCommonButtons();
  5558. SendMessage(_btb._hwnd, TB_ADDBUTTONS, nNewButtons, (LPARAM)lpTBCopy);
  5559. }
  5560. _bs._SetMinDimensions();
  5561. return S_OK;
  5562. }
  5563. HRESULT CInternetToolbar::AddString(const GUID * pguidButtonGroup, HINSTANCE hInst, UINT_PTR uiResID, LONG_PTR *pOffset)
  5564. {
  5565. TraceMsg(DM_ITBAR, "CITBar::AddString called");
  5566. *pOffset = -1;
  5567. if (!IsWindow(_btb._hwnd))
  5568. {
  5569. TraceMsg(DM_ERROR, "CITBar::AddString failed");
  5570. return E_FAIL;
  5571. }
  5572. *pOffset= SendMessage(_btb._hwnd, TB_ADDSTRING, (WPARAM)hInst, (LPARAM)uiResID);
  5573. if (*pOffset != -1)
  5574. return S_OK;
  5575. TraceMsg(DM_ERROR, "CITBar::AddString failed");
  5576. return E_FAIL;
  5577. }
  5578. HRESULT CInternetToolbar::GetButton(const GUID* pguidButtonGroup, UINT uiCommand, LPTBBUTTON lpButton)
  5579. {
  5580. UINT_PTR uiIndex = 0;
  5581. TraceMsg(DM_ITBAR, "CITBar::GetButton called");
  5582. if (!pguidButtonGroup || !IsWindow(_btb._hwnd))
  5583. return E_FAIL;
  5584. if (SUCCEEDED(_btb._ConvertCmd(pguidButtonGroup, uiCommand, NULL, &uiCommand)))
  5585. {
  5586. uiIndex = SendMessage(_btb._hwnd, TB_COMMANDTOINDEX, uiCommand, 0L);
  5587. if (SendMessage(_btb._hwnd, TB_GETBUTTON, uiIndex, (LPARAM)lpButton))
  5588. {
  5589. GUID guid;
  5590. _btb._ConvertCmd(NULL, lpButton->idCommand, &guid, (UINT*)&lpButton->idCommand);
  5591. return S_OK;
  5592. }
  5593. }
  5594. return E_FAIL;
  5595. }
  5596. HRESULT CInternetToolbar::GetState(const GUID* pguidButtonGroup, UINT uiCommand, UINT * pfState)
  5597. {
  5598. TraceMsg(DM_ITBAR, "CITBar::GetState called");
  5599. if (!pguidButtonGroup || !IsWindow(_btb._hwnd))
  5600. return E_FAIL;
  5601. if (SUCCEEDED(_btb._ConvertCmd(pguidButtonGroup, uiCommand, NULL, &uiCommand)))
  5602. {
  5603. *pfState = (UINT)SendMessage(_btb._hwnd, TB_GETSTATE, uiCommand, 0L);
  5604. return S_OK;
  5605. }
  5606. return E_FAIL;
  5607. }
  5608. HRESULT CInternetToolbar::SetState(const GUID* pguidButtonGroup, UINT uiCommand, UINT fState)
  5609. {
  5610. BOOL bIsSearchBtn;
  5611. if (!pguidButtonGroup || !IsWindow(_btb._hwnd))
  5612. return E_FAIL;
  5613. TraceMsg(DM_ITBAR, "CITBar::SetState called");
  5614. bIsSearchBtn = uiCommand == TBIDM_SEARCH;
  5615. if (SUCCEEDED(_btb._ConvertCmd(pguidButtonGroup, uiCommand, NULL, &uiCommand)))
  5616. {
  5617. UINT_PTR uiState;
  5618. uiState = SendMessage(_btb._hwnd, TB_GETSTATE, uiCommand, NULL);
  5619. uiState ^= fState;
  5620. if (uiState)
  5621. {
  5622. // search button is being unchecked, change the icon to the default search's
  5623. if (bIsSearchBtn && !(fState & TBSTATE_CHECKED) && !IsEqualGUID(_guidCurrentSearch, _guidDefaultSearch))
  5624. {
  5625. _guidCurrentSearch = _guidDefaultSearch;
  5626. }
  5627. if (SendMessage(_btb._hwnd, TB_SETSTATE, uiCommand, (LPARAM)fState))
  5628. {
  5629. if (uiState & TBSTATE_HIDDEN)
  5630. _bs._SetMinDimensions();
  5631. }
  5632. }
  5633. return S_OK;
  5634. }
  5635. return E_FAIL;
  5636. }
  5637. //
  5638. // A bitmap can be added in two ways:
  5639. // 1. Send a bitmap in the hBMPNew field. The uiBMPType parameter needs to be a BITMAP_BMP*
  5640. // The uiCount and the ptb parameters are ignored
  5641. // The offset is placed in puiOffset
  5642. //
  5643. // 2. A TBADDBITMAP struct can be sent. The uiCount should have the count
  5644. // uiBMPType parameter needs to be a BITMAP_TBA* value
  5645. // The offset is placed in puiOffset
  5646. HRESULT CInternetToolbar::AddBitmap(const GUID * pguidButtonGroup, UINT uiBMPType, UINT uiCount, TBADDBITMAP * ptb, LRESULT * pOffset, COLORREF rgbMask)
  5647. {
  5648. UINT uiGetMSG, uiSetMSG;
  5649. TBBMP_LIST tbl = {NULL};
  5650. TraceMsg(DM_ITBAR, "CITBar::AddBitmap called");
  5651. *pOffset = -1;
  5652. _CreateBands();
  5653. if ((!pguidButtonGroup) || (!IsWindow(_btb._hwnd)) || !_hdsaTBBMPs)
  5654. {
  5655. TraceMsg(DM_ERROR, "CITBar::AddBitmap failed - NULL pguidButtonGroup or invalid _hwnd");
  5656. return E_FAIL;
  5657. }
  5658. // See if we already have the bitmap loaded.
  5659. TBBMP_LIST * pTBBs = NULL;
  5660. int nCount = DSA_GetItemCount(_hdsaTBBMPs);
  5661. for (int nIndex = 0; nIndex < nCount; nIndex++)
  5662. {
  5663. pTBBs = (TBBMP_LIST*)DSA_GetItemPtr(_hdsaTBBMPs, nIndex);
  5664. if ((pTBBs) && (pTBBs->hInst == ptb->hInst) && (pTBBs->uiResID == ptb->nID))
  5665. break;
  5666. pTBBs = NULL;
  5667. }
  5668. // If it was in the commctrl, then we should already have an entry in the DSA
  5669. if ((ptb->hInst == HINST_COMMCTRL) && (!pTBBs))
  5670. {
  5671. TraceMsg(DM_ERROR, "CITBar::AddBitmap failed - bogus ResID for HINST_COMMCTL");
  5672. return E_FAIL;
  5673. }
  5674. // If the icons being added are from fontsext.dll or from dialup networking
  5675. // or the briefcase, then we have it. So just send return the offset
  5676. if (ptb->hInst != HINST_COMMCTRL)
  5677. {
  5678. TCHAR szDLLFileName[MAX_PATH], *pszFN;
  5679. memset(szDLLFileName, 0, ARRAYSIZE(szDLLFileName));
  5680. if (GetModuleFileName(ptb->hInst, szDLLFileName, ARRAYSIZE(szDLLFileName)))
  5681. {
  5682. pszFN = PathFindFileName(szDLLFileName);
  5683. if(!lstrcmpi(pszFN, TEXT("fontext.dll")))
  5684. *pOffset = FONTGLYPH_OFFSET;
  5685. else if (!lstrcmpi(pszFN, TEXT("shell32.dll")))
  5686. {
  5687. // 140 and 141 are the glyphs that Shell32.dll uses:
  5688. // IDB_BRF_TB_SMALL 140
  5689. // IDB_BRF_TB_LARGE 141
  5690. if ((ptb->nID == 140) || (ptb->nID == 141))
  5691. *pOffset = BRIEFCASEGLYPH_OFFSET;
  5692. }
  5693. else if (!lstrcmpi(pszFN, TEXT("rnaui.dll")))
  5694. *pOffset = RNAUIGLYPH_OFFSET;
  5695. else if (!lstrcmpi(pszFN, TEXT("webcheck.dll")))
  5696. *pOffset = WEBCHECKGLYPH_OFFSET;
  5697. if (*pOffset != -1)
  5698. return S_OK;
  5699. }
  5700. }
  5701. // So the bitmaps is not from commctrl. And we have never seen this before.
  5702. // Add an entry into the DSA and then add the bitmap to the himage list.
  5703. if (!pTBBs)
  5704. {
  5705. tbl.hInst = ptb->hInst;
  5706. tbl.uiResID = ptb->nID;
  5707. nIndex = DSA_AppendItem(_hdsaTBBMPs, &tbl);
  5708. if (nIndex < 0)
  5709. {
  5710. TraceMsg(DM_ERROR, "CITBar::AddBitmap failed - nIndex < 0!");
  5711. return E_FAIL;
  5712. }
  5713. pTBBs = (TBBMP_LIST*)DSA_GetItemPtr(_hdsaTBBMPs, nIndex);
  5714. if (!pTBBs)
  5715. {
  5716. TraceMsg(DM_ERROR, "CITBar::AddBitmap failed - pTBBS is NULL!");
  5717. return E_FAIL;
  5718. }
  5719. }
  5720. switch(uiBMPType)
  5721. {
  5722. case BITMAP_NORMAL:
  5723. if ((pTBBs) && (pTBBs->fNormal))
  5724. {
  5725. *pOffset = pTBBs->uiOffset;
  5726. return S_OK;
  5727. }
  5728. else if (pTBBs)
  5729. pTBBs->fNormal = TRUE;
  5730. uiGetMSG = TB_GETIMAGELIST; uiSetMSG = TB_SETIMAGELIST;
  5731. break;
  5732. case BITMAP_HOT:
  5733. if ((pTBBs) && (pTBBs->fHot))
  5734. {
  5735. *pOffset = pTBBs->uiOffset;
  5736. return S_OK;
  5737. }
  5738. else if (pTBBs)
  5739. pTBBs->fHot = TRUE;
  5740. uiGetMSG = TB_GETHOTIMAGELIST; uiSetMSG = TB_SETHOTIMAGELIST;
  5741. break;
  5742. case BITMAP_DISABLED:
  5743. if ((pTBBs) && (pTBBs->fDisabled))
  5744. {
  5745. *pOffset = pTBBs->uiOffset;
  5746. return S_OK;
  5747. }
  5748. else if (pTBBs)
  5749. pTBBs->fDisabled = TRUE;
  5750. uiGetMSG = TB_GETDISABLEDIMAGELIST; uiSetMSG = TB_SETDISABLEDIMAGELIST;
  5751. break;
  5752. default:
  5753. ASSERT(FALSE);
  5754. return E_FAIL;
  5755. }
  5756. pTBBs->uiCount = uiCount;
  5757. *pOffset = _AddBitmapFromForeignModule(uiGetMSG, uiSetMSG, uiCount, ptb->hInst, ptb->nID, rgbMask);
  5758. if (pTBBs)
  5759. pTBBs->uiOffset = (UINT)*pOffset;
  5760. return S_OK;
  5761. }
  5762. // the CmdTarget needs to call this to see what size of bmps we are using.
  5763. HRESULT CInternetToolbar::GetBitmapSize(UINT * uiSize)
  5764. {
  5765. TraceMsg(DM_ITBAR, "CITBar::GetBitmapSize called");
  5766. *uiSize = g_fSmallIcons ? MAKELONG(TB_SMBMP_CX, TB_SMBMP_CY) : MAKELONG(g_iToolBarLargeIconWidth,g_iToolBarLargeIconHeight);
  5767. return S_OK;
  5768. }
  5769. HRESULT CInternetToolbar::SetImageList( const GUID* pguidCmdGroup, HIMAGELIST himlNormal, HIMAGELIST himlHot, HIMAGELIST himlDisabled)
  5770. {
  5771. if (IsEqualGUID(*pguidCmdGroup, _btb._guidCurrentButtonGroup))
  5772. {
  5773. SendMessage(_btb._hwnd, TB_SETIMAGELIST, 1, (LPARAM)himlNormal);
  5774. SendMessage(_btb._hwnd, TB_SETHOTIMAGELIST, 1, (LPARAM)himlHot);
  5775. SendMessage(_btb._hwnd, TB_SETDISABLEDIMAGELIST, 1, (LPARAM)himlDisabled);
  5776. }
  5777. return S_OK;
  5778. }
  5779. HRESULT CInternetToolbar::ModifyButton( const GUID * pguidButtonGroup, UINT uiCommand, LPTBBUTTON lpButton)
  5780. {
  5781. UINT uiIndex = 0;
  5782. TraceMsg(DM_ITBAR, "CITBar::ModifyButton called");
  5783. if (!pguidButtonGroup || !IsWindow(_btb._hwnd))
  5784. return E_FAIL;
  5785. if (SUCCEEDED(_btb._ConvertCmd(pguidButtonGroup, uiCommand, NULL, &uiCommand)))
  5786. {
  5787. TBBUTTONINFO tbbi;
  5788. tbbi.cbSize = sizeof(tbbi);
  5789. tbbi.dwMask = TBIF_STATE | TBIF_IMAGE;
  5790. tbbi.fsState = lpButton->fsState;
  5791. tbbi.iImage = lpButton->iBitmap;
  5792. if (SendMessage(_btb._hwnd, TB_SETBUTTONINFO, uiCommand, (LPARAM)&tbbi))
  5793. {
  5794. return S_OK;
  5795. }
  5796. }
  5797. return E_FAIL;
  5798. }
  5799. HRESULT CInternetToolbar::SendToolbarMsg(const GUID* pguidButtonGroup, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT * plRes)
  5800. {
  5801. LRESULT lRes;
  5802. if (!IsWindow(_btb._hwnd))
  5803. {
  5804. TraceMsg(DM_ERROR, "CITBar::SendToolbarMsg Message failed");
  5805. return E_FAIL;
  5806. }
  5807. if (
  5808. // this api is only here for back compat, and these messages didn't
  5809. // exist when the old clients were written
  5810. uMsg == TB_GETBUTTONINFOA ||
  5811. uMsg == TB_GETBUTTONINFOW ||
  5812. uMsg == TB_SETBUTTONINFOA ||
  5813. uMsg == TB_SETBUTTONINFOW ||
  5814. // unsupported right now
  5815. uMsg == TB_ADDBUTTONSA || uMsg == TB_ADDBUTTONSW
  5816. )
  5817. {
  5818. ASSERT(0);
  5819. return E_FAIL;
  5820. }
  5821. if ((uMsg == TB_ENABLEBUTTON) || (uMsg == TB_HIDEBUTTON) || (uMsg == TB_CHECKBUTTON) ||
  5822. (uMsg == TB_PRESSBUTTON) || (uMsg == TB_MARKBUTTON))
  5823. {
  5824. unsigned int uiTemp;
  5825. if (SUCCEEDED(_btb._ConvertCmd(pguidButtonGroup, (UINT)wParam, NULL, &uiTemp)))
  5826. wParam = uiTemp;
  5827. }
  5828. if (uMsg == TB_INSERTBUTTON && lParam)
  5829. {
  5830. TBBUTTON btn = (*(TBBUTTON*)lParam);
  5831. _btb._PreProcessExternalTBButton(&btn);
  5832. lRes = SendMessage(_btb._hwnd, uMsg, wParam, (LPARAM)&btn);
  5833. }
  5834. else
  5835. {
  5836. lRes = SendMessage(_btb._hwnd, uMsg, wParam, lParam);
  5837. if (uMsg == TB_GETBUTTON)
  5838. {
  5839. TBBUTTON* pbtn = (TBBUTTON*)lParam;
  5840. if (pbtn && pbtn->dwData)
  5841. {
  5842. CMDMAP* pcm = (CMDMAP*)pbtn->dwData;
  5843. pbtn->idCommand = pcm->nCmdID;
  5844. pbtn->dwData = pcm->lParam;
  5845. }
  5846. }
  5847. }
  5848. if (plRes)
  5849. *plRes = lRes;
  5850. return S_OK;
  5851. }
  5852. TOOLSBANDCLASS::CBrowserToolsBand() : CToolbarBand()
  5853. {
  5854. _fCanFocus = TRUE;
  5855. }
  5856. #define DEFAULT_LIST_VALUE() (GetUIVersion() >= 5)
  5857. void TOOLSBANDCLASS::_FreeBtnsAdded()
  5858. {
  5859. if (_pbtnsAdded)
  5860. {
  5861. if (_fNeedFreeCmdMapsAdded)
  5862. {
  5863. for (int i = 0; i < _cBtnsAdded; i++)
  5864. {
  5865. CMDMAP* pcm = (CMDMAP*)_pbtnsAdded[i].dwData;
  5866. _FreeCmdMap(pcm);
  5867. }
  5868. }
  5869. LocalFree(_pbtnsAdded);
  5870. _pbtnsAdded = NULL;
  5871. _cBtnsAdded = 0;
  5872. }
  5873. }
  5874. LRESULT TOOLSBANDCLASS::_ToolsCustNotify (LPNMHDR pnmh)
  5875. {
  5876. LPTBNOTIFY ptbn = (LPTBNOTIFY) pnmh;
  5877. switch (pnmh->code)
  5878. {
  5879. case TBN_SAVE:
  5880. {
  5881. NMTBSAVE *pnmtbs = (NMTBSAVE*)pnmh;
  5882. if (pnmtbs->iItem == -1)
  5883. {
  5884. // before the save
  5885. int nButtons = (int) SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0L);
  5886. int uSize = pnmtbs->cbData +
  5887. sizeof(BUTTONSAVEINFO) * nButtons + // stuff for each button
  5888. sizeof(TOOLBARSAVEINFO); // stuff for the toolbar
  5889. pnmtbs->pData = (LPDWORD)LocalAlloc(LPTR, uSize);
  5890. pnmtbs->pCurrent = pnmtbs->pData;
  5891. pnmtbs->cbData = uSize;
  5892. if (pnmtbs->pData)
  5893. {
  5894. TOOLBARSAVEINFO *ptbsi = (TOOLBARSAVEINFO*)pnmtbs->pData;
  5895. ptbsi->cVersion = TBSI_VERSION;
  5896. pnmtbs->pCurrent = (LPDWORD)(ptbsi+1);
  5897. }
  5898. }
  5899. else
  5900. {
  5901. CMDMAP *pcm = (CMDMAP*)pnmtbs->tbButton.dwData;
  5902. BUTTONSAVEINFO* pbsi = (BUTTONSAVEINFO*)pnmtbs->pCurrent;
  5903. pnmtbs->pCurrent = (LPDWORD)(pbsi+1);
  5904. if (pcm)
  5905. {
  5906. pbsi->guid = pcm->guidButtonGroup;
  5907. pbsi->nCmdID = pcm->nCmdID;
  5908. pbsi->fButtonState = pnmtbs->tbButton.fsState;
  5909. #ifdef DEBUG
  5910. TCHAR szGuid[80];
  5911. SHStringFromGUID(pcm->guidButtonGroup, szGuid, ARRAYSIZE(szGuid));
  5912. TraceMsg(TF_TBCUST, "Saving: %s - %d (%x)", szGuid, pbsi->nCmdID, pbsi->nCmdID);
  5913. #endif
  5914. }
  5915. else
  5916. {
  5917. ASSERT(pnmtbs->tbButton.fsStyle & BTNS_SEP);
  5918. if (pnmtbs->tbButton.idCommand)
  5919. {
  5920. TraceMsg(TF_TBCUST, "Saving: a separator w/ id %d (%x)", pnmtbs->tbButton.idCommand, pnmtbs->tbButton.idCommand);
  5921. pbsi->guid = CLSID_Separator;
  5922. pbsi->nCmdID = pnmtbs->tbButton.idCommand;
  5923. }
  5924. else
  5925. {
  5926. TraceMsg(TF_TBCUST, "Saving: a separator");
  5927. }
  5928. }
  5929. }
  5930. break;
  5931. }
  5932. case TBN_RESTORE:
  5933. {
  5934. NMTBRESTORE* pnmtbr = (NMTBRESTORE*)pnmh;
  5935. if (pnmtbr->iItem == -1)
  5936. {
  5937. // before the restore.
  5938. // take the data, verify the version,
  5939. // fill in the button count, bytes per record
  5940. // initialize the pCurrent to the end of the tb header
  5941. //
  5942. TOOLBARSAVEINFO* ptbsi = (TOOLBARSAVEINFO*)pnmtbr->pCurrent;
  5943. if (ptbsi->cVersion != TBSI_VERSION)
  5944. {
  5945. TraceMsg( TF_WARNING, "TOOLSBANDCLASS::_ToolsCustNotify() - Wrong Toolbar Save Info Version (0x%x vs. 0x%x)!", ptbsi->cVersion, TBSI_VERSION );
  5946. return 1; // abort
  5947. }
  5948. // we're actually going to do a restore. initialize our database:
  5949. _BuildButtonDSA();
  5950. pnmtbr->pCurrent = (LPDWORD)(ptbsi+1);
  5951. pnmtbr->cbBytesPerRecord += sizeof(BUTTONSAVEINFO);
  5952. pnmtbr->cButtons = (pnmtbr->cbData - sizeof(TOOLBARSAVEINFO)) / pnmtbr->cbBytesPerRecord;
  5953. // make sure we did the math right and there are no remainders
  5954. ASSERT(((pnmtbr->cbData - sizeof(TOOLBARSAVEINFO)) % pnmtbr->cbBytesPerRecord) == 0);
  5955. //this is going to clobber all of the buttons in the current toolbar.
  5956. // since toolbar control just writes over the dwords, we need to go free them now.
  5957. int nButtons = (int) SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0L);
  5958. for (int nTemp = 0; nTemp < nButtons; nTemp++)
  5959. {
  5960. CMDMAP *pcm = _GetCmdMapByIndex(nTemp);
  5961. _FreeCmdMap(pcm);
  5962. TBBUTTONINFO tbbi;
  5963. tbbi.cbSize = sizeof(tbbi);
  5964. tbbi.lParam = (LPARAM)NULL;
  5965. tbbi.dwMask = TBIF_LPARAM | TBIF_BYINDEX;
  5966. SendMessage(_hwnd, TB_SETBUTTONINFO, nTemp, (LPARAM)&tbbi);
  5967. }
  5968. }
  5969. else
  5970. {
  5971. BUTTONSAVEINFO* pbsi = (BUTTONSAVEINFO*)pnmtbr->pCurrent;
  5972. pnmtbr->pCurrent = (LPDWORD)(pbsi+1);
  5973. pnmtbr->tbButton.dwData = 0;
  5974. pnmtbr->tbButton.iString = -1;
  5975. if (IsEqualGUID(CLSID_Separator, pbsi->guid))
  5976. {
  5977. // restore a separator with a command id
  5978. pnmtbr->tbButton.fsStyle = BTNS_SEP;
  5979. TraceMsg(TF_TBCUST, "Restoring: a separator w/ id %d (%x)", pnmtbr->tbButton.idCommand, pnmtbr->tbButton.idCommand);
  5980. }
  5981. else if (!(pnmtbr->tbButton.fsStyle & BTNS_SEP))
  5982. {
  5983. // Make sure that the button exists for this site
  5984. CMDMAPCUSTOMIZE* pcmc = _GetCmdMapCustomize(&pbsi->guid, pbsi->nCmdID);
  5985. if ((pcmc == NULL) || (SHRestricted(REST_NONLEGACYSHELLMODE) && ((pbsi->nCmdID == TBIDM_BACK) || (pbsi->nCmdID == TBIDM_FORWARD))))
  5986. {
  5987. // Ignore this button
  5988. return 1;
  5989. }
  5990. CMDMAP* pcm = (CMDMAP*)LocalAlloc(LPTR, sizeof(CMDMAP));
  5991. if (pcm)
  5992. {
  5993. pcm->guidButtonGroup = pbsi->guid;
  5994. pcm->nCmdID = pbsi->nCmdID;
  5995. #ifdef DEBUG
  5996. TCHAR szGuid[80];
  5997. SHStringFromGUID(pcm->guidButtonGroup, szGuid, ARRAYSIZE(szGuid));
  5998. TraceMsg(TF_TBCUST, "Restoring: %s - %d (%x)", szGuid, pbsi->nCmdID, pbsi->nCmdID);
  5999. #endif
  6000. // fill in the rest of the info
  6001. pnmtbr->tbButton = pcmc->btn;
  6002. pnmtbr->tbButton.fsState = pbsi->fButtonState;
  6003. pnmtbr->tbButton.dwData = (DWORD_PTR) pcm;
  6004. }
  6005. }
  6006. else
  6007. {
  6008. TraceMsg(TF_TBCUST, "Restoring: a separator");
  6009. }
  6010. }
  6011. }
  6012. break;
  6013. case TBN_ENDADJUST:
  6014. _OnEndCustomize();
  6015. break;
  6016. case TBN_TOOLBARCHANGE:
  6017. _pcinfo->fDirty = TRUE;
  6018. break;
  6019. case TBN_INITCUSTOMIZE:
  6020. _OnBeginCustomize((NMTBCUSTOMIZEDLG*)pnmh);
  6021. return TBNRF_HIDEHELP;
  6022. case TBN_RESET:
  6023. _pcinfo->fDirty = FALSE;
  6024. if (_pctCurrentButtonGroup)
  6025. {
  6026. NMTBCUSTOMIZEDLG *pnm = (NMTBCUSTOMIZEDLG*)pnmh;
  6027. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _btb, this);
  6028. TCHAR szGuid[GUIDSTR_MAX];
  6029. SHStringFromGUID(_guidCurrentButtonGroup, szGuid, ARRAYSIZE(szGuid));
  6030. SHDeleteValue(HKEY_CURRENT_USER, REGSTR_PATH_TOOLBAR, szGuid);
  6031. // Default text labels setting should be as follows:
  6032. //
  6033. // If fullscreen mode, any platform -- "No text labels"
  6034. // Else if NT5 -- "Selective text on right"
  6035. // Else -- "Show text labels"
  6036. //
  6037. int idsDefault;
  6038. if (pitbar->_fTheater)
  6039. idsDefault = IDS_NOTEXTLABELS;
  6040. else if (DEFAULT_LIST_VALUE())
  6041. idsDefault = IDS_PARTIALTEXT;
  6042. else
  6043. idsDefault = IDS_TEXTLABELS;
  6044. _UpdateTextSettings(idsDefault);
  6045. HWND hwnd = (HWND) GetProp(pnm->hDlg, SZ_PROP_CUSTDLG);
  6046. if (hwnd)
  6047. {
  6048. // update our dialog's control selection states
  6049. _SetDialogSelections(hwnd, _DefaultToSmallIcons());
  6050. }
  6051. _RemoveAllButtons();
  6052. _OnEndCustomize();
  6053. if (_pbtnsAdded)
  6054. {
  6055. pitbar->AddButtons(&_guidCurrentButtonGroup, _cBtnsAdded, _pbtnsAdded);
  6056. #ifdef EDIT_HACK
  6057. // Restore the edit button
  6058. pitbar->_InitEditButtonStyle();
  6059. #endif
  6060. pitbar->_UpdateToolbar(TRUE);
  6061. }
  6062. else
  6063. {
  6064. return TBNRF_ENDCUSTOMIZE;
  6065. }
  6066. }
  6067. break;
  6068. case TBN_QUERYINSERT:
  6069. return TRUE;
  6070. case TBN_QUERYDELETE:
  6071. return (SendMessage(_hwnd, TB_ISBUTTONHIDDEN,
  6072. (WPARAM) ptbn->tbButton.idCommand,
  6073. (LPARAM) 0)) ? FALSE : TRUE;
  6074. case TBN_GETBUTTONINFO:
  6075. if (ptbn->iItem < DSA_GetItemCount(_pcinfo->hdsa))
  6076. {
  6077. CMDMAPCUSTOMIZE *pcmc;
  6078. pcmc = (CMDMAPCUSTOMIZE*)DSA_GetItemPtr(_pcinfo->hdsa, ptbn->iItem);
  6079. ptbn->tbButton = pcmc->btn;
  6080. ptbn->tbButton.fsState &= ~TBSTATE_HIDDEN;
  6081. return TRUE;
  6082. }
  6083. return FALSE;
  6084. case TBN_BEGINADJUST:
  6085. if (!_pcinfo || !_pcinfo->fAdjust)
  6086. return 1;
  6087. break;
  6088. }
  6089. return FALSE;
  6090. }
  6091. BOOL TOOLSBANDCLASS::_SaveRestoreToolbar(BOOL fSave)
  6092. {
  6093. TBSAVEPARAMS tbsp;
  6094. TCHAR szGuid[GUIDSTR_MAX];
  6095. SHStringFromGUID(_guidCurrentButtonGroup, szGuid, ARRAYSIZE(szGuid));
  6096. tbsp.hkr = HKEY_CURRENT_USER;
  6097. tbsp.pszSubKey = REGSTR_PATH_TOOLBAR;
  6098. tbsp.pszValueName = szGuid;
  6099. BOOL fRet = BOOLFROMPTR(SendMessage(_hwnd, TB_SAVERESTORE, (WPARAM) fSave, (LPARAM) &tbsp));
  6100. _FreeCustomizeInfo();
  6101. return fRet;
  6102. }
  6103. void TOOLSBANDCLASS::_AddMediaBarButton()
  6104. {
  6105. // Wrap this with a reg key to make sure it happens only once
  6106. // then check to make sure it's not already in the thing
  6107. if (_hwnd && !SHRestricted2W(REST_No_LaunchMediaBar, NULL, 0) && !SHRestricted2(REST_BTN_MEDIABAR, NULL, 0) && CMediaBarUtil::IsWMP7OrGreaterCapable())
  6108. {
  6109. DWORD dwType, dwSize;
  6110. DWORD dwValue = TBBIF_NONE;
  6111. dwSize = sizeof(dwValue);
  6112. if ( (ERROR_SUCCESS==SHGetValue(HKEY_CURRENT_USER, TBBIF_REG_PATH, TBBIF_REG_KEY, &dwType, &dwValue, &dwSize))
  6113. && (dwType==REG_DWORD)
  6114. && ((dwValue & TBBIF_MEDIA) != 0))
  6115. {
  6116. return;
  6117. }
  6118. dwValue |= TBBIF_MEDIA;
  6119. SHSetValue(HKEY_CURRENT_USER, TBBIF_REG_PATH, TBBIF_REG_KEY, REG_DWORD, &dwValue, sizeof(dwValue));
  6120. TBBUTTONINFO tbbi;
  6121. tbbi.cbSize = sizeof(tbbi);
  6122. tbbi.dwMask = TBIF_STATE | TBIF_BYINDEX | TBIF_LPARAM;
  6123. int iFavs = -1, iHist = -1, iLastTool = -1;
  6124. int iMedia = -1;
  6125. // lookup MediaBar in current toolbar
  6126. // this could be a previous PersonalBar since the MediaBar reuses the cmdID
  6127. BOOL fFound = FALSE;
  6128. int cntButtons = (int)SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0);
  6129. for (int j = 0; j < cntButtons; j++)
  6130. {
  6131. if (SendMessage(_hwnd, TB_GETBUTTONINFO, j, (LPARAM)&tbbi)!=-1)
  6132. {
  6133. CMDMAP* pcm = (CMDMAP*)tbbi.lParam;
  6134. if (pcm)
  6135. {
  6136. // already present ?
  6137. if (pcm->nCmdID == TBIDM_MEDIABAR)
  6138. {
  6139. fFound = TRUE; // no need to add, only care about updating position in toolbar
  6140. iMedia = j;
  6141. }
  6142. // will try placing after Favorites....
  6143. else if (pcm->nCmdID == TBIDM_FAVORITES)
  6144. {
  6145. iFavs = j;
  6146. iLastTool = j;
  6147. }
  6148. // ... and/or before History
  6149. else if (pcm->nCmdID == TBIDM_HISTORY)
  6150. {
  6151. iHist = j;
  6152. iLastTool = j;
  6153. }
  6154. // ... but at least after last found button in second group
  6155. else if ( (pcm->nCmdID == TBIDM_SEARCH)
  6156. || (pcm->nCmdID == TBIDM_ALLFOLDERS))
  6157. {
  6158. iLastTool = j;
  6159. }
  6160. }
  6161. }
  6162. }
  6163. // force-expose MediaBar button at least once
  6164. if (!fFound)
  6165. {
  6166. TBBUTTON tbXBar;
  6167. memcpy((VOID*)&tbXBar, (VOID*)&c_tbExplorer[TBXID_MEDIABAR], sizeof(TBBUTTON));
  6168. CMDMAP* pcm = (CMDMAP*)LocalAlloc(LPTR, sizeof(CMDMAP));
  6169. if (pcm)
  6170. {
  6171. pcm->guidButtonGroup = CLSID_CommonButtons;
  6172. pcm->nCmdID = c_tbExplorer[TBXID_MEDIABAR].idCommand;
  6173. tbXBar.idCommand = _nNextCommandID++;
  6174. tbXBar.dwData = (LPARAM)pcm;
  6175. SendMessage(_hwnd, TB_ADDBUTTONS, 1, (LPARAM)&tbXBar);
  6176. }
  6177. }
  6178. if (iMedia < 0)
  6179. {
  6180. cntButtons = (int)SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0);
  6181. for (j = cntButtons - 1; j >= 0; j--)
  6182. {
  6183. if (SendMessage(_hwnd, TB_GETBUTTONINFO, j, (LPARAM)&tbbi)!=-1)
  6184. {
  6185. CMDMAP* pcm = (CMDMAP*)tbbi.lParam;
  6186. if (pcm)
  6187. {
  6188. // already present ?
  6189. if (pcm->nCmdID == TBIDM_MEDIABAR)
  6190. {
  6191. iMedia = j;
  6192. break;
  6193. }
  6194. }
  6195. }
  6196. }
  6197. }
  6198. // update position of MediaBar button
  6199. // do we know a preferred position where the MediaBar button should move to?
  6200. if ((iMedia >= 0) && ((iFavs >= 0) || (iHist >= 0) || (iLastTool >= 0)))
  6201. {
  6202. int iNewPos = -1;
  6203. if (iFavs >= 0)
  6204. {
  6205. iNewPos = iFavs;
  6206. }
  6207. else if (iHist >= 0)
  6208. {
  6209. iNewPos = max(iHist - 1, 0);
  6210. }
  6211. else if (iLastTool >= 0)
  6212. {
  6213. iNewPos = iLastTool;
  6214. }
  6215. if (iNewPos >= 0)
  6216. {
  6217. if (iNewPos < iMedia)
  6218. SendMessage(_hwnd, TB_MOVEBUTTON, iMedia, iNewPos + 1);
  6219. else
  6220. SendMessage(_hwnd, TB_MOVEBUTTON, iMedia, iNewPos);
  6221. _SaveRestoreToolbar(TRUE);
  6222. _RecalcButtonWidths();
  6223. }
  6224. }
  6225. }
  6226. }
  6227. int TOOLSBANDCLASS::_CommandFromIndex(UINT uIndex)
  6228. {
  6229. TBBUTTONINFO tbbi;
  6230. tbbi.cbSize = sizeof(tbbi);
  6231. tbbi.dwMask = TBIF_COMMAND | TBIF_BYINDEX;
  6232. SendMessage(_hwnd, TB_GETBUTTONINFO, uIndex, (LPARAM)&tbbi);
  6233. return tbbi.idCommand;
  6234. }
  6235. // _btb._ConvertCmd()
  6236. // This is used to covert a external Command ID to an internal ID or vice versa
  6237. // If we are converting to an external ID then
  6238. // call with pguidButtonGroup == NULL (to external: pguidButtonGroup == NULL)
  6239. // otherwise call with the external button group GUID (to internal: pguidOut == NULL)
  6240. HRESULT TOOLSBANDCLASS::_ConvertCmd(const GUID* pguidButtonGroup, UINT id, GUID* pguidOut, UINT * pid)
  6241. {
  6242. HRESULT hres = E_FAIL;
  6243. BOOL fToInternal = (bool) (pguidButtonGroup);
  6244. ASSERT((pguidButtonGroup == NULL) ^ (pguidOut == NULL));
  6245. // First look for the command
  6246. if (fToInternal)
  6247. {
  6248. if (_hwnd)
  6249. {
  6250. int nCount = (int) SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0);
  6251. for (int i = 0; i < nCount; i++)
  6252. {
  6253. CMDMAP *pcm = _GetCmdMapByIndex(i);
  6254. if (pcm)
  6255. {
  6256. // loop through the command mapping structures until we
  6257. // find this guid and id
  6258. if (IsEqualGUID(pcm->guidButtonGroup, *pguidButtonGroup) &&
  6259. id == pcm->nCmdID)
  6260. {
  6261. *pid = _CommandFromIndex(i);
  6262. hres = S_OK;
  6263. break;
  6264. }
  6265. }
  6266. }
  6267. }
  6268. }
  6269. else
  6270. {
  6271. // going from toolbar id to commandtarget info
  6272. CMDMAP *pcm = _GetCmdMapByID(id);
  6273. if (pcm)
  6274. {
  6275. *pguidOut = pcm->guidButtonGroup;
  6276. *pid = pcm->nCmdID;
  6277. hres = S_OK;
  6278. }
  6279. }
  6280. return hres;
  6281. }
  6282. LRESULT CInternetToolbar::_AddBitmapFromForeignModule(UINT uiGetMSG, UINT uiSetMSG, UINT uiCount, HINSTANCE hinst, UINT_PTR nID, COLORREF rgbMask)
  6283. {
  6284. HBITMAP hBMPRaw = NULL, hBMPFixedUp = NULL;
  6285. HBITMAP * phBmp = &hBMPFixedUp;
  6286. BITMAP bmp;
  6287. HIMAGELIST himlTemp;
  6288. LRESULT lRes = 1L;
  6289. BOOL fOk = TRUE;
  6290. HDC dc = NULL, dcMemSrc = NULL, dcMemDest = NULL;
  6291. HBITMAP hbmpOldDest = NULL, hbmpOldSrc = NULL;
  6292. int cxOrg = 0;
  6293. int xDest = 0, yDest = 0;
  6294. RECT rect = {0,0,0,0};
  6295. HBRUSH hbr = NULL;
  6296. // What if hinst == NULL? That means that nID is really an HBITMAP
  6297. ASSERT( hinst != NULL );
  6298. if (!(hBMPRaw = LoadBitmap(hinst, MAKEINTRESOURCE(nID))))
  6299. return 0L;
  6300. fOk = (BOOL)(GetObject(hBMPRaw, sizeof(BITMAP), &bmp) != 0);
  6301. // Check is the size is OK
  6302. if (fOk && (bmp.bmWidth != (LONG)(g_iToolBarLargeIconWidth * uiCount)) || (bmp.bmHeight != (LONG)g_iToolBarLargeIconHeight) )
  6303. {
  6304. int cxBmp;
  6305. int cyBmp;
  6306. if (g_fSmallIcons)
  6307. {
  6308. cxBmp = TB_SMBMP_CX;
  6309. cyBmp = TB_SMBMP_CY;
  6310. }
  6311. else
  6312. {
  6313. cxBmp = g_iToolBarLargeIconWidth;
  6314. cyBmp = g_iToolBarLargeIconHeight;
  6315. }
  6316. // If the height is 15, the we assume that this is one of the old bitmaps therefore
  6317. // the width is 16. We cannot rely on the (bmp.bmWidth / uiCount) because some apps
  6318. // like SecureFile give us a bitmap 192 wide and say that there are 10 glyphs in it.
  6319. if (bmp.bmHeight == 15)
  6320. cxOrg = 16;
  6321. else
  6322. cxOrg = bmp.bmWidth / (uiCount ? uiCount : 1);
  6323. if (rgbMask)
  6324. fOk = (BOOL)((hbr = CreateSolidBrush(rgbMask))!= NULL);
  6325. if (fOk)
  6326. fOk = (BOOL)((dc = GetDC(_btb._hwnd)) != NULL);
  6327. if (fOk)
  6328. fOk = (BOOL)((hBMPFixedUp = CreateCompatibleBitmap(dc, (cxBmp * uiCount), cyBmp)) != NULL);
  6329. if (fOk)
  6330. fOk = (BOOL)((dcMemSrc = CreateCompatibleDC(dc)) != NULL);
  6331. if (fOk)
  6332. fOk = (BOOL)((dcMemDest = CreateCompatibleDC(dc)) != NULL);
  6333. if (!fOk)
  6334. goto Error;
  6335. hbmpOldSrc = (HBITMAP)SelectObject(dcMemSrc, hBMPRaw);
  6336. hbmpOldDest = (HBITMAP)SelectObject(dcMemDest, hBMPFixedUp);
  6337. rect.right = (cxBmp * uiCount);
  6338. rect.bottom = cyBmp;
  6339. if (rgbMask)
  6340. FillRect(dcMemDest, &rect, hbr);
  6341. for (UINT n = 0; n < uiCount; n++)
  6342. {
  6343. int cxCopy;
  6344. int cyCopy;
  6345. xDest = (n * cxBmp);
  6346. if (cxOrg < cxBmp)
  6347. {
  6348. // if the bitmap is too small, we need to center it.
  6349. // the amount we copy is the full bitmap
  6350. cxCopy = cxOrg;
  6351. xDest += ((cxBmp - cxOrg) / 2);
  6352. }
  6353. else
  6354. {
  6355. // if the bitmap is big enough, we align it to top left and
  6356. // we strecth(shrink) it down to fit
  6357. cxCopy = cxBmp;
  6358. }
  6359. if (bmp.bmHeight < cyBmp)
  6360. {
  6361. cyCopy = bmp.bmHeight;
  6362. yDest = ((cyBmp - bmp.bmHeight) / 2);
  6363. }
  6364. else
  6365. {
  6366. cyCopy = cyBmp;
  6367. yDest = 0;
  6368. }
  6369. StretchBlt(dcMemDest, xDest, yDest, cxOrg, bmp.bmHeight,
  6370. dcMemSrc, (cxOrg * n), 0, cxCopy, cyCopy, SRCCOPY);
  6371. }
  6372. SelectObject(dcMemDest, hbmpOldDest);
  6373. SelectObject(dcMemSrc, hbmpOldSrc);
  6374. }
  6375. else
  6376. phBmp = &hBMPRaw;
  6377. if (!(himlTemp = (HIMAGELIST)SendMessage(_btb._hwnd, uiGetMSG, 0, 0L)))
  6378. {
  6379. TraceMsg(DM_ERROR, "CITBar::_AddBitmapFromForeignModule Failed - uiGetMSG SendMessage Failure");
  6380. fOk = FALSE;
  6381. goto Error;
  6382. }
  6383. if (rgbMask)
  6384. lRes = ImageList_AddMasked(himlTemp, (HBITMAP)*phBmp, rgbMask);
  6385. else
  6386. lRes = ImageList_Add(himlTemp, (HBITMAP)*phBmp, NULL);
  6387. if (lRes == -1)
  6388. {
  6389. TraceMsg(DM_ERROR, "CITBar::_AddBitmapFromForeignModule Failed - lRes == -1");
  6390. fOk = FALSE;
  6391. goto Error;
  6392. }
  6393. if (!SendMessage(_btb._hwnd, uiSetMSG, 0, (LPARAM)himlTemp))
  6394. {
  6395. TraceMsg(DM_ERROR, "CITBar::_AddBitmapFromForeignModule Failed - uiSetMSG SendMessage Failed");
  6396. fOk = FALSE;
  6397. goto Error;
  6398. }
  6399. Error:
  6400. if (hBMPFixedUp)
  6401. DeleteObject(hBMPFixedUp);
  6402. if (hBMPRaw)
  6403. DeleteObject(hBMPRaw);
  6404. if (dc)
  6405. ReleaseDC(_btb._hwnd, dc);
  6406. if (dcMemSrc)
  6407. DeleteDC(dcMemSrc);
  6408. if (dcMemDest)
  6409. DeleteDC(dcMemDest);
  6410. if (hbr)
  6411. DeleteObject(hbr);
  6412. if (!fOk)
  6413. lRes = 0L;
  6414. return lRes;
  6415. }
  6416. #define VERY_HIGH_NUMBER 4000
  6417. HRESULT CInternetToolbar::_LoadDefaultSettings()
  6418. {
  6419. memset(&_cs, 0, sizeof(COOLBARSAVE));
  6420. _cs.cbVer = CBS_VERSION;
  6421. _cs.bs[0].wID = CBIDX_MENU;
  6422. _cs.bs[0].cx = VERY_HIGH_NUMBER;
  6423. _cs.bs[1].wID = CBIDX_BRAND;
  6424. _cs.bs[2].wID = CBIDX_TOOLS;
  6425. _cs.bs[2].cx = VERY_HIGH_NUMBER;
  6426. _cs.bs[2].fStyle = RBBS_BREAK;
  6427. _cs.bs[3].wID = CBIDX_ADDRESS;
  6428. _cs.bs[3].cx = VERY_HIGH_NUMBER;
  6429. _cs.bs[3].fStyle = RBBS_BREAK;
  6430. _cs.bs[4].wID = CBIDX_LINKS;
  6431. if (!_fInitialPidlIsWeb)
  6432. {
  6433. // we're in shell view, or we're rooted. for perf, don't bother creating the links band.
  6434. if (IsOS(OS_WHISTLERORGREATER) && (IsOS(OS_PERSONAL)))
  6435. {
  6436. _cs.uiVisible = (VBF_MENU | VBF_TOOLS | VBF_BRAND);
  6437. }
  6438. else
  6439. {
  6440. _cs.uiVisible = (VBF_MENU | VBF_TOOLS | VBF_ADDRESS | VBF_BRAND);
  6441. }
  6442. }
  6443. else
  6444. {
  6445. // web page
  6446. _cs.uiVisible = (VBF_MENU | VBF_TOOLS | VBF_ADDRESS | VBF_LINKS | VBF_BRAND);
  6447. }
  6448. _cs.clsidVerticalBar = GUID_NULL;
  6449. _cs.clsidHorizontalBar = GUID_NULL;
  6450. _cs.fNoText = FALSE;
  6451. _cs.fList = DEFAULT_LIST_VALUE();
  6452. _fUsingDefaultBands = TRUE;
  6453. return(NOERROR);
  6454. }
  6455. typedef struct tagCOOLBARSAVEv12 // IE4
  6456. {
  6457. UINT cbVer;
  6458. UINT uiMaxTBWidth;
  6459. UINT uiMaxQLWidth;
  6460. #ifdef UNIX
  6461. BITBOOL fUnUsed : 28; // unused
  6462. #endif
  6463. BOOL fVertical : 1; // The bar is oriented vertically
  6464. BOOL fNoText :1; // "NoText"
  6465. BOOL fAutoHide : 1; // Auto hide toolbar in theater mode
  6466. BOOL fStatusBar : 1; // Status bar in theater mode
  6467. BOOL fSaveInShellIntegrationMode : 1; // Did we save in shell
  6468. UINT uiVisible; // "Visible bands"
  6469. UINT cyRebar;
  6470. BANDSAVE bs[5];
  6471. } COOLBARSAVEv12;
  6472. typedef struct tagCOOLBARSAVEv15 // IE5 Beta2
  6473. {
  6474. UINT cbVer;
  6475. UINT uiMaxTBWidth;
  6476. UINT uiMaxQLWidth;
  6477. #ifdef UNIX
  6478. BITBOOL fUnUsed : 28; // unused
  6479. #endif
  6480. BITBOOL fVertical : 1; // The bar is oriented vertically
  6481. BITBOOL fNoText :1; // "NoText"
  6482. BITBOOL fList : 1; // toolbar is TBSTYLE_LIST (text on right) + TBSTYLE_EX_MIXEDBUTTONS
  6483. BITBOOL fAutoHide : 1; // Auto hide toolbar in theater mode
  6484. BITBOOL fStatusBar : 1; // Status bar in theater mode
  6485. BITBOOL fSaveInShellIntegrationMode : 1; // Did we save in shell integration mode?
  6486. UINT uiVisible; // "Visible bands"
  6487. UINT cyRebar;
  6488. BANDSAVE bs[5];
  6489. CLSID clsidVerticalBar; //clsid of bar persisted within vertical band
  6490. CLSID clsidHorizontalBar;
  6491. } COOLBARSAVEv15;
  6492. #define CB_V12 (sizeof(COOLBARSAVEv12))
  6493. #define CB_V13 (sizeof(COOLBARSAVEv15))
  6494. #define CB_V14 CB_V13 // 14: added fList:1 (in middle!)
  6495. #define CB_V15 CB_V14 // 15: new rbbi.fStyle semantics
  6496. #define CB_V17 (sizeof(COOLBARSAVE))
  6497. HRESULT CInternetToolbar::_LoadUpgradeSettings(ULONG cbRead)
  6498. {
  6499. // If we shipped with the CBS_VERSION you're incrementing, you need
  6500. // to add upgrade code here for that version, then update this assertion.
  6501. COMPILETIME_ASSERT(CBS_VERSION == 17);
  6502. // Double-check our size calculations.
  6503. #ifndef UNIX
  6504. COMPILETIME_ASSERT(CB_V12 == (6 * sizeof(UINT) + CBIDX_LAST * sizeof(BANDSAVE)));
  6505. #endif
  6506. COMPILETIME_ASSERT(CB_V12 == (CB_V15 - sizeof(CLSID) * 2));
  6507. COMPILETIME_ASSERT(CB_V13 == (CB_V12 + 2 * sizeof(CLSID)));
  6508. COMPILETIME_ASSERT(CB_V14 == (CB_V13 + 0));
  6509. COMPILETIME_ASSERT(CB_V15 == (CB_V14 + 0));
  6510. COMPILETIME_ASSERT(CB_V17 == (CB_V15 + (MAXEXTERNALBANDS * sizeof(BANDSAVE)) + (MAXEXTERNALBANDS * sizeof(CLSID))));
  6511. // If the stream was shorter than the version data field, there's nothing we can do.
  6512. if (cbRead < sizeof(_cs.cbVer))
  6513. {
  6514. return E_FAIL;
  6515. }
  6516. // Check to see if the version is one we know about and that the stream
  6517. // size is the same as that version's structure size.
  6518. if (!((_cs.cbVer == 12 && cbRead == CB_V12) || // IE4
  6519. (_cs.cbVer == 13 && cbRead == CB_V13) || // ?
  6520. (_cs.cbVer == 14 && cbRead == CB_V14) || // ?
  6521. (_cs.cbVer == 15 && cbRead == CB_V15))) // IE5 Beta2
  6522. {
  6523. return E_FAIL;
  6524. }
  6525. TraceMsg(DM_WARNING, "citb._lus: try upgrade %d->%d", _cs.cbVer, CBS_VERSION);
  6526. // Make a scratch copy of _cs so we don't worry about overwriting
  6527. // parts of _cs we need to read later.
  6528. COOLBARSAVE cs = _cs;
  6529. if (_cs.cbVer == 12)
  6530. {
  6531. // clsidVerticalBar/clsidHorizontalBar weren't a part
  6532. // of the structure until v13
  6533. cs.clsidVerticalBar = GUID_NULL;
  6534. cs.clsidHorizontalBar = GUID_NULL;
  6535. }
  6536. else
  6537. {
  6538. ASSERT(_cs.cbVer < 16);
  6539. // Band array (bs) grew in v16 to include external bands, so
  6540. // clsidVerticalBar/clsidHorizontalBar were at a different offset.
  6541. COOLBARSAVEv15 *pv15 = (COOLBARSAVEv15 *) &_cs;
  6542. cs.clsidVerticalBar = pv15->clsidVerticalBar;
  6543. cs.clsidHorizontalBar = pv15->clsidHorizontalBar;
  6544. cs.bs[CBIDX_LAST].wID = 0xFFFFFFFF;
  6545. }
  6546. if (InRange(_cs.cbVer, 12, 13))
  6547. {
  6548. // fList was inserted into the middle of the bitbool list in v14.
  6549. // Copy the displaced bitbools and initialize fList.
  6550. COOLBARSAVEv12 *pv12 = (COOLBARSAVEv12 *) &_cs;
  6551. cs.fAutoHide = pv12->fAutoHide;
  6552. cs.fStatusBar = pv12->fStatusBar;
  6553. cs.fSaveInShellIntegrationMode = pv12->fSaveInShellIntegrationMode;
  6554. cs.fList = DEFAULT_LIST_VALUE();
  6555. }
  6556. // Force FALSE as no longer support vertical itbar mode.
  6557. cs.fVertical = FALSE;
  6558. // Strip off any invalid visible band bits
  6559. cs.uiVisible &= VBF_VALID;
  6560. // Set current version and copy scratch cs back to _cs
  6561. cs.cbVer = CBS_VERSION;
  6562. _cs = cs;
  6563. return S_OK;
  6564. }
  6565. HRESULT CInternetToolbar::_LoadDefaultWidths()
  6566. {
  6567. // If there was no max width set for the QL bar or the Toolbar, then
  6568. // before we use the default, check it the localization people wanted to
  6569. // increase the width. The RC file string range from '0' to '9'
  6570. TCHAR szScratch[16];
  6571. UINT uiExtraWidth = 0;
  6572. if (GetSystemMetrics(SM_CXSCREEN) < 650)
  6573. {
  6574. MLLoadString(IDS_TB_WIDTH_EXTRA_LORES, szScratch, ARRAYSIZE(szScratch));
  6575. _uiMaxTBWidth = MAX_TB_WIDTH_LORES;
  6576. }
  6577. else
  6578. {
  6579. MLLoadString(IDS_TB_WIDTH_EXTRA_HIRES, szScratch, ARRAYSIZE(szScratch));
  6580. _uiMaxTBWidth = MAX_TB_WIDTH_HIRES;
  6581. }
  6582. _uiMaxTBWidth += StrToInt(szScratch) * WIDTH_FACTOR;
  6583. return(NOERROR);
  6584. }
  6585. BOOL IsClsidInHKCR(REFGUID pclsid)
  6586. {
  6587. HKEY hkeyResult;
  6588. if (SHRegGetCLSIDKeyW(pclsid, NULL, FALSE, FALSE, &hkeyResult) == ERROR_SUCCESS)
  6589. {
  6590. RegCloseKey(hkeyResult);
  6591. return TRUE;
  6592. }
  6593. return FALSE;
  6594. }
  6595. typedef struct tagCOOLBARSAVEv2 // IE3
  6596. {
  6597. UINT cbVer;
  6598. UINT uiMaxTBWidth;
  6599. UINT uiMaxQLWidth;
  6600. BOOL fVertical; // The bar is oriented vertically
  6601. BANDSAVE bs[4];
  6602. } COOLBARSAVEv2;
  6603. #define VBF_VALIDv2 (VBF_TOOLS | VBF_ADDRESS | VBF_LINKS)
  6604. void CInternetToolbar::_TryLoadIE3Settings()
  6605. {
  6606. HKEY hKey;
  6607. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, c_szRegKeyCoolbar, 0, KEY_QUERY_VALUE, &hKey))
  6608. {
  6609. COOLBARSAVEv2 cbv2;
  6610. DWORD dwcbData = sizeof(cbv2);
  6611. if (SHQueryValueEx(hKey, TEXT("Layout"), NULL, NULL, (LPBYTE)&cbv2, &dwcbData) == ERROR_SUCCESS)
  6612. {
  6613. _cs.uiMaxTBWidth = cbv2.uiMaxTBWidth;
  6614. _cs.uiMaxQLWidth = cbv2.uiMaxQLWidth;
  6615. // FEATURE: todo -- read in bs field too; need to do some conversions as
  6616. // CBIDX_ numbers were zero-based and there was no menuband in IE3.
  6617. }
  6618. BOOL fNoText;
  6619. dwcbData = sizeof(fNoText);
  6620. if (SHQueryValueEx(hKey, TEXT("NoText"), NULL, NULL, (LPBYTE)&fNoText, &dwcbData) == ERROR_SUCCESS)
  6621. {
  6622. // Set the no-text flag.
  6623. _cs.fNoText = BOOLIFY(fNoText);
  6624. }
  6625. UINT uiVisible;
  6626. dwcbData = sizeof(uiVisible);
  6627. if (SHQueryValueEx(hKey, TEXT("VisibleBands"), NULL, NULL, (LPBYTE)&uiVisible, &dwcbData) == ERROR_SUCCESS)
  6628. {
  6629. // Set the visible bands, changing only the ones that IE3 knew about.
  6630. _cs.uiVisible = (_cs.uiVisible &~ VBF_VALIDv2) | (uiVisible & VBF_VALIDv2);
  6631. }
  6632. RegCloseKey(hKey);
  6633. }
  6634. }
  6635. VOID CInternetToolbar::_UpdateLocking()
  6636. {
  6637. // if we have no gripper then turn them off
  6638. BANDSITEINFO bsinfo;
  6639. bsinfo.dwMask = BSIM_STYLE;
  6640. bsinfo.dwStyle = BSIS_LEFTALIGN | (_fLockedToolbar ? BSIS_NOGRIPPER : 0);
  6641. _bs.SetBandSiteInfo(&bsinfo);
  6642. _bs._UpdateAllBands(FALSE, TRUE);
  6643. ResizeBorderDW(NULL, NULL, FALSE);
  6644. }
  6645. HRESULT CInternetToolbar::Load(IStream *pstm)
  6646. {
  6647. ULONG ulRead;
  6648. //Read from the given stream and initialize the Toolbar data!
  6649. _fLoading = TRUE;
  6650. HRESULT hr = pstm->Read(&_cs, sizeof(COOLBARSAVE), &ulRead);
  6651. if (SUCCEEDED(hr))
  6652. {
  6653. if (ulRead != sizeof(COOLBARSAVE) || _cs.cbVer != CBS_VERSION)
  6654. {
  6655. hr = _LoadUpgradeSettings(ulRead);
  6656. }
  6657. }
  6658. if (FAILED(hr))
  6659. {
  6660. _LoadDefaultSettings();
  6661. }
  6662. ASSERT(_cs.uiVisible & VBF_MENU);
  6663. // make sure that the settings include a menu
  6664. _cs.uiVisible |= VBF_MENU;
  6665. _LoadDefaultWidths();
  6666. hr = _CreateBands();
  6667. _UpdateLocking();
  6668. //if in web view, show the last visible browser bars too
  6669. if (!_fShellView)
  6670. {
  6671. VARIANT varOut = {0};
  6672. varOut.vt = VT_I4;
  6673. if (!IsEqualGUID(_cs.clsidVerticalBar, GUID_NULL) && IsClsidInHKCR(_cs.clsidVerticalBar))
  6674. {
  6675. BOOL fSearch = IsEqualGUID(_cs.clsidVerticalBar, CLSID_SearchBand)
  6676. || IsEqualGUID(_cs.clsidVerticalBar, CLSID_FileSearchBand);
  6677. WCHAR wsz[GUIDSTR_MAX];
  6678. SHStringFromGUID((const CLSID)_cs.clsidVerticalBar, wsz, ARRAYSIZE(wsz));
  6679. #ifdef UNIX
  6680. // IEUNIX: Donot persist/load MsgBand
  6681. if (!IsEqualGUID(_cs.clsidVerticalBar, CLSID_MsgBand))
  6682. #endif
  6683. {
  6684. if (!fSearch)
  6685. {
  6686. VARIANT varClsid;
  6687. varClsid.vt = VT_BSTR;
  6688. varClsid.bstrVal = wsz;
  6689. IUnknown_Exec(_pbs2, &CGID_ShellDocView, SHDVID_SHOWBROWSERBAR, 1, &varClsid, &varOut);
  6690. }
  6691. else
  6692. {
  6693. // if it's the search band, must be shown in this way to get correct search
  6694. VARIANTARG var;
  6695. var.vt = VT_I4;
  6696. var.lVal = -1;
  6697. Exec(&CLSID_CommonButtons, TBIDM_SEARCH, 0, NULL, &var);
  6698. }
  6699. }
  6700. }
  6701. if (!IsEqualGUID(_cs.clsidHorizontalBar, GUID_NULL) && IsClsidInHKCR(_cs.clsidHorizontalBar))
  6702. {
  6703. WCHAR wsz[GUIDSTR_MAX];
  6704. SHStringFromGUID((const CLSID)_cs.clsidHorizontalBar, wsz, ARRAYSIZE(wsz));
  6705. VARIANT varClsid;
  6706. varClsid.vt = VT_BSTR;
  6707. varClsid.bstrVal = wsz;
  6708. IUnknown_Exec(_pbs2, &CGID_ShellDocView, SHDVID_SHOWBROWSERBAR, 1, &varClsid, &varOut);
  6709. }
  6710. }
  6711. _fLoading = FALSE;
  6712. return hr;
  6713. }
  6714. //see APPHACK note below
  6715. const GUID CLSID_AlexaVert = { 0xBA0B386CL, 0x7143, 0x11d1, 0xba, 0x8c, 0x00, 0x60, 0x08, 0x27, 0x87, 0x8d };
  6716. const GUID CLSID_AlexaHorz = { 0xBA0B386EL, 0x7143, 0x11d1, 0xba, 0x8c, 0x00, 0x60, 0x08, 0x27, 0x87, 0x8d };
  6717. void CInternetToolbar::_GetVisibleBrowserBar(UINT idBar, CLSID *pclsidOut)
  6718. {
  6719. *pclsidOut = GUID_NULL;
  6720. ASSERT(idBar == IDBAR_VERTICAL || idBar == IDBAR_HORIZONTAL);
  6721. IDockingWindowFrame *psb;
  6722. if (_psp && SUCCEEDED(_psp->QueryService(SID_STopLevelBrowser, IID_PPV_ARG(IDockingWindowFrame, &psb))))
  6723. {
  6724. IDeskBar* pdb;
  6725. if ( (IDBAR_VERTICAL == idBar && (SUCCEEDED(psb->FindToolbar(INFOBAR_TBNAME, IID_PPV_ARG(IDeskBar, &pdb))) && pdb)) ||
  6726. (IDBAR_HORIZONTAL == idBar && (SUCCEEDED(psb->FindToolbar(COMMBAR_TBNAME, IID_PPV_ARG(IDeskBar, &pdb))) && pdb)) )
  6727. {
  6728. VARIANT varClsid = {0};
  6729. if (SUCCEEDED(IUnknown_Exec(pdb, &CGID_DeskBarClient, DBCID_CLSIDOFBAR, 1, NULL, &varClsid)))
  6730. {
  6731. if (varClsid.vt == VT_BSTR)
  6732. {
  6733. GUIDFromString(varClsid.bstrVal, pclsidOut);
  6734. VariantClear(&varClsid);
  6735. }
  6736. //APPHACK
  6737. // Alexa 3.0 has some code so that their explorer bar persists that works in ie4. however, when ie5
  6738. // persists them, they don't handle the case where the main page has not finished loading yet, which
  6739. // causes them to fault on launch of the browser. see IE5 55895.
  6740. if ( (IDBAR_VERTICAL == idBar && (IsEqualGUID(*pclsidOut, CLSID_AlexaVert))) ||
  6741. (IDBAR_HORIZONTAL == idBar && (IsEqualGUID(*pclsidOut, CLSID_AlexaHorz))) )
  6742. {
  6743. *pclsidOut = GUID_NULL;
  6744. }
  6745. //END APPHACK
  6746. }
  6747. pdb->Release();
  6748. }
  6749. psb->Release();
  6750. }
  6751. }
  6752. void CInternetToolbar::_BuildSaveStruct(COOLBARSAVE* pcs)
  6753. {
  6754. REBARBANDINFO rbbi;
  6755. RECT rc;
  6756. static BOOL fBrowserOnly = (WhichPlatform() != PLATFORM_INTEGRATED);
  6757. //Save into the given stream!
  6758. memset(pcs, 0, sizeof(COOLBARSAVE));
  6759. pcs->cbVer = CBS_VERSION;
  6760. // Browser Only can't load Shell Integrated streams because of the Favorites
  6761. // shell extension created pidls unreadable by browser only which doesn't have the Favorites ShellExt
  6762. pcs->fSaveInShellIntegrationMode = !fBrowserOnly;
  6763. GetWindowRect(_bs._hwnd, &rc);
  6764. pcs->cyRebar = RECTHEIGHT(rc);
  6765. //Save the new fields.
  6766. pcs->fAutoHide = _fAutoHide;
  6767. pcs->fNoText = _fCompressed;
  6768. pcs->fList = IS_LIST_STYLE(_btb._hwnd);
  6769. pcs->uiVisible = _nVisibleBands;
  6770. //only persist the visible bars for web view
  6771. if (!_fShellView)
  6772. {
  6773. _GetVisibleBrowserBar(IDBAR_VERTICAL, &pcs->clsidVerticalBar);
  6774. _GetVisibleBrowserBar(IDBAR_HORIZONTAL, &pcs->clsidHorizontalBar);
  6775. }
  6776. //else pcs->clsid*Bar nulled out by memset above
  6777. LRESULT lStyle = GetWindowLong(_bs._hwnd, GWL_STYLE);
  6778. pcs->fVertical = BOOLIFY(lStyle & CCS_VERT);
  6779. pcs->uiMaxTBWidth = _uiMaxTBWidth;
  6780. rbbi.cbSize = sizeof(REBARBANDINFO);
  6781. rbbi.fMask = RBBIM_STYLE | RBBIM_SIZE | RBBIM_ID;
  6782. int icBands = (int) SendMessage( _bs._hwnd, RB_GETBANDCOUNT, 0, 0 );
  6783. for (int i = 0; i < icBands; i++)
  6784. {
  6785. pcs->bs[i].wID = 0xFFFFFFFF;
  6786. if (SendMessage(_bs._hwnd, RB_GETBANDINFO, i, (LPARAM) &rbbi))
  6787. {
  6788. if (rbbi.wID < CBANDSMAX)
  6789. {
  6790. // desk band objects have the choice of not saving there visibility
  6791. // state
  6792. BANDITEMDATA *pbid = _bs._GetBandItem( i );
  6793. UINT uiMask = rbbi.wID <= CBIDX_LAST ? ( 1 << (rbbi.wID - 1) ) : EXTERNALBAND_VBF_BIT(rbbi.wID - CBIDX_LAST-1);
  6794. if (pbid && pbid->pdb && (pcs->uiVisible & uiMask))
  6795. {
  6796. OLECMD cmd;
  6797. cmd.cmdID = CITIDM_DISABLEVISIBILITYSAVE;
  6798. cmd.cmdf = 0;
  6799. IUnknown_QueryStatus( pbid->pdb, &CGID_PrivCITCommands, 1, &cmd, NULL );
  6800. if ( cmd.cmdf & OLECMDF_ENABLED )
  6801. {
  6802. pcs->uiVisible &= ~uiMask;
  6803. rbbi.fStyle |= RBBS_HIDDEN;
  6804. }
  6805. }
  6806. pcs->bs[i].fStyle = rbbi.fStyle;
  6807. pcs->bs[i].cx = rbbi.cx;
  6808. pcs->bs[i].wID = rbbi.wID;
  6809. if (IS_EXTERNALBAND(rbbi.wID))
  6810. {
  6811. pcs->aclsidExternalBands[MAP_TO_EXTERNAL(rbbi.wID)] = _rgebi[MAP_TO_EXTERNAL(rbbi.wID)].clsid;
  6812. }
  6813. }
  6814. }
  6815. }
  6816. // Query CShellBrowser for status bar state
  6817. VARIANTARG v = { 0 };
  6818. v.vt = VT_I4;
  6819. IUnknown_Exec(_ptbsite, &CGID_ShellBrowser, FCIDM_GETSTATUSBAR,
  6820. 0, NULL, &v);
  6821. pcs->fStatusBar = v.lVal;
  6822. }
  6823. typedef struct tagCLSID_BANDTYPE
  6824. {
  6825. const CLSID * pclsid;
  6826. DWORD dwBandID;
  6827. } CLSID_BANDTYPE;
  6828. CLSID_BANDTYPE c_CLSIDsToSave[] =
  6829. {
  6830. {&CLSID_AddressBand, CBIDX_ADDRESS},
  6831. {&CLSID_QuickLinks, CBIDX_LINKS},
  6832. };
  6833. HRESULT CInternetToolbar::Save(IStream *pstm, BOOL fClearDirty)
  6834. {
  6835. COOLBARSAVE cs;
  6836. HRESULT hr = S_FALSE;
  6837. // avoid the hit of saving when we are still loading. State will not have
  6838. // changed, at least not enough to justify saving, until after we are loaded.
  6839. if (_fLoading)
  6840. return S_OK;
  6841. // Check the dirty bit to see if we need to save.
  6842. if (!_fDirty)
  6843. return S_OK;
  6844. // if we failed during creation, our current state isnt good enough to persist.
  6845. if (_fDontSave)
  6846. return S_OK;
  6847. ASSERT(!_fTheater);
  6848. _BuildSaveStruct(&cs);
  6849. if(SUCCEEDED(hr = pstm->Write(&cs, sizeof(COOLBARSAVE), NULL)) && fClearDirty)
  6850. _fDirty = FALSE;
  6851. REBARBANDINFO rbbi;
  6852. rbbi.cbSize = sizeof(REBARBANDINFO);
  6853. rbbi.fMask = RBBIM_ID;
  6854. int icBands = (int) SendMessage( _bs._hwnd, RB_GETBANDCOUNT, 0, 0 );
  6855. for (int i = 0; i < icBands; i++)
  6856. {
  6857. if (SendMessage(_bs._hwnd, RB_GETBANDINFO, i, (LPARAM) &rbbi))
  6858. {
  6859. if ((rbbi.wID == CBIDX_ADDRESS) || (rbbi.wID == CBIDX_LINKS) || IS_EXTERNALBAND(rbbi.wID))
  6860. {
  6861. BANDITEMDATA *pbid = _bs._GetBandItem( i );
  6862. if (pbid && pbid->pdb)
  6863. {
  6864. CLSID clsid;
  6865. IPersistStream *pStream;
  6866. if (SUCCEEDED(pbid->pdb->QueryInterface(IID_PPV_ARG(IPersistStream, &pStream))))
  6867. {
  6868. pStream->GetClassID( &clsid );
  6869. IStream * pstm;
  6870. TCHAR szGUID[MAX_PATH];
  6871. SHStringFromGUID( clsid, szGUID, ARRAYSIZE(szGUID) );
  6872. pstm = GetRegStream( _fInitialPidlIsWeb, szGUID, STGM_WRITE | STGM_CREATE );
  6873. if (pstm)
  6874. {
  6875. HRESULT hrInternal = _bs.SaveToStreamBS(pbid->pdb, pstm);
  6876. // Only return Success values
  6877. if (SUCCEEDED(hrInternal))
  6878. hr = S_OK;
  6879. pstm->Release();
  6880. }
  6881. pStream->Release();
  6882. }
  6883. }
  6884. }
  6885. }
  6886. }
  6887. return(hr);
  6888. }
  6889. HRESULT CInternetToolbar::InitNew(void)
  6890. {
  6891. // This shouldn't get called if Load has already been called, so assert
  6892. // that _cs is uninitialized.
  6893. ASSERT(_cs.cbVer == 0);
  6894. _LoadDefaultSettings();
  6895. // Look for any IE3 settings and override defaults with those. (IE3
  6896. // wrote structures directly to registry, rather than via IPersistStream).
  6897. _TryLoadIE3Settings();
  6898. _LoadDefaultWidths();
  6899. return S_OK;
  6900. }
  6901. BOOL CInternetToolbar::_SendToToolband(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plres)
  6902. {
  6903. return _bs._SendToToolband(hwnd, uMsg, wParam, lParam, plres);
  6904. }
  6905. HRESULT CInternetToolbar::IsDirty(void)
  6906. {
  6907. if (_fDirty && !_fLoading)
  6908. return S_OK;
  6909. else
  6910. return S_FALSE;
  6911. }
  6912. HRESULT CInternetToolbar::QueryService(REFGUID guidService,
  6913. REFIID riid, void **ppvObj)
  6914. {
  6915. HRESULT hres = E_NOTIMPL;
  6916. if (IsEqualIID(guidService, SID_IBandProxy))
  6917. {
  6918. hres = QueryService_SID_IBandProxy(SAFECAST(_ptbsitect, IUnknown *), riid, &_pbp, ppvObj);
  6919. if(!_pbp)
  6920. {
  6921. // We need to create it ourselves since our parent couldn't help
  6922. ASSERT(FALSE == _fCreatedBandProxy);
  6923. hres = CreateIBandProxyAndSetSite(SAFECAST(_ptbsitect, IUnknown *), riid, &_pbp, ppvObj);
  6924. if(_pbp)
  6925. {
  6926. ASSERT(S_OK == hres);
  6927. _fCreatedBandProxy = TRUE;
  6928. }
  6929. }
  6930. return hres;
  6931. }
  6932. else if (IsEqualGUID(guidService, IID_IBandSite))
  6933. {
  6934. return _bs.QueryInterface(riid, ppvObj);
  6935. }
  6936. else if (IsEqualGUID(guidService, IID_IAddressBand))
  6937. {
  6938. LPBANDITEMDATA pbid = _bs._GetBandItemDataStructByID(CBIDX_ADDRESS);
  6939. if (pbid && pbid->pdb)
  6940. {
  6941. return pbid->pdb->QueryInterface(riid, ppvObj);
  6942. }
  6943. else
  6944. {
  6945. *ppvObj = NULL;
  6946. return E_FAIL;
  6947. }
  6948. }
  6949. if (_psp)
  6950. return _psp->QueryService(guidService, riid, ppvObj);
  6951. return SUPERCLASS::QueryService(guidService, riid, ppvObj);
  6952. }
  6953. //
  6954. // FEATURE: Do we really need to implement the following two functions?
  6955. // Currently nobody uses them.
  6956. //
  6957. HRESULT CInternetToolbar::GetClassID(GUID *pguid)
  6958. {
  6959. *pguid = CLSID_InternetToolbar;
  6960. return(S_OK);
  6961. }
  6962. HRESULT CInternetToolbar::GetSizeMax(ULARGE_INTEGER *ulMaxSize)
  6963. {
  6964. ulMaxSize->LowPart = sizeof(COOLBARSAVE);
  6965. ulMaxSize->HighPart = 0;
  6966. return(S_OK);
  6967. }
  6968. CInternetToolbar::CITBandSite::CITBandSite() : CBandSite(NULL)
  6969. {
  6970. // HACKHACK: set the initial band ID to something bigger
  6971. // than the number of toolbars that is in this
  6972. // object. Currently those toolbars are not
  6973. // individual bands, but we want CBandSite to
  6974. // at least be aware of them.
  6975. //
  6976. _dwBandIDNext = CBANDSMAX;
  6977. }
  6978. HRESULT CInternetToolbar::CITBandSite::_OnContextMenu(WPARAM wParam, LPARAM lParam)
  6979. {
  6980. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _bs, this);
  6981. pitbar->_ShowContextMenu((HWND)wParam, lParam, NULL);
  6982. return S_OK;
  6983. }
  6984. HRESULT CInternetToolbar::CITBandSite::_Initialize(HWND hwndParent)
  6985. {
  6986. _hwnd = CreateWindowEx(WS_EX_TOOLWINDOW, REBARCLASSNAME, NULL,
  6987. RBS_VARHEIGHT | RBS_BANDBORDERS | RBS_REGISTERDROP | RBS_DBLCLKTOGGLE |
  6988. WS_VISIBLE | WS_BORDER | WS_CHILD | WS_CLIPCHILDREN |
  6989. // WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN |
  6990. WS_CLIPSIBLINGS | CCS_NODIVIDER | CCS_NOPARENTALIGN,
  6991. 0, 0, 100, 36, hwndParent, (HMENU) FCIDM_REBAR, HINST_THISDLL, NULL);
  6992. if (_hwnd)
  6993. {
  6994. Comctl32_SetWindowTheme(_hwnd, TEXT("ExplorerToolbar"));
  6995. SendMessage(_hwnd, RB_SETTEXTCOLOR, 0, CLR_DEFAULT);
  6996. SendMessage(_hwnd, RB_SETBKCOLOR, 0, CLR_DEFAULT);
  6997. SendMessage(_hwnd, CCM_SETVERSION, COMCTL32_VERSION, 0);
  6998. }
  6999. return CBandSite::_Initialize(hwndParent);
  7000. }
  7001. HRESULT CInternetToolbar::CITBandSite::Exec(const GUID *pguidCmdGroup, DWORD nCmdID,
  7002. DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut)
  7003. {
  7004. if (!pguidCmdGroup)
  7005. {
  7006. /*NOTHING*/
  7007. }
  7008. else if (IsEqualGUID(CGID_PrivCITCommands, *pguidCmdGroup))
  7009. {
  7010. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _bs, this);
  7011. return pitbar->Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvarargIn, pvarargOut);
  7012. }
  7013. else if (IsEqualGUID(CGID_Theater, *pguidCmdGroup))
  7014. {
  7015. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _bs, this);
  7016. return IUnknown_Exec(pitbar->_ptbsite, pguidCmdGroup, nCmdID, nCmdexecopt, pvarargIn, pvarargOut);
  7017. }
  7018. return CBandSite::Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvarargIn, pvarargOut);
  7019. }
  7020. HRESULT CInternetToolbar::CITBandSite::AddBand(IUnknown *punk)
  7021. {
  7022. HRESULT hres = CBandSite::AddBand(punk);
  7023. if (SUCCEEDED(hres))
  7024. {
  7025. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _bs, this);
  7026. pitbar->_SetBackground();
  7027. }
  7028. return hres;
  7029. }
  7030. HRESULT CInternetToolbar::CITBandSite::HasFocusIO()
  7031. {
  7032. HRESULT hres = CBandSite::HasFocusIO();
  7033. if (hres == S_FALSE)
  7034. {
  7035. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _bs, this);
  7036. if (pitbar->_btb._hwnd == GetFocus())
  7037. hres = S_OK;
  7038. }
  7039. return hres;
  7040. }
  7041. // This will remove all the buttons except the first 2
  7042. BOOL TOOLSBANDCLASS::_RemoveAllButtons()
  7043. {
  7044. INT_PTR nCount = SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0L);
  7045. if (!nCount)
  7046. return FALSE;
  7047. while (nCount-- > 0)
  7048. {
  7049. SendMessage(_hwnd, TB_DELETEBUTTON, nCount, 0L);
  7050. }
  7051. return S_OK;
  7052. }
  7053. HRESULT TOOLSBANDCLASS::Exec(const GUID *pguidCmdGroup, DWORD nCmdID,
  7054. DWORD nCmdexecopt, VARIANTARG *pvarargIn, VARIANTARG *pvarargOut)
  7055. {
  7056. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _btb, this);
  7057. if (!pguidCmdGroup)
  7058. {
  7059. /*NOTHING*/
  7060. #ifdef DEBUG
  7061. }
  7062. else if (IsEqualGUID(*pguidCmdGroup, IID_IExplorerToolbar))
  7063. {
  7064. switch(nCmdID)
  7065. {
  7066. case ETCMDID_GETBUTTONS:
  7067. // if this rips call tjgreen
  7068. ASSERT(0);
  7069. return E_FAIL;
  7070. }
  7071. #endif
  7072. }
  7073. else if (_IsDocHostGUID(pguidCmdGroup))
  7074. {
  7075. UEMFireEvent(&UEMIID_BROWSER, UEME_UITOOLBAR, UEMF_XEVENT, UIG_INET, nCmdID);
  7076. if (nCmdexecopt == OLECMDEXECOPT_PROMPTUSER)
  7077. {
  7078. // the user hit the drop down
  7079. if (pitbar->_ptbsitect && pvarargIn && pvarargIn->vt == VT_INT_PTR)
  7080. {
  7081. // v.vt = VT_I4;
  7082. POINT pt;
  7083. RECT* prc = (RECT*)pvarargIn->byref;
  7084. pt.x = prc->left;
  7085. pt.y = prc->bottom;
  7086. switch (nCmdID)
  7087. {
  7088. #ifdef EDIT_HACK
  7089. case DVIDM_EDITPAGE:
  7090. {
  7091. // Show the edit pop-up
  7092. BSTR bstrURL;
  7093. pitbar->_pdie->get_LocationURL(&bstrURL);
  7094. if (bstrURL)
  7095. {
  7096. USES_CONVERSION;
  7097. pitbar->_aEditVerb.ShowEditMenu(pt, pitbar->_hwnd, W2T(bstrURL));
  7098. SysFreeString(bstrURL);
  7099. }
  7100. break;
  7101. }
  7102. #endif
  7103. default:
  7104. // if this rips find tjgreen
  7105. ASSERT(0);
  7106. break;
  7107. }
  7108. }
  7109. return S_OK;
  7110. }
  7111. switch(nCmdID)
  7112. {
  7113. case DVIDM_EDITPAGE:
  7114. {
  7115. BSTR bstrURL;
  7116. ULONG fMask = 0;
  7117. TCHAR szCacheFileName[MAX_PATH + MAX_URL_STRING + 2];
  7118. memset(szCacheFileName, 0, sizeof(szCacheFileName));
  7119. pitbar->_pdie->get_LocationURL(&bstrURL);
  7120. if (NULL == bstrURL)
  7121. break;
  7122. USES_CONVERSION;
  7123. LPCTSTR szURL = W2T(bstrURL);
  7124. #ifdef EDIT_HACK
  7125. // Use the default edit verb
  7126. pitbar->_aEditVerb.Edit(szURL);
  7127. #else
  7128. SHELLEXECUTEINFO sei = {0};
  7129. LPTSTR pszTemp = PathFindExtension(szURL);
  7130. // If we did not find an extension, we assume it is an .htm or .html
  7131. if (*pszTemp != TEXT('.'))
  7132. {
  7133. if (SHVerbExists(TEXT(".htm"), TEXT("edit"), NULL))
  7134. sei.lpClass = TEXT(".htm");
  7135. else
  7136. sei.lpClass = TEXT(".html");
  7137. }
  7138. else
  7139. {
  7140. sei.lpClass = pszTemp;
  7141. }
  7142. if (PathIsURL(szURL))
  7143. {
  7144. // (reinerf)
  7145. // Some apps (FrontPad, Office99, etc) want the URL passed to
  7146. // them instead of the cache filename. We therefore create a string
  7147. // that has the URL name after the null:
  7148. //
  7149. // "CacheFileName/0UrlName"
  7150. //
  7151. // and pass it as the lpFile parameter to shellexecute.
  7152. // We also pass SEE_MASK_FILEANDURL, so shellexecute can
  7153. // recognize this case.
  7154. int iLength;
  7155. URLDownloadToCacheFile(NULL, szURL, szCacheFileName, 0, URLOSTRM_USECACHEDCOPY, NULL);
  7156. iLength = lstrlen(szCacheFileName);
  7157. // copy in the URL name
  7158. StrCpy(&szCacheFileName[iLength + 1], szURL);
  7159. // add the mask so shellexecute knows to check for the URL, if necessary.
  7160. fMask |= SEE_MASK_FILEANDURL;
  7161. }
  7162. else
  7163. {
  7164. StrCpy(szCacheFileName, szURL);
  7165. }
  7166. sei.cbSize = sizeof(SHELLEXECUTEINFO);
  7167. sei.fMask = fMask;
  7168. sei.hwnd = NULL;
  7169. sei.lpVerb = TEXT("edit");
  7170. sei.lpFile = szCacheFileName;
  7171. sei.lpParameters = NULL;
  7172. sei.lpDirectory = NULL;
  7173. sei.nShow = SW_SHOWNORMAL;
  7174. sei.hInstApp = NULL;
  7175. ShellExecuteEx(&sei);
  7176. SysFreeString(bstrURL);
  7177. #endif //!EDIT_HACK
  7178. }
  7179. break;
  7180. default:
  7181. // if this rips call tjgreen
  7182. ASSERT(0);
  7183. break;
  7184. }
  7185. }
  7186. return S_OK;
  7187. }
  7188. // *** IInputObject methods ***
  7189. HRESULT TOOLSBANDCLASS::TranslateAcceleratorIO(LPMSG lpMsg)
  7190. {
  7191. if (SendMessage(_hwnd, TB_TRANSLATEACCELERATOR, 0, (LPARAM)lpMsg))
  7192. return S_OK;
  7193. return CToolBand::TranslateAcceleratorIO(lpMsg);
  7194. }
  7195. // *** IUnknown methods ***
  7196. HRESULT TOOLSBANDCLASS::QueryInterface(REFIID riid, void ** ppvObj)
  7197. {
  7198. static const QITAB qit[] = {
  7199. QITABENT(TOOLSBANDCLASS, IWinEventHandler),
  7200. { 0 },
  7201. };
  7202. HRESULT hres = QISearch(this, qit, riid, ppvObj);
  7203. if (FAILED(hres))
  7204. hres = CToolBand::QueryInterface(riid, ppvObj);
  7205. return hres;
  7206. }
  7207. // *** IDeskBand methods ***
  7208. HRESULT TOOLSBANDCLASS::GetBandInfo(DWORD dwBandID, DWORD fViewMode, DESKBANDINFO* pdbi)
  7209. {
  7210. _dwBandID = dwBandID;
  7211. // set dwModeFlags
  7212. pdbi->dwModeFlags = DBIMF_FIXEDBMP | DBIMF_USECHEVRON;
  7213. // set ptMinSize
  7214. {
  7215. if (SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0))
  7216. {
  7217. // make our min size just big enough to show the first button
  7218. RECT rc;
  7219. SendMessage(_hwnd, TB_GETITEMRECT, 0, (LPARAM)&rc);
  7220. pdbi->ptMinSize.x = RECTWIDTH(rc);
  7221. pdbi->ptMinSize.y = RECTHEIGHT(rc);
  7222. }
  7223. else
  7224. {
  7225. // we don't have any buttons; so use standard button size
  7226. LONG lButtonSize = (long) SendMessage(_hwnd, TB_GETBUTTONSIZE, 0, 0);
  7227. pdbi->ptMinSize.x = LOWORD(lButtonSize);
  7228. pdbi->ptMinSize.y = HIWORD(lButtonSize);
  7229. }
  7230. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _btb, this);
  7231. if (pitbar->_fTheater && (pdbi->ptMinSize.y < (THEATER_CYTOOLBAR - 1)))
  7232. pdbi->ptMinSize.y = (THEATER_CYTOOLBAR - 1);
  7233. }
  7234. // set ptActual
  7235. {
  7236. SIZE size;
  7237. size.cy = pdbi->ptMinSize.y;
  7238. SendMessage(_hwnd, TB_GETIDEALSIZE, FALSE, (LPARAM)&size);
  7239. pdbi->ptActual.x = size.cx;
  7240. pdbi->ptActual.y = size.cy;
  7241. }
  7242. // no title
  7243. pdbi->dwMask &= ~DBIM_TITLE;
  7244. return S_OK;
  7245. }
  7246. IOleCommandTarget* TOOLSBANDCLASS::_CommandTargetFromCmdMap(CMDMAP* pcm)
  7247. {
  7248. IOleCommandTarget* pct = NULL;
  7249. if (pcm)
  7250. {
  7251. if (IsEqualGUID(pcm->guidButtonGroup, CLSID_CommonButtons))
  7252. {
  7253. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _btb, this);
  7254. pct = SAFECAST(pitbar, IOleCommandTarget*);
  7255. }
  7256. else
  7257. {
  7258. // If either of these rip, the button is stale
  7259. ASSERT(IsEqualGUID(pcm->guidButtonGroup, _guidCurrentButtonGroup));
  7260. ASSERT(_pctCurrentButtonGroup);
  7261. pct = _pctCurrentButtonGroup;
  7262. }
  7263. }
  7264. return pct;
  7265. }
  7266. BOOL ShiftRectToEdgeOfMonitor(RECT *prc)
  7267. {
  7268. BOOL bRet = FALSE;
  7269. POINT pt = {prc->left, prc->top};
  7270. HMONITOR hmon = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
  7271. if (hmon)
  7272. {
  7273. MONITORINFO mi = {sizeof(MONITORINFO)};
  7274. if (GetMonitorInfo(hmon, &mi))
  7275. {
  7276. // get the different between the monitor's left edge and the rect's left edge
  7277. int iShift = mi.rcMonitor.left - prc->left;
  7278. if (iShift > 0)
  7279. {
  7280. prc->left += iShift;
  7281. prc->right += iShift;
  7282. bRet = TRUE;
  7283. }
  7284. }
  7285. }
  7286. return bRet;
  7287. }
  7288. LRESULT TOOLSBANDCLASS::_OnToolbarDropDown(TBNOTIFY *ptbn)
  7289. {
  7290. if (ptbn->hdr.hwndFrom == _hwnd)
  7291. {
  7292. CMDMAP* pcm = _GetCmdMapByID(ptbn->iItem);
  7293. IOleCommandTarget* pct = _CommandTargetFromCmdMap(pcm);
  7294. if (pct)
  7295. {
  7296. VARIANTARG var;
  7297. var.vt = VT_I4;
  7298. var.lVal = ptbn->iItem;
  7299. // REARCHITECT: use VARIANT[TO/FROM]BUFFER here to fix win64 problem
  7300. VARIANT v = {VT_INT_PTR};
  7301. v.byref = &ptbn->rcButton;
  7302. MapWindowRect(_hwnd, HWND_DESKTOP, &ptbn->rcButton);
  7303. //
  7304. // If this window is mirrored, then let's take the
  7305. // other coordinate [samera]
  7306. //
  7307. if (IS_WINDOW_RTL_MIRRORED(_hwnd))
  7308. {
  7309. int iTmp = ptbn->rcButton.right;
  7310. ptbn->rcButton.right = ptbn->rcButton.left;
  7311. ptbn->rcButton.left = iTmp;
  7312. }
  7313. // TrackMenuPopup is lame when confronted with negative co-ordinates... lets clip to the edge of the screen.
  7314. ShiftRectToEdgeOfMonitor(&ptbn->rcButton);
  7315. #ifdef EDIT_HACK
  7316. // FEATURE: temp code -- edit code moving to dochost.cpp
  7317. if (_IsDocHostGUID(&pcm->guidButtonGroup) && pcm->nCmdID == DVIDM_EDITPAGE)
  7318. Exec(&pcm->guidButtonGroup, (DWORD)pcm->nCmdID, OLECMDEXECOPT_PROMPTUSER, &v, &var);
  7319. else
  7320. #endif
  7321. pct->Exec(&pcm->guidButtonGroup, (DWORD)pcm->nCmdID, OLECMDEXECOPT_PROMPTUSER, &v, &var);
  7322. }
  7323. }
  7324. return TBDDRET_DEFAULT;
  7325. }
  7326. LRESULT TOOLSBANDCLASS::_TryShowBackForwardMenu(DWORD dwItemSpec, LPPOINT ppt, LPRECT prcExclude)
  7327. {
  7328. LRESULT lres = 0;
  7329. GUID guid;
  7330. UINT id;
  7331. if (SUCCEEDED(_ConvertCmd(NULL, dwItemSpec, &guid, &id)))
  7332. {
  7333. // If the user right clicked on the the back or forward button, show the context menu
  7334. // On all other buttons show the regular shortcut menu
  7335. if (IsEqualGUID(guid, CLSID_CommonButtons))
  7336. {
  7337. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _btb, this);
  7338. if (id == TBIDM_BACK)
  7339. {
  7340. pitbar->_ShowBackForwardMenu(FALSE, *ppt, prcExclude);
  7341. lres = 1;
  7342. }
  7343. else if (id == TBIDM_FORWARD)
  7344. {
  7345. pitbar->_ShowBackForwardMenu(TRUE, *ppt, prcExclude);
  7346. lres = 1;
  7347. }
  7348. }
  7349. }
  7350. return lres;
  7351. }
  7352. LRESULT TOOLSBANDCLASS::_OnNotify(LPNMHDR pnmh)
  7353. {
  7354. LRESULT lres = 0;
  7355. ASSERT(pnmh->idFrom == FCIDM_TOOLBAR);
  7356. switch (pnmh->code)
  7357. {
  7358. case NM_RCLICK:
  7359. {
  7360. NMCLICK * pnm = (LPNMCLICK)pnmh;
  7361. if (!pnm)
  7362. break;
  7363. // Convert to Screen coordinates
  7364. MapWindowPoints(pnmh->hwndFrom, HWND_DESKTOP, &pnm->pt, 1);
  7365. if (pnmh->hwndFrom == _hwnd)
  7366. lres = _TryShowBackForwardMenu((DWORD)pnm->dwItemSpec, &pnm->pt, NULL);
  7367. }
  7368. break;
  7369. case TBN_DROPDOWN:
  7370. lres = _OnToolbarDropDown((TBNOTIFY *)pnmh);
  7371. break;
  7372. case TBN_DELETINGBUTTON:
  7373. _OnDeletingButton((TBNOTIFY*)pnmh);
  7374. break;
  7375. case TBN_SAVE:
  7376. case TBN_RESET:
  7377. case TBN_INITCUSTOMIZE:
  7378. case TBN_RESTORE:
  7379. case TBN_BEGINADJUST:
  7380. case TBN_GETBUTTONINFO:
  7381. case TBN_ENDADJUST:
  7382. case TBN_QUERYDELETE:
  7383. case TBN_QUERYINSERT:
  7384. case TBN_TOOLBARCHANGE:
  7385. if (pnmh->hwndFrom == _hwnd)
  7386. lres = _ToolsCustNotify (pnmh);
  7387. break;
  7388. case TBN_GETOBJECT:
  7389. {
  7390. NMOBJECTNOTIFY *pnmon = (NMOBJECTNOTIFY *)pnmh;
  7391. if (IsEqualIID(*pnmon->piid, IID_IDropTarget))
  7392. {
  7393. if (pnmh->hwndFrom == _hwnd)
  7394. {
  7395. UINT uiCmd;
  7396. GUID guid;
  7397. _ConvertCmd(NULL, pnmon->iItem, &guid, &uiCmd);
  7398. if (IsEqualGUID(guid, CLSID_CommonButtons) &&
  7399. (uiCmd == TBIDM_HOME || uiCmd == TBIDM_FAVORITES))
  7400. {
  7401. CITBarDropTarget *pdtgt = new CITBarDropTarget(_hwnd, uiCmd);
  7402. if (pdtgt)
  7403. {
  7404. pnmon->pObject = SAFECAST(pdtgt, IDropTarget*);
  7405. pnmon->hResult = NOERROR;
  7406. }
  7407. }
  7408. else // pass back CDropDummy to handle basics.
  7409. {
  7410. CDropDummy *pdtgt = new CDropDummy(_hwnd);
  7411. if (pdtgt)
  7412. {
  7413. pnmon->pObject = SAFECAST(pdtgt, IDropTarget*);
  7414. pnmon->hResult = NOERROR;
  7415. }
  7416. }
  7417. }
  7418. lres = TRUE;
  7419. }
  7420. }
  7421. break;
  7422. default:
  7423. lres = CToolbarBand::_OnNotify(pnmh);
  7424. break;
  7425. }
  7426. return lres;
  7427. }
  7428. LRESULT TOOLSBANDCLASS::_OnContextMenu(LPARAM lParam, WPARAM wParam)
  7429. {
  7430. LRESULT lres = 0;
  7431. if (IS_WM_CONTEXTMENU_KEYBOARD(lParam))
  7432. {
  7433. // keyboard context menu. figure out where to pop up menu and
  7434. // which context menu to use, and tell itbar to pop it up.
  7435. RECT rc;
  7436. BOOL fBackForward = FALSE;
  7437. // figure out coordinates to use
  7438. INT_PTR iBtn = SendMessage(_hwnd, TB_GETHOTITEM, 0, 0);
  7439. if (iBtn != -1)
  7440. {
  7441. // use lower left corner of current hot button
  7442. SendMessage(_hwnd, TB_GETITEMRECT, iBtn, (LPARAM)&rc);
  7443. }
  7444. else
  7445. {
  7446. // no hot button; use top left corner of tools window
  7447. SetRect(&rc, 0, 0, 0, 0);
  7448. }
  7449. MapWindowPoints(_hwnd, HWND_DESKTOP, (LPPOINT)&rc, 2);
  7450. if (iBtn != -1)
  7451. {
  7452. // get hot button's command
  7453. TBBUTTONINFO tbbi;
  7454. tbbi.cbSize = sizeof(TBBUTTONINFO);
  7455. tbbi.dwMask = TBIF_BYINDEX | TBIF_COMMAND;
  7456. SendMessage(_hwnd, TB_GETBUTTONINFO, iBtn, (LPARAM)&tbbi);
  7457. POINT pt = {rc.left, rc.bottom};
  7458. // try popping up the back/forward context menu
  7459. if (_TryShowBackForwardMenu(tbbi.idCommand, &pt, &rc))
  7460. fBackForward = TRUE;
  7461. }
  7462. if (!fBackForward)
  7463. {
  7464. // pop up the standard context menu
  7465. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _btb, this);
  7466. pitbar->_ShowContextMenu((HWND)wParam, MAKELONG(rc.left, rc.bottom), (iBtn == -1 ? NULL : &rc));
  7467. }
  7468. lres = 1;
  7469. }
  7470. return lres;
  7471. }
  7472. void TOOLSBANDCLASS::_RecalcButtonWidths()
  7473. {
  7474. // We need the toolbars buttons to use ONLY exactly as much space as is needed.
  7475. // By setting the size a a really small number like 10, and then setting it to
  7476. // the real number we can accomplish this.
  7477. // If we don't use do this, then when we add new buttons after doing this
  7478. // RemoveAllButtons(), the new buttons will be at least as wide as the widest
  7479. // button that existed on the last set of buttons (the ones we are just removing)
  7480. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _btb, this);
  7481. SendMessage(_hwnd, TB_SETBUTTONWIDTH, 0, (LPARAM)MAKELONG(0, 10));
  7482. SendMessage(_hwnd, TB_SETBUTTONWIDTH, 0, (LPARAM)(pitbar->_fCompressed ? MAKELONG(0, MAX_TB_COMPRESSED_WIDTH) : MAKELONG(0, pitbar->_uiMaxTBWidth)));
  7483. }
  7484. // *** IWinEventHandler methods ***
  7485. HRESULT TOOLSBANDCLASS::OnWinEvent(HWND hwnd, UINT dwMsg, WPARAM wParam, LPARAM lParam, LRESULT* plres)
  7486. {
  7487. HRESULT hres = S_OK;
  7488. switch (dwMsg)
  7489. {
  7490. case WM_CONTEXTMENU:
  7491. *plres = _OnContextMenu(lParam, wParam);
  7492. break;
  7493. case WM_NOTIFY:
  7494. *plres = _OnNotify((LPNMHDR)lParam);
  7495. break;
  7496. case WM_WININICHANGE:
  7497. *plres = SendMessage(_hwnd, dwMsg, wParam, lParam);
  7498. if (wParam == SPI_SETNONCLIENTMETRICS)
  7499. {
  7500. _RecalcButtonWidths();
  7501. _BandInfoChanged();
  7502. }
  7503. break;
  7504. default:
  7505. hres = CToolbarBand::OnWinEvent(hwnd, dwMsg, wParam, lParam, plres);
  7506. break;
  7507. }
  7508. return hres;
  7509. }
  7510. CMDMAP* TOOLSBANDCLASS::_GetCmdMap(int i, BOOL fByIndex)
  7511. {
  7512. TBBUTTONINFO tbbi;
  7513. tbbi.cbSize = sizeof(tbbi);
  7514. tbbi.dwMask = TBIF_LPARAM;
  7515. tbbi.lParam = 0;
  7516. if (fByIndex)
  7517. tbbi.dwMask |= TBIF_BYINDEX;
  7518. SendMessage(_hwnd, TB_GETBUTTONINFO, i, (LPARAM)&tbbi);
  7519. return (CMDMAP*)(void*)tbbi.lParam;
  7520. }
  7521. void TOOLSBANDCLASS::_FreeCmdMap(CMDMAP* pcm)
  7522. {
  7523. if (pcm)
  7524. LocalFree(pcm);
  7525. }
  7526. void TOOLSBANDCLASS::_OnDeletingButton(TBNOTIFY* ptbn)
  7527. {
  7528. CMDMAP *pcm = (CMDMAP*)(void*)ptbn->tbButton.dwData;
  7529. _FreeCmdMap(pcm);
  7530. }
  7531. LONG_PTR TOOLSBANDCLASS::_AddString(LPWSTR pwstr)
  7532. {
  7533. LONG_PTR lOffset;
  7534. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _btb, this);
  7535. pitbar->AddString(&_guidCurrentButtonGroup, 0, (UINT_PTR)pwstr, &lOffset);
  7536. return lOffset;
  7537. }
  7538. #define PPBS_LOOKINTOOLBAR 0x00000001
  7539. #define PPBS_EXTERNALBUTTON 0x00000002
  7540. void TOOLSBANDCLASS::_PreProcessButtonString(TBBUTTON *ptbn, DWORD dwFlags)
  7541. {
  7542. // Caller should have checked this.
  7543. ASSERT(!(ptbn->fsStyle & BTNS_SEP));
  7544. // If we don't have a command target, we shouldn't have any external buttons.
  7545. ASSERT(_pctCurrentButtonGroup || !(dwFlags & PPBS_EXTERNALBUTTON));
  7546. if (ptbn->iString < 0 && ptbn->iBitmap <= MAX_SHELLGLYPHINDEX)
  7547. {
  7548. // total hack
  7549. // we're hard coding the strings in to match
  7550. // the bitmap. so if anyone uses the shell bitmaps,
  7551. // they're going to get our text labels
  7552. // also hacking in that the bitmap array and string array are
  7553. // matched
  7554. // who designed reviewed this???
  7555. ptbn->iString = ptbn->iBitmap;
  7556. }
  7557. else if (!ptbn->iString && (dwFlags & PPBS_EXTERNALBUTTON))
  7558. {
  7559. // Some Extensions are giving us bogus string ids (Font ext sends 0)
  7560. ptbn->iString = -1;
  7561. }
  7562. else if (ptbn->iString != -1 && !IS_INTRESOURCE(ptbn->iString))
  7563. {
  7564. // It's a string pointer. The customization mechanism requires that all buttons
  7565. // use strings from the tb string pool. So add the string to the pool and set
  7566. // iString to the pool index.
  7567. ptbn->iString = _AddString((LPWSTR)ptbn->iString);
  7568. }
  7569. if (ptbn->iString == -1 && IsFlagSet(dwFlags, PPBS_LOOKINTOOLBAR | PPBS_EXTERNALBUTTON))
  7570. {
  7571. // If we're building the customization dsa rather than adding new buttons to the
  7572. // toolbar, we may already have this button in the toolbar. If so, use that string.
  7573. UINT idCommand;
  7574. if (SUCCEEDED(_ConvertCmd(&_guidCurrentButtonGroup, ptbn->idCommand, NULL, &idCommand)))
  7575. {
  7576. TBBUTTON tbb;
  7577. if (SendMessage(_hwnd, TB_GETBUTTON, idCommand, (LPARAM)&tbb))
  7578. ptbn->iString = tbb.iString;
  7579. }
  7580. }
  7581. if (ptbn->iString == -1 && (dwFlags & PPBS_EXTERNALBUTTON))
  7582. {
  7583. // Still don't have a string for this puppy. Last resort is to ask via QueryStatus.
  7584. OLECMDTEXTV<MAX_TOOLTIP_STRING> cmdtv;
  7585. OLECMDTEXT *pcmdText = &cmdtv;
  7586. pcmdText->cwBuf = MAX_TOOLTIP_STRING;
  7587. pcmdText->cmdtextf = OLECMDTEXTF_NAME;
  7588. pcmdText->cwActual = 0;
  7589. OLECMD rgcmd = {ptbn->idCommand, 0};
  7590. HRESULT hr = _pctCurrentButtonGroup->QueryStatus(&_guidCurrentButtonGroup, 1, &rgcmd, pcmdText);
  7591. if (SUCCEEDED(hr) && (pcmdText->cwActual))
  7592. ptbn->iString = _AddString(pcmdText->rgwz);
  7593. }
  7594. // If it's an internal button, we'd better have found a string for it.
  7595. ASSERT(ptbn->iString != -1 || (dwFlags & PPBS_EXTERNALBUTTON));
  7596. }
  7597. void TOOLSBANDCLASS::_PreProcessExternalTBButton(TBBUTTON *ptbn)
  7598. {
  7599. if (!(ptbn->fsStyle & BTNS_SEP))
  7600. {
  7601. CMDMAP* pcm = (CMDMAP*)LocalAlloc(LPTR, sizeof(CMDMAP));
  7602. if (pcm)
  7603. {
  7604. pcm->guidButtonGroup = _guidCurrentButtonGroup;
  7605. pcm->nCmdID = ptbn->idCommand;
  7606. _PreProcessButtonString(ptbn, PPBS_EXTERNALBUTTON);
  7607. _nNextCommandID++;
  7608. pcm->lParam = ptbn->dwData;
  7609. }
  7610. ptbn->dwData = (LPARAM)pcm;
  7611. }
  7612. else
  7613. {
  7614. ptbn->dwData = 0;
  7615. // override default toolbar width for separators; iBitmap member of
  7616. // TBBUTTON struct is a union of bitmap index & separator width
  7617. ptbn->iBitmap = CX_SEPARATOR;
  7618. }
  7619. }
  7620. UINT TOOLSBANDCLASS::_ProcessExternalButtons(PTBBUTTON ptbb, UINT cButtons)
  7621. {
  7622. cButtons = RemoveHiddenButtons(ptbb, cButtons);
  7623. for (UINT i = 0; i < cButtons; i++)
  7624. _PreProcessExternalTBButton(&ptbb[i]);
  7625. return cButtons;
  7626. }
  7627. void TOOLSBANDCLASS::_GetButtons(IOleCommandTarget* pct, const GUID* pguid, HDSA hdsa)
  7628. {
  7629. LONG lCount;
  7630. VARIANTARG v1;
  7631. VariantInit(&v1);
  7632. v1.vt = VT_BYREF | VT_I4;
  7633. v1.plVal = &lCount;
  7634. VARIANTARG v2;
  7635. VariantInit(&v2);
  7636. if (SUCCEEDED(pct->Exec(&IID_IExplorerToolbar, ETCMDID_GETBUTTONS, 0, &v1, &v2)) && v2.vt == VT_BYREF)
  7637. {
  7638. CMDMAPCUSTOMIZE cmc;
  7639. TBBUTTON* pbtn = (TBBUTTON*)v2.byref;
  7640. cmc.cm.guidButtonGroup = *pguid;
  7641. DWORD dwFlags = PPBS_LOOKINTOOLBAR;
  7642. if (!IsEqualGUID(*pguid, CLSID_CommonButtons))
  7643. dwFlags |= PPBS_EXTERNALBUTTON;
  7644. for (long l = 0; l < lCount; l++)
  7645. {
  7646. cmc.btn = pbtn[l];
  7647. if (!(cmc.btn.fsStyle & BTNS_SEP))
  7648. {
  7649. cmc.cm.nCmdID = pbtn[l].idCommand;
  7650. _PreProcessButtonString(&cmc.btn, dwFlags);
  7651. if (FAILED(_ConvertCmd(pguid, cmc.cm.nCmdID, NULL, (UINT*)&cmc.btn.idCommand)))
  7652. {
  7653. // not already in the toolbar, generate a new id
  7654. cmc.btn.idCommand = _nNextCommandID++;
  7655. }
  7656. DSA_AppendItem(hdsa, &cmc);
  7657. }
  7658. else
  7659. {
  7660. cmc.btn.dwData = 0;
  7661. }
  7662. }
  7663. }
  7664. }
  7665. void TOOLSBANDCLASS::_OnEndCustomize()
  7666. {
  7667. if (_pcinfo)
  7668. {
  7669. // loop through and make sure that any items added have the appropriate cmdmap
  7670. int i;
  7671. INT_PTR nCount = SendMessage(_hwnd, TB_BUTTONCOUNT, 0, 0L);
  7672. _pcinfo->fAdjust = FALSE;
  7673. for(i = 0; i < nCount; i++)
  7674. {
  7675. CMDMAP* pcm = _GetCmdMapByIndex(i);
  7676. if (!pcm)
  7677. {
  7678. // no command map for this item
  7679. // find the corresponding CMDMAP in our hdsa, clone it and give it to this button.
  7680. // the command id's are the same, so get the toolbar command id, find the corresponding
  7681. // one in the hdsa and clone away.
  7682. TBBUTTONINFO tbbi;
  7683. tbbi.cbSize = sizeof(tbbi);
  7684. tbbi.dwMask = TBIF_COMMAND | TBIF_BYINDEX;
  7685. SendMessage(_hwnd, TB_GETBUTTONINFO, i, (LPARAM)&tbbi);
  7686. int j;
  7687. for (j = 0; j < DSA_GetItemCount(_pcinfo->hdsa); j++)
  7688. {
  7689. CMDMAPCUSTOMIZE* pcmc = (CMDMAPCUSTOMIZE*)DSA_GetItemPtr(_pcinfo->hdsa, j);
  7690. ASSERT(pcmc);
  7691. if (pcmc->btn.idCommand == tbbi.idCommand)
  7692. {
  7693. // found it!
  7694. // clone the cmdmap
  7695. CMDMAP *pcm = (CMDMAP*)LocalAlloc(LPTR, sizeof(CMDMAP));
  7696. if (pcm)
  7697. {
  7698. *pcm = pcmc->cm;
  7699. tbbi.lParam = (LPARAM)pcm;
  7700. tbbi.dwMask = TBIF_LPARAM | TBIF_BYINDEX;
  7701. SendMessage(_hwnd, TB_SETBUTTONINFO, i, (LPARAM)&tbbi);
  7702. }
  7703. }
  7704. }
  7705. }
  7706. }
  7707. if (_pcinfo->fDirty)
  7708. _SaveRestoreToolbar(TRUE);
  7709. _FreeCustomizeInfo();
  7710. _RecalcButtonWidths();
  7711. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _btb, this);
  7712. #ifdef EDIT_HACK
  7713. pitbar->_InitEditButtonStyle();
  7714. #endif
  7715. if (g_fSmallIcons != _UseSmallIcons())
  7716. {
  7717. SendShellIEBroadcastMessage(WM_WININICHANGE, 0, (LPARAM)SZ_REGKEY_SMALLICONS, 3000);
  7718. // Resize the Theater Controls based upon the icon changes.
  7719. IUnknown_Exec( _punkSite, &CGID_Theater, THID_RECALCSIZING, 0, NULL, NULL );
  7720. }
  7721. pitbar->_UpdateToolbar(TRUE);
  7722. }
  7723. }
  7724. void TOOLSBANDCLASS::_FreeCustomizeInfo()
  7725. {
  7726. if (_pcinfo)
  7727. {
  7728. DSA_Destroy(_pcinfo->hdsa);
  7729. _pcinfo->hdsa = NULL;
  7730. LocalFree(_pcinfo);
  7731. _pcinfo = NULL;
  7732. }
  7733. }
  7734. CMDMAPCUSTOMIZE* TOOLSBANDCLASS::_GetCmdMapCustomize(GUID* pguid, UINT nCmdID)
  7735. {
  7736. int j;
  7737. for (j = 0; j < DSA_GetItemCount(_pcinfo->hdsa); j++)
  7738. {
  7739. CMDMAPCUSTOMIZE* pcmc = (CMDMAPCUSTOMIZE*)DSA_GetItemPtr(_pcinfo->hdsa, j);
  7740. if (pcmc->cm.nCmdID == nCmdID &&
  7741. IsEqualGUID(*pguid, pcmc->cm.guidButtonGroup))
  7742. {
  7743. return pcmc;
  7744. }
  7745. }
  7746. return NULL;
  7747. }
  7748. BOOL TOOLSBANDCLASS::_BuildButtonDSA()
  7749. {
  7750. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _btb, this);
  7751. ASSERT(!_pcinfo);
  7752. _pcinfo = (CUSTOMIZEINFO*)LocalAlloc(LPTR, sizeof(CUSTOMIZEINFO));
  7753. if (_pcinfo)
  7754. {
  7755. // build a CMDMAP array of all the buttons available
  7756. _pcinfo->hdsa = DSA_Create(sizeof(CMDMAPCUSTOMIZE), 4);
  7757. if (_pcinfo->hdsa)
  7758. {
  7759. // add the common set (back,forward, stop, refresh, home and search
  7760. _GetButtons(pitbar, &CLSID_CommonButtons, _pcinfo->hdsa);
  7761. _GetButtons(_pctCurrentButtonGroup, &_guidCurrentButtonGroup, _pcinfo->hdsa);
  7762. return TRUE;
  7763. }
  7764. else
  7765. {
  7766. _FreeCustomizeInfo();
  7767. return FALSE;
  7768. }
  7769. }
  7770. return FALSE;
  7771. }
  7772. void TOOLSBANDCLASS::_UpdateTextSettings(INT_PTR ids)
  7773. {
  7774. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _btb, this);
  7775. BOOL fText, fList;
  7776. switch (ids)
  7777. {
  7778. case IDS_TEXTLABELS:
  7779. fList = FALSE;
  7780. fText = TRUE;
  7781. break;
  7782. case IDS_PARTIALTEXT:
  7783. fList = TRUE;
  7784. fText = TRUE;
  7785. break;
  7786. case IDS_NOTEXTLABELS:
  7787. fList = FALSE; // (but we really don't care)
  7788. fText = FALSE;
  7789. break;
  7790. default:
  7791. ASSERT(0);
  7792. fList = FALSE;
  7793. fText = FALSE;
  7794. break;
  7795. }
  7796. pitbar->_UpdateToolsStyle(fList);
  7797. // (_fCompressed == TRUE means no text labels)
  7798. pitbar->_UpdateToolbarDisplay(UTD_TEXTLABEL, 0, !fText, TRUE);
  7799. }
  7800. const static DWORD c_aBtnAttrHelpIDs[] = {
  7801. IDC_SHOWTEXT, IDH_BROWSEUI_TB_TEXTOPTNS,
  7802. IDC_SMALLICONS, IDH_BROWSEUI_TB_ICONOPTNS,
  7803. 0, 0
  7804. };
  7805. BOOL_PTR CALLBACK TOOLSBANDCLASS::_BtnAttrDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  7806. {
  7807. CInternetToolbar* pitbar = (CInternetToolbar*)GetWindowPtr(hDlg, DWLP_USER);
  7808. switch (uMsg)
  7809. {
  7810. case WM_INITDIALOG:
  7811. SetWindowLongPtr(hDlg, DWLP_USER, lParam); /* LPADJUSTDLGDATA pointer */
  7812. return TRUE;
  7813. case WM_COMMAND:
  7814. if (GET_WM_COMMAND_ID(wParam, lParam) == IDC_SHOWTEXT)
  7815. {
  7816. if (GET_WM_COMMAND_CMD(wParam, lParam) == CBN_SELENDOK ||
  7817. GET_WM_COMMAND_CMD(wParam, lParam) == CBN_CLOSEUP)
  7818. {
  7819. // what'd they pick?
  7820. HWND hwndText = GET_WM_COMMAND_HWND(wParam, lParam);
  7821. INT_PTR iSel = SendMessage(hwndText, CB_GETCURSEL, 0, 0);
  7822. INT_PTR idsSel = SendMessage(hwndText, CB_GETITEMDATA, iSel, 0);
  7823. pitbar->_btb._UpdateTextSettings(idsSel);
  7824. return TRUE;
  7825. }
  7826. }
  7827. break;
  7828. case WM_CONTEXTMENU:
  7829. SHWinHelpOnDemandWrap((HWND) wParam, c_szHelpFile,
  7830. HELP_CONTEXTMENU, (DWORD_PTR)(LPTSTR) c_aBtnAttrHelpIDs);
  7831. return TRUE;
  7832. case WM_HELP:
  7833. SHWinHelpOnDemandWrap((HWND) ((LPHELPINFO) lParam)->hItemHandle, c_szHelpFile,
  7834. HELP_WM_HELP, (DWORD_PTR)(LPTSTR) c_aBtnAttrHelpIDs);
  7835. return TRUE;
  7836. case WM_DESTROY:
  7837. {
  7838. #define SZ_YES TEXT("yes")
  7839. #define SZ_NO TEXT("no")
  7840. HWND hwndIcons = GetDlgItem(hDlg, IDC_SMALLICONS);
  7841. if (TPTR(hwndIcons))
  7842. {
  7843. INT_PTR iSel = SendMessage(hwndIcons, CB_GETCURSEL, 0, 0);
  7844. BOOL fSmallIcons = (SendMessage(hwndIcons, CB_GETITEMDATA, iSel, 0) == IDS_SMALLICONS);
  7845. LPCTSTR szData;
  7846. DWORD cbData;
  7847. if (fSmallIcons)
  7848. {
  7849. szData = SZ_YES;
  7850. cbData = sizeof(SZ_YES);
  7851. }
  7852. else
  7853. {
  7854. szData = SZ_NO;
  7855. cbData = sizeof(SZ_NO);
  7856. }
  7857. SHRegSetUSValue(SZ_REGKEY_SMALLICONS, SZ_REGVALUE_SMALLICONS, REG_SZ, (void*)szData, cbData, SHREGSET_FORCE_HKCU);
  7858. }
  7859. }
  7860. return TRUE;
  7861. }
  7862. return FALSE;
  7863. }
  7864. void TOOLSBANDCLASS::_PopulateComboBox(HWND hwnd, const int iResource[], UINT cResources)
  7865. {
  7866. TCHAR sz[256];
  7867. // loop through iResource[], load each string resource and insert into combobox
  7868. for (UINT i = 0; i < cResources; i++)
  7869. {
  7870. if (MLLoadString(iResource[i], sz, ARRAYSIZE(sz)))
  7871. {
  7872. INT_PTR iIndex = SendMessage(hwnd, CB_ADDSTRING, 0, (LPARAM)sz);
  7873. SendMessage(hwnd, CB_SETITEMDATA, iIndex, iResource[i]);
  7874. }
  7875. }
  7876. }
  7877. void TOOLSBANDCLASS::_SetComboSelection(HWND hwnd, int iCurOption)
  7878. {
  7879. INT_PTR cItems = SendMessage(hwnd, CB_GETCOUNT, 0, 0);
  7880. while (cItems--)
  7881. {
  7882. INT_PTR iItemData = SendMessage(hwnd, CB_GETITEMDATA, cItems, 0);
  7883. if (iItemData == iCurOption)
  7884. {
  7885. SendMessage(hwnd, CB_SETCURSEL, cItems, 0);
  7886. break;
  7887. }
  7888. else
  7889. {
  7890. // iCurOption should be in list somewhere;
  7891. // assert that we're not done looking
  7892. ASSERT(cItems);
  7893. }
  7894. }
  7895. }
  7896. void TOOLSBANDCLASS::_SetDialogSelections(HWND hDlg, BOOL fSmallIcons)
  7897. {
  7898. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _btb, this);
  7899. int iCurOption;
  7900. HWND hwnd;
  7901. hwnd = GetDlgItem(hDlg, IDC_SHOWTEXT);
  7902. if (pitbar->_fCompressed)
  7903. iCurOption = IDS_NOTEXTLABELS;
  7904. else if (IS_LIST_STYLE(_hwnd))
  7905. iCurOption = IDS_PARTIALTEXT;
  7906. else
  7907. iCurOption = IDS_TEXTLABELS;
  7908. _SetComboSelection(hwnd, iCurOption);
  7909. if (pitbar->_fTheater)
  7910. SHSetWindowBits(hwnd, GWL_STYLE, WS_DISABLED, WS_DISABLED);
  7911. hwnd = GetDlgItem(hDlg, IDC_SMALLICONS);
  7912. iCurOption = (fSmallIcons ? IDS_SMALLICONS : IDS_LARGEICONS);
  7913. _SetComboSelection(hwnd, iCurOption);
  7914. }
  7915. static const int c_iTextOptions[] = {
  7916. IDS_TEXTLABELS,
  7917. IDS_PARTIALTEXT,
  7918. IDS_NOTEXTLABELS,
  7919. };
  7920. static const int c_iIconOptions[] = {
  7921. IDS_SMALLICONS,
  7922. IDS_LARGEICONS,
  7923. };
  7924. void TOOLSBANDCLASS::_PopulateDialog(HWND hDlg)
  7925. {
  7926. HWND hwnd;
  7927. hwnd = GetDlgItem(hDlg, IDC_SHOWTEXT);
  7928. _PopulateComboBox(hwnd, c_iTextOptions, ARRAYSIZE(c_iTextOptions));
  7929. hwnd = GetDlgItem(hDlg, IDC_SMALLICONS);
  7930. _PopulateComboBox(hwnd, c_iIconOptions, ARRAYSIZE(c_iIconOptions));
  7931. }
  7932. void TOOLSBANDCLASS::_OnBeginCustomize(LPNMTBCUSTOMIZEDLG pnm)
  7933. {
  7934. CInternetToolbar* pitbar = IToClass(CInternetToolbar, _btb, this);
  7935. HWND hwnd = (HWND) GetProp(pnm->hDlg, SZ_PROP_CUSTDLG);
  7936. if (!hwnd)
  7937. {
  7938. //
  7939. // hasn't been initialized.
  7940. //
  7941. // we need to check this because this init will be called
  7942. // when the user hits reset as well
  7943. hwnd = CreateDialogParam(MLGetHinst(), MAKEINTRESOURCE(DLG_TEXTICONOPTIONS), pnm->hDlg, _BtnAttrDlgProc, (LPARAM)pitbar);
  7944. if (hwnd)
  7945. {
  7946. // store hwnd of our dialog as property on tb cust dialog
  7947. SetProp(pnm->hDlg, SZ_PROP_CUSTDLG, hwnd);
  7948. // populate dialog controls
  7949. _PopulateDialog(hwnd);
  7950. // initialize dialog control selection states
  7951. _SetDialogSelections(hwnd, g_fSmallIcons);
  7952. RECT rc, rcWnd, rcClient;
  7953. GetWindowRect(pnm->hDlg, &rcWnd);
  7954. GetClientRect(pnm->hDlg, &rcClient);
  7955. GetWindowRect(hwnd, &rc);
  7956. // enlarge tb dialog to make room for our dialog
  7957. SetWindowPos(pnm->hDlg, NULL, rcWnd.left, rcWnd.top + 64, RECTWIDTH(rcWnd), RECTHEIGHT(rcWnd) + RECTHEIGHT(rc), SWP_NOZORDER);
  7958. // position our dialog at the bottom of the tb dialog
  7959. SetWindowPos(hwnd, HWND_TOP, rcClient.left, rcClient.bottom, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
  7960. }
  7961. }
  7962. if (_BuildButtonDSA())
  7963. {
  7964. _pcinfo->fAdjust = TRUE;
  7965. }
  7966. }
  7967. class CBitmapPreload : public IRunnableTask
  7968. {
  7969. public:
  7970. STDMETHOD ( QueryInterface ) ( REFIID riid, void ** ppvObj );
  7971. STDMETHOD_( ULONG, AddRef ) ();
  7972. STDMETHOD_( ULONG, Release ) ();
  7973. STDMETHOD (Run)( void );
  7974. STDMETHOD (Kill)( BOOL fWait );
  7975. STDMETHOD (Suspend)( );
  7976. STDMETHOD (Resume)( );
  7977. STDMETHOD_( ULONG, IsRunning )( void );
  7978. protected:
  7979. friend HRESULT CBitmapPreload_CreateInstance(IUnknown* pUnkOuter, IUnknown** ppunk, LPCOBJECTINFO poi);
  7980. CBitmapPreload();
  7981. ~CBitmapPreload();
  7982. LONG m_cRef;
  7983. LONG m_lState;
  7984. };
  7985. STDAPI CBitmapPreload_CreateInstance(IUnknown* pUnkOuter, IUnknown** ppunk, LPCOBJECTINFO poi)
  7986. {
  7987. // aggregation checking and *ppunk zeroing are handled in class factory
  7988. ASSERT(pUnkOuter == NULL);
  7989. CBitmapPreload* pbp = new CBitmapPreload();
  7990. if (pbp)
  7991. {
  7992. *ppunk = SAFECAST(pbp, IRunnableTask*);
  7993. return S_OK;
  7994. }
  7995. else
  7996. {
  7997. *ppunk = NULL; // redundant but doesn't hurt
  7998. return E_OUTOFMEMORY;
  7999. }
  8000. }
  8001. CBitmapPreload::CBitmapPreload() : m_cRef(1)
  8002. {
  8003. m_lState = IRTIR_TASK_NOT_RUNNING;
  8004. }
  8005. CBitmapPreload::~CBitmapPreload()
  8006. {
  8007. }
  8008. STDMETHODIMP CBitmapPreload::QueryInterface (REFIID riid, void ** ppv)
  8009. {
  8010. static const QITAB qit[] = {
  8011. QITABENT(CBitmapPreload, IRunnableTask),
  8012. { 0 },
  8013. };
  8014. return QISearch(this, qit, riid, ppv);
  8015. }
  8016. STDMETHODIMP_( ULONG ) CBitmapPreload:: AddRef ()
  8017. {
  8018. return InterlockedIncrement( &m_cRef );
  8019. }
  8020. STDMETHODIMP_( ULONG ) CBitmapPreload:: Release ()
  8021. {
  8022. if (InterlockedDecrement( &m_cRef ) == 0 )
  8023. {
  8024. delete this;
  8025. return 0;
  8026. }
  8027. return m_cRef;
  8028. }
  8029. STDMETHODIMP CBitmapPreload::Run ( void )
  8030. {
  8031. if ( m_lState != IRTIR_TASK_NOT_RUNNING )
  8032. {
  8033. return E_FAIL;
  8034. }
  8035. InterlockedExchange( &m_lState, IRTIR_TASK_RUNNING );
  8036. CInternetToolbar_Preload( );
  8037. InterlockedExchange( &m_lState, IRTIR_TASK_FINISHED );
  8038. return NOERROR;
  8039. }
  8040. STDMETHODIMP CBitmapPreload::Kill ( BOOL fWait )
  8041. {
  8042. return E_NOTIMPL;
  8043. }
  8044. STDMETHODIMP CBitmapPreload::Suspend ( )
  8045. {
  8046. return E_NOTIMPL;
  8047. }
  8048. STDMETHODIMP CBitmapPreload::Resume ( )
  8049. {
  8050. return E_NOTIMPL;
  8051. }
  8052. STDMETHODIMP_( ULONG ) CBitmapPreload:: IsRunning ( void )
  8053. {
  8054. return m_lState;
  8055. }
  8056. #ifdef EDIT_HACK
  8057. //+-------------------------------------------------------------------------
  8058. // Constructor
  8059. //--------------------------------------------------------------------------
  8060. CInternetToolbar::CEditVerb::CEditVerb()
  8061. {
  8062. ASSERT(_nElements == 0);
  8063. ASSERT(_nDefault == 0);
  8064. ASSERT(_pVerb == NULL);
  8065. ASSERT(_lpfnOldWndProc == NULL);
  8066. ASSERT(_pszDefaultEditor == NULL);
  8067. ASSERT(_fInitEditor == FALSE);
  8068. }
  8069. //+-------------------------------------------------------------------------
  8070. // Destructor
  8071. //--------------------------------------------------------------------------
  8072. CInternetToolbar::CEditVerb::~CEditVerb()
  8073. {
  8074. if (_pVerb) RemoveAll();
  8075. SetStr(&_pszDefaultEditor, NULL);
  8076. }
  8077. //+-------------------------------------------------------------------------
  8078. // Removes all cached edit verbs and associated memory
  8079. //--------------------------------------------------------------------------
  8080. void CInternetToolbar::CEditVerb::RemoveAll()
  8081. {
  8082. if (_nElements > 0)
  8083. {
  8084. for (UINT i=0; i < _nElements; ++i)
  8085. {
  8086. EDITVERB& rVerb = _pVerb[i];
  8087. SetStr(&rVerb.pszDesc, NULL);
  8088. SetStr(&rVerb.pszMenuText, NULL);
  8089. SetStr(&rVerb.pszExe, NULL);
  8090. if (rVerb.hkeyProgID)
  8091. {
  8092. RegCloseKey(rVerb.hkeyProgID);
  8093. }
  8094. _ClearMSAAMenuInfo(rVerb);
  8095. }
  8096. LocalFree(_pVerb);
  8097. _pVerb = NULL;
  8098. _nElements = 0;
  8099. _nDefault = 0;
  8100. }
  8101. }
  8102. void _AddToOpenWithList(HKEY hkeyProgid, LPCWSTR pszVerb, LPCWSTR pszFileExt)
  8103. {
  8104. ASSERT(hkeyProgid);
  8105. ASSERT(pszVerb);
  8106. ASSERT(pszFileExt);
  8107. // First get the name of the exe
  8108. WCHAR szPath[MAX_PATH];
  8109. if (SUCCEEDED(AssocQueryStringByKey(ASSOCF_VERIFY, ASSOCSTR_EXECUTABLE, hkeyProgid,
  8110. pszVerb, szPath, (LPDWORD)MAKEINTRESOURCE(SIZECHARS(szPath)))))
  8111. {
  8112. // Now see if it is in the openwith list for the given file extension
  8113. LPCWSTR pszExe = PathFindFileName(szPath);
  8114. WCHAR szKey[MAX_PATH];
  8115. wnsprintf(szKey, ARRAYSIZE(szKey), L"%s\\OpenWithList\\%s", pszFileExt, pszExe);
  8116. HKEY hkey;
  8117. DWORD dwDisp;
  8118. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CLASSES_ROOT, szKey, 0, L"", REG_OPTION_NON_VOLATILE,
  8119. KEY_READ | KEY_WRITE, NULL, &hkey, &dwDisp))
  8120. {
  8121. // If we create a new key, we then need to check that verb is registered
  8122. // for this app
  8123. if (dwDisp == REG_CREATED_NEW_KEY)
  8124. {
  8125. AssocMakeApplicationByKey(ASSOCMAKEF_VERIFY, hkeyProgid, pszVerb);
  8126. }
  8127. RegCloseKey(hkey);
  8128. }
  8129. }
  8130. }
  8131. //+-------------------------------------------------------------------------
  8132. // Check registry for a default mhtml editor. If a new editor is detected,
  8133. // it is added to the mhtml openwith list.
  8134. //--------------------------------------------------------------------------
  8135. void CInternetToolbar::CEditVerb::_InitDefaultMHTMLEditor()
  8136. {
  8137. //
  8138. // Check for a default MHTML editor.
  8139. //
  8140. HKEY hkeyEdit = NULL;
  8141. if (ERROR_SUCCESS != RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_DEFAULT_MHTML_EDITOR, 0, KEY_READ | KEY_WRITE, &hkeyEdit))
  8142. {
  8143. // Migrate hklm setting to hkcu
  8144. HKEY hkeySrc;
  8145. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_DEFAULT_MHTML_EDITOR, 0, KEY_READ, &hkeySrc))
  8146. {
  8147. HKEY hkeyDest;
  8148. if (ERROR_SUCCESS == RegCreateKey(HKEY_CURRENT_USER, REGSTR_PATH_DEFAULT_MHTML_EDITOR, &hkeyDest))
  8149. {
  8150. SHCopyKey(hkeySrc, NULL, hkeyDest, 0);
  8151. hkeyEdit = hkeyDest;
  8152. }
  8153. RegCloseKey(hkeySrc);
  8154. }
  8155. }
  8156. if (hkeyEdit)
  8157. {
  8158. // If the mhtml editor has changed, copy it into the mhtml openwithlist
  8159. DWORD dwType;
  8160. WCHAR szCurrent[MAX_PATH];
  8161. DWORD cb = sizeof(szCurrent);
  8162. if (ERROR_SUCCESS == SHGetValue(hkeyEdit, L"shell\\edit\\command", NULL, &dwType, szCurrent, &cb) &&
  8163. dwType == REG_SZ)
  8164. {
  8165. WCHAR szLast[MAX_PATH];
  8166. DWORD cb = sizeof(szLast);
  8167. if (ERROR_SUCCESS != SHGetValue(hkeyEdit, NULL, L"Last", &dwType, szLast, &cb) ||
  8168. (dwType == REG_SZ && StrCmp(szLast, szCurrent) != 0))
  8169. {
  8170. // Copy the MHTML editor into our MHTML openwithlist
  8171. _AddToOpenWithList(hkeyEdit, L"edit", L".mhtml");
  8172. // Remember that we migrated this key. Copying to the openwithlist can be slow
  8173. // because we need to hit the disk to verify the exe name. So it's worth the effort
  8174. // to avoid doing this unecessarily.
  8175. SHSetValue(hkeyEdit, NULL, L"Last", REG_SZ, szCurrent, CbFromCch(lstrlen(szCurrent) +1));
  8176. }
  8177. }
  8178. RegCloseKey(hkeyEdit);
  8179. }
  8180. }
  8181. //+-------------------------------------------------------------------------
  8182. // Check registry for the friendly name of the default html editor. This
  8183. // editor is configured by inetcpl or by office 2000. If necessary, the
  8184. // associated verb is moved to the OpenWithList for .htm files.
  8185. //--------------------------------------------------------------------------
  8186. void CInternetToolbar::CEditVerb::InitDefaultEditor(HKEY hkey)
  8187. {
  8188. //
  8189. // First see if the default editor is in HKCU
  8190. //
  8191. HKEY hkeyEdit = hkey;
  8192. if (hkey ||
  8193. ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_DEFAULT_HTML_EDITOR,
  8194. 0, KEY_READ | KEY_WRITE, &hkeyEdit))
  8195. {
  8196. //
  8197. // See if we have a default editor selected
  8198. //
  8199. WCHAR szBuf[MAX_PATH];
  8200. DWORD cbBuf = sizeof(szBuf);
  8201. if (ERROR_SUCCESS == SHGetValue(hkeyEdit, NULL, L"Description", NULL, szBuf, &cbBuf))
  8202. {
  8203. // We got it! Save the friendly name.
  8204. PathRemoveBlanks(szBuf);
  8205. SetStr(&_pszDefaultEditor, szBuf);
  8206. }
  8207. else
  8208. {
  8209. // No default editor description, so check to see if an edit verb was added.
  8210. // (Office/inetcpl deletes the description key to signal to us that something changed).
  8211. IQueryAssociations *pqa;
  8212. if (SUCCEEDED(AssocCreate(CLSID_QueryAssociations, IID_PPV_ARG(IQueryAssociations, &pqa))))
  8213. {
  8214. if (SUCCEEDED(pqa->Init(0, NULL, hkeyEdit, NULL)) &&
  8215. ( SUCCEEDED(pqa->GetString(ASSOCF_VERIFY, ASSOCSTR_FRIENDLYAPPNAME, L"edit", szBuf, (LPDWORD)MAKEINTRESOURCE(SIZECHARS(szBuf))))
  8216. || SUCCEEDED(pqa->GetString(ASSOCF_VERIFY, ASSOCSTR_FRIENDLYAPPNAME, NULL, szBuf, (LPDWORD)MAKEINTRESOURCE(SIZECHARS(szBuf))))))
  8217. {
  8218. PathRemoveBlanks(szBuf);
  8219. // Save the name of the default editor
  8220. SetStr(&_pszDefaultEditor, szBuf);
  8221. SHSetValue(hkeyEdit, NULL, L"Description", REG_SZ, szBuf, CbFromCch(lstrlen(szBuf) +1));
  8222. // Add it to our openwithlist for .htm files
  8223. _AddToOpenWithList(hkeyEdit, L"edit", L".htm");
  8224. }
  8225. pqa->Release();
  8226. }
  8227. }
  8228. // Close the key if it wasn't passed in
  8229. if (hkeyEdit && NULL == hkey)
  8230. {
  8231. RegCloseKey(hkeyEdit);
  8232. }
  8233. }
  8234. // During setup, Office places the orginial edit verb in HKLM. We need to copy this to HKCU.
  8235. else if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, REGSTR_PATH_DEFAULT_HTML_EDITOR, 0, KEY_READ, &hkeyEdit))
  8236. {
  8237. // Migrate this key into HKCU
  8238. HKEY hkeyDest;
  8239. if (ERROR_SUCCESS == RegCreateKey(HKEY_CURRENT_USER, REGSTR_PATH_DEFAULT_HTML_EDITOR, &hkeyDest))
  8240. {
  8241. SHCopyKey(hkeyEdit, NULL, hkeyDest, 0);
  8242. // Try again
  8243. InitDefaultEditor(hkeyDest);
  8244. RegCloseKey(hkeyDest);
  8245. }
  8246. RegCloseKey(hkeyEdit);
  8247. }
  8248. //
  8249. // Check for a default MHTML editor.
  8250. //
  8251. if (hkey == NULL) // Don't do on recursion
  8252. {
  8253. _InitDefaultMHTMLEditor();
  8254. }
  8255. }
  8256. BOOL _GetAppKey(LPCWSTR pszApp, HKEY *phkApp)
  8257. {
  8258. ASSERT(pszApp && *pszApp);
  8259. WCHAR szKey[MAX_PATH];
  8260. StrCpy(szKey, L"Applications\\");
  8261. StrCatBuff(szKey, pszApp, SIZECHARS(szKey));
  8262. return (NOERROR == RegOpenKeyEx(
  8263. HKEY_CLASSES_ROOT,
  8264. szKey,
  8265. 0L,
  8266. MAXIMUM_ALLOWED,
  8267. phkApp));
  8268. }
  8269. //+-------------------------------------------------------------------------
  8270. // Make sure that notepad is registered in the OpenWithList for .htm files.
  8271. // This is called when this dll is registered (at setup time)
  8272. //--------------------------------------------------------------------------
  8273. void AddNotepadToOpenWithList()
  8274. {
  8275. // Add notepad to the openwith list for .htm files
  8276. HKEY hkeyOpenWith;
  8277. DWORD dwDisp;
  8278. if (ERROR_SUCCESS == RegCreateKeyEx(HKEY_CLASSES_ROOT, L".htm\\OpenWithList\\notepad.exe", 0, L"",
  8279. REG_OPTION_NON_VOLATILE, KEY_READ, NULL, &hkeyOpenWith, &dwDisp))
  8280. {
  8281. // Add the edit verb for notepad
  8282. // if (g_fRunningOnNT) // didn't work on nt4
  8283. // {
  8284. // const WCHAR szPath[] = L"%SystemRoot%\\notepad.exe %1";
  8285. // SHSetValue(HKEY_CLASSES_ROOT, L"Applications\\notepad.exe\\shell\\edit\\command", NULL, REG_EXPAND_SZ, szPath, sizeof(szPath));
  8286. // }
  8287. // else
  8288. {
  8289. WCHAR szPath[MAX_PATH];
  8290. GetWindowsDirectory(szPath, ARRAYSIZE(szPath));
  8291. PathAddBackslash(szPath);
  8292. StrCatBuff(szPath, L"notepad.exe %1", ARRAYSIZE(szPath));
  8293. SHSetValue(HKEY_CLASSES_ROOT, L"Applications\\notepad.exe\\shell\\edit\\command", NULL, REG_SZ, szPath, (lstrlen(szPath)+1) * sizeof(WCHAR));
  8294. }
  8295. // Add a localizable name for the edit verb
  8296. TCHAR szEditVerb[MAX_PATH];
  8297. int cch = MLLoadShellLangString(IDS_EDITVERB, szEditVerb, ARRAYSIZE(szEditVerb));
  8298. if (cch > 0)
  8299. {
  8300. SHSetValue(HKEY_CLASSES_ROOT, L"Applications\\notepad.exe\\shell\\edit", NULL, REG_SZ, szEditVerb, (cch + 1) * sizeof(WCHAR));
  8301. }
  8302. RegCloseKey(hkeyOpenWith);
  8303. }
  8304. }
  8305. //+-------------------------------------------------------------------------
  8306. // Returns the friendly name of the default HTML editor
  8307. //--------------------------------------------------------------------------
  8308. LPCTSTR CInternetToolbar::CEditVerb::_GetDefaultEditor()
  8309. {
  8310. // Do a lazy init of the default editor
  8311. if (!_fInitEditor)
  8312. {
  8313. InitDefaultEditor();
  8314. _fInitEditor = TRUE;
  8315. }
  8316. return _pszDefaultEditor;
  8317. }
  8318. //+-------------------------------------------------------------------------
  8319. // Gets the path of the exe associated with the verb and stores the
  8320. // result in rVerb. The caller is responsible for freeing the string
  8321. // returned.
  8322. //--------------------------------------------------------------------------
  8323. LPCTSTR CInternetToolbar::CEditVerb::_GetExePath(EDITVERB& rVerb)
  8324. {
  8325. // If we already have the path, simply return it
  8326. if (NULL == rVerb.pszExe)
  8327. {
  8328. ASSERT(rVerb.hkeyProgID);
  8329. TCHAR sz[MAX_PATH];
  8330. if (SUCCEEDED(AssocQueryStringByKey(ASSOCF_VERIFY, ASSOCSTR_EXECUTABLE, rVerb.hkeyProgID,
  8331. rVerb.fUseOpenVerb ? NULL : L"edit", sz, (LPDWORD)MAKEINTRESOURCE(SIZECHARS(sz)))))
  8332. rVerb.pszExe = StrDup(sz);
  8333. }
  8334. return rVerb.pszExe;
  8335. }
  8336. //+-------------------------------------------------------------------------
  8337. // Returns TRUE if path of the exe associated with the verb is not found in
  8338. // any of the existing verbs.
  8339. //--------------------------------------------------------------------------
  8340. BOOL CInternetToolbar::CEditVerb::_IsUnique(EDITVERB& rNewVerb)
  8341. {
  8342. // Get the friendly name of the new element
  8343. LPCTSTR pszNewDesc = _GetDescription(rNewVerb);
  8344. if (NULL == pszNewDesc)
  8345. {
  8346. // Executable must not exist
  8347. return FALSE;
  8348. }
  8349. // Scan existing elements for the same executable
  8350. for (UINT i=0; i < _nElements; ++i)
  8351. {
  8352. LPCTSTR pszDesc = _GetDescription(_pVerb[i]);
  8353. if (pszDesc && (StrCmpI(pszNewDesc, pszDesc) == 0))
  8354. {
  8355. // Match found, so free the friendly name for the new verb
  8356. SetStr(&rNewVerb.pszDesc, NULL);
  8357. // If the new item shows its icon on the button, make the duplicate
  8358. // do the same.
  8359. if (rNewVerb.fShowIcon)
  8360. {
  8361. _pVerb[i].fShowIcon = TRUE;
  8362. _nDefault = i;
  8363. }
  8364. return FALSE;
  8365. }
  8366. }
  8367. return TRUE;
  8368. }
  8369. //+-------------------------------------------------------------------------
  8370. // Some programs such as msothmed.exe act as stubs that redirect the edit
  8371. // command to the appropriate executable. This function returns true if
  8372. // the path contains the name of a known stub.
  8373. //--------------------------------------------------------------------------
  8374. BOOL CInternetToolbar::CEditVerb::_IsHtmlStub
  8375. (
  8376. LPCWSTR pszPath
  8377. )
  8378. {
  8379. BOOL fRet = FALSE;
  8380. // Get the MULTISZ list of known redirectors
  8381. TCHAR szRedir[MAX_PATH];
  8382. ZeroInit(szRedir, ARRAYSIZE(szRedir)); // Protect against non-multisz strings in the reg
  8383. DWORD dwType;
  8384. DWORD cb = sizeof(szRedir) - 4;
  8385. if (ERROR_SUCCESS != SHGetValue(HKEY_LOCAL_MACHINE, REGSTR_PATH_DEFAULT_HTML_EDITOR, L"Stubs", &dwType, szRedir, &cb))
  8386. {
  8387. // Nothing in registry, so default to ignore the Office redirector
  8388. StrCpyN(szRedir, L"msohtmed.exe\0", ARRAYSIZE(szRedir));
  8389. }
  8390. // See if the path contains the name of a redirectors
  8391. // Note that PathFindFileName doesn't work well for pathes with parameters so we just
  8392. // check for the exe name in the path)
  8393. for (LPTSTR p = szRedir; *p != NULL; p += lstrlen(p) + 1)
  8394. {
  8395. if (StrStrI(pszPath, p))
  8396. {
  8397. fRet = TRUE;
  8398. break;
  8399. }
  8400. }
  8401. return fRet;
  8402. }
  8403. //+-------------------------------------------------------------------------
  8404. // Adds a new edit verb. Returns a pointer to the new verb if it
  8405. // successfully added.
  8406. //--------------------------------------------------------------------------
  8407. CInternetToolbar::CEditVerb::EDITVERB* CInternetToolbar::CEditVerb::_Add
  8408. (
  8409. HKEY hkeyProgID, // location of of verb
  8410. BOOL fPermitOpenVerb, // permit open as well as edit verb
  8411. BOOL fCheckForOfficeApp,// redirect to office app
  8412. BOOL fShowIcon // if button face icon should be customized
  8413. )
  8414. {
  8415. EDITVERB* pNewVerb = NULL;
  8416. if (hkeyProgID)
  8417. {
  8418. BOOL fUseOpenVerb = FALSE;
  8419. //
  8420. // See if an appropriate verb exists.
  8421. //
  8422. TCHAR szCommand[MAX_PATH];
  8423. HRESULT hr = AssocQueryStringByKey(0, ASSOCSTR_COMMAND, hkeyProgID, L"edit", szCommand, (LPDWORD)MAKEINTRESOURCE(SIZECHARS(szCommand)));
  8424. if (FAILED(hr) && fPermitOpenVerb)
  8425. {
  8426. hr = AssocQueryStringByKey(0, ASSOCSTR_COMMAND, hkeyProgID, NULL, szCommand, (LPDWORD)MAKEINTRESOURCE(SIZECHARS(szCommand)));
  8427. if (SUCCEEDED(hr))
  8428. {
  8429. fUseOpenVerb = TRUE;
  8430. }
  8431. }
  8432. // If no verb or if this is the office redirector, ignore this progid
  8433. // Otherwise we can get two entries that do the same thing.
  8434. if (FAILED(hr) || _IsHtmlStub(szCommand))
  8435. {
  8436. RegCloseKey(hkeyProgID);
  8437. return NULL;
  8438. }
  8439. if (fCheckForOfficeApp)
  8440. {
  8441. ASSERT(*szCommand);
  8442. //
  8443. // HACK: Office2000 needs us to call a special proxy to get around thier DDE bugs and
  8444. // to check the HTML document for the name of the original document. These problems
  8445. // should be fixed in the apps themselves.
  8446. //
  8447. // So if this is an office app, we will redirect to the appropriate progid. Note that
  8448. // we don't need to do this if a progid was from the html meta tag because this progid
  8449. // already supports the proxy.
  8450. //
  8451. struct OfficeHackery {LPCWSTR pszApp; LPCWSTR pszProgID;};
  8452. // Must not have been a progid passed in.
  8453. static const OfficeHackery exeToProgID[] =
  8454. {
  8455. {L"winword", L"Word.Document"},
  8456. {L"excel", L"Excel.Sheet"},
  8457. {L"powerpnt", L"PowerPoint.Slide"},
  8458. {L"msaccess", L"Access.Application"},
  8459. {L"frontpg", L"FrontPage.Editor.Document"},
  8460. };
  8461. for (int i=0; i < ARRAYSIZE(exeToProgID); ++i)
  8462. {
  8463. if (StrStrI(szCommand, exeToProgID[i].pszApp))
  8464. {
  8465. // Match found!
  8466. HKEY hkeyOffice = NULL;
  8467. if (SUCCEEDED(AssocQueryKey(0, ASSOCKEY_SHELLEXECCLASS, exeToProgID[i].pszProgID, NULL, &hkeyOffice)))
  8468. {
  8469. // Redirect to the office progid
  8470. RegCloseKey(hkeyProgID);
  8471. hkeyProgID = hkeyOffice;
  8472. // The office apps always use the open verb
  8473. fUseOpenVerb = TRUE;
  8474. // The icon is shown on the button face for office apps
  8475. fShowIcon = TRUE;
  8476. }
  8477. break;
  8478. }
  8479. }
  8480. }
  8481. EDITVERB newVerb = {0};
  8482. newVerb.hkeyProgID = hkeyProgID;
  8483. newVerb.fUseOpenVerb = fUseOpenVerb;
  8484. newVerb.fShowIcon = fShowIcon;
  8485. // Ignore it if we have another verb to the same exe.
  8486. if (!_IsUnique(newVerb))
  8487. {
  8488. RegCloseKey(hkeyProgID);
  8489. }
  8490. else
  8491. {
  8492. EDITVERB* pVerbsNew;
  8493. if (_pVerb == NULL)
  8494. {
  8495. pVerbsNew = (EDITVERB*)LocalAlloc(LPTR, sizeof(EDITVERB));
  8496. }
  8497. else
  8498. {
  8499. pVerbsNew = (EDITVERB*)LocalReAlloc(_pVerb, (_nElements+1) * sizeof(EDITVERB), LMEM_MOVEABLE | LMEM_ZEROINIT);
  8500. }
  8501. if (pVerbsNew == NULL)
  8502. {
  8503. RegCloseKey(hkeyProgID);
  8504. }
  8505. else
  8506. {
  8507. _pVerb = pVerbsNew;
  8508. pNewVerb = &_pVerb[_nElements];
  8509. *pNewVerb = newVerb;
  8510. //
  8511. // If the description of the executable matches that of the default editor, make
  8512. // it our default edit verb. If we are not checking for the office app, we
  8513. // can assume that this verb was from a progid in an html file and we will also
  8514. // make it our default.
  8515. //
  8516. LPCWSTR pszDefDesc = _GetDefaultEditor();
  8517. LPCWSTR pszNewDesc = _GetDescription(*pNewVerb);
  8518. if (!fCheckForOfficeApp ||
  8519. (pszDefDesc && pszNewDesc && StrCmp(pszDefDesc, pNewVerb->pszDesc) == 0))
  8520. {
  8521. _nDefault = _nElements;
  8522. }
  8523. ++_nElements;
  8524. }
  8525. }
  8526. }
  8527. return pNewVerb;
  8528. }
  8529. //+-------------------------------------------------------------------------
  8530. // Adds a new edit verb. Returns TRUE if a verb was successfully added.
  8531. //--------------------------------------------------------------------------
  8532. BOOL CInternetToolbar::CEditVerb::Add
  8533. (
  8534. LPTSTR pszProgID // program id or file extension associated with verb
  8535. )
  8536. {
  8537. ASSERT(pszProgID);
  8538. BOOL fRet = FALSE;
  8539. BOOL fFileExt = (pszProgID[0] == TEXT('.'));
  8540. //
  8541. // Open the associated reg key and try to add it to our list of verbs
  8542. //
  8543. BOOL fUseOpenVerb = FALSE;
  8544. HKEY hkeyProgID = NULL;
  8545. BOOL fPermitOpenVerb = !fFileExt;
  8546. BOOL fShowIcon = !fFileExt; // If a progid was passed in, we will show the icon on the button face
  8547. if (SUCCEEDED(AssocQueryKey(0, ASSOCKEY_SHELLEXECCLASS, pszProgID, NULL, &hkeyProgID)))
  8548. {
  8549. EDITVERB* pNewVerb = _Add(hkeyProgID, fPermitOpenVerb, fFileExt, fShowIcon);
  8550. if (pNewVerb)
  8551. {
  8552. fRet = TRUE;
  8553. }
  8554. }
  8555. //
  8556. // If a file extension was passed in, we also add the alternative editors from the
  8557. // OpenWithList
  8558. //
  8559. if (fFileExt)
  8560. {
  8561. WCHAR szOpenWith[MAX_PATH];
  8562. StrCpyN(szOpenWith, pszProgID, ARRAYSIZE(szOpenWith));
  8563. StrCatBuff(szOpenWith, L"\\OpenWithList", ARRAYSIZE(szOpenWith));
  8564. HKEY hkeyOpenWithList;
  8565. // See if there is an OpenWithList
  8566. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CLASSES_ROOT, szOpenWith, 0, KEY_READ, &hkeyOpenWithList))
  8567. {
  8568. DWORD dwIndex = 0;
  8569. DWORD dwSize = ARRAYSIZE(szOpenWith);
  8570. HKEY hkeyOpenWith = NULL;
  8571. while (ERROR_SUCCESS == RegEnumKeyEx(hkeyOpenWithList, dwIndex, szOpenWith, &dwSize, NULL, NULL, NULL, NULL))
  8572. {
  8573. if (_GetAppKey(szOpenWith, &hkeyOpenWith))
  8574. {
  8575. // We only permit the edit verbs from here
  8576. EDITVERB* pNewVerb = _Add(hkeyOpenWith, FALSE, TRUE, FALSE);
  8577. if (pNewVerb)
  8578. {
  8579. fRet = TRUE;
  8580. }
  8581. ++dwIndex;
  8582. // Note that we don't close hkeyOpenWith here. It is either closed if it was not added, or
  8583. // it will be closed later.
  8584. }
  8585. else
  8586. {
  8587. // Invalid entry, so try to fix it (may be old format):
  8588. //
  8589. // In IE5.0 we use to store the friendly names of apps in the openwithlist. For shell compatibility, we need
  8590. // to convert these entries to store the exe name instead:
  8591. //
  8592. // ----> permanent entries are stored un HKCR
  8593. // HKCR
  8594. // \.Ext
  8595. // \OpenWithList
  8596. // \app.exe
  8597. //
  8598. // ----> and applications or the system can write app association here
  8599. // \Applications
  8600. // \APP.EXE
  8601. // \shell...
  8602. // \foo.exe
  8603. // \shell...
  8604. //
  8605. if (ERROR_SUCCESS == RegOpenKeyEx(hkeyOpenWithList, szOpenWith, 0, KEY_READ, &hkeyOpenWith))
  8606. {
  8607. _AddToOpenWithList(hkeyOpenWith, L"edit", L".htm");
  8608. // Remove the invalid entry
  8609. if (ERROR_SUCCESS != SHDeleteKey(hkeyOpenWith, L""))
  8610. {
  8611. // NOTE (andrewgu): ie5.5 b#108551 - on locked-down nt5 this will fail
  8612. // and if dwIndex is not incremented, will result in an infinite loop.
  8613. dwIndex++;
  8614. }
  8615. RegCloseKey(hkeyOpenWith);
  8616. }
  8617. }
  8618. dwSize = ARRAYSIZE(szOpenWith);
  8619. }
  8620. RegCloseKey(hkeyOpenWithList);
  8621. }
  8622. //
  8623. // If a ".htm" or ".html" was passed in, add our default html editor
  8624. //
  8625. if ((StrCmpI(pszProgID, L".htm") == 0 || StrCmpI(pszProgID, L".html") == 0) &&
  8626. _GetDefaultEditor())
  8627. {
  8628. HKEY hkeyDefault;
  8629. if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_CURRENT_USER, REGSTR_PATH_DEFAULT_HTML_EDITOR, 0, KEY_READ, &hkeyDefault))
  8630. {
  8631. if (_Add(hkeyDefault, TRUE, TRUE, FALSE))
  8632. {
  8633. fRet = TRUE;
  8634. }
  8635. }
  8636. }
  8637. }
  8638. return fRet;
  8639. }
  8640. //+-------------------------------------------------------------------------
  8641. // Returns the tooltip for the default edit verb
  8642. //--------------------------------------------------------------------------
  8643. BOOL CInternetToolbar::CEditVerb::GetToolTip
  8644. (
  8645. LPTSTR pszToolTip,
  8646. UINT cchMax,
  8647. BOOL fStripAmpersands
  8648. )
  8649. {
  8650. if (_nElements == 0)
  8651. {
  8652. return FALSE;
  8653. }
  8654. // Use the menu text for the tooltip.
  8655. _FormatMenuText(_nDefault);
  8656. // Copy text stripping out any ampersands
  8657. LPWSTR pszDest = pszToolTip;
  8658. LPWSTR pszSrc = _GetVerb(_nDefault).pszMenuText;
  8659. if (0 < cchMax)
  8660. {
  8661. // Leave room for the null terminator
  8662. while (0 < --cchMax)
  8663. {
  8664. // strip out '&'
  8665. if (fStripAmpersands)
  8666. {
  8667. while (*pszSrc == L'&')
  8668. {
  8669. ++pszSrc;
  8670. }
  8671. }
  8672. if ( !(*pszDest++ = *pszSrc++) )
  8673. {
  8674. --pszDest;
  8675. break;
  8676. }
  8677. }
  8678. if (0 == cchMax)
  8679. *pszDest = L'\0';
  8680. ASSERT(*pszDest == 0);
  8681. //
  8682. // In some locals, the accelerator is identified in brackets at the
  8683. // end of the string, so if we strip ampersands, we strip these too.
  8684. //
  8685. if (fStripAmpersands && --pszDest >= pszToolTip && *pszDest == L')')
  8686. {
  8687. while (--pszDest >= pszToolTip)
  8688. {
  8689. if (*pszDest == L'(')
  8690. {
  8691. *pszDest = L'\0';
  8692. break;
  8693. }
  8694. }
  8695. }
  8696. }
  8697. return TRUE;
  8698. }
  8699. //+-------------------------------------------------------------------------
  8700. // "Lazy-fetches" the verb info, and returns the desired info.
  8701. //--------------------------------------------------------------------------
  8702. CInternetToolbar::CEditVerb::EDITVERB& CInternetToolbar::CEditVerb::_GetVerb(UINT nIndex)
  8703. {
  8704. ASSERT(nIndex < _nElements);
  8705. // We fetch the info when first asked for it.
  8706. if (!_pVerb[nIndex].fInit)
  8707. {
  8708. _FetchInfo(nIndex);
  8709. _pVerb[nIndex].fInit = TRUE;
  8710. }
  8711. return _pVerb[nIndex];
  8712. }
  8713. //+-------------------------------------------------------------------------
  8714. // Gets the name of the app associated with the verb.
  8715. //--------------------------------------------------------------------------
  8716. LPCTSTR CInternetToolbar::CEditVerb::_GetDescription(EDITVERB& rVerb)
  8717. {
  8718. // If we already have a description, we are done
  8719. if (NULL == rVerb.pszDesc)
  8720. {
  8721. ASSERT(rVerb.hkeyProgID);
  8722. TCHAR sz[MAX_PATH];
  8723. if (SUCCEEDED(AssocQueryStringByKey(ASSOCF_VERIFY, ASSOCSTR_FRIENDLYAPPNAME, rVerb.hkeyProgID,
  8724. rVerb.fUseOpenVerb ? NULL : L"edit", sz, (LPDWORD)MAKEINTRESOURCE(SIZECHARS(sz)))))
  8725. {
  8726. rVerb.pszDesc = StrDup(sz);
  8727. if (rVerb.pszDesc)
  8728. {
  8729. // Remove preceeding and trailing blanks
  8730. PathRemoveBlanks(rVerb.pszDesc);
  8731. }
  8732. }
  8733. }
  8734. return rVerb.pszDesc;
  8735. }
  8736. //+-------------------------------------------------------------------------
  8737. // Reads the info associated with the progid at the given index. This
  8738. // function allows us to do a lazy fetch of the info when requested.
  8739. //--------------------------------------------------------------------------
  8740. void CInternetToolbar::CEditVerb::_FetchInfo(UINT nIndex)
  8741. {
  8742. ASSERT(nIndex < _nElements);
  8743. ASSERT(_pVerb[nIndex].hkeyProgID != NULL);
  8744. EDITVERB& rVerb = _pVerb[nIndex];
  8745. //
  8746. // Get the path to the edit verb's exe
  8747. //
  8748. if (_GetExePath(rVerb))
  8749. {
  8750. ASSERT(rVerb.pszExe);
  8751. // Note that we fetched the friendly name earlier
  8752. ASSERT(rVerb.pszDesc);
  8753. // Now get the icon
  8754. rVerb.iIcon = Shell_GetCachedImageIndex(rVerb.pszExe, 0, 0);
  8755. }
  8756. else
  8757. {
  8758. rVerb.iIcon = -1;
  8759. }
  8760. }
  8761. //+-------------------------------------------------------------------------
  8762. // SetMSAAMenuInfo()
  8763. //
  8764. // Fills in MSAAMenuInfo part of EDITVERB from the other fields of the rVerb
  8765. //--------------------------------------------------------------------------
  8766. void CInternetToolbar::CEditVerb::_SetMSAAMenuInfo( EDITVERB& rVerb )
  8767. {
  8768. #ifdef UNICODE
  8769. // If we're UNICODE, we can just refer to the m_pName of the MenuEntry itself...
  8770. rVerb.m_MSAA.m_CharLen = lstrlen( rVerb.pszMenuText );
  8771. rVerb.m_MSAA.m_pWStr = rVerb.pszMenuText;
  8772. #else // UNICODE
  8773. // If we're ANSI, need to create a UNICODE string for the MSAA text...
  8774. // Call MultiByteToWideChar first with 0 to get the size needed. (Assumes
  8775. // m_pName is ASCII NUL terminated - cChars will include the terminating NUL)
  8776. int cChars = MultiByteToWideChar( CP_ACP, 0, rVerb.pszMenuText, -1, NULL, 0 );
  8777. // Don't want to include NUL in character length, so subtract one...
  8778. rVerb.m_MSAA.m_CharLen = cChars - 1;
  8779. // Now call MultiByteToWideChar to do the conversion.
  8780. // MultiByteToWideChar adds the terminating WIDE-NUL for us, so we don't have to
  8781. // add it explicitly...
  8782. rVerb.m_MSAA.m_pWStr = new WCHAR [ cChars ];
  8783. if (rVerb.m_MSAA.m_pWStr)
  8784. {
  8785. // Note - we don't delete[] the above allocated memory in this sample
  8786. // code because we know that in this case it will be reclaimed by the system on
  8787. // exit and won't give a leak.
  8788. MultiByteToWideChar( CP_ACP, 0, rVerb.pszMenuText, -1, rVerb.m_MSAA.m_pWStr, cChars );
  8789. }
  8790. #endif // UNICODE
  8791. // Finally, add MSAAINFO signature...
  8792. rVerb.m_MSAA.m_MSAASig = MSAA_MENU_SIG;
  8793. }
  8794. //+-------------------------------------------------------------------------
  8795. // ClearMSAAMenuInfo()
  8796. //
  8797. // Clean up MSAAMenuInfo - specifically, release the allocated
  8798. // UNICODE string, if appropriate...
  8799. //--------------------------------------------------------------------------
  8800. void CInternetToolbar::CEditVerb::_ClearMSAAMenuInfo( EDITVERB& rVerb )
  8801. {
  8802. // Paranoia - clear signature...
  8803. rVerb.m_MSAA.m_MSAASig = 0;
  8804. #ifdef UNICODE
  8805. // We're unicode - nothing to do, since we didn't allocate anything.
  8806. #else // UNICODE
  8807. // We're ANSI - release allocated UNICODE string...
  8808. delete [] rVerb.m_MSAA.m_pWStr;
  8809. #endif // UNICODE
  8810. }
  8811. //+-------------------------------------------------------------------------
  8812. // Shows the edit pop-up menu.
  8813. //--------------------------------------------------------------------------
  8814. BOOL CInternetToolbar::CEditVerb::ShowEditMenu(POINT pt, HWND hwnd, LPTSTR pszURL)
  8815. {
  8816. BOOL bRet = FALSE;
  8817. HMENU hmEdit = CreatePopupMenu();
  8818. if (hmEdit)
  8819. {
  8820. UINT idCmd = FCIDM_EDITFIRST;
  8821. UINT nMax = FCIDM_EDITLAST - FCIDM_EDITFIRST;
  8822. // Add each verb to the menu
  8823. for (UINT i=0; i<_nElements && i < nMax; ++i)
  8824. {
  8825. EDITVERB& rVerb = _GetVerb(i);
  8826. _FormatMenuText(i);
  8827. rVerb.idCmd = idCmd;
  8828. AppendMenu(hmEdit, MF_OWNERDRAW, idCmd, (LPCTSTR) &rVerb );
  8829. // Fix up MSAAMenuInfo part...
  8830. _SetMSAAMenuInfo( rVerb );
  8831. ++idCmd;
  8832. }
  8833. // Temporarily subclass the hwnd to intercept the owner-draw messages
  8834. if (SetProp(hwnd, SZ_EDITVERB_PROP, this))
  8835. {
  8836. ASSERT(!_lpfnOldWndProc);
  8837. _lpfnOldWndProc = (WNDPROC) SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR) _WndProc);
  8838. idCmd = ITBar_TrackPopupMenuEx(hmEdit, TPM_RETURNCMD, pt.x, pt.y, hwnd, NULL);
  8839. SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)_lpfnOldWndProc);
  8840. _lpfnOldWndProc = NULL;
  8841. RemoveProp(hwnd, SZ_EDITVERB_PROP);
  8842. if (InRange(idCmd, FCIDM_EDITFIRST, FCIDM_EDITLAST))
  8843. {
  8844. // Execute the selected edit verb
  8845. _Edit(pszURL, idCmd - FCIDM_EDITFIRST);
  8846. }
  8847. }
  8848. DestroyMenu(hmEdit);
  8849. }
  8850. return bRet;
  8851. }
  8852. //+-------------------------------------------------------------------------
  8853. // Creates a menu string from the progid's description
  8854. //--------------------------------------------------------------------------
  8855. void CInternetToolbar::CEditVerb::_FormatMenuText(UINT nIndex)
  8856. {
  8857. ASSERT(nIndex < _nElements);
  8858. EDITVERB& rVerb = _GetVerb(nIndex);
  8859. if (rVerb.pszMenuText == NULL)
  8860. {
  8861. if (_GetDescription(rVerb))
  8862. {
  8863. TCHAR szFormat[100];
  8864. TCHAR szMenuText[200];
  8865. MLLoadString(IDS_EDITWITH, szFormat, ARRAYSIZE(szFormat));
  8866. wnsprintf(szMenuText, ARRAYSIZE(szMenuText), szFormat, rVerb.pszDesc);
  8867. SetStr(&((EDITVERB&)rVerb).pszMenuText, szMenuText);
  8868. }
  8869. else
  8870. {
  8871. // Things are really messed up
  8872. ASSERT(FALSE);
  8873. SetStr(&((EDITVERB&)rVerb).pszMenuText, TEXT(""));
  8874. }
  8875. }
  8876. }
  8877. //+-------------------------------------------------------------------------
  8878. // Executes the edit verb indicated by nIndex.
  8879. //--------------------------------------------------------------------------
  8880. void CInternetToolbar::CEditVerb::_Edit
  8881. (
  8882. LPCTSTR pszURL, // url assocated with the verb
  8883. UINT nIndex // verb to execute
  8884. )
  8885. {
  8886. ASSERT(pszURL);
  8887. if (nIndex >= _nElements)
  8888. {
  8889. return;
  8890. }
  8891. EDITVERB& rVerb = _pVerb[nIndex];
  8892. int fMask = SEE_MASK_CLASSKEY;
  8893. SHELLEXECUTEINFO sei = {0};
  8894. TCHAR szCacheFileName[MAX_PATH + MAX_URL_STRING + 2];
  8895. memset(szCacheFileName, 0, sizeof(szCacheFileName));
  8896. if (PathIsURL(pszURL))
  8897. {
  8898. // We pass the url if the app has register that it wants this
  8899. if ((WhichPlatform() == PLATFORM_BROWSERONLY) && DoesAppWantUrl(rVerb.pszExe))
  8900. {
  8901. //
  8902. // Old versions of shell32 (PLATFORM_BROWSERONLY) ignore the SEE_MASK_FILEANDURL
  8903. // flag, so on these platforms we check ourselves to see if the app
  8904. // wants the url instead of the cache file name.
  8905. //
  8906. StrCpyN(szCacheFileName, pszURL, ARRAYSIZE(szCacheFileName));
  8907. sei.lpFile = szCacheFileName;
  8908. }
  8909. else
  8910. {
  8911. // (reinerf)
  8912. // Some apps (FrontPad, Office99, etc) want the URL passed to
  8913. // them instead of the cache filename. We therefore create a string
  8914. // that has the URL name after the null:
  8915. //
  8916. // "CacheFileName/0UrlName"
  8917. //
  8918. // and pass it as the lpFile parameter to shellexecute.
  8919. // We also pass SEE_MASK_FILEANDURL, so shellexecute can
  8920. // recognize this case.
  8921. //
  8922. int iLength;
  8923. if (FAILED(URLToCacheFile(pszURL, szCacheFileName, ARRAYSIZE(szCacheFileName))))
  8924. {
  8925. // Frontpage express crashes if we pass a null file name, so if the app doesn't
  8926. // prefer the url instead, we bail.
  8927. if (!DoesAppWantUrl(rVerb.pszExe))
  8928. {
  8929. return;
  8930. }
  8931. }
  8932. iLength = lstrlen(szCacheFileName);
  8933. // copy in the URL name
  8934. StrCpyN(&szCacheFileName[iLength + 1], pszURL, ARRAYSIZE(szCacheFileName) - (iLength + 1));
  8935. // add the mask so shellexecute knows to check for the URL, if necessary.
  8936. fMask |= SEE_MASK_FILEANDURL;
  8937. sei.lpFile = szCacheFileName;
  8938. }
  8939. }
  8940. else
  8941. {
  8942. // Not a URL, so pass the filename
  8943. StrCpyN(szCacheFileName, pszURL, ARRAYSIZE(szCacheFileName));
  8944. sei.lpFile = szCacheFileName;
  8945. }
  8946. // Hack for IE5 bug 50033 - Can remove when fpxpress fixes mru buffer overrun
  8947. _GetExePath(rVerb);
  8948. if(StrStr(rVerb.pszExe, TEXT("fpxpress.exe")) != NULL)
  8949. szCacheFileName[256] = TEXT('\0');
  8950. sei.cbSize = sizeof(SHELLEXECUTEINFO);
  8951. sei.fMask = fMask;
  8952. sei.hwnd = NULL;
  8953. sei.lpVerb = rVerb.fUseOpenVerb ? NULL : TEXT("edit");
  8954. // sei.lpFile = szCacheFileName;
  8955. // sei.lpParameters = NULL;
  8956. sei.lpDirectory = NULL;
  8957. sei.nShow = SW_SHOWNORMAL;
  8958. sei.hInstApp = NULL;
  8959. sei.hkeyClass= rVerb.hkeyProgID;
  8960. //
  8961. // The office guys want us to call a special proxy to get around some DDE problems
  8962. // and to sniff the html file for the original document name. Hackers! So let's
  8963. // see if it is registered.
  8964. //
  8965. HKEY hkeyProxy = NULL;
  8966. if (ERROR_SUCCESS == RegOpenKeyEx(rVerb.hkeyProgID, TEXT("HTML Handler"), 0, KEY_READ, &hkeyProxy))
  8967. {
  8968. DWORD cch;
  8969. if (SUCCEEDED(AssocQueryStringByKey(0, ASSOCSTR_COMMAND, hkeyProxy, L"edit", NULL, &cch)))
  8970. {
  8971. sei.lpVerb = L"edit";
  8972. sei.hkeyClass = hkeyProxy;
  8973. }
  8974. else if (SUCCEEDED(AssocQueryStringByKey(0, ASSOCSTR_COMMAND, hkeyProxy, NULL, NULL, &cch)))
  8975. {
  8976. sei.lpVerb = NULL;
  8977. sei.hkeyClass = hkeyProxy;
  8978. }
  8979. }
  8980. ShellExecuteEx(&sei);
  8981. if (hkeyProxy)
  8982. {
  8983. RegCloseKey(hkeyProxy);
  8984. }
  8985. }
  8986. //+-------------------------------------------------------------------------
  8987. // This window procedure intercepts owner-draw menu messages when the edit
  8988. // pop-up menu is displayed.
  8989. //--------------------------------------------------------------------------
  8990. LRESULT CALLBACK CInternetToolbar::CEditVerb::_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  8991. {
  8992. CEditVerb* pThis = (CEditVerb*)GetProp(hwnd, SZ_EDITVERB_PROP);
  8993. if (!pThis)
  8994. return DefWindowProcWrap(hwnd, uMsg, wParam, lParam);
  8995. switch(uMsg)
  8996. {
  8997. case WM_DRAWITEM:
  8998. case WM_MEASUREITEM:
  8999. {
  9000. UINT idCmd;
  9001. switch (uMsg)
  9002. {
  9003. case WM_DRAWITEM:
  9004. idCmd = ((EDITVERB*)((DRAWITEMSTRUCT*)lParam)->itemData)->idCmd;
  9005. break;
  9006. case WM_MEASUREITEM:
  9007. idCmd = ((EDITVERB*)((MEASUREITEMSTRUCT*)lParam)->itemData)->idCmd;
  9008. break;
  9009. }
  9010. if (InRange(idCmd, FCIDM_EDITFIRST, FCIDM_EDITLAST))
  9011. {
  9012. // do our own measuring
  9013. UINT index = idCmd - FCIDM_EDITFIRST;
  9014. const EDITVERB& rVerb = pThis->_GetVerb(index);
  9015. // We don't want the same accelerator on all items,
  9016. // so remove underlines
  9017. WCHAR wzBuf[MAX_PATH];
  9018. UINT cchMax = ARRAYSIZE(wzBuf);
  9019. LPWSTR pszTo = wzBuf;
  9020. LPWSTR pszFrom = rVerb.pszMenuText;
  9021. if (pszFrom)
  9022. {
  9023. while (0 < --cchMax)
  9024. {
  9025. if (*pszFrom == L'&')
  9026. {
  9027. pszFrom++;
  9028. continue;
  9029. }
  9030. if ( !(*pszTo++ = *pszFrom++) )
  9031. {
  9032. --pszTo;
  9033. break;
  9034. }
  9035. }
  9036. if (0 == cchMax)
  9037. *pszTo = L'\0';
  9038. //
  9039. // In some locals, the accelerator is identified in brackets at the
  9040. // end of the string, so if we strip ampersands, we strip these too.
  9041. //
  9042. if (--pszTo >= wzBuf && *pszTo == L')')
  9043. {
  9044. while (--pszTo >= wzBuf)
  9045. {
  9046. if (*pszTo == L'(')
  9047. {
  9048. *pszTo = L'\0';
  9049. break;
  9050. }
  9051. }
  9052. }
  9053. }
  9054. else
  9055. {
  9056. wzBuf[0] = 0;
  9057. }
  9058. switch (uMsg)
  9059. {
  9060. case WM_MEASUREITEM:
  9061. MeasureMenuItem((MEASUREITEMSTRUCT *)lParam, wzBuf);
  9062. break;
  9063. case WM_DRAWITEM:
  9064. int iIcon = (rVerb.iIcon != -1) ? rVerb.iIcon : 0;
  9065. DrawMenuItem((LPDRAWITEMSTRUCT)lParam, wzBuf, iIcon);
  9066. break;
  9067. }
  9068. }
  9069. }
  9070. default:
  9071. return CallWindowProc(pThis->_lpfnOldWndProc, hwnd, uMsg, wParam, lParam);
  9072. }
  9073. return 0L;
  9074. }
  9075. #endif // EDIT_HACK