home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / file / managers / mc-3.2 / mc-3 / mc-3.2.1 / xv / xvaction.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  2.9 KB  |  113 lines

  1. /* XView Action Icons (for Drag and Drop).
  2.    Copyright (C) 1995 Jakub Jelinek.
  3.    
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2 of the License, or
  7.    (at your option) any later version.
  8.    
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include <config.h>
  19.  
  20. #include <stdlib.h>
  21. #include "setup.h"
  22. #include "profile.h"
  23. #include "xvmain.h"
  24.  
  25. #ifdef HAVE_XPM_SHAPE
  26. #include "xvicon.h"
  27.  
  28. extern char *regex_command_title;
  29.  
  30. extern Display *dpy;
  31.  
  32. void add_action_icon (char *filename, char *geometry)
  33. {
  34.     char *iconname, *title, *p, *base = x_basename (filename);
  35.     int x, y, z;
  36.     XpmIcon *icon;
  37.  
  38.     iconname = regex_command (base, "Icon", NULL);
  39.     if (iconname == NULL)
  40.         iconname = strdup ("file.xpm");
  41.     if (*iconname != '/') {
  42.         p = copy_strings (ICONDIR, iconname, NULL);
  43.         free (iconname);
  44.         iconname = p;
  45.     }
  46.     title = regex_command_title;
  47.     if (title == NULL)
  48.         title = strdup (base);
  49.     else {
  50.         char *q, *r;
  51.         
  52.         y = strlen (filename);
  53.         z = strlen (base);
  54.         for (q = title, x = 1; *q; q++, x++)
  55.             if (*q == '%') {
  56.                 if (q [1] == 'p')
  57.             x += z - 2;
  58.         else if (q [1] == 'd')
  59.             x += y - 2;
  60.         }
  61.     r = xmalloc (x, "Icon Title");
  62.     for (q = title, p = r; *q; q++, p++)
  63.             if (*q == '%') {
  64.                 if (q [1] == 'p') {
  65.             strcpy (p, base);
  66.             p += z - 1;
  67.             q++;
  68.         } else if (q [1] == 'd') {
  69.             strcpy (p, filename);
  70.             p += y - 1;
  71.             q++;
  72.         } else
  73.             *p = *q;
  74.         } else
  75.             *p = *q;
  76.     *p = 0;
  77.     free (title);
  78.     title = r;
  79.     }
  80.     x = atoi (geometry);
  81.     for (p = geometry; *p && (*p < '0' || *p > '9'); p++);
  82.     for (; *p >= '0' && *p <= '9'; p++);
  83.     y = atoi (p);
  84.     icon = CreateXpmIcon (iconname, x, y, title);
  85.     if (icon != NULL) {
  86.         icon->filename = strdup (filename);
  87.     }
  88.     free (iconname);
  89.     free (title);
  90.     XFlush (dpy);
  91.     xv_dispatch_a_bit ();
  92. }
  93. #endif
  94.  
  95. void xv_action_icons (void)
  96. {
  97. #ifdef HAVE_XPM_SHAPE
  98.     char *key, *value;
  99.     void *keys = profile_init_iterator ("Action Icons", profile_name);
  100.  
  101.     xv_dispatch_a_bit ();
  102.     if (keys == NULL) {
  103.         add_action_icon ("/bin/rm", "+45+100");
  104.         add_action_icon ("/usr/bin/lpr", "+45+160");
  105.     }
  106.     
  107.     while (keys != NULL) {
  108.         keys = profile_iterator_next (keys, &key, &value);
  109.         add_action_icon (key, value);
  110.     }
  111. #endif
  112. }
  113.