Пример #1
0
void Event::GetInfo() {
    EventRep& e = *rep();
    w = World::current();
    y = 0;
    XEvent& xe = e.xevent_;
    switch (xe.type) {
    case MotionNotify:
	GetMotionInfo();
	break;
    case KeyPress:
	GetKeyInfo();
	break;
    case ButtonPress:
	GetButtonInfo(DownEvent);
	break;
    case ButtonRelease:
	GetButtonInfo(UpEvent);
	break;
    case FocusIn:
	eventType = FocusInEvent;
	break;
    case FocusOut:
	eventType = FocusOutEvent;
	break;
    case EnterNotify:
	GetCrossingInfo(EnterEvent);
	break;
    case LeaveNotify:
	GetCrossingInfo(LeaveEvent);
	break;
    }
}
Пример #2
0
HRESULT CMenuToolbarBase::GetDataFromId(INT iItem, INT* pIndex, DWORD_PTR* pData)
{
    if (pData)
        *pData = NULL;

    if (pIndex)
        *pIndex = -1;

    if (iItem < 0)
        return S_OK;

    TBBUTTONINFO info = { 0 };

    info.cbSize = sizeof(TBBUTTONINFO);
    info.dwMask = TBIF_COMMAND | TBIF_LPARAM;

    int index = GetButtonInfo(iItem, &info);
    if (index < 0)
        return E_FAIL;

    if (pIndex)
        *pIndex = index;

    if (pData)
        *pData = info.lParam;

    return S_OK;
}
Пример #3
0
void CPlayerToolBar::ArrangeControls()
{
    if (!::IsWindow(m_volctrl.m_hWnd)) {
        return;
    }

    CRect r;
    GetClientRect(&r);

    CRect br = GetBorders();

    CRect r10;
    GetItemRect(10, &r10);

    CRect vr(r.right + br.right - 60, r.top - 2, r.right + br.right + 6, r.bottom);
    m_volctrl.MoveWindow(vr);

    CRect thumbRect;
    m_volctrl.GetThumbRect(thumbRect);
    m_volctrl.MapWindowPoints(this, thumbRect);
    vr.top += std::max((r.bottom - thumbRect.bottom - 4) / 2, 0l);
    vr.left -= m_volumeMinSizeInc = MulDiv(thumbRect.Height(), 50, 19) - 50;
    m_volctrl.MoveWindow(vr);

    UINT nID;
    UINT nStyle;
    int iImage;
    GetButtonInfo(12, nID, nStyle, iImage);
    SetButtonInfo(11, GetItemID(11), TBBS_SEPARATOR, vr.left - iImage - r10.right - (r10.bottom - r10.top) + 11);
}
Пример #4
0
void CToolBarEx::OnRestore( NMHDR* pNMHDR, LRESULT* pResult )
{
    NMTBRESTORE* lpnmtb = ( NMTBRESTORE* )pNMHDR;
    if ( lpnmtb->iItem == -1 )
    {
        lpnmtb->cButtons = ( lpnmtb->cbData - sizeof( DWORD ) * 2 ) / lpnmtb->cbBytesPerRecord;
        lpnmtb->pCurrent = lpnmtb->pData;

        SetTextOptions( ( ETextOptions )*lpnmtb->pCurrent++, false );
        SetIconOptions( ( EIconOptions )*lpnmtb->pCurrent++, false );

        if ( lpnmtb->cButtons == 0 )
        {
            ReloadButtons();
            UpdateParentBandInfo();

            *pResult = 1;
            return;
        }
    }
    else
    {
        VERIFY( GetButtonInfo( lpnmtb->tbButton.idCommand, lpnmtb->tbButton ) );
    }

    *pResult = 0;
}
Пример #5
0
void CPlayerToolBar::ArrangeControls()
{
    if (!::IsWindow(m_volctrl.m_hWnd)) {
        return;
    }

    CRect r;
    GetClientRect(&r);

    CRect br = GetBorders();

    CRect r10;
    GetItemRect(10, &r10);

    CRect vr;
    m_volctrl.GetClientRect(&vr);
    CRect vr2(r.right + br.right - 60, r.bottom - 25, r.right + br.right + 6, r.bottom);
    m_volctrl.MoveWindow(vr2);

    UINT nID;
    UINT nStyle;
    int iImage;
    GetButtonInfo(12, nID, nStyle, iImage);
    SetButtonInfo(11, GetItemID(11), TBBS_SEPARATOR, vr2.left - iImage - r10.right - (r10.bottom - r10.top) + 11);
}
Пример #6
0
HRESULT CMenuToolbarBase::ChangeHotItem(CMenuToolbarBase * toolbar, INT item, DWORD dwFlags)
{
    // Ignore the change if it already matches the stored info
    if (m_hotBar == toolbar && m_hotItem == item)
        return S_FALSE;

    // Prevent a change of hot item if the change was triggered by the mouse,
    // and mouse tracking is disabled.
    if (m_disableMouseTrack && dwFlags & HICF_MOUSE)
    {
        TRACE("Hot item change prevented by DisableMouseTrack\n");
        return S_OK;
    }

    // Notify the toolbar if the hot-tracking left this toolbar
    if (m_hotBar == this && toolbar != this)
    {
        SetHotItem(-1);
    }

    TRACE("Hot item changed from %p %p, to %p %p\n", m_hotBar, m_hotItem, toolbar, item);
    m_hotBar = toolbar;
    m_hotItem = item;

    if (m_hotBar == this)
    {
        if (m_isTrackingPopup && !(m_initFlags & SMINIT_VERTICAL))
        {
            // If the menubar has an open submenu, switch to the new item's submenu immediately
            PopupItem(m_hotItem, FALSE);
        }
        else if (dwFlags & HICF_MOUSE)
        {
            // Vertical menus show/hide the submenu after a delay,
            // but only with the mouse.
            if (m_initFlags & SMINIT_VERTICAL)
            {
                DWORD elapsed = 0;
                SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &elapsed, 0);
                SetTimer(TIMERID_HOTTRACK, elapsed);
                m_timerEnabled = TRUE;
                TRACE("SetTimer called with m_hotItem=%d\n", m_hotItem);
            }
        }
        else
        {
            TBBUTTONINFO info;
            info.cbSize = sizeof(info);
            info.dwMask = 0;

            int index = GetButtonInfo(item, &info);

            SetHotItem(index);
        }
    }

    InvalidateDraw();
    return S_OK;
}
Пример #7
0
DWORD CToolBarCtrlX::GetBtnStyle(int id)
{
	TBBUTTONINFO tbbi = {0};
	tbbi.cbSize = sizeof tbbi;
	tbbi.dwMask = TBIF_STYLE;
	(void)GetButtonInfo(id, &tbbi);
	return tbbi.fsStyle;
}
Пример #8
0
int CToolBarCtrlX::GetBtnWidth(int nID)
{
	TBBUTTONINFO tbbi = {0};
	tbbi.cbSize = sizeof tbbi;
	tbbi.dwMask = TBIF_SIZE;
	(void)GetButtonInfo(nID, &tbbi);
	return tbbi.cx;
}
Пример #9
0
CString CToolBarCtrlX::GetBtnText(int nID)
{
	TCHAR szString[512];
	TBBUTTONINFO tbbi = {0};
	tbbi.cbSize = sizeof tbbi;
	tbbi.dwMask = TBIF_TEXT;
	tbbi.pszText = szString;
	tbbi.cchText = _countof(szString);
	GetButtonInfo(nID, &tbbi);
	return szString;
}
Пример #10
0
DWORD CToolBarCtrlX::RemoveBtnStyle(int id, DWORD dwStyle)
{
	TBBUTTONINFO tbbi = {0};
	tbbi.cbSize = sizeof tbbi;
	tbbi.dwMask = TBIF_STYLE;
	(void)GetButtonInfo(id, &tbbi);
	DWORD dwOldStyle = tbbi.fsStyle;
	tbbi.fsStyle &= ~dwStyle;
	SetButtonInfo(id, &tbbi);
	return dwOldStyle;
}
Пример #11
0
void CToolBarEx::ReloadButtons()
{
    // Reload buttons from internal cache
    CToolBarCtrl& tbCtrl = GetToolBarCtrl();
    for ( int nIndex = 0, nButtons = tbCtrl.GetButtonCount(); nIndex < nButtons; nIndex++ )
    {
        TBBUTTON tbinfo;
        VERIFY( tbCtrl.GetButton( 0, &tbinfo ) );
        VERIFY( GetButtonInfo( tbinfo.idCommand, tbinfo ) );
        VERIFY( tbCtrl.DeleteButton( 0 ) );
        VERIFY( tbCtrl.AddButtons( 1, &tbinfo ) );
    }
}
Пример #12
0
BOOL CPaletteBar::OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* pLResult)
{
	if (message == WM_NOTIFY)
	{
		NMHDR *pNMHDR = (NMHDR *) lParam;
		switch (pNMHDR->code)
		{
		case TBN_BEGINADJUST :
			return BeginAdjust(wParam,  lParam,  pLResult);

		case TBN_BEGINDRAG:
			return BeginDrag(wParam,  lParam,  pLResult);

		case TBN_CUSTHELP:
			return CustomizeHelp(wParam,  lParam,  pLResult);

		case TBN_ENDADJUST:
			return EndAdjust(wParam,  lParam,  pLResult);

		case TBN_ENDDRAG:
			return EndDrag(wParam,  lParam,  pLResult);

		case TBN_GETBUTTONINFO:
			return GetButtonInfo(wParam,  lParam,  pLResult);

		case TBN_QUERYDELETE:
			return QueryDelete(wParam,  lParam,  pLResult);

		case TBN_QUERYINSERT:
			return QueryInsert(wParam,  lParam,  pLResult);

		case TBN_RESET:
			return Reset(wParam, lParam,  pLResult);

		case TBN_TOOLBARCHANGE:
			return ToolBarChange(wParam, lParam, pLResult);
		}
	}

	return CToolBarCtrl::OnChildNotify(message, wParam, lParam, pLResult);
}
Пример #13
0
BOOL CFormatBar::create(CWnd *parent)
{
	if (!CreateEx(parent, TBSTYLE_FLAT,
		WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS | CBRS_SIZE_FIXED) ||
		!LoadBitmap(IDB_FORMATBAR) ||
		!SetButtons(format, sizeof(format)/sizeof(UINT)))
	{
		return FALSE;      // fail to create
	}

	for (int i = 0; i < 3; ++i) {
		UINT id, style;
		int image;
		GetButtonInfo(i, id, style, image);
		SetButtonInfo(i, id, style | TBBS_CHECKBOX, image);
	}

	SetSizes(CSize(23,22), CSize(16,16));
	PositionCombos();

	return TRUE;
}
Пример #14
0
void CMuleToolbarCtrl::ChangeTextLabelStyle(EToolbarLabelType eLabelType, bool bRefresh, bool bForceUpdateButtons)
{
	if (m_eLabelType != eLabelType || bForceUpdateButtons)
	{
		switch (eLabelType)
		{
			case NoLabels:
				SetStyle(GetStyle() & ~TBSTYLE_LIST);
				SetMaxTextRows(0);
				break;
			case LabelsBelow:
				SetStyle(GetStyle() & ~TBSTYLE_LIST);
				SetMaxTextRows(1);
				break;
			case LabelsRight:
				SetStyle(GetStyle() | TBSTYLE_LIST);
				SetMaxTextRows(1);
				break;
		}

		for (int i = 0; i < m_buttoncount; i++)
		{	
			TBBUTTONINFO tbbi = {0};
			tbbi.cbSize = sizeof(tbbi);
			tbbi.dwMask = TBIF_STYLE;
			GetButtonInfo(IDC_TOOLBARBUTTON + i, &tbbi);
			if (eLabelType == LabelsRight)
				tbbi.fsStyle |= TBSTYLE_AUTOSIZE;
			else
				tbbi.fsStyle &= ~TBSTYLE_AUTOSIZE;
			SetButtonInfo(IDC_TOOLBARBUTTON + i, &tbbi);
		}

		m_eLabelType = eLabelType;
		if (bRefresh)
			Refresh();
	}
}
void CBrowserToolbarCtrl::EnableAllButtons(BOOL bEnable)
{
	int iCount = GetButtonCount();

	int	i;
	TBBUTTONINFO	tbbi;

	ZeroMemory(&tbbi, sizeof(tbbi));
	tbbi.cbSize = sizeof(tbbi);
	tbbi.dwMask = TBIF_BYINDEX | TBIF_STATE;

	for (i = 0; i < iCount; i++)
	{
		GetButtonInfo(i, &tbbi);

		if (bEnable)
			tbbi.fsState |= TBSTATE_ENABLED;
		else
			tbbi.fsState &= ~TBSTATE_ENABLED;

		SetButtonInfo(i, &tbbi);
	}
}
Пример #16
0
void
CToolWindow::UpdateIcon()
{
	if (!m_Parent) return;
	if (!m_hWnd) return;
	CString bname = _T("XRefresh");
	int count = GetButtonCount();
	for (int i=0; i<count; i++)
	{
		TBBUTTON button;
		ZeroMemory(&button, sizeof(button));
		GetButton(i, &button);

		TBBUTTONINFO info;
		TCHAR buf[1000];
		ZeroMemory(&info, sizeof(info));
		info.cbSize = sizeof(info);
		info.dwMask = TBIF_TEXT|TBIF_IMAGE;
		info.cchText = 999;
		info.pszText = buf;
		GetButtonInfo(button.idCommand, &info);
		if (bname==buf)
		{
			if (m_Parent->IsConnected())
			{
				info.iImage = m_IconBase+0;
			}
			else
			{
				info.iImage = m_IconBase+1;
			}
			SetButtonInfo(button.idCommand, &info);
			break;
		}
	}
}
Пример #17
0
void CCustomToolBar::OnMouseMove(UINT nFlags, CPoint point) 
{
	// Check if the mouse is over one of our buttons. If so, then
	// we may need to redraw.

	// If we have the capture, then, by convention, we assume the
	// mouse is still over the button that has the capture.
	if ((CWnd::GetCapture() != this)
	 || (m_nLastButtonUnderCursor == -1))
	{
		// Remember the button that was underneath the cursor.
		int nButtonUnderCursor = -1;

		// Search for the button which is under the cursor. During
		// the search we can possible redraw two buttons: the button
		// that *was* under the cursor, and the button that is *now*
		// under the cursor. Only non-hidden, non-seprator buttons
		// are readrawn.
		int nButtons = GetToolBarCtrl().GetButtonCount();
		for (int nButton = 0; nButton < nButtons; nButton++)
		{
			// Get the bounding rectangle of the button.
			CRect crButton;
			GetItemRect(nButton, crButton);

			// Get the button information.
			UINT uButtonID;
			UINT uButtonStyleState;
			int nButtonBitmap;
			GetButtonInfo(nButton, uButtonID, uButtonStyleState, nButtonBitmap);
			WORD wButtonStyle = LOWORD(uButtonStyleState);
			WORD wButtonState = HIWORD(uButtonStyleState);

			// If the button is hidden or a separator, ignore it.
			if (((wButtonState & TBSTATE_HIDDEN) == 0)
			 && (wButtonStyle != TBSTYLE_SEP))
			{
				// Set some state variables.
				BOOL fButtonPressed ((wButtonState & TBSTATE_PRESSED) != 0);
				BOOL fButtonChecked ((wButtonState & TBSTATE_CHECKED) != 0);
				BOOL fButtonEnabled = GetToolBarCtrl().IsButtonEnabled((int)uButtonID);

				POINT ptCursor;
				::GetCursorPos(&ptCursor);
				ScreenToClient(&ptCursor);
				BOOL fButtonUnderCursor = IsActive() && crButton.PtInRect(ptCursor);

				if (fButtonUnderCursor)
				{
					// The cursor is over the current button.
					// Redraw it if necessary.
					nButtonUnderCursor = nButton;
					if (nButton != m_nLastButtonUnderCursor)
					{
						InvalidateRect(crButton, TRUE);
					}
				}
				else
				{
					// The cursor is not over the current button.
					// If this is the same button that the cursor
					// use to be over then redraw it.
					if (nButton == m_nLastButtonUnderCursor)
					{
						InvalidateRect(crButton, TRUE);
					}
				}
			}
		}

		// Remember the button underneath the cursor.
		m_nLastButtonUnderCursor = nButtonUnderCursor;
	}

	// If the user moves the mouse too fast, then it can leave the
	// toolbar without us noticing and the last button will not
	// be drawn. We use a timer to check if the mouse has left the
	// toolbar and the last button needs to be redrawn.
	KillTimer(m_uTimer);
	m_uTimer = SetTimer(1, 100, NULL);

	CToolBar::OnMouseMove(nFlags, point);
}
Пример #18
0
HRESULT CMenuToolbarBase::OnCustomDraw(LPNMTBCUSTOMDRAW cdraw, LRESULT * theResult)
{
    bool     isHot, isPopup;
    TBBUTTONINFO btni;

    switch (cdraw->nmcd.dwDrawStage)
    {
    case CDDS_PREPAINT:
        *theResult = CDRF_NOTIFYITEMDRAW;
        return S_OK;

    case CDDS_ITEMPREPAINT:
        
        // The item with an active submenu gets the CHECKED flag.
        isHot = m_hotBar == this && (int) cdraw->nmcd.dwItemSpec == m_hotItem;
        isPopup = m_popupBar == this && (int) cdraw->nmcd.dwItemSpec == m_popupItem;

        if ((m_initFlags & SMINIT_VERTICAL))
        {
            COLORREF clrText;
            HBRUSH   bgBrush;
            RECT rc = cdraw->nmcd.rc;
            HDC hdc = cdraw->nmcd.hdc;

            // Remove HOT and CHECKED flags (will restore HOT if necessary)
            cdraw->nmcd.uItemState &= ~(CDIS_HOT | CDIS_CHECKED);

            // Decide on the colors
            if (isHot || (m_hotItem < 0 && isPopup))
            {
                cdraw->nmcd.uItemState |= CDIS_HOT;

                clrText = GetSysColor(COLOR_HIGHLIGHTTEXT);
                bgBrush = GetSysColorBrush(m_useFlatMenus ? COLOR_MENUHILIGHT : COLOR_HIGHLIGHT);
            }
            else
            {
                clrText = GetSysColor(COLOR_MENUTEXT);
                bgBrush = GetSysColorBrush(COLOR_MENU);
            }

            // Paint the background color with the selected color
            FillRect(hdc, &rc, bgBrush);

            // Set the text color in advance, this color will be assigned when the ITEMPOSTPAINT triggers
            SetTextColor(hdc, clrText);

            // Set the text color, will be used by the internal drawing code
            cdraw->clrText = clrText;
            cdraw->iListGap += 4;

            // Tell the default drawing code we don't want any fanciness, not even a background.
            *theResult = CDRF_NOTIFYPOSTPAINT | TBCDRF_NOBACKGROUND | TBCDRF_NOEDGES | TBCDRF_NOOFFSET | TBCDRF_NOMARK | 0x00800000; // FIXME: the last bit is Vista+, useful for debugging only
        }
        else
        {
            // Remove HOT and CHECKED flags (will restore HOT if necessary)
            cdraw->nmcd.uItemState &= ~CDIS_HOT;

            // Decide on the colors
            if (isHot || (m_hotItem < 0 && isPopup))
            {
                cdraw->nmcd.uItemState |= CDIS_HOT;
            }

            *theResult = 0;
        }

        return S_OK;

    case CDDS_ITEMPOSTPAINT:

        // Fetch the button style
        btni.cbSize = sizeof(btni);
        btni.dwMask = TBIF_STYLE;
        GetButtonInfo(cdraw->nmcd.dwItemSpec, &btni);

        // Check if we need to draw a submenu arrow
        if (btni.fsStyle & BTNS_DROPDOWN)
        {
            // TODO: Support RTL text modes by drawing a leftwards arrow aligned to the left of the control

            // "8" is the rightwards dropdown arrow in the Marlett font
            WCHAR text [] = L"8";

            // Configure the font to draw with Marlett, keeping the current background color as-is
            SelectObject(cdraw->nmcd.hdc, m_marlett);
            SetBkMode(cdraw->nmcd.hdc, TRANSPARENT);

            // Tweak the alignment by 1 pixel so the menu draws like the Windows start menu.
            RECT rc = cdraw->nmcd.rc;
            rc.right += 1;

            // The arrow is drawn at the right of the item's rect, aligned vertically.
            DrawTextEx(cdraw->nmcd.hdc, text, 1, &rc, DT_NOCLIP | DT_VCENTER | DT_RIGHT | DT_SINGLELINE, NULL);
        }
        *theResult = TRUE;
        return S_OK;
    }
    return S_OK;
}
Пример #19
0
void CToolBarCtrlZ::DrawItem(CDC *pDC, int iIndex, const CRect &rtItem, BOOL bHover)
{
	UINT			uItemId;
	UINT			uItemState;
	TBBUTTON		tbb;


	TCHAR			szText[1024];
	TBBUTTONINFO	tbi;
	CArray<CxImage*, CxImage*>	*parrImgs = NULL;
	CxImage			*pIconImg = NULL;		
	int				iIconTop;
	CRect			rtDraw;
	CRect			rtText;
	COLORREF		clrText;
	
	CClientRect		rtClient(this);
	rtDraw = rtItem;
	rtDraw.top = rtClient.top;
	rtDraw.bottom = rtClient.bottom;

	if (!GetButton(iIndex, &tbb))
		return;

	uItemId = tbb.idCommand;
	uItemState = GetState(uItemId);

	parrImgs = &m_arrImgs;
	if ( !IsButtonEnabled(uItemId) )
	{
		clrText = RGB(204, 128, 128);
		if (0 != m_arrDisableImgs.GetCount())
			parrImgs = &m_arrDisableImgs;
	}
	else
	{
		clrText = RGB(255, 254, 253);

		if (TBSTATE_PRESSED & uItemState/*IsButtonPressed(uItemId)*/)
			rtDraw.OffsetRect(1, 1);
		else if (bHover/*iIndex == GetHotItem()*/)
			rtDraw.OffsetRect(-1, -2);
	}


	ZeroMemory(&tbi, sizeof(TBBUTTONINFO));
	tbi.cbSize = sizeof(TBBUTTONINFO);
	tbi.dwMask = TBIF_TEXT | TBIF_IMAGE;
	tbi.pszText = szText;
	tbi.cchText = 1024;
	//if (GetButtonInfo(p->nmcd.dwItemSpec, &tbi))
	GetButtonInfo(uItemId, &tbi);
	{

		rtText = rtDraw;

		if (tbi.iImage < parrImgs->GetCount())
		{
			pIconImg = parrImgs->GetAt(tbi.iImage);
			if (NULL != pIconImg)
			{
				iIconTop = rtDraw.Height() - pIconImg->GetHeight();
				iIconTop /= 2;
				iIconTop += rtDraw.top;
				pIconImg->Draw(pDC->GetSafeHdc(), rtDraw.left, iIconTop);
				rtText.left += pIconImg->GetWidth() + 4;
			}
		}


		{
			CWndFontDC	fontDC(pDC->GetSafeHdc(), GetSafeHwnd());
			CTextDC		textDC(pDC->GetSafeHdc(), clrText);
			
			pDC->DrawText(tbi.pszText, -1, &rtText, DT_LEFT | DT_VCENTER | DT_SINGLELINE);
		}
	}

}
Пример #20
0
void CCustomToolBar::OnPaint() 
{
	//////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////
	// Copied from CToolBar::OnPaint()

	if (m_bDelayedButtonLayout)
	{
		m_bDelayedButtonLayout = FALSE;
		BOOL bHorz = (m_dwStyle & CBRS_ORIENT_HORZ) != 0;
		if ((m_dwStyle & CBRS_FLOATING) && (m_dwStyle & CBRS_SIZE_DYNAMIC))
			CalcDynamicLayout(0, LM_HORZ | LM_MRUWIDTH | LM_COMMIT);
		else if (bHorz)
 			CalcDynamicLayout(0, LM_HORZ | LM_HORZDOCK | LM_COMMIT);
		else
			CalcDynamicLayout(0, LM_VERTDOCK | LM_COMMIT);
	}

	//////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////

	// Get the rectangle we're going to be drawing.
	CRect crUpdate;
	if (GetUpdateRect(crUpdate))
	{
		// Get the actual device context we will be painting onto.
		CPaintDC dc(this);

		// Select out palette into the DC.
		CPalette* pOldPalette;
		SelectPalette(dc, pOldPalette, FALSE);

		// We construct an offscreen bitmap with the contents
		// to copy onto the final DC. This should avoid all flicker.

		// Create a DC for the offscreen bitmap.
		CDC dcOffScreen;
		if (dcOffScreen.CreateCompatibleDC(&dc))
		{
			// Create the offscreen bitmap in a format compatible
			// with the destination DC.
			CBitmap OffScreenBitmap;
			if (OffScreenBitmap.CreateCompatibleBitmap(&dc, crUpdate.Width(), crUpdate.Height()))
			{
				// Select our palette into the offscreen DC.
				CPalette* pOldOffScreenPalette;
				SelectPalette(dcOffScreen, pOldOffScreenPalette, TRUE);

				// Select the bitmap into the DC.
				CBitmap* pOldBitmap = dcOffScreen.SelectObject(&OffScreenBitmap);
				if (pOldBitmap != NULL)
				{
					// Offset the origin of the offscreen DC to match
					// the coordinate system of the final destination DC.
					dcOffScreen.OffsetWindowOrg(crUpdate.left, crUpdate.top);

					// Draw the background (DrawBackground() is virtual.)
					DrawBackground(dcOffScreen, crUpdate, CSize(0,0));

					int nButtons = GetToolBarCtrl().GetButtonCount();

					for (int nButton = 0; nButton < nButtons; nButton++)
					{
						// Get the bounding rectangle of the button.
						CRect crButton;
						GetItemRect(nButton, crButton);

						// Check if the button is in the update region. If not, then
						// there's nothing to draw.
						CRect crIntersect;
						if (crIntersect.IntersectRect(crButton, crUpdate))
						{
							// Get the button information.
							UINT uButtonID;
							UINT uButtonStyleState;
							int nButtonBitmap;
							GetButtonInfo(nButton, uButtonID, uButtonStyleState, nButtonBitmap);
							WORD wButtonStyle = LOWORD(uButtonStyleState);
							WORD wButtonState = HIWORD(uButtonStyleState);

							// If the button is hidden, then there's nothing to draw.
							if ((wButtonState & TBSTATE_HIDDEN) == 0)
							{
								if (wButtonStyle == TBSTYLE_SEP)
								{
									// Draw the separator (DrawSeparator() is virtual.)
									DrawSeparator(dcOffScreen, crButton, nButton, uButtonID, wButtonStyle, wButtonState);
								}
								else
								{
									// Draw the button (DrawButton() is virtual.)
									DrawButton(dcOffScreen, crButton, nButton, uButtonID, wButtonStyle, wButtonState);
								}
							}
						}
					}

					// Copy the offscreen bitmap to the destination DC.
					dc.BitBlt(
						crUpdate.left,
						crUpdate.top,
						crUpdate.Width(),
						crUpdate.Height(),
						&dcOffScreen,
						crUpdate.left,
						crUpdate.top,
						SRCCOPY);

					dcOffScreen.SelectObject(pOldBitmap);
					pOldBitmap = NULL;
				}

				// Clean up the offscreen bitmap and DC.
				OffScreenBitmap.DeleteObject();
				DeselectPalette(dcOffScreen, pOldOffScreenPalette, TRUE);
			}

			dcOffScreen.DeleteDC();
		}

		DeselectPalette(dc, pOldPalette, FALSE);
	}
}
Пример #21
0
HRESULT CMenuToolbarBase::KeyboardItemChange(DWORD dwSelectType)
{
    int prev = m_hotItem;
    int index = -1;

    if (dwSelectType != 0xFFFFFFFF)
    {
        int count = GetButtonCount();

        if (dwSelectType == VK_HOME)
        {
            index = 0;
            dwSelectType = VK_DOWN;
        }
        else if (dwSelectType == VK_END)
        {
            index = count - 1;
            dwSelectType = VK_UP;
        }
        else
        {
            if (m_hotItem >= 0)
            {
                TBBUTTONINFO info = { 0 };
                info.cbSize = sizeof(TBBUTTONINFO);
                info.dwMask = 0;
                index = GetButtonInfo(m_hotItem, &info);
            }

            if (index < 0)
            {
                if (dwSelectType == VK_UP)
                {
                    index = count - 1;
                }
                else if (dwSelectType == VK_DOWN)
                {
                    index = 0;
                }
            }
            else
            {
                if (dwSelectType == VK_UP)
                {
                    index--;
                }
                else if (dwSelectType == VK_DOWN)
                {
                    index++;
                }
            }
        }

        TBBUTTON btn = { 0 };
        while (index >= 0 && index < count)
        {
            DWORD res = GetButton(index, &btn);
            if (!res)
                return E_FAIL;

            if (btn.dwData)
            {
                if (prev != btn.idCommand)
                {
                    TRACE("Setting Hot item to %d\n", index);
                    if (!(m_initFlags & SMINIT_VERTICAL) && m_isTrackingPopup)
                    {
                        HWND tlw;
                        m_menuBand->_GetTopLevelWindow(&tlw);
                        SendMessageW(tlw, WM_CANCELMODE, 0, 0);
                        PostMessageW(WM_USER_CHANGETRACKEDITEM, index, MAKELPARAM(m_isTrackingPopup, FALSE));
                    }
                    else
                        m_menuBand->_ChangeHotItem(this, btn.idCommand, 0);
                }
                return S_OK;
            }

            if (dwSelectType == VK_UP)
            {
                index--;
            }
            else if (dwSelectType == VK_DOWN)
            {
                index++;
            }
        }

        return S_FALSE;
    }

    if (prev != -1)
    {
        TRACE("Setting Hot item to null\n");
        m_menuBand->_ChangeHotItem(NULL, -1, 0);
    }

    return S_FALSE;
}
Пример #22
0
void CMuleToolbarCtrl::Dump()
{
	TRACE("---\n");
	CRect rcWnd;
	GetWindowRect(&rcWnd);
	TRACE("Wnd =%4d,%4d-%4d,%4d (%4d x %4d)\n", rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, rcWnd.Width(), rcWnd.Height());

	CRect rcClnt;
	GetClientRect(&rcClnt);
	TRACE("Clnt=%4d,%4d-%4d,%4d (%4d x %4d)\n", rcClnt.left, rcClnt.top, rcClnt.right, rcClnt.bottom, rcClnt.Width(), rcClnt.Height());

	// Total size of all of the visible buttons and separators in the toolbar.
	CSize siz;
	GetMaxSize(&siz);
	TRACE("MaxSize=                  %4d x %4d\n", siz.cx, siz.cy);

	int iButtons = GetButtonCount();	// Count of the buttons currently in the toolbar.
	int iRows = GetRows();				// Number of rows of buttons in a toolbar with the TBSTYLE_WRAPABLE style
	int iMaxTextRows = GetMaxTextRows();// Maximum number of text rows that can be displayed on a toolbar button.
	TRACE("ButtonCount=%d  Rows=%d  MaxTextRows=%d\n", iButtons, iRows, iMaxTextRows);

	// Current width and height of toolbar buttons, in pixels.
	DWORD dwButtonSize = GetButtonSize();
	TRACE("ButtonSize=%dx%d\n", LOWORD(dwButtonSize), HIWORD(dwButtonSize));

	// Padding for a toolbar control.
	DWORD dwPadding = SendMessage(TB_GETPADDING);
	TRACE("Padding=%dx%d\n", LOWORD(dwPadding), HIWORD(dwPadding));

	DWORD dwBitmapFlags = GetBitmapFlags(); // TBBF_LARGE=0x0001
	TRACE("BitmapFlags=%u\n", dwBitmapFlags);

	// Bounding rectangle of a button in a toolbar.
	TRACE("ItemRects:");
	for (int i = 0; i < iButtons; i++)
	{
		CRect rcButton(0,0,0,0);
		GetItemRect(i, &rcButton);
		TRACE(" %2dx%2d", rcButton.Width(), rcButton.Height());
	}
	TRACE("\n");

	// Bounding rectangle for a specified toolbar button.
	TRACE("Rects    :");
	for (int i = 0; i < iButtons; i++)
	{
		CRect rcButton(0,0,0,0);
		GetRect(IDC_TOOLBARBUTTON + i, &rcButton);
		TRACE(" %2dx%2d", rcButton.Width(), rcButton.Height());
	}
	TRACE("\n");

	TRACE("Info     :");
	for (int i = 0; i < iButtons; i++)
	{
		TCHAR szLabel[256];
		TBBUTTONINFO tbi = {0};
		tbi.cbSize = sizeof(tbi);
		tbi.dwMask |= TBIF_BYINDEX | TBIF_COMMAND | TBIF_IMAGE | TBIF_LPARAM | TBIF_SIZE | TBIF_STATE | TBIF_STYLE | TBIF_TEXT;
		tbi.cchText = _countof(szLabel);
		tbi.pszText = szLabel;
		GetButtonInfo(i, &tbi);
		szLabel[_countof(szLabel) - 1] = _T('\0');
		TRACE(" %2d ", tbi.cx);
	}
	TRACE("\n");
}
Пример #23
0
void CGuiToolBarWnd::OnPaint()
{

	CPaintDC dc(this);  	
	CRect rcBtn;
	
	int nBtn=GetToolBarCtrl().GetButtonCount();
	int iBitmap;
	UINT nID;
	UINT nStyle;
	WORD wStyle, wState;
	DWORD dwBarStyle = GetToolBarCtrl().GetStyle();
	BOOL mbIsPress;
	BOOL mbIsEnabled;
	CBrush cb;
	CImageList m_imgList;
	CRect rcUpdate;
	int iUltbot;
	CRect rcClient;
	GetClientRect(&rcClient);
	cb.CreateSolidBrush(GuiDrawLayer::GetRGBColorXP());
	
    // draw borders in non-client area
    CRect rcDraw = rcClient;
 
	dc.FillRect(rcDraw, &cb);
	
	
	HIMAGELIST hiImg = 0;
	iBitmap=0;
	hiImg = HIMAGELIST(SendMessage(TB_GETIMAGELIST));
	m_imgList.Attach(hiImg);
	int j=0;
	for(int i=0; i < nBtn; i++)
	{
		
		bOver=FALSE;
		GetItemRect(i,&rcBtn);
		GetButtonInfo(i,nID,nStyle,iBitmap);
		wStyle= LOWORD(nStyle);
		wState= HIWORD(nStyle);
		if (wState & TBSTATE_HIDDEN) continue;
		if (wStyle == TBSTYLE_SEP)
		{
			if (!(wState & TBSTATE_WRAP) || ! IsFloating() )
			{
				CRect m_Separ;
				m_Separ=rcBtn;
				
				//si existe un separador vertical
				if (m_dwStyle & CBRS_ORIENT_HORZ)
				{
					dc.FillRect(&rcBtn,&cb);
					int nhalf=(m_Separ.Width()/2)-1;
					m_Separ.top-=1;
					m_Separ.left+=nhalf;
					m_Separ.right=m_Separ.left+1;
					m_Separ.bottom+=1;
					
				}
				else
				{
					int nhalf=(m_Separ.Width()/2)-1;
					int iHeigh=m_Separ.Height();
					
					m_Separ.left=0;
					m_Separ.right=m_Separ.left+m_Separ.Height()+1;
					m_Separ.top=iUltbot;
					m_Separ.bottom=m_Separ.top+m_Separ.Width();			
					dc.FillRect(&m_Separ,&cb);
					
					m_Separ.left=0;
					m_Separ.right=m_Separ.left+iHeigh+1;
					m_Separ.top=iUltbot+nhalf;
					m_Separ.bottom=m_Separ.top+1;
					
					
				}
				CBrush cbt;
				cbt.CreateSolidBrush(RGB(167, 167, 167));
				dc.FillRect(m_Separ,&cbt);
				continue;
				
			}
			
				 
		}
		else {
			
			mbIsPress=(wState & TBSTATE_CHECKED) || (wState & TBSTATE_PRESSED);
			mbIsEnabled= GetToolBarCtrl().IsButtonEnabled((int)nID);
			CPoint pt;
			GetCursorPos(&pt);
			ScreenToClient(&pt);
			CBrush cblu;
			if(!rcBtn.PtInRect(pt))
			{
				if (wState & TBSTATE_CHECKED)
				{
					cblu.CreateSolidBrush(GuiDrawLayer::GetRGBPressBXP());
					dc.FillRect(rcBtn,&cblu);					
				}
				else
				{
					dc.FillRect(rcBtn,&cb);
				}
			}
			else
			{
				
				if (bPressDown)
					dc.Draw3dRect(rcBtn,GuiDrawLayer::GetRGBColorShadow(),GuiDrawLayer::GetRGBColorShadow());
				else
					dc.Draw3dRect(rcBtn,GuiDrawLayer::GetRGBCaptionXP(),GuiDrawLayer::GetRGBCaptionXP());
				rcBtn.DeflateRect(1,1);
				if (wState & TBSTATE_CHECKED)
				{
					cblu.CreateSolidBrush(GuiDrawLayer::GetRGBFondoXP());
					dc.FillRect(rcBtn,&cblu);					
				}
				else
				{
					
					if (bPressDown)
					{
						cblu.CreateSolidBrush(GuiDrawLayer::GetRGBColorXP());
						dc.FillRect(rcBtn,&cblu);
					}
					else
					{
						cblu.CreateSolidBrush(mbIsPress?GuiDrawLayer::GetRGBPressBXP():GuiDrawLayer::GetRGBFondoXP());
						dc.FillRect(rcBtn,&cblu);					
					}
					if (wStyle == 8) 
					{
						
						CRect rcCli=rcBtn;
						int dif=rcBtn.right-_afxDropDownWidth;
						rcCli.left=dif+1;
						
						if (!bPressDown)
						{
							CPen Cp( PS_SOLID, 1, GuiDrawLayer::GetRGBCaptionXP());
							CPen* oldPen= dc.SelectObject(&Cp);
							dc.MoveTo(dif,rcBtn.top);
							dc.LineTo(dif,rcBtn.bottom);
							dc.SelectObject(oldPen);
						}
						
					}
					if (!mbIsPress && !bPressDown)
						bOver=TRUE;
					else
						bOver=FALSE;
					if (!bPressDown) 
						SetTimer(1,10,NULL);
					else
						KillTimer(1);		

				}
				rcBtn.InflateRect(1,1);
				
			}

		}

		if (wStyle != TBSTYLE_SEP)
	{
			
			int OldMode=dc.SetBkMode(TRANSPARENT);
			IMAGEINFO pImageInfo;
			m_imgList.GetImageInfo(iBitmap,&pImageInfo);
			CRect rcima =pImageInfo.rcImage;
			CSize siImg=CSize(rcima.Width(),rcima.Height());
			/* Modified By SunZhenyu 2003/6/27, Replace by the next 5 lines, CPoint pti(rcBtn.left+2,rcBtn.top+4); */
			CPoint pti(rcBtn.left+(rcBtn.Width()-siImg.cx)/2,rcBtn.top+4);
			if( dwBarStyle & TBSTYLE_LIST ) // ÎÄ×ÖÔÚÓÒ±ß
				pti = CPoint(rcBtn.left+4,rcBtn.top+(rcBtn.Height()-siImg.cy)/2);
			else if( wStyle & TBSTYLE_DROPDOWN )
				pti.x -= _AfxGetDropDownWidth()/2;
			CString mszText=GetButtonText(i);
			CFont* m_fontOld=dc.SelectObject(&m_cfont);
			if (!(wState & TBSTATE_ENABLED))
			{
				if (bOver==TRUE)
				{
					pti.x+=1;
					pti.y+=1;
					dc.DrawState(pti,siImg,m_imgList.ExtractIcon(iBitmap),DSS_MONO,CBrush (GuiDrawLayer::GetRGBColorShadow()));
							pti.x-=2;					pti.y-=2;
				
				}
				m_imgList.Draw(&dc, iBitmap, pti, ILD_TRANSPARENT);
				if (mszText.GetLength() > 0 && !bVertDocked)
				{
					CRect m_rctext=rcBtn;
					/* Modified By SunZhenyu 2003/6/27, Replace by the next 6 line, m_rctext.left+=siImg.cx+4; */
					if( dwBarStyle & TBSTYLE_LIST )
						m_rctext.left += siImg.cx+4;
					else
						m_rctext.top += siImg.cy+4;
					if( wStyle & TBSTYLE_DROPDOWN )
						m_rctext.right -= _AfxGetDropDownWidth();
					m_rctext.bottom-=1;
					/* Modified By SunZhenyu 2003/6/27, Replace by the next 5 line
					dc.DrawText(mszText,&m_rctext,DT_SINGLELINE|DT_BOTTOM|DT_CENTER);
					*/
					m_rctext.right-=1;
					if( dwBarStyle & TBSTYLE_LIST )
						dc.DrawText(mszText,&m_rctext,DT_SINGLELINE|DT_VCENTER|DT_RIGHT);
					else
						dc.DrawText(mszText,&m_rctext,DT_SINGLELINE|DT_BOTTOM|DT_CENTER);
				}
			}
			else
			{
				dc.DrawState(pti,siImg,m_imgList.ExtractIcon(iBitmap),DSS_DISABLED,(CBrush*)NULL);
				CRect m_rctext=rcBtn;
				/* Modified By SunZhenyu 2003/6/27, Replace by the next 5 line, m_rctext.left+=siImg.cx+4; */
				if( dwBarStyle & TBSTYLE_LIST )
					m_rctext.left += siImg.cx+4;
				else
					m_rctext.top += siImg.cy+4;
				m_rctext.bottom-=1;
				CSize szText=dc.GetTextExtent(mszText);
				/* Modified By SunZhenyu 2003/6/27, Replace by the next 4 lines,
				pti.x= m_rctext.left+2;
				pti.y= (m_rctext.Height()/2)-1;
				*/
				pti.x = m_rctext.left+(m_rctext.Width()-szText.cx)/2;
				if( wStyle & TBSTYLE_DROPDOWN )
					pti.x = m_rctext.left+(m_rctext.Width()-szText.cx-_AfxGetDropDownWidth())/2;
				pti.y= m_rctext.top+(m_rctext.Height()-szText.cy)/2;
				//DrawState(pt, m_Csize, m_szCaption, DSS_DISABLED, TRUE, 0, (HBRUSH)NULL);
				dc.DrawState(pti,szText,mszText,DSS_DISABLED,TRUE,0,(HBRUSH)NULL);
			}
			
			if (wStyle == TBSTYLE_DROPDOWN) 
				DrawArrow(&dc,rcBtn);
			dc.SetBkMode(OldMode);
			// Modified By SunZhenyu
			dc.SelectObject(m_fontOld);
			iBitmap++;
			iUltbot=rcBtn.bottom;
			j++;
		}
	}
	m_imgList.Detach();
	
	
    ReleaseDC(&dc);

  
}