home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / XAP / XFM / XFM-1.3 / XFM-1 / xfm-1.3 / xfm / FmAwActions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-09  |  7.2 KB  |  276 lines

  1. /*---------------------------------------------------------------------------
  2.   Module FmAwActions
  3.   
  4.   (c) Simon Marlow 1990-92
  5.   (c) Albert Graef 1994
  6.  
  7.   Action procedures for widgets in the application window
  8. ---------------------------------------------------------------------------*/
  9.  
  10. #include <string.h>
  11.  
  12. #include <X11/Intrinsic.h>
  13. #include <X11/StringDefs.h>
  14. #include <X11/Xaw/Toggle.h>
  15.  
  16. #include "Am.h"
  17.  
  18. /*---------------------------------------------------------------------------
  19.   PUBLIC FUNCTIONS
  20. ---------------------------------------------------------------------------*/
  21.  
  22. int findAppWidget(Widget w)
  23. {
  24.   int i;
  25.  
  26.   for (i=0; i<aw.n_apps; i++)
  27.     if (aw.apps[i].toggle == w)
  28.       return i;
  29.   return -1;
  30. }
  31.  
  32. /*---------------------------------------------------------------------------*/
  33.  
  34. void appPopup(Widget w, XEvent *event, String *params, Cardinal *num_params)
  35. {
  36.   Display *dpy;
  37.   Window root, child;
  38.   int x, y, x_win, y_win;
  39.   unsigned int mask;
  40.   int i = findAppWidget(w);
  41.  
  42.   dpy = XtDisplay(aw.shell);
  43.  
  44.   XQueryPointer(dpy, XtWindow(w), &root, &child, &x, &y, 
  45.         &x_win, &y_win, &mask);
  46.  
  47.   /* check whether icon was selected */
  48.   if (child != None) {
  49.     XTranslateCoordinates(dpy, XtWindow(w), child, x_win, y_win,
  50.               &x_win, &y_win, &child);
  51.     if (child != None) w = XtWindowToWidget(dpy, child);
  52.   }
  53.  
  54.   i = findAppWidget(w);
  55.   if (i != -1) appSelect(w, event, params, num_params);
  56.  
  57.   if (i == -1) {
  58.     if (aw.n_selections == 0)
  59.       grayOut(app_popup_items[1]);
  60.     else
  61.       fillIn(app_popup_items[1]);
  62.  
  63.     XQueryPointer(dpy, DefaultRootWindow(dpy), &root, &child, &x, &y, 
  64.           &x_win, &y_win, &mask);
  65.   
  66.     XtVaSetValues(app_popup_widget, XtNx, (XtArgVal) x, XtNy, (XtArgVal) y,
  67.           NULL);
  68.   
  69.     XtPopupSpringLoaded(app_popup_widget);
  70.   } else {
  71.     XQueryPointer(dpy, DefaultRootWindow(dpy), &root, &child, &x, &y, 
  72.           &x_win, &y_win, &mask);
  73.   
  74.     XtVaSetValues(app_popup_widget1, XtNx, (XtArgVal) x, XtNy, (XtArgVal) y,
  75.           NULL);
  76.   
  77.     XtPopupSpringLoaded(app_popup_widget1);
  78.   }
  79. }  
  80.  
  81. /*---------------------------------------------------------------------------*/
  82.  
  83. void appMaybeHighlight(Widget w, XEvent *event, String *params, 
  84.                Cardinal *num_params)
  85. {
  86.   int i;
  87.  
  88.   if (!dragging)
  89.     return;
  90.   
  91.   i = findAppWidget(w);
  92.   if (*aw.apps[i].drop_action)
  93.     XtCallActionProc(w, "highlight", event, NULL, 0);
  94. }
  95.  
  96. /*---------------------------------------------------------------------------*/
  97.  
  98. void runApp(Widget w, XEvent *event, String *params, Cardinal *num_params)
  99. {
  100.   int i;
  101.   char **argv;
  102.   char directory[MAXPATHLEN];
  103.  
  104.   i = findAppWidget(w);
  105.   strcpy(directory, aw.apps[i].directory);
  106.   if (*directory)
  107.     fnexpand(directory);
  108.   else
  109.     strcpy(directory, user.home);
  110.  
  111.   if (*aw.apps[i].push_action)
  112.     if (!strcmp(aw.apps[i].push_action, "EDIT"))
  113.       doEdit(directory, aw.apps[i].fname);
  114.     else if (!strcmp(aw.apps[i].push_action, "OPEN")) {
  115.       int l = strlen(directory);
  116.       if (directory[l-1] != '/')
  117.     directory[l++] = '/';
  118.       strcpy(directory+l, aw.apps[i].fname);
  119.       newFileWindow(directory, resources.default_display_type,
  120.             False);
  121.     } else if (!strcmp(aw.apps[i].push_action, "LOAD")) {
  122.       int j, l = strlen(directory);
  123.       zzz();
  124.       if (resources.auto_save && aw.modified)
  125.     writeApplicationData(resources.app_file);
  126.       strcpy(resources.app_file, directory);
  127.       if (resources.app_file[l-1] != '/')
  128.     resources.app_file[l++] = '/';
  129.       strcpy(resources.app_file+l, aw.apps[i].fname);
  130.       for(j=0; j<aw.n_apps; j++)
  131.     freeApplicationResources(&aw.apps[j]);
  132.       XTFREE(aw.apps);
  133.       readApplicationData(resources.app_file);
  134.       updateApplicationDisplay();
  135.       wakeUp();
  136.     } else {
  137.       char *action = varPopup(aw.apps[i].icon_bm, aw.apps[i].push_action);
  138.       if (!action) return;
  139.       if (*aw.apps[i].fname)
  140.     argv = makeArgv2(action, aw.apps[i].fname);
  141.       else
  142.     argv = makeArgv(action);
  143.       executeApplication(user.shell, directory, argv);
  144.       freeArgv(argv);
  145.     }
  146. }
  147.  
  148. /*---------------------------------------------------------------------------*/
  149.  
  150. void appEndMove(int i)
  151. {
  152.   char **argv;
  153.  
  154.   if (*aw.apps[i].drop_action) {
  155.     char *action = varPopup(aw.apps[i].icon_bm, aw.apps[i].drop_action);
  156.     if (!action) return;
  157.     if (*aw.apps[i].fname) {
  158.       int l;
  159.       char path[MAXPATHLEN];
  160.       strcpy(path, aw.apps[i].directory);
  161.       if (*path)
  162.     fnexpand(path);
  163.       else
  164.     strcpy(path, user.home);
  165.       l = strlen(path);
  166.       if (path[l-1] != '/')
  167.     path[l++] = '/';
  168.       strcpy(path+l, aw.apps[i].fname);
  169.       argv = makeArgv2(action, path);
  170.     } else
  171.       argv = makeArgv(action);
  172.     argv = expandArgv(argv);
  173.     executeApplication(user.shell, move_info.fw->directory, argv);
  174.     freeArgv(argv);
  175.   }
  176. }
  177.  
  178. /*---------------------------------------------------------------------------*/
  179.  
  180. void appEndMoveInBox(void)
  181. {
  182.   int i;
  183.  
  184.   for (i=0; i<move_info.fw->n_files; i++)
  185.     if (move_info.fw->files[i]->selected) {
  186.       if (S_ISDIR(move_info.fw->files[i]->stats.st_mode)) {
  187.     installApplication(move_info.fw->files[i]->name,
  188.                move_info.fw->directory,
  189.                move_info.fw->files[i]->name,
  190.                "",
  191.                "OPEN",
  192.                "");
  193.       } else if (move_info.fw->files[i]->stats.st_mode &
  194.          (S_IXUSR | S_IXGRP | S_IXOTH)) {
  195.     char *push_action, *drop_action;
  196.     push_action = move_info.fw->files[i]->name;
  197.     drop_action = alloca(strlen(push_action)+4);
  198.     strcpy(drop_action, push_action);
  199.     strcat(drop_action, " $*");
  200.     installApplication(move_info.fw->files[i]->name,
  201.                move_info.fw->directory,
  202.                "",
  203.                "",
  204.                push_action,
  205.                drop_action);
  206.       } else if (move_info.fw->files[i]->type) {
  207.     installApplication(move_info.fw->files[i]->name,
  208.                move_info.fw->directory,
  209.                move_info.fw->files[i]->name,
  210.                move_info.fw->files[i]->type->icon,
  211.                move_info.fw->files[i]->type->push_action,
  212.                move_info.fw->files[i]->type->drop_action);
  213.       } else {
  214.     installApplication(move_info.fw->files[i]->name,
  215.                move_info.fw->directory,
  216.                move_info.fw->files[i]->name,
  217.                "",
  218.                "EDIT",
  219.                "");
  220.       }
  221.     }
  222.   updateApplicationDisplay();
  223. }
  224.  
  225. /*---------------------------------------------------------------------------*/
  226.  
  227. void appSelect(Widget w, XEvent *event, String *params, Cardinal *num_params)
  228. {
  229.   int i, j;
  230.   Pixel back, fore;
  231.   
  232.   j = findAppWidget(w);
  233.   if (j == -1) {
  234.     error("Internal error:", "widget not found in appSelect");
  235.     return;
  236.   }
  237.   
  238.   for (i=0; i<aw.n_apps; i++)
  239.     if (aw.apps[i].selected) {
  240.       XtVaGetValues(aw.apps[i].toggle, XtNbackground, &back, NULL);
  241.       XtVaSetValues(aw.apps[i].toggle, XtNborder, (XtArgVal) back, NULL);
  242.       aw.apps[i].selected = False;
  243.     }
  244.  
  245.   XtVaGetValues(w, XtNforeground, &fore, NULL);
  246.   XtVaSetValues(w, XtNborder, (XtArgVal) fore, NULL);
  247.   
  248.   aw.apps[j].selected = True;
  249.   aw.n_selections = 1;
  250. }
  251.  
  252. /*---------------------------------------------------------------------------*/
  253.  
  254. void appToggle(Widget w, XEvent *event, String *params, Cardinal *num_params)
  255. {
  256.   int i;
  257.   Pixel pix;
  258.   
  259.   i = findAppWidget(w);
  260.   if (i == -1) {
  261.     error("Internal error:", "widget not found in appToggle");
  262.     return;
  263.   }
  264.   
  265.   XtVaGetValues(w, aw.apps[i].selected?XtNbackground:XtNforeground, &pix,
  266.         NULL);
  267.   XtVaSetValues(w, XtNborder, (XtArgVal) pix, NULL);
  268.   
  269.   aw.apps[i].selected = !aw.apps[i].selected;
  270.   if (aw.apps[i].selected)
  271.     aw.n_selections++;
  272.   else
  273.     aw.n_selections--;
  274. }
  275.  
  276.