]> git.sur5r.net Git - glabels/commitdiff
2009-09-07 Jim Evins <evins@snaught.com>
authorJim Evins <evins@snaught.com>
Tue, 8 Sep 2009 03:22:09 +0000 (03:22 +0000)
committerJim Evins <evins@snaught.com>
Tue, 8 Sep 2009 03:22:09 +0000 (03:22 +0000)
Created new glFontCombo widget family subsystem + minor refinements to glColorCombo
widget family.

* src/color-combo-button.c:
* src/color-combo-button.h:
Renamed ColorButton to ColorComboButton.
* src/color.h:
Added GL_COLOR_WHITE macro.
* src/color-combo.c: (gl_color_combo_init):
Minor cleanup.
* src/Makefile.am:
* src/font-combo.c:
* src/font-combo.h:
* src/font-combo-menu.c:
* src/font-combo-menu.h:
* src/font-combo-menu-item.c:
* src/font-combo-menu-item.h:
* src/font-sample.c:
* src/font-sample.h:
* src/font-util.c:
* src/font-util.h:
New FontCombo subsystem.
* src/util.c:
* src/util.h:
Moved font functions to font-util.[ch].
* data/builder/object-editor.builder:
* data/builder/prefs-dialog.builder:
* data/builder/property-bar.builder:
* src/label-text.c: (set_font_family):
* src/object-editor-private.h:
* src/object-editor-text-page.c:
(gl_object_editor_prepare_text_page),
(gl_object_editor_set_font_family),
(gl_object_editor_get_font_family):
* src/prefs-dialog.c: (construct_object_page),
(update_object_page_from_prefs), (update_prefs_from_object_page):
* src/ui-property-bar.c: (gl_ui_property_bar_construct),
(reset_to_default_properties), (update_text_properties),
(update_fill_color), (update_line_color), (font_family_changed_cb),
(text_color_changed_cb), (fill_color_changed_cb),
(line_color_changed_cb):
Incorporated new FontCombo subsystem.
* po/POTFILES.in:
Reconciled with above changes/additions.

git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@872 f5e0f49d-192f-0410-a22d-a8d8700d0965

29 files changed:
glabels2/ChangeLog
glabels2/data/builder/object-editor.builder
glabels2/data/builder/prefs-dialog.builder
glabels2/data/builder/property-bar.builder
glabels2/po/POTFILES.in
glabels2/src/Makefile.am
glabels2/src/color-button.c [deleted file]
glabels2/src/color-button.h [deleted file]
glabels2/src/color-combo-button.c [new file with mode: 0644]
glabels2/src/color-combo-button.h [new file with mode: 0644]
glabels2/src/color-combo.c
glabels2/src/color.h
glabels2/src/font-combo-menu-item.c [new file with mode: 0644]
glabels2/src/font-combo-menu-item.h [new file with mode: 0644]
glabels2/src/font-combo-menu.c [new file with mode: 0644]
glabels2/src/font-combo-menu.h [new file with mode: 0644]
glabels2/src/font-combo.c [new file with mode: 0644]
glabels2/src/font-combo.h [new file with mode: 0644]
glabels2/src/font-sample.c [new file with mode: 0644]
glabels2/src/font-sample.h [new file with mode: 0644]
glabels2/src/font-util.c [new file with mode: 0644]
glabels2/src/font-util.h [new file with mode: 0644]
glabels2/src/label-text.c
glabels2/src/object-editor-private.h
glabels2/src/object-editor-text-page.c
glabels2/src/prefs-dialog.c
glabels2/src/ui-property-bar.c
glabels2/src/util.c
glabels2/src/util.h

index bfc4933d26c8c1565ac8eed2ecabd953447b7f78..dcaaac4d79130ed9eaec1778af5122cbf6304319 100644 (file)
@@ -1,3 +1,50 @@
+2009-09-07  Jim Evins  <evins@snaught.com>
+
+       Created new glFontCombo widget family subsystem + minor refinements to glColorCombo
+       widget family.
+
+       * src/color-combo-button.c:
+       * src/color-combo-button.h:
+               Renamed ColorButton to ColorComboButton.
+       * src/color.h:
+               Added GL_COLOR_WHITE macro.
+       * src/color-combo.c: (gl_color_combo_init):
+               Minor cleanup.
+       * src/Makefile.am:
+       * src/font-combo.c:
+       * src/font-combo.h:
+       * src/font-combo-menu.c:
+       * src/font-combo-menu.h:
+       * src/font-combo-menu-item.c:
+       * src/font-combo-menu-item.h:
+       * src/font-sample.c:
+       * src/font-sample.h:
+       * src/font-util.c:
+       * src/font-util.h:
+               New FontCombo subsystem.
+       * src/util.c:
+       * src/util.h:
+               Moved font functions to font-util.[ch].
+       * data/builder/object-editor.builder:
+       * data/builder/prefs-dialog.builder:
+       * data/builder/property-bar.builder:
+       * src/label-text.c: (set_font_family):
+       * src/object-editor-private.h:
+       * src/object-editor-text-page.c:
+       (gl_object_editor_prepare_text_page),
+       (gl_object_editor_set_font_family),
+       (gl_object_editor_get_font_family):
+       * src/prefs-dialog.c: (construct_object_page),
+       (update_object_page_from_prefs), (update_prefs_from_object_page):
+       * src/ui-property-bar.c: (gl_ui_property_bar_construct),
+       (reset_to_default_properties), (update_text_properties),
+       (update_fill_color), (update_line_color), (font_family_changed_cb),
+       (text_color_changed_cb), (fill_color_changed_cb),
+       (line_color_changed_cb):
+               Incorporated new FontCombo subsystem.
+       * po/POTFILES.in:
+               Reconciled with above changes/additions.
+       
 2009-09-06  Jim Evins  <evins@snaught.com>
 
        * src/color-button.c: (gl_color_button_finalize):
index 8991acd557fb03bbc0927ed1d20272050eff939a..5cfb9002717ec17f60073d92597a8a4dc53d347c 100644 (file)
                           </packing>
                         </child>
                         <child>
-                          <object class="GtkComboBox" id="text_family_combo">
+                          <object class="GtkHBox" id="text_family_hbox">
                             <property name="visible">True</property>
+                            <child>
+                              <placeholder/>
+                            </child>
                           </object>
                           <packing>
                             <property name="position">1</property>
index 81d39bc0fc76bc925e8eaec655f45f8c15b22114..65d236883e0a80dd4e4cfc21040cfabe750b4ba3 100644 (file)
                                 <property name="visible">True</property>
                                 <property name="spacing">12</property>
                                 <child>
-                                  <object class="GtkComboBox" id="text_family_combo">
+                                  <object class="GtkHBox" id="text_family_hbox">
                                     <property name="visible">True</property>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
                                   </object>
                                   <packing>
                                     <property name="position">0</property>
index 3fd4f0ac37385c9f3552e67d4e46b42ce5e1439e..a98e892bfc12b294c0b8f59f90305ef15f297740 100644 (file)
           <object class="GtkToolItem" id="toolitem1">
             <property name="visible">True</property>
             <child>
-              <object class="GtkEventBox" id="eventbox1">
+              <object class="GtkEventBox" id="font_family_eventbox">
                 <property name="visible">True</property>
+                <property name="tooltip_markup">Font family</property>
+                <property name="visible_window">False</property>
                 <child>
-                  <object class="GtkComboBox" id="font_family_combo">
-                    <property name="visible">True</property>
-                    <property name="tooltip_text" translatable="yes">Font family</property>
-                    <property name="focus_on_click">False</property>
-                  </object>
+                  <placeholder/>
                 </child>
               </object>
             </child>
index 7a7da566572fef222355efe7d83e7674805672e3..424b2223e464408ed90e43be027199559141520f 100644 (file)
@@ -103,20 +103,34 @@ src/text-node.c
 src/text-node.h
 src/color-combo.c
 src/color-combo.h
+src/color-combo-button.c
+src/color-combo-button.h
+src/color-combo-menu.c
+src/color-combo-menu.h
 src/color-combo-color-menu-item.c
 src/color-combo-color-menu-item.h
 src/color-combo-history.c
 src/color-combo-history.h
-src/color-combo-menu.c
-src/color-combo-menu.h
+src/color-swatch.c
+src/color-swatch.h
+src/font-combo.c
+src/font-combo.h
+src/font-combo-menu.c
+src/font-combo-menu.h
+src/font-combo-menu-item.c
+src/font-combo-menu-item.h
+src/font-sample.c
+src/font-sample.h
+src/font-util.c
+src/font-util.h
 src/wdgt-print-copies.c
 src/wdgt-print-copies.h
 src/wdgt-print-merge.c
 src/wdgt-print-merge.h
 src/wdgt-media-select.c
 src/wdgt-media-select.h
-src/wdgt-mini-preview.c
-src/wdgt-mini-preview.h
+src/mini-preview.c
+src/mini-preview.h
 src/wdgt-rotate-label.c
 src/wdgt-rotate-label.h
 src/wdgt-chain-button.c
index 4a2e23325f7844cf2fef8995f3b7900192029c27..a7ca062f99d175bd5adcec678f4a6d0b85bbcbc9 100644 (file)
@@ -181,8 +181,8 @@ glabels_SOURCES =                   \
        wdgt-merge-menu.h               \
        color-combo.c                   \
        color-combo.h                   \
-       color-button.c                  \
-       color-button.h                  \
+       color-combo-button.c            \
+       color-combo-button.h            \
        color-combo-menu.c              \
        color-combo-menu.h              \
        color-combo-color-menu-item.c   \
@@ -191,6 +191,16 @@ glabels_SOURCES =                  \
        color-combo-history.h           \
        color-swatch.c                  \
        color-swatch.h                  \
+       font-combo.c                    \
+       font-combo.h                    \
+       font-combo-menu.c               \
+       font-combo-menu.h               \
+       font-combo-menu-item.c          \
+       font-combo-menu-item.h          \
+       font-sample.c                   \
+       font-sample.h                   \
+       font-util.c                     \
+       font-util.h                     \
        cairo-label-path.c              \
        cairo-label-path.h              \
        cairo-markup-path.c             \
@@ -260,6 +270,8 @@ glabels_batch_SOURCES =             \
        prefs.h                         \
        prefs-model.c                   \
        prefs-model.h                   \
+       font-util.c                     \
+       font-util.h                     \
        util.c                          \
        util.h                          \
        color.c                         \
diff --git a/glabels2/src/color-button.c b/glabels2/src/color-button.c
deleted file mode 100644 (file)
index ef5a95b..0000000
+++ /dev/null
@@ -1,435 +0,0 @@
-/*
- *  color-button.c
- *  Copyright (C) 2008-2009  Jim Evins <evins@snaught.com>.
- *
- *  This file is part of gLabels.
- *
- *  gLabels is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  gLabels 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 General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <config.h>
-
-#include "color-button.h"
-
-#include "color-combo-menu.h"
-#include <glib/gi18n.h>
-#include <gtk/gtktogglebutton.h>
-#include <gtk/gtkvbox.h>
-#include "color-swatch.h"
-#include <gtk/gtkarrow.h>
-#include "marshal.h"
-#include "color.h"
-
-
-#define IMAGE_W 24
-#define IMAGE_H 24
-
-#define SWATCH_H 5
-
-
-/*========================================================*/
-/* Private types.                                         */
-/*========================================================*/
-
-/** GL_COLOR_BUTTON Private fields */
-struct _glColorButtonPrivate {
-
-        guint       color;
-        gboolean    is_default_flag;
-
-        guint       default_color;
-
-        GtkWidget  *button;
-        GtkWidget  *button_vbox;
-        GtkWidget  *swatch;
-        GtkWidget  *dropdown_button;
-
-        GtkWidget  *menu;
-};
-
-enum {
-        COLOR_CHANGED,
-        LAST_SIGNAL
-};
-
-
-/*========================================================*/
-/* Private globals.                                       */
-/*========================================================*/
-
-static guint signals[LAST_SIGNAL] = {0};
-
-
-/*========================================================*/
-/* Private function prototypes.                           */
-/*========================================================*/
-
-static void
-gl_color_button_finalize (GObject *object);
-
-static void
-button_clicked_cb (glColorButton *this);
-
-static GdkPixbuf *
-create_pixbuf (glColorButton   *this,
-               gdouble         w,
-               gdouble         h);
-
-static gboolean
-dropdown_button_press_event_cb (GtkWidget      *widget,
-                                GdkEventButton *event,
-                                glColorButton  *this);
-
-static void
-menu_color_changed_cb (glColorComboMenu        *object,
-                       guint                    color,
-                       gboolean                 is_default,
-                       glColorButton           *this);
-
-static void
-menu_selection_done_cb (GtkMenuShell           *object,
-                        glColorButton          *this);
-
-
-/*****************************************************************************/
-/* Object infrastructure.                                                    */
-/*****************************************************************************/
-G_DEFINE_TYPE (glColorButton, gl_color_button, GTK_TYPE_HBOX);
-
-
-/*****************************************************************************/
-/* Class Init Function.                                                      */
-/*****************************************************************************/
-static void
-gl_color_button_class_init (glColorButtonClass *class)
-{
-        GObjectClass        *gobject_class = (GObjectClass *) class;
-        GtkWidgetClass      *widget_class  = (GtkWidgetClass *) class;
-        glColorButtonClass  *object_class  = (glColorButtonClass *) class;
-
-        gl_color_button_parent_class = g_type_class_peek_parent (class);
-
-        gobject_class->finalize = gl_color_button_finalize;
-
-        signals[COLOR_CHANGED] =
-                g_signal_new ("color_changed",
-                              G_OBJECT_CLASS_TYPE (gobject_class),
-                              G_SIGNAL_RUN_LAST,
-                              G_STRUCT_OFFSET (glColorButtonClass, color_changed),
-                              NULL, NULL,
-                              gl_marshal_VOID__UINT_BOOLEAN,
-                              G_TYPE_NONE,
-                              2, G_TYPE_POINTER, G_TYPE_BOOLEAN);
-
-}
-
-
-/*****************************************************************************/
-/* Object Instance Init Function.                                            */
-/*****************************************************************************/
-static void
-gl_color_button_init (glColorButton *this)
-{
-        GtkWidget *arrow;
-
-        gtk_box_set_spacing (GTK_BOX (this), 0);
-
-        this->priv = g_new0 (glColorButtonPrivate, 1);
-
-        this->priv->button_vbox = gtk_vbox_new (FALSE, 0);
-
-        this->priv->button = gtk_toggle_button_new ();
-        gtk_container_add (GTK_CONTAINER (this->priv->button), this->priv->button_vbox);
-        gtk_button_set_focus_on_click (GTK_BUTTON (this->priv->button), FALSE);
-        g_signal_connect_swapped (this->priv->button, "clicked",
-                          G_CALLBACK(button_clicked_cb), this);
-
-        gtk_box_pack_start (GTK_BOX (this), this->priv->button, FALSE, FALSE, 0);
-
-        this->priv->dropdown_button = gtk_toggle_button_new ();
-        arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
-        gtk_container_add (GTK_CONTAINER (this->priv->dropdown_button), arrow);
-        gtk_button_set_relief (GTK_BUTTON (this->priv->dropdown_button), GTK_RELIEF_NONE);
-        gtk_button_set_focus_on_click (GTK_BUTTON (this->priv->dropdown_button), FALSE);
-        g_signal_connect (this->priv->dropdown_button, "button_press_event",
-                          G_CALLBACK(dropdown_button_press_event_cb), this);
-
-        gtk_box_pack_start (GTK_BOX (this), this->priv->dropdown_button, FALSE, FALSE, 0);
-}
-
-
-/*****************************************************************************/
-/* Finalize Method.                                                          */
-/*****************************************************************************/
-static void
-gl_color_button_finalize (GObject *object)
-{
-        glColorButton    *this;
-
-        g_return_if_fail (object && IS_GL_COLOR_BUTTON (object));
-        this = GL_COLOR_BUTTON (object);
-
-        g_object_ref_sink (this->priv->menu);
-        g_free (this->priv);
-
-        G_OBJECT_CLASS (gl_color_button_parent_class)->finalize (object);
-}
-
-
-/*****************************************************************************/
-/** New Object Generator.                                                    */
-/*****************************************************************************/
-GtkWidget *
-gl_color_button_new (GdkPixbuf    *icon,
-                     const gchar  *default_label,
-                     guint         default_color,
-                     guint         color)
-{
-        glColorButton *this;
-        GdkPixbuf     *pixbuf;
-        GtkWidget     *wimage;
-
-        this = g_object_new (TYPE_GL_COLOR_BUTTON, NULL);
-
-        if (!default_label)
-        {
-                default_label = _("Default Color");
-        }
-
-        this->priv->default_color = default_color;
-        this->priv->color = color;
-
-        if (icon)
-        {
-                pixbuf = gdk_pixbuf_new_subpixbuf (icon, 0, 0, IMAGE_W, IMAGE_H-SWATCH_H);
-                wimage = gtk_image_new_from_pixbuf (pixbuf);
-                g_object_unref (G_OBJECT (pixbuf));
-                gtk_box_pack_start (GTK_BOX (this->priv->button_vbox), wimage, FALSE, FALSE, 0);
-
-                this->priv->swatch = gl_color_swatch_new (IMAGE_W, SWATCH_H, color);
-        }
-        else
-        {
-                this->priv->swatch = gl_color_swatch_new (IMAGE_W, IMAGE_H, color);
-        }
-        gtk_box_pack_start (GTK_BOX (this->priv->button_vbox), this->priv->swatch, FALSE, FALSE, 0);
-
-        this->priv->menu = gl_color_combo_menu_new (default_label, color);
-        gtk_widget_show_all (this->priv->menu);
-
-        g_signal_connect (this->priv->menu, "color_changed",
-                          G_CALLBACK (menu_color_changed_cb), this);
-        g_signal_connect (this->priv->menu, "selection_done",
-                          G_CALLBACK (menu_selection_done_cb), this);
-
-        return GTK_WIDGET (this);
-}
-
-
-/*****************************************************************************/
-/* Set color.                                                                */
-/*****************************************************************************/
-void
-gl_color_button_set_color (glColorButton  *this,
-                           guint           color)
-{
-        this->priv->color = color;
-
-        gl_color_swatch_set_color (GL_COLOR_SWATCH (this->priv->swatch), color);
-}
-
-
-/*****************************************************************************/
-/* Set to default color.                                                     */
-/*****************************************************************************/
-void
-gl_color_button_set_to_default (glColorButton  *this)
-{
-        gl_color_button_set_color (this, this->priv->default_color);
-}
-
-/*****************************************************************************/
-/* Get color.                                                                */
-/*****************************************************************************/
-guint
-gl_color_button_get_color (glColorButton  *this,
-                           gboolean       *is_default)
-{
-        if (is_default)
-        {
-                *is_default = this->priv->is_default_flag;
-        }
-
-        return this->priv->color;
-}
-
-
-/*****************************************************************************/
-/** Set relief style.                                                        */
-/*****************************************************************************/
-void
-gl_color_button_set_relief( glColorButton  *this,
-                           GtkReliefStyle   relief )
-{
-        gtk_button_set_relief (GTK_BUTTON (this->priv->button), relief);
-}
-
-
-/*****************************************************************************/
-/* Color button "clicked" callback.                                          */
-/*****************************************************************************/
-static void
-button_clicked_cb( glColorButton *this )
-{
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this->priv->button),
-                                      FALSE);
-
-        g_signal_emit (this, signals[COLOR_CHANGED], 0,
-                       this->priv->color,
-                       this->priv->is_default_flag);
-}
-
-
-/*****************************************************************************/
-/* Menu positioning function.                                                */
-/*****************************************************************************/
-static void
-menu_position_function (GtkMenu  *menu,
-                        gint     *x,
-                        gint     *y,
-                        gboolean *push_in,
-                        gpointer  user_data)
-{
-        glColorButton *this = GL_COLOR_BUTTON (user_data);
-        gint           x1, y1;
-        gint           menu_h, menu_w;
-
-        gdk_window_get_origin (GTK_WIDGET (this)->window, &x1, &y1);
-        *x = x1 + GTK_WIDGET (this)->allocation.x;
-        *y = y1 + GTK_WIDGET (this)->allocation.y +
-                GTK_WIDGET (this)->allocation.height;
-                
-        menu_h = this->priv->menu->allocation.height;
-        menu_w = this->priv->menu->allocation.width;
-
-        if ((*y + menu_h) > gdk_screen_height ())
-        {
-                *y = y1 + GTK_WIDGET (this)->allocation.y - menu_h;
-                if ( *y < 0 )
-                {
-                        *y = gdk_screen_height () - menu_h;
-                }
-        }
-
-        if ((*x + menu_w) > gdk_screen_width ())
-        {
-                *x = gdk_screen_width () - menu_w;
-        }
-
-        *push_in = TRUE;
-}
-
-
-/*****************************************************************************/
-/* Dropdown button "button_press_event" callback.                            */
-/*****************************************************************************/
-static gboolean
-dropdown_button_press_event_cb (GtkWidget      *widget,
-                                GdkEventButton *event,
-                                glColorButton  *this)
-{
-        switch (event->button)
-        {
-
-        case 1:
-                g_signal_handlers_block_by_func (G_OBJECT (this->priv->button),
-                                                 button_clicked_cb, this);
-                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this->priv->button),
-                                              TRUE);
-                g_signal_handlers_unblock_by_func (G_OBJECT (this->priv->button),
-                                                   button_clicked_cb, this);
-                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this->priv->dropdown_button),
-                                              TRUE);
-
-                gtk_menu_popup (GTK_MENU (this->priv->menu),
-                                NULL, NULL,
-                                menu_position_function, this,
-                                event->button, event->time);
-                break;
-
-        default:
-                break;
-
-        }
-
-        return FALSE;
-}
-
-
-/*****************************************************************************/
-/* Menu "color changed" callback.                                          */
-/*****************************************************************************/
-static void
-menu_color_changed_cb (glColorComboMenu     *object,
-                       guint                 color,
-                       gboolean              is_default,
-                       glColorButton         *this)
-{
-        if (is_default)
-        {
-                this->priv->color = this->priv->default_color;
-        }
-        else
-        {
-                this->priv->color = color;
-        }
-        this->priv->is_default_flag = is_default;
-
-        gl_color_swatch_set_color (GL_COLOR_SWATCH (this->priv->swatch),
-                                   this->priv->color);
-
-        g_signal_emit (this, signals[COLOR_CHANGED], 0,
-                       this->priv->color,
-                       this->priv->is_default_flag);
-}
-
-
-/*****************************************************************************/
-/* Menu "color changed" callback.                                            */
-/*****************************************************************************/
-static void
-menu_selection_done_cb (GtkMenuShell         *object,
-                        glColorButton        *this)
-{
-        g_signal_handlers_block_by_func (G_OBJECT (this->priv->button),
-                                         button_clicked_cb, this);
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this->priv->button),
-                                      FALSE);
-        g_signal_handlers_unblock_by_func (G_OBJECT (this->priv->button),
-                                           button_clicked_cb, this);
-
-        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this->priv->dropdown_button),
-                                      FALSE);
-}
-
-
-
-/*
- * Local Variables:       -- emacs
- * mode: C                -- emacs
- * c-basic-offset: 8      -- emacs
- * tab-width: 8           -- emacs
- * indent-tabs-mode: nil  -- emacs
- * End:                   -- emacs
- */
diff --git a/glabels2/src/color-button.h b/glabels2/src/color-button.h
deleted file mode 100644 (file)
index ad1dfd6..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- *  color-button.h
- *  Copyright (C) 2008-2009  Jim Evins <evins@snaught.com>.
- *
- *  This file is part of gLabels.
- *
- *  gLabels is free software: you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation, either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  gLabels 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 General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef __GL_COLOR_BUTTON_H__
-#define __GL_COLOR_BUTTON_H__
-
-
-#include <gtk/gtkhbox.h>
-
-
-G_BEGIN_DECLS
-
-#define TYPE_GL_COLOR_BUTTON              (gl_color_button_get_type ())
-#define GL_COLOR_BUTTON(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GL_COLOR_BUTTON, glColorButton))
-#define GL_COLOR_BUTTON_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GL_COLOR_BUTTON, glColorButtonClass))
-#define IS_GL_COLOR_BUTTON(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GL_COLOR_BUTTON))
-#define IS_GL_COLOR_BUTTON_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GL_COLOR_BUTTON))
-#define GL_COLOR_BUTTON_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), TYPE_GL_COLOR_BUTTON, glColorButtonClass))
-
-
-typedef struct _glColorButton          glColorButton;
-typedef struct _glColorButtonPrivate   glColorButtonPrivate;
-typedef struct _glColorButtonClass     glColorButtonClass;
-
-
-struct _glColorButton {
-        GtkHBox                        parent;
-
-        glColorButtonPrivate          *priv;
-};
-
-struct _glColorButtonClass {
-        GtkHBoxClass                   parent_class;
-
-        /*
-         * Signals
-         */
-        void (*color_changed) (glColorButton *object,
-                               guint         color,
-                               gboolean      is_default,
-                               gpointer      user_data);
-
-};
-
-
-GType            gl_color_button_get_type         (void) G_GNUC_CONST;
-
-GtkWidget       *gl_color_button_new              (GdkPixbuf     *icon,
-                                                   const gchar   *default_label,
-                                                   guint          default_color,
-                                                   guint          color);
-
-void             gl_color_button_set_color        (glColorButton  *this,
-                                                   guint          color);
-
-void             gl_color_button_set_to_default   (glColorButton  *this);
-
-guint            gl_color_button_get_color        (glColorButton  *this,
-                                                   gboolean      *is_default);
-
-void             gl_color_button_set_relief       (glColorButton  *this,
-                                                   GtkReliefStyle relief);
-
-
-G_END_DECLS
-
-#endif /* __GL_COLOR_BUTTON_H__ */
-
-
-
-/*
- * Local Variables:       -- emacs
- * mode: C                -- emacs
- * c-basic-offset: 8      -- emacs
- * tab-width: 8           -- emacs
- * indent-tabs-mode: nil  -- emacs
- * End:                   -- emacs
- */
diff --git a/glabels2/src/color-combo-button.c b/glabels2/src/color-combo-button.c
new file mode 100644 (file)
index 0000000..c444ee8
--- /dev/null
@@ -0,0 +1,430 @@
+/*
+ *  color-combo-button.c
+ *  Copyright (C) 2008-2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "color-combo-button.h"
+
+#include "color-combo-menu.h"
+#include <glib/gi18n.h>
+#include <gtk/gtktogglebutton.h>
+#include <gtk/gtkvbox.h>
+#include "color-swatch.h"
+#include <gtk/gtkarrow.h>
+#include "marshal.h"
+#include "color.h"
+
+
+#define IMAGE_W 24
+#define IMAGE_H 24
+
+#define SWATCH_H 5
+
+
+/*========================================================*/
+/* Private types.                                         */
+/*========================================================*/
+
+/** GL_COLOR_COMBO_BUTTON Private fields */
+struct _glColorComboButtonPrivate {
+
+        guint       color;
+        gboolean    is_default_flag;
+
+        guint       default_color;
+
+        GtkWidget  *button;
+        GtkWidget  *button_vbox;
+        GtkWidget  *swatch;
+        GtkWidget  *dropdown_button;
+
+        GtkWidget  *menu;
+};
+
+enum {
+        COLOR_CHANGED,
+        LAST_SIGNAL
+};
+
+
+/*========================================================*/
+/* Private globals.                                       */
+/*========================================================*/
+
+static guint signals[LAST_SIGNAL] = {0};
+
+
+/*========================================================*/
+/* Private function prototypes.                           */
+/*========================================================*/
+
+static void
+gl_color_combo_button_finalize (GObject *object);
+
+static void
+button_clicked_cb (glColorComboButton *this);
+
+static gboolean
+dropdown_button_press_event_cb (GtkWidget          *widget,
+                                GdkEventButton     *event,
+                                glColorComboButton *this);
+
+static void
+menu_color_changed_cb (glColorComboMenu            *object,
+                       guint                        color,
+                       gboolean                     is_default,
+                       glColorComboButton          *this);
+
+static void
+menu_selection_done_cb (GtkMenuShell               *object,
+                        glColorComboButton         *this);
+
+
+/*****************************************************************************/
+/* Object infrastructure.                                                    */
+/*****************************************************************************/
+G_DEFINE_TYPE (glColorComboButton, gl_color_combo_button, GTK_TYPE_HBOX);
+
+
+/*****************************************************************************/
+/* Class Init Function.                                                      */
+/*****************************************************************************/
+static void
+gl_color_combo_button_class_init (glColorComboButtonClass *class)
+{
+        GObjectClass            *gobject_class = (GObjectClass *) class;
+        GtkWidgetClass          *widget_class  = (GtkWidgetClass *) class;
+        glColorComboButtonClass *object_class  = (glColorComboButtonClass *) class;
+
+        gl_color_combo_button_parent_class = g_type_class_peek_parent (class);
+
+        gobject_class->finalize = gl_color_combo_button_finalize;
+
+        signals[COLOR_CHANGED] =
+                g_signal_new ("color_changed",
+                              G_OBJECT_CLASS_TYPE (gobject_class),
+                              G_SIGNAL_RUN_LAST,
+                              G_STRUCT_OFFSET (glColorComboButtonClass, color_changed),
+                              NULL, NULL,
+                              gl_marshal_VOID__UINT_BOOLEAN,
+                              G_TYPE_NONE,
+                              2, G_TYPE_POINTER, G_TYPE_BOOLEAN);
+
+}
+
+
+/*****************************************************************************/
+/* Object Instance Init Function.                                            */
+/*****************************************************************************/
+static void
+gl_color_combo_button_init (glColorComboButton *this)
+{
+        GtkWidget *arrow;
+
+        gtk_box_set_spacing (GTK_BOX (this), 0);
+
+        this->priv = g_new0 (glColorComboButtonPrivate, 1);
+
+        this->priv->button_vbox = gtk_vbox_new (FALSE, 0);
+
+        this->priv->button = gtk_toggle_button_new ();
+        gtk_container_add (GTK_CONTAINER (this->priv->button), this->priv->button_vbox);
+        gtk_button_set_focus_on_click (GTK_BUTTON (this->priv->button), FALSE);
+        g_signal_connect_swapped (this->priv->button, "clicked",
+                          G_CALLBACK(button_clicked_cb), this);
+
+        gtk_box_pack_start (GTK_BOX (this), this->priv->button, FALSE, FALSE, 0);
+
+        this->priv->dropdown_button = gtk_toggle_button_new ();
+        arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
+        gtk_container_add (GTK_CONTAINER (this->priv->dropdown_button), arrow);
+        gtk_button_set_relief (GTK_BUTTON (this->priv->dropdown_button), GTK_RELIEF_NONE);
+        gtk_button_set_focus_on_click (GTK_BUTTON (this->priv->dropdown_button), FALSE);
+        g_signal_connect (this->priv->dropdown_button, "button_press_event",
+                          G_CALLBACK(dropdown_button_press_event_cb), this);
+
+        gtk_box_pack_start (GTK_BOX (this), this->priv->dropdown_button, FALSE, FALSE, 0);
+}
+
+
+/*****************************************************************************/
+/* Finalize Method.                                                          */
+/*****************************************************************************/
+static void
+gl_color_combo_button_finalize (GObject *object)
+{
+        glColorComboButton    *this;
+
+        g_return_if_fail (object && IS_GL_COLOR_COMBO_BUTTON (object));
+        this = GL_COLOR_COMBO_BUTTON (object);
+
+        g_object_ref_sink (this->priv->menu);
+        g_free (this->priv);
+
+        G_OBJECT_CLASS (gl_color_combo_button_parent_class)->finalize (object);
+}
+
+
+/*****************************************************************************/
+/** New Object Generator.                                                    */
+/*****************************************************************************/
+GtkWidget *
+gl_color_combo_button_new (GdkPixbuf    *icon,
+                           const gchar  *default_label,
+                           guint         default_color,
+                           guint         color)
+{
+        glColorComboButton *this;
+        GdkPixbuf          *pixbuf;
+        GtkWidget          *wimage;
+
+        this = g_object_new (TYPE_GL_COLOR_COMBO_BUTTON, NULL);
+
+        if (!default_label)
+        {
+                default_label = _("Default Color");
+        }
+
+        this->priv->default_color = default_color;
+        this->priv->color = color;
+
+        if (icon)
+        {
+                pixbuf = gdk_pixbuf_new_subpixbuf (icon, 0, 0, IMAGE_W, IMAGE_H-SWATCH_H);
+                wimage = gtk_image_new_from_pixbuf (pixbuf);
+                g_object_unref (G_OBJECT (pixbuf));
+                gtk_box_pack_start (GTK_BOX (this->priv->button_vbox), wimage, FALSE, FALSE, 0);
+
+                this->priv->swatch = gl_color_swatch_new (IMAGE_W, SWATCH_H, color);
+        }
+        else
+        {
+                this->priv->swatch = gl_color_swatch_new (IMAGE_W, IMAGE_H, color);
+        }
+        gtk_box_pack_start (GTK_BOX (this->priv->button_vbox), this->priv->swatch, FALSE, FALSE, 0);
+
+        this->priv->menu = gl_color_combo_menu_new (default_label, color);
+        gtk_widget_show_all (this->priv->menu);
+
+        g_signal_connect (this->priv->menu, "color_changed",
+                          G_CALLBACK (menu_color_changed_cb), this);
+        g_signal_connect (this->priv->menu, "selection_done",
+                          G_CALLBACK (menu_selection_done_cb), this);
+
+        return GTK_WIDGET (this);
+}
+
+
+/*****************************************************************************/
+/* Set color.                                                                */
+/*****************************************************************************/
+void
+gl_color_combo_button_set_color (glColorComboButton  *this,
+                                 guint                color)
+{
+        this->priv->color = color;
+
+        gl_color_swatch_set_color (GL_COLOR_SWATCH (this->priv->swatch), color);
+}
+
+
+/*****************************************************************************/
+/* Set to default color.                                                     */
+/*****************************************************************************/
+void
+gl_color_combo_button_set_to_default (glColorComboButton  *this)
+{
+        gl_color_combo_button_set_color (this, this->priv->default_color);
+}
+
+/*****************************************************************************/
+/* Get color.                                                                */
+/*****************************************************************************/
+guint
+gl_color_combo_button_get_color (glColorComboButton  *this,
+                                 gboolean            *is_default)
+{
+        if (is_default)
+        {
+                *is_default = this->priv->is_default_flag;
+        }
+
+        return this->priv->color;
+}
+
+
+/*****************************************************************************/
+/** Set relief style.                                                        */
+/*****************************************************************************/
+void
+gl_color_combo_button_set_relief( glColorComboButton  *this,
+                                  GtkReliefStyle       relief )
+{
+        gtk_button_set_relief (GTK_BUTTON (this->priv->button), relief);
+}
+
+
+/*****************************************************************************/
+/* Color button "clicked" callback.                                          */
+/*****************************************************************************/
+static void
+button_clicked_cb( glColorComboButton *this )
+{
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this->priv->button),
+                                      FALSE);
+
+        g_signal_emit (this, signals[COLOR_CHANGED], 0,
+                       this->priv->color,
+                       this->priv->is_default_flag);
+}
+
+
+/*****************************************************************************/
+/* Menu positioning function.                                                */
+/*****************************************************************************/
+static void
+menu_position_function (GtkMenu  *menu,
+                        gint     *x,
+                        gint     *y,
+                        gboolean *push_in,
+                        gpointer  user_data)
+{
+        glColorComboButton *this = GL_COLOR_COMBO_BUTTON (user_data);
+        gint                x1, y1;
+        gint                menu_h, menu_w;
+
+        gdk_window_get_origin (GTK_WIDGET (this)->window, &x1, &y1);
+        *x = x1 + GTK_WIDGET (this)->allocation.x;
+        *y = y1 + GTK_WIDGET (this)->allocation.y +
+                GTK_WIDGET (this)->allocation.height;
+                
+        menu_h = this->priv->menu->allocation.height;
+        menu_w = this->priv->menu->allocation.width;
+
+        if ((*y + menu_h) > gdk_screen_height ())
+        {
+                *y = y1 + GTK_WIDGET (this)->allocation.y - menu_h;
+                if ( *y < 0 )
+                {
+                        *y = gdk_screen_height () - menu_h;
+                }
+        }
+
+        if ((*x + menu_w) > gdk_screen_width ())
+        {
+                *x = gdk_screen_width () - menu_w;
+        }
+
+        *push_in = TRUE;
+}
+
+
+/*****************************************************************************/
+/* Dropdown button "button_press_event" callback.                            */
+/*****************************************************************************/
+static gboolean
+dropdown_button_press_event_cb (GtkWidget          *widget,
+                                GdkEventButton     *event,
+                                glColorComboButton *this)
+{
+        switch (event->button)
+        {
+
+        case 1:
+                g_signal_handlers_block_by_func (G_OBJECT (this->priv->button),
+                                                 button_clicked_cb, this);
+                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this->priv->button),
+                                              TRUE);
+                g_signal_handlers_unblock_by_func (G_OBJECT (this->priv->button),
+                                                   button_clicked_cb, this);
+                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this->priv->dropdown_button),
+                                              TRUE);
+
+                gtk_menu_popup (GTK_MENU (this->priv->menu),
+                                NULL, NULL,
+                                menu_position_function, this,
+                                event->button, event->time);
+                break;
+
+        default:
+                break;
+
+        }
+
+        return FALSE;
+}
+
+
+/*****************************************************************************/
+/* Menu "color changed" callback.                                            */
+/*****************************************************************************/
+static void
+menu_color_changed_cb (glColorComboMenu   *object,
+                       guint               color,
+                       gboolean            is_default,
+                       glColorComboButton *this)
+{
+        if (is_default)
+        {
+                this->priv->color = this->priv->default_color;
+        }
+        else
+        {
+                this->priv->color = color;
+        }
+        this->priv->is_default_flag = is_default;
+
+        gl_color_swatch_set_color (GL_COLOR_SWATCH (this->priv->swatch),
+                                   this->priv->color);
+
+        g_signal_emit (this, signals[COLOR_CHANGED], 0,
+                       this->priv->color,
+                       this->priv->is_default_flag);
+}
+
+
+/*****************************************************************************/
+/* Menu "color changed" callback.                                            */
+/*****************************************************************************/
+static void
+menu_selection_done_cb (GtkMenuShell       *object,
+                        glColorComboButton *this)
+{
+        g_signal_handlers_block_by_func (G_OBJECT (this->priv->button),
+                                         button_clicked_cb, this);
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this->priv->button),
+                                      FALSE);
+        g_signal_handlers_unblock_by_func (G_OBJECT (this->priv->button),
+                                           button_clicked_cb, this);
+
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this->priv->dropdown_button),
+                                      FALSE);
+}
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/glabels2/src/color-combo-button.h b/glabels2/src/color-combo-button.h
new file mode 100644 (file)
index 0000000..fca405e
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ *  color-combo-button.h
+ *  Copyright (C) 2008-2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GL_COLOR_COMBO_BUTTON_H__
+#define __GL_COLOR_COMBO_BUTTON_H__
+
+
+#include <gtk/gtkhbox.h>
+
+
+G_BEGIN_DECLS
+
+#define TYPE_GL_COLOR_COMBO_BUTTON              (gl_color_combo_button_get_type ())
+#define GL_COLOR_COMBO_BUTTON(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GL_COLOR_COMBO_BUTTON, glColorComboButton))
+#define GL_COLOR_COMBO_BUTTON_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GL_COLOR_COMBO_BUTTON, glColorComboButtonClass))
+#define IS_GL_COLOR_COMBO_BUTTON(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GL_COLOR_COMBO_BUTTON))
+#define IS_GL_COLOR_COMBO_BUTTON_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GL_COLOR_COMBO_BUTTON))
+#define GL_COLOR_COMBO_BUTTON_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), TYPE_GL_COLOR_COMBO_BUTTON, glColorComboButtonClass))
+
+
+typedef struct _glColorComboButton          glColorComboButton;
+typedef struct _glColorComboButtonPrivate   glColorComboButtonPrivate;
+typedef struct _glColorComboButtonClass     glColorComboButtonClass;
+
+
+struct _glColorComboButton {
+        GtkHBox                        parent;
+
+        glColorComboButtonPrivate     *priv;
+};
+
+struct _glColorComboButtonClass {
+        GtkHBoxClass                   parent_class;
+
+        /*
+         * Signals
+         */
+        void (*color_changed) (glColorComboButton *object,
+                               guint               color,
+                               gboolean            is_default,
+                               gpointer            user_data);
+
+};
+
+
+GType            gl_color_combo_button_get_type       (void) G_GNUC_CONST;
+
+GtkWidget       *gl_color_combo_button_new            (GdkPixbuf          *icon,
+                                                       const gchar        *default_label,
+                                                       guint               default_color,
+                                                       guint               color);
+
+void             gl_color_combo_button_set_color      (glColorComboButton *this,
+                                                       guint               color);
+
+void             gl_color_combo_button_set_to_default (glColorComboButton *this);
+
+guint            gl_color_combo_button_get_color      (glColorComboButton *this,
+                                                       gboolean           *is_default);
+
+void             gl_color_combo_button_set_relief     (glColorComboButton *this,
+                                                       GtkReliefStyle      relief);
+
+
+G_END_DECLS
+
+#endif /* __GL_COLOR_COMBO_BUTTON_H__ */
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
index 6b9e5761260c575a27f367e037fc4a11a3b8a454..172f2e206b31c568d4d002f816788b261fe0ff53 100644 (file)
@@ -76,11 +76,6 @@ button_press_event_cb (GtkWidget      *widget,
                        GdkEventButton *event,
                        glColorCombo   *this);
 
-static GdkPixbuf *
-create_pixbuf (glColorCombo   *this,
-               gdouble         w,
-               gdouble         h);
-
 static void
 menu_color_changed_cb (glColorComboMenu   *object,
                        guint               color,
@@ -140,7 +135,7 @@ gl_color_combo_init (glColorCombo *this)
         gtk_container_add (GTK_CONTAINER (this), hbox);
         
         this->priv->swatch = gl_color_swatch_new (IMAGE_W, IMAGE_H, GL_COLOR_NONE);
-        gtk_box_pack_start (GTK_BOX (hbox), this->priv->swatch, FALSE, FALSE, 0);
+        gtk_box_pack_start (GTK_BOX (hbox), this->priv->swatch, TRUE, TRUE, 0);
 
         arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
         gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
index ac774dc403f10036fe50a5e3d6309efe2ca46a65..113f9527caeebd8d19ee4562dcdfa23df98c2218 100644 (file)
@@ -46,6 +46,7 @@ G_BEGIN_DECLS
 
 #define GL_COLOR_NONE                  GL_COLOR_A(0,0,0,0)
 #define GL_COLOR_BLACK                 GL_COLOR_A(0,0,0,255)
+#define GL_COLOR_WHITE                 GL_COLOR_A(255,255,255,255)
 
 #define GL_COLOR_TEXT_DEFAULT          GL_COLOR_BLACK
 #define GL_COLOR_BC_DEFAULT            GL_COLOR_BLACK
diff --git a/glabels2/src/font-combo-menu-item.c b/glabels2/src/font-combo-menu-item.c
new file mode 100644 (file)
index 0000000..bbaafb2
--- /dev/null
@@ -0,0 +1,166 @@
+/*
+ *  font-combo-menu-item.c
+ *  Copyright (C) 2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "font-combo-menu-item.h"
+
+#include "marshal.h"
+#include <glib/gi18n.h>
+#include <gtk/gtkmenuitem.h>
+#include <gtk/gtkseparatormenuitem.h>
+#include <gtk/gtkhbox.h>
+#include <gtk/gtklabel.h>
+
+
+
+/*===========================================*/
+/* Private macros and constants.             */
+/*===========================================*/
+
+#define SAMPLE_W 32
+#define SAMPLE_H 24
+
+
+/*===========================================*/
+/* Private types                             */
+/*===========================================*/
+
+struct _glFontComboMenuItemPrivate {
+
+        gchar *font_family;
+
+};
+
+
+/*===========================================*/
+/* Private globals                           */
+/*===========================================*/
+
+
+/*===========================================*/
+/* Local function prototypes                 */
+/*===========================================*/
+
+static void gl_font_combo_menu_item_finalize    (GObject                *object);
+
+
+/****************************************************************************/
+/* Boilerplate Object stuff.                                                */
+/****************************************************************************/
+G_DEFINE_TYPE (glFontComboMenuItem, gl_font_combo_menu_item, GTK_TYPE_MENU_ITEM);
+
+
+/*****************************************************************************/
+/* Class Init Function.                                                      */
+/*****************************************************************************/
+static void
+gl_font_combo_menu_item_class_init (glFontComboMenuItemClass *class)
+{
+       GObjectClass   *gobject_class = G_OBJECT_CLASS (class);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+        gl_font_combo_menu_item_parent_class = g_type_class_peek_parent (class);
+
+       gobject_class->finalize = gl_font_combo_menu_item_finalize;
+}
+
+
+/*****************************************************************************/
+/* Object Instance Init Function.                                            */
+/*****************************************************************************/
+static void
+gl_font_combo_menu_item_init (glFontComboMenuItem *this)
+{
+       this->priv = g_new0 (glFontComboMenuItemPrivate, 1);
+}
+
+
+/*****************************************************************************/
+/* Finalize Method.                                                          */
+/*****************************************************************************/
+static void
+gl_font_combo_menu_item_finalize (GObject *object)
+{
+       glFontComboMenuItem *this = GL_FONT_COMBO_MENU_ITEM (object);
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GL_IS_FONT_COMBO_MENU_ITEM (object));
+
+        g_free (this->priv->font_family);
+       g_free (this->priv);
+
+       G_OBJECT_CLASS (gl_font_combo_menu_item_parent_class)->finalize (object);
+}
+
+
+/*****************************************************************************/
+/** New Object Generator.                                                    */
+/*****************************************************************************/
+GtkWidget *
+gl_font_combo_menu_item_new (gchar *font_family)
+{
+       glFontComboMenuItem *this;
+        GtkWidget           *hbox;
+        GtkWidget           *sample;
+        GtkWidget           *label;
+        gchar               *markup;
+
+       this = g_object_new (GL_TYPE_FONT_COMBO_MENU_ITEM, NULL);
+
+        this->priv->font_family = g_strdup (font_family);
+
+        hbox = gtk_hbox_new (FALSE, 6);
+        gtk_container_add (GTK_CONTAINER (this), hbox);
+
+        sample = gl_font_sample_new (SAMPLE_W, SAMPLE_H, "Aa", font_family);
+        gtk_box_pack_start (GTK_BOX (hbox), sample, FALSE, FALSE, 0);
+
+        label = gtk_label_new (font_family);
+        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+
+        markup = g_strdup_printf ("<span font_family=\"%s\" size=\"x-large\">ABCDEFGHIJKLMNOPQRSTUVWXYZ\nabcdefghijklmnopqrstuvwxyz\n0123456789</span>",
+                                  font_family);
+        gtk_widget_set_tooltip_markup (GTK_WIDGET (this), markup);
+        g_free (markup);
+
+       return GTK_WIDGET (this);
+}
+
+
+/*****************************************************************************/
+/* Get family.                                                               */
+/*****************************************************************************/
+gchar *
+gl_font_combo_menu_item_get_family (glFontComboMenuItem *this)
+{
+        return g_strdup (this->priv->font_family);
+}
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/glabels2/src/font-combo-menu-item.h b/glabels2/src/font-combo-menu-item.h
new file mode 100644 (file)
index 0000000..010b0c1
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ *  font-combo-menu-item.h
+ *  Copyright (C) 2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __FONT_COMBO_MENU_ITEM_H__
+#define __FONT_COMBO_MENU_ITEM_H__
+
+
+#include <gtk/gtkmenuitem.h>
+
+
+G_BEGIN_DECLS
+
+#define GL_TYPE_FONT_COMBO_MENU_ITEM (gl_font_combo_menu_item_get_type ())
+#define GL_FONT_COMBO_MENU_ITEM(obj) \
+        (G_TYPE_CHECK_INSTANCE_CAST((obj), GL_TYPE_FONT_COMBO_MENU_ITEM, glFontComboMenuItem ))
+#define GL_FONT_COMBO_MENU_ITEM_CLASS(klass) \
+        (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_FONT_COMBO_MENU_ITEM, glFontComboMenuItemClass))
+#define GL_IS_FONT_COMBO_MENU_ITEM(obj) \
+        (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GL_TYPE_FONT_COMBO_MENU_ITEM))
+#define GL_IS_FONT_COMBO_MENU_ITEM_CLASS(klass) \
+        (G_TYPE_CHECK_CLASS_TYPE ((klass), GL_TYPE_FONT_COMBO_MENU_ITEM))
+
+typedef struct _glFontComboMenuItem        glFontComboMenuItem;
+typedef struct _glFontComboMenuItemPrivate glFontComboMenuItemPrivate;
+typedef struct _glFontComboMenuItemClass   glFontComboMenuItemClass;
+
+struct _glFontComboMenuItem {
+       GtkMenuItem            parent_widget;
+
+       glFontComboMenuItemPrivate *priv;
+};
+
+struct _glFontComboMenuItemClass {
+       GtkMenuItemClass       parent_class;
+};
+
+
+GType      gl_font_combo_menu_item_get_type   (void) G_GNUC_CONST;
+
+GtkWidget *gl_font_combo_menu_item_new        (gchar                *font_family);
+
+gchar     *gl_font_combo_menu_item_get_family (glFontComboMenuItem  *this);
+
+
+G_END_DECLS
+
+#endif /* __FONT_COMBO_MENU_ITEM_H__ */
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/glabels2/src/font-combo-menu.c b/glabels2/src/font-combo-menu.c
new file mode 100644 (file)
index 0000000..cf26370
--- /dev/null
@@ -0,0 +1,241 @@
+/*
+ *  font-combo-menu.c
+ *  Copyright (C) 2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "font-combo-menu.h"
+
+#include "marshal.h"
+#include <glib/gi18n.h>
+#include <gtk/gtkmenuitem.h>
+#include <gtk/gtkseparatormenuitem.h>
+#include <gtk/gtkcolorseldialog.h>
+#include "font-combo-menu-item.h"
+#include "font-util.h"
+
+
+/*===========================================*/
+/* Private macros and constants.             */
+/*===========================================*/
+
+
+/*===========================================*/
+/* Private types                             */
+/*===========================================*/
+
+struct _glFontComboMenuPrivate {
+
+        gchar *font_family;
+
+};
+
+enum {
+        FONT_CHANGED,
+        LAST_SIGNAL
+};
+
+gchar *standard_families[] = { "Sans", "Serif", "Monospace", NULL };
+
+/*===========================================*/
+/* Private globals                           */
+/*===========================================*/
+
+static guint signals[LAST_SIGNAL] = {0};
+
+
+/*===========================================*/
+/* Local function prototypes                 */
+/*===========================================*/
+
+static void gl_font_combo_menu_finalize (GObject        *object);
+
+static void menu_item_activate_cb (glFontComboMenuItem *item,
+                                   glFontComboMenu     *this);
+
+
+/****************************************************************************/
+/* Boilerplate Object stuff.                                                */
+/****************************************************************************/
+G_DEFINE_TYPE (glFontComboMenu, gl_font_combo_menu, GTK_TYPE_MENU);
+
+
+/*****************************************************************************/
+/* Class Init Function.                                                      */
+/*****************************************************************************/
+static void
+gl_font_combo_menu_class_init (glFontComboMenuClass *class)
+{
+       GObjectClass   *gobject_class = G_OBJECT_CLASS (class);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+        gl_font_combo_menu_parent_class = g_type_class_peek_parent (class);
+
+       gobject_class->finalize = gl_font_combo_menu_finalize;
+
+        signals[FONT_CHANGED] =
+                g_signal_new ("font_changed",
+                              G_OBJECT_CLASS_TYPE (gobject_class),
+                              G_SIGNAL_RUN_LAST,
+                              G_STRUCT_OFFSET (glFontComboMenuClass, font_changed),
+                              NULL, NULL,
+                              gl_marshal_VOID__VOID,
+                              G_TYPE_NONE, 0);
+}
+
+
+/*****************************************************************************/
+/* Object Instance Init Function.                                            */
+/*****************************************************************************/
+static void
+gl_font_combo_menu_init (glFontComboMenu *this)
+{
+        gint         i;
+        GtkWidget   *menu_item;
+        GtkWidget   *sub_menu;
+        const GList *list;
+        GList       *p;
+
+       this->priv = g_new0 (glFontComboMenuPrivate, 1);
+
+
+        for ( i = 0; standard_families[i] != NULL; i++ )
+        {
+                menu_item = gl_font_combo_menu_item_new (standard_families[i]);
+                gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item);
+                g_signal_connect (menu_item, "activate",
+                                  G_CALLBACK (menu_item_activate_cb), this);
+        }
+
+        menu_item = gtk_separator_menu_item_new ();
+        gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item);
+
+        menu_item = gtk_menu_item_new_with_label (_("Proportional fonts"));
+        gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item);
+
+        sub_menu = gtk_menu_new ();
+        gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
+
+        list = gl_font_util_get_proportional_families ();
+        for ( p = (GList *)list; p != NULL; p = p->next )
+        {
+                menu_item = gl_font_combo_menu_item_new (p->data);
+                gtk_menu_shell_append (GTK_MENU_SHELL (sub_menu), menu_item);
+                g_signal_connect (menu_item, "activate",
+                                  G_CALLBACK (menu_item_activate_cb), this);
+        }
+
+        menu_item = gtk_menu_item_new_with_label (_("Fixed-width fonts"));
+        gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item);
+
+        sub_menu = gtk_menu_new ();
+        gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
+
+        list = gl_font_util_get_fixed_width_families ();
+        for ( p = (GList *)list; p != NULL; p = p->next )
+        {
+                menu_item = gl_font_combo_menu_item_new (p->data);
+                gtk_menu_shell_append (GTK_MENU_SHELL (sub_menu), menu_item);
+                g_signal_connect (menu_item, "activate",
+                                  G_CALLBACK (menu_item_activate_cb), this);
+        }
+
+        menu_item = gtk_menu_item_new_with_label (_("All fonts"));
+        gtk_menu_shell_append (GTK_MENU_SHELL (this), menu_item);
+
+        sub_menu = gtk_menu_new ();
+        gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item), sub_menu);
+
+        list = gl_font_util_get_all_families ();
+        for ( p = (GList *)list; p != NULL; p = p->next )
+        {
+                menu_item = gl_font_combo_menu_item_new (p->data);
+                gtk_menu_shell_append (GTK_MENU_SHELL (sub_menu), menu_item);
+                g_signal_connect (menu_item, "activate",
+                                  G_CALLBACK (menu_item_activate_cb), this);
+        }
+
+}
+
+
+/*****************************************************************************/
+/* Finalize Method.                                                          */
+/*****************************************************************************/
+static void
+gl_font_combo_menu_finalize (GObject *object)
+{
+       glFontComboMenu *this = GL_FONT_COMBO_MENU (object);
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GL_IS_FONT_COMBO_MENU (object));
+
+       g_free (this->priv);
+
+       G_OBJECT_CLASS (gl_font_combo_menu_parent_class)->finalize (object);
+}
+
+
+/*****************************************************************************/
+/** New Object Generator.                                                    */
+/*****************************************************************************/
+GtkWidget *
+gl_font_combo_menu_new (void)
+{
+       glFontComboMenu *this;
+
+       this = g_object_new (gl_font_combo_menu_get_type (), NULL);
+
+       return GTK_WIDGET (this);
+}
+
+
+/*****************************************************************************/
+/* menu_item activate callback.                                              */
+/*****************************************************************************/
+static void menu_item_activate_cb (glFontComboMenuItem *item,
+                                   glFontComboMenu     *this)
+{
+        this->priv->font_family = gl_font_combo_menu_item_get_family (item);
+
+        g_signal_emit (this, signals[FONT_CHANGED], 0);
+
+        gtk_widget_hide (GTK_WIDGET (this));
+}
+
+
+/*****************************************************************************/
+/* Get font family name.                                                     */
+/*****************************************************************************/
+gchar *
+gl_font_combo_menu_get_family (glFontComboMenu *this)
+{
+        return g_strdup (this->priv->font_family);
+}
+
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/glabels2/src/font-combo-menu.h b/glabels2/src/font-combo-menu.h
new file mode 100644 (file)
index 0000000..df65b0d
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ *  font-combo-menu.h
+ *  Copyright (C) 2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __FONT_COMBO_MENU_H__
+#define __FONT_COMBO_MENU_H__
+
+#include <gtk/gtkmenu.h>
+
+
+G_BEGIN_DECLS
+
+#define GL_TYPE_FONT_COMBO_MENU (gl_font_combo_menu_get_type ())
+#define GL_FONT_COMBO_MENU(obj) \
+        (G_TYPE_CHECK_INSTANCE_CAST((obj), GL_TYPE_FONT_COMBO_MENU, glFontComboMenu ))
+#define GL_FONT_COMBO_MENU_CLASS(klass) \
+        (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_FONT_COMBO_MENU, glFontComboMenuClass))
+#define GL_IS_FONT_COMBO_MENU(obj) \
+        (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GL_TYPE_FONT_COMBO_MENU))
+#define GL_IS_FONT_COMBO_MENU_CLASS(klass) \
+        (G_TYPE_CHECK_CLASS_TYPE ((klass), GL_TYPE_FONT_COMBO_MENU))
+
+typedef struct _glFontComboMenu        glFontComboMenu;
+typedef struct _glFontComboMenuPrivate glFontComboMenuPrivate;
+typedef struct _glFontComboMenuClass   glFontComboMenuClass;
+
+struct _glFontComboMenu {
+       GtkMenu                 parent_widget;
+
+       glFontComboMenuPrivate *priv;
+};
+
+struct _glFontComboMenuClass {
+       GtkMenuClass            parent_class;
+
+        /*
+         * Signals
+         */
+        void (*font_changed) (glFontComboMenu *object,
+                              gpointer         user_data);
+
+};
+
+
+GType      gl_font_combo_menu_get_type     (void) G_GNUC_CONST;
+
+GtkWidget *gl_font_combo_menu_new          (void);
+
+gchar     *gl_font_combo_menu_get_family   (glFontComboMenu *this);
+
+
+G_END_DECLS
+
+
+#endif /* __FONT_COMBO_MENU_H__ */
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
+
diff --git a/glabels2/src/font-combo.c b/glabels2/src/font-combo.c
new file mode 100644 (file)
index 0000000..44dfc39
--- /dev/null
@@ -0,0 +1,323 @@
+/*
+ *  font-combo.c
+ *  Copyright (C) 2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "font-combo.h"
+
+#include "font-combo-menu.h"
+#include <glib/gi18n.h>
+#include <gtk/gtkhbox.h>
+#include <gtk/gtklabel.h>
+#include <gtk/gtkarrow.h>
+#include "marshal.h"
+
+
+
+/*========================================================*/
+/* Private types.                                         */
+/*========================================================*/
+
+/** GL_FONT_COMBO Private fields */
+struct _glFontComboPrivate {
+
+        gchar      *font_family;
+
+        GtkWidget  *label;
+
+        GtkWidget  *menu;
+};
+
+enum {
+        CHANGED,
+        LAST_SIGNAL
+};
+
+
+/*========================================================*/
+/* Private globals.                                       */
+/*========================================================*/
+
+static guint signals[LAST_SIGNAL] = {0};
+
+
+/*========================================================*/
+/* Private function prototypes.                           */
+/*========================================================*/
+
+static void gl_font_combo_finalize      (GObject             *object);
+
+static gboolean
+button_press_event_cb (GtkWidget      *widget,
+                       GdkEventButton *event,
+                       glFontCombo    *this);
+
+static void
+menu_font_changed_cb   (glFontComboMenu  *menu,
+                        glFontCombo      *this);
+
+static void
+menu_selection_done_cb (GtkMenuShell     *object,
+                        glFontCombo      *this);
+
+
+/*****************************************************************************/
+/* Object infrastructure.                                                    */
+/*****************************************************************************/
+G_DEFINE_TYPE (glFontCombo, gl_font_combo, GTK_TYPE_TOGGLE_BUTTON);
+
+
+/*****************************************************************************/
+/* Class Init Function.                                                      */
+/*****************************************************************************/
+static void
+gl_font_combo_class_init (glFontComboClass *class)
+{
+        GObjectClass      *gobject_class = (GObjectClass *) class;
+        GtkWidgetClass    *widget_class  = (GtkWidgetClass *) class;
+        glFontComboClass  *object_class  = (glFontComboClass *) class;
+
+        gl_font_combo_parent_class = g_type_class_peek_parent (class);
+
+        gobject_class->finalize = gl_font_combo_finalize;
+
+        signals[CHANGED] =
+                g_signal_new ("changed",
+                              G_OBJECT_CLASS_TYPE (gobject_class),
+                              G_SIGNAL_RUN_LAST,
+                              G_STRUCT_OFFSET (glFontComboClass, changed),
+                              NULL, NULL,
+                              gl_marshal_VOID__VOID,
+                              G_TYPE_NONE, 0);
+}
+
+
+/*****************************************************************************/
+/* Object Instance Init Function.                                            */
+/*****************************************************************************/
+static void
+gl_font_combo_init (glFontCombo *this)
+{
+        GtkWidget *hbox;
+        GtkWidget *arrow;
+
+        this->priv = g_new0 (glFontComboPrivate, 1);
+
+        hbox = gtk_hbox_new (FALSE, 3);
+        gtk_container_add (GTK_CONTAINER (this), hbox);
+        
+        this->priv->label = gtk_label_new ("");
+        gtk_misc_set_alignment (GTK_MISC (this->priv->label), 0.0, 0.5);
+       gtk_widget_set_size_request (this->priv->label, 180, -1);
+        gtk_box_pack_start (GTK_BOX (hbox), this->priv->label, TRUE, TRUE, 0);
+
+        arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN);
+        gtk_box_pack_end (GTK_BOX (hbox), arrow, FALSE, FALSE, 0);
+
+        g_signal_connect (this, "button_press_event",
+                          G_CALLBACK(button_press_event_cb), this);
+}
+
+
+/*****************************************************************************/
+/* Finalize Method.                                                          */
+/*****************************************************************************/
+static void
+gl_font_combo_finalize (GObject *object)
+{
+        glFontCombo    *this;
+
+        g_return_if_fail (object && IS_GL_FONT_COMBO (object));
+        this = GL_FONT_COMBO (object);
+
+        g_free (this->priv->font_family);
+        g_object_ref_sink (this->priv->menu);
+        g_free (this->priv);
+
+        G_OBJECT_CLASS (gl_font_combo_parent_class)->finalize (object);
+}
+
+
+/*****************************************************************************/
+/** New Object Generator.                                                    */
+/*****************************************************************************/
+GtkWidget *
+gl_font_combo_new (const gchar  *font_family)
+{
+        glFontCombo  *this;
+
+        this = g_object_new (TYPE_GL_FONT_COMBO, NULL);
+
+        this->priv->font_family = g_strdup (font_family);
+
+        gtk_label_set_text (GTK_LABEL (this->priv->label), font_family);
+
+        this->priv->menu = gl_font_combo_menu_new ();
+
+        gtk_widget_show_all (this->priv->menu);
+
+        g_signal_connect (this->priv->menu, "font_changed",
+                          G_CALLBACK (menu_font_changed_cb), this);
+        g_signal_connect (this->priv->menu, "selection_done",
+                          G_CALLBACK (menu_selection_done_cb), this);
+
+        return GTK_WIDGET (this);
+}
+
+
+/*****************************************************************************/
+/** Set relief style.                                                        */
+/*****************************************************************************/
+void
+gl_font_combo_set_relief( glFontCombo    *this,
+                          GtkReliefStyle  relief )
+{
+        gtk_button_set_relief (GTK_BUTTON (this), relief);
+}
+
+
+/*****************************************************************************/
+/* Set font family.                                                          */
+/*****************************************************************************/
+void
+gl_font_combo_set_family (glFontCombo  *this,
+                          const gchar  *font_family)
+{
+
+        this->priv->font_family = g_strdup (font_family);
+
+        gtk_label_set_text (GTK_LABEL (this->priv->label), font_family);
+}
+
+
+/*****************************************************************************/
+/* Get font family.                                                          */
+/*****************************************************************************/
+gchar *
+gl_font_combo_get_family (glFontCombo  *this)
+{
+        return g_strdup (this->priv->font_family);
+}
+
+
+/*****************************************************************************/
+/* Menu positioning function.                                                */
+/*****************************************************************************/
+static void
+menu_position_function (GtkMenu  *menu,
+                        gint     *x,
+                        gint     *y,
+                        gboolean *push_in,
+                        gpointer  user_data)
+{
+        glFontCombo *this = GL_FONT_COMBO (user_data);
+        gint          x1, y1;
+        gint          menu_h, menu_w;
+
+        gdk_window_get_origin (GTK_WIDGET (this)->window, &x1, &y1);
+        *x = x1 + GTK_WIDGET (this)->allocation.x;
+        *y = y1 + GTK_WIDGET (this)->allocation.y +
+                GTK_WIDGET (this)->allocation.height;
+                
+        menu_h = this->priv->menu->allocation.height;
+        menu_w = this->priv->menu->allocation.width;
+
+        if ((*y + menu_h) > gdk_screen_height ())
+        {
+                *y = y1 + GTK_WIDGET (this)->allocation.y - menu_h;
+                if ( *y < 0 )
+                {
+                        *y = gdk_screen_height () - menu_h;
+                }
+        }
+
+        if ((*x + menu_w) > gdk_screen_width ())
+        {
+                *x = gdk_screen_width () - menu_w;
+        }
+
+        *push_in = TRUE;
+}
+
+
+/*****************************************************************************/
+/* Button "button_press_event" callback.                                     */
+/*****************************************************************************/
+static gboolean
+button_press_event_cb (GtkWidget      *widget,
+                       GdkEventButton *event,
+                       glFontCombo   *this)
+{
+        switch (event->button)
+        {
+
+        case 1:
+                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this), TRUE);
+
+                gtk_menu_popup (GTK_MENU (this->priv->menu),
+                                NULL, NULL,
+                                menu_position_function, this,
+                                event->button, event->time);
+                break;
+
+        default:
+                break;
+
+        }
+
+        return FALSE;
+}
+
+
+/*****************************************************************************/
+/* Menu "font changed" callback.                                             */
+/*****************************************************************************/
+static void
+menu_font_changed_cb (glFontComboMenu     *menu,
+                      glFontCombo         *this)
+{
+        this->priv->font_family = gl_font_combo_menu_get_family (menu);
+
+        gtk_label_set_text (GTK_LABEL (this->priv->label), this->priv->font_family);
+
+        g_signal_emit (this, signals[CHANGED], 0);
+}
+
+
+/*****************************************************************************/
+/* Menu "selection done" callback.                                           */
+/*****************************************************************************/
+static void
+menu_selection_done_cb (GtkMenuShell         *object,
+                        glFontCombo         *this)
+{
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (this), FALSE);
+}
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/glabels2/src/font-combo.h b/glabels2/src/font-combo.h
new file mode 100644 (file)
index 0000000..e53d6e0
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ *  font-combo.h
+ *  Copyright (C) 2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GL_FONT_COMBO_H__
+#define __GL_FONT_COMBO_H__
+
+
+#include <gtk/gtktogglebutton.h>
+
+
+G_BEGIN_DECLS
+
+#define TYPE_GL_FONT_COMBO              (gl_font_combo_get_type ())
+#define GL_FONT_COMBO(obj)              (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GL_FONT_COMBO, glFontCombo))
+#define GL_FONT_COMBO_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GL_FONT_COMBO, glFontComboClass))
+#define IS_GL_FONT_COMBO(obj)           (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GL_FONT_COMBO))
+#define IS_GL_FONT_COMBO_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GL_FONT_COMBO))
+#define GL_FONT_COMBO_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), TYPE_GL_FONT_COMBO, glFontComboClass))
+
+
+typedef struct _glFontCombo          glFontCombo;
+typedef struct _glFontComboPrivate   glFontComboPrivate;
+typedef struct _glFontComboClass     glFontComboClass;
+
+
+struct _glFontCombo {
+        GtkToggleButton               parent;
+
+        glFontComboPrivate           *priv;
+};
+
+struct _glFontComboClass {
+        GtkToggleButtonClass          parent_class;
+
+        /*
+         * Signals
+         */
+        void (*changed) (glFontCombo *object,
+                         gpointer     user_data);
+
+};
+
+
+GType            gl_font_combo_get_type          (void) G_GNUC_CONST;
+
+GtkWidget       *gl_font_combo_new               (const gchar   *font_family);
+
+void             gl_font_combo_set_family        (glFontCombo   *this,
+                                                  const gchar   *font_family);
+
+gchar           *gl_font_combo_get_family        (glFontCombo   *this);
+
+void             gl_font_combo_set_relief        (glFontCombo   *this,
+                                                  GtkReliefStyle relief);
+
+
+G_END_DECLS
+
+#endif /* __GL_COLOR_COMBO_H__ */
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/glabels2/src/font-sample.c b/glabels2/src/font-sample.c
new file mode 100644 (file)
index 0000000..299b9ba
--- /dev/null
@@ -0,0 +1,285 @@
+/*
+ *  font-sample.c
+ *  Copyright (C) 2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "font-sample.h"
+
+#include "marshal.h"
+#include "color.h"
+
+
+/*===========================================*/
+/* Private macros and constants.             */
+/*===========================================*/
+
+#define MARGIN 2
+
+
+/*===========================================*/
+/* Private types                             */
+/*===========================================*/
+
+struct _glFontSamplePrivate {
+
+        gchar *sample_text;
+
+        gchar *font_family;
+};
+
+
+/*===========================================*/
+/* Private globals                           */
+/*===========================================*/
+
+
+/*===========================================*/
+/* Local function prototypes                 */
+/*===========================================*/
+
+static void       gl_font_sample_finalize     (GObject        *object);
+
+static void       redraw                      (glFontSample   *this);
+
+static gboolean   expose_event_cb             (GtkWidget      *widget,
+                                               GdkEventExpose *event);
+
+static void       draw_sample                 (glFontSample   *this,
+                                               cairo_t        *cr);
+
+
+
+/****************************************************************************/
+/* Boilerplate Object stuff.                                                */
+/****************************************************************************/
+G_DEFINE_TYPE (glFontSample, gl_font_sample, GTK_TYPE_DRAWING_AREA);
+
+
+/*****************************************************************************/
+/* Class Init Function.                                                      */
+/*****************************************************************************/
+static void
+gl_font_sample_class_init (glFontSampleClass *class)
+{
+       GObjectClass   *gobject_class = G_OBJECT_CLASS (class);
+       GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
+
+        gl_font_sample_parent_class = g_type_class_peek_parent (class);
+
+       gobject_class->finalize    = gl_font_sample_finalize;
+
+        widget_class->expose_event = expose_event_cb;
+}
+
+
+/*****************************************************************************/
+/* Object Instance Init Function.                                            */
+/*****************************************************************************/
+static void
+gl_font_sample_init (glFontSample *this)
+{
+        GTK_WIDGET_SET_FLAGS (GTK_WIDGET (this), GTK_NO_WINDOW);
+
+       this->priv = g_new0 (glFontSamplePrivate, 1);
+}
+
+
+/*****************************************************************************/
+/* Finalize Method.                                                          */
+/*****************************************************************************/
+static void
+gl_font_sample_finalize (GObject *object)
+{
+       glFontSample *this = GL_FONT_SAMPLE (object);
+
+       g_return_if_fail (object != NULL);
+       g_return_if_fail (GL_IS_FONT_SAMPLE (object));
+
+        g_free (this->priv->sample_text);
+        g_free (this->priv->font_family);
+       g_free (this->priv);
+
+       G_OBJECT_CLASS (gl_font_sample_parent_class)->finalize (object);
+}
+
+
+/*****************************************************************************/
+/** New Object Generator.                                                    */
+/*****************************************************************************/
+GtkWidget *
+gl_font_sample_new (gint         w,
+                    gint         h,
+                    const gchar *sample_text,
+                    const gchar *font_family)
+{
+       glFontSample *this;
+
+       this = g_object_new (GL_TYPE_FONT_SAMPLE, NULL);
+
+        this->priv->sample_text = g_strdup (sample_text);
+        this->priv->font_family = g_strdup (font_family);
+
+        gtk_widget_set_size_request (GTK_WIDGET (this), w, h);
+
+       return GTK_WIDGET (this);
+}
+
+
+/*****************************************************************************/
+/* Request redraw.                                                           */
+/*****************************************************************************/
+static void
+redraw (glFontSample  *this)
+{
+       GdkRegion *region;
+
+        if (GTK_WIDGET_REALIZED (GTK_WIDGET (this)))
+        {
+                /* redraw the cairo canvas forcing an expose event */
+                region = gdk_drawable_get_clip_region (GTK_WIDGET (this)->window);
+                gdk_window_invalidate_region (GTK_WIDGET (this)->window, region, TRUE);
+                gdk_region_destroy (region);
+        }
+}
+
+
+/*****************************************************************************/
+/* "Expose event" callback.                                                  */
+/*****************************************************************************/
+static gboolean
+expose_event_cb (GtkWidget      *widget,
+                 GdkEventExpose *event)
+{
+       cairo_t *cr;
+
+       cr = gdk_cairo_create (widget->window);
+
+       cairo_rectangle (cr,
+                       event->area.x, event->area.y,
+                       event->area.width, event->area.height);
+       cairo_clip (cr);
+
+        cairo_translate (cr, widget->allocation.x, widget->allocation.y);
+
+       draw_sample (GL_FONT_SAMPLE (widget), cr);
+
+       cairo_destroy (cr);
+
+       return FALSE;
+}
+
+
+/*****************************************************************************/
+/* Draw sample.                                                              */
+/*****************************************************************************/
+static void
+draw_sample (glFontSample *this,
+             cairo_t       *cr)
+{
+        GdkPixbuf            *pixbuf;
+        GtkStyle             *style;
+        gdouble               w, h;
+        guint                 fill_color, line_color;
+        PangoLayout          *layout;
+        PangoFontDescription *desc;
+        PangoRectangle        ink_rect, logical_rect;
+        gdouble               layout_x, layout_y, layout_width, layout_height;
+
+
+
+        w = GTK_WIDGET (this)->allocation.width;
+        h = GTK_WIDGET (this)->allocation.height;
+
+
+        style = gtk_widget_get_style (GTK_WIDGET (this));
+        if ( GTK_WIDGET_IS_SENSITIVE (GTK_WIDGET (this)) )
+        {
+                fill_color = GL_COLOR_WHITE;
+                line_color = gl_color_from_gdk_color (&style->fg[GTK_STATE_NORMAL]);
+        }
+        else
+        {
+                fill_color = GL_COLOR_NONE;
+                line_color = gl_color_from_gdk_color (&style->fg[GTK_STATE_INSENSITIVE]);
+        }
+
+
+        cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE);
+
+        cairo_rectangle( cr, 0, 0, w-1, h-1 );
+
+        cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (fill_color));
+        cairo_fill_preserve( cr );
+
+        cairo_set_source_rgb (cr, GL_COLOR_RGB_ARGS (line_color));
+        cairo_set_line_width (cr, 1.0);
+        cairo_stroke (cr);
+
+
+        cairo_set_antialias (cr, CAIRO_ANTIALIAS_DEFAULT);
+
+
+        layout = pango_cairo_create_layout (cr);
+
+        desc = pango_font_description_new ();
+        pango_font_description_set_family (desc, this->priv->font_family);
+        pango_font_description_set_weight (desc, PANGO_WEIGHT_NORMAL);
+        pango_font_description_set_style  (desc, PANGO_STYLE_NORMAL);
+        pango_font_description_set_size   (desc, 0.6 * h * PANGO_SCALE);
+        
+        pango_layout_set_font_description (layout, desc);
+        pango_font_description_free       (desc);
+
+        pango_layout_set_text (layout, this->priv->sample_text, -1);
+        pango_layout_set_width (layout, -1);
+        pango_layout_get_pixel_extents (layout, &ink_rect, &logical_rect);
+        layout_width  = MAX (logical_rect.width, ink_rect.width);
+        layout_height = MAX (logical_rect.height, ink_rect.height);
+
+        layout_x = (w - layout_width) / 2.0;
+        layout_y = (h - layout_height) / 2.0;
+
+        if (ink_rect.x < logical_rect.x)
+        {
+                layout_x += logical_rect.x - ink_rect.x;
+        }
+
+        if (ink_rect.y < logical_rect.y)
+        {
+                layout_y += logical_rect.y - ink_rect.y;
+        }
+
+        cairo_set_source_rgba (cr, GL_COLOR_RGBA_ARGS (line_color));
+        cairo_move_to (cr, layout_x, layout_y);
+        pango_cairo_show_layout (cr, layout);
+
+        g_object_unref (layout);
+}
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/glabels2/src/font-sample.h b/glabels2/src/font-sample.h
new file mode 100644 (file)
index 0000000..16d0e25
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ *  font-sample.h
+ *  Copyright (C) 2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __FONT_SAMPLE_H__
+#define __FONT_SAMPLE_H__
+
+
+#include <gtk/gtkdrawingarea.h>
+
+
+G_BEGIN_DECLS
+
+#define GL_TYPE_FONT_SAMPLE (gl_font_sample_get_type ())
+#define GL_FONT_SAMPLE(obj) \
+        (G_TYPE_CHECK_INSTANCE_CAST((obj), GL_TYPE_FONT_SAMPLE, glFontSample ))
+#define GL_FONT_SAMPLE_CLASS(klass) \
+        (G_TYPE_CHECK_CLASS_CAST ((klass), GL_TYPE_FONT_SAMPLE, glFontSampleClass))
+#define GL_IS_FONT_SAMPLE(obj) \
+        (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GL_TYPE_FONT_SAMPLE))
+#define GL_IS_FONT_SAMPLE_CLASS(klass) \
+        (G_TYPE_CHECK_CLASS_TYPE ((klass), GL_TYPE_FONT_SAMPLE))
+
+typedef struct _glFontSample        glFontSample;
+typedef struct _glFontSamplePrivate glFontSamplePrivate;
+typedef struct _glFontSampleClass   glFontSampleClass;
+
+struct _glFontSample {
+       GtkDrawingArea         parent_widget;
+
+       glFontSamplePrivate   *priv;
+};
+
+struct _glFontSampleClass {
+       GtkDrawingAreaClass    parent_class;
+};
+
+
+GType      gl_font_sample_get_type (void) G_GNUC_CONST;
+
+GtkWidget *gl_font_sample_new      (gint           w,
+                                    gint           h,
+                                    const gchar   *sample_text,
+                                    const gchar   *font_family);
+
+
+G_END_DECLS
+
+#endif /* __FONT_SAMPLE_H__ */
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/glabels2/src/font-util.c b/glabels2/src/font-util.c
new file mode 100644 (file)
index 0000000..15555f5
--- /dev/null
@@ -0,0 +1,159 @@
+/*
+ *  font-util.h
+ *  Copyright (C) 2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <config.h>
+
+#include "font-util.h"
+
+#include <pango/pango.h>
+#include <pango/pangocairo.h>
+#include <glib/gstrfuncs.h>
+#include <libglabels/str.h>
+
+
+/****************************************************************************/
+/* Get list of all available font families.                                 */
+/****************************************************************************/
+const GList  *
+gl_font_util_get_all_families (void)
+{
+       static GList         *list = NULL;
+       PangoFontMap         *fontmap;
+       PangoContext         *context;
+       PangoFontFamily     **families;
+       gint                  n;
+       gint                  i;
+       gchar                *name;
+
+        if ( !list )
+        {
+                fontmap = pango_cairo_font_map_new ();
+                context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap));
+
+                pango_context_list_families (context, &families, &n);
+
+                for ( i=0; i<n; i++ )
+                {
+                        name = g_strdup (pango_font_family_get_name (families[i]));
+                        list = g_list_insert_sorted (list, name,
+                                                     (GCompareFunc)lgl_str_utf8_casecmp);
+                }
+
+                g_free (families);
+
+                g_object_unref (context);
+                g_object_unref (fontmap);
+        }
+
+       return list;
+}
+
+
+/****************************************************************************/
+/* Get list of all available proportional font families.                    */
+/****************************************************************************/
+const GList  *
+gl_font_util_get_proportional_families (void)
+{
+       static GList         *list = NULL;
+       PangoFontMap         *fontmap;
+       PangoContext         *context;
+       PangoFontFamily     **families;
+       gint                  n;
+       gint                  i;
+       gchar                *name;
+
+        if ( !list )
+        {
+                fontmap = pango_cairo_font_map_new ();
+                context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap));
+
+                pango_context_list_families (context, &families, &n);
+
+                for ( i=0; i<n; i++ )
+                {
+                        if ( !pango_font_family_is_monospace (families[i]) )
+                        {
+                                name = g_strdup (pango_font_family_get_name (families[i]));
+                                list = g_list_insert_sorted (list, name,
+                                                             (GCompareFunc)lgl_str_utf8_casecmp);
+                        }
+                }
+
+                g_free (families);
+
+                g_object_unref (context);
+                g_object_unref (fontmap);
+        }
+
+       return list;
+}
+
+
+/****************************************************************************/
+/* Get list of all available fixed-width font families.                     */
+/****************************************************************************/
+const GList  *
+gl_font_util_get_fixed_width_families (void)
+{
+       static GList         *list = NULL;
+       PangoFontMap         *fontmap;
+       PangoContext         *context;
+       PangoFontFamily     **families;
+       gint                  n;
+       gint                  i;
+       gchar                *name;
+
+        if ( !list )
+        {
+                fontmap = pango_cairo_font_map_new ();
+                context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap));
+
+                pango_context_list_families (context, &families, &n);
+
+                for ( i=0; i<n; i++ )
+                {
+                        if ( pango_font_family_is_monospace (families[i]) )
+                        {
+                                name = g_strdup (pango_font_family_get_name (families[i]));
+                                list = g_list_insert_sorted (list, name,
+                                                             (GCompareFunc)lgl_str_utf8_casecmp);
+                        }
+                }
+
+                g_free (families);
+
+                g_object_unref (context);
+                g_object_unref (fontmap);
+        }
+
+       return list;
+}
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
diff --git a/glabels2/src/font-util.h b/glabels2/src/font-util.h
new file mode 100644 (file)
index 0000000..38541f7
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ *  font-util.h
+ *  Copyright (C) 2009  Jim Evins <evins@snaught.com>.
+ *
+ *  This file is part of gLabels.
+ *
+ *  gLabels is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  gLabels 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with gLabels.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __FONT_UTIL_H__
+#define __FONT_UTIL_H__
+
+#include <glib/glist.h>
+
+G_BEGIN_DECLS
+
+const GList *gl_font_util_get_all_families          (void);
+const GList *gl_font_util_get_proportional_families (void);
+const GList *gl_font_util_get_fixed_width_families  (void);
+
+G_END_DECLS
+
+#endif /* __FONT_UTIL_H__ */
+
+
+
+/*
+ * Local Variables:       -- emacs
+ * mode: C                -- emacs
+ * c-basic-offset: 8      -- emacs
+ * tab-width: 8           -- emacs
+ * indent-tabs-mode: nil  -- emacs
+ * End:                   -- emacs
+ */
index df5a6c67e4b8fcb57b11309e5ba1f1bfe04dd9b0..118af190b19d6c3a9cf9cc6070fe407b60fe3219 100644 (file)
@@ -29,7 +29,7 @@
 #include <math.h>
 #include <string.h>
 
-#include "util.h"
+#include "font-util.h"
 
 #include "debug.h"
 
@@ -467,7 +467,7 @@ set_font_family (glLabelObject *object,
        g_return_if_fail (ltext && GL_IS_LABEL_TEXT (ltext));
        g_return_if_fail (font_family);
 
-       family_names = gl_util_get_font_family_list ();
+       family_names = gl_font_util_get_all_families ();
        if (g_list_find_custom (family_names, font_family, (GCompareFunc)g_utf8_collate)) {
                good_font_family = g_strdup (font_family);
        } else {
index 66bffe9ad60b889d1dcde35fc3ab83767be21a30..9a5e650e65bada5f29557ff0816e16c7478825b8 100644 (file)
@@ -96,6 +96,7 @@ struct _glObjectEditorPrivate {
        GtkWidget  *img_key_combo;
 
        GtkWidget  *text_page_vbox;
+       GtkWidget  *text_family_hbox;
        GtkWidget  *text_family_combo;
        GtkWidget  *text_size_spin;
        GtkWidget  *text_bold_toggle;
index fcc088237158779916b7dc94d51130ac04c9e6ab..ee4280eff5ab367775bffa5d5cc3ea8646797f48 100644 (file)
@@ -31,6 +31,8 @@
 #include "prefs.h"
 #include "color-combo.h"
 #include "color.h"
+#include "font-combo.h"
+#include "font-util.h"
 #include "util.h"
 
 #include "object-editor-private.h"
@@ -75,7 +77,7 @@ gl_object_editor_prepare_text_page (glObjectEditor       *editor)
        /* Extract widgets from XML tree. */
         gl_util_get_builder_widgets (editor->priv->builder,
                                      "text_page_vbox",         &editor->priv->text_page_vbox,
-                                     "text_family_combo",      &editor->priv->text_family_combo,
+                                     "text_family_hbox",       &editor->priv->text_family_hbox,
                                      "text_size_spin",         &editor->priv->text_size_spin,
                                      "text_bold_toggle",       &editor->priv->text_bold_toggle,
                                      "text_italic_toggle",     &editor->priv->text_italic_toggle,
@@ -90,6 +92,11 @@ gl_object_editor_prepare_text_page (glObjectEditor       *editor)
                                      "text_auto_shrink_check", &editor->priv->text_auto_shrink_check,
                                      NULL);
 
+       editor->priv->text_family_combo = gl_font_combo_new ("Sans");
+        gtk_box_pack_start (GTK_BOX (editor->priv->text_family_hbox),
+                            editor->priv->text_family_combo,
+                            TRUE, TRUE, 0);
+
        editor->priv->text_color_combo = gl_color_combo_new (_("Default"),
                                                              GL_COLOR_TEXT_DEFAULT,
                                                              gl_prefs->default_text_color);
@@ -97,14 +104,8 @@ gl_object_editor_prepare_text_page (glObjectEditor       *editor)
                             editor->priv->text_color_combo,
                             FALSE, FALSE, 0);
 
-       gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->text_family_combo));
        gl_util_combo_box_add_text_model ( GTK_COMBO_BOX(editor->priv->text_color_key_combo));
 
-       /* Load family names */
-       family_names = gl_util_get_font_family_list ();
-       gl_util_combo_box_set_strings (GTK_COMBO_BOX(editor->priv->text_family_combo),
-                                      family_names);
-
        /* Modify widgets */
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->text_color_radio), TRUE);
        gtk_widget_set_sensitive (editor->priv->text_color_combo, TRUE);
@@ -232,13 +233,13 @@ gl_object_editor_set_font_family (glObjectEditor      *editor,
 
         editor->priv->stop_signals = TRUE;
 
-       old_font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->text_family_combo));
+       old_font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
 
         if ( !old_font_family || g_utf8_collate( old_font_family, font_family ) )
         {
 
                 /* Make sure we have a valid font family.  if not provide a good default. */
-                family_names = gl_util_get_font_family_list ();
+                family_names = gl_font_util_get_all_families ();
                 if (g_list_find_custom (family_names, font_family, (GCompareFunc)g_utf8_collate)) {
                         good_font_family = g_strdup (font_family);
                 } else {
@@ -248,7 +249,7 @@ gl_object_editor_set_font_family (glObjectEditor      *editor,
                                 good_font_family = NULL;
                         }
                 }
-                gl_util_combo_box_set_active_text (GTK_COMBO_BOX (editor->priv->text_family_combo), good_font_family);
+                gl_font_combo_set_family (GL_FONT_COMBO (editor->priv->text_family_combo), good_font_family);
                 g_free (good_font_family);
         }
 
@@ -270,7 +271,7 @@ gl_object_editor_get_font_family (glObjectEditor      *editor)
 
        gl_debug (DEBUG_EDITOR, "START");
 
-       font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->text_family_combo));
+       font_family = gl_font_combo_get_family (GL_FONT_COMBO (editor->priv->text_family_combo));
 
        gl_debug (DEBUG_EDITOR, "END");
 
index a0f2492356a868a33e8504aee9dd935b58845f08..b263e522c08401a19427c8003ef44c718e79c18c 100644 (file)
@@ -34,6 +34,8 @@
 #include "hig.h"
 #include "color-combo.h"
 #include "color.h"
+#include "font-combo.h"
+#include "font-util.h"
 #include "util.h"
 
 #include "debug.h"
@@ -65,6 +67,7 @@ struct _glPrefsDialogPrivate
        GtkWidget       *page_size_a4_radio;
 
        /* Default text properties */
+       GtkWidget       *text_family_hbox;
        GtkWidget       *text_family_combo;
        GtkWidget       *text_size_spin;
        GtkWidget       *text_bold_toggle;
@@ -322,7 +325,7 @@ construct_object_page (glPrefsDialog *dialog)
         GList    *family_names;
 
         gl_util_get_builder_widgets (dialog->priv->builder,
-                                     "text_family_combo",      &dialog->priv->text_family_combo,
+                                     "text_family_hbox",       &dialog->priv->text_family_hbox,
                                      "text_size_spin",         &dialog->priv->text_size_spin,
                                      "text_bold_toggle",       &dialog->priv->text_bold_toggle,
                                      "text_italic_toggle",     &dialog->priv->text_italic_toggle,
@@ -336,7 +339,7 @@ construct_object_page (glPrefsDialog *dialog)
                                      "fill_color_hbox",        &dialog->priv->fill_color_hbox,
                                      NULL);
 
-       gl_util_combo_box_add_text_model (GTK_COMBO_BOX (dialog->priv->text_family_combo));
+        dialog->priv->text_family_combo = gl_font_combo_new ("Sans");
 
        dialog->priv->text_color_combo = gl_color_combo_new (_("Default"),
                                                              GL_COLOR_TEXT_DEFAULT,
@@ -348,22 +351,19 @@ construct_object_page (glPrefsDialog *dialog)
                                                              GL_COLOR_NO_FILL,
                                                              gl_prefs->default_fill_color);
 
+        gtk_box_pack_start (GTK_BOX (dialog->priv->text_family_hbox),
+                            dialog->priv->text_family_combo,
+                            FALSE, FALSE, 0);
         gtk_box_pack_start (GTK_BOX (dialog->priv->text_color_hbox),
                             dialog->priv->text_color_combo,
                             FALSE, FALSE, 0);
         gtk_box_pack_start (GTK_BOX (dialog->priv->line_color_hbox),
                             dialog->priv->line_color_combo,
                             FALSE, FALSE, 0);
-        gtk_box_pack_start (GTK_CONTAINER (dialog->priv->fill_color_hbox),
+        gtk_box_pack_start (GTK_BOX (dialog->priv->fill_color_hbox),
                             dialog->priv->fill_color_combo,
                             FALSE, FALSE, 0);
 
-        /* Load family names */
-        family_names = gl_util_get_font_family_list ();
-       gl_util_combo_box_set_strings (GTK_COMBO_BOX (dialog->priv->text_family_combo),
-                                      family_names);
-                                                                                
-
        g_signal_connect_swapped (G_OBJECT(dialog->priv->text_family_combo),
                                  "changed",
                                  G_CALLBACK(update_prefs_from_object_page),
@@ -517,15 +517,15 @@ update_locale_page_from_prefs (glPrefsDialog *dialog)
 static void
 update_object_page_from_prefs (glPrefsDialog *dialog)
 {
-        GList    *family_names;
-        gchar    *good_font_family;
+        const GList *family_names;
+        gchar       *good_font_family;
  
        dialog->priv->stop_signals = TRUE;
 
 
         /* Make sure we have a valid font family.  if not provide a good default. */
-        family_names = gl_util_get_font_family_list ();
-        if (g_list_find_custom (family_names,
+        family_names = gl_font_util_get_all_families ();
+        if (g_list_find_custom ((GList *)family_names,
                                gl_prefs->default_font_family,
                                (GCompareFunc)g_utf8_collate))
         {
@@ -542,8 +542,8 @@ update_object_page_from_prefs (glPrefsDialog *dialog)
                         good_font_family = NULL;
                 }
         }
-       gl_util_combo_box_set_active_text (GTK_COMBO_BOX (dialog->priv->text_family_combo),
-                                          good_font_family);
+       gl_font_combo_set_family (GL_FONT_COMBO (dialog->priv->text_family_combo),
+                                  good_font_family);
         g_free (good_font_family);
 
         gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->text_size_spin),
@@ -637,7 +637,7 @@ update_prefs_from_object_page (glPrefsDialog *dialog)
 
         g_free (gl_prefs->default_font_family);
         gl_prefs->default_font_family =
-               gtk_combo_box_get_active_text (GTK_COMBO_BOX (dialog->priv->text_family_combo));
+               gl_font_combo_get_family (GL_FONT_COMBO (dialog->priv->text_family_combo));
         gl_prefs->default_font_size =
                 gtk_spin_button_get_value (GTK_SPIN_BUTTON(dialog->priv->text_size_spin));
 
index 644748f8273f211c5753c0d650e431cf5ca41746..6ed7ed28fbf4319ee847e1cba002846c63e59b17 100644 (file)
 
 #include <glib/gi18n.h>
 #include <gtk/gtkbuilder.h>
-#include <gtk/gtkcombobox.h>
 #include <gtk/gtkspinbutton.h>
 #include <gtk/gtktoolbar.h>
 #include <gtk/gtktoggletoolbutton.h>
 #include <string.h>
 
 #include "util.h"
-#include "color-button.h"
+#include "font-combo.h"
+#include "color-combo-button.h"
 #include "stock-pixmaps/stockpixbufs.h"
 #include "prefs.h"
 #include "color.h"
@@ -57,6 +57,7 @@ struct _glUIPropertyBarPrivate {
        GtkWidget  *tool_bar;
 
        /* Font selection */
+       GtkWidget  *font_family_eventbox;
        GtkWidget  *font_family_combo;
        GtkWidget  *font_size_spin;
        GtkWidget  *font_bold_toggle;
@@ -70,10 +71,10 @@ struct _glUIPropertyBarPrivate {
        /* Color combos */
         GtkWidget  *text_color_eventbox;
        GtkWidget  *text_color_button;
-       GtkWidget  *fill_color_button;
         GtkWidget  *fill_color_eventbox;
-       GtkWidget  *line_color_button;
+       GtkWidget  *fill_color_button;
         GtkWidget  *line_color_eventbox;
+       GtkWidget  *line_color_button;
 
        /* Line width */
        GtkWidget  *line_width_spin;
@@ -104,17 +105,17 @@ static void     font_family_changed_cb           (GtkComboBox          *combo,
 static void     font_size_changed_cb             (GtkSpinButton        *spin,
                                                  glUIPropertyBar      *this);
 
-static void     text_color_changed_cb            (glColorButton        *cc,
+static void     text_color_changed_cb            (glColorComboButton   *cc,
                                                   guint                 color,
                                                  gboolean              is_default,
                                                  glUIPropertyBar      *this);
 
-static void     fill_color_changed_cb            (glColorButton        *cc,
+static void     fill_color_changed_cb            (glColorComboButton   *cc,
                                                   guint                 color,
                                                  gboolean              is_default,
                                                  glUIPropertyBar      *this);
 
-static void     line_color_changed_cb            (glColorButton        *cc,
+static void     line_color_changed_cb            (glColorComboButton   *cc,
                                                   guint                 color,
                                                  gboolean              is_default,
                                                  glUIPropertyBar      *this);
@@ -257,7 +258,7 @@ gl_ui_property_bar_construct (glUIPropertyBar   *this)
 
         gl_util_get_builder_widgets (builder,
                                      "property_toolbar",        &this->priv->tool_bar,
-                                     "font_family_combo",       &this->priv->font_family_combo,
+                                     "font_family_eventbox",    &this->priv->font_family_eventbox,
                                      "font_size_spin",          &this->priv->font_size_spin,
                                      "font_bold_toggle",        &this->priv->font_bold_toggle,
                                      "font_italic_toggle",      &this->priv->font_italic_toggle,
@@ -272,38 +273,42 @@ gl_ui_property_bar_construct (glUIPropertyBar   *this)
 
        gtk_container_add (GTK_CONTAINER (this), this->priv->tool_bar);
 
+        this->priv->font_family_combo = gl_font_combo_new (gl_prefs->default_font_family);
+        gtk_container_add (GTK_CONTAINER (this->priv->font_family_eventbox),
+                           this->priv->font_family_combo);
+
         pixbuf = gdk_pixbuf_new_from_inline (-1, stock_text_24, FALSE, NULL);
         this->priv->text_color_button =
-                gl_color_button_new (pixbuf,
-                                     _("Default"),
-                                     GL_COLOR_TEXT_DEFAULT,
-                                     gl_prefs->default_text_color);
-        gl_color_button_set_relief (GL_COLOR_BUTTON(this->priv->text_color_button),
-                                    GTK_RELIEF_NONE);
+                gl_color_combo_button_new (pixbuf,
+                                           _("Default"),
+                                           GL_COLOR_TEXT_DEFAULT,
+                                           gl_prefs->default_text_color);
+        gl_color_combo_button_set_relief (GL_COLOR_COMBO_BUTTON(this->priv->text_color_button),
+                                          GTK_RELIEF_NONE);
        g_object_unref (G_OBJECT (pixbuf));
         gtk_container_add (GTK_CONTAINER (this->priv->text_color_eventbox),
                            this->priv->text_color_button);
 
         pixbuf = gdk_pixbuf_new_from_inline (-1, stock_bucket_fill_24, FALSE, NULL);
         this->priv->fill_color_button =
-                gl_color_button_new (pixbuf,
-                                     _("No Fill"),
-                                     GL_COLOR_NO_FILL,
-                                     gl_prefs->default_fill_color);
-        gl_color_button_set_relief (GL_COLOR_BUTTON(this->priv->fill_color_button),
-                                    GTK_RELIEF_NONE);
+                gl_color_combo_button_new (pixbuf,
+                                           _("No Fill"),
+                                           GL_COLOR_NO_FILL,
+                                           gl_prefs->default_fill_color);
+        gl_color_combo_button_set_relief (GL_COLOR_COMBO_BUTTON(this->priv->fill_color_button),
+                                          GTK_RELIEF_NONE);
        g_object_unref (G_OBJECT (pixbuf));
         gtk_container_add (GTK_CONTAINER (this->priv->fill_color_eventbox),
                            this->priv->fill_color_button);
 
         pixbuf = gdk_pixbuf_new_from_inline (-1, stock_pencil_24, FALSE, NULL);
         this->priv->line_color_button =
-                gl_color_button_new (pixbuf,
-                                     _("No Line"),
-                                     GL_COLOR_NO_LINE,
-                                     gl_prefs->default_line_color);
-       gl_color_button_set_relief (GL_COLOR_BUTTON(this->priv->line_color_button),
-                                    GTK_RELIEF_NONE);
+                gl_color_combo_button_new (pixbuf,
+                                           _("No Line"),
+                                           GL_COLOR_NO_LINE,
+                                           gl_prefs->default_line_color);
+       gl_color_combo_button_set_relief (GL_COLOR_COMBO_BUTTON(this->priv->line_color_button),
+                                          GTK_RELIEF_NONE);
        g_object_unref (G_OBJECT (pixbuf));
         gtk_container_add (GTK_CONTAINER (this->priv->line_color_eventbox),
                            this->priv->line_color_button);
@@ -314,27 +319,6 @@ gl_ui_property_bar_construct (glUIPropertyBar   *this)
        set_doc_items_sensitive (this, FALSE);
 
        /* Font family entry widget */
-       gl_util_combo_box_add_text_model (GTK_COMBO_BOX (this->priv->font_family_combo));
-       family_names = gl_util_get_font_family_list ();
-       gl_util_combo_box_set_strings (GTK_COMBO_BOX (this->priv->font_family_combo),
-                                      family_names);
-       gtk_widget_set_size_request (this->priv->font_family_combo, 200, -1);
-
-       /* Make sure we have a valid font.  if not provide a good default. */
-       family_node = g_list_find_custom (family_names,
-                                         gl_prefs->default_font_family,
-                                         (GCompareFunc)g_utf8_collate);
-       if (family_node)
-        {
-               gtk_combo_box_set_active (GTK_COMBO_BOX (this->priv->font_family_combo),
-                                         g_list_position (family_names,
-                                                          family_node));
-       }
-        else
-        {
-               gtk_combo_box_set_active (GTK_COMBO_BOX (this->priv->font_family_combo), 0);
-       }
-
        g_signal_connect (G_OBJECT (this->priv->font_family_combo),
                          "changed", G_CALLBACK (font_family_changed_cb), this);
 
@@ -372,19 +356,22 @@ gl_ui_property_bar_construct (glUIPropertyBar   *this)
                          "toggled", G_CALLBACK (text_align_toggled_cb), this);
 
        /* Text color widget */
-       gl_color_button_set_color (GL_COLOR_BUTTON (this->priv->text_color_button), gl_prefs->default_text_color);
+       gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->text_color_button),
+                                         gl_prefs->default_text_color);
        g_signal_connect (G_OBJECT (this->priv->text_color_button),
                          "color_changed",
                          G_CALLBACK (text_color_changed_cb), this);
 
        /* Fill color widget */
-       gl_color_button_set_color (GL_COLOR_BUTTON (this->priv->fill_color_button), gl_prefs->default_fill_color);
+       gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->fill_color_button),
+                                         gl_prefs->default_fill_color);
        g_signal_connect (G_OBJECT (this->priv->fill_color_button),
                          "color_changed",
                          G_CALLBACK (fill_color_changed_cb), this);
 
        /* Line color widget */
-       gl_color_button_set_color (GL_COLOR_BUTTON (this->priv->line_color_button), gl_prefs->default_line_color);
+       gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->line_color_button),
+                                         gl_prefs->default_line_color);
        g_signal_connect (G_OBJECT (this->priv->line_color_button),
                          "color_changed",
                          G_CALLBACK (line_color_changed_cb), this);
@@ -411,7 +398,7 @@ reset_to_default_properties (glView *view,
        gchar     *good_font_family;
 
        /* Make sure we have a valid font.  if not provide a good default. */
-       family_names = gl_util_get_font_family_list ();
+       family_names = gl_font_util_get_all_families ();
        if (g_list_find_custom (family_names,
                                view->default_font_family,
                                (GCompareFunc)g_utf8_collate))
@@ -429,8 +416,8 @@ reset_to_default_properties (glView *view,
                        good_font_family = NULL;
                }
        }
-       gl_util_combo_box_set_active_text (GTK_COMBO_BOX (this->priv->font_family_combo),
-                                          good_font_family);
+       gl_font_combo_set_family (GL_FONT_COMBO (this->priv->font_family_combo),
+                                  good_font_family);
        g_free (good_font_family);
 
        gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->font_size_spin),
@@ -448,11 +435,14 @@ reset_to_default_properties (glView *view,
        gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (this->priv->text_align_right_radio),
                                           (view->default_text_alignment == PANGO_ALIGN_RIGHT));
 
-       gl_color_button_set_color (GL_COLOR_BUTTON(this->priv->text_color_button), view->default_text_color);
+       gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON(this->priv->text_color_button),
+                                         view->default_text_color);
 
-       gl_color_button_set_color (GL_COLOR_BUTTON(this->priv->fill_color_button), view->default_fill_color);
+       gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON(this->priv->fill_color_button),
+                                         view->default_fill_color);
 
-       gl_color_button_set_color (GL_COLOR_BUTTON(this->priv->line_color_button), view->default_line_color);
+       gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON(this->priv->line_color_button),
+                                         view->default_line_color);
 
        gtk_spin_button_set_value (GTK_SPIN_BUTTON(this->priv->line_width_spin),
                                   view->default_line_width);
@@ -602,8 +592,8 @@ update_text_properties (glView *view,
        if (is_same_font_family && (selection_font_family != NULL)) 
                gl_debug (DEBUG_PROPERTY_BAR, "same font family = %s", 
                          selection_font_family);
-       gl_util_combo_box_set_active_text (GTK_COMBO_BOX (this->priv->font_family_combo),
-                                          is_same_font_family?selection_font_family:"");
+       gl_font_combo_set_family (GL_FONT_COMBO (this->priv->font_family_combo),
+                                  is_same_font_family?selection_font_family:"");
        g_free (selection_font_family);
 
        if (is_same_font_size)
@@ -621,8 +611,8 @@ update_text_properties (glView *view,
        if (is_same_text_color)
         {
                gl_debug (DEBUG_PROPERTY_BAR, "same text color = %08x", selection_text_color);
-               gl_color_button_set_color (GL_COLOR_BUTTON (this->priv->text_color_button),
-                                          selection_text_color);
+               gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->text_color_button),
+                                                 selection_text_color);
        }
 
        if (is_same_is_italic)
@@ -713,8 +703,8 @@ update_fill_color (glView *view,
        if (is_same_fill_color)
         {
                gl_debug (DEBUG_PROPERTY_BAR, "same fill color = %08x", selection_fill_color);
-               gl_color_button_set_color (GL_COLOR_BUTTON (this->priv->fill_color_button),
-                                          selection_fill_color);
+               gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->fill_color_button),
+                                                 selection_fill_color);
        }
 }
 
@@ -777,8 +767,8 @@ update_line_color (glView *view,
        if (is_same_line_color)
         {
                gl_debug (DEBUG_PROPERTY_BAR, "same line color = %08x", selection_line_color);
-               gl_color_button_set_color (GL_COLOR_BUTTON (this->priv->line_color_button),
-                                          selection_line_color);
+               gl_color_combo_button_set_color (GL_COLOR_COMBO_BUTTON (this->priv->line_color_button),
+                                                 selection_line_color);
        }
 }
 
@@ -886,7 +876,7 @@ font_family_changed_cb (GtkComboBox     *combo,
 
        gl_debug (DEBUG_PROPERTY_BAR, "START");
 
-       font_family = gtk_combo_box_get_active_text (GTK_COMBO_BOX (combo));
+       font_family = gl_font_combo_get_family (GL_FONT_COMBO (combo));
        if ( strlen(font_family) )
         {
                gl_view_set_selection_font_family (this->priv->view,
@@ -933,7 +923,7 @@ font_size_changed_cb (GtkSpinButton        *spin,
 /* PRIVATE.  Text color combo changed.                                      */
 /*--------------------------------------------------------------------------*/
 static void
-text_color_changed_cb (glColorButton        *cc,
+text_color_changed_cb (glColorComboButton   *cc,
                        guint                 color,
                       gboolean              is_default,
                       glUIPropertyBar      *this)
@@ -981,7 +971,7 @@ text_color_changed_cb (glColorButton        *cc,
 /* PRIVATE.  Fill color combo changed.                                      */
 /*--------------------------------------------------------------------------*/
 static void
-fill_color_changed_cb (glColorButton        *cc,
+fill_color_changed_cb (glColorComboButton   *cc,
                        guint                 color,
                       gboolean              is_default,
                       glUIPropertyBar      *this)
@@ -1030,7 +1020,7 @@ fill_color_changed_cb (glColorButton        *cc,
 /* PRIVATE.  Line color combo changed.                                      */
 /*--------------------------------------------------------------------------*/
 static void
-line_color_changed_cb (glColorButton        *cc,
+line_color_changed_cb (glColorComboButton   *cc,
                        guint                 color,
                       gboolean              is_default,
                       glUIPropertyBar      *this)
index 92e31107d77b7e17f65ba2153fce20bd3a64cc8d..f2f7dcfac938e87177ab5f84e17c3b7bbcec6cb2 100644 (file)
@@ -307,114 +307,6 @@ gl_util_combo_box_add_text_model (GtkComboBox       *combo)
 
 
 
-/****************************************************************************/
-/* Get list of available font families.                                     */
-/****************************************************************************/
-GList  *
-gl_util_get_font_family_list (void)
-{
-       static GList         *list = NULL;
-       PangoFontMap         *fontmap;
-       PangoContext         *context;
-       PangoFontFamily     **families;
-       gint                  n;
-       gint                  i;
-       gchar                *name;
-
-        if ( !list )
-        {
-                fontmap = pango_cairo_font_map_new ();
-                context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fontmap));
-
-                pango_context_list_families (context, &families, &n);
-
-                for ( i=0; i<n; i++ )
-                {
-                        name = g_strdup (pango_font_family_get_name (families[i]));
-                        list = g_list_insert_sorted (list, name,
-                                                     (GCompareFunc)lgl_str_utf8_casecmp);
-                }
-
-                g_free (families);
-
-                g_object_unref (context);
-                g_object_unref (fontmap);
-        }
-
-       return list;
-}
-
-
-/****************************************************************************/
-/* Convert cairo surface to GdkPixbuf.                                      */
-/* from http://davyd.livejournal.com/240469.html                            */
-/****************************************************************************/
-static inline guint8
-convert_color_channel (guint8 src, guint8 alpha)
-{
-       return alpha ? ((src << 8) - src) / alpha : 0;
-}
-
-/**
- * gl_util_cairo_convert_to_pixbuf:
- * Converts from a Cairo image surface to a GdkPixbuf. Why does GTK+ not
- * implement this?
- */
-GdkPixbuf *
-gl_util_cairo_convert_to_pixbuf (cairo_surface_t *surface)
-{
-       GdkPixbuf *pixbuf;
-       int width, height;
-       int srcstride, dststride;
-       guchar *srcpixels, *dstpixels;
-       guchar *srcpixel, *dstpixel;
-       int n_channels;
-       int x, y;
-
-       switch (cairo_image_surface_get_format (surface))
-       {
-               case CAIRO_FORMAT_ARGB32:
-               case CAIRO_FORMAT_RGB24:
-                       break;
-
-               default:
-                       g_critical ("This Cairo surface format not supported");
-                       return NULL;
-                       break;
-       }
-
-       width = cairo_image_surface_get_width (surface);
-       height = cairo_image_surface_get_height (surface);
-       srcstride = cairo_image_surface_get_stride (surface);
-       srcpixels = cairo_image_surface_get_data (surface);
-
-       pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8,
-                       width, height);
-       dststride = gdk_pixbuf_get_rowstride (pixbuf);
-       dstpixels = gdk_pixbuf_get_pixels (pixbuf);
-       n_channels = gdk_pixbuf_get_n_channels (pixbuf);
-
-       for (y = 0; y < height; y++)
-       {
-               for (x = 0; x < width; x++)
-               {
-                       srcpixel = srcpixels + y * srcstride + x * 4;
-                       dstpixel = dstpixels + y * dststride + x * n_channels;
-
-                       dstpixel[0] = convert_color_channel (srcpixel[2],
-                                                            srcpixel[3]);
-                       dstpixel[1] = convert_color_channel (srcpixel[1],
-                                                            srcpixel[3]);
-                       dstpixel[2] = convert_color_channel (srcpixel[0],
-                                                            srcpixel[3]);
-                       dstpixel[3] = srcpixel[3];
-               }
-       }
-
-       return pixbuf;
-}
-
-
 /****************************************************************************/
 /* Get widgets from GtkBuilder "en masse."                                  */
 /****************************************************************************/
index 5629cbace2740903444038b63a680a87878bfeda..d4458d1842abd5abb3b46a82ab675ad72b8e3f43 100644 (file)
@@ -51,8 +51,6 @@ void gl_util_combo_box_set_active_text (GtkComboBox       *combo,
                                        const gchar       *text);
 void gl_util_combo_box_add_text_model  (GtkComboBox       *combo);
 
-GList  *gl_util_get_font_family_list (void);
-
 GdkPixbuf *gl_util_cairo_convert_to_pixbuf (cairo_surface_t *surface);
 
 void gl_util_get_builder_widgets (GtkBuilder *builder,