void XDrawLines( Display *display, Drawable d, GC gc, XPoint *points, int npoints, int mode) { HPEN pen; TkWinDCState state; HDC dc; if (d == None) { return; } dc = TkWinGetDrawableDC(display, d, &state); pen = SetUpGraphicsPort(gc); SetBkMode(dc, TRANSPARENT); RenderObject(dc, gc, points, npoints, mode, pen, Polyline); DeleteObject(pen); TkWinReleaseDrawableDC(d, dc, &state); }
void XFillPolygon( Display *display, Drawable d, GC gc, XPoint *points, int npoints, int shape, int mode) { HPEN pen; TkWinDCState state; HDC dc; if (d == None) { return; } dc = TkWinGetDrawableDC(display, d, &state); pen = GetStockObject(NULL_PEN); RenderObject(dc, gc, points, npoints, mode, pen, Polygon); TkWinReleaseDrawableDC(d, dc, &state); }
static void TroughElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { TroughClientData *cd = clientData; TkWinDCState dcState; HDC hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); HBRUSH hbr; COLORREF bk, oldbk, oldtxt; hbr = SelectObject(hdc, GetSysColorBrush(COLOR_SCROLLBAR)); bk = GetSysColor(COLOR_3DHIGHLIGHT); oldtxt = SetTextColor(hdc, GetSysColor(COLOR_3DFACE)); oldbk = SetBkColor(hdc, bk); /* WAS: if (bk (COLOR_3DHIGHLIGHT) == GetSysColor(COLOR_WINDOW)) ... */ if (GetSysColor(COLOR_SCROLLBAR) == GetSysColor(COLOR_BTNFACE)) { /* Draw using the pattern brush */ SelectObject(hdc, cd->PatternBrush); } PatBlt(hdc, b.x, b.y, b.width, b.height, PATCOPY); SetBkColor(hdc, oldbk); SetTextColor(hdc, oldtxt); SelectObject(hdc, hbr); TkWinReleaseDrawableDC(d, hdc, &dcState); }
void XDrawRectangle( Display *display, Drawable d, GC gc, int x, int y, unsigned int width, unsigned int height) { HPEN pen, oldPen; TkWinDCState state; HBRUSH oldBrush; HDC dc; if (d == None) { return; } dc = TkWinGetDrawableDC(display, d, &state); pen = SetUpGraphicsPort(gc); SetBkMode(dc, TRANSPARENT); oldPen = SelectObject(dc, pen); oldBrush = SelectObject(dc, GetStockObject(NULL_BRUSH)); SetROP2(dc, tkpWinRopModes[gc->function]); Rectangle(dc, x, y, (int) x+width+1, (int) y+height+1); DeleteObject(SelectObject(dc, oldPen)); SelectObject(dc, oldBrush); TkWinReleaseDrawableDC(d, dc, &state); }
static void ClientElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { RECT rc = BoxToRect(b); TkWinDCState dcState; HDC hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); DrawEdge(hdc, &rc, EDGE_RAISED, BF_RECT | BF_SOFT); TkWinReleaseDrawableDC(d, hdc, &dcState); }
static void FocusElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { if (state & TTK_STATE_FOCUS) { RECT rc = BoxToRect(b); TkWinDCState dcState; HDC hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); DrawFocusRect(hdc, &rc); TkWinReleaseDrawableDC(d, hdc, &dcState); } }
int XCopyArea( Display *display, Drawable src, Drawable dest, GC gc, int src_x, int src_y, unsigned int width, unsigned int height, int dest_x, int dest_y) { HDC srcDC, destDC; TkWinDCState srcState, destState; TkpClipMask *clipPtr = (TkpClipMask*)gc->clip_mask; srcDC = TkWinGetDrawableDC(display, src, &srcState); if (src != dest) { destDC = TkWinGetDrawableDC(display, dest, &destState); } else { destDC = srcDC; } if (clipPtr && clipPtr->type == TKP_CLIP_REGION) { SelectClipRgn(destDC, (HRGN) clipPtr->value.region); OffsetClipRgn(destDC, gc->clip_x_origin, gc->clip_y_origin); } BitBlt(destDC, dest_x, dest_y, (int) width, (int) height, srcDC, src_x, src_y, (DWORD) tkpWinBltModes[gc->function]); SelectClipRgn(destDC, NULL); if (src != dest) { TkWinReleaseDrawableDC(dest, destDC, &destState); } TkWinReleaseDrawableDC(src, srcDC, &srcState); return Success; }
static void FrameControlElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { FrameControlElementData *elementData = clientData; RECT rc = BoxToRect(Ttk_PadBox(b, elementData->margins)); TkWinDCState dcState; HDC hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); DrawFrameControl(hdc, &rc, elementData->classId, elementData->partId|Ttk_StateTableLookup(elementData->stateMap, state)); TkWinReleaseDrawableDC(d, hdc, &dcState); }
static void ThumbElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { RECT rc = BoxToRect(b); TkWinDCState dcState; HDC hdc; /* Windows doesn't show a thumb when the scrollbar is disabled */ if (state & TTK_STATE_DISABLED) return; hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); DrawEdge(hdc, &rc, EDGE_RAISED, BF_RECT | BF_MIDDLE); TkWinReleaseDrawableDC(d, hdc, &dcState); }
static void FieldElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { FieldElement *field = elementRecord; Tk_3DBorder bg = Tk_Get3DBorderFromObj(tkwin, field->backgroundObj); RECT rc = BoxToRect(b); TkWinDCState dcState; HDC hdc; Tk_Fill3DRectangle( tkwin, d, bg, b.x, b.y, b.width, b.height, 0, TK_RELIEF_FLAT); hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); DrawEdge(hdc, &rc, EDGE_SUNKEN, BF_RECT); TkWinReleaseDrawableDC(d, hdc, &dcState); }
/* @@@ FIX THIS */ static void FillFocusElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { FillFocusElement *focus = elementRecord; if (state & TTK_STATE_FOCUS) { RECT rc = BoxToRect(b); TkWinDCState dcState; XColor *fillColor = Tk_GetColorFromObj(tkwin, focus->fillColorObj); GC gc = Tk_GCForColor(fillColor, d); HDC hdc; XFillRectangle(Tk_Display(tkwin),d,gc, b.x,b.y,b.width,b.height); hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); DrawFocusRect(hdc, &rc); TkWinReleaseDrawableDC(d, hdc, &dcState); } }
static void BorderElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { BorderElement *border = elementRecord; RECT rc = BoxToRect(b); int relief = TK_RELIEF_FLAT; TkWinDCState dcState; HDC hdc; Tk_GetReliefFromObj(NULL, border->reliefObj, &relief); if (relief != TK_RELIEF_FLAT) { UINT xFlags = (relief == TK_RELIEF_SOLID) ? BF_FLAT : 0; hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); DrawEdge(hdc, &rc, ReliefToEdge(relief), BF_RECT | xFlags); TkWinReleaseDrawableDC(d, hdc, &dcState); } }
static void ButtonBorderElementDraw( void *clientData, void *elementRecord, Tk_Window tkwin, Drawable d, Ttk_Box b, unsigned int state) { ButtonBorderElement *bd = elementRecord; int relief = TK_RELIEF_FLAT; int defaultState = TTK_BUTTON_DEFAULT_DISABLED; TkWinDCState dcState; HDC hdc; RECT rc; Tk_GetReliefFromObj(NULL, bd->reliefObj, &relief); Ttk_GetButtonDefaultStateFromObj(NULL, bd->defaultStateObj, &defaultState); if (defaultState == TTK_BUTTON_DEFAULT_ACTIVE) { XColor *highlightColor = Tk_GetColorFromObj(tkwin, bd->highlightColorObj); GC gc = Tk_GCForColor(highlightColor, d); XDrawRectangle(Tk_Display(tkwin), d, gc, b.x,b.y,b.width-1,b.height-1); } if (defaultState != TTK_BUTTON_DEFAULT_DISABLED) { ++b.x; ++b.y; b.width -= 2; b.height -= 2; } hdc = TkWinGetDrawableDC(Tk_Display(tkwin), d, &dcState); rc = BoxToRect(b); DrawFrameControl(hdc, &rc, DFC_BUTTON, /* classId */ DFCS_BUTTONPUSH | Ttk_StateTableLookup(pushbutton_statemap, state)); /* Draw focus ring: */ if (state & TTK_STATE_FOCUS) { short int borderWidth = 3; /* @@@ Use GetSystemMetrics?*/ rc = BoxToRect(Ttk_PadBox(b, Ttk_UniformPadding(borderWidth))); DrawFocusRect(hdc, &rc); } TkWinReleaseDrawableDC(d, hdc, &dcState); }
void XFillRectangles( Display *display, Drawable d, GC gc, XRectangle *rectangles, int nrectangles) { HDC dc; int i; RECT rect; TkWinDCState state; HBRUSH brush, oldBrush; if (d == None) { return; } dc = TkWinGetDrawableDC(display, d, &state); SetROP2(dc, tkpWinRopModes[gc->function]); brush = CreateSolidBrush(gc->foreground); if ((gc->fill_style == FillStippled || gc->fill_style == FillOpaqueStippled) && gc->stipple != None) { TkWinDrawable *twdPtr = (TkWinDrawable *)gc->stipple; HBRUSH stipple; HBITMAP oldBitmap, bitmap; HDC dcMem; HBRUSH bgBrush = CreateSolidBrush(gc->background); if (twdPtr->type != TWD_BITMAP) { Tcl_Panic("unexpected drawable type in stipple"); } /* * Select stipple pattern into destination dc. */ stipple = CreatePatternBrush(twdPtr->bitmap.handle); SetBrushOrgEx(dc, gc->ts_x_origin, gc->ts_y_origin, NULL); oldBrush = SelectObject(dc, stipple); dcMem = CreateCompatibleDC(dc); /* * For each rectangle, create a drawing surface which is the size of * the rectangle and fill it with the background color. Then merge the * result with the stipple pattern. */ for (i = 0; i < nrectangles; i++) { bitmap = CreateCompatibleBitmap(dc, rectangles[i].width, rectangles[i].height); oldBitmap = SelectObject(dcMem, bitmap); rect.left = 0; rect.top = 0; rect.right = rectangles[i].width; rect.bottom = rectangles[i].height; FillRect(dcMem, &rect, brush); BitBlt(dc, rectangles[i].x, rectangles[i].y, rectangles[i].width, rectangles[i].height, dcMem, 0, 0, COPYFG); if (gc->fill_style == FillOpaqueStippled) { FillRect(dcMem, &rect, bgBrush); BitBlt(dc, rectangles[i].x, rectangles[i].y, rectangles[i].width, rectangles[i].height, dcMem, 0, 0, COPYBG); } SelectObject(dcMem, oldBitmap); DeleteObject(bitmap); } DeleteDC(dcMem); SelectObject(dc, oldBrush); DeleteObject(stipple); DeleteObject(bgBrush); } else { if (gc->function == GXcopy) { for (i = 0; i < nrectangles; i++) { rect.left = rectangles[i].x; rect.right = rect.left + rectangles[i].width; rect.top = rectangles[i].y; rect.bottom = rect.top + rectangles[i].height; FillRect(dc, &rect, brush); } } else { HPEN newPen = CreatePen(PS_NULL, 0, gc->foreground); HPEN oldPen = SelectObject(dc, newPen); oldBrush = SelectObject(dc, brush); for (i = 0; i < nrectangles; i++) { Rectangle(dc, rectangles[i].x, rectangles[i].y, rectangles[i].x + rectangles[i].width + 1, rectangles[i].y + rectangles[i].height + 1); } SelectObject(dc, oldBrush); SelectObject(dc, oldPen); DeleteObject(newPen); } } DeleteObject(brush); TkWinReleaseDrawableDC(d, dc, &state); }
void TkPutImage( unsigned long *colors, /* Array of pixel values used by this image. * May be NULL. */ int ncolors, /* Number of colors used, or 0. */ Display *display, Drawable d, /* Destination drawable. */ GC gc, XImage *image, /* Source image. */ int src_x, int src_y, /* Offset of subimage. */ int dest_x, int dest_y, /* Position of subimage origin in drawable. */ unsigned int width, unsigned int height) /* Dimensions of subimage. */ { HDC dc, dcMem; TkWinDCState state; BITMAPINFO *infoPtr; HBITMAP bitmap; char *data; display->request++; dc = TkWinGetDrawableDC(display, d, &state); SetROP2(dc, tkpWinRopModes[gc->function]); dcMem = CreateCompatibleDC(dc); if (image->bits_per_pixel == 1) { /* * If the image isn't in the right format, we have to copy it into a * new buffer in MSBFirst and word-aligned format. */ if ((image->bitmap_bit_order != MSBFirst) || (image->bitmap_pad != sizeof(WORD))) { data = TkAlignImageData(image, sizeof(WORD), MSBFirst); bitmap = CreateBitmap(image->width, image->height, 1, 1, data); ckfree(data); } else { bitmap = CreateBitmap(image->width, image->height, 1, 1, image->data); } SetTextColor(dc, gc->foreground); SetBkColor(dc, gc->background); } else { int i, usePalette; /* * Do not use a palette for TrueColor images. */ usePalette = (image->bits_per_pixel < 16); if (usePalette) { infoPtr = (BITMAPINFO *) ckalloc(sizeof(BITMAPINFOHEADER) + sizeof(RGBQUAD)*ncolors); } else { infoPtr = (BITMAPINFO *) ckalloc(sizeof(BITMAPINFOHEADER)); } infoPtr->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); infoPtr->bmiHeader.biWidth = image->width; infoPtr->bmiHeader.biHeight = -image->height; /* Top-down order */ infoPtr->bmiHeader.biPlanes = 1; infoPtr->bmiHeader.biBitCount = image->bits_per_pixel; infoPtr->bmiHeader.biCompression = BI_RGB; infoPtr->bmiHeader.biSizeImage = 0; infoPtr->bmiHeader.biXPelsPerMeter = 0; infoPtr->bmiHeader.biYPelsPerMeter = 0; infoPtr->bmiHeader.biClrImportant = 0; if (usePalette) { infoPtr->bmiHeader.biClrUsed = ncolors; for (i = 0; i < ncolors; i++) { infoPtr->bmiColors[i].rgbBlue = GetBValue(colors[i]); infoPtr->bmiColors[i].rgbGreen = GetGValue(colors[i]); infoPtr->bmiColors[i].rgbRed = GetRValue(colors[i]); infoPtr->bmiColors[i].rgbReserved = 0; } } else { infoPtr->bmiHeader.biClrUsed = 0; } bitmap = CreateDIBitmap(dc, &infoPtr->bmiHeader, CBM_INIT, image->data, infoPtr, DIB_RGB_COLORS); ckfree((char *) infoPtr); } if (!bitmap) { Tcl_Panic("Fail to allocate bitmap\n"); DeleteDC(dcMem); TkWinReleaseDrawableDC(d, dc, &state); return; } bitmap = SelectObject(dcMem, bitmap); BitBlt(dc, dest_x, dest_y, (int) width, (int) height, dcMem, src_x, src_y, SRCCOPY); DeleteObject(SelectObject(dcMem, bitmap)); DeleteDC(dcMem); TkWinReleaseDrawableDC(d, dc, &state); }
void XCopyPlane( Display *display, Drawable src, Drawable dest, GC gc, int src_x, int src_y, unsigned int width, unsigned int height, int dest_x, int dest_y, unsigned long plane) { HDC srcDC, destDC; TkWinDCState srcState, destState; HBRUSH bgBrush, fgBrush, oldBrush; TkpClipMask *clipPtr = (TkpClipMask*)gc->clip_mask; display->request++; if (plane != 1) { Tcl_Panic("Unexpected plane specified for XCopyPlane"); } srcDC = TkWinGetDrawableDC(display, src, &srcState); if (src != dest) { destDC = TkWinGetDrawableDC(display, dest, &destState); } else { destDC = srcDC; } if (clipPtr == NULL || clipPtr->type == TKP_CLIP_REGION) { /* * Case 1: opaque bitmaps. Windows handles the conversion from one bit * to multiple bits by setting 0 to the foreground color, and 1 to the * background color (seems backwards, but there you are). */ if (clipPtr && clipPtr->type == TKP_CLIP_REGION) { SelectClipRgn(destDC, (HRGN) clipPtr->value.region); OffsetClipRgn(destDC, gc->clip_x_origin, gc->clip_y_origin); } SetBkMode(destDC, OPAQUE); SetBkColor(destDC, gc->foreground); SetTextColor(destDC, gc->background); BitBlt(destDC, dest_x, dest_y, (int) width, (int) height, srcDC, src_x, src_y, SRCCOPY); SelectClipRgn(destDC, NULL); } else if (clipPtr->type == TKP_CLIP_PIXMAP) { if (clipPtr->value.pixmap == src) { /* * Case 2: transparent bitmaps are handled by setting the * destination to the foreground color whenever the source pixel * is set. */ fgBrush = CreateSolidBrush(gc->foreground); oldBrush = SelectObject(destDC, fgBrush); SetBkColor(destDC, RGB(255,255,255)); SetTextColor(destDC, RGB(0,0,0)); BitBlt(destDC, dest_x, dest_y, (int) width, (int) height, srcDC, src_x, src_y, MASKPAT); SelectObject(destDC, oldBrush); DeleteObject(fgBrush); } else { /* * Case 3: two arbitrary bitmaps. Copy the source rectangle into a * color pixmap. Use the result as a brush when copying the clip * mask into the destination. */ HDC memDC, maskDC; HBITMAP bitmap; TkWinDCState maskState; fgBrush = CreateSolidBrush(gc->foreground); bgBrush = CreateSolidBrush(gc->background); maskDC = TkWinGetDrawableDC(display, clipPtr->value.pixmap, &maskState); memDC = CreateCompatibleDC(destDC); bitmap = CreateBitmap((int) width, (int) height, 1, 1, NULL); SelectObject(memDC, bitmap); /* * Set foreground bits. We create a new bitmap containing (source * AND mask), then use it to set the foreground color into the * destination. */ BitBlt(memDC, 0, 0, (int) width, (int) height, srcDC, src_x, src_y, SRCCOPY); BitBlt(memDC, 0, 0, (int) width, (int) height, maskDC, dest_x - gc->clip_x_origin, dest_y - gc->clip_y_origin, SRCAND); oldBrush = SelectObject(destDC, fgBrush); BitBlt(destDC, dest_x, dest_y, (int) width, (int) height, memDC, 0, 0, MASKPAT); /* * Set background bits. Same as foreground, except we use ((NOT * source) AND mask) and the background brush. */ BitBlt(memDC, 0, 0, (int) width, (int) height, srcDC, src_x, src_y, NOTSRCCOPY); BitBlt(memDC, 0, 0, (int) width, (int) height, maskDC, dest_x - gc->clip_x_origin, dest_y - gc->clip_y_origin, SRCAND); SelectObject(destDC, bgBrush); BitBlt(destDC, dest_x, dest_y, (int) width, (int) height, memDC, 0, 0, MASKPAT); TkWinReleaseDrawableDC(clipPtr->value.pixmap, maskDC, &maskState); SelectObject(destDC, oldBrush); DeleteDC(memDC); DeleteObject(bitmap); DeleteObject(fgBrush); DeleteObject(bgBrush); } } if (src != dest) { TkWinReleaseDrawableDC(dest, destDC, &destState); } TkWinReleaseDrawableDC(src, srcDC, &srcState); }
static void DrawOrFillArc( Display *display, Drawable d, GC gc, int x, int y, /* left top */ unsigned int width, unsigned int height, int start, /* start: three-o'clock (deg*64) */ int extent, /* extent: relative (deg*64) */ int fill) /* ==0 draw, !=0 fill */ { HDC dc; HBRUSH brush, oldBrush; HPEN pen, oldPen; TkWinDCState state; int clockwise = (extent < 0); /* non-zero if clockwise */ int xstart, ystart, xend, yend; double radian_start, radian_end, xr, yr; if (d == None) { return; } dc = TkWinGetDrawableDC(display, d, &state); SetROP2(dc, tkpWinRopModes[gc->function]); /* * Compute the absolute starting and ending angles in normalized radians. * Swap the start and end if drawing clockwise. */ start = start % (64*360); if (start < 0) { start += (64*360); } extent = (start+extent) % (64*360); if (extent < 0) { extent += (64*360); } if (clockwise) { int tmp = start; start = extent; extent = tmp; } radian_start = XAngleToRadians(start); radian_end = XAngleToRadians(extent); /* * Now compute points on the radial lines that define the starting and * ending angles. Be sure to take into account that the y-coordinate * system is inverted. */ xr = x + width / 2.0; yr = y + height / 2.0; xstart = (int)((xr + cos(radian_start)*width/2.0) + 0.5); ystart = (int)((yr + sin(-radian_start)*height/2.0) + 0.5); xend = (int)((xr + cos(radian_end)*width/2.0) + 0.5); yend = (int)((yr + sin(-radian_end)*height/2.0) + 0.5); /* * Now draw a filled or open figure. Note that we have to increase the * size of the bounding box by one to account for the difference in pixel * definitions between X and Windows. */ pen = SetUpGraphicsPort(gc); oldPen = SelectObject(dc, pen); if (!fill) { /* * Note that this call will leave a gap of one pixel at the end of the * arc for thin arcs. We can't use ArcTo because it's only supported * under Windows NT. */ SetBkMode(dc, TRANSPARENT); Arc(dc, x, y, (int) (x+width+1), (int) (y+height+1), xstart, ystart, xend, yend); } else { brush = CreateSolidBrush(gc->foreground); oldBrush = SelectObject(dc, brush); if (gc->arc_mode == ArcChord) { Chord(dc, x, y, (int) (x+width+1), (int) (y+height+1), xstart, ystart, xend, yend); } else if (gc->arc_mode == ArcPieSlice) { Pie(dc, x, y, (int) (x+width+1), (int) (y+height+1), xstart, ystart, xend, yend); } DeleteObject(SelectObject(dc, oldBrush)); } DeleteObject(SelectObject(dc, oldPen)); TkWinReleaseDrawableDC(d, dc, &state); }