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
|
#include "Tools.h"
/***********************************************/
/* Fonction pour RadioButton */
/***********************************************/
void InitRadioButton(struct XObj *xobj)
{
unsigned long mask;
XSetWindowAttributes Attr;
int asc,desc,dir;
XCharStruct struc;
/* Enregistrement des couleurs et de la police */
MyAllocNamedColor(xobj->display,*xobj->colormap,xobj->forecolor,&xobj->TabColor[fore]);
MyAllocNamedColor(xobj->display,*xobj->colormap,xobj->backcolor,&xobj->TabColor[back]);
MyAllocNamedColor(xobj->display,*xobj->colormap,xobj->licolor,&xobj->TabColor[li]);
MyAllocNamedColor(xobj->display,*xobj->colormap,xobj->shadcolor,&xobj->TabColor[shad]);
MyAllocNamedColor(xobj->display,*xobj->colormap,"#000000",&xobj->TabColor[black]);
MyAllocNamedColor(xobj->display,*xobj->colormap,"#FFFFFF",&xobj->TabColor[white]);
mask=0;
Attr.cursor=XCreateFontCursor(xobj->display,XC_hand2);
mask|=CWCursor; /* Curseur pour la fenetre */
Attr.background_pixel=xobj->TabColor[back].pixel;
mask|=CWBackPixel;
xobj->win=XCreateWindow(x11base->display,*xobj->ParentWin,
xobj->x,xobj->y,xobj->width,xobj->height,0,
CopyFromParent,InputOutput,CopyFromParent,
mask,&Attr);
xobj->gc=XCreateGC(xobj->display,xobj->win,0,NULL);
XSetForeground(xobj->display,xobj->gc,xobj->TabColor[fore].pixel);
XSetBackground(xobj->display,xobj->gc,xobj->TabColor[back].pixel);
if ((xobj->xfont=XLoadQueryFont(xobj->display,xobj->font))==NULL)
{
fprintf(stderr,"Can't load font %s\n",xobj->font);
}
else
XSetFont(xobj->display,xobj->gc,xobj->xfont->fid);
XSetLineAttributes(xobj->display,xobj->gc,1,LineSolid,CapRound,JoinMiter);
/* Redimensionnement du 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))+20;
XResizeWindow(xobj->display,xobj->win,xobj->width,xobj->height);
}
void DestroyRadioButton(struct XObj *xobj)
{
XFreeFont(xobj->display,xobj->xfont);
XFreeGC(xobj->display,xobj->gc);
XDestroyWindow(xobj->display,xobj->win);
}
void DrawRadioButton(struct XObj *xobj)
{
int i,j;
j=xobj->height/2+3;
i=16;
/* Dessin du cercle arrondi */
XSetForeground(xobj->display,xobj->gc,xobj->TabColor[shad].pixel);
XDrawArc(xobj->display,xobj->win,xobj->gc,1,j-11,11,11,45*64,180*64);
XSetForeground(xobj->display,xobj->gc,xobj->TabColor[li].pixel);
XDrawArc(xobj->display,xobj->win,xobj->gc,1,j-11,11,11,225*64,180*64);
XSetForeground(xobj->display,xobj->gc,xobj->TabColor[white].pixel);
XFillArc(xobj->display,xobj->win,xobj->gc,2,j-10,9,9,0*64,360*64);
XSetForeground(xobj->display,xobj->gc,xobj->TabColor[black].pixel);
XDrawArc(xobj->display,xobj->win,xobj->gc,2,j-10,9,9,0*64,360*64);
if (xobj->value)
{
XSetForeground(xobj->display,xobj->gc,xobj->TabColor[black].pixel);
XFillArc(xobj->display,xobj->win,xobj->gc,3,j-9,7,7,0*64,360*64);
}
/* Calcul de la position de la chaine de charactere */
DrawString(xobj->display,xobj->gc,xobj->win,i,j,xobj->title,
strlen(xobj->title),xobj->TabColor[fore].pixel,
xobj->TabColor[li].pixel,xobj->TabColor[back].pixel,
!xobj->flags[1]);
}
void EvtMouseRadioButton(struct XObj *xobj,XButtonEvent *EvtButton)
{
static XEvent event;
int End=1;
unsigned int modif;
int x1,x2,y1,y2,i,j;
Window Win1,Win2;
Window WinBut=0;
int In;
j=xobj->height/2+3;
i=(xobj->width-XTextWidth(xobj->xfont,xobj->title,strlen(xobj->title)))/2;
while (End)
{
XNextEvent(xobj->display, &event);
switch (event.type)
{
case EnterNotify:
XQueryPointer(xobj->display,*xobj->ParentWin,
&Win1,&Win2,&x1,&y1,&x2,&y2,&modif);
if (WinBut==0)
{
WinBut=Win2;
/* Mouse on button */
XSetForeground(xobj->display,xobj->gc,xobj->TabColor[back].pixel);
XFillArc(xobj->display,xobj->win,xobj->gc,3,j-9,7,7,0*64,360*64);
In=1;
}
else
{
if (Win2==WinBut)
{
/* Mouse on button */
XSetForeground(xobj->display,xobj->gc,xobj->TabColor[back].pixel);
XFillArc(xobj->display,xobj->win,xobj->gc,3,j-9,7,7,0*64,360*64);
In=1;
}
else if (In)
{
In=0;
/* Mouse not on button */
XSetForeground(xobj->display,xobj->gc,xobj->TabColor[white].pixel);
XFillArc(xobj->display,xobj->win,xobj->gc,3,j-9,7,7,0*64,360*64);
}
}
break;
case LeaveNotify:
XQueryPointer(xobj->display,*xobj->ParentWin,
&Win1,&Win2,&x1,&y1,&x2,&y2,&modif);
if (Win2==WinBut)
{
In=1;
/* Mouse on button */
XSetForeground(xobj->display,xobj->gc,xobj->TabColor[back].pixel);
XFillArc(xobj->display,xobj->win,xobj->gc,3,j-9,7,7,0*64,360*64);
}
else if (In)
{
/* Mouse not on button */
XSetForeground(xobj->display,xobj->gc,xobj->TabColor[white].pixel);
XFillArc(xobj->display,xobj->win,xobj->gc,3,j-9,7,7,0*64,360*64);
In=0;
}
break;
case ButtonRelease:
End=0;
/* Mouse not on button */
if (In)
{
/* Envoie d'un message vide de type SingleClic pour un clique souris */
xobj->value=1;
XSetForeground(xobj->display,xobj->gc,xobj->TabColor[black].pixel);
XFillArc(xobj->display,xobj->win,xobj->gc,3,j-9,7,7,0*64,360*64);
SendMsg(xobj,SingleClic);
}
else if (xobj->value)
{
XSetForeground(xobj->display,xobj->gc,xobj->TabColor[black].pixel);
XFillArc(xobj->display,xobj->win,xobj->gc,3,j-9,7,7,0*64,360*64);
}
break;
}
}
}
void EvtKeyRadioButton(struct XObj *xobj,XKeyEvent *EvtKey)
{
}
void ProcessMsgRadioButton(struct XObj *xobj,unsigned long type,unsigned long *body)
{
}
|