Mercurial > hg > xemacs-beta
comparison lwlib/xlwgauge.c @ 442:abe6d1db359e r21-2-36
Import from CVS: tag r21-2-36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:35:02 +0200 |
parents | 8de8e3f6228a |
children | c33ae14dd6d0 |
comparison
equal
deleted
inserted
replaced
441:72a7cfa4a488 | 442:abe6d1db359e |
---|---|
1 /* Gauge Widget for XEmacs. | 1 /* Gauge Widget for XEmacs. |
2 Copyright (C) 1999 Edward A. Falk | 2 Copyright (C) 1999 Edward A. Falk |
3 | 3 |
4 This file is part of XEmacs. | 4 This file is part of XEmacs. |
5 | 5 |
6 XEmacs is free software; you can redistribute it and/or modify it | 6 XEmacs is free software; you can redistribute it and/or modify it |
23 /* | 23 /* |
24 * Gauge.c - Gauge widget | 24 * Gauge.c - Gauge widget |
25 * | 25 * |
26 * Author: Edward A. Falk | 26 * Author: Edward A. Falk |
27 * falk@falconer.vip.best.com | 27 * falk@falconer.vip.best.com |
28 * | 28 * |
29 * Date: July 9, 1997 | 29 * Date: July 9, 1997 |
30 * | 30 * |
31 * Note: for fun and demonstration purposes, I have added selection | 31 * Note: for fun and demonstration purposes, I have added selection |
32 * capabilities to this widget. If you select the widget, you create | 32 * capabilities to this widget. If you select the widget, you create |
33 * a primary selection containing the current value of the widget in | 33 * a primary selection containing the current value of the widget in |
50 #include <stdio.h> | 50 #include <stdio.h> |
51 #include <ctype.h> | 51 #include <ctype.h> |
52 #include <X11/IntrinsicP.h> | 52 #include <X11/IntrinsicP.h> |
53 #include <X11/Xatom.h> | 53 #include <X11/Xatom.h> |
54 #include <X11/StringDefs.h> | 54 #include <X11/StringDefs.h> |
55 #include ATHENA_INCLUDE(XawInit.h) | 55 #include ATHENA_XawInit_h_ |
56 #include "xlwgaugeP.h" | 56 #include "xlwgaugeP.h" |
57 #include "../src/xmu.h" | 57 #include "../src/xmu.h" |
58 #ifdef HAVE_XMU | 58 #ifdef HAVE_XMU |
59 #include <X11/Xmu/Atoms.h> | 59 #include <X11/Xmu/Atoms.h> |
60 #include <X11/Xmu/Drawing.h> | 60 #include <X11/Xmu/Drawing.h> |
158 * | 158 * |
159 ****************************************************************/ | 159 ****************************************************************/ |
160 | 160 |
161 GaugeClassRec gaugeClassRec = { | 161 GaugeClassRec gaugeClassRec = { |
162 { | 162 { |
163 /* core_class fields */ | 163 /* core_class fields */ |
164 /* superclass */ (WidgetClass) &labelClassRec, | 164 /* superclass */ (WidgetClass) &labelClassRec, |
165 /* class_name */ "Gauge", | 165 /* class_name */ "Gauge", |
166 /* widget_size */ sizeof(GaugeRec), | 166 /* widget_size */ sizeof(GaugeRec), |
167 /* class_initialize */ GaugeClassInit, | 167 /* class_initialize */ GaugeClassInit, |
168 /* class_part_initialize */ NULL, | 168 /* class_part_initialize */ NULL, |
332 gw->gauge.margin1 = lw1 / 2 ; | 332 gw->gauge.margin1 = lw1 / 2 ; |
333 size += lh + vmargin ; | 333 size += lh + vmargin ; |
334 } | 334 } |
335 else | 335 else |
336 { | 336 { |
337 gw->gauge.margin0 = | 337 gw->gauge.margin0 = |
338 gw->gauge.margin1 = lh / 2 ; | 338 gw->gauge.margin1 = lh / 2 ; |
339 size += lwm + vmargin ; | 339 size += lwm + vmargin ; |
340 } | 340 } |
341 } | 341 } |
342 else | 342 else |
402 len = gw->core.height ; | 402 len = gw->core.height ; |
403 hgt = gw->core.width ; | 403 hgt = gw->core.width ; |
404 } | 404 } |
405 | 405 |
406 /* if the gauge is selected, signify by drawing the background | 406 /* if the gauge is selected, signify by drawing the background |
407 * in a constrasting color. | 407 * in a contrasting color. |
408 */ | 408 */ |
409 | 409 |
410 if( gw->gauge.selected ) | 410 if( gw->gauge.selected ) |
411 { | 411 { |
412 XFillRectangle(dpy,win, gc, 0,0, w->core.width,w->core.height) ; | 412 XFillRectangle(dpy,win, gc, 0,0, w->core.width,w->core.height) ; |
464 | 464 |
465 /* draw labels */ | 465 /* draw labels */ |
466 if( gw->gauge.nlabels > 1 ) | 466 if( gw->gauge.nlabels > 1 ) |
467 { | 467 { |
468 char label[20], *s = label ; | 468 char label[20], *s = label ; |
469 int len, w,h =0 ; | 469 int xlen, wd,h =0 ; |
470 | 470 |
471 if( gw->gauge.orientation == XtorientHorizontal ) | 471 if( gw->gauge.orientation == XtorientHorizontal ) |
472 y = gw->gauge.lmargin + gw->label.font->max_bounds.ascent - 1 ; | 472 y = gw->gauge.lmargin + gw->label.font->max_bounds.ascent - 1 ; |
473 else { | 473 else { |
474 y = gw->gauge.lmargin ; | 474 y = gw->gauge.lmargin ; |
481 sprintf(label, "%d", v0+i*(v1 - v0)/(gw->gauge.nlabels - 1)) ; | 481 sprintf(label, "%d", v0+i*(v1 - v0)/(gw->gauge.nlabels - 1)) ; |
482 else | 482 else |
483 s = gw->gauge.labels[i] ; | 483 s = gw->gauge.labels[i] ; |
484 if( s != NULL ) { | 484 if( s != NULL ) { |
485 x = e0 + i*(e1-e0-1)/(gw->gauge.nlabels-1) ; | 485 x = e0 + i*(e1-e0-1)/(gw->gauge.nlabels-1) ; |
486 len = strlen(s) ; | 486 xlen = strlen(s) ; |
487 if( gw->gauge.orientation == XtorientHorizontal ) { | 487 if( gw->gauge.orientation == XtorientHorizontal ) { |
488 w = XTextWidth(gw->label.font, s, len) ; | 488 wd = XTextWidth(gw->label.font, s, xlen) ; |
489 XDrawString(dpy,win,gc, x-w/2,y, s,len) ; | 489 XDrawString(dpy,win,gc, x-wd/2,y, s,xlen) ; |
490 } | 490 } |
491 else { | 491 else { |
492 XDrawString(dpy,win,gc, y,x+h, s,len) ; | 492 XDrawString(dpy,win,gc, y,x+h, s,xlen) ; |
493 } | 493 } |
494 } | 494 } |
495 } | 495 } |
496 } | 496 } |
497 } | 497 } |
538 if( gw->label.resize ) | 538 if( gw->label.resize ) |
539 GaugeSize(gw, &gw->core.width, &gw->core.height, DEF_LEN) ; | 539 GaugeSize(gw, &gw->core.width, &gw->core.height, DEF_LEN) ; |
540 else | 540 else |
541 GaugeResize(new) ; | 541 GaugeResize(new) ; |
542 } | 542 } |
543 | 543 |
544 if( gw->gauge.update != oldgw->gauge.update ) | 544 if( gw->gauge.update != oldgw->gauge.update ) |
545 { | 545 { |
546 if( gw->gauge.update > 0 ) | 546 if( gw->gauge.update > 0 ) |
547 EnableUpdate(gw) ; | 547 EnableUpdate(gw) ; |
548 else | 548 else |
672 XtFree((char*) stdTargets) ; | 672 XtFree((char*) stdTargets) ; |
673 *format = 8*sizeof(Atom) ; /* TODO: needed? */ | 673 *format = 8*sizeof(Atom) ; /* TODO: needed? */ |
674 return True ; | 674 return True ; |
675 } | 675 } |
676 | 676 |
677 else | 677 else |
678 #endif | 678 #endif |
679 if( *target == XA_INTEGER ) | 679 if( *target == XA_INTEGER ) |
680 { | 680 { |
681 *type = XA_INTEGER ; | 681 *type = XA_INTEGER ; |
682 *length = 1 ; | 682 *length = 1 ; |
683 *value = (XtPointer) &gw->gauge.value ; | 683 *value = (XtPointer) &gw->gauge.value ; |
684 *format = 8*sizeof(int) ; | 684 *format = 8*sizeof(int) ; |
685 return True ; | 685 return True ; |
686 } | 686 } |
687 | 687 |
688 else if( *target == XA_STRING | 688 else if( *target == XA_STRING |
689 #ifdef HAVE_XMU | 689 #ifdef HAVE_XMU |
690 || | 690 || |
691 *target == XA_TEXT(XtDisplay(w)) | 691 *target == XA_TEXT(XtDisplay(w)) |
692 #endif | 692 #endif |
693 ) | 693 ) |
694 { | 694 { |
695 *type = *target ; | 695 *type = *target ; |
696 *length = strlen(gw->gauge.selstr)*sizeof(char) ; | 696 *length = strlen(gw->gauge.selstr)*sizeof(char) ; |
705 #ifdef HAVE_XMU | 705 #ifdef HAVE_XMU |
706 req = XtGetSelectionRequest(w, *selection, NULL) ; | 706 req = XtGetSelectionRequest(w, *selection, NULL) ; |
707 if( XmuConvertStandardSelection(w, req->time, selection, target, | 707 if( XmuConvertStandardSelection(w, req->time, selection, target, |
708 type, (XPointer *) value, length, format) ) | 708 type, (XPointer *) value, length, format) ) |
709 return True ; | 709 return True ; |
710 else | 710 else |
711 #endif | 711 #endif |
712 { | 712 { |
713 printf( | 713 printf( |
714 "Gauge: requestor is requesting unsupported selection %s:%s\n", | 714 "Gauge: requestor is requesting unsupported selection %s:%s\n", |
715 XGetAtomName(XtDisplay(w),*selection), | 715 XGetAtomName(XtDisplay(w),*selection), |
785 if( *type == XA_INTEGER ) { | 785 if( *type == XA_INTEGER ) { |
786 iptr = (int *)value ; | 786 iptr = (int *)value ; |
787 XawGaugeSetValue(w, *iptr) ; | 787 XawGaugeSetValue(w, *iptr) ; |
788 } | 788 } |
789 | 789 |
790 else if( *type == XA_STRING | 790 else if( *type == XA_STRING |
791 #ifdef HAVE_XMU | 791 #ifdef HAVE_XMU |
792 || | 792 || |
793 *type == XA_TEXT(dpy) | 793 *type == XA_TEXT(dpy) |
794 #endif | 794 #endif |
795 ) | 795 ) |
796 { | 796 { |
797 cptr = (char *)value ; | 797 cptr = (char *)value ; |
798 XawGaugeSetValue(w, atoi(cptr)) ; | 798 XawGaugeSetValue(w, atoi(cptr)) ; |
799 } | 799 } |
800 | 800 |