2 #include <X11/StringDefs.h>
3 #include <X11/IntrinsicP.h>
4 #include <X11/CompositeP.h>
7 #include <Xol/OpenLook.h>
8 #include <Xol/MenuButton.h>
9 #include <Xol/OblongButt.h>
10 #include <Xol/ControlAre.h>
12 #include <Xol/StaticText.h>
14 \f/* forward declarations */
16 update_menu_widget (widget_instance
* instance
, Widget widget
,
19 \f/* Menu callbacks */
21 pre_hook (Widget w
, caddr_t client_data
, caddr_t call_data
)
23 OlVirtualEvent ve
= (OlVirtualEvent
)call_data
;
24 widget_instance
* instance
= (widget_instance
*)client_data
;
26 if (w
->core
.being_destroyed
)
29 if (XtParent (w
) == instance
->widget
)
31 if (ve
->xevent
->type
== ButtonPress
&& instance
->info
->pre_activate_cb
)
32 instance
->info
->pre_activate_cb (instance
->widget
, instance
->info
->id
,
38 post_hook (Widget w
, caddr_t client_data
, caddr_t call_data
)
40 widget_instance
* instance
= (widget_instance
*)client_data
;
42 if (w
->core
.being_destroyed
)
45 if (instance
->info
->post_activate_cb
)
46 instance
->info
->post_activate_cb (w
, instance
->info
->id
, NULL
);
50 pick_hook (Widget w
, caddr_t client_data
, caddr_t call_data
)
52 widget_instance
* instance
= 0;
53 widget_value
* val
= (widget_value
*)client_data
;
55 if (w
->core
.being_destroyed
)
58 XtVaGetValues (w
, XtNuserData
, &instance
, 0);
63 if (instance
->info
->selection_cb
&& val
&& val
->enabled
65 instance
->info
->selection_cb (w
, instance
->info
->id
, val
->call_data
);
68 \f/* creation functions */
70 xol_create_menubar (widget_instance
* instance
)
73 XtVaCreateWidget (instance
->info
->name
, controlAreaWidgetClass
,
79 xol_create_popup_menu (widget_instance
* instance
)
82 XtCreatePopupShell (instance
->info
->name
, menuShellWidgetClass
,
83 instance
->parent
, NULL
, 0);
88 xol_creation_table
[] =
90 {"menubar", xol_create_menubar
},
91 {"popup", xol_create_popup_menu
},
96 xol_create_dialog (widget_instance
* instance
)
102 lw_olit_widget_p (Widget widget
)
107 \f/* update functions */
109 destroy_all_children (Widget widget
)
115 children
= (Widget
*) XtCompositeChildren (widget
, &number
);
118 /* Unmanage all children and destroy them. They will only be
119 * really destroyed when we get out of DispatchEvent. */
120 for (i
= 0; i
< number
; i
++)
122 Widget child
= children
[i
];
123 if (!child
->core
.being_destroyed
)
125 XtUnmanageChild (child
);
126 XtDestroyWidget (child
);
134 all_dashes_p (char* s
)
144 make_menu_in_widget (widget_instance
* instance
, Widget widget
,
153 for (cur
= val
; cur
; cur
= cur
->next
)
156 XtSetArg (al
[ac
], XtNsensitive
, cur
->enabled
); ac
++;
157 XtSetArg (al
[ac
], XtNuserData
, instance
); ac
++;
158 XtSetArg (al
[ac
], XtNacceleratorText
, cur
->key
); ac
++;
160 /* label = (char *) resource_string (widget, cur->name);*/
164 XtSetArg (al
[ac
], XtNlabel
, label
); ac
++;
167 if (all_dashes_p (cur
->name
))
169 /* no separator in OpenLook just make some space. */
170 XtSetArg (al
[ac
], XtNheight
, 5); ac
++;
171 XtSetArg (al
[ac
], XtNwidth
, 5); ac
++;
172 button
= XtCreateWidget (cur
->name
, stubWidgetClass
, widget
, al
, ac
);
174 else if (!cur
->contents
)
178 XtCreateManagedWidget (cur
->name
, staticTextWidgetClass
, widget
,
183 XtCreateManagedWidget (cur
->name
, oblongButtonWidgetClass
,
185 XtAddCallback (button
, XtNselect
, pick_hook
, cur
);
192 XtCreateManagedWidget (cur
->name
, menuButtonWidgetClass
, widget
,
194 XtVaGetValues (button
, XtNmenuPane
, &menu
, 0);
197 make_menu_in_widget (instance
, menu
, cur
->contents
);
198 OlAddCallback (button
, XtNconsumeEvent
, pre_hook
, instance
);
204 update_one_menu_entry (widget_instance
* instance
, Widget widget
,
210 widget_value
* contents
;
212 if (val
->change
== NO_CHANGE
)
215 /* update the sensitivity */
216 XtVaSetValues (widget
, XtNsensitive
, val
->enabled
, 0);
218 /* update the pulldown/pullaside as needed */
221 XtVaGetValues (widget
, XtNmenuPane
, &menu
, 0);
222 contents
= val
->contents
;
228 /* in OLIT this woudl have to be a structural change on the
235 /* in OLIT this woudl have to be a structural change on the button. */
238 else if (contents
->change
!= NO_CHANGE
)
239 update_menu_widget (instance
, menu
, val
);
243 update_menu_widget (widget_instance
* instance
, Widget widget
,
247 if (val
->change
== STRUCTURAL_CHANGE
248 || val
->contents
->change
== STRUCTURAL_CHANGE
)
250 destroy_all_children (widget
);
251 make_menu_in_widget (instance
, widget
, val
->contents
);
255 /* Update all the buttons of the composite widget in order. */
257 unsigned int num_children
;
261 children
= (Widget
*) XtCompositeChildren (widget
, &num_children
);
264 for (i
= 0, cur
= val
->contents
; i
< num_children
; i
++)
268 if (children
[i
]->core
.being_destroyed
269 || strcmp (XtName (children
[i
]), cur
->name
))
271 update_one_menu_entry (instance
, children
[i
], cur
);
282 xol_update_one_widget (widget_instance
* instance
, Widget widget
,
283 widget_value
* val
, Boolean deep_p
)
285 Widget menu
= widget
;
287 if (XtIsShell (widget
))
288 XtVaGetValues (widget
, XtNmenuPane
, &menu
, 0);
290 update_menu_widget (instance
, menu
, val
);
294 xol_update_one_value (widget_instance
* instance
, Widget widget
,
301 xol_pop_instance (widget_instance
* instance
, Boolean up
)
306 xol_popup_menu (Widget widget
)
311 \f/* Destruction of instances */
313 xol_destroy_instance (widget_instance
* instance
)
315 XtDestroyWidget (instance
->widget
);