1
/* $Xorg: Dialog.c,v 1.4 2001/02/09 02:05:28 xorgcvs Exp $ */
4
Copyright 1989, 1998 The Open Group
6
Permission to use, copy, modify, distribute, and sell this software and its
7
documentation for any purpose is hereby granted without fee, provided that
8
the above copyright notice appear in all copies and that both that
9
copyright notice and this permission notice appear in supporting
12
The above copyright notice and this permission notice shall be included
13
in all copies or substantial portions of the Software.
15
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
19
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall
24
not be used in advertising or otherwise to promote the sale, use or
25
other dealings in this Software without prior written authorization
29
/* $XFree86: xc/programs/bitmap/Dialog.c,v 1.3 2001/01/17 23:44:51 dawes Exp $ */
32
* Author: Davor Matic, MIT X Consortium
35
#include <X11/Intrinsic.h>
36
#include <X11/StringDefs.h>
37
#include <X11/Shell.h>
38
#include <X11/Xaw/Dialog.h>
39
#include <X11/Xaw/Command.h>
40
#include <X11/Xmu/CharSet.h>
44
#define min(x, y) (((x) < (y)) ? (x) : (y))
45
#define max(x, y) (((x) > (y)) ? (x) : (y))
48
static void SetDialogButton(Widget w, XEvent *event,
49
String *argv, Cardinal *argc);
51
static XtActionsRec actions_table[] = {
52
{"set-dialog-button", SetDialogButton},
55
static DialogButton dialog_buttons[] = {
65
static unsigned long selected;
69
SetSelected(Widget w, XtPointer clientData, XtPointer callData) /* ARGSUSED */
71
String name = (String)clientData;
74
for (i = 0; i < XtNumber(dialog_buttons); i++)
75
if (!strcmp(dialog_buttons[i].name, name))
76
selected |= dialog_buttons[i].flag;
81
SetDialogButton(Widget w, /* not used */
82
XEvent *event, /* not used */
87
XtPointer dummy = NULL;
90
for (i = 0; i < *argc; i++) {
91
XmuCopyISOLatin1Lowered (button_name, argv[i]);
92
SetSelected(w, button_name, dummy);
96
static Boolean firstTime = True;
99
CreateDialog(Widget top_widget, String name, unsigned long options)
104
popup = (Dialog) XtMalloc(sizeof(_Dialog));
108
XtAddActions(actions_table, XtNumber(actions_table));
111
popup->top_widget = top_widget;
112
popup->shell_widget = XtCreatePopupShell(name,
113
transientShellWidgetClass,
114
top_widget, NULL, 0);
115
popup->dialog_widget = XtCreateManagedWidget("dialog",
119
for (i = 0; i < XtNumber(dialog_buttons); i++)
120
if (options & dialog_buttons[i].flag)
121
XawDialogAddButton(popup->dialog_widget,
122
dialog_buttons[i].name,
123
SetSelected, dialog_buttons[i].name);
124
popup->options = options;
132
PopdownDialog(Dialog popup, String *answer)
135
*answer = XawDialogGetValueString(popup->dialog_widget);
137
XtPopdown(popup->shell_widget);
141
PopupDialog(Dialog popup, String message, String suggestion,
142
String *answer, XtGrabKind grab)
144
Position popup_x, popup_y, top_x, top_y;
145
Dimension popup_width, popup_height, top_width, top_height, border_width;
150
XtSetArg(wargs[n], XtNlabel, message); n++;
151
XtSetArg(wargs[n], XtNvalue, suggestion); n++;
152
XtSetValues(popup->dialog_widget, wargs, n);
154
XtRealizeWidget(popup->shell_widget);
157
XtSetArg(wargs[n], XtNx, &top_x); n++;
158
XtSetArg(wargs[n], XtNy, &top_y); n++;
159
XtSetArg(wargs[n], XtNwidth, &top_width); n++;
160
XtSetArg(wargs[n], XtNheight, &top_height); n++;
161
XtGetValues(popup->top_widget, wargs, n);
164
XtSetArg(wargs[n], XtNwidth, &popup_width); n++;
165
XtSetArg(wargs[n], XtNheight, &popup_height); n++;
166
XtSetArg(wargs[n], XtNborderWidth, &border_width); n++;
167
XtGetValues(popup->shell_widget, wargs, n);
170
min(top_x + ((Position)top_width - (Position)popup_width) / 2,
171
(Position)DisplayWidth(XtDisplay(popup->shell_widget),
172
DefaultScreen(XtDisplay(popup->shell_widget))) -
173
(Position)popup_width - 2 * (Position)border_width));
175
min(top_y + ((Position)top_height - (Position)popup_height) / 2,
176
(Position)DisplayHeight(XtDisplay(popup->shell_widget),
177
DefaultScreen(XtDisplay(popup->shell_widget))) -
178
(Position)popup_height - 2 * (Position)border_width));
180
XtSetArg(wargs[n], XtNx, popup_x); n++;
181
XtSetArg(wargs[n], XtNy, popup_y); n++;
182
XtSetValues(popup->shell_widget, wargs, n);
186
XtPopup(popup->shell_widget, grab);
187
XWarpPointer(XtDisplay(popup->shell_widget),
188
XtWindow(popup->top_widget),
189
XtWindow(popup->shell_widget),
190
0, 0, top_width, top_height,
191
popup_width / 2, popup_height / 2);
193
while ((selected & popup->options) == None) {
196
XtDispatchEvent(&event);
199
PopdownDialog(popup, answer);
201
return (selected & popup->options);