Adding an example to check scrolled window theming. Adding hildon_caption_set_label_m...
authorMichael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
Fri, 2 Mar 2007 15:00:42 +0000 (15:00 +0000)
committerMichael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
Fri, 2 Mar 2007 15:00:42 +0000 (15:00 +0000)
ChangeLog.2
examples/Makefile.am
examples/hildon-caption-example.c
examples/hildon-scrolled-window-example.c [new file with mode: 0644]
src/hildon-caption.c
src/hildon-caption.h

index dfbeda0..0492a37 100644 (file)
@@ -1,3 +1,14 @@
+2007-03-02  Michael Dominic Kostrzewa  <michael.kostrzewa@nokia.com> 
+
+       * examples/Makefile.am:
+       * examples/hildon-caption-example.c:
+       * examples/hildon-scrolled-window-example.c: Adding an example to
+       check scrolled window theming.
+
+       * src/hildon-caption.c:
+       * src/hildon-caption.h: Adding hildon_caption_set_label_markup to set
+       markup on the caption. Fixes NB#51736.
+
 2007-03-01  Michael Dominic Kostrzewa  <michael.kostrzewa@nokia.com> 
 
        * src/hildon-banner.c: Small fix, check for NULL before comparing
index 049e741..ade790e 100644 (file)
@@ -24,7 +24,8 @@ noinst_PROGRAMS                               = hildon-window-example                 \
                                          hildon-code-dialog-example            \
                                          hildon-hvolumebar-example             \
                                          hildon-lookup-example                 \
-                                         hildon-number-editor-example
+                                         hildon-number-editor-example          \
+                                         hildon-scrolled-window-example
 
 # HIldon window
 hildon_window_example_LDADD            = $(HILDON_OBJ_LIBS)
@@ -146,4 +147,9 @@ hildon_number_editor_example_LDADD  = $(HILDON_OBJ_LIBS)
 hildon_number_editor_example_CFLAGS    = $(HILDON_OBJ_CFLAGS)
 hildon_number_editor_example_SOURCES   = hildon-number-editor-example.c
 
+# Hildon scrolled window
+hildon_scrolled_window_example_LDADD   = $(HILDON_OBJ_LIBS)
+hildon_scrolled_window_example_CFLAGS  = $(HILDON_OBJ_CFLAGS)
+hildon_scrolled_window_example_SOURCES = hildon-scrolled-window-example.c
+
 endif
index 4a46483..82e8762 100644 (file)
@@ -46,15 +46,18 @@ main                                            (int argc,
                                               gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON), 0);
     GtkWidget *caption4 = hildon_caption_new (size_group, "Check caption", gtk_check_button_new (), 
                                               gtk_image_new_from_stock (GTK_STOCK_OK, GTK_ICON_SIZE_BUTTON), 0);
-
+    GtkWidget *caption5 = hildon_caption_new (size_group, "", gtk_entry_new (), 
+                                              NULL, 0);
 
     hildon_caption_set_icon_position (HILDON_CAPTION (caption2), HILDON_CAPTION_POSITION_LEFT);
     hildon_caption_set_icon_position (HILDON_CAPTION (caption3), HILDON_CAPTION_POSITION_RIGHT);
+    hildon_caption_set_label_markup (HILDON_CAPTION (caption5), "<b>Bold caption</b>");
     
     gtk_box_pack_start (GTK_BOX (dialog->vbox), caption1, FALSE, FALSE, 0);
     gtk_box_pack_start (GTK_BOX (dialog->vbox), caption2, FALSE, FALSE, 0);
     gtk_box_pack_start (GTK_BOX (dialog->vbox), caption3, FALSE, FALSE, 0);
     gtk_box_pack_start (GTK_BOX (dialog->vbox), caption4, FALSE, FALSE, 0);
+    gtk_box_pack_start (GTK_BOX (dialog->vbox), caption5, FALSE, FALSE, 0);
 
     gtk_dialog_add_button (dialog, "Close", GTK_RESPONSE_CLOSE);
 
diff --git a/examples/hildon-scrolled-window-example.c b/examples/hildon-scrolled-window-example.c
new file mode 100644 (file)
index 0000000..77402b3
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * This file is a part of hildon examples
+ *
+ * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
+ *
+ * Author: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; version 2.1 of
+ * the License.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include                                        <stdio.h>
+#include                                        <stdlib.h>
+#include                                        <glib.h>
+#include                                        <gtk/gtk.h>
+#include                                        "hildon.h"
+
+int
+main                                            (int argc, 
+                                                 char **args)
+{
+    gtk_init (&argc, &args);
+    
+    HildonProgram *program = hildon_program_get_instance ();
+
+    GtkWidget *window = hildon_window_new ();
+    hildon_program_add_window (program, HILDON_WINDOW (window));    
+
+    gtk_container_set_border_width (GTK_CONTAINER (window), 6);
+
+    GtkWidget *scrolled_window = gtk_scrolled_window_new (NULL, NULL);
+    GtkWidget *vbox = gtk_vbox_new (6, FALSE);
+    int i = 0;
+
+    for (i = 0; i < 20; i++) {
+        gchar *str = g_strdup_printf ("This is one more line of %d", i);
+        GtkWidget *label = gtk_label_new (str);
+        gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+        g_free (str);
+    }
+
+    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window), GTK_SHADOW_IN);
+    gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), vbox);
+
+    gtk_container_add (GTK_CONTAINER (window), scrolled_window);
+    
+    g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
+    gtk_widget_show_all (GTK_WIDGET (window));
+    
+    gtk_main ();
+    return 0;
+}
+
+
index 74f754c..a1bf348 100644 (file)
@@ -118,7 +118,8 @@ hildon_caption_button_press                     (GtkWidget *widget,
                                                  GdkEventButton *event);
 
 static void
-hildon_caption_set_label_text                   (HildonCaptionPrivate *priv);
+hildon_caption_set_label_text                   (HildonCaptionPrivate *priv, 
+                                                 gboolean markup);
 
 static void 
 hildon_caption_set_child_property               (GtkContainer *container,
@@ -138,6 +139,7 @@ enum
 {
     PROP_0,
     PROP_LABEL,
+    PROP_MARKUP,
     PROP_ICON,
     PROP_STATUS,
     PROP_SEPARATOR,
@@ -232,6 +234,16 @@ hildon_caption_class_init                       (HildonCaptionClass *caption_cla
             g_param_spec_string ("label",
                 "Current label", "Caption label",
                 NULL, G_PARAM_READABLE | G_PARAM_WRITABLE) );
+    
+    /**
+     * HildonCaption:markup:
+     *
+     * Caption markup. Mutually exclusive with label.
+     */
+    g_object_class_install_property (gobject_class, PROP_MARKUP,
+            g_param_spec_string ("markup",
+                "Current markup", "Caption markup",
+                NULL, G_PARAM_WRITABLE) );
 
     /**
      * HildonCaption:icon:
@@ -408,7 +420,20 @@ hildon_caption_set_property                     (GObject *object,
 
             /* Update label */
             priv->text = g_value_dup_string (value);
-            hildon_caption_set_label_text (priv);
+            hildon_caption_set_label_text (priv, FALSE);
+            break;
+
+        case PROP_MARKUP:
+            /* Free old label string */
+            if (priv->text)
+            {
+                g_free (priv->text);
+                priv->text = NULL;
+            }
+
+            /* Update label */
+            priv->text = g_value_dup_string (value);
+            hildon_caption_set_label_text (priv, TRUE);
             break;
 
         case PROP_ICON:
@@ -453,7 +478,7 @@ hildon_caption_set_property                     (GObject *object,
             }
 
             priv->separator = g_value_dup_string (value);
-            hildon_caption_set_label_text (priv);
+            hildon_caption_set_label_text (priv, FALSE);
             break;
 
         default:
@@ -1036,12 +1061,30 @@ void
 hildon_caption_set_label                        (HildonCaption *caption, 
                                                  const gchar *label)
 {
-    g_return_if_fail (HILDON_IS_CAPTION(caption));
+    g_return_if_fail (HILDON_IS_CAPTION (caption));
 
     g_object_set (G_OBJECT(caption), "label", label, NULL);
 }
 
 /**
+ * hildon_caption_set_label_markup:
+ * @caption : a #HildonCaption
+ * @markup : the markup text to use
+ *
+ * Sets the label markup text that appears before the control. It acts like
+ * #hildon_caption_set_label but is using the markup text that allows to specify
+ * text properties such as bold or italic.
+ */
+void 
+hildon_caption_set_label_markup                 (HildonCaption *caption, 
+                                                 const gchar *markup)
+{
+    g_return_if_fail (HILDON_IS_CAPTION (caption));
+
+    g_object_set (G_OBJECT(caption), "markup", markup, NULL);
+}
+
+/**
  * hildon_caption_get_label:
  * @caption : a #HildonCaption
  *
@@ -1172,7 +1215,8 @@ hildon_caption_get_child_expand                 (const HildonCaption *caption)
 }
 
 static void
-hildon_caption_set_label_text                   (HildonCaptionPrivate *priv)
+hildon_caption_set_label_text                   (HildonCaptionPrivate *priv, 
+                                                 gboolean markup)
 {
     gchar *tmp = NULL;
     g_assert (priv != NULL);
@@ -1184,27 +1228,40 @@ hildon_caption_set_label_text                   (HildonCaptionPrivate *priv)
             /* Don't duplicate the separator, if the string already contains one */
             if (g_str_has_suffix (priv->text, priv->separator))
             {
-                gtk_label_set_text (GTK_LABEL (priv->label), priv->text);
+                if (markup)
+                    gtk_label_set_markup (GTK_LABEL (priv->label), priv->text);
+                else
+                    gtk_label_set_text (GTK_LABEL (priv->label), priv->text);
             }
             else
             {
                 /* Append separator and set text */
                 tmp = g_strconcat( priv->text, priv->separator, NULL );
-                gtk_label_set_text (GTK_LABEL( priv->label), tmp);
+                
+                if (markup)
+                    gtk_label_set_markup (GTK_LABEL (priv->label), tmp);
+                else
+                    gtk_label_set_text (GTK_LABEL (priv->label), tmp);
+
                 g_free (tmp);
             }
         }
         else
         {
-            gtk_label_set_text (GTK_LABEL (priv->label), priv->text);
+            if (markup) 
+                gtk_label_set_markup (GTK_LABEL (priv->label), priv->text);
+            else
+                gtk_label_set_text (GTK_LABEL (priv->label), priv->text);
         }
     }
     else
     {
         /* Clear the label */
-        gtk_label_set_text (GTK_LABEL (priv->label), "" );
+        if (markup)
+            gtk_label_set_markup (GTK_LABEL (priv->label), "");
+        else
+            gtk_label_set_text (GTK_LABEL (priv->label), "" );
     }
-
 }
 
 /**
index 4626f87..c561815 100644 (file)
@@ -161,6 +161,10 @@ hildon_caption_set_child_expand                 (HildonCaption *caption,
 gboolean 
 hildon_caption_get_child_expand                 (const HildonCaption *caption);
 
+void
+hildon_caption_set_label_markup                 (HildonCaption *caption,
+                                                 const gchar *markup);
+
 G_END_DECLS
 
 #endif                                          /* __HILDON_CAPTION_H__ */