Leaked source code of windows server 2003
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.

8025 lines
208 KiB

  1. //
  2. // tipbar.cpp
  3. //
  4. #include "private.h"
  5. #include "globals.h"
  6. #include <initguid.h>
  7. #include "tipbar.h"
  8. #include "helpers.h"
  9. #include "xstring.h"
  10. #include "commctrl.h"
  11. #include "resource.h"
  12. #include "inatlib.h"
  13. #include "thdutil.h"
  14. #include "catutil.h"
  15. #include "immxutil.h"
  16. #include "utbmenu.h"
  17. #include "balloon.h"
  18. #include "cregkey.h"
  19. #include "cuimenu.h"
  20. #include "cuishadw.h"
  21. #include "cuischem.h"
  22. #include "cmydc.h"
  23. #include "intlmenu.h"
  24. #include "utbtray.h"
  25. #include "catenum.h"
  26. #include "asynccal.h"
  27. #include "fontlink.h"
  28. #include "cresstr.h"
  29. #include "nuiinat.h"
  30. #include "tlapi.h"
  31. #include "cuiutil.h"
  32. #include "cuischem.h"
  33. #include "cuitip.h"
  34. #include "utbdlgs.h"
  35. #include <shlapip.h>
  36. #include "deskband.h"
  37. #include "lmcons.h" // for UNLEN
  38. #include "sddl.h"
  39. #include "winuserp.h"
  40. const DWORD TF_LBESF_GLOBAL = 0x0001;
  41. const DWORD TF_LBSMI_FILTERCURRENTTHREAD = 0x0001;
  42. extern HINSTANCE g_hInst;
  43. const TCHAR c_szTipbarWndClass[] = TEXT("TipbarWndClass");
  44. const TCHAR c_szTipbarWndName[] = TEXT("Cicload Tipbar");
  45. const TCHAR c_szCicKey[] = TEXT("SOFTWARE\\Microsoft\\CTF\\");
  46. const TCHAR c_szUTBKey[] = TEXT("SOFTWARE\\Microsoft\\CTF\\MSUTB\\");
  47. const TCHAR c_szSkipRedrawHKL[] = TEXT("SOFTWARE\\Microsoft\\CTF\\MSUTB\\SkipRedrawHKL");
  48. const TCHAR c_szShowTipbar[] = TEXT("ShowTipbar");
  49. const TCHAR c_szDontShowCloseLangBarDlg[] = TEXT("DontShowCloseLangBarDlg");
  50. const TCHAR c_szDontShowMinimizeLangBarDlg[] = TEXT("DontShowMinimizeLangBarDlg");
  51. const TCHAR c_szShowDebugMenu[] = TEXT("ShowDebugMenu");
  52. const TCHAR c_szShowDeskBand[] = TEXT("ShowDeskBand");
  53. const TCHAR c_szNewLook[] = TEXT("NewLook");
  54. const TCHAR c_szIntelliSense[] = TEXT("IntelliSense");
  55. const TCHAR c_szTimeOutNonIntentional[] = TEXT("TimeOutNonIntentional");
  56. const TCHAR c_szTimeOutIntentional[] = TEXT("TimeOutIntentional");
  57. const TCHAR c_szShowCloseMenu[] = TEXT("ShowCloseMenu");
  58. const TCHAR c_szShowMinimizedBalloon[] = TEXT("ShowMinimizedBalloon");
  59. const TCHAR c_szLeft[] = TEXT("Left");
  60. const TCHAR c_szTop[] = TEXT("Top");
  61. const TCHAR c_szExcludeCaptionButtons[] = TEXT("ExcludeCaptionButtons");
  62. const TCHAR c_szShowShadow[] = TEXT("ShowShadow");
  63. const TCHAR c_szTaskbarTheme[] = TEXT("TaskbarTheme");
  64. const TCHAR c_szVertical[] = TEXT("Vertical");
  65. // const TCHAR c_szMoveToTray[] = TEXT("MoveToTray");
  66. BOOL g_bNewLook = TRUE;
  67. BOOL g_bIntelliSense = FALSE;
  68. BOOL g_bShowTipbar = TRUE;
  69. BOOL g_bShowDebugMenu = FALSE;
  70. BOOL g_bShowCloseMenu = FALSE;
  71. BOOL g_bShowMinimizedBalloon = TRUE;
  72. BOOL g_bExcludeCaptionButtons = TRUE;
  73. BOOL g_bShowShadow = FALSE;
  74. BOOL g_bShowDeskBand = FALSE;
  75. BOOL g_nLeft = -1;
  76. BOOL g_nTop = -1;
  77. DWORD g_dwWndStyle = 0;
  78. DWORD g_dwChildWndStyle = 0;
  79. DWORD g_dwMenuStyle = 0;
  80. CTipbarWnd *g_pTipbarWnd;
  81. CTrayIconWnd *g_pTrayIconWnd;
  82. HWND g_hwndParent;
  83. BOOL g_bWinLogon = FALSE;
  84. BOOL g_fTaskbarTheme = TRUE;
  85. BOOL g_fVertical = FALSE;
  86. BOOL g_fInClosePopupTipbar = FALSE;
  87. BOOL g_fRTL = FALSE;
  88. const TCHAR c_szTimerElapseSTUBSTART[] = TEXT("TimerElapseSTUBSTART");
  89. const TCHAR c_szTimerElapseSTUBEND[] = TEXT("TimerElapseSTUBEND");
  90. const TCHAR c_szTimerElapseBACKTOALPHA[] = TEXT("TimerElapseBACKTOALPHA");
  91. const TCHAR c_szTimerElapseONTHREADITEMCHANGE[] = TEXT("TimerElapseONTHREADITEMCHANGE");
  92. const TCHAR c_szTimerElapseSETWINDOWPOS[] = TEXT("TimerElapseSETWINDOWPOS");
  93. const TCHAR c_szTimerElapseONUPDATECALLED[] = TEXT("TimerElapseONUPDATECALLED");
  94. const TCHAR c_szTimerElapseSYSCOLORCHANGED[] = TEXT("TimerElapseSYSCOLORCHANGED");
  95. const TCHAR c_szTimerElapseDISPLAYCHANGE[] = TEXT("TimerElapseDISPLAYCHANGE");
  96. const TCHAR c_szTimerElapseUPDATEUI[] = TEXT("TimerElapseUPDATEUI");
  97. const TCHAR c_szTimerElapseSHOWWINDOW[] = TEXT("TimerElapseSHOWWINDOW");
  98. const TCHAR c_szTimerElapseMOVETOTRAY[] = TEXT("TimerElapseMOVETOTRAY");
  99. const TCHAR c_szTimerElapseTRAYWNDONDELAYMSG[] = TEXT("TimerElapseTRAYWNDONDELAYMSG");
  100. const TCHAR c_szTimerElapseDOACCDEFAULTACTION[] = TEXT("TimerElapseDOACCDEFAULTACTION");
  101. const TCHAR c_szTimerElapseENSUREFOCUS[] = TEXT("TimerElapseENSUREFOCUS");
  102. const TCHAR c_szTimerElapseSHOWDESKBAND[] = TEXT("TimerElapseSHOWWDESKBAND");
  103. UINT g_uTimerElapseSTUBSTART = 100;
  104. UINT g_uTimerElapseSTUBEND = 2000;
  105. UINT g_uTimerElapseBACKTOALPHA = 3000;
  106. UINT g_uTimerElapseONTHREADITEMCHANGE = 200;
  107. UINT g_uTimerElapseSETWINDOWPOS = 100;
  108. UINT g_uTimerElapseONUPDATECALLED = 50; // Satori tune up 20,50,100 or 200
  109. UINT g_uTimerElapseSYSCOLORCHANGED = 20;
  110. UINT g_uTimerElapseDISPLAYCHANGE = 20;
  111. UINT g_uTimerElapseUPDATEUI = 70; // MSIME2002 JP needs 70ms.
  112. UINT g_uTimerElapseSHOWWINDOW = 50;
  113. UINT g_uTimerElapseMOVETOTRAY = 50;
  114. UINT g_uTimerElapseTRAYWNDONDELAYMSG = 50;
  115. UINT g_uTimerElapseDOACCDEFAULTACTION = 200;
  116. UINT g_uTimerElapseENSUREFOCUS = 50;
  117. UINT g_uTimerElapseSHOWDESKBAND = 3000;
  118. //
  119. // from bandobjs.cpp
  120. //
  121. extern UINT g_wmTaskbarCreated;
  122. //
  123. // from itemlist.cpp
  124. //
  125. extern UINT g_uTimeOutNonIntentional;
  126. extern UINT g_uTimeOutIntentional;
  127. extern UINT g_uTimeOutMax;
  128. //
  129. // SkipRedrawing Hack HKL list.
  130. //
  131. CStructArray<HKL> *g_prghklSkipRedrawing = NULL;
  132. void UninitSkipRedrawHKLArray();
  133. #define WM_LBWND_SHOWCONTEXTMENU (WM_USER + 1)
  134. // TM_LANGUAGEBAND is defined in "shell\inc\trayp.h"
  135. #define TM_LANGUAGEBAND WM_USER+0x105
  136. /* 142b6d42-955d-4488-97c0-b23b23e6b048 */
  137. const IID IID_PRIV_BUTTONITEM = {
  138. 0x142b6d42,
  139. 0x955d,
  140. 0x4488,
  141. {0x97, 0xc0, 0xb2, 0x3b, 0x23, 0xe6, 0xb0, 0x48}
  142. };
  143. /* 8dd1cc81-fca0-4dd5-b848-2b85732d2fc4 */
  144. const IID IID_PRIV_BITMAPBUTTONITEM = {
  145. 0x8dd1cc81,
  146. 0xfca0,
  147. 0x4dd5,
  148. {0xb8, 0x48, 0x2b, 0x85, 0x73, 0x2d, 0x2f, 0xc4}
  149. };
  150. /* 36b40e05-7b3e-4a4a-bda7-2249ba17d3c4 */
  151. const IID IID_PRIV_BITMAPITEM = {
  152. 0x36b40e05,
  153. 0x7b3e,
  154. 0x4a4a,
  155. {0xbd, 0xa7, 0x22, 0x49, 0xba, 0x17, 0xd3, 0xc4}
  156. };
  157. /* 68831a74-6f86-447a-b2b8-634250ac445e */
  158. const IID IID_PRIV_BALLOONITEM = {
  159. 0x68831a74,
  160. 0x6f86,
  161. 0x447a,
  162. {0xb2, 0xb8, 0x63, 0x42, 0x50, 0xac, 0x44, 0x5e}
  163. };
  164. //
  165. // from MSCTF.DLL.
  166. //
  167. extern "C" BOOL WINAPI TF_IsFullScreenWindowAcitvated();
  168. extern "C" DWORD WINAPI TF_CheckThreadInputIdle(DWORD dwThreadId, DWORD dwTimeOut);
  169. //
  170. // from intlmenu.cpp
  171. //
  172. extern BOOL IsFELangId(LANGID langid);
  173. //////////////////////////////////////////////////////////////////////////////
  174. //
  175. // predefined control buttons
  176. //
  177. //////////////////////////////////////////////////////////////////////////////
  178. static CTRLBTNMAP g_cbCtrlBtn[NUM_CTRLBUTTONS] = {
  179. {ID_CBTN_CAPSKEY, UIBUTTON_CENTER | UIBUTTON_VCENTER | UIBUTTON_TOGGLE,
  180. 0, 0, CTRL_ICONFROMRES | CTRL_TOGGLEBUTTON, {0x0, 0x0}},
  181. {ID_CBTN_KANAKEY, UIBUTTON_CENTER | UIBUTTON_VCENTER | UIBUTTON_TOGGLE,
  182. 0, 1, CTRL_ICONFROMRES | CTRL_TOGGLEBUTTON, {0x0, 0x0}},
  183. {ID_CBTN_MINIMIZE, UIBUTTON_CENTER | UIBUTTON_VCENTER,
  184. 1, 0, CTRL_USEMARLETT | CTRL_DISABLEONWINLOGON, {0x0030, 0x0000}},
  185. {ID_CBTN_EXTMENU, UIBUTTON_CENTER | UIBUTTON_VCENTER,
  186. 1, 1, CTRL_USEMARLETT | CTRL_DISABLEONWINLOGON, {0x0075, 0x0000}},
  187. };
  188. static CTRLBTNMAP g_cbCtrlBtnDeskBand[NUM_CTRLBUTTONS] = {
  189. {ID_CBTN_CAPSKEY, UIBUTTON_CENTER | UIBUTTON_VCENTER | UIBUTTON_TOGGLE,
  190. 0, 0, CTRL_ICONFROMRES | CTRL_TOGGLEBUTTON, {0x0, 0x0}},
  191. {ID_CBTN_KANAKEY, UIBUTTON_CENTER | UIBUTTON_VCENTER | UIBUTTON_TOGGLE,
  192. 0, 1, CTRL_ICONFROMRES | CTRL_TOGGLEBUTTON, {0x0, 0x0}},
  193. {ID_CBTN_RESTORE, UIBUTTON_CENTER | UIBUTTON_VCENTER,
  194. 1, 0, CTRL_USEMARLETT | CTRL_DISABLEONWINLOGON, {0x0032, 0x0000}},
  195. {ID_CBTN_EXTMENU, UIBUTTON_CENTER | UIBUTTON_VCENTER,
  196. 1, 1, CTRL_USEMARLETT | CTRL_DISABLEONWINLOGON, {0x0075, 0x0000}},
  197. };
  198. static int c_nColumnStart[] = {0, CX_COLUMN0, CX_COLUMN1};
  199. //////////////////////////////////////////////////////////////////////////////
  200. //
  201. // APIs
  202. //
  203. //////////////////////////////////////////////////////////////////////////////
  204. extern "C" BOOL WINAPI GetPopupTipbar(HWND hwndParent, DWORD dwFlags)
  205. {
  206. if ( !(dwFlags & UTB_GTI_WINLOGON) )
  207. {
  208. TurnOffSpeechIfItsOn( );
  209. }
  210. return GetTipbarInternal(hwndParent, UTB_GTI_POPUP | dwFlags, NULL);
  211. }
  212. BOOL GetTipbarInternal(HWND hwndParent, DWORD dwFlags, CDeskBand *pDeskBand)
  213. {
  214. DWORD dwSFSFlags;
  215. BOOL fPopup = (dwFlags & UTB_GTI_POPUP) ? TRUE : FALSE;
  216. g_bWinLogon = (dwFlags & UTB_GTI_WINLOGON) ? TRUE : FALSE;
  217. //
  218. // MSAA support
  219. //
  220. InitTipbarAcc();
  221. InitFromReg();
  222. if (!g_bShowTipbar)
  223. return NULL;
  224. //
  225. // we don't have to create TrayIconWnd under explorer's desk band.
  226. //
  227. if (fPopup)
  228. {
  229. g_pTrayIconWnd = new CTrayIconWnd();
  230. if (!g_pTrayIconWnd)
  231. return FALSE;
  232. g_pTrayIconWnd->CreateWnd();
  233. }
  234. g_pTipbarWnd = new CTipbarWnd(fPopup ? g_dwWndStyle : g_dwChildWndStyle);
  235. if (!g_pTipbarWnd)
  236. return FALSE;
  237. if (!g_pTipbarWnd->Initialize())
  238. return FALSE;
  239. g_pTipbarWnd->Init(!fPopup, pDeskBand);
  240. g_pTipbarWnd->CreateWnd(hwndParent);
  241. SetWindowText(g_pTipbarWnd->GetWnd(), TF_FLOATINGLANGBAR_WNDTITLE);
  242. DWORD dwPrevFlags = 0;
  243. if (!fPopup)
  244. {
  245. g_pTipbarWnd->GetLangBarMgr()->GetPrevShowFloatingStatus(&dwPrevFlags);
  246. g_pTipbarWnd->GetLangBarMgr()->ShowFloating(TF_SFT_DESKBAND);
  247. }
  248. g_pTipbarWnd->GetLangBarMgr()->GetShowFloatingStatus(&dwSFSFlags);
  249. g_pTipbarWnd->ShowFloating(dwSFSFlags);
  250. //
  251. // get the previous show floating status.
  252. // if it does not have TF_SFT_DESKBAND, the floating toolbar
  253. // was minimized.
  254. // if it has TF_SFT_DESKBAND, exploere just started. Then we don't
  255. // want to adjust the deskband and use the default size.
  256. // (Explorer remembers the position of the previous logon.)
  257. //
  258. if (!fPopup && (dwPrevFlags & TF_SFT_DESKBAND))
  259. g_pTipbarWnd->SetDeskbandSizeAdjusted();
  260. g_hwndParent = hwndParent;
  261. return TRUE;
  262. }
  263. extern "C" void WINAPI ClosePopupTipbar()
  264. {
  265. if (g_fInClosePopupTipbar)
  266. return;
  267. g_fInClosePopupTipbar = TRUE;
  268. if (g_pTipbarWnd)
  269. {
  270. g_pTipbarWnd->ClearDeskBandPointer();
  271. g_pTipbarWnd->DestroyWnd();
  272. g_pTipbarWnd->Release();
  273. g_pTipbarWnd = NULL;
  274. }
  275. if (g_pTrayIconWnd)
  276. {
  277. g_pTrayIconWnd->DestroyWnd();
  278. delete g_pTrayIconWnd;
  279. g_pTrayIconWnd = NULL;
  280. }
  281. UninitSkipRedrawHKLArray();
  282. g_fInClosePopupTipbar = FALSE;
  283. }
  284. //////////////////////////////////////////////////////////////////////////////
  285. //
  286. // misc func
  287. //
  288. //////////////////////////////////////////////////////////////////////////////
  289. extern "C" HRESULT WINAPI TF_GetGlobalCompartment(ITfCompartmentMgr **pCompMgr);
  290. //+---------------------------------------------------------------------------
  291. //
  292. // GetCompartment
  293. //
  294. //----------------------------------------------------------------------------
  295. HRESULT GetGlobalCompartment(REFGUID rguidComp, ITfCompartment **ppComp)
  296. {
  297. HRESULT hr = E_FAIL;
  298. ITfCompartmentMgr *pCompMgr = NULL;
  299. if (FAILED(hr = TF_GetGlobalCompartment(&pCompMgr)))
  300. {
  301. Assert(0);
  302. goto Exit;
  303. }
  304. if (SUCCEEDED(hr) && pCompMgr)
  305. {
  306. hr = pCompMgr->GetCompartment(rguidComp, ppComp);
  307. pCompMgr->Release();
  308. }
  309. else
  310. hr = E_FAIL;
  311. Exit:
  312. return hr;
  313. }
  314. //+---------------------------------------------------------------------------
  315. //
  316. // SetCompartmentDWORD
  317. //
  318. //----------------------------------------------------------------------------
  319. HRESULT SetGlobalCompartmentDWORD(REFGUID rguidComp, DWORD dw)
  320. {
  321. HRESULT hr;
  322. ITfCompartment *pComp;
  323. VARIANT var;
  324. if (SUCCEEDED(hr = GetGlobalCompartment(rguidComp, &pComp)))
  325. {
  326. var.vt = VT_I4;
  327. var.lVal = dw;
  328. hr = pComp->SetValue(0, &var);
  329. pComp->Release();
  330. }
  331. return hr;
  332. }
  333. //+---------------------------------------------------------------------------
  334. //
  335. // GetGlobalCompartmentDWORD
  336. //
  337. //----------------------------------------------------------------------------
  338. HRESULT GetGlobalCompartmentDWORD(REFGUID rguidComp, DWORD *pdw)
  339. {
  340. HRESULT hr;
  341. ITfCompartment *pComp;
  342. VARIANT var;
  343. *pdw = 0;
  344. if (SUCCEEDED(hr = GetGlobalCompartment(rguidComp, &pComp)))
  345. {
  346. if ((hr = pComp->GetValue(&var)) == S_OK)
  347. {
  348. Assert(var.vt == VT_I4);
  349. *pdw = var.lVal;
  350. }
  351. pComp->Release();
  352. }
  353. return hr;
  354. }
  355. //+---------------------------------------------------------------------------
  356. //
  357. // TurnOffSpeechIfItsOn
  358. //
  359. //----------------------------------------------------------------------------
  360. void TurnOffSpeechIfItsOn()
  361. {
  362. // turn off the mic here only if someone set speech on
  363. DWORD dw = 0;
  364. HRESULT hr = GetGlobalCompartmentDWORD(GUID_COMPARTMENT_SPEECH_OPENCLOSE, &dw);
  365. if (SUCCEEDED(hr) && dw > 0)
  366. {
  367. SetGlobalCompartmentDWORD(GUID_COMPARTMENT_SPEECH_OPENCLOSE, 0);
  368. }
  369. }
  370. //+---------------------------------------------------------------------------
  371. //
  372. // InitSkipRedrawHKLArray
  373. //
  374. //+---------------------------------------------------------------------------
  375. void InitSkipRedrawHKLArray()
  376. {
  377. CMyRegKey key;
  378. HKL *phkl;
  379. Assert(!g_prghklSkipRedrawing);
  380. g_prghklSkipRedrawing = new CStructArray<HKL>;
  381. if (!g_prghklSkipRedrawing)
  382. return;
  383. if (IsOnNT51())
  384. {
  385. phkl = g_prghklSkipRedrawing->Append(1);
  386. if (phkl)
  387. *phkl = (HKL)IntToPtr(0xe0010411);
  388. }
  389. if (key.Open(HKEY_LOCAL_MACHINE, c_szSkipRedrawHKL, KEY_READ) == S_OK)
  390. {
  391. char szValue[255];
  392. DWORD dwIndex = 0;
  393. while (key.EnumValue(dwIndex, szValue, ARRAYSIZE(szValue)) == S_OK)
  394. {
  395. if ((szValue[0] == '0') &&
  396. ((szValue[1] == 'X') || (szValue[1] == 'x')))
  397. {
  398. phkl = g_prghklSkipRedrawing->Append(1);
  399. if (phkl)
  400. *phkl = (HKL)IntToPtr(AsciiToNum(&szValue[2]));
  401. }
  402. dwIndex++;
  403. }
  404. }
  405. }
  406. //+---------------------------------------------------------------------------
  407. //
  408. // UninitSkipRedrawHKLArray
  409. //
  410. //+---------------------------------------------------------------------------
  411. void UninitSkipRedrawHKLArray()
  412. {
  413. if (!g_prghklSkipRedrawing)
  414. return;
  415. delete g_prghklSkipRedrawing;
  416. g_prghklSkipRedrawing = NULL;
  417. }
  418. //+---------------------------------------------------------------------------
  419. //
  420. // IsSkipRedrawHKL
  421. //
  422. //+---------------------------------------------------------------------------
  423. BOOL IsSkipRedrawHKL(HKL hkl)
  424. {
  425. int i;
  426. if (0x0411 != LANGID(LOWORD(HandleToLong(hkl))))
  427. return FALSE;
  428. if (!g_prghklSkipRedrawing)
  429. return FALSE;
  430. for (i = 0; i < g_prghklSkipRedrawing->Count(); i++)
  431. {
  432. HKL *phkl = g_prghklSkipRedrawing->GetPtr(i);
  433. if (phkl && (*phkl == hkl))
  434. return TRUE;
  435. }
  436. return FALSE;
  437. }
  438. //+---------------------------------------------------------------------------
  439. //
  440. // InitFromReg
  441. //
  442. //+---------------------------------------------------------------------------
  443. BOOL InitFromReg()
  444. {
  445. CMyRegKey key;
  446. CMyRegKey keyUTB;
  447. DWORD dwValue;
  448. LANGID langID = 0;
  449. if (key.Open(HKEY_CURRENT_USER, c_szCicKey, KEY_READ) == S_OK)
  450. {
  451. if (key.QueryValue(dwValue, c_szShowTipbar) == S_OK)
  452. g_bShowTipbar = dwValue ? TRUE : FALSE;
  453. }
  454. if (keyUTB.Open(HKEY_CURRENT_USER, c_szUTBKey, KEY_READ) == S_OK)
  455. {
  456. if (keyUTB.QueryValue(dwValue, c_szShowDebugMenu) == S_OK)
  457. g_bShowDebugMenu = dwValue ? TRUE : FALSE;
  458. if (keyUTB.QueryValue(dwValue, c_szNewLook) == S_OK)
  459. g_bNewLook = dwValue ? TRUE : FALSE;
  460. if (keyUTB.QueryValue(dwValue, c_szIntelliSense) == S_OK)
  461. g_bIntelliSense = dwValue ? TRUE : FALSE;
  462. if (keyUTB.QueryValue(dwValue, c_szShowCloseMenu) == S_OK)
  463. g_bShowCloseMenu = dwValue ? TRUE : FALSE;
  464. if (keyUTB.QueryValue(dwValue, c_szTimeOutNonIntentional) == S_OK)
  465. g_uTimeOutNonIntentional = dwValue * 1000;
  466. if (keyUTB.QueryValue(dwValue, c_szTimeOutIntentional) == S_OK)
  467. {
  468. g_uTimeOutIntentional = dwValue * 1000;
  469. g_uTimeOutMax = g_uTimeOutIntentional * 6;
  470. }
  471. if (keyUTB.QueryValue(dwValue, c_szShowMinimizedBalloon) == S_OK)
  472. g_bShowMinimizedBalloon = dwValue ? TRUE : FALSE;
  473. if (keyUTB.QueryValue(dwValue, c_szLeft) == S_OK)
  474. g_nLeft = dwValue;
  475. if (keyUTB.QueryValue(dwValue, c_szTop) == S_OK)
  476. g_nTop = dwValue;
  477. if (keyUTB.QueryValue(dwValue, c_szExcludeCaptionButtons) == S_OK)
  478. g_bExcludeCaptionButtons = dwValue ? TRUE : FALSE;
  479. if (keyUTB.QueryValue(dwValue, c_szShowShadow) == S_OK)
  480. g_bShowShadow = dwValue ? TRUE : FALSE;
  481. if (keyUTB.QueryValue(dwValue, c_szTaskbarTheme) == S_OK)
  482. g_fTaskbarTheme = dwValue ? TRUE : FALSE;
  483. if (keyUTB.QueryValue(dwValue, c_szVertical) == S_OK)
  484. g_fVertical = dwValue ? TRUE : FALSE;
  485. if (keyUTB.QueryValue(dwValue, c_szTimerElapseSTUBSTART) == S_OK)
  486. g_uTimerElapseSTUBSTART = dwValue;
  487. if (keyUTB.QueryValue(dwValue, c_szTimerElapseSTUBEND) == S_OK)
  488. g_uTimerElapseSTUBEND = dwValue;
  489. if (keyUTB.QueryValue(dwValue, c_szTimerElapseBACKTOALPHA) == S_OK)
  490. g_uTimerElapseBACKTOALPHA = dwValue;
  491. if (keyUTB.QueryValue(dwValue, c_szTimerElapseONTHREADITEMCHANGE) == S_OK)
  492. g_uTimerElapseONTHREADITEMCHANGE = dwValue;
  493. if (keyUTB.QueryValue(dwValue, c_szTimerElapseSETWINDOWPOS) == S_OK)
  494. g_uTimerElapseSETWINDOWPOS = dwValue;
  495. if (keyUTB.QueryValue(dwValue, c_szTimerElapseONUPDATECALLED) == S_OK)
  496. g_uTimerElapseONUPDATECALLED = dwValue;
  497. if (keyUTB.QueryValue(dwValue, c_szTimerElapseSYSCOLORCHANGED) == S_OK)
  498. g_uTimerElapseSYSCOLORCHANGED = dwValue;
  499. if (keyUTB.QueryValue(dwValue, c_szTimerElapseDISPLAYCHANGE) == S_OK)
  500. g_uTimerElapseDISPLAYCHANGE = dwValue;
  501. if (keyUTB.QueryValue(dwValue, c_szTimerElapseUPDATEUI) == S_OK)
  502. g_uTimerElapseUPDATEUI = dwValue;
  503. if (keyUTB.QueryValue(dwValue, c_szTimerElapseSHOWWINDOW) == S_OK)
  504. g_uTimerElapseSHOWWINDOW = dwValue;
  505. if (keyUTB.QueryValue(dwValue, c_szTimerElapseMOVETOTRAY) == S_OK)
  506. g_uTimerElapseMOVETOTRAY = dwValue;
  507. if (keyUTB.QueryValue(dwValue, c_szTimerElapseTRAYWNDONDELAYMSG) == S_OK)
  508. g_uTimerElapseTRAYWNDONDELAYMSG = dwValue;
  509. if (keyUTB.QueryValue(dwValue, c_szTimerElapseDOACCDEFAULTACTION) == S_OK)
  510. g_uTimerElapseDOACCDEFAULTACTION = dwValue;
  511. if (keyUTB.QueryValue(dwValue, c_szTimerElapseENSUREFOCUS) == S_OK)
  512. g_uTimerElapseENSUREFOCUS = dwValue;
  513. if (IsOnNT51() && keyUTB.QueryValue(dwValue, c_szShowDeskBand) == S_OK)
  514. g_bShowDeskBand = dwValue ? TRUE : FALSE;
  515. if (IsOnNT51() && keyUTB.QueryValue(dwValue, c_szTimerElapseSHOWDESKBAND) == S_OK)
  516. g_uTimerElapseSHOWDESKBAND = dwValue;
  517. }
  518. InitSkipRedrawHKLArray();
  519. if (g_bNewLook)
  520. {
  521. g_dwWndStyle = UIWINDOW_TOPMOST |
  522. // UIWINDOW_WSDLGFRAME |
  523. UIWINDOW_HASTOOLTIP |
  524. UIWINDOW_HABITATINWORKAREA |
  525. UIWINDOW_OFC10TOOLBAR |
  526. UIWINDOW_TOOLWINDOW;
  527. if (IsOnNT51())
  528. {
  529. g_dwWndStyle &= ~UIWINDOW_OFC10TOOLBAR;
  530. g_dwWndStyle |= UIWINDOW_WHISTLERLOOK;
  531. // g_dwWndStyle |= UIWINDOW_WSBORDER;
  532. }
  533. if (g_bShowShadow)
  534. g_dwWndStyle |= UIWINDOW_HASSHADOW;
  535. g_dwMenuStyle = UIWINDOW_TOPMOST |
  536. UIWINDOW_TOOLWINDOW |
  537. UIWINDOW_OFC10MENU |
  538. UIWINDOW_HASSHADOW |
  539. UIWINDOW_HABITATINSCREEN;
  540. }
  541. else
  542. {
  543. g_dwWndStyle = UIWINDOW_TOPMOST |
  544. UIWINDOW_HASTOOLTIP |
  545. UIWINDOW_WSDLGFRAME |
  546. UIWINDOW_HABITATINWORKAREA;
  547. g_dwMenuStyle = UIWINDOW_TOPMOST |
  548. UIWINDOW_WSDLGFRAME |
  549. UIWINDOW_HABITATINSCREEN;
  550. }
  551. g_dwChildWndStyle = UIWINDOW_CHILDWND;
  552. if (IsOnNT51())
  553. {
  554. g_dwChildWndStyle |= UIWINDOW_WHISTLERLOOK |
  555. UIWINDOW_HASTOOLTIP |
  556. UIWINDOW_NOMOUSEMSGFROMSETCURSOR;
  557. }
  558. langID = GetPlatformResourceLangID();
  559. if (PRIMARYLANGID(langID) == LANG_ARABIC || PRIMARYLANGID(langID) == LANG_HEBREW)
  560. {
  561. g_dwWndStyle |= UIWINDOW_LAYOUTRTL;
  562. g_dwChildWndStyle |= UIWINDOW_LAYOUTRTL;
  563. g_dwMenuStyle |= UIWINDOW_LAYOUTRTL;
  564. g_fRTL = TRUE;
  565. }
  566. return TRUE;
  567. }
  568. //+---------------------------------------------------------------------------
  569. //
  570. // GetTopLevelWindow
  571. //
  572. //+---------------------------------------------------------------------------
  573. HWND GetTopLevelWindow(HWND hwnd)
  574. {
  575. HWND hwndT,hwndRet;
  576. HWND hwndDsktop = GetDesktopWindow();
  577. hwndT = hwndRet = hwnd;
  578. while (hwndT && hwndT != hwndDsktop)
  579. {
  580. HWND hwndT0;
  581. hwndRet = hwndT;
  582. hwndT0 = GetParent(hwndT);
  583. if (IsOn98() && !hwndT0)
  584. {
  585. //
  586. // GetLastActivePopup() returns hwnd->hwndLastActive.
  587. // But top level owner's hwndLastActive is used.
  588. // We need to find a top level owner.
  589. //
  590. hwndT0 = GetWindow(hwndT, GW_OWNER);
  591. }
  592. hwndT = hwndT0;
  593. }
  594. return(hwndRet);
  595. }
  596. //+---------------------------------------------------------------------------
  597. //
  598. // MyWaitForInputIdle
  599. //
  600. //+---------------------------------------------------------------------------
  601. #define UTB_INPUTIDLETIMEOUT 2000
  602. DWORD MyWaitForInputIdle(DWORD dwThreadId, DWORD dwTimeOut)
  603. {
  604. DWORD dwRet = -1;
  605. DWORD dwProcessId = 0;
  606. DWORD dwThreadFlags;
  607. if (g_pTipbarWnd && g_pTipbarWnd->IsSFDeskband())
  608. {
  609. //
  610. // Skip it on the Deskband that is belong to Explorer process.
  611. //
  612. return 0;
  613. }
  614. //
  615. // If the target thread is in marshaling call, we can behave as it's busy.
  616. //
  617. if (TF_IsInMarshaling(dwThreadId))
  618. return WAIT_TIMEOUT;
  619. if (TF_GetThreadFlags(dwThreadId, &dwThreadFlags, &dwProcessId, NULL) && dwProcessId)
  620. {
  621. dwRet = 0;
  622. if (IsOnNT() &&
  623. Is16bitThread(dwProcessId, dwThreadId))
  624. {
  625. //
  626. // we need to do something here to detect 16bit idle.
  627. //
  628. }
  629. else if (IsOnNT() || !(dwThreadFlags & TLF_NOWAITFORINPUTIDLEONWIN9X))
  630. {
  631. #if 0
  632. HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS,
  633. FALSE, dwProcessId);
  634. if (hProcess)
  635. {
  636. dwRet = WaitForInputIdle(hProcess, dwTimeOut);
  637. CloseHandle(hProcess);
  638. }
  639. else
  640. dwRet = -1;
  641. #else
  642. dwRet = TF_CheckThreadInputIdle(dwThreadId, dwTimeOut);
  643. #endif
  644. }
  645. }
  646. return dwRet;
  647. }
  648. //+---------------------------------------------------------------------------
  649. //
  650. // ClearMsgQueue
  651. //
  652. //+---------------------------------------------------------------------------
  653. void ClearMsgQueue()
  654. {
  655. MSG msg;
  656. ULONG ulQuitCode;
  657. BOOL fQuitReceived = FALSE;
  658. while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE | PM_NOYIELD))
  659. {
  660. if (msg.message == WM_QUIT)
  661. {
  662. ulQuitCode = (ULONG)(msg.wParam);
  663. fQuitReceived = TRUE;
  664. }
  665. DispatchMessage(&msg);
  666. }
  667. if (fQuitReceived)
  668. PostQuitMessage(ulQuitCode);
  669. }
  670. //+---------------------------------------------------------------------------
  671. //
  672. // IsFullScreenSize
  673. //
  674. //+---------------------------------------------------------------------------
  675. BOOL IsFullScreenSize(HWND hwnd)
  676. {
  677. RECT rc;
  678. GetWindowRect(hwnd, &rc);
  679. if ((rc.left <= 0) &&
  680. (rc.top <= 0)&&
  681. (rc.right >= GetSystemMetrics(SM_CXFULLSCREEN)) &&
  682. (rc.bottom >= GetSystemMetrics(SM_CYFULLSCREEN)))
  683. {
  684. return TRUE;
  685. }
  686. return FALSE;
  687. }
  688. //+---------------------------------------------------------------------------
  689. //
  690. // InitUniqueString
  691. //
  692. //----------------------------------------------------------------------------
  693. BOOL GetUserSIDString(DWORD dwProcessId, char *pch, UINT cch)
  694. {
  695. HANDLE hToken = NULL;
  696. char *pszStringSid = NULL;
  697. HANDLE hProcess;
  698. hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, dwProcessId);
  699. if (hProcess)
  700. OpenProcessToken(hProcess, TOKEN_QUERY, &hToken);
  701. if (hToken)
  702. {
  703. DWORD dwReturnLength = 0;
  704. void *pvUserBuffer = NULL;
  705. GetTokenInformation(hToken, TokenUser, NULL, 0, &dwReturnLength);
  706. pvUserBuffer = cicMemAllocClear(dwReturnLength);
  707. if (pvUserBuffer &&
  708. GetTokenInformation(hToken,
  709. TokenUser,
  710. pvUserBuffer,
  711. dwReturnLength,
  712. &dwReturnLength))
  713. {
  714. if (!ConvertSidToStringSid(((TOKEN_USER*)(pvUserBuffer))->User.Sid,
  715. &pszStringSid))
  716. {
  717. if (pszStringSid)
  718. LocalFree(pszStringSid);
  719. pszStringSid = NULL;
  720. }
  721. }
  722. if (pvUserBuffer)
  723. {
  724. cicMemFree(pvUserBuffer);
  725. }
  726. CloseHandle(hToken);
  727. }
  728. if (hProcess)
  729. CloseHandle(hProcess);
  730. if (pszStringSid)
  731. {
  732. StringCchCopy(pch, cch, pszStringSid);
  733. LocalFree(pszStringSid);
  734. return TRUE;
  735. }
  736. *pch = '\0';
  737. return FALSE;
  738. }
  739. //+---------------------------------------------------------------------------
  740. //
  741. // InitCurrentProcessSid
  742. //
  743. //+---------------------------------------------------------------------------
  744. BOOL g_fSidInit = FALSE;
  745. char g_szSid[UNLEN + 1];
  746. BOOL InitCurrentProcessSid()
  747. {
  748. if (g_fSidInit)
  749. return TRUE;
  750. if (GetUserSIDString(GetCurrentProcessId(), g_szSid, ARRAYSIZE(g_szSid)))
  751. g_fSidInit = TRUE;
  752. return g_fSidInit;
  753. }
  754. //+---------------------------------------------------------------------------
  755. //
  756. // IsVisibleWindowInDesktop()
  757. //
  758. //+---------------------------------------------------------------------------
  759. BOOL CALLBACK EnumVisibleWindowProc(HWND hwnd, LPARAM lParam)
  760. {
  761. DWORD dwProcessId;
  762. if (!GetWindowThreadProcessId(hwnd, &dwProcessId))
  763. dwProcessId = 0;
  764. //
  765. // we're not interested in ctfmon's process window.
  766. //
  767. if (g_pTipbarWnd && !g_pTipbarWnd->IsInDeskBand())
  768. if (dwProcessId == GetCurrentProcessId())
  769. return TRUE;
  770. if (IsWindowVisible(hwnd))
  771. {
  772. if (g_fSidInit)
  773. {
  774. //
  775. // if the process is owned by different user, we skip it.
  776. //
  777. char szSid[UNLEN + 1];
  778. GetUserSIDString(dwProcessId, szSid, ARRAYSIZE(szSid));
  779. if (lstrcmp(szSid, g_szSid))
  780. return TRUE;
  781. }
  782. BOOL *pfFound = (BOOL *)lParam;
  783. *pfFound = TRUE;
  784. return FALSE;
  785. }
  786. return TRUE;
  787. }
  788. BOOL IsVisibleWindowInDesktop()
  789. {
  790. BOOL fFound = FALSE;
  791. InitCurrentProcessSid();
  792. EnumWindows(EnumVisibleWindowProc, (LPARAM)&fFound);
  793. return fFound;
  794. }
  795. //////////////////////////////////////////////////////////////////////////////
  796. //
  797. // CTipbarGripper
  798. //
  799. //////////////////////////////////////////////////////////////////////////////
  800. //+---------------------------------------------------------------------------
  801. //
  802. // CTipbarGripper::ctor
  803. //
  804. //----------------------------------------------------------------------------
  805. CTipbarGripper::CTipbarGripper(CTipbarWnd *pTipbarWnd, RECT *prc, DWORD dwStyle) : CUIFGripper( pTipbarWnd, prc, dwStyle)
  806. {
  807. _pTipbarWnd = pTipbarWnd;
  808. _fInMenu = FALSE;
  809. }
  810. //+---------------------------------------------------------------------------
  811. //
  812. // CTipbarGripper::OnSetCursor
  813. //
  814. //----------------------------------------------------------------------------
  815. BOOL CTipbarGripper::OnSetCursor(UINT uMsg, POINT pt)
  816. {
  817. if (!_fInMenu)
  818. return CUIFGripper::OnSetCursor(uMsg, pt);
  819. return FALSE;
  820. }
  821. //+---------------------------------------------------------------------------
  822. //
  823. // CTipbarGripper::OnRButtonUp
  824. //
  825. //----------------------------------------------------------------------------
  826. void CTipbarGripper::OnRButtonUp(POINT pt)
  827. {
  828. if (!g_bShowDebugMenu)
  829. return;
  830. HMENU hMenu = CreatePopupMenu();
  831. if (!hMenu)
  832. return;
  833. SetCursor(LoadCursor(NULL, IDC_ARROW));
  834. ClientToScreen(_pTipbarWnd->GetWnd(), &pt);
  835. InsertMenu(hMenu, -1, MF_BYPOSITION | MF_STRING, IDM_CLOSECICLOAD, "Close cicload");
  836. #ifdef DEBUG
  837. InsertMenu(hMenu, -1, MF_BYPOSITION | MF_STRING, IDM_BREAK, CRStr(IDS_BREAK));
  838. #endif
  839. InsertMenu(hMenu, -1, MF_BYPOSITION | MF_STRING, IDCANCEL, CRStr(IDS_CANCEL));
  840. _fInMenu = TRUE;
  841. int nRet = TrackPopupMenuEx(hMenu,
  842. TPM_LEFTBUTTON | TPM_NONOTIFY | TPM_RETURNCMD,
  843. pt.x, pt.y, _pTipbarWnd->GetWnd(), NULL);
  844. _fInMenu = FALSE;
  845. DestroyMenu(hMenu);
  846. switch (nRet)
  847. {
  848. case IDM_CLOSECICLOAD:
  849. {
  850. _pTipbarWnd->UnInit();
  851. if (IsWindow(g_hwndParent))
  852. DestroyWindow(g_hwndParent);
  853. MSG msg;
  854. while(PeekMessage(&msg, NULL, NULL, NULL, PM_REMOVE | PM_NOYIELD));
  855. PostQuitMessage(0);
  856. }
  857. break;
  858. #ifdef DEBUG
  859. case IDM_BREAK:
  860. DebugBreak();
  861. break;
  862. #endif
  863. }
  864. }
  865. //+---------------------------------------------------------------------------
  866. //
  867. // CTipbarGripper::OnLButtonUp
  868. //
  869. //----------------------------------------------------------------------------
  870. void CTipbarGripper::OnLButtonUp(POINT pt)
  871. {
  872. _pTipbarWnd->RestoreFromStub();
  873. //
  874. // Mouse Drag/Drop from floating language bar to deskband.
  875. //
  876. if (IsOnNT51())
  877. {
  878. APPBARDATA abd;
  879. RECT rcTrayWnd;
  880. abd.cbSize = sizeof(APPBARDATA);
  881. abd.hWnd = FindWindow(TEXT(WNDCLASS_TRAYNOTIFY), NULL);
  882. if (SHAppBarMessage(ABM_GETTASKBARPOS, &abd))
  883. {
  884. POINT ptCursor;
  885. rcTrayWnd = abd.rc;
  886. GetCursorPos(&ptCursor);
  887. if ((ptCursor.x >= rcTrayWnd.left && ptCursor.x <= rcTrayWnd.right) &&
  888. (ptCursor.y >= rcTrayWnd.top && ptCursor.y <= rcTrayWnd.bottom))
  889. {
  890. if (g_pTipbarWnd)
  891. g_pTipbarWnd->GetLangBarMgr()->ShowFloating(TF_SFT_DESKBAND |
  892. TF_SFT_EXTRAICONSONMINIMIZED);
  893. }
  894. }
  895. }
  896. CUIFGripper::OnLButtonUp(pt);
  897. //
  898. // CUIFGripper::OnLButonUp() calls MoveWindow.
  899. // Now we update pos flags of TipbarWnd.
  900. //
  901. _pTipbarWnd->UpdatePosFlags();
  902. }
  903. //////////////////////////////////////////////////////////////////////////////
  904. //
  905. // CTipbarWnd
  906. //
  907. //////////////////////////////////////////////////////////////////////////////
  908. //+---------------------------------------------------------------------------
  909. //
  910. // IUnknown
  911. //
  912. //----------------------------------------------------------------------------
  913. STDAPI CTipbarWnd::QueryInterface(REFIID riid, void **ppvObj)
  914. {
  915. *ppvObj = NULL;
  916. if (IsEqualIID(riid, IID_IUnknown) ||
  917. IsEqualIID(riid, IID_ITfLangBarEventSink))
  918. {
  919. *ppvObj = SAFECAST(this, ITfLangBarEventSink *);
  920. }
  921. else if (IsEqualIID(riid, IID_ITfLangBarEventSink_P))
  922. {
  923. *ppvObj = SAFECAST(this, ITfLangBarEventSink_P *);
  924. }
  925. if (*ppvObj)
  926. {
  927. AddRef();
  928. return S_OK;
  929. }
  930. return E_NOINTERFACE;
  931. }
  932. STDAPI_(ULONG) CTipbarWnd::AddRef()
  933. {
  934. return ++_cRef;
  935. }
  936. STDAPI_(ULONG) CTipbarWnd::Release()
  937. {
  938. _cRef--;
  939. Assert(_cRef >= 0);
  940. if (_cRef == 0)
  941. {
  942. delete this;
  943. return 0;
  944. }
  945. return _cRef;
  946. }
  947. //+---------------------------------------------------------------------------
  948. //
  949. // ctor
  950. //
  951. //----------------------------------------------------------------------------
  952. CTipbarWnd::CTipbarWnd(DWORD dwStyle) : CUIFWindow(g_hInst, dwStyle)
  953. {
  954. Dbg_MemSetThisName(TEXT("CTipbarWnd"));
  955. POINT pt;
  956. RECT rc;
  957. pt.x = g_nLeft;
  958. pt.y = g_nTop;
  959. CUIGetScreenRect(pt, &rc);
  960. if (!PtInRect(&rc, pt))
  961. {
  962. if (IsOnFE())
  963. {
  964. RECT rcWork;
  965. SystemParametersInfo( SPI_GETWORKAREA, 0, &rcWork, 0 );
  966. g_nLeft = rcWork.right;
  967. g_nTop = rcWork.bottom;
  968. }
  969. else if (g_fRTL)
  970. {
  971. g_nLeft = GetSystemMetrics(SM_CXSIZE) * 3;
  972. g_nTop = 0;
  973. }
  974. else
  975. {
  976. g_nLeft = GetSystemMetrics(SM_CXSCREEN) - (GetSystemMetrics(SM_CXSIZE) * 3);
  977. g_nTop = 0;
  978. }
  979. }
  980. Move(g_nLeft, g_nTop, STATUSWND_WIDTH, STATUSWND_HEIGHT);
  981. //
  982. // initialize Pos flags after calling Move().
  983. //
  984. UpdatePosFlags();
  985. _fShowText = FALSE;
  986. _fInStub = FALSE;
  987. _hfontMarlett = CreateFont(8, 8, 0, 0, 400, FALSE, FALSE, FALSE, SYMBOL_CHARSET, 0, 0, 0, 0, "Marlett");
  988. ITfLangBarMgr *putb;
  989. if (SUCCEEDED(TF_CreateLangBarMgr(&putb)) && putb)
  990. {
  991. putb->QueryInterface(IID_ITfLangBarMgr_P, (void **)&_putb);
  992. putb->Release();
  993. }
  994. if (dwStyle & UIWINDOW_WHISTLERLOOK)
  995. {
  996. if (g_fTaskbarTheme)
  997. SetActiveTheme(L"TASKBAR", TBP_BACKGROUNDBOTTOM, TS_NORMAL );
  998. else
  999. SetActiveTheme(L"REBAR", 0, TS_NORMAL );
  1000. }
  1001. SetVertical(g_fVertical);
  1002. _cRef = 1;
  1003. }
  1004. //+---------------------------------------------------------------------------
  1005. //
  1006. // dtor
  1007. //
  1008. //----------------------------------------------------------------------------
  1009. CTipbarWnd::~CTipbarWnd()
  1010. {
  1011. Assert(!_pModalMenu);
  1012. UnInit();
  1013. DeleteObject(_hfontMarlett);
  1014. if (_hfontVert)
  1015. DeleteObject(_hfontVert);
  1016. TFUninitLib_Thread(&g_libTLS);
  1017. }
  1018. //+---------------------------------------------------------------------------
  1019. //
  1020. // UnInit
  1021. //
  1022. //----------------------------------------------------------------------------
  1023. void CTipbarWnd::UnInit()
  1024. {
  1025. SetFocusThread(NULL);
  1026. int i;
  1027. for (i = 0; i < _rgThread.Count(); i++)
  1028. {
  1029. CTipbarThread *pThread = _rgThread.Get(i);
  1030. if (!pThread)
  1031. continue;
  1032. pThread->_UninitItemList(TRUE);
  1033. pThread->Disconnect();
  1034. pThread->_Release();
  1035. }
  1036. _rgThread.Clear();
  1037. if (_putb)
  1038. _putb->UnadviseEventSink(_dwlbimCookie);
  1039. SafeReleaseClear(_putb);
  1040. }
  1041. //+---------------------------------------------------------------------------
  1042. //
  1043. // SetFocus
  1044. //
  1045. //----------------------------------------------------------------------------
  1046. HRESULT CTipbarWnd::OnSetFocus(DWORD dwThreadId)
  1047. {
  1048. BOOL fNewThread = FALSE;
  1049. CTipbarThread *pThread;
  1050. CTipbarThread *pPrevFocusThread;
  1051. BOOL fWasInFullScreen = _fInFullScreen;
  1052. HWND hwndFore = GetForegroundWindow();
  1053. DWORD dwThreadIdFore = GetWindowThreadProcessId(hwndFore, NULL);
  1054. HRESULT hr;
  1055. CTipbarThread *pThreadPrev = NULL;
  1056. BOOL fSkipRedrawOnNoItem = FALSE;
  1057. TraceMsg(TF_FUNC, "focusnfy OnSetFocus %x ", dwThreadId);
  1058. //
  1059. // if the toolbar is being terminated, do nothing.
  1060. //
  1061. if (_fTerminating)
  1062. return S_OK;
  1063. if (_dwThreadIdWaitNotify && (_dwThreadIdWaitNotify != dwThreadId))
  1064. return S_OK;
  1065. //
  1066. // If this MSUTB is in ctfmon.exe and the langbar status is in Deskband,
  1067. // this meutb should stop wroking.
  1068. //
  1069. if (!_fInDeskBand && IsSFDeskband())
  1070. return S_OK;
  1071. if (!IsWindow(GetWnd()))
  1072. return E_FAIL;
  1073. StartPendingUpdateUI();
  1074. AddRef();
  1075. if (!_fInDeskBand && dwThreadIdFore)
  1076. {
  1077. BOOL fScreenSaverRunning = FALSE;
  1078. if (IsOnNT5() || IsOn98())
  1079. {
  1080. SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0,
  1081. &fScreenSaverRunning, FALSE);
  1082. }
  1083. if (IsFullScreenWindow(hwndFore) || fScreenSaverRunning)
  1084. {
  1085. if (GetWindowLongPtr(GetWnd(), GWL_STYLE) & WS_VISIBLE)
  1086. {
  1087. Show(FALSE);
  1088. _fInFullScreen = TRUE;
  1089. _dwPrevTBStatus = _dwSFTFlags;
  1090. }
  1091. }
  1092. else if (fWasInFullScreen)
  1093. {
  1094. Show(TRUE);
  1095. _fInFullScreen = FALSE;
  1096. //
  1097. // Bug#500507 - Need to recover language bar show status value.
  1098. //
  1099. if (!(_dwPrevTBStatus & TF_SFT_DESKBAND))
  1100. GetLangBarMgr()->ShowFloating(_dwPrevTBStatus);
  1101. }
  1102. }
  1103. KillTimer(TIPWND_TIMER_SETWINDOWPOS);
  1104. SetTimer(TIPWND_TIMER_SETWINDOWPOS, g_uTimerElapseSETWINDOWPOS);
  1105. pThread = _FindThread(dwThreadId);
  1106. if (_pFocusThread && (pThread == _pFocusThread))
  1107. {
  1108. hr = S_OK;
  1109. goto Exit;
  1110. }
  1111. //
  1112. // keep the current focus thread.
  1113. //
  1114. pPrevFocusThread = _pFocusThread;
  1115. CancelMenu();
  1116. if (!pThread)
  1117. {
  1118. pThread = _CreateThread(dwThreadId);
  1119. if (!pThread)
  1120. {
  1121. hr = E_FAIL;
  1122. goto Exit;
  1123. }
  1124. fNewThread = TRUE;
  1125. }
  1126. //
  1127. // focus has been change during creating pThread.
  1128. // we don't have to do anything now.
  1129. //
  1130. if (_pFocusThread && (pPrevFocusThread != _pFocusThread))
  1131. {
  1132. hr = S_OK;
  1133. goto Exit;
  1134. }
  1135. if (_pFocusThread)
  1136. {
  1137. _pFocusThread->RemoveUIObjs();
  1138. }
  1139. SetFocusThread(pThread);
  1140. if (pThread)
  1141. {
  1142. Assert(pThread == _pFocusThread);
  1143. BOOL fItemChanged = pThread->_fItemChanged;
  1144. //
  1145. // addref to increment the refcount.
  1146. //
  1147. pThread->_AddRef();
  1148. hr = S_OK;
  1149. if (fItemChanged)
  1150. hr = pThread->_UninitItemList(TRUE);
  1151. if (SUCCEEDED(hr))
  1152. {
  1153. pThread->RemoveUIObjs();
  1154. if (fItemChanged)
  1155. pThread->InitItemList();
  1156. }
  1157. //
  1158. // UninitItemList and InitItemList make marshaling calls.
  1159. // we need to check _pFocusThread again.
  1160. //
  1161. if (pThread == _pFocusThread)
  1162. {
  1163. pThread->LocateItems();
  1164. pThread->AddUIObjs();
  1165. if (fNewThread || fItemChanged)
  1166. {
  1167. if (!pThread->UpdateItems())
  1168. {
  1169. pThread->RemoveUIObjs();
  1170. SetFocusThread(NULL);
  1171. }
  1172. }
  1173. else if (pThread->IsDirtyItem())
  1174. {
  1175. //
  1176. // this thread has a update dirty item. Need to update now.
  1177. // We got OnUpdate call while it was background thread.
  1178. //
  1179. KillTimer(TIPWND_TIMER_ONUPDATECALLED);
  1180. SetTimer(TIPWND_TIMER_ONUPDATECALLED, g_uTimerElapseONUPDATECALLED);
  1181. }
  1182. }
  1183. fSkipRedrawOnNoItem = pThread->_fSkipRedrawOnNoItem;
  1184. //
  1185. // release to decrement the refcount.
  1186. //
  1187. pThread->_Release();
  1188. }
  1189. _ctrlbtnHolder.EnableBtns();
  1190. if (_fShowTrayIcon)
  1191. {
  1192. KillTimer(TIPWND_TIMER_MOVETOTRAY);
  1193. SetTimer(TIPWND_TIMER_MOVETOTRAY, g_uTimerElapseMOVETOTRAY);
  1194. }
  1195. //
  1196. // Cic#4712
  1197. //
  1198. if (_dwThreadItemChangedForTimer != dwThreadId)
  1199. {
  1200. KillOnTheadItemChangeTimer();
  1201. }
  1202. hr = S_OK;
  1203. Exit:
  1204. if (fSkipRedrawOnNoItem)
  1205. KillTimer(TIPWND_TIMER_UPDATEUI);
  1206. EndPendingUpdateUI();
  1207. Release();
  1208. return hr;
  1209. }
  1210. //+---------------------------------------------------------------------------
  1211. //
  1212. // IsFullScreenWindow
  1213. //
  1214. //+---------------------------------------------------------------------------
  1215. BOOL CTipbarWnd::IsFullScreenWindow(HWND hwnd)
  1216. {
  1217. ULONG_PTR dwStyle;
  1218. ULONG_PTR dwExStyle;
  1219. dwStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
  1220. if (!(dwStyle & WS_VISIBLE))
  1221. return FALSE;
  1222. if (dwStyle & WS_CAPTION)
  1223. return FALSE;
  1224. dwExStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
  1225. #ifdef OLD_FULLSCREENDETECTION
  1226. if (dwExStyle & WS_EX_TOOLWINDOW)
  1227. return FALSE;
  1228. if (!IsZoomed(hwnd) && !(dwExStyle & WS_EX_LAYERED))
  1229. {
  1230. if (IsFullScreenSize(hwnd))
  1231. return TRUE;
  1232. }
  1233. #else
  1234. if (dwExStyle & WS_EX_LAYERED)
  1235. return FALSE;
  1236. //
  1237. // #376691
  1238. //
  1239. // the full screen mode of Windows Media Player uses WS_EX_TOOLWINDOW style.
  1240. // we need to check if it is fullscreen window or not.
  1241. //
  1242. if (dwExStyle & WS_EX_TOOLWINDOW)
  1243. {
  1244. if (hwnd == shellwnd.GetWndProgman())
  1245. return FALSE;
  1246. }
  1247. //
  1248. // And some shell fullscreen window (such as slide show)
  1249. // has "mazimized" status. So we don't want to check IsZoomed().
  1250. //
  1251. // Thus any application without caption covers the screen won't have a
  1252. // floating toolbar.
  1253. //
  1254. if (IsFullScreenSize(hwnd))
  1255. return TRUE;
  1256. #endif
  1257. return FALSE;
  1258. }
  1259. //+---------------------------------------------------------------------------
  1260. //
  1261. // SetFocusThread
  1262. //
  1263. //----------------------------------------------------------------------------
  1264. HRESULT CTipbarWnd::SetFocusThread(CTipbarThread *pThread)
  1265. {
  1266. if (pThread == _pFocusThread)
  1267. return S_OK;
  1268. DWORD dwThreadId = GetCurrentThreadId();
  1269. DestroyOverScreenSizeBalloon();
  1270. if (_pFocusThread)
  1271. {
  1272. _pFocusThread->SetFocus(FALSE);
  1273. AttachThreadInput(dwThreadId, _pFocusThread->_dwThreadId, FALSE);
  1274. }
  1275. _pFocusThread = pThread;
  1276. //
  1277. // we will attach the focus thread input into this thread when
  1278. // when we need (mouse message comes and any other case?).
  1279. //
  1280. _fFocusAttached = FALSE;
  1281. if (_pFocusThread)
  1282. {
  1283. _pFocusThread->SetFocus(TRUE);
  1284. }
  1285. if (!_pFocusThread)
  1286. {
  1287. if (!IsVisibleWindowInDesktop())
  1288. {
  1289. // this is a hack to shut down ctfmon.exe when we're in a terminal server session
  1290. // and the main app has shutdown and no shell is running -- terminal server won't
  1291. // end the session as long as ctfmon is running which effectively locks the machine.
  1292. // See cicero bug 4235.
  1293. //
  1294. // Issue: got some more info from the terminal server team, another cleaner fix:
  1295. //
  1296. // Anyway if you need to put something in "not wait for" list, just add a value to
  1297. // "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\SysProcs" key.
  1298. // Name of the value should be equal to a name of executable, type is REG_DWORD, value is 0.
  1299. if (!_fInDeskBand)
  1300. PostQuitMessage(0);
  1301. else if (_pDeskBand)
  1302. _pDeskBand->DeleteBand();
  1303. }
  1304. }
  1305. return S_OK;
  1306. }
  1307. //+---------------------------------------------------------------------------
  1308. //
  1309. // AttachFocusThread
  1310. //
  1311. //----------------------------------------------------------------------------
  1312. HRESULT CTipbarWnd::AttachFocusThread()
  1313. {
  1314. if (_fFocusAttached)
  1315. return TRUE;
  1316. //
  1317. // Attach the focus thread when mouse message is coming. Since this
  1318. // toolbar window is disabled window, using different input focus
  1319. // causes unexpected focus change.
  1320. //
  1321. if (_pFocusThread)
  1322. {
  1323. DWORD dwThreadId = GetCurrentThreadId();
  1324. AttachThreadInput(dwThreadId, _pFocusThread->_dwThreadId, TRUE);
  1325. _fFocusAttached = TRUE;
  1326. }
  1327. return S_OK;
  1328. }
  1329. //+---------------------------------------------------------------------------
  1330. //
  1331. // ThreadTerminate
  1332. //
  1333. //----------------------------------------------------------------------------
  1334. HRESULT CTipbarWnd::OnThreadTerminate(DWORD dwThreadId)
  1335. {
  1336. HRESULT hr;
  1337. StartPendingUpdateUI();
  1338. AddRef();
  1339. hr = OnThreadTerminateInternal(dwThreadId);
  1340. if (!_pFocusThread)
  1341. EnsureFocusThread();
  1342. EndPendingUpdateUI();
  1343. Release();
  1344. return hr;
  1345. }
  1346. //+---------------------------------------------------------------------------
  1347. //
  1348. // OnThreadTerminateInternal
  1349. //
  1350. //----------------------------------------------------------------------------
  1351. HRESULT CTipbarWnd::OnThreadTerminateInternal(DWORD dwThreadId)
  1352. {
  1353. TraceMsg(TF_FUNC, "focusnfy OnThreadTerminate %x ", dwThreadId);
  1354. int i;
  1355. for (i = 0; i < _rgThread.Count(); i++)
  1356. {
  1357. CTipbarThread *pThread = _rgThread.Get(i);
  1358. if (!pThread)
  1359. continue;
  1360. if (pThread->_dwThreadId == dwThreadId)
  1361. {
  1362. _rgThread.Remove(i, 1);
  1363. pThread->RemoveUIObjs();
  1364. CleanUpThreadPointer(pThread, FALSE);
  1365. pThread->_UninitItemList(TRUE);
  1366. pThread->Disconnect();
  1367. pThread->_Release();
  1368. goto Exit;
  1369. }
  1370. }
  1371. Exit:
  1372. return S_OK;
  1373. }
  1374. //+---------------------------------------------------------------------------
  1375. //
  1376. // CleanUpThreadPointer
  1377. //
  1378. // This function make sure CTipbarWnd does not have pThread pointer any more.
  1379. //
  1380. //----------------------------------------------------------------------------
  1381. void CTipbarWnd::CleanUpThreadPointer(CTipbarThread *pThread, BOOL fCheckThreadArray)
  1382. {
  1383. Assert(pThread);
  1384. if (fCheckThreadArray)
  1385. {
  1386. int i;
  1387. for (i = 0; i < _rgThread.Count(); i++)
  1388. {
  1389. if (pThread == _rgThread.Get(i))
  1390. {
  1391. _rgThread.Remove(i, 1);
  1392. break;
  1393. }
  1394. }
  1395. }
  1396. if (pThread == _pFocusThread)
  1397. SetFocusThread(NULL);
  1398. if (pThread == _pttModal)
  1399. _pttModal = NULL;
  1400. if (pThread == _pThreadShowWindowAtTimer)
  1401. _pThreadShowWindowAtTimer = NULL;
  1402. }
  1403. //+---------------------------------------------------------------------------
  1404. //
  1405. // EnsureFocusThread
  1406. //
  1407. //----------------------------------------------------------------------------
  1408. void CTipbarWnd::EnsureFocusThread()
  1409. {
  1410. if (_pFocusThread)
  1411. {
  1412. Assert(0);
  1413. return;
  1414. }
  1415. if (_fTerminating)
  1416. return;
  1417. if (_fInEnsureFocusThread)
  1418. return;
  1419. _fInEnsureFocusThread = TRUE;
  1420. HWND hwndFore = GetForegroundWindow();
  1421. if (hwndFore)
  1422. {
  1423. DWORD dwThreadId = GetWindowThreadProcessId(hwndFore, NULL);
  1424. if (dwThreadId)
  1425. OnSetFocus(dwThreadId);
  1426. }
  1427. _fInEnsureFocusThread = FALSE;
  1428. }
  1429. //+---------------------------------------------------------------------------
  1430. //
  1431. // OnThreadItemChange
  1432. //
  1433. //----------------------------------------------------------------------------
  1434. HRESULT CTipbarWnd::OnThreadItemChange(DWORD dwThreadId)
  1435. {
  1436. CTipbarThread *pThread;
  1437. TraceMsg(TF_FUNC, "focusnfy OnThreadItemChange %x ", dwThreadId);
  1438. //
  1439. // if the toolbar is being terminated, do nothing.
  1440. //
  1441. if (_fTerminating)
  1442. return S_OK;
  1443. //
  1444. // If this MSUTB is in ctfmon.exe and the langbar status is in Deskband,
  1445. // this meutb should stop wroking.
  1446. //
  1447. if (!_fInDeskBand && IsSFDeskband())
  1448. return S_OK;
  1449. pThread = _FindThread(dwThreadId);
  1450. if (!pThread)
  1451. {
  1452. #if 0
  1453. //
  1454. // Issue: #365434 - In the running of Deskband after just restart
  1455. // machine, this hit will disable the showing deskband.
  1456. //
  1457. if (!_pFocusThread)
  1458. Show(FALSE);
  1459. #endif
  1460. return S_OK;
  1461. }
  1462. if ((_dwThreadIdWaitNotify && (_dwThreadIdWaitNotify != dwThreadId)) ||
  1463. (pThread != _pFocusThread))
  1464. {
  1465. pThread->_fItemChanged = TRUE;
  1466. return S_OK;
  1467. }
  1468. KillOnTheadItemChangeTimer();
  1469. _dwThreadItemChangedForTimer = dwThreadId;
  1470. KillTimer(TIPWND_TIMER_ONUPDATECALLED);
  1471. SetTimer(TIPWND_TIMER_ONTHREADITEMCHANGE, g_uTimerElapseONTHREADITEMCHANGE);
  1472. return S_OK;
  1473. }
  1474. //+---------------------------------------------------------------------------
  1475. //
  1476. // OnThreadItemChange
  1477. //
  1478. //----------------------------------------------------------------------------
  1479. HRESULT CTipbarWnd::OnThreadItemChangeInternal(DWORD dwThreadId)
  1480. {
  1481. CTipbarThread *pThread;
  1482. HRESULT hr = S_OK;
  1483. TraceMsg(TF_FUNC, "focusnfy OnThreadItemChangeInternal %x ", dwThreadId);
  1484. if (_dwThreadIdWaitNotify && (_dwThreadIdWaitNotify != dwThreadId))
  1485. return S_OK;
  1486. //
  1487. // If this MSUTB is in ctfmon.exe and the langbar status is in Deskband,
  1488. // this meutb should stop wroking.
  1489. //
  1490. if (!_fInDeskBand && IsSFDeskband())
  1491. return S_OK;
  1492. pThread = _FindThread(dwThreadId);
  1493. if (!pThread)
  1494. return S_OK;
  1495. if (pThread != _pFocusThread)
  1496. {
  1497. pThread->_fItemChanged = TRUE;
  1498. return hr;
  1499. }
  1500. //
  1501. // Ok, dwThreadId has a focus now, we need immediate action to update
  1502. // langbar.
  1503. //
  1504. Assert(dwThreadId == pThread->_dwThreadId);
  1505. StartPendingUpdateUI();
  1506. //
  1507. // addref to increment the refcount.
  1508. //
  1509. pThread->_AddRef();
  1510. hr = pThread->_UninitItemList(TRUE);
  1511. if (SUCCEEDED(hr))
  1512. {
  1513. pThread->RemoveUIObjs();
  1514. hr = pThread->InitItemList();
  1515. if (SUCCEEDED(hr))
  1516. {
  1517. //
  1518. // UninitItemList and InitItemList make marshaling calls.
  1519. // we need to check _pFocusThread again.
  1520. //
  1521. if (pThread == _pFocusThread)
  1522. {
  1523. pThread->LocateItems();
  1524. pThread->AddUIObjs();
  1525. pThread->UpdateItems();
  1526. }
  1527. }
  1528. }
  1529. //
  1530. // release to decrement the refcount.
  1531. //
  1532. pThread->_Release();
  1533. //
  1534. // #366835
  1535. //
  1536. // We got an error for the focus thread. Marshalling stubs might been gone!
  1537. // Let's restart marshaling.
  1538. //
  1539. if (hr == RPC_E_CONNECTION_TERMINATED)
  1540. {
  1541. //
  1542. // Throw away lost marshalled interfaces.
  1543. //
  1544. OnThreadTerminateInternal(dwThreadId);
  1545. //
  1546. // OnSetFocus() will reacate CTipbarThread.
  1547. //
  1548. OnSetFocus(dwThreadId);
  1549. }
  1550. _ctrlbtnHolder.EnableBtns();
  1551. // InvalidateRect(GetWnd(), NULL, TRUE);
  1552. if (_fShowTrayIcon)
  1553. {
  1554. KillTimer(TIPWND_TIMER_MOVETOTRAY);
  1555. SetTimer(TIPWND_TIMER_MOVETOTRAY, g_uTimerElapseMOVETOTRAY);
  1556. }
  1557. EndPendingUpdateUI();
  1558. return hr;
  1559. }
  1560. //+---------------------------------------------------------------------------
  1561. //
  1562. // MoveToTray
  1563. //
  1564. //----------------------------------------------------------------------------
  1565. void CTipbarWnd::MoveToTray()
  1566. {
  1567. //
  1568. // we don't use NotyfTrayIcon on WinXP.
  1569. //
  1570. if (IsOnNT51())
  1571. return;
  1572. if (!g_pTrayIconWnd)
  1573. return;
  1574. //
  1575. // Even if the floating toolbar setting is "minimized", we need to show
  1576. // it when explorer.exe is not running.
  1577. //
  1578. if (!g_pTrayIconWnd->GetNotifyWnd())
  1579. {
  1580. Show(TRUE);
  1581. return;
  1582. }
  1583. if (_fShowTrayIcon)
  1584. {
  1585. if (_pFocusThread)
  1586. {
  1587. if (TF_IsInMarshaling(_pFocusThread->_dwThreadId))
  1588. {
  1589. SetTimer(TIPWND_TIMER_MOVETOTRAY, g_uTimerElapseMOVETOTRAY);
  1590. return;
  1591. }
  1592. }
  1593. //
  1594. // we move to TrayIcon. Make sure the toolbar is hidden.
  1595. //
  1596. KillTimer(TIPWND_TIMER_SHOWWINDOW);
  1597. Show(FALSE);
  1598. DestroyOverScreenSizeBalloon();
  1599. CTipbarItem *pItem = NULL;
  1600. BOOL fIsKeyboardItemVisible = FALSE;
  1601. CTipbarItem *pKeyboardItem = NULL;
  1602. if (_pFocusThread)
  1603. {
  1604. if (_pFocusThread->IsConsole())
  1605. pItem = _pFocusThread->GetItem(GUID_LBI_INATITEM);
  1606. else
  1607. pItem = _pFocusThread->GetItem(GUID_LBI_CTRL);
  1608. if (pItem && !pItem->IsVisibleInToolbar())
  1609. pItem = NULL;
  1610. pKeyboardItem = _pFocusThread->GetItem(GUID_TFCAT_TIP_KEYBOARD);
  1611. if (pKeyboardItem && !pKeyboardItem->IsInHiddenStatus())
  1612. fIsKeyboardItemVisible = TRUE;
  1613. }
  1614. //
  1615. // we don't have to show UTB's Main Icon when
  1616. // - there is LBI_INATITEM or LBI_CTRL item.
  1617. // - there is a visible keyboard item.
  1618. //
  1619. g_pTrayIconWnd->SetMainIcon(pItem ? NULL : fIsKeyboardItemVisible ? NULL : GetFocusKeyboardLayout());
  1620. if (!g_pTrayIconWnd->_fShowExtraIcons)
  1621. {
  1622. DWORD dwRAIFlags = 0;
  1623. if (pItem)
  1624. dwRAIFlags |= TIW_RAI_LEAVELANGICON;
  1625. if (fIsKeyboardItemVisible)
  1626. dwRAIFlags |= TIW_RAI_LEAVEKEYBOARDICON;
  1627. g_pTrayIconWnd->RemoveAllIcon(dwRAIFlags);
  1628. if (pItem)
  1629. {
  1630. pItem->MoveToTray();
  1631. }
  1632. else if (fIsKeyboardItemVisible)
  1633. {
  1634. Assert(!!pKeyboardItem)
  1635. pKeyboardItem->MoveToTray();
  1636. }
  1637. }
  1638. else if (_pFocusThread)
  1639. {
  1640. int i;
  1641. g_pTrayIconWnd->RemoveUnusedIcons(&_pFocusThread->_rgItem);
  1642. for (i = 0; i < _pFocusThread->_rgItem.Count(); i++)
  1643. {
  1644. if (TF_IsInMarshaling(_pFocusThread->_dwThreadId))
  1645. {
  1646. SetTimer(TIPWND_TIMER_MOVETOTRAY, g_uTimerElapseMOVETOTRAY);
  1647. return;
  1648. }
  1649. pItem = _pFocusThread->_rgItem.Get(i);
  1650. if (pItem)
  1651. pItem->MoveToTray();
  1652. }
  1653. }
  1654. }
  1655. }
  1656. //+---------------------------------------------------------------------------
  1657. //
  1658. // OnModalInput
  1659. //
  1660. //----------------------------------------------------------------------------
  1661. STDAPI CTipbarWnd::OnModalInput(DWORD dwThreadId, UINT uMsg, WPARAM wParam, LPARAM lParam)
  1662. {
  1663. switch (uMsg)
  1664. {
  1665. case WM_KEYDOWN:
  1666. case WM_KEYUP:
  1667. if (_pttModal)
  1668. {
  1669. Assert(_pModalMenu);
  1670. Assert(_pttModal->_dwThreadId == dwThreadId);
  1671. _pModalMenu->PostKey((uMsg == WM_KEYUP), wParam, lParam);
  1672. }
  1673. break;
  1674. case WM_NCLBUTTONDOWN:
  1675. case WM_NCRBUTTONDOWN:
  1676. case WM_NCMBUTTONDOWN:
  1677. break;
  1678. case WM_NCLBUTTONUP:
  1679. case WM_NCRBUTTONUP:
  1680. case WM_NCMBUTTONUP:
  1681. //
  1682. // Multi Monitor
  1683. //
  1684. // if the disable window is in the negative location of
  1685. // screen coordinate, wm_ncxx message is generated.
  1686. // (maybe this is not mm specific, since siable window does not
  1687. // get WM_NCHITTEST.)
  1688. //
  1689. // we just forward this message to modal menu window as a normal
  1690. // mouse message to simulate the mouse action.
  1691. //
  1692. if (_pttModal)
  1693. {
  1694. Assert(_pModalMenu);
  1695. Assert(_pttModal->_dwThreadId == dwThreadId);
  1696. HWND hwnd = _pModalMenu->GetWnd();
  1697. if (hwnd)
  1698. {
  1699. POINT pt;
  1700. POINTSTOPOINT( pt, MAKEPOINTS( lParam ) );
  1701. ScreenToClient(hwnd, &pt);
  1702. PostMessage(hwnd,
  1703. uMsg + (WM_MOUSEMOVE - WM_NCMOUSEMOVE),
  1704. wParam,
  1705. MAKELPARAM(pt.x, pt.y));
  1706. }
  1707. }
  1708. break;
  1709. case WM_LBUTTONUP:
  1710. case WM_RBUTTONUP:
  1711. case WM_MBUTTONUP:
  1712. break;
  1713. default:
  1714. CancelMenu();
  1715. break;
  1716. }
  1717. return S_OK;
  1718. }
  1719. //+---------------------------------------------------------------------------
  1720. //
  1721. // ShowFloating
  1722. //
  1723. //----------------------------------------------------------------------------
  1724. STDAPI CTipbarWnd::ShowFloating(DWORD dwFlags)
  1725. {
  1726. if (_fInDeskBand)
  1727. {
  1728. _dwSFTFlags = dwFlags;
  1729. if (dwFlags & TF_SFT_DESKBAND)
  1730. {
  1731. //
  1732. // If we don't have _pFocusThread, the empty langbar is shown.
  1733. // Try to get the thread of the foreground window. This may not
  1734. // work correctly because the actual focus could be different
  1735. // from the thread of the foreground window.
  1736. //
  1737. if (!_pFocusThread)
  1738. {
  1739. KillTimer(TIPWND_TIMER_ENSUREFOCUS);
  1740. SetTimer(TIPWND_TIMER_ENSUREFOCUS, g_uTimerElapseENSUREFOCUS);
  1741. }
  1742. //
  1743. // Update Extra icons changing options
  1744. //
  1745. KillTimer(TIPWND_TIMER_SYSCOLORCHANGED);
  1746. SetTimer(TIPWND_TIMER_SYSCOLORCHANGED, g_uTimerElapseSYSCOLORCHANGED);
  1747. }
  1748. if (dwFlags & TF_SFT_EXTRAICONSONMINIMIZED)
  1749. {
  1750. _fAddExtraIcon = TRUE;
  1751. ClearDeskbandSizeAdjusted();
  1752. }
  1753. else if (dwFlags & TF_SFT_NOEXTRAICONSONMINIMIZED)
  1754. {
  1755. _fAddExtraIcon = FALSE;
  1756. ClearDeskbandSizeAdjusted();
  1757. }
  1758. return S_OK;
  1759. }
  1760. if (dwFlags & TF_SFT_SHOWNORMAL)
  1761. {
  1762. //
  1763. // we update the itemlist from registry now.
  1764. // something might be change during deskbanding.
  1765. //
  1766. _itemList.Load();
  1767. SetShowTrayIcon(FALSE);
  1768. //
  1769. // Call SetLangBar() before updating _dwSFTFlags.
  1770. //
  1771. SetLangBand(FALSE);
  1772. //
  1773. // Set SHOWNOARMAL flag before calling OnSetFocus().
  1774. //
  1775. _dwSFTFlags = TF_SFT_SHOWNORMAL;
  1776. //
  1777. // If we don't have _pFocusThread, the empty langbar is shown.
  1778. // Try to get the thread of the foreground window. This may not
  1779. // work correctly because the actual focus could be different
  1780. // from the thread of the foreground window.
  1781. //
  1782. if (!_pFocusThread)
  1783. EnsureFocusThread();
  1784. Show(TRUE);
  1785. }
  1786. else if (dwFlags & TF_SFT_DOCK)
  1787. {
  1788. //
  1789. // Call SetLangBar() before updating _dwSFTFlags.
  1790. //
  1791. SetLangBand(FALSE);
  1792. _dwSFTFlags = TF_SFT_DOCK;
  1793. }
  1794. else if (dwFlags & TF_SFT_MINIMIZED)
  1795. {
  1796. SetShowTrayIcon(TRUE);
  1797. KillTimer(TIPWND_TIMER_SHOWWINDOW);
  1798. Show(FALSE);
  1799. //
  1800. // Call SetLangBar() before updating _dwSFTFlags.
  1801. //
  1802. SetLangBand(FALSE);
  1803. _dwSFTFlags = TF_SFT_MINIMIZED;
  1804. }
  1805. else if (dwFlags & TF_SFT_HIDDEN)
  1806. {
  1807. SetShowTrayIcon(FALSE);
  1808. KillTimer(TIPWND_TIMER_SHOWWINDOW);
  1809. Show(FALSE);
  1810. //
  1811. // Call SetLangBar() before updating _dwSFTFlags.
  1812. //
  1813. SetLangBand(FALSE);
  1814. _dwSFTFlags = TF_SFT_HIDDEN;
  1815. TurnOffSpeechIfItsOn();
  1816. }
  1817. else if (dwFlags & TF_SFT_DESKBAND)
  1818. {
  1819. SetShowTrayIcon(FALSE);
  1820. KillTimer(TIPWND_TIMER_SHOWWINDOW);
  1821. KillTimer(TIPWND_TIMER_SHOWDESKBAND);
  1822. Show(FALSE);
  1823. //
  1824. // if the process of explorer belongs to different user, we don't
  1825. // set langband.
  1826. //
  1827. if (InitCurrentProcessSid())
  1828. {
  1829. DWORD dwProcessIdTray;
  1830. HWND hwndTray = shellwnd.GetWndTray();
  1831. GetWindowThreadProcessId(hwndTray, &dwProcessIdTray);
  1832. if (dwProcessIdTray)
  1833. {
  1834. char szSid[UNLEN + 1];
  1835. GetUserSIDString(dwProcessIdTray, szSid, ARRAYSIZE(szSid));
  1836. if (lstrcmp(szSid, g_szSid))
  1837. return S_OK;
  1838. }
  1839. }
  1840. //
  1841. // Need to make sure adding the language bar menu on taskbar
  1842. //
  1843. SetRegisterLangBand(TRUE);
  1844. //
  1845. // BugBug#377897 - Always show the extra additional icons in case of
  1846. // single keyboard layout.
  1847. //
  1848. if (IsSFNoExtraIcon())
  1849. {
  1850. if (IsSingleKeyboardLayout())
  1851. {
  1852. GetLangBarMgr()->ShowFloating(TF_SFT_EXTRAICONSONMINIMIZED);
  1853. }
  1854. }
  1855. //
  1856. // Call SetLangBar() before updating _dwSFTFlags.
  1857. //
  1858. if (SetLangBand(TRUE))
  1859. _dwSFTFlags = TF_SFT_DESKBAND;
  1860. else
  1861. SetTimer(TIPWND_TIMER_SHOWDESKBAND, g_uTimerElapseSHOWDESKBAND);
  1862. }
  1863. if (dwFlags & TF_SFT_NOTRANSPARENCY)
  1864. {
  1865. SetAlpha(255, FALSE);
  1866. }
  1867. else if (dwFlags & TF_SFT_LOWTRANSPARENCY)
  1868. {
  1869. SetAlpha(128, FALSE);
  1870. }
  1871. else if (dwFlags & TF_SFT_HIGHTRANSPARENCY)
  1872. {
  1873. SetAlpha(62, FALSE);
  1874. }
  1875. if (dwFlags & TF_SFT_LABELS)
  1876. {
  1877. SetShowText(TRUE);
  1878. }
  1879. else if (dwFlags & TF_SFT_NOLABELS)
  1880. {
  1881. SetShowText(FALSE);
  1882. }
  1883. if (dwFlags & TF_SFT_EXTRAICONSONMINIMIZED)
  1884. {
  1885. _fAddExtraIcon = TRUE;
  1886. if (g_pTrayIconWnd)
  1887. {
  1888. g_pTrayIconWnd->_fShowExtraIcons = TRUE;
  1889. if (_fShowTrayIcon)
  1890. SetShowTrayIcon(TRUE);
  1891. }
  1892. }
  1893. else if (dwFlags & TF_SFT_NOEXTRAICONSONMINIMIZED)
  1894. {
  1895. _fAddExtraIcon = FALSE;
  1896. if (g_pTrayIconWnd)
  1897. {
  1898. g_pTrayIconWnd->_fShowExtraIcons = FALSE;
  1899. if (_fShowTrayIcon)
  1900. SetShowTrayIcon(TRUE);
  1901. }
  1902. }
  1903. return S_OK;
  1904. }
  1905. //+---------------------------------------------------------------------------
  1906. //
  1907. // GetItemFloatingRect
  1908. //
  1909. //----------------------------------------------------------------------------
  1910. STDAPI CTipbarWnd::GetItemFloatingRect(DWORD dwThreadId, REFGUID rguid, RECT *prc)
  1911. {
  1912. HRESULT hr;
  1913. if (IsShowTrayIcon())
  1914. return E_UNEXPECTED;
  1915. if (!_pFocusThread)
  1916. return E_FAIL;
  1917. if (_pFocusThread->_dwThreadId != dwThreadId)
  1918. return E_FAIL;
  1919. hr = E_FAIL;
  1920. int i;
  1921. for (i = 0; i < _pFocusThread->_rgItem.Count(); i++)
  1922. {
  1923. CTipbarItem *pItem = _pFocusThread->_rgItem.Get(i);
  1924. if (!pItem)
  1925. continue;
  1926. if (pItem->IsVisibleInToolbar() && IsEqualGUID(*pItem->GetGUID(), rguid))
  1927. {
  1928. pItem->GetScreenRect(prc);
  1929. hr = S_OK;
  1930. break;
  1931. }
  1932. }
  1933. return hr;
  1934. }
  1935. //+---------------------------------------------------------------------------
  1936. //
  1937. // OnLangBarUpdate
  1938. //
  1939. //----------------------------------------------------------------------------
  1940. STDAPI CTipbarWnd::OnLangBarUpdate(UINT uUpdate, LPARAM lParam)
  1941. {
  1942. switch (uUpdate)
  1943. {
  1944. case TF_LBU_CAPSKANAKEY:
  1945. _ctrlbtnHolder.UpdateCapsKanaState(lParam);
  1946. break;
  1947. case TF_LBU_NTCONSOLELANGCHANGE:
  1948. if (_pFocusThread && _pFocusThread->IsConsole())
  1949. {
  1950. CTipbarItem *pItem = _pFocusThread->GetItem(GUID_LBI_INATITEM);
  1951. if (pItem)
  1952. {
  1953. CLBarInatItem *plbi = (CLBarInatItem *)pItem->GetNotifyUI();
  1954. HKL hkl = (HKL)lParam;
  1955. if (!hkl)
  1956. {
  1957. //
  1958. // #403714
  1959. //
  1960. // Don't know when GetKeyboardLayout() starts returning
  1961. // the correct value for the Console thread id.
  1962. // Want to use another timer to have an interval but
  1963. // having lots of code and path is not good idea at
  1964. // this time (just before releasing WinXP).
  1965. // Calling Sleep() with small interval looks the
  1966. // safest way to solve this problem.
  1967. //
  1968. Sleep(50);
  1969. hkl = GetKeyboardLayout(_pFocusThread->_dwThreadId);
  1970. }
  1971. plbi->SetHKL(hkl);
  1972. if (g_pTrayIconWnd)
  1973. {
  1974. g_pTrayIconWnd->SetMainIcon(NULL);
  1975. }
  1976. }
  1977. _pFocusThread->UpdateItems();
  1978. }
  1979. break;
  1980. }
  1981. return S_OK;
  1982. }
  1983. //+---------------------------------------------------------------------------
  1984. //
  1985. // FindAndCreateThread
  1986. //
  1987. //----------------------------------------------------------------------------
  1988. CTipbarThread *CTipbarWnd::_FindThread(DWORD dwThreadId)
  1989. {
  1990. int i;
  1991. for (i = 0; i < _rgThread.Count(); i++)
  1992. {
  1993. CTipbarThread *pThread = _rgThread.Get(i);
  1994. if (!pThread)
  1995. continue;
  1996. if (pThread->_dwThreadId == dwThreadId)
  1997. {
  1998. DWORD dwProcessId;
  1999. DWORD dwThreadFlags;
  2000. DWORD dwTickTime;
  2001. //
  2002. // TF_GetThreadFlag() does not work corrently on
  2003. // winlogon desktop..
  2004. //
  2005. if (g_bWinLogon)
  2006. break;
  2007. TF_GetThreadFlags(dwThreadId, &dwThreadFlags, &dwProcessId, &dwTickTime);
  2008. if (!dwProcessId ||
  2009. (dwProcessId != pThread->_dwProcessId) ||
  2010. (dwTickTime != pThread->_dwTickTime))
  2011. {
  2012. OnThreadTerminateInternal(dwThreadId);
  2013. pThread = NULL;
  2014. }
  2015. return pThread;
  2016. }
  2017. }
  2018. return NULL;
  2019. }
  2020. //+---------------------------------------------------------------------------
  2021. //
  2022. // FindAndCreateThread
  2023. //
  2024. //----------------------------------------------------------------------------
  2025. CTipbarThread *CTipbarWnd::_CreateThread(DWORD dwThreadId)
  2026. {
  2027. HRESULT hr;
  2028. CTipbarThread *pThread = _FindThread(dwThreadId);
  2029. if (pThread)
  2030. return pThread;
  2031. CTipbarThread **ppThread;
  2032. MyWaitForInputIdle(dwThreadId, UTB_INPUTIDLETIMEOUT);
  2033. pThread = new CTipbarThread(this);
  2034. if (!pThread)
  2035. goto Exit;
  2036. hr = pThread->Init(dwThreadId);
  2037. if (FAILED(hr))
  2038. {
  2039. goto FreeThread;
  2040. }
  2041. if (SUCCEEDED(pThread->InitItemList()))
  2042. {
  2043. TraceMsg(TF_GENERAL, "OnSetFocus Create New CTipbarThreadm");
  2044. ppThread = _rgThread.Append(1);
  2045. if (!ppThread)
  2046. {
  2047. goto FreeThread;
  2048. }
  2049. *ppThread = pThread;
  2050. }
  2051. else
  2052. {
  2053. TraceMsg(TF_GENERAL, "focusnfy OnSetFocus fail to create CTipbarThreadm");
  2054. FreeThread:
  2055. pThread->_UninitItemList(TRUE);
  2056. pThread->Disconnect();
  2057. pThread->_Release();
  2058. pThread = NULL;
  2059. goto Exit;
  2060. }
  2061. Exit:
  2062. return pThread;
  2063. }
  2064. //+---------------------------------------------------------------------------
  2065. //
  2066. // Init
  2067. //
  2068. //----------------------------------------------------------------------------
  2069. void CTipbarWnd::Init(BOOL fInDeskBand, CDeskBand *pDeskBand)
  2070. {
  2071. RECT rc;
  2072. if (_fInDeskBand = fInDeskBand)
  2073. _fShowText = FALSE;
  2074. _pDeskBand = pDeskBand;
  2075. ::SetRect(&rc, 0, 0, 0, 0);
  2076. if (g_bNewLook &&
  2077. !_pWndFrame &&
  2078. (GetStyle() & UIWINDOW_OFC10TOOLBAR))
  2079. {
  2080. UINT uWndFrameStyle;
  2081. uWndFrameStyle = UIWNDFRAME_THIN | UIWNDFRAME_NORESIZE;
  2082. _pWndFrame = new CUIFWndFrame(this, &rc, uWndFrameStyle);
  2083. if (_pWndFrame)
  2084. {
  2085. _pWndFrame->Initialize();
  2086. AddUIObj(_pWndFrame);
  2087. }
  2088. }
  2089. if (!_pGripper && !_fInDeskBand)
  2090. {
  2091. _pGripper = new CTipbarGripper(this, &rc, IsVertical() ? UIGRIPPER_VERTICAL : 0);
  2092. if (_pGripper)
  2093. {
  2094. _pGripper->Initialize();
  2095. AddUIObj(_pGripper);
  2096. }
  2097. }
  2098. _ctrlbtnHolder.Init(this);
  2099. if (!IsVertical())
  2100. Move(_xWnd, _yWnd, 0, GetTipbarHeight());
  2101. else
  2102. Move(_xWnd, _yWnd, GetTipbarHeight(), 0);
  2103. }
  2104. //+---------------------------------------------------------------------------
  2105. //
  2106. // SetVertical
  2107. //
  2108. //----------------------------------------------------------------------------
  2109. void CTipbarWnd::SetVertical(BOOL fVertical)
  2110. {
  2111. int iPartID;
  2112. _fVertical = fVertical;
  2113. if (_fVertical)
  2114. iPartID = TBP_BACKGROUNDLEFT;
  2115. else
  2116. iPartID = TBP_BACKGROUNDBOTTOM;
  2117. if (_pGripper)
  2118. {
  2119. DWORD dwStyle = _pGripper->GetStyle();
  2120. if (fVertical)
  2121. dwStyle |= UIGRIPPER_VERTICAL;
  2122. else
  2123. dwStyle &= ~UIGRIPPER_VERTICAL;
  2124. _pGripper->SetStyle(dwStyle);
  2125. }
  2126. if (g_fTaskbarTheme)
  2127. SetActiveTheme(L"TASKBAR", iPartID, TS_NORMAL );
  2128. if (!_fInDeskBand)
  2129. {
  2130. if (!IsVertical())
  2131. Move(_xWnd, _yWnd, 0, GetTipbarHeight());
  2132. else
  2133. Move(_xWnd, _yWnd, GetTipbarHeight(), 0);
  2134. }
  2135. if (GetWnd())
  2136. {
  2137. KillTimer(TIPWND_TIMER_SYSCOLORCHANGED);
  2138. SetTimer(TIPWND_TIMER_SYSCOLORCHANGED, g_uTimerElapseSYSCOLORCHANGED);
  2139. }
  2140. }
  2141. //+---------------------------------------------------------------------------
  2142. //
  2143. // InitThemeMargins
  2144. //
  2145. //----------------------------------------------------------------------------
  2146. void CTipbarWnd::InitThemeMargins()
  2147. {
  2148. CUIFTheme themeBtn;
  2149. memset(&_marginsItem, 0, sizeof(_marginsItem));
  2150. _cxItemMargin = CX_ITEMMARGIN;
  2151. _nItemDistance = ITEMDISTANCE;
  2152. _nCtrlItemHeightMargin = CTRLITEMHEIGHTMARGIN;
  2153. _cxCapBtn = GetSystemMetrics( SM_CXSIZE );
  2154. themeBtn.SetActiveTheme(L"TOOLBAR", TP_BUTTON, 0);
  2155. if (SUCCEEDED(themeBtn.OpenThemeData(GetWnd())))
  2156. {
  2157. themeBtn.GetThemeMargins(NULL, TS_NORMAL,
  2158. TMT_CONTENTMARGINS,
  2159. NULL, &_marginsItem);
  2160. _cxItemMargin = CX_ITEMMARGIN_THEME;
  2161. _nItemDistance = ITEMDISTANCE_THEME;
  2162. _nCtrlItemHeightMargin = CTRLITEMHEIGHTMARGIN_THEME;
  2163. }
  2164. themeBtn.CloseThemeData();
  2165. themeBtn.SetActiveTheme(L"WINDOW", WP_CLOSEBUTTON, 0);
  2166. if (SUCCEEDED(themeBtn.OpenThemeData(GetWnd())))
  2167. {
  2168. SIZE size;
  2169. themeBtn.GetThemePartSize(NULL, TS_NORMAL,
  2170. NULL,
  2171. TS_TRUE,
  2172. &size);
  2173. int cy = themeBtn.GetThemeSysSize(SM_CYSIZE);
  2174. _cxCapBtn = MulDiv(cy, size.cx, size.cy);
  2175. }
  2176. }
  2177. //+---------------------------------------------------------------------------
  2178. //
  2179. // UpdateVerticalFont
  2180. //
  2181. //----------------------------------------------------------------------------
  2182. void CTipbarWnd::UpdateVerticalFont()
  2183. {
  2184. if (_fVertical)
  2185. {
  2186. if (_hfontVert)
  2187. {
  2188. DeleteObject(_hfontVert);
  2189. SetFontToThis(NULL);
  2190. _hfontVert = NULL;
  2191. }
  2192. _hfontVert = CreateVerticalFont();
  2193. SetFontToThis(_hfontVert);
  2194. }
  2195. else
  2196. {
  2197. SetFontToThis(NULL);
  2198. }
  2199. }
  2200. //+---------------------------------------------------------------------------
  2201. //
  2202. // CheckEAFonts
  2203. //
  2204. //----------------------------------------------------------------------------
  2205. int CALLBACK FindEAEnumFontProc(const LOGFONT *plf, const TEXTMETRIC *ptm, WORD wType, LPARAM lParam)
  2206. {
  2207. BOOL *pf = (BOOL *)lParam;
  2208. if (wType != TRUETYPE_FONTTYPE)
  2209. return 1;
  2210. if (plf->lfFaceName[0] == '@')
  2211. {
  2212. *pf = TRUE;
  2213. return 0;
  2214. }
  2215. return 1;
  2216. }
  2217. BOOL CheckEAFonts()
  2218. {
  2219. HDC hdc = GetDC(NULL);
  2220. BOOL fFound = FALSE;
  2221. EnumFonts(hdc, NULL, (FONTENUMPROC)FindEAEnumFontProc, (LPARAM)&fFound);
  2222. ReleaseDC(NULL, hdc);
  2223. return fFound;
  2224. }
  2225. //+---------------------------------------------------------------------------
  2226. //
  2227. // CreateVerticalFont
  2228. //
  2229. //----------------------------------------------------------------------------
  2230. HFONT CTipbarWnd::CreateVerticalFont()
  2231. {
  2232. HFONT hfontVert = NULL;
  2233. CUIFTheme themeBtn;
  2234. themeBtn.SetActiveTheme(L"TOOLBAR", TP_BUTTON, 0);
  2235. if (!GetWnd())
  2236. return NULL;
  2237. BOOL fIsEAFonts = CheckEAFonts();
  2238. if (SUCCEEDED(themeBtn.OpenThemeData(GetWnd())))
  2239. {
  2240. LOGFONTW lfw;
  2241. Assert(IsOnNT51());
  2242. if (SUCCEEDED(themeBtn.GetThemeFont(NULL, 0 , TMT_FONT, &lfw)))
  2243. {
  2244. lfw.lfEscapement = 2700;
  2245. lfw.lfOrientation = 2700;
  2246. lfw.lfOutPrecision = OUT_TT_ONLY_PRECIS;
  2247. if (fIsEAFonts)
  2248. {
  2249. //
  2250. // Use @font for vertical langbar.
  2251. //
  2252. WCHAR szFaceName[LF_FACESIZE];
  2253. szFaceName[0] = L'@';
  2254. StringCchCopyW(&szFaceName[1], ARRAYSIZE(szFaceName) -1, lfw.lfFaceName);
  2255. StringCchCopyW(lfw.lfFaceName, ARRAYSIZE(lfw.lfFaceName), szFaceName);
  2256. }
  2257. hfontVert = CreateFontIndirectW(&lfw);
  2258. goto CheckFont;
  2259. }
  2260. }
  2261. LOGFONT lf;
  2262. HFONT hDefFont = (HFONT)GetStockObject( DEFAULT_GUI_FONT );
  2263. GetObject(hDefFont, sizeof(LOGFONT), &lf);
  2264. lf.lfEscapement = 2700;
  2265. lf.lfOrientation = 2700;
  2266. lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;
  2267. if (fIsEAFonts)
  2268. {
  2269. //
  2270. // Use @font for vertical langbar.
  2271. //
  2272. char szFaceName[LF_FACESIZE];
  2273. szFaceName[0] = '@';
  2274. StringCchCopy(&szFaceName[1], ARRAYSIZE(szFaceName) -1, lf.lfFaceName);
  2275. StringCchCopy(lf.lfFaceName, ARRAYSIZE(lf.lfFaceName), szFaceName);
  2276. }
  2277. hfontVert = CreateFontIndirect(&lf);
  2278. CheckFont:
  2279. return hfontVert;
  2280. }
  2281. //+---------------------------------------------------------------------------
  2282. //
  2283. // SetLangBand
  2284. //
  2285. //----------------------------------------------------------------------------
  2286. BOOL CTipbarWnd::SetLangBand(BOOL fLangBand, BOOL fNotify)
  2287. {
  2288. BOOL fRet = TRUE;
  2289. if (fLangBand == (IsSFDeskband() ? TRUE : FALSE))
  2290. return fRet;
  2291. //
  2292. // Set/Remove language band object
  2293. //
  2294. HWND hwndTray = shellwnd.GetWndTray();
  2295. if (fNotify && hwndTray)
  2296. {
  2297. #ifndef CUAS_ENABLE
  2298. DWORD_PTR dwResult;
  2299. LRESULT lResult = (LRESULT)0;
  2300. lResult = SendMessageTimeout(hwndTray,
  2301. TM_LANGUAGEBAND,
  2302. 0,
  2303. fLangBand,
  2304. SMTO_ABORTIFHUNG | SMTO_BLOCK,
  2305. 5000,
  2306. &dwResult);
  2307. //
  2308. // Checking the language band setting fail case
  2309. //
  2310. if (!lResult || dwResult != fLangBand)
  2311. {
  2312. Assert(0);
  2313. }
  2314. #else
  2315. DWORD_PTR dwResult;
  2316. LRESULT lResult = (LRESULT)0;
  2317. //
  2318. // Workaround fixes of Cicero 5181
  2319. // Explorer process doesn't initialize _ptbs yet when receive TM_LANGUAGEBAND.
  2320. //
  2321. HWND hwndIME = NULL;
  2322. //
  2323. // we should not load IMM32 here. If there is no IMM32.DLL loaded,
  2324. // there is no hwndIME.
  2325. //
  2326. if (GetSystemModuleHandle("imm32.dll"))
  2327. hwndIME = ImmGetDefaultIMEWnd(hwndTray);
  2328. if (hwndIME)
  2329. {
  2330. lResult = SendMessageTimeout(hwndIME,
  2331. WM_IME_SYSTEM,
  2332. fLangBand ? IMS_SETLANGBAND : IMS_RESETLANGBAND,
  2333. (LPARAM)hwndTray,
  2334. SMTO_ABORTIFHUNG | SMTO_BLOCK,
  2335. 5000,
  2336. &dwResult);
  2337. }
  2338. else
  2339. {
  2340. lResult = SendMessageTimeout(hwndTray,
  2341. TM_LANGUAGEBAND,
  2342. 0,
  2343. fLangBand,
  2344. SMTO_ABORTIFHUNG | SMTO_BLOCK,
  2345. 5000,
  2346. &dwResult);
  2347. }
  2348. //
  2349. // Checking the language band setting fail case
  2350. //
  2351. if (!lResult || dwResult != fLangBand)
  2352. {
  2353. Assert(0);
  2354. }
  2355. #endif
  2356. }
  2357. else
  2358. {
  2359. fRet = FALSE;
  2360. }
  2361. //
  2362. // If this MSUTB is in ctfmon.exe and the langbar status is in Deskband,
  2363. // this meutb should stop wroking.
  2364. //
  2365. if (!_fInDeskBand && fLangBand)
  2366. {
  2367. KillTimer(TIPWND_TIMER_SYSCOLORCHANGED);
  2368. SetTimer(TIPWND_TIMER_SYSCOLORCHANGED, g_uTimerElapseSYSCOLORCHANGED);
  2369. }
  2370. return fRet;
  2371. }
  2372. //+---------------------------------------------------------------------------
  2373. //
  2374. // SetMoveRect
  2375. //
  2376. //----------------------------------------------------------------------------
  2377. void CTipbarWnd::SetMoveRect( int x, int y, int nWidth, int nHeight)
  2378. {
  2379. if (_fInDeskBand)
  2380. {
  2381. //
  2382. // In case of DeskBand case, only update width and height.
  2383. //
  2384. _nWidth = nWidth;
  2385. _nHeight = nHeight;
  2386. return;
  2387. }
  2388. _rcNew.left = x;
  2389. _rcNew.top = y;
  2390. _rcNew.right = nWidth;
  2391. _rcNew.bottom = nHeight;
  2392. _fNeedMoveWindow = TRUE;
  2393. StartPendingUpdateUI();
  2394. RECT rc;
  2395. SIZE sizeWndFrame;
  2396. sizeWndFrame.cx = 0;
  2397. sizeWndFrame.cy = 0;
  2398. if (_pWndFrame)
  2399. {
  2400. ::SetRect(&rc, 0, 0,
  2401. nWidth - GetCxDlgFrame(),
  2402. nHeight - GetCyDlgFrame());
  2403. _pWndFrame->SetRect(&rc);
  2404. _pWndFrame->GetFrameSize( &sizeWndFrame );
  2405. }
  2406. if (_pGripper)
  2407. {
  2408. if (!IsVertical())
  2409. {
  2410. ::SetRect(&rc,
  2411. sizeWndFrame.cx,
  2412. sizeWndFrame.cy,
  2413. sizeWndFrame.cx + GetGripperWidth(),
  2414. nHeight - GetCyDlgFrame() - sizeWndFrame.cy);
  2415. }
  2416. else
  2417. {
  2418. ::SetRect(&rc,
  2419. sizeWndFrame.cx,
  2420. sizeWndFrame.cy,
  2421. nWidth - GetCxDlgFrame() - sizeWndFrame.cx,
  2422. sizeWndFrame.cy + GetGripperWidth());
  2423. }
  2424. _pGripper->SetRect(&rc);
  2425. }
  2426. EndPendingUpdateUI();
  2427. }
  2428. //+---------------------------------------------------------------------------
  2429. //
  2430. // GetGripperWidth
  2431. //
  2432. //----------------------------------------------------------------------------
  2433. int CTipbarWnd::GetGripperWidth()
  2434. {
  2435. if (_fInDeskBand)
  2436. return 0;
  2437. if (_pGripper)
  2438. {
  2439. if (SUCCEEDED(_pGripper->EnsureThemeData(GetWnd())))
  2440. {
  2441. int nRet = -1;
  2442. SIZE size;
  2443. HDC hdc = GetDC(GetWnd());
  2444. if (SUCCEEDED(_pGripper->GetThemePartSize(hdc,
  2445. TS_NORMAL,
  2446. NULL,
  2447. TS_TRUE,
  2448. &size)))
  2449. {
  2450. if (!IsVertical())
  2451. nRet = size.cx + CUI_GRIPPER_THEME_MARGIN * 2;
  2452. else
  2453. nRet = size.cy + CUI_GRIPPER_THEME_MARGIN * 2;
  2454. }
  2455. ReleaseDC(GetWnd(), hdc);
  2456. if (nRet >= 0)
  2457. return nRet;
  2458. }
  2459. }
  2460. return 5;
  2461. }
  2462. //+---------------------------------------------------------------------------
  2463. //
  2464. // Move
  2465. //
  2466. //----------------------------------------------------------------------------
  2467. void CTipbarWnd::Move( int x, int y, int nWidth, int nHeight)
  2468. {
  2469. CUIFWindow::Move(x, y, nWidth, nHeight);
  2470. }
  2471. //+---------------------------------------------------------------------------
  2472. //
  2473. // LocateCtrlButtons
  2474. //
  2475. //----------------------------------------------------------------------------
  2476. void CTipbarWnd::LocateCtrlButtons()
  2477. {
  2478. DWORD dwFlags = 0;
  2479. if (IsSFDeskband() && IsSFNoExtraIcon())
  2480. dwFlags |= TCBH_NOCOLUMN;
  2481. if (!IsCapKanaShown())
  2482. dwFlags |= TCBH_NOCOLUMN0;
  2483. SIZE sizeWndFrame;
  2484. sizeWndFrame.cx = 0;
  2485. sizeWndFrame.cy = 0;
  2486. if (_pWndFrame != NULL)
  2487. _pWndFrame->GetFrameSize( &sizeWndFrame );
  2488. int nTipbarHeight = GetTipbarHeight();
  2489. RECT rc;
  2490. GetRect(&rc);
  2491. int nHeightPadding = 0;
  2492. if (!IsVertical())
  2493. {
  2494. if (rc.bottom - rc.top > nTipbarHeight)
  2495. nHeightPadding = (rc.bottom - rc.top - nTipbarHeight) / 2;
  2496. int xNew;
  2497. if (_fNeedMoveWindow)
  2498. xNew = _rcNew.right - GetCtrlButtonWidth() - sizeWndFrame.cx;
  2499. else
  2500. xNew = _nWidth - GetCtrlButtonWidth() - sizeWndFrame.cx;
  2501. _ctrlbtnHolder.Locate(this,
  2502. xNew,
  2503. sizeWndFrame.cy + nHeightPadding,
  2504. nTipbarHeight - (sizeWndFrame.cy * 2),
  2505. dwFlags, FALSE);
  2506. }
  2507. else
  2508. {
  2509. if (rc.right - rc.left > nTipbarHeight)
  2510. nHeightPadding = (rc.right - rc.left - nTipbarHeight) / 2;
  2511. int yNew;
  2512. if (_fNeedMoveWindow)
  2513. yNew = _rcNew.bottom - GetCtrlButtonWidth() - sizeWndFrame.cy;
  2514. else
  2515. yNew = _nHeight - GetCtrlButtonWidth() - sizeWndFrame.cy;
  2516. _ctrlbtnHolder.Locate(this,
  2517. sizeWndFrame.cx + nHeightPadding,
  2518. yNew,
  2519. nTipbarHeight - (sizeWndFrame.cx * 2),
  2520. dwFlags, TRUE);
  2521. }
  2522. }
  2523. //+---------------------------------------------------------------------------
  2524. //
  2525. // GetFocusKeyboardLayout
  2526. //
  2527. //----------------------------------------------------------------------------
  2528. HKL CTipbarWnd::GetFocusKeyboardLayout()
  2529. {
  2530. return GetKeyboardLayout(_pFocusThread ? _pFocusThread->_dwThreadId : 0);
  2531. }
  2532. //+---------------------------------------------------------------------------
  2533. //
  2534. // HandleMouseMsg
  2535. //
  2536. //----------------------------------------------------------------------------
  2537. void CTipbarWnd::HandleMouseMsg( UINT uMsg, POINT pt )
  2538. {
  2539. if (_fInHandleMouseMsg)
  2540. return;
  2541. //
  2542. // Bug#477031: Add the reference count to finish the current task before
  2543. // destructing this object.
  2544. //
  2545. //
  2546. AddRef();
  2547. _fInHandleMouseMsg = TRUE;
  2548. if (_pFocusThread)
  2549. {
  2550. AttachFocusThread();
  2551. if ((uMsg == WM_LBUTTONDOWN) || (uMsg == WM_RBUTTONDOWN))
  2552. if (!MyWaitForInputIdle(_pFocusThread->_dwThreadId,
  2553. UTB_INPUTIDLETIMEOUT))
  2554. _pFocusThread->_ptw->_putb->RestoreLastFocus(NULL, FALSE);
  2555. }
  2556. POINT ptScrn = pt;
  2557. ClientToScreen(GetWnd(), &ptScrn);
  2558. if (WindowFromPoint(ptScrn) == GetWnd())
  2559. {
  2560. SetAlpha(255, TRUE);
  2561. if (_fInStub)
  2562. {
  2563. KillTimer(TIPWND_TIMER_STUBEND);
  2564. if (!_fInStubShow)
  2565. SetTimer(TIPWND_TIMER_STUBSTART, g_uTimerElapseSTUBSTART);
  2566. }
  2567. }
  2568. else
  2569. {
  2570. SetAlpha(_bAlpha, TRUE);
  2571. if (_fInStub && _fInStubShow)
  2572. SetTimer(TIPWND_TIMER_STUBEND, g_uTimerElapseSTUBEND);
  2573. }
  2574. CUIFWindow::HandleMouseMsg(uMsg, pt);
  2575. if (uMsg == WM_RBUTTONUP)
  2576. {
  2577. CUIFObject *pUIObj = ObjectFromPoint( pt );
  2578. if (pUIObj && pUIObj->GetID() != (-1))
  2579. {
  2580. PostMessage(GetWnd(), WM_LBWND_SHOWCONTEXTMENU, 0, MAKELPARAM(pt.x, pt.y));
  2581. }
  2582. }
  2583. _fInHandleMouseMsg = FALSE;
  2584. Release();
  2585. }
  2586. //+---------------------------------------------------------------------------
  2587. //
  2588. // OnMouseOutFromWindow
  2589. //
  2590. //----------------------------------------------------------------------------
  2591. void CTipbarWnd::OnMouseOutFromWindow( POINT pt )
  2592. {
  2593. StartBackToAlphaTimer();
  2594. if (_fInStub && _fInStubShow)
  2595. SetTimer(TIPWND_TIMER_STUBEND, g_uTimerElapseSTUBEND);
  2596. }
  2597. //+---------------------------------------------------------------------------
  2598. //
  2599. // CheckO10Flag
  2600. //
  2601. //----------------------------------------------------------------------------
  2602. #ifdef USE_OFC10LOOKONWINXP
  2603. void CTipbarWnd::CheckO10Flag()
  2604. {
  2605. if (!g_bNewLook)
  2606. return;
  2607. EnsureThemeData(GetWnd());
  2608. if (IsThemeActive() || _fInDeskBand)
  2609. {
  2610. g_dwWndStyle &= ~UIWINDOW_OFC10TOOLBAR;
  2611. }
  2612. else
  2613. {
  2614. g_dwWndStyle |= UIWINDOW_OFC10TOOLBAR;
  2615. }
  2616. SetStyle(g_dwWndStyle);
  2617. CreateScheme();
  2618. }
  2619. #endif
  2620. //+---------------------------------------------------------------------------
  2621. //
  2622. // OnCreate
  2623. //
  2624. //----------------------------------------------------------------------------
  2625. void CTipbarWnd::OnCreate(HWND hWnd)
  2626. {
  2627. if (g_fTaskbarTheme)
  2628. SetWindowTheme(hWnd, L"TASKBAR", NULL);
  2629. #ifdef USE_OFC10LOOKONWINXP
  2630. CheckO10Flag();
  2631. #endif
  2632. if (_fVertical)
  2633. {
  2634. if (!_hfontVert)
  2635. {
  2636. _hfontVert = CreateVerticalFont();
  2637. }
  2638. SetFontToThis(_hfontVert);
  2639. }
  2640. _ctrlbtnHolder.UpdateBitmap(this);
  2641. _itemList.Load();
  2642. if (_putb)
  2643. _putb->AdviseEventSink(this, hWnd, TF_LBESF_GLOBAL, &_dwlbimCookie);
  2644. if (_pFocusThread)
  2645. _pFocusThread->InitItemList();
  2646. InitHighContrast();
  2647. SetAlpha(128, FALSE);
  2648. InitMetrics();
  2649. //
  2650. // MSAA support
  2651. //
  2652. Assert(!_pTipbarAcc);
  2653. _pTipbarAcc = new CTipbarAccessible(this);
  2654. if (_pTipbarAcc)
  2655. {
  2656. _pTipbarAcc->SetWindow(hWnd);
  2657. }
  2658. }
  2659. //+---------------------------------------------------------------------------
  2660. //
  2661. // SetAlpha
  2662. //
  2663. //----------------------------------------------------------------------------
  2664. typedef BOOL (WINAPI * SETLAYERWINDOWATTRIBUTE)(HWND, COLORREF, BYTE, DWORD);
  2665. void CTipbarWnd::SetAlpha(BYTE bAlpha, BOOL fTemp)
  2666. {
  2667. if (!_fInDeskBand && IsOnNT5())
  2668. {
  2669. //
  2670. // we don't do alpha blending.
  2671. //
  2672. // when high contrast is on
  2673. // when Modal Menu is shown.
  2674. //
  2675. //
  2676. if (IsHighContrastOn() ||
  2677. _pModalMenu)
  2678. {
  2679. fTemp = TRUE;
  2680. bAlpha = 255;
  2681. }
  2682. if (!fTemp)
  2683. _bAlpha = bAlpha;
  2684. if (_bCurAlpha == bAlpha)
  2685. return;
  2686. CUIFShadow *pShadowWnd = GetShadowWnd();
  2687. if (pShadowWnd)
  2688. {
  2689. EnableShadow(bAlpha == 255);
  2690. pShadowWnd->Show((bAlpha == 255) && IsVisible());
  2691. }
  2692. DWORD dwExStyle = GetWindowLong(GetWnd(), GWL_EXSTYLE);
  2693. SetWindowLong(GetWnd(), GWL_EXSTYLE, dwExStyle | WS_EX_LAYERED);
  2694. static SETLAYERWINDOWATTRIBUTE pfnSetLayeredWindowAttributes = NULL;
  2695. if (!pfnSetLayeredWindowAttributes)
  2696. {
  2697. HINSTANCE hUser32;
  2698. hUser32 = GetSystemModuleHandle(TEXT("user32.dll"));
  2699. if (hUser32)
  2700. pfnSetLayeredWindowAttributes = (SETLAYERWINDOWATTRIBUTE)GetProcAddress(hUser32, TEXT("SetLayeredWindowAttributes"));
  2701. }
  2702. if (pfnSetLayeredWindowAttributes)
  2703. pfnSetLayeredWindowAttributes(GetWnd(), 0, (BYTE)bAlpha, LWA_ALPHA);
  2704. _bCurAlpha = bAlpha;
  2705. }
  2706. }
  2707. //+---------------------------------------------------------------------------
  2708. //
  2709. // OnDestroy
  2710. //
  2711. //----------------------------------------------------------------------------
  2712. void CTipbarWnd::OnDestroy(HWND hWnd)
  2713. {
  2714. CancelMenu();
  2715. //
  2716. // MSAA support
  2717. //
  2718. if (_pTipbarAcc)
  2719. _pTipbarAcc->NotifyWinEvent( EVENT_OBJECT_DESTROY, this);
  2720. OnTerminateToolbar();
  2721. if (_pTipbarAcc)
  2722. {
  2723. _pTipbarAcc->ClearAccItems();
  2724. _pTipbarAcc->Release();
  2725. _pTipbarAcc = NULL;
  2726. }
  2727. CoUninit();
  2728. if (_putb)
  2729. _putb->UnadviseEventSink(_dwlbimCookie);
  2730. }
  2731. //+---------------------------------------------------------------------------
  2732. //
  2733. // OnShowWindow
  2734. //
  2735. //----------------------------------------------------------------------------
  2736. LRESULT CTipbarWnd::OnShowWindow( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  2737. {
  2738. //
  2739. // MSAA support
  2740. //
  2741. if (_pTipbarAcc)
  2742. {
  2743. if (wParam)
  2744. {
  2745. _pTipbarAcc->NotifyWinEvent( EVENT_OBJECT_SHOW ,this);
  2746. //
  2747. // MSCANDUI does this.
  2748. //
  2749. // REVIEW: KOJIW: Unless we send notify EVENT_OBJECT_FOCUS,
  2750. // we never receive WM_GETOBJECT message. Why???
  2751. //
  2752. _pTipbarAcc->NotifyWinEvent( EVENT_OBJECT_FOCUS ,this);
  2753. }
  2754. else
  2755. {
  2756. _pTipbarAcc->NotifyWinEvent( EVENT_OBJECT_HIDE ,this);
  2757. }
  2758. }
  2759. return CUIFWindow::OnShowWindow( hWnd, uMsg, wParam, lParam );
  2760. }
  2761. //+---------------------------------------------------------------------------
  2762. //
  2763. // OnEndSession
  2764. //
  2765. //----------------------------------------------------------------------------
  2766. void CTipbarWnd::OnEndSession(HWND hwnd, WPARAM wParam, LPARAM lParam)
  2767. {
  2768. if (!g_bWinLogon)
  2769. OnTerminateToolbar();
  2770. if (wParam)
  2771. {
  2772. if (lParam & ENDSESSION_LOGOFF)
  2773. {
  2774. KillTimer(TIPWND_TIMER_SHOWWINDOW);
  2775. Show(FALSE);
  2776. }
  2777. else
  2778. {
  2779. OnTerminateToolbar();
  2780. AddRef();
  2781. DestroyWindow(hwnd);
  2782. Release();
  2783. }
  2784. }
  2785. }
  2786. //+---------------------------------------------------------------------------
  2787. //
  2788. // OnTerminateToolbar
  2789. //
  2790. //----------------------------------------------------------------------------
  2791. void CTipbarWnd::OnTerminateToolbar()
  2792. {
  2793. _fTerminating = TRUE;
  2794. DestroyOverScreenSizeBalloon();
  2795. TerminateAllThreads(TRUE);
  2796. if (!_fInDeskBand)
  2797. SavePosition();
  2798. }
  2799. //+---------------------------------------------------------------------------
  2800. //
  2801. // SavePosition
  2802. //
  2803. //----------------------------------------------------------------------------
  2804. void CTipbarWnd::SavePosition()
  2805. {
  2806. CMyRegKey keyUTB;
  2807. if (keyUTB.Create(HKEY_CURRENT_USER, c_szUTBKey) == S_OK)
  2808. {
  2809. POINT pt;
  2810. pt.x = 0;
  2811. pt.y = 0;
  2812. MyClientToScreen(&pt, NULL);
  2813. keyUTB.SetValue((DWORD)pt.x, c_szLeft);
  2814. keyUTB.SetValue((DWORD)pt.y, c_szTop);
  2815. keyUTB.SetValue((DWORD)_fVertical ? 1 : 0, c_szVertical);
  2816. }
  2817. }
  2818. //+---------------------------------------------------------------------------
  2819. //
  2820. // TerminateAllThreads
  2821. //
  2822. //----------------------------------------------------------------------------
  2823. void CTipbarWnd::TerminateAllThreads(BOOL fTerminatFocusThread)
  2824. {
  2825. int nCnt = _rgThread.Count();
  2826. int i;
  2827. DWORD *pdwThread;
  2828. pdwThread = new DWORD[nCnt + 1];
  2829. if (!pdwThread)
  2830. return;
  2831. for (i = 0; i < nCnt; i++)
  2832. {
  2833. pdwThread[i] = 0;
  2834. CTipbarThread *pThread = _rgThread.Get(i);
  2835. if (!pThread)
  2836. continue;
  2837. if (!fTerminatFocusThread && (pThread == _pFocusThread))
  2838. continue;
  2839. pdwThread[i] = pThread->_dwThreadId;
  2840. }
  2841. for (i = 0; i < nCnt; i++)
  2842. {
  2843. if (pdwThread[i])
  2844. OnThreadTerminateInternal(pdwThread[i]);
  2845. }
  2846. delete[] pdwThread;
  2847. }
  2848. //+---------------------------------------------------------------------------
  2849. //
  2850. // SetShowText()
  2851. //
  2852. //----------------------------------------------------------------------------
  2853. void CTipbarWnd::SetShowText(BOOL fShowText)
  2854. {
  2855. _fShowText = fShowText;
  2856. if (_pFocusThread)
  2857. {
  2858. OnThreadItemChange(_pFocusThread->_dwThreadId);
  2859. }
  2860. TerminateAllThreads(FALSE);
  2861. }
  2862. //+---------------------------------------------------------------------------
  2863. //
  2864. // OnWindowPosChanged
  2865. //
  2866. //----------------------------------------------------------------------------
  2867. LRESULT CTipbarWnd::OnWindowPosChanged(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2868. {
  2869. if (_pFocusThread)
  2870. {
  2871. int i;
  2872. for (i = 0; i < _pFocusThread->_rgItem.Count(); i++)
  2873. {
  2874. CTipbarItem *pItem = _pFocusThread->_rgItem.Get(i);
  2875. if (pItem)
  2876. pItem->OnPosChanged();
  2877. }
  2878. }
  2879. return CUIFWindow::OnWindowPosChanged(hWnd, uMsg, wParam, lParam);
  2880. }
  2881. //+---------------------------------------------------------------------------
  2882. //
  2883. // OnWindowPosChanging
  2884. //
  2885. //----------------------------------------------------------------------------
  2886. LRESULT CTipbarWnd::OnWindowPosChanging(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2887. {
  2888. WINDOWPOS *pwp = (WINDOWPOS *)lParam;
  2889. if (!(pwp->flags & SWP_NOZORDER))
  2890. {
  2891. CUIFToolTip *ptip = GetToolTipWnd();
  2892. //
  2893. // we don't patch hwndInsertAfter, when
  2894. // - Tooltip is being shown.
  2895. // - Modal Popup menu is shown.
  2896. //
  2897. if ((!ptip || !(ptip->IsBeingShown())) &&
  2898. !_pttModal)
  2899. pwp->hwndInsertAfter = HWND_TOP;
  2900. }
  2901. return CUIFWindow::OnWindowPosChanged(hWnd, uMsg, wParam, lParam);
  2902. }
  2903. //+---------------------------------------------------------------------------
  2904. //
  2905. // OnEraseBkGnd()
  2906. //
  2907. //----------------------------------------------------------------------------
  2908. LRESULT CTipbarWnd::OnEraseBkGnd( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  2909. {
  2910. return 1;
  2911. }
  2912. //+---------------------------------------------------------------------------
  2913. //
  2914. // PaintObject()
  2915. //
  2916. //----------------------------------------------------------------------------
  2917. void CTipbarWnd::PaintObject( HDC hDC, const RECT *prcUpdate )
  2918. {
  2919. // KillTimer(TIPWND_TIMER_ONUPDATECALLED);
  2920. if (_fNeedMoveWindow)
  2921. {
  2922. Move(_rcNew.left, _rcNew.top, _rcNew.right, _rcNew.bottom);
  2923. _fNeedMoveWindow = FALSE;
  2924. }
  2925. if (_pFocusThread && _pFocusThread->IsDirtyItem())
  2926. {
  2927. _pFocusThread->CallOnUpdateHandler();
  2928. //
  2929. // #432697: Stress fault
  2930. //
  2931. // ClosePopupTipbar() could be called while CallOnUpdateHandler()
  2932. // is calling marshaling. We should check if g_pTIpbarWnd is
  2933. // available.
  2934. //
  2935. if (!g_pTipbarWnd)
  2936. return;
  2937. }
  2938. CUIFWindow::PaintObject(hDC, prcUpdate);
  2939. }
  2940. //+---------------------------------------------------------------------------
  2941. //
  2942. // UpdateUI()
  2943. //
  2944. //----------------------------------------------------------------------------
  2945. void CTipbarWnd::UpdateUI( const RECT *prcUpdate )
  2946. {
  2947. // TraceMsg(TF_FUNC, "UpdateUI");
  2948. KillTimer(TIPWND_TIMER_UPDATEUI);
  2949. if (_dwThreadItemChangedForTimer ||
  2950. _dwPendingUpdateUI ||
  2951. (_pFocusThread && _pFocusThread->IsDirtyItem()))
  2952. {
  2953. SetTimer(TIPWND_TIMER_UPDATEUI, g_uTimerElapseUPDATEUI);
  2954. return;
  2955. }
  2956. if (_fNeedMoveWindow)
  2957. {
  2958. // TraceMsg(TF_FUNC, "UpdateUI need move window");
  2959. StartPendingUpdateUI();
  2960. Move(_rcNew.left, _rcNew.top, _rcNew.right, _rcNew.bottom);
  2961. _fNeedMoveWindow = FALSE;
  2962. EndPendingUpdateUI();
  2963. }
  2964. TraceMsg(TF_FUNC, "UpdateUI update now ");
  2965. CUIFWindow::UpdateUI(NULL);
  2966. }
  2967. //+---------------------------------------------------------------------------
  2968. //
  2969. // SetShowTrayIcon()
  2970. //
  2971. //----------------------------------------------------------------------------
  2972. void CTipbarWnd::SetShowTrayIcon(BOOL fShowTrayIcon)
  2973. {
  2974. _fShowTrayIcon = fShowTrayIcon;
  2975. if (_fShowTrayIcon && _pFocusThread)
  2976. {
  2977. KillTimer(TIPWND_TIMER_MOVETOTRAY);
  2978. SetTimer(TIPWND_TIMER_MOVETOTRAY, g_uTimerElapseMOVETOTRAY);
  2979. }
  2980. else if (g_pTrayIconWnd)
  2981. {
  2982. g_pTrayIconWnd->SetMainIcon(NULL);
  2983. g_pTrayIconWnd->RemoveAllIcon(0);
  2984. }
  2985. }
  2986. //+---------------------------------------------------------------------------
  2987. //
  2988. // ShowOverScreenSizeBalloon
  2989. //
  2990. //----------------------------------------------------------------------------
  2991. void CTipbarWnd::ShowOverScreenSizeBalloon()
  2992. {
  2993. RECT rc;
  2994. POINT pt;
  2995. CTipbarCtrlButton *pcuiCtrlbtn = _ctrlbtnHolder.GetCtrlBtn(ID_CBTN_EXTMENU);
  2996. if (!pcuiCtrlbtn)
  2997. {
  2998. Assert(0);
  2999. return;
  3000. }
  3001. DestroyOverScreenSizeBalloon();
  3002. _pblnOverScreenSize = new CUIFBalloonWindow(g_hInst, UIBALLOON_OK);
  3003. if (!_pblnOverScreenSize)
  3004. return;
  3005. _pblnOverScreenSize->Initialize();
  3006. pcuiCtrlbtn->GetRect(&rc);
  3007. pt.x = (rc.left + rc.right) / 2;
  3008. pt.y = rc.top;
  3009. MyClientToScreen(&pt, &rc);
  3010. _pblnOverScreenSize->SetTargetPos(pt);
  3011. _pblnOverScreenSize->SetExcludeRect(&rc);
  3012. _pblnOverScreenSize->SetText(CRStr(IDS_OVERSCREENSIZE));
  3013. _pblnOverScreenSize->CreateWnd(GetWnd());
  3014. }
  3015. //+---------------------------------------------------------------------------
  3016. //
  3017. // DestroyMinimizeBalloon
  3018. //
  3019. //----------------------------------------------------------------------------
  3020. void CTipbarWnd::DestroyOverScreenSizeBalloon()
  3021. {
  3022. if (_pblnOverScreenSize)
  3023. {
  3024. if (IsWindow(_pblnOverScreenSize->GetWnd()))
  3025. DestroyWindow(_pblnOverScreenSize->GetWnd());
  3026. delete _pblnOverScreenSize;
  3027. _pblnOverScreenSize = NULL;
  3028. }
  3029. }
  3030. //+---------------------------------------------------------------------------
  3031. //
  3032. // CancelMenu
  3033. //
  3034. //----------------------------------------------------------------------------
  3035. void CTipbarWnd::CancelMenu()
  3036. {
  3037. if (_pttModal)
  3038. {
  3039. if (_pttModal->_ptw && _pttModal->_ptw->_putb)
  3040. _pttModal->_ptw->StartModalInput(NULL, _pttModal->_dwThreadId);
  3041. Assert(_pModalMenu);
  3042. _pModalMenu->CancelMenu();
  3043. StartBackToAlphaTimer();
  3044. }
  3045. }
  3046. //+---------------------------------------------------------------------------
  3047. //
  3048. // MoveToStub
  3049. //
  3050. //----------------------------------------------------------------------------
  3051. void CTipbarWnd::MoveToStub(BOOL fHide)
  3052. {
  3053. RECT rc;
  3054. _fInStub = TRUE;
  3055. SystemParametersInfo(SPI_GETWORKAREA, 0, (void *)&rc, FALSE);
  3056. if (fHide)
  3057. {
  3058. _xWnd = rc.right - (24 + 14);
  3059. _fInStubShow = FALSE;
  3060. }
  3061. else
  3062. {
  3063. RECT rcWnd;
  3064. GetWindowRect(GetWnd(), &rcWnd);
  3065. _xWnd = rc.right - (rcWnd.right - rcWnd.left);
  3066. _fInStubShow = TRUE;
  3067. }
  3068. _yWnd = rc.bottom - GetTipbarHeight() - _cyDlgFrame;
  3069. if (_pFocusThread)
  3070. _pFocusThread->MyMoveWnd(0, 0);
  3071. }
  3072. //+---------------------------------------------------------------------------
  3073. //
  3074. // RestoreFromStub
  3075. //
  3076. //----------------------------------------------------------------------------
  3077. void CTipbarWnd::RestoreFromStub()
  3078. {
  3079. _fInStub = FALSE;
  3080. _fInStubShow = FALSE;
  3081. KillTimer(TIPWND_TIMER_STUBSTART);
  3082. KillTimer(TIPWND_TIMER_STUBEND);
  3083. }
  3084. //+---------------------------------------------------------------------------
  3085. //
  3086. // CTipbarWnd::KillOnThreadItemChangeTimer
  3087. //
  3088. //----------------------------------------------------------------------------
  3089. void CTipbarWnd::KillOnTheadItemChangeTimer()
  3090. {
  3091. DWORD dwThreadId = _dwThreadItemChangedForTimer;
  3092. _dwThreadItemChangedForTimer = 0;
  3093. KillTimer(TIPWND_TIMER_ONTHREADITEMCHANGE);
  3094. if (dwThreadId)
  3095. {
  3096. CTipbarThread *pThread = _FindThread(dwThreadId);
  3097. if (pThread)
  3098. pThread->_fItemChanged = TRUE;
  3099. }
  3100. }
  3101. //+---------------------------------------------------------------------------
  3102. //
  3103. // CTipbarWnd::OnTimer
  3104. //
  3105. //----------------------------------------------------------------------------
  3106. void CTipbarWnd::OnTimer(UINT uId)
  3107. {
  3108. DWORD dwFocusThreadId;
  3109. DWORD dwRet;
  3110. AddRef();
  3111. switch (uId)
  3112. {
  3113. case TIPWND_TIMER_STUBSTART:
  3114. KillTimer(TIPWND_TIMER_STUBSTART);
  3115. MoveToStub(FALSE);
  3116. break;
  3117. case TIPWND_TIMER_STUBEND:
  3118. KillTimer(TIPWND_TIMER_STUBEND);
  3119. MoveToStub(TRUE);
  3120. break;
  3121. case TIPWND_TIMER_BACKTOALPHA:
  3122. KillTimer(TIPWND_TIMER_BACKTOALPHA);
  3123. SetAlpha(_bAlpha, TRUE);
  3124. break;
  3125. case TIPWND_TIMER_ONTHREADITEMCHANGE:
  3126. //
  3127. // OnThreadItemChangeInternat will disconnect the marshaling for
  3128. // all items. It is better todo this later.
  3129. //
  3130. dwRet = MyWaitForInputIdle(_dwThreadItemChangedForTimer,
  3131. UTB_INPUTIDLETIMEOUT);
  3132. if (dwRet)
  3133. {
  3134. if (dwRet != WAIT_TIMEOUT)
  3135. {
  3136. KillTimer(TIPWND_TIMER_ONTHREADITEMCHANGE);
  3137. _dwThreadItemChangedForTimer = 0;
  3138. }
  3139. break;
  3140. }
  3141. if (!_pttModal)
  3142. {
  3143. KillTimer(TIPWND_TIMER_ONTHREADITEMCHANGE);
  3144. //
  3145. // #509156
  3146. //
  3147. // Set _dwThreadItemChagnedForTimer before calling
  3148. // OnThreadItemChangeInternal(). During the marshaling call
  3149. // in the function, someone else may set
  3150. // _dwThreadItemChangedForTimer.
  3151. //
  3152. DWORD dwThreadIdTemp = _dwThreadItemChangedForTimer;
  3153. _dwThreadItemChangedForTimer = 0;
  3154. OnThreadItemChangeInternal(dwThreadIdTemp);
  3155. }
  3156. break;
  3157. case TIPWND_TIMER_SETWINDOWPOS:
  3158. KillTimer(TIPWND_TIMER_SETWINDOWPOS);
  3159. SetWindowPos(GetWnd(), HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
  3160. break;
  3161. case TIPWND_TIMER_ONUPDATECALLED:
  3162. KillTimer(TIPWND_TIMER_ONUPDATECALLED);
  3163. //
  3164. // if _dwThreadItemChangedForTimer is not 0, we will
  3165. // update all items later.
  3166. //
  3167. if (_pFocusThread &&
  3168. (_pFocusThread->_dwThreadId != _dwThreadItemChangedForTimer))
  3169. {
  3170. if (!_pFocusThread->CallOnUpdateHandler())
  3171. {
  3172. if (_pFocusThread)
  3173. OnThreadItemChange(_pFocusThread->_dwThreadId);
  3174. }
  3175. }
  3176. break;
  3177. case TIPWND_TIMER_SYSCOLORCHANGED:
  3178. KillTimer(TIPWND_TIMER_SYSCOLORCHANGED);
  3179. //
  3180. // the sys colors were changed, we recreate all thread info
  3181. // again.
  3182. //
  3183. if (_pFocusThread)
  3184. dwFocusThreadId = _pFocusThread->_dwThreadId;
  3185. else
  3186. dwFocusThreadId = 0;
  3187. TerminateAllThreads(TRUE);
  3188. UpdateVerticalFont();
  3189. if (dwFocusThreadId)
  3190. OnSetFocus(dwFocusThreadId);
  3191. InitMetrics();
  3192. _ctrlbtnHolder.UpdateBitmap(this);
  3193. InitHighContrast();
  3194. SetAlpha(255, TRUE);
  3195. ::RedrawWindow(GetWnd(),
  3196. NULL,
  3197. NULL,
  3198. RDW_FRAME | RDW_INVALIDATE | RDW_UPDATENOW);
  3199. break;
  3200. case TIPWND_TIMER_DISPLAYCHANGE:
  3201. KillTimer(TIPWND_TIMER_DISPLAYCHANGE);
  3202. AdjustPosOnDisplayChange();
  3203. break;
  3204. case TIPWND_TIMER_UPDATEUI:
  3205. KillTimer(TIPWND_TIMER_UPDATEUI);
  3206. UpdateUI(NULL);
  3207. break;
  3208. case TIPWND_TIMER_SHOWWINDOW:
  3209. KillTimer(TIPWND_TIMER_SHOWWINDOW);
  3210. if (_pThreadShowWindowAtTimer == _pFocusThread)
  3211. Show(_fShowWindowAtTimer);
  3212. _pThreadShowWindowAtTimer = NULL;
  3213. //
  3214. // If the window was over the screen and hide some items,
  3215. // we show balloon tips.
  3216. //
  3217. if (_fShowOverItemBalloonAtTimer)
  3218. ShowOverScreenSizeBalloon();
  3219. break;
  3220. case TIPWND_TIMER_SHOWDESKBAND:
  3221. if (SetLangBand(TRUE))
  3222. {
  3223. _dwSFTFlags = TF_SFT_DESKBAND;
  3224. KillTimer(TIPWND_TIMER_SHOWDESKBAND);
  3225. }
  3226. break;
  3227. case TIPWND_TIMER_MOVETOTRAY:
  3228. KillTimer(TIPWND_TIMER_MOVETOTRAY);
  3229. MoveToTray();
  3230. break;
  3231. case TIPWND_TIMER_ENSUREFOCUS:
  3232. if (_pDeskBand && _pDeskBand->IsInTipbarCreating())
  3233. break;
  3234. KillTimer(TIPWND_TIMER_ENSUREFOCUS);
  3235. if (!_pFocusThread)
  3236. EnsureFocusThread();
  3237. break;
  3238. case TIPWND_TIMER_DOACCDEFAULTACTION:
  3239. //
  3240. // MSAA support
  3241. //
  3242. KillTimer(TIPWND_TIMER_DOACCDEFAULTACTION);
  3243. if (_pTipbarAcc && _nDoAccDefaultActionItemId)
  3244. {
  3245. _pTipbarAcc->DoDefaultActionReal(_nDoAccDefaultActionItemId);
  3246. _nDoAccDefaultActionItemId = 0;
  3247. }
  3248. break;
  3249. default:
  3250. if ((uId >= TIPWND_TIMER_DEMOTEITEMFIRST) &&
  3251. (uId < TIPWND_TIMER_DEMOTEITEMLAST))
  3252. {
  3253. LANGBARITEMSTATE *pItemState;
  3254. if (pItemState = _itemList.GetItemStateFromTimerId(uId))
  3255. {
  3256. CTipbarItem *pItem;
  3257. _itemList.SetDemoteLevel(pItemState->guid, DL_HIDDENLEVEL1);
  3258. if (_pFocusThread &&
  3259. (pItem = _pFocusThread->GetItem(pItemState->guid)))
  3260. {
  3261. Assert(!pItem->IsHiddenStatusControl())
  3262. pItem->AddRemoveMeToUI(FALSE);
  3263. }
  3264. }
  3265. break;
  3266. }
  3267. }
  3268. Release();
  3269. return;
  3270. }
  3271. //+---------------------------------------------------------------------------
  3272. //
  3273. // CTipbarWnd::OnSysColoeChange
  3274. //
  3275. //----------------------------------------------------------------------------
  3276. void CTipbarWnd::OnSysColorChange()
  3277. {
  3278. KillTimer(TIPWND_TIMER_SYSCOLORCHANGED);
  3279. SetTimer(TIPWND_TIMER_SYSCOLORCHANGED, g_uTimerElapseSYSCOLORCHANGED);
  3280. }
  3281. //+---------------------------------------------------------------------------
  3282. //
  3283. // OnUser
  3284. //
  3285. //----------------------------------------------------------------------------
  3286. void CTipbarWnd::OnUser(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3287. {
  3288. POINT pt;
  3289. switch (uMsg)
  3290. {
  3291. case WM_LBWND_SHOWCONTEXTMENU:
  3292. pt.x = LOWORD(lParam);
  3293. pt.y = HIWORD(lParam);
  3294. MyClientToScreen(&pt, NULL);
  3295. ShowContextMenu(pt, NULL, TRUE);
  3296. break;
  3297. default:
  3298. if (uMsg == g_wmTaskbarCreated)
  3299. {
  3300. shellwnd.Clear();
  3301. }
  3302. break;
  3303. }
  3304. }
  3305. //+---------------------------------------------------------------------------
  3306. //
  3307. // OnSettingChange
  3308. //
  3309. //----------------------------------------------------------------------------
  3310. LRESULT CTipbarWnd::OnSettingChange(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3311. {
  3312. switch (wParam)
  3313. {
  3314. case 0:
  3315. case SPI_SETHIGHCONTRAST:
  3316. case SPI_SETNONCLIENTMETRICS:
  3317. KillTimer(TIPWND_TIMER_SYSCOLORCHANGED);
  3318. SetTimer(TIPWND_TIMER_SYSCOLORCHANGED, g_uTimerElapseSYSCOLORCHANGED);
  3319. break;
  3320. }
  3321. return 0;
  3322. }
  3323. //+---------------------------------------------------------------------------
  3324. //
  3325. // OnDisplayChange
  3326. //
  3327. //----------------------------------------------------------------------------
  3328. LRESULT CTipbarWnd::OnDisplayChange(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  3329. {
  3330. if (!_fInDeskBand)
  3331. {
  3332. KillTimer(TIPWND_TIMER_DISPLAYCHANGE);
  3333. SetTimer(TIPWND_TIMER_DISPLAYCHANGE, g_uTimerElapseDISPLAYCHANGE);
  3334. }
  3335. return CUIFWindow::OnDisplayChange(hWnd, uMsg, wParam, lParam);
  3336. }
  3337. //+---------------------------------------------------------------------------
  3338. //
  3339. // AdjustPosOnDisplayChange
  3340. //
  3341. //----------------------------------------------------------------------------
  3342. void CTipbarWnd::AdjustPosOnDisplayChange()
  3343. {
  3344. RECT rc;
  3345. RECT rcWnd;
  3346. int xWnd = _xWnd;
  3347. int yWnd = _yWnd;
  3348. Assert(!_fInDeskBand);
  3349. rcWnd.left = _xWnd;
  3350. rcWnd.top = _yWnd;
  3351. rcWnd.right = _xWnd + _nWidth;
  3352. rcWnd.bottom = _yWnd + _nHeight;
  3353. if (!GetWorkArea(&rcWnd, &rc))
  3354. return;
  3355. if (_fPosLeft)
  3356. xWnd = rc.left;
  3357. if (_fPosTop)
  3358. yWnd = rc.top;
  3359. if (_fPosRight)
  3360. xWnd = rc.right - _nWidth;
  3361. if (_fPosBottom)
  3362. yWnd = rc.bottom - _nHeight;
  3363. if ((xWnd != _xWnd) || (yWnd != _yWnd))
  3364. Move(xWnd, yWnd, _nWidth, _nHeight);
  3365. }
  3366. //+---------------------------------------------------------------------------
  3367. //
  3368. // UpdatePosFlags
  3369. //
  3370. //----------------------------------------------------------------------------
  3371. #define POSFLAG_MARGIN 2
  3372. void CTipbarWnd::UpdatePosFlags()
  3373. {
  3374. RECT rc;
  3375. RECT rcWnd;
  3376. if (_fInDeskBand)
  3377. return;
  3378. rcWnd.left = _xWnd;
  3379. rcWnd.top = _yWnd;
  3380. rcWnd.right = _xWnd + _nWidth;
  3381. rcWnd.bottom = _yWnd + _nHeight;
  3382. if (!GetWorkArea(&rcWnd, &rc))
  3383. return;
  3384. if (_xWnd <= rc.left + POSFLAG_MARGIN)
  3385. _fPosLeft = TRUE;
  3386. else
  3387. _fPosLeft = FALSE;
  3388. if (_yWnd <= rc.top + POSFLAG_MARGIN)
  3389. _fPosTop = TRUE;
  3390. else
  3391. _fPosTop = FALSE;
  3392. if (_xWnd + _nWidth >= rc.right - POSFLAG_MARGIN)
  3393. _fPosRight = TRUE;
  3394. else
  3395. _fPosRight = FALSE;
  3396. if (_yWnd + _nHeight >= rc.bottom - POSFLAG_MARGIN)
  3397. _fPosBottom = TRUE;
  3398. else
  3399. _fPosBottom = FALSE;
  3400. }
  3401. //+---------------------------------------------------------------------------
  3402. //
  3403. // AutoAdjustDeskBandSize
  3404. //
  3405. //----------------------------------------------------------------------------
  3406. BOOL CTipbarWnd::AutoAdjustDeskBandSize()
  3407. {
  3408. if (_fDeskbandSizeAdjusted)
  3409. return FALSE;
  3410. if (!_pFocusThread)
  3411. return FALSE;
  3412. if (_pFocusThread->IsCtfmonProcess())
  3413. return FALSE;
  3414. //
  3415. // if _fAdjustDeskbandIfNoRoom is on, don't put fFit so we don't
  3416. // do anything if there is a room.
  3417. //
  3418. BOOL fFit = TRUE;
  3419. if (_fAdjustDeskbandIfNoRoom)
  3420. fFit = FALSE;
  3421. _fAdjustDeskbandIfNoRoom = FALSE;
  3422. if (AdjustDeskBandSize(fFit))
  3423. {
  3424. SetDeskbandSizeAdjusted();
  3425. return TRUE;
  3426. }
  3427. return FALSE;
  3428. }
  3429. //+---------------------------------------------------------------------------
  3430. //
  3431. // AdjustDeskBandSize
  3432. //
  3433. //----------------------------------------------------------------------------
  3434. BOOL CTipbarWnd::AdjustDeskBandSize(BOOL fFit)
  3435. {
  3436. if (!_fInDeskBand)
  3437. return FALSE;
  3438. if (!_pDeskBand)
  3439. return FALSE;
  3440. return _pDeskBand->ResizeRebar(GetWnd(),
  3441. IsVertical() ? _nHeight : _nWidth,
  3442. fFit);
  3443. }
  3444. //+---------------------------------------------------------------------------
  3445. //
  3446. // GetThread
  3447. //
  3448. //----------------------------------------------------------------------------
  3449. CTipbarThread *CTipbarWnd::GetThread(DWORD dwThreadId)
  3450. {
  3451. int i;
  3452. for (i = 0; i < _rgThread.Count(); i++)
  3453. {
  3454. CTipbarThread *pThread = _rgThread.Get(i);
  3455. if (!pThread)
  3456. continue;
  3457. if (pThread->_dwThreadId == dwThreadId)
  3458. {
  3459. if (TF_GetThreadFlags(dwThreadId, NULL, NULL, NULL))
  3460. {
  3461. return pThread;
  3462. }
  3463. }
  3464. }
  3465. return NULL;
  3466. }
  3467. //+---------------------------------------------------------------------------
  3468. //
  3469. // RestoreLastFocs
  3470. //
  3471. //----------------------------------------------------------------------------
  3472. void CTipbarWnd::RestoreLastFocus(DWORD *pdwThreadId, BOOL fPrev)
  3473. {
  3474. if (_putb)
  3475. _putb->RestoreLastFocus(pdwThreadId, fPrev);
  3476. }
  3477. //+---------------------------------------------------------------------------
  3478. //
  3479. // StartModalInput
  3480. //
  3481. //----------------------------------------------------------------------------
  3482. void CTipbarWnd::StartModalInput(ITfLangBarEventSink *pSink, DWORD dwThreadId)
  3483. {
  3484. if (!_putb)
  3485. return;
  3486. _putb->SetModalInput(pSink, dwThreadId, 0);
  3487. //
  3488. // we want this to track a mouse event of Tray window.
  3489. //
  3490. if (g_pTrayIconWnd)
  3491. _putb->SetModalInput(pSink, g_pTrayIconWnd->GetThreadIdTray(), 0);
  3492. //
  3493. // we want this to track a mouse event of CMD prompt window.
  3494. //
  3495. _putb->SetModalInput(pSink, GetCurrentThreadId(), TF_LBSMI_FILTERCURRENTTHREAD );
  3496. }
  3497. //+---------------------------------------------------------------------------
  3498. //
  3499. // StopModalInput
  3500. //
  3501. //----------------------------------------------------------------------------
  3502. void CTipbarWnd::StopModalInput(DWORD dwThreadId)
  3503. {
  3504. if (!_putb)
  3505. return;
  3506. _putb->SetModalInput(NULL, dwThreadId, 0);
  3507. if (g_pTrayIconWnd)
  3508. _putb->SetModalInput(NULL, g_pTrayIconWnd->GetThreadIdTray(), 0);
  3509. _putb->SetModalInput(NULL, GetCurrentThreadId(), 0);
  3510. }
  3511. //+---------------------------------------------------------------------------
  3512. //
  3513. // ClearLBItemList
  3514. //
  3515. //----------------------------------------------------------------------------
  3516. void CTipbarWnd::ClearLBItemList()
  3517. {
  3518. _itemList.Clear();
  3519. if (_pFocusThread)
  3520. {
  3521. OnThreadItemChange(_pFocusThread->_dwThreadId);
  3522. }
  3523. }
  3524. //+---------------------------------------------------------------------------
  3525. //
  3526. // ShowMenuExtendMenu
  3527. //
  3528. //----------------------------------------------------------------------------
  3529. void CTipbarWnd::ShowContextMenu(POINT pt, RECT *prc, BOOL fExtendMenuItems)
  3530. {
  3531. CUTBContextMenu *pMenu = NULL;
  3532. RECT rc;
  3533. CTipbarThread *ptt = GetFocusThread();
  3534. DWORD dwThreadId;
  3535. UINT uId = CUI_MENU_UNSELECTED;
  3536. //
  3537. // CTipbarWnd could be destroyed during ShowPopup().
  3538. //
  3539. AddRef();
  3540. if (!prc)
  3541. {
  3542. rc.left = pt.x;
  3543. rc.top = pt.y;
  3544. rc.right = pt.x;
  3545. rc.bottom = pt.y;
  3546. prc = &rc;
  3547. }
  3548. if (!ptt)
  3549. goto Exit;
  3550. pMenu = new CUTBContextMenu(this);
  3551. if (!pMenu)
  3552. goto Exit;
  3553. if (!pMenu->Init())
  3554. goto Exit;
  3555. _pttModal = ptt;
  3556. StartModalInput(this, ptt->_dwThreadId);
  3557. dwThreadId = GetCurrentThreadId();
  3558. _pModalMenu = pMenu;
  3559. uId = pMenu->ShowPopup(this, pt, prc, fExtendMenuItems);
  3560. _pModalMenu = NULL;
  3561. if (_pttModal)
  3562. StopModalInput(_pttModal->_dwThreadId);
  3563. _pttModal = NULL;
  3564. if (uId != CUI_MENU_UNSELECTED)
  3565. {
  3566. pMenu->SelectMenuItem(uId);
  3567. }
  3568. Exit:
  3569. if (pMenu)
  3570. delete pMenu;
  3571. Release();
  3572. }
  3573. //+---------------------------------------------------------------------------
  3574. //
  3575. // IsInItemChangOrDirty
  3576. //
  3577. //----------------------------------------------------------------------------
  3578. BOOL CTipbarWnd::IsInItemChangeOrDirty(CTipbarThread *pThread)
  3579. {
  3580. if (pThread->_dwThreadId == _dwThreadItemChangedForTimer)
  3581. return TRUE;
  3582. return pThread->IsDirtyItem();
  3583. }
  3584. //+---------------------------------------------------------------------------
  3585. //
  3586. // OnGetObject
  3587. //
  3588. //----------------------------------------------------------------------------
  3589. LRESULT CTipbarWnd::OnGetObject( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  3590. {
  3591. LRESULT lResult = (LRESULT)0;
  3592. switch (lParam)
  3593. {
  3594. //
  3595. // We process the OBJID_CLIENT object identifier;
  3596. // this is the client area of our application
  3597. // window.
  3598. //
  3599. case OBJID_CLIENT:
  3600. {
  3601. HRESULT hr;
  3602. if (_pTipbarAcc == NULL)
  3603. {
  3604. return E_OUTOFMEMORY;
  3605. }
  3606. if (!_pTipbarAcc->IsInitialized())
  3607. {
  3608. //
  3609. //
  3610. //
  3611. hr = EnsureCoInit();
  3612. if (FAILED(hr))
  3613. {
  3614. break;
  3615. }
  3616. //
  3617. // Initialize our Accessible object. If the
  3618. // initialization fails, delete the Accessible
  3619. // object and return the failure code.
  3620. //
  3621. hr = _pTipbarAcc->Initialize();
  3622. if (FAILED(hr))
  3623. {
  3624. _pTipbarAcc->Release();
  3625. _pTipbarAcc = NULL;
  3626. lResult = (LRESULT)hr;
  3627. break;
  3628. }
  3629. //
  3630. // Send an EVENT_OBJECT_CREATE WinEvent for the
  3631. // creation of the Accessible object for the
  3632. // client area.
  3633. //
  3634. _pTipbarAcc->NotifyWinEvent( EVENT_OBJECT_CREATE , this);
  3635. }
  3636. //
  3637. // Call LresultFromObject() to create reference to
  3638. // our Accessible object that MSAA will marshal to
  3639. // the client.
  3640. //
  3641. lResult = _pTipbarAcc->CreateRefToAccObj( wParam );
  3642. break;
  3643. }
  3644. }
  3645. return lResult;
  3646. }
  3647. //+---------------------------------------------------------------------------
  3648. //
  3649. // OnThemeChanged
  3650. //
  3651. //----------------------------------------------------------------------------
  3652. void CTipbarWnd::OnThemeChanged(HWND hwnd, WPARAM wParam, LPARAM lParam)
  3653. {
  3654. #ifdef USE_OFC10LOOKONWINXP
  3655. CheckO10Flag();
  3656. #endif
  3657. CUIFWindow::OnThemeChanged(hwnd, wParam, lParam);
  3658. }
  3659. //+---------------------------------------------------------------------------
  3660. //
  3661. // StartDoDefaultActionTimer
  3662. //
  3663. //----------------------------------------------------------------------------
  3664. BOOL CTipbarWnd::StartDoAccDefaultActionTimer(CTipbarItem *pItem)
  3665. {
  3666. if (!_pTipbarAcc)
  3667. return FALSE;
  3668. _nDoAccDefaultActionItemId = _pTipbarAcc->GetIDOfItem(pItem);
  3669. if ((_nDoAccDefaultActionItemId == 0) || (_nDoAccDefaultActionItemId == -1))
  3670. return FALSE;
  3671. KillTimer(TIPWND_TIMER_DOACCDEFAULTACTION);
  3672. SetTimer(TIPWND_TIMER_DOACCDEFAULTACTION, g_uTimerElapseDOACCDEFAULTACTION);
  3673. return TRUE;
  3674. }
  3675. //////////////////////////////////////////////////////////////////////////////
  3676. //
  3677. // CTipbarThread
  3678. //
  3679. //////////////////////////////////////////////////////////////////////////////
  3680. //+---------------------------------------------------------------------------
  3681. //
  3682. // ctor
  3683. //
  3684. //----------------------------------------------------------------------------
  3685. CTipbarThread::CTipbarThread(CTipbarWnd *ptw)
  3686. {
  3687. Dbg_MemSetThisName(TEXT("CTipbarThread"));
  3688. _ptw = ptw;
  3689. _dwThreadId = 0;
  3690. _plbim = NULL;
  3691. _ref = 1;
  3692. }
  3693. //+---------------------------------------------------------------------------
  3694. //
  3695. // Init
  3696. //
  3697. //----------------------------------------------------------------------------
  3698. HRESULT CTipbarThread::Init(DWORD dwThreadId)
  3699. {
  3700. DWORD dwThreadIdTmp;
  3701. HRESULT hr = S_OK;
  3702. _dwThreadId = dwThreadId;
  3703. if (!TF_GetThreadFlags(_dwThreadId, &_dwThreadFlags, &_dwProcessId, &_dwTickTime))
  3704. return E_FAIL;
  3705. if (IsConsole())
  3706. return S_OK;
  3707. // What's happening: we eventually reach InternalGetThreadUIManager
  3708. // which, if _dwThreadId is NULL, will substitute
  3709. // g_ShareMem.dwActiveThreadId.
  3710. // This is dangerous, because if the active thread does not match
  3711. // this one we'll do rpc and _plbim will be on the wrong thread.
  3712. // Passing in _dwThreadId seems like the right thing to do....
  3713. hr = _ptw->GetLangBarMgr()->GetThreadLangBarItemMgr(_dwThreadId, &_plbim, &dwThreadIdTmp);
  3714. if (FAILED(hr))
  3715. return hr;
  3716. Assert(dwThreadIdTmp == _dwThreadId);
  3717. return hr;
  3718. }
  3719. //+---------------------------------------------------------------------------
  3720. //
  3721. // dtor
  3722. //
  3723. //----------------------------------------------------------------------------
  3724. CTipbarThread::~CTipbarThread()
  3725. {
  3726. #ifdef DEBUG
  3727. Assert(!_fInCallOnUpdateHandler);
  3728. #endif
  3729. if (_ptw)
  3730. {
  3731. Assert(this != _ptw->GetFocusThread());
  3732. RemoveUIObjs();
  3733. _ptw->CleanUpThreadPointer(this, TRUE);
  3734. }
  3735. _UninitItemList(TRUE);
  3736. SafeReleaseClear(_plbim);
  3737. }
  3738. //+---------------------------------------------------------------------------
  3739. //
  3740. // _AddRef
  3741. //
  3742. //----------------------------------------------------------------------------
  3743. ULONG CTipbarThread::_AddRef( )
  3744. {
  3745. _ref++;
  3746. return _ref;
  3747. }
  3748. //+---------------------------------------------------------------------------
  3749. //
  3750. // _Release
  3751. //
  3752. //----------------------------------------------------------------------------
  3753. ULONG CTipbarThread::_Release( )
  3754. {
  3755. ULONG cr;
  3756. _ref--;
  3757. cr = _ref;
  3758. if (cr == 0) {
  3759. delete this;
  3760. }
  3761. return cr;
  3762. }
  3763. //+---------------------------------------------------------------------------
  3764. //
  3765. // SetFocus
  3766. //
  3767. //----------------------------------------------------------------------------
  3768. BOOL CTipbarThread::SetFocus(BOOL fFocus)
  3769. {
  3770. if (!fFocus)
  3771. {
  3772. int i;
  3773. for (i = 0; i < _rgItem.Count(); i++)
  3774. {
  3775. CTipbarItem *pItem = _rgItem.Get(i);
  3776. CTipbarBalloonItem *pballoon;
  3777. if (pItem &&
  3778. SUCCEEDED(pItem->QueryInterface(IID_PRIV_BALLOONITEM, (void **)&pballoon)))
  3779. {
  3780. pballoon->DestroyBalloonTip();
  3781. pballoon->Release();
  3782. }
  3783. }
  3784. }
  3785. return TRUE;
  3786. }
  3787. //+---------------------------------------------------------------------------
  3788. //
  3789. // InitItemList
  3790. //
  3791. //----------------------------------------------------------------------------
  3792. #define NUM_GETITEMATONCE 30
  3793. HRESULT CTipbarThread::InitItemList()
  3794. {
  3795. HRESULT hr = E_FAIL;
  3796. IEnumTfLangBarItems *pEnum = NULL;
  3797. RECT rc;
  3798. CEnumCatCache *penumcache = NULL;
  3799. CGuidDwordCache *pgdcache = NULL;
  3800. if (!_ptw)
  3801. return hr;
  3802. SIZE sizeWndFrame;
  3803. sizeWndFrame.cx = 0;
  3804. sizeWndFrame.cy = 0;
  3805. if (_ptw->GetWndFrame() != NULL)
  3806. _ptw->GetWndFrame()->GetFrameSize( &sizeWndFrame );
  3807. _ptw->InitThemeMargins();
  3808. if (!IsVertical())
  3809. {
  3810. rc.left = _ptw->GetGripperWidth() + 1 + sizeWndFrame.cx;
  3811. rc.top = 0 + sizeWndFrame.cy;
  3812. rc.right = 0;
  3813. rc.bottom = _ptw->GetTipbarHeight() - sizeWndFrame.cy;
  3814. }
  3815. else
  3816. {
  3817. rc.left = 0 + sizeWndFrame.cx;
  3818. rc.top = _ptw->GetGripperWidth() + 1 + sizeWndFrame.cy;
  3819. rc.right = _ptw->GetTipbarHeight() - sizeWndFrame.cx;
  3820. rc.bottom = 0;
  3821. }
  3822. _nNumItem = 0;
  3823. penumcache = new CEnumCatCache;
  3824. if (!penumcache)
  3825. {
  3826. TraceMsg(TF_FUNC, "could not create CEnumCatCache");
  3827. goto Exit;
  3828. }
  3829. pgdcache = new CGuidDwordCache;
  3830. if (!pgdcache)
  3831. {
  3832. TraceMsg(TF_FUNC, "could not create CGuidDwordCache");
  3833. goto Exit;
  3834. }
  3835. if (_plbim)
  3836. {
  3837. ULONG ulFetched = 0;
  3838. ITfLangBarItem *plbi[NUM_GETITEMATONCE] = {NULL};
  3839. TF_LANGBARITEMINFO lbiInfo[NUM_GETITEMATONCE];
  3840. DWORD dwStatus[NUM_GETITEMATONCE];
  3841. ULONG ul;
  3842. if (SUCCEEDED(hr = _plbim->GetItems(NUM_GETITEMATONCE,
  3843. plbi,
  3844. lbiInfo,
  3845. dwStatus,
  3846. &ulFetched)) && ulFetched)
  3847. {
  3848. for (ul = 0; ul < ulFetched; ul++)
  3849. {
  3850. if (plbi[ul])
  3851. {
  3852. if (SUCCEEDED(hr))
  3853. {
  3854. if (!InsertItem(plbi[ul],
  3855. penumcache,
  3856. pgdcache,
  3857. &rc,
  3858. _ptw->GetThemeMargins(),
  3859. &lbiInfo[ul],
  3860. &dwStatus[ul]))
  3861. {
  3862. hr = E_FAIL;
  3863. }
  3864. }
  3865. plbi[ul]->Release();
  3866. }
  3867. }
  3868. }
  3869. if (SUCCEEDED(hr))
  3870. _AdviseItemsSink();
  3871. }
  3872. else if (IsConsole())
  3873. {
  3874. CLBarInatItem *pInatItem = new CLBarInatItem(_dwThreadId);
  3875. if (pInatItem)
  3876. {
  3877. #ifdef DEBUG
  3878. Assert(!_fIsInatItem);
  3879. _fIsInatItem = TRUE;
  3880. #endif
  3881. TF_LANGBARITEMINFO lbiInfo;
  3882. DWORD dwStatus;
  3883. pInatItem->GetInfo(&lbiInfo);
  3884. pInatItem->GetStatus(&dwStatus);
  3885. InsertItem(pInatItem, penumcache, pgdcache, &rc, _ptw->GetThemeMargins(), &lbiInfo, &dwStatus);
  3886. pInatItem->Release();
  3887. _AdviseItemsSink();
  3888. hr = S_OK;
  3889. }
  3890. }
  3891. LocateItems();
  3892. Exit:
  3893. if (penumcache)
  3894. delete penumcache;
  3895. if (pgdcache)
  3896. delete pgdcache;
  3897. return hr;
  3898. }
  3899. //+---------------------------------------------------------------------------
  3900. //
  3901. // GetTextSize
  3902. //
  3903. //----------------------------------------------------------------------------
  3904. void CTipbarThread::GetTextSize(BSTR bstr, SIZE *psize)
  3905. {
  3906. HFONT hfontOld = NULL;
  3907. HDC hdc = GetDC(_ptw->GetWnd());
  3908. if (SUCCEEDED(_ptw->EnsureThemeData(_ptw->GetWnd())))
  3909. {
  3910. RECT rcText;
  3911. LOGFONTW lf;
  3912. HFONT hfont = NULL;
  3913. CUIFTheme themeBtn;
  3914. Assert(IsOnNT51());
  3915. themeBtn.SetActiveTheme(L"TOOLBAR", TP_BUTTON, 0);
  3916. if (SUCCEEDED(themeBtn.OpenThemeData(_ptw->GetWnd())))
  3917. {
  3918. if (SUCCEEDED(themeBtn.GetThemeFont(NULL, 0 , TMT_FONT, &lf)))
  3919. if (hfont = CreateFontIndirectW(&lf))
  3920. hfontOld = (HFONT)SelectObject(hdc, hfont);
  3921. themeBtn.GetThemeTextExtent(hdc, 0 , bstr, SysStringLen(bstr),0, NULL, &rcText);
  3922. }
  3923. psize->cx = rcText.right;
  3924. psize->cy = rcText.bottom;
  3925. if (hfontOld)
  3926. SelectObject(hdc, hfontOld);
  3927. if (hfont)
  3928. DeleteObject(hfont);
  3929. }
  3930. else
  3931. {
  3932. if (_ptw->GetFont())
  3933. hfontOld = (HFONT)SelectObject(hdc, _ptw->GetFont());
  3934. FLGetTextExtentPoint32( hdc, bstr, SysStringLen(bstr), psize);
  3935. if (hfontOld)
  3936. SelectObject(hdc, hfontOld);
  3937. }
  3938. ReleaseDC(_ptw->GetWnd(), hdc);
  3939. }
  3940. //+---------------------------------------------------------------------------
  3941. //
  3942. // InsertItem
  3943. //
  3944. //----------------------------------------------------------------------------
  3945. BOOL CTipbarThread::InsertItem(ITfLangBarItem *plbi, CEnumCatCache *penumcache, CGuidDwordCache *pgdcache, RECT *prc, MARGINS *pmargins, TF_LANGBARITEMINFO *plbiInfo, DWORD *pdwStatus)
  3946. {
  3947. ITfLangBarItemButton *plbiButton = NULL;
  3948. ITfLangBarItemBitmapButton *plbiBitmapButton = NULL;
  3949. ITfLangBarItemBitmap *plbiBitmap = NULL;
  3950. ITfLangBarItemBalloon *plbiBalloon = NULL;
  3951. CTipbarItem *ptbItem = NULL;
  3952. RECT rc = {0, 0, 0, 0};
  3953. BOOL bRet = FALSE;
  3954. BSTR bstrText = NULL;
  3955. Assert(plbi);
  3956. if ((SUCCEEDED(plbi->QueryInterface(IID_ITfLangBarItemButton,
  3957. (void **)&plbiButton))) ||
  3958. (SUCCEEDED(plbi->QueryInterface(IID_ITfLangBarItemBitmapButton,
  3959. (void **)&plbiBitmapButton))))
  3960. {
  3961. if (!_ptw)
  3962. goto Next;
  3963. SIZE sizeText = {0,0};
  3964. DWORD dwNuiBtnStyle = 0;
  3965. DWORD dwSBtnShowType = 0;
  3966. int nWidth = _ptw->GetSmIconWidth() + _ptw->GetItemMargin();
  3967. if (_ptw->IsShowText())
  3968. {
  3969. dwSBtnShowType |= UITBBUTTON_TEXT;
  3970. HRESULT hr;
  3971. if (plbiButton)
  3972. hr = plbiButton->GetText(&bstrText);
  3973. else if (plbiBitmapButton)
  3974. hr = plbiBitmapButton->GetText(&bstrText);
  3975. else
  3976. goto Next;
  3977. //
  3978. // check if it is disconnected.
  3979. //
  3980. if (!_ptw)
  3981. goto Next;
  3982. if (SUCCEEDED(hr) && bstrText)
  3983. {
  3984. GetTextSize(bstrText, &sizeText);
  3985. //
  3986. // use height for text margin.
  3987. //
  3988. nWidth += (sizeText.cx + (sizeText.cy / 2));
  3989. }
  3990. }
  3991. nWidth += pmargins->cxLeftWidth;
  3992. nWidth += pmargins->cxRightWidth;
  3993. dwNuiBtnStyle = plbiInfo->dwStyle &
  3994. (TF_LBI_STYLE_BTN_BUTTON |
  3995. TF_LBI_STYLE_BTN_MENU |
  3996. TF_LBI_STYLE_BTN_TOGGLE);
  3997. if ((dwNuiBtnStyle & (TF_LBI_STYLE_BTN_BUTTON | TF_LBI_STYLE_BTN_MENU))
  3998. == (TF_LBI_STYLE_BTN_BUTTON | TF_LBI_STYLE_BTN_MENU))
  3999. nWidth += 14;
  4000. if (!IsVertical())
  4001. {
  4002. prc->right = prc->left + nWidth;
  4003. }
  4004. else
  4005. {
  4006. prc->bottom = prc->top + nWidth;
  4007. dwNuiBtnStyle |= UITBBUTTON_VERTICAL;
  4008. }
  4009. if (plbiButton)
  4010. {
  4011. ptbItem = new CTipbarButtonItem(this,
  4012. plbiButton,
  4013. plbiButton,
  4014. 0,
  4015. prc,
  4016. 0,
  4017. dwNuiBtnStyle,
  4018. dwSBtnShowType,
  4019. plbiInfo,
  4020. *pdwStatus);
  4021. }
  4022. else if (plbiBitmapButton)
  4023. {
  4024. ptbItem = new CTipbarBitmapButtonItem(this,
  4025. plbiBitmapButton,
  4026. plbiBitmapButton,
  4027. 0,
  4028. prc,
  4029. 0,
  4030. dwNuiBtnStyle,
  4031. dwSBtnShowType,
  4032. plbiInfo,
  4033. *pdwStatus);
  4034. }
  4035. else
  4036. {
  4037. Assert(0);
  4038. goto Next;
  4039. }
  4040. if (!ptbItem)
  4041. goto Next;
  4042. ptbItem->Init();
  4043. if (IsVertical())
  4044. ptbItem->SetFont(_ptw->GetVerticalFont());
  4045. ptbItem->SetText((bstrText && SysStringLen(bstrText)) ? bstrText : NULL);
  4046. ptbItem->SetTextSize(&sizeText);
  4047. GetSortScore(ptbItem->GetItemSortScore(), plbiInfo, penumcache, pgdcache);
  4048. ptbItem->SetWidth(nWidth);
  4049. }
  4050. else if (SUCCEEDED(plbi->QueryInterface(IID_ITfLangBarItemBitmap,
  4051. (void **)&plbiBitmap)))
  4052. {
  4053. if (!_ptw)
  4054. goto Next;
  4055. if (!plbiBitmap)
  4056. goto Next;
  4057. SIZE sizeDefault = {_ptw->GetSmIconWidth() * 2,
  4058. _ptw->GetSmIconHeight()};
  4059. SIZE size;
  4060. plbiBitmap->GetPreferredSize(&sizeDefault, &size);
  4061. if (!_ptw)
  4062. goto Next;
  4063. if (!IsVertical())
  4064. prc->right = prc->left + size.cx;
  4065. else
  4066. prc->bottom = prc->top + size.cx;
  4067. ptbItem = new CTipbarBitmapItem(this,
  4068. plbiBitmap,
  4069. plbiBitmap,
  4070. 0,
  4071. prc,
  4072. 0,
  4073. plbiInfo,
  4074. *pdwStatus);
  4075. if (!ptbItem)
  4076. goto Next;
  4077. ptbItem->Init();
  4078. GetSortScore(ptbItem->GetItemSortScore(), plbiInfo, penumcache, pgdcache);
  4079. ptbItem->SetWidth(size.cx);
  4080. }
  4081. else if (SUCCEEDED(plbi->QueryInterface(IID_ITfLangBarItemBalloon,
  4082. (void **)&plbiBalloon)))
  4083. {
  4084. if (!_ptw)
  4085. goto Next;
  4086. if (!plbiBalloon)
  4087. goto Next;
  4088. SIZE sizeDefault = {32,16};
  4089. SIZE size;
  4090. plbiBalloon->GetPreferredSize(&sizeDefault, &size);
  4091. if (!_ptw)
  4092. goto Next;
  4093. if (!IsVertical())
  4094. prc->right = prc->left + size.cx;
  4095. else
  4096. prc->bottom = prc->top + size.cx;
  4097. ptbItem = new CTipbarBalloonItem(this,
  4098. plbiBalloon,
  4099. plbiBalloon,
  4100. 0,
  4101. prc,
  4102. 0,
  4103. plbiInfo,
  4104. *pdwStatus);
  4105. if (!ptbItem)
  4106. goto Next;
  4107. ptbItem->Init();
  4108. if (IsVertical())
  4109. ptbItem->SetFont(_ptw->GetVerticalFont());
  4110. GetSortScore(ptbItem->GetItemSortScore(), plbiInfo, penumcache, pgdcache);
  4111. ptbItem->SetWidth(size.cx);
  4112. }
  4113. Next:
  4114. SafeReleaseClear(plbiButton);
  4115. SafeReleaseClear(plbiBitmapButton);
  4116. SafeReleaseClear(plbiBitmap);
  4117. SafeReleaseClear(plbiBalloon);
  4118. if (!_ptw && ptbItem)
  4119. {
  4120. delete ptbItem;
  4121. ptbItem = NULL;
  4122. }
  4123. if (ptbItem)
  4124. {
  4125. CTipbarItem **pptbItem = _rgItem.Append(1);
  4126. if (pptbItem)
  4127. {
  4128. *pptbItem = ptbItem;
  4129. if (!IsVertical())
  4130. prc->left = prc->right;
  4131. else
  4132. prc->top = prc->bottom;
  4133. _nNumItem++;
  4134. bRet = TRUE;
  4135. }
  4136. else
  4137. {
  4138. delete ptbItem;
  4139. ptbItem = NULL;
  4140. }
  4141. }
  4142. if (bstrText)
  4143. SysFreeString(bstrText);
  4144. return bRet;
  4145. }
  4146. //+---------------------------------------------------------------------------
  4147. //
  4148. // _UninitItemList
  4149. //
  4150. //----------------------------------------------------------------------------
  4151. HRESULT CTipbarThread::_UninitItemList(BOOL fUnAdvise)
  4152. {
  4153. int i = 0;
  4154. HRESULT hr = S_OK;
  4155. for (i = 0; i < _rgItem.Count(); i++)
  4156. {
  4157. CTipbarItem *pItem = _rgItem.Get(i);
  4158. if (!pItem)
  4159. continue;
  4160. pItem->Disconnect();
  4161. }
  4162. if (fUnAdvise)
  4163. {
  4164. if ((_dwThreadId == GetCurrentThreadId()) ||
  4165. !MyWaitForInputIdle(_dwThreadId, UTB_INPUTIDLETIMEOUT))
  4166. hr = _UnadviseItemsSink();
  4167. }
  4168. for (i = 0; i < _rgItem.Count(); i++)
  4169. {
  4170. CTipbarItem *pItem = _rgItem.Get(i);
  4171. if (!pItem)
  4172. continue;
  4173. if (_ptw)
  4174. pItem->RemoveMeToUI(_ptw);
  4175. pItem->ClearConnections();
  4176. if (!_ptw)
  4177. pItem->ClearWnd();
  4178. else
  4179. pItem->DetachWnd();
  4180. pItem->UninitUIResource();
  4181. pItem->Release();
  4182. }
  4183. _rgItem.Clear();
  4184. RemoveAllSeparators();
  4185. return hr;
  4186. }
  4187. //+---------------------------------------------------------------------------
  4188. //
  4189. // _AdviseItemsSink
  4190. //
  4191. //----------------------------------------------------------------------------
  4192. void CTipbarThread::_AdviseItemsSink()
  4193. {
  4194. HRESULT hr;
  4195. int nCnt = _rgItem.Count();
  4196. int i = 0;
  4197. ITfLangBarItemSink **pplbis = NULL;
  4198. GUID *pguid = NULL;
  4199. DWORD *pdwCookie = NULL;
  4200. if (!_plbim || !nCnt)
  4201. goto Exit;
  4202. pplbis = new ITfLangBarItemSink*[nCnt];
  4203. if (!pplbis)
  4204. goto Exit;
  4205. pguid = new GUID[nCnt];
  4206. if (!pguid)
  4207. goto Exit;
  4208. pdwCookie = new DWORD[nCnt];
  4209. if (!pdwCookie)
  4210. goto Exit;
  4211. for (i = 0; (i < nCnt) && (i < _rgItem.Count()); i++)
  4212. {
  4213. CTipbarItem *pItem = _rgItem.Get(i);
  4214. if (!pItem)
  4215. {
  4216. Assert(0);
  4217. goto Exit;
  4218. }
  4219. pguid[i] = *pItem->GetGUID();
  4220. hr = pItem->QueryInterface(IID_ITfLangBarItemSink, (void **)&pplbis[i]);
  4221. if (FAILED(hr))
  4222. {
  4223. Assert(0);
  4224. goto Exit;
  4225. }
  4226. }
  4227. if (FAILED(_plbim->AdviseItemsSink(nCnt, pplbis, pguid, pdwCookie)))
  4228. goto Exit;
  4229. for (i = 0; (i < nCnt) && (i < _rgItem.Count()); i++)
  4230. {
  4231. CTipbarItem *pItem = _rgItem.Get(i);
  4232. if (pItem)
  4233. pItem->_dwlbiSinkCookie = pdwCookie[i];
  4234. pplbis[i]->Release();
  4235. }
  4236. Exit:
  4237. if (pplbis)
  4238. delete[] pplbis;
  4239. if (pguid)
  4240. delete[] pguid;
  4241. if (pdwCookie)
  4242. delete[] pdwCookie;
  4243. }
  4244. //+---------------------------------------------------------------------------
  4245. //
  4246. // _UnadviseItemsSink
  4247. //
  4248. //----------------------------------------------------------------------------
  4249. HRESULT CTipbarThread::_UnadviseItemsSink()
  4250. {
  4251. int nCnt = _rgItem.Count();
  4252. int i = 0;
  4253. DWORD *pdwCookie = NULL;
  4254. HRESULT hr = S_OK;
  4255. if (!nCnt)
  4256. goto Exit;
  4257. if (!_plbim)
  4258. {
  4259. hr = E_FAIL;
  4260. goto Exit;
  4261. }
  4262. pdwCookie = new DWORD[nCnt];
  4263. if (!pdwCookie)
  4264. {
  4265. hr = E_OUTOFMEMORY;
  4266. goto Exit;
  4267. }
  4268. for (i = 0; i < nCnt; i++)
  4269. {
  4270. CTipbarItem *pItem = _rgItem.Get(i);
  4271. if (pItem)
  4272. pdwCookie[i] = pItem->_dwlbiSinkCookie;
  4273. }
  4274. if (FAILED(hr = _plbim->UnadviseItemsSink(nCnt, pdwCookie)))
  4275. goto Exit;
  4276. Exit:
  4277. if (pdwCookie)
  4278. delete[] pdwCookie;
  4279. return hr;
  4280. }
  4281. //+---------------------------------------------------------------------------
  4282. //
  4283. // IsHKLToSkipRedrawOnNoItem
  4284. //
  4285. //----------------------------------------------------------------------------
  4286. BOOL CTipbarWnd::IsHKLToSkipRedrawOnNoItem()
  4287. {
  4288. return IsSkipRedrawHKL(GetFocusKeyboardLayout());
  4289. }
  4290. //+---------------------------------------------------------------------------
  4291. //
  4292. // LocateItems
  4293. //
  4294. //----------------------------------------------------------------------------
  4295. void CTipbarThread::LocateItems()
  4296. {
  4297. int i = 0;
  4298. SIZE sizeWndFrame;
  4299. POINT pt;
  4300. RECT rcWork;
  4301. RECT rc;
  4302. BOOL fOverScreen = FALSE;
  4303. int nTipbarHeight;
  4304. _fSkipRedrawOnNoItem = FALSE;
  4305. if (!_ptw)
  4306. return;
  4307. _ptw->GetRect(&rc);
  4308. pt.x = rc.left;
  4309. pt.y = rc.top;
  4310. CUIGetWorkAreaRect(pt, &rcWork);
  4311. sizeWndFrame.cx = 0;
  4312. sizeWndFrame.cy = 0;
  4313. if (_ptw->GetWndFrame() != NULL)
  4314. _ptw->GetWndFrame()->GetFrameSize( &sizeWndFrame );
  4315. for (i = 0; i < _rgItem.Count(); i++)
  4316. {
  4317. CTipbarItem *ptbItem = _rgItem.Get(i);
  4318. CTipbarItem *ptbMin = NULL;
  4319. if (!ptbItem)
  4320. continue;
  4321. int j;
  4322. CItemSortScore issMin(-1, -1, -1);
  4323. int nMin;
  4324. for (j = i; j < _rgItem.Count(); j++)
  4325. {
  4326. CTipbarItem *ptb = _rgItem.Get(j);
  4327. CItemSortScore *piss = ptb->GetItemSortScore();
  4328. if (issMin > *piss)
  4329. {
  4330. ptbMin = ptb;
  4331. issMin = *piss;
  4332. nMin = j;
  4333. }
  4334. }
  4335. if (ptbMin)
  4336. {
  4337. CTipbarItem **pptbItem = _rgItem.GetPtr(i);
  4338. CTipbarItem **pptbMin = _rgItem.GetPtr(nMin);
  4339. *pptbItem = ptbMin;
  4340. *pptbMin = ptbItem;
  4341. }
  4342. }
  4343. LocateItemsAgain:
  4344. RemoveAllSeparators();
  4345. nTipbarHeight = _ptw->GetTipbarHeight();
  4346. if (!IsVertical())
  4347. {
  4348. rc.left = 1 + _ptw->GetGripperWidth() + sizeWndFrame.cx;
  4349. if (rc.bottom - rc.top > nTipbarHeight)
  4350. {
  4351. int nHeightPadding = (rc.bottom - rc.top - nTipbarHeight) / 2;
  4352. if (nHeightPadding > CY_ITEMMARGIN_THEME)
  4353. nHeightPadding -= CY_ITEMMARGIN_THEME;
  4354. else
  4355. nHeightPadding = 0;
  4356. rc.top += (0 + sizeWndFrame.cy + nHeightPadding);
  4357. rc.bottom -= (sizeWndFrame.cy + nHeightPadding);
  4358. }
  4359. else
  4360. {
  4361. rc.top = 0 + sizeWndFrame.cy;
  4362. rc.bottom = nTipbarHeight - sizeWndFrame.cy;
  4363. }
  4364. }
  4365. else
  4366. {
  4367. rc.top = 1 + _ptw->GetGripperWidth() + sizeWndFrame.cx;
  4368. if (rc.right - rc.left > nTipbarHeight)
  4369. {
  4370. int nHeightPadding = (rc.right - rc.left - nTipbarHeight) / 2;
  4371. if (nHeightPadding > CY_ITEMMARGIN_THEME)
  4372. nHeightPadding -= CY_ITEMMARGIN_THEME;
  4373. else
  4374. nHeightPadding = 0;
  4375. rc.left += (0 + sizeWndFrame.cy + nHeightPadding);
  4376. rc.right -= (sizeWndFrame.cy + nHeightPadding);
  4377. }
  4378. else
  4379. {
  4380. rc.left = 0 + sizeWndFrame.cy;
  4381. rc.right = nTipbarHeight - sizeWndFrame.cy;
  4382. }
  4383. }
  4384. i = 0;
  4385. DWORD dwCatScore = 0;
  4386. ULONG ulShownItemInPrevCat = 0;
  4387. BOOL bShowToolbar = FALSE;
  4388. LANGID langid = LANGID(LOWORD(HandleToLong(_ptw->GetFocusKeyboardLayout())));
  4389. CTipbarItem *ptbLastHiddenableItem = NULL;
  4390. while (i < _rgItem.Count())
  4391. {
  4392. LANGBARITEMSTATE *pItemState;
  4393. CTipbarItem *ptbItem = _rgItem.Get(i);
  4394. DWORD dwWidth = ptbItem->GetWidth();
  4395. if (ptbItem->IsHiddenStatusControl())
  4396. {
  4397. if (ptbItem->IsInHiddenStatus())
  4398. goto HideThis;
  4399. }
  4400. else
  4401. {
  4402. pItemState = _ptw->_itemList.FindItem(*ptbItem->GetGUID());
  4403. if (pItemState)
  4404. {
  4405. if (!pItemState->IsShown())
  4406. goto HideThis;
  4407. }
  4408. else
  4409. {
  4410. if (ptbItem->IsHiddenByDefault())
  4411. goto HideThis;
  4412. }
  4413. ptbLastHiddenableItem = ptbItem;
  4414. }
  4415. if (_ptw->IsSFDeskband() && _ptw->IsSFNoExtraIcon())
  4416. {
  4417. REFGUID rguidItem = *ptbItem->GetGUID();
  4418. if (!IsEqualGUID(rguidItem, GUID_TFCAT_TIP_KEYBOARD) &&
  4419. !IsEqualGUID(rguidItem, GUID_LBI_INATITEM) &&
  4420. !IsEqualGUID(rguidItem, GUID_LBI_CTRL) &&
  4421. (!IsFELangId(langid) || (IsFELangId(langid) && !ptbItem->IsShownInTray())))
  4422. goto HideThis;
  4423. }
  4424. if (ptbItem->IsShownInTrayOnly())
  4425. {
  4426. HideThis:
  4427. RECT rcEmp = {0, 0, 0, 0};
  4428. ptbItem->SetRect(&rcEmp);
  4429. ptbItem->VisibleInToolbar(FALSE);
  4430. goto Next;
  4431. }
  4432. if (!ptbItem->IsHiddenStatusControl())
  4433. _ptw->_itemList.StartDemotingTimer(*ptbItem->GetGUID(), FALSE);
  4434. //
  4435. // If we find an Item to be shown, we show toolbar.
  4436. // If we have only "HideOnNoOterItems" to be shown, we hide toolbar.
  4437. //
  4438. if (!ptbItem->IsHideOnNoOtherItems())
  4439. {
  4440. bShowToolbar = TRUE;
  4441. }
  4442. if (ulShownItemInPrevCat && (dwCatScore != ptbItem->GetCatScore()))
  4443. {
  4444. DWORD dwSepStyle = 0;
  4445. if (!IsVertical())
  4446. rc.right = rc.left + _ptw->GetItemDistance();
  4447. else
  4448. {
  4449. rc.bottom = rc.top + _ptw->GetItemDistance();
  4450. dwSepStyle |= UITBSEPARATOR_VERTICAL;
  4451. }
  4452. CUIFSeparator *pSep = new CUIFSeparator(_ptw, -1, &rc, dwSepStyle);
  4453. if (pSep)
  4454. {
  4455. int nCntSep = _rgSep.Count();
  4456. pSep->Initialize();
  4457. if (_rgSep.Insert(nCntSep, 1))
  4458. {
  4459. _rgSep.Set(nCntSep, pSep);
  4460. }
  4461. else
  4462. {
  4463. delete pSep;
  4464. pSep = NULL;
  4465. }
  4466. }
  4467. if (!IsVertical())
  4468. rc.left = rc.right;
  4469. else
  4470. rc.top = rc.bottom;
  4471. ulShownItemInPrevCat = 0;
  4472. }
  4473. dwCatScore = ptbItem->GetCatScore();
  4474. if (!IsVertical())
  4475. rc.right = rc.left + dwWidth;
  4476. else
  4477. rc.bottom = rc.top + dwWidth;
  4478. ptbItem->SetRect(&rc);
  4479. ptbItem->VisibleInToolbar(TRUE);
  4480. if (!IsVertical())
  4481. rc.left = rc.right;
  4482. else
  4483. rc.top = rc.bottom;
  4484. ulShownItemInPrevCat++;
  4485. Next:
  4486. i++;
  4487. }
  4488. // Add the last sepcarator
  4489. if (!IsVertical())
  4490. rc.right = rc.left + 4;
  4491. else
  4492. rc.bottom = rc.top + 4;
  4493. DWORD dwSepStyle = 0;
  4494. if (IsVertical())
  4495. dwSepStyle |= UITBSEPARATOR_VERTICAL;
  4496. CUIFSeparator *pSep = new CUIFSeparator(_ptw, -1, &rc, dwSepStyle);
  4497. if (pSep)
  4498. {
  4499. int nCntSep = _rgSep.Count();
  4500. pSep->Initialize();
  4501. if (_rgSep.Insert(nCntSep, 1))
  4502. {
  4503. _rgSep.Set(nCntSep, pSep);
  4504. }
  4505. else
  4506. {
  4507. delete pSep;
  4508. pSep = NULL;
  4509. }
  4510. }
  4511. if (!IsVertical())
  4512. {
  4513. rc.left = rc.right;
  4514. // allocate the space for ctrl buttons.
  4515. rc.right = rc.left + _ptw->GetCtrlButtonWidth();
  4516. }
  4517. else
  4518. {
  4519. rc.top = rc.bottom;
  4520. // allocate the space for ctrl buttons.
  4521. rc.bottom = rc.top + _ptw->GetCtrlButtonWidth();
  4522. }
  4523. _sizeWnd.cx = rc.right + sizeWndFrame.cx;
  4524. _sizeWnd.cy = rc.bottom + sizeWndFrame.cy;
  4525. if (_ptw->GetWndFrame() != NULL)
  4526. {
  4527. RECT rcWnd;
  4528. rcWnd.left = 0;
  4529. rcWnd.top = 0;
  4530. rcWnd.right = _sizeWnd.cx;
  4531. rcWnd.bottom = _sizeWnd.cy;
  4532. _ptw->GetWndFrame()->SetRect(&rcWnd);
  4533. }
  4534. //
  4535. // If the window is wider than WorkArea, we hide one item and locate items
  4536. // again.
  4537. //
  4538. if (_sizeWnd.cx > (rcWork.right - rcWork.left))
  4539. {
  4540. fOverScreen = TRUE;
  4541. if (ptbLastHiddenableItem)
  4542. {
  4543. _ptw->_itemList.SetDemoteLevel(*ptbLastHiddenableItem->GetGUID(),
  4544. DL_HIDDENLEVEL1);
  4545. goto LocateItemsAgain;
  4546. }
  4547. }
  4548. //
  4549. // Exclude caption buttons.
  4550. //
  4551. int dxOffset = 0;
  4552. int dyOffset = 0;
  4553. if (!IsVertical() && g_bExcludeCaptionButtons)
  4554. {
  4555. RECT rcWnd;
  4556. _ptw->GetRect(&rcWnd);
  4557. _ptw->MyClientToScreen(NULL, &rcWnd);
  4558. if (_ptw->CheckExcludeCaptionButtonMode(&rcWnd, &rcWork))
  4559. {
  4560. if ((rcWnd.left + _sizeWnd.cx + _ptw->GetCxDlgFrame()) >
  4561. (rcWork.right - (_ptw->GetCaptionButtonWidth() * 3)))
  4562. {
  4563. dyOffset = 0 - rcWnd.top;
  4564. dxOffset = (rcWork.right - (_ptw->GetCaptionButtonWidth() * 3)) -
  4565. (rcWnd.left + _sizeWnd.cx + _ptw->GetCxDlgFrame());
  4566. _ptw->SetRect(&rcWnd);
  4567. _ptw->SetExcludeCaptionButtonMode(TRUE);
  4568. }
  4569. }
  4570. else
  4571. _ptw->SetExcludeCaptionButtonMode(FALSE);
  4572. }
  4573. MyMoveWnd(dxOffset, dyOffset);
  4574. if (!_ptw)
  4575. goto Exit;
  4576. _ptw->_fIsItemShownInFloatingToolbar = bShowToolbar;
  4577. //
  4578. // We show or hide only when toolbar is floating arround.
  4579. //
  4580. if (IsFocusThread() && _ptw->IsSFShowNormal() && !_ptw->IsInFullScreen())
  4581. {
  4582. //
  4583. // Satori Hack.
  4584. //
  4585. // If the focus thread is running with Satori we don't hide
  4586. // the toolbar.
  4587. //
  4588. if (!bShowToolbar && _ptw->IsHKLToSkipRedrawOnNoItem())
  4589. {
  4590. _fSkipRedrawOnNoItem = TRUE;
  4591. goto Exit;
  4592. }
  4593. _ptw->_fShowWindowAtTimer = bShowToolbar;
  4594. _ptw->_pThreadShowWindowAtTimer = this;
  4595. _ptw->_fShowOverItemBalloonAtTimer = fOverScreen;
  4596. _ptw->KillTimer(TIPWND_TIMER_SHOWWINDOW);
  4597. _ptw->SetTimer(TIPWND_TIMER_SHOWWINDOW, g_uTimerElapseSHOWWINDOW);
  4598. #if 0
  4599. _ptw->Show(bShowToolbar);
  4600. //
  4601. // If the window was over the screen and hide some items,
  4602. // we show balloon tips.
  4603. //
  4604. if (fOverScreen)
  4605. _ptw->ShowOverScreenSizeBalloon();
  4606. #endif
  4607. }
  4608. Exit:
  4609. return;
  4610. }
  4611. //+---------------------------------------------------------------------------
  4612. //
  4613. // GetSortScore
  4614. //
  4615. //----------------------------------------------------------------------------
  4616. void CTipbarThread::GetSortScore(CItemSortScore *pScore, TF_LANGBARITEMINFO *plbiInfo, CEnumCatCache *penumcache, CGuidDwordCache *pgdcache)
  4617. {
  4618. DWORD dwSub = 0;
  4619. DWORD dwCat = 0;
  4620. DWORD dwCatIndex = 256;
  4621. IEnumGUID *pEnum;
  4622. BOOL bFound = FALSE;
  4623. GUID guid;
  4624. //
  4625. // check system device type button.
  4626. //
  4627. if (pEnum = penumcache->GetEnumItemsInCategory(GUID_TFCAT_CATEGORY_OF_TIP))
  4628. {
  4629. while (!bFound && (pEnum->Next(1, &guid, NULL) == S_OK))
  4630. {
  4631. dwCatIndex++;
  4632. if (!(dwCat = pgdcache->GetGuidDWORD(guid)))
  4633. dwCat = dwCatIndex;
  4634. if (IsEqualGUID(guid, plbiInfo->guidItem))
  4635. bFound = TRUE;
  4636. else
  4637. {
  4638. IEnumGUID *pEnumTip;
  4639. if (pEnumTip = penumcache->GetEnumItemsInCategory(guid))
  4640. {
  4641. CLSID clsid;
  4642. while (!bFound && (pEnumTip->Next(1, &clsid, NULL) == S_OK))
  4643. {
  4644. dwSub++;
  4645. if (IsEqualGUID(clsid, plbiInfo->clsidService))
  4646. {
  4647. bFound = TRUE;
  4648. }
  4649. }
  4650. }
  4651. }
  4652. }
  4653. }
  4654. if (bFound)
  4655. {
  4656. pScore->Set(dwCat, plbiInfo->ulSort, dwSub);
  4657. return;
  4658. }
  4659. //
  4660. // check system toolbar button.
  4661. //
  4662. if (IsEqualGUID(GUID_NULL, plbiInfo->clsidService))
  4663. {
  4664. pScore->Set(0, plbiInfo->ulSort, 0);
  4665. return;
  4666. }
  4667. else if (IsEqualGUID(CLSID_SYSTEMLANGBARITEM, plbiInfo->clsidService))
  4668. {
  4669. pScore->Set(0, plbiInfo->ulSort, 0);
  4670. return;
  4671. }
  4672. else if (IsEqualGUID(CLSID_SYSTEMLANGBARITEM2, plbiInfo->clsidService))
  4673. {
  4674. pScore->Set((-1), plbiInfo->ulSort, 0);
  4675. return;
  4676. }
  4677. else if (IsEqualGUID(CLSID_SYSTEMLANGBARITEM_KEYBOARD, plbiInfo->clsidService))
  4678. {
  4679. dwCat = pgdcache->GetGuidDWORD(GUID_TFCAT_TIP_KEYBOARD);
  4680. pScore->Set(dwCat, plbiInfo->ulSort, (DWORD)-1);
  4681. return;
  4682. }
  4683. else if (IsEqualGUID(CLSID_SYSTEMLANGBARITEM_SPEECH, plbiInfo->clsidService))
  4684. {
  4685. dwCat = pgdcache->GetGuidDWORD(GUID_TFCAT_TIP_SPEECH);
  4686. pScore->Set(dwCat, plbiInfo->ulSort, (DWORD)-1);
  4687. return;
  4688. }
  4689. else if (IsEqualGUID(CLSID_SYSTEMLANGBARITEM_HANDWRITING, plbiInfo->clsidService))
  4690. {
  4691. dwCat = pgdcache->GetGuidDWORD(GUID_TFCAT_TIP_HANDWRITING);
  4692. pScore->Set(dwCat, plbiInfo->ulSort, (DWORD)-1);
  4693. return;
  4694. }
  4695. pScore->Set((DWORD)-1, (DWORD)-1, (DWORD)-1);
  4696. return;
  4697. }
  4698. //+---------------------------------------------------------------------------
  4699. //
  4700. // UpdateItems
  4701. //
  4702. //----------------------------------------------------------------------------
  4703. BOOL CTipbarThread::UpdateItems()
  4704. {
  4705. int i;
  4706. _fItemChanged = FALSE;
  4707. for (i = 0; i < _rgItem.Count(); i++)
  4708. {
  4709. CTipbarItem *ptbItem = _rgItem.Get(i);
  4710. if (ptbItem)
  4711. ptbItem->OnUpdate(TF_LBI_STATUS | TF_LBI_BTNALL | TF_LBI_BMPALL | TF_LBI_BALLOON);
  4712. }
  4713. for (i = 0; i < _rgSep.Count(); i++)
  4714. {
  4715. CUIFSeparator *pSep = _rgSep.Get(i);
  4716. if (pSep)
  4717. pSep->CallOnPaint();
  4718. }
  4719. return TRUE;
  4720. }
  4721. //+---------------------------------------------------------------------------
  4722. //
  4723. // MyMoveWnd
  4724. //
  4725. //----------------------------------------------------------------------------
  4726. void CTipbarThread::MyMoveWnd(int dxOffset, int dyOffset)
  4727. {
  4728. if (!_ptw)
  4729. return;
  4730. if (_ptw->GetFocusThread() != this)
  4731. return;
  4732. POINT pt;
  4733. RECT rc;
  4734. RECT rcWork;
  4735. _ptw->GetRect(&rc);
  4736. pt.x = rc.left;
  4737. pt.y = rc.top;
  4738. CUIGetWorkAreaRect(pt, &rcWork);
  4739. GetWindowRect(_ptw->GetWnd(), &rc);
  4740. int x = rc.left + dxOffset;
  4741. int y = rc.top + dyOffset;
  4742. if (_ptw->IsInExcludeCaptionButtonMode())
  4743. {
  4744. //
  4745. // now we're in exclude caption button mode.
  4746. // adjust position to the next of caption buttons.
  4747. //
  4748. if (_ptw->CheckExcludeCaptionButtonMode(&rc, &rcWork))
  4749. {
  4750. x = (rcWork.right - (_ptw->GetCaptionButtonWidth() * 3)) -
  4751. (_sizeWnd.cx + _ptw->GetCxDlgFrame());
  4752. y = 0;
  4753. }
  4754. else
  4755. {
  4756. _ptw->SetExcludeCaptionButtonMode(FALSE);
  4757. }
  4758. }
  4759. if (!IsVertical())
  4760. {
  4761. _ptw->SetMoveRect(x, y,
  4762. _sizeWnd.cx + _ptw->GetCxDlgFrame(),
  4763. _ptw->GetTipbarHeight() + _ptw->GetCyDlgFrame());
  4764. }
  4765. else
  4766. {
  4767. _ptw->SetMoveRect(x, y,
  4768. _ptw->GetTipbarHeight() + _ptw->GetCxDlgFrame(),
  4769. _sizeWnd.cy + _ptw->GetCyDlgFrame());
  4770. }
  4771. SIZE sizeWndFrame;
  4772. sizeWndFrame.cx = 0;
  4773. sizeWndFrame.cy = 0;
  4774. if (_ptw->GetWndFrame() != NULL)
  4775. _ptw->GetWndFrame()->GetFrameSize( &sizeWndFrame );
  4776. _ptw->LocateCtrlButtons();
  4777. //
  4778. // call AutoAdjustDeskBandSize() now.
  4779. // this function adjust the deskband size at first call only.
  4780. //
  4781. _ptw->AutoAdjustDeskBandSize();
  4782. }
  4783. //+---------------------------------------------------------------------------
  4784. //
  4785. // AddUIObjs
  4786. //
  4787. //----------------------------------------------------------------------------
  4788. void CTipbarThread::AddUIObjs()
  4789. {
  4790. _AddRef();
  4791. int i;
  4792. for (i = 0; i < _rgItem.Count(); i++)
  4793. {
  4794. CTipbarItem *ptbItem = _rgItem.Get(i);
  4795. if (ptbItem && ptbItem->IsVisibleInToolbar())
  4796. ptbItem->AddMeToUI(_ptw);
  4797. }
  4798. AddAllSeparators();
  4799. MyMoveWnd(0, 0);
  4800. _Release();
  4801. }
  4802. //+---------------------------------------------------------------------------
  4803. //
  4804. // AddAllSeparators
  4805. //
  4806. //----------------------------------------------------------------------------
  4807. void CTipbarThread::AddAllSeparators()
  4808. {
  4809. int i;
  4810. for (i = 0; i < _rgSep.Count(); i++)
  4811. {
  4812. CUIFSeparator *pSep = _rgSep.Get(i);
  4813. if (pSep)
  4814. _ptw->AddUIObj(pSep);
  4815. }
  4816. }
  4817. //+---------------------------------------------------------------------------
  4818. //
  4819. // RemoveUIObjs
  4820. //
  4821. //----------------------------------------------------------------------------
  4822. void CTipbarThread::RemoveUIObjs()
  4823. {
  4824. int i;
  4825. for (i = 0; i < _rgItem.Count(); i++)
  4826. {
  4827. CTipbarItem *ptbItem = _rgItem.Get(i);
  4828. if (ptbItem)
  4829. ptbItem->RemoveMeToUI(_ptw);
  4830. }
  4831. RemoveAllSeparators();
  4832. }
  4833. //+---------------------------------------------------------------------------
  4834. //
  4835. // RemoveAllSeparators
  4836. //
  4837. //----------------------------------------------------------------------------
  4838. void CTipbarThread::RemoveAllSeparators()
  4839. {
  4840. int i;
  4841. for (i = 0; i < _rgSep.Count(); i++)
  4842. {
  4843. CUIFSeparator *pSep = _rgSep.Get(i);
  4844. if (pSep)
  4845. {
  4846. if (_ptw)
  4847. _ptw->RemoveUIObj(pSep);
  4848. delete pSep;
  4849. }
  4850. }
  4851. _rgSep.Clear();
  4852. }
  4853. //+---------------------------------------------------------------------------
  4854. //
  4855. // GetItem
  4856. //
  4857. //----------------------------------------------------------------------------
  4858. CTipbarItem *CTipbarThread::GetItem(REFGUID guid)
  4859. {
  4860. int i;
  4861. for (i = 0; i < _rgItem.Count(); i++)
  4862. {
  4863. CTipbarItem *ptbItem = _rgItem.Get(i);
  4864. if (ptbItem)
  4865. {
  4866. GUID *pguid= ptbItem->GetGUID();
  4867. if (IsEqualGUID(*pguid, guid))
  4868. return ptbItem;
  4869. }
  4870. }
  4871. return NULL;
  4872. }
  4873. //+---------------------------------------------------------------------------
  4874. //
  4875. // IsDirtyItem
  4876. //
  4877. //----------------------------------------------------------------------------
  4878. DWORD CTipbarThread::IsDirtyItem()
  4879. {
  4880. DWORD dwFlags = 0;
  4881. int i;
  4882. for (i = 0; i < _rgItem.Count(); i++)
  4883. {
  4884. CTipbarItem *pItem = _rgItem.Get(i);
  4885. if (pItem)
  4886. dwFlags |= pItem->GetDirtyUpdateFlags();
  4887. }
  4888. return dwFlags;
  4889. }
  4890. //+---------------------------------------------------------------------------
  4891. //
  4892. // CallOnUpdateHandler
  4893. //
  4894. //----------------------------------------------------------------------------
  4895. BOOL CTipbarThread::CallOnUpdateHandler()
  4896. {
  4897. int i;
  4898. int nCnt;
  4899. DWORD dwFlags;
  4900. CTipbarItemGuidArray rgGuid;
  4901. DWORD *pdw = NULL;
  4902. BOOL bRet = TRUE;
  4903. //
  4904. // Windows Bug #367869.
  4905. //
  4906. // AddRef now because there is a change for this thread to be removed.
  4907. //
  4908. _AddRef();
  4909. #ifdef DEBUG
  4910. _fInCallOnUpdateHandler = TRUE;
  4911. #endif
  4912. //
  4913. // we want to use g_pTipbarWnd instead of _ptw.
  4914. // _ptw could be disconnected during this function. If it is disconnected,
  4915. // we can not decrement the pending counter.
  4916. //
  4917. if (g_pTipbarWnd)
  4918. g_pTipbarWnd->StartPendingUpdateUI();
  4919. //
  4920. // if there is no items, do nothing
  4921. //
  4922. nCnt = _rgItem.Count();
  4923. if (!nCnt)
  4924. {
  4925. goto Exit;
  4926. }
  4927. if (!_plbim)
  4928. {
  4929. if (IsConsole())
  4930. {
  4931. for (i = 0; i < _rgItem.Count(); i++)
  4932. {
  4933. DWORD dwStatus;
  4934. CTipbarItem *pItem = _rgItem.Get(i);
  4935. if (pItem && pItem->GetNotifyUI())
  4936. {
  4937. dwFlags = pItem->GetDirtyUpdateFlags();
  4938. if (dwFlags & TF_LBI_STATUS)
  4939. pItem->GetNotifyUI()->GetStatus(&dwStatus);
  4940. else
  4941. dwStatus = 0;
  4942. pItem->ClearDirtyUpdateFlags();
  4943. pItem->OnUpdateHandler(dwFlags, dwStatus);
  4944. }
  4945. }
  4946. }
  4947. goto Exit;
  4948. }
  4949. rgGuid.Init(&_rgItem);
  4950. //
  4951. // if there is no dirty flag, do nothig.
  4952. //
  4953. dwFlags = IsDirtyItem();
  4954. if (!dwFlags)
  4955. goto Exit;
  4956. pdw = new DWORD[nCnt];
  4957. if (!pdw)
  4958. goto Exit;
  4959. //
  4960. // Clear the each item OnUpdate() request
  4961. //
  4962. for (i = 0; (i < nCnt) && (i < _rgItem.Count()); i++)
  4963. {
  4964. CTipbarItem *pItem = _rgItem.Get(i);
  4965. if (!pItem)
  4966. continue;
  4967. pItem->ClearOnUpdateRequest();
  4968. }
  4969. //
  4970. // get items flag at once.
  4971. //
  4972. if (FAILED(_plbim->GetItemsStatus(nCnt, rgGuid.GetPtr(), pdw)))
  4973. {
  4974. TraceMsg(TF_FUNC, "GetItemStatus failed");
  4975. bRet = FALSE;
  4976. goto Exit;
  4977. }
  4978. for (i = 0; (i < nCnt) && (i < _rgItem.Count()); i++)
  4979. {
  4980. CTipbarItem *pItem = _rgItem.Get(i);
  4981. if (!pItem)
  4982. continue;
  4983. //
  4984. // Skip the current item update request if the item has another OnUpdate() Request
  4985. //
  4986. if (pItem->IsNewOnUpdateRequest())
  4987. continue;
  4988. dwFlags = pItem->GetDirtyUpdateFlags();
  4989. if (dwFlags)
  4990. {
  4991. pItem->ClearDirtyUpdateFlags();
  4992. pItem->OnUpdateHandler(dwFlags, pdw[i]);
  4993. }
  4994. }
  4995. Exit:
  4996. if (pdw)
  4997. delete[] pdw;
  4998. //
  4999. // we want to use g_pTipbarWnd instead of _ptw.
  5000. // _ptw could be disconnected during this function. If it is disconnected,
  5001. // we can not decrement the pending counter.
  5002. //
  5003. if (g_pTipbarWnd)
  5004. g_pTipbarWnd->EndPendingUpdateUI();
  5005. #ifdef DEBUG
  5006. _fInCallOnUpdateHandler = FALSE;
  5007. #endif
  5008. _Release();
  5009. return bRet;
  5010. }
  5011. //////////////////////////////////////////////////////////////////////////////
  5012. //
  5013. // CTipbarItem
  5014. //
  5015. //////////////////////////////////////////////////////////////////////////////
  5016. //+---------------------------------------------------------------------------
  5017. //
  5018. // ctor
  5019. //
  5020. //----------------------------------------------------------------------------
  5021. CTipbarItem::CTipbarItem(CTipbarThread *ptt,
  5022. ITfLangBarItem *plbi,
  5023. TF_LANGBARITEMINFO *plbiInfo,
  5024. DWORD dwStatus)
  5025. {
  5026. _ptt = ptt;
  5027. _lbiInfo = *plbiInfo;
  5028. _plbi = plbi;
  5029. _plbi->AddRef();
  5030. _fToolTipInit = FALSE;
  5031. _fAddedToUI = FALSE;
  5032. _fDisconnected = FALSE;
  5033. _dwDirtyUpdateFlags = (TF_LBI_STATUS | TF_LBI_BTNALL | TF_LBI_BMPALL | TF_LBI_BALLOON);
  5034. _dwStatus = dwStatus;
  5035. }
  5036. //+---------------------------------------------------------------------------
  5037. //
  5038. // dtor
  5039. //
  5040. //----------------------------------------------------------------------------
  5041. CTipbarItem::~CTipbarItem()
  5042. {
  5043. if (g_pTipbarWnd && g_pTipbarWnd->GetAccessible())
  5044. {
  5045. g_pTipbarWnd->GetAccessible()->RemoveAccItem(this);
  5046. }
  5047. SafeRelease(_plbi);
  5048. }
  5049. //+---------------------------------------------------------------------------
  5050. //
  5051. // OnSetCursor
  5052. //
  5053. //----------------------------------------------------------------------------
  5054. BOOL CTipbarItem::OnSetCursor(UINT uMsg, POINT pt)
  5055. {
  5056. return FALSE;
  5057. }
  5058. //+---------------------------------------------------------------------------
  5059. //
  5060. // GetToolTip
  5061. //
  5062. //----------------------------------------------------------------------------
  5063. LPCWSTR CTipbarItem::GetToolTip()
  5064. {
  5065. AddRef();
  5066. if (!_fToolTipInit)
  5067. {
  5068. BSTR bstrTooltip;
  5069. HRESULT hr;
  5070. _fToolTipInit = TRUE;
  5071. if (FAILED(hr =_plbi->GetTooltipString(&bstrTooltip)))
  5072. return NULL;
  5073. if (bstrTooltip)
  5074. {
  5075. SetToolTip(bstrTooltip);
  5076. SysFreeString(bstrTooltip);
  5077. }
  5078. }
  5079. LPCWSTR psz;
  5080. psz = GetToolTipFromUIOBJ();
  5081. Release();
  5082. return psz;
  5083. }
  5084. //+---------------------------------------------------------------------------
  5085. //
  5086. // AddedToUI
  5087. //
  5088. //----------------------------------------------------------------------------
  5089. void CTipbarItem::_AddedToUI()
  5090. {
  5091. if (!IsConnected())
  5092. return;
  5093. AddRef();
  5094. _fAddedToUI = TRUE;
  5095. if (_dwDirtyUpdateFlags)
  5096. {
  5097. DWORD dwStatus;
  5098. if (_dwDirtyUpdateFlags & TF_LBI_STATUS)
  5099. _plbi->GetStatus(&dwStatus);
  5100. else
  5101. dwStatus = 0;
  5102. OnUpdateHandler(_dwDirtyUpdateFlags, dwStatus);
  5103. _dwDirtyUpdateFlags = 0;
  5104. }
  5105. if (_ptt && _ptt->_ptw && _ptt->_ptw->GetAccessible())
  5106. {
  5107. _ptt->_ptw->GetAccessible()->AddAccItem(this);
  5108. }
  5109. Release();
  5110. }
  5111. //+---------------------------------------------------------------------------
  5112. //
  5113. // RemovedToUI
  5114. //
  5115. //----------------------------------------------------------------------------
  5116. void CTipbarItem::_RemovedToUI()
  5117. {
  5118. _fAddedToUI = FALSE;
  5119. if (g_pTipbarWnd && g_pTipbarWnd->GetAccessible())
  5120. {
  5121. g_pTipbarWnd->GetAccessible()->RemoveAccItem(this);
  5122. }
  5123. }
  5124. //+---------------------------------------------------------------------------
  5125. //
  5126. // Update
  5127. //
  5128. //----------------------------------------------------------------------------
  5129. HRESULT CTipbarItem::OnUpdate(DWORD dwFlags)
  5130. {
  5131. DWORD dwPrevDirtyUpdateFlags = _dwDirtyUpdateFlags;
  5132. if (!IsConnected())
  5133. return S_OK;
  5134. _dwDirtyUpdateFlags |= dwFlags;
  5135. _fNewOnUpdateRequest = TRUE;
  5136. //
  5137. // if this item is not aded to UI or TrayIcon,
  5138. // we don't have to update anything yet.
  5139. // OnUpdate() will be called again
  5140. // when this item is added to UI or TrayIcon.
  5141. //
  5142. if ((!(dwFlags & TF_LBI_STATUS)) && !_fAddedToUI && !_fAddedToIconTray)
  5143. {
  5144. return S_OK;
  5145. }
  5146. if (_ptt && _ptt->_ptw && _ptt->_ptw->GetWnd())
  5147. {
  5148. _ptt->_ptw->KillTimer(TIPWND_TIMER_ONUPDATECALLED);
  5149. _ptt->_ptw->SetTimer(TIPWND_TIMER_ONUPDATECALLED, g_uTimerElapseONUPDATECALLED);
  5150. }
  5151. return S_OK;
  5152. }
  5153. //+---------------------------------------------------------------------------
  5154. //
  5155. // OnUpdateHandler
  5156. //
  5157. //----------------------------------------------------------------------------
  5158. HRESULT CTipbarItem::OnUpdateHandler(DWORD dwFlags, DWORD dwStatus)
  5159. {
  5160. if (!IsConnected())
  5161. return S_OK;
  5162. BOOL fPrevHidden = TRUE;
  5163. if (IsHiddenStatusControl())
  5164. fPrevHidden = IsInHiddenStatus();
  5165. if (dwFlags & TF_LBI_TOOLTIP)
  5166. {
  5167. _fToolTipInit = FALSE;
  5168. }
  5169. if (dwFlags & TF_LBI_STATUS)
  5170. {
  5171. BOOL fEnabled = (_dwStatus & TF_LBI_STATUS_DISABLED) ? FALSE : TRUE;
  5172. if (!IsHiddenStatusControl())
  5173. {
  5174. // Assert(dwStatus & TF_LBI_STATUS_HIDDEN);
  5175. dwStatus &= ~TF_LBI_STATUS_HIDDEN;
  5176. }
  5177. //
  5178. // MSAA support
  5179. //
  5180. if (_dwStatus != dwStatus)
  5181. {
  5182. if (_ptt && _ptt->_ptw && _ptt->_ptw->GetAccessible())
  5183. _ptt->_ptw->GetAccessible()->NotifyWinEvent( EVENT_OBJECT_STATECHANGE , this);
  5184. }
  5185. _dwStatus = dwStatus;
  5186. if (fEnabled && (_dwStatus & TF_LBI_STATUS_DISABLED))
  5187. Enable(FALSE);
  5188. else if (!fEnabled && !(_dwStatus & TF_LBI_STATUS_DISABLED))
  5189. Enable(TRUE);
  5190. }
  5191. if (IsHiddenStatusControl())
  5192. {
  5193. if (fPrevHidden != IsInHiddenStatus())
  5194. AddRemoveMeToUI(!IsInHiddenStatus() && !IsShownInTrayOnly());
  5195. }
  5196. return S_OK;
  5197. }
  5198. //+---------------------------------------------------------------------------
  5199. //
  5200. // AddRemoveMeToUI
  5201. //
  5202. //----------------------------------------------------------------------------
  5203. void CTipbarItem::AddRemoveMeToUI(BOOL fAdd)
  5204. {
  5205. if (!IsConnected())
  5206. return;
  5207. _ptt->LocateItems();
  5208. _ptt->AddAllSeparators();
  5209. if (fAdd)
  5210. {
  5211. Assert(IsVisibleInToolbar());
  5212. AddMeToUI(_ptt->_ptw);
  5213. }
  5214. else
  5215. {
  5216. Assert(!IsVisibleInToolbar());
  5217. RemoveMeToUI(_ptt->_ptw);
  5218. }
  5219. }
  5220. //////////////////////////////////////////////////////////////////////////////
  5221. //
  5222. // CTipbarButtonItem
  5223. //
  5224. //////////////////////////////////////////////////////////////////////////////
  5225. //+---------------------------------------------------------------------------
  5226. //
  5227. // IUnknown
  5228. //
  5229. //----------------------------------------------------------------------------
  5230. STDAPI CTipbarButtonItem::QueryInterface(REFIID riid, void **ppvObj)
  5231. {
  5232. *ppvObj = NULL;
  5233. if (IsEqualIID(riid, IID_IUnknown) ||
  5234. IsEqualIID(riid, IID_ITfLangBarItemSink))
  5235. {
  5236. *ppvObj = SAFECAST(this, ITfLangBarItemSink *);
  5237. }
  5238. else if (IsEqualIID(riid, IID_PRIV_BUTTONITEM))
  5239. {
  5240. *ppvObj = this;
  5241. }
  5242. if (*ppvObj)
  5243. {
  5244. AddRef();
  5245. return S_OK;
  5246. }
  5247. return E_NOINTERFACE;
  5248. }
  5249. STDAPI_(ULONG) CTipbarButtonItem::AddRef()
  5250. {
  5251. return ++_cRef;
  5252. }
  5253. STDAPI_(ULONG) CTipbarButtonItem::Release()
  5254. {
  5255. _cRef--;
  5256. Assert(_cRef >= 0);
  5257. if (_cRef == 0)
  5258. {
  5259. delete this;
  5260. return 0;
  5261. }
  5262. return _cRef;
  5263. }
  5264. //+---------------------------------------------------------------------------
  5265. //
  5266. // ctor
  5267. //
  5268. //----------------------------------------------------------------------------
  5269. CTipbarButtonItem::CTipbarButtonItem(CTipbarThread *ptt,
  5270. ITfLangBarItem *plbi,
  5271. ITfLangBarItemButton *plbiButton,
  5272. DWORD dwId,
  5273. RECT *prc,
  5274. DWORD dwStyle,
  5275. DWORD dwNuiBtnStyle,
  5276. DWORD dwSBtnShowType,
  5277. TF_LANGBARITEMINFO *plbiInfo,
  5278. DWORD dwStatus)
  5279. : CUIFToolbarButton(ptt->_ptw,
  5280. dwId,
  5281. prc,
  5282. dwStyle,
  5283. dwNuiBtnStyle,
  5284. dwSBtnShowType) ,
  5285. CTipbarItem(ptt, plbi, plbiInfo, dwStatus)
  5286. {
  5287. Dbg_MemSetThisName(TEXT("CTipbarButtonItem"));
  5288. _plbiButton = plbiButton;
  5289. _plbiButton->AddRef();
  5290. if (_dwStatus & TF_LBI_STATUS_DISABLED)
  5291. Enable(FALSE);
  5292. _cRef = 1;
  5293. }
  5294. //+---------------------------------------------------------------------------
  5295. //
  5296. // dtor
  5297. //
  5298. //----------------------------------------------------------------------------
  5299. CTipbarButtonItem::~CTipbarButtonItem()
  5300. {
  5301. UninitUIResource();
  5302. SafeRelease(_plbiButton);
  5303. }
  5304. //+---------------------------------------------------------------------------
  5305. //
  5306. // OnUpdateHandler
  5307. //
  5308. //----------------------------------------------------------------------------
  5309. HRESULT CTipbarButtonItem::OnUpdateHandler(DWORD dwFlags, DWORD dwStatus)
  5310. {
  5311. BOOL fPrevHidden = TRUE;
  5312. if (!IsConnected())
  5313. return S_OK;
  5314. HRESULT hr = S_OK;
  5315. BOOL fCallPaint = FALSE;
  5316. BOOL fUpdateToggleStatus = FALSE;
  5317. //
  5318. // add ref count to be safe for releasing during marshaling.
  5319. //
  5320. AddRef();
  5321. if (dwFlags & TF_LBI_ICON)
  5322. {
  5323. HICON hIconOld;
  5324. HICON hIcon = GetIcon();
  5325. if (!_ptt || !_ptt->_ptw)
  5326. goto Exit;
  5327. if (hIconOld = GetIconFromUIObj())
  5328. DestroyIcon(hIconOld);
  5329. if (hIcon)
  5330. {
  5331. HICON hSmIcon = NULL;
  5332. int cxSmIcon;
  5333. int cySmIcon;
  5334. #ifdef SCALE_ICON
  5335. cxSmIcon = GetSystemMetrics( SM_CXSMICON );
  5336. cySmIcon = GetSystemMetrics( SM_CYSMICON );
  5337. #else
  5338. cxSmIcon = 16;
  5339. cySmIcon = 16;
  5340. #endif
  5341. if (IsTextColorIcon())
  5342. {
  5343. COLORREF rgbText = GetSysColor(COLOR_BTNTEXT);
  5344. if (_ptt &&
  5345. _ptt->_ptw &&
  5346. SUCCEEDED(_pBtn->EnsureThemeData(_ptt->_ptw->GetWnd())))
  5347. {
  5348. COLORREF col;
  5349. if (SUCCEEDED(_pBtn->GetThemeColor(TS_NORMAL, TMT_TEXTCOLOR, &col)))
  5350. rgbText = col;
  5351. }
  5352. CMaskBitmap maskbmp;
  5353. maskbmp.Init(hIcon, 16,16, rgbText);
  5354. ICONINFO ii;
  5355. ii.fIcon = TRUE;
  5356. ii.xHotspot = 0;
  5357. ii.yHotspot = 0;
  5358. ii.hbmMask = maskbmp.GetBmpMask();
  5359. ii.hbmColor = maskbmp.GetBmp();
  5360. hSmIcon = CreateIconIndirect(&ii);
  5361. }
  5362. else
  5363. {
  5364. #ifdef SCALE_ICON
  5365. hSmIcon = StretchIcon(hIcon, cxSmIcon, cySmIcon);
  5366. #else
  5367. hSmIcon = (HICON)CopyImage(hIcon,
  5368. IMAGE_ICON,
  5369. cxSmIcon, cySmIcon,
  5370. LR_COPYFROMRESOURCE);
  5371. #endif
  5372. }
  5373. SetIcon(hSmIcon ? hSmIcon : hIcon);
  5374. if (!IsHiddenStatusControl() && IsVisibleInToolbar())
  5375. StartDemotingTimer(FALSE);
  5376. if (hSmIcon)
  5377. DestroyIcon(hIcon);
  5378. }
  5379. else
  5380. SetIcon((HICON)NULL);
  5381. fCallPaint = TRUE;
  5382. }
  5383. if ((dwFlags & TF_LBI_TEXT) &&
  5384. _ptt &&
  5385. _ptt->_ptw &&
  5386. _ptt->_ptw->IsShowText())
  5387. {
  5388. BSTR bstr;
  5389. hr = _plbiButton->GetText(&bstr);
  5390. if (FAILED(hr))
  5391. goto Exit;
  5392. if (_ptt && bstr && (!GetText() || wcscmp(GetText(), bstr)))
  5393. {
  5394. SIZE size;
  5395. _ptt->GetTextSize(bstr, &size);
  5396. SetText(SysStringLen(bstr) ? bstr : NULL);
  5397. if (_sizeText.cx != size.cx)
  5398. {
  5399. _dwWidth += (size.cx - _sizeText.cx);
  5400. _ptt->LocateItems();
  5401. }
  5402. _sizeText = size;
  5403. fCallPaint = TRUE;
  5404. }
  5405. if (bstr)
  5406. SysFreeString(bstr);
  5407. }
  5408. if (IsHiddenStatusControl())
  5409. fPrevHidden = IsInHiddenStatus();
  5410. CTipbarItem::OnUpdateHandler(dwFlags, dwStatus);
  5411. if (_pBtn->GetToggleState() != IsToggled())
  5412. {
  5413. _pBtn->SetToggleState(IsToggled());
  5414. fUpdateToggleStatus = TRUE;
  5415. }
  5416. if ((dwFlags & (TF_LBI_ICON | TF_LBI_TOOLTIP)) ||
  5417. fUpdateToggleStatus ||
  5418. (fPrevHidden != IsInHiddenStatus()))
  5419. {
  5420. // we need to call Thread's MoveToTray too keep the order of Icons.
  5421. // _ptt->_ptw->MoveToTray();
  5422. if (_ptt && _ptt->_ptw && _ptt->_ptw->IsShowTrayIcon())
  5423. {
  5424. _ptt->_ptw->KillTimer(TIPWND_TIMER_MOVETOTRAY);
  5425. _ptt->_ptw->SetTimer(TIPWND_TIMER_MOVETOTRAY, g_uTimerElapseMOVETOTRAY);
  5426. }
  5427. }
  5428. if (fCallPaint)
  5429. CallOnPaint();
  5430. Exit:
  5431. Release();
  5432. return hr;
  5433. }
  5434. //+---------------------------------------------------------------------------
  5435. //
  5436. // OnRightClick
  5437. //
  5438. //----------------------------------------------------------------------------
  5439. void CTipbarButtonItem::OnRightClick()
  5440. {
  5441. if (_plbiButton)
  5442. {
  5443. HRESULT hr;
  5444. POINT pt;
  5445. RECT rc;
  5446. GetCursorPos(&pt);
  5447. GetRect(&rc);
  5448. MyClientToScreen(&rc);
  5449. CAsyncCall *pac = new CAsyncCall(_plbiButton);
  5450. if (pac)
  5451. {
  5452. hr = pac->OnClick(TF_LBI_CLK_RIGHT, pt, &rc);
  5453. pac->_Release();
  5454. }
  5455. else
  5456. {
  5457. hr = E_OUTOFMEMORY;
  5458. }
  5459. if (RPC_S_SERVER_UNAVAILABLE == HRESULT_CODE(hr))
  5460. {
  5461. if (_ptt && _ptt->_ptw)
  5462. _ptt->_ptw->OnThreadTerminate(_ptt->_dwThreadId);
  5463. return;
  5464. }
  5465. }
  5466. }
  5467. //+---------------------------------------------------------------------------
  5468. //
  5469. // OnLeftClick
  5470. //
  5471. //----------------------------------------------------------------------------
  5472. void CTipbarButtonItem::OnLeftClick()
  5473. {
  5474. if (_plbiButton)
  5475. {
  5476. HRESULT hr;
  5477. POINT pt;
  5478. RECT rc;
  5479. GetCursorPos(&pt);
  5480. GetRect(&rc);
  5481. MyClientToScreen(&rc);
  5482. CAsyncCall *pac = new CAsyncCall(_plbiButton);
  5483. if (pac)
  5484. {
  5485. hr = pac->OnClick(TF_LBI_CLK_LEFT, pt, &rc);
  5486. pac->_Release();
  5487. }
  5488. else
  5489. {
  5490. hr = E_OUTOFMEMORY;
  5491. }
  5492. if (RPC_S_SERVER_UNAVAILABLE == HRESULT_CODE(hr))
  5493. {
  5494. if (_ptt && _ptt->_ptw)
  5495. _ptt->_ptw->OnThreadTerminate(_ptt->_dwThreadId);
  5496. return;
  5497. }
  5498. if (!IsHiddenStatusControl() && IsVisibleInToolbar())
  5499. StartDemotingTimer(TRUE);
  5500. }
  5501. }
  5502. //+---------------------------------------------------------------------------
  5503. //
  5504. // OnShowMenu
  5505. //
  5506. //----------------------------------------------------------------------------
  5507. void CTipbarButtonItem::OnShowMenu()
  5508. {
  5509. if (!_ptt)
  5510. return;
  5511. if (!_ptt->_ptw)
  5512. return;
  5513. if (_plbiButton)
  5514. {
  5515. POINT pt;
  5516. RECT rc;
  5517. GetRect(&rc);
  5518. pt.x = rc.left;
  5519. pt.y = rc.bottom;
  5520. MyClientToScreen(&pt, &rc);
  5521. DoModalMenu(&pt, &rc);
  5522. }
  5523. }
  5524. //+---------------------------------------------------------------------------
  5525. //
  5526. // DoModalMenu
  5527. //
  5528. //----------------------------------------------------------------------------
  5529. void CTipbarButtonItem::DoModalMenu(POINT *ppt, RECT *prc)
  5530. {
  5531. HRESULT hr;
  5532. UINT uId;
  5533. DWORD dwThreadId;
  5534. CTipbarWnd *ptw;
  5535. if (!_ptt)
  5536. return;
  5537. if (!_ptt->_ptw)
  5538. return;
  5539. CUTBLBarMenu *pMenu = new CUTBLBarMenu(g_hInst);
  5540. if (!pMenu)
  5541. return;
  5542. AddRef();
  5543. hr = _plbiButton->InitMenu(pMenu);
  5544. if (RPC_S_SERVER_UNAVAILABLE == HRESULT_CODE(hr))
  5545. {
  5546. if (_ptt && _ptt->_ptw)
  5547. _ptt->_ptw->OnThreadTerminate(_ptt->_dwThreadId);
  5548. goto Exit;
  5549. }
  5550. if (FAILED(hr))
  5551. goto Exit;
  5552. ptw = _ptt->_ptw;
  5553. dwThreadId = _ptt->_dwThreadId;
  5554. Assert(!_ptt->_ptw->_pttModal);
  5555. ptw->_pttModal = _ptt;
  5556. ptw->StartModalInput(ptw, dwThreadId);
  5557. Assert(!ptw->_pModalMenu);
  5558. ptw->_pModalMenu = pMenu;
  5559. uId = pMenu->ShowPopup(ptw, *ppt, prc);
  5560. ptw->_pModalMenu = NULL;
  5561. ptw->StopModalInput(dwThreadId);
  5562. ptw->_pttModal = NULL;
  5563. if (IsConnected() && (uId != CUI_MENU_UNSELECTED))
  5564. {
  5565. CAsyncCall *pac = new CAsyncCall(_plbiButton);
  5566. if (pac)
  5567. {
  5568. hr = pac->OnMenuSelect(uId);
  5569. pac->_Release();
  5570. }
  5571. if (RPC_S_SERVER_UNAVAILABLE == HRESULT_CODE(hr))
  5572. {
  5573. if (_ptt && _ptt->_ptw)
  5574. _ptt->_ptw->OnThreadTerminate(_ptt->_dwThreadId);
  5575. goto Exit;
  5576. }
  5577. if (FAILED(hr))
  5578. goto Exit;
  5579. }
  5580. Exit:
  5581. pMenu->Release();
  5582. Release();
  5583. }
  5584. //+---------------------------------------------------------------------------
  5585. //
  5586. // MoveToTray
  5587. //
  5588. //----------------------------------------------------------------------------
  5589. void CTipbarButtonItem::MoveToTray()
  5590. {
  5591. if (!g_pTrayIconWnd)
  5592. return;
  5593. if (IsVisibleInToolbar() && (IsShownInTray() || IsShownInTrayOnly()))
  5594. {
  5595. HICON hIcon = GetIcon();
  5596. if (hIcon)
  5597. {
  5598. SIZE size;
  5599. if (IsToggled() && CUIGetIconSize(hIcon, &size))
  5600. {
  5601. COLORREF cr;
  5602. RECT rc;
  5603. CBitmapDC hdcSrc(TRUE);
  5604. CBitmapDC hdcMask(TRUE);
  5605. #if 0
  5606. CUIFScheme *pscheme = _ptt->_ptw->GetUIFScheme();
  5607. if (!pscheme)
  5608. cr = GetSysColor(COLOR_HIGHLIGHT);
  5609. else
  5610. cr = pscheme->GetColor(UIFCOLOR_MOUSEDOWNBKGND);
  5611. #else
  5612. cr = GetSysColor(COLOR_HIGHLIGHT);
  5613. #endif
  5614. CSolidBrush hbrBk(cr);
  5615. hdcSrc.SetDIB(size.cx, size.cy);
  5616. hdcMask.SetBitmap(size.cx, size.cy, 1, 1);
  5617. rc.left = 0;
  5618. rc.top = 0;
  5619. rc.right = size.cx;
  5620. rc.bottom = size.cy;
  5621. FillRect(hdcSrc, &rc, (HBRUSH)hbrBk);
  5622. DrawIconEx(hdcSrc, 0, 0, hIcon, size.cx, size.cy, 0, NULL, DI_NORMAL);
  5623. FillRect(hdcMask, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
  5624. ICONINFO ii;
  5625. ii.fIcon = TRUE;
  5626. ii.xHotspot = 0;
  5627. ii.yHotspot = 0;
  5628. ii.hbmMask = hdcMask.GetBitmap();
  5629. ii.hbmColor = hdcSrc.GetBitmap();
  5630. DestroyIcon(hIcon);
  5631. hIcon = CreateIconIndirect(&ii);
  5632. }
  5633. if (hIcon)
  5634. {
  5635. g_pTrayIconWnd->SetIcon(*GetGUID(), IsMenuBtn(), hIcon, GetToolTip());
  5636. DestroyIcon(hIcon);
  5637. }
  5638. }
  5639. }
  5640. else
  5641. {
  5642. g_pTrayIconWnd->SetIcon(*GetGUID(), IsMenuBtn(), NULL, NULL);
  5643. }
  5644. }
  5645. //////////////////////////////////////////////////////////////////////////////
  5646. //
  5647. // CTipbarBitmapButtonItem
  5648. //
  5649. //////////////////////////////////////////////////////////////////////////////
  5650. //+---------------------------------------------------------------------------
  5651. //
  5652. // IUnknown
  5653. //
  5654. //----------------------------------------------------------------------------
  5655. STDAPI CTipbarBitmapButtonItem::QueryInterface(REFIID riid, void **ppvObj)
  5656. {
  5657. *ppvObj = NULL;
  5658. if (IsEqualIID(riid, IID_IUnknown) ||
  5659. IsEqualIID(riid, IID_ITfLangBarItemSink))
  5660. {
  5661. *ppvObj = SAFECAST(this, ITfLangBarItemSink *);
  5662. }
  5663. else if (IsEqualIID(riid, IID_PRIV_BITMAPBUTTONITEM))
  5664. {
  5665. *ppvObj = this;
  5666. }
  5667. if (*ppvObj)
  5668. {
  5669. AddRef();
  5670. return S_OK;
  5671. }
  5672. return E_NOINTERFACE;
  5673. }
  5674. STDAPI_(ULONG) CTipbarBitmapButtonItem::AddRef()
  5675. {
  5676. return ++_cRef;
  5677. }
  5678. STDAPI_(ULONG) CTipbarBitmapButtonItem::Release()
  5679. {
  5680. _cRef--;
  5681. Assert(_cRef >= 0);
  5682. if (_cRef == 0)
  5683. {
  5684. delete this;
  5685. return 0;
  5686. }
  5687. return _cRef;
  5688. }
  5689. //+---------------------------------------------------------------------------
  5690. //
  5691. // ctor
  5692. //
  5693. //----------------------------------------------------------------------------
  5694. CTipbarBitmapButtonItem::CTipbarBitmapButtonItem(CTipbarThread *ptt,
  5695. ITfLangBarItem *plbi,
  5696. ITfLangBarItemBitmapButton *plbiBitmapButton,
  5697. DWORD dwId,
  5698. RECT *prc,
  5699. DWORD dwStyle,
  5700. DWORD dwNuiBtnStyle,
  5701. DWORD dwSBtnShowType,
  5702. TF_LANGBARITEMINFO *plbiInfo,
  5703. DWORD dwStatus)
  5704. : CUIFToolbarButton(ptt->_ptw,
  5705. dwId,
  5706. prc,
  5707. dwStyle,
  5708. dwNuiBtnStyle,
  5709. dwSBtnShowType) ,
  5710. CTipbarItem(ptt, plbi, plbiInfo, dwStatus)
  5711. {
  5712. Dbg_MemSetThisName(TEXT("CTipbarBitmapButtonItem"));
  5713. _plbiBitmapButton = plbiBitmapButton;
  5714. _plbiBitmapButton->AddRef();
  5715. if (_dwStatus & TF_LBI_STATUS_DISABLED)
  5716. Enable(FALSE);
  5717. _cRef = 1;
  5718. }
  5719. //+---------------------------------------------------------------------------
  5720. //
  5721. // dtor
  5722. //
  5723. //----------------------------------------------------------------------------
  5724. CTipbarBitmapButtonItem::~CTipbarBitmapButtonItem()
  5725. {
  5726. HBITMAP hbmpOld;
  5727. HBITMAP hbmpMaskOld;
  5728. hbmpOld = GetBitmap();
  5729. hbmpMaskOld = GetBitmapMask();
  5730. if (hbmpOld)
  5731. DeleteObject(hbmpOld);
  5732. if (hbmpMaskOld)
  5733. DeleteObject(hbmpMaskOld);
  5734. SetBitmap((HBITMAP)NULL);
  5735. SetBitmapMask((HBITMAP)NULL);
  5736. SafeRelease(_plbiBitmapButton);
  5737. }
  5738. //+---------------------------------------------------------------------------
  5739. //
  5740. // Update
  5741. //
  5742. //----------------------------------------------------------------------------
  5743. HRESULT CTipbarBitmapButtonItem::OnUpdateHandler(DWORD dwFlags, DWORD dwStatus)
  5744. {
  5745. if (!IsConnected())
  5746. return S_OK;
  5747. HRESULT hr = S_OK;
  5748. BOOL fCallPaint = FALSE;
  5749. //
  5750. // add ref count to be safe for releasing during marshaling.
  5751. //
  5752. AddRef();
  5753. if (dwFlags & TF_LBI_BITMAP)
  5754. {
  5755. if (!_GetBitmapFromNUI())
  5756. {
  5757. hr = E_FAIL;
  5758. goto Exit;
  5759. }
  5760. if (!IsHiddenStatusControl() && IsVisibleInToolbar())
  5761. StartDemotingTimer(FALSE);
  5762. fCallPaint = TRUE;
  5763. }
  5764. if ((dwFlags & TF_LBI_TEXT) &&
  5765. _ptt &&
  5766. _ptt->_ptw &&
  5767. _ptt->_ptw->IsShowText())
  5768. {
  5769. BSTR bstr;
  5770. hr = _plbiBitmapButton->GetText(&bstr);
  5771. if (FAILED(hr))
  5772. goto Exit;
  5773. if (bstr && (!GetText() || wcscmp(GetText(), bstr)))
  5774. {
  5775. SIZE size;
  5776. _ptt->GetTextSize(bstr, &size);
  5777. SetText(SysStringLen(bstr) ? bstr : NULL);
  5778. if (_sizeText.cx != size.cx)
  5779. {
  5780. _dwWidth += (size.cx - _sizeText.cx);
  5781. _ptt->LocateItems();
  5782. }
  5783. _sizeText = size;
  5784. fCallPaint = TRUE;
  5785. }
  5786. if (bstr)
  5787. SysFreeString(bstr);
  5788. }
  5789. CTipbarItem::OnUpdateHandler(dwFlags, dwStatus);
  5790. if (_pBtn->GetToggleState() != IsToggled())
  5791. {
  5792. _pBtn->SetToggleState(IsToggled());
  5793. }
  5794. if (fCallPaint)
  5795. CallOnPaint();
  5796. Exit:
  5797. Release();
  5798. return hr;
  5799. }
  5800. //+---------------------------------------------------------------------------
  5801. //
  5802. // _GetBitmapFromNUI
  5803. //
  5804. //----------------------------------------------------------------------------
  5805. BOOL CTipbarBitmapButtonItem::_GetBitmapFromNUI()
  5806. {
  5807. BOOL bRet = FALSE;
  5808. HBITMAP hbmp;
  5809. HBITMAP hbmpMask;
  5810. HBITMAP hbmpOld;
  5811. HBITMAP hbmpMaskOld;
  5812. int x, y;
  5813. hbmpOld = GetBitmap();
  5814. if (hbmpOld)
  5815. DeleteObject(hbmpOld);
  5816. hbmpMaskOld = GetBitmapMask();
  5817. if (hbmpMaskOld)
  5818. DeleteObject(hbmpMaskOld);
  5819. SetBitmap((HBITMAP)NULL);
  5820. SetBitmapMask((HBITMAP)NULL);
  5821. x = GetRectRef().right - GetRectRef().left;
  5822. y = GetRectRef().bottom - GetRectRef().top;
  5823. if (_ptt->_ptw->IsShowText())
  5824. y -= 12;
  5825. HRESULT hr = _plbiBitmapButton->DrawBitmap(x, y, 0, &hbmp, &hbmpMask);
  5826. if (SUCCEEDED(hr))
  5827. {
  5828. SetBitmap(hbmp);
  5829. SetBitmapMask(hbmpMask);
  5830. bRet = TRUE;
  5831. }
  5832. return bRet;
  5833. }
  5834. //+---------------------------------------------------------------------------
  5835. //
  5836. // OnRightClick
  5837. //
  5838. //----------------------------------------------------------------------------
  5839. void CTipbarBitmapButtonItem::OnRightClick()
  5840. {
  5841. if (_plbiBitmapButton)
  5842. {
  5843. HRESULT hr;
  5844. POINT pt;
  5845. RECT rc;
  5846. GetCursorPos(&pt);
  5847. GetRect(&rc);
  5848. MyClientToScreen(&rc);
  5849. CAsyncCall *pac = new CAsyncCall(_plbiBitmapButton);
  5850. if (pac)
  5851. {
  5852. hr = pac->OnClick(TF_LBI_CLK_RIGHT, pt, &rc);
  5853. pac->_Release();
  5854. }
  5855. else
  5856. {
  5857. hr = E_OUTOFMEMORY;
  5858. }
  5859. if (RPC_S_SERVER_UNAVAILABLE == HRESULT_CODE(hr))
  5860. {
  5861. if (_ptt && _ptt->_ptw)
  5862. _ptt->_ptw->OnThreadTerminate(_ptt->_dwThreadId);
  5863. return;
  5864. }
  5865. }
  5866. }
  5867. //+---------------------------------------------------------------------------
  5868. //
  5869. // OnLeftClick
  5870. //
  5871. //----------------------------------------------------------------------------
  5872. void CTipbarBitmapButtonItem::OnLeftClick()
  5873. {
  5874. if (_plbiBitmapButton)
  5875. {
  5876. HRESULT hr;
  5877. POINT pt;
  5878. RECT rc;
  5879. GetCursorPos(&pt);
  5880. GetRect(&rc);
  5881. MyClientToScreen(&rc);
  5882. CAsyncCall *pac = new CAsyncCall(_plbiBitmapButton);
  5883. if (pac)
  5884. {
  5885. hr = pac->OnClick(TF_LBI_CLK_LEFT, pt, &rc);
  5886. pac->_Release();
  5887. }
  5888. else
  5889. {
  5890. hr = E_OUTOFMEMORY;
  5891. }
  5892. if (RPC_S_SERVER_UNAVAILABLE == HRESULT_CODE(hr))
  5893. {
  5894. if (_ptt && _ptt->_ptw)
  5895. _ptt->_ptw->OnThreadTerminate(_ptt->_dwThreadId);
  5896. return;
  5897. }
  5898. if (!IsHiddenStatusControl() && IsVisibleInToolbar())
  5899. StartDemotingTimer(TRUE);
  5900. }
  5901. }
  5902. //+---------------------------------------------------------------------------
  5903. //
  5904. // OnShowMenu
  5905. //
  5906. //----------------------------------------------------------------------------
  5907. void CTipbarBitmapButtonItem::OnShowMenu()
  5908. {
  5909. if (!_ptt)
  5910. return;
  5911. if (!_ptt->_ptw)
  5912. return;
  5913. if (_plbiBitmapButton)
  5914. {
  5915. POINT pt;
  5916. RECT rc;
  5917. GetRect(&rc);
  5918. pt.x = rc.left;
  5919. pt.y = rc.bottom;
  5920. MyClientToScreen(&pt, &rc);
  5921. HRESULT hr;
  5922. UINT uId;
  5923. DWORD dwThreadId;
  5924. CTipbarWnd *ptw;
  5925. CUTBLBarMenu *pMenu = new CUTBLBarMenu(g_hInst);
  5926. if (!pMenu)
  5927. return;
  5928. hr = _plbiBitmapButton->InitMenu(pMenu);
  5929. if (RPC_S_SERVER_UNAVAILABLE == HRESULT_CODE(hr))
  5930. {
  5931. if (_ptt && _ptt->_ptw)
  5932. _ptt->_ptw->OnThreadTerminate(_ptt->_dwThreadId);
  5933. goto Exit;
  5934. }
  5935. if (FAILED(hr))
  5936. goto Exit;
  5937. ptw = _ptt->_ptw;
  5938. dwThreadId = _ptt->_dwThreadId;
  5939. Assert(!ptw->_pttModal);
  5940. ptw->_pttModal = _ptt;
  5941. ptw->StartModalInput(ptw, dwThreadId);
  5942. Assert(!ptw->_pModalMenu);
  5943. ptw->_pModalMenu = pMenu;
  5944. uId = pMenu->ShowPopup(ptw, pt, &rc);
  5945. ptw->_pModalMenu = NULL;
  5946. ptw->StopModalInput(dwThreadId);
  5947. ptw->_pttModal = NULL;
  5948. if (IsConnected() && (uId != CUI_MENU_UNSELECTED))
  5949. {
  5950. Assert(_ptt);
  5951. CAsyncCall *pac = new CAsyncCall(_plbiBitmapButton);
  5952. if (pac)
  5953. {
  5954. hr = pac->OnMenuSelect(uId);
  5955. pac->_Release();
  5956. }
  5957. else
  5958. {
  5959. hr = E_OUTOFMEMORY;
  5960. }
  5961. if (RPC_S_SERVER_UNAVAILABLE == HRESULT_CODE(hr))
  5962. {
  5963. ptw->OnThreadTerminate(dwThreadId);
  5964. goto Exit;
  5965. }
  5966. if (FAILED(hr))
  5967. goto Exit;
  5968. }
  5969. Exit:
  5970. pMenu->Release();
  5971. }
  5972. }
  5973. //////////////////////////////////////////////////////////////////////////////
  5974. //
  5975. // CTipbarBitmapItem
  5976. //
  5977. //////////////////////////////////////////////////////////////////////////////
  5978. //+---------------------------------------------------------------------------
  5979. //
  5980. // IUnknown
  5981. //
  5982. //----------------------------------------------------------------------------
  5983. STDAPI CTipbarBitmapItem::QueryInterface(REFIID riid, void **ppvObj)
  5984. {
  5985. *ppvObj = NULL;
  5986. if (IsEqualIID(riid, IID_IUnknown) ||
  5987. IsEqualIID(riid, IID_ITfLangBarItemSink))
  5988. {
  5989. *ppvObj = SAFECAST(this, ITfLangBarItemSink *);
  5990. }
  5991. else if (IsEqualIID(riid, IID_PRIV_BITMAPITEM))
  5992. {
  5993. *ppvObj = this;
  5994. }
  5995. if (*ppvObj)
  5996. {
  5997. AddRef();
  5998. return S_OK;
  5999. }
  6000. return E_NOINTERFACE;
  6001. }
  6002. STDAPI_(ULONG) CTipbarBitmapItem::AddRef()
  6003. {
  6004. return ++_cRef;
  6005. }
  6006. STDAPI_(ULONG) CTipbarBitmapItem::Release()
  6007. {
  6008. _cRef--;
  6009. Assert(_cRef >= 0);
  6010. if (_cRef == 0)
  6011. {
  6012. delete this;
  6013. return 0;
  6014. }
  6015. return _cRef;
  6016. }
  6017. //+---------------------------------------------------------------------------
  6018. //
  6019. // ctor
  6020. //
  6021. //----------------------------------------------------------------------------
  6022. CTipbarBitmapItem::CTipbarBitmapItem(CTipbarThread *ptt,
  6023. ITfLangBarItem *plbi,
  6024. ITfLangBarItemBitmap *plbiBitmap,
  6025. DWORD dwId,
  6026. RECT *prc,
  6027. DWORD dwStyle,
  6028. TF_LANGBARITEMINFO *plbiInfo,
  6029. DWORD dwStatus)
  6030. : CUIFObject(ptt->_ptw,
  6031. dwId,
  6032. prc,
  6033. dwStyle) ,
  6034. CTipbarItem(ptt, plbi, plbiInfo, dwStatus)
  6035. {
  6036. Dbg_MemSetThisName(TEXT("CTipbarBitmapItem"));
  6037. _plbiBitmap = plbiBitmap;
  6038. _plbiBitmap->AddRef();
  6039. if (_dwStatus & TF_LBI_STATUS_DISABLED)
  6040. Enable(FALSE);
  6041. _cRef = 1;
  6042. }
  6043. //+---------------------------------------------------------------------------
  6044. //
  6045. // dtor
  6046. //
  6047. //----------------------------------------------------------------------------
  6048. CTipbarBitmapItem::~CTipbarBitmapItem()
  6049. {
  6050. if (_hbmp)
  6051. DeleteObject(_hbmp);
  6052. SafeRelease(_plbiBitmap);
  6053. }
  6054. //+---------------------------------------------------------------------------
  6055. //
  6056. // Update
  6057. //
  6058. //----------------------------------------------------------------------------
  6059. HRESULT CTipbarBitmapItem::OnUpdateHandler(DWORD dwFlags, DWORD dwStatus)
  6060. {
  6061. if (!IsConnected())
  6062. return S_OK;
  6063. HRESULT hr = S_OK;
  6064. BOOL fCallPaint = FALSE;
  6065. //
  6066. // add ref count to be safe for releasing during marshaling.
  6067. //
  6068. AddRef();
  6069. if (dwFlags & TF_LBI_BITMAP)
  6070. {
  6071. if (!_GetBitmapFromNUI())
  6072. {
  6073. hr = E_FAIL;
  6074. goto Exit;
  6075. }
  6076. fCallPaint = TRUE;
  6077. }
  6078. CTipbarItem::OnUpdateHandler(dwFlags, dwStatus);
  6079. if (fCallPaint)
  6080. CallOnPaint();
  6081. Exit:
  6082. Release();
  6083. return hr;
  6084. }
  6085. //+---------------------------------------------------------------------------
  6086. //
  6087. // _GetBitmapFromNUI
  6088. //
  6089. //----------------------------------------------------------------------------
  6090. BOOL CTipbarBitmapItem::_GetBitmapFromNUI()
  6091. {
  6092. BOOL bRet = TRUE;
  6093. HBITMAP hbmp = NULL;
  6094. HBITMAP hbmpMask = NULL;
  6095. int x = GetRectRef().right - GetRectRef().left;
  6096. int y = GetRectRef().bottom - GetRectRef().top;
  6097. HRESULT hr = _plbiBitmap->DrawBitmap(x, y, 0, &hbmp, &hbmpMask);
  6098. if (FAILED(hr))
  6099. {
  6100. if (_hbmp)
  6101. DeleteObject(_hbmp);
  6102. _hbmp = NULL;
  6103. bRet = FALSE;
  6104. }
  6105. if (!hbmpMask)
  6106. {
  6107. if (_hbmp)
  6108. DeleteObject(_hbmp);
  6109. _hbmp = hbmp;
  6110. }
  6111. else
  6112. {
  6113. CUIFScheme *pScheme = GetUIFScheme();
  6114. if (_hbmp)
  6115. DeleteObject(_hbmp);
  6116. _hbmp = CreateMaskBmp(&GetRectRef(), hbmp, hbmpMask,
  6117. pScheme->GetBrush(UIFCOLOR_CTRLBKGND), 0, 0);
  6118. }
  6119. if (hbmp)
  6120. DeleteObject(hbmp);
  6121. if (hbmpMask)
  6122. DeleteObject(hbmpMask);
  6123. return bRet;
  6124. }
  6125. //+---------------------------------------------------------------------------
  6126. //
  6127. // OnPaint
  6128. //
  6129. //----------------------------------------------------------------------------
  6130. void CTipbarBitmapItem::OnPaint( HDC hdc )
  6131. {
  6132. CBitmapDC hdcMem(TRUE);
  6133. hdcMem.SetBitmap(_hbmp);
  6134. BitBlt(hdc,
  6135. GetRectRef().left,
  6136. GetRectRef().top,
  6137. GetRectRef().right - GetRectRef().left,
  6138. GetRectRef().bottom - GetRectRef().top,
  6139. hdcMem,
  6140. 0,
  6141. 0,
  6142. SRCCOPY);
  6143. }
  6144. //+---------------------------------------------------------------------------
  6145. //
  6146. // SetRect
  6147. //
  6148. //----------------------------------------------------------------------------
  6149. void CTipbarBitmapItem::SetRect( const RECT *prc )
  6150. {
  6151. if (((GetRectRef().bottom - GetRectRef().top) != (prc->bottom - prc->top)) ||
  6152. ((GetRectRef().right - GetRectRef().left) != (prc->right - prc->left)))
  6153. {
  6154. if (_hbmp)
  6155. DeleteObject(_hbmp);
  6156. _hbmp = NULL;
  6157. }
  6158. CUIFObject::SetRect(prc);
  6159. }
  6160. //+---------------------------------------------------------------------------
  6161. //
  6162. // OnRightClick
  6163. //
  6164. //----------------------------------------------------------------------------
  6165. void CTipbarBitmapItem::OnRightClick()
  6166. {
  6167. if (_plbiBitmap)
  6168. {
  6169. POINT pt;
  6170. RECT rc;
  6171. HRESULT hr;
  6172. GetCursorPos(&pt);
  6173. GetRect(&rc);
  6174. MyClientToScreen(&rc);
  6175. CAsyncCall *pac = new CAsyncCall(_plbiBitmap);
  6176. if (!pac)
  6177. return;
  6178. hr = pac->OnClick(TF_LBI_CLK_RIGHT, pt, &rc);
  6179. pac->_Release();
  6180. if (RPC_S_SERVER_UNAVAILABLE == HRESULT_CODE(hr))
  6181. {
  6182. if (_ptt && _ptt->_ptw)
  6183. _ptt->_ptw->OnThreadTerminate(_ptt->_dwThreadId);
  6184. return;
  6185. }
  6186. }
  6187. }
  6188. //+---------------------------------------------------------------------------
  6189. //
  6190. // OnLeftClick
  6191. //
  6192. //----------------------------------------------------------------------------
  6193. void CTipbarBitmapItem::OnLeftClick()
  6194. {
  6195. if (_plbiBitmap)
  6196. {
  6197. HRESULT hr;
  6198. POINT pt;
  6199. RECT rc;
  6200. GetCursorPos(&pt);
  6201. GetRect(&rc);
  6202. MyClientToScreen(&rc);
  6203. CAsyncCall *pac = new CAsyncCall(_plbiBitmap);
  6204. if (pac)
  6205. {
  6206. hr = pac->OnClick(TF_LBI_CLK_LEFT, pt, &rc);
  6207. pac->_Release();
  6208. }
  6209. else
  6210. {
  6211. hr = E_OUTOFMEMORY;
  6212. }
  6213. if (RPC_S_SERVER_UNAVAILABLE == HRESULT_CODE(hr))
  6214. {
  6215. if (_ptt && _ptt->_ptw)
  6216. _ptt->_ptw->OnThreadTerminate(_ptt->_dwThreadId);
  6217. return;
  6218. }
  6219. if (!IsHiddenStatusControl() && IsVisibleInToolbar())
  6220. StartDemotingTimer(TRUE);
  6221. }
  6222. }
  6223. //////////////////////////////////////////////////////////////////////////////
  6224. //
  6225. // CTipbarCtrlButtonHolder
  6226. //
  6227. //////////////////////////////////////////////////////////////////////////////
  6228. //+---------------------------------------------------------------------------
  6229. //
  6230. // ctor
  6231. //
  6232. //----------------------------------------------------------------------------
  6233. CTipbarCtrlButtonHolder::CTipbarCtrlButtonHolder()
  6234. {
  6235. }
  6236. //+---------------------------------------------------------------------------
  6237. //
  6238. // Init
  6239. //
  6240. //+---------------------------------------------------------------------------
  6241. void CTipbarCtrlButtonHolder::Init(CTipbarWnd *ptw)
  6242. {
  6243. int i;
  6244. RECT rc;
  6245. ::SetRect(&rc, 0, 0, 0, 0);
  6246. if (ptw->IsInDeskBand())
  6247. _pcbCtrlBtn = g_cbCtrlBtnDeskBand;
  6248. else
  6249. _pcbCtrlBtn = g_cbCtrlBtn;
  6250. for (i = 0; i < NUM_CTRLBUTTONS; i++)
  6251. {
  6252. Assert(!_rgpCtrlBtn[i]);
  6253. _rgpCtrlBtn[i] = new CTipbarCtrlButton(ptw,
  6254. _pcbCtrlBtn[i].dwId,
  6255. &rc,
  6256. _pcbCtrlBtn[i].dwStyle);
  6257. _rgpCtrlBtn[i]->Initialize();
  6258. ptw->AddUIObj(_rgpCtrlBtn[i]);
  6259. if (_pcbCtrlBtn[i].dwFlags & CTRL_USEMARLETT)
  6260. _rgpCtrlBtn[i]->SetFont(ptw->GetMarlett());
  6261. if (_pcbCtrlBtn[i].dwFlags & CTRL_ICONFROMRES)
  6262. {
  6263. if (_pcbCtrlBtn[i].dwId == ID_CBTN_CAPSKEY)
  6264. {
  6265. _rgpCtrlBtn[i]->SetVKey(VK_CAPITAL);
  6266. }
  6267. else
  6268. {
  6269. _rgpCtrlBtn[i]->SetVKey(VK_KANA);
  6270. }
  6271. _rgpCtrlBtn[i]->SetToggleStateByVKey();
  6272. }
  6273. else
  6274. _rgpCtrlBtn[i]->SetText(_pcbCtrlBtn[i].wsz);
  6275. }
  6276. }
  6277. //+---------------------------------------------------------------------------
  6278. //
  6279. // EnableBtns
  6280. //
  6281. //+---------------------------------------------------------------------------
  6282. void CTipbarCtrlButtonHolder::EnableBtns()
  6283. {
  6284. int i;
  6285. for (i = 0; i < NUM_CTRLBUTTONS; i++)
  6286. {
  6287. if (_pcbCtrlBtn[i].dwFlags & CTRL_DISABLEONWINLOGON)
  6288. {
  6289. if (g_bWinLogon || (g_pTipbarWnd && g_pTipbarWnd->IsSFMinmized()))
  6290. _rgpCtrlBtn[i]->Enable(FALSE);
  6291. else
  6292. _rgpCtrlBtn[i]->Enable(TRUE);
  6293. }
  6294. }
  6295. }
  6296. //+---------------------------------------------------------------------------
  6297. //
  6298. // UpdateBitmap
  6299. //
  6300. //+---------------------------------------------------------------------------
  6301. void CTipbarCtrlButtonHolder::UpdateBitmap(CTipbarWnd *ptw)
  6302. {
  6303. int i;
  6304. for (i = 0; i < NUM_CTRLBUTTONS; i++)
  6305. {
  6306. if (_pcbCtrlBtn[i].dwFlags & CTRL_ICONFROMRES)
  6307. {
  6308. HBITMAP hbmp;
  6309. HBITMAP hbmpMask;
  6310. COLORREF rgbText = GetSysColor(COLOR_BTNTEXT);
  6311. if (SUCCEEDED(_rgpCtrlBtn[i]->EnsureThemeData(ptw->GetWnd())))
  6312. {
  6313. COLORREF col;
  6314. if (SUCCEEDED(_rgpCtrlBtn[i]->GetThemeColor(TS_NORMAL, TMT_TEXTCOLOR, &col)))
  6315. rgbText = col;
  6316. }
  6317. if (_pcbCtrlBtn[i].dwId == ID_CBTN_CAPSKEY)
  6318. {
  6319. if (!ptw->IsVertical())
  6320. _maskbmpCap.Init(ID_BITMAP_CAPS ,
  6321. KANACAPSBMP_WIDTH,
  6322. KANACAPSBMP_HEIGHT,
  6323. rgbText);
  6324. else
  6325. _maskbmpCap.Init(ID_BITMAP_CAPSV,
  6326. KANACAPSBMP_HEIGHT,
  6327. KANACAPSBMP_WIDTH,
  6328. rgbText);
  6329. hbmp = _maskbmpCap.GetBmp();
  6330. hbmpMask = _maskbmpCap.GetBmpMask();
  6331. }
  6332. else
  6333. {
  6334. if (!ptw->IsVertical())
  6335. _maskbmpKana.Init(ID_BITMAP_KANA ,
  6336. KANACAPSBMP_WIDTH,
  6337. KANACAPSBMP_HEIGHT,
  6338. rgbText);
  6339. else
  6340. _maskbmpKana.Init(ID_BITMAP_KANAV,
  6341. KANACAPSBMP_HEIGHT,
  6342. KANACAPSBMP_WIDTH,
  6343. rgbText);
  6344. hbmp = _maskbmpKana.GetBmp();
  6345. hbmpMask = _maskbmpKana.GetBmpMask();
  6346. }
  6347. _rgpCtrlBtn[i]->SetBitmap(hbmp);
  6348. _rgpCtrlBtn[i]->SetBitmapMask(hbmpMask);
  6349. }
  6350. }
  6351. }
  6352. //+---------------------------------------------------------------------------
  6353. //
  6354. // Locate
  6355. //
  6356. //+---------------------------------------------------------------------------
  6357. void CTipbarCtrlButtonHolder::Locate(CTipbarWnd *ptw, int x, int y, int nHeight, DWORD dwFlags, BOOL fVertical)
  6358. {
  6359. int i;
  6360. int nCtrlItemHeight = (nHeight - ptw->GetCtrlItemHeightMargin() * 2) / 2;
  6361. c_nColumnStart[0] = 0;
  6362. c_nColumnStart[1] = CX_COLUMN0 +
  6363. ptw->GetThemeMargins()->cxLeftWidth +
  6364. ptw->GetThemeMargins()->cxRightWidth;
  6365. c_nColumnStart[2] = CX_COLUMN1 +
  6366. ptw->GetThemeMargins()->cxLeftWidth +
  6367. ptw->GetThemeMargins()->cxRightWidth;
  6368. for (i = 0; i < NUM_CTRLBUTTONS; i++)
  6369. {
  6370. RECT rc;
  6371. int nColumn = _pcbCtrlBtn[i].nColumn;
  6372. int nRow = _pcbCtrlBtn[i].nRow;
  6373. if (dwFlags & TCBH_NOCOLUMN)
  6374. {
  6375. rc.left = 0;
  6376. rc.top = 0;
  6377. rc.right = 0;
  6378. rc.bottom = 0;
  6379. _rgpCtrlBtn[i]->SetRect(&rc);
  6380. continue;
  6381. }
  6382. if (dwFlags & TCBH_NOCOLUMN0)
  6383. {
  6384. if (!_pcbCtrlBtn[i].nColumn)
  6385. {
  6386. rc.left = 0;
  6387. rc.top = 0;
  6388. rc.right = 0;
  6389. rc.bottom = 0;
  6390. _rgpCtrlBtn[i]->SetRect(&rc);
  6391. continue;
  6392. }
  6393. nColumn--;
  6394. }
  6395. if (!fVertical)
  6396. {
  6397. rc.left = x + c_nColumnStart[nColumn];
  6398. rc.top = ptw->GetCtrlItemHeightMargin() + y + nRow * nCtrlItemHeight;
  6399. rc.right = rc.left + c_nColumnStart[_pcbCtrlBtn[i].nColumn + 1];
  6400. rc.bottom = rc.top + nCtrlItemHeight;
  6401. }
  6402. else
  6403. {
  6404. //
  6405. // swap Row when this is the vertical langbar.
  6406. //
  6407. rc.left = ptw->GetCtrlItemHeightMargin() + x + (1 - nRow) * nCtrlItemHeight;
  6408. rc.top = y + c_nColumnStart[nColumn];
  6409. rc.right = rc.left + nCtrlItemHeight;
  6410. rc.bottom = rc.top + c_nColumnStart[_pcbCtrlBtn[i].nColumn + 1];
  6411. }
  6412. _rgpCtrlBtn[i]->SetRect(&rc);
  6413. }
  6414. }
  6415. //+---------------------------------------------------------------------------
  6416. //
  6417. // GetWidth
  6418. //
  6419. //+---------------------------------------------------------------------------
  6420. int CTipbarCtrlButtonHolder::GetWidth(DWORD dwFlags)
  6421. {
  6422. if (dwFlags & TCBH_NOCOLUMN)
  6423. return 0;
  6424. int nWidth = 0;
  6425. if (!(dwFlags & TCBH_NOCOLUMN0))
  6426. nWidth += c_nColumnStart[1];
  6427. nWidth += c_nColumnStart[2];
  6428. return nWidth;
  6429. }
  6430. //+---------------------------------------------------------------------------
  6431. //
  6432. // UpdateCapsKanaState
  6433. //
  6434. //+---------------------------------------------------------------------------
  6435. void CTipbarCtrlButtonHolder::UpdateCapsKanaState(LPARAM lParam)
  6436. {
  6437. int i;
  6438. for (i = 0; i < NUM_CTRLBUTTONS; i++)
  6439. {
  6440. if (_rgpCtrlBtn[i]->GetVKey())
  6441. {
  6442. if (_rgpCtrlBtn[i]->GetVKey() == VK_CAPITAL)
  6443. _rgpCtrlBtn[i]->SetToggleState((lParam & TF_LBUF_CAPS) ? TRUE: FALSE);
  6444. else if (_rgpCtrlBtn[i]->GetVKey() == VK_KANA)
  6445. _rgpCtrlBtn[i]->SetToggleState((lParam & TF_LBUF_KANA) ? TRUE: FALSE);
  6446. }
  6447. }
  6448. }
  6449. //+---------------------------------------------------------------------------
  6450. //
  6451. // GetCtrlBtn
  6452. //
  6453. //+---------------------------------------------------------------------------
  6454. CTipbarCtrlButton *CTipbarCtrlButtonHolder::GetCtrlBtn(DWORD dwId)
  6455. {
  6456. int i;
  6457. for (i = 0; i < NUM_CTRLBUTTONS; i++)
  6458. {
  6459. if (_rgpCtrlBtn[i]->GetID() == dwId)
  6460. return _rgpCtrlBtn[i];
  6461. }
  6462. return NULL;
  6463. }
  6464. //////////////////////////////////////////////////////////////////////////////
  6465. //
  6466. // CTipbarCtrlButton
  6467. //
  6468. //////////////////////////////////////////////////////////////////////////////
  6469. //+---------------------------------------------------------------------------
  6470. //
  6471. // ctor
  6472. //
  6473. //----------------------------------------------------------------------------
  6474. CTipbarCtrlButton::CTipbarCtrlButton(CTipbarWnd *ptw,
  6475. DWORD dwId,
  6476. const RECT *prc,
  6477. DWORD dwStyle)
  6478. : CUIFButton2(ptw,
  6479. dwId,
  6480. prc,
  6481. dwStyle)
  6482. {
  6483. _ptw = ptw;
  6484. _fInMenu = FALSE;
  6485. SetToolTip(CRStr(IDS_CONTROLBUTTONTOOLTIP + dwId));
  6486. }
  6487. //+---------------------------------------------------------------------------
  6488. //
  6489. // OnLButtonUp
  6490. //
  6491. //----------------------------------------------------------------------------
  6492. void CTipbarCtrlButton::OnLButtonUp(POINT pt)
  6493. {
  6494. CUIFButton2::OnLButtonUp(pt);
  6495. CUTBMinimizeLangBarDlg *pMinimizeDlg;
  6496. switch (GetID())
  6497. {
  6498. case ID_CBTN_MINIMIZE:
  6499. //
  6500. // Use Deskband object instead of system tray icon on NT51
  6501. //
  6502. if (IsOnNT51())
  6503. {
  6504. if (!_ptw->IsSFDeskband())
  6505. {
  6506. _ptw->GetLangBarMgr()->ShowFloating(TF_SFT_DESKBAND);
  6507. if (pMinimizeDlg = new CUTBMinimizeLangBarDlg)
  6508. {
  6509. pMinimizeDlg->DoModal(_ptw->GetWnd());
  6510. pMinimizeDlg->_Release();
  6511. }
  6512. }
  6513. break;
  6514. }
  6515. else
  6516. {
  6517. _ptw->GetLangBarMgr()->ShowFloating(TF_SFT_MINIMIZED);
  6518. if (pMinimizeDlg = new CUTBMinimizeLangBarDlg)
  6519. {
  6520. pMinimizeDlg->DoModal(_ptw->GetWnd());
  6521. pMinimizeDlg->_Release();
  6522. }
  6523. break;
  6524. }
  6525. case ID_CBTN_RESTORE:
  6526. //
  6527. // Use Deskband object instead of system tray icon on NT51
  6528. //
  6529. Assert(IsOnNT51());
  6530. if (_ptw->IsSFDeskband())
  6531. {
  6532. _ptw->GetLangBarMgr()->ShowFloating(TF_SFT_SHOWNORMAL);
  6533. }
  6534. break;
  6535. case ID_CBTN_EXTMENU:
  6536. ShowExtendMenu(pt);
  6537. break;
  6538. case ID_CBTN_KANAKEY:
  6539. keybd_event(VK_KANA, 0, 0, 0);
  6540. keybd_event(VK_KANA, 0, KEYEVENTF_KEYUP, 0);
  6541. break;
  6542. case ID_CBTN_CAPSKEY:
  6543. keybd_event(VK_CAPITAL, 0, 0, 0);
  6544. keybd_event(VK_CAPITAL, 0, KEYEVENTF_KEYUP, 0);
  6545. break;
  6546. }
  6547. }
  6548. //+---------------------------------------------------------------------------
  6549. //
  6550. // ShowExtendMenu
  6551. //
  6552. //----------------------------------------------------------------------------
  6553. void CTipbarCtrlButton::ShowExtendMenu(POINT pt)
  6554. {
  6555. CUTBIntelliMenu *pMenu;
  6556. RECT rc;
  6557. GetRect(&rc);
  6558. MyClientToScreen(&pt, &rc);
  6559. DWORD dwThreadId;
  6560. UINT uId = CUI_MENU_UNSELECTED;
  6561. if (!_ptw)
  6562. return;
  6563. if (!_ptw->GetFocusThread())
  6564. return;
  6565. dwThreadId = _ptw->GetFocusThread()->_dwThreadId;
  6566. pMenu = new CUTBIntelliMenu(_ptw);
  6567. if (!pMenu)
  6568. return;
  6569. if (!pMenu->Init())
  6570. goto Exit;
  6571. _ptw->_pttModal = _ptw->GetFocusThread();
  6572. _ptw->StartModalInput(_ptw, dwThreadId);
  6573. _ptw->_pModalMenu = pMenu;
  6574. uId = pMenu->ShowPopup(_ptw, pt, &rc);
  6575. _ptw->_pModalMenu = NULL;
  6576. _ptw->StopModalInput(dwThreadId);
  6577. _ptw->_pttModal = NULL;
  6578. if (uId != CUI_MENU_UNSELECTED)
  6579. {
  6580. pMenu->SelectMenuItem(uId);
  6581. }
  6582. Exit:
  6583. delete pMenu;
  6584. }