Authors: Chris Morgan <cmorgan@wpi.edu>, James Abbatiello <abbeyj@wpi.edu>

Fixed various problems related to bitmaps and flat toolbars.
This commit is contained in:
Alexandre Julliard 1999-06-26 10:27:30 +00:00
parent b73d53c0d4
commit 74e77c27bd
2 changed files with 91 additions and 111 deletions

View File

@ -129,7 +129,7 @@ TOOLBAR_DrawMasked (TOOLBAR_INFO *infoPtr, TBUTTON_INFO *btnPtr,
HDC hdcImageList = CreateCompatibleDC (0); HDC hdcImageList = CreateCompatibleDC (0);
HDC hdcMask = CreateCompatibleDC (0); HDC hdcMask = CreateCompatibleDC (0);
HIMAGELIST himl = infoPtr->himlStd; HIMAGELIST himl = infoPtr->himlDef;
HBITMAP hbmMask; HBITMAP hbmMask;
/* create new bitmap */ /* create new bitmap */
@ -177,24 +177,23 @@ TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
return; return;
rc = btnPtr->rect; rc = btnPtr->rect;
/* separator */
if (btnPtr->fsStyle & TBSTYLE_SEP) { if (btnPtr->fsStyle & TBSTYLE_SEP) {
if ((dwStyle & TBSTYLE_FLAT) && (btnPtr->idCommand == 0)) if ((dwStyle & TBSTYLE_FLAT) && (btnPtr->idCommand == 0))
TOOLBAR_DrawFlatSeparator (&btnPtr->rect, hdc); TOOLBAR_DrawFlatSeparator (&rc, hdc);
return; return;
} }
/* disabled */ /* disabled */
if (!(btnPtr->fsState & TBSTATE_ENABLED)) { if (!(btnPtr->fsState & TBSTATE_ENABLED)) {
DrawEdge (hdc, &rc, EDGE_RAISED, if (!(dwStyle & TBSTYLE_FLAT))
BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST); DrawEdge (hdc, &rc, EDGE_RAISED,
BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
if (dwStyle & TBSTYLE_FLAT) {
/* if (infoPtr->himlDis) */ if (infoPtr->himlDis)
ImageList_Draw (infoPtr->himlDis, btnPtr->iBitmap, hdc, ImageList_Draw (infoPtr->himlDis, btnPtr->iBitmap, hdc,
rc.left+1, rc.top+1, ILD_NORMAL); rc.left+1, rc.top+1, ILD_NORMAL);
/* else */
/* TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1); */
}
else else
TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1); TOOLBAR_DrawMasked (infoPtr, btnPtr, hdc, rc.left+1, rc.top+1);
@ -205,13 +204,13 @@ TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
/* pressed TBSTYLE_BUTTON */ /* pressed TBSTYLE_BUTTON */
if (btnPtr->fsState & TBSTATE_PRESSED) { if (btnPtr->fsState & TBSTATE_PRESSED) {
DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST); DrawEdge (hdc, &rc, EDGE_SUNKEN, BF_RECT | BF_MIDDLE | BF_ADJUST);
ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc, ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
rc.left+2, rc.top+2, ILD_NORMAL); rc.left+2, rc.top+2, ILD_NORMAL);
TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState); TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
return; return;
} }
/* checked TBSTYLE_CHECK*/ /* checked TBSTYLE_CHECK */
if ((btnPtr->fsStyle & TBSTYLE_CHECK) && if ((btnPtr->fsStyle & TBSTYLE_CHECK) &&
(btnPtr->fsState & TBSTATE_CHECKED)) { (btnPtr->fsState & TBSTATE_CHECKED)) {
if (dwStyle & TBSTYLE_FLAT) if (dwStyle & TBSTYLE_FLAT)
@ -222,18 +221,10 @@ TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
BF_RECT | BF_MIDDLE | BF_ADJUST); BF_RECT | BF_MIDDLE | BF_ADJUST);
TOOLBAR_DrawPattern (hdc, &rc); TOOLBAR_DrawPattern (hdc, &rc);
if (dwStyle & TBSTYLE_FLAT)
{ ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
if (infoPtr->himlDef != NULL) rc.left+2, rc.top+2, ILD_NORMAL);
ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
rc.left+2, rc.top+2, ILD_NORMAL);
else
ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc,
rc.left+2, rc.top+2, ILD_NORMAL);
}
else
ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc,
rc.left+2, rc.top+2, ILD_NORMAL);
TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState); TOOLBAR_DrawString (infoPtr, btnPtr, hdc, btnPtr->fsState);
return; return;
} }
@ -249,25 +240,25 @@ TOOLBAR_DrawButton (HWND hwnd, TBUTTON_INFO *btnPtr, HDC hdc)
return; return;
} }
/* normal state */
if (dwStyle & TBSTYLE_FLAT) if (dwStyle & TBSTYLE_FLAT)
{ {
if(btnPtr->bHot) if (btnPtr->bHot)
DrawEdge (hdc, &rc, BDR_RAISEDINNER, DrawEdge (hdc, &rc, BDR_RAISEDINNER,
BF_RECT | BF_MIDDLE | BF_SOFT); BF_RECT | BF_MIDDLE | BF_SOFT);
if (btnPtr->bHot && infoPtr->himlHot)
if(infoPtr->himlDef != NULL) ImageList_Draw (infoPtr->himlHot, btnPtr->iBitmap, hdc,
ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
rc.left +2, rc.top +2, ILD_NORMAL); rc.left +2, rc.top +2, ILD_NORMAL);
else else
ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc, ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
rc.left +2, rc.top +2, ILD_NORMAL); rc.left +2, rc.top +2, ILD_NORMAL);
} }
else{ else
/* normal state */ {
DrawEdge (hdc, &rc, EDGE_RAISED, DrawEdge (hdc, &rc, EDGE_RAISED,
BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST); BF_SOFT | BF_RECT | BF_MIDDLE | BF_ADJUST);
ImageList_Draw (infoPtr->himlStd, btnPtr->iBitmap, hdc, ImageList_Draw (infoPtr->himlDef, btnPtr->iBitmap, hdc,
rc.left+1, rc.top+1, ILD_NORMAL); rc.left+1, rc.top+1, ILD_NORMAL);
} }
@ -871,75 +862,90 @@ TOOLBAR_AddBitmap (HWND hwnd, WPARAM wParam, LPARAM lParam)
{ {
TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam; LPTBADDBITMAP lpAddBmp = (LPTBADDBITMAP)lParam;
INT nIndex = 0; INT nIndex = 0, nButtons;
if ((!lpAddBmp) || ((INT)wParam <= 0)) if (!lpAddBmp)
return -1; return -1;
TRACE("adding %d bitmaps!\n", wParam); if (lpAddBmp->hInst == HINST_COMMCTRL)
{
if (!(infoPtr->himlStd)) { if ((lpAddBmp->nID & ~1) == IDB_STD_SMALL_COLOR)
/* create new standard image list */ nButtons = 15;
else if ((lpAddBmp->nID & ~1) == IDB_VIEW_SMALL_COLOR)
TRACE("creating standard image list!\n"); nButtons = 13;
else if ((lpAddBmp->nID & ~1) == IDB_HIST_SMALL_COLOR)
nButtons = 5;
else
return -1;
TRACE ("adding %d internal bitmaps!\n", nButtons);
/* Windows resize all the buttons to the size of a newly added STandard Image*/ /* Windows resize all the buttons to the size of a newly added STandard Image*/
/* TODO: The resizing should be done each time a standard image is added*/ if (lpAddBmp->nID & 1)
if (lpAddBmp->hInst == HINST_COMMCTRL)
{ {
/* large icons */
if (lpAddBmp->nID & 1) SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
{ MAKELPARAM((WORD)26, (WORD)26));
SendMessageA (hwnd, TB_SETBITMAPSIZE, 0, SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
MAKELPARAM((WORD)26, (WORD)26)); MAKELPARAM((WORD)33, (WORD)33));
SendMessageA (hwnd, TB_SETBUTTONSIZE, 0, }
MAKELPARAM((WORD)33, (WORD)33)); else
} {
else /* small icons */
{ SendMessageA (hwnd, TB_SETBITMAPSIZE, 0,
SendMessageA (hwnd, TB_SETBITMAPSIZE, 0, MAKELPARAM((WORD)16, (WORD)16));
MAKELPARAM((WORD)16, (WORD)16)); SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
MAKELPARAM((WORD)22, (WORD)22));
SendMessageA (hwnd, TB_SETBUTTONSIZE, 0,
MAKELPARAM((WORD)22, (WORD)22));
}
TOOLBAR_CalcToolbar (hwnd);
} }
TOOLBAR_CalcToolbar (hwnd);
}
else
{
nButtons = (INT)wParam;
if (nButtons <= 0)
return -1;
TRACE ("adding %d bitmaps!\n", nButtons);
}
if (!(infoPtr->himlDef)) {
/* create new default image list */
TRACE ("creating default image list!\n");
infoPtr->himlStd = infoPtr->himlDef =
ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight, ImageList_Create (infoPtr->nBitmapWidth, infoPtr->nBitmapHeight,
ILC_COLOR | ILC_MASK, (INT)wParam, 2); ILC_COLOR | ILC_MASK, nButtons, 2);
infoPtr->himlInt = infoPtr->himlDef;
} }
/* Add bitmaps to the standard image list */ /* Add bitmaps to the default image list */
if (lpAddBmp->hInst == (HINSTANCE)0) { if (lpAddBmp->hInst == (HINSTANCE)0)
{
nIndex = nIndex =
ImageList_AddMasked (infoPtr->himlStd, (HBITMAP)lpAddBmp->nID, ImageList_AddMasked (infoPtr->himlDef, (HBITMAP)lpAddBmp->nID,
CLR_DEFAULT); CLR_DEFAULT);
} }
else if (lpAddBmp->hInst == HINST_COMMCTRL) { else if (lpAddBmp->hInst == HINST_COMMCTRL)
{
/* add internal bitmaps */ /* add internal bitmaps */
FIXME ("internal bitmaps not supported!\n");
FIXME("internal bitmaps not supported!\n");
/* TODO: Resize all the buttons when a new standard image is added */
/* Hack to "add" some reserved images within the image list /* Hack to "add" some reserved images within the image list
to get the right image indices */ to get the right image indices */
nIndex = ImageList_GetImageCount (infoPtr->himlStd); nIndex = ImageList_GetImageCount (infoPtr->himlDef);
ImageList_SetImageCount (infoPtr->himlStd, nIndex + (INT)wParam); ImageList_SetImageCount (infoPtr->himlDef, nIndex + nButtons);
} }
else { else
{
HBITMAP hBmp = HBITMAP hBmp =
LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID); LoadBitmapA (lpAddBmp->hInst, (LPSTR)lpAddBmp->nID);
nIndex = ImageList_AddMasked (infoPtr->himlStd, hBmp, CLR_DEFAULT); nIndex = ImageList_AddMasked (infoPtr->himlDef, hBmp, CLR_DEFAULT);
DeleteObject (hBmp); DeleteObject (hBmp);
} }
infoPtr->nNumBitmaps += (INT)wParam; infoPtr->nNumBitmaps += nButtons;
return nIndex; return nIndex;
} }
@ -1564,10 +1570,7 @@ TOOLBAR_GetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
{ {
TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT) return (LRESULT)infoPtr->himlDis;
return (LRESULT)infoPtr->himlDis;
else
return 0;
} }
@ -1585,10 +1588,7 @@ TOOLBAR_GetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
{ {
TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT) return (LRESULT)infoPtr->himlHot;
return (LRESULT)infoPtr->himlHot;
else
return 0;
} }
@ -1600,10 +1600,7 @@ TOOLBAR_GetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
{ {
TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
if (GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT) return (LRESULT)infoPtr->himlDef;
return (LRESULT)infoPtr->himlDef;
else
return 0;
} }
@ -2176,9 +2173,6 @@ TOOLBAR_SetDisabledImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
HIMAGELIST himlTemp; HIMAGELIST himlTemp;
if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
return 0;
himlTemp = infoPtr->himlDis; himlTemp = infoPtr->himlDis;
infoPtr->himlDis = (HIMAGELIST)lParam; infoPtr->himlDis = (HIMAGELIST)lParam;
@ -2221,9 +2215,6 @@ TOOLBAR_SetHotImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd); TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr(hwnd);
HIMAGELIST himlTemp; HIMAGELIST himlTemp;
if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
return 0;
himlTemp = infoPtr->himlHot; himlTemp = infoPtr->himlHot;
infoPtr->himlHot = (HIMAGELIST)lParam; infoPtr->himlHot = (HIMAGELIST)lParam;
@ -2242,9 +2233,6 @@ TOOLBAR_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd); TOOLBAR_INFO *infoPtr = TOOLBAR_GetInfoPtr (hwnd);
HIMAGELIST himlTemp; HIMAGELIST himlTemp;
if (!(GetWindowLongA (hwnd, GWL_STYLE) & TBSTYLE_FLAT))
return 0;
himlTemp = infoPtr->himlDef; himlTemp = infoPtr->himlDef;
infoPtr->himlDef = (HIMAGELIST)lParam; infoPtr->himlDef = (HIMAGELIST)lParam;
@ -2507,17 +2495,9 @@ TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
COMCTL32_Free (infoPtr->strings); COMCTL32_Free (infoPtr->strings);
} }
/* destroy default image list */ /* destroy internal image list */
if (infoPtr->himlDef) if (infoPtr->himlInt)
ImageList_Destroy (infoPtr->himlDef); ImageList_Destroy (infoPtr->himlInt);
/* destroy disabled image list */
if (infoPtr->himlDis)
ImageList_Destroy (infoPtr->himlDis);
/* destroy hot image list */
if (infoPtr->himlHot)
ImageList_Destroy (infoPtr->himlHot);
/* delete default font */ /* delete default font */
if (infoPtr->hFont) if (infoPtr->hFont)

View File

@ -46,8 +46,8 @@ typedef struct tagTOOLBAR_INFO
INT nOldHit; INT nOldHit;
INT nHotItem; /* index of the "hot" item */ INT nHotItem; /* index of the "hot" item */
HFONT hFont; /* text font */ HFONT hFont; /* text font */
HIMAGELIST himlStd; /* standard image list for TB_ADDBITMAP command*/ HIMAGELIST himlInt; /* image list created internally */
HIMAGELIST himlDef; /* default image list for TB_SETIMAGELIST*/ HIMAGELIST himlDef; /* default image list */
HIMAGELIST himlHot; /* hot image list */ HIMAGELIST himlHot; /* hot image list */
HIMAGELIST himlDis; /* disabled image list */ HIMAGELIST himlDis; /* disabled image list */
HWND hwndToolTip; /* handle to tool tip control */ HWND hwndToolTip; /* handle to tool tip control */