📄 rebar.c
字号:
TRACE(" clrF=0x%06x clrB=0x%06x", pB->clrFore, pB->clrBack);
TRACE("\n");
TRACE("band # %u: mask=0x%08x (%s)\n", i, pB->fMask, REBAR_FmtMask(pB->fMask));
if (pB->fMask & RBBIM_STYLE)
TRACE("band # %u: style=0x%08x (%s)\n",
i, pB->fStyle, REBAR_FmtStyle(pB->fStyle));
TRACE("band # %u: xHeader=%u",
i, pB->cxHeader);
if (pB->fMask & (RBBIM_SIZE | RBBIM_IDEALSIZE | RBBIM_LPARAM )) {
if (pB->fMask & RBBIM_SIZE)
TRACE(" cx=%u", pB->cx);
if (pB->fMask & RBBIM_IDEALSIZE)
TRACE(" xIdeal=%u", pB->cxIdeal);
if (pB->fMask & RBBIM_LPARAM)
TRACE(" lParam=0x%08lx", pB->lParam);
}
TRACE("\n");
if (RBBIM_CHILDSIZE)
TRACE("band # %u: xMin=%u, yMin=%u, yChild=%u, yMax=%u, yIntgl=%u\n",
i, pB->cxMinChild, pB->cyMinChild, pB->cyChild, pB->cyMaxChild, pB->cyIntegral);
if (pB->fMask & RBBIM_TEXT)
TRACE("band # %u: text=%s\n",
i, (pB->lpText) ? debugstr_w(pB->lpText) : "(null)");
TRACE("band # %u: lcx=%u, cxEffective=%u, lcy=%u\n",
i, pB->lcx, pB->cxEffective, pB->lcy);
TRACE("band # %u: fStatus=%08x, fDraw=%08x, Band=(%d,%d)-(%d,%d), Grip=(%d,%d)-(%d,%d)\n",
i, pB->fStatus, pB->fDraw,
pB->rcBand.left, pB->rcBand.top, pB->rcBand.right, pB->rcBand.bottom,
pB->rcGripper.left, pB->rcGripper.top, pB->rcGripper.right, pB->rcGripper.bottom);
TRACE("band # %u: Img=(%d,%d)-(%d,%d), Txt=(%d,%d)-(%d,%d), Child=(%d,%d)-(%d,%d)\n",
i,
pB->rcCapImage.left, pB->rcCapImage.top, pB->rcCapImage.right, pB->rcCapImage.bottom,
pB->rcCapText.left, pB->rcCapText.top, pB->rcCapText.right, pB->rcCapText.bottom,
pB->rcChild.left, pB->rcChild.top, pB->rcChild.right, pB->rcChild.bottom);
}
}
/* dest can be equal to src */
static void translate_rect(const REBAR_INFO *infoPtr, RECT *dest, const RECT *src)
{
if (infoPtr->dwStyle & CCS_VERT) {
int tmp;
tmp = src->left;
dest->left = src->top;
dest->top = tmp;
tmp = src->right;
dest->right = src->bottom;
dest->bottom = tmp;
} else {
*dest = *src;
}
}
static int get_rect_cx(const REBAR_INFO *infoPtr, const RECT *lpRect)
{
if (infoPtr->dwStyle & CCS_VERT)
return lpRect->bottom - lpRect->top;
return lpRect->right - lpRect->left;
}
static int get_rect_cy(const REBAR_INFO *infoPtr, const RECT *lpRect)
{
if (infoPtr->dwStyle & CCS_VERT)
return lpRect->right - lpRect->left;
return lpRect->bottom - lpRect->top;
}
static void round_child_height(REBAR_BAND *lpBand, int cyHeight)
{
int cy = 0;
if (lpBand->cyIntegral == 0)
return;
cy = max(cyHeight - (int)lpBand->cyMinChild, 0);
cy = lpBand->cyMinChild + (cy/lpBand->cyIntegral) * lpBand->cyIntegral;
cy = min(cy, lpBand->cyMaxChild);
lpBand->cyChild = cy;
}
static void
REBAR_DrawChevron (HDC hdc, INT left, INT top, INT colorRef)
{
INT x, y;
HPEN hPen, hOldPen;
if (!(hPen = CreatePen( PS_SOLID, 1, GetSysColor( colorRef )))) return;
hOldPen = SelectObject ( hdc, hPen );
x = left + 2;
y = top;
MoveToEx (hdc, x, y, NULL);
LineTo (hdc, x+5, y++); x++;
MoveToEx (hdc, x, y, NULL);
LineTo (hdc, x+3, y++); x++;
MoveToEx (hdc, x, y, NULL);
LineTo (hdc, x+1, y++);
SelectObject( hdc, hOldPen );
DeleteObject( hPen );
}
static HWND
REBAR_GetNotifyParent (const REBAR_INFO *infoPtr)
{
HWND parent, owner;
parent = infoPtr->hwndNotify;
if (!parent) {
parent = GetParent (infoPtr->hwndSelf);
owner = GetWindow (infoPtr->hwndSelf, GW_OWNER);
if (owner) parent = owner;
}
return parent;
}
static INT
REBAR_Notify (NMHDR *nmhdr, const REBAR_INFO *infoPtr, UINT code)
{
HWND parent;
parent = REBAR_GetNotifyParent (infoPtr);
nmhdr->idFrom = GetDlgCtrlID (infoPtr->hwndSelf);
nmhdr->hwndFrom = infoPtr->hwndSelf;
nmhdr->code = code;
TRACE("window %p, code=%08x, via %s\n", parent, code, (infoPtr->bUnicode)?"Unicode":"ANSI");
return SendMessageW(parent, WM_NOTIFY, (WPARAM)nmhdr->idFrom, (LPARAM)nmhdr);
}
static INT
REBAR_Notify_NMREBAR (const REBAR_INFO *infoPtr, UINT uBand, UINT code)
{
NMREBAR notify_rebar;
REBAR_BAND *lpBand;
notify_rebar.dwMask = 0;
if (uBand!=-1) {
lpBand = &infoPtr->bands[uBand];
if (lpBand->fMask & RBBIM_ID) {
notify_rebar.dwMask |= RBNM_ID;
notify_rebar.wID = lpBand->wID;
}
if (lpBand->fMask & RBBIM_LPARAM) {
notify_rebar.dwMask |= RBNM_LPARAM;
notify_rebar.lParam = lpBand->lParam;
}
if (lpBand->fMask & RBBIM_STYLE) {
notify_rebar.dwMask |= RBNM_STYLE;
notify_rebar.fStyle = lpBand->fStyle;
}
}
notify_rebar.uBand = uBand;
return REBAR_Notify ((NMHDR *)¬ify_rebar, infoPtr, code);
}
static VOID
REBAR_DrawBand (HDC hdc, const REBAR_INFO *infoPtr, REBAR_BAND *lpBand)
{
HFONT hOldFont = 0;
INT oldBkMode = 0;
NMCUSTOMDRAW nmcd;
HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
RECT rcBand;
translate_rect(infoPtr, &rcBand, &lpBand->rcBand);
if (lpBand->fDraw & DRAW_TEXT) {
hOldFont = SelectObject (hdc, infoPtr->hFont);
oldBkMode = SetBkMode (hdc, TRANSPARENT);
}
/* should test for CDRF_NOTIFYITEMDRAW here */
nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
nmcd.hdc = hdc;
nmcd.rc = rcBand;
nmcd.rc.right = lpBand->rcCapText.right;
nmcd.rc.bottom = lpBand->rcCapText.bottom;
nmcd.dwItemSpec = lpBand->wID;
nmcd.uItemState = 0;
nmcd.lItemlParam = lpBand->lParam;
lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
if (lpBand->uCDret == CDRF_SKIPDEFAULT) {
if (oldBkMode != TRANSPARENT)
SetBkMode (hdc, oldBkMode);
SelectObject (hdc, hOldFont);
return;
}
/* draw gripper */
if (lpBand->fDraw & DRAW_GRIPPER)
{
if (theme)
{
RECT rcGripper = lpBand->rcGripper;
int partId = (infoPtr->dwStyle & CCS_VERT) ? RP_GRIPPERVERT : RP_GRIPPER;
GetThemeBackgroundExtent (theme, hdc, partId, 0, &rcGripper, &rcGripper);
OffsetRect (&rcGripper, lpBand->rcGripper.left - rcGripper.left,
lpBand->rcGripper.top - rcGripper.top);
DrawThemeBackground (theme, hdc, partId, 0, &rcGripper, NULL);
}
else
DrawEdge (hdc, &lpBand->rcGripper, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
}
/* draw caption image */
if (lpBand->fDraw & DRAW_IMAGE) {
POINT pt;
/* center image */
pt.y = (lpBand->rcCapImage.bottom + lpBand->rcCapImage.top - infoPtr->imageSize.cy)/2;
pt.x = (lpBand->rcCapImage.right + lpBand->rcCapImage.left - infoPtr->imageSize.cx)/2;
ImageList_Draw (infoPtr->himl, lpBand->iImage, hdc,
pt.x, pt.y,
ILD_TRANSPARENT);
}
/* draw caption text */
if (lpBand->fDraw & DRAW_TEXT) {
/* need to handle CDRF_NEWFONT here */
INT oldBkMode = SetBkMode (hdc, TRANSPARENT);
COLORREF oldcolor = CLR_NONE;
COLORREF new;
if (lpBand->clrFore != CLR_NONE) {
new = (lpBand->clrFore == CLR_DEFAULT) ? infoPtr->clrBtnText :
lpBand->clrFore;
oldcolor = SetTextColor (hdc, new);
}
DrawTextW (hdc, lpBand->lpText, -1, &lpBand->rcCapText,
DT_CENTER | DT_VCENTER | DT_SINGLELINE);
if (oldBkMode != TRANSPARENT)
SetBkMode (hdc, oldBkMode);
if (lpBand->clrFore != CLR_NONE)
SetTextColor (hdc, oldcolor);
SelectObject (hdc, hOldFont);
}
if (!IsRectEmpty(&lpBand->rcChevron))
{
if (theme)
{
int stateId;
if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
stateId = CHEVS_PRESSED;
else if (lpBand->fDraw & DRAW_CHEVRONHOT)
stateId = CHEVS_HOT;
else
stateId = CHEVS_NORMAL;
DrawThemeBackground (theme, hdc, RP_CHEVRON, stateId, &lpBand->rcChevron, NULL);
}
else
{
if (lpBand->fDraw & DRAW_CHEVRONPUSHED)
{
DrawEdge(hdc, &lpBand->rcChevron, BDR_SUNKENOUTER, BF_RECT | BF_MIDDLE);
REBAR_DrawChevron(hdc, lpBand->rcChevron.left+1, lpBand->rcChevron.top + 11, COLOR_WINDOWFRAME);
}
else if (lpBand->fDraw & DRAW_CHEVRONHOT)
{
DrawEdge(hdc, &lpBand->rcChevron, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
}
else
REBAR_DrawChevron(hdc, lpBand->rcChevron.left, lpBand->rcChevron.top + 10, COLOR_WINDOWFRAME);
}
}
if (lpBand->uCDret == (CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYITEMDRAW)) {
nmcd.dwDrawStage = CDDS_ITEMPOSTPAINT;
nmcd.hdc = hdc;
nmcd.rc = rcBand;
nmcd.rc.right = lpBand->rcCapText.right;
nmcd.rc.bottom = lpBand->rcCapText.bottom;
nmcd.dwItemSpec = lpBand->wID;
nmcd.uItemState = 0;
nmcd.lItemlParam = lpBand->lParam;
lpBand->uCDret = REBAR_Notify ((NMHDR *)&nmcd, infoPtr, NM_CUSTOMDRAW);
}
}
static VOID
REBAR_Refresh (const REBAR_INFO *infoPtr, HDC hdc)
{
REBAR_BAND *lpBand;
UINT i;
if (!infoPtr->DoRedraw) return;
for (i = 0; i < infoPtr->uNumBands; i++) {
lpBand = &infoPtr->bands[i];
if (HIDDENBAND(lpBand)) continue;
/* now draw the band */
TRACE("[%p] drawing band %i, flags=%08x\n",
infoPtr->hwndSelf, i, lpBand->fDraw);
REBAR_DrawBand (hdc, infoPtr, lpBand);
}
}
static void
REBAR_CalcHorzBand (const REBAR_INFO *infoPtr, UINT rstart, UINT rend)
/* Function: this routine initializes all the rectangles in */
/* each band in a row to fit in the adjusted rcBand rect. */
/* *** Supports only Horizontal bars. *** */
{
REBAR_BAND *lpBand;
UINT i, xoff, yoff;
RECT work;
for(i=rstart; i<rend; i++){
lpBand = &infoPtr->bands[i];
if (HIDDENBAND(lpBand)) {
SetRect (&lpBand->rcChild,
lpBand->rcBand.right, lpBand->rcBand.top,
lpBand->rcBand.right, lpBand->rcBand.bottom);
continue;
}
/* set initial gripper rectangle */
SetRect (&lpBand->rcGripper, lpBand->rcBand.left, lpBand->rcBand.top,
lpBand->rcBand.left, lpBand->rcBand.bottom);
/* calculate gripper rectangle */
if ( lpBand->fStatus & HAS_GRIPPER) {
lpBand->fDraw |= DRAW_GRIPPER;
lpBand->rcGripper.left += REBAR_PRE_GRIPPER;
lpBand->rcGripper.right = lpBand->rcGripper.left + GRIPPER_WIDTH;
lpBand->rcGripper.top += 2;
lpBand->rcGripper.bottom -= 2;
SetRect (&lpBand->rcCapImage,
lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.top,
lpBand->rcGripper.right+REBAR_ALWAYS_SPACE, lpBand->rcBand.bottom);
}
else { /* no gripper will be drawn */
xoff = 0;
if (lpBand->fStatus & (HAS_IMAGE | HAS_TEXT))
/* if no gripper but either image or text, then leave space */
xoff = REBAR_ALWAYS_SPACE;
SetRect (&lpBand->rcCapImage,
lpBand->rcBand.left+xoff, lpBand->rcBand.top,
lpBand->rcBand.left+xoff, lpBand->rcBand.bottom);
}
/* image is visible */
if (lpBand->fStatus & HAS_IMAGE) {
lpBand->fDraw |= DRAW_IMAGE;
lpBand->rcCapImage.right += infoPtr->imageSize.cx;
lpBand->rcCapImage.bottom = lpBand->rcCapImage.top + infoPtr->imageSize.cy;
/* set initial caption text rectangle */
SetRect (&lpBand->rcCapText,
lpBand->rcCapImage.right+REBAR_POST_IMAGE, lpBand->rcBand.top+1,
lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
}
else {
/* set initial caption text rectangle */
SetRect (&lpBand->rcCapText, lpBand->rcCapImage.right, lpBand->rcBand.top+1,
lpBand->rcBand.left+lpBand->cxHeader, lpBand->rcBand.bottom-1);
}
/* text is visible */
if ((lpBand->fStatus & HAS_TEXT) && !(lpBand->fStyle & RBBS_HIDETITLE)) {
lpBand->fDraw |= DRAW_TEXT;
lpBand->rcCapText.right = max(lpBand->rcCapText.left,
lpBand->rcCapText.right-REBAR_POST_TEXT);
}
/* set initial child window rectangle if there is a child */
if (lpBand->hwndChild != NULL) {
int cyBand = lpBand->rcBand.bottom - lpBand->rcBand.top;
yoff = (cyBand - lpBand->cyChild) / 2;
SetRect (&lpBand->rcChild,
lpBand->rcBand.left + lpBand->cxHeader, lpBand->rcBand.top + yoff,
lpBand->rcBand.right - REBAR_POST_CHILD, lpBand->rcBand.top + yoff + lpBand->cyChild);
if ((lpBand->fStyle & RBBS_USECHEVRON) && (lpBand->rcChild.right - lpBand->rcChild.left < lpBand->cxIdeal))
{
lpBand->rcChild.right -= CHEVRON_WIDTH;
SetRect(&lpBand->rcChevron, lpBand->rcChild.right,
lpBand->rcChild.top, lpBand->rcChild.right + CHEVRON_WIDTH,
lpBand->rcChild.bottom);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -