Subject: FvwmButtons patch for changing icons

From: Tim Phipps <[email-masked]>
Date: Thu, 07 Feb 2002 12:19:44 +0000

Hi All,
	Another patch, this one adds the ability to do

SendToModule FvwmButtons Icon 7 AIcons/appl/mail/xmail_new.xpm

No documentation yet since I'm not sure if this syntax is any good.

Cheers,
Tim.
Index: modules/FvwmButtons/FvwmButtons.c
===================================================================
RCS file: /u/phippst/share/cvsroot/fvwm/modules/FvwmButtons/FvwmButtons.c,v
retrieving revision 1.19
diff -u -r1.19 FvwmButtons.c
--- modules/FvwmButtons/FvwmButtons.c	2002/02/04 09:37:14	1.19
+++ modules/FvwmButtons/FvwmButtons.c	2002/02/07 11:34:35
@@ -3084,16 +3084,59 @@
 }
 
 /* SendToModule options */
-static void parse_title(char *line)
+static void change_title(button_info *b, char *line)
 {
+  if (!(b->flags & b_Title)) {
+    fprintf(stderr, "%s: cannot create a title, only change one\n", MyName);
+    return;
+  }
+  free(b->title);
+  CopyString(&b->title, line);
+  RedrawButton(b, 2);
+  return;  
+}
+
+static void change_icon(button_info *b, char *line)
+{
+  Picture *new_icon;
+  if (!(b->flags & b_Icon)) {
+    fprintf(stderr, "%s: cannot create an icon, only change one\n", MyName);
+    return;
+  }
+  if (LoadIconFile(line, &new_icon) == 0) {
+    fprintf(stderr, "%s: cannot load icon %s\n", MyName, line);
+    return;
+  }
+  free(b->icon_file);
+  CopyString(&b->icon_file, line);
+  DestroyPicture(Dpy, b->icon);
+  XDestroyWindow(Dpy, b->IconWin);
+  b->IconWin = None;
+  b->icon = new_icon;
+  CreateIconWindow(b);
+  ConfigureIconWindow(b);
+  XMapWindow(Dpy, b->IconWin);
+  RedrawButton(b, 2);
+  return;  
+}
+
+static char *message_options[] = {"Title", "Icon", NULL};
+
+void parse_message_line(char *line)
+{
+  char *rest;
+  int type;
   int n, count, i;
   button_info *b, *ub = UberButton;
 
-  /* find out which button */
-  if (GetIntegerArguments(line, &line, &n, 1) != 1)
+  type = GetTokenIndex(line, message_options, -1, &rest);
+  if (type == -1) {
+    fprintf(stderr, "%s: Message not understood: %s\n", MyName, line);
     return;
-  if (n < 0)
-  {
+  }
+  
+  /* find out which button */
+  if (GetIntegerArguments(rest, &rest, &n, 1) != 1 || n < 0) {
     fprintf(stderr, "%s: button number must not be negative\n", MyName);
     return;
   }
@@ -3103,31 +3146,17 @@
     if (++count == n)
       break;
   }
-  if (count != n) {
+  if (count != n || b == NULL) {
     fprintf(stderr, "%s: button number %d not found\n", MyName, n);
     return;
-  }
-  if (b) {
-    if (!b->flags & b_Title) {
-      fprintf(stderr, "%s: cannot create a title, only change one\n", MyName);
-      return;
-    }
-    free(b->title);
-    CopyString(&b->title, line);
-    RedrawButton(b, 2);
   }
-  return;  
-}
-
-static char *message_options[] = {"Title", NULL};
-
-void parse_message_line(char *line)
-{
-  char *rest;
-
-  switch(GetTokenIndex(line, message_options, -1, &rest)) {
+  
+  switch(type) {
   case 0:
-    parse_title(rest);
+    change_title(b, rest);
+    break;
+  case 1:
+    change_icon(b, rest);
     break;
   }
 }