Index: gok/gok-key.c
===================================================================
RCS file: /cvs/gnome/gok/gok/gok-key.c,v
retrieving revision 1.46
diff -u -r1.46 gok-key.c
--- gok/gok-key.c	4 Mar 2003 17:05:58 -0000	1.46
+++ gok/gok-key.c	11 Mar 2003 01:35:59 -0000
@@ -32,6 +32,7 @@
 #include "gok-feedback.h"
 #include "gok-data.h"
 #include "gok-branchback-stack.h"
+#include "gok-modifier-keymasks.h"
 
 gchar m_TextEmpty[]="";
 
@@ -76,6 +77,14 @@
 		g_free (str);
 		str = "Mute";
 	}
+	else if (!strcmp (str, "Pointer\nEnableKeys")) {
+		g_free (str);
+		str = "Mouse\nKeys";
+	}
+	else if (!strcmp (str, "ISO_Left\nTab")) {
+		g_free (str);
+		str = "Left\nTab";
+	}
 	else {
 		gint len;
 		gboolean prev_is_lower, is_upper;
@@ -136,14 +145,26 @@
 	return cp;
 }
 
-static unsigned int
+static unsigned int _numlock_mask = 0xFFFF;
+
+unsigned int
 gok_key_get_numlock_mask (Display *display)
 {
-	static unsigned int numlock_mask = 0xFFFF;
-	if (numlock_mask == 0xFFFF) {
-		numlock_mask = XkbKeysymToModifiers (display, XK_Num_Lock);
+	struct gok_modifier_keymask *m;
+
+	if (_numlock_mask == 0xFFFF) {
+		_numlock_mask = XkbKeysymToModifiers (display, XK_Num_Lock);
+		/* 
+		 * FIXME: this should really be taken care of in 
+		 * gok_modifier_add 
+		 */
+		for (m = gok_modifier_keymasks ;m->name != NULL; m++)
+		{
+			if (!strcmp (m->name, "numlock")) 
+				m->keymask = _numlock_mask;
+		}
 	}
-	return numlock_mask;
+	return _numlock_mask;
 }
 
 static int
@@ -249,13 +270,14 @@
 
 /* HACK copies gtk+ */
 #define CHILD_SPACING 1 
+#define BEVEL_WIDTH 1 
 
 gint
 gok_key_get_default_border_width (GokKey *pKey)
 {
 	if (pKey->pButton)
 		return GTK_CONTAINER (pKey->pButton)->border_width + 
-			CHILD_SPACING + 
+			CHILD_SPACING +
 			GTK_WIDGET (pKey->pButton)->style->xthickness;
 	else
 		return 0;
@@ -319,6 +341,7 @@
   XkbBoundsRec *pBounds;
   int width, height, len;
   gboolean is_modifier = FALSE;
+  unsigned int numlock_mask = gok_key_get_numlock_mask (display);
 
   pKey->Top = row;
   pBounds = &pGeom->shapes[keyp->shape_ndx].bounds;
@@ -362,24 +385,19 @@
   gok_keylabel_new (pKey, label, "alt");
   label = gok_key_label_from_keycode (keycode, display, ControlMask, 0);
   gok_keylabel_new (pKey, label, "ctrl");
-  label = gok_key_label_from_keycode (keycode, display, Mod2Mask, 0);
-  gok_keylabel_new (pKey, label, "mod2");
-  label = gok_key_label_from_keycode (keycode, display, Mod2Mask | ShiftMask, 0);
-  gok_keylabel_new (pKey, label, "mod2+shift");
-  label = gok_key_label_from_keycode (keycode, display, Mod2Mask | LockMask, 0);
-  gok_keylabel_new (pKey, label, "mod2+capslock");
+  label = gok_key_label_from_keycode (keycode, display, numlock_mask, 0);
+  gok_keylabel_new (pKey, label, "numlock");
+  label = gok_key_label_from_keycode (keycode, display, numlock_mask | ShiftMask, 0);
+  gok_keylabel_new (pKey, label, "numlock+shift");
+  label = gok_key_label_from_keycode (keycode, display, numlock_mask | LockMask, 0);
+  gok_keylabel_new (pKey, label, "numlock+capslock");
   label = gok_key_label_from_keycode (keycode, display, 
-				      Mod2Mask | LockMask | ShiftMask, 0);
-  gok_keylabel_new (pKey, label, "mod2+capslock+shift");
+				      numlock_mask | LockMask | ShiftMask, 0);
+  gok_keylabel_new (pKey, label, "numlock+capslock+shift");
+  label = gok_key_label_from_keycode (keycode, display, Mod3Mask, 0);
+  gok_keylabel_new (pKey, label, "mod2");
   label = gok_key_label_from_keycode (keycode, display, Mod3Mask, 0);
   gok_keylabel_new (pKey, label, "mod3");
-  label = gok_key_label_from_keycode (keycode, display, Mod3Mask | ShiftMask, 0);
-  gok_keylabel_new (pKey, label, "mod3+shift");
-  label = gok_key_label_from_keycode (keycode, display, Mod3Mask | LockMask, 0);
-  gok_keylabel_new (pKey, label, "mod2+capslock");
-  label = gok_key_label_from_keycode (keycode, display, 
-				      Mod3Mask | LockMask | ShiftMask, 0);
-  gok_keylabel_new (pKey, label, "mod3+capslock+shift");
   label = gok_key_label_from_keycode (keycode, display, Mod4Mask, 0);
   gok_keylabel_new (pKey, label, "mod4");
   label = gok_key_label_from_keycode (keycode, display, Mod5Mask, 0);
@@ -626,6 +644,20 @@
 		pKey->Type = KEYTYPE_POINTERCONTROL;
 		pKey->Style = KEYSTYLE_POINTERCONTROL;
 	}
+	else if (xmlStrcmp (pStringAttributeValue, (const xmlChar *)"move-resize") == 0)
+	{
+		pKey->Type = KEYTYPE_MOVERESIZE;
+		pKey->Style = KEYSTYLE_NORMAL;
+		pKey->pGeneral = g_new0 (GokKeyboardDirection, 1);
+		pStringAttributeValue = 
+			xmlGetProp (pNode, (const xmlChar *) "dir");
+		if (pStringAttributeValue != NULL) 
+		{
+			* (GokKeyboardDirection *) pKey->pGeneral = 
+				gok_keyboard_parse_direction (pStringAttributeValue);
+			g_free (pStringAttributeValue);
+		}
+	}
 
 	/* branch target */
 	pStringAttributeValue = xmlGetProp (pNode, (const xmlChar *) "target");
@@ -945,6 +977,52 @@
 	gok_key_set_button_name (pKey);	
 }
 
+static
+int gok_key_get_label_length (GokKey* pKey)
+{
+	PangoLayout* pPangoLayout;
+	PangoRectangle rectInk;
+	PangoRectangle rectLogical;
+	GtkLabel* pLabel;
+
+	if ((pKey->pButton == NULL) ||
+		(strlen (gok_key_get_label (pKey)) == 0))
+	{
+		return 0;
+	}
+	
+	pLabel = GTK_LABEL(((GokButton*)pKey->pButton)->pLabel);
+	g_assert (pLabel != NULL);
+	
+	pPangoLayout = gtk_label_get_layout (pLabel);
+	pango_layout_get_pixel_extents (pPangoLayout, &rectInk, &rectLogical);
+
+	return (rectLogical.x + MAX (rectLogical.width, rectInk.width));
+}
+
+static
+int gok_key_get_label_height (GokKey* pKey)
+{
+	PangoLayout* pPangoLayout;
+	PangoRectangle rectInk;
+	PangoRectangle rectLogical;
+	GtkLabel* pLabel;
+
+	if ((pKey->pButton == NULL) ||
+		(strlen (gok_key_get_label (pKey)) == 0))
+	{
+		return 0;
+	}
+	
+	pLabel = GTK_LABEL(((GokButton*)pKey->pButton)->pLabel);
+	g_assert (pLabel != NULL);
+	
+	pPangoLayout = gtk_label_get_layout (pLabel);
+	pango_layout_get_pixel_extents (pPangoLayout, &rectInk, &rectLogical);
+	
+	return rectLogical.y + MAX (rectLogical.height, rectInk.height); 
+}
+
 /**
 * gok_key_update_label
 * @pKey: Pointer to the key that gets an updated label.
@@ -978,6 +1056,28 @@
 	{
 		gtk_label_set_text (GTK_LABEL(pButtonLabel), pNewLabelText);
 	}
+
+	/* make sure the label still fits on the key */
+	if ((gok_key_get_label_length (pKey) > 
+	     (gok_data_get_key_width () * 
+	      (pKey->Right - pKey->Left) - 2 * 
+	      gok_key_get_default_border_width (pKey) - 1)) ||
+	     (gok_key_get_label_height (pKey) >
+	      (gok_data_get_key_height () *
+	       (pKey->Bottom - pKey->Top) - 2 *
+	       gok_key_get_default_border_height (pKey) - 1)) )
+	{
+		/* Note that this shrinks the label size for all mod states */
+#ifdef GOK_DEBUG
+		gok_log (stderr, "oversize label %s; group %d, size%d\n", 
+			 pNewLabelText,
+			 pKey->FontSizeGroup,
+			 pKey->FontSize);
+#endif
+		gok_key_set_font_size (pKey,
+				       gok_key_calculate_font_size (pKey, 
+								    TRUE, TRUE));
+	}
 }
 
 /**
@@ -1158,8 +1258,8 @@
 			strcpy (styleText, "StyleTextNormal");
 			break;
 		case KEYSTYLE_BRANCHMODAL:
-			strcpy (styleButton, "StyleButtonDisabled");
-			strcpy (styleText, "StyleTextDisabled");
+			strcpy (styleButton, "StyleButtonBranch");
+			strcpy (styleText, "StyleTextNormal");
 			break;
 	        case KEYSTYLE_BRANCHBACK: 			
 			/* disable the button if we can't branch back */
@@ -1258,52 +1358,6 @@
 	}
 }
 
-static
-int gok_key_get_label_length (GokKey* pKey)
-{
-	PangoLayout* pPangoLayout;
-	PangoRectangle rectInk;
-	PangoRectangle rectLogical;
-	GtkLabel* pLabel;
-
-	if ((pKey->pButton == NULL) ||
-		(strlen (gok_key_get_label (pKey)) == 0))
-	{
-		return 0;
-	}
-	
-	pLabel = GTK_LABEL(((GokButton*)pKey->pButton)->pLabel);
-	g_assert (pLabel != NULL);
-	
-	pPangoLayout = gtk_label_get_layout (pLabel);
-	pango_layout_get_pixel_extents (pPangoLayout, &rectInk, &rectLogical);
-	
-	return (rectLogical.x + rectLogical.width);
-}
-
-static
-int gok_key_get_label_height (GokKey* pKey)
-{
-	PangoLayout* pPangoLayout;
-	PangoRectangle rectInk;
-	PangoRectangle rectLogical;
-	GtkLabel* pLabel;
-
-	if ((pKey->pButton == NULL) ||
-		(strlen (gok_key_get_label (pKey)) == 0))
-	{
-		return 0;
-	}
-	
-	pLabel = GTK_LABEL(((GokButton*)pKey->pButton)->pLabel);
-	g_assert (pLabel != NULL);
-	
-	pPangoLayout = gtk_label_get_layout (pLabel);
-	pango_layout_get_pixel_extents (pPangoLayout, &rectInk, &rectLogical);
-	
-	return rectLogical.y + rectLogical.height; 
-}
-
 /**
 * gok_key_calculate_font_size
 * @pKey: Pointer to the key that we're getting the font size for.
@@ -1351,15 +1405,10 @@
 		/* get the size of a key cell*/
 	        widthCell = gok_data_get_key_width () * 
 		        (pKey->Right - pKey->Left) - 2 * 
-		        gok_key_get_default_border_width (pKey);
+		        gok_key_get_default_border_width (pKey) - 1;
 	
-		increment = 1000;
-		/* 
-		 * TODO: don't exceed the application font size 
-		 * if we're in FONT_SIZE_GROUP_UNIQUE, and
-		 * limit to 1.5 * the application font size for 
-		 * short (e.g. 1 to 2 character) labels.
-		 */
+		increment = 500;
+
 		for (sizeFontWidth = 5000; sizeFontWidth < maxFontSize; sizeFontWidth += increment)
 		{
 			/* set the key label to the trial size */
@@ -1385,7 +1434,11 @@
 			}
 			
 			/* at very large font sizes, increase the increment we increase */
-			if (sizeFontWidth > 50000)
+			if (sizeFontWidth > 9000)
+			{
+				increment = 1000;
+			}
+			else if (sizeFontWidth > 50000)
 			{
 				increment = 2000;
 			}
@@ -1401,12 +1454,12 @@
 	/* now check the cell height */
 	if (bHeight == TRUE)
 	{
-	        increment = 1000;
+	        increment = 500;
 		/* get the size of a key cell*/
 		heightCell = gok_data_get_key_height() - 2 *
-		        gok_key_get_default_border_height (pKey);
+		        gok_key_get_default_border_height (pKey) - 1;
 	
-		for (sizeFontHeight = 5000; sizeFontHeight < 200000; sizeFontHeight += increment)
+		for (sizeFontHeight = 5000; sizeFontHeight < maxFontSize; sizeFontHeight += increment)
 		{
 			/* set the key label to the trial size */
 			gok_key_set_font_size (pKey, sizeFontHeight);
@@ -1431,7 +1484,11 @@
 			}
 			
 			/* at very large font sizes, increase the increment we increase */
-			if (sizeFontHeight > 50000)
+			if (sizeFontHeight > 9000)
+			{
+				increment = 1000;
+			}
+			else if (sizeFontHeight > 50000)
 			{
 				increment = 2000;
 			}
