"Fossies" - the Fresh Open Source Software Archive

Member "ghostview-1.5/actions.c" (1 Oct 1992, 10890 Bytes) of package /linux/misc/old/ghost/gnu/ghostview/ghostview-1.5.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  * actions.c -- X11 actions 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/Xaw/Cardinals.h>
   29 #include <X11/Xaw/Scrollbar.h>
   30 #include "gv.h"
   31 #include "ps.h"
   32 
   33 /* Popup the copyright window */
   34 void
   35 gv_copyright(w, event, params, num_params)
   36     Widget w;
   37     XEvent *event;
   38     String *params;
   39     Cardinal *num_params;
   40 {
   41     popup(w, (XtPointer)copyrightpopup, NULL);
   42 }
   43 
   44 /* Call the quit callback to stop ghostview */
   45 void
   46 gv_quit(w, event, params, num_params)
   47     Widget w;
   48     XEvent *event;
   49     String *params;
   50     Cardinal *num_params;
   51 {
   52     quit_ghostview(w, NULL, NULL);
   53 }
   54 
   55 /* Popup the open file dialog box. */
   56 void
   57 gv_open(w, event, params, num_params)
   58     Widget w;
   59     XEvent *event;
   60     String *params;
   61     Cardinal *num_params;
   62 {
   63     popup_dialog(w, (XtPointer)OPEN, NULL);
   64 }
   65 
   66 /* Popup the open file dialog box. */
   67 void
   68 gv_reopen(w, event, params, num_params)
   69     Widget w;
   70     XEvent *event;
   71     String *params;
   72     Cardinal *num_params;
   73 {
   74     if (!XtIsSensitive(reopenbutton)) return;
   75     reopen_file(w, NULL, NULL);
   76 }
   77 
   78 /* Popup the save file dialog box. */
   79 void
   80 gv_save(w, event, params, num_params)
   81     Widget w;
   82     XEvent *event;
   83     String *params;
   84     Cardinal *num_params;
   85 {
   86     if (!XtIsSensitive(savebutton)) return;
   87     popup_dialog(w, (XtPointer)SAVE, NULL);
   88 }
   89 
   90 /* Popup the print file dialog box. */
   91 void
   92 gv_print_whole(w, event, params, num_params)
   93     Widget w;
   94     XEvent *event;
   95     String *params;
   96     Cardinal *num_params;
   97 {
   98     if (!XtIsSensitive(printwholebutton)) return;
   99     popup_dialog(w, (XtPointer)PRINT_WHOLE, NULL);
  100 }
  101 
  102 /* Popup the print file dialog box. */
  103 void
  104 gv_print_marked(w, event, params, num_params)
  105     Widget w;
  106     XEvent *event;
  107     String *params;
  108     Cardinal *num_params;
  109 {
  110     if (!XtIsSensitive(printmarkedbutton)) return;
  111     popup_dialog(w, (XtPointer)PRINT_MARKED, NULL);
  112 }
  113 
  114 /* Call the prev_page callback */
  115 void
  116 gv_prev(w, event, params, num_params)
  117     Widget w;
  118     XEvent *event;
  119     String *params;
  120     Cardinal *num_params;
  121 {
  122     if (!XtIsSensitive(prevbutton)) return;
  123     prev_page(w, NULL, NULL);
  124 }
  125 
  126 /* Call the this_page callback */
  127 void
  128 gv_show(w, event, params, num_params)
  129     Widget w;
  130     XEvent *event;
  131     String *params;
  132     Cardinal *num_params;
  133 {
  134     if (!XtIsSensitive(showbutton)) return;
  135     this_page(w, NULL, NULL);
  136 }
  137 
  138 /* Call the next_page callback */
  139 void
  140 gv_next(w, event, params, num_params)
  141     Widget w;
  142     XEvent *event;
  143     String *params;
  144     Cardinal *num_params;
  145 {
  146     if (!XtIsSensitive(nextbutton)) return;
  147     next_page(w, NULL, NULL);
  148 }
  149 
  150 /* Call the center_page callback */
  151 void
  152 gv_center(w, event, params, num_params)
  153     Widget w;
  154     XEvent *event;
  155     String *params;
  156     Cardinal *num_params;
  157 {
  158     if (!XtIsSensitive(centerbutton)) return;
  159     center_page(w, NULL, NULL);
  160 }
  161 
  162 /* Call the mark_page callback */
  163 void
  164 gv_mark(w, event, params, num_params)
  165     Widget w;
  166     XEvent *event;
  167     String *params;
  168     Cardinal *num_params;
  169 {
  170     if (!XtIsSensitive(markbutton)) return;
  171     mark_page(w, NULL, NULL);
  172 }
  173 
  174 /* Call the unmark_page callback */
  175 void
  176 gv_unmark(w, event, params, num_params)
  177     Widget w;
  178     XEvent *event;
  179     String *params;
  180     Cardinal *num_params;
  181 {
  182     if (!XtIsSensitive(unmarkbutton)) return;
  183     unmark_page(w, NULL, NULL);
  184 }
  185 
  186 /* Get the magstep from the parameter string and
  187  * call the set_magstep callback with that magstep */
  188 void
  189 gv_set_magstep(w, event, params, num_params)
  190     Widget w;
  191     XEvent *event;
  192     String *params;
  193     Cardinal *num_params;
  194 {
  195     int i;
  196 
  197     if (*num_params < 1) return;
  198     i = atoi(params[0]);
  199     set_magstep(w, (XtPointer)i, NULL);
  200 }
  201 
  202 /* Increment the magstep and
  203  * call the set_magstep callback with that magstep */
  204 void
  205 gv_increase_magstep(w, event, params, num_params)
  206     Widget w;
  207     XEvent *event;
  208     String *params;
  209     Cardinal *num_params;
  210 {
  211     int i;
  212 
  213     i = app_res.magstep + 1;
  214     if (i <= app_res.maximum_magstep)
  215     set_magstep(w, (XtPointer)i, NULL);
  216 }
  217 
  218 /* Decrement the magstep and
  219  * call the set_magstep callback with that magstep */
  220 void
  221 gv_decrease_magstep(w, event, params, num_params)
  222     Widget w;
  223     XEvent *event;
  224     String *params;
  225     Cardinal *num_params;
  226 {
  227     int i;
  228 
  229     i = app_res.magstep - 1;
  230     if (i >= app_res.minimum_magstep)
  231     set_magstep(w, (XtPointer)i, NULL);
  232 }
  233 
  234 /* Set orientation action routine.  Converts text parameter
  235  * to XtPageOrientation and all set_orientation callback */
  236 void
  237 gv_set_orientation(w, event, params, num_params)
  238     Widget w;
  239     XEvent *event;
  240     String *params;
  241     Cardinal *num_params;
  242 {
  243     XrmValue from, to;
  244     XtPageOrientation orient;
  245 
  246     if (*num_params < 1) return;
  247     from.size = sizeof(String);
  248     from.addr = params[0];
  249     to.size = 0;
  250     to.addr = NULL;
  251     if (XmuCvtStringToPageOrientation(XtDisplay(w), NULL, ZERO,
  252                       &from, &to, NULL)) {
  253     orient = *(XtPageOrientation *)(to.addr);
  254     set_orientation(w, (XtPointer)orient, NULL);
  255     }
  256 }
  257 
  258 /* Call the swap_landscape callback */
  259 void
  260 gv_swap_landscape(w, event, params, num_params)
  261     Widget w;
  262     XEvent *event;
  263     String *params;
  264     Cardinal *num_params;
  265 {
  266     swap_landscape(w, NULL, NULL);
  267 }
  268 
  269 /* Set pagemedia action routine.  Converts text parameter
  270  * to index into the pagemedia widgets and calls the set_pagemedia
  271  * callback. */
  272 void
  273 gv_set_pagemedia(w, event, params, num_params)
  274     Widget w;
  275     XEvent *event;
  276     String *params;
  277     Cardinal *num_params;
  278 {
  279     int i;
  280 
  281     if (*num_params < 1) return;
  282 
  283     /* First check pagemedia defined within the document */
  284     if (doc && doc->nummedia) {
  285     for (i = 0; i < doc->nummedia; i++) {
  286         if (!strcmp(params[0], doc->media[i].name)) {
  287         set_pagemedia(w, (XtPointer)i, NULL);
  288         break;
  289         }
  290     }
  291     }
  292 
  293     /* Then check the standard ones */
  294     for (i = 0; papersizes[i].name; i++) {
  295     if (!strcmp(params[0], papersizes[i].name)) {
  296             set_pagemedia(w, (XtPointer)(base_papersize+i), NULL);
  297         break;
  298     }
  299     }
  300 }
  301 
  302 
  303 /* Reset the force flag.  */
  304 /* (force flag is checked when setting orientaion and pagemedia) */
  305 void
  306 gv_default(w, event, params, num_params)
  307     Widget w;
  308     XEvent *event;
  309     String *params;
  310     Cardinal *num_params;
  311 {
  312     force_setting = False;
  313 }
  314 
  315 /* Set the force flag.  */
  316 /* (force flag is checked when setting orientaion and pagemedia) */
  317 void
  318 gv_force(w, event, params, num_params)
  319     Widget w;
  320     XEvent *event;
  321     String *params;
  322     Cardinal *num_params;
  323 {
  324     force_setting = True;
  325 }
  326 
  327 /* Implement WM_DELETE_WINDOW protocol */
  328 void
  329 gv_delete_window(w, event, params, num_params)
  330     Widget w;
  331     XEvent *event;
  332     String *params;
  333     Cardinal *num_params;
  334 {
  335     if (event->type == ClientMessage &&
  336     event->xclient.data.l[0] != wm_delete_window) return;
  337     XtDestroyWidget(w);
  338 }
  339 
  340 
  341 /* Destroy popup zoom window */
  342 void
  343 gv_delete_zoom(w, event, params, num_params)
  344     Widget w;
  345     XEvent *event;
  346     String *params;
  347     Cardinal *num_params;
  348 {
  349     XtDestroyWidget(XtParent(w));
  350 }
  351 
  352 /* dismiss a popup window */
  353 void
  354 gv_dismiss(w, event, params, num_params)
  355     Widget w;
  356     XEvent *event;
  357     String *params;
  358     Cardinal *num_params;
  359 {
  360     XtPopdown(w);
  361     if (w == infopopup) info_up = False;
  362 }
  363 
  364 /* scroll main viewport up */
  365 void
  366 gv_scroll_up(w, event, params, num_params)
  367     Widget w;
  368     XEvent *event;
  369     String *params;
  370     Cardinal *num_params;
  371 {
  372     Arg args[2];
  373     Widget scroll;
  374     float top, shown;
  375 
  376     scroll = XtNameToWidget(pageview, "vertical");
  377     if (scroll) {
  378     XtSetArg(args[0], XtNshown, &shown);
  379     XtSetArg(args[1], XtNtopOfThumb, &top);
  380     XtGetValues(scroll, args, TWO);
  381 
  382     top = top - shown;
  383     if (top < 0.0) top = 0.0;
  384     XtCallCallbacks(scroll, XtNjumpProc, &top);
  385     }
  386 }
  387 
  388 /* scroll main viewport down */
  389 void
  390 gv_scroll_down(w, event, params, num_params)
  391     Widget w;
  392     XEvent *event;
  393     String *params;
  394     Cardinal *num_params;
  395 {
  396     Arg args[2];
  397     Widget scroll;
  398     float top, shown;
  399 
  400     scroll = XtNameToWidget(pageview, "vertical");
  401     if (scroll) {
  402     XtSetArg(args[0], XtNshown, &shown);
  403     XtSetArg(args[1], XtNtopOfThumb, &top);
  404     XtGetValues(scroll, args, TWO);
  405 
  406     top = top + shown;
  407     if (top > (1.0 - shown)) top = (1.0 - shown);
  408     XtCallCallbacks(scroll, XtNjumpProc, &top);
  409     }
  410 }
  411 
  412 /* scroll main viewport left */
  413 void
  414 gv_scroll_left(w, event, params, num_params)
  415     Widget w;
  416     XEvent *event;
  417     String *params;
  418     Cardinal *num_params;
  419 {
  420     Arg args[2];
  421     Widget scroll;
  422     float top, shown;
  423 
  424     scroll = XtNameToWidget(pageview, "horizontal");
  425     if (scroll) {
  426     XtSetArg(args[0], XtNshown, &shown);
  427     XtSetArg(args[1], XtNtopOfThumb, &top);
  428     XtGetValues(scroll, args, TWO);
  429 
  430     top = top - shown;
  431     if (top < 0.0) top = 0.0;
  432     XtCallCallbacks(scroll, XtNjumpProc, &top);
  433     }
  434 }
  435 
  436 /* scroll main viewport right */
  437 void
  438 gv_scroll_right(w, event, params, num_params)
  439     Widget w;
  440     XEvent *event;
  441     String *params;
  442     Cardinal *num_params;
  443 {
  444     Arg args[2];
  445     Widget scroll;
  446     float top, shown;
  447 
  448     scroll = XtNameToWidget(pageview, "horizontal");
  449     if (scroll) {
  450     XtSetArg(args[0], XtNshown, &shown);
  451     XtSetArg(args[1], XtNtopOfThumb, &top);
  452     XtGetValues(scroll, args, TWO);
  453 
  454     top = top + shown;
  455     if (top > (1.0 - shown)) top = (1.0 - shown);
  456     XtCallCallbacks(scroll, XtNjumpProc, &top);
  457     }
  458 }
  459 
  460 /* Pop down locator window */
  461 void
  462 gv_erase_locator(w, event, params, num_params)
  463     Widget w;
  464     XEvent *event;
  465     String *params;
  466     Cardinal *num_params;
  467 {
  468     Arg args[1];
  469 
  470     if (!app_res.show_locator) return;
  471     XtSetArg(args[0], XtNlabel, "");
  472     XtSetValues(locator, args, ONE);
  473 }
  474 
  475 /* Check to see if file was updated */
  476 void
  477 gv_check_file(w, event, params, num_params)
  478     Widget w;
  479     XEvent *event;
  480     String *params;
  481     Cardinal *num_params;
  482 {
  483     struct stat sbuf;
  484 
  485     if (psfile) {
  486     if (!stat(filename, &sbuf) && mtime != sbuf.st_mtime) {
  487         show_page(current_page);
  488     }
  489     }
  490 }