1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
|
/*
* tixWinDraw.c --
*
* Implement the Windows specific function calls for drawing.
*
* Copyright (c) 1993-1999 Ioi Kim Lam.
* Copyright (c) 2000 Tix Project Group.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* $Id: tixWinDraw.c,v 1.5 2004/03/28 02:44:57 hobbs Exp $
*/
#include <tkWinInt.h>
#include <tixInt.h>
#include <tixPort.h>
/*----------------------------------------------------------------------
*
* TixpDrawTmpLine --
*
* Draws a "temporarily" line on the desktop window with XOR
* drawing mode. This function is used by the PanedWindow and
* ResizeHandler to draw the rubberband lines. Calling the
* function again with the same parameters cancels the temporary
* lines without affecting what was originally on the screen.
*
* Results:
* None.
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
void
TixpDrawTmpLine(x1, y1, x2, y2, tkwin)
int x1;
int y1;
int x2;
int y2;
Tk_Window tkwin;
{
HWND desktop;
HDC hdc;
HPEN hpen;
HGDIOBJ old;
desktop = GetDesktopWindow();
hdc = GetWindowDC(desktop);
hpen = CreatePen(PS_SOLID, 0, RGB(255,255,255));
old = SelectObject(hdc, hpen);
SetROP2(hdc, R2_XORPEN);
MoveToEx(hdc, x1, y1, NULL);
LineTo(hdc, x2, y2);
SelectObject(hdc, old);
DeleteObject(hpen);
ReleaseDC(desktop, hdc);
}
/*
*----------------------------------------------------------------------
*
* TixpDrawAnchorLines --
*
* See comments near Tix_DrawAnchorLines in tixUtils.c.
*
* Results:
* None.
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
void
TixpDrawAnchorLines(display, drawable, gc, x, y, w, h)
Display *display;
Drawable drawable;
GC gc;
int x;
int y;
int w;
int h;
{
HDC hdc;
TkWinDCState state;
RECT rect;
if (w < 2 || h < 2) {
/*
* Area too small to show effect. Don't bother
*/
return;
}
hdc = TkWinGetDrawableDC(display, drawable, &state);
rect.left = x;
rect.top = y;
rect.right = x+w;
rect.bottom = y+h;
DrawFocusRect(hdc, &rect);
TkWinReleaseDrawableDC(drawable, hdc, &state);
}
/*
*----------------------------------------------------------------------
*
* TixpStartSubRegionDraw --
*
* This function is used by the Tix DItem code to implement
* clipped rendering -- if a DItem is larger than the region
* where the DItem is displayed (with the Tix_DItemDisplay
* function), we clip the DItem so that all the rendering
* happens inside the region.
*
* This Win32 implementation is tricky (which explains why the
* TixpSubRegDrawXXX API looks so arcane.) Tk does not support
* a portable API for setting the clip region of a GC. We could
* hack into Tk's Win32 implementation of GC to get the clipping
* to work, but that may run into future incompatibilities.
*
* For a clean and (almost) portable, albeit a bit slow,
* implemetation of clipping, we allocate a pixmap when clipping
* is required. All subsequent drawing goes into this
* pixmap. When TixpEndSubRegionDraw is called we then copy from
* the pixmap back to the destination drawable.
*
* Results:
* None.
*
* Side effects:
* A Tk pixmap may be created and saved into subRegPtr->pixmap in
* for the clipped drawing operations.
*
*----------------------------------------------------------------------
*/
void
TixpStartSubRegionDraw(display, drawable, gc, subRegPtr, origX, origY,
x, y, width, height, needWidth, needHeight)
Display *display;
Drawable drawable;
GC gc;
TixpSubRegion * subRegPtr;
int origX;
int origY;
int x;
int y;
int width;
int height;
int needWidth;
int needHeight;
{
TkWinDrawable * wdrPtr;
int depth;
if ((width < needWidth) || (height < needHeight)) {
subRegPtr->origX = origX;
subRegPtr->origY = origY;
subRegPtr->x = x;
subRegPtr->y = y;
subRegPtr->width = width;
subRegPtr->height = height;
/*
* Find out the depth of the drawable and create a pixmap of
* the same depth.
*/
wdrPtr = (TkWinDrawable *)drawable;
if (wdrPtr->type == TWD_BITMAP) {
depth = wdrPtr->bitmap.depth;
} else {
depth = wdrPtr->window.winPtr->depth;
}
subRegPtr->pixmap = Tk_GetPixmap(display, drawable, width, height,
depth);
if (subRegPtr->pixmap != None) {
/*
* It could be None if we have somehow exhausted the Windows
* GDI resources.
*/
XCopyArea(display, drawable, subRegPtr->pixmap, gc, x, y,
(unsigned) width, (unsigned) height, 0, 0);
}
} else {
subRegPtr->pixmap = None;
}
}
/*----------------------------------------------------------------------
* TixpEndSubRegionDraw --
*
*
*----------------------------------------------------------------------
*/
void
TixpEndSubRegionDraw(display, drawable, gc, subRegPtr)
Display *display;
Drawable drawable;
GC gc;
TixpSubRegion * subRegPtr;
{
if (subRegPtr->pixmap != None) {
XCopyArea(display, subRegPtr->pixmap, drawable, gc, 0, 0,
(unsigned) subRegPtr->width, (unsigned) subRegPtr->height,
subRegPtr->x, subRegPtr->y);
Tk_FreePixmap(display, subRegPtr->pixmap);
subRegPtr->pixmap = None;
}
}
void
TixpSubRegSetClip(display, subRegPtr, gc)
Display *display;
TixpSubRegion * subRegPtr;
GC gc;
{
/* Do nothing */
}
void
TixpSubRegUnsetClip(display, subRegPtr, gc)
Display *display;
TixpSubRegion * subRegPtr;
GC gc;
{
/* Do nothing */
}
/*
*----------------------------------------------------------------------
*
* TixpSubRegDisplayText --
*
* Display a text string on one or more lines in a sub region.
*
* Results:
* See TkDisplayText
*
* Side effects:
* See TkDisplayText
*
*----------------------------------------------------------------------
*/
void
TixpSubRegDisplayText(display, drawable, gc, subRegPtr, font, string,
numChars, x, y, length, justify, underline)
Display *display; /* X display to use for drawing text. */
Drawable drawable; /* Window or pixmap in which to draw the
* text. */
GC gc; /* Graphics context to use for drawing text. */
TixpSubRegion * subRegPtr; /* Information about the subregion */
TixFont font; /* Font that determines geometry of text
* (should be same as font in gc). */
CONST84 char *string; /* String to display; may contain embedded
* newlines. */
int numChars; /* Number of characters to use from string. */
int x, y; /* Pixel coordinates within drawable of
* upper left corner of display area. */
int length; /* Line length in pixels; used to compute
* word wrap points and also for
* justification. Must be > 0. */
Tk_Justify justify; /* How to justify lines. */
int underline; /* Index of character to underline, or < 0
* for no underlining. */
{
if (subRegPtr->pixmap != None) {
TixDisplayText(display, subRegPtr->pixmap, font, string,
numChars, x - subRegPtr->x, y - subRegPtr->y,
length, justify, underline, gc);
} else {
TixDisplayText(display, drawable, font, string,
numChars, x, y, length, justify, underline, gc);
}
}
/*----------------------------------------------------------------------
* TixpSubRegFillRectangle --
*
*
*----------------------------------------------------------------------
*/
void
TixpSubRegFillRectangle(display, drawable, gc, subRegPtr, x, y, width, height)
Display *display; /* X display to use for drawing rectangle. */
Drawable drawable; /* Window or pixmap in which to draw the
* rectangle. */
GC gc; /* Graphics context to use for drawing. */
TixpSubRegion * subRegPtr; /* Information about the subregion */
int x, y; /* Pixel coordinates within drawable of
* upper left corner of display area. */
int width, height; /* Size of the rectangle. */
{
if (subRegPtr->pixmap != None) {
XFillRectangle(display, subRegPtr->pixmap, gc,
x - subRegPtr->x, y - subRegPtr->y, width, height);
} else {
XFillRectangle(display, drawable, gc, x, y, width, height);
}
}
/*----------------------------------------------------------------------
* TixpSubRegDrawImage --
*
* Draws a Tk image in a subregion.
*----------------------------------------------------------------------
*/
void
TixpSubRegDrawImage(subRegPtr, image, imageX, imageY, width, height,
drawable, drawableX, drawableY)
TixpSubRegion * subRegPtr;
Tk_Image image;
int imageX;
int imageY;
int width;
int height;
Drawable drawable;
int drawableX;
int drawableY;
{
Drawable dest;
if (subRegPtr->pixmap != None) {
dest = subRegPtr->pixmap;
drawableX -= subRegPtr->x;
drawableY -= subRegPtr->y;
} else {
dest = drawable;
}
Tk_RedrawImage(image, imageX, imageY, width, height, dest,
drawableX, drawableY);
}
void
TixpSubRegDrawBitmap(display, drawable, gc, subRegPtr, bitmap, src_x, src_y,
width, height, dest_x, dest_y, plane)
Display *display;
Drawable drawable;
GC gc;
TixpSubRegion * subRegPtr;
Pixmap bitmap;
int src_x, src_y;
int width, height;
int dest_x, dest_y;
unsigned long plane;
{
XSetClipOrigin(display, gc, dest_x, dest_y);
if (subRegPtr->pixmap != None) {
XCopyPlane(display, bitmap, subRegPtr->pixmap, gc, src_x, src_y,
width, height, dest_x - subRegPtr->x, dest_y - subRegPtr->y,
plane);
} else {
XCopyPlane(display, bitmap, drawable, gc, src_x, src_y, width, height,
dest_x, dest_y, plane);
}
XSetClipOrigin(display, gc, 0, 0);
}
/*
*----------------------------------------------------------------------
*
* TixpSubRegDrawAnchorLines --
*
* Draw anchor lines inside the given sub region.
*
* Results:
* None.
*
* Side effects:
* None
*
*----------------------------------------------------------------------
*/
void
TixpSubRegDrawAnchorLines(display, drawable, gc, subRegPtr, x, y, w, h)
Display *display; /* Display to draw on. */
Drawable drawable; /* Drawable to draw on. */
GC gc; /* Use the foreground color of this GC. */
TixpSubRegion * subRegPtr; /* Describes the subregion. */
int x; /* x pos of top-left corner of anchor rect */
int y; /* y pos of top-left corner of anchor rect */
int w; /* width of anchor rect */
int h; /* height of anchor rect */
{
Drawable dest;
if (subRegPtr->pixmap != None) {
dest = subRegPtr->pixmap;
x -= subRegPtr->x;
y -= subRegPtr->y;
} else {
dest = drawable;
}
TixpDrawAnchorLines(display, dest, gc, x, y, w, h);
}
|