1 /*
2  *  Copyright (C) 1995, 1996  Karl-Johan Johnsson.
3  */
4 
5 #include <X11/IntrinsicP.h>
6 #include <X11/StringDefs.h>
7 
8 #include "Compat.h"
9 #include "MenuGP.h"
10 
11 static XtResource resources[] = {
12 #define offset(field) XtOffsetOf(MenuGadgetRec, menu_g.field)
13     {XtNcallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
14      offset(callback), XtRImmediate, (XtPointer)NULL},
15     {XtNpostPopdownCallback, XtCCallback, XtRCallback, sizeof(XtCallbackList),
16      offset(post_popdown_callback), XtRImmediate, (XtPointer)NULL},
17     {XtNlabel, XtCLabel, XtRString, sizeof(String),
18      offset(label), XtRImmediate, (XtPointer)NULL},
19 #undef offset
20 };
21 
22 static void	ClassPartInitialize(WidgetClass);
23 static void	Initialize(Widget, Widget, ArgList, Cardinal*);
24 static void	Destroy(Widget);
25 static Boolean	SetValues(Widget, Widget, Widget, ArgList, Cardinal*);
26 static void	GenericProc(MenuGadget);
27 static int	Notify(MenuGadget);
28 static int	PostNotify(MenuGadget);
29 static void	SetActive(MenuGadget, int);
30 
31 MenuGadgetClassRec menuGadgetClassRec = {
32     { /* rectObj fields */
33         (WidgetClass) &rectObjClassRec, /* superclass                   */
34         "MenuGadget",                   /* class_name                   */
35         sizeof(MenuGadgetRec),	        /* widget_size                  */
36         NULL,                           /* class_initialize             */
37         ClassPartInitialize,            /* class_part_initialize        */
38         FALSE,                          /* class_inited                 */
39         Initialize,                     /* initialize                   */
40         NULL,                           /* initialize_hook              */
41         NULL,                           /* rect1                        */
42         NULL,                           /* rect2                        */
43         0,                              /* rect3                        */
44         resources,                      /* resources                    */
45         XtNumber(resources),            /* num_resources                */
46         NULLQUARK,                      /* xrm_class                    */
47         FALSE,                          /* rect4                        */
48         FALSE,                          /* rect5                        */
49         FALSE,                          /* rect6                        */
50         FALSE,                          /* rect7                        */
51         Destroy,    			/* destroy                      */
52         NULL,                           /* resize                       */
53         NULL,                           /* expose                       */
54         SetValues,			/* set_values                   */
55         NULL,                           /* set_values_hook              */
56         XtInheritSetValuesAlmost,       /* set_values_almost            */
57         NULL,                           /* get_values_hook              */
58         NULL,                           /* rect9                        */
59         XtVersion,                      /* version                      */
60         NULL,                           /* callback_private             */
61         NULL,                           /* rect10                       */
62         NULL,                           /* query_geometry               */
63         NULL,                           /* rect11                       */
64         NULL,                           /* extension                    */
65     },
66     { /* menu_g fields */
67         GenericProc,			/* change_hl			*/
68 	GenericProc,			/* popdown			*/
69 	Notify,				/* notify			*/
70 	PostNotify,			/* post_notify			*/
71 	SetActive,			/* set_active			*/
72 	False,				/* ignore_leave			*/
73 	NULL,				/* extension			*/
74     }
75 };
76 
77 WidgetClass menuGadgetClass = (WidgetClass)&menuGadgetClassRec;
78 
79 /*************************************************************************/
80 
ClassPartInitialize(WidgetClass gclass)81 static void ClassPartInitialize(WidgetClass gclass)
82 {
83     MenuGadgetClass	class, super;
84 
85     class = (MenuGadgetClass)gclass;
86     super = (MenuGadgetClass)class->rect_class.superclass;
87 
88     if (class->menu_g_class.change_hl    == XtInheritChangeHl)
89 	class->menu_g_class.change_hl    = super->menu_g_class.change_hl;
90     if (class->menu_g_class.popdown      == XtInheritPopdown)
91 	class->menu_g_class.popdown      = super->menu_g_class.popdown;
92     if (class->menu_g_class.notify       == XtInheritNotify)
93 	class->menu_g_class.notify       = super->menu_g_class.notify;
94     if (class->menu_g_class.post_notify  == XtInheritPostNotify)
95 	class->menu_g_class.post_notify  = super->menu_g_class.post_notify;
96     if (class->menu_g_class.set_active   == XtInheritSetActive)
97 	class->menu_g_class.set_active   = super->menu_g_class.set_active;
98 }
99 
Initialize(Widget grequest,Widget gnew,ArgList args,Cardinal * no_args)100 static void Initialize(Widget    grequest,
101 		       Widget    gnew,
102 		       ArgList   args,
103 		       Cardinal *no_args)
104 {
105     MenuGadget	new = (MenuGadget)gnew;
106 
107     new->menu_g.hl     = False;
108     new->menu_g.inside = False;
109     new->menu_g.active = False;
110     new->menu_g.label  = new->menu_g.label ?
111 	XtNewString(new->menu_g.label) : XtNewString(XtName((Widget)new));
112 }
113 
Destroy(Widget gw)114 static void Destroy(Widget gw)
115 {
116     MenuGadget	g = (MenuGadget)gw;
117 
118     XtFree(g->menu_g.label);
119 }
120 
SetValues(Widget gcurrent,Widget grequest,Widget gnew,ArgList args,Cardinal * num_args)121 static Boolean SetValues(Widget	   gcurrent,
122 			 Widget	   grequest,
123 			 Widget	   gnew,
124 			 ArgList   args,
125 			 Cardinal *num_args)
126 {
127     int		redisplay = False;
128     MenuGadget	new       = (MenuGadget)gnew;
129     MenuGadget	current   = (MenuGadget)gcurrent;
130 
131     if (new->menu_g.label != current->menu_g.label) {
132 	XtFree(current->menu_g.label);
133 	new->menu_g.label = new->menu_g.label ?
134 	    XtNewString(new->menu_g.label) : XtNewString(XtName((Widget)new));
135 	redisplay = True;
136     }
137 
138     return redisplay;
139 }
140 
GenericProc(MenuGadget g)141 static void GenericProc(MenuGadget g)
142 {
143 }
144 
Notify(MenuGadget g)145 static int Notify(MenuGadget g)
146 {
147     XtCallbackList	c_list = g->menu_g.callback;
148 
149     if (!g->menu_g.inside)
150 	return False;
151 
152     if (c_list)
153 	XtCallCallbackList((Widget)g, c_list, (XtPointer)g->menu_g.label);
154 
155     return True;
156 }
157 
PostNotify(MenuGadget g)158 static int PostNotify(MenuGadget g)
159 {
160     XtCallbackList	c_list = g->menu_g.post_popdown_callback;
161 
162     if (!g->menu_g.inside)
163 	return False;
164 
165     if (c_list)
166 	XtCallCallbackList((Widget)g, c_list, (XtPointer)g->menu_g.label);
167 
168     return True;
169 }
170 
SetActive(MenuGadget g,int active)171 static void SetActive(MenuGadget g, int active)
172 {
173     g->menu_g.active = active;
174 }
175