File: MiniScroll.c

package info (click to toggle)
fvwm95 2.0.43ba-15
  • links: PTS
  • area: main
  • in suites: potato
  • size: 6,356 kB
  • ctags: 4,759
  • sloc: ansic: 46,398; makefile: 1,586; sh: 782; perl: 328
file content (157 lines) | stat: -rw-r--r-- 3,982 bytes parent folder | download | duplicates (7)
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
#include "Tools.h"


/***********************************************/
/* Fonction pour MiniScroll                      */
/***********************************************/
void InitMiniScroll(struct XObj *xobj)
{
 unsigned long mask;
 XSetWindowAttributes Attr;
 int i;

 /* 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.background_pixel=xobj->TabColor[back].pixel;
 mask|=CWBackPixel;

 /* La taille du widget est fixe */
 xobj->width=19;
 xobj->height=34;
 xobj->win=XCreateWindow(xobj->display,*xobj->ParentWin,
		xobj->x,xobj->y,xobj->width,xobj->height,1,
		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);
 if (xobj->value2>xobj->value3)
 {
  i=xobj->value2;
  xobj->value2=xobj->value3;
  xobj->value3=i;
 }
 if ((xobj->value<xobj->value2)||(xobj->value>xobj->value3))
  xobj->value=xobj->value2;
}

void DestroyMiniScroll(struct XObj *xobj)
{
 XFreeFont(xobj->display,xobj->xfont);
 XFreeGC(xobj->display,xobj->gc);
 XDestroyWindow(xobj->display,xobj->win);
}

void DrawMiniScroll(struct XObj *xobj)
{

 DrawReliefRect(-1,-1,xobj->width+2,xobj->height+2,xobj,xobj->TabColor[li].pixel,
 		xobj->TabColor[shad].pixel,xobj->TabColor[black].pixel,-1);

 /* Dessin de la fleche du haut */
 DrawArrowN(xobj,3,3,0);
 DrawArrowS(xobj,3,18,0);

}

void EvtMouseMiniScroll(struct XObj *xobj,XButtonEvent *EvtButton)
{
 static XEvent event;
 int x1,y1,x2,y2;
 Window Win1,Win2;
 unsigned int modif;
 int Pos=0;
 struct timeval *tv;
 long tus,ts;
 
 do
 {
  XQueryPointer(xobj->display,*xobj->ParentWin,&Win1,&Win2,&x1,&y1,&x2,&y2,&modif);
  /* Determiner l'option courante */
  y2=y2-xobj->y;
  x2=x2-xobj->x;
  if ((x2>0)&&(x2<xobj->width)&&(y2>0)&&(y2<xobj->height/2))
  {
   if (Pos==1)
   {
    tv=(struct timeval*)calloc(1,sizeof(struct timeval));
    gettimeofday(tv,NULL);
    tus=tv->tv_usec;
    ts=tv->tv_sec;
    while (((tv->tv_usec-tus)+(tv->tv_sec-ts)*1000000)<16667*8)
     gettimeofday(tv,NULL);
    free(tv);
   }
   else
   {
    DrawArrowN(xobj,3,3,1);
    Pos=1;
   }
   xobj->value++;
   if (xobj->value>xobj->value3)
    xobj->value=xobj->value2;
   SendMsg(xobj,SingleClic);
   
  }
  else if ((x2>0)&&(x2<xobj->width)&&(y2>xobj->height/2)&&(y2<xobj->height))
  {
   if (Pos==-1)
   {
    tv=(struct timeval*)calloc(1,sizeof(struct timeval));
    gettimeofday(tv,NULL);
    tus=tv->tv_usec;
    ts=tv->tv_sec;
    while (((tv->tv_usec-tus)+(tv->tv_sec-ts)*1000000)<16667*8)
     gettimeofday(tv,NULL);
    free(tv);
   }
   else
   {
    DrawArrowS(xobj,3,18,1);
    Pos=-1;
   }
   xobj->value--;
   if (xobj->value<xobj->value2)
    xobj->value=xobj->value3;
   SendMsg(xobj,SingleClic);
  }
  else if (Pos!=0)
  {
   Pos=0;
   DrawArrowN(xobj,3,3,0);
   DrawArrowS(xobj,3,18,0);
  }
 }
 while (!XCheckTypedEvent(xobj->display,ButtonRelease,&event));
 DrawArrowN(xobj,3,3,0);
 DrawArrowS(xobj,3,18,0);
}

void EvtKeyMiniScroll(struct XObj *xobj,XKeyEvent *EvtKey)
{
}

void ProcessMsgMiniScroll(struct XObj *xobj,unsigned long type,unsigned long *body)
{
}