xvaction.c 2.9 KB

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