Beispiel #1
0
void CFlexWnd::RenderInto(HDC hDC, int x, int y)
{
	if (hDC == NULL)
		return;
		
	int sdc = SaveDC(hDC);
	{
		OffsetViewportOrgEx(hDC, x, y, NULL);
		SIZE size = GetClientSize();
		IntersectClipRect(hDC, 0, 0, size.cx, size.cy);

		m_hRenderInto = hDC;

		int sdc2 = SaveDC(hDC);
		{
			EnumChildWindows/*ZDown*/(m_hWnd, ::RenderIntoClipChild, (LPARAM)(PVOID)this);
			EnumSiblingsAbove(m_hWnd, ::RenderIntoClipChild, (LPARAM)(PVOID)this);
			DoOnPaint(hDC);
		}
		if (sdc2)
			RestoreDC(hDC, sdc2);

		EnumChildWindows/*ZDown*/(m_hWnd, ::RenderIntoRenderChild, (LPARAM)(PVOID)this);

		m_hRenderInto = NULL;
	}

	if (sdc)
		RestoreDC(hDC, sdc);
}
Beispiel #2
0
static void RestrictControlECRGN (CLIPRGN* crgn, PCONTROL pCtrl)
{
    RECT rc;
    PCONTROL pRoot = (PCONTROL) (pCtrl->pMainWin);
    int off_x = 0, off_y = 0;

    do {
        PCONTROL pParent = pCtrl;

        rc.left = pRoot->cl + off_x;
        rc.top  = pRoot->ct + off_y;
        rc.right = pRoot->cr + off_x;
        rc.bottom = pRoot->cb + off_y;
        IntersectClipRect (crgn, &rc);

        if (pRoot == pCtrl->pParent)
            break;

        off_x += pRoot->cl;
        off_y += pRoot->ct;

        while (TRUE) {
            if (pRoot->children == pParent->pParent->children) {
                pRoot = pParent;
                break;
            }
            pParent = pParent->pParent;
        }
    } while (TRUE);
}
void
_cairo_win32_display_surface_unset_clip (cairo_win32_display_surface_t *surface)
{
    XFORM saved_xform;
    int gm = GetGraphicsMode (surface->win32.dc);
    if (gm == GM_ADVANCED) {
	GetWorldTransform (surface->win32.dc, &saved_xform);
	ModifyWorldTransform (surface->win32.dc, NULL, MWT_IDENTITY);
    }

    /* initial_clip_rgn will either be a real region or NULL (which means reset to no clip region) */
    SelectClipRgn (surface->win32.dc, surface->initial_clip_rgn);

    if (surface->had_simple_clip) {
	/* then if we had a simple clip, intersect */
	IntersectClipRect (surface->win32.dc,
			   surface->win32.extents.x,
			   surface->win32.extents.y,
			   surface->win32.extents.x + surface->win32.extents.width,
			   surface->win32.extents.y + surface->win32.extents.height);
    }

    if (gm == GM_ADVANCED)
	SetWorldTransform (surface->win32.dc, &saved_xform);
}
Beispiel #4
0
static void setup_clipping( HWND hwnd, HDC hdc )
{
    RECT rc;

    GetClientRect( hwnd, &rc );
    DPtoLP( hdc, (POINT *)&rc, 2 );
    IntersectClipRect( hdc, rc.left, rc.top, rc.right, rc.bottom );
}
Beispiel #5
0
// This function init DC.
// set the default parameters.
static void dc_InitDC(PDC pdc, HWND hWnd, BOOL bIsClient)
{
    PCONTROL pCtrl;

    pdc->hwnd = hWnd;
    pdc->gc = PHYSICALGC;

    pdc->bkcolor = PIXEL_lightwhite;
    pdc->bkmode = 0;

    pdc->brushtype = BT_SOLID;
    pdc->brushcolor = PIXEL_lightwhite;
    pdc->BrushOrig.x = pdc->BrushOrig.y = 0;

    pdc->pentype = PT_SOLID;
    pdc->pencolor = PIXEL_black;
    pdc->CurPenPos.x = pdc->CurPenPos.y = 0;

    pdc->textcolor = PIXEL_black;
    if (!(pdc->pLogFont = GetWindowFont (hWnd)))
        pdc->pLogFont = GetSystemFont (SYSLOGFONT_WCHAR_DEF);
    pdc->tabstop = 8;
    pdc->CurTextPos.x = pdc->CurTextPos.y = 0;
    pdc->cExtra = pdc->alExtra = pdc->blExtra = 0;

    pdc->mapmode = MM_TEXT;
    pdc->ViewOrig.x = pdc->ViewOrig.y = 0;
    pdc->ViewExtent.x = pdc->ViewExtent.y = 1;
    pdc->WindowOrig.x = pdc->WindowOrig.y = 0;
    pdc->WindowExtent.x = pdc->WindowExtent.y = 1;

    // assume that the local clip region is empty.
  
    // Get global clip region info and generate effective clip region.
    pdc->pGCRInfo = GetGCRgnInfo (hWnd);

    pthread_mutex_lock (&pdc->pGCRInfo->lock);

    pdc->oldage = pdc->pGCRInfo->age;
    ClipRgnCopy (&pdc->ecrgn, &pdc->pGCRInfo->crgn);

    if (bIsClient)
        WndClientRect (pdc->hwnd, &pdc->DevRC);
    else
        WndRect (pdc->hwnd, &pdc->DevRC);

    pdc->bIsClient = bIsClient;
    if (bIsClient)
        IntersectClipRect (&pdc->ecrgn, &pdc->DevRC);

    pCtrl = Control (pdc->hwnd);
    if (pCtrl && !(pCtrl->dwExStyle & WS_EX_CTRLASMAINWIN))
        RestrictControlECRGN (&pdc->ecrgn, pCtrl);

    pthread_mutex_unlock (&pdc->pGCRInfo->lock);

}
Beispiel #6
0
BOOL dc_GenerateECRgn(PDC pdc, BOOL fForce)
{
    RECT rc, rcInter;
    PCLIPRECT pcr, pgcr;
    PCONTROL pCtrl;

    // is global clip region is empty?
    if ((!fForce) && (!dc_IsVisible (pdc)))
            return FALSE;

    // need regenerate?
    if (fForce || (pdc->oldage != pdc->pGCRInfo->age)) {
        EmptyClipRgn (&pdc->ecrgn);

        pcr = pdc->lcrgn.head;
        while (pcr) {
            rc = pcr->rc;
            coor_LP2SP (pdc, &rc.left, &rc.top);
            coor_LP2SP (pdc, &rc.right, &rc.bottom);
            
            pgcr = pdc->pGCRInfo->crgn.head;
            while (pgcr) {

                if (IntersectRect (&rcInter, &rc, &pgcr->rc))
                    AddClipRect (&pdc->ecrgn, &rcInter);

                pgcr = pgcr->next;
            }
            
            pcr = pcr->next;
        }
        
        if (pdc->lcrgn.head == NULL)
            ClipRgnCopy (&pdc->ecrgn, &pdc->pGCRInfo->crgn);

        // update the DevRC;
        if (pdc->bIsClient)
            WndClientRect (pdc->hwnd, &pdc->DevRC);
        else
            WndRect (pdc->hwnd, &pdc->DevRC);
            
        IntersectClipRect (&pdc->ecrgn, &pdc->DevRC);

        pCtrl = Control (pdc->hwnd);
        if (pCtrl && !(pCtrl->dwExStyle & WS_EX_CTRLASMAINWIN))
            RestrictControlECRGN (&pdc->ecrgn, pCtrl);

        pdc->oldage = pdc->pGCRInfo->age;
    }

    return TRUE;
}
Beispiel #7
0
static HRGN
mi_clip(HDC dc)
{
  HRGN rgn;

  rgn = CreateRectRgn(g_clip_left + g_xoff - g_xscroll,
                      g_clip_top + g_yoff - g_yscroll,
                      g_clip_right + g_xoff - g_xscroll,
                      g_clip_bottom + g_yoff - g_yscroll);
  SelectClipRgn(dc, rgn);
  IntersectClipRect(dc, g_wnd_clip.left + g_xoff, g_wnd_clip.top + g_yoff,
                    g_wnd_clip.right + g_xoff, g_wnd_clip.bottom + g_yoff);
  return rgn;
}
Beispiel #8
0
void DynamicDisplayItem::DrawIconOnly(HDC theDC, bool theSelected, const RECT & theContainer, const Theme * theTheme)
{
	// Step 1. Clip the output so that no text is touched.
	int aWidth = theTheme->GetMetric(WIDTH_ICONSITE) + theTheme->GetMetric(WIDTH_INDENT_LEFT);
	IntersectClipRect(theDC, theContainer.left, theContainer.top, aWidth, theContainer.bottom);

	// Step 2. Redraw a part of the background.
	DrawBackground(theDC, theSelected, theContainer, theTheme);

	// Step 3. Draw icon
	DrawIcon(theDC, theSelected, theContainer, theTheme);

	// Step 4. Remove clipping
	SelectClipRgn(theDC, NULL);
}
Beispiel #9
0
void scrollVertical(gdioutput *gdi, int yInc, HWND hWnd) {
  SCROLLINFO si;
  si.cbSize=sizeof(si);
  si.fMask=SIF_ALL;
  GetScrollInfo(hWnd, SB_VERT, &si);
  if (si.nPage==0)
    yInc = 0;

  int yPos=gdi->GetOffsetY();
  int a=si.nMax-signed(si.nPage-1) - yPos;

  if ( (yInc = max( -yPos, min(yInc, a)))!=0 ) {
    yPos += yInc;
    RECT ScrollArea, ClipArea;
    GetClientRect(hWnd, &ScrollArea);
    ClipArea=ScrollArea;

    ScrollArea.top=-gdi->getHeight()-100;
    ScrollArea.bottom+=gdi->getHeight();
    ScrollArea.right=gdi->getWidth()-gdi->GetOffsetX()+15;
    ScrollArea.left = -2000;
    gdi->SetOffsetY(yPos);

    bool inv = true; //Inv = false works only for lists etc. where there are not controls in the scroll area.

    RECT invalidArea;
    ScrollWindowEx (hWnd, 0,  -yInc,
      &ScrollArea, &ClipArea,
      (HRGN) NULL, &invalidArea, SW_SCROLLCHILDREN | (inv ? SW_INVALIDATE : 0));

   //	gdi->UpdateObjectPositions();

    si.cbSize = sizeof(si);
    si.fMask  = SIF_POS;
    si.nPos   = yPos;

    SetScrollInfo(hWnd, SB_VERT, &si, TRUE);

    if (inv)
      UpdateWindow(hWnd);
    else {
      HDC hDC = GetDC(hWnd);
      IntersectClipRect(hDC, invalidArea.left, invalidArea.top, invalidArea.right, invalidArea.bottom);
      gdi->draw(hDC, ScrollArea, invalidArea);
      ReleaseDC(hWnd, hDC);
    }
  }
}
Beispiel #10
0
bool SystemDraw::IntersectClipOp(const Rect& r)
{
    GuiLock __;
#ifdef PLATFORM_WINCE
    int q = IntersectClipRect(handle, r.left, r.top, r.right, r.bottom);
#else
    LTIMING("Intersect");
    drawingclip &= r;
    Rect rr = LPtoDP(r);
    HRGN hrgn = ::CreateRectRgnIndirect(rr);
    int q = ::ExtSelectClipRgn(handle, hrgn, RGN_AND);
    ASSERT(q != ERROR);
    ::DeleteObject(hrgn);
#endif
    return q == SIMPLEREGION || q == COMPLEXREGION;
}
Beispiel #11
0
/***********************************************************************
 *           set_control_clipping
 *
 * Set clipping for a builtin control that uses CS_PARENTDC.
 * Return the previous clip region if any.
 */
HRGN set_control_clipping( HDC hdc, const RECT *rect )
{
    RECT rc = *rect;
    HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );

    if (GetClipRgn( hdc, hrgn ) != 1)
    {
        DeleteObject( hrgn );
        hrgn = 0;
    }
    DPtoLP( hdc, (POINT *)&rc, 2 );
    if (GetLayout( hdc ) & LAYOUT_RTL)  /* compensate for the shifting done by IntersectClipRect */
    {
        rc.left++;
        rc.right++;
    }
    IntersectClipRect( hdc, rc.left, rc.top, rc.right, rc.bottom );
    return hrgn;
}
Beispiel #12
0
/*
 * Function: void GUIAPI ReleaseDC(HDC hDC)
 *     This function release the specified DC.
 * Parameter:
 *     HDC hDC: The DC handle want to release.
 * Return:
 *     None. 
 */
void GUIAPI ReleaseDC (HDC hDC)
{
    PMAINWIN pWin;
    PDC pdc;
    PCONTROL pCtrl;

    pdc = dc_HDC2PDC(hDC);

    EmptyClipRgn (&pdc->lcrgn);

    pWin = (PMAINWIN)(pdc->hwnd);
    if (pWin && pWin->privCDC == hDC) {
        /* for private DC, we reset the clip region info. */
        pthread_mutex_lock (&pdc->pGCRInfo->lock);

        pdc->oldage = pdc->pGCRInfo->age;
        ClipRgnCopy (&pdc->ecrgn, &pdc->pGCRInfo->crgn);

        if (pdc->bIsClient)
            WndClientRect (pdc->hwnd, &pdc->DevRC);
        else
            WndRect (pdc->hwnd, &pdc->DevRC);

        IntersectClipRect (&pdc->ecrgn, &pdc->DevRC);

        pCtrl = Control (pdc->hwnd);
        if (pCtrl && !(pCtrl->dwExStyle & WS_EX_CTRLASMAINWIN))
            RestrictControlECRGN (&pdc->ecrgn, pCtrl);

        pthread_mutex_unlock (&pdc->pGCRInfo->lock);
    }
    else {
        EmptyClipRgn (&pdc->ecrgn);
        pdc->pGCRInfo = NULL;
        pdc->oldage = 0;

        pthread_mutex_lock (&dcslot);
        pdc->inuse = FALSE;
        pthread_mutex_unlock(&dcslot);
    }

}
Beispiel #13
0
void NFOView::DrawHyperlink(void)
{
    RECT viewWindowRect;
    GetClientRect(_handle, &viewWindowRect);

    HDC viewWindowDC = GetDC(_handle);
    HFONT hFont = (HFONT)SendMessage(_handle, WM_GETFONT, NULL, NULL);
    SelectObject(viewWindowDC, hFont);
    SetBkMode(viewWindowDC, TRANSPARENT);
    IntersectClipRect(viewWindowDC, viewWindowRect.left, viewWindowRect.top, viewWindowRect.right, viewWindowRect.bottom);
    SetTextColor(viewWindowDC, RGB(0, 102, 204));

    DWORD selStart;
    DWORD selEnd;
    SendMessage(_handle, EM_GETSEL, (WPARAM)&selStart, (LPARAM)&selEnd);

    for (int i = 0; i < _hyperlinkOffsets.size(); i++)
    {
        for (int charIndex  = _hyperlinkOffsets[i].start; charIndex <= _hyperlinkOffsets[i].end; charIndex++)
        {
            DWORD pos = SendMessage(_handle, EM_POSFROMCHAR, (WPARAM)charIndex, NULL);
            POINT charPt = {LOWORD(pos), HIWORD(pos)};    
            // don't draw text that selected
            if (selStart != selEnd && 
                charIndex >= selStart &&
                charIndex < selEnd)
            {
                continue;
            }

            TextOutW(viewWindowDC, charPt.x, charPt.y, _nfoText.c_str()+charIndex, 1);
        }
    }

    ReleaseDC(_handle, viewWindowDC);
}
Beispiel #14
0
    // Paints the tabs that intersect the window's update rectangle.
    void Paint(HDC hdc, RECT &rc) {
        IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);

        // paint the background
        bool isTranslucentMode = inTitlebar && dwm::IsCompositionEnabled();
        if (isTranslucentMode)
            PaintParentBackground(hwnd, hdc);
        else {
            HBRUSH brush = CreateSolidBrush(color.bar);
            FillRect(hdc, &rc, brush);
            DeleteObject(brush);
        }

        // TODO: GDI+ doesn't seem to cope well with SetWorldTransform
        XFORM ctm = { 1.0, 0, 0, 1.0, 0, 0 };
        SetWorldTransform(hdc, &ctm);

        Graphics graphics(hdc);
        graphics.SetCompositingMode(CompositingModeSourceCopy);
        graphics.SetCompositingQuality(CompositingQualityHighQuality);
        graphics.SetSmoothingMode(SmoothingModeHighQuality);
        graphics.SetTextRenderingHint(TextRenderingHintClearTypeGridFit);
        graphics.SetPageUnit(UnitPixel);
        GraphicsPath shapes(data->Points, data->Types, data->Count);
        GraphicsPath shape;
        GraphicsPathIterator iterator(&shapes);

        SolidBrush br(Color(0, 0, 0));
        Pen pen(&br, 2.0f);

        Font f(hdc, GetDefaultGuiFont());
        // TODO: adjust these constant values for DPI?
        RectF layout((REAL)DpiScaleX(hwnd,3), 1.0f, REAL(width - DpiScaleX(hwnd,20)), (REAL)height);
        StringFormat sf(StringFormat::GenericDefault());
        sf.SetFormatFlags(StringFormatFlagsNoWrap);
        sf.SetLineAlignment(StringAlignmentCenter);
        sf.SetTrimming(StringTrimmingEllipsisCharacter);

        REAL yPosTab = inTitlebar ? 0.0f : REAL(ClientRect(hwnd).dy - height - 1);
        for (int i = 0; i < Count(); i++) {
            graphics.ResetTransform();
            graphics.TranslateTransform(1.f + (REAL)(width + 1) * i - (REAL)rc.left, yPosTab - (REAL)rc.top);

            if (!graphics.IsVisible(0, 0, width + 1, height + 1))
                continue;

            // in firefox style we only paint current and highlighed tabs
            // all other tabs only show
            bool onlyText = g_FirefoxStyle && !((current == i) || (highlighted == i));
            if (onlyText) {
#if 0
                // we need to first paint the background with the same color as caption,
                // otherwise the text looks funny (because is transparent?)
                // TODO: what is the damn bg color of caption? bar is too light, outline is too dark
                Color bgColTmp;
                bgColTmp.SetFromCOLORREF(color.bar);
                {
                    SolidBrush bgBr(bgColTmp);
                    graphics.FillRectangle(&bgBr, layout);
                }
                bgColTmp.SetFromCOLORREF(color.outline);
                {
                    SolidBrush bgBr(bgColTmp);
                    graphics.FillRectangle(&bgBr, layout);
                }
#endif
                // TODO: this is a hack. If I use no background and cleartype, the
                // text looks funny (is bold).
                // CompositingModeSourceCopy doesn't work with clear type
                // another option is to draw background before drawing text, but
                // I can't figure out what is the actual color of caption
                graphics.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
                graphics.SetCompositingMode(CompositingModeSourceCopy);
                //graphics.SetCompositingMode(CompositingModeSourceOver);
                br.SetColor(ToColor(color.text));
                graphics.DrawString(text.At(i), -1, &f, layout, &sf, &br);
                graphics.SetTextRenderingHint(TextRenderingHintClearTypeGridFit);
                continue;
            }

            COLORREF bgCol = color.background;;
            if (current == i) {
                bgCol = color.current;
            } else if (highlighted == i) {
                bgCol = color.highlight;
            }

            // ensure contrast between text and background color
            // TODO: adjust threshold (and try adjusting both current/background tabs)
            COLORREF textCol = color.text;
            float bgLight = GetLightness(bgCol), textLight = GetLightness(textCol);
            if (textLight < bgLight ? bgLight < 0x70 : bgLight > 0x90)
                textCol = textLight ? AdjustLightness(textCol, 255.0f / textLight - 1.0f) : RGB(255, 255, 255);
            if (fabs(textLight - bgLight) < 0x40)
                textCol = bgLight < 0x80 ? RGB(255, 255, 255) : RGB(0, 0, 0);

            // paint tab's body
            graphics.SetCompositingMode(CompositingModeSourceCopy);
            iterator.NextMarker(&shape);
            br.SetColor(ToColor(bgCol));
            graphics.FillPath(&br, &shape);

            // draw tab's text
            graphics.SetCompositingMode(CompositingModeSourceOver);
            br.SetColor(ToColor(textCol));
            graphics.DrawString(text.At(i), -1, &f, layout, &sf, &br);

            // paint "x"'s circle
            iterator.NextMarker(&shape);
            if (xClicked == i || xHighlighted == i) {
                br.SetColor(ToColor(i == xClicked ? color.x_click : color.x_highlight));
                graphics.FillPath(&br, &shape);
            }

            // paint "x"
            iterator.NextMarker(&shape);
            if (xClicked == i || xHighlighted == i)
                pen.SetColor(ToColor(color.x_line));
            else
                pen.SetColor(ToColor(color.outline));
            graphics.DrawPath(&pen, &shape);
            iterator.Rewind();
        }
    }
Beispiel #15
0
void sClipRect(const sRect &r)
{
  IntersectClipRect(sGDIDC,r.x0,r.y0,r.x1,r.y1);
}
Beispiel #16
0
static void test_GetRandomRgn(void)
{
    HWND hwnd = CreateWindowExA(0,"BUTTON","test",WS_VISIBLE|WS_POPUP,0,0,100,100,GetDesktopWindow(),0,0,0);
    HDC hdc;
    HRGN hrgn = CreateRectRgn(0, 0, 0, 0);
    int ret;
    RECT rc, rc2;
    RECT ret_rc, window_rc;

    ok( hwnd != 0, "CreateWindow failed\n" );

    SetRect(&window_rc, 400, 300, 500, 400);
    SetWindowPos(hwnd, HWND_TOPMOST, window_rc.left, window_rc.top,
                 window_rc.right - window_rc.left, window_rc.bottom - window_rc.top, 0 );
    hdc = GetDC(hwnd);

    ret = GetRandomRgn(hdc, hrgn, 1);
    ok(ret == 0, "GetRandomRgn rets %d\n", ret);
    ret = GetRandomRgn(hdc, hrgn, 2);
    ok(ret == 0, "GetRandomRgn rets %d\n", ret);
    ret = GetRandomRgn(hdc, hrgn, 3);
    ok(ret == 0, "GetRandomRgn rets %d\n", ret);

    /* Set a clip region */
    SetRect(&rc, 20, 20, 80, 80);
    IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);

    ret = GetRandomRgn(hdc, hrgn, 1);
    ok(ret != 0, "GetRandomRgn rets %d\n", ret);
    GetRgnBox(hrgn, &ret_rc);
    ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
       ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
 
    ret = GetRandomRgn(hdc, hrgn, 2);
    ok(ret == 0, "GetRandomRgn rets %d\n", ret);

    ret = GetRandomRgn(hdc, hrgn, 3);
    ok(ret != 0, "GetRandomRgn rets %d\n", ret);
    GetRgnBox(hrgn, &ret_rc);
    ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
       ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);

    /* Move the clip to the meta and clear the clip */
    SetMetaRgn(hdc);

    ret = GetRandomRgn(hdc, hrgn, 1);
    ok(ret == 0, "GetRandomRgn rets %d\n", ret);
    ret = GetRandomRgn(hdc, hrgn, 2);
    ok(ret != 0, "GetRandomRgn rets %d\n", ret);
    GetRgnBox(hrgn, &ret_rc);
    ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
       ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);

    ret = GetRandomRgn(hdc, hrgn, 3);
    ok(ret != 0, "GetRandomRgn rets %d\n", ret);
    GetRgnBox(hrgn, &ret_rc);
    ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
       ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);

    /* Set a new clip (still got the meta) */
    SetRect(&rc2, 10, 30, 70, 90);
    IntersectClipRect(hdc, rc2.left, rc2.top, rc2.right, rc2.bottom);

    ret = GetRandomRgn(hdc, hrgn, 1);
    ok(ret != 0, "GetRandomRgn rets %d\n", ret);
    GetRgnBox(hrgn, &ret_rc);
    ok(EqualRect(&rc2, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
       ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);

    ret = GetRandomRgn(hdc, hrgn, 2);
    ok(ret != 0, "GetRandomRgn rets %d\n", ret);
    GetRgnBox(hrgn, &ret_rc);
    ok(EqualRect(&rc, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
       ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);
 
    IntersectRect(&rc2, &rc, &rc2);

    ret = GetRandomRgn(hdc, hrgn, 3);
    ok(ret != 0, "GetRandomRgn rets %d\n", ret);
    GetRgnBox(hrgn, &ret_rc);
    ok(EqualRect(&rc2, &ret_rc), "GetRandomRgn %d,%d - %d,%d\n",
       ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);


    ret = GetRandomRgn(hdc, hrgn, SYSRGN);
    ok(ret != 0, "GetRandomRgn rets %d\n", ret);
    GetRgnBox(hrgn, &ret_rc);
    if(GetVersion() & 0x80000000)
        OffsetRect(&window_rc, -window_rc.left, -window_rc.top);
    /* the window may be partially obscured so the region may be smaller */
    IntersectRect( &window_rc, &ret_rc, &ret_rc );
    ok(EqualRect(&window_rc, &ret_rc) ||
       broken(IsRectEmpty(&ret_rc)), /* win95 */
       "GetRandomRgn %d,%d - %d,%d\n",
       ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom);

    DeleteObject(hrgn);
    ReleaseDC(hwnd, hdc);
    DestroyWindow(hwnd);
}
Beispiel #17
0
static void test_dc_layout(void)
{
    INT ret, size_cx, size_cy, res_x, res_y, dpi_x, dpi_y;
    SIZE size;
    POINT pt;
    HBITMAP bitmap;
    RECT rc, ret_rc;
    HDC hdc;
    HRGN hrgn;

    if (!pGetLayout || !pSetLayout)
    {
        win_skip( "Don't have SetLayout\n" );
        return;
    }

    hdc = CreateCompatibleDC(0);
    bitmap = CreateCompatibleBitmap( hdc, 100, 100 );
    SelectObject( hdc, bitmap );

    size_cx = GetDeviceCaps(hdc, HORZSIZE);
    size_cy = GetDeviceCaps(hdc, VERTSIZE);
    res_x = GetDeviceCaps(hdc, HORZRES);
    res_y = GetDeviceCaps(hdc, VERTRES);
    dpi_x = GetDeviceCaps(hdc, LOGPIXELSX);
    dpi_y = GetDeviceCaps(hdc, LOGPIXELSY);

    ret = GetMapMode( hdc );
    ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);
    expect_viewport_ext(hdc, 1, 1);
    expect_window_ext(hdc, 1, 1);
    expect_world_transform(hdc, 1.0, 1.0);
    expect_LPtoDP(hdc, 1000, 1000);

    pSetLayout( hdc, LAYOUT_RTL );
    if (!pGetLayout( hdc ))
    {
        win_skip( "SetLayout not supported\n" );
        DeleteDC(hdc);
        return;
    }

    ret = GetMapMode( hdc );
    ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
    expect_viewport_ext(hdc, 1, 1);
    expect_window_ext(hdc, 1, 1);
    expect_world_transform(hdc, 1.0, 1.0);
    expect_LPtoDP(hdc, -1000 + 99, 1000);
    GetViewportOrgEx( hdc, &pt );
    ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y );
    GetWindowOrgEx( hdc, &pt );
    ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y );
    GetDCOrgEx( hdc, &pt );
    ok( pt.x == 0 && pt.y == 0, "wrong origin %d,%d\n", pt.x, pt.y );
    if (pGetTransform)
    {
        XFORM xform;
        BOOL ret = pGetTransform( hdc, 0x204, &xform ); /* World -> Device */
        ok( ret, "got %d\n", ret );
        ok( xform.eM11 == -1.0, "got %f\n", xform.eM11 );
        ok( xform.eM12 == 0.0, "got %f\n", xform.eM12 );
        ok( xform.eM21 == 0.0, "got %f\n", xform.eM21 );
        ok( xform.eM22 == 1.0, "got %f\n", xform.eM22 );
        ok( xform.eDx == 99.0, "got %f\n", xform.eDx );
        ok( xform.eDy == 0.0, "got %f\n", xform.eDy );
    }

    SetRect( &rc, 10, 10, 20, 20 );
    IntersectClipRect( hdc, 10, 10, 20, 20 );
    hrgn = CreateRectRgn( 0, 0, 0, 0 );
    GetClipRgn( hdc, hrgn );
    GetRgnBox( hrgn, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    pSetLayout( hdc, LAYOUT_LTR );
    SetRect( &rc, 80, 10, 90, 20 );
    GetClipRgn( hdc, hrgn );
    GetRgnBox( hrgn, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    GetClipBox( hdc, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    IntersectClipRect( hdc, 80, 10, 85, 20 );
    pSetLayout( hdc, LAYOUT_RTL );
    SetRect( &rc, 15, 10, 20, 20 );
    GetClipRgn( hdc, hrgn );
    GetRgnBox( hrgn, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    GetClipBox( hdc, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    SetRectRgn( hrgn, 60, 10, 80, 20 );
    pSetLayout( hdc, LAYOUT_LTR );
    ExtSelectClipRgn( hdc, hrgn, RGN_OR );
    pSetLayout( hdc, LAYOUT_RTL );
    SetRect( &rc, 15, 10, 40, 20 );
    GetClipRgn( hdc, hrgn );
    GetRgnBox( hrgn, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    GetClipBox( hdc, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );

    /* OffsetClipRgn mirrors too */
    OffsetClipRgn( hdc, 5, 5 );
    OffsetRect( &rc, 5, 5 );
    GetClipRgn( hdc, hrgn );
    GetRgnBox( hrgn, &ret_rc );
    ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
        ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );

    /* GetRandomRgn returns the raw region */
    if (pGetRandomRgn)
    {
        SetRect( &rc, 55, 15, 80, 25 );
        pGetRandomRgn( hdc, hrgn, 1 );
        GetRgnBox( hrgn, &ret_rc );
        ok( EqualRect( &rc, &ret_rc ), "wrong clip box %d,%d - %d,%d\n",
            ret_rc.left, ret_rc.top, ret_rc.right, ret_rc.bottom );
    }

    SetMapMode(hdc, MM_LOMETRIC);
    ret = GetMapMode( hdc );
    ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);

    expect_viewport_ext(hdc, res_x, -res_y);
    ok( GetWindowExtEx( hdc, &size ), "GetWindowExtEx failed\n" );
    ok( rough_match( size.cx, size_cx * 10 ) ||
        rough_match( size.cx, MulDiv( res_x, 254, dpi_x )),  /* Vista uses a more precise method */
        "expected cx %d or %d, got %d\n", size_cx * 10, MulDiv( res_x, 254, dpi_x ), size.cx );
    ok( rough_match( size.cy, size_cy * 10 ) ||
        rough_match( size.cy, MulDiv( res_y, 254, dpi_y )),  /* Vista uses a more precise method */
        "expected cy %d or %d, got %d\n", size_cy * 10, MulDiv( res_y, 254, dpi_y ), size.cy );
    expect_world_transform(hdc, 1.0, 1.0);
    expect_LPtoDP(hdc, -MulDiv(1000 / 10, res_x, size_cx) + 99, -MulDiv(1000 / 10, res_y, size_cy));

    SetMapMode(hdc, MM_TEXT);
    ret = GetMapMode( hdc );
    ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
    pSetLayout( hdc, LAYOUT_LTR );
    ret = GetMapMode( hdc );
    ok(ret == MM_ANISOTROPIC, "expected MM_ANISOTROPIC, got %d\n", ret);
    SetMapMode(hdc, MM_TEXT);
    ret = GetMapMode( hdc );
    ok(ret == MM_TEXT, "expected MM_TEXT, got %d\n", ret);

    DeleteDC(hdc);
    DeleteObject( bitmap );
}
Beispiel #18
0
void
winimg_paint(void)
{
  imglist *img;
  imglist *prev = NULL;
  int left, top;
  int x, y;
  termchar *dchar;
  bool update_flag;
  HDC dc;
  RECT rc;

  /* free disk space if number of tempfile exceeds TEMPFILE_MAX_NUM */
  while (tempfile_num > TEMPFILE_MAX_NUM && term.imgs.first) {
    img = term.imgs.first;
    term.imgs.first = term.imgs.first->next;
    winimg_destroy(img);
  }

  dc = GetDC(wnd);

  GetClientRect(wnd, &rc);
  IntersectClipRect(dc, rc.left + PADDING, rc.top + PADDING,
                    rc.left + PADDING + term.cols * cell_width,
                    rc.top + PADDING + term.rows * cell_height);
  for (img = term.imgs.first; img;) {
    // if the image is out of scrollback, collect it
    if (img->top + img->height - term.virtuallines < - term.sblines) {
      if (img == term.imgs.first)
        term.imgs.first = img->next;
      if (img == term.imgs.last)
        term.imgs.last = prev;
      if (prev)
        prev->next = img->next;
      prev = img;
      img = img->next;
      winimg_destroy(prev);
    } else {
      // if the image is scrolled out, serialize it into a temp file.
      left = img->left;
      top = img->top - term.virtuallines - term.disptop;
      if (top + img->height < 0 || top > term.rows) {
        winimg_hibernate(img);
      } else {
        // create DC handle if it is not initialized, or resume from hibernate
        winimg_lazyinit(img);
        for (y = max(0, top); y < min(top + img->height, term.rows); ++y) {
          int wide_factor = (term.displines[y]->lattr & LATTR_MODE) == LATTR_NORM ? 1: 2;
          for (x = left; x < min(left + img->width, term.cols); ++x) {
            dchar = &term.displines[y]->chars[x];

            // if sixel image is overwirtten by characters,
            // exclude the area from the clipping rect.
            update_flag = false;
            if (dchar->chr != SIXELCH)
              update_flag = true;
            if (dchar->attr.attr & (TATTR_RESULT | TATTR_CURRESULT | TATTR_MARKED | TATTR_CURMARKED))
              update_flag = true;
            if (term.selected && !update_flag) {
              pos scrpos = {y + term.disptop, x, false};
              update_flag = term.sel_rect
                  ? posPle(term.sel_start, scrpos) && posPlt(scrpos, term.sel_end)
                  : posle(term.sel_start, scrpos) && poslt(scrpos, term.sel_end);
            }
            if (update_flag)
              ExcludeClipRect(dc,
                              x * wide_factor * cell_width + PADDING,
                              y * cell_height + PADDING,
                              (x + 1) * wide_factor * cell_width + PADDING,
                              (y + 1) * cell_height + PADDING);
          }
        }
        StretchBlt(dc, left * cell_width + PADDING, top * cell_height + PADDING,
                   img->width * cell_width, img->height * cell_height, img->hdc,
                   0, 0, img->pixelwidth, img->pixelheight, SRCCOPY);
      }
      prev = img;
      img = img->next;
    }
  }
  ReleaseDC(wnd, dc);
}
Beispiel #19
0
static void
button_paint_icon(HWND win, button_t* button, HDC dc)
{
    HICON icon;
    RECT rect;
    RECT content;
    int state;
    SIZE size;
    UINT flags;
    HFONT font, old_font;
    int old_bk_mode;
    COLORREF old_text_color;
    HRGN old_clip;

    /* When theming is not used, we keep all the work on COMCTL32 button
     * implementation. */
    MC_ASSERT(button->theme != NULL);

    GetClientRect(win, &rect);

    icon = (HICON) MC_SEND(win, BM_GETIMAGE, IMAGE_ICON, 0);
    font = (HFONT) MC_SEND(win, WM_GETFONT, 0, 0);
    if(font == NULL)
        font = GetStockObject(SYSTEM_FONT);

    old_font = SelectObject(dc, font);
    old_bk_mode = GetBkMode(dc);
    old_text_color = GetTextColor(dc);
    old_clip = get_clip(dc);

    /* Draw background */
    if(button->style & WS_DISABLED) {
        state = PBS_DISABLED;
    } else {
        LRESULT s = MC_SEND(win, BM_GETSTATE, 0, 0);
        if(s & BST_PUSHED)
            state = PBS_PRESSED;
        else if(s & BST_HOT)
            state = PBS_HOT;
        else if(button->style & BS_DEFPUSHBUTTON)
            state = PBS_DEFAULTED;
        else
            state = PBS_NORMAL;
    }
    if(mcIsThemeBackgroundPartiallyTransparent(button->theme, BP_PUSHBUTTON, state))
        mcDrawThemeParentBackground(win, dc, &rect);
    mcDrawThemeBackground(button->theme, dc, BP_PUSHBUTTON, state, &rect, &rect);

    /* Get content rectangle of the button and clip DC to it */
    mcGetThemeBackgroundContentRect(button->theme, dc, BP_PUSHBUTTON, state, &rect, &content);
    IntersectClipRect(dc, content.left, content.top, content.right, content.bottom);

    /* Draw focus rectangle */
    if(MC_SEND(win, BM_GETSTATE, 0, 0) & BST_FOCUS) {
        if(!button->hide_focus)
            DrawFocusRect(dc, &content);
    }

    /* Draw the contents (i.e. the icon) */
    if(icon != NULL) {
        mc_icon_size(icon, &size);
        flags = DST_ICON;
        if(button->style & WS_DISABLED)
            flags |= DSS_DISABLED;
        DrawState(dc, NULL, NULL, (LPARAM) icon, 0, (rect.right + rect.left - size.cx) / 2,
                  (rect.bottom + rect.top - size.cy) / 2, size.cx, size.cy, flags);
    }

    /* Revert DC into original state */
    SelectObject(dc, old_font);
    SetBkMode(dc, old_bk_mode);
    SetTextColor(dc, old_text_color);
    SelectObject(dc, old_clip);
}
Beispiel #20
0
static void test_savedc_2(void)
{
    HWND hwnd;
    HDC hdc;
    HRGN hrgn;
    RECT rc, rc_clip;
    int ret;

    hwnd = CreateWindowExA(0, "static", "", WS_POPUP, 0,0,100,100,
                           0, 0, 0, NULL);
    assert(hwnd != 0);
    ShowWindow(hwnd, SW_SHOW);
    UpdateWindow(hwnd);

    hrgn = CreateRectRgn(0, 0, 0, 0);
    assert(hrgn != 0);

    hdc = GetDC(hwnd);
    ok(hdc != NULL, "GetDC failed\n");

    ret = GetClipBox(hdc, &rc_clip);
    ok(ret == SIMPLEREGION, "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
    ret = GetClipRgn(hdc, hrgn);
    ok(ret == 0, "GetClipRgn returned %d instead of 0\n", ret);
    ret = GetRgnBox(hrgn, &rc);
    ok(ret == NULLREGION, "GetRgnBox returned %d (%d,%d-%d,%d) instead of NULLREGION\n",
       ret, rc.left, rc.top, rc.right, rc.bottom);
    /*dump_region(hrgn);*/
    SetRect(&rc, 0, 0, 100, 100);
    ok(EqualRect(&rc, &rc_clip),
       "rects are not equal: (%d,%d-%d,%d) - (%d,%d-%d,%d)\n",
       rc.left, rc.top, rc.right, rc.bottom,
       rc_clip.left, rc_clip.top, rc_clip.right, rc_clip.bottom);

    ret = SaveDC(hdc);
todo_wine
{
    ok(ret == 1, "ret = %d\n", ret);
}

    ret = IntersectClipRect(hdc, 0, 0, 50, 50);
    if (ret == COMPLEXREGION)
    {
        /* XP returns COMPLEXREGION although dump_region reports only 1 rect */
        trace("Windows BUG: IntersectClipRect returned %d instead of SIMPLEREGION\n", ret);
        /* let's make sure that it's a simple region */
        ret = GetClipRgn(hdc, hrgn);
        ok(ret == 1, "GetClipRgn returned %d instead of 1\n", ret);
        dump_region(hrgn);
    }
    else
        ok(ret == SIMPLEREGION, "IntersectClipRect returned %d instead of SIMPLEREGION\n", ret);

    ret = GetClipBox(hdc, &rc_clip);
    ok(ret == SIMPLEREGION, "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
    SetRect(&rc, 0, 0, 50, 50);
    ok(EqualRect(&rc, &rc_clip), "rects are not equal\n");

    ret = RestoreDC(hdc, 1);
    ok(ret, "ret = %d\n", ret);

    ret = GetClipBox(hdc, &rc_clip);
    ok(ret == SIMPLEREGION, "GetClipBox returned %d instead of SIMPLEREGION\n", ret);
    SetRect(&rc, 0, 0, 100, 100);
    ok(EqualRect(&rc, &rc_clip), "rects are not equal\n");

    DeleteObject(hrgn);
    ReleaseDC(hwnd, hdc);
    DestroyWindow(hwnd);
}
Beispiel #21
0
    // Paints the tabs that intersect the window's update rectangle.
    void Paint(HDC hdc, RECT& rc) {
        IntersectClipRect(hdc, rc.left, rc.top, rc.right, rc.bottom);

// paint the background
#if 0
        bool isTranslucentMode = inTitlebar && dwm::IsCompositionEnabled();
        if (isTranslucentMode) {
            PaintParentBackground(hwnd, hdc);
        } else {
            // note: not sure what color should be used here and painting
            // background works fine
            /*HBRUSH brush = CreateSolidBrush(colors.bar);
            FillRect(hdc, &rc, brush);
            DeleteObject(brush);*/
        }
#else
        PaintParentBackground(hwnd, hdc);
#endif
        // TODO: GDI+ doesn't seem to cope well with SetWorldTransform
        XFORM ctm = {1.0, 0, 0, 1.0, 0, 0};
        SetWorldTransform(hdc, &ctm);

        Graphics gfx(hdc);
        gfx.SetCompositingMode(CompositingModeSourceCopy);
        gfx.SetCompositingQuality(CompositingQualityHighQuality);
        gfx.SetSmoothingMode(SmoothingModeHighQuality);
        gfx.SetTextRenderingHint(TextRenderingHintClearTypeGridFit);
        gfx.SetPageUnit(UnitPixel);
        GraphicsPath shapes(data->Points, data->Types, data->Count);
        GraphicsPath shape;
        GraphicsPathIterator iterator(&shapes);

        SolidBrush br(Color(0, 0, 0));
        Pen pen(&br, 2.0f);

        Font f(hdc, GetDefaultGuiFont());
        // TODO: adjust these constant values for DPI?
        RectF layout((REAL)DpiScaleX(hwnd, 3), 1.0f, REAL(width - DpiScaleX(hwnd, 20)), (REAL)height);
        StringFormat sf(StringFormat::GenericDefault());
        sf.SetFormatFlags(StringFormatFlagsNoWrap);
        sf.SetLineAlignment(StringAlignmentCenter);
        sf.SetTrimming(StringTrimmingEllipsisCharacter);

        REAL yPosTab = inTitlebar ? 0.0f : REAL(ClientRect(hwnd).dy - height - 1);
        for (int i = 0; i < Count(); i++) {
            gfx.ResetTransform();
            gfx.TranslateTransform(1.f + (REAL)(width + 1) * i - (REAL)rc.left, yPosTab - (REAL)rc.top);

            if (!gfx.IsVisible(0, 0, width + 1, height + 1))
                continue;

            // Get the correct colors based on the state and the current theme
            COLORREF bgCol = GetAppColor(AppColor::TabBackgroundBg);
            COLORREF textCol = GetAppColor(AppColor::TabBackgroundText);
            COLORREF xColor = GetAppColor(AppColor::TabBackgroundCloseX);
            COLORREF circleColor = GetAppColor(AppColor::TabBackgroundCloseCircle);

            if (selectedTabIdx == i) {
                bgCol = GetAppColor(AppColor::TabSelectedBg);
                textCol = GetAppColor(AppColor::TabSelectedText);
                xColor = GetAppColor(AppColor::TabSelectedCloseX);
                circleColor = GetAppColor(AppColor::TabSelectedCloseCircle);
            } else if (highlighted == i) {
                bgCol = GetAppColor(AppColor::TabHighlightedBg);
                textCol = GetAppColor(AppColor::TabHighlightedText);
                xColor = GetAppColor(AppColor::TabHighlightedCloseX);
                circleColor = GetAppColor(AppColor::TabHighlightedCloseCircle);
            }
            if (xHighlighted == i) {
                xColor = GetAppColor(AppColor::TabHoveredCloseX);
                circleColor = GetAppColor(AppColor::TabHoveredCloseCircle);
            }
            if (xClicked == i) {
                xColor = GetAppColor(AppColor::TabClickedCloseX);
                circleColor = GetAppColor(AppColor::TabClickedCloseCircle);
            }

            // paint tab's body
            gfx.SetCompositingMode(CompositingModeSourceCopy);
            iterator.NextMarker(&shape);
            br.SetColor(ToColor(bgCol));
            Point points[4];
            shape.GetPathPoints(points, 4);
            Rect body(points[0].X, points[0].Y, points[2].X - points[0].X, points[2].Y - points[0].Y);
            body.Inflate(0, 0);
            gfx.SetClip(body);
            body.Inflate(5, 5);
            gfx.FillRectangle(&br, body);
            gfx.ResetClip();

            // draw tab's text
            gfx.SetCompositingMode(CompositingModeSourceOver);
            br.SetColor(ToColor(textCol));
            gfx.DrawString(text.at(i), -1, &f, layout, &sf, &br);

            // paint "x"'s circle
            iterator.NextMarker(&shape);
            bool closeCircleEnabled = true;
            if ((xClicked == i || xHighlighted == i) && closeCircleEnabled) {
                br.SetColor(ToColor(circleColor));
                gfx.FillPath(&br, &shape);
            }

            // paint "x"
            iterator.NextMarker(&shape);
            pen.SetColor(ToColor(xColor));
            gfx.DrawPath(&pen, &shape);
            iterator.Rewind();
        }
    }
Beispiel #22
0
//
//	Dialogbox procedure for Configuration window
//
BOOL CALLBACK ConfigDlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	static char buf[256];
	HWND	hwndCombo, hwndCtrl;
	int		index, items, val;
	RECT	rect;
	static  int prevwidth, prevheight;

	switch(uMsg)
	{
	case WM_INITDIALOG:

		prevwidth  = GetSystemMetrics(SM_CXSCREEN) / GLYPH_WIDTH;
		prevheight = GetSystemMetrics(SM_CYSCREEN) / GLYPH_HEIGHT + 1;

		//Add any saved messages to the combo box
		for(index = 0; index < g_nNumMessages; index++)
		{
			if(lstrlen(g_szMessages[index]) > 0)
				SendDlgItemMessage(hwnd, IDC_COMBO1, CB_ADDSTRING, 0, (LPARAM)g_szMessages[index]);
		}

		//select the first message, and preview it
		SendDlgItemMessage(hwnd, IDC_COMBO1, CB_SETCURSEL, 0, 0);
		
		SendDlgItemMessage(hwnd, IDC_SLIDER1, TBM_SETRANGE, 0, MAKELONG(SPEED_MIN, SPEED_MAX));
		SendDlgItemMessage(hwnd, IDC_SLIDER2, TBM_SETRANGE, 0, MAKELONG(DENSITY_MIN, DENSITY_MAX));
		SendDlgItemMessage(hwnd, IDC_SLIDER3, TBM_SETRANGE, 0, MAKELONG(MSGSPEED_MIN, MSGSPEED_MAX));
		SendDlgItemMessage(hwnd, IDC_SLIDER4, TBM_SETRANGE, 0, MAKELONG(FONT_MIN, FONT_MAX));

		//SendDlgItemMessage(hwnd, IDC_SLIDER1, TBM_SETTICFREQ, 5, 0);
		SendDlgItemMessage(hwnd, IDC_SLIDER2, TBM_SETTICFREQ, 5, 0);
		SendDlgItemMessage(hwnd, IDC_SLIDER3, TBM_SETTICFREQ, 50, 0);
		SendDlgItemMessage(hwnd, IDC_SLIDER4, TBM_SETTICFREQ, 2, 0);
		
		SendDlgItemMessage(hwnd, IDC_SLIDER1, TBM_SETPOS, TRUE, g_nMatrixSpeed);
		SendDlgItemMessage(hwnd, IDC_SLIDER2, TBM_SETPOS, TRUE, g_nDensity);
		SendDlgItemMessage(hwnd, IDC_SLIDER3, TBM_SETPOS, TRUE, g_nMessageSpeed);
		SendDlgItemMessage(hwnd, IDC_SLIDER4, TBM_SETPOS, TRUE, g_nFontSize);

		CheckDlgButton(hwnd, IDC_RANDOM, g_fRandomizeMessages);
		CheckDlgButton(hwnd, IDC_BOLD, g_fFontBold);

		AddFonts(GetDlgItem(hwnd, IDC_COMBO2));
		index = SendDlgItemMessage(hwnd, IDC_COMBO2, CB_FINDSTRING, 0, (LPARAM)g_szFontName);
		SendDlgItemMessage(hwnd, IDC_COMBO2, CB_SETCURSEL, index, 0);
		UpdatePreview(hwnd);
		return 0;

	case WM_DESTROY:
		//DeInitMessage();
		return 0;

	case WM_CTLCOLORSTATIC:

		if(GetDlgCtrlID((HWND)lParam) == IDC_ABOUT)
		{
			SetTextColor((HDC)wParam, RGB(0,80,0));
			SetBkColor((HDC)wParam, GetSysColor(COLOR_3DFACE));
			return (BOOL)GetSysColorBrush(COLOR_3DFACE);
		}
		else if(GetDlgCtrlID((HWND)lParam) == IDC_PREVIEW)
		{
			HDC hdc = (HDC)wParam;
			RECT clip;

			GetDlgItemText(hwnd, IDC_COMBO1, buf, 256);
			
			GetClientRect((HWND)lParam, &rect);

			if(prevwidth < rect.right)
			{
				rect.left = (rect.right-prevwidth) / 2;
				rect.right = rect.left + prevwidth;
			}
			else
			{
				rect.left  = 0;
				rect.right = prevwidth;
			}		

			if(prevheight < rect.bottom)
			{
				rect.top = (rect.bottom-prevheight) / 2;
				rect.bottom = rect.top + prevheight;
			}
			else
			{
				rect.top = 0;
				rect.bottom = prevheight;
			}

			SetTextColor(hdc, RGB(128,255,128));
			SetBkColor(hdc, 0);

			//SetRect(&rect, 0, 0, PrevMessage->width, MAXMSG_HEIGHT);
			CopyRect(&clip, &rect);
			FillRect(hdc, &rect, GetStockObject(BLACK_BRUSH));

			SelectObject(hdc, g_hFont);

			InflateRect(&clip, 2, 2);

			FrameRect(hdc, &clip, GetSysColorBrush(COLOR_3DSHADOW));
			IntersectClipRect(hdc, rect.left, rect.top, rect.right, rect.bottom);

			// figure out where the bounding rectangle should be
			DrawText(hdc, buf, -1, &rect, DT_CENTER|DT_VCENTER|DT_WORDBREAK|DT_CALCRECT);
			OffsetRect(&rect, (prevwidth-(rect.right-rect.left))/2, (prevheight-(rect.bottom-rect.top))/2);

			// now draw it!
			DrawText(hdc, buf, -1, &rect, DT_CENTER|DT_VCENTER|DT_WORDBREAK);
			

			return (BOOL)GetStockObject(NULL_BRUSH);
		}	
		else
		{
			break;
		}

	case WM_HSCROLL:

		if((HWND)lParam == GetDlgItem(hwnd, IDC_SLIDER4))
		{
			// one of the sliders changed..update
			UpdatePreview(hwnd);
		}

		return 0;

	case WM_COMMAND:

		switch(HIWORD(wParam))
		{
		case CBN_EDITCHANGE:
		case CBN_SELCHANGE:

			//fall through to Preview:
			index = SendDlgItemMessage(hwnd, IDC_COMBO2, CB_GETCURSEL, 0, 0);
			SendDlgItemMessage(hwnd, IDC_COMBO2, CB_GETLBTEXT, index, (LPARAM)g_szFontName);
			//SetMessageFont(hwnd, g_szFontName, g_nFontSize, TRUE);
			
			UpdatePreview(hwnd);
			return 0;
		}

		switch(LOWORD(wParam))
		{
		case IDC_RANDOM:
			g_fRandomizeMessages = IsDlgButtonChecked(hwnd, IDC_RANDOM);
			break;

		case IDC_BOLD:
			g_fFontBold = IsDlgButtonChecked(hwnd, IDC_BOLD);
			UpdatePreview(hwnd);
			break;

		case IDOK:
			
			hwndCtrl = GetDlgItem(hwnd, IDC_COMBO1);

			items = min(MAX_MESSAGES, SendMessage(hwndCtrl, CB_GETCOUNT, 0, 0));

			for(index = 0; index < items; index++)
			{
				SendMessage(hwndCtrl, CB_GETLBTEXT, index, (LPARAM)g_szMessages[index]);
			}

			g_nNumMessages = items;
			
			//matrix speed
			val = SendDlgItemMessage(hwnd, IDC_SLIDER1, TBM_GETPOS, 0, 0);	
			if(val >= SPEED_MIN && val <= SPEED_MAX)
				g_nMatrixSpeed = val;

			//density
			val = SendDlgItemMessage(hwnd, IDC_SLIDER2, TBM_GETPOS, 0, 0);	
			if(val >= DENSITY_MIN && val <= DENSITY_MAX)
				g_nDensity = val;

			//message speed
			val = SendDlgItemMessage(hwnd, IDC_SLIDER3, TBM_GETPOS, 0, 0);	
			if(val >= MSGSPEED_MIN && val <= MSGSPEED_MAX)
				g_nMessageSpeed = val;

			//font size
			val = SendDlgItemMessage(hwnd, IDC_SLIDER4, TBM_GETPOS, 0, 0);	
			if(val >= FONT_MIN && val <= FONT_MAX)
				g_nFontSize = val;

			SaveSettings();
			EndDialog(hwnd, 0);
			return 0;

		case IDCANCEL:
			EndDialog(hwnd, 0);
			return TRUE;

		case IDC_ADD:
			
			hwndCombo = GetDlgItem(hwnd, IDC_COMBO1);
			
			if(GetWindowText(hwndCombo, buf, 256))
			{
				SendMessage(hwndCombo, CB_ADDSTRING, 0, (LPARAM)buf);
			}
			
			UpdatePreview(hwnd);

			return 0;

		case IDC_REMOVE:
			hwndCombo = GetDlgItem(hwnd, IDC_COMBO1);
			GetWindowText(hwndCombo, buf, 256);

			index = SendMessage(hwndCombo, CB_GETCURSEL, 0, 0);
			SendMessage(hwndCombo, CB_DELETESTRING, index, 0);

			SendMessage(hwndCombo, CB_SETCURSEL, 0, 0);
			UpdatePreview(hwnd);
			return 0;
		}
		return 0;

	case WM_CLOSE:
		EndDialog(hwnd, 0);
		return 0;
	}
	return 0;
}
void GraphicsContextPlatformPrivate::clip(const FloatRect& clipRect)
{
    if (!m_hdc)
        return;
    IntersectClipRect(m_hdc, clipRect.x(), clipRect.y(), clipRect.right(), clipRect.bottom());
}
Beispiel #24
0
void DrawColorCol (PLEGEND pLegend,
                   PLINE pLine,
                   int iCol,
                   HDC hDC,
                   int yPos)
/*
   Effect:        Draw the "color" column of a legend entry. The color 
                  column displays a small sample of the line drawing.

                  For charts, the sample is a line of the correct style,
                  color, and width.  Since we are using wide lines, 
                  the round endcaps of the lines will breach the column.
                  Therefore we need to set the clip region. We could
                  remove this clipping if we find a way to change the
                  end cap design.  

                  For alerts, the sample is a small circle which echos
                  the design in the alert log itself.
*/      
   {  // DrawColorCol
   HBRUSH         hBrush, hBrushPrevious ;
   RECT           rect ;
   int            yMiddle ;
   int            iCircle ;



   rect.left = pLegend->aCols[iCol].xPos - LegendLeftMargin () + 2 ;
   rect.top = yPos + 1 ;
   rect.right = rect.left + pLegend->aCols[iCol].xWidth - LegendHorzMargin () ;
   rect.bottom = yPos + pLegend->yItemHeight - 1 ;

   yMiddle = rect.top + (rect.bottom - rect.top) / 2 ;
   iCircle = rect.bottom - rect.top - 2 ;
 
  switch (pLegend->iLineType)
      {  // switch
      case LineTypeChart:
   
         if (pLine->Visual.iWidth == 1)
            {
            // simple case with thin pen
//            hBrush = SelectBrush (hDC, hbLightGray) ;
            hBrush = SelectBrush (hDC, hBrushFace) ;
            Rectangle (hDC, rect.left, rect.top, rect.right, rect.bottom) ;
   
            HLine (hDC, pLine->hPen, 
                   rect.left + 1, rect.right - 1, yMiddle) ;
            SelectBrush (hDC, hBrush) ;
            }
         else
            {
            // thicker pen width, have to set ClipRect so
            // it will not draw otherside the rect.
            SaveDC (hDC) ;
//            hBrush = SelectBrush (hDC, hbLightGray) ;
            hBrush = SelectBrush (hDC, hBrushFace) ;
            Rectangle (hDC, rect.left, rect.top, rect.right, rect.bottom) ;
   
            IntersectClipRect (hDC, 
                               rect.left + 1,
                               rect.top + 1,
                               rect.right - 1,
                               rect.bottom - 1) ;
            HLine (hDC, pLine->hPen, 
                   rect.left + 1, rect.right - 1, yMiddle) ;
            SelectBrush (hDC, hBrush) ;
            RestoreDC (hDC, -1) ;
            }
         break ;


      case LineTypeAlert:
         hBrushPrevious = SelectBrush (hDC, pLine->hBrush) ;

         Ellipse (hDC,
                  rect.left + 2,
                  rect.top + 2,
                  rect.left + 2 + iCircle,
                  rect.top + 2 + iCircle) ;

         SelectBrush (hDC, hBrushPrevious) ;
         break ;
      }  // switch

   }  // DrawColorCol
Beispiel #25
0
static void
button_paint_split(HWND win, button_t* button, HDC dc)
{
    RECT rect;
    RECT rect_left, rect_right;
    int state_left, state_right;
    int text_offset = 0;
    HFONT font, old_font;
    int old_bk_mode;
    COLORREF old_text_color;
    HRGN old_clip;
    HICON glyph;
    int width_right = DROPDOWN_W;

    glyph = ImageList_GetIcon(mc_bmp_glyphs, MC_BMP_GLYPH_MORE_OPTIONS, ILD_TRANSPARENT);
    GetClientRect(win, &rect);

    font = (HFONT) MC_SEND(win, WM_GETFONT, 0, 0);
    if(font == NULL)
        font = GetStockObject(SYSTEM_FONT);

    old_font = SelectObject(dc, font);
    old_bk_mode = GetBkMode(dc);
    old_text_color = GetTextColor(dc);
    old_clip = get_clip(dc);

    /* Draw what's common for left and right parts background. */
    if(!button->theme  &&  (button->style & BS_DEFPUSHBUTTON)) {
        SelectObject(dc, GetSysColorBrush(COLOR_WINDOWFRAME));
        Rectangle(dc, rect.left, rect.top, rect.right, rect.bottom);
        mc_rect_inflate(&rect, -1, -1);
        width_right--;
    }

    /* Setup subrectangles (mainpart 1 and push-down part 2) */
    mc_rect_copy(&rect_left, &rect);
    rect_left.right -= width_right;
    mc_rect_copy(&rect_right, &rect);
    rect_right.left = rect_left.right;

    /* Draw background. */
    if(button->theme) {
        UINT transparent;
        RECT tmp;

        /* Determine styles for left and right parts */
        if(button->style & WS_DISABLED) {
            state_left = state_right = PBS_DISABLED;
        } else {
            LRESULT state;

            state = MC_SEND(win, BM_GETSTATE, 0, 0);
            if(state & MC_BST_DROPDOWNPUSHED) {
                state_left = PBS_NORMAL;
                state_right = PBS_PRESSED;
            } else {
                if(state & BST_PUSHED)
                    state_left = state_right = PBS_PRESSED;
                else if(state & BST_HOT)
                    state_left = state_right = PBS_HOT;
                else if(button->style & BS_DEFPUSHBUTTON)
                    state_left = state_right = PBS_DEFAULTED;
                else
                    state_left = state_right = PBS_NORMAL;
            }
        }

        /* Handle (semi-)transparent themes. */
        transparent = 0;
        if(mcIsThemeBackgroundPartiallyTransparent(button->theme,
                    BP_PUSHBUTTON, state_left))
            transparent |= 0x1;
        if(mcIsThemeBackgroundPartiallyTransparent(button->theme,
                    BP_PUSHBUTTON, state_right))
            transparent |= 0x2;
        switch(transparent) {
            case 0x1:
                mcDrawThemeParentBackground(win, dc, &rect_left);
                break;
            case 0x2:
                mcDrawThemeParentBackground(win, dc, &rect_right);
                break;
            case 0x3:
                mcDrawThemeParentBackground(win, dc, &rect);
                break;
        }

        /* Draw backgrond. */
        mcDrawThemeBackground(button->theme, dc, BP_PUSHBUTTON, state_left, &rect, &rect_left);
        mcDrawThemeBackground(button->theme, dc, BP_PUSHBUTTON, state_right, &rect, &rect_right);

        /* Deflate both rects to content rects only */
        mcGetThemeBackgroundContentRect(button->theme, dc, BP_PUSHBUTTON, state_left, &rect_left, &tmp);
        rect_left.left = tmp.left;
        rect_left.top = tmp.top;
        rect_left.bottom = tmp.bottom;
        mcGetThemeBackgroundContentRect(button->theme, dc, BP_PUSHBUTTON, state_right, &rect_right, &tmp);
        rect_right.top = tmp.top;
        rect_right.right = tmp.right;
        rect_right.bottom = tmp.bottom;

        /* Draw delimiter of left and right parts. */
        rect_right.top += 1;
        rect_right.bottom -= 1;
        mcDrawThemeEdge(button->theme, dc, BP_PUSHBUTTON, state_right, &rect_right, BDR_SUNKEN, BF_LEFT, NULL);
        rect_right.left = tmp.left;
    } else {
        /* Determine styles for left and right parts */
        if(button->style & WS_DISABLED) {
            state_left = state_right = DFCS_INACTIVE;
        } else {
            LRESULT s = MC_SEND(win, BM_GETSTATE, 0, 0);
            if(s & MC_BST_DROPDOWNPUSHED) {
                state_left = 0;
                state_right = DFCS_PUSHED;
            } else {
                if(s & BST_PUSHED) {
                    state_left = state_right = DFCS_PUSHED;
                } else {
                    state_left = state_right = 0;
                }
            }
        }

        button_send_ctlcolorbtn(win, dc);

        /* Draw control edges */
        IntersectClipRect(dc, rect_left.left, rect_left.top, rect_left.right, rect_left.bottom);
        DrawFrameControl(dc, &rect, DFC_BUTTON, DFCS_BUTTONPUSH | state_left);
        SelectClipRgn(dc, NULL);
        IntersectClipRect(dc, rect_right.left, rect_right.top, rect_right.right, rect_right.bottom);
        DrawFrameControl(dc, &rect, DFC_BUTTON, DFCS_BUTTONPUSH | state_right);

        /* Parts which are pushed, should have the contents moved a bit */
        if(state_left == DFCS_PUSHED)
            mc_rect_offset(&rect_left, 1, 1);
        if(state_right == DFCS_PUSHED)
            mc_rect_offset(&rect_right, 1, 1);

        /* Draw delimiter */
        if(state_left == state_right) {
            DrawEdge(dc, &rect_right, BDR_SUNKENOUTER | BDR_RAISEDINNER, BF_LEFT | BF_SOFT);
        } else {
            rect_right.left--;
            DrawEdge(dc, &rect_right, BDR_SUNKENOUTER, BF_LEFT | BF_SOFT);
            rect_right.left++;
        }

        /* Adjust for the outer control edges */
        mc_rect_inflate(&rect_left, 0, -2);
        rect_left.left += 2;
        mc_rect_inflate(&rect_right, -2, -2);
    }

    /* Draw focus rectangle. */
    if((MC_SEND(win, BM_GETSTATE, 0, 0) & BST_FOCUS) && !button->hide_focus) {
        SelectClipRgn(dc, NULL);
        if(button->theme) {
            mc_rect_set(&rect, rect_left.left, rect_left.top,
                        rect_right.right - DROPDOWN_W, rect_right.bottom);
            DrawFocusRect(dc, &rect);
        } else {
            mc_rect_inflate(&rect_left, -1, -2);
            DrawFocusRect(dc, &rect_left);
            mc_rect_inflate(&rect_left, -1, -1);
        }
    }

    /* Draw glyph into the right part */
    SelectClipRgn(dc, NULL);
    IntersectClipRect(dc, rect_right.left, rect_right.top,
                          rect_right.right, rect_right.bottom);
    DrawIconEx(dc, (rect_right.right + rect_right.left - MC_BMP_GLYPH_W) / 2,
                   (rect_right.bottom + rect_right.top - MC_BMP_GLYPH_H) / 2,
                   glyph, MC_BMP_GLYPH_W, MC_BMP_GLYPH_H, 0, NULL, DI_NORMAL);

    /* Draw left part contents */
    SelectClipRgn(dc, NULL);
    IntersectClipRect(dc, rect_left.left, rect_left.top,
                          rect_left.right, rect_left.bottom);
    if(button->style & BS_ICON) {
        /* Paint (BS_SPLITBUTTON | BS_ICON). Note that this is used even on
         * Vista, as according to some my testing this style combination
         * is not supported there... */
        HICON icon;

        icon = (HICON) MC_SEND(win, BM_GETIMAGE, (WPARAM) IMAGE_ICON, (LPARAM) 0);
        if(icon != NULL) {
            SIZE size;
            UINT flags;

            mc_icon_size(icon, &size);

            flags = DST_ICON;
            if(button->style & WS_DISABLED)
                flags |= DSS_DISABLED;

            DrawState(dc, NULL, NULL, (LPARAM) icon, 0,
                      (rect_left.right + rect_left.left - size.cx) / 2,
                      (rect_left.bottom + rect_left.top - size.cy) / 2,
                      size.cx, size.cy, flags);
        }
    } else {
        /* Paint text label */
        TCHAR buffer[256];
        int n;
        UINT flags = 0;

        /* Setup flags for TextOut/mcDrawThemeText */
        switch(button->style & (BS_LEFT | BS_CENTER | BS_RIGHT)) {
            case BS_LEFT:
                flags |= DT_LEFT;
                break;
            case BS_RIGHT:
                flags |= DT_RIGHT;
                break;
            default:
                if(GetWindowLong(win, GWL_EXSTYLE) & WS_EX_RIGHT)
                    flags |= DT_RIGHT;
                else
                    flags |= DT_CENTER;
                break;
        }
        switch(button->style & (BS_TOP | BS_VCENTER | BS_BOTTOM)) {
            case BS_TOP:
                flags |= DT_TOP;
                break;
            case BS_BOTTOM:
                flags |= DT_BOTTOM;
                break;
            default:
                flags |= DT_VCENTER;
                break;
        }
        if(button->style & BS_MULTILINE)
            flags |= DT_WORDBREAK;
        else
            flags |= DT_SINGLELINE;

        if(button->hide_accel)
            flags |= DT_HIDEPREFIX;

        n = MC_SEND(win, WM_GETTEXT, MC_ARRAY_SIZE(buffer), buffer);

        if(button->theme) {
            mcDrawThemeText(button->theme, dc, BP_PUSHBUTTON,
                        state_left, buffer, n, flags, 0, &rect_left);
        } else {
            SetBkMode(dc, TRANSPARENT);
            SetTextColor(dc, GetSysColor(COLOR_BTNTEXT));
            mc_rect_offset(&rect_left, text_offset, text_offset);
            DrawText(dc, buffer, n, &rect_left, flags);
        }
    }

    SelectObject(dc, old_font);
    SetBkMode(dc, old_bk_mode);
    SetTextColor(dc, old_text_color);
    SelectObject(dc, old_clip);
}
Beispiel #26
0
/***********************************************************************
 *      BeginBufferedPaint                                 (UXTHEME.@)
 */
HPAINTBUFFER WINAPI BeginBufferedPaint(HDC targetdc, const RECT *rect,
        BP_BUFFERFORMAT format, BP_PAINTPARAMS *params, HDC *retdc)
{
    char bmibuf[FIELD_OFFSET(BITMAPINFO, bmiColors[256])];
    BITMAPINFO *bmi = (BITMAPINFO *)bmibuf;
    struct paintbuffer *buffer;

    TRACE("(%p %s %d %p %p)\n", targetdc, wine_dbgstr_rect(rect), format,
          params, retdc);

    if (retdc)
        *retdc = NULL;

    if (!targetdc || IsRectEmpty(rect))
        return NULL;

    if (params)
        FIXME("painting parameters are ignored\n");

    buffer = HeapAlloc(GetProcessHeap(), 0, sizeof(*buffer));
    buffer->targetdc = targetdc;
    buffer->rect = *rect;
    buffer->memorydc = CreateCompatibleDC(targetdc);

    switch (format)
    {
    case BPBF_COMPATIBLEBITMAP:
        buffer->bitmap = CreateCompatibleBitmap(targetdc, rect->right - rect->left, rect->bottom - rect->top);
        buffer->bits = NULL;
        break;
    case BPBF_DIB:
    case BPBF_TOPDOWNDIB:
    case BPBF_TOPDOWNMONODIB:
        /* create DIB section */
        memset(bmi, 0, sizeof(bmibuf));
        bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
        bmi->bmiHeader.biHeight = format == BPBF_DIB ? rect->bottom - rect->top :
                -(rect->bottom - rect->top);
        bmi->bmiHeader.biWidth = rect->right - rect->left;
        bmi->bmiHeader.biBitCount = format == BPBF_TOPDOWNMONODIB ? 1 : 32;
        bmi->bmiHeader.biPlanes = 1;
        bmi->bmiHeader.biCompression = BI_RGB;
        buffer->bitmap = CreateDIBSection(buffer->memorydc, bmi, DIB_RGB_COLORS, &buffer->bits, NULL, 0);
        break;
    default:
        WARN("Unknown buffer format %d\n", format);
        buffer->bitmap = NULL;
        free_paintbuffer(buffer);
        return NULL;
    }

    if (!buffer->bitmap)
    {
        WARN("Failed to create buffer bitmap\n");
        free_paintbuffer(buffer);
        return NULL;
    }

    SetWindowOrgEx(buffer->memorydc, rect->left, rect->top, NULL);
    IntersectClipRect(buffer->memorydc, rect->left, rect->top, rect->right, rect->bottom);
    DeleteObject(SelectObject(buffer->memorydc, buffer->bitmap));

    *retdc = buffer->memorydc;

    return (HPAINTBUFFER)buffer;
}
Beispiel #27
0
void clipper_t::crop(int x, int y, int w, int h)
{
	IntersectClipRect(hdc, x, y, x+w, y+h);
}
Beispiel #28
0
LRESULT CALLBACK MainWndProc(HWND HWnd, UINT Msg, WPARAM WParam,
   LPARAM LParam)
{
  const char* text = "Persistent Text";

   switch (Msg)
   {
      case WM_PAINT:
      {
         // determine the invalidated area of the window
         RECT RUpdate;
         HDC Hdc;
         GetUpdateRect(HWnd, &RUpdate, FALSE);

         // grab a handle to our window's
         // common display device context
         Hdc = GetDC(HWnd);
#if 0
         try
#endif
         {
            RECT RClient;
            GetClientRect(HWnd, &RClient);

            // set the clipping region
            IntersectClipRect(Hdc, RUpdate.left, RUpdate.top,
                              RUpdate.right, RUpdate.bottom);

            // fill the client area with the background brush
            /*HBRUSH HBrush =
               reinterpret_cast<HBRUSH>
                  (HBRUSH)(GetClassLong(HWnd, GCL_HBRBACKGROUND)
                  );*/
            FillRect(Hdc, &RClient, NULL);

            // render the persistent text
            SetTextColor(Hdc, PALETTERGB(0, 0, 255));
            DrawText(Hdc, text, strlen(text), &RClient,
                     DT_CENTER | DT_VCENTER | DT_SINGLELINE);
         }
#if 0
         catch (...)
#endif
         {
            // release the device context
            ReleaseDC(HWnd, Hdc);

            // validate the update area
            ValidateRect(HWnd, &RUpdate);
         }
         // release the device context
         ReleaseDC(HWnd, Hdc);

         // validate the update area
         ValidateRect(HWnd, &RUpdate);

         break;
      }
      case WM_DESTROY:
      {
         PostQuitMessage(0);
         return 0;
      }
   }
   return DefWindowProc(HWnd, Msg, WParam, LParam);
}
Beispiel #29
0
void Label::Paint(HDC hDC)
{
    // Figure out how much space we have to work with
    int x = mPaddingLeft;
    int y = mPaddingTop;
    int w = mWidth - mPaddingLeft - mPaddingRight;
    int h = mHeight - mPaddingTop - mPaddingBottom;
    
    // Compute the size of the image
    int wImage = 0;
    int hImage = 0;
    
    if (mImage)
    {
        GetLSBitmapSize(mImage, &wImage, &hImage);
    }
    
    // Compute the amount of space between the image and the text
    int wGap = 0;
    int hGap = 0;
    
    if (mImage && StrLen(mText) > 0)
    {
        wGap = mImageTextGap;
        hGap = mImageTextGap;
    }
    
    // Compute the size of the text
    int wText = 0;
    int hText = 0;
    
    if (StrLen(mText) > 0)
    {
        GetTextExtent(hDC, &wText, &hText);
    }
    
    // Compute the size of the content area (image and text)
    int wContent = 0;
    int hContent = 0;
    
    if (mImagePosition == IMAGE_POSITION_LEFT || mImagePosition == IMAGE_POSITION_RIGHT)
    {
        wContent = wImage + wGap + wText;
        hContent = max(hImage, hText);
    }
    else
    {
        wContent = max(wImage, wText);
        hContent = hImage + hGap + hText;
    }
    
    // Align the content area horizontally
    int xContent = 0;
    
    switch (mAlign)
    {
    case ALIGN_LEFT:
        xContent = x;
        break;
        
    case ALIGN_CENTER:
        xContent = x + (w - wContent) / 2;
        break;
        
    case ALIGN_RIGHT:
        xContent = x + (w - wContent);
        break;
    }
    
    // Align the content area vertically
    int yContent = 0;
    
    switch (mVerticalAlign)
    {
    case VERTICAL_ALIGN_TOP:
        yContent = y;
        break;
        
    case VERTICAL_ALIGN_CENTER:
        yContent = y + (h - hContent) / 2;
        break;
        
    case VERTICAL_ALIGN_BOTTOM:
        yContent = y + (h - hContent);
        break;
    }
    
    // Place the image and the text
    int xImage = 0;
    int yImage = 0;
    int xText = 0;
    int yText = 0;
    
    switch (mImagePosition)
    {
    case IMAGE_POSITION_LEFT:
        xImage = xContent;
        yImage = yContent + (hContent - hImage) / 2;
        xText = xContent + wImage + wGap;
        yText = yContent + (hContent - hText) / 2;
        break;
        
    case IMAGE_POSITION_TOP:
        xImage = xContent + (wContent - wImage) / 2;
        yImage = yContent;
        xText = xContent + (wContent - wText) / 2;
        yText = yContent + hImage + hGap;
        break;
        
    case IMAGE_POSITION_RIGHT:
        xImage = xContent + wText + wGap;
        yImage = yContent + (hContent - hImage) / 2;
        xText = xContent;
        yText = yContent + (hContent - hText) / 2;
        break;
        
    case IMAGE_POSITION_BOTTOM:
        xImage = xContent + (wContent - wImage) / 2;
        yImage = yContent + hText + hGap;
        xText = xContent + (wContent - wText) / 2;
        yText = yContent;
        break;
    }
    
    // Paint the background
    DrawBackground(hDC);
    
    // Clip the content area
    IntersectClipRect(hDC, x, y, x + w, y + h);
    
    // Paint the image
    if (mImage)
    {
        DrawImage(hDC, xImage, yImage);
    }
    
    // Paint the text
    if (StrLen(mText) > 0)
    {
        DrawText(hDC, xText, yText);
    }
}
Beispiel #30
0
void TraceWindow::Draw_JumpLog(HDC p_hdc) {
  SetScrollMax(GetAllLine());

  HDC hdc = m_dlg->getBackDC();

  HBRUSH hbBG = (HBRUSH)CreateSolidBrush(COLOR_BG);
  HBRUSH hbFixedBG = (HBRUSH)CreateSolidBrush(GetSysColor(COLOR_3DFACE));
  HBRUSH hbSelect = CreateSolidBrush(COLOR_SELECT);

  SetBkColor(p_hdc, RGB(0, 0, 0));
  SetBkMode(p_hdc, TRANSPARENT);
  g_dbg->setFontToFixed(p_hdc);

  RECT clientrect;
  GetClientRect(m_dlg->getHwnd(), &clientrect);

  DrawListFrame();

  SetTextColor(p_hdc, RGB(255, 255, 255));

  char str[1024];
  for (int i = 0; i < GetPageLine() + 1; i++) {
    int left = 0;
    for (u32 j = 0; j < m_col_array.size(); j++) {
      RECT selrect;
      selrect.top    = i * kFontSize + GetListTop();
      selrect.bottom  = (i + 1) * kFontSize + GetListTop();
      selrect.left  = left + 1;
      selrect.right  = left + m_col_array[j]->width;

      // 最後はウィンドウの端まで
      if (j == m_col_array.size() - 1) selrect.right = clientrect.right;

      if (i + m_head < GetAllLine() && m_sel == i + m_head) FillRect(hdc, &selrect, hbSelect);
      else FillRect(hdc, &selrect, hbBG);

      if (i + m_head < GetAllLine()) {
        switch (j) {
        case 0:
          sprintf(str, "%08x", g_dbg->jumplog(i + m_head)->va());
          TextOut(hdc, left + 4, kFontSize * i + GetListTop(), str, strlen(str));
          break;
        case 1:
          //if (g_dbg->jumplog(i + m_head)->m_repeat.size() > 0) {
          //  int ridx = g_dbg->jumplog(i + m_head)->m_repeat.size() - 1;
          //  sprintf(str, "    cnt=%d len=%d lv=%d",
          //    g_dbg->jumplog(i + m_head)->m_repeat[ridx]->count,
          //    g_dbg->jumplog(i + m_head)->m_repeat[ridx]->len,
          //    g_dbg->getJumpLogNestLevel(i + m_head, ridx) + ridx - 1);
          //  TextOut(hdc, left + 4, kFontSize * i + GetListTop(), str, strlen(str));
          //}
          break;
        }
      }
      left += m_col_array[j]->width;
    }
  }

  // ヘッダ行を上書きしてしまうのでクリッピング
  IntersectClipRect(hdc, clientrect.left, GetListTop(), clientrect.right, clientrect.bottom);
  
  // ネストブロックを図で示す
  HPEN hpPen = CreatePen(PS_SOLID, 1, RGB(255, 255, 64));
  SelectObject(hdc, hpPen);
  SelectObject(p_hdc, m_small_font);
  for (int i = 0; i < g_dbg->jumplog_count(); i++) {
    for (u32 j = 0; j < g_dbg->jumplog(i)->m_repeat.size(); j++) {
      const int kNestIndent = 12;
      int level = g_dbg->getJumpLogNestLevel(i, j) + j;
      int range = g_dbg->jumplog(i)->m_repeat[j]->len - 1;
      int count = g_dbg->jumplog(i)->m_repeat[j]->count;
      int left = m_col_array[0]->width;
      int top  = GetListTop() + kFontSize * (i - m_head);
      
      s8 cnt_str[256];
      if (count > 999) {
        strcpy(cnt_str, "*");
      } else {
        _itoa(count, cnt_str, 10);
      }

      if (g_dbg->jumplog(i)->m_repeat[j]->len == 1) {
        MoveToEx(hdc, left, top + kFontSize / 2, NULL);
        LineTo(hdc,   left + 4, top + kFontSize / 2);

        TextOut(hdc, left + 5, top, cnt_str, strlen(cnt_str));
      } else {
        MoveToEx(hdc, left, top + 2, NULL);
        LineTo(hdc,   left + level * kNestIndent, top + 2);

        MoveToEx(hdc, left, top - 2 + kFontSize * (1 + range), NULL);
        LineTo(hdc,   left + level * kNestIndent, top - 2 + kFontSize * (1 + range));

        MoveToEx(hdc, left + level * kNestIndent, top + 3, NULL);
        LineTo(hdc,   left + level * kNestIndent, top - 2 + kFontSize * (1 + range));

        TextOut(hdc, left + 1 + level * kNestIndent, top + range * kFontSize / 2, cnt_str, strlen(cnt_str));
      }
    }
  }
  DeleteObject(hpPen);

  DeleteObject(hbSelect);
  DeleteObject(hbFixedBG);
  DeleteObject(hbBG);

  m_dlg->update(0, GetListHeaderTop(), clientrect.right, clientrect.bottom);
}