Exemplo n.º 1
0
static void paintTabView(TabView * tPtr)
{
	Pixmap buffer;
	WMScreen *scr = W_VIEW(tPtr)->screen;
	Display *dpy = scr->display;
	GC white = WMColorGC(scr->white);
	int i;

	if (tPtr->flags.type == WTTopTabsBevelBorder) {
		int count = tPtr->visibleTabs;
		int first = tPtr->firstVisible;
		int moreAtLeft;
		int moreAtRight;
		int selectedIsVisible;
		int ty;
		int twidth, theight;

		ty = 2;
		theight = tPtr->tabHeight;

		buffer = XCreatePixmap(dpy, W_VIEW(tPtr)->window,
				       W_VIEW(tPtr)->size.width, theight, W_VIEW(tPtr)->screen->depth);

		XFillRectangle(dpy, buffer, WMColorGC(W_VIEW(tPtr)->backColor),
			       0, 0, W_VIEW(tPtr)->size.width, tPtr->tabHeight);

		if (tPtr->flags.dontFitAll) {
			moreAtLeft = first > 0;
			moreAtRight = (first + count) < tPtr->itemCount;
			if (tPtr->selectedItem >= first && tPtr->selectedItem < first + count)
				selectedIsVisible = 1;
			else
				selectedIsVisible = 0;
		} else {
			moreAtLeft = 0;
			moreAtRight = 0;
			selectedIsVisible = 1;
		}

		if (moreAtRight) {
			drawTab(tPtr, buffer, positionOfTab(tPtr, first + count), 0,
				W_VIEW_WIDTH(tPtr->view), theight, False);
		}
		for (i = first + count - 1; i >= first; i--) {
			if (!selectedIsVisible || i != tPtr->selectedItem) {
				twidth = W_TabViewItemTabWidth(tPtr->items[i]);

				drawTab(tPtr, buffer, positionOfTab(tPtr, i), 0, twidth, theight, False);
			}
		}
		if (moreAtLeft) {
			drawTab(tPtr, buffer, positionOfTab(tPtr, 0) - 2 * BUTTONED_SIDE_OFFSET,
				0, BUTTONED_SIDE_OFFSET * 4, theight, False);
		}

		if (selectedIsVisible) {
			int idx = tPtr->selectedItem;

			drawTab(tPtr, buffer, positionOfTab(tPtr, idx),
				0, W_TabViewItemTabWidth(tPtr->items[idx]), theight, True);

			XDrawLine(dpy, buffer, white, 0, theight - 1, positionOfTab(tPtr, idx), theight - 1);

			XDrawLine(dpy, buffer, white,
				  positionOfTab(tPtr, idx) + W_TabViewItemTabWidth(tPtr->items[idx]),
				  tPtr->tabHeight - 1, W_VIEW_WIDTH(tPtr->view) - 1, tPtr->tabHeight - 1);
		} else {
			XDrawLine(dpy, buffer, white, 0, theight - 1, W_VIEW_WIDTH(tPtr->view), theight - 1);
		}

		for (i = 0; i < count; i++) {
			WMRect rect;

			rect.pos.x = 15 + positionOfTab(tPtr, first + i);
			rect.pos.y = ty;
			rect.size.width = W_TabViewItemTabWidth(tPtr->items[first + i]);
			rect.size.height = theight;
			W_DrawLabel(tPtr->items[first + i], buffer, rect,
				    tPtr->flags.enabled && tPtr->items[first + i]->flags.enabled);
		}

		if (moreAtLeft) {
			paintDot(tPtr, buffer, 4, 10);
			paintDot(tPtr, buffer, 7, 10);
			paintDot(tPtr, buffer, 10, 10);
		}
		if (moreAtRight) {
			int x;

			x = positionOfTab(tPtr, tPtr->firstVisible + tPtr->visibleTabs);

			x = x + (W_VIEW_WIDTH(tPtr->view) - x) / 2;
			paintDot(tPtr, buffer, x + 5, 10);
			paintDot(tPtr, buffer, x + 8, 10);
			paintDot(tPtr, buffer, x + 11, 10);
		}

		XCopyArea(dpy, buffer, W_VIEW(tPtr)->window, scr->copyGC, 0, 0,
			  W_VIEW_WIDTH(tPtr->view), theight, 0, 0);

		XFreePixmap(dpy, buffer);
	}
	switch (tPtr->flags.type) {
	case WTTopTabsBevelBorder:
		drawRelief(scr, W_VIEW(tPtr)->window, 0, tPtr->tabHeight - 1,
			   W_VIEW(tPtr)->size.width, W_VIEW(tPtr)->size.height - tPtr->tabHeight + 1);
		break;

	case WTNoTabsBevelBorder:
		W_DrawRelief(scr, W_VIEW(tPtr)->window, 0, 0, W_VIEW(tPtr)->size.width,
			     W_VIEW(tPtr)->size.height, WRRaised);
		break;

	case WTNoTabsLineBorder:
		W_DrawRelief(scr, W_VIEW(tPtr)->window, 0, 0, W_VIEW(tPtr)->size.width,
			     W_VIEW(tPtr)->size.height, WRSimple);
		break;

	case WTNoTabsNoBorder:
		break;
	}
}
Exemplo n.º 2
0
int
main(int argc, char **argv)
{
	unsigned int x = 1, y = 1;
	Pixmap back;
	DACallbacks eventCallbacks = {
		destroy, /* destroy */
		NULL, /* buttonPress */
		NULL, /* buttonRelease */
		NULL, /* motion (mouse) */
		NULL, /* mouse enters window */
		NULL, /* mouse leaves window */
		moveBall /* timeout */
	};

	/* provide standard command-line options */
	DAParseArguments(
		argc, argv, /* Where the options come from */
		NULL, 0, /* Our list with options - none as you can see */
		"This is the help text for the basic example of how to "
		"use libDockapp.\n",
		"Basic example version 1.1");

	/* Tell libdockapp what version we expect it to be (a date from
	 * NEWS should do).
	 */
	DASetExpectedVersion(20020126);

	DAOpenDisplay(
		NULL /* default display */,
		argc, argv /* needed by libdockapp */
		);
	DACreateIcon(
		"daBasicExample" /* WM_CLASS hint; don't use chars in [.?*: ] */,
		48, 48 /* geometry of dockapp internals */,
		argc, argv      /* needed by libdockapp */
		);

	/* The pixmap that makes up the background of the dockapp */
	back = DAMakePixmap();
	drawRelief(back);
	DASetPixmap(back);
	XFreePixmap(DADisplay, back);

	/* A window(!) for the ball pixmap.
	 * Moving a window is a lot easier then erasing/copying the pixmap all
	 * the time.
	 *
	 * I use a DAShapedPixmap here, which contains all the information
	 * related to the pixmap: pixmap, mask and geometry.
	 */
	ballPix = DAMakeShapedPixmapFromData(ball_red_xpm);
	ballWin = XCreateSimpleWindow(DADisplay, DAWindow,
				      x, y,
				      /* Use the geometry of the shaped pixmap */
				      ballPix->geometry.width, ballPix->geometry.height,
				      0, 0, 0);
	DASPSetPixmapForWindow(ballWin, ballPix);

	/* Respond to destroy and timeout events (the ones not NULL in the
	 * eventCallbacks variable.
	 */
	DASetCallbacks(&eventCallbacks);

	/* Set the time for timeout events (in msec) */
	DASetTimeout(SPEED);

	/* Randomize movement variation.
	 * Run multiple versions of the dockapp simultaneously to see the effect
	 * best.
	 * (which function to use is set from the Imakefile)
	 */
#ifdef HAS_RANDOMDEV
	srandomdev();
#else
	srandom(time(NULL));
#endif

	DAShow(); /* Show the dockapp window. */

	/* Process events and keep the dockapp running */
	DAEventLoop();

	/* not reached */
	exit(EXIT_SUCCESS);
}
Exemplo n.º 3
0
static void paintTextField(TextField * tPtr)
{
	W_Screen *screen = tPtr->view->screen;
	W_View *view = tPtr->view;
	W_View viewbuffer;
	int tx, ty, tw;
	int rx;
	int bd;
	int totalWidth;
	char *text;
	Pixmap drawbuffer;
	WMColor *color;

	if (!view->flags.realized || !view->flags.mapped)
		return;

	if (!tPtr->flags.bordered) {
		bd = 0;
	} else {
		bd = 2;
	}

	if (tPtr->flags.secure) {
		text = makeHiddenString(strlen(tPtr->text));
	} else {
		text = tPtr->text;
	}

	totalWidth = tPtr->view->size.width - 2 * bd;

	drawbuffer = XCreatePixmap(screen->display, view->window,
				   view->size.width, view->size.height, screen->depth);
	XFillRectangle(screen->display, drawbuffer, WMColorGC(screen->white),
		       0, 0, view->size.width, view->size.height);
	/* this is quite dirty */
	viewbuffer.screen = view->screen;
	viewbuffer.size = view->size;
	viewbuffer.window = drawbuffer;

	if (tPtr->textLen > 0) {
		tw = WMWidthOfString(tPtr->font, &(text[tPtr->viewPosition]), tPtr->textLen - tPtr->viewPosition);

		ty = tPtr->offsetWidth;
		switch (tPtr->flags.alignment) {
		case WALeft:
			tx = tPtr->offsetWidth + 1;
			if (tw < tPtr->usableWidth)
				XFillRectangle(screen->display, drawbuffer,
					       WMColorGC(screen->white),
					       bd + tw, bd, totalWidth - tw, view->size.height - 2 * bd);
			break;

		case WACenter:
			tx = tPtr->offsetWidth + (tPtr->usableWidth - tw) / 2;
			if (tw < tPtr->usableWidth)
				XClearArea(screen->display, view->window, bd, bd,
					   totalWidth, view->size.height - 2 * bd, False);
			break;

		default:
		case WARight:
			tx = tPtr->offsetWidth + tPtr->usableWidth - tw - 1;
			if (tw < tPtr->usableWidth)
				XClearArea(screen->display, view->window, bd, bd,
					   totalWidth - tw, view->size.height - 2 * bd, False);
			break;
		}

		color = tPtr->flags.enabled ? screen->black : screen->darkGray;

		WMDrawImageString(screen, drawbuffer, color, screen->white,
				  tPtr->font, tx, ty, &(text[tPtr->viewPosition]),
				  tPtr->textLen - tPtr->viewPosition);

		if (tPtr->selection.count) {
			int count, count2;

			count = tPtr->selection.count < 0
			    ? tPtr->selection.position + tPtr->selection.count : tPtr->selection.position;
			count2 = abs(tPtr->selection.count);
			if (count < tPtr->viewPosition) {
				count2 = abs(count2 - abs(tPtr->viewPosition - count));
				count = tPtr->viewPosition;
			}

			rx = tPtr->offsetWidth + 1 + WMWidthOfString(tPtr->font, text, count)
			    - WMWidthOfString(tPtr->font, text, tPtr->viewPosition);

			WMDrawImageString(screen, drawbuffer, color, screen->gray,
					  tPtr->font, rx, ty, &(text[count]), count2);
		}
	} else {
		XFillRectangle(screen->display, drawbuffer, WMColorGC(screen->white),
			       bd, bd, totalWidth, view->size.height - 2 * bd);
	}

	/* draw relief */
	if (tPtr->flags.bordered) {
		drawRelief(&viewbuffer, tPtr->flags.beveled);
	}

	if (tPtr->flags.secure)
		wfree(text);
	XCopyArea(screen->display, drawbuffer, view->window,
		  screen->copyGC, 0, 0, view->size.width, view->size.height, 0, 0);
	XFreePixmap(screen->display, drawbuffer);

	/* draw cursor */
	if (tPtr->flags.focused && tPtr->flags.enabled && tPtr->flags.cursorOn) {
		paintCursor(tPtr);
	}
}