~ubuntu-branches/ubuntu/lucid/x11-apps/lucid

« back to all changes in this revision

Viewing changes to bitmap/Dialog.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien Cristau
  • Date: 2008-09-23 00:24:45 UTC
  • mfrom: (1.1.2 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080923002445-mb2rwkif45zz1vlj
Tags: 7.3+4
* Remove xedit from the package, it's unmaintained and broken
  (closes: #321434).
* Remove xedit's conffiles on upgrade.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Xorg: Dialog.c,v 1.4 2001/02/09 02:05:28 xorgcvs Exp $ */
 
2
/*
 
3
 
 
4
Copyright 1989, 1998  The Open Group
 
5
 
 
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
 
10
documentation.
 
11
 
 
12
The above copyright notice and this permission notice shall be included
 
13
in all copies or substantial portions of the Software.
 
14
 
 
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.
 
22
 
 
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
 
26
from The Open Group.
 
27
 
 
28
*/
 
29
/* $XFree86: xc/programs/bitmap/Dialog.c,v 1.3 2001/01/17 23:44:51 dawes Exp $ */
 
30
 
 
31
/*
 
32
 * Author:  Davor Matic, MIT X Consortium
 
33
 */
 
34
 
 
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>
 
41
    
 
42
#include "Dialog.h"
 
43
 
 
44
#define min(x, y)                     (((x) < (y)) ? (x) : (y))
 
45
#define max(x, y)                     (((x) > (y)) ? (x) : (y))
 
46
 
 
47
 
 
48
static void SetDialogButton(Widget w, XEvent *event, 
 
49
                            String *argv, Cardinal *argc);
 
50
 
 
51
static XtActionsRec actions_table[] = {
 
52
  {"set-dialog-button", SetDialogButton},
 
53
};
 
54
 
 
55
static DialogButton dialog_buttons[] = {
 
56
    {"yes", Yes},
 
57
    {"no", No},
 
58
    {"maybe", Maybe},
 
59
    {"okay", Okay},
 
60
    {"abort", Abort},
 
61
    {"cancel", Cancel},
 
62
    {"retry", Retry},
 
63
};
 
64
 
 
65
static unsigned long selected;
 
66
 
 
67
/* ARGSUSED */
 
68
static void 
 
69
SetSelected(Widget w, XtPointer clientData, XtPointer callData) /* ARGSUSED */
 
70
{
 
71
    String name = (String)clientData;
 
72
    int i;
 
73
    
 
74
    for (i = 0; i < XtNumber(dialog_buttons); i++) 
 
75
        if (!strcmp(dialog_buttons[i].name, name)) 
 
76
            selected |= dialog_buttons[i].flag;
 
77
}
 
78
 
 
79
/* ARGSUSED */
 
80
static void 
 
81
SetDialogButton(Widget w,       /* not used */
 
82
                XEvent *event,  /* not used */
 
83
                String *argv, 
 
84
                Cardinal *argc)
 
85
{
 
86
  char button_name[80];
 
87
  XtPointer dummy = NULL;
 
88
  int i;
 
89
 
 
90
  for (i = 0; i < *argc; i++) {
 
91
    XmuCopyISOLatin1Lowered (button_name, argv[i]);
 
92
    SetSelected(w, button_name, dummy);
 
93
  }
 
94
}
 
95
 
 
96
static Boolean firstTime = True;
 
97
 
 
98
Dialog 
 
99
CreateDialog(Widget top_widget, String name, unsigned long options)
 
100
{
 
101
    int i;
 
102
    Dialog popup;
 
103
 
 
104
    popup = (Dialog) XtMalloc(sizeof(_Dialog));
 
105
 
 
106
    if (popup) {
 
107
        if (firstTime) {
 
108
          XtAddActions(actions_table, XtNumber(actions_table));
 
109
          firstTime = False;
 
110
        }
 
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", 
 
116
                                                     dialogWidgetClass,
 
117
                                                     popup->shell_widget, 
 
118
                                                     NULL, 0);
 
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;
 
125
        return popup;
 
126
    }
 
127
    else
 
128
        return NULL;
 
129
}
 
130
 
 
131
void 
 
132
PopdownDialog(Dialog popup, String *answer)
 
133
{
 
134
    if (answer)
 
135
        *answer = XawDialogGetValueString(popup->dialog_widget);
 
136
    
 
137
    XtPopdown(popup->shell_widget);
 
138
}
 
139
 
 
140
unsigned long 
 
141
PopupDialog(Dialog popup, String message, String suggestion, 
 
142
            String *answer, XtGrabKind grab)
 
143
{
 
144
  Position popup_x, popup_y, top_x, top_y;
 
145
  Dimension popup_width, popup_height, top_width, top_height, border_width;
 
146
  int n;
 
147
  Arg wargs[4];
 
148
 
 
149
  n = 0;
 
150
  XtSetArg(wargs[n], XtNlabel, message); n++;
 
151
  XtSetArg(wargs[n], XtNvalue, suggestion); n++;
 
152
  XtSetValues(popup->dialog_widget, wargs, n);
 
153
 
 
154
  XtRealizeWidget(popup->shell_widget);
 
155
 
 
156
  n = 0;
 
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);
 
162
 
 
163
  n = 0;
 
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);
 
168
 
 
169
  popup_x = max(0, 
 
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));
 
174
  popup_y = max(0, 
 
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));
 
179
  n = 0;
 
180
  XtSetArg(wargs[n], XtNx, popup_x); n++;
 
181
  XtSetArg(wargs[n], XtNy, popup_y); n++;
 
182
  XtSetValues(popup->shell_widget, wargs, n);
 
183
 
 
184
  selected = None;
 
185
 
 
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);
 
192
 
 
193
  while ((selected & popup->options) == None) {
 
194
      XEvent event;
 
195
      XtNextEvent(&event);
 
196
      XtDispatchEvent(&event);
 
197
  }
 
198
 
 
199
  PopdownDialog(popup, answer);
 
200
 
 
201
  return (selected & popup->options);
 
202
}