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

3899 lines
110 KiB

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