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.

3749 lines
110 KiB

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