1 /* $XConsortium: ScalTics.c /main/7 1995/12/06 21:39:58 cde-sun $ */
2 /*
3 * Motif
4 *
5 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
6 *
7 * These libraries and programs are free software; you can
8 * redistribute them and/or modify them under the terms of the GNU
9 * Lesser General Public License as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * These libraries and programs are distributed in the hope that
14 * they will be useful, but WITHOUT ANY WARRANTY; without even the
15 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU Lesser General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with these librararies and programs; if not, write
21 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
22 * Floor, Boston, MA 02110-1301 USA
23 *
24 */
25 /*
26 * HISTORY
27 */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31
32
33
34 #include <Xm/Xm.h>
35 #include <Xm/XmosP.h> /* for allocate local */
36 #include <Xm/Scale.h>
37 #include <Xm/SeparatoG.h>
38 #include "XmI.h"
39
40 /************************************************************************
41 *
42 * XmScaleSetTicks
43 *
44 ************************************************************************/
45 void
XmScaleSetTicks(Widget scale,int big_every,Cardinal num_med,Cardinal num_small,Dimension size_big,Dimension size_med,Dimension size_small)46 XmScaleSetTicks(
47 Widget scale,
48 int big_every,
49 Cardinal num_med,
50 Cardinal num_small,
51 Dimension size_big,
52 Dimension size_med,
53 Dimension size_small)
54 {
55 Widget *sep ;
56 Cardinal n, i, j, k, sep_num;
57 int real_num_big, real_num_med, real_num_small;
58 Arg args[5];
59 int max, min ;
60 unsigned char orient ;
61 char * dim_res ;
62
63 _XmWidgetToAppContext(scale);
64
65 _XmAppLock(app);
66
67 /* Some checking first */
68 if (size_big == 0) { _XmAppUnlock(app); return ; }
69 if (size_med == 0) num_med = 0 ;
70 if (size_small == 0) num_small = 0 ;
71
72 /* big_every is the number of values between big tics, while
73 num_med and num_small are the number of tics between resp.
74 big and med values */
75
76 /* compute num_big first */
77 n = 0 ;
78 XtSetArg(args[n], XmNmaximum, &max); n++;
79 XtSetArg(args[n], XmNminimum, &min); n++;
80 XtSetArg(args[n], XmNorientation, &orient); n++;
81 XtGetValues(scale, args, n);
82
83 real_num_big = ((max - min) / big_every) + 1 ;
84 if (real_num_big < 2) { _XmAppUnlock(app); return ; }
85
86 real_num_med = (real_num_big - 1) * num_med;
87 real_num_small = (real_num_big + real_num_med - 1) * num_small;
88 sep_num = real_num_big + real_num_med + real_num_small;
89
90 sep = (Widget*) ALLOCATE_LOCAL(sep_num * sizeof(Widget));
91
92 if (orient == XmHORIZONTAL) {
93 dim_res = XmNheight;
94 orient = XmVERTICAL;
95 } else {
96 dim_res = XmNwidth ;
97 orient = XmHORIZONTAL;
98 }
99 XtSetArg(args[0], XmNmargin, 0);
100 XtSetArg(args[1], XmNorientation, orient);
101
102 sep_num = 0 ;
103 for (i=0; i < real_num_big; i++) {
104 n = 2 ;
105 XtSetArg(args[n], dim_res, size_big); n++ ;
106 sep[sep_num] = XmCreateSeparatorGadget(scale, "BigTic", args, n);
107 sep_num++;
108
109 if (i == real_num_big - 1) break ;
110
111 for (k=0; k < num_small; k++) {
112 n = 2 ;
113 XtSetArg(args[n], dim_res, size_small); n++;
114 XtSetArg(args[n], XmNseparatorType, XmSINGLE_LINE); n++;
115 sep[sep_num] = XmCreateSeparatorGadget(scale, "SmallTic",
116 args, n);
117 sep_num++;
118 }
119
120 for (j=0; j < num_med; j++) {
121 n = 2 ;
122 XtSetArg(args[n], dim_res, size_med); n++;
123 sep[sep_num] = XmCreateSeparatorGadget(scale, "MedTic", args, n);
124 sep_num++;
125 for (k=0; k < num_small; k++) {
126 n = 2 ;
127 XtSetArg(args[n], dim_res, size_small); n++;
128 XtSetArg(args[n], XmNseparatorType, XmSINGLE_LINE); n++;
129 sep[sep_num] = XmCreateSeparatorGadget(scale, "SmallTic",
130 args, n);
131 sep_num++;
132 }
133
134 }
135 }
136
137 XtManageChildren(sep, sep_num);
138 DEALLOCATE_LOCAL((char*)sep);
139
140 _XmAppUnlock(app);
141 }
142
143
144