Ejemplo n.º 1
0
/*
 * Fonction pour HDipstick
 * Création d'une jauge horizontale
 * plusieurs options
 */
void InitHDipstick(struct XObj *xobj)
{
 unsigned long mask;
 XSetWindowAttributes Attr;

 /* Enregistrement des couleurs et de la police */
 if (xobj->colorset >= 0) {
  xobj->TabColor[fore] = Colorset[xobj->colorset].fg;
  xobj->TabColor[back] = Colorset[xobj->colorset].bg;
  xobj->TabColor[hili] = Colorset[xobj->colorset].hilite;
  xobj->TabColor[shad] = Colorset[xobj->colorset].shadow;
 } else {
  xobj->TabColor[fore] = GetColor(xobj->forecolor);
  xobj->TabColor[back] = GetColor(xobj->backcolor);
  xobj->TabColor[hili] = GetColor(xobj->hilicolor);
  xobj->TabColor[shad] = GetColor(xobj->shadcolor);
 }

 /* Minimum size */
 if (xobj->width<30)
  xobj->width=30;
 if (xobj->height<11)
  xobj->height=11;

 mask=0;
 Attr.background_pixel=xobj->TabColor[back];
 mask|=CWBackPixel;
 xobj->win=XCreateWindow(dpy,*xobj->ParentWin,
		xobj->x,xobj->y,xobj->width,xobj->height,0,
		CopyFromParent,InputOutput,CopyFromParent,
		mask,&Attr);
 xobj->gc=fvwmlib_XCreateGC(dpy,xobj->win,0,NULL);
 if (xobj->colorset >= 0)
   SetWindowBackground(dpy, xobj->win, xobj->width, xobj->height,
		       &Colorset[xobj->colorset], Pdepth,
		       xobj->gc, True);

 XSetForeground(dpy,xobj->gc,xobj->TabColor[fore]);
 XSetLineAttributes(dpy,xobj->gc,1,LineSolid,CapRound,JoinMiter);

 if (xobj->value2>xobj->value3)
  xobj->value3=xobj->value2+50;
 if (xobj->value<xobj->value2)
  xobj->value=xobj->value2;
 if (xobj->value>xobj->value3)
  xobj->value=xobj->value3;

 XSelectInput(dpy, xobj->win, ExposureMask);
}
Ejemplo n.º 2
0
void SetDeskPageBackground(const Command *c)
{
	Display *dpy2 = NULL;
	Window root2 = None;
	int screen2;
	Pixmap pix = None;

	current_colorset = -1;

	/* FvwmBacker bg preperation */
	switch (c->type)
	{
	case 1: /* solid colors */
	case 2: /* colorset */
		dpy2 =  XOpenDisplay(displayName);
		if (!dpy2)
		{
			fvwm_msg(ERR, "FvwmBacker",
				 "Fail to create a forking dpy, Exit!");
			exit(2);
		}
		screen2 = DefaultScreen(dpy2);
		root2 = RootWindow(dpy2, screen2);
		if (RetainPixmap)
		{
			XSetCloseDownMode(dpy2, RetainPermanent);
		}
		XGrabServer(dpy2);
		DeleteRootAtoms(dpy2, root2);
		switch (c->type)
		{
		case 2:
			current_colorset = c->colorset;
			/* Process a colorset */
			if (CSET_IS_TRANSPARENT(c->colorset))
			{
				fvwm_msg(ERR,"FvwmBacker", "You cannot "
					 "use a transparent colorset as "
					 "background!");
				XUngrabServer(dpy2);
				XCloseDisplay(dpy2);
				return;
			}
			else if (Pdepth != DefaultDepth(dpy2, screen2))
			{
				fvwm_msg(ERR,"FvwmBacker", "You cannot "
					 "use a colorset background if\n"
					 "the fvwm depth is not equal "
					 "to the root depth!");
				XUngrabServer(dpy2);
				XCloseDisplay(dpy2);
				return;
			}
			else if (RetainPixmap)
			{
				pix = CreateBackgroundPixmap(
					dpy2, root2, MyDisplayWidth,
					MyDisplayHeight,
					&Colorset[c->colorset],
					DefaultDepth(dpy2, screen2),
					DefaultGC(dpy2, screen2), False);
				if (pix != None)
				{
					XSetWindowBackgroundPixmap(
						dpy2, root2, pix);
					XClearWindow(dpy2, root2);
				}
			}
			else
			{
				SetWindowBackground(
					dpy2, root2, MyDisplayWidth,
					MyDisplayHeight,
					&Colorset[c->colorset],
					DefaultDepth(dpy2, screen2),
					DefaultGC(dpy2, screen2), True);
			}
			break;
		case 1: /* Process a solid color request */
			if (RetainPixmap)
			{
				GC gc;
				XGCValues xgcv;

				xgcv.foreground = c->solidColor;
				gc = fvwmlib_XCreateGC(
					dpy2, root2, GCForeground,
					&xgcv);
				pix = XCreatePixmap(
					dpy2, root2, 1, 1,
					DefaultDepth(dpy2, screen2));
				XFillRectangle(
					dpy2, pix, gc, 0, 0, 1, 1);
				XFreeGC(dpy2, gc);
			}
			XSetWindowBackground(dpy2, root2, c->solidColor);
			XClearWindow(dpy2, root2);
			break;
		}
		SetRootAtoms(dpy2, root2, pix);
		XUngrabServer(dpy2);
		XCloseDisplay(dpy2); /* this XSync, Ungrab, ...etc */
		break;
	case -1:
	case 0:
	default:
		if(c->cmdStr != NULL)
		{
			SendFvwmPipe(fvwm_fd, c->cmdStr, (unsigned long)0);
		}
		break;
	}
}
Ejemplo n.º 3
0
Archivo: ItemDraw.c Proyecto: att/uwin
void InitItemDraw(struct XObj *xobj)
{
  unsigned long mask;
  XSetWindowAttributes Attr;
  int minHeight,minWidth;
  int asc,desc,dir;
  XCharStruct struc;
#ifdef I18N_MB
  char **ml;
  XFontStruct **fs_list;
#endif

  /* Enregistrement des couleurs et de la police */
  if (xobj->colorset >= 0) {
    xobj->TabColor[fore] = Colorset[xobj->colorset].fg;
    xobj->TabColor[back] = Colorset[xobj->colorset].bg;
    xobj->TabColor[hili] = Colorset[xobj->colorset].hilite;
    xobj->TabColor[shad] = Colorset[xobj->colorset].shadow;
  } else {
    xobj->TabColor[fore] = GetColor(xobj->forecolor);
    xobj->TabColor[back] = GetColor(xobj->backcolor);
    xobj->TabColor[hili] = GetColor(xobj->hilicolor);
    xobj->TabColor[shad] = GetColor(xobj->shadcolor);
  }

  Attr.background_pixel = xobj->TabColor[back];
  mask = CWBackPixel;

  xobj->win = XCreateWindow(dpy, *xobj->ParentWin,
		xobj->x, xobj->y, xobj->width, xobj->height, 0,
		CopyFromParent, InputOutput, CopyFromParent,
		mask, &Attr);
  xobj->gc = fvwmlib_XCreateGC(dpy, xobj->win, 0, NULL);
  XSetForeground(dpy, xobj->gc, xobj->TabColor[fore]);

#ifdef I18N_MB
  if ((xobj->xfontset = GetFontSetOrFixed(dpy,xobj->font)) == NULL) {
    fprintf(stderr, "FvwmScript: Couldn't load font. Exiting!\n");
    exit(1);
  }
  XFontsOfFontSet(xobj->xfontset, &fs_list, &ml);
  xobj->xfont = fs_list[0];
#else
  if ((xobj->xfont = GetFontOrFixed(dpy, xobj->font)) == NULL) {
    fprintf(stderr, "FvwmScript: Couldn't load font. Exiting!\n");
    exit(1);
  }
#endif
  XSetFont(dpy, xobj->gc, xobj->xfont->fid);

  XSetLineAttributes(dpy, xobj->gc, 1, LineSolid, CapRound, JoinMiter);

  /* Redimensionnement du widget */
  if (strlen(xobj->title) != 0)
    XTextExtents(xobj->xfont, "lp", strlen("lp"), &dir, &asc, &desc, &struc);
  else {
    asc = 0;
    desc = 0;
  }

  if (xobj->icon == NULL)
  {
    if (strlen(xobj->title) != 0)
    {
      /* title but no icon */
      minHeight = asc+desc+2;
      minWidth = XTextWidth(xobj->xfont, xobj->title, strlen(xobj->title))+2;
      if (xobj->height < minHeight)
	xobj->height = minHeight;
      if (xobj->width < minWidth)
	xobj->width = minWidth;
    }
  }
  else if (strlen(xobj->title)==0)
  {
    /* icon but no title */
    if (xobj->height<xobj->icon_h)
      xobj->height = xobj->icon_h;
    if (xobj->width<xobj->icon_w)
      xobj->width = xobj->icon_w;
  }
  else
  {
    /* title and icon */
    if (xobj->icon_w>XTextWidth(xobj->xfont, xobj->title, strlen(xobj->title))+2)
    {
      /* icon is wider than the title */
      if (xobj->width<xobj->icon_w)
	xobj->width = xobj->icon_w;
    }
    else
    {
      /* title is wider than icon */
      if (xobj->width < 
	  XTextWidth(xobj->xfont, xobj->title, strlen(xobj->title)) + 2)
	xobj->width =
	  XTextWidth(xobj->xfont, xobj->title, strlen(xobj->title))+2;
    }
    xobj->height = xobj->icon_h+asc+desc+2;
  }
  XResizeWindow(dpy, xobj->win, xobj->width, xobj->height);
  if (xobj->colorset >= 0)
    SetWindowBackground(dpy, xobj->win, xobj->width, xobj->height,
			&Colorset[xobj->colorset], Pdepth,
			xobj->gc, True);
  XSelectInput(dpy, xobj->win, ExposureMask);
  /* x and y value of a clic */
  xobj->value2 = -1;
  xobj->value3 = -1;
}
Ejemplo n.º 4
0
void InitPopupMenu(struct XObj *xobj)
{
  unsigned long mask;
  XSetWindowAttributes Attr;
  int i;
  char *str;

  /* Enregistrement des couleurs et de la police / set the colors and the font
   */
  if (xobj->colorset >= 0) {
    xobj->TabColor[fore] = Colorset[xobj->colorset].fg;
    xobj->TabColor[back] = Colorset[xobj->colorset].bg;
    xobj->TabColor[hili] = Colorset[xobj->colorset].hilite;
    xobj->TabColor[shad] = Colorset[xobj->colorset].shadow;
  } else {
    xobj->TabColor[fore] = GetColor(xobj->forecolor);
    xobj->TabColor[back] = GetColor(xobj->backcolor);
    xobj->TabColor[hili] = GetColor(xobj->hilicolor);
    xobj->TabColor[shad] = GetColor(xobj->shadcolor);
  }

  mask = 0;
  Attr.background_pixel = xobj->TabColor[back];
  mask |= CWBackPixel;
  Attr.cursor = XCreateFontCursor(dpy, XC_hand2);
  mask |= CWCursor;             /* Curseur pour la fenetre / window cursor */

  xobj->win = XCreateWindow(dpy, *xobj->ParentWin,
		xobj->x, xobj->y, xobj->width, xobj->height, 0,
		CopyFromParent, InputOutput, CopyFromParent,
		mask, &Attr);
  xobj->gc = fvwmlib_XCreateGC(dpy, xobj->win, 0, NULL);
  XSetForeground(dpy, xobj->gc, xobj->TabColor[fore]);

  if ((xobj->Ffont = FlocaleLoadFont(dpy, xobj->font, ScriptName)) == NULL)
  {
    fprintf(stderr, "%s: Couldn't load font. Exiting!\n", ScriptName);
    exit(1);
  }
  if (xobj->Ffont->font != NULL)
    XSetFont(dpy, xobj->gc, xobj->Ffont->font->fid);

  XSetLineAttributes(dpy, xobj->gc, 1, LineSolid, CapRound, JoinMiter);
  xobj->value3 = CountOption(xobj->title);
  if (xobj->value > xobj->value3)
    xobj->value = xobj->value3;
  if (xobj->value < 1)
    xobj->value = 1;

  /* Redimensionnement du widget / Widget resizing */
  xobj->height = xobj->Ffont->height  +12;
  xobj->width = 30;
  for (i = 1; i <= xobj->value3; i++)
  {
    str = (char*)GetMenuTitle(xobj->title, i);
    if (xobj->width < FlocaleTextWidth(xobj->Ffont, str, strlen(str))+34)
      xobj->width = FlocaleTextWidth(xobj->Ffont, str, strlen(str))+34;
    free(str);
  }
  XResizeWindow(dpy, xobj->win, xobj->width, xobj->height);
  if (xobj->colorset >= 0)
    SetWindowBackground(dpy, xobj->win, xobj->width, xobj->height,
			&Colorset[xobj->colorset], Pdepth,
			xobj->gc, True);
  XSelectInput(dpy, xobj->win, ExposureMask);
}
Ejemplo n.º 5
0
void EvtMousePopupMenu(struct XObj *xobj, XButtonEvent *EvtButton)
{
  static XEvent event;
  int x,y,hOpt,yMenu,hMenu;
  int x1,y1,x2,y2,oldy;
  int oldvalue = 0;
  int newvalue = 0;
  Window Win1,Win2,WinPop;
  unsigned int modif;
  unsigned long mask;
  unsigned long while_mask;
  XSetWindowAttributes Attr;
  Time start_time = 0;
  KeySym ks;
  unsigned char buf[10];
  Bool End = 1;
  int asc = xobj->Ffont->ascent;

  hOpt = xobj->Ffont->height + 10;
  xobj->value3 = CountOption(xobj->title);
  yMenu = xobj->y - ((xobj->value-1) * hOpt);
  hMenu = xobj->value3 * hOpt;

  /* Creation de la fenetre menu */
  XTranslateCoordinates(dpy, *xobj->ParentWin, Root,
			xobj->x, yMenu, &x, &y, &Win1);
  if (x < 0) x = 0;
  if (y < 0) y = 0;
  if (x+xobj->width > XDisplayWidth(dpy, screen))
    x = XDisplayWidth(dpy, screen) - xobj->width;
  if (y+hMenu > XDisplayHeight(dpy, screen))
    y = XDisplayHeight(dpy, screen) - hMenu;
  mask = 0;
  Attr.background_pixel = xobj->TabColor[back];
  mask |= CWBackPixel;
  Attr.border_pixel = 0;
  mask |= CWBorderPixel;
  Attr.colormap = Pcmap;
  mask |= CWColormap;
  Attr.cursor = XCreateFontCursor(dpy, XC_hand2);
  mask |= CWCursor;             /* Curseur pour la fenetre / Window cursor */
  Attr.override_redirect = True;
  mask |= CWOverrideRedirect;
  WinPop = XCreateWindow(dpy, Root, x, y, xobj->width, hMenu, 0,
			 Pdepth, InputOutput, Pvisual, mask, &Attr);
  if (xobj->colorset >= 0)
    SetWindowBackground(dpy, WinPop, xobj->width, hMenu,
			&Colorset[xobj->colorset], Pdepth,
			xobj->gc, True);
  XMapRaised(dpy, WinPop);

  /* Dessin du menu / Drawing the menu */
  DrawPMenu(xobj, WinPop, hOpt, 0);
  XGrabPointer(dpy, WinPop, True, GRAB_EVMASK, GrabModeAsync, GrabModeAsync,
	       None, None, CurrentTime);
  if (EvtButton == NULL) {
    while_mask = ButtonPress;
  }
  else {
    start_time = EvtButton->time;
    while_mask = ButtonRelease;
  }

  while (End)
  {
    FQueryPointer(dpy, Root, &Win1, &Win2, &x1, &y1, &x2, &y2, &modif);
    /* Determiner l'option courante / Current option */
    y2 = y2 - y;
    x2 = x2 - x;
    oldy = y2;
    /* calcule de xobj->value / compute xobj->value */
    if ((x2 > 0) && (x2 < xobj->width) && (y2 > 0) && (y2 < hMenu))
      newvalue = y2 / hOpt+1;
    else
      newvalue = 0;
    if (newvalue != oldvalue)
    {
      UnselectMenu(xobj, WinPop, hOpt, oldvalue, xobj->width, asc, 0);
      SelectMenu(xobj, WinPop, hOpt, newvalue);
      oldvalue = newvalue;
    }

    FNextEvent(dpy, &event);
    switch (event.type)
    {
    case KeyPress:
      XLookupString(&event.xkey, (char *)buf, sizeof(buf), &ks, NULL);
      if (ks == XK_Escape) {
	newvalue = 0;
	End = 0;
      }
      else if (ks == XK_Return) {
	End = 0;
      }
      else if (ks == XK_Up && y2 >= hOpt) {
	FWarpPointer(dpy, None, None, 0, 0, 0, 0, 0, -hOpt);
      }
      else if (ks == XK_Down && y2 + hOpt <= hMenu) {
	FWarpPointer(dpy, None, None, 0, 0, 0, 0, 0, hOpt);
      }
      break;
    case ButtonPress:
      if (while_mask == ButtonPress)
	End = 0;
      break;
    case ButtonRelease:
      if (start_time != 0 && event.xbutton.time - start_time < MENU_DRAG_TIME) {
	while_mask = ButtonPress;
	start_time = 0;
      }
      if (while_mask == ButtonRelease)
	End = 0;
      break;
    }
  }
#if 0
  do
  {
    FQueryPointer(dpy, Root, &Win1, &Win2, &x1, &y1, &x2, &y2, &modif);
    /* Determiner l'option courante / Current option */
    y2 = y2 - y;
    x2 = x2 - x;
    {
      oldy = y2;
      /* calcule de xobj->value / compute xobj->value */
      if ((x2 > 0) && (x2 < xobj->width) && (y2 > 0) && (y2 < hMenu))
	newvalue = y2 / hOpt+1;
      else
	newvalue = 0;
      if (newvalue != oldvalue)
      {
	UnselectMenu(xobj, WinPop, hOpt, oldvalue, xobj->width, asc, 0);
	SelectMenu(xobj, WinPop, hOpt, newvalue);
	oldvalue = newvalue;
      }
    }
    FD_ZERO(&in_fdset);
    FD_SET(x_fd, &in_fdset);
    select(32, SELECT_FD_SET_CAST &in_fdset, NULL, NULL, NULL);
  }
  while (!FCheckTypedEvent(dpy, while_mask, &event));
#endif
 XUngrabPointer(dpy, CurrentTime);
 XSync(dpy,0);

 XDestroyWindow(dpy, WinPop);
 if (newvalue != 0)
 {
   xobj->value = newvalue;
   SendMsg(xobj, SingleClic);
 }
}
Ejemplo n.º 6
0
Archivo: CheckBox.c Proyecto: att/uwin
void InitCheckBox(struct XObj *xobj)
{
  unsigned long mask;
  XSetWindowAttributes Attr;
  int asc,desc,dir;
  XCharStruct struc;
#ifdef I18N_MB
  char **ml;
  XFontStruct **fs_list;
#endif
  
  /* Enregistrement des couleurs et de la police / fonts and colors */
  if (xobj->colorset >= 0) {
    xobj->TabColor[fore] = Colorset[xobj->colorset].fg;
    xobj->TabColor[back] = Colorset[xobj->colorset].bg;
    xobj->TabColor[hili] = Colorset[xobj->colorset].hilite;
    xobj->TabColor[shad] = Colorset[xobj->colorset].shadow;
  } else {
    xobj->TabColor[fore] = GetColor(xobj->forecolor);
    xobj->TabColor[back] = GetColor(xobj->backcolor);
    xobj->TabColor[hili] = GetColor(xobj->hilicolor);
    xobj->TabColor[shad] = GetColor(xobj->shadcolor);
  }

  mask = 0;
  Attr.background_pixel = xobj->TabColor[back];
  mask |= CWBackPixel;
  Attr.cursor = XCreateFontCursor(dpy,XC_hand2);
  mask |= CWCursor;  /* Curseur pour la fenetre / Cursor for the window */

  xobj->win = XCreateWindow(dpy, *xobj->ParentWin,
		xobj->x, xobj->y, xobj->width, xobj->height,0,
		CopyFromParent, InputOutput, CopyFromParent,
		mask, &Attr);
  xobj->gc = fvwmlib_XCreateGC(dpy,xobj->win,0,NULL);
  XSetForeground(dpy, xobj->gc, xobj->TabColor[fore]);

#ifdef I18N_MB
  if ((xobj->xfontset = GetFontSetOrFixed(dpy,xobj->font)) == NULL) {
    fprintf(stderr, "FvwmScript: Couldn't load font. Exiting!\n");
    exit(1);
  }
  XFontsOfFontSet(xobj->xfontset,&fs_list,&ml);
  xobj->xfont = fs_list[0];
#else
  if ((xobj->xfont = GetFontOrFixed(dpy,xobj->font)) == NULL) {
    fprintf(stderr, "FvwmScript: Couldn't load font. Exiting!\n");
    exit(1);
  }
#endif
  XSetFont(dpy, xobj->gc, xobj->xfont->fid);

  XSetLineAttributes(dpy, xobj->gc, 1, LineSolid, CapRound, JoinMiter);

  /* Redimensionnement du widget / resize the widget */
  XTextExtents(xobj->xfont, "lp", strlen("lp"), &dir, &asc, &desc, &struc);
  xobj->height = asc+desc+5;
  xobj->width = XTextWidth(xobj->xfont, xobj->title, strlen(xobj->title)) + 30;
  XResizeWindow(dpy, xobj->win, xobj->width, xobj->height);
  if (xobj->colorset >= 0)
    SetWindowBackground(dpy, xobj->win, xobj->width, xobj->height,
			&Colorset[xobj->colorset], Pdepth,
			xobj->gc, True);
  XSelectInput(dpy, xobj->win, ExposureMask);
}
Ejemplo n.º 7
0
void InitTextField(struct XObj *xobj)
{
	unsigned long mask;
	XSetWindowAttributes Attr;
	int i;
	int num_chars;

	/* Enregistrement des couleurs et de la police */
	/* colors and fonts */
	if (xobj->colorset >= 0) {
		xobj->TabColor[fore] = Colorset[xobj->colorset].fg;
		xobj->TabColor[back] = Colorset[xobj->colorset].bg;
		xobj->TabColor[hili] = Colorset[xobj->colorset].hilite;
		xobj->TabColor[shad] = Colorset[xobj->colorset].shadow;
	} else {
		xobj->TabColor[fore] = GetColor(xobj->forecolor);
		xobj->TabColor[back] = GetColor(xobj->backcolor);
		xobj->TabColor[hili] = GetColor(xobj->hilicolor);
		xobj->TabColor[shad] = GetColor(xobj->shadcolor);
	}

	mask=0;
	Attr.cursor=XCreateFontCursor(dpy,XC_xterm);
	mask|=CWCursor; /* Curseur pour la fenetre / window cursor */
	Attr.background_pixel=xobj->TabColor[back];
	mask|=CWBackPixel;

	xobj->win=XCreateWindow(dpy,*xobj->ParentWin,
				xobj->x,xobj->y,xobj->width,xobj->height,0,
				CopyFromParent,InputOutput,CopyFromParent,
				mask,&Attr);
	xobj->gc=fvwmlib_XCreateGC(dpy,xobj->win,0,NULL);
	XSetForeground(dpy,xobj->gc,xobj->TabColor[fore]);

	if ((xobj->Ffont = FlocaleLoadFont(
		     dpy, xobj->font, ScriptName)) == NULL)
	{
		fprintf(
			stderr, "%s: Couldn't load font. Exiting!\n",
			ScriptName);
		exit(1);
	}
	if (xobj->Ffont->font != NULL)
		XSetFont(dpy, xobj->gc, xobj->Ffont->font->fid);

	XSetLineAttributes(dpy,xobj->gc,1,LineSolid,CapRound,JoinMiter);
	/* value2 représente la fin de la zone selectionnee */
	/* value2 gives the end of the selected zone */
	/* calculate number of characters in title */
	num_chars = FlocaleStringCharLength(xobj->Ffont, xobj->title);
	if (xobj->value > num_chars)
		xobj->value = num_chars;
	xobj->value2=xobj->value;
	/* left position of the visible title */
	xobj->value3=0;

	/* Redimensionnement du widget */
	/* widget resizing */
	xobj->height= xobj->Ffont->height + 10;
	i = FlocaleTextWidth(xobj->Ffont,xobj->title,strlen(xobj->title))+40;
	if (xobj->width<i)
		xobj->width=i;
	XResizeWindow(dpy,xobj->win,xobj->width,xobj->height);
	if (xobj->colorset >= 0)
		SetWindowBackground(dpy, xobj->win, xobj->width, xobj->height,
				    &Colorset[xobj->colorset], Pdepth,
				    xobj->gc, True);
	XSelectInput(dpy, xobj->win, ExposureMask);
}
Ejemplo n.º 8
0
/*
 * Fonction pour PushButton
 */
void InitPushButton(struct XObj *xobj)
{
	unsigned long mask;
	XSetWindowAttributes Attr;
	int i;
	char *str;

	/* Enregistrement des couleurs et de la police */
	if (xobj->colorset >= 0) {
		xobj->TabColor[fore] = Colorset[xobj->colorset].fg;
		xobj->TabColor[back] = Colorset[xobj->colorset].bg;
		xobj->TabColor[hili] = Colorset[xobj->colorset].hilite;
		xobj->TabColor[shad] = Colorset[xobj->colorset].shadow;
	} else {
		xobj->TabColor[fore] = GetColor(xobj->forecolor);
		xobj->TabColor[back] = GetColor(xobj->backcolor);
		xobj->TabColor[hili] = GetColor(xobj->hilicolor);
		xobj->TabColor[shad] = GetColor(xobj->shadcolor);
	}

	mask = 0;
	Attr.cursor = XCreateFontCursor(dpy, XC_hand2);
	mask |= CWCursor;
	Attr.background_pixel = xobj->TabColor[back];
	mask |= CWBackPixel;


	/* Epaisseur de la fenetre = 0 */
	xobj->win = XCreateWindow(
		dpy, *xobj->ParentWin, xobj->x, xobj->y, xobj->width,
		xobj->height, 0, CopyFromParent, InputOutput, CopyFromParent,
		mask, &Attr);
	xobj->gc = fvwmlib_XCreateGC(dpy, xobj->win, 0, NULL);
	XSetForeground(dpy, xobj->gc, xobj->TabColor[fore]);

	if ((xobj->Ffont = FlocaleLoadFont(
		     dpy, xobj->font, ScriptName)) == NULL)
	{
		fprintf(
			stderr, "%s: Couldn't load font. Exiting!\n",
			ScriptName);
		exit(1);
	}
	if (xobj->Ffont->font != NULL)
		XSetFont(dpy, xobj->gc, xobj->Ffont->font->fid);

	XSetLineAttributes(dpy, xobj->gc, 1, LineSolid, CapRound, JoinMiter);

	/* Redimensionnement du widget */
	str = (char*)GetMenuTitle(xobj->title, 1);
	if (xobj->icon == NULL)
	{
		i = xobj->Ffont->height + 12;
		if (xobj->height < i)
			xobj->height = i;
		i = FlocaleTextWidth(xobj->Ffont, str, strlen(str)) + 16;
		if (xobj->width < i)
			xobj->width = i;
	}
	else if (strlen(str) == 0)
	{
		if (xobj->height < xobj->icon_h + 10)
			xobj->height = xobj->icon_h + 10;
		if (xobj->width < xobj->icon_w + 10)
			xobj->width = xobj->icon_w + 10;
	}
	else
	{
		if (xobj->icon_w + 10 > FlocaleTextWidth(
			    xobj->Ffont, str, strlen(str)) + 16)
			i = xobj->icon_w + 10;
		else
			i = FlocaleTextWidth(
				xobj->Ffont, str, strlen(str)) + 16;
		if (xobj->width < i)
			xobj->width = i;
		i = xobj->icon_h+ 2 * (xobj->Ffont->height + 10);
		if (xobj->height < i)
			xobj->height = i;
	}
	XResizeWindow(dpy, xobj->win, xobj->width, xobj->height);
	if (xobj->colorset >= 0)
		SetWindowBackground(dpy, xobj->win, xobj->width, xobj->height,
				    &Colorset[xobj->colorset], Pdepth,
				    xobj->gc, True);
	xobj->value3 = CountOption(xobj->title);
	XSelectInput(dpy, xobj->win, ExposureMask);
}
Ejemplo n.º 9
0
void EvtMousePushButton(struct XObj *xobj, XButtonEvent *EvtButton)
{
	static XEvent event;
	int End = 1;
	unsigned int modif;
	int x1,x2,y1,y2,i;
	Window Win1,Win2,WinPop;
	Window WinBut = 0;
	int In = 0;
	char *str;
	int x,y,hOpt,yMenu,hMenu,wMenu;
	int oldvalue = 0,newvalue;
	unsigned long mask;
	XSetWindowAttributes Attr;

	if (EvtButton->button == Button1)
	{
		i = (xobj->width -
		     FlocaleTextWidth(
			     xobj->Ffont, xobj->title, strlen(xobj->title)))/2;

		while (End)
		{
			FNextEvent(dpy, &event);
			switch (event.type)
			{
			case EnterNotify:
				FQueryPointer(
					dpy, *xobj->ParentWin,
					&Win1, &Win2, &x1, &y1, &x2, &y2,
					&modif);
				if (WinBut == 0)
				{
					WinBut = Win2;
					DrawReliefRect(
						0, 0, xobj->width,
						xobj->height, xobj, shad,
						hili);
					DrawIconStr(
						0,xobj, True,
						PUSH_BUTTON_LCR_OFFSETS, NULL,
						NULL, NULL);
					In = 1;
				}
				else
				{
					if (Win2 == WinBut)
					{
						DrawReliefRect(
							0, 0, xobj->width,
							xobj->height, xobj,
							shad, hili);
						DrawIconStr(
							1, xobj, True,
							PUSH_BUTTON_LCR_OFFSETS,
							NULL, NULL, NULL);
						In = 1;
					}
					else if (In)
					{
						In = 0;
						DrawReliefRect(
							0, 0, xobj->width,
							xobj->height, xobj,
							hili, shad);
						DrawIconStr(
							0, xobj, True,
							PUSH_BUTTON_LCR_OFFSETS,
							NULL, NULL, NULL);
					}
				}
				break;
			case LeaveNotify:
				FQueryPointer(
					dpy, *xobj->ParentWin,
					&Win1, &Win2, &x1, &y1, &x2, &y2,
					&modif);
				if (Win2 == WinBut)
				{
					In = 1;
					DrawReliefRect(
						0, 0, xobj->width,
						xobj->height, xobj, shad,
						hili);
					DrawIconStr(
						1, xobj, True,
						PUSH_BUTTON_LCR_OFFSETS, NULL,
						NULL, NULL);
				}
				else if (In)
				{
					DrawReliefRect(
						0, 0, xobj->width,
						xobj->height, xobj, hili,
						shad);
					DrawIconStr(
						0, xobj, True,
						PUSH_BUTTON_LCR_OFFSETS, NULL,
						NULL, NULL);
					In = 0;
				}
				break;
			case ButtonRelease:
				End = 0;
				DrawReliefRect(
					0, 0, xobj->width, xobj->height, xobj,
					hili, shad);
				DrawIconStr(
					0, xobj, True,
					PUSH_BUTTON_LCR_OFFSETS, NULL, NULL,
					NULL);
				if (In)
				{
					/* Envoie d'un message vide de type
					 * SingleClic pour un clique souris */
					xobj->value = 1;
					SendMsg(xobj, SingleClic);
					xobj->value = 0;
				}
				break;
			}
		}
	}
	/* affichage du popup menu / Drawing the popup menu */
	else if (EvtButton->button == Button3)
	{
		if (xobj->value3 > 1)
		{
			hOpt = xobj->Ffont->height + 10;
			/* Hauteur totale du menu / Total height of the menu */
			hMenu = (xobj->value3 - 1) * hOpt;
			yMenu = xobj->y + xobj->height;
			wMenu = 0;
			for (i = 2 ; i <= xobj->value3; i++)
			{
				str = (char*)GetMenuTitle(xobj->title, i);
				if (wMenu < FlocaleTextWidth(
					    xobj->Ffont, str, strlen(str))+34)
					wMenu = FlocaleTextWidth(
						xobj->Ffont, str,
						strlen(str))+34;
				free(str);
			}

			/* Creation de la fenetre menu / create the menu
			 * window */
			XTranslateCoordinates(dpy, *xobj->ParentWin, Root,
					      xobj->x, yMenu, &x, &y, &Win1);
			if (x<0) x = 0;
			if (y<0) y = 0;
			if (x + wMenu > XDisplayWidth(dpy, screen))
			{
				x = XDisplayWidth(dpy, screen) - wMenu;
			}
			if (y + hMenu > XDisplayHeight(dpy, screen))
			{
				y = y-hMenu-xobj->height;
			}

			mask = 0;
			Attr.background_pixel = xobj->TabColor[back];
			mask |= CWBackPixel;
			Attr.border_pixel  =  0;
			mask |= CWBorderPixel;
			Attr.colormap = Pcmap;
			mask |= CWColormap;
			Attr.cursor = XCreateFontCursor(dpy, XC_hand2);
			mask |= CWCursor;         /* Curseur pour la fenetre */
			Attr.override_redirect = True;
			mask |= CWOverrideRedirect;
			WinPop = XCreateWindow(
				dpy, Root, x, y, wMenu-5, hMenu, 0,
				Pdepth, InputOutput, Pvisual, mask, &Attr);
			if (xobj->colorset >= 0)
				SetWindowBackground(
					dpy, WinPop, wMenu - 5, hMenu,
					&Colorset[xobj->colorset], Pdepth,
					xobj->gc, True);
			XMapRaised(dpy, WinPop);

			/* Dessin du menu */
			DrawPMenu(xobj, WinPop, hOpt, 1);
			do
			{
				FQueryPointer(
					dpy, Root, &Win1, &Win2, &x1, &y1,
					&x2, &y2, &modif);
				/* Determiner l'option courante / Current
				 * option */
				y2 = y2 - y;
				x2 = x2 - x;
				{
					/* calcule de xobj->value / Compute
					 * xobj->value */
					if ((x2 > 0) && (x2 < wMenu) &&
					    (y2 > 0) && (y2 < hMenu))
						newvalue = y2 / hOpt+1;
					else
						newvalue = 0;
					if (newvalue!=oldvalue)
					{
						UnselectMenu(
							xobj, WinPop, hOpt,
							oldvalue, wMenu-5,
							xobj->Ffont->ascent,
							1);
						SelectMenu(
							xobj, WinPop, hOpt,
							newvalue);
						oldvalue = newvalue;
					}
				}
			}
			while (!FCheckTypedEvent(dpy, ButtonRelease, &event));
			XDestroyWindow(dpy, WinPop);
			if (newvalue != 0)
			{
				xobj->value = newvalue;
				SendMsg(xobj, SingleClic);
				xobj->value = 0;
			}
			xobj->DrawObj(xobj, NULL);
		} /* xobj->value3 > 1 */
	} /* EvtButton->button == Button3 */
}
Ejemplo n.º 10
0
void InitVScrollBar(struct XObj *xobj)
{
  unsigned long mask;
  XSetWindowAttributes Attr;
  int i,j;
  char str[20];
  int asc,desc,dir;
  XCharStruct struc;
#ifdef I18N_MB
  char **ml;
  XFontStruct **fs_list;
#endif

  /* Enregistrement des couleurs et de la police */
  if (xobj->colorset >= 0) {
    xobj->TabColor[fore] = Colorset[xobj->colorset].fg;
    xobj->TabColor[back] = Colorset[xobj->colorset].bg;
    xobj->TabColor[hili] = Colorset[xobj->colorset].hilite;
    xobj->TabColor[shad] = Colorset[xobj->colorset].shadow;
  } else {
    xobj->TabColor[fore] = GetColor(xobj->forecolor);
    xobj->TabColor[back] = GetColor(xobj->backcolor);
    xobj->TabColor[hili] = GetColor(xobj->hilicolor);
    xobj->TabColor[shad] = GetColor(xobj->shadcolor);
  }

  mask = 0;
  Attr.background_pixel = xobj->TabColor[back];
  mask |= CWBackPixel;
  Attr.cursor = XCreateFontCursor(dpy,XC_hand2);
  mask |= CWCursor;		/* Curseur pour la fenetre */

  xobj->win = XCreateWindow(dpy, *xobj->ParentWin,
			    xobj->x, xobj->y, xobj->width, xobj->height, 0,
			    CopyFromParent, InputOutput, CopyFromParent,
			    mask, &Attr);
  xobj->gc = fvwmlib_XCreateGC(dpy, xobj->win, 0, NULL);
  XSetForeground(dpy, xobj->gc, xobj->TabColor[fore]);

#ifdef I18N_MB
  if ((xobj->xfontset = GetFontSetOrFixed(dpy,xobj->font)) == NULL) {
    fprintf(stderr, "FvwmScript: Couldn't load font. Exiting!\n");
    exit(1);
  }
  XFontsOfFontSet(xobj->xfontset, &fs_list, &ml);
  xobj->xfont = fs_list[0];
#else
  if ((xobj->xfont = GetFontOrFixed(dpy,xobj->font)) == NULL) {
    fprintf(stderr, "FvwmScript: Couldn't load font. Exiting!\n");
    exit(1);
 }
#endif
  XSetFont(dpy, xobj->gc, xobj->xfont->fid);

  XSetLineAttributes(dpy, xobj->gc, 1, LineSolid, CapRound, JoinMiter);

  if ((xobj->value3 - xobj->value2) <= 0)
    xobj->value3 = xobj->value2 + 10;
  if (!((xobj->value >= xobj->value2) && (xobj->value <= xobj->value3)))
    xobj->value = xobj->value2;

  XTextExtents(xobj->xfont, "lp", strlen("lp"), &dir, &asc, &desc, &struc);
  i = (asc+desc)*2+30;
  if (xobj->height < i)
    xobj->height = i;
  sprintf(str, "%d", xobj->value2);
  i = XTextWidth(xobj->xfont, str, strlen(str));
  sprintf(str, "%d", xobj->value3);
  j = XTextWidth(xobj->xfont, str, strlen(str));
  if (i<j)
    i = j*2+30;
  else
    i = i*2+30;
  xobj->width = i;
  XResizeWindow(dpy, xobj->win, xobj->width, xobj->height);
  if (xobj->colorset >= 0)
    SetWindowBackground(dpy, xobj->win, xobj->width, xobj->height,
			&Colorset[xobj->colorset], Pdepth,
			xobj->gc, True);
  XSelectInput(dpy, xobj->win, ExposureMask);
}
Ejemplo n.º 11
0
Archivo: FTips.c Proyecto: fvwmorg/fvwm
static
void __map_window(Display *dpy)
{
	rectangle new_g;
	rectangle screen_g;
	Window dummy;
	fscreen_scr_arg *fsarg = NULL; /* for now no xinerama support */
	ftips_placement_t placement;
	int x,y;
	static int border_width = 1;
	static Window win_f = None;

	if (border_width != current_config->border_width)
	{
		XSetWindowBorderWidth(dpy, win, current_config->border_width);
		border_width = current_config->border_width;
	}

	FScreenGetScrRect(
		fsarg,  FSCREEN_GLOBAL, &screen_g.x, &screen_g.y,
		&screen_g.width, &screen_g.height);

	new_g.height = ((current_config->Ffont)? current_config->Ffont->height:0)
		+ 1;
	new_g.width = 4;

	if (label && current_config->Ffont)
	{
		new_g.width += FlocaleTextWidth(
			current_config->Ffont, label, strlen(label));
	}

	if (current_config->placement != FTIPS_PLACEMENT_AUTO_UPDOWN &&
	    current_config->placement != FTIPS_PLACEMENT_AUTO_LEFTRIGHT)
	{
		placement = current_config->placement;
	}
	else
	{
		XTranslateCoordinates(
			dpy, win_for, DefaultRootWindow(dpy), box.x, box.y,
			&x, &y, &dummy);
		if (current_config->placement == FTIPS_PLACEMENT_AUTO_UPDOWN)
		{
			if (y + box.height/2 >= screen_g.height/2)
			{
				placement = FTIPS_PLACEMENT_UP;
			}
			else
			{
				placement = FTIPS_PLACEMENT_DOWN;
			}
		}
		else
		{
			if (x + box.width/2 >= screen_g.width/2)
			{
				placement = FTIPS_PLACEMENT_LEFT;
			}
			else
			{
				placement = FTIPS_PLACEMENT_RIGHT;
			}
		}
	}

	if (placement == FTIPS_PLACEMENT_RIGHT ||
	    placement == FTIPS_PLACEMENT_LEFT)
	{
		if (current_config->justification == FTIPS_JUSTIFICATION_CENTER)
		{
			y = box.y + (box.height / 2) - (new_g.height / 2) -
				current_config->border_width;
		}
		else if (current_config->justification ==
			 FTIPS_JUSTIFICATION_RIGHT_DOWN)
		{
			y = box.y + box.height  - new_g.height -
				(2 * current_config->border_width) -
				current_config->justification_offset;
		}
		else /* LEFT_UP */
		{
			y = box.y + current_config->justification_offset;

		}
	}
	else /* placement == FTIPS_PLACEMENT_DOWN ||
	       placement == FTIPS_PLACEMENT_UP */
	{
		if (current_config->justification == FTIPS_JUSTIFICATION_CENTER)
		{
			x = box.x + (box.width / 2) - (new_g.width / 2) -
				current_config->border_width;
		}
		else if (current_config->justification ==
			 FTIPS_JUSTIFICATION_RIGHT_DOWN)
		{
			x = box.x + box.width  - new_g.width -
				(2 * current_config->border_width) -
				current_config->justification_offset;
		}
		else /* LEFT_UP */
		{
			x = box.x + current_config->justification_offset;
		}
	}

	if (placement == FTIPS_PLACEMENT_RIGHT)
	{
		x = box.x + box.width + current_config->placement_offset + 1;
	}
	else if (placement == FTIPS_PLACEMENT_LEFT)
	{
		x = box.x - current_config->placement_offset - new_g.width
			- (2 * current_config->border_width) - 1;
	}
	else if (placement == FTIPS_PLACEMENT_DOWN)
	{
		y = box.y + box.height + current_config->placement_offset - 0;
	}
	else  /* UP */
	{
		y = box.y - current_config->placement_offset - new_g.height
			+ 0 - (2 * current_config->border_width);
	}

	XTranslateCoordinates(
		dpy, win_for, DefaultRootWindow(dpy), x, y,
		&new_g.x, &new_g.y, &dummy);

	if (placement == FTIPS_PLACEMENT_RIGHT ||
	    placement == FTIPS_PLACEMENT_LEFT)
	{
		int x1,y1,l1,l2;

		if (new_g.x < 2)
		{
			x = box.x + box.width + current_config->placement_offset
				+ 1;
			XTranslateCoordinates(
				dpy, win_for, DefaultRootWindow(dpy), x, y,
				&x1, &y1, &dummy);
			/* */
			l1 = new_g.width + new_g.x - 2;
			l2 = screen_g.width - (x1 + new_g.width) -
				current_config->border_width - 2;
			if (l2 > l1)
			{
				new_g.x = x1;
			}
		}
		else if (new_g.x + new_g.width >
			 screen_g.width - (2 * current_config->border_width) - 2)
		{
			x = box.x - current_config->placement_offset - new_g.width
				- (2 * current_config->border_width) - 1;
			XTranslateCoordinates(
				dpy, win_for, DefaultRootWindow(dpy), x, y,
				&x1, &y1, &dummy);
			/* */
			l1 = new_g.width + x1 - 2;
			l2 = screen_g.width - (new_g.x + new_g.width) -
				(2 * current_config->border_width) - 2;
			if (l1 > l2)
			{
				new_g.x = x1;
			}
		}
		if ( new_g.y < 2 )
		{
			new_g.y = 2;
		}
		else if (new_g.y + new_g.height >
			 screen_g.height - (2 * current_config->border_width) - 2)
		{
			new_g.y = screen_g.height - new_g.height -
				(2 * current_config->border_width) - 2;
		}
	}
	else /* placement == FTIPS_PLACEMENT_DOWN ||
		placement == FTIPS_PLACEMENT_UP */
	{
		if (new_g.y < 2)
		{
			y = box.y + box.height +
				current_config->placement_offset - 0;
			XTranslateCoordinates(
				dpy, win_for, DefaultRootWindow(dpy),
				x, y, &new_g.x, &new_g.y, &dummy);
		}
		else if (new_g.y + new_g.height >
			 screen_g.height - (2 * current_config->border_width) - 2)
		{
			y = box.y - current_config->placement_offset -
				new_g.height + 0
				- (2 * current_config->border_width);
			XTranslateCoordinates(
				dpy, win_for, DefaultRootWindow(dpy),
				x, y, &new_g.x, &new_g.y, &dummy);
		}
		if ( new_g.x < 2 )
		{
			new_g.x = 2;
		}
		else if (new_g.x + new_g.width >
			 screen_g.width - (2 * current_config->border_width) - 2)
		{
			new_g.x = screen_g.width - new_g.width -
				(2 * current_config->border_width) - 2;
		}
	}

	/* make changes to window */
	XMoveResizeWindow(
		dpy, win, new_g.x, new_g.y, new_g.width, new_g.height);
	__setup_gc(dpy);
	if (current_config->colorset > -1)
	{
		SetWindowBackground(
			dpy, win, new_g.width, new_g.height,
			&Colorset[current_config->colorset], Pdepth, gc, True);
	}
	else
	{
		XSetWindowBackground (dpy, win, current_config->bg);
	}
	if (current_config->border_width > 0)
	{
		XSetWindowBorder(
			dpy, win, Colorset[current_config->colorset].fg);
	}

	if (state != FVWM_TIPS_MAPPED && win_f != win_for)
	{
		long l_win_for;

		l_win_for = win_for;
		XChangeProperty(
			dpy, win, _net_um_for, XA_WINDOW, 32, PropModeReplace,
			(unsigned char *) &l_win_for, 1);
		win_f = win_for;
	}
	XMapRaised(dpy, win);
	state = FVWM_TIPS_MAPPED;

	return;
}
Ejemplo n.º 12
0
void InitVScrollBar(struct XObj *xobj)
{
	unsigned long mask;
	XSetWindowAttributes Attr;
	int i,j;
	char str[20];

	/* Enregistrement des couleurs et de la police */
	if (xobj->colorset >= 0) {
		xobj->TabColor[fore] = Colorset[xobj->colorset].fg;
		xobj->TabColor[back] = Colorset[xobj->colorset].bg;
		xobj->TabColor[hili] = Colorset[xobj->colorset].hilite;
		xobj->TabColor[shad] = Colorset[xobj->colorset].shadow;
	} else {
		xobj->TabColor[fore] = GetColor(xobj->forecolor);
		xobj->TabColor[back] = GetColor(xobj->backcolor);
		xobj->TabColor[hili] = GetColor(xobj->hilicolor);
		xobj->TabColor[shad] = GetColor(xobj->shadcolor);
	}

	mask = 0;
	Attr.background_pixel = xobj->TabColor[back];
	mask |= CWBackPixel;
	Attr.cursor = XCreateFontCursor(dpy,XC_hand2);
	mask |= CWCursor;             /* Curseur pour la fenetre */

	xobj->win = XCreateWindow(
		dpy, *xobj->ParentWin, xobj->x, xobj->y, xobj->width,
		xobj->height, 0, CopyFromParent, InputOutput, CopyFromParent,
		mask, &Attr);
	xobj->gc = fvwmlib_XCreateGC(dpy, xobj->win, 0, NULL);
	XSetForeground(dpy, xobj->gc, xobj->TabColor[fore]);


	if ((xobj->Ffont = FlocaleLoadFont(dpy, xobj->font, ScriptName)) ==
	    NULL)
	{
		fprintf(
			stderr, "%s: Couldn't load font. Exiting!\n",
			ScriptName);
		exit(1);
	}
	if (xobj->Ffont->font != NULL)
		XSetFont(dpy, xobj->gc, xobj->Ffont->font->fid);

	XSetLineAttributes(dpy, xobj->gc, 1, LineSolid, CapRound, JoinMiter);

	if ((xobj->value3 - xobj->value2) <= 0)
		xobj->value3 = xobj->value2 + 10;
	if (!((xobj->value >= xobj->value2) && (xobj->value <= xobj->value3)))
		xobj->value = xobj->value2;

	i = (xobj->Ffont->height)*2+30;
	if (xobj->height < i)
		xobj->height = i;
	sprintf(str, "%d", xobj->value2);
	i = FlocaleTextWidth(xobj->Ffont, str, strlen(str));
	sprintf(str, "%d", xobj->value3);
	j = FlocaleTextWidth(xobj->Ffont, str, strlen(str));
	if (i<j)
		i = j*2+30;
	else
		i = i*2+30;
	xobj->width = i;
	XResizeWindow(dpy, xobj->win, xobj->width, xobj->height);
	if (xobj->colorset >= 0)
		SetWindowBackground(dpy, xobj->win, xobj->width, xobj->height,
				    &Colorset[xobj->colorset], Pdepth,
				    xobj->gc, True);
	XSelectInput(dpy, xobj->win, ExposureMask);
}