Replace size-request by minimal height-for-width
[projects/chimara/chimara.git] / libchimara / chimara-glk.c
index b7c0a7d6f3df2f9290ed5e459ea02d9c481b9e26..bb2758a68c9a32f3d5c52947da9240ccfa5a5f03 100644 (file)
@@ -148,7 +148,8 @@ enum {
        PROP_SPACING,
        PROP_PROGRAM_NAME,
        PROP_PROGRAM_INFO,
-       PROP_STORY_NAME
+       PROP_STORY_NAME,
+       PROP_RUNNING
 };
 
 enum {
@@ -170,6 +171,8 @@ G_DEFINE_TYPE(ChimaraGlk, chimara_glk, GTK_TYPE_CONTAINER);
 static void
 chimara_glk_init(ChimaraGlk *self)
 {
+       chimara_init(); /* This is a library entry point */
+
     gtk_widget_set_has_window(GTK_WIDGET(self), FALSE);
 
     ChimaraGlkPrivate *priv = CHIMARA_GLK_PRIVATE(self);
@@ -267,6 +270,9 @@ chimara_glk_get_property(GObject *object, guint prop_id, GValue *value, GParamSp
                case PROP_STORY_NAME:
                        g_value_set_string(value, priv->story_name);
                        break;
+               case PROP_RUNNING:
+                       g_value_set_boolean(value, priv->running);
+                       break;
                default:
             G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
     }
@@ -403,7 +409,9 @@ request_recurse(winid_t win, GtkRequisition *requisition, guint spacing)
                gtk_widget_size_request(win->frame, requisition);
 }
 
-/* Overrides gtk_widget_size_request */
+/* Old GTK 2 functionality overriding gtk_widget_size_request();
+get_preferred_width() and get_preferred_height() are implemented in terms of
+this function. */
 static void
 chimara_glk_size_request(GtkWidget *widget, GtkRequisition *requisition)
 {
@@ -428,6 +436,36 @@ chimara_glk_size_request(GtkWidget *widget, GtkRequisition *requisition)
     }
 }
 
+/* Minimal implementation of width-for-height request, in terms of the old
+GTK 2 mechanism. FIXME: make this more efficient. */
+static void
+chimara_glk_get_preferred_width(GtkWidget *widget, int *minimal, int *natural)
+{
+    g_return_if_fail(widget || CHIMARA_IS_GLK(widget));
+    g_return_if_fail(minimal);
+    g_return_if_fail(natural);
+
+    GtkRequisition requisition;
+
+    chimara_glk_size_request(widget, &requisition);
+    *minimal = *natural = requisition.width;
+}
+
+/* Minimal implementation of height-for-width request, in terms of the old
+GTK 2 mechanism. FIXME: make this more efficient. */
+static void
+chimara_glk_get_preferred_height(GtkWidget *widget, int *minimal, int *natural)
+{
+    g_return_if_fail(widget || CHIMARA_IS_GLK(widget));
+    g_return_if_fail(minimal);
+    g_return_if_fail(natural);
+
+    GtkRequisition requisition;
+
+    chimara_glk_size_request(widget, &requisition);
+    *minimal = *natural = requisition.height;
+}
+
 /* Recursively give the Glk windows their allocated space. Returns a window
  containing all children of this window that must be redrawn, or NULL if there 
  are no children that require redrawing. */
@@ -751,7 +789,8 @@ chimara_glk_class_init(ChimaraGlkClass *klass)
     object_class->finalize = chimara_glk_finalize;
     
     GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
-    widget_class->size_request = chimara_glk_size_request;
+    widget_class->get_preferred_width = chimara_glk_get_preferred_width;
+    widget_class->get_preferred_height = chimara_glk_get_preferred_height;
     widget_class->size_allocate = chimara_glk_size_allocate;
 
     GtkContainerClass *container_class = GTK_CONTAINER_CLASS(klass);
@@ -947,6 +986,17 @@ chimara_glk_class_init(ChimaraGlkClass *klass)
                NULL,
                G_PARAM_READABLE | G_PARAM_STATIC_STRINGS) );
        
+       /**
+        * ChimaraGlk:running:
+        *
+        * Whether this Glk widget is currently running a game or not.
+        */
+       g_object_class_install_property(object_class, PROP_RUNNING,
+               g_param_spec_boolean("running", _("Running"),
+               _("Whether there is a program currently running"),
+               FALSE,
+               G_PARAM_READABLE | G_PARAM_STATIC_STRINGS) );
+
        /* Private data */
     g_type_class_add_private(klass, sizeof(ChimaraGlkPrivate));
 }