Changeset 10098 for trunk/src/comctl32/toolbar.c
- Timestamp:
- May 15, 2003, 4:26:27 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comctl32/toolbar.c
r9394 r10098 30 30 * 31 31 * TODO: 32 * - A little bug in TOOLBAR_DrawMasked()33 32 * - Button wrapping (under construction). 34 33 * - Messages. … … 97 96 typedef struct 98 97 { 98 HIMAGELIST himl; 99 INT id; 100 } IMLENTRY, *PIMLENTRY; 101 102 typedef struct 103 { 99 104 DWORD dwStructSize; /* size of TBBUTTON struct */ 100 105 INT nHeight; /* height of the toolbar */ … … 125 130 HFONT hFont; /* text font */ 126 131 HIMAGELIST himlInt; /* image list created internally */ 127 HIMAGELIST himlDef; /* default image list */ 128 HIMAGELIST himlHot; /* hot image list */ 129 HIMAGELIST himlDis; /* disabled image list */ 132 PIMLENTRY *himlDef; /* default image list array */ 133 INT cimlDef; /* default image list array count */ 134 PIMLENTRY *himlHot; /* hot image list array */ 135 INT cimlHot; /* hot image list array count */ 136 PIMLENTRY *himlDis; /* disabled image list array */ 137 INT cimlDis; /* disabled image list array count */ 130 138 HWND hwndToolTip; /* handle to tool tip control */ 131 139 HWND hwndNotify; /* handle to the window that gets notifications */ … … 164 172 BOOL bVirtual; 165 173 BOOL bRemovable; 166 CHARtext[64];174 WCHAR text[64]; 167 175 } CUSTOMBUTTON, *PCUSTOMBUTTON; 168 176 … … 183 191 TBSTYLE_EX_HIDECLIPPEDBUTTONS) 184 192 193 #define GETIBITMAP(infoPtr, i) (infoPtr->iVersion >= 5 ? LOWORD(i) : i) 194 #define GETHIMLID(infoPtr, i) (infoPtr->iVersion >= 5 ? HIWORD(i) : 0) 195 #define GETDEFIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDef, infoPtr->cimlDef, id) 196 #define GETHOTIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlHot, infoPtr->cimlHot, id) 197 #define GETDISIMAGELIST(infoPtr, id) TOOLBAR_GetImageList(infoPtr->himlDis, infoPtr->cimlDis, id) 198 199 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb); 200 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, int iItem, PCUSTOMBUTTON btnInfo); 201 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id); 202 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id); 203 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies); 204 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id); 205 185 206 static LRESULT 186 207 TOOLBAR_NotifyFormat(TOOLBAR_INFO *infoPtr, WPARAM wParam, LPARAM lParam); … … 206 227 if (TRACE_ON(toolbar)){ 207 228 TRACE("button %d id %d, bitmap=%d, state=%02x, style=%02x, data=%08lx, stringid=0x%08x\n", 208 btn_num, bP->idCommand, 209 bP->iBitmap,bP->fsState, bP->fsStyle, bP->dwData, bP->iString);229 btn_num, bP->idCommand, GETIBITMAP(infoPtr, bP->iBitmap), 230 bP->fsState, bP->fsStyle, bP->dwData, bP->iString); 210 231 TRACE("string %s\n", debugstr_w(TOOLBAR_GetText(infoPtr,bP))); 211 232 if (internal) 212 TRACE("button %d id %d, hot=%s, row=%d, rect=(% d,%d)-(%d,%d)\n",233 TRACE("button %d id %d, hot=%s, row=%d, rect=(%ld,%ld)-(%ld,%ld)\n", 213 234 btn_num, bP->idCommand, 214 235 (bP->bHot) ? "TRUE":"FALSE", bP->nRow, … … 309 330 ret, nmgd.dwMask, infoPtr->nNumBitmaps); 310 331 } 332 333 if (ret != I_IMAGENONE) 334 ret = GETIBITMAP(infoPtr, ret); 335 311 336 return ret; 312 337 } … … 316 341 TOOLBAR_IsValidBitmapIndex(TOOLBAR_INFO *infoPtr, INT index) 317 342 { 318 if (((index>=0) && (index <= infoPtr->nNumBitmaps)) || 319 (index == I_IMAGECALLBACK)) 343 HIMAGELIST himl; 344 INT id = GETHIMLID(infoPtr, index); 345 INT iBitmap = GETIBITMAP(infoPtr, index); 346 347 if (((himl = GETDEFIMAGELIST(infoPtr, id)) && 348 iBitmap >= 0 && iBitmap < ImageList_GetImageCount(himl)) || 349 (index == I_IMAGECALLBACK)) 320 350 return TRUE; 321 351 else … … 444 474 InflateRect (&myrect, -2, 0); 445 475 446 TRACE("rect=(% d,%d)-(%d,%d)\n",476 TRACE("rect=(%ld,%ld)-(%ld,%ld)\n", 447 477 myrect.left, myrect.top, myrect.right, myrect.bottom); 448 478 … … 500 530 /* draw text */ 501 531 if (lpText) { 502 TRACE("string rect=(% d,%d)-(%d,%d)\n",532 TRACE("string rect=(%ld,%ld)-(%ld,%ld)\n", 503 533 rcText->left, rcText->top, rcText->right, rcText->bottom); 504 534 … … 543 573 HDC hdc, INT x, INT y) 544 574 { 545 /* FIXME: this function is a hack since it uses image list 546 internals directly */ 547 548 HIMAGELIST himl = infoPtr->himlDef; 575 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, 0); 576 INT cx, cy; 549 577 HBITMAP hbmMask; 550 HDC hdcImageList;551 578 HDC hdcMask; 552 579 … … 554 581 return; 555 582 583 ImageList_GetIconSize(himl, &cx, &cy); 584 556 585 /* create new dc's */ 557 hdcImageList = CreateCompatibleDC (0);558 586 hdcMask = CreateCompatibleDC (0); 559 587 560 588 /* create new bitmap */ 561 hbmMask = CreateBitmap ( himl->cx, himl->cy, 1, 1, NULL);589 hbmMask = CreateBitmap (cx, cy, 1, 1, NULL); 562 590 SelectObject (hdcMask, hbmMask); 563 591 564 592 /* copy the mask bitmap */ 565 SelectObject (hdcImageList, himl->hbmMask); 566 SetBkColor (hdcImageList, RGB(255, 255, 255)); 567 SetTextColor (hdcImageList, RGB(0, 0, 0)); 568 BitBlt (hdcMask, 0, 0, himl->cx, himl->cy, 569 hdcImageList, himl->cx * btnPtr->iBitmap, 0, SRCCOPY); 593 ImageList_DrawEx(himl, btnPtr->iBitmap, hdcMask, 0, 0, 0, 0, RGB(255, 255, 255), RGB(0, 0, 0), ILD_MASK); 570 594 571 595 /* draw the new mask */ 572 596 SelectObject (hdc, GetSysColorBrush (COLOR_3DHILIGHT)); 573 BitBlt (hdc, x+1, y+1, himl->cx, himl->cy, 574 hdcMask, 0, 0, 0xB8074A); 597 BitBlt (hdc, x+1, y+1, cx, cy, hdcMask, 0, 0, 0xB8074A); 575 598 576 599 SelectObject (hdc, GetSysColorBrush (COLOR_3DSHADOW)); 577 BitBlt (hdc, x, y, himl->cx, himl->cy, 578 hdcMask, 0, 0, 0xB8074A); 600 BitBlt (hdc, x, y, cx, cy, hdcMask, 0, 0, 0xB8074A); 579 601 580 602 DeleteObject (hbmMask); 581 603 DeleteDC (hdcMask); 582 DeleteDC (hdcImageList);583 604 } 584 605 … … 613 634 DWORD ntfret; 614 635 INT offset; 636 HIMAGELIST himlDef; 615 637 616 638 if (btnPtr->fsState & TBSTATE_HIDDEN) … … 646 668 rcBitmap.top+=(infoPtr->nButtonHeight - infoPtr->nBitmapHeight) / 2; 647 669 648 TRACE("iBitmap: %d, start=(% d,%d) w=%d, h=%d\n",670 TRACE("iBitmap: %d, start=(%ld,%ld) w=%d, h=%d\n", 649 671 btnPtr->iBitmap, rcBitmap.left, rcBitmap.top, 650 672 infoPtr->nBitmapWidth, infoPtr->nBitmapHeight); … … 657 679 InflateRect (&rcText, -3, -3); 658 680 659 if ( infoPtr->himlDef&&681 if (GETDEFIMAGELIST(infoPtr, 0) && 660 682 TOOLBAR_IsValidBitmapIndex(infoPtr,btnPtr->iBitmap)) { 661 683 /* The following test looked like this before … … 756 778 } 757 779 780 /* Determine index of image list */ 781 himlDef = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap)); 782 758 783 /* disabled */ 759 784 if (!(btnPtr->fsState & TBSTATE_ENABLED)) { 785 HIMAGELIST himlDis = GETDISIMAGELIST(infoPtr, GETHIMLID(infoPtr, btnPtr->iBitmap)); 760 786 if (!(dwStyle & TBSTYLE_FLAT) && !(infoPtr->dwItemCDFlag & TBCDRF_NOEDGES)) 761 787 { … … 773 799 } 774 800 775 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDis,801 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDis, 776 802 hdc, rcBitmap.left, rcBitmap.top, 777 803 ILD_NORMAL)) … … 804 830 TOOLBAR_DrawArrow(hdc, rcArrow.left, rcArrow.top, COLOR_WINDOWFRAME); 805 831 806 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,832 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef, 807 833 hdc, rcBitmap.left+offset, rcBitmap.top+offset, 808 834 ILD_NORMAL); … … 827 853 TOOLBAR_DrawPattern (hdc, &rc); 828 854 829 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,855 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef, 830 856 hdc, rcBitmap.left+1, rcBitmap.top+1, 831 857 ILD_NORMAL); … … 888 914 889 915 if (btnPtr->bHot) { 916 HIMAGELIST himlHot = GETHOTIMAGELIST(infoPtr, 917 GETHIMLID(infoPtr, btnPtr->iBitmap)); 890 918 /* if hot, attempt to draw with himlHot, if fails, use himlDef */ 891 919 if (!TOOLBAR_DrawImageList (infoPtr, btnPtr, 892 infoPtr->himlHot,920 himlHot, 893 921 hdc, rcBitmap.left, 894 922 rcBitmap.top, ILD_NORMAL)) 895 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,923 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef, 896 924 hdc, rcBitmap.left, rcBitmap.top, 897 925 ILD_NORMAL); 898 926 } 899 927 else 900 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,928 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef, 901 929 hdc, rcBitmap.left, rcBitmap.top, 902 930 ILD_NORMAL); … … 916 944 } 917 945 918 TOOLBAR_DrawImageList (infoPtr, btnPtr, infoPtr->himlDef,946 TOOLBAR_DrawImageList (infoPtr, btnPtr, himlDef, 919 947 hdc, rcBitmap.left, rcBitmap.top, 920 948 ILD_NORMAL);} … … 953 981 /* if imagelist belongs to the app, it can be changed 954 982 by the app after setting it */ 955 if (infoPtr->himlDef != infoPtr->himlInt) 956 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef); 983 if (GETDEFIMAGELIST(infoPtr, 0) != infoPtr->himlInt) 984 { 985 infoPtr->nNumBitmaps = 0; 986 for (i = 0; i < infoPtr->cimlDef; i++) 987 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl); 988 } 957 989 958 990 TOOLBAR_DumpToolbar (infoPtr, __LINE__); … … 1408 1440 cx = sz.cx + 6 + 5 + 5; 1409 1441 if ((dwStyle & TBSTYLE_LIST) && 1410 (TOOLBAR_TestImageExist (infoPtr, btnPtr, infoPtr->himlDef)))1442 (TOOLBAR_TestImageExist (infoPtr, btnPtr, GETDEFIMAGELIST(infoPtr,0)))) 1411 1443 cx += infoPtr->nBitmapWidth; 1412 1444 } … … 1646 1678 if (custInfo) 1647 1679 { 1648 charBuffer[256];1680 WCHAR Buffer[256]; 1649 1681 int i = 0; 1650 1682 int index; … … 1658 1690 return FALSE; 1659 1691 1692 /* Send TBN_INITCUSTOMIZE notification */ 1693 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_INITCUSTOMIZE) == 1694 TBNRF_HIDEHELP) 1695 { 1696 FIXME("TBNRF_HIDEHELP not supported\n"); 1697 } 1698 1660 1699 /* add items to 'toolbar buttons' list and check if removable */ 1661 1700 for (i = 0; i < custInfo->tbInfo->nNumButtons; i++) 1662 1701 { 1663 1702 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON)); 1664 1665 1666 1667 LoadString A(COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);1703 memset (&btnInfo->btn, 0, sizeof(TBBUTTON)); 1704 btnInfo->btn.fsStyle = TBSTYLE_SEP; 1705 btnInfo->bVirtual = FALSE; 1706 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64); 1668 1707 1669 1708 /* send TBN_QUERYDELETE notification */ 1670 nmtb.iItem = i; 1671 btnInfo->bRemovable = TOOLBAR_SendNotify ((NMHDR *) &nmtb, 1672 infoPtr, 1673 TBN_QUERYDELETE); 1709 btnInfo->bRemovable = TOOLBAR_IsButtonRemovable(infoPtr, i, btnInfo); 1674 1710 1675 1711 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, 0); … … 1683 1719 btnInfo->bVirtual = FALSE; 1684 1720 btnInfo->bRemovable = TRUE; 1685 LoadString A(COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);1721 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64); 1686 1722 index = (int)SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo); 1687 1723 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo); … … 1691 1727 { 1692 1728 /* send TBN_GETBUTTONINFO notification */ 1729 NMTOOLBARW nmtb; 1693 1730 nmtb.iItem = i; 1694 1731 nmtb.pszText = Buffer; 1695 1732 nmtb.cchText = 256; 1696 1733 1697 if (!TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_GETBUTTONINFOA)) 1734 /* Clear previous button's text */ 1735 ZeroMemory(nmtb.pszText, nmtb.cchText * sizeof(WCHAR)); 1736 1737 if (!TOOLBAR_GetButtonInfo(infoPtr, &nmtb)) 1698 1738 break; 1699 1739 1700 TRACE("style: %x\n", nmtb.tbButton.fsStyle); 1740 TRACE("WM_INITDIALOG style: %x iItem(%d) idCommand(%d) iString(%d) %s\n", 1741 nmtb.tbButton.fsStyle, i, 1742 nmtb.tbButton.idCommand, 1743 nmtb.tbButton.iString, 1744 nmtb.tbButton.iString >= 0 ? debugstr_w(infoPtr->strings[nmtb.tbButton.iString]) 1745 : ""); 1701 1746 1702 1747 /* insert button into the apropriate list */ … … 1705 1750 { 1706 1751 btnInfo = (PCUSTOMBUTTON)COMCTL32_Alloc(sizeof(CUSTOMBUTTON)); 1707 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON));1708 1752 btnInfo->bVirtual = FALSE; 1709 1753 btnInfo->bRemovable = TRUE; 1710 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP))1711 strcpy (btnInfo->text, nmtb.pszText);1712 1754 1713 1755 index = SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_ADDSTRING, 0, 0); 1714 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo); 1756 SendDlgItemMessageA (hwnd, IDC_AVAILBTN_LBOX, 1757 LB_SETITEMDATA, index, (LPARAM)btnInfo); 1715 1758 } 1716 1759 else 1717 1760 { 1718 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0); 1719 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON)); 1720 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP)) 1721 strcpy (btnInfo->text, nmtb.pszText); 1722 1723 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo); 1761 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, 1762 IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0); 1763 } 1764 1765 memcpy (&btnInfo->btn, &nmtb.tbButton, sizeof(TBBUTTON)); 1766 if (!(nmtb.tbButton.fsStyle & TBSTYLE_SEP)) 1767 { 1768 if (lstrlenW(nmtb.pszText)) 1769 lstrcpyW(btnInfo->text, nmtb.pszText); 1770 else if (nmtb.tbButton.iString >= 0 && 1771 nmtb.tbButton.iString < infoPtr->nNumStrings) 1772 { 1773 lstrcpyW(btnInfo->text, 1774 infoPtr->strings[nmtb.tbButton.iString]); 1775 } 1724 1776 } 1725 1777 } … … 1734 1786 btnInfo->bVirtual = TRUE; 1735 1787 btnInfo->bRemovable = FALSE; 1736 LoadString A(COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64);1788 LoadStringW (COMCTL32_hModule, IDS_SEPARATOR, btnInfo->text, 64); 1737 1789 index = (int)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_ADDSTRING, 0, (LPARAM)btnInfo); 1738 1790 SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_SETITEMDATA, index, (LPARAM)btnInfo); … … 1882 1934 1883 1935 index = SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETCURSEL, 0, 0); 1936 1937 if (LB_ERR == index) 1938 break; 1939 1884 1940 TRACE("Remove: index %d\n", index); 1885 1941 1942 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, 1943 LB_GETITEMDATA, index, 0); 1944 1886 1945 /* send TBN_QUERYDELETE notification */ 1887 nmtb.iItem = index; 1888 if (TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, 1889 TBN_QUERYDELETE)) 1946 if (TOOLBAR_IsButtonRemovable(infoPtr, index, btnInfo)) 1890 1947 { 1891 1948 btnInfo = (PCUSTOMBUTTON)SendDlgItemMessageA (hwnd, IDC_TOOLBARBTN_LBOX, LB_GETITEMDATA, index, 0); … … 1990 2047 { 1991 2048 LPDRAWITEMSTRUCT lpdis = (LPDRAWITEMSTRUCT)lParam; 2049 DWORD dwStyle = GetWindowLongA (infoPtr->hwndSelf, GWL_STYLE); 1992 2050 RECT rcButton; 1993 2051 RECT rcText; … … 2032 2090 2033 2091 /* draw button */ 2092 if (!(dwStyle & TBSTYLE_FLAT)) 2034 2093 DrawEdge (lpdis->hDC, &rcButton, EDGE_RAISED, BF_RECT|BF_MIDDLE|BF_SOFT); 2035 2094 2036 2095 /* draw image and text */ 2037 if ((btnInfo->btn.fsStyle & TBSTYLE_SEP) == 0) 2038 ImageList_Draw (custInfo->tbInfo->himlDef, btnInfo->btn.iBitmap, lpdis->hDC, 2039 rcButton.left+3, rcButton.top+3, ILD_NORMAL); 2040 DrawTextA (lpdis->hDC, btnInfo->text, -1, &rcText, 2096 if ((btnInfo->btn.fsStyle & TBSTYLE_SEP) == 0) { 2097 HIMAGELIST himl = GETDEFIMAGELIST(infoPtr, GETHIMLID(infoPtr, 2098 btnInfo->btn.iBitmap)); 2099 ImageList_Draw (himl, GETIBITMAP(infoPtr, btnInfo->btn.iBitmap), 2100 lpdis->hDC, rcButton.left+3, rcButton.top+3, ILD_NORMAL); 2101 } 2102 DrawTextW (lpdis->hDC, btnInfo->text, -1, &rcText, 2041 2103 DT_LEFT | DT_VCENTER | DT_SINGLELINE); 2042 2104 … … 2082 2144 INT nIndex = 0, nButtons, nCount; 2083 2145 HBITMAP hbmLoad; 2146 HIMAGELIST himlDef; 2084 2147 2085 2148 TRACE("hwnd=%p wParam=%x lParam=%lx\n", hwnd, wParam, lParam); … … 2132 2195 } 2133 2196 2134 if (! (infoPtr->himlDef)) {2197 if (!infoPtr->cimlDef) { 2135 2198 /* create new default image list */ 2136 2199 TRACE ("creating default image list!\n"); 2137 2200 2138 infoPtr->himlDef = 2139 ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, 2140 ILC_COLOR | ILC_MASK, nButtons, 2); 2141 infoPtr->himlInt = infoPtr->himlDef; 2142 } 2143 2144 nCount = ImageList_GetImageCount(infoPtr->himlDef); 2201 himlDef = ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, 2202 ILC_COLOR | ILC_MASK, nButtons, 2); 2203 TOOLBAR_InsertImageList(&infoPtr->himlDef, &infoPtr->cimlDef, himlDef, 0); 2204 infoPtr->himlInt = himlDef; 2205 } 2206 else { 2207 himlDef = GETDEFIMAGELIST(infoPtr, 0); 2208 } 2209 2210 if (!himlDef) { 2211 WARN("No default image list available\n"); 2212 return -1; 2213 } 2214 2215 nCount = ImageList_GetImageCount(himlDef); 2145 2216 2146 2217 /* Add bitmaps to the default image list */ 2147 if (lpAddBmp->hInst == (HINSTANCE)0)2218 if (lpAddBmp->hInst == NULL) 2148 2219 { 2149 nIndex = 2150 ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID, 2151 CLR_DEFAULT); 2220 BITMAP bmp; 2221 HBITMAP hOldBitmapBitmap, hOldBitmapLoad; 2222 HDC hdcImage, hdcBitmap; 2223 2224 /* copy the bitmap before adding it so that the user's bitmap 2225 * doesn't get modified. 2226 */ 2227 GetObjectA ((HBITMAP)lpAddBmp->nID, sizeof(BITMAP), (LPVOID)&bmp); 2228 2229 hdcImage = CreateCompatibleDC(0); 2230 hdcBitmap = CreateCompatibleDC(0); 2231 2232 /* create new bitmap */ 2233 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL); 2234 hOldBitmapBitmap = SelectObject(hdcBitmap, (HBITMAP)lpAddBmp->nID); 2235 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad); 2236 2237 /* Copy the user's image */ 2238 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, 2239 hdcBitmap, 0, 0, SRCCOPY); 2240 2241 SelectObject (hdcImage, hOldBitmapLoad); 2242 SelectObject (hdcBitmap, hOldBitmapBitmap); 2243 DeleteDC (hdcImage); 2244 DeleteDC (hdcBitmap); 2245 2246 nIndex = ImageList_AddMasked (himlDef, hbmLoad, CLR_DEFAULT); 2247 DeleteObject (hbmLoad); 2152 2248 } 2153 2249 else if (lpAddBmp->hInst == HINST_COMMCTRL) … … 2159 2255 hbmLoad = LoadBitmapA (COMCTL32_hModule, 2160 2256 MAKEINTRESOURCEA(IDB_STD_SMALL)); 2161 nIndex = ImageList_AddMasked ( infoPtr->himlDef,2257 nIndex = ImageList_AddMasked (himlDef, 2162 2258 hbmLoad, CLR_DEFAULT); 2163 2259 DeleteObject (hbmLoad); … … 2167 2263 hbmLoad = LoadBitmapA (COMCTL32_hModule, 2168 2264 MAKEINTRESOURCEA(IDB_STD_LARGE)); 2169 nIndex = ImageList_AddMasked ( infoPtr->himlDef,2265 nIndex = ImageList_AddMasked (himlDef, 2170 2266 hbmLoad, CLR_DEFAULT); 2171 2267 DeleteObject (hbmLoad); … … 2175 2271 hbmLoad = LoadBitmapA (COMCTL32_hModule, 2176 2272 MAKEINTRESOURCEA(IDB_VIEW_SMALL)); 2177 nIndex = ImageList_AddMasked ( infoPtr->himlDef,2273 nIndex = ImageList_AddMasked (himlDef, 2178 2274 hbmLoad, CLR_DEFAULT); 2179 2275 DeleteObject (hbmLoad); … … 2183 2279 hbmLoad = LoadBitmapA (COMCTL32_hModule, 2184 2280 MAKEINTRESOURCEA(IDB_VIEW_LARGE)); 2185 nIndex = ImageList_AddMasked ( infoPtr->himlDef,2281 nIndex = ImageList_AddMasked (himlDef, 2186 2282 hbmLoad, CLR_DEFAULT); 2187 2283 DeleteObject (hbmLoad); … … 2191 2287 hbmLoad = LoadBitmapA (COMCTL32_hModule, 2192 2288 MAKEINTRESOURCEA(IDB_HIST_SMALL)); 2193 nIndex = ImageList_AddMasked ( infoPtr->himlDef,2289 nIndex = ImageList_AddMasked (himlDef, 2194 2290 hbmLoad, CLR_DEFAULT); 2195 2291 DeleteObject (hbmLoad); … … 2199 2295 hbmLoad = LoadBitmapA (COMCTL32_hModule, 2200 2296 MAKEINTRESOURCEA(IDB_HIST_LARGE)); 2201 nIndex = ImageList_AddMasked ( infoPtr->himlDef,2297 nIndex = ImageList_AddMasked (himlDef, 2202 2298 hbmLoad, CLR_DEFAULT); 2203 2299 DeleteObject (hbmLoad); … … 2205 2301 2206 2302 default: 2207 nIndex = ImageList_GetImageCount ( infoPtr->himlDef);2303 nIndex = ImageList_GetImageCount (himlDef); 2208 2304 ERR ("invalid imagelist!\n"); 2209 2305 break; … … 2213 2309 { 2214 2310 hbmLoad = LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID); 2215 nIndex = ImageList_AddMasked ( infoPtr->himlDef, hbmLoad, CLR_DEFAULT);2311 nIndex = ImageList_AddMasked (himlDef, hbmLoad, CLR_DEFAULT); 2216 2312 DeleteObject (hbmLoad); 2217 2313 } … … 2239 2335 if (nIndex != -1) 2240 2336 { 2241 INT imagecount = ImageList_GetImageCount( infoPtr->himlDef);2337 INT imagecount = ImageList_GetImageCount(himlDef); 2242 2338 2243 2339 if (infoPtr->nNumBitmaps + nButtons != imagecount) … … 2921 3017 lpTbb->fsState = btnPtr->fsState; 2922 3018 lpTbb->fsStyle = btnPtr->fsStyle; 3019 lpTbb->bReserved[0] = 0; 3020 lpTbb->bReserved[1] = 0; 2923 3021 lpTbb->dwData = btnPtr->dwData; 2924 3022 lpTbb->iString = btnPtr->iString; … … 3075 3173 TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam) 3076 3174 { 3077 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); 3078 3079 return (LRESULT)infoPtr->himlDis; 3175 return (LRESULT)GETDISIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), 0); 3080 3176 } 3081 3177 … … 3093 3189 TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam) 3094 3190 { 3095 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); 3096 3097 return (LRESULT)infoPtr->himlHot; 3191 return (LRESULT)GETHOTIMAGELIST(TOOLBAR_GetInfoPtr (hwnd), 0); 3098 3192 } 3099 3193 … … 3115 3209 3116 3210 static LRESULT 3117 TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam) 3118 { 3119 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); 3120 3121 return (LRESULT)infoPtr->himlDef; 3211 TOOLBAR_GetDefImageList (HWND hwnd, WPARAM wParam, LPARAM lParam) 3212 { 3213 return (LRESULT) GETDEFIMAGELIST(TOOLBAR_GetInfoPtr(hwnd), 0); 3122 3214 } 3123 3215 … … 3168 3260 lpSize->cy = infoPtr->rcBound.bottom - infoPtr->rcBound.top; 3169 3261 3170 TRACE("maximum size % d x %d\n",3262 TRACE("maximum size %ld x %ld\n", 3171 3263 infoPtr->rcBound.right - infoPtr->rcBound.left, 3172 3264 infoPtr->rcBound.bottom - infoPtr->rcBound.top); … … 3680 3772 HBITMAP hBitmap; 3681 3773 int i = 0, nOldButtons = 0, pos = 0; 3774 HIMAGELIST himlDef = 0; 3682 3775 3683 3776 TRACE("hInstOld %p nIDOld %x hInstNew %p nIDNew %x nButtons %x\n", … … 3725 3818 infoPtr->nNumBitmaps = infoPtr->nNumBitmaps - nOldButtons + lpReplace->nButtons; 3726 3819 3727 /* ImageList_Replace(infoPtr->himlDef, pos, hBitmap, NULL); */ 3728 3729 3820 /* ImageList_Replace(GETDEFIMAGELIST(), pos, hBitmap, NULL); */ 3821 3822 3823 himlDef = GETDEFIMAGELIST(infoPtr, 0); 3730 3824 for (i = pos + nOldButtons - 1; i >= pos; i--) { 3731 ImageList_Remove(infoPtr->himlDef, i); 3732 } 3733 3734 ImageList_AddMasked(infoPtr->himlDef, hBitmap, CLR_DEFAULT); 3825 ImageList_Remove(himlDef, i); 3826 } 3827 3828 { 3829 BITMAP bmp; 3830 HBITMAP hOldBitmapBitmap, hOldBitmapLoad, hbmLoad; 3831 HDC hdcImage, hdcBitmap; 3832 3833 /* copy the bitmap before adding it so that the user's bitmap 3834 * doesn't get modified. 3835 */ 3836 GetObjectA (hBitmap, sizeof(BITMAP), (LPVOID)&bmp); 3837 3838 hdcImage = CreateCompatibleDC(0); 3839 hdcBitmap = CreateCompatibleDC(0); 3840 3841 /* create new bitmap */ 3842 hbmLoad = CreateBitmap (bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes, bmp.bmBitsPixel, NULL); 3843 hOldBitmapBitmap = SelectObject(hdcBitmap, hBitmap); 3844 hOldBitmapLoad = SelectObject(hdcImage, hbmLoad); 3845 3846 /* Copy the user's image */ 3847 BitBlt (hdcImage, 0, 0, bmp.bmWidth, bmp.bmHeight, 3848 hdcBitmap, 0, 0, SRCCOPY); 3849 3850 SelectObject (hdcImage, hOldBitmapLoad); 3851 SelectObject (hdcBitmap, hOldBitmapBitmap); 3852 DeleteDC (hdcImage); 3853 DeleteDC (hdcBitmap); 3854 3855 ImageList_AddMasked (himlDef, hbmLoad, CLR_DEFAULT); 3856 DeleteObject (hbmLoad); 3857 } 3735 3858 3736 3859 InvalidateRect(hwnd, NULL, FALSE); … … 3816 3939 { 3817 3940 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); 3941 HIMAGELIST himlDef = GETDEFIMAGELIST(infoPtr, 0); 3818 3942 3819 3943 if ((LOWORD(lParam) <= 0) || (HIWORD(lParam)<=0)) … … 3829 3953 infoPtr->nBitmapHeight = (INT)HIWORD(lParam); 3830 3954 3955 3831 3956 /* uses image list internals directly */ 3832 if ( infoPtr->himlDef) {3833 infoPtr->himlDef->cx = infoPtr->nBitmapWidth;3834 infoPtr->himlDef->cy = infoPtr->nBitmapHeight;3957 if (himlDef) { 3958 himlDef->cx = infoPtr->nBitmapWidth; 3959 himlDef->cy = infoPtr->nBitmapHeight; 3835 3960 } 3836 3961 … … 4020 4145 { 4021 4146 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); 4147 HIMAGELIST himl = (HIMAGELIST)lParam; 4022 4148 HIMAGELIST himlTemp; 4023 4024 4025 if (wParam != 0) { 4026 FIXME("no support for multiple image lists\n"); 4027 return 0; 4028 } 4029 4030 himlTemp = infoPtr->himlDis; 4031 infoPtr->himlDis = (HIMAGELIST)lParam; 4149 INT id = 0; 4150 4151 if (infoPtr->iVersion >= 5) 4152 id = wParam; 4153 4154 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDis, 4155 &infoPtr->cimlDis, himl, id); 4032 4156 4033 4157 /* FIXME: redraw ? */ … … 4081 4205 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd); 4082 4206 HIMAGELIST himlTemp; 4083 4084 if (wParam != 0) {4085 FIXME("no support for multiple image lists\n"); 4086 return 0; 4087 }4088 4089 himlTemp = infoPtr->himlHot;4090 infoPtr->himlHot = (HIMAGELIST)lParam;4207 HIMAGELIST himl = (HIMAGELIST)lParam; 4208 INT id = 0; 4209 4210 if (infoPtr->iVersion >= 5) 4211 id = wParam; 4212 4213 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlHot, 4214 &infoPtr->cimlHot, himl, id); 4091 4215 4092 4216 /* FIXME: redraw ? */ … … 4138 4262 TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); 4139 4263 HIMAGELIST himlTemp; 4140 4141 if (wParam != 0) { 4142 FIXME("no support for multiple image lists\n"); 4143 return 0; 4144 } 4145 4146 himlTemp = infoPtr->himlDef; 4147 infoPtr->himlDef = (HIMAGELIST)lParam; 4148 4149 infoPtr->nNumBitmaps = ImageList_GetImageCount(infoPtr->himlDef); 4150 4151 ImageList_GetIconSize(infoPtr->himlDef, &infoPtr->nBitmapWidth, 4264 HIMAGELIST himl = (HIMAGELIST)lParam; 4265 INT i, id = 0; 4266 4267 if (infoPtr->iVersion >= 5) 4268 id = wParam; 4269 4270 himlTemp = TOOLBAR_InsertImageList(&infoPtr->himlDef, 4271 &infoPtr->cimlDef, himl, id); 4272 4273 infoPtr->nNumBitmaps = 0; 4274 for (i = 0; i < infoPtr->cimlDef; i++) 4275 infoPtr->nNumBitmaps += ImageList_GetImageCount(infoPtr->himlDef[i]->himl); 4276 4277 ImageList_GetIconSize(himl, &infoPtr->nBitmapWidth, 4152 4278 &infoPtr->nBitmapHeight); 4153 4279 TRACE("hwnd %p, new himl=%08x, count=%d, bitmap w=%d, h=%d\n", … … 4407 4533 4408 4534 infoPtr->iVersion = iVersion; 4535 4536 if (infoPtr->iVersion >= 5) 4537 TOOLBAR_SetUnicodeFormat(hwnd, (WPARAM)TRUE, (LPARAM)0); 4409 4538 4410 4539 return iOldVersion; … … 4497 4626 GetWindowRect(hwnd, &rc); 4498 4627 MapWindowPoints(0, hwndParent, (LPPOINT)&rc, 2); 4499 TRACE("mapped to (% d,%d)-(%d,%d)\n",4628 TRACE("mapped to (%ld,%ld)-(%ld,%ld)\n", 4500 4629 rc.left, rc.top, rc.right, rc.bottom); 4501 4630 lpsize->cx = max(rc.right-rc.left, … … 4617 4746 if (infoPtr->himlInt) 4618 4747 ImageList_Destroy (infoPtr->himlInt); 4748 4749 TOOLBAR_DeleteImageList(&infoPtr->himlDef, &infoPtr->cimlDef); 4750 TOOLBAR_DeleteImageList(&infoPtr->himlDis, &infoPtr->cimlDis); 4751 TOOLBAR_DeleteImageList(&infoPtr->himlHot, &infoPtr->cimlHot); 4619 4752 4620 4753 /* delete default font */ … … 5312 5445 hdc = wParam==0 ? BeginPaint(hwnd, &ps) : (HDC)wParam; 5313 5446 5314 TRACE("psrect=(% d,%d)-(%d,%d)\n",5447 TRACE("psrect=(%ld,%ld)-(%ld,%ld)\n", 5315 5448 ps.rcPaint.left, ps.rcPaint.top, 5316 5449 ps.rcPaint.right, ps.rcPaint.bottom); … … 5568 5701 5569 5702 case TB_GETIMAGELIST: 5570 return TOOLBAR_Get ImageList (hwnd, wParam, lParam);5703 return TOOLBAR_GetDefImageList (hwnd, wParam, lParam); 5571 5704 5572 5705 /* case TB_GETINSERTMARK: */ /* 4.71 */ … … 5874 6007 TOOLBAR_Unregister (void) 5875 6008 { 5876 UnregisterClassA (TOOLBARCLASSNAMEA, (HINSTANCE)NULL); 5877 } 6009 UnregisterClassA (TOOLBARCLASSNAMEA, NULL); 6010 } 6011 6012 static HIMAGELIST TOOLBAR_InsertImageList(PIMLENTRY **pies, INT *cies, HIMAGELIST himl, INT id) 6013 { 6014 HIMAGELIST himlold; 6015 PIMLENTRY c = NULL; 6016 6017 /* Check if the entry already exists */ 6018 c = TOOLBAR_GetImageListEntry(*pies, *cies, id); 6019 6020 /* If this is a new entry we must create it and insert into the array */ 6021 if (!c) 6022 { 6023 PIMLENTRY *pnies; 6024 6025 c = (PIMLENTRY) COMCTL32_Alloc(sizeof(IMLENTRY)); 6026 c->id = id; 6027 6028 pnies = COMCTL32_Alloc((*cies + 1) * sizeof(PIMLENTRY)); 6029 memcpy(pnies, *pies, ((*cies) * sizeof(PIMLENTRY))); 6030 pnies[*cies] = c; 6031 (*cies)++; 6032 6033 COMCTL32_Free(*pies); 6034 *pies = pnies; 6035 } 6036 6037 himlold = c->himl; 6038 c->himl = himl; 6039 6040 return himlold; 6041 } 6042 6043 6044 static VOID TOOLBAR_DeleteImageList(PIMLENTRY **pies, INT *cies) 6045 { 6046 int i; 6047 6048 for (i = 0; i < *cies; i++) 6049 COMCTL32_Free((*pies)[i]); 6050 6051 COMCTL32_Free(*pies); 6052 6053 *cies = 0; 6054 *pies = NULL; 6055 } 6056 6057 6058 static PIMLENTRY TOOLBAR_GetImageListEntry(PIMLENTRY *pies, INT cies, INT id) 6059 { 6060 PIMLENTRY c = NULL; 6061 6062 if (pies != NULL) 6063 { 6064 int i; 6065 6066 for (i = 0; i < cies; i++) 6067 { 6068 if (pies[i]->id == id) 6069 { 6070 c = pies[i]; 6071 break; 6072 } 6073 } 6074 } 6075 6076 return c; 6077 } 6078 6079 6080 static HIMAGELIST TOOLBAR_GetImageList(PIMLENTRY *pies, INT cies, INT id) 6081 { 6082 HIMAGELIST himlDef = 0; 6083 PIMLENTRY pie = TOOLBAR_GetImageListEntry(pies, cies, id); 6084 6085 if (pie) 6086 himlDef = pie->himl; 6087 6088 return himlDef; 6089 } 6090 6091 6092 static BOOL TOOLBAR_GetButtonInfo(TOOLBAR_INFO *infoPtr, NMTOOLBARW *nmtb) 6093 { 6094 if (infoPtr->bUnicode) 6095 return TOOLBAR_SendNotify ((NMHDR *) nmtb, infoPtr, TBN_GETBUTTONINFOW); 6096 else 6097 { 6098 CHAR Buffer[256]; 6099 NMTOOLBARA nmtba; 6100 BOOL bRet = FALSE; 6101 6102 nmtba.iItem = nmtb->iItem; 6103 nmtba.pszText = Buffer; 6104 nmtba.cchText = 256; 6105 ZeroMemory(nmtba.pszText, nmtba.cchText); 6106 6107 if (TOOLBAR_SendNotify ((NMHDR *) &nmtba, infoPtr, TBN_GETBUTTONINFOA)) 6108 { 6109 int ccht = strlen(nmtba.pszText); 6110 if (ccht) 6111 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)nmtba.pszText, -1, 6112 nmtb->pszText, nmtb->cchText); 6113 6114 memcpy(&nmtb->tbButton, &nmtba.tbButton, sizeof(TBBUTTON)); 6115 bRet = TRUE; 6116 } 6117 6118 return bRet; 6119 } 6120 } 6121 6122 6123 static BOOL TOOLBAR_IsButtonRemovable(TOOLBAR_INFO *infoPtr, 6124 int iItem, PCUSTOMBUTTON btnInfo) 6125 { 6126 NMTOOLBARA nmtb; 6127 6128 nmtb.iItem = iItem; 6129 memcpy(&nmtb.tbButton, &btnInfo->btn, sizeof(TBBUTTON)); 6130 6131 return TOOLBAR_SendNotify ((NMHDR *) &nmtb, infoPtr, TBN_QUERYDELETE); 6132 }
Note:
See TracChangeset
for help on using the changeset viewer.