"Fossies" - the Fresh Open Source Software Archive

Member "ghostview-1.4.1/dialogs.c" (19 Jun 1992, 7098 Bytes) of package /linux/misc/old/ghost/gnu/ghostview/ghostview-1.4.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * dialogs.c -- Dialog box for ghostview.
    3  * Copyright (C) 1992  Timothy O. Theisen
    4  *
    5  * This program is free software; you can redistribute it and/or modify
    6  * it under the terms of the GNU General Public License as published by
    7  * the Free Software Foundation; either version 2 of the License, or
    8  * (at your option) any later version.
    9  *
   10  * This program is distributed in the hope that it will be useful,
   11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   13  * GNU General Public License for more details.
   14  *
   15  * You should have received a copy of the GNU General Public License
   16  * along with this program; if not, write to the Free Software
   17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   18  *
   19  *   Author: Tim Theisen           Systems Programmer
   20  * Internet: tim@cs.wisc.edu       Department of Computer Sciences
   21  *     UUCP: uwvax!tim             University of Wisconsin-Madison
   22  *    Phone: (608)262-0438         1210 West Dayton Street
   23  *      FAX: (608)262-9777         Madison, WI   53706
   24  */
   25 
   26 #include <X11/Intrinsic.h>
   27 #include <X11/StringDefs.h>
   28 #include <X11/Xos.h>
   29 #include <X11/Xaw/Cardinals.h>
   30 #include <X11/Xaw/Form.h>
   31 #include <X11/Xaw/Label.h>
   32 #include <X11/Xaw/AsciiText.h>
   33 #include <X11/Xaw/Command.h>
   34 #include "gv.h"
   35 
   36 static String okay_accelerators =
   37     "#override\n\
   38      <Key>Return: set() notify() unset()\n";
   39 
   40 /* Create a dialog widget */
   41 /* It is just a form widget with
   42  *   a label prompt
   43  *   a text response
   44  *   an oky button
   45  *   a cancel button */
   46 Widget
   47 CreateDialog(parent, name, okay_callback, cancel_callback)
   48     Widget parent;
   49     String name;
   50     XtCallbackProc okay_callback;
   51     XtCallbackProc cancel_callback;
   52 {
   53     Widget form, prompt, response, okay, cancel;
   54     Arg args[20];
   55     Cardinal num_args;
   56 
   57                             num_args = 0;
   58     if (special_cmap) {
   59     XtSetArg(args[num_args], XtNbackground, white); num_args++;
   60     }
   61     form = XtCreateManagedWidget(name, formWidgetClass, parent, args, num_args);
   62 
   63                             num_args = 0;
   64     if (special_cmap) {
   65     XtSetArg(args[num_args], XtNforeground, black); num_args++;
   66     XtSetArg(args[num_args], XtNbackground, white); num_args++;
   67     }
   68     XtSetArg(args[num_args], XtNtop, XtChainTop);   num_args++;
   69     XtSetArg(args[num_args], XtNbottom, XtChainTop);    num_args++;
   70     XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++;
   71     XtSetArg(args[num_args], XtNright, XtChainLeft);    num_args++;
   72     XtSetArg(args[num_args], XtNresizable, True);   num_args++;
   73     XtSetArg(args[num_args], XtNborderWidth, 0);    num_args++;
   74     prompt = XtCreateManagedWidget("prompt", labelWidgetClass,
   75                    form, args, num_args);
   76 
   77                             num_args = 0;
   78     if (special_cmap) {
   79     XtSetArg(args[num_args], XtNforeground, black); num_args++;
   80     XtSetArg(args[num_args], XtNbackground, white); num_args++;
   81     }
   82     XtSetArg(args[num_args], XtNfromVert, prompt);  num_args++;
   83     XtSetArg(args[num_args], XtNtop, XtChainTop);   num_args++;
   84     XtSetArg(args[num_args], XtNbottom, XtChainTop);    num_args++;
   85     XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++;
   86     XtSetArg(args[num_args], XtNright, XtChainLeft);    num_args++;
   87     XtSetArg(args[num_args], XtNresizable, True);   num_args++;
   88     XtSetArg(args[num_args], XtNeditType, XawtextEdit); num_args++;
   89     XtSetArg(args[num_args], XtNresize, XawtextResizeWidth);    num_args++;
   90     XtSetArg(args[num_args], XtNstring, "");        num_args++;
   91     response = XtCreateManagedWidget("response", asciiTextWidgetClass,
   92                      form, args, num_args);
   93 
   94                             num_args = 0;
   95     if (special_cmap) {
   96     XtSetArg(args[num_args], XtNforeground, black); num_args++;
   97     XtSetArg(args[num_args], XtNbackground, white); num_args++;
   98     }
   99     XtSetArg(args[num_args], XtNfromVert, response);    num_args++;
  100     XtSetArg(args[num_args], XtNtop, XtChainTop);   num_args++;
  101     XtSetArg(args[num_args], XtNbottom, XtChainTop);    num_args++;
  102     XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++;
  103     XtSetArg(args[num_args], XtNright, XtChainLeft);    num_args++;
  104     XtSetArg(args[num_args], XtNresizable, True);   num_args++;
  105     XtSetArg(args[num_args], XtNaccelerators,
  106          XtParseAcceleratorTable(okay_accelerators));   num_args++;
  107     okay = XtCreateManagedWidget("okay", commandWidgetClass,
  108                  form, args, num_args);
  109     XtAddCallback(okay, XtNcallback, okay_callback, form);
  110 
  111                             num_args = 0;
  112     if (special_cmap) {
  113     XtSetArg(args[num_args], XtNforeground, black); num_args++;
  114     XtSetArg(args[num_args], XtNbackground, white); num_args++;
  115     }
  116     XtSetArg(args[num_args], XtNfromVert, response);    num_args++;
  117     XtSetArg(args[num_args], XtNfromHoriz, okay);   num_args++;
  118     XtSetArg(args[num_args], XtNtop, XtChainTop);   num_args++;
  119     XtSetArg(args[num_args], XtNbottom, XtChainTop);    num_args++;
  120     XtSetArg(args[num_args], XtNleft, XtChainLeft); num_args++;
  121     XtSetArg(args[num_args], XtNright, XtChainLeft);    num_args++;
  122     XtSetArg(args[num_args], XtNresizable, True);   num_args++;
  123     cancel = XtCreateManagedWidget("cancel", commandWidgetClass,
  124                    form, args, num_args);
  125     XtAddCallback(cancel, XtNcallback, cancel_callback, parent);
  126 
  127     XtInstallAccelerators(response, okay);
  128     XtSetKeyboardFocus(form, response);
  129 
  130     return form;
  131 }
  132 
  133 /* get the prompt from the dialog box.  Used a startup time to
  134  * save away the initial prompt */
  135 String
  136 GetDialogPrompt(w)
  137     Widget w;
  138 {
  139     Arg args[1];
  140     Widget label;
  141     String s;
  142 
  143     label = XtNameToWidget(w, "prompt");
  144     XtSetArg(args[0], XtNlabel, &s);
  145     XtGetValues(label, args, ONE);
  146     return XtNewString(s);
  147 }
  148 
  149 /* set the prompt.  This is used to put error information in the prompt */
  150 void
  151 SetDialogPrompt(w, newprompt)
  152     Widget w;
  153     String newprompt;
  154 {
  155     Arg args[1];
  156     Widget label;
  157 
  158     label = XtNameToWidget(w, "prompt");
  159     XtSetArg(args[0], XtNlabel, newprompt);
  160     XtSetValues(label, args, ONE);
  161 }
  162 
  163 /* get what the user typed */
  164 String
  165 GetDialogResponse(w)
  166     Widget w;
  167 {
  168     Arg args[1];
  169     Widget response;
  170     String s;
  171 
  172     response = XtNameToWidget(w, "response");
  173     XtSetArg(args[0], XtNstring, &s);
  174     XtGetValues(response, args, ONE);
  175     return XtNewString(s);
  176 }
  177 
  178 /* set the default reponse */
  179 void
  180 SetDialogResponse(w, s)
  181     Widget w;
  182     String s;
  183 {
  184     Arg args[3];
  185     Widget response;
  186     XFontStruct *font;
  187     Dimension width, leftMargin, rightMargin;
  188 
  189     response = XtNameToWidget(w, "response");
  190     XtSetArg(args[0], XtNfont, &font);
  191     XtSetArg(args[1], XtNleftMargin, &leftMargin);
  192     XtSetArg(args[2], XtNrightMargin, &rightMargin);
  193     XtGetValues(response, args, THREE);
  194     width = font->max_bounds.width * strlen(s) + leftMargin + rightMargin;
  195 
  196     XtSetArg(args[0], XtNstring, s);
  197     XtSetArg(args[1], XtNwidth, width);
  198     XtSetValues(response, args, TWO);
  199     XawTextSetInsertionPoint(response, strlen(s));
  200 
  201 }
  202 
  203 /* clear the response */
  204 void
  205 ClearDialogResponse(w)
  206     Widget w;
  207 {
  208     Arg args[2];
  209     Widget response;
  210 
  211     response = XtNameToWidget(w, "response");
  212     XtSetArg(args[0], XtNstring, "");
  213     XtSetArg(args[1], XtNwidth, 100);
  214     XtSetValues(response, args, TWO);
  215 }