Blame plugins/gtk+/glade-gtk-combo-box.c

Packit 1e8aac
/*
Packit 1e8aac
 * glade-gtk-combo-box.c - GladeWidgetAdaptor for GtkComboBox
Packit 1e8aac
 *
Packit 1e8aac
 * Copyright (C) 2013 Tristan Van Berkom
Packit 1e8aac
 *
Packit 1e8aac
 * Authors:
Packit 1e8aac
 *      Tristan Van Berkom <tristan.van.berkom@gmail.com>
Packit 1e8aac
 *
Packit 1e8aac
 * This library is free software; you can redistribute it and/or modify it
Packit 1e8aac
 * under the terms of the GNU Lesser General Public License as
Packit 1e8aac
 * published by the Free Software Foundation; either version 2.1 of
Packit 1e8aac
 * the License, or (at your option) any later version.
Packit 1e8aac
 *
Packit 1e8aac
 * This library is distributed in the hope that it will be useful, but
Packit 1e8aac
 * WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 1e8aac
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 1e8aac
 * Lesser General Public License for more details.
Packit 1e8aac
 *
Packit 1e8aac
 * You should have received a copy of the GNU Lesser General Public 
Packit 1e8aac
 * License along with this program; if not, write to the Free Software
Packit 1e8aac
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Packit 1e8aac
 */
Packit 1e8aac
Packit 1e8aac
#include <config.h>
Packit 1e8aac
#include <glib/gi18n-lib.h>
Packit 1e8aac
#include <gladeui/glade.h>
Packit 1e8aac
Packit 1e8aac
#include "glade-gtk-cell-layout.h"
Packit 1e8aac
#include "glade-combo-box-editor.h"
Packit 1e8aac
Packit 1e8aac
#define NO_ENTRY_MSG _("This combo box is not configured to have an entry")
Packit 1e8aac
Packit 1e8aac
GladeEditable *
Packit 1e8aac
glade_gtk_combo_box_create_editable (GladeWidgetAdaptor * adaptor,
Packit 1e8aac
				     GladeEditorPageType type)
Packit 1e8aac
{
Packit 1e8aac
  if (type == GLADE_PAGE_GENERAL)
Packit 1e8aac
    {
Packit 1e8aac
      return (GladeEditable *) glade_combo_box_editor_new ();
Packit 1e8aac
    }
Packit 1e8aac
Packit 1e8aac
  return GWA_GET_CLASS (GTK_TYPE_CONTAINER)->create_editable (adaptor, type);
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
void
Packit 1e8aac
glade_gtk_combo_box_post_create (GladeWidgetAdaptor *adaptor,
Packit 1e8aac
				 GObject            *object, 
Packit 1e8aac
				 GladeCreateReason   reason)
Packit 1e8aac
{
Packit 1e8aac
  GladeWidget *widget;
Packit 1e8aac
Packit 1e8aac
  /* Chain Up */
Packit 1e8aac
  GWA_GET_CLASS (GTK_TYPE_CONTAINER)->post_create (adaptor, object, reason);
Packit 1e8aac
Packit 1e8aac
  widget = glade_widget_get_from_gobject (object);
Packit 1e8aac
  if (gtk_combo_box_get_has_entry (GTK_COMBO_BOX (object)))
Packit 1e8aac
    {
Packit 1e8aac
      glade_widget_property_set_sensitive (widget, "entry-text-column", TRUE, NULL);
Packit 1e8aac
      glade_widget_property_set_sensitive (widget, "has-frame", TRUE, NULL);
Packit 1e8aac
    }
Packit 1e8aac
  else
Packit 1e8aac
    {
Packit 1e8aac
      glade_widget_property_set_sensitive (widget, "entry-text-column", FALSE, NO_ENTRY_MSG);
Packit 1e8aac
      glade_widget_property_set_sensitive (widget, "has-frame", FALSE, NO_ENTRY_MSG);
Packit 1e8aac
    }
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
void
Packit 1e8aac
glade_gtk_combo_box_set_property (GladeWidgetAdaptor * adaptor,
Packit 1e8aac
                                  GObject * object,
Packit 1e8aac
                                  const gchar * id, const GValue * value)
Packit 1e8aac
{
Packit 1e8aac
  if (!strcmp (id, "entry-text-column"))
Packit 1e8aac
    {
Packit 1e8aac
      /* Avoid warnings */
Packit 1e8aac
      if (g_value_get_int (value) >= 0)
Packit 1e8aac
        GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor,
Packit 1e8aac
                                                          object, id, value);
Packit 1e8aac
    }
Packit 1e8aac
  else if (!strcmp (id, "text-column"))
Packit 1e8aac
    {
Packit 1e8aac
      if (g_value_get_int (value) >= 0)
Packit 1e8aac
        gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX (object),
Packit 1e8aac
                                             g_value_get_int (value));
Packit 1e8aac
    }
Packit 1e8aac
  else if (!strcmp (id, "add-tearoffs"))
Packit 1e8aac
    {
Packit 1e8aac
      GladeWidget *widget = glade_widget_get_from_gobject (object);
Packit 1e8aac
Packit 1e8aac
      if (g_value_get_boolean (value))
Packit 1e8aac
	glade_widget_property_set_sensitive (widget, "tearoff-title", TRUE, NULL);
Packit 1e8aac
      else
Packit 1e8aac
	glade_widget_property_set_sensitive (widget, "tearoff-title", FALSE,
Packit 1e8aac
					     _("Tearoff menus are disabled"));
Packit 1e8aac
    }
Packit 1e8aac
  else
Packit 1e8aac
    GWA_GET_CLASS (GTK_TYPE_CONTAINER)->set_property (adaptor,
Packit 1e8aac
                                                      object, id, value);
Packit 1e8aac
}
Packit 1e8aac
Packit 1e8aac
GList *
Packit 1e8aac
glade_gtk_combo_box_get_children (GladeWidgetAdaptor * adaptor,
Packit 1e8aac
                                  GtkComboBox * combo)
Packit 1e8aac
{
Packit 1e8aac
  GList *list = NULL;
Packit 1e8aac
Packit 1e8aac
  list = glade_gtk_cell_layout_get_children (adaptor, G_OBJECT (combo));
Packit 1e8aac
Packit 1e8aac
  if (gtk_combo_box_get_has_entry (combo))
Packit 1e8aac
    list = g_list_append (list, gtk_bin_get_child (GTK_BIN (combo)));
Packit 1e8aac
Packit 1e8aac
  return list;
Packit 1e8aac
}