home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / e / ebut10.zip / ebuttons-1.0 / ebuttons.c < prev    next >
C/C++ Source or Header  |  1992-11-28  |  4KB  |  175 lines

  1. #ifndef lint
  2. static char *rcsid = "$Header: /tmp_mnt/vida/disks/disk5/Users/terry/s/ebuttons/RCS/ebuttons.c,v 1.1 1992/11/28 22:41:25 terry Exp $";
  3. #endif
  4.  
  5.  
  6. /*
  7.  * X interface to Emacs.
  8.  * Copyright (C) 1992  Terry Jones
  9.  * (Based (heavily) on the taglist facility written by Brad Mears)
  10.  *
  11.  * This file is part of ebuttons
  12.  *
  13.  * Ebuttons is free software; you can redistribute it and/or modify
  14.  * it under the terms of the GNU General Public License as published by
  15.  * the Free Software Foundation; either version 1, or (at your option)
  16.  * any later version.
  17.  *
  18.  * The GNU General Public License can be obtained via anonymous ftp from
  19.  * prep.ai.mit.edu as pub/gnu/COPYING or pub/gnu/COPYING-2.
  20.  *
  21.  * Ebuttons is distributed in the hope that it will be useful,
  22.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24.  * GNU General Public License for more details.
  25.  */
  26.  
  27. /*
  28.  * This provides a point-and-click command interface to an 
  29.  * emacs session.  This won't be much use without ebuttons.el.
  30.  * See the README for details on use.
  31.  */
  32.  
  33. #include <stdio.h>
  34.  
  35. #include <X11/Intrinsic.h>
  36. #include <X11/StringDefs.h>
  37. #include <X11/Shell.h>
  38.  
  39. #ifdef HAVE_XAW3D
  40. #include <X11/Xaw3d/Box.h>
  41. #include <X11/Xaw3d/Command.h>
  42. #else
  43. #include <X11/Xaw/Box.h>
  44. #include <X11/Xaw/Command.h>
  45. #endif
  46.  
  47. static void create_buttons();
  48. static void button_press();
  49. void toggle_visibility();
  50.  
  51. typedef struct {
  52.     String labels[MAX_BUTTONS];
  53.     String commands[MAX_BUTTONS];
  54. } AppResources;
  55.  
  56. static AppResources appResources;
  57. static Widget toplevel;            
  58.  
  59. #include "ebuttons.h"
  60.  
  61. int 
  62. main(argc, argv)
  63. int argc;
  64. char **argv;
  65. {
  66.    XtAppContext appContext;
  67.  
  68.    toplevel = XtAppInitialize(&appContext, "ebuttons", NULL, 0, &argc, argv, NULL, NULL, 0);
  69.    XtGetApplicationResources(toplevel, (XtPointer)&appResources, resources, XtNumber(resources), NULL, 0);
  70.    create_buttons(toplevel);
  71.    XtAppAddInput(appContext, fileno(stdin), XtInputReadMask, toggle_visibility, NULL);
  72.    XtRealizeWidget(toplevel);
  73.    XtAppMainLoop(appContext);
  74.    return 0;
  75. }
  76.  
  77.  
  78. /*
  79.  * Callback for the configurable command buttons.  The quit button
  80.  * has no associated command.
  81.  */
  82. static void 
  83. button_press(w, command, dummy)
  84. Widget  w;
  85. XtPointer command; 
  86. XtPointer dummy;
  87. {
  88.    if (!command){
  89.       exit(0);
  90.   }
  91.  
  92.    printf("%s", (String)command);
  93.    fflush(stdout);
  94.    return;
  95. }
  96.  
  97.  
  98. static void 
  99. create_buttons(parent)
  100. Widget parent;
  101. {
  102.     Widget cmds[MAX_BUTTONS];
  103.     Widget cmdbox;              
  104.     Widget quit;
  105.     int i;
  106.     Dimension width;
  107.     Dimension max_width = 0;
  108.     
  109.     cmdbox = XtCreateManagedWidget("cmdbox", boxWidgetClass, parent, NULL, 0);
  110.     
  111.     for (i = 0; i < MAX_BUTTONS; i++) {
  112.     if (appResources.labels[i] && appResources.commands[i]){
  113.         cmds[i] = XtCreateManagedWidget(appResources.labels[i], commandWidgetClass, cmdbox, NULL, 0);
  114.         XtAddCallback(cmds[i], XtNcallback, button_press, (XtPointer)appResources.commands[i]);
  115.     
  116.         XtVaGetValues(cmds[i], XtNwidth, &width, NULL);
  117.         
  118.         if (max_width < width){
  119.         max_width = width;
  120.         }
  121.     }
  122.     }
  123.     
  124.     quit = XtCreateManagedWidget("Quit", commandWidgetClass, cmdbox, NULL, 0);
  125.     XtAddCallback(quit, XtNcallback, button_press, NULL);
  126.     
  127.     XtVaGetValues(quit, XtNwidth, &width, NULL);
  128.     
  129.     if (max_width < width){
  130.     max_width = width;
  131.     }
  132.     
  133.     /* Set all the buttons to the same width */
  134.     for (i = 0; i < MAX_BUTTONS; i++) {
  135.     if (appResources.labels[i] && appResources.commands[i]){
  136.         XtVaSetValues(cmds[i], XtNwidth, max_width, NULL);
  137.     }
  138.     }
  139.     
  140.     XtVaSetValues(quit, XtNwidth, max_width, NULL);
  141.     
  142.     return;
  143. }
  144.  
  145.  
  146. void 
  147. toggle_visibility(client_data, dummy1, dummy2)
  148. XtPointer client_data;
  149. int *dummy1;
  150. XtInputId *dummy2;
  151. {
  152.    char buf[BUFSIZ];
  153.    static int visible = 1;
  154.  
  155.     /* Read input from stdin.  We know it is ready since we have been called. */
  156.    
  157.    if (!fgets(buf, BUFSIZ, stdin)){
  158.        /* This goes to stdout, not stderr. */
  159.        printf("could not read from stdin!\n");
  160.        exit(0);
  161.    }
  162.  
  163.    if (visible) {
  164.        XtUnmapWidget(toplevel);
  165.        visible = 0;
  166.    }
  167.    else {
  168.        XtMapWidget(toplevel);
  169.        visible = 1;
  170.    }
  171.    
  172.    return;
  173. }
  174.  
  175.