Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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