-
Notifications
You must be signed in to change notification settings - Fork 6
/
jlAxis.c
3086 lines (2655 loc) · 83.6 KB
/
jlAxis.c
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
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*************************************************************************\
* Copyright (c) 1994-2004 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 1997-2003 Southeastern Universities Research Association,
* as Operator of Thomas Jefferson National Accelerator Facility.
* Copyright (c) 1997-2002 Deutches Elektronen-Synchrotron in der Helmholtz-
* Gemelnschaft (DESY).
* This file is distributed subject to a Software License Agreement found
* in the file LICENSE that is included with this distribution.
\*************************************************************************/
#include <Xm/XmP.h>
#include "jlAxisP.h"
#include "rotated.h"
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <math.h>
#include <time.h>
#define offset(field) XtOffsetOf(AxisRec, field)
#define DEFAULT_MIN_MARGIN 50
#define DEFAULT_MINOR_SIDE DEFAUILT_MIN_MARGIN
#define DEFAULT_MAJOR_SIDE 150
#define MIN_SIDE 3
#define BUF_SIZE 256
static double DEFAULT_MINVAL = 0.0;
static double DEFAULT_MAXVAL = 100.0;
static double DEFAULT_LOGEPSILON = 0;
static char PLUS_MINUS = (char)254;
enum TicDivisorNames
{
One = 0, Two, Five, Ten, NumTicDivisors
};
static double TicDivisorValues[] = {1, 2, 5, 10};
enum TimeUnitNames
{
Seconds = 0, Minutes, Hours, Days, Weeks, Months, Years, NumTimeUnits
};
static char *TimeUnitNameStrings[] =
{
"Seconds", "Minutes", "Hours", "Days", "Weeks", "Months", "Years"
};
static double TimeUnitValues[] =
{
1, /* seconds */
60, /* minutes */
60*60, /* hours */
24*60*60, /* days */
7*24*60*60, /* weeks */
30*24*60*60, /* months */
365*24*60*60 /* years */
};
/* MaxTimeUnits
*
* The maximum number of intervals for a particular time unit before adjusting
* scale to the next.
*/
static int MaxTimeIntervals[] =
{
180, /* 3 minutes */
180, /* 3 hours */
72, /* 3 days */
21, /* 3 weeks */
12, /* ~3 months */
36, /* 3 years */
100 /* a century */
};
/* TimeFormats
*
* Format strings for strftime for corresponding level of detail
*/
static const char * TimeFormats[] =
{
"%H:%M:%S\n%b %d, %Y", /* seconds */
"%H:%M\n%b %d, %Y", /* minutes */
"%H\n%b %d, %Y", /* hours */
"%a\n%b %d, %Y", /* days */
"%a\n%b %d, %Y", /* weeks */
"%b %Y", /* months */
"%Y" /* years */
};
/* resources
*/
static XtResource resources[] =
{
/* font */
{
XmNfont,
XmCFont,
XmRFontStruct,
sizeof (XFontStruct),
offset (axis.font),
XmRString,
(XtPointer)XtDefaultFont
},
/* units string */
{
XjNunitString,
XjCUnitString,
XmRString,
sizeof (String),
offset (axis.unit_string),
XmRImmediate,
(XtPointer)0
},
/* direction */
{
XjNdirection,
XjCDirection,
XjRAxisDirection,
sizeof (AxisDirection),
offset (axis.direction),
XmRImmediate,
(XtPointer)XjAXIS_LEFT
},
/* value type */
{
XjNvalueType,
XjCValueType,
XjRAxisValueType,
sizeof (AxisValueType),
offset (axis.value_type),
XmRImmediate,
(XtPointer)XjAXIS_REAL
},
/* transform */
{
XjNtransform,
XjCTransform,
XjRAxisTransform,
sizeof (AxisTransform),
offset (axis.transform),
XmRImmediate,
(XtPointer)XjAXIS_LINEAR
},
/* log epsilon */
{
XjNlogEpsilon,
XjCLogEpsilon,
XjRDouble,
sizeof (double),
offset (axis.log_epsilon),
XjRDouble,
(XtPointer)&DEFAULT_LOGEPSILON
},
/* min_val */
{
XjNminVal,
XjCMinVal,
XjRDouble,
sizeof (double),
offset (axis.min_val),
XjRDouble,
(XtPointer)&DEFAULT_MINVAL
},
/* max_val */
{
XjNmaxVal,
XjCMaxVal,
XjRDouble,
sizeof (double),
offset (axis.max_val),
XjRDouble,
(XtPointer)&DEFAULT_MAXVAL
},
/* min_pos */
{
XjNminPos,
XjCMinPos,
XjRAxisEndpointPosition,
sizeof (AxisEndpointPosition),
offset (axis.min_pos),
XmRImmediate,
(XtPointer)XjAXIS_ORIGIN
},
/* max_pos */
{
XjNmaxPos,
XjCMaxPos,
XjRAxisEndpointPosition,
sizeof (AxisEndpointPosition),
offset (axis.max_pos),
XmRImmediate,
(XtPointer)XjAXIS_TERMINUS
},
/* min_margin */
{
XjNminMargin,
XjCMinMargin,
XmRDimension,
sizeof (Dimension),
offset (axis.min_margin),
XmRImmediate,
(XtPointer)DEFAULT_MIN_MARGIN
},
/* use_pixmap */
{
XjNusePixmap,
XjCUsePixmap,
XmRBoolean,
sizeof (Boolean),
offset (axis.use_pixmap),
XmRImmediate,
(XtPointer)False
},
/* text color */
{
XjNtextColor,
XjCTextColor,
XmRPixel,
sizeof (Pixel),
offset (axis.text_color),
XmRImmediate,
(XtPointer)XtDefaultForeground
},
/* ptr min_val */
{
XjNpMinVal,
XjCPMinVal,
XtRPointer,
sizeof (double *),
offset (axis.pmin_val),
XmRImmediate,
(double *)0
},
/* ptr max_val */
{
XjNpMaxVal,
XjCPMaxVal,
XtRPointer,
sizeof (double *),
offset (axis.pmax_val),
XmRImmediate,
(double *)0
},
/* ptr log epsilon */
{
XjNpLogEpsilon,
XjCPLogEpsilon,
XtRPointer,
sizeof (double *),
offset (axis.plog_epsilon),
XmRImmediate,
(double *)0
}
};
/* static variables
*/
static Boolean quarks_initialized = False;
static XrmQuark QAxisUp, QAxisDown, QAxisLeft, QAxisRight;
static XrmQuark QAxisOrigin, QAxisTerminus;
static XrmQuark QAxisLinear, QAxisLog10;
static XrmQuark QAxisReal, QAxisAbsTime;
static XrmQuark QAxisRelTimeDates, QAxisRelTimeNumbers;
static char buf[BUF_SIZE+1];
/* method prototypes
*/
static void ClassInitialize (void);
static void Initialize (Widget, /* request */
Widget, /* new */
ArgList, /* args */
Cardinal *); /* num_args */
static void Redisplay (Widget,
XEvent *, /* event */
Region); /* region */
static void Destroy (Widget);
static void Resize (Widget);
static Boolean SetValues (Widget, /* old */
Widget, /* request */
Widget, /* new */
ArgList, /* args */
Cardinal *); /* num_args */
static XtGeometryResult QueryGeometry (Widget,
XtWidgetGeometry *, /* request */
XtWidgetGeometry *); /* reply */
/* action function prototypes
*/
static void Arm (Widget,
XEvent *,
String *, /* params */
Cardinal *); /* num_params */
/* private function prototypes
*/
static Boolean ValidateValues (AxisWidget);
static Boolean ValidatePositions (AxisWidget);
static Boolean ValidateTransform (AxisWidget);
static int FindGoodMargin (AxisWidget);
static void GetDrawGC (AxisWidget);
static void FreeDrawGC (AxisWidget);
static void GetTextGC (AxisWidget);
static void FreeTextGC (AxisWidget);
static void GetEraseGC (AxisWidget);
static void FreeEraseGC (AxisWidget);
static void GetPixmap (AxisWidget);
static void FreePixmap (AxisWidget);
static void Draw (AxisWidget, Drawable);
/* these all return true if they precipitate a need to redisplay */
static int ComputeTics (AxisWidget);
static int ComputeTimeTics (AxisWidget);
static int ComputeNormalTics (AxisWidget);
static int ComputeLogTics (AxisWidget);
/* helper functions
*/
static void find_good_linear_tics (AxisWidget, /* for XtAppErrorMsg */
Boolean, /* nice intervals? */
double, /* min val */
double, /* max val */
double *, /* tic magnitude */
double *, /* minor divisor */
double *); /* major divisor */
static void find_good_log_tics (AxisWidget, /* for XtAppErrorMsg */
double *, /* tic magnitude */
int *, /* num minor */
int *, /* num major */
double *, /* minor divisor */
double *); /* major divisor */
static void compute_log_info (AxisWidget);
static int get_log_index_value (AxisWidget,
int, /* index */
int *, /* power */
int *); /* sign */
static int get_log_info (double, /* min_val */
double, /* max_val */
double, /* log_epsilon */
short *, /* log_epsilon_index */
short *, /* log_n_powers */
double *, /* log_delta */
double *); /* log_epsilon_offset*/
static void transform_values_normalized (AxisTransform,
AxisValueType,
AxisEndpointPosition,
AxisEndpointPosition,
register double,
register double,
register double,
register double,
register double,
register double *,
register double *,
register int);
static void untransform_normalized_values (AxisTransform,
AxisValueType,
AxisEndpointPosition,
AxisEndpointPosition,
register double,
register double,
register double,
register double,
register double,
register double *,
register double *,
register int);
/* converter prototypes
*/
static Boolean CvtStringToAxisDirection (Display *,
XrmValue *, /* args */
Cardinal *, /* n args */
XrmValue *, /* from */
XrmValue *, /* to */
XtPointer *); /* data */
static Boolean CvtStringToAxisValueType (Display *,
XrmValue *, /* args */
Cardinal *, /* n args */
XrmValue *, /* from */
XrmValue *, /* to */
XtPointer *); /* data */
static Boolean CvtStringToAxisTransform (Display *,
XrmValue *, /* args */
Cardinal *, /* n args */
XrmValue *, /* from */
XrmValue *, /* to */
XtPointer *); /* data */
static Boolean CvtStringToAxisEndpointPosition(Display *,
XrmValue *, /* args */
Cardinal *, /* n args */
XrmValue *, /* from */
XrmValue *, /* to */
XtPointer *); /* data */
static Boolean CvtStringToDouble (Display *,
XrmValue *, /* args */
Cardinal *, /* n args */
XrmValue *, /* from */
XrmValue *, /* to */
XtPointer *); /* data */
/* default translations
*/
static char defaultTranslations[] =
"<Btn1Down>: Arm(1) \n"
"<Btn2Down>: Arm(2) \n"
"<Btn3Down>: Arm(3) \n";
/* actions
*/
static XtActionsRec actions[] =
{
{"Arm", Arm}
};
/* class record
*/
AxisClassRec axisClassRec = {
/* core_class fields */
{
/* superclass */ (WidgetClass) &xmPrimitiveClassRec,
/* class_name */ "Axis",
/* widget_size */ sizeof (AxisRec),
/* class_initialize */ ClassInitialize,
/* class_part_initialize */ NULL,
/* class_inited */ FALSE,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ XtInheritRealize,
/* actions */ actions,
/* num_actions */ XtNumber (actions),
/* resources */ resources,
/* num_resources */ XtNumber (resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ TRUE,
/* compress_exposure */ XtExposeCompressMultiple,
/* compress_enterleave */ FALSE,
/* visible_interest */ FALSE,
/* destroy */ Destroy,
/* resize */ Resize,
/* expose */ Redisplay,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ NULL,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ defaultTranslations,
/* query_geometry */ QueryGeometry,
/* display_accelerator */ XtInheritDisplayAccelerator,
/* extension */ NULL
},
/* Primitive class fields */
{
/* border_highlight */ XmInheritWidgetProc,
/* border_unhighlight */ XmInheritWidgetProc,
/* translations */ XmInheritTranslations,
/* arm_and_activate */ NULL,
/* syn resources */ NULL,
/* num_syn_resources */ 0,
/* extension */ NULL,
},
/* Axis */
{
/* placeholder */ 0,
},
};
WidgetClass axisWidgetClass = (WidgetClass) &axisClassRec;
/* ========================================================================
*
* >>>>>>>>>> U S E F U L M A C R O S <<<<<<<<<<
*
* ========================================================================
*/
/* ABS
*
* Returns absolute value of number.
*/
#if !defined (ABS)
# define ABS(X) ((X) < 0? (-(X)) : (X))
#endif
/* MAX
*
*/
#if !defined (MAX)
# define MAX(a,b) ((a) > (b)? (a) : (b))
#endif
/* ROUND
*
* Returns the integer nearest the given (small) number.
*/
#define ROUND(X) ((X) < 0? (int)((X)-0.5) : (int)((X)+0.5))
/* LENGTH
*
* Returns the length of the widget's side parallel to the axis line.
*/
#define LENGTH(w) \
((((w)->axis.direction == XjAXIS_UP) || ((w)->axis.direction == XjAXIS_DOWN))?\
(w)->core.width : (w)->core.height)
/* ORIENTATION
*
* Returns XmHORIZONTAL for UP/DOWN widgets, else XmVERTICAL
*/
#define ORIENTATION(w) \
((((w)->axis.direction == XjAXIS_UP) || ((w)->axis.direction == XjAXIS_DOWN))?\
XmHORIZONTAL : XmVERTICAL)
/* MINPOS
*
* Returns the offset of the axis endpoint corresponding to
* the min value.
*/
#define MINPOS(w) \
(((w)->axis.min_pos == XjAXIS_ORIGIN)? 0 : (w)->axis.min_pos)
/* MAXPOS
*
* Returns the offset of the axis endpoint corresponding to
* the max value.
*/
#define MAXPOS(w) \
(((w)->axis.max_pos == XjAXIS_TERMINUS)? (LENGTH((w))-1) : (w)->axis.max_pos)
/* ========================================================================
*
* >>>>>>>>>> W I D G E T M E T H O D S <<<<<<<<<<
*
* ========================================================================
*/
/* ClassInitialize
*/
static void
ClassInitialize (void)
{
if (!quarks_initialized)
{
/* let's make some quarks! */
QAxisUp = XrmStringToQuark ("XjAXIS_UP");
QAxisDown = XrmStringToQuark ("XjAXIS_DOWN");
QAxisLeft = XrmStringToQuark ("XjAXIS_LEFT");
QAxisRight = XrmStringToQuark ("XjAXIS_RIGHT");
QAxisOrigin = XrmStringToQuark ("XjAXIS_ORIGIN");
QAxisTerminus = XrmStringToQuark ("XjAXIS_TERMINUS");
QAxisReal = XrmStringToQuark ("XjAXIS_REAL");
QAxisAbsTime = XrmStringToQuark ("XjAXIS_ABSTIME");
QAxisRelTimeDates = XrmStringToQuark ("XjAXIS_RELTIME_DATES");
QAxisRelTimeNumbers = XrmStringToQuark ("XjAXIS_RELTIME_NUMBERS");
QAxisLinear = XrmStringToQuark ("XjAXIS_LINEAR");
QAxisLog10 = XrmStringToQuark ("XjAXIS_LOG10");
quarks_initialized = True;
}
/* register type converters */
XtSetTypeConverter
(XmRString, XjRAxisDirection, CvtStringToAxisDirection,
(XtConvertArgList)0, 0, XtCacheNone, 0);
XtSetTypeConverter
(XmRString, XjRAxisValueType, CvtStringToAxisValueType,
(XtConvertArgList)0, 0, XtCacheNone, 0);
XtSetTypeConverter
(XmRString, XjRAxisTransform, CvtStringToAxisTransform,
(XtConvertArgList)0, 0, XtCacheNone, 0);
XtSetTypeConverter
(XmRString, XjRAxisEndpointPosition, CvtStringToAxisEndpointPosition,
(XtConvertArgList)0, 0, XtCacheNone, 0);
XtSetTypeConverter
(XmRString, XjRDouble, CvtStringToDouble,
(XtConvertArgList)0, 0, XtCacheNone, 0);
}
/* Initialize
*/
static void
Initialize (Widget treq,
Widget tnew,
ArgList args,
Cardinal *num_args)
{
AxisWidget nw = (AxisWidget) tnew;
/* verify that min_val is less than max_val */
ValidateValues (nw);
/* Motif Primitive sets width and height to provide enough room for
* the highlight and shadow around a widget. A widget that uses these
* features would *add* its desired dimensions to those set by Primitive.
*/
if (ORIENTATION(nw) == XmHORIZONTAL)
{
nw->core.width = DEFAULT_MAJOR_SIDE;
nw->core.height = MAX (nw->axis.min_margin, FindGoodMargin (nw));
}
else
{
nw->core.width = MAX (nw->axis.min_margin, FindGoodMargin (nw));
nw->core.height = DEFAULT_MAJOR_SIDE;
}
/* don't want any border */
nw->core.border_width = 0;
/* verify that min and max positions are ok */
ValidatePositions (nw);
/* tell Primitive not to allow tabbing to this widget,
* set shadow thickness to 0, etc. */
XtVaSetValues
((Widget)nw,
XmNtraversalOn, False,
XmNshadowThickness, (Dimension)0,
XmNhighlightThickness, (Dimension)0,
NULL);
nw->axis.pixmap = 0;
nw->axis.need_refresh = True;
GetDrawGC (nw);
GetEraseGC (nw);
GetTextGC (nw);
ComputeTics (nw);
}
/* Redisplay
*
* If the event is null, then the function was called
* by the widget itself.
*/
static void
Redisplay (Widget w, XEvent *event, Region region)
{
AxisWidget cw = (AxisWidget)w;
XExposeEvent *expose = 0;
if (!XtIsRealized ((Widget)cw)) return;
if (!cw->axis.pixmap && cw->axis.use_pixmap) GetPixmap (cw);
/* determine event type */
if (event) if (event->type == Expose) expose = (XExposeEvent *)event;
/* if no pixmap, draw directly into window */
if (!cw->axis.pixmap)
{
/* If this wasn't an expose event, then the window hasn't
* been cleared for us */
if (!expose) XClearWindow (XtDisplay (cw), XtWindow (cw));
Draw (cw, XtWindow (cw));
cw->axis.need_refresh = False;
}
/* use pixmap */
else
{
/* if the pixmap needs to be updated, do that */
if (cw->axis.need_refresh) Draw (cw, cw->axis.pixmap);
cw->axis.need_refresh = False;
/* if called internally, redraw the whole area */
if (!expose)
XCopyArea
(XtDisplay (cw), cw->axis.pixmap, XtWindow (cw), cw->axis.draw_gc,
0, 0, cw->core.width, cw->core.height, 0, 0);
/* otherwise, copy the bounding box for the exposed region
* from the pixmap */
else
XCopyArea
(XtDisplay (cw), cw->axis.pixmap, XtWindow (cw), cw->axis.draw_gc,
expose->x, expose->y, expose->width, expose->height,
expose->x, expose->y);
}
}
static Boolean
SetValues (Widget cur_w,
Widget req_w,
Widget new_w,
ArgList args,
Cardinal *num_args)
{
AxisWidget cur = (AxisWidget) cur_w;
AxisWidget nw = (AxisWidget) new_w;
Boolean do_redisplay = False;
Boolean do_recompute = False;
ArgList arg;
Cardinal nargs=*num_args;
for (arg=args; nargs!=0; nargs--,arg++) {
if (strcmp(arg->name,XjNpMinVal)==0 && arg->value)
nw->axis.min_val=*(double *)arg->value;
if (strcmp(arg->name,XjNpMaxVal)==0 && arg->value)
nw->axis.max_val=*(double *)arg->value;
if (strcmp(arg->name,XjNpLogEpsilon)==0 && arg->value)
nw->axis.log_epsilon=*(double *)arg->value;
}
/* new text gc? */
if ((cur->axis.text_color != nw->axis.text_color) ||
(cur->axis.font != nw->axis.font))
{
FreeTextGC (nw);
GetTextGC (nw);
nw->axis.need_refresh = True;
}
/* new draw gc? */
if ((cur->primitive.foreground != nw->primitive.foreground) ||
(cur->core.background_pixel != nw->core.background_pixel))
{
FreeDrawGC (nw);
GetDrawGC (nw);
nw->axis.need_refresh = True;
}
/* need new erase gc? */
if (cur->core.background_pixel != nw->core.background_pixel)
{
FreeEraseGC (nw);
GetEraseGC (nw);
nw->axis.need_refresh = True;
}
/* if the units have changed, we need to update the pixmap
* and update the window contents */
if (cur->axis.unit_string && nw->axis.unit_string)
if (strcmp (cur->axis.unit_string, nw->axis.unit_string) != 0)
nw->axis.need_refresh = True;
if ((cur->axis.unit_string && !nw->axis.unit_string) ||
(!cur->axis.unit_string && nw->axis.unit_string))
nw->axis.need_refresh = True;
/* start or stop using a pixmap? */
if (cur->axis.use_pixmap != nw->axis.use_pixmap)
{
if (!nw->axis.use_pixmap && cur->axis.pixmap)
FreePixmap (nw);
nw->axis.pixmap = 0;
nw->axis.need_refresh = True;
}
/* if the orientation has changed, then we need to update
* the pixmap. */
if (cur->axis.direction != nw->axis.direction)
nw->axis.need_refresh = True;
/* if the min margin has grown bigger than the current
* margin, then we need to resize */
if (cur->axis.min_margin != nw->axis.min_margin)
{
if (ORIENTATION (nw) == XmHORIZONTAL)
nw->core.height = MAX (nw->axis.min_margin, nw->core.height);
else
nw->core.width = MAX (nw->axis.min_margin, nw->core.width);
}
/* if the dimensions have changed, then we need to get a new
* pixmap and redraw */
if ((cur->core.width != nw->core.width) ||
(cur->core.height != nw->core.height))
{
if (nw->axis.pixmap) FreePixmap (nw);
nw->axis.need_refresh = True;
}
/* transform function */
ValidateTransform (nw);
if (cur->axis.transform != nw->axis.transform)
{
do_recompute = True;
nw->axis.need_refresh = True;
}
/* positions */
ValidatePositions (nw);
if ((cur->axis.min_pos != nw->axis.min_pos) ||
(cur->axis.max_pos != nw->axis.max_pos))
{
do_recompute = True;
nw->axis.need_refresh = True;
do_redisplay = True;
}
/* axis range */
ValidateValues (nw);
if ((ABS(cur->axis.min_val - nw->axis.min_val) > DBL_EPSILON) ||
(ABS(cur->axis.max_val - nw->axis.max_val) > DBL_EPSILON) ||
cur->axis.log_epsilon != nw->axis.log_epsilon)
{
do_recompute = True;
nw->axis.need_refresh = True;
}
/* recompute if necessary */
if (do_recompute) ComputeTics (nw);
/* if we return True, then the X Toolkit will clear the widget
* and invoke Redisplay. We only want this to happen if we
* aren't using a pixmap and the widget needs to be refreshed. */
do_redisplay |= (nw->axis.need_refresh && !nw->axis.use_pixmap);
if (nw->axis.need_refresh && !do_redisplay)
Redisplay ((Widget)nw, 0, 0);
return do_redisplay;
}
static void
Destroy (Widget w)
{
AxisWidget cw = (AxisWidget)w;
FreeDrawGC (cw);
FreeTextGC (cw);
FreeEraseGC (cw);
FreePixmap (cw);
}
static void
Resize (Widget w)
{
AxisWidget cw = (AxisWidget)w;
if (cw->axis.pixmap) FreePixmap (cw);
ComputeTics (cw);
cw->axis.need_refresh = 1;
}
static XtGeometryResult
QueryGeometry (Widget w,
XtWidgetGeometry *proposed,
XtWidgetGeometry *answer)
{
AxisWidget cw = (AxisWidget)w;
XtGeometryResult response;
answer->request_mode = CWWidth | CWHeight;
/* ====== Horizontal ====== */
if (ORIENTATION (cw) == XmHORIZONTAL)
{
/* for horizontal widgets, we don't care about width,
* so accept the proposal if such exists, otherwise
* suggest the current width */
if (proposed->request_mode & CWWidth)
answer->width = proposed->width;
else answer->width = cw->core.width;
if (proposed->request_mode & CWHeight)
{
if (proposed->height <= cw->axis.min_margin)
answer->height = cw->axis.min_margin;
}
else answer->height = MAX (cw->core.height, cw->axis.min_margin);
}
/* ====== Vertical ====== */
else
{
/* for vertical widgets, we don't care about height,
* so accept the proposal if such exists, otherwise
* suggest the current height */
if (proposed->request_mode & CWHeight)
answer->height = proposed->height;
else answer->height = cw->core.height;
if (proposed->request_mode & CWWidth)
{
if (proposed->width <= cw->axis.min_margin)
answer->width = cw->axis.min_margin;
}
else answer->width = MAX (cw->core.width, cw->axis.min_margin);
}
if ((proposed->request_mode & CWWidth) &&
(proposed->request_mode & CWHeight) &&
(proposed->width = answer->width) &&
(proposed->height = answer->height))
response = XtGeometryYes;
else if ((answer->width == cw->core.width) &&
(answer->height == cw->core.height))
response = XtGeometryNo;
else
response = XtGeometryAlmost;
return response;
}
/* ========================================================================
*
* >>>>>>>>>> P R I V A T E F U N C T I O N S <<<<<<<<<<
*
* ========================================================================
*/
/* FindGoodMargin
*/
static int
FindGoodMargin (AxisWidget cw)
{
int m;
/* for time being, just use max ascent and descent and width. Later,
* perhaps determine dimensions depending upon which characters might
* actually appear */
if (ORIENTATION(cw) == XmVERTICAL)
{
/* max digits in number, sign, radix character */
m = AXIS_MAX_DIGITS;
}
return m = 0;
}
/* GetDrawGC
*/
static void
GetDrawGC (AxisWidget cw)
{
XtGCMask mask;
XGCValues values;
mask = GCForeground | GCBackground;
values.foreground = cw->primitive.foreground;
values.background = cw->core.background_pixel;
cw->axis.draw_gc = XtGetGC ((Widget)cw, mask, &values);
}
/* FreeDrawGC
*/
static void
FreeDrawGC (AxisWidget cw)
{
XtReleaseGC ((Widget)cw, cw->axis.draw_gc);
}