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

4184 lines
117 KiB

  1. #include "ctlspriv.h"
  2. #include "tab.h"
  3. #define BMOVECURSORONCLICK FALSE
  4. #define BMOVECURSORONDRAG TRUE
  5. BOOL Tab_OnGetItemRect(PTC ptc, int iItem, LPRECT lprc);
  6. BOOL Tab_Init(HINSTANCE hinst)
  7. {
  8. WNDCLASS wc;
  9. wc.lpfnWndProc = Tab_WndProc;
  10. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  11. wc.hIcon = NULL;
  12. wc.lpszMenuName = NULL;
  13. wc.hInstance = hinst;
  14. wc.lpszClassName = c_szTabControlClass;
  15. wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
  16. wc.style = CS_GLOBALCLASS | CS_DBLCLKS | CS_HREDRAW | CS_VREDRAW;
  17. wc.cbWndExtra = sizeof(PTC);
  18. wc.cbClsExtra = 0;
  19. if (!RegisterClass(&wc) && !GetClassInfo(hinst, c_szTabControlClass, &wc))
  20. return FALSE;
  21. return TRUE;
  22. }
  23. void Tab_VFlipRect(PTC ptc, LPRECT prc);
  24. void FlipRect(LPRECT prc);
  25. void VertInvalidateRect(HWND hwnd, LPRECT qrc, BOOL b, BOOL fVert);
  26. // Shared generic theme-aware code (exists in trackbar.c)
  27. void VertDrawEdge(HDC hdc, LPRECT qrc, UINT edgeType, UINT grfFlags,
  28. BOOL fVert, HTHEME hTheme, int iPartId, int iStateId);
  29. void VertPatBlt(HDC hdc1, int x1, int y1, int w, int h,
  30. DWORD rop, BOOL fVert, HTHEME hTheme, int iPartId, int iStateId);
  31. LRESULT TabDragCallback(HWND hwnd, UINT code, WPARAM wp, LPARAM lp)
  32. {
  33. PTC ptc = (PTC)GetWindowInt(hwnd, 0);
  34. LRESULT lres;
  35. switch (code)
  36. {
  37. case DPX_ENTER:
  38. case DPX_LEAVE:
  39. ptc->iDragTab = -1;
  40. ptc->dwDragDelay = 0;
  41. lres = 1;
  42. break;
  43. case DPX_DRAGHIT:
  44. if (lp)
  45. {
  46. BOOL fResetDelay = TRUE;
  47. int iTab;
  48. POINT pt;
  49. pt.x = ((POINTL *)lp)->x;
  50. pt.y = ((POINTL *)lp)->y;
  51. MapWindowPoints(NULL, ptc->ci.hwnd, &pt, 1);
  52. iTab = Tab_OnHitTest(ptc, pt.x, pt.y, NULL);
  53. if ((iTab != ptc->iSel))
  54. {
  55. if (iTab >= 0)
  56. {
  57. DWORD dwHitTime = GetTickCount();
  58. if (ptc->dwDragDelay == 0 ||
  59. dwHitTime - ptc->dwDragDelay >= TAB_DRAGDELAY)
  60. {
  61. if (ptc->dwDragDelay)
  62. {
  63. ChangeSel(ptc, iTab, TRUE, BMOVECURSORONDRAG);
  64. // present no target if validation failed
  65. // this will prevent accidental drops
  66. if (ptc->iSel != iTab)
  67. iTab = -1;
  68. }
  69. else
  70. {
  71. ptc->dwDragDelay = dwHitTime | 1; // make sure value is not zero
  72. fResetDelay = FALSE;
  73. }
  74. }
  75. else if (iTab == ptc->iDragTab)
  76. fResetDelay = FALSE;
  77. }
  78. ptc->iDragTab = iTab;
  79. }
  80. if (fResetDelay)
  81. ptc->dwDragDelay = 0;
  82. lres = (LRESULT)iTab;
  83. }
  84. else
  85. lres = -1;
  86. break;
  87. case DPX_GETOBJECT:
  88. lres = (LRESULT)GetItemObject(&ptc->ci, TCN_GETOBJECT, &IID_IDropTarget, (LPNMOBJECTNOTIFY)lp);
  89. break;
  90. case DPX_SELECT:
  91. if (((int)wp) >= 0)
  92. {
  93. SendMessage(ptc->ci.hwnd, TCM_HIGHLIGHTITEM, wp,
  94. MAKELPARAM((lp != DROPEFFECT_NONE), 0));
  95. }
  96. lres = 0;
  97. break;
  98. default:
  99. lres = -1;
  100. break;
  101. }
  102. return lres;
  103. }
  104. void VertSmoothScrollWindow(HWND hwnd, int dx, int dy, LPCRECT lprcSrc, LPCRECT lprcClip, HRGN hrgn, LPRECT lprcUpdate, UINT fuScroll, BOOL fVert, UINT uScrollMin)
  105. {
  106. RECT rcSrc;
  107. RECT rcClip;
  108. SMOOTHSCROLLINFO si;
  109. if (fVert)
  110. {
  111. SWAP(dx, dy, int);
  112. if (lprcSrc)
  113. {
  114. rcSrc = *lprcSrc;
  115. lprcSrc = &rcSrc;
  116. FlipRect(&rcSrc);
  117. }
  118. if (lprcClip)
  119. {
  120. rcClip = *lprcClip;
  121. lprcClip = &rcClip;
  122. FlipRect(&rcClip);
  123. }
  124. }
  125. si.cbSize=sizeof(si);
  126. si.fMask= SSIF_MINSCROLL;
  127. si.hwnd= hwnd;
  128. si.dx=dx;
  129. si.dy=dy;
  130. si.lprcSrc=lprcSrc;
  131. si.lprcClip=lprcClip;
  132. si.hrgnUpdate=hrgn;
  133. si.lprcUpdate=lprcUpdate;
  134. si.fuScroll=fuScroll;
  135. si.uMaxScrollTime=SSI_DEFAULT;
  136. si.cxMinScroll=uScrollMin;
  137. si.cyMinScroll= uScrollMin;
  138. si.pfnScrollProc = NULL;
  139. SmoothScrollWindow(&si);
  140. if (fVert)
  141. {
  142. if (lprcUpdate)
  143. FlipRect(lprcUpdate);
  144. }
  145. }
  146. void Tab_SmoothScrollWindow(PTC ptc, int dx, int dy, LPRECT lprcSrc, LPRECT lprcClip,
  147. HRGN hrgn, LPRECT lprcUpdate, UINT fuScroll, UINT uScrollMin)
  148. {
  149. RECT rcSrc;
  150. RECT rcClip;
  151. if (Tab_Bottom(ptc))
  152. {
  153. dy *= -1;
  154. if (lprcSrc)
  155. {
  156. rcSrc = *lprcSrc;
  157. lprcSrc = &rcSrc;
  158. Tab_VFlipRect(ptc, lprcSrc);
  159. }
  160. if (lprcClip)
  161. {
  162. rcClip = *lprcClip;
  163. lprcClip = &rcClip;
  164. Tab_VFlipRect(ptc, lprcClip);
  165. }
  166. }
  167. VertSmoothScrollWindow(ptc->ci.hwnd, dx, dy, lprcSrc, lprcClip, hrgn, lprcUpdate, fuScroll, Tab_Vertical(ptc), uScrollMin);
  168. if (lprcUpdate)
  169. {
  170. Tab_VFlipRect(ptc, lprcClip);
  171. }
  172. }
  173. void Tab_InvalidateRect(PTC ptc, LPRECT prc, BOOL b)
  174. {
  175. RECT rc = *prc;
  176. Tab_VFlipRect(ptc, &rc);
  177. VertInvalidateRect((ptc)->ci.hwnd, &rc, b, Tab_Vertical(ptc));
  178. }
  179. // Tab_DrawEdge is theme-aware
  180. void Tab_DrawEdge(HDC hdc, LPRECT prc, UINT uType, UINT uFlags, PTC ptc)
  181. {
  182. RECT rc = *prc;
  183. Tab_VFlipRect(ptc, &rc);
  184. if (Tab_Bottom(ptc))
  185. {
  186. UINT uNewFlags;
  187. if (uFlags & BF_DIAGONAL)
  188. {
  189. uNewFlags = uFlags & ~(BF_RIGHT | BF_LEFT);
  190. if (uFlags & BF_LEFT)
  191. uNewFlags |= BF_RIGHT;
  192. if (uFlags & BF_RIGHT)
  193. uNewFlags |= BF_LEFT;
  194. }
  195. else
  196. {
  197. uNewFlags = uFlags & ~(BF_TOP | BF_BOTTOM);
  198. if (uFlags & BF_TOP)
  199. uNewFlags |= BF_BOTTOM;
  200. if (uFlags & BF_BOTTOM)
  201. uNewFlags |= BF_TOP;
  202. }
  203. uFlags = uNewFlags;
  204. }
  205. VertDrawEdge(hdc, &rc, uType, uFlags, Tab_Vertical(ptc), ptc->hTheme, ptc->iPartId, ptc->iStateId);
  206. }
  207. // Tab_PatBlt is theme aware
  208. void Tab_PatBlt(HDC hdc, int x1, int y1, int w, int h, UINT rop, PTC ptc)
  209. {
  210. RECT rc;
  211. rc.top = y1;
  212. rc.left = x1;
  213. rc.right = x1+w;
  214. rc.bottom = y1+h;
  215. Tab_VFlipRect(ptc, &rc);
  216. VertPatBlt(hdc, rc.left, rc.top, RECTWIDTH(rc) , RECTHEIGHT(rc), rop, Tab_Vertical(ptc), ptc->hTheme, ptc->iPartId, ptc->iStateId);
  217. }
  218. void NormalizeRect(LPRECT prc)
  219. {
  220. if (prc->right < prc->left)
  221. {
  222. SWAP(prc->right, prc->left, int);
  223. }
  224. if (prc->bottom < prc->top)
  225. {
  226. SWAP(prc->bottom, prc->top, int);
  227. }
  228. }
  229. void VFlipRect(LPRECT prcClient, LPRECT prc)
  230. {
  231. int iTemp = prc->bottom;
  232. prc->bottom = prcClient->bottom - (prc->top - prcClient->top);
  233. prc->top = prcClient->bottom - (iTemp - prcClient->top);
  234. }
  235. // diagonal flip.
  236. void Tab_DFlipRect(PTC ptc, LPRECT prc)
  237. {
  238. if (Tab_Vertical(ptc))
  239. {
  240. FlipRect(prc);
  241. }
  242. }
  243. // vertical support is done much like the trackbar control. we're going
  244. // to flip the coordinate system. this means that tabs will be added from top down.
  245. void Tab_GetClientRect(PTC ptc, LPRECT prc)
  246. {
  247. GetClientRect(ptc->ci.hwnd, prc);
  248. Tab_DFlipRect(ptc, prc);
  249. }
  250. // vertical flip
  251. void Tab_VFlipRect(PTC ptc, LPRECT prc)
  252. {
  253. if (Tab_Bottom(ptc))
  254. {
  255. RECT rcClient;
  256. Tab_GetClientRect(ptc, &rcClient);
  257. VFlipRect(&rcClient, prc);
  258. }
  259. }
  260. void Tab_VDFlipRect(PTC ptc, LPRECT prc)
  261. {
  262. Tab_VFlipRect(ptc, prc);
  263. Tab_DFlipRect(ptc, prc);
  264. }
  265. // real coordinates to tab coordinates
  266. void Tab_DVFlipRect(PTC ptc, LPRECT prc)
  267. {
  268. Tab_DFlipRect(ptc, prc);
  269. Tab_VFlipRect(ptc, prc);
  270. }
  271. #define Tab_ImageList_GetIconSize(ptc, pcx, pcy) VertImageList_GetIconSize((ptc)->himl, pcx, pcy, Tab_Vertical(ptc))
  272. void VertImageList_GetIconSize(HIMAGELIST himl, LPINT pcx, LPINT pcy, BOOL fVert)
  273. {
  274. ImageList_GetIconSize(himl, pcx, pcy);
  275. if (fVert)
  276. {
  277. // if we're in vertical mode, the width is really the height.
  278. // we won't draw the bitmaps sideways. we'll rely on people
  279. // authoring them that way.
  280. int iTemp = *pcy;
  281. *pcy = *pcx;
  282. *pcx = iTemp;
  283. }
  284. }
  285. void VertImageList_Draw(HIMAGELIST himl, int iIndex, HDC hdc, int x, int y, UINT uFlags, BOOL fVert)
  286. {
  287. if (fVert) {
  288. int iTemp;
  289. iTemp = y;
  290. y = x;
  291. x = iTemp;
  292. // since we draw from the upper left, flipping the x/y axis means we still draw from the upper left.
  293. // all we need to do is swap x and y. we don't need to offset
  294. }
  295. ImageList_Draw( himl, iIndex, hdc, x, y, uFlags);
  296. }
  297. void Tab_ImageList_Draw(PTC ptc, int iImage, HDC hdc, int x, int y, UINT uFlags)
  298. {
  299. RECT rc;
  300. int cxImage, cyImage;
  301. Tab_ImageList_GetIconSize(ptc, &cxImage, &cyImage);
  302. if (Tab_Bottom(ptc)) {
  303. y += cyImage;
  304. }
  305. rc.top = rc.bottom = y;
  306. Tab_VFlipRect(ptc, &rc);
  307. y = rc.top;
  308. VertImageList_Draw((ptc)->himl, iImage, hdc, x, y, uFlags, Tab_Vertical(ptc));
  309. }
  310. // Tab_DrawText is theme aware (RENDERS)
  311. void Tab_DrawText(HDC hdc, LPTSTR lpsz, int nCount, LPRECT lprc, UINT uFormat, PTC ptc)
  312. {
  313. RECT rcTemp = *lprc;
  314. Tab_VDFlipRect(ptc, &rcTemp);
  315. if (Tab_Vertical(ptc))
  316. uFormat |= DT_BOTTOM;
  317. if (CCGetUIState(&(ptc->ci)) & UISF_HIDEACCEL)
  318. {
  319. uFormat |= DT_HIDEPREFIX;
  320. }
  321. // Use theme text renderer if possible
  322. if (ptc->hTheme)
  323. {
  324. DrawThemeText(ptc->hTheme, hdc, ptc->iPartId, ptc->iStateId, lpsz, nCount, uFormat, nCount, &rcTemp);
  325. }
  326. else
  327. {
  328. DrawText(hdc, lpsz, nCount, &rcTemp, uFormat);
  329. }
  330. }
  331. // Tab_DrawTextEx is theme aware (RENDERS)
  332. void Tab_DrawTextEx(HDC hdc, LPTSTR lpsz, int nCount, LPRECT lprc, UINT uFormat, LPDRAWTEXTPARAMS lpParams, PTC ptc)
  333. {
  334. RECT rcTemp = *lprc;
  335. Tab_VDFlipRect(ptc, &rcTemp);
  336. if (Tab_Vertical(ptc))
  337. uFormat |= DT_BOTTOM;
  338. if (CCGetUIState(&(ptc->ci)) & UISF_HIDEACCEL)
  339. {
  340. uFormat |= DT_HIDEPREFIX;
  341. }
  342. // Use theme text renderer if possible
  343. if (ptc->hTheme)
  344. {
  345. DrawThemeText(ptc->hTheme, hdc, ptc->iPartId, ptc->iStateId, lpsz, nCount, uFormat | DT_CENTER, nCount, &rcTemp);
  346. }
  347. else
  348. {
  349. DrawTextEx(hdc, lpsz, nCount, &rcTemp, uFormat, lpParams);
  350. }
  351. }
  352. // Tab_ExtTextOut is theme aware (RENDERS)
  353. void Tab_ExtTextOut(HDC hdc, int x, int y, UINT uFlags, LPRECT prc,
  354. LPTSTR lpsz, UINT cch, CONST INT *pdw, PTC ptc)
  355. {
  356. RECT rcTemp;
  357. rcTemp.left = rcTemp.right = x;
  358. if (Tab_Bottom(ptc) && !Tab_Vertical(ptc)) {
  359. // first we need to move the top point because if we're drawing on Tab_Bottom, then
  360. // text won't extend down from y.
  361. y += ptc->tmHeight;
  362. }
  363. rcTemp.top = rcTemp.bottom = y;
  364. Tab_VDFlipRect(ptc, &rcTemp);
  365. x = rcTemp.left;
  366. y = rcTemp.bottom;
  367. rcTemp = *prc;
  368. Tab_VDFlipRect(ptc, &rcTemp);
  369. // Use theme text renderer if possible
  370. if (ptc->hTheme)
  371. {
  372. if (lpsz)
  373. {
  374. UINT uDTFlags = 0;
  375. RECT rc = { x, y, rcTemp.right, rcTemp.bottom };
  376. if (!(uFlags & ETO_CLIPPED))
  377. uDTFlags |= DT_NOCLIP;
  378. if (uFlags & ETO_RTLREADING)
  379. uDTFlags |= DT_RTLREADING;
  380. // Vertical text not supported
  381. DrawThemeText(ptc->hTheme, hdc, ptc->iPartId, ptc->iStateId, lpsz, cch, uDTFlags, 0, &rc);
  382. }
  383. }
  384. else
  385. {
  386. ExtTextOut(hdc, x, y, uFlags, &rcTemp, lpsz, cch, pdw);
  387. }
  388. }
  389. void VertDrawFocusRect(HDC hdc, LPRECT lprc, BOOL fVert)
  390. {
  391. RECT rc;
  392. rc = *lprc;
  393. if (fVert)
  394. FlipRect(&rc);
  395. DrawFocusRect(hdc, &rc);
  396. }
  397. // Tab_DrawFocusRect is theme aware
  398. void Tab_DrawFocusRect(HDC hdc, LPRECT lprc, PTC ptc)
  399. {
  400. RECT rc = *lprc;
  401. Tab_VFlipRect(ptc, &rc);
  402. VertDrawFocusRect(hdc, &rc, Tab_Vertical(ptc));
  403. }
  404. void Tab_Scroll(PTC ptc, int dx, int iNewFirstIndex)
  405. {
  406. int i;
  407. int iMax;
  408. RECT rc;
  409. LPTABITEM pitem = NULL;
  410. // don't stomp on edge unless first item is selected
  411. rc.left = g_cxEdge;
  412. rc.right = ptc->cxTabs; // Dont scroll beyond tabs.
  413. rc.top = 0;
  414. rc.bottom = ptc->cyTabs + 2 * g_cyEdge; // Only scroll in the tab area
  415. // See if we can scroll the window...
  416. // DebugMsg(DM_TRACE, TEXT("Tab_Scroll dx=%d, iNew=%d\n\r"), dx, iNewFirstIndex);
  417. Tab_SmoothScrollWindow(ptc, dx, 0, NULL, &rc,
  418. NULL, NULL, SW_INVALIDATE | SW_ERASE, SSI_DEFAULT);
  419. // We also need to update the item rectangles and also
  420. // update the internal variables...
  421. iMax = Tab_Count(ptc) - 1;
  422. for (i = iMax; i >= 0; i--)
  423. {
  424. pitem = Tab_FastGetItemPtr(ptc, i);
  425. OffsetRect(&pitem->rc, dx, 0);
  426. }
  427. // If the previously last visible item is not fully visible
  428. // now, we need to invalidate it also.
  429. //
  430. if (ptc->iLastVisible > iMax)
  431. ptc->iLastVisible = iMax;
  432. for (i = ptc->iLastVisible; i>= 0; i--)
  433. {
  434. pitem = Tab_GetItemPtr(ptc, i);
  435. if (pitem) {
  436. if (pitem->rc.right <= ptc->cxTabs)
  437. break;
  438. Tab_InvalidateItem(ptc, ptc->iLastVisible, TRUE);
  439. }
  440. }
  441. if ((i == ptc->iLastVisible) && pitem)
  442. {
  443. // The last previously visible item is still fully visible, so
  444. // we need to invalidate to the right of it as there may have been
  445. // room for a partial item before, that will now need to be drawn.
  446. rc.left = pitem->rc.right;
  447. Tab_InvalidateRect(ptc, &rc, TRUE);
  448. }
  449. ptc->iFirstVisible = iNewFirstIndex;
  450. if (ptc->hwndArrows)
  451. SendMessage(ptc->hwndArrows, UDM_SETPOS, 0, MAKELPARAM(iNewFirstIndex, 0));
  452. UpdateToolTipRects(ptc);
  453. }
  454. void Tab_OnHScroll(PTC ptc, HWND hwndCtl, UINT code, int pos)
  455. {
  456. // Now process the Scroll messages
  457. if (code == SB_THUMBPOSITION)
  458. {
  459. //
  460. // For now lets simply try to set that item as the first one
  461. //
  462. {
  463. // If we got here we need to scroll
  464. LPTABITEM pitem = Tab_GetItemPtr(ptc, pos);
  465. int dx = 0;
  466. if (pitem)
  467. dx = -pitem->rc.left + g_cxEdge;
  468. if (dx || !pitem) {
  469. Tab_Scroll(ptc, dx, pos);
  470. UpdateWindow(ptc->ci.hwnd);
  471. }
  472. }
  473. }
  474. }
  475. void Tab_OnSetRedraw(PTC ptc, BOOL fRedraw)
  476. {
  477. if (fRedraw) {
  478. ptc->flags |= TCF_REDRAW;
  479. RedrawAll(ptc, RDW_INVALIDATE);
  480. } else {
  481. ptc->flags &= ~TCF_REDRAW;
  482. }
  483. }
  484. // Tab_OnSetFont will always cache the font (even if themes are on, in which case this font will be
  485. // ignored). This is because dialog managers will set the tabs font on creation. If themes are
  486. // turned off and this font was never set, the default system font will be incorrectly used.
  487. void Tab_OnSetFont(PTC ptc, HFONT hfont, BOOL fRedraw)
  488. {
  489. ASSERT(ptc);
  490. if (!ptc->hfontLabel || hfont != ptc->hfontLabel)
  491. {
  492. if (ptc->flags & TCF_FONTCREATED)
  493. {
  494. DeleteObject(ptc->hfontLabel);
  495. ptc->flags &= ~TCF_FONTCREATED;
  496. ptc->hfontLabel = NULL;
  497. }
  498. if (!hfont)
  499. {
  500. // set back to system font
  501. ptc->hfontLabel = g_hfontSystem;
  502. }
  503. else
  504. {
  505. ptc->flags |= TCF_FONTSET;
  506. ptc->hfontLabel = hfont;
  507. ptc->ci.uiCodePage = GetCodePageForFont(hfont);
  508. }
  509. ptc->cxItem = ptc->cyTabs = RECOMPUTE;
  510. if (Tab_Vertical(ptc))
  511. {
  512. // make sure that the font is drawn vertically
  513. LOGFONT lf;
  514. GetObject(ptc->hfontLabel, sizeof(lf), &lf);
  515. if (Tab_Bottom(ptc))
  516. {
  517. lf.lfEscapement = 2700;
  518. }
  519. else
  520. {
  521. lf.lfEscapement = 900; // 90 degrees
  522. }
  523. lf.lfOutPrecision = OUT_TT_ONLY_PRECIS;
  524. ptc->hfontLabel = CreateFontIndirect(&lf);
  525. if (ptc->hfontLabel != NULL)
  526. ptc->flags |= TCF_FONTCREATED;
  527. }
  528. if (ptc->hfontLabel != NULL)
  529. RedrawAll(ptc, RDW_INVALIDATE | RDW_ERASE);
  530. }
  531. }
  532. BOOL Tab_OnCreate(PTC ptc)
  533. {
  534. HDC hdc;
  535. DWORD exStyle = 0;
  536. ptc->hdpa = DPA_Create(4);
  537. if (!ptc->hdpa)
  538. return FALSE;
  539. // make sure we don't have invalid bits set
  540. if (!Tab_FixedWidth(ptc))
  541. {
  542. ptc->ci.style &= ~(TCS_FORCEICONLEFT | TCS_FORCELABELLEFT);
  543. }
  544. if (Tab_Vertical(ptc))
  545. {
  546. ptc->ci.style |= TCS_MULTILINE;
  547. //ptc->ci.style &= ~TCS_BUTTONS;
  548. }
  549. if (Tab_ScrollOpposite(ptc))
  550. {
  551. ptc->ci.style |= TCS_MULTILINE;
  552. ptc->ci.style &= ~TCS_BUTTONS;
  553. }
  554. if (Tab_FlatButtons(ptc))
  555. {
  556. ptc->dwStyleEx |= TCS_EX_FLATSEPARATORS;
  557. }
  558. // Initialize themes. No themes for owner drawn or button-style tab controls
  559. ptc->hTheme = (!Tab_OwnerDraw(ptc) && !Tab_DrawButtons(ptc)) ? OpenThemeData(ptc->ci.hwnd, L"Tab") : NULL;
  560. // Active hot state if themes are in use
  561. if (ptc->hTheme)
  562. {
  563. ptc->ci.style |= TCS_HOTTRACK;
  564. }
  565. // make us always clip siblings
  566. SetWindowLong(ptc->ci.hwnd, GWL_STYLE, WS_CLIPSIBLINGS | ptc->ci.style);
  567. ptc->flags = TCF_REDRAW; // enable redraw
  568. ptc->cbExtra = sizeof(LPARAM); // default extra size
  569. ptc->iSel = -1;
  570. ptc->iHot = -1;
  571. ptc->cxItem = ptc->cyTabs = RECOMPUTE;
  572. ptc->cxPad = g_cxEdge * 3;
  573. ptc->cyPad = (g_cyEdge * 3/2);
  574. ptc->iFirstVisible = 0;
  575. ptc->hwndArrows = NULL;
  576. ptc->iLastRow = -1;
  577. ptc->iNewSel = -1;
  578. ptc->iLastTopRow = -1;
  579. hdc = GetDC(NULL);
  580. ptc->iTabWidth = GetDeviceCaps(hdc, LOGPIXELSX);
  581. ReleaseDC(NULL, hdc);
  582. InitDitherBrush();
  583. if (ptc->ci.style & TCS_TOOLTIPS)
  584. {
  585. TOOLINFO ti;
  586. // don't bother setting the rect because we'll do it below
  587. // in FlushToolTipsMgr;
  588. ti.cbSize = sizeof(ti);
  589. ti.uFlags = TTF_IDISHWND;
  590. ti.hwnd = ptc->ci.hwnd;
  591. ti.uId = (UINT_PTR)ptc->ci.hwnd;
  592. ti.lpszText = 0;
  593. ptc->hwndToolTips = CreateWindowEx(exStyle, c_szSToolTipsClass, TEXT(""),
  594. WS_POPUP,
  595. CW_USEDEFAULT, CW_USEDEFAULT,
  596. CW_USEDEFAULT, CW_USEDEFAULT,
  597. ptc->ci.hwnd, NULL, HINST_THISDLL,
  598. NULL);
  599. if (ptc->hwndToolTips)
  600. SendMessage(ptc->hwndToolTips, TTM_ADDTOOL, 0,
  601. (LPARAM)(LPTOOLINFO)&ti);
  602. else
  603. ptc->ci.style &= ~(TCS_TOOLTIPS);
  604. }
  605. if (g_fDBCSInputEnabled)
  606. ptc->hPrevImc = ImmAssociateContext(ptc->ci.hwnd, 0L);
  607. // Setup theme state for methods called that render themes before first paint, setup state (TAB/BUTTON)
  608. if (ptc->hTheme)
  609. {
  610. ptc->iPartId = TABP_TABITEM;
  611. ptc->iStateId = TIS_NORMAL;
  612. }
  613. return TRUE;
  614. }
  615. void Tab_OnDestroy(PTC ptc)
  616. {
  617. int i;
  618. // Close theme
  619. if (ptc->hTheme)
  620. CloseThemeData(ptc->hTheme);
  621. if (g_fDBCSInputEnabled)
  622. ImmAssociateContext(ptc->ci.hwnd, ptc->hPrevImc);
  623. if ((ptc->ci.style & TCS_TOOLTIPS) && IsWindow(ptc->hwndToolTips))
  624. {
  625. DestroyWindow(ptc->hwndToolTips);
  626. }
  627. for (i = 0; i < Tab_Count(ptc); i++)
  628. Tab_FreeItem(ptc, Tab_FastGetItemPtr(ptc, i));
  629. DPA_Destroy(ptc->hdpa);
  630. if (ptc->hDragProxy)
  631. DestroyDragProxy(ptc->hDragProxy);
  632. if (ptc->flags & TCF_FONTCREATED) {
  633. DeleteObject(ptc->hfontLabel);
  634. }
  635. if (ptc) {
  636. SetWindowInt(ptc->ci.hwnd, 0, 0);
  637. NearFree((HLOCAL)ptc);
  638. }
  639. TerminateDitherBrush();
  640. }
  641. // returns true if it actually moved
  642. void PutzRowToBottom(PTC ptc, int iRowMoving)
  643. {
  644. int i;
  645. LPTABITEM pitem;
  646. int dy;
  647. RECT rcTabs;
  648. Tab_GetClientRect(ptc, &rcTabs);
  649. if (Tab_ScrollOpposite(ptc)) {
  650. // in scroll mode, the iRow doesn't change. only the rc's do.
  651. int yOldTop;
  652. int yNewTop;
  653. int iLastTopRow = ptc->iLastTopRow == -1 ? ptc->iLastRow : ptc->iLastTopRow;
  654. if (iRowMoving == iLastTopRow) {
  655. if (ptc->iLastTopRow == -1)
  656. ptc->iLastTopRow = iRowMoving;
  657. return; // already at the bottom;
  658. }
  659. // this is the height of the tab's empty area... which is the amount
  660. // of space a tab must move to get from the top to the bottom
  661. dy = rcTabs.bottom - rcTabs.top - (ptc->cyTabs * (ptc->iLastRow + 1)) - g_cyEdge;
  662. for (i = Tab_Count(ptc) - 1; i >= 0; i--) {
  663. pitem = Tab_FastGetItemPtr(ptc, i);
  664. DebugMsg(DM_TRACE, TEXT("Putzing %s %d %d %d %d"), pitem->pszText, pitem->rc.left, pitem->rc.top, pitem->rc.right, pitem->rc.bottom);
  665. // save this for scrolling below
  666. if (pitem->iRow == iRowMoving) {
  667. yNewTop = pitem->rc.bottom;
  668. } else if (pitem->iRow == iLastTopRow) {
  669. yOldTop = pitem->rc.bottom;
  670. }
  671. if (pitem->iRow > iRowMoving) {
  672. // this item should be on the bottom
  673. if (pitem->iRow <= iLastTopRow) {
  674. // but it's not...
  675. OffsetRect(&pitem->rc, 0, dy);
  676. }
  677. } else {
  678. // this item should be on the top
  679. if (pitem->iRow > iLastTopRow) {
  680. // but it's not... so move it
  681. OffsetRect(&pitem->rc, 0, -dy);
  682. }
  683. }
  684. if ((pitem->iRow == iLastTopRow) && iLastTopRow > iRowMoving) {
  685. // in this case, we need to get the yOldTop AFTER it's moved.
  686. yOldTop = pitem->rc.bottom;
  687. }
  688. DebugMsg(DM_TRACE, TEXT("Putzing %s %d %d %d %d"), pitem->pszText, pitem->rc.left, pitem->rc.top, pitem->rc.right, pitem->rc.bottom);
  689. }
  690. if (ptc->iLastTopRow != -1) {
  691. // if it wasn't a full recalc, then we need to do some scrollwindow stuff.
  692. int dy;
  693. // first find the topmost parent
  694. dy = yOldTop - yNewTop;
  695. if (yNewTop > yOldTop) {
  696. rcTabs.top = yOldTop;
  697. rcTabs.bottom = yNewTop;
  698. } else {
  699. rcTabs.top = yNewTop;
  700. rcTabs.bottom = yOldTop;
  701. }
  702. Tab_SmoothScrollWindow(ptc, 0, dy, NULL, &rcTabs, NULL, NULL, SW_ERASE |SW_INVALIDATE, 1);
  703. InflateRect(&rcTabs, g_cxEdge, g_cyEdge);
  704. Tab_InvalidateRect(ptc, &rcTabs, FALSE);
  705. }
  706. ptc->iLastTopRow = iRowMoving;
  707. } else {
  708. if (iRowMoving == ptc->iLastRow)
  709. return; // already at the bottom;
  710. // no scrolling. just set the iRow var appropriatesly
  711. for (i = Tab_Count(ptc) -1 ;i >= 0; i--) {
  712. pitem = Tab_FastGetItemPtr(ptc, i);
  713. if (pitem->iRow > iRowMoving) {
  714. // if the row is higher than the row that's being selected,
  715. // it drops one.
  716. pitem->iRow--;
  717. dy = -ptc->cyTabs;
  718. } else if (pitem->iRow == iRowMoving) {
  719. // save this
  720. rcTabs.top = pitem->rc.top;
  721. // if it's on the row that's moving down, we assign it to iLastRow and
  722. //calculate how far it needs to go.
  723. dy = ptc->cyTabs * (ptc->iLastRow - iRowMoving);
  724. pitem->iRow = ptc->iLastRow;
  725. } else
  726. continue;
  727. pitem->rc.top += dy;
  728. pitem->rc.bottom += dy;
  729. }
  730. rcTabs.bottom = ptc->cyTabs * (ptc->iLastRow + 1);
  731. Tab_SmoothScrollWindow(ptc, 0, rcTabs.bottom - rcTabs.top, NULL, &rcTabs, NULL, NULL, SW_ERASE |SW_INVALIDATE, 1);
  732. UpdateWindow(ptc->ci.hwnd);
  733. // invalidate the little bit below the
  734. rcTabs.bottom += 2*g_cyEdge;
  735. rcTabs.top = rcTabs.bottom - 3 * g_cyEdge;
  736. Tab_InvalidateRect(ptc, &rcTabs, TRUE);
  737. }
  738. UpdateToolTipRects(ptc);
  739. }
  740. __inline int Tab_InterButtonGap(PTC ptc)
  741. {
  742. ASSERT(Tab_DrawButtons(ptc));
  743. if (Tab_FlatButtons(ptc)) {
  744. return (g_cxEdge * 5);
  745. } else {
  746. return (g_cxEdge * 3)/2;
  747. }
  748. }
  749. //
  750. // BADNESS is the amount of unused space in the row
  751. //
  752. #define BADNESS(ptc, i) (ptc->cxTabs - Tab_FastGetItemPtr(ptc, i)->rc.right)
  753. // borrow one tab from the prevous row
  754. BOOL BorrowOne(PTC ptc, int iCurLast, int iPrevLast, int iBorrow)
  755. {
  756. LPTABITEM pitem, pitem2;
  757. int i;
  758. int dx;
  759. // is there room to move the prev item? (might now be if iPrev is huge)
  760. pitem = Tab_FastGetItemPtr(ptc, iPrevLast);
  761. pitem2 = Tab_FastGetItemPtr(ptc, iCurLast);
  762. // dx is the number of extra pixels that aren't part of the pitem->rc.
  763. // The non-button case of 2 * g_cxEdge is maniacally hard-coded
  764. // all over the place. Change it at your own risk.
  765. if (Tab_DrawButtons(ptc))
  766. dx = Tab_InterButtonGap(ptc);
  767. else
  768. dx = 2 * g_cxEdge; // inflate by g_cxEdge
  769. // if the size of the item is greaterthan the badness
  770. if (BADNESS(ptc, iCurLast) < (pitem->rc.right - pitem->rc.left + dx))
  771. return FALSE;
  772. // otherwise do it.
  773. // move this one down
  774. dx = pitem->rc.left - Tab_FastGetItemPtr(ptc, iPrevLast + 1)->rc.left;
  775. pitem->rc.left -= dx;
  776. pitem->rc.right -= dx;
  777. pitem->rc.top = pitem2->rc.top;
  778. pitem->rc.bottom = pitem2->rc.bottom;
  779. pitem->iRow = pitem2->iRow;
  780. // and move all the others over.
  781. dx = pitem->rc.right - pitem->rc.left;
  782. for(i = iPrevLast + 1 ; i <= iCurLast ; i++ ) {
  783. pitem = Tab_FastGetItemPtr(ptc, i);
  784. pitem->rc.left += dx;
  785. pitem->rc.right += dx;
  786. }
  787. if (iBorrow) {
  788. if (pitem->iRow > 1) {
  789. // borrow one from the next row up.
  790. // setup the new iCurLast as the one right before the one we moved
  791. // (the one we moved is now the current row's first
  792. // and hunt backwards until we find an iPrevLast
  793. iCurLast = iPrevLast - 1;
  794. while (iPrevLast-- &&
  795. Tab_FastGetItemPtr(ptc, iPrevLast)->iRow == (pitem->iRow - 1))
  796. {
  797. if (iPrevLast <= 0)
  798. {
  799. // sanity check
  800. return FALSE;
  801. }
  802. }
  803. return BorrowOne(ptc, iCurLast, iPrevLast, iBorrow - 1 );
  804. } else
  805. return FALSE;
  806. }
  807. return TRUE;
  808. }
  809. // fill last row will fiddle around borrowing from the previous row(s)
  810. // to keep from having huge huge bottom tabs
  811. void FillLastRow(PTC ptc)
  812. {
  813. int hspace;
  814. int cItems = Tab_Count(ptc);
  815. int iPrevLast;
  816. int iBorrow = 0;
  817. // if not even two items, nothing to fill from
  818. if (cItems < 2)
  819. return;
  820. // find last item on previous row
  821. for (iPrevLast = cItems - 2;
  822. Tab_FastGetItemPtr(ptc, iPrevLast)->iRow == ptc->iLastRow;
  823. iPrevLast--)
  824. {
  825. // sanity check
  826. if (iPrevLast <= 0)
  827. {
  828. ASSERT(FALSE);
  829. return;
  830. }
  831. }
  832. while (iPrevLast && (hspace = BADNESS(ptc, cItems-1)) &&
  833. (hspace > ((ptc->cxTabs/8) + BADNESS(ptc, iPrevLast))))
  834. {
  835. // if borrow fails, bail
  836. if (!BorrowOne(ptc, cItems - 1, iPrevLast, iBorrow++))
  837. return;
  838. iPrevLast--;
  839. }
  840. }
  841. void RightJustify(PTC ptc)
  842. {
  843. int i;
  844. LPTABITEM pitem;
  845. int j;
  846. int k;
  847. int n;
  848. int cItems = Tab_Count(ptc);
  849. int hspace, dwidth, dremainder, moved;
  850. // don't justify if only one row
  851. if (ptc->iLastRow < 1)
  852. return;
  853. FillLastRow(ptc);
  854. for ( i = 0; i < cItems; i++ ) {
  855. int iRow;
  856. pitem = Tab_FastGetItemPtr(ptc, i) ;
  857. iRow = pitem->iRow;
  858. // find the last item in this row
  859. for( j = i ; j < cItems; j++) {
  860. if(Tab_FastGetItemPtr(ptc, j)->iRow != iRow)
  861. break;
  862. }
  863. // count the number of items
  864. for(n=0,k=i ; k < j ; k++ ) {
  865. pitem = Tab_FastGetItemPtr(ptc, k);
  866. if (!(pitem->dwState & TCIS_HIDDEN))
  867. n++;
  868. }
  869. // how much to fill
  870. hspace = ptc->cxTabs - Tab_FastGetItemPtr(ptc, j-1)->rc.right - g_cxEdge;
  871. dwidth = hspace/n; // amount to increase each by.
  872. dremainder = hspace % n; // the remnants
  873. moved = 0; // how much we've moved already
  874. for( ; i < j ; i++ ) {
  875. int iHalf = dwidth/2;
  876. pitem = Tab_FastGetItemPtr(ptc, i);
  877. if (!(pitem->dwState & TCIS_HIDDEN)) {
  878. pitem->rc.left += moved;
  879. pitem->xLabel += iHalf;
  880. pitem->xImage += iHalf;
  881. moved += dwidth + (dremainder ? 1 : 0);
  882. if ( dremainder ) dremainder--;
  883. pitem->rc.right += moved;
  884. }
  885. }
  886. i--; //dec because the outter forloop incs again.
  887. }
  888. }
  889. BOOL Tab_OnDeleteAllItems(PTC ptc)
  890. {
  891. int i;
  892. for (i = Tab_Count(ptc); i-- > 0; i) {
  893. if(ptc->hwndToolTips) {
  894. TOOLINFO ti;
  895. ti.cbSize = sizeof(ti);
  896. ti.hwnd = ptc->ci.hwnd;
  897. ti.uId = i;
  898. SendMessage(ptc->hwndToolTips, TTM_DELTOOL, 0,
  899. (LPARAM)(LPTOOLINFO)&ti);
  900. }
  901. Tab_FreeItem(ptc, Tab_FastGetItemPtr(ptc, i));
  902. }
  903. DPA_DeleteAllPtrs(ptc->hdpa);
  904. ptc->cxItem = RECOMPUTE; // force recomputing of all tabs
  905. ptc->iSel = -1;
  906. ptc->iFirstVisible = 0;
  907. RedrawAll(ptc, RDW_INVALIDATE | RDW_ERASE);
  908. return TRUE;
  909. }
  910. BOOL Tab_OnSetItemExtra(PTC ptc, int cbExtra)
  911. {
  912. if (Tab_Count(ptc) >0 || cbExtra<0)
  913. return FALSE;
  914. ptc->cbExtra = cbExtra;
  915. return TRUE;
  916. }
  917. BOOL Tab_OnSetItem(PTC ptc, int iItem, const TC_ITEM* ptci)
  918. {
  919. TABITEM* pitem;
  920. UINT mask;
  921. BOOL fChanged = FALSE;
  922. BOOL fFullRedraw = FALSE;
  923. mask = ptci->mask;
  924. if (!mask)
  925. return TRUE;
  926. pitem = Tab_GetItemPtr(ptc, iItem);
  927. if (!pitem)
  928. return FALSE;
  929. if (mask & TCIF_TEXT)
  930. {
  931. if (!Str_Set(&pitem->pszText, ptci->pszText))
  932. return FALSE;
  933. fFullRedraw = TRUE;
  934. fChanged = TRUE;
  935. pitem->etoRtlReading = (mask & TCIF_RTLREADING) ?ETO_RTLREADING :0;
  936. }
  937. if (mask & TCIF_IMAGE)
  938. {
  939. if (pitem->iImage == -1 ||
  940. ptci->iImage == -1)
  941. {
  942. // went from no image to image... or vice versa
  943. // means needs full redraw
  944. fFullRedraw = TRUE;
  945. }
  946. pitem->iImage = ptci->iImage;
  947. fChanged = TRUE;
  948. }
  949. if ((mask & TCIF_PARAM) && ptc->cbExtra)
  950. {
  951. hmemcpy(pitem->DUMMYUNION_MEMBER(abExtra), &ptci->lParam, ptc->cbExtra);
  952. }
  953. if (mask & TCIF_STATE) {
  954. DWORD dwOldState = pitem->dwState;
  955. pitem->dwState =
  956. (ptci->dwState & ptci->dwStateMask) |
  957. (pitem->dwState & ~ptci->dwStateMask);
  958. if (dwOldState != pitem->dwState)
  959. fChanged = TRUE;
  960. if ((dwOldState ^ pitem->dwState) & TCIS_HIDDEN)
  961. fFullRedraw = TRUE;
  962. if ((ptci->dwStateMask & TCIS_BUTTONPRESSED) &&
  963. !(ptci->dwState & TCIS_BUTTONPRESSED)) {
  964. // if they turned OFF being pushed and we were pushed because of
  965. // selection, nuke it now.
  966. if (ptc->iNewSel == iItem) {
  967. ptc->iNewSel = -1;
  968. fChanged = TRUE;
  969. }
  970. if (ptc->iSel == iItem) {
  971. ChangeSel(ptc, -1, TRUE, FALSE);
  972. fChanged = TRUE;
  973. }
  974. }
  975. }
  976. if (fChanged) {
  977. if (Tab_FixedWidth(ptc) || !fFullRedraw) {
  978. Tab_InvalidateItem(ptc, iItem, FALSE);
  979. } else {
  980. ptc->cxItem = ptc->cyTabs = RECOMPUTE;
  981. RedrawAll(ptc, RDW_INVALIDATE | RDW_NOCHILDREN | RDW_ERASE);
  982. }
  983. }
  984. return TRUE;
  985. }
  986. void Tab_OnMouseMove(PTC ptc, WPARAM fwKeys, int x, int y)
  987. {
  988. POINT pt;
  989. int iHit;
  990. pt.x=x; pt.y=y;
  991. iHit = Tab_OnHitTest(ptc, x, y, NULL);
  992. if (Tab_HotTrack(ptc)) {
  993. if (iHit != ptc->iHot) {
  994. Tab_InvalidateItem(ptc, iHit, FALSE);
  995. Tab_InvalidateItem(ptc, ptc->iHot, FALSE);
  996. ptc->iHot = iHit;
  997. }
  998. }
  999. if (fwKeys & MK_LBUTTON && Tab_DrawButtons(ptc)) {
  1000. UINT uFlags;
  1001. if (ptc->iNewSel == -1)
  1002. return;
  1003. if (iHit == ptc->iNewSel) {
  1004. uFlags = TCF_DRAWSUNKEN;
  1005. } else {
  1006. uFlags = 0;
  1007. }
  1008. if ((ptc->flags & TCF_DRAWSUNKEN) != uFlags) {
  1009. // the bit isn't what it should be
  1010. ptc->flags ^= TCF_DRAWSUNKEN;
  1011. // we need to invalidate on flat buttons because we go from one pixes to 2 pixel edge
  1012. Tab_InvalidateItem(ptc, ptc->iNewSel, Tab_FlatButtons(ptc));
  1013. }
  1014. }
  1015. }
  1016. void Tab_OnButtonUp(PTC ptc, int x, int y, BOOL fNotify)
  1017. {
  1018. BOOL fAllow = TRUE;
  1019. if (fNotify) {
  1020. // pass NULL for parent because W95 queryied each time and some
  1021. // folks reparent
  1022. fAllow = !SendNotifyEx(NULL, ptc->ci.hwnd, NM_CLICK, NULL, ptc->ci.bUnicode);
  1023. }
  1024. if (Tab_DrawSunken(ptc)) {
  1025. // nothing selected (its empty)
  1026. // only do this if something is selected...
  1027. // otherwise we still do need to go below and release capture though
  1028. if (ptc->iNewSel != -1) {
  1029. if (Tab_OnHitTest(ptc, x, y, NULL) == ptc->iNewSel) {
  1030. int iNewSel = ptc->iNewSel;
  1031. // use iNewSel instead of ptc->iNewSel because the SendNotify could have nuked us
  1032. if (fAllow)
  1033. ChangeSel(ptc, iNewSel, TRUE, BMOVECURSORONCLICK);
  1034. Tab_InvalidateItem(ptc, iNewSel, FALSE);
  1035. } else {
  1036. Tab_InvalidateItem(ptc, ptc->iNewSel, FALSE);
  1037. Tab_InvalidateItem(ptc, ptc->iNewSel, FALSE);
  1038. }
  1039. // the changsel forces an updatewindow,
  1040. // but we might have a border to unpaint(because of the TCF_DRAWSUNKEN
  1041. // so we do another invalidate with just redraw
  1042. ptc->flags &= ~TCF_DRAWSUNKEN;
  1043. ptc->iNewSel = -1;
  1044. }
  1045. }
  1046. // don't worry about checking DrawButtons because TCF_MOUSEDOWN
  1047. // wouldn't be set otherwise.
  1048. if (ptc->flags & TCF_MOUSEDOWN) {
  1049. int iOldSel = ptc->iNewSel;
  1050. ptc->flags &= ~TCF_MOUSEDOWN; // do this before release to avoid reentry
  1051. ptc->iNewSel = -1;
  1052. Tab_InvalidateItem(ptc, iOldSel, FALSE);
  1053. CCReleaseCapture(&ptc->ci);
  1054. }
  1055. }
  1056. int Tab_OnHitTest(PTC ptc, int x, int y, UINT *lpuFlags)
  1057. {
  1058. int i;
  1059. int iLast = Tab_Count(ptc);
  1060. RECT rc;
  1061. POINT pt;
  1062. UINT uTemp;
  1063. rc.left = rc.right = x;
  1064. rc.top = rc.bottom = y;
  1065. Tab_DVFlipRect(ptc, &rc);
  1066. pt.x = rc.left;
  1067. pt.y = rc.top;
  1068. if (!lpuFlags) lpuFlags = &uTemp;
  1069. for (i = 0; i < iLast; i++) {
  1070. LPTABITEM pitem = Tab_FastGetItemPtr(ptc, i);
  1071. if (PtInRect(&pitem->rc, pt)) {
  1072. // x now needs to be in pitem coordinates
  1073. x -= pitem->rc.left;
  1074. *lpuFlags = TCHT_ONITEM;
  1075. if (!Tab_OwnerDraw(ptc)) {
  1076. if ((x > pitem->xLabel) && x < pitem->xLabel + pitem->cxLabel) {
  1077. *lpuFlags = TCHT_ONITEMLABEL;
  1078. } else if (HASIMAGE(ptc, pitem)) {
  1079. int cxImage, cyImage;
  1080. Tab_ImageList_GetIconSize(ptc, &cxImage, &cyImage);
  1081. if ((x > pitem->xImage) && (x < (pitem->xImage + cxImage)))
  1082. *lpuFlags = TCHT_ONITEMICON;
  1083. }
  1084. }
  1085. return i;
  1086. }
  1087. }
  1088. *lpuFlags = TCHT_NOWHERE;
  1089. return -1;
  1090. }
  1091. void Tab_DeselectAll(PTC ptc, BOOL fExcludeFocus)
  1092. {
  1093. int iMax = Tab_Count(ptc) - 1;
  1094. int i;
  1095. if (Tab_DrawButtons(ptc)) {
  1096. for (i = iMax; i >= 0; i--)
  1097. {
  1098. LPTABITEM pitem;
  1099. pitem = Tab_FastGetItemPtr(ptc, i);
  1100. if (!fExcludeFocus || (pitem->dwState & TCIS_BUTTONPRESSED)) {
  1101. TCITEM tci;
  1102. tci.mask = TCIF_STATE;
  1103. tci.dwStateMask = TCIS_BUTTONPRESSED;
  1104. tci.dwState = 0;
  1105. Tab_OnSetItem(ptc, i, &tci);
  1106. }
  1107. }
  1108. }
  1109. }
  1110. void Tab_OnRButtonDown(PTC ptc, int x, int y, WPARAM keyFlags)
  1111. {
  1112. int i;
  1113. int iOldSel = -1;
  1114. if (Tab_Vertical(ptc)) {
  1115. if (y > ptc->cxTabs)
  1116. return;
  1117. } else {
  1118. if (x > ptc->cxTabs)
  1119. return; // outside the range of the visible tabs
  1120. }
  1121. i = Tab_OnHitTest(ptc, x,y, NULL); // we don't swap x,y here because OnHitTest will
  1122. if (i != -1) {
  1123. if (Tab_DrawButtons(ptc) && Tab_MultiSelect(ptc)) {
  1124. TCITEM tci;
  1125. tci.mask = TCIF_STATE;
  1126. tci.dwStateMask = TCIS_BUTTONPRESSED;
  1127. Tab_OnGetItem(ptc, i, &tci);
  1128. // as with the listview, don't deselect anything on right button
  1129. if (!(tci.dwState & TCIS_BUTTONPRESSED)) {
  1130. if (!(GetAsyncKeyState(VK_CONTROL) < 0)) {
  1131. Tab_DeselectAll(ptc, FALSE);
  1132. }
  1133. // just toggle the pushed state.
  1134. tci.dwState = TCIS_BUTTONPRESSED;
  1135. Tab_OnSetItem(ptc, i, &tci);
  1136. }
  1137. }
  1138. }
  1139. }
  1140. void Tab_OnLButtonDown(PTC ptc, int x, int y, WPARAM keyFlags)
  1141. {
  1142. int i;
  1143. int iOldSel = -1;
  1144. if (Tab_Vertical(ptc)) {
  1145. if (y > ptc->cxTabs)
  1146. return;
  1147. } else {
  1148. if (x > ptc->cxTabs)
  1149. return; // outside the range of the visible tabs
  1150. }
  1151. i = Tab_OnHitTest(ptc, x,y, NULL); // we don't swap x,y here because OnHitTest will
  1152. if (i != -1) {
  1153. if (Tab_MultiSelect(ptc) && (GetAsyncKeyState(VK_CONTROL) < 0) && Tab_DrawButtons(ptc) ) {
  1154. // just toggle the pushed state.
  1155. TCITEM tci;
  1156. tci.mask = TCIF_STATE;
  1157. tci.dwStateMask = TCIS_BUTTONPRESSED;
  1158. Tab_OnGetItem(ptc, i, &tci);
  1159. tci.dwState ^= TCIS_BUTTONPRESSED;
  1160. Tab_OnSetItem(ptc, i, &tci);
  1161. } else {
  1162. iOldSel = ptc->iSel;
  1163. if ((!Tab_FocusNever(ptc))
  1164. && Tab_FocusOnButtonDown(ptc))
  1165. {
  1166. SetFocus(ptc->ci.hwnd);
  1167. }
  1168. if (Tab_DrawButtons(ptc)) {
  1169. ptc->iNewSel = i;
  1170. ptc->flags |= (TCF_DRAWSUNKEN|TCF_MOUSEDOWN);
  1171. SetCapture(ptc->ci.hwnd);
  1172. // we need to invalidate on flat buttons because we go from one pixes to 2 pixel edge
  1173. Tab_InvalidateItem(ptc, i, Tab_FlatButtons(ptc));
  1174. } else {
  1175. iOldSel = ChangeSel(ptc, i, TRUE, BMOVECURSORONCLICK);
  1176. }
  1177. }
  1178. }
  1179. if ((!Tab_FocusNever(ptc)) &&
  1180. (iOldSel == i)) // reselect current selection
  1181. // this also catches i == -1 because iOldSel started as -1
  1182. {
  1183. SetFocus(ptc->ci.hwnd);
  1184. UpdateWindow(ptc->ci.hwnd);
  1185. }
  1186. }
  1187. TABITEM* Tab_CreateItem(PTC ptc, const TC_ITEM* ptci)
  1188. {
  1189. TABITEM* pitem;
  1190. if (pitem = Alloc(sizeof(TABITEM)-sizeof(LPARAM)+ptc->cbExtra))
  1191. {
  1192. if (ptci->mask & TCIF_IMAGE)
  1193. pitem->iImage = ptci->iImage;
  1194. else
  1195. pitem->iImage = -1;
  1196. pitem->xLabel = pitem->yLabel = RECOMPUTE;
  1197. // If specified, copy extra block of memory.
  1198. if (ptci->mask & TCIF_PARAM)
  1199. {
  1200. if (ptc->cbExtra)
  1201. {
  1202. hmemcpy(pitem->DUMMYUNION_MEMBER(abExtra), &ptci->lParam, ptc->cbExtra);
  1203. }
  1204. }
  1205. if (ptci->mask & TCIF_TEXT)
  1206. {
  1207. if (!Str_Set(&pitem->pszText, ptci->pszText))
  1208. {
  1209. Tab_FreeItem(ptc, pitem);
  1210. return NULL;
  1211. }
  1212. pitem->etoRtlReading = (ptci->mask & TCIF_RTLREADING) ?ETO_RTLREADING :0;
  1213. }
  1214. }
  1215. return pitem;
  1216. }
  1217. void Tab_UpdateArrows(PTC ptc, BOOL fSizeChanged)
  1218. {
  1219. RECT rc;
  1220. BOOL fArrow;
  1221. Tab_GetClientRect(ptc, &rc);
  1222. if (IsRectEmpty(&rc))
  1223. return; // Nothing to do yet!
  1224. // See if all of the tabs will fit.
  1225. ptc->cxTabs = rc.right; // Assume can use whole area to paint
  1226. if (Tab_MultiLine(ptc))
  1227. fArrow = FALSE;
  1228. else {
  1229. Tab_CalcPaintMetrics(ptc, NULL);
  1230. fArrow = (ptc->cxItem >= rc.right);
  1231. }
  1232. if (!fArrow)
  1233. {
  1234. NoArrows:
  1235. // Don't need arrows
  1236. if (ptc->hwndArrows)
  1237. {
  1238. ShowWindow(ptc->hwndArrows, SW_HIDE);
  1239. // Bug#94368:: This is overkill should only invalidate portion
  1240. // that may be impacted, like the last displayed item..
  1241. InvalidateRect(ptc->ci.hwnd, NULL, TRUE);
  1242. }
  1243. if (ptc->iFirstVisible > 0)
  1244. {
  1245. Tab_OnHScroll(ptc, NULL, SB_THUMBPOSITION, 0);
  1246. // Bug#94368:: This is overkill should only invalidate portion
  1247. // that may be impacted, like the last displayed item..
  1248. InvalidateRect(ptc->ci.hwnd, NULL, TRUE);
  1249. }
  1250. }
  1251. else
  1252. {
  1253. int cx;
  1254. int cy;
  1255. int iMaxBtnVal;
  1256. int xSum;
  1257. TABITEM * pitem;
  1258. cy = ptc->cxyArrows;
  1259. cx = cy * 2;
  1260. ptc->cxTabs = rc.right - cx; // Make buttons square
  1261. // See how many tabs we have to remove until the last tab becomes
  1262. // fully visible.
  1263. xSum = 0; // Number of pixels in removed tabs
  1264. for (iMaxBtnVal=0; (ptc->cxTabs + xSum) < ptc->cxItem; iMaxBtnVal++)
  1265. {
  1266. pitem = Tab_GetItemPtr(ptc, iMaxBtnVal);
  1267. if (!pitem)
  1268. break;
  1269. xSum += pitem->rc.right - pitem->rc.left;
  1270. }
  1271. // If we removed *all* the tabs, then put the last one back.
  1272. // This happens if the last tab is so huge it doesn't fit into
  1273. // the requisite space no matter how many tabs you remove.
  1274. if (iMaxBtnVal >= Tab_Count(ptc))
  1275. {
  1276. iMaxBtnVal = Tab_Count(ptc) - 1;
  1277. }
  1278. // If we don't need to remove any tabs, then we guessed wrong about
  1279. // arrows. This can happen if there is exactly one tab that doesn't
  1280. // fit in the requisite space. No arrow since there is nothing to
  1281. // scroll to!
  1282. //
  1283. if (iMaxBtnVal <= 0)
  1284. {
  1285. ptc->cxTabs = rc.right; // Can use whole area to paint
  1286. goto NoArrows;
  1287. }
  1288. if (!ptc->hwndArrows) {
  1289. InvalidateRect(ptc->ci.hwnd, NULL, TRUE);
  1290. ptc->hwndArrows = CreateUpDownControl
  1291. (Tab_Vertical(ptc) ? (HDS_VERT | WS_CHILD) : (UDS_HORZ | WS_CHILD), 0, 0, 0, 0,
  1292. ptc->ci.hwnd, 1, HINST_THISDLL, NULL, iMaxBtnVal, 0,
  1293. ptc->iFirstVisible);
  1294. }
  1295. // DebugMsg(DM_TRACE, TEXT("Tabs_UpdateArrows iMax=%d\n\r"), iMaxBtnVal);
  1296. if (ptc->hwndArrows)
  1297. {
  1298. rc.left = rc.right - cx;
  1299. rc.top = ptc->cyTabs - cy;
  1300. rc.bottom = ptc->cyTabs;
  1301. Tab_VDFlipRect(ptc, &rc);
  1302. if (fSizeChanged || !IsWindowVisible(ptc->hwndArrows))
  1303. SetWindowPos(ptc->hwndArrows, NULL,
  1304. rc.left, rc.top, RECTWIDTH(rc), RECTHEIGHT(rc),
  1305. SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW);
  1306. // Make sure the range is set
  1307. SendMessage(ptc->hwndArrows, UDM_SETRANGE, 0,
  1308. MAKELPARAM(iMaxBtnVal, 0));
  1309. }
  1310. }
  1311. }
  1312. int Tab_OnInsertItem(PTC ptc, int iItem, const TC_ITEM* ptci)
  1313. {
  1314. TABITEM* pitem;
  1315. int i;
  1316. pitem = Tab_CreateItem(ptc, ptci);
  1317. if (!pitem)
  1318. return -1;
  1319. i = iItem;
  1320. i = DPA_InsertPtr(ptc->hdpa, i, pitem);
  1321. if (i == -1)
  1322. {
  1323. Tab_FreeItem(ptc, pitem);
  1324. return -1;
  1325. }
  1326. if (ptc->iSel < 0)
  1327. ptc->iSel = i;
  1328. else if (ptc->iSel >= i)
  1329. ptc->iSel++;
  1330. if (ptc->iFirstVisible > i)
  1331. ptc->iFirstVisible++;
  1332. ptc->cxItem = RECOMPUTE; // force recomputing of all tabs
  1333. //Add tab to tooltips.. calculate the rect later
  1334. if(ptc->hwndToolTips) {
  1335. TOOLINFO ti;
  1336. // don't bother setting the rect because we'll do it below
  1337. // in FlushToolTipsMgr;
  1338. ti.cbSize = sizeof(ti);
  1339. ti.uFlags = ptci->mask & TCIF_RTLREADING ?TTF_RTLREADING :0;
  1340. ti.hwnd = ptc->ci.hwnd;
  1341. ti.uId = Tab_Count(ptc) - 1 ;
  1342. ti.lpszText = LPSTR_TEXTCALLBACK;
  1343. SendMessage(ptc->hwndToolTips, TTM_ADDTOOL, 0,
  1344. (LPARAM)(LPTOOLINFO)&ti);
  1345. }
  1346. if (Tab_RedrawEnabled(ptc)) {
  1347. RECT rcInval;
  1348. LPTABITEM pitem;
  1349. if (Tab_DrawButtons(ptc)) {
  1350. if (Tab_FixedWidth(ptc)) {
  1351. Tab_CalcPaintMetrics(ptc, NULL);
  1352. if (i == Tab_Count(ptc) - 1) {
  1353. Tab_InvalidateItem(ptc, i, FALSE);
  1354. } else {
  1355. pitem = Tab_GetItemPtr(ptc, i);
  1356. GetClientRect(ptc->ci.hwnd, &rcInval);
  1357. if (pitem) {
  1358. rcInval.top = pitem->rc.top;
  1359. if (ptc->iLastRow == 0) {
  1360. rcInval.left = pitem->rc.left;
  1361. }
  1362. Tab_UpdateArrows(ptc, FALSE);
  1363. RedrawWindow(ptc->ci.hwnd, &rcInval, NULL, RDW_INVALIDATE |RDW_NOCHILDREN);
  1364. }
  1365. }
  1366. NotifyWinEvent(EVENT_OBJECT_CREATE, ptc->ci.hwnd, OBJID_CLIENT, i+1);
  1367. return i;
  1368. }
  1369. } else {
  1370. // in tab mode Clear the selected item because it may move
  1371. // and it sticks high a bit.
  1372. if (ptc->iSel > i) {
  1373. // update now because invalidate erases
  1374. // and the redraw below doesn't.
  1375. Tab_InvalidateItem(ptc, ptc->iSel, TRUE);
  1376. UpdateWindow(ptc->ci.hwnd);
  1377. }
  1378. }
  1379. RedrawAll(ptc, RDW_INVALIDATE | RDW_NOCHILDREN);
  1380. }
  1381. NotifyWinEvent(EVENT_OBJECT_CREATE, ptc->ci.hwnd, OBJID_CLIENT, i+1);
  1382. return i;
  1383. }
  1384. // Add/remove/replace item
  1385. BOOL Tab_FreeItem(PTC ptc, TABITEM* pitem)
  1386. {
  1387. if (pitem)
  1388. {
  1389. Str_Set(&pitem->pszText, NULL);
  1390. Free(pitem);
  1391. }
  1392. return FALSE;
  1393. }
  1394. void Tab_OnRemoveImage(PTC ptc, int iItem)
  1395. {
  1396. if (ptc->himl && iItem >= 0) {
  1397. int i;
  1398. LPTABITEM pitem;
  1399. ImageList_Remove(ptc->himl, iItem);
  1400. for( i = Tab_Count(ptc)-1 ; i >= 0; i-- ) {
  1401. pitem = Tab_FastGetItemPtr(ptc, i);
  1402. if (pitem->iImage > iItem)
  1403. pitem->iImage--;
  1404. else if (pitem->iImage == iItem) {
  1405. pitem->iImage = -1; // if we now don't draw something, inval
  1406. Tab_InvalidateItem(ptc, i, FALSE);
  1407. }
  1408. }
  1409. }
  1410. }
  1411. BOOL Tab_OnDeleteItem(PTC ptc, int i)
  1412. {
  1413. TABITEM* pitem;
  1414. UINT uRedraw;
  1415. RECT rcInval;
  1416. rcInval.left = -1; // special flag...
  1417. if (i >= Tab_Count(ptc))
  1418. return FALSE;
  1419. NotifyWinEvent(EVENT_OBJECT_DESTROY, ptc->ci.hwnd, OBJID_CLIENT, i+1);
  1420. if (!Tab_DrawButtons(ptc) && (Tab_RedrawEnabled(ptc) || ptc->iSel >= i)) {
  1421. // in tab mode, Clear the selected item because it may move
  1422. // and it sticks high a bit.
  1423. Tab_InvalidateItem(ptc, ptc->iSel, TRUE);
  1424. }
  1425. // if its fixed width, don't need to erase everything, just the last one
  1426. if (Tab_FixedWidth(ptc)) {
  1427. int j;
  1428. uRedraw = RDW_INVALIDATE | RDW_NOCHILDREN;
  1429. j = Tab_Count(ptc) -1;
  1430. Tab_InvalidateItem(ptc, j, TRUE);
  1431. // update optimization
  1432. if (Tab_DrawButtons(ptc)) {
  1433. if (i == Tab_Count(ptc) - 1) {
  1434. rcInval.left = 0;
  1435. uRedraw = 0;
  1436. } else {
  1437. pitem = Tab_GetItemPtr(ptc, i);
  1438. GetClientRect(ptc->ci.hwnd, &rcInval);
  1439. if (pitem) {
  1440. rcInval.top = pitem->rc.top;
  1441. if (ptc->iLastRow == 0) {
  1442. rcInval.left = pitem->rc.left;
  1443. }
  1444. }
  1445. }
  1446. }
  1447. } else {
  1448. uRedraw = RDW_INVALIDATE | RDW_NOCHILDREN | RDW_ERASE;
  1449. }
  1450. pitem = DPA_DeletePtr(ptc->hdpa, i);
  1451. if (!pitem)
  1452. return FALSE;
  1453. Tab_FreeItem(ptc, pitem);
  1454. if (ptc->iSel == i)
  1455. ptc->iSel = -1; // deleted the focus item
  1456. else if (ptc->iSel > i)
  1457. ptc->iSel--; // slide the foucs index down
  1458. // maintain the first visible
  1459. if (ptc->iFirstVisible > i)
  1460. ptc->iFirstVisible--;
  1461. ptc->cxItem = RECOMPUTE; // force recomputing of all tabs
  1462. ptc->iLastTopRow = -1;
  1463. if(ptc->hwndToolTips) {
  1464. TOOLINFO ti;
  1465. ti.cbSize = sizeof(ti);
  1466. ti.hwnd = ptc->ci.hwnd;
  1467. ti.uId = Tab_Count(ptc) ;
  1468. SendMessage(ptc->hwndToolTips, TTM_DELTOOL, 0, (LPARAM)(LPTOOLINFO)&ti);
  1469. }
  1470. if (Tab_RedrawEnabled(ptc)) {
  1471. if (rcInval.left == -1) {
  1472. RedrawAll(ptc, uRedraw);
  1473. } else {
  1474. Tab_UpdateArrows(ptc, FALSE);
  1475. if (uRedraw)
  1476. RedrawWindow(ptc->ci.hwnd, &rcInval, NULL, uRedraw);
  1477. }
  1478. }
  1479. return TRUE;
  1480. }
  1481. BOOL Tab_OnGetItem(PTC ptc, int iItem, TC_ITEM* ptci)
  1482. {
  1483. UINT mask = ptci->mask;
  1484. const TABITEM* pitem = Tab_GetItemPtr(ptc, iItem);
  1485. if (!pitem)
  1486. {
  1487. // NULL init the the tci struct incase there is no pitem.
  1488. // This is incase the dude calling doesn't check the return
  1489. // from this function. Bug # 7105
  1490. if (mask & TCIF_PARAM)
  1491. ptci->lParam = 0;
  1492. else if (mask & TCIF_TEXT)
  1493. ptci->pszText = 0;
  1494. else if (mask & TCIF_IMAGE)
  1495. ptci->iImage = 0;
  1496. return FALSE;
  1497. }
  1498. if (mask & TCIF_TEXT) {
  1499. if (pitem->pszText)
  1500. lstrcpyn(ptci->pszText, pitem->pszText, ptci->cchTextMax);
  1501. else
  1502. ptci->pszText = 0;
  1503. }
  1504. if (mask & TCIF_STATE) {
  1505. ptci->dwState = pitem->dwState & ptci->dwStateMask;
  1506. // REViEW... maybe we should maintain the state in the statemask...
  1507. if (ptci->dwStateMask & TCIS_BUTTONPRESSED) {
  1508. if ((ptc->iSel == iItem) ||
  1509. ((ptc->iNewSel == iItem) && Tab_DrawSunken(ptc))) {
  1510. ptci->dwState |= TCIS_BUTTONPRESSED;
  1511. }
  1512. }
  1513. }
  1514. if ((mask & TCIF_PARAM) && ptc->cbExtra)
  1515. hmemcpy(&ptci->lParam, pitem->DUMMYUNION_MEMBER(abExtra), ptc->cbExtra);
  1516. if (mask & TCIF_IMAGE)
  1517. ptci->iImage = pitem->iImage;
  1518. // TC_ITEM does not have room for querying TCIF_RTLREADING !!
  1519. // it only allows you to set it.
  1520. // This is a hack to return info about tab item reading order
  1521. if((mask & TCIF_RTLREADING) && !(mask & TCIF_TEXT))
  1522. {
  1523. if(pitem->etoRtlReading)
  1524. ptci->cchTextMax = 1;
  1525. }
  1526. return TRUE;
  1527. }
  1528. void Tab_InvalidateItem(PTC ptc, int iItem, BOOL bErase)
  1529. {
  1530. if (iItem != -1) {
  1531. LPTABITEM pitem = Tab_GetItemPtr(ptc, iItem);
  1532. if (pitem) {
  1533. RECT rc = pitem->rc;
  1534. if (rc.right > ptc->cxTabs)
  1535. rc.right = ptc->cxTabs; // don't invalidate past our end
  1536. InflateRect(&rc, g_cxEdge, g_cyEdge);
  1537. if (Tab_FlatButtons(ptc)) {
  1538. rc.right += 2 * g_cxEdge;
  1539. }
  1540. Tab_InvalidateRect(ptc, &rc, bErase);
  1541. }
  1542. }
  1543. }
  1544. BOOL RedrawAll(PTC ptc, UINT uFlags)
  1545. {
  1546. if (ptc && Tab_RedrawEnabled(ptc)) {
  1547. Tab_UpdateArrows(ptc, FALSE);
  1548. RedrawWindow(ptc->ci.hwnd, NULL, NULL, uFlags);
  1549. return TRUE;
  1550. }
  1551. return FALSE;
  1552. }
  1553. int ChangeSel(PTC ptc, int iNewSel, BOOL bSendNotify,
  1554. BOOL bUpdateCursorPos)
  1555. {
  1556. BOOL bErase;
  1557. int iOldSel;
  1558. HWND hwnd;
  1559. SIZE screenDelta;
  1560. RECT rcT;
  1561. if (iNewSel == ptc->iSel)
  1562. return ptc->iSel;
  1563. if (bUpdateCursorPos && Tab_OnGetItemRect(ptc, iNewSel, &rcT))
  1564. {
  1565. screenDelta.cx = rcT.left;
  1566. screenDelta.cy = rcT.top;
  1567. }
  1568. else
  1569. {
  1570. screenDelta.cx = screenDelta.cy = 0;
  1571. bUpdateCursorPos = FALSE;
  1572. }
  1573. hwnd = ptc->ci.hwnd;
  1574. // make sure in range
  1575. if (iNewSel < 0) {
  1576. iOldSel = ptc->iSel;
  1577. ptc->iSel = -1;
  1578. } else if (iNewSel < Tab_Count(ptc)) {
  1579. LPTABITEM pitem = Tab_GetItemPtr(ptc, iNewSel);
  1580. ASSERT(pitem);
  1581. if (!pitem)
  1582. return -1;
  1583. //
  1584. // dont allow a hidden item to get the focus
  1585. //
  1586. // Bug#94368 this is not 100% correct, focus will only
  1587. // work right if hidden items are at the begining
  1588. // or end (user will not be able to arrow past it)
  1589. //
  1590. // currenly this is not a bad restriction
  1591. // only desk.cpl uses this flag, and it
  1592. // always hides the last item.
  1593. //
  1594. // if we make this a general flag we will need to
  1595. // fix this.
  1596. //
  1597. if (pitem->dwState & TCIS_HIDDEN)
  1598. return -1;
  1599. // make sure this is a change that's wanted
  1600. if (bSendNotify)
  1601. {
  1602. // pass NULL for parent because W95 queryied each time and some
  1603. // folks reparent
  1604. if (SendNotifyEx(NULL, hwnd, TCN_SELCHANGING, NULL, ptc->ci.bUnicode))
  1605. return ptc->iSel;
  1606. }
  1607. iOldSel = ptc->iSel;
  1608. ptc->iSel = iNewSel;
  1609. // See if we need to make sure the item is visible
  1610. if (Tab_MultiLine(ptc)) {
  1611. if( !Tab_DrawButtons(ptc) && ptc->iLastRow > 0 && iNewSel != -1) {
  1612. // In multiLineTab Mode bring the row to the bottom.
  1613. PutzRowToBottom(ptc, Tab_FastGetItemPtr(ptc, iNewSel)->iRow);
  1614. }
  1615. } else {
  1616. // In single line mode, slide things over to show selection
  1617. RECT rcClient;
  1618. int xOffset = 0;
  1619. int iNewFirstVisible = 0;
  1620. GetClientRect(ptc->ci.hwnd, &rcClient);
  1621. if (pitem->rc.left < g_cxEdge)
  1622. {
  1623. xOffset = -pitem->rc.left + g_cxEdge; // Offset to get back to zero
  1624. iNewFirstVisible = iNewSel;
  1625. }
  1626. else if ((iNewSel != ptc->iFirstVisible) &&
  1627. (pitem->rc.right > ptc->cxTabs))
  1628. {
  1629. // A little more tricky new to scroll each tab until we
  1630. // fit on the end
  1631. for (iNewFirstVisible = ptc->iFirstVisible;
  1632. iNewFirstVisible < iNewSel;)
  1633. {
  1634. LPTABITEM pitemT = Tab_FastGetItemPtr(ptc, iNewFirstVisible);
  1635. xOffset -= (pitemT->rc.right - pitemT->rc.left);
  1636. iNewFirstVisible++;
  1637. if ((pitem->rc.right + xOffset) < ptc->cxTabs)
  1638. break; // Found our new top index
  1639. }
  1640. // If we end up being the first item shown make sure our left
  1641. // end is showing correctly
  1642. if (iNewFirstVisible == iNewSel)
  1643. xOffset = -pitem->rc.left + g_cxEdge;
  1644. }
  1645. if (xOffset != 0)
  1646. {
  1647. Tab_Scroll(ptc, xOffset, iNewFirstVisible);
  1648. }
  1649. }
  1650. } else
  1651. return -1;
  1652. Tab_DeselectAll(ptc, TRUE);
  1653. // repaint opt: we don't need to erase for buttons because their paint covers all.
  1654. bErase = (!Tab_DrawButtons(ptc) || Tab_FlatButtons(ptc));
  1655. if (bErase)
  1656. UpdateWindow(hwnd);
  1657. Tab_InvalidateItem(ptc, iOldSel, bErase);
  1658. Tab_InvalidateItem(ptc, iNewSel, bErase);
  1659. // mfc4.2 relies upon this update window. they do something that
  1660. // forces the window invalid bit to be false on the TCN_SELCHANGE and
  1661. // thereby making us lose this update window
  1662. UpdateWindow(hwnd);
  1663. if (bUpdateCursorPos && Tab_OnGetItemRect(ptc, iNewSel, &rcT))
  1664. {
  1665. POINT ptCursor;
  1666. screenDelta.cx = rcT.left - screenDelta.cx;
  1667. screenDelta.cy = rcT.top - screenDelta.cy;
  1668. GetCursorPos(&ptCursor);
  1669. SetCursorPos(ptCursor.x + screenDelta.cx, ptCursor.y + screenDelta.cy);
  1670. }
  1671. // if they are buttons, we send the message on mouse up
  1672. if (bSendNotify)
  1673. {
  1674. // pass NULL for parent because W95 queryied each time and some
  1675. // folks reparent
  1676. SendNotifyEx(NULL, hwnd, TCN_SELCHANGE, NULL, ptc->ci.bUnicode);
  1677. }
  1678. NotifyWinEvent(EVENT_OBJECT_SELECTION, hwnd, OBJID_CLIENT, ptc->iSel+1);
  1679. // We might've been destroyed during the notify, but GetFocus
  1680. // couldn't possibly return our hwnd in that case, so we're still safe.
  1681. if (GetFocus() == hwnd)
  1682. NotifyWinEvent(EVENT_OBJECT_FOCUS, hwnd, OBJID_CLIENT, ptc->iSel+1);
  1683. return iOldSel;
  1684. }
  1685. // Tab_CalcTabHeight is theme aware
  1686. void Tab_CalcTabHeight(PTC ptc, HDC hdc)
  1687. {
  1688. BOOL bReleaseDC = FALSE;
  1689. if (ptc->cyTabs == RECOMPUTE) {
  1690. TEXTMETRIC tm;
  1691. int iYExtra;
  1692. int cx = 0;
  1693. int cy = 0;
  1694. ZeroMemory(&tm, sizeof(TEXTMETRIC));
  1695. if (!hdc)
  1696. {
  1697. bReleaseDC = TRUE;
  1698. hdc = GetDC(NULL);
  1699. SelectObject(hdc, ptc->hfontLabel);
  1700. }
  1701. // Get metircs on theme font
  1702. if (ptc->hTheme)
  1703. {
  1704. GetThemeTextMetrics(ptc->hTheme, hdc, ptc->iPartId, ptc->iStateId, &tm);
  1705. }
  1706. else
  1707. {
  1708. GetTextMetrics(hdc, &tm);
  1709. }
  1710. if (!ptc->fMinTabSet) {
  1711. ptc->cxMinTab = tm.tmAveCharWidth * 6 + ptc->cxPad * 2;
  1712. }
  1713. ptc->cxyArrows = tm.tmHeight + 2 * g_cyEdge;
  1714. if (ptc->himl)
  1715. Tab_ImageList_GetIconSize(ptc, &cx, &cy);
  1716. if (ptc->iTabHeight) {
  1717. ptc->cyTabs = ptc->iTabHeight;
  1718. if (Tab_DrawButtons(ptc))
  1719. iYExtra = 3 * g_cyEdge; // (for the top edge, button edge and room to drop down)
  1720. else
  1721. iYExtra = 2 * g_cyEdge - 1;
  1722. } else {
  1723. // the height is the max of image or label plus padding.
  1724. // where padding is 2*cypad-edge but at lease an edges
  1725. iYExtra = ptc->cyPad*2;
  1726. if (iYExtra < 2*g_cyEdge)
  1727. iYExtra = 2*g_cyEdge;
  1728. if (!Tab_DrawButtons(ptc))
  1729. iYExtra -= (1 + g_cyEdge);
  1730. // add an edge to the font height because we want a bit of
  1731. // space under the text
  1732. ptc->cyTabs = max(tm.tmHeight + g_cyEdge, cy) + iYExtra;
  1733. }
  1734. ptc->tmHeight = tm.tmHeight;
  1735. // add one so that if it's odd, we'll round up.
  1736. ptc->cyText = (ptc->cyTabs - iYExtra - tm.tmHeight + 1) / 2;
  1737. ptc->cyIcon = (ptc->cyTabs - iYExtra - cy) / 2;
  1738. if (bReleaseDC)
  1739. {
  1740. ReleaseDC(NULL, hdc);
  1741. }
  1742. }
  1743. }
  1744. void UpdateToolTipRects(PTC ptc)
  1745. {
  1746. if(ptc->hwndToolTips) {
  1747. int i;
  1748. TOOLINFO ti;
  1749. int iMax;
  1750. LPTABITEM pitem;
  1751. ti.cbSize = sizeof(ti);
  1752. ti.uFlags = 0;
  1753. ti.hwnd = ptc->ci.hwnd;
  1754. ti.lpszText = LPSTR_TEXTCALLBACK;
  1755. for ( i = 0, iMax = Tab_Count(ptc); i < iMax; i++) {
  1756. pitem = Tab_FastGetItemPtr(ptc, i);
  1757. ti.uId = i;
  1758. ti.rect = pitem->rc;
  1759. Tab_VDFlipRect(ptc, &ti.rect);
  1760. SendMessage(ptc->hwndToolTips, TTM_NEWTOOLRECT, 0, (LPARAM)((LPTOOLINFO)&ti));
  1761. }
  1762. }
  1763. }
  1764. // Tab_GetTextExtentPoint is theme aware
  1765. void Tab_GetTextExtentPoint(PTC ptc, HDC hdc, LPTSTR lpszText, int iCount, LPSIZE lpsize)
  1766. {
  1767. TCHAR szBuffer[128];
  1768. if (iCount < ARRAYSIZE(szBuffer) && !Tab_Vertical(ptc)) {
  1769. StripAccelerators(lpszText, szBuffer, TRUE);
  1770. lpszText = szBuffer;
  1771. iCount = lstrlen(lpszText);
  1772. }
  1773. if (ptc->hTheme)
  1774. {
  1775. RECT rc = { 0 };
  1776. GetThemeTextExtent(ptc->hTheme, hdc, ptc->iPartId, ptc->iStateId, lpszText, iCount, 0, &rc, &rc);
  1777. lpsize->cx = RECTWIDTH(rc);
  1778. lpsize->cy = RECTHEIGHT(rc);
  1779. }
  1780. else
  1781. {
  1782. GetTextExtentPoint(hdc, lpszText, iCount, lpsize);
  1783. }
  1784. }
  1785. void Tab_InvertRows(PTC ptc)
  1786. {
  1787. int i;
  1788. int yTop = g_cyEdge;
  1789. int yNew;
  1790. int iNewRow;
  1791. // we want the first item to be on the bottom.
  1792. for (i = Tab_Count(ptc) - 1; i >= 0; i--) {
  1793. LPTABITEM pitem = Tab_FastGetItemPtr(ptc, i);
  1794. iNewRow = ptc->iLastRow - pitem->iRow;
  1795. yNew = yTop + iNewRow * ptc->cyTabs;
  1796. pitem->iRow = iNewRow;
  1797. OffsetRect(&pitem->rc, 0, yNew - pitem->rc.top);
  1798. }
  1799. }
  1800. // Tab_CalcPaintMetrics is theme aware
  1801. void Tab_CalcPaintMetrics(PTC ptc, HDC hdc)
  1802. {
  1803. SIZE siz;
  1804. LPTABITEM pitem;
  1805. int i, x, y;
  1806. int xStart;
  1807. int iRow = 0;
  1808. int cItems = Tab_Count(ptc);
  1809. BOOL bReleaseDC = FALSE;
  1810. if (ptc->cxItem == RECOMPUTE) {
  1811. // if the font hasn't been created yet, let's do it now
  1812. if (!ptc->hfontLabel)
  1813. Tab_OnSetFont(ptc, NULL, FALSE);
  1814. if (!hdc)
  1815. {
  1816. bReleaseDC = TRUE;
  1817. hdc = GetDC(NULL);
  1818. SelectObject(hdc, ptc->hfontLabel);
  1819. }
  1820. Tab_CalcTabHeight(ptc, hdc);
  1821. if (Tab_DrawButtons(ptc)) {
  1822. // start at the edge;
  1823. xStart = 0;
  1824. y = 0;
  1825. } else {
  1826. xStart = g_cxEdge;
  1827. y = g_cyEdge;
  1828. }
  1829. x = xStart;
  1830. for (i = 0; i < cItems; i++) {
  1831. int cxImage = 0;
  1832. int cy = 0;
  1833. int cxBounds = 0;
  1834. pitem = Tab_FastGetItemPtr(ptc, i);
  1835. if (pitem->pszText) {
  1836. Tab_GetTextExtentPoint(ptc, hdc, pitem->pszText, lstrlen(pitem->pszText), &siz);
  1837. } else {
  1838. siz.cx = 0;
  1839. siz.cy = 0;
  1840. }
  1841. pitem->cxLabel = siz.cx;
  1842. // if there's an image, count that too
  1843. if (HASIMAGE(ptc, pitem)) {
  1844. Tab_ImageList_GetIconSize(ptc, &cxImage, &cy);
  1845. cxImage += ptc->cxPad;
  1846. siz.cx += cxImage;
  1847. }
  1848. // If a theme is in use, inflate rect to accomidate full theme background (including margins)
  1849. if (ptc->hTheme)
  1850. {
  1851. RECT rc = { 0, 0, siz.cx, siz.cy }; // Current content size
  1852. GetThemeBackgroundExtent(ptc->hTheme, hdc, ptc->iPartId, ptc->iStateId, &rc, &rc);
  1853. siz.cx = rc.right - rc.left;
  1854. siz.cy = rc.bottom - rc.top;
  1855. }
  1856. cxBounds = siz.cx;
  1857. if (Tab_FixedWidth(ptc)) {
  1858. siz.cx = ptc->iTabWidth;
  1859. } else {
  1860. siz.cx += ptc->cxPad * 2;
  1861. // Make sure the tab has a least a minimum width
  1862. if (siz.cx < ptc->cxMinTab)
  1863. siz.cx = ptc->cxMinTab;
  1864. }
  1865. // handle hidden items
  1866. if (pitem->dwState & TCIS_HIDDEN) {
  1867. siz.cx = 0;
  1868. siz.cy = 0;
  1869. }
  1870. // should we wrap?
  1871. if (Tab_MultiLine(ptc)) {
  1872. // two cases to wrap around:
  1873. // case 2: is our right edge past the end but we ourselves
  1874. // are shorter than the width?
  1875. // case 1: are we already past the end? (this happens if
  1876. // the previous line had only one item and it was longer
  1877. // than the tab's width.
  1878. int iTotalWidth = ptc->cxTabs - g_cxEdge;
  1879. if (x > iTotalWidth ||
  1880. (x+siz.cx >= iTotalWidth &&
  1881. (siz.cx < iTotalWidth))) {
  1882. x = xStart;
  1883. y += ptc->cyTabs;
  1884. iRow++;
  1885. if (Tab_DrawButtons(ptc))
  1886. y += ((g_cyEdge * 3)/2);
  1887. }
  1888. pitem->iRow = iRow;
  1889. }
  1890. pitem->rc.left = x;
  1891. pitem->rc.right = x + siz.cx;
  1892. pitem->rc.top = y;
  1893. pitem->rc.bottom = ptc->cyTabs + y;
  1894. if (!Tab_FixedWidth(ptc) || Tab_ForceLabelLeft(ptc) ||
  1895. Tab_ForceIconLeft(ptc)) {
  1896. pitem->xImage = ptc->cxPad;
  1897. } else {
  1898. // in fixed width mode center it
  1899. pitem->xImage = (siz.cx - cxBounds)/2;
  1900. }
  1901. if (pitem->xImage < g_cxEdge)
  1902. pitem->xImage = g_cxEdge;
  1903. if (Tab_ForceIconLeft(ptc)) {
  1904. // Center the text in the space remaining after the icon
  1905. // The math here gets kind of crazy so I'm going to draw
  1906. // a picture.
  1907. //
  1908. // xImage
  1909. // |
  1910. // ->| |<- cxImage
  1911. // +-----------------------------------------------+
  1912. // | @@@ text text text |
  1913. // | @@@ |
  1914. // +-----------------------------------------------+
  1915. // |<----------------- siz.cx -------------------->|
  1916. // |<-magic->|<--cxLabel--->|
  1917. // xLabel
  1918. //
  1919. // Therefore,
  1920. //
  1921. // remaining space = siz.cx - cxImage - xImage - cxLabel.
  1922. // magic = remaining space / 2
  1923. // xLabel = xImage + cxImage + magic.
  1924. //
  1925. int cxImageTotal = pitem->xImage + cxImage;
  1926. int cxRemaining = siz.cx - cxImageTotal - pitem->cxLabel;
  1927. int cxMagic = cxRemaining / 2;
  1928. pitem->xLabel = cxImageTotal + cxMagic;
  1929. } else {
  1930. // Place the text immediately after the icon
  1931. pitem->xLabel = pitem->xImage + cxImage;
  1932. }
  1933. pitem->yImage = ptc->cyPad + ptc->cyIcon - (g_cyEdge/2);
  1934. pitem->yLabel = ptc->cyPad + ptc->cyText - (g_cyEdge/2);
  1935. x = pitem->rc.right;
  1936. if (Tab_DrawButtons(ptc))
  1937. x += Tab_InterButtonGap(ptc);
  1938. }
  1939. ptc->cxItem = x; // total width of all tabs
  1940. // if we added a line in non-button mode, we need to do a full refresh
  1941. if (ptc->iLastRow != -1 &&
  1942. ptc->iLastRow != iRow &&
  1943. !Tab_DrawButtons(ptc)) {
  1944. InvalidateRect(ptc->ci.hwnd, NULL, TRUE);
  1945. }
  1946. ptc->iLastRow = (cItems > 0) ? iRow : -1;
  1947. if (Tab_MultiLine(ptc)) {
  1948. if (!Tab_RaggedRight(ptc) && !Tab_FixedWidth(ptc))
  1949. RightJustify(ptc);
  1950. if (Tab_ScrollOpposite(ptc)) {
  1951. Tab_InvertRows(ptc);
  1952. // if we have no selection, then the last row is the last top row
  1953. if (ptc->iSel == -1)
  1954. ptc->iLastTopRow = ptc->iLastRow;
  1955. }
  1956. if (!Tab_DrawButtons(ptc) && ptc->iSel != -1) {
  1957. ptc->iLastTopRow = -1;
  1958. PutzRowToBottom(ptc, Tab_FastGetItemPtr(ptc, ptc->iSel)->iRow);
  1959. }
  1960. } else if ( cItems > 0) {
  1961. // adjust x's to the first visible
  1962. int dx;
  1963. pitem = Tab_GetItemPtr(ptc, ptc->iFirstVisible);
  1964. if (pitem) {
  1965. dx = -pitem->rc.left + g_cxEdge;
  1966. for ( i = cItems - 1; i >=0 ; i--) {
  1967. pitem = Tab_FastGetItemPtr(ptc, i);
  1968. OffsetRect(&pitem->rc, dx, 0);
  1969. }
  1970. }
  1971. }
  1972. if (bReleaseDC)
  1973. {
  1974. ReleaseDC(NULL, hdc);
  1975. }
  1976. UpdateToolTipRects(ptc);
  1977. }
  1978. }
  1979. // Tab_DoCorners is theme aware
  1980. void Tab_DoCorners(HDC hdc, LPRECT prc, PTC ptc, BOOL fBottom)
  1981. {
  1982. RECT rc;
  1983. COLORREF iOldColor;
  1984. // Ignore for themes
  1985. if (!ptc->hTheme)
  1986. {
  1987. iOldColor = SetBkColor(hdc, g_clrBtnFace);
  1988. if (fBottom) {
  1989. // lower right;
  1990. rc = *prc;
  1991. rc.left = rc.right - 2;
  1992. rc.top = rc.bottom - 3;
  1993. Tab_ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL, ptc);
  1994. rc.bottom--;
  1995. Tab_DrawEdge(hdc, &rc, EDGE_RAISED, BF_SOFT | BF_DIAGONAL_ENDBOTTOMLEFT, ptc);
  1996. // lower left
  1997. rc = *prc;
  1998. rc.right = rc.left + 2;
  1999. rc.top = rc.bottom - 3;
  2000. Tab_ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL, ptc);
  2001. rc.bottom--;
  2002. Tab_DrawEdge(hdc, &rc, EDGE_RAISED, BF_SOFT | BF_DIAGONAL_ENDTOPLEFT, ptc);
  2003. } else {
  2004. // upper right
  2005. rc = *prc;
  2006. rc.left = rc.right - 2;
  2007. rc.bottom = rc.top + 3;
  2008. Tab_ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL, ptc);
  2009. rc.top++;
  2010. Tab_DrawEdge(hdc, &rc, EDGE_RAISED, BF_SOFT | BF_DIAGONAL_ENDBOTTOMRIGHT, ptc);
  2011. // upper left
  2012. rc = *prc;
  2013. rc.right = rc.left + 2;
  2014. rc.bottom = rc.top + 3;
  2015. Tab_ExtTextOut(hdc, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL, ptc);
  2016. rc.top++;
  2017. Tab_DrawEdge(hdc, &rc, EDGE_RAISED, BF_SOFT | BF_DIAGONAL_ENDTOPRIGHT, ptc);
  2018. }
  2019. }
  2020. }
  2021. void RefreshArrows(PTC ptc, HDC hdc)
  2022. {
  2023. RECT rcClip, rcArrows, rcIntersect;
  2024. if (ptc->hwndArrows && IsWindowVisible(ptc->hwndArrows)) {
  2025. GetClipBox(hdc, &rcClip);
  2026. GetWindowRect(ptc->hwndArrows, &rcArrows);
  2027. MapWindowRect(NULL, ptc->ci.hwnd, &rcArrows);
  2028. if (IntersectRect(&rcIntersect, &rcClip, &rcArrows))
  2029. RedrawWindow(ptc->hwndArrows, NULL, NULL, RDW_INVALIDATE);
  2030. }
  2031. }
  2032. // Tab_DrawBody is theme aware
  2033. void Tab_DrawBody(HDC hdc, PTC ptc, LPTABITEM pitem, LPRECT lprc, int i,
  2034. BOOL fTransparent, int dx, int dy)
  2035. {
  2036. BOOL fSelected = (i == ptc->iSel);
  2037. if (i == ptc->iHot)
  2038. {
  2039. if ( !Tab_FlatButtons(ptc) )
  2040. {
  2041. SetTextColor(hdc, GetSysColor(COLOR_HOTLIGHT));
  2042. }
  2043. }
  2044. if (Tab_OwnerDraw(ptc))
  2045. {
  2046. DRAWITEMSTRUCT dis;
  2047. WORD wID = (WORD) GetWindowID(ptc->ci.hwnd);
  2048. dis.CtlType = ODT_TAB;
  2049. dis.CtlID = wID;
  2050. dis.itemID = i;
  2051. dis.itemAction = ODA_DRAWENTIRE;
  2052. if (fSelected)
  2053. dis.itemState = ODS_SELECTED;
  2054. else
  2055. dis.itemState = 0;
  2056. dis.hwndItem = ptc->ci.hwnd;
  2057. dis.hDC = hdc;
  2058. dis.rcItem = *lprc;
  2059. Tab_VDFlipRect(ptc, &dis.rcItem);
  2060. dis.itemData =
  2061. (ptc->cbExtra <= sizeof(LPARAM)) ?
  2062. (DWORD)pitem->DUMMYUNION_MEMBER(lParam) : (ULONG_PTR)(LPBYTE)&pitem->DUMMYUNION_MEMBER(abExtra);
  2063. SendMessage( ptc->ci.hwndParent , WM_DRAWITEM, wID,
  2064. (LPARAM)(DRAWITEMSTRUCT *)&dis);
  2065. }
  2066. else
  2067. {
  2068. // draw the text and image
  2069. // draw even if pszText == NULL to blank it out
  2070. int xLabel;
  2071. int xIcon;
  2072. BOOL fUseDrawText = FALSE;
  2073. if (pitem->pszText)
  2074. {
  2075. // only use draw text if there's any underlining to do.
  2076. // Draw text does not support vertical drawing, so only do this in horz mode
  2077. if (!Tab_Vertical(ptc) &&
  2078. StrChr(pitem->pszText, CH_PREFIX))
  2079. {
  2080. fUseDrawText = TRUE;
  2081. }
  2082. }
  2083. // DrawTextEx will not clear the entire area, so we need to.
  2084. // or if there's no text, we need to blank it out
  2085. if ((fUseDrawText || !pitem->pszText) && !fTransparent)
  2086. Tab_ExtTextOut(hdc, 0, 0,
  2087. ETO_OPAQUE, lprc, NULL, 0, NULL, ptc);
  2088. xLabel = pitem->rc.left + pitem->xLabel + dx;
  2089. xIcon = pitem->rc.left + pitem->xImage + dx;
  2090. if (pitem->pszText)
  2091. {
  2092. int xVertOffset = 0;
  2093. int yOffset = 0;
  2094. int oldMode;
  2095. COLORREF oldBkColor;
  2096. COLORREF oldTextColor;
  2097. TEXTMETRIC tm;
  2098. GetTextMetrics(hdc, &tm);
  2099. if (tm.tmInternalLeading == 0)
  2100. yOffset = 1;
  2101. if (Tab_Vertical(ptc) && !Tab_Bottom(ptc))
  2102. {
  2103. // add this offset because we need to draw from the bottom up
  2104. xLabel += pitem->cxLabel;
  2105. // if we're drawing vertically (on the left)
  2106. // the icon needs to go below (flipped coordinate, on the right)
  2107. if (HASIMAGE(ptc, pitem))
  2108. {
  2109. int cxIcon = 0;
  2110. int cyIcon = 0;
  2111. int xLabelNew;
  2112. Tab_ImageList_GetIconSize(ptc, &cxIcon, &cyIcon);
  2113. xLabelNew = xIcon + pitem->cxLabel;
  2114. xIcon = xLabel - cxIcon;
  2115. xLabel = xLabelNew;
  2116. }
  2117. }
  2118. if (pitem->dwState & TCIS_HIGHLIGHTED)
  2119. {
  2120. oldMode = SetBkMode (hdc, OPAQUE);
  2121. oldBkColor = SetBkColor (hdc, g_clrHighlight);
  2122. oldTextColor = SetTextColor (hdc, g_clrHighlightText);
  2123. }
  2124. if (fUseDrawText)
  2125. {
  2126. DRAWTEXTPARAMS dtp;
  2127. int topPrev;
  2128. dtp.cbSize = sizeof(DRAWTEXTPARAMS);
  2129. dtp.iLeftMargin = xLabel - lprc->left;
  2130. dtp.iRightMargin = 0;
  2131. // There is no dtp.iTopMargin so we have to adjust the
  2132. // rectangle instead. The opaqueing has already been done,
  2133. // so isn't not a problem if we "miss" some pixels since
  2134. // they've already been erased.
  2135. topPrev = lprc->top;
  2136. lprc->top = pitem->rc.top + pitem->yLabel + dy + yOffset;
  2137. Tab_DrawTextEx(hdc, pitem->pszText, -1, lprc, DT_SINGLELINE | DT_TOP, &dtp, ptc);
  2138. // Undo our changes to lprc before anybody (else) notices.
  2139. lprc->top = topPrev;
  2140. }
  2141. else
  2142. {
  2143. UINT uETOFlags = (ETO_CLIPPED | pitem->etoRtlReading | (ptc->ci.dwExStyle & WS_EX_RTLREADING ? ETO_RTLREADING : 0 ));
  2144. if (!fTransparent || (pitem->dwState & TCIS_HIGHLIGHTED))
  2145. uETOFlags |= ETO_OPAQUE;
  2146. Tab_ExtTextOut(hdc, xLabel, pitem->rc.top + pitem->yLabel + dy + yOffset,
  2147. uETOFlags, lprc, pitem->pszText, lstrlen(pitem->pszText),
  2148. NULL, ptc);
  2149. }
  2150. if (pitem->dwState & TCIS_HIGHLIGHTED)
  2151. {
  2152. SetBkMode(hdc, oldMode);
  2153. SetBkColor (hdc, oldBkColor);
  2154. SetTextColor (hdc, oldTextColor);
  2155. }
  2156. }
  2157. if (HASIMAGE(ptc, pitem))
  2158. {
  2159. UINT uFlags = fTransparent ? ILD_TRANSPARENT : ILD_NORMAL;
  2160. if (pitem->dwState & TCIS_HIGHLIGHTED)
  2161. uFlags |= ILD_BLEND50;
  2162. Tab_ImageList_Draw(ptc, pitem->iImage, hdc, xIcon,
  2163. pitem->rc.top + pitem->yImage + dy, uFlags);
  2164. }
  2165. }
  2166. if (i == ptc->iHot)
  2167. {
  2168. if ( !Tab_FlatButtons(ptc) )
  2169. {
  2170. SetTextColor(hdc, g_clrBtnText);
  2171. }
  2172. }
  2173. }
  2174. // Tab_DrawItemFrame is theme aware
  2175. void Tab_DrawItemFrame(PTC ptc, HDC hdc, UINT edgeType, LPTABITEM pitem, int i)
  2176. {
  2177. UINT uWhichEdges;
  2178. BOOL fBottom = FALSE;
  2179. if (Tab_DrawButtons(ptc))
  2180. {
  2181. if (Tab_FlatButtons(ptc))
  2182. {
  2183. if ((edgeType == EDGE_SUNKEN) ||
  2184. (edgeType == BDR_RAISEDINNER))
  2185. {
  2186. uWhichEdges = BF_RECT;
  2187. }
  2188. else
  2189. {
  2190. if ((ptc->ci.style & TCS_HOTTRACK) &&
  2191. (i == ptc->iHot))
  2192. {
  2193. edgeType = BDR_RAISEDINNER;
  2194. uWhichEdges = BF_RECT;
  2195. }
  2196. else
  2197. {
  2198. HPEN hPen, hOldPen;
  2199. RECT rcEdge;
  2200. // Ignore for themes
  2201. if (!ptc->hTheme)
  2202. {
  2203. CopyRect (&rcEdge, &pitem->rc);
  2204. //InflateRect (&rcEdge, -g_cxEdge, -g_cyEdge);
  2205. hPen = CreatePen (PS_SOLID, 2 * g_cyEdge, GetSysColor(COLOR_3DFACE));
  2206. hOldPen = SelectObject (hdc, hPen);
  2207. //
  2208. // Remove any border in the x direction
  2209. //
  2210. MoveToEx (hdc, rcEdge.left, rcEdge.top, NULL);
  2211. LineTo (hdc, rcEdge.right, rcEdge.top);
  2212. MoveToEx (hdc, rcEdge.left, rcEdge.bottom, NULL);
  2213. LineTo (hdc, rcEdge.right, rcEdge.bottom);
  2214. SelectObject (hdc, hOldPen);
  2215. DeleteObject (hPen);
  2216. //
  2217. // Remove any border in the y direction
  2218. //
  2219. hPen = CreatePen (PS_SOLID, 2 * g_cxEdge, GetSysColor(COLOR_3DFACE));
  2220. hOldPen = SelectObject (hdc, hPen);
  2221. MoveToEx (hdc, rcEdge.left, rcEdge.top, NULL);
  2222. LineTo (hdc, rcEdge.left, rcEdge.bottom);
  2223. MoveToEx (hdc, rcEdge.right, rcEdge.top, NULL);
  2224. LineTo (hdc, rcEdge.right, rcEdge.bottom);
  2225. SelectObject (hdc, hOldPen);
  2226. DeleteObject (hPen);
  2227. }
  2228. goto DrawCorners;
  2229. }
  2230. }
  2231. }
  2232. else
  2233. {
  2234. uWhichEdges = BF_RECT | BF_SOFT;
  2235. }
  2236. }
  2237. else
  2238. {
  2239. uWhichEdges = BF_LEFT | BF_TOP | BF_RIGHT | BF_SOFT;
  2240. if (Tab_ScrollOpposite(ptc))
  2241. {
  2242. ASSERT(ptc->iLastTopRow != -1);
  2243. if (Tab_IsItemOnBottom(ptc, pitem))
  2244. {
  2245. fBottom = TRUE;
  2246. uWhichEdges = BF_LEFT | BF_BOTTOM | BF_RIGHT | BF_SOFT;
  2247. }
  2248. }
  2249. }
  2250. Tab_DrawEdge(hdc, &pitem->rc, edgeType, uWhichEdges, ptc);
  2251. DrawCorners:
  2252. if (!Tab_DrawButtons(ptc))
  2253. {
  2254. Tab_DoCorners(hdc, &pitem->rc, ptc, fBottom);
  2255. }
  2256. else
  2257. {
  2258. if (Tab_FlatButtons(ptc) && Tab_FlatSeparators(ptc))
  2259. {
  2260. RECT rcEdge;
  2261. // Ignore in themes
  2262. if (!ptc->hTheme)
  2263. {
  2264. CopyRect (&rcEdge, &pitem->rc);
  2265. rcEdge.right += (3 * g_cxEdge);
  2266. DrawEdge(hdc, &rcEdge, EDGE_ETCHED, BF_RIGHT);
  2267. }
  2268. }
  2269. }
  2270. }
  2271. // Tab_Paint is theme aware (iPartId and iStateId are only set here)
  2272. void Tab_Paint(PTC ptc, HDC hdcIn)
  2273. {
  2274. PAINTSTRUCT ps;
  2275. HDC hdc;
  2276. RECT rcClient, rcClipBox, rcTest, rcBody;
  2277. int cItems, i;
  2278. int fnNewMode = OPAQUE;
  2279. LPTABITEM pitem;
  2280. HWND hwnd = ptc->ci.hwnd;
  2281. HBRUSH hbrOld = NULL;
  2282. // Calling methods that render themes, setup state (TAB/BUTTON)
  2283. if (ptc->hTheme)
  2284. {
  2285. ptc->iPartId = TABP_TABITEM;
  2286. ptc->iStateId = TIS_NORMAL;
  2287. }
  2288. GetClientRect(hwnd, &rcClient);
  2289. if (!rcClient.right)
  2290. return;
  2291. if (hdcIn)
  2292. {
  2293. hdc = hdcIn;
  2294. ps.rcPaint = rcClient;
  2295. }
  2296. else
  2297. {
  2298. hdc = BeginPaint(hwnd, &ps);
  2299. }
  2300. // Fill background if themes are in use, WM_ERASEBKGND will be overridden to do nothing in this case
  2301. if (ptc->hTheme)
  2302. {
  2303. if (CCSendPrint(&ptc->ci, hdc) == FALSE)
  2304. {
  2305. FillRect(hdc, &rcClient, g_hbrBtnFace);
  2306. }
  2307. }
  2308. // select font first so metrics will have the right size
  2309. if (!ptc->hfontLabel)
  2310. Tab_OnSetFont(ptc, NULL, FALSE);
  2311. SelectObject(hdc, ptc->hfontLabel);
  2312. Tab_CalcPaintMetrics(ptc, hdc);
  2313. // now put it in our native orientation if it was vertical
  2314. Tab_DFlipRect(ptc, &rcClient);
  2315. Tab_OnAdjustRect(ptc, FALSE, &rcClient);
  2316. InflateRect(&rcClient, g_cxEdge * 2, g_cyEdge * 2);
  2317. rcClient.top += g_cyEdge;
  2318. // Draw pane (if applicable)
  2319. if(!Tab_DrawButtons(ptc))
  2320. {
  2321. DebugMsg(DM_TRACE, TEXT("Drawing at %d %d %d %d"), rcClient.left, rcClient.top, rcClient.right, rcClient.bottom);
  2322. // Calling a method that render themes, setup state (PANE)
  2323. if (ptc->hTheme)
  2324. {
  2325. ptc->iPartId = TABP_PANE;
  2326. ptc->iStateId = 0;
  2327. }
  2328. Tab_DrawEdge(hdc, &rcClient, EDGE_RAISED, BF_SOFT | BF_RECT, ptc);
  2329. }
  2330. // Draw tab items
  2331. // Calling methods that render themes, setup state (TAB/BUTTON)
  2332. if (ptc->hTheme)
  2333. {
  2334. ptc->iPartId = TABP_TABITEM;
  2335. ptc->iStateId = TIS_NORMAL;
  2336. }
  2337. cItems = Tab_Count(ptc);
  2338. if (cItems)
  2339. {
  2340. RefreshArrows(ptc, hdc);
  2341. SetBkColor(hdc, g_clrBtnFace);
  2342. SetTextColor(hdc, g_clrBtnText);
  2343. if (!Tab_MultiLine(ptc))
  2344. IntersectClipRect(hdc, 0, 0,
  2345. ptc->cxTabs, rcClient.bottom);
  2346. GetClipBox(hdc, &rcClipBox);
  2347. Tab_DVFlipRect(ptc, &rcClipBox);
  2348. // draw all but the selected item
  2349. for (i = ptc->iFirstVisible; i < cItems; i++)
  2350. {
  2351. // Calling methods that render themes, setup state (TAB/BUTTON, HOT state)
  2352. if (ptc->hTheme)
  2353. {
  2354. ptc->iStateId = (i == ptc->iHot) ? TIS_HOT : TIS_NORMAL;
  2355. }
  2356. pitem = Tab_FastGetItemPtr(ptc, i);
  2357. if (pitem->dwState & TCIS_HIDDEN)
  2358. continue;
  2359. if (!Tab_MultiLine(ptc))
  2360. {
  2361. // if not multiline, and we're off the screen... we're done
  2362. if (pitem->rc.left > ptc->cxTabs)
  2363. break;
  2364. }
  2365. // should we bother drawing this?
  2366. if (i != ptc->iSel || Tab_DrawButtons(ptc))
  2367. {
  2368. if (IntersectRect(&rcTest, &rcClipBox, &pitem->rc))
  2369. {
  2370. int dx = 0, dy = 0; // shift variables if button sunken;
  2371. UINT edgeType;
  2372. rcBody = pitem->rc;
  2373. // Draw the edge around each item
  2374. if(Tab_DrawButtons(ptc) &&
  2375. ((ptc->iNewSel == i && Tab_DrawSunken(ptc)) ||
  2376. (ptc->iSel == i) ||
  2377. (pitem->dwState & TCIS_BUTTONPRESSED)))
  2378. {
  2379. dx = g_cxEdge/2;
  2380. dy = g_cyEdge/2;
  2381. if (Tab_FlatButtons(ptc) &&
  2382. (ptc->iNewSel == i && Tab_DrawSunken(ptc)))
  2383. {
  2384. edgeType = BDR_RAISEDINNER;
  2385. }
  2386. else
  2387. {
  2388. edgeType = EDGE_SUNKEN;
  2389. }
  2390. }
  2391. else
  2392. {
  2393. edgeType = EDGE_RAISED;
  2394. }
  2395. if (Tab_DrawButtons(ptc) && !Tab_OwnerDraw(ptc))
  2396. {
  2397. // if drawing buttons, show selected by dithering background
  2398. // which means we need to draw transparent.
  2399. if (ptc->iSel == i)
  2400. {
  2401. // Calling methods that render themes, setup state (BUTTON, SELECTED state)
  2402. if (ptc->hTheme)
  2403. {
  2404. ptc->iStateId = TIS_SELECTED;
  2405. }
  2406. fnNewMode = TRANSPARENT;
  2407. SetBkMode(hdc, TRANSPARENT);
  2408. hbrOld = SelectObject(hdc, g_hbrMonoDither);
  2409. SetTextColor(hdc, g_clrBtnHighlight);
  2410. Tab_PatBlt(hdc, pitem->rc.left, pitem->rc.top, pitem->rc.right - pitem->rc.left,
  2411. pitem->rc.bottom - pitem->rc.top, PATCOPY, ptc);
  2412. SetTextColor(hdc, g_clrBtnText);
  2413. // Calling methods that render themes, setup state (TAB/BUTTON, HOT state)
  2414. if (ptc->hTheme)
  2415. {
  2416. ptc->iStateId = (i == ptc->iHot) ? TIS_HOT : TIS_NORMAL;
  2417. }
  2418. }
  2419. }
  2420. InflateRect(&rcBody, -g_cxEdge, -g_cyEdge);
  2421. if (!Tab_DrawButtons(ptc))
  2422. {
  2423. // move the bottom (or top) by an edge to draw where the tab doesn't have an edge.
  2424. // by doing this, we fill the entire area and don't need to do as many inval with erase
  2425. if (Tab_IsItemOnBottom(ptc, pitem))
  2426. {
  2427. rcBody.top -= g_cyEdge;
  2428. }
  2429. else
  2430. {
  2431. rcBody.bottom += g_cyEdge;
  2432. }
  2433. }
  2434. // Draw background and content (for all items expect selected tab-style item)
  2435. if (ptc->hTheme)
  2436. {
  2437. RECT rcc;
  2438. GetClientRect(ptc->ci.hwnd, &rcc);
  2439. // Determine what part is currently being rendered
  2440. ptc->iPartId = TABP_TABITEM;
  2441. if (pitem->rc.left == g_cxEdge)
  2442. ptc->iPartId = TABP_TABITEMLEFTEDGE;
  2443. // Ick: Aaron wants "slop" for determining the right tab edge.
  2444. if ((pitem->rc.right >= (rcc.right - 2 * g_cxEdge)) || ((i + 1) == cItems))
  2445. ptc->iPartId = (ptc->iPartId == TABP_TABITEMLEFTEDGE) ? TABP_TABITEMBOTHEDGE : TABP_TABITEMRIGHTEDGE;
  2446. if (pitem->rc.top == g_cyEdge)
  2447. {
  2448. switch (ptc->iPartId)
  2449. {
  2450. case TABP_TABITEM:
  2451. ptc->iPartId = TABP_TOPTABITEM;
  2452. break;
  2453. case TABP_TABITEMLEFTEDGE:
  2454. ptc->iPartId = TABP_TOPTABITEMLEFTEDGE;
  2455. break;
  2456. case TABP_TABITEMRIGHTEDGE:
  2457. ptc->iPartId = TABP_TOPTABITEMRIGHTEDGE;
  2458. break;
  2459. case TABP_TABITEMBOTHEDGE:
  2460. ptc->iPartId = TABP_TOPTABITEMBOTHEDGE;
  2461. break;
  2462. }
  2463. }
  2464. // Reverse order for themes
  2465. // Edges
  2466. Tab_DrawItemFrame(ptc, hdc, edgeType, pitem, i);
  2467. // Content
  2468. Tab_DrawBody(hdc, ptc, pitem, &rcBody, i, fnNewMode == TRANSPARENT, dx, dy);
  2469. }
  2470. else
  2471. {
  2472. // Content
  2473. Tab_DrawBody(hdc, ptc, pitem, &rcBody, i, fnNewMode == TRANSPARENT, dx, dy);
  2474. // Edges
  2475. Tab_DrawItemFrame(ptc, hdc, edgeType, pitem, i);
  2476. }
  2477. if (fnNewMode == TRANSPARENT)
  2478. {
  2479. fnNewMode = OPAQUE;
  2480. SelectObject(hdc, hbrOld);
  2481. SetBkMode(hdc, OPAQUE);
  2482. }
  2483. }
  2484. }
  2485. }
  2486. if (!Tab_MultiLine(ptc))
  2487. ptc->iLastVisible = i - 1;
  2488. else
  2489. ptc->iLastVisible = cItems - 1;
  2490. // Calling methods that render themes, setup state (TAB, SELECTED state)
  2491. if (ptc->hTheme)
  2492. {
  2493. ptc->iStateId = TIS_SELECTED;
  2494. }
  2495. // draw the selected one last to make sure it is on top
  2496. pitem = Tab_GetItemPtr(ptc, ptc->iSel);
  2497. if (pitem && (pitem->rc.left <= ptc->cxTabs))
  2498. {
  2499. rcBody = pitem->rc;
  2500. if (!Tab_DrawButtons(ptc))
  2501. {
  2502. UINT uWhichEdges;
  2503. InflateRect(&rcBody, g_cxEdge, g_cyEdge);
  2504. if (IntersectRect(&rcTest, &rcClipBox, &rcBody))
  2505. {
  2506. // Content
  2507. if (ptc->hTheme)
  2508. {
  2509. RECT rcc;
  2510. RECT rcBack = rcBody;
  2511. GetClientRect(ptc->ci.hwnd, &rcc);
  2512. // Determine what part is currently being rendered
  2513. ptc->iPartId = TABP_TABITEM;
  2514. if (pitem->rc.left == g_cxEdge)
  2515. ptc->iPartId = TABP_TABITEMLEFTEDGE;
  2516. if ((pitem->rc.right >= (rcc.right - 2 * g_cxEdge)) || ((i + 1) == cItems))
  2517. ptc->iPartId = (ptc->iPartId == TABP_TABITEMLEFTEDGE) ? TABP_TABITEMBOTHEDGE : TABP_TABITEMRIGHTEDGE;
  2518. if (pitem->rc.top == g_cyEdge)
  2519. {
  2520. switch (ptc->iPartId)
  2521. {
  2522. case TABP_TABITEM:
  2523. ptc->iPartId = TABP_TOPTABITEM;
  2524. break;
  2525. case TABP_TABITEMLEFTEDGE:
  2526. ptc->iPartId = TABP_TOPTABITEMLEFTEDGE;
  2527. break;
  2528. case TABP_TABITEMRIGHTEDGE:
  2529. ptc->iPartId = TABP_TOPTABITEMRIGHTEDGE;
  2530. break;
  2531. case TABP_TABITEMBOTHEDGE:
  2532. ptc->iPartId = TABP_TOPTABITEMBOTHEDGE;
  2533. break;
  2534. }
  2535. }
  2536. Tab_DrawEdge(hdc, &rcBack, EDGE_RAISED,
  2537. BF_LEFT | BF_TOP | BF_RIGHT | BF_SOFT,
  2538. ptc);
  2539. Tab_DrawBody(hdc, ptc, pitem, &rcBody, ptc->iSel, FALSE, 0,-g_cyEdge);
  2540. }
  2541. else
  2542. {
  2543. Tab_DrawBody(hdc, ptc, pitem, &rcBody, ptc->iSel, FALSE, 0,-g_cyEdge);
  2544. rcBody.bottom--; //because of button softness
  2545. Tab_DrawEdge(hdc, &rcBody, EDGE_RAISED,
  2546. BF_LEFT | BF_TOP | BF_RIGHT | BF_SOFT,
  2547. ptc);
  2548. }
  2549. // Edges
  2550. Tab_DoCorners(hdc, &rcBody, ptc, FALSE);
  2551. // draw that extra bit on the left or right side
  2552. // if we're on the edge
  2553. rcBody.bottom++;
  2554. rcBody.top = rcBody.bottom-1;
  2555. if (rcBody.right == rcClient.right)
  2556. {
  2557. uWhichEdges = BF_SOFT | BF_RIGHT;
  2558. }
  2559. else if (rcBody.left == rcClient.left)
  2560. {
  2561. uWhichEdges = BF_SOFT | BF_LEFT;
  2562. }
  2563. else
  2564. {
  2565. uWhichEdges = 0;
  2566. }
  2567. if (!ptc->hTheme)
  2568. {
  2569. if (uWhichEdges)
  2570. Tab_DrawEdge(hdc, &rcBody, EDGE_RAISED, uWhichEdges, ptc);
  2571. }
  2572. }
  2573. }
  2574. }
  2575. if (GetFocus() == hwnd)
  2576. {
  2577. if (!pitem && (ptc->iNewSel != -1))
  2578. {
  2579. pitem = Tab_GetItemPtr(ptc, ptc->iNewSel);
  2580. }
  2581. if (pitem && !(CCGetUIState(&(ptc->ci))& UISF_HIDEFOCUS))
  2582. {
  2583. rcBody = pitem->rc;
  2584. if (Tab_DrawButtons(ptc))
  2585. InflateRect(&rcBody, -g_cxEdge, -g_cyEdge);
  2586. else
  2587. InflateRect(&rcBody, -(g_cxEdge/2), -(g_cyEdge/2));
  2588. Tab_DrawFocusRect(hdc, &rcBody, ptc);
  2589. }
  2590. }
  2591. }
  2592. if (hdcIn == NULL)
  2593. EndPaint(hwnd, &ps);
  2594. }
  2595. int Tab_FindTab(PTC ptc, int iStart, UINT vk)
  2596. {
  2597. int iRow;
  2598. int x;
  2599. int i;
  2600. LPTABITEM pitem = Tab_GetItemPtr(ptc, iStart);
  2601. if (!pitem)
  2602. {
  2603. return(0);
  2604. }
  2605. iRow= pitem->iRow + ((vk == VK_UP) ? -1 : 1);
  2606. x = (pitem->rc.right + pitem->rc.left) / 2;
  2607. // find the and item on the iRow at horizontal x
  2608. if (iRow > ptc->iLastRow || iRow < 0)
  2609. return iStart;
  2610. // this relies on the ordering of tabs from left to right , but
  2611. // not necessarily top to bottom.
  2612. for (i = Tab_Count(ptc) - 1 ; i >= 0; i--) {
  2613. pitem = Tab_FastGetItemPtr(ptc, i);
  2614. if (pitem->iRow == iRow) {
  2615. if (pitem->rc.left < x)
  2616. return i;
  2617. }
  2618. }
  2619. // this should never happen.. we should have caught this case in the iRow check
  2620. // right before the for loop.
  2621. ASSERT(0);
  2622. return iStart;
  2623. }
  2624. void Tab_SetCurFocus(PTC ptc, int iStart)
  2625. {
  2626. if (Tab_DrawButtons(ptc)) {
  2627. if ((iStart >= 0) && (iStart < Tab_Count(ptc)) && (ptc->iNewSel != iStart)) {
  2628. if (ptc->iNewSel != -1)
  2629. Tab_InvalidateItem(ptc, ptc->iNewSel, FALSE);
  2630. Tab_InvalidateItem(ptc, iStart, FALSE);
  2631. ptc->iNewSel = iStart;
  2632. ptc->flags |= TCF_DRAWSUNKEN;
  2633. if (!Tab_MultiLine(ptc)) {
  2634. // scroll into view if necessary
  2635. RECT rc;
  2636. do {
  2637. Tab_OnGetItemRect(ptc, iStart, &rc);
  2638. if (rc.right > ptc->cxTabs) {
  2639. Tab_OnHScroll(ptc, NULL, SB_THUMBPOSITION, ptc->iFirstVisible + 1);
  2640. } else if (rc.left < 0) {
  2641. Tab_OnHScroll(ptc, NULL, SB_THUMBPOSITION, iStart);
  2642. break;
  2643. } else {
  2644. break;
  2645. }
  2646. } while (1);
  2647. }
  2648. CCSendNotify(&ptc->ci, TCN_FOCUSCHANGE, NULL);
  2649. NotifyWinEvent(EVENT_OBJECT_FOCUS, ptc->ci.hwnd, OBJID_CLIENT,
  2650. iStart+1);
  2651. }
  2652. } else
  2653. {
  2654. int iOld = ptc->iSel;
  2655. ChangeSel(ptc, iStart, TRUE, FALSE);
  2656. if ((iOld != ptc->iSel) && (GetFocus() == ptc->ci.hwnd))
  2657. NotifyWinEvent(EVENT_OBJECT_FOCUS, ptc->ci.hwnd, OBJID_CLIENT,
  2658. ptc->iSel+1);
  2659. }
  2660. }
  2661. void Tab_OnKeyDown(PTC ptc, UINT vk, BOOL fDown, int cRepeat, UINT flags)
  2662. {
  2663. int iStart;
  2664. TC_KEYDOWN nm;
  2665. // Notify
  2666. nm.wVKey = (WORD) vk;
  2667. nm.flags = flags;
  2668. // pass NULL for parent because W95 queryied each time and some
  2669. // folks reparent
  2670. SendNotifyEx(NULL, ptc->ci.hwnd, TCN_KEYDOWN, &nm.hdr, ptc->ci.bUnicode);
  2671. if (Tab_DrawButtons(ptc)) {
  2672. ptc->flags |= (TCF_DRAWSUNKEN|TCF_MOUSEDOWN);
  2673. if (ptc->iNewSel != -1) {
  2674. iStart = ptc->iNewSel;
  2675. } else {
  2676. iStart = ptc->iSel;
  2677. }
  2678. } else {
  2679. iStart = ptc->iSel;
  2680. }
  2681. vk = RTLSwapLeftRightArrows(&ptc->ci, vk);
  2682. if (Tab_Vertical(ptc)) {
  2683. // remap arrow keys if we're in vertial mode
  2684. switch(vk) {
  2685. case VK_LEFT:
  2686. vk = VK_DOWN;
  2687. break;
  2688. case VK_RIGHT:
  2689. vk = VK_UP;
  2690. break;
  2691. case VK_DOWN:
  2692. vk = VK_RIGHT;
  2693. break;
  2694. case VK_UP:
  2695. vk = VK_LEFT;
  2696. break;
  2697. }
  2698. }
  2699. switch (vk) {
  2700. case VK_LEFT:
  2701. iStart--;
  2702. break;
  2703. case VK_RIGHT:
  2704. iStart++;
  2705. break;
  2706. case VK_UP:
  2707. case VK_DOWN:
  2708. if (iStart != -1) {
  2709. iStart = Tab_FindTab(ptc, iStart, vk);
  2710. break;
  2711. } // else fall through to set iStart = 0;
  2712. case VK_HOME:
  2713. iStart = 0;
  2714. break;
  2715. case VK_END:
  2716. iStart = Tab_Count(ptc) - 1;
  2717. break;
  2718. case VK_SPACE:
  2719. if (!Tab_DrawButtons(ptc))
  2720. return;
  2721. // else fall through... in button mode space does selection
  2722. case VK_RETURN:
  2723. ChangeSel(ptc, iStart, TRUE, FALSE);
  2724. ptc->iNewSel = -1;
  2725. ptc->flags &= ~TCF_DRAWSUNKEN;
  2726. //notify of navigation key usage
  2727. CCNotifyNavigationKeyUsage(&(ptc->ci), UISF_HIDEFOCUS | UISF_HIDEACCEL);
  2728. return;
  2729. default:
  2730. return;
  2731. }
  2732. if (iStart < 0)
  2733. iStart = 0;
  2734. Tab_SetCurFocus(ptc, iStart);
  2735. //notify of navigation key usage
  2736. CCNotifyNavigationKeyUsage(&(ptc->ci), UISF_HIDEFOCUS | UISF_HIDEACCEL);
  2737. }
  2738. void Tab_Size(PTC ptc)
  2739. {
  2740. ptc->cxItem = RECOMPUTE;
  2741. Tab_UpdateArrows(ptc, TRUE);
  2742. }
  2743. BOOL Tab_OnGetItemRect(PTC ptc, int iItem, LPRECT lprc)
  2744. {
  2745. LPTABITEM pitem = Tab_GetItemPtr(ptc, iItem);
  2746. BOOL fRet = FALSE;
  2747. if (lprc)
  2748. {
  2749. Tab_CalcPaintMetrics(ptc, NULL);
  2750. if (pitem)
  2751. {
  2752. // Make sure all the item rects are up-to-date
  2753. *lprc = pitem->rc;
  2754. fRet = TRUE;
  2755. }
  2756. else
  2757. {
  2758. lprc->top = 0;
  2759. lprc->bottom = ptc->cyTabs;
  2760. lprc->right = 0;
  2761. lprc->left = 0;
  2762. }
  2763. Tab_VDFlipRect(ptc, lprc);
  2764. }
  2765. return fRet;
  2766. }
  2767. void Tab_StyleChanged(PTC ptc, UINT gwl, LPSTYLESTRUCT pinfo)
  2768. {
  2769. #define STYLE_MASK (TCS_BUTTONS | TCS_VERTICAL | TCS_MULTILINE | TCS_RAGGEDRIGHT | TCS_FIXEDWIDTH | TCS_FORCELABELLEFT | TCS_FORCEICONLEFT | TCS_BOTTOM | TCS_RIGHT | TCS_FLATBUTTONS | TCS_OWNERDRAWFIXED | TCS_HOTTRACK)
  2770. if (ptc && (gwl == GWL_STYLE)) {
  2771. DWORD dwChanged = (ptc->ci.style & STYLE_MASK) ^ (pinfo->styleNew & STYLE_MASK);
  2772. // special case. this is "Insider Trading" app (by papyrus, now kanisa). they set the 3 on the low byte in ie3 comctl32 when it
  2773. // had no meaning anyways. so we bail on that.
  2774. if (ptc->ci.style == 0x50004000 && pinfo->styleNew == 0x54004003)
  2775. return;
  2776. if (dwChanged) {
  2777. ptc->ci.style = (ptc->ci.style & ~STYLE_MASK) | (pinfo->styleNew & STYLE_MASK);
  2778. // make sure we don't have invalid bits set
  2779. if (!Tab_FixedWidth(ptc)) {
  2780. ptc->ci.style &= ~(TCS_FORCEICONLEFT | TCS_FORCELABELLEFT);
  2781. }
  2782. ptc->cxItem = RECOMPUTE;
  2783. ptc->cyTabs = RECOMPUTE;
  2784. //if the left/right orientation changed
  2785. // we need to re-create the font (if we own it)
  2786. // becaus the text orientation needs to flip by 180
  2787. if ((dwChanged & TCS_VERTICAL) ||
  2788. ((dwChanged & TCS_RIGHT) && Tab_Vertical(ptc))) {
  2789. if (!(ptc->flags & TCF_FONTSET))
  2790. Tab_OnSetFont(ptc, NULL, FALSE);
  2791. }
  2792. if (Tab_RedrawEnabled(ptc))
  2793. Tab_UpdateArrows(ptc, TRUE);
  2794. RedrawAll(ptc, RDW_ERASE | RDW_INVALIDATE);
  2795. }
  2796. #define FOCUS_MASK (TCS_FOCUSONBUTTONDOWN | TCS_FOCUSNEVER)
  2797. if ( (ptc->ci.style & FOCUS_MASK) ^ (pinfo->styleNew & FOCUS_MASK)) {
  2798. ptc->ci.style = (ptc->ci.style & ~FOCUS_MASK) | (pinfo->styleNew & FOCUS_MASK);
  2799. }
  2800. }
  2801. if (gwl == GWL_EXSTYLE)
  2802. {
  2803. ptc->ci.dwExStyle &= ~WS_EX_RTLREADING;
  2804. ptc->ci.dwExStyle |= (pinfo->styleNew & WS_EX_RTLREADING);
  2805. }
  2806. }
  2807. DWORD Tab_ExtendedStyleChange(PTC ptc, DWORD dwNewStyle, DWORD dwExMask)
  2808. {
  2809. DWORD dwOldStyle = ptc->dwStyleEx;
  2810. if (ptc->hDragProxy)
  2811. {
  2812. DestroyDragProxy(ptc->hDragProxy);
  2813. ptc->hDragProxy = NULL;
  2814. }
  2815. if (dwExMask)
  2816. dwNewStyle = (ptc->dwStyleEx & ~ dwExMask) | (dwNewStyle & dwExMask);
  2817. ptc->dwStyleEx = dwNewStyle;
  2818. // do any invalidation or whatever is needed here.
  2819. if ((dwOldStyle ^ dwNewStyle) & TCS_EX_FLATSEPARATORS)
  2820. {
  2821. InvalidateRect (ptc->ci.hwnd, NULL, TRUE);
  2822. }
  2823. if (ptc->dwStyleEx & TCS_EX_REGISTERDROP)
  2824. ptc->hDragProxy = CreateDragProxy(ptc->ci.hwnd, TabDragCallback, TRUE);
  2825. return dwOldStyle;
  2826. }
  2827. //
  2828. // APPCOMPAT Assumes that the tab control is on top. Returns bogus values for
  2829. // left, bottom or right. For app compat reasons, we can't change this
  2830. // buggy behavior. (Apps might be relying on the wrong values and fixing them
  2831. // up, so if we fix the function, they end up trying to "fix" something that
  2832. // wasn't broken, thereby breaking it.) But we might want to add
  2833. // TCM_ADJUSTRECT2 that can handle the left/right/bottom cases.
  2834. //
  2835. void Tab_OnAdjustRect(PTC ptc, BOOL fGrow, LPRECT prc)
  2836. {
  2837. int idy;
  2838. Tab_CalcPaintMetrics(ptc, NULL);
  2839. if (Tab_DrawButtons(ptc)) {
  2840. if (Tab_Count(ptc)) {
  2841. RECT rc;
  2842. Tab_OnGetItemRect(ptc, Tab_Count(ptc) - 1, &rc);
  2843. idy = rc.bottom;
  2844. } else {
  2845. idy = 0;
  2846. }
  2847. } else {
  2848. idy = (ptc->cyTabs * (ptc->iLastRow + 1));
  2849. }
  2850. if (fGrow) {
  2851. // calc a larger rect from the smaller
  2852. prc->top -= idy;
  2853. InflateRect(prc, g_cxEdge * 2, g_cyEdge * 2);
  2854. } else {
  2855. prc->top += idy;
  2856. // given the bounds, calc the "client" area
  2857. InflateRect(prc, -g_cxEdge * 2, -g_cyEdge * 2);
  2858. }
  2859. if (Tab_ScrollOpposite(ptc)) {
  2860. // the sizes are the same, it's just offset wrong vertically
  2861. idy = ptc->cyTabs * (ptc->iLastRow - ptc->iLastTopRow);
  2862. ASSERT(ptc->iLastTopRow != -1);
  2863. if (!fGrow) {
  2864. idy *= -1;
  2865. }
  2866. DebugMsg(DM_TRACE, TEXT("Tab_AdjustRect %d %d %d %d"), prc->left, prc->top, prc->right, prc->bottom);
  2867. OffsetRect(prc, 0, idy);
  2868. DebugMsg(DM_TRACE, TEXT("Tab_AdjustRect %d %d %d %d"), prc->left, prc->top, prc->right, prc->bottom);
  2869. }
  2870. }
  2871. // Tab_WndProc is theme aware
  2872. LRESULT CALLBACK Tab_WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  2873. {
  2874. PTC ptc = (PTC)GetWindowInt((hwnd), 0);
  2875. if (ptc)
  2876. {
  2877. if ((uMsg >= WM_MOUSEFIRST) && (uMsg <= WM_MOUSELAST) &&
  2878. Tab_HotTrack(ptc) && !ptc->fTrackSet)
  2879. {
  2880. TRACKMOUSEEVENT tme;
  2881. ptc->fTrackSet = TRUE;
  2882. tme.cbSize = sizeof(tme);
  2883. tme.hwndTrack = ptc->ci.hwnd;
  2884. tme.dwFlags = TME_LEAVE;
  2885. TrackMouseEvent(&tme);
  2886. }
  2887. else
  2888. {
  2889. // Check for theme changes
  2890. if (uMsg == WM_THEMECHANGED)
  2891. {
  2892. if (ptc->hTheme)
  2893. CloseThemeData(ptc->hTheme);
  2894. ptc->hTheme = (!Tab_OwnerDraw(ptc) && !Tab_DrawButtons(ptc)) ? OpenThemeData(ptc->ci.hwnd, L"Tab") : NULL;
  2895. // Active hot state if themes are in use
  2896. if (ptc->hTheme)
  2897. ptc->ci.style |= TCS_HOTTRACK;
  2898. else
  2899. ptc->ci.style &= ~TCS_HOTTRACK;
  2900. // Recompute metrics since font may have changed
  2901. ptc->cxItem = RECOMPUTE;
  2902. ptc->cyTabs = RECOMPUTE;
  2903. InvalidateRect(ptc->ci.hwnd, NULL, TRUE);
  2904. }
  2905. }
  2906. } else if (uMsg != WM_CREATE)
  2907. goto DoDefault;
  2908. switch (uMsg) {
  2909. HANDLE_MSG(ptc, WM_HSCROLL, Tab_OnHScroll);
  2910. case WM_MOUSELEAVE:
  2911. Tab_InvalidateItem(ptc, ptc->iHot, FALSE);
  2912. ptc->iHot = -1;
  2913. ptc->fTrackSet = FALSE;
  2914. break;
  2915. case WM_CREATE:
  2916. InitGlobalColors();
  2917. ptc = (PTC)NearAlloc(sizeof(TC));
  2918. if (!ptc)
  2919. return -1; // fail the window create
  2920. SetWindowPtr(hwnd, 0, ptc);
  2921. CIInitialize(&ptc->ci, hwnd, (LPCREATESTRUCT)lParam);
  2922. if (!Tab_OnCreate(ptc))
  2923. return -1;
  2924. break;
  2925. case WM_DESTROY:
  2926. Tab_OnDestroy(ptc);
  2927. break;
  2928. case WM_SIZE:
  2929. Tab_Size(ptc);
  2930. break;
  2931. case WM_SYSCOLORCHANGE:
  2932. InitGlobalColors();
  2933. if (!(ptc->flags & TCF_FONTSET))
  2934. Tab_OnSetFont(ptc, NULL, FALSE);
  2935. RedrawAll(ptc, RDW_INVALIDATE | RDW_ERASE);
  2936. break;
  2937. case WM_WININICHANGE:
  2938. InitGlobalMetrics(wParam);
  2939. if ((wParam == SPI_SETNONCLIENTMETRICS) ||
  2940. (!wParam && !lParam))
  2941. RedrawAll(ptc, RDW_INVALIDATE | RDW_ERASE);
  2942. break;
  2943. case WM_ERASEBKGND:
  2944. // Background fill will happen in Tab_Paint if themes are active
  2945. if (ptc->hTheme)
  2946. return 1;
  2947. goto DoDefault;
  2948. case WM_PRINTCLIENT:
  2949. case WM_PAINT:
  2950. Tab_Paint(ptc, (HDC)wParam);
  2951. break;
  2952. case WM_STYLECHANGED:
  2953. Tab_StyleChanged(ptc, (UINT) wParam, (LPSTYLESTRUCT)lParam);
  2954. break;
  2955. case WM_MOUSEMOVE:
  2956. RelayToToolTips(ptc->hwndToolTips, hwnd, uMsg, wParam, lParam);
  2957. Tab_OnMouseMove(ptc, wParam, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
  2958. break;
  2959. case WM_LBUTTONDOWN:
  2960. RelayToToolTips(ptc->hwndToolTips, hwnd, uMsg, wParam, lParam);
  2961. Tab_OnLButtonDown(ptc, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam);
  2962. break;
  2963. case WM_LBUTTONDBLCLK:
  2964. if (Tab_DrawButtons(ptc)) {
  2965. MSG msg;
  2966. // on the double click, grab capture until we get the lbutton up and
  2967. // eat it.
  2968. SetCapture(ptc->ci.hwnd);
  2969. while (GetCapture() == ptc->ci.hwnd &&
  2970. !PeekMessage(&msg, ptc->ci.hwnd, WM_LBUTTONUP, WM_LBUTTONUP, PM_REMOVE))
  2971. {
  2972. }
  2973. CCReleaseCapture(&ptc->ci);
  2974. }
  2975. break;
  2976. case WM_MBUTTONDOWN:
  2977. SetFocus(hwnd);
  2978. break;
  2979. case WM_RBUTTONDOWN:
  2980. Tab_OnRButtonDown(ptc, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam);
  2981. break;
  2982. case WM_RBUTTONUP:
  2983. // pass NULL for parent because W95 queryied each time and some
  2984. // folks reparent
  2985. if (!SendNotifyEx(NULL, ptc->ci.hwnd, NM_RCLICK, NULL, ptc->ci.bUnicode))
  2986. goto DoDefault;
  2987. break;
  2988. case WM_CAPTURECHANGED:
  2989. lParam = -1L; // fall through to LBUTTONUP
  2990. case WM_LBUTTONUP:
  2991. if (uMsg == WM_LBUTTONUP) {
  2992. RelayToToolTips(ptc->hwndToolTips, hwnd, uMsg, wParam, lParam);
  2993. }
  2994. Tab_OnButtonUp(ptc, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), (uMsg == WM_LBUTTONUP));
  2995. break;
  2996. case WM_SYSKEYDOWN:
  2997. //notify of navigation key usage
  2998. if (HIWORD(lParam) & KF_ALTDOWN)
  2999. CCNotifyNavigationKeyUsage(&(ptc->ci), UISF_HIDEFOCUS | UISF_HIDEACCEL);
  3000. goto DoDefault;
  3001. case WM_KEYDOWN:
  3002. HANDLE_WM_KEYDOWN(ptc, wParam, lParam, Tab_OnKeyDown);
  3003. break;
  3004. case WM_KILLFOCUS:
  3005. if (ptc->iNewSel != -1) {
  3006. int iOldSel = ptc->iNewSel;
  3007. ptc->iNewSel = -1;
  3008. Tab_InvalidateItem(ptc, iOldSel, FALSE);
  3009. ptc->flags &= ~TCF_DRAWSUNKEN;
  3010. }
  3011. // fall through
  3012. case WM_SETFOCUS:
  3013. Tab_InvalidateItem(ptc, ptc->iSel, Tab_OwnerDraw(ptc));
  3014. if ((uMsg == WM_SETFOCUS) && (ptc->iSel != -1))
  3015. NotifyWinEvent(EVENT_OBJECT_FOCUS, hwnd, OBJID_CLIENT, ptc->iSel+1);
  3016. break;
  3017. case WM_GETDLGCODE:
  3018. return DLGC_WANTARROWS | DLGC_WANTCHARS;
  3019. HANDLE_MSG(ptc, WM_SETREDRAW, Tab_OnSetRedraw);
  3020. HANDLE_MSG(ptc, WM_SETFONT, Tab_OnSetFont);
  3021. case WM_GETFONT:
  3022. return (LRESULT)ptc->hfontLabel;
  3023. case WM_NOTIFYFORMAT:
  3024. return CIHandleNotifyFormat(&ptc->ci, lParam);
  3025. case WM_NOTIFY: {
  3026. LPNMHDR lpNmhdr = (LPNMHDR)(lParam);
  3027. //
  3028. // We are just going to pass this on to the
  3029. // real parent. Note that -1 is used as
  3030. // the hwndFrom. This prevents SendNotifyEx
  3031. // from updating the NMHDR structure.
  3032. //
  3033. SendNotifyEx(GetParent(ptc->ci.hwnd), (HWND) -1,
  3034. lpNmhdr->code, lpNmhdr, ptc->ci.bUnicode);
  3035. }
  3036. break;
  3037. case WM_UPDATEUISTATE:
  3038. if (CCOnUIState(&(ptc->ci), WM_UPDATEUISTATE, wParam, lParam))
  3039. {
  3040. if (UISF_HIDEFOCUS == HIWORD(wParam))
  3041. {
  3042. // We erase only if we are removing the focus rect or the accel
  3043. Tab_InvalidateItem(ptc, ptc->iSel,
  3044. (UIS_CLEAR == LOWORD(wParam)) ? TRUE : FALSE);
  3045. }
  3046. else
  3047. {
  3048. if ((UISF_HIDEFOCUS | UISF_HIDEACCEL) & HIWORD(wParam))
  3049. {
  3050. int i;
  3051. for (i = ptc->iFirstVisible; i <= ptc->iLastVisible; ++i)
  3052. {
  3053. Tab_InvalidateItem(ptc, i,
  3054. (UIS_CLEAR == LOWORD(wParam)) ? TRUE : FALSE);
  3055. }
  3056. }
  3057. }
  3058. }
  3059. goto DoDefault;
  3060. case TCM_SETITEMEXTRA:
  3061. return (LRESULT)Tab_OnSetItemExtra(ptc, (int)wParam);
  3062. case TCM_GETITEMCOUNT:
  3063. return (LRESULT)Tab_Count(ptc);
  3064. case TCM_SETITEMA:
  3065. {
  3066. LRESULT lResult;
  3067. TC_ITEMW * pItemW;
  3068. if (!lParam)
  3069. {
  3070. return FALSE;
  3071. }
  3072. pItemW = ThunkItemAtoW(ptc, (TC_ITEMA*)lParam);
  3073. if (!pItemW)
  3074. {
  3075. return FALSE;
  3076. }
  3077. lResult = (LRESULT)Tab_OnSetItem(ptc, (int)wParam, pItemW);
  3078. FreeItemW(pItemW);
  3079. return lResult;
  3080. }
  3081. case TCM_SETITEM:
  3082. if (!lParam)
  3083. {
  3084. return FALSE;
  3085. }
  3086. return (LRESULT)Tab_OnSetItem(ptc, (int)wParam, (const TC_ITEM*)lParam);
  3087. case TCM_GETITEMA:
  3088. {
  3089. LRESULT lResult;
  3090. TC_ITEMW * pItemW;
  3091. LPWSTR pszTextW = NULL;
  3092. TC_ITEMA * pItemA = (TC_ITEMA*)lParam;
  3093. if (!ptc || !pItemA)
  3094. {
  3095. return FALSE;
  3096. }
  3097. pItemW = GlobalAlloc (GPTR, sizeof(TC_ITEMW) + ptc->cbExtra);
  3098. if (!pItemW)
  3099. {
  3100. return FALSE;
  3101. }
  3102. if (pItemA->mask & TCIF_TEXT)
  3103. {
  3104. pszTextW = GlobalAlloc (GPTR, pItemA->cchTextMax * sizeof (TCHAR));
  3105. if (!pszTextW)
  3106. {
  3107. GlobalFree (pItemW);
  3108. return FALSE;
  3109. }
  3110. pItemW->pszText = pszTextW;
  3111. }
  3112. pItemW->mask = pItemA->mask;
  3113. pItemW->cchTextMax = pItemA->cchTextMax;
  3114. pItemW->dwStateMask = pItemA->dwStateMask;
  3115. lResult = (LRESULT)Tab_OnGetItem(ptc, (int)wParam, pItemW);
  3116. if (!ThunkItemWtoA (ptc, pItemW, pItemA))
  3117. {
  3118. lResult = (LRESULT)FALSE;
  3119. }
  3120. if (pszTextW)
  3121. {
  3122. GlobalFree (pszTextW);
  3123. }
  3124. GlobalFree (pItemW);
  3125. return lResult;
  3126. }
  3127. case TCM_GETITEM:
  3128. if (!ptc || !lParam)
  3129. {
  3130. return FALSE;
  3131. }
  3132. return (LRESULT)Tab_OnGetItem(ptc, (int)wParam, (TC_ITEM*)lParam);
  3133. case TCM_INSERTITEMA:
  3134. {
  3135. LRESULT lResult;
  3136. TC_ITEMW * pItemW;
  3137. if (!lParam)
  3138. {
  3139. return FALSE;
  3140. }
  3141. pItemW = ThunkItemAtoW(ptc, (TC_ITEMA*)lParam);
  3142. if (!pItemW)
  3143. {
  3144. return FALSE;
  3145. }
  3146. lResult = (LRESULT)Tab_OnInsertItem(ptc, (int)wParam, pItemW);
  3147. FreeItemW(pItemW);
  3148. return lResult;
  3149. }
  3150. case TCM_INSERTITEM:
  3151. if (!lParam)
  3152. {
  3153. return FALSE;
  3154. }
  3155. return (LRESULT)Tab_OnInsertItem(ptc, (int)wParam, (const TC_ITEM*)lParam);
  3156. case TCM_DELETEITEM:
  3157. return (LRESULT)Tab_OnDeleteItem(ptc, (int)wParam);
  3158. case TCM_DELETEALLITEMS:
  3159. return (LRESULT)Tab_OnDeleteAllItems(ptc);
  3160. case TCM_SETCURFOCUS:
  3161. Tab_SetCurFocus(ptc, (int) wParam);
  3162. break;
  3163. case TCM_GETCURFOCUS:
  3164. if (ptc->iNewSel != -1)
  3165. return ptc->iNewSel;
  3166. // else fall through
  3167. case TCM_GETCURSEL:
  3168. return ptc->iSel;
  3169. case TCM_SETCURSEL:
  3170. return (LRESULT)ChangeSel(ptc, (int)wParam, FALSE, FALSE);
  3171. case TCM_GETTOOLTIPS:
  3172. return (LRESULT)ptc->hwndToolTips;
  3173. case TCM_SETTOOLTIPS:
  3174. ptc->hwndToolTips = (HWND)wParam;
  3175. break;
  3176. case TCM_ADJUSTRECT:
  3177. if (lParam)
  3178. {
  3179. RECT* prc = (RECT *)lParam;
  3180. Tab_DVFlipRect(ptc, prc);
  3181. Tab_OnAdjustRect(ptc, BOOLFROMPTR( wParam), (LPRECT)lParam);
  3182. Tab_VDFlipRect(ptc, prc);
  3183. }
  3184. else
  3185. return -1;
  3186. break;
  3187. case TCM_GETITEMRECT:
  3188. return Tab_OnGetItemRect(ptc, (int)wParam, (LPRECT)lParam);
  3189. case TCM_SETIMAGELIST:
  3190. {
  3191. HIMAGELIST himlOld = ptc->himl;
  3192. ptc->himl = (HIMAGELIST)lParam;
  3193. ptc->cxItem = ptc->cyTabs = RECOMPUTE;
  3194. RedrawAll(ptc, RDW_INVALIDATE | RDW_ERASE);
  3195. return (LRESULT)himlOld;
  3196. }
  3197. case TCM_GETIMAGELIST:
  3198. return (LRESULT)ptc->himl;
  3199. case TCM_REMOVEIMAGE:
  3200. Tab_OnRemoveImage(ptc, (int)wParam);
  3201. break;
  3202. case TCM_SETITEMSIZE:
  3203. {
  3204. int iOldWidth = ptc->iTabWidth;
  3205. int iOldHeight = ptc->iTabHeight;
  3206. int iNewWidth = LOWORD(lParam);
  3207. int iNewHeight = HIWORD(lParam);
  3208. if (ptc->himl)
  3209. {
  3210. int cx, cy;
  3211. Tab_ImageList_GetIconSize(ptc, &cx, &cy);
  3212. if (iNewWidth < (cx + (2*g_cxEdge)))
  3213. iNewWidth = cx + (2*g_cxEdge);
  3214. }
  3215. ptc->iTabWidth = iNewWidth;
  3216. ptc->iTabHeight = iNewHeight;
  3217. if (iNewWidth != iOldWidth ||
  3218. iNewHeight != iOldHeight)
  3219. {
  3220. ptc->cxItem = RECOMPUTE;
  3221. ptc->cyTabs = RECOMPUTE;
  3222. RedrawAll(ptc, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);
  3223. }
  3224. return (LRESULT)MAKELONG(iOldWidth, iOldHeight);
  3225. }
  3226. case TCM_SETPADDING:
  3227. ptc->cxPad = GET_X_LPARAM(lParam);
  3228. ptc->cyPad = GET_Y_LPARAM(lParam);
  3229. break;
  3230. case TCM_GETROWCOUNT:
  3231. Tab_CalcPaintMetrics(ptc, NULL);
  3232. return (LRESULT)ptc->iLastRow + 1;
  3233. case TCM_SETMINTABWIDTH:
  3234. {
  3235. int iOld = ptc->cxMinTab;
  3236. if ((int)lParam >= 0)
  3237. {
  3238. ptc->cxMinTab = (int)lParam;
  3239. ptc->fMinTabSet = TRUE;
  3240. }
  3241. else
  3242. {
  3243. ptc->fMinTabSet = FALSE;
  3244. }
  3245. ptc->cyTabs = RECOMPUTE;
  3246. ptc->cxItem = RECOMPUTE;
  3247. InvalidateRect(ptc->ci.hwnd, NULL, TRUE);
  3248. return iOld;
  3249. }
  3250. case TCM_DESELECTALL:
  3251. Tab_DeselectAll(ptc, BOOLFROMPTR( wParam));
  3252. break;
  3253. case TCM_SETEXTENDEDSTYLE:
  3254. return Tab_ExtendedStyleChange(ptc, (DWORD) lParam, (DWORD) wParam);
  3255. case TCM_GETEXTENDEDSTYLE:
  3256. return ptc->dwStyleEx;
  3257. case TCM_HITTEST:
  3258. {
  3259. LPTC_HITTESTINFO lphitinfo = (LPTC_HITTESTINFO)lParam;
  3260. return Tab_OnHitTest(ptc, lphitinfo->pt.x, lphitinfo->pt.y, &lphitinfo->flags);
  3261. }
  3262. case TCM_HIGHLIGHTITEM:
  3263. {
  3264. LPTABITEM pitem = Tab_GetItemPtr(ptc, (int)wParam);
  3265. if (pitem)
  3266. {
  3267. BOOL fHighlight = LOWORD(lParam) != 0;
  3268. // Don't do anything if state hasn't changed.
  3269. if (fHighlight == ((pitem->dwState & TCIS_HIGHLIGHTED) != 0))
  3270. break;
  3271. if (fHighlight)
  3272. pitem->dwState |= TCIS_HIGHLIGHTED;
  3273. else
  3274. pitem->dwState &= ~TCIS_HIGHLIGHTED;
  3275. Tab_InvalidateItem(ptc, (int)wParam, TRUE);
  3276. return TRUE;
  3277. }
  3278. break;
  3279. }
  3280. case WM_NCHITTEST:
  3281. {
  3282. POINT pt;
  3283. pt.x = GET_X_LPARAM(lParam);
  3284. pt.y = GET_Y_LPARAM(lParam);
  3285. ScreenToClient(ptc->ci.hwnd, &pt);
  3286. if (Tab_OnHitTest(ptc, pt.x, pt.y, NULL) == -1)
  3287. return(HTTRANSPARENT);
  3288. else {
  3289. goto DoDefault;
  3290. }
  3291. }
  3292. case WM_GETOBJECT:
  3293. if( lParam == OBJID_QUERYCLASSNAMEIDX )
  3294. return MSAA_CLASSNAMEIDX_TAB;
  3295. break;
  3296. default:
  3297. {
  3298. LRESULT lres;
  3299. if (CCWndProc(&ptc->ci, uMsg, wParam, lParam, &lres))
  3300. return lres;
  3301. }
  3302. DoDefault:
  3303. return DefWindowProc(hwnd, uMsg, wParam, lParam);
  3304. }
  3305. return 0L;
  3306. }
  3307. //
  3308. // ANSI <=> UNICODE thunks
  3309. //
  3310. TC_ITEMW * ThunkItemAtoW (PTC ptc, TC_ITEMA * pItemA)
  3311. {
  3312. TC_ITEMW *pItemW;
  3313. UINT cbTextW;
  3314. INT iResult;
  3315. pItemW = (TC_ITEMW *) GlobalAlloc (GPTR, sizeof(TC_ITEMW) + ptc->cbExtra);
  3316. if (!pItemW) {
  3317. return NULL;
  3318. }
  3319. pItemW->mask = pItemA->mask;
  3320. pItemW->dwState = pItemA->dwState;
  3321. pItemW->dwStateMask = pItemA->dwStateMask;
  3322. if ((pItemA->mask & TCIF_TEXT) && pItemA->pszText) {
  3323. cbTextW = lstrlenA(pItemA->pszText) + 1;
  3324. pItemW->pszText = (LPWSTR)GlobalAlloc (GPTR, cbTextW * sizeof(TCHAR));
  3325. if (!pItemW->pszText) {
  3326. GlobalFree (pItemW);
  3327. return NULL;
  3328. }
  3329. iResult = MultiByteToWideChar (CP_ACP, 0, pItemA->pszText, -1,
  3330. pItemW->pszText, cbTextW);
  3331. if (!iResult) {
  3332. if (GetLastError()) {
  3333. GlobalFree (pItemW->pszText);
  3334. GlobalFree (pItemW);
  3335. return NULL;
  3336. }
  3337. }
  3338. }
  3339. pItemW->cchTextMax = pItemA->cchTextMax;
  3340. if (pItemA->mask & TCIF_IMAGE) {
  3341. pItemW->iImage = pItemA->iImage;
  3342. }
  3343. if (pItemA->mask & TCIF_PARAM) {
  3344. hmemcpy(&pItemW->lParam, &pItemA->lParam, ptc->cbExtra);
  3345. }
  3346. return (pItemW);
  3347. }
  3348. BOOL ThunkItemWtoA (PTC ptc, TC_ITEMW * pItemW, TC_ITEMA * pItemA)
  3349. {
  3350. INT iResult;
  3351. if (!pItemA) {
  3352. return FALSE;
  3353. }
  3354. pItemA->mask = pItemW->mask;
  3355. pItemA->dwState = pItemW->dwState;
  3356. pItemA->dwStateMask = pItemW->dwStateMask;
  3357. if ((pItemW->mask & TCIF_TEXT) && pItemW->pszText && pItemW->cchTextMax) {
  3358. iResult = WideCharToMultiByte (CP_ACP, 0, pItemW->pszText, -1,
  3359. pItemA->pszText, pItemW->cchTextMax, NULL, NULL);
  3360. if (!iResult) {
  3361. if (GetLastError()) {
  3362. return FALSE;
  3363. }
  3364. }
  3365. }
  3366. pItemA->cchTextMax = pItemW->cchTextMax;
  3367. if (pItemW->mask & TCIF_IMAGE) {
  3368. pItemA->iImage = pItemW->iImage;
  3369. }
  3370. if (pItemW->mask & TCIF_PARAM) {
  3371. hmemcpy(&pItemA->lParam, &pItemW->lParam, ptc->cbExtra);
  3372. }
  3373. return TRUE;
  3374. }
  3375. BOOL FreeItemW (TC_ITEMW *pItemW)
  3376. {
  3377. if ((pItemW->mask & TCIF_TEXT) && pItemW->pszText) {
  3378. GlobalFree (pItemW->pszText);
  3379. }
  3380. GlobalFree (pItemW);
  3381. return TRUE;
  3382. }
  3383. BOOL FreeItemA (TC_ITEMA *pItemA)
  3384. {
  3385. if ((pItemA->mask & TCIF_TEXT) && pItemA->pszText) {
  3386. GlobalFree (pItemA->pszText);
  3387. }
  3388. GlobalFree (pItemA);
  3389. return TRUE;
  3390. }