1 /*
2 **
3 ** Switch.c
4 **
5 ** Copyright (C) 1995, 1996, 1997 Johannes Plass
6 ** Copyright (C) 2004 Jose E. Marchesi
7 **
8 ** This program is free software; you can redistribute it and/or modify
9 ** it under the terms of the GNU General Public License as published by
10 ** the Free Software Foundation; either version 3 of the License, or
11 ** (at your option) any later version.
12 **
13 ** This program is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ** GNU General Public License for more details.
17 **
18 ** You should have received a copy of the GNU General Public License
19 ** along with GNU gv; see the file COPYING.  If not, write to
20 ** the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 ** Boston, MA 02111-1307, USA.
22 **
23 ** Author:   Johannes Plass (plass@thep.physik.uni-mainz.de)
24 **           Department of Physics
25 **           Johannes Gutenberg-University
26 **           Mainz, Germany
27 **
28 **           Jose E. Marchesi (jemarch@gnu.org)
29 **           GNU Project
30 **
31 */
32 
33 #include "ac_config.h"
34 
35 /*
36 #define MESSAGES
37 */
38 #include "message.h"
39 
40 #include <stdio.h>
41 #include "paths.h"
42 #include INC_X11(IntrinsicP.h)
43 #include INC_X11(StringDefs.h)
44 #include INC_XAW(XawInit.h)
45 #include "SwitchP.h"
46 
47 static void ClassInitialize(void);
48 
49 #define superclass ((ButtonWidgetClass)&buttonClassRec)
50 
51 static char defaultTranslations[] =
52 "Any<BtnDown>:highlight()\n\
53 Any<BtnUp>:toggle()";
54 
55 #define offset(field) XtOffsetOf(SwitchRec, field)
56 static XtResource resources[] = {
57   {XtNhighlightedFrameStyle, XtCHighlightedFrameStyle, XtRFrameType, sizeof(XawFrameType),
58    offset(button.highlighted_frame_style), XtRImmediate, (XtPointer) XawSUNKEN },
59   {XtNunsetFrameStyle, XtCUnsetFrameStyle, XtRFrameType, sizeof(XawFrameType),
60    offset(button.unset_frame_style), XtRImmediate, (XtPointer) XawCHISELED },
61   {XtNsetFrameStyle, XtCSetFrameStyle, XtRFrameType, sizeof(XawFrameType),
62    offset(button.set_frame_style), XtRImmediate, (XtPointer) XawSUNKEN },
63 };
64 #undef offset
65 
66 static XtActionsRec actionsList[] = {
67   {"toggle",	SwitchToggle},
68 };
69 
70 SwitchClassRec switchClassRec = {
71   {
72     (WidgetClass) superclass,		/* superclass		  */
73     "Switch",				/* class_name		  */
74     sizeof(SwitchRec),     	  	/* size			  */
75     ClassInitialize,			/* class_initialize	  */
76     NULL,				/* class_part_initialize  */
77     FALSE,				/* class_inited		  */
78     NULL,				/* initialize		  */
79     NULL,				/* initialize_hook	  */
80     XtInheritRealize,			/* realize		  */
81     actionsList,			/* actions		  */
82     XtNumber(actionsList),		/* num_actions		  */
83     resources,				/* resources		  */
84     XtNumber(resources),		/* resource_count	  */
85     NULLQUARK,				/* xrm_class		  */
86     FALSE,				/* compress_motion	  */
87     TRUE,				/* compress_exposure	  */
88     TRUE,				/* compress_enterleave    */
89     FALSE,				/* visible_interest	  */
90     NULL,				/* destroy		  */
91     XtInheritResize,			/* resize		  */
92     XtInheritExpose,			/* expose		  */
93     NULL,				/* set_values		  */
94     NULL,				/* set_values_hook	  */
95     XtInheritSetValuesAlmost,		/* set_values_almost	  */
96     NULL,				/* get_values_hook	  */
97     NULL,				/* accept_focus		  */
98     XtVersion,				/* version		  */
99     NULL,				/* callback_private	  */
100     defaultTranslations,               	/* tm_table		  */
101     XtInheritQueryGeometry,		/* query_geometry	  */
102     XtInheritDisplayAccelerator,	/* display_accelerator	  */
103     NULL				/* extension		  */
104   },  /* CoreClass fields initialization */
105   {
106     XtInheritChangeSensitive		/* change_sensitive	  */
107   },  /* SimpleClass fields initialization */
108   {
109     XtInheritXaw3dShadowDraw,           /* shadowdraw           */
110   },  /* ThreeDClass fields initialization */
111   {
112     0,                                     /* field not used    */
113   },  /* LabelClass fields initialization */
114   {
115     0,                                     /* field not used    */
116   },  /* CommandClass fields initialization */
117   {
118     0,                                     /* field not used    */
119   },  /* ButtonClass fields initialization */
120   {
121     0,                                     /* field not used    */
122   }  /* SwitchClass fields initialization */
123 };
124 
125 WidgetClass switchWidgetClass = (WidgetClass) &switchClassRec;
126 
127 
128 /*---------------------------------------------------*/
129 /* Private Procedures */
130 /*---------------------------------------------------*/
131 
ClassInitialize(void)132 static void ClassInitialize(void)
133 {
134   XawInitializeWidgetSet();
135 }
136 
137 /*###################################################*/
138 /* Public Procedures */
139 /*###################################################*/
140 
141 void
SwitchToggle(w,event,params,num_params)142 SwitchToggle(w,event,params,num_params)
143   Widget w;
144   XEvent *event;
145   String *params;
146   Cardinal *num_params;
147 {
148   SwitchWidget sw = (SwitchWidget)w;
149 
150   BEGINMESSAGE(SwitchToggle)
151   if (sw->command.set) {
152     sw->command.highlighted = 0;
153     ButtonReset(w,event,params,num_params);
154   }
155   else ButtonSet(w,event,params,num_params);
156   ENDMESSAGE(SwitchToggle)
157 }
158 
SwitchIsSet(w)159 int SwitchIsSet(w)
160   Widget w;
161 {
162   SwitchWidget sw = (SwitchWidget)w;
163 
164   BEGINMESSAGE(SwitchIsSet)
165   if (sw->command.set) return(1);
166   else return(0);
167   ENDMESSAGE(SwitchIsSet)
168 }
169