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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935
|
/*
* Copyright 2004 Computing Research Labs, New Mexico State University
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COMPUTING RESEARCH LAB OR NEW MEXICO STATE UNIVERSITY BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
* OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
* THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef lint
#ifdef __GNUC__
static char rcsid[] __attribute__ ((unused)) = "$Id: ProgBar.c,v 1.8 2004/02/09 16:28:25 mleisher Exp $";
#else
static char rcsid[] = "$Id: ProgBar.c,v 1.8 2004/02/09 16:28:25 mleisher Exp $";
#endif
#endif
#include <stdlib.h>
#include "ProgBarP.h"
static Dimension
#ifndef _NO_PROTO
_XmuttProgressBarPMargins(XmuttProgressBarWidget pw)
#else
_XmuttProgressBarPMargins(pw)
XmuttProgressBarWidget pw;
#endif
{
return pw->primitive.shadow_thickness << 1;
}
static Dimension
#ifndef _NO_PROTO
_XmuttProgressBarHMargins(XmuttProgressBarWidget pw)
#else
_XmuttProgressBarHMargins(pw)
XmuttProgressBarWidget pw;
#endif
{
return _XmuttProgressBarPMargins(pw) + (pw->progress.mwidth << 1);
}
static Dimension
#ifndef _NO_PROTO
_XmuttProgressBarVMargins(XmuttProgressBarWidget pw)
#else
_XmuttProgressBarVMargins(pw)
XmuttProgressBarWidget pw;
#endif
{
return _XmuttProgressBarPMargins(pw) + (pw->progress.mheight << 1);
}
static Dimension
#ifndef _NO_PROTO
_XmuttProgressBarTopY(XmuttProgressBarWidget pw)
#else
_XmuttProgressBarTopY(pw)
XmuttProgressBarWidget pw;
#endif
{
return (_XmuttProgressBarPMargins(pw) >> 1) + pw->progress.mheight;
}
static Dimension
#ifndef _NO_PROTO
_XmuttProgressBarBottomY(XmuttProgressBarWidget pw)
#else
_XmuttProgressBarBottomY(pw)
XmuttProgressBarWidget pw;
#endif
{
return pw->core.height -
((_XmuttProgressBarPMargins(pw) >> 1) + pw->progress.mheight);
}
static Dimension
#ifndef _NO_PROTO
_XmuttProgressBarLeftX(XmuttProgressBarWidget pw)
#else
_XmuttProgressBarLeftX(pw)
XmuttProgressBarWidget pw;
#endif
{
return (_XmuttProgressBarPMargins(pw) >> 1) + pw->progress.mwidth;
}
static Dimension
#ifndef _NO_PROTO
_XmuttProgressBarRightX(XmuttProgressBarWidget pw)
#else
_XmuttProgressBarRightX(pw)
XmuttProgressBarWidget pw;
#endif
{
return pw->core.width -
((_XmuttProgressBarPMargins(pw) >> 1) + pw->progress.mwidth);
}
static void
#ifndef _NO_PROTO
_XmuttProgressBarShadowWindow(XmuttProgressBarWidget pw)
#else
_XmuttProgressBarShadowWindow(pw)
XmuttProgressBarWidget pw;
#endif
{
Widget w;
int i;
XPoint br[3], tl[3];
w = (Widget) pw;
if (!XtIsRealized(w) || pw->primitive.shadow_thickness == 0)
return;
/*
* Lower left corner outside line.
*/
tl[0].x = 0;
tl[0].y = pw->core.height - 1;
/*
* Upper left corner outside line.
*/
tl[1].x = tl[0].x;
tl[1].y = 0;
/*
* Upper right corner outside line.
*/
tl[2].x = pw->core.width - 1;
tl[2].y = tl[1].y;
/*
* Upper right corner outside line.
*/
br[0].x = tl[2].x;
br[0].y = tl[2].y + 1;
/*
* Lower right corner outside line.
*/
br[1].x = br[0].x;
br[1].y = pw->core.height - 1;
/*
* Lower left corner outside line.
*/
br[2].x = 1;
br[2].y = br[1].y;
XDrawLines(XtDisplay(w), XtWindow(w), pw->primitive.top_shadow_GC,
tl, 3, CoordModeOrigin);
XDrawLines(XtDisplay(w), XtWindow(w), pw->primitive.bottom_shadow_GC,
br, 3, CoordModeOrigin);
/*
* Draw the remaining shadows successively inward.
*/
for (i = 1; i < pw->primitive.shadow_thickness; i++) {
tl[0].x++;
tl[0].y--;
tl[1].x++;
tl[1].y++;
tl[2].x--;
tl[2].y++;
br[0].x--;
br[0].y++;
br[1].x--;
br[1].y--;
br[2].x++;
br[2].y--;
XDrawLines(XtDisplay(w), XtWindow(w), pw->primitive.top_shadow_GC,
tl, 3, CoordModeOrigin);
XDrawLines(XtDisplay(w), XtWindow(w), pw->primitive.bottom_shadow_GC,
br, 3, CoordModeOrigin);
}
}
static void
#ifndef _NO_PROTO
_XmuttProgressBarPreferredGeometry(XmuttProgressBarWidget pw, Dimension *width,
Dimension *height)
#else
_XmuttProgressBarPreferredGeometry(pw, width, height)
XmuttProgressBarWidget pw;
Dimension *width, *height;
#endif
{
Dimension wd, ht, pmargin, lheight, lwidth;
pmargin = pw->primitive.shadow_thickness << 1;
lheight = pw->progress.label_height;
if ((lwidth = pw->progress.label_width) < 200)
lwidth = 200;
wd = _XmuttProgressBarHMargins(pw) + 4 + lwidth;
ht = _XmuttProgressBarVMargins(pw) + 4 + pw->progress.percheight;
/*
* Add the label height if a label exists.
*/
if (lheight)
ht += lheight + 2;
*width = wd;
*height = ht;
}
static void
#ifndef _NO_PROTO
_XmuttProgressBarSetBarGeometry(XmuttProgressBarWidget pw)
#else
_XmuttProgressBarSetBarGeometry(pw)
XmuttProgressBarWidget pw;
#endif
{
pw->progress.bar.x = _XmuttProgressBarLeftX(pw) + 2;
pw->progress.bar.y = _XmuttProgressBarTopY(pw) + 2 +
pw->progress.label_height + 2;
pw->progress.bar.width = (_XmuttProgressBarRightX(pw) - 2) -
pw->progress.bar.x;
pw->progress.bar.height = (_XmuttProgressBarBottomY(pw) - 2) -
pw->progress.bar.y;
}
static void
#ifndef _NO_PROTO
_XmuttProgressBarMakeGCs(Widget w, Boolean force)
#else
_XmuttProgressBarMakeGCs(w, force)
Widget w;
Boolean force;
#endif
{
XmuttProgressBarWidget pw;
XmFontContext fctx;
XmFontListEntry fe;
XmFontType ft;
XFontStruct *fnt;
XtGCMask gcvm;
XGCValues gcv;
pw = (XmuttProgressBarWidget) w;
gcvm = GCForeground|GCBackground|GCFunction;
XmFontListInitFontContext(&fctx, pw->progress.font);
fe = XmFontListNextEntry(fctx);
fnt = (XFontStruct *) XmFontListEntryGetFont(fe, &ft);
XmFontListFreeFontContext(fctx);
gcv.font = fnt->fid;
gcv.foreground = pw->primitive.foreground;
gcv.background = pw->core.background_pixel;
gcv.function = GXcopy;
if (pw->progress.labelgc == 0 || force == True) {
if (pw->progress.labelgc != 0)
XFreeGC(XtDisplay(w), pw->progress.labelgc);
pw->progress.labelgc = XCreateGC(XtDisplay(w), XtWindow(w),
gcvm|GCFont, &gcv);
}
if (pw->progress.numgc == 0 || force == True) {
if (pw->progress.numgc != 0)
XFreeGC(XtDisplay(w), pw->progress.numgc);
pw->progress.numgc = XCreateGC(XtDisplay(w), XtWindow(w),
gcvm|GCFont, &gcv);
}
gcv.foreground = pw->primitive.foreground ^ pw->core.background_pixel;
gcv.background = 0;
gcv.function = GXxor;
if (pw->progress.bargc == 0 || force == True) {
if (pw->progress.bargc != 0)
XFreeGC(XtDisplay(w), pw->progress.bargc);
pw->progress.bargc = XCreateGC(XtDisplay(w), XtWindow(w),
gcvm, &gcv);
}
}
static void
#ifndef _NO_PROTO
_XmuttProgressBarRedraw(Widget w)
#else
_XmuttProgressBarRedraw(w)
Widget w;
#endif
{
XmuttProgressBarWidget pw;
unsigned long n;
Position x, y;
Dimension nswd, nsht;
XmString ns;
double a, b;
XRectangle bar;
XPoint br[3], tl[3];
char nbuf[8];
if (!XtIsRealized(w))
return;
pw = (XmuttProgressBarWidget) w;
/*
* Draw the label string if it exists.
*/
if (pw->progress.label != 0) {
x = _XmuttProgressBarLeftX(pw);
y = _XmuttProgressBarTopY(pw);
bar.x = x;
bar.y = y;
bar.width = pw->progress.label_width;
bar.height = pw->progress.label_height;
if (pw->progress.dir == XmuttProgressBarLeftToRight)
XmStringDrawImage(XtDisplay(w), XtWindow(w), pw->progress.font,
pw->progress.label, pw->progress.labelgc, x, y,
bar.width, XmALIGNMENT_BEGINNING,
XmSTRING_DIRECTION_L_TO_R, &bar);
else {
x = _XmuttProgressBarRightX(pw) - pw->progress.label_width;
bar.x = x;
XmStringDrawImage(XtDisplay(w), XtWindow(w), pw->progress.font,
pw->progress.label, pw->progress.labelgc, x, y,
bar.width, XmALIGNMENT_BEGINNING,
XmSTRING_DIRECTION_R_TO_L, &bar);
}
}
tl[0].x = pw->progress.bar.x - 2;
tl[0].y = pw->progress.bar.y + pw->progress.bar.height + 1;
tl[1].x = tl[0].x;
tl[1].y = pw->progress.bar.y - 2;
tl[2].x = _XmuttProgressBarRightX(pw) - 1;
tl[2].y = tl[1].y;
br[0].x = tl[2].x;
br[0].y = tl[2].y + 1;
br[1].x = br[0].x;
br[1].y = tl[0].y;
br[2].x = tl[0].x;
br[2].y = br[1].y;
XDrawLines(XtDisplay(w), XtWindow(w), pw->primitive.bottom_shadow_GC,
tl, 3, CoordModeOrigin);
XDrawLines(XtDisplay(w), XtWindow(w), pw->primitive.top_shadow_GC,
br, 3, CoordModeOrigin);
tl[0].x++;
tl[0].y--;
tl[1].x++;
tl[1].y++;
tl[2].x--;
tl[2].y++;
br[0].x--;
br[0].y++;
br[1].x--;
br[1].y--;
br[2].x++;
br[2].y--;
XDrawLines(XtDisplay(w), XtWindow(w), pw->primitive.bottom_shadow_GC,
tl, 3, CoordModeOrigin);
XDrawLines(XtDisplay(w), XtWindow(w), pw->primitive.top_shadow_GC,
br, 3, CoordModeOrigin);
/*
* Draw the bar with the current values.
*/
if (pw->progress.minval < pw->progress.maxval &&
pw->progress.currval != 0) {
bar.y = pw->progress.bar.y + 1;
bar.height = pw->progress.bar.height - 2;
/*
* Figure out what the width is supposed to be.
*/
if (pw->progress.currval == pw->progress.maxval)
bar.width = pw->progress.bar.width - 2;
else {
n = (unsigned long)
((((float) pw->progress.currval) /
((float) (pw->progress.maxval - pw->progress.minval))) *
100.0);
bar.width = (pw->progress.bar.width * n) / 100;
}
if (pw->progress.dir == XmuttProgressBarLeftToRight)
bar.x = pw->progress.bar.x + 1;
else
bar.x = _XmuttProgressBarRightX(pw) - 2 - bar.width - 1;
/*
* Draw the percentage text.
*/
a = (double) (pw->progress.currval - pw->progress.minval);
b = (double) (pw->progress.maxval - pw->progress.minval);
n = (unsigned long) ((a / b) * 100.0);
sprintf(nbuf, "%ld%%", n);
ns = XmStringCreateSimple(nbuf);
XmStringExtent(pw->progress.font, ns, &nswd, &nsht);
XmStringDrawImage(XtDisplay(w), XtWindow(w), pw->progress.font, ns,
pw->progress.numgc,
pw->progress.bar.x +
((pw->progress.bar.width >> 1) - (nswd >> 1)),
pw->progress.bar.y +
((pw->progress.bar.height >> 1) - (nsht >> 1)) + 1,
nswd, XmALIGNMENT_BEGINNING,
XmSTRING_DIRECTION_L_TO_R,
&pw->progress.bar);
XmStringFree(ns);
if (pw->progress.number_only == False)
/*
* And redraw draw the progress bar itself.
*/
XFillRectangle(XtDisplay(w), XtWindow(w), pw->progress.bargc,
bar.x, bar.y, bar.width, bar.height);
pw->progress.lastwidth = bar.width;
}
}
static void
#ifndef _NO_PROTO
_XmuttProgressBarUpdate(Widget w)
#else
_XmuttProgressBarUpdate(w)
Widget w;
#endif
{
XmuttProgressBarWidget pw;
unsigned long n;
Dimension nswd, nsht, nsx;
XmString ns;
double a, b;
char nbuf[8];
XRectangle bar;
if (!XtIsRealized(w))
return;
pw = (XmuttProgressBarWidget) w;
bar.y = pw->progress.bar.y + 1;
bar.height = pw->progress.bar.height - 2;
if (pw->progress.currval == pw->progress.maxval)
bar.width = pw->progress.bar.width - 2;
else {
n = (unsigned long)
((((float) pw->progress.currval) /
((float) (pw->progress.maxval - pw->progress.minval))) * 100.0);
bar.width = (pw->progress.bar.width * n) / 100;
}
if (pw->progress.dir == XmuttProgressBarLeftToRight)
bar.x = pw->progress.bar.x + 1;
else
bar.x = _XmuttProgressBarRightX(pw) - 2 - bar.width - 1;
a = (double) (pw->progress.currval - pw->progress.minval);
b = (double) (pw->progress.maxval - pw->progress.minval);
n = (unsigned long) ((a / b) * 100.0);
sprintf(nbuf, "%ld%%", n);
ns = XmStringCreateSimple(nbuf);
XmStringExtent(pw->progress.font, ns, &nswd, &nsht);
nsx = pw->progress.bar.x +
((pw->progress.bar.width >> 1) - (nswd >> 1));
/*
* Only update every indicated percent.
*/
if (n % pw->progress.percent == 0 && n != pw->progress.lastpercent) {
pw->progress.lastpercent = n;
/*
* Draw the percentage text.
*/
XmStringDrawImage(XtDisplay(w), XtWindow(w), pw->progress.font, ns,
pw->progress.numgc, nsx,
pw->progress.bar.y +
((pw->progress.bar.height >> 1) - (nsht >> 1)) + 1,
nswd, XmALIGNMENT_BEGINNING,
XmSTRING_DIRECTION_L_TO_R,
&pw->progress.bar);
if (pw->progress.number_only == False &&
bar.x + bar.width > nsx && bar.x + pw->progress.lastwidth >= nsx) {
if (bar.x + pw->progress.lastwidth >= nsx + nswd)
XFillRectangle(XtDisplay(w), XtWindow(w), pw->progress.bargc,
nsx, bar.y, nswd, bar.height);
else
XFillRectangle(XtDisplay(w), XtWindow(w), pw->progress.bargc,
nsx, bar.y,
((bar.x + pw->progress.lastwidth) - nsx),
bar.height);
}
}
/*
* Free up the number string.
*/
XmStringFree(ns);
/*
* Add check to see if new value is smaller or larger.
*/
if (pw->progress.number_only == False &&
bar.width != pw->progress.lastwidth)
XFillRectangle(XtDisplay(w), XtWindow(w), pw->progress.bargc,
bar.x + pw->progress.lastwidth, bar.y,
bar.width - pw->progress.lastwidth, bar.height);
pw->progress.lastwidth = bar.width;
}
/*************************************************************************
*
* Start class methods.
*
*************************************************************************/
static void
#ifndef _NO_PROTO
ClassInitialize(void)
#else
ClassInitialize()
#endif
{
}
static void
#ifndef _NO_PROTO
ClassPartInitialize (WidgetClass wc)
#else
ClassPartInitialize (wc)
WidgetClass wc;
#endif
{
}
static void
#ifndef _NO_PROTO
Initialize(Widget req, Widget newone, ArgList args, Cardinal *num_args)
#else
Initialize(req, newone, args, num_args)
Widget req, newone;
ArgList args;
Cardinal *num_args;
#endif
{
XmuttProgressBarWidget pw = (XmuttProgressBarWidget) newone;
Dimension wd, ht;
unsigned long tmp;
XFontStruct *fs;
XmFontContext fctx;
XmFontListEntry fe;
XmFontType ft;
if (pw->progress.font == 0) {
if ((fs = XLoadQueryFont(XtDisplay(newone), "fixed")) == 0) {
fprintf(stderr,
"XmuttProgressBar: unable to load the \"fixed\" font.\n");
exit(1);
}
pw->progress.font = XmFontListCreate(fs, XmSTRING_DEFAULT_CHARSET);
}
/*
* Initialize the GCs.
*/
pw->progress.labelgc = pw->progress.numgc = pw->progress.bargc = 0;
/*
* Get the first font to determine the max font bounds for the progress
* bar size.
*/
XmFontListInitFontContext(&fctx, pw->progress.font);
fe = XmFontListNextEntry(fctx);
fs = (XFontStruct *) XmFontListEntryGetFont(fe, &ft);
XmFontListFreeFontContext(fctx);
pw->progress.percheight = fs->max_bounds.ascent + fs->max_bounds.descent;
/*
* Determine the extents of the label string if supplied.
*/
if (pw->progress.label != 0) {
/*
* Copy the string.
*/
pw->progress.label = XmStringCopy(pw->progress.label);
XmStringExtent(pw->progress.font, pw->progress.label,
&pw->progress.label_width, &pw->progress.label_height);
} else
pw->progress.label_width = pw->progress.label_height = 0;
pw->progress.lastwidth = 0;
pw->progress.lastpercent = 0;
if (pw->progress.percent == 0 || pw->progress.percent > 100)
pw->progress.percent = 10;
if (pw->progress.minval > pw->progress.maxval) {
tmp = pw->progress.minval;
pw->progress.minval = pw->progress.maxval;
pw->progress.maxval = tmp;
}
_XmuttProgressBarPreferredGeometry(pw, &wd, &ht);
pw->core.width = wd;
pw->core.height = ht;
_XmuttProgressBarSetBarGeometry(pw);
}
static void
#ifndef _NO_PROTO
Resize(Widget w)
#else
Resize(w)
Widget w;
#endif
{
XmuttProgressBarWidget pw;
pw = (XmuttProgressBarWidget) w;
_XmuttProgressBarSetBarGeometry(pw);
}
static void
#ifndef _NO_PROTO
Realize(Widget w, Mask *valueMask, XSetWindowAttributes *attributes)
#else
Realize(w, valueMask, attributes)
Widget w;
Mask *valueMask;
XSetWindowAttributes *attributes;
#endif
{
XtCreateWindow(w, (unsigned int) InputOutput, (Visual *) CopyFromParent,
*valueMask, attributes);
_XmuttProgressBarMakeGCs(w, False);
}
static void
#ifndef _NO_PROTO
Destroy(Widget w)
#else
Destroy(w)
Widget w;
#endif
{
XmuttProgressBarWidget pw;
pw = (XmuttProgressBarWidget) w;
if (pw->progress.labelgc != 0)
XFreeGC(XtDisplay(w), pw->progress.labelgc);
if (pw->progress.numgc != 0)
XFreeGC(XtDisplay(w), pw->progress.numgc);
if (pw->progress.bargc != 0)
XFreeGC(XtDisplay(w), pw->progress.bargc);
pw->progress.labelgc = pw->progress.numgc = pw->progress.bargc = 0;
if (pw->progress.font != 0)
XmFontListFree(pw->progress.font);
pw->progress.font = 0;
if (pw->progress.label != 0)
XmStringFree(pw->progress.label);
pw->progress.label = 0;
}
static void
#ifndef _NO_PROTO
Redisplay(Widget w, XEvent *event, Region region)
#else
Redisplay(w, event, region)
Widget w;
XEvent *event;
Region region;
#endif
{
XmuttProgressBarWidget pw;
pw = (XmuttProgressBarWidget) w;
_XmuttProgressBarShadowWindow(pw);
_XmuttProgressBarRedraw(w);
}
static Boolean
#ifndef _NO_PROTO
SetValues(Widget curr, Widget req, Widget newone,
ArgList args, Cardinal *num_args)
#else
SetValues(curr, req, newone, args, num_args)
Widget curr, req, newone;
ArgList args;
Cardinal *num_args;
#endif
{
XmuttProgressBarWidget opw, npw;
Dimension wd, ht;
Boolean redo;
opw = (XmuttProgressBarWidget) curr;
npw = (XmuttProgressBarWidget) newone;
redo = False;
if (opw->progress.label != npw->progress.label) {
XmStringFree(opw->progress.label);
npw->progress.label = XmStringCopy(npw->progress.label);
XmStringExtent(npw->progress.font, npw->progress.label,
&npw->progress.label_width,
&npw->progress.label_height);
_XmuttProgressBarPreferredGeometry(npw, &wd, &ht);
if (wd != npw->core.width || ht != npw->core.height) {
npw->core.width = wd;
npw->core.height = ht;
_XmuttProgressBarSetBarGeometry(npw);
}
redo = True;
}
if (opw->progress.minval != npw->progress.minval ||
opw->progress.maxval != npw->progress.maxval)
redo = True;
if (redo == False && opw->progress.currval != npw->progress.currval) {
if (npw->progress.currval > npw->progress.maxval)
npw->progress.currval = npw->progress.maxval;
if (XtIsRealized(newone))
_XmuttProgressBarUpdate(newone);
}
return redo;
}
/*************************************************************************
*
* Start action procedures.
*
*************************************************************************/
static XtResource resources[] = {
{
XmNtraversalOn,
XmCTraversalOn,
XmRBoolean,
sizeof(Boolean),
XtOffset(XmPrimitiveWidget, primitive.traversal_on),
XmRImmediate,
(XtPointer) False,
},
{
XmNhighlightThickness,
XmCHighlightThickness,
XmRDimension,
sizeof(Dimension),
XtOffset(XmPrimitiveWidget, primitive.highlight_thickness),
XmRImmediate,
(XtPointer) 0,
},
{
XmNmarginWidth,
XmCMarginWidth,
XmRHorizontalDimension,
sizeof(Dimension),
XtOffset(XmuttProgressBarWidget, progress.mwidth),
XmRImmediate,
(XtPointer) 2,
},
{
XmNmarginHeight,
XmCMarginHeight,
XmRVerticalDimension,
sizeof(Dimension),
XtOffset(XmuttProgressBarWidget, progress.mheight),
XmRImmediate,
(XtPointer) 2,
},
{
XmNminValue,
XmCMinValue,
XmRInt,
sizeof(unsigned long),
XtOffset(XmuttProgressBarWidget, progress.minval),
XmRImmediate,
(XtPointer) 0,
},
{
XmNmaxValue,
XmCMaxValue,
XmRInt,
sizeof(unsigned long),
XtOffset(XmuttProgressBarWidget, progress.maxval),
XmRImmediate,
(XtPointer) 0,
},
{
XmNcurrentValue,
XmCCurrentValue,
XmRInt,
sizeof(unsigned long),
XtOffset(XmuttProgressBarWidget, progress.currval),
XmRImmediate,
(XtPointer) 0,
},
{
XmNreportEveryPercent,
XmCReportEveryPercent,
XmRInt,
sizeof(unsigned long),
XtOffset(XmuttProgressBarWidget, progress.percent),
XmRImmediate,
(XtPointer) 10,
},
{
XmNfontList,
XmCFontList,
XmRFontList,
sizeof(XmFontList),
XtOffset(XmuttProgressBarWidget, progress.font),
XmRImmediate,
(XtPointer) 0,
},
{
XmNlabelString,
XmCLabelString,
XmRString,
sizeof(XmString),
XtOffset(XmuttProgressBarWidget, progress.label),
XmRImmediate,
(XtPointer) 0,
},
{
XmNupdateDirection,
XmCUpdateDirection,
XmRInt,
sizeof(int),
XtOffset(XmuttProgressBarWidget, progress.dir),
XmRImmediate,
(XtPointer) XmuttProgressBarLeftToRight,
},
{
XmNpercentOnly,
XmCPercentOnly,
XmRBoolean,
sizeof(Boolean),
XtOffset(XmuttProgressBarWidget, progress.number_only),
XmRImmediate,
(XtPointer) False,
},
};
externaldef(xmuttprogbarclassrec) XmuttProgBarClassRec xmuttProgBarClassRec = {
{
(WidgetClass) &xmPrimitiveClassRec, /* superclass */
"XmuttProgressBar", /* class_name */
sizeof(XmuttProgBarRec), /* widget_size */
ClassInitialize, /* class_initialize */
ClassPartInitialize, /* chained class init */
FALSE, /* class_inited */
Initialize, /* initialize */
NULL, /* initialize hook */
Realize, /* realize */
NULL, /* actions */
0, /* num_actions */
resources, /* resources */
XtNumber(resources), /* num_resources */
NULLQUARK, /* xrm_class */
TRUE, /* compress_motion */
XtExposeCompressMaximal, /* compress_exposure */
TRUE, /* compress enter/exit */
FALSE, /* visible_interest */
Destroy, /* destroy */
Resize, /* resize */
Redisplay, /* expose */
(XtSetValuesFunc) SetValues, /* set_values */
NULL, /* set values hook */
XtInheritSetValuesAlmost, /* set values almost */
NULL, /* get values hook */
NULL, /* accept_focus */
XtVersion, /* version */
NULL, /* callback offsetlst */
NULL, /* default trans */
XtInheritQueryGeometry, /* query geo proc */
XtInheritDisplayAccelerator, /* display accelerator */
NULL, /* extension record reserved*/
},
{ /* XmPrimitive */
(XtWidgetProc) _XtInherit, /* border_highlight */
(XtWidgetProc) _XtInherit, /* border_unhighlight */
0, /* translations */
0, /* arm_and_activate */
0, /* syn resources */
0, /* num syn_resources */
0, /* extension */
},
{ /* XmuttProgressBar */
0, /* Extension record pointer.*/
}
};
externaldef(xmuttprogressbarwidgetclass)
WidgetClass xmuttProgressBarWidgetClass = (WidgetClass)
&xmuttProgBarClassRec;
|