Subject: patch: basing menustyles on other menustyles

From: Pekka Marjola <[email-masked]>
Date: 11 Oct 1999 13:07:26 +0300

At least previously it was not possible to base menustyles on other
menustyle. I wanted to do that instead of copying the whole menu
specification, so here's a patch. Someone should review it before
patching, especially frees. Applies to CVS source updated this morning
(EET).

Tested it like this:

MenuStyle * Foreground White, Background Blue
MenuStyle Foo Foreground Red, Background Black
MenuStyle Bar Foreground Red, Background Black
MenuStyle Bar UseMenuStyle *, Background Green

AddToMenu T1 "T1" Title
+		       "Icons"	      WindowList OnlyIcons, Alphabetic
+		       "All"	      WindowList Alphabetic

AddToMenu T2 "T2" Title
+		       "Icons"	      WindowList OnlyIcons, Alphabetic
+		       "All"	      WindowList Alphabetic

ChangeMenuStyle Foo T1
ChangeMenuStyle Bar T2

Mouse 2	R    	A      	Menu T1
Mouse 3 R	A	Menu T2

1999-10-11  Pekka Marjola  <[email-masked]>

       * fvwm/menus.c (NewMenuStyle):
       * fvwm/fvwm2.1:
       Added new option UseManuStyle to MenuStyle command.

--- fvwm2.1.orig    Mon Oct 11 12:48:31 1999
+++ fvwm2.1     Mon Oct 11 12:53:18 1999
@@ -1107,7 +1107,8 @@
 ItemFormat,
 VerticalItemSpacing,
 VerticalTitleSpacing,
-AutomaticHotkeys / AutomaticHotkeysOff.
+AutomaticHotkeys / AutomaticHotkeysOff,
+UseMenuStyle.
 
 In the above list some options are listed as option pairs or triples
 with a / in between. These options exclude each other.
@@ -1441,6 +1442,11 @@
 each menu item's label. This behavior is always overridden if an
 explicit hotkey is assigned in the AddToMenu command.
 
+\fUseMenuStyle\fP copies all menustyle options from given style to
+current style deleting all existing style information. This can be
+used to base styles on other styles by further modifying the style
+copied from old style.
+
 Examples:
 
 .EX
@@ -1459,6 +1465,9 @@
 MenuStyle red HilightBackOff, Hilight3DOff
 MenuStyle red Font lucidasanstypewriter-12
 MenuStyle red MenuFace DGradient 64 Red Black
+
+MenuStyle whitered UseStyle red
+MenuStyle whitered Foreground white
 .EE
 
 Note that all style options could be placed on a single line for each
--- menus.c.orig    Mon Oct 11 11:07:43 1999
+++ menus.c     Mon Oct 11 12:40:30 1999
@@ -5218,6 +5218,7 @@
     "VerticalItemSpacing",
     "VerticalTitleSpacing",
     "MenuColorset", "ActiveColorset", "GreyedColorset",
+    "UseMenuStyle",
     NULL
   };
   return GetTokenIndex(option, optlist, 0, NULL);
@@ -5231,8 +5232,10 @@
   char *nextarg;
   char *args = NULL;
   char *arg1;
+  char *oldstyle = NULL;
   MenuStyle *ms;
   MenuStyle *tmpms;
+  MenuStyle *oldms;
   Bool is_initialised = True;
   Bool has_gc_changed = False;
   Bool is_default_style = False;
@@ -5758,6 +5761,58 @@
       }
       has_gc_changed = True;
       break;
+    case 49: /* UseMenuStyle */
+      if (GetQuotedString(arg1, &oldstyle, ",", NULL, NULL, NULL) == 0)
+       fvwm_msg(ERR,"NewMenuStyle",
+                "UseMenuStyle requires one argument");
+      else
+      {
+       if (!(oldms = FindMenuStyle(oldstyle)))
+         fvwm_msg(WARN, "NewMenuStyle", "Couldn't find menustyle %s", oldstyle);
+       else
+       {
+         printf("Got UseMenuStyle %s\n", oldstyle);
+         name = ST_NAME(tmpms);
+
+         /* free all structures */
+         FreeColors(&ST_MENU_COLORS(tmpms).fore, 1);
+         FreeColors(&ST_MENU_COLORS(tmpms).back, 1);
+         if (ST_HAS_STIPPLE_FORE(tmpms))
+           FreeColors(&ST_MENU_STIPPLE_COLORS(tmpms).fore, 1);
+         if (ST_HAS_ACTIVE_BACK(tmpms))
+           FreeColors(&ST_MENU_ACTIVE_COLORS(tmpms).back, 1);
+         if (ST_HAS_ACTIVE_FORE(tmpms))
+           FreeColors(&ST_MENU_ACTIVE_COLORS(tmpms).fore, 1);
+         if (ST_PSTDFONT(tmpms) && ST_PSTDFONT(tmpms) != &Scr.StdFont)
+         {
+#ifdef I18N_MB
+           if (ST_PSTDFONT(tmpms)->fontset)
+             XFreeFontSet(dpy, ST_PSTDFONT(tmpms)->fontset);
+#else
+           if (ST_PSTDFONT(tmpms)->font)
+             XFreeFont(dpy, ST_PSTDFONT(tmpms)->font);
+#endif
+           free(ST_PSTDFONT(tmpms));
+         }
+
+         if (ST_ITEM_FORMAT(tmpms))
+         {
+           free(ST_ITEM_FORMAT(tmpms));
+           ST_ITEM_FORMAT(tmpms) = NULL;
+         }
+         if (ST_HAS_SIDE_COLOR(tmpms) == 1)
+          {
+           FreeColors(&ST_SIDE_COLOR(tmpms), 1);
+           ST_HAS_SIDE_COLOR(tmpms) = 0;
+         }
+
+         memcpy(tmpms, oldms, sizeof(MenuStyle));
+         ST_NAME(tmpms) = name;
+       }
+      }
+      if (oldstyle)            /* Do I need to check NULL? */
+       free(oldstyle);
+      break;
 
 #if 0
     case 99: /* PositionHints */

-- 
Pekka Marjola * [email-masked] * http://www.iki.fi/pema/ * PGPid 0x2865206D 
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]

---

From: Dominik Vogt <[email-masked]>
Date: Mon, 11 Oct 1999 12:59:59 +0200

> +		       "All"	      WindowList Alphabetic

[snip]

> +         memcpy(tmpms, oldms, sizeof(MenuStyle));
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Uh, oh, you can't simply copy one menu style over the other.  If some
style with allocated memory changes in one of the two styles fvwm
will coredump as soon as the other style is used because it still
accesses the freed memory.  All allocated aread have to be duplicated
in a different memory area.

Bye

Dominik ^_^

--
Dominik Vogt, [email-masked]
Reply-To: [email-masked]
--
Visit the official FVWM web page at <URL:http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm-workers" in the
body of a message to [email-masked].
To report problems, send mail to [email-masked]