Lines Matching refs:sp

53 void SCCreate(sp, parent, x, y, vert, len, minv, maxv, curv, page,  in SCCreate()  argument
55 SCRL *sp; in SCCreate()
80 sp->x = x;
81 sp->y = y;
83 sp->vert = vert;
84 sp->len = len;
85 sp->fg = fg;
86 sp->bg = bg;
87 sp->hi = hi;
88 sp->lo = lo;
89 sp->uplit = sp->dnlit = 0;
90 sp->tsize = 19;
93 sp->win = XCreateSimpleWindow(theDisp,parent,x,y,
94 (u_int) sp->tsize, (u_int) len,1,fg,bg);
95 sp->w = sp->tsize;
96 sp->h = len;
99 sp->win = XCreateSimpleWindow(theDisp,parent,x,y,
100 (u_int) len, (u_int) sp->tsize,1,fg,bg);
101 sp->w = len;
102 sp->h = sp->tsize;
106 if (!sp->win) FatalError("can't create scrollbar window");
108 sp->tmin = sp->tsize+1;
109 sp->tmax = len - (sp->tsize+1) - sp->tsize;
111 sp->drawobj = func;
113 SCSetRange(sp, minv, maxv, curv, page);
114 XSelectInput(theDisp, sp->win, ExposureMask | ButtonPressMask);
119 void SCChange(sp, x, y, vert, len, minv, maxv, curv, page) in SCChange() argument
120 SCRL *sp; in SCChange()
123 sp->vert = vert;
124 sp->len = len;
125 sp->uplit = sp->dnlit = 0;
127 if (vert) XMoveResizeWindow(theDisp, sp->win, x,y,
128 (u_int) sp->tsize,(u_int) len);
129 else XMoveResizeWindow(theDisp, sp->win, x,y,
130 (u_int) len, (u_int) sp->tsize);
132 sp->tmin = sp->tsize+1;
133 sp->tmax = len - (sp->tsize+1) - sp->tsize;
135 SCSetRange(sp, minv, maxv, curv, page);
140 void SCSetRange(sp, minv, maxv, curv, page) in SCSetRange() argument
141 SCRL *sp; in SCSetRange()
145 sp->min = minv; sp->max = maxv; sp->page = page;
146 sp->active = (minv < maxv);
149 if (sp->active) {
150 if (ctrlColor) XSetWindowBackground(theDisp, sp->win, sp->lo);
151 else XSetWindowBackgroundPixmap(theDisp, sp->win, sgray);
153 else XSetWindowBackground(theDisp, sp->win, sp->bg);
155 sp->val = -99999; /* force redraw */
156 SCSetVal(sp, curv);
161 int SCSetVal(sp, curv) in SCSetVal() argument
162 SCRL *sp; in SCSetVal()
168 RANGE(curv, sp->min, sp->max); /* make sure curv is in-range */
170 if (sp->val == curv) return 0;
172 oldval = sp->val;
175 sp->val = curv;
177 if (sp->active)
178 sp->tpos = sp->tmin + ((sp->tmax - sp->tmin)*(curv - sp->min))
179 / (sp->max - sp->min);
181 drawThumb(sp);
182 (sp->drawobj)(curv-oldval, sp); /* redraw what the scrlbar controls */
190 void SCRedraw(sp) in SCRedraw() argument
191 SCRL *sp; in SCRedraw()
193 XSetForeground(theDisp, theGC, sp->fg);
194 XSetBackground(theDisp, theGC, sp->bg);
196 XClearWindow(theDisp, sp->win);
198 drawArrow(sp,UPLINE); /* draw up/down arrows */
199 drawArrow(sp,DNLINE);
201 XSetForeground(theDisp, theGC, sp->fg);
203 if (sp->vert) {
204 XDrawLine(theDisp, sp->win, theGC, 0, sp->tsize, sp->tsize, sp->tsize);
205 XDrawLine(theDisp, sp->win, theGC, 0, sp->len-sp->tsize-1,
206 sp->tsize, sp->len-sp->tsize-1);
209 XDrawLine(theDisp, sp->win, theGC, sp->tsize, 0, sp->tsize, sp->tsize);
210 XDrawLine(theDisp, sp->win, theGC, sp->len - sp->tsize-1, 0,
211 sp->len - sp->tsize-1, sp->tsize);
214 drawThumb(sp);
220 static void drawArrow(sp,arr) in drawArrow() argument
221 SCRL *sp; in drawArrow()
227 XSetForeground(theDisp, theGC, sp->bg);
228 XFillRectangle(theDisp, sp->win, theGC, 0, 0,
229 (u_int) sp->tsize, (u_int) sp->tsize);
231 if (sp->vert) butpix = (sp->uplit) ? up1Pix : upPix;
232 else butpix = (sp->uplit) ? uph1Pix : uphPix;
234 XSetForeground(theDisp, theGC, sp->fg);
235 XSetBackground(theDisp, theGC, sp->bg);
236 XCopyPlane(theDisp, butpix, sp->win, theGC, 0, 0, up_width,up_height,
238 Draw3dRect(sp->win, 0,0, (u_int) sp->tsize-1, (u_int) sp->tsize-1,
239 (sp->uplit) ? R3D_IN : R3D_OUT, 2, sp->hi, sp->lo, sp->bg);
243 if (sp->vert) {
244 XSetForeground(theDisp, theGC, sp->bg);
245 XFillRectangle(theDisp, sp->win, theGC, 0, sp->len - sp->tsize,
246 (u_int) sp->tsize, (u_int) sp->tsize);
247 butpix = (sp->dnlit) ? down1Pix : downPix;
249 XSetForeground(theDisp, theGC, sp->fg);
250 XSetBackground(theDisp, theGC, sp->bg);
251 XCopyPlane(theDisp, butpix, sp->win, theGC, 0, 0, up_width,up_height,
252 3, sp->len - 3 - up_height, 1L);
254 Draw3dRect(sp->win, 0, sp->len - sp->tsize,
255 (u_int) sp->tsize-1, (u_int) sp->tsize-1,
256 (sp->dnlit) ? R3D_IN : R3D_OUT, 2, sp->hi, sp->lo, sp->bg);
260 XSetForeground(theDisp, theGC, sp->bg);
261 XFillRectangle(theDisp, sp->win, theGC, sp->len - sp->tsize, 0,
262 (u_int) sp->tsize, (u_int) sp->tsize);
263 butpix = (sp->dnlit) ? downh1Pix : downhPix;
265 XSetForeground(theDisp, theGC, sp->fg);
266 XSetBackground(theDisp, theGC, sp->bg);
267 XCopyPlane(theDisp, butpix, sp->win, theGC, 0, 0, up_width,up_height,
268 sp->len - 3 - up_width, 3, 1L);
270 Draw3dRect(sp->win, sp->len - sp->tsize, 0,
271 (u_int) sp->tsize-1, (u_int) sp->tsize-1,
272 (sp->dnlit) ? R3D_IN : R3D_OUT, 2, sp->hi, sp->lo, sp->bg);
281 static void drawThumb(sp) in drawThumb() argument
282 SCRL *sp; in drawThumb()
284 if (sp->vert) {
286 XClearArea(theDisp, sp->win, 0, sp->tsize+1, (u_int) sp->tsize,
287 (u_int) ((sp->len-sp->tsize-1)-(sp->tsize+1)), False);
289 if (sp->active) { /* a thumb is necessary */
291 XSetForeground(theDisp, theGC, sp->bg);
292 XFillRectangle(theDisp, sp->win, theGC, 1, sp->tpos+1,
293 (u_int) (sp->tsize-2), (u_int) (sp->tsize-2));
295 XSetForeground(theDisp, theGC, sp->fg);
296 XDrawRectangle(theDisp, sp->win, theGC, 0, sp->tpos,
297 (u_int) (sp->tsize-1), (u_int) (sp->tsize-1));
299 XDrawLine(theDisp, sp->win, theGC, 9-3, sp->tpos+6, 9+3, sp->tpos+6);
300 XDrawLine(theDisp, sp->win, theGC, 9-3, sp->tpos+8, 9+3, sp->tpos+8);
301 XDrawLine(theDisp, sp->win, theGC, 9-3, sp->tpos+10,9+3, sp->tpos+10);
302 XDrawLine(theDisp, sp->win, theGC, 9-3, sp->tpos+12,9+3, sp->tpos+12);
304 Draw3dRect(sp->win, 1, sp->tpos+1,
305 (u_int) sp->tsize-3, (u_int) sp->tsize-3, R3D_OUT,2,
306 sp->hi, sp->lo, sp->bg);
312 XClearArea(theDisp, sp->win, sp->tsize+1, 0,
313 (u_int) ((sp->len-sp->tsize-1)-(sp->tsize+1)),
314 (u_int) sp->tsize, False);
316 if (sp->active) { /* a thumb is necessary */
317 XSetForeground(theDisp, theGC, sp->bg);
318 XFillRectangle(theDisp, sp->win, theGC, sp->tpos+1, 1,
319 (u_int) (sp->tsize-2), (u_int) (sp->tsize-2));
321 XSetForeground(theDisp, theGC, sp->fg);
322 XDrawRectangle(theDisp, sp->win, theGC, sp->tpos, 0,
323 (u_int) (sp->tsize-1), (u_int) (sp->tsize-1));
325 XDrawLine(theDisp, sp->win, theGC, sp->tpos+6, 9-3, sp->tpos+6, 9+3);
326 XDrawLine(theDisp, sp->win, theGC, sp->tpos+8, 9-3, sp->tpos+8, 9+3);
327 XDrawLine(theDisp, sp->win, theGC, sp->tpos+10,9-3, sp->tpos+10,9+3);
328 XDrawLine(theDisp, sp->win, theGC, sp->tpos+12,9-3, sp->tpos+12,9+3);
330 Draw3dRect(sp->win, sp->tpos+1, 1,
331 (u_int) sp->tsize-3, (u_int) sp->tsize-3, R3D_OUT,2,
332 sp->hi, sp->lo, sp->bg);
340 static int whereInScrl(sp,x,y) in whereInScrl() argument
341 SCRL *sp; in whereInScrl()
349 if (sp->vert) {
350 if (x<0 || x>sp->tsize || y<0 || y>sp->len) return -1;
354 if (y<0 || y>sp->tsize || x<0 || x>sp->len) return -1;
359 if (v < sp->tmin) return UPLINE;
360 if (sp->active) {
361 if (v < sp->tpos) return UPPAGE;
362 if (v < sp->tpos + sp->tsize) return THUMB;
363 if (v <= sp->tmax + sp->tsize) return DNPAGE;
365 if (v > sp->tmax+sp->tsize) return DNLINE;
372 void SCTrack(sp,mx,my) in SCTrack() argument
373 SCRL *sp; in SCTrack()
385 if (!sp->active) return;
387 XSetForeground(theDisp, theGC, sp->fg);
388 XSetBackground(theDisp, theGC, sp->bg);
391 ipos = whereInScrl(sp,mx,my);
395 case UPLINE: sp->uplit = 1;
396 drawArrow(sp, UPLINE);
397 if (sp->val > sp->min) SCSetVal(sp,sp->val-1);
401 case DNLINE: sp->dnlit = 1;
402 drawArrow(sp, DNLINE);
403 if (sp->val < sp->max) SCSetVal(sp,sp->val+1);
407 case UPPAGE: SCSetVal(sp,sp->val - sp->page); break;
408 case DNPAGE: SCSetVal(sp,sp->val + sp->page); break;
409 case THUMB: tyoff = sp->tpos - my;
410 txoff = sp->tpos - mx;
411 ty = sp->tpos;
412 tx = sp->tpos;
416 while (XQueryPointer(theDisp,sp->win,&rW,&cW,&rx,&ry,&x,&y,&mask)) {
424 if (sp->vert) {
426 RANGE(ty1, sp->tmin, sp->tmax);
429 dt = sp->tmax - sp->tmin;
430 dv = sp->max - sp->min;
432 SCSetVal(sp, sp->min + (dv*(ty - sp->tmin)+dt/2) / dt);
437 RANGE(tx1, sp->tmin, sp->tmax);
440 dt = sp->tmax - sp->tmin;
441 dv = sp->max - sp->min;
443 SCSetVal(sp, sp->min + (dv*(tx - sp->tmin)+dt/2) / dt);
451 pos = whereInScrl(sp,x,y);
455 if (ipos == UPLINE) { sp->uplit = 1; drawArrow(sp,UPLINE); }
456 else { sp->dnlit = 1; drawArrow(sp,DNLINE); }
460 if (sp->val > sp->min && pos==UPLINE) {
461 SCSetVal(sp, sp->val-1);
464 else if (sp->val < sp->max && pos==DNLINE) {
465 SCSetVal(sp, sp->val+1);
474 if (ipos == UPLINE) { sp->uplit = 0; drawArrow(sp,UPLINE); }
475 else { sp->dnlit = 0; drawArrow(sp,DNLINE); }
484 if (lit && ipos == UPLINE) { sp->uplit = 0; drawArrow(sp, UPLINE); }
485 if (lit && ipos == DNLINE) { sp->dnlit = 0; drawArrow(sp, DNLINE); }