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

« back to all changes in this revision

Viewing changes to xgc/getfile.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
/*
 
2
** getfilename.c
 
3
**
 
4
*/
 
5
/* $XFree86: xc/programs/xgc/getfile.c,v 1.4tsi Exp $ */
 
6
 
 
7
#include <X11/Intrinsic.h>
 
8
#include <X11/StringDefs.h>
 
9
#include <X11/Xaw/Label.h>
 
10
#include <X11/Xaw/Command.h>
 
11
#include <X11/Xaw/Form.h>
 
12
#include <X11/Shell.h>
 
13
#include <X11/Xaw/AsciiText.h>
 
14
#include <stdio.h>
 
15
 
 
16
#include "xgc.h"
 
17
 
 
18
 
 
19
static Widget popupshell = NULL;        /* popup dialog box */
 
20
Widget filename_text_widget;    /* Widget containing the name of
 
21
                                   the file the user has selected */
 
22
 
 
23
static void kill_popup_shell(void);
 
24
 
 
25
void
 
26
get_filename(
 
27
     void (*success)(void),     /* what function to call when a filename is
 
28
                                   chosen */
 
29
     void (*failure)(void))     /* what function to call when the user
 
30
                                   cancels */
 
31
{
 
32
  static Widget popupform;      /* form inside shell */
 
33
  static Widget label;          /* "Filename :" */
 
34
 
 
35
  Window dummy1, dummy2;
 
36
  int x1,y1,x2,y2;
 
37
  unsigned int mask;
 
38
 
 
39
  /* The translation table for the text widget.  Things such as <RETURN>
 
40
  ** confirm the user's choice.  Other keys which would move out of
 
41
  ** the range of a one-line window are disabled. */
 
42
 
 
43
  static const char *translationtable = 
 
44
    "Ctrl<Key>J:    KillPopup() Done()\n\
 
45
     Ctrl<Key>M:    KillPopup() Done()\n\
 
46
     <Key>Linefeed: KillPopup() Done()\n\
 
47
     <Key>Return:   KillPopup() Done()\n\
 
48
     Ctrl<Key>O:    Nothing()\n\
 
49
     Meta<Key>I:    Nothing()\n\
 
50
     Ctrl<Key>N:    Nothing()\n\
 
51
     Ctrl<Key>P:    Nothing()\n\
 
52
     Ctrl<Key>Z:    Nothing()\n\
 
53
     Meta<Key>Z:    Nothing()\n\
 
54
     Ctrl<Key>V:    Nothing()\n\
 
55
     Meta<Key>V:    Nothing()";
 
56
 
 
57
  /* What the actions in the translation table correspond to. */
 
58
 
 
59
  static XtActionsRec actiontable[] = {
 
60
    {"KillPopup", (XtActionProc) kill_popup_shell},
 
61
    {"Done",      NULL},
 
62
    {"Nothing",   NULL}
 
63
  };
 
64
 
 
65
  static Arg popupshellargs[] = {     /* Where to put the popup shell. */
 
66
    {XtNx,         (XtArgVal) NULL},
 
67
    {XtNy,         (XtArgVal) NULL}
 
68
  };
 
69
 
 
70
  static Arg labelargs[] = {    /* ArgList for the label */
 
71
    {XtNborderWidth,    (XtArgVal) 0},
 
72
    {XtNjustify,        (XtArgVal) XtJustifyRight}
 
73
  };
 
74
 
 
75
  static Arg textargs[] = {     /* ArgList for the text widget */
 
76
    {XtNeditType,       (XtArgVal) XawtextEdit},
 
77
    {XtNwidth,          (XtArgVal) 200},
 
78
    {XtNhorizDistance,  (XtArgVal) 10},
 
79
    {XtNfromHoriz,      (XtArgVal) NULL},
 
80
  };
 
81
 
 
82
  static Arg cancelargs[] = {   /* ArgList for the cancel button */
 
83
    {XtNfromHoriz,      (XtArgVal) NULL},
 
84
    {XtNcallback,       (XtArgVal) NULL}
 
85
  };
 
86
 
 
87
  /* Procedures to call when the user selects 'cancel' */
 
88
  static XtCallbackRec cancelcallbacklist[] = {
 
89
    {(XtCallbackProc) kill_popup_shell, NULL},
 
90
    {NULL, NULL},
 
91
    {NULL, NULL}
 
92
  };
 
93
 
 
94
  if (popupshell != NULL) {
 
95
      XtPopup(popupshell,XtGrabExclusive);
 
96
      return;
 
97
  }
 
98
 
 
99
  /* Find out where the pointer is, so we can put the popup window there */
 
100
 
 
101
  (void) XQueryPointer(X.dpy,XtWindow(topform),&dummy1,&dummy2,&x1,&y1,
 
102
                       &x2,&y2,&mask);
 
103
  
 
104
  popupshellargs[0].value = (XtArgVal) x2;
 
105
  popupshellargs[1].value = (XtArgVal) y2;
 
106
  
 
107
  popupshell = XtCreatePopupShell("popup",overrideShellWidgetClass,
 
108
                         topform,popupshellargs,XtNumber(popupshellargs));
 
109
 
 
110
  popupform = XtCreateManagedWidget("form",formWidgetClass,popupshell,
 
111
                            NULL, 0);
 
112
 
 
113
  label = XtCreateManagedWidget("Filename: ",labelWidgetClass,popupform,
 
114
                               labelargs,XtNumber(labelargs));
 
115
 
 
116
  textargs[3].value = (XtArgVal) label;
 
117
 
 
118
  filename_text_widget = XtCreateManagedWidget("text",asciiTextWidgetClass,
 
119
                                               popupform,
 
120
                                               textargs,XtNumber(textargs));
 
121
 
 
122
  /* Complete the action table.  We have to do it here because success
 
123
  ** isn't known at compile time. */
 
124
 
 
125
  actiontable[1].proc = (XtActionProc) success;
 
126
 
 
127
  /* Register actions, translations, callbacks */
 
128
 
 
129
  XtAppAddActions(appcontext,actiontable,XtNumber(actiontable));
 
130
  XtOverrideTranslations(filename_text_widget,
 
131
                         XtParseTranslationTable(translationtable));
 
132
  cancelcallbacklist[1].callback = (XtCallbackProc) failure;
 
133
 
 
134
  cancelargs[0].value = (XtArgVal) filename_text_widget;
 
135
  cancelargs[1].value = (XtArgVal) cancelcallbacklist;
 
136
 
 
137
  (void) XtCreateManagedWidget("Cancel",commandWidgetClass,popupform,
 
138
                               cancelargs,XtNumber(cancelargs));
 
139
 
 
140
  /* Bring up the popup.  When the user presses cancel or the return key,
 
141
  ** the function kill_popup_shell (below) will be called to remove it. */
 
142
 
 
143
  XtPopup(popupshell,XtGrabExclusive);
 
144
}
 
145
 
 
146
/* kill_popup_shell()
 
147
** ------------------
 
148
** Remove the popup window that get_filename popped up.
 
149
*/
 
150
 
 
151
static void
 
152
kill_popup_shell(void)
 
153
{
 
154
  XtPopdown(popupshell);
 
155
}