home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume2 / xbrowser / part02 / modcommand.c next >
Encoding:
C/C++ Source or Header  |  1989-01-03  |  3.4 KB  |  157 lines

  1. /* Systems Sciences Laboratory, Webster Research Center */
  2.  
  3. static char *PROGRAM_information[] =
  4. {
  5.     "Copyright (c) 1988 Xerox Corporation.  All rights reserved.",
  6.     "$Header$",
  7.     "$Locker$"
  8. }
  9. ;
  10.  
  11. /*
  12.  * Copyright protection claimed includes all forms and matters of copyrightable
  13.  * material and information now allowed by statutory or judicial lay or
  14.  * herinafter granted, including without limitation, material generated from
  15.  * the software programs which are displayed on the screen such as icons,
  16.  * screen display looks, etc.
  17.  */
  18.  
  19.  
  20. /*
  21.  * this defines modifications to the command button widget;
  22.  * it redefines the translation table to accept input from
  23.  * all three mouse buttons; the notify routine is redone to
  24.  * return the number of the pressed mouse button as the call_data
  25.  * parameter;
  26.  *
  27.  */
  28.  
  29. #include "xfilebrowser.h"
  30. #include <X11/IntrinsicP.h>
  31. #include <X11/CommandP.h>
  32.  
  33.  
  34. /* Private Data */
  35. extern void My_Notify();
  36. extern void My_Double();
  37.  
  38. static char defaultTranslations[] =
  39.     "<Btn1Down>:    set() \n\
  40.      <Btn1Up>:        mynotify(1) unset() \n\
  41.      <Btn2Down>:    set() \n\
  42.      <Btn2Up>:        mynotify(2) unset() \n\
  43.      <Btn3Down>:    set() \n\
  44.      <Btn3Up>:        mynotify(3) unset()";
  45.  
  46. static char textTranslations[] =
  47.      "<Btn1Up>(2):    mydouble()";
  48.  
  49.  
  50. static XtActionsRec actionsList[] =
  51. {
  52.   {"mynotify",        My_Notify},
  53. };
  54.  
  55. static XtActionsRec actionsText[] =
  56. {
  57.   {"mydouble",        My_Double},
  58. };
  59.  
  60.  
  61. /************************************
  62. *
  63. *  Modifications for command buttons
  64. *
  65. *************************************/
  66.  
  67.  
  68.  
  69. /* ARGSUSED */
  70. void ModCommand_Init(command)
  71. Widget command;
  72. {
  73.     XtTranslations modtable;
  74.  
  75.     modtable = XtParseTranslationTable(defaultTranslations);
  76.     XtOverrideTranslations(command, modtable);
  77.     XtAddActions(actionsList, 1);
  78.  
  79. /***************************
  80. *
  81. *  Action Procedures
  82. *
  83. ***************************/
  84.  
  85.  
  86. /* ARGSUSED */
  87. static void My_Notify(w, event, params, num_params)
  88. Widget w;
  89. XEvent *event;
  90. String *params;
  91. Cardinal *num_params;
  92. {
  93.     CommandWidget cbw = (CommandWidget)w;
  94.     int button;
  95.  
  96.     if (cbw->command.set) {
  97.          button = 0;
  98.          if (params[0] != NULL) {
  99.              if (*params[0] == '1') button = 1;
  100.              else if (*params[0] == '2') button = 2;
  101.              else if (*params[0] == '3') button = 3;
  102.        }
  103.          XtCallCallbacks(w, XtNcallback, (caddr_t)button);
  104.     }
  105. }
  106.  
  107.  
  108. /************************************
  109. *
  110. *  Modifications for text widgets
  111. *
  112. *************************************/
  113.  
  114. /* ARGSUSED */
  115. void Modtext_Init(command)
  116. Widget command;
  117. {
  118.     XtTranslations modtable;
  119.  
  120.     modtable = XtParseTranslationTable(textTranslations);
  121.     XtOverrideTranslations(command, modtable);
  122.     XtAddActions(actionsText, 1);
  123.  
  124. /* ARGSUSED */
  125. static void My_Double(w, event, params, num_params)
  126. Widget w;
  127. XEvent *event;
  128. String *params;
  129. Cardinal *num_params;
  130. {
  131.     XtTextPosition pos1, pos2;
  132.     int i;
  133.     long view_edit = (viewEdit ? 2 : 1); 
  134.     struct stat buf; 
  135.  
  136.     if (w == listwidget) {
  137.        XtTextGetSelectionPos(listwidget, &pos1, &pos2);
  138.        if (pos1 != pos2 && numfiles != 0 && 
  139.           ( (i = select_file(pos1, pos2)) != -1)) {
  140.            if (stat((*files[i]).d_name, &buf) == -1) {
  141.             disp_message("\ncannot check file stats");
  142.                return;
  143.             }
  144.        }
  145.        else return;
  146.  
  147.         if (buf.st_mode & S_IFDIR) 
  148.            DoList(listbutton, (caddr_t)NULL, (caddr_t)0);
  149.        else 
  150.            DoEdit(editbutton, (caddr_t)NULL, (caddr_t)view_edit);
  151.     }
  152.     else if (w == grepwidget) 
  153.        DoGrepEdit(grepbutton, (caddr_t)NULL, (caddr_t)view_edit);
  154. }
  155.