Exemple #1
0
static void
glade_gtk_widget_add2group_cb (GtkMenuItem * item, GladeWidget * gwidget)
{
  GladeWidget *group =
      g_object_get_data (G_OBJECT (item), "glade-group-widget");
  GladeWidgetAdaptor *adaptor =
      glade_widget_adaptor_get_by_type (GTK_TYPE_SIZE_GROUP);
  GList *widget_list = NULL, *new_list;
  GladeProperty *property;

  if (group)
    glade_command_push_group (_("Adding %s to Size Group %s"), 
			      glade_widget_get_name (gwidget),
                              glade_widget_get_name (group));
  else
    glade_command_push_group (_("Adding %s to a new Size Group"),
                              glade_widget_get_name (gwidget));

  if (!group)
    /* Cant cancel a size group */
    group =
        glade_command_create (adaptor, NULL, NULL,
                              glade_widget_get_project (gwidget));

  property = glade_widget_get_property (group, "widgets");
  glade_property_get (property, &widget_list);
  new_list = g_list_copy (widget_list);
  if (!g_list_find (widget_list, glade_widget_get_object (gwidget)))
    new_list = g_list_append (new_list, glade_widget_get_object (gwidget));
  glade_command_set_property (property, new_list);

  g_list_free (new_list);

  glade_command_pop_group ();
}
static void
glade_gtk_widget_add2group_cb (GtkMenuItem * item, GladeWidget * gwidget)
{
  GladeWidget *group =
      g_object_get_data (G_OBJECT (item), "glade-group-widget");
  GladeWidgetAdaptor *adaptor =
      glade_widget_adaptor_get_by_type (GTK_TYPE_SIZE_GROUP);
  GList *widget_list = NULL, *new_list;
  GladeProperty *property;
  const gchar *current_name;
  const gchar *size_group_name = NULL;
  gchar *widget_name;

  /* Display "(unnamed)" for unnamed size groups */
  if (group)
    {
      size_group_name = glade_widget_get_name (group);
      if (g_str_has_prefix (size_group_name, GLADE_UNNAMED_PREFIX))
	size_group_name = _("(unnamed)");
    }

  /* Ensure the widget has a name if it's going to be referred to by a size group */
  current_name = glade_widget_get_name (gwidget);
  if (g_str_has_prefix (current_name, GLADE_UNNAMED_PREFIX))
    widget_name = glade_project_new_widget_name (glade_widget_get_project (gwidget), NULL,
						 glade_widget_adaptor_get_generic_name (glade_widget_get_adaptor (gwidget)));
  else
    widget_name = g_strdup (current_name);

  if (group)
    glade_command_push_group (_("Adding %s to Size Group %s"),
			      widget_name,
                              size_group_name);
  else
    glade_command_push_group (_("Adding %s to a new Size Group"),
                              widget_name);

  glade_command_set_name (gwidget, widget_name);

  if (!group)
    /* Cant cancel a size group */
    group =
        glade_command_create (adaptor, NULL, NULL,
                              glade_widget_get_project (gwidget));

  property = glade_widget_get_property (group, "widgets");
  glade_property_get (property, &widget_list);
  new_list = g_list_copy (widget_list);
  if (!g_list_find (widget_list, glade_widget_get_object (gwidget)))
    new_list = g_list_append (new_list, glade_widget_get_object (gwidget));
  glade_command_set_property (property, new_list);

  g_list_free (new_list);
  g_free (widget_name);

  glade_command_pop_group ();
}
static void
use_center_child_toggled (GtkWidget            * widget,
                          GladeActionBarEditor * box_editor)
{
  GladeActionBarEditorPrivate *priv = box_editor->priv;
  GladeWidget   *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (box_editor));
  GladeWidget   *gcenter = NULL;
  GtkWidget     *box;
  GtkWidget     *center;
  GladeProperty *property;
  gboolean       use_center_child;

  if (glade_editable_loading (GLADE_EDITABLE (box_editor)) || !gwidget)
    return;

  /* Get new desired property state */
  use_center_child = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->use_center_child));

  /* Get any existing center child */
  box = (GtkWidget *)glade_widget_get_object (gwidget);
  center = gtk_action_bar_get_center_widget (GTK_ACTION_BAR (box));

  if (center && !GLADE_IS_PLACEHOLDER (center))
    gcenter = glade_widget_get_from_gobject (center);

  glade_editable_block (GLADE_EDITABLE (box_editor));

  if (use_center_child)
    glade_command_push_group (_("Setting %s to use a center child"),
                              glade_widget_get_name (gwidget));
  else
    glade_command_push_group (_("Setting %s to not use a center child"),
                              glade_widget_get_name (gwidget));

  /* If a project widget exists when were disabling center child, it needs
   * to be removed first as a part of the issuing GladeCommand group
   */
  if (gcenter)
    {
      GList list;
      list.prev = list.next = NULL;
      list.data = gcenter;
      glade_command_delete (&list);
    }

  property = glade_widget_get_property (gwidget, "use-center-child");
  glade_command_set_property (property, use_center_child);

  glade_command_pop_group ();

  glade_editable_unblock (GLADE_EDITABLE (box_editor));

  /* reload buttons and sensitivity and stuff... */
  glade_editable_load (GLADE_EDITABLE (box_editor), gwidget);
}
Exemple #4
0
static void
glade_gtk_listbox_child_insert_action (GladeWidgetAdaptor *adaptor,
                                       GObject            *container,
                                       GObject            *object,
                                       const gchar        *group_format,
                                       gboolean            after)
{
  GladeWidget *parent;
  GladeWidget *gchild;
  gint position;

  parent = glade_widget_get_from_gobject (container);
  glade_command_push_group (group_format, glade_widget_get_name (parent));

  position = gtk_list_box_row_get_index (GTK_LIST_BOX_ROW (object));
  if (after)
    position++;

  gchild = glade_command_create (glade_widget_adaptor_get_by_type (GTK_TYPE_LIST_BOX_ROW),
                                 parent,
                                 NULL,
                                 glade_widget_get_project (parent));
  glade_widget_pack_property_set (gchild, "position", position);

  glade_command_pop_group ();
}
Exemple #5
0
static void
glade_gtk_size_group_write_widgets (GladeWidget * widget,
                                    GladeXmlContext * context,
                                    GladeXmlNode * node)
{
  GladeXmlNode *widgets_node, *widget_node;
  GList *widgets = NULL, *list;
  GladeWidget *awidget;

  widgets_node = glade_xml_node_new (context, GLADE_TAG_SIZEGROUP_WIDGETS);

  if (glade_widget_property_get (widget, "widgets", &widgets))
    {
      for (list = widgets; list; list = list->next)
        {
          awidget = glade_widget_get_from_gobject (list->data);
          widget_node =
              glade_xml_node_new (context, GLADE_TAG_SIZEGROUP_WIDGET);
          glade_xml_node_append_child (widgets_node, widget_node);
          glade_xml_node_set_property_string (widget_node, GLADE_TAG_NAME,
                                              glade_widget_get_name (awidget));
        }
    }

  if (!glade_xml_node_get_children (widgets_node))
    glade_xml_node_delete (widgets_node);
  else
    glade_xml_node_append_child (node, widgets_node);

}
Exemple #6
0
static void
glade_gtk_window_write_accel_groups (GladeWidget * widget,
                                     GladeXmlContext * context,
                                     GladeXmlNode * node)
{
  GladeXmlNode *groups_node, *group_node;
  GList *groups = NULL, *list;
  GladeWidget *agroup;

  groups_node = glade_xml_node_new (context, GLADE_TAG_ACCEL_GROUPS);

  if (glade_widget_property_get (widget, "accel-groups", &groups))
    {
      for (list = groups; list; list = list->next)
        {
          agroup = glade_widget_get_from_gobject (list->data);
          group_node = glade_xml_node_new (context, GLADE_TAG_ACCEL_GROUP);
          glade_xml_node_append_child (groups_node, group_node);
          glade_xml_node_set_property_string (group_node, GLADE_TAG_NAME,
                                              glade_widget_get_name (agroup));
        }
    }

  if (!glade_xml_node_get_children (groups_node))
    glade_xml_node_delete (groups_node);
  else
    glade_xml_node_append_child (node, groups_node);

}
static void
icon_file_toggled (GtkWidget         *widget,
		   GladeWindowEditor *window_editor)
{
  GladeWindowEditorPrivate *priv = window_editor->priv;
  GladeWidget   *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (window_editor));
  GladeProperty *property;

  if (glade_editable_loading (GLADE_EDITABLE (window_editor)) || !gwidget)
    return;

  if (!gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->icon_file_radio)))
    return;

  glade_editable_block (GLADE_EDITABLE (window_editor));

  glade_command_push_group (_("Setting %s to use an icon file"),
                            glade_widget_get_name (gwidget));

  property = glade_widget_get_property (gwidget, "icon-name");
  glade_command_set_property (property, NULL);
  property = glade_widget_get_property (gwidget, "icon");
  glade_command_set_property (property, NULL);
  property = glade_widget_get_property (gwidget, "glade-window-icon-name");
  glade_command_set_property (property, FALSE);

  glade_command_pop_group ();

  glade_editable_unblock (GLADE_EDITABLE (window_editor));

  /* reload buttons and sensitivity and stuff... */
  glade_editable_load (GLADE_EDITABLE (window_editor), gwidget);
}
Exemple #8
0
static gboolean
glade_gtk_box_configure_end (GladeFixed * fixed,
                             GladeWidget * child, GtkWidget * box)
{
  GList *list, *l, *children;
  GList *prop_list = NULL;

  children = gtk_container_get_children (GTK_CONTAINER (box));

  for (list = children; list; list = list->next)
    {
      GtkWidget *bchild = list->data;

      for (l = glade_gtk_box_original_positions; l; l = l->next)
        {
          GladeGtkBoxChild *gbchild = l->data;
          GladeWidget *gchild = glade_widget_get_from_gobject (gbchild->widget);


          if (bchild == gbchild->widget)
            {
              GCSetPropData *prop_data = g_new0 (GCSetPropData, 1);
              prop_data->property =
                  glade_widget_get_pack_property (gchild, "position");

              prop_data->old_value = g_new0 (GValue, 1);
              prop_data->new_value = g_new0 (GValue, 1);

              glade_property_get_value (prop_data->property,
                                        prop_data->new_value);

              g_value_init (prop_data->old_value, G_TYPE_INT);
              g_value_set_int (prop_data->old_value, gbchild->position);

              prop_list = g_list_prepend (prop_list, prop_data);
              break;
            }
        }
    }

  g_list_free (children);

  glade_command_push_group (_("Ordering children of %s"),
                            glade_widget_get_name (GLADE_WIDGET (fixed)));
  glade_property_push_superuser ();
  if (prop_list)
    glade_command_set_properties_list (glade_widget_get_project (GLADE_WIDGET (fixed)),
                                       prop_list);
  glade_property_pop_superuser ();
  glade_command_pop_group ();

  for (l = glade_gtk_box_original_positions; l; l = l->next)
    g_free (l->data);

  glade_gtk_box_original_positions =
      (g_list_free (glade_gtk_box_original_positions), NULL);


  return TRUE;
}
static void
label_widget_toggled (GtkWidget *widget, GladeToolItemGroupEditor *group_editor)
{
  GladeProperty *property;
  GladeWidget   *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (group_editor));

  if (glade_editable_loading (GLADE_EDITABLE (group_editor)) || !gwidget)
    return;

  if (!gtk_toggle_button_get_active
      (GTK_TOGGLE_BUTTON (group_editor->label_widget_radio)))
    return;

  glade_editable_block (GLADE_EDITABLE (group_editor));

  glade_command_push_group (_("Setting %s to use a custom label widget"),
                            glade_widget_get_name (gwidget));

  property = glade_widget_get_property (gwidget, "label");
  glade_command_set_property (property, NULL);
  property = glade_widget_get_property (gwidget, "custom-label");
  glade_command_set_property (property, TRUE);

  glade_command_pop_group ();

  glade_editable_unblock (GLADE_EDITABLE (group_editor));

  /* reload buttons and sensitivity and stuff... */
  glade_editable_load (GLADE_EDITABLE (group_editor), gwidget);
}
Exemple #10
0
static void
markup_toggled (GtkWidget         *widget,
		GladeWidgetEditor *widget_editor)
{
  GladeProperty *property;
  GladeWidget *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (widget_editor));
  gboolean active;


  if (glade_editable_loading (GLADE_EDITABLE (widget_editor)) || !gwidget)
    return;

  active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));

  glade_editable_block (GLADE_EDITABLE (widget_editor));

  if (active)
    {
      glade_command_push_group (_("Setting %s to use tooltip markup"),
				glade_widget_get_name (gwidget));

      transfer_text_property (gwidget, "tooltip-text", "tooltip-markup");

      property = glade_widget_get_property (gwidget, "glade-tooltip-markup");
      glade_command_set_property (property, TRUE);

      glade_command_pop_group ();
    }
  else
    {
      glade_command_push_group (_("Setting %s to not use tooltip markup"),
				glade_widget_get_name (gwidget));

      transfer_text_property (gwidget, "tooltip-markup", "tooltip-text");

      property = glade_widget_get_property (gwidget, "glade-tooltip-markup");
      glade_command_set_property (property, FALSE);

      glade_command_pop_group ();
    }

  glade_editable_unblock (GLADE_EDITABLE (widget_editor));

  /* reload widgets and sensitivity and stuff... */
  glade_editable_load (GLADE_EDITABLE (widget_editor), gwidget);
}
GtkWidget *
glade_gtk_widget_action_submenu (GladeWidgetAdaptor * adaptor,
                                 GObject * object, const gchar * action_path)
{
  GladeWidget *gwidget = glade_widget_get_from_gobject (object);
  GList *groups, *list;

  if (strcmp (action_path, "sizegroup_add") == 0)
    {
      GtkWidget *menu = gtk_menu_new ();
      GtkWidget *separator, *item;
      GladeWidget *group;
      const gchar *size_group_name;

      if ((groups = list_sizegroups (gwidget)) != NULL)
        {
          for (list = groups; list; list = list->next)
            {
              group = list->data;

	      size_group_name = glade_widget_get_name (group);
	      if (g_str_has_prefix (size_group_name, GLADE_UNNAMED_PREFIX))
		size_group_name = _("(unnamed)");

	      item = gtk_menu_item_new_with_label (size_group_name);

              g_object_set_data (G_OBJECT (item), "glade-group-widget", group);
              g_signal_connect (G_OBJECT (item), "activate",
                                G_CALLBACK (glade_gtk_widget_add2group_cb),
                                gwidget);

              gtk_widget_show (item);
              gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
            }
          g_list_free (groups);

          separator = gtk_menu_item_new ();
          gtk_menu_shell_append (GTK_MENU_SHELL (menu), separator);
          gtk_widget_show (separator);
        }

      /* Add trailing new... item */
      item = gtk_menu_item_new_with_label (_("New Size Group"));
      g_signal_connect (G_OBJECT (item), "activate",
                        G_CALLBACK (glade_gtk_widget_add2group_cb), gwidget);

      gtk_widget_show (item);
      gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);

      return menu;
    }
  else if (GWA_GET_CLASS (G_TYPE_OBJECT)->action_submenu)
    return GWA_GET_CLASS (G_TYPE_OBJECT)->action_submenu (adaptor,
                                                          object, action_path);

  return NULL;
}
Exemple #12
0
static void
widget_name_changed (GladeWidget      *widget,
                     GParamSpec       *pspec,
		     GladeEditorTable *table)
{
  if (!gtk_widget_get_mapped (GTK_WIDGET (table)))
    return;

  if (table->priv->name_entry)
    {
      BLOCK_NAME_ENTRY_CB (table);
      gtk_entry_set_text (GTK_ENTRY (table->priv->name_entry),
                          glade_widget_get_name (table->priv->loaded_widget));
      UNBLOCK_NAME_ENTRY_CB (table);
    }
}
static void
glade_gtk_widget_write_atk_relations (GladeWidget * widget,
                                      GladeXmlContext * context,
                                      GladeXmlNode * node)
{
  GladeProperty *property;
  gint i;

  for (i = 0; atk_relations_list[i]; i++)
    {
      if ((property =
           glade_widget_get_property (widget, atk_relations_list[i])))
        glade_gtk_widget_write_atk_relation (property, context, node);
      else
        g_warning ("Couldnt find atk relation %s on widget %s",
                   atk_relations_list[i], glade_widget_get_name (widget));
    }
}
static void
glade_gtk_widget_write_atk_properties (GladeWidget * widget,
                                       GladeXmlContext * context,
                                       GladeXmlNode * node)
{
  GladeXmlNode *child_node, *object_node;
  GladeProperty *name_prop, *desc_prop;

  name_prop = glade_widget_get_property (widget, "AtkObject::accessible-name");
  desc_prop =
      glade_widget_get_property (widget, "AtkObject::accessible-description");

  /* Create internal child here if any of these properties are non-null */
  if (!glade_property_default (name_prop) ||
      !glade_property_default (desc_prop))
    {
      gchar *atkname = g_strdup_printf ("%s-atkobject", glade_widget_get_name (widget));

      child_node = glade_xml_node_new (context, GLADE_XML_TAG_CHILD);
      glade_xml_node_append_child (node, child_node);

      glade_xml_node_set_property_string (child_node,
                                          GLADE_XML_TAG_INTERNAL_CHILD,
                                          GLADE_TAG_A11Y_INTERNAL_NAME);

      object_node = glade_xml_node_new (context, GLADE_XML_TAG_WIDGET);
      glade_xml_node_append_child (child_node, object_node);

      glade_xml_node_set_property_string (object_node,
                                          GLADE_XML_TAG_CLASS, "AtkObject");

      glade_xml_node_set_property_string (object_node,
                                          GLADE_XML_TAG_ID, atkname);

      if (!glade_property_default (name_prop))
        glade_gtk_widget_write_atk_property (name_prop, context, object_node);
      if (!glade_property_default (desc_prop))
        glade_gtk_widget_write_atk_property (desc_prop, context, object_node);

      g_free (atkname);
    }

}
void
glade_gtk_header_bar_child_action_activate (GladeWidgetAdaptor * adaptor,
                                            GObject * container,
                                            GObject * object,
                                            const gchar * action_path)
{
  if (strcmp (action_path, "remove_slot") == 0)
    {
      GladeWidget *parent;
      GladeProperty *property;

      parent = glade_widget_get_from_gobject (container);
      glade_command_push_group (_("Remove placeholder from %s"), glade_widget_get_name (parent));

      if (g_object_get_data (object, "special-child-type"))
        {
          property = glade_widget_get_property (parent, "use-custom-title");
          glade_command_set_property (property, FALSE);
        }
      else
        {
          gint size;

          gtk_container_remove (GTK_CONTAINER (container), GTK_WIDGET (object));

          property = glade_widget_get_property (parent, "size");
          glade_property_get (property, &size);
          glade_command_set_property (property, size - 1);
        }

      glade_command_pop_group ();
    }
  else
    GWA_GET_CLASS (GTK_TYPE_CONTAINER)->child_action_activate (adaptor,
                                                               container,
                                                               object,
                                                               action_path);
}
Exemple #16
0
void
    glade_gtk_sheet_add_child(GladeWidgetAdaptor *adaptor, GObject *object, GObject *child)
{
    GtkSheet *sheet;
    GtkSheetColumn *newcol;
    GladeWidget *child_widget = glade_widget_get_from_gobject (child);
    const gchar *name = glade_widget_get_name(child_widget);

    g_return_if_fail (GTK_IS_SHEET (object));
    g_return_if_fail (GTK_IS_WIDGET (child));

#ifdef GTK_SHEET_DEBUG
    g_debug("glade_gtk_sheet_add_child: %s %d", 
            name ? name : "NULL",
            GLADE_IS_WIDGET(child)
            );
#endif

    sheet = GTK_SHEET(object);
    newcol = GTK_SHEET_COLUMN(child);

    gtk_sheet_buildable_add_child_internal(sheet, newcol, name);
}
void
glade_gtk_header_bar_action_activate (GladeWidgetAdaptor *adaptor,
                                      GObject * object,
                                      const gchar *action_path)
{
  if (!strcmp (action_path, "add_slot"))
    {
      GladeWidget *parent;
      GladeProperty *property;
      gint size;

      parent = glade_widget_get_from_gobject (object);

      glade_command_push_group (_("Insert placeholder to %s"), glade_widget_get_name (parent));

      property = glade_widget_get_property (parent, "size");
      glade_property_get (property, &size);
      glade_command_set_property (property, size + 1);

      glade_command_pop_group ();
    }
  else
    GWA_GET_CLASS (GTK_TYPE_CONTAINER)->action_activate (adaptor, object, action_path);
}
void
glade_gtk_widget_action_activate (GladeWidgetAdaptor * adaptor,
                                  GObject * object, const gchar * action_path)
{
  GladeWidget *gwidget = glade_widget_get_from_gobject (object), *gparent;
  GList this_widget = { 0, }, that_widget = { 0,};
  GladeProject *project;

  gparent = glade_widget_get_parent (gwidget);
  project = glade_widget_get_project (gwidget);

  if (strcmp (action_path, "preview") == 0)
    {
      glade_project_preview (project,
                             glade_widget_get_from_gobject ((gpointer) object));
    }
  else if (strcmp (action_path, "edit_separate") == 0)
    {
      GtkWidget *dialog = glade_editor_dialog_for_widget (gwidget);
      gtk_widget_show_all (dialog);
    }
  else if (strcmp (action_path, "remove_parent") == 0)
    {
      GladeWidget *new_gparent;
      GladeProperty *property;

      g_return_if_fail (gparent);

      property = glade_widget_get_parentless_widget_ref (gparent);
      new_gparent = glade_widget_get_parent (gparent);

      glade_command_push_group (_("Removing parent of %s"), glade_widget_get_name (gwidget));

      /* Remove "this" widget, If the parent we're removing is a parentless 
       * widget reference, the reference will be implicitly broken by the 'cut' command */
      this_widget.data = gwidget;
      glade_command_delete (&this_widget);

      /* Delete the parent */
      that_widget.data = gparent;
      glade_command_delete (&that_widget);

      /* Add "this" widget to the new parent, if there is no new parent this will re-add
       * the widget to the project at the toplevel without a parent
       */
      glade_command_add (&this_widget, new_gparent, NULL, project, FALSE);

      /* If the parent had a parentless widget reference, undoably add the child
       * as the new parentless widget reference here */
      if (property)
	glade_command_set_property (property, glade_widget_get_object (gwidget));

      glade_command_pop_group ();
    }
  else if (strncmp (action_path, "add_parent/", 11) == 0)
    {
      const gchar *action = action_path + 11;
      GType new_type = 0;

      if (strcmp (action, "alignment") == 0)
        new_type = GTK_TYPE_ALIGNMENT;
      else if (strcmp (action, "viewport") == 0)
        new_type = GTK_TYPE_VIEWPORT;
      else if (strcmp (action, "eventbox") == 0)
        new_type = GTK_TYPE_EVENT_BOX;
      else if (strcmp (action, "frame") == 0)
        new_type = GTK_TYPE_FRAME;
      else if (strcmp (action, "aspect_frame") == 0)
        new_type = GTK_TYPE_ASPECT_FRAME;
      else if (strcmp (action, "scrolled_window") == 0)
        new_type = GTK_TYPE_SCROLLED_WINDOW;
      else if (strcmp (action, "expander") == 0)
        new_type = GTK_TYPE_EXPANDER;
      else if (strcmp (action, "grid") == 0)
        new_type = GTK_TYPE_GRID;
      else if (strcmp (action, "box") == 0)
        new_type = GTK_TYPE_BOX;
      else if (strcmp (action, "paned") == 0)
        new_type = GTK_TYPE_PANED;
      else if (strcmp (action, "stack") == 0)
        new_type = GTK_TYPE_STACK;

      if (new_type)
        {
          GladeWidgetAdaptor *adaptor =
            glade_widget_adaptor_get_by_type (new_type);
          GList *saved_props, *prop_cmds;
	  GladeWidget *gnew_parent;
          GladeProperty *property;

          glade_command_push_group (_("Adding parent %s for %s"),
                                    glade_widget_adaptor_get_title (adaptor), 
				    glade_widget_get_name (gwidget));

          /* Record packing properties */
          saved_props =
	    glade_widget_dup_properties (gwidget, glade_widget_get_packing_properties (gwidget),
					 FALSE, FALSE, FALSE);

	  property = glade_widget_get_parentless_widget_ref (gwidget);

	  /* Remove "this" widget, If the parent we're removing is a parentless 
	   * widget reference, the reference will be implicitly broken by the 'cut' command */
          this_widget.data = gwidget;
          glade_command_delete (&this_widget);

          /* Create new widget and put it where the placeholder was */
          if ((gnew_parent =
               glade_command_create (adaptor, gparent, NULL, project)) != NULL)
            {
	      /* Now we created the new parent, if gwidget had a parentless widget reference...
	       * set that reference to the new parent instead */
	      if (property)
		glade_command_set_property (property, glade_widget_get_object (gnew_parent));

              /* Remove the alignment that we added in the frame's post_create... */
              if (new_type == GTK_TYPE_FRAME)
                {
                  GObject *frame = glade_widget_get_object (gnew_parent);
                  GladeWidget *galign =
                      glade_widget_get_from_gobject (gtk_bin_get_child (GTK_BIN (frame)));
                  GList to_delete = { 0, };

                  to_delete.data = galign;
                  glade_command_delete (&to_delete);
                }

              /* Create heavy-duty glade-command properties stuff */
              prop_cmds =
                  create_command_property_list (gnew_parent, saved_props);

              /* Apply the properties in an undoable way */
              if (prop_cmds)
                glade_command_set_properties_list 
		  (glade_widget_get_project (gparent), prop_cmds);

              /* Add "this" widget to the new parent */
              glade_command_add (&this_widget, gnew_parent, NULL, project, FALSE);

              glade_command_pop_group ();
            }
          else
	    {
              glade_command_pop_group ();

              /* Undo delete command
               * FIXME: this will leave the "Adding parent..." comand in the
               * redo list, which I think its better than leaving it in the
               * undo list by using glade_command_add() to add the widget back
               * to the original parent.
               * Ideally we need a way to remove a redo item from the project or
               * simply do not let the user cancel a widget creation!
               */
	      glade_project_undo (project);
	    }

          g_list_foreach (saved_props, (GFunc) g_object_unref, NULL);
          g_list_free (saved_props);
        }
    }
  else if (strcmp (action_path, "sizegroup_add") == 0)
    {
      /* Ignore dummy */
    }
  else if (strcmp (action_path, "clear_properties") == 0)
    {
      glade_editor_reset_dialog_run (gtk_widget_get_toplevel (GTK_WIDGET (object)), gwidget);
    }
  else if (strcmp (action_path, "read_documentation") == 0)
    {
      glade_app_search_docs (glade_widget_adaptor_get_book (adaptor),
                             glade_widget_adaptor_get_name (adaptor),
                             NULL);
    }
  else
    GWA_GET_CLASS (G_TYPE_OBJECT)->action_activate (adaptor,
                                                    object, action_path);
}
Exemple #19
0
static gboolean
glade_gtk_box_configure_child (GladeFixed * fixed,
                               GladeWidget * child,
                               GdkRectangle * rect, GtkWidget * box)
{
  GList *list, *children;
  GtkWidget *bchild;
  GtkAllocation allocation, bchild_allocation;
  gint point, trans_point, span,
      iter_span, position, old_position, offset, orig_offset;
  gboolean found = FALSE;

  gtk_widget_get_allocation (GTK_WIDGET (glade_widget_get_object (child)), &allocation);

  if (gtk_orientable_get_orientation (GTK_ORIENTABLE (box)) == GTK_ORIENTATION_HORIZONTAL)
    {
      point = fixed->mouse_x;
      span = allocation.width;
      offset = rect->x;
      orig_offset = fixed->child_x_origin;
    }
  else
    {
      point = fixed->mouse_y;
      span = allocation.height;
      offset = rect->y;
      orig_offset = fixed->child_y_origin;
    }

  glade_widget_pack_property_get (child, "position", &old_position);

  children = gtk_container_get_children (GTK_CONTAINER (box));

  for (list = children; list; list = list->next)
    {
      bchild = list->data;

      if (bchild == GTK_WIDGET (glade_widget_get_object (child)))
        continue;

      /* Find the widget in the box where the center of
       * this rectangle fits... and set the position to that
       * position.
       */

      gtk_widget_get_allocation (GTK_WIDGET (bchild), &bchild_allocation);
      if (gtk_orientable_get_orientation (GTK_ORIENTABLE (box)) == GTK_ORIENTATION_HORIZONTAL)
        {
          gtk_widget_translate_coordinates
              (GTK_WIDGET (box), bchild, point, 0, &trans_point, NULL);

          iter_span = bchild_allocation.width;
        }
      else
        {
          gtk_widget_translate_coordinates
              (GTK_WIDGET (box), bchild, 0, point, NULL, &trans_point);
          iter_span = bchild_allocation.height;
        }

#if 0
      gtk_container_child_get (GTK_CONTAINER (box),
                               bchild, "position", &position, NULL);
      g_print ("widget: %p pos %d, point %d, trans_point %d, iter_span %d\n",
               bchild, position, point, trans_point, iter_span);
#endif

      if (iter_span <= span)
        {
          found = trans_point >= 0 && trans_point < iter_span;
        }
      else
        {
          if (offset > orig_offset)
            found = trans_point >= iter_span - span && trans_point < iter_span;
          else if (offset < orig_offset)
            found = trans_point >= 0 && trans_point < span;
        }

      if (found)
        {
          gtk_container_child_get (GTK_CONTAINER (box),
                                   bchild, "position", &position, NULL);

#if 0
          g_print ("setting position of %s from %d to %d, "
                   "(point %d iter_span %d)\n",
                   glade_widget_get_name (child), old_position, position, trans_point, iter_span);
#endif

          glade_widget_pack_property_set (child, "position", position);

          break;
        }

    }

  g_list_free (children);

  return TRUE;
}
Exemple #20
0
static gboolean
glade_gtk_grid_configure_end (GladeFixed  *fixed,
                              GladeWidget *child,
                              GtkWidget   *grid)
{
  GladeGridChild new_child = { child, };

  glade_widget_pack_property_get (child, "left-attach", &new_child.left_attach);
  glade_widget_pack_property_get (child, "width",       &new_child.width);
  glade_widget_pack_property_get (child, "top-attach",  &new_child.top_attach);
  glade_widget_pack_property_get (child, "height",      &new_child.height);

  /* Compare the meaningfull part of the current edit. */
  if (memcmp (&new_child, &grid_edit, sizeof (GladeGridChild)) != 0)
    {
      GValue left_attach_value = { 0, };
      GValue width_attach_value = { 0, };
      GValue top_attach_value = { 0, };
      GValue height_attach_value = { 0, };

      GValue new_left_attach_value = { 0, };
      GValue new_width_attach_value = { 0, };
      GValue new_top_attach_value = { 0, };
      GValue new_height_attach_value = { 0, };

      GladeProperty *left_attach_prop, *width_attach_prop,
      *top_attach_prop, *height_attach_prop;

      left_attach_prop   = glade_widget_get_pack_property (child, "left-attach");
      width_attach_prop  = glade_widget_get_pack_property (child, "width");
      top_attach_prop    = glade_widget_get_pack_property (child, "top-attach");
      height_attach_prop = glade_widget_get_pack_property (child, "height");

      g_return_val_if_fail (GLADE_IS_PROPERTY (left_attach_prop), FALSE);
      g_return_val_if_fail (GLADE_IS_PROPERTY (width_attach_prop), FALSE);
      g_return_val_if_fail (GLADE_IS_PROPERTY (top_attach_prop), FALSE);
      g_return_val_if_fail (GLADE_IS_PROPERTY (height_attach_prop), FALSE);

      glade_property_get_value (left_attach_prop, &new_left_attach_value);
      glade_property_get_value (width_attach_prop, &new_width_attach_value);
      glade_property_get_value (top_attach_prop, &new_top_attach_value);
      glade_property_get_value (height_attach_prop, &new_height_attach_value);

      g_value_init (&left_attach_value, G_TYPE_INT);
      g_value_init (&width_attach_value, G_TYPE_INT);
      g_value_init (&top_attach_value, G_TYPE_INT);
      g_value_init (&height_attach_value, G_TYPE_INT);

      g_value_set_int (&left_attach_value, grid_edit.left_attach);
      g_value_set_int (&width_attach_value, grid_edit.width);
      g_value_set_int (&top_attach_value, grid_edit.top_attach);
      g_value_set_int (&height_attach_value, grid_edit.height);

      glade_command_push_group (_("Placing %s inside %s"),
                                glade_widget_get_name (child), 
                                glade_widget_get_name (GLADE_WIDGET (fixed)));
      glade_command_set_properties
        (left_attach_prop,   &left_attach_value,   &new_left_attach_value,
         width_attach_prop,  &width_attach_value,  &new_width_attach_value,
         top_attach_prop,    &top_attach_value,    &new_top_attach_value,
         height_attach_prop, &height_attach_value, &new_height_attach_value,
         NULL);
      glade_command_pop_group ();

      g_value_unset (&left_attach_value);
      g_value_unset (&width_attach_value);
      g_value_unset (&top_attach_value);
      g_value_unset (&height_attach_value);
      g_value_unset (&new_left_attach_value);
      g_value_unset (&new_width_attach_value);
      g_value_unset (&new_top_attach_value);
      g_value_unset (&new_height_attach_value);
    }

  return TRUE;
}
Exemple #21
0
static void
glade_gtk_grid_child_insert_remove_action (GladeWidgetAdaptor *adaptor, 
                                           GObject            *container, 
                                           GObject            *object, 
                                           GroupAction         group_action,
                                           const gchar        *n_row_col, 
                                           const gchar        *attach1,    /* should be smaller (top/left) attachment */
                                           const gchar        *attach2,      /* should be larger (bot/right) attachment */
                                           gboolean            remove, 
                                           gboolean            after)
{
  GladeWidget *parent;
  GList *children, *l;
  gint child_pos, size, offset;

  gtk_container_child_get (GTK_CONTAINER (container),
                           GTK_WIDGET (object),
                           attach1, &child_pos, NULL);

  parent = glade_widget_get_from_gobject (container);

  switch (group_action)
    {
      case GROUP_ACTION_INSERT_ROW:
        glade_command_push_group (_("Insert Row on %s"), glade_widget_get_name (parent));
        break;
      case GROUP_ACTION_INSERT_COLUMN:
        glade_command_push_group (_("Insert Column on %s"), glade_widget_get_name (parent));
        break;
      case GROUP_ACTION_REMOVE_COLUMN:
        glade_command_push_group (_("Remove Column on %s"), glade_widget_get_name (parent));
        break;
      case GROUP_ACTION_REMOVE_ROW:
        glade_command_push_group (_("Remove Row on %s"), glade_widget_get_name (parent));
        break;
      default:
        g_assert_not_reached ();
    }

  children = glade_widget_adaptor_get_children (adaptor, container);
  /* Make sure widgets does not get destroyed */
  g_list_foreach (children, (GFunc) g_object_ref, NULL);

  glade_widget_property_get (parent, n_row_col, &size);

  if (remove)
    {
      GList *del = NULL;
      /* Remove children first */
      for (l = children; l; l = g_list_next (l))
        {
          GladeWidget *gchild = glade_widget_get_from_gobject (l->data);
          gint pos1, pos2;

          /* Skip placeholders */
          if (gchild == NULL)
            continue;

          glade_widget_pack_property_get (gchild, attach1, &pos1);
          glade_widget_pack_property_get (gchild, attach2, &pos2);
          pos2 += pos1;
          if ((pos1 + 1 == pos2) && ((after ? pos2 : pos1) == child_pos))
            {
              del = g_list_prepend (del, gchild);
            }
        }
      if (del)
        {
          glade_command_delete (del);
          g_list_free (del);
        }
      offset = -1;
    }
  else
    {
      /* Expand the grid */
      glade_command_set_property (glade_widget_get_property (parent, n_row_col),
                                  size + 1);
      offset = 1;
    }

  /* Reorder children */
  for (l = children; l; l = g_list_next (l))
    {
      GladeWidget *gchild = glade_widget_get_from_gobject (l->data);
      gint pos;

      /* Skip placeholders */
      if (gchild == NULL)
        continue;

      /* if removing, do top/left before bot/right */
      if (remove)
        {
          /* adjust top-left attachment */
          glade_widget_pack_property_get (gchild, attach1, &pos);
          if (pos > child_pos || (after && pos == child_pos))
            {
              glade_command_set_property (glade_widget_get_pack_property
                                          (gchild, attach1), pos + offset);
            }
        }
      /* if inserting, do bot/right before top/left */
      else
        {
          /* adjust top-left attachment */
          glade_widget_pack_property_get (gchild, attach1, &pos);

          if ((after && pos > child_pos) || (!after && pos >= child_pos))
            {
              glade_command_set_property (glade_widget_get_pack_property
                                          (gchild, attach1), pos + offset);
            }
        }
    }

  if (remove)
    {
      /* Shrink the grid */
      glade_command_set_property (glade_widget_get_property (parent, n_row_col),
                                  size - 1);
    }

  g_list_foreach (children, (GFunc) g_object_unref, NULL);
  g_list_free (children);

  glade_command_pop_group ();
}
static void
use_csd_toggled (GtkWidget         *widget,
		 GladeWindowEditor *window_editor)
{
  GladeWindowEditorPrivate *priv = window_editor->priv;
  GladeWidget   *gwidget = glade_editable_loaded_widget (GLADE_EDITABLE (window_editor));
  GladeWidget   *gtitlebar = NULL;
  GtkWidget     *window;
  GtkWidget     *titlebar;
  GladeProperty *property;
  gboolean       use_csd;

  if (glade_editable_loading (GLADE_EDITABLE (window_editor)) || !gwidget)
    return;

  /* Get new desired property state */
  use_csd = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->use_csd_check));

  /* Get any existing titlebar widget */
  window = (GtkWidget *)glade_widget_get_object (gwidget);
  titlebar = gtk_window_get_titlebar (GTK_WINDOW (window));

  if (titlebar && !GLADE_IS_PLACEHOLDER (titlebar))
    gtitlebar = glade_widget_get_from_gobject (titlebar);

  glade_editable_block (GLADE_EDITABLE (window_editor));

  if (use_csd)
    glade_command_push_group (_("Setting %s to use a custom titlebar"),
			      glade_widget_get_name (gwidget));
  else
    glade_command_push_group (_("Setting %s to use a system provided titlebar"),
			      glade_widget_get_name (gwidget));

  /* If a project widget exists when were disabling CSD, it needs
   * to be removed first as a part of the issuing GladeCommand group
   */
  if (gtitlebar)
    {
      GList list;
      list.prev = list.next = NULL;
      list.data = gtitlebar;
      glade_command_delete (&list);
    }

  property = glade_widget_get_property (gwidget, "use-csd");
  glade_command_set_property (property, use_csd);

  if (use_csd)
    {
      property = glade_widget_get_property (gwidget, "title");
      glade_command_set_property (property, NULL);
      property = glade_widget_get_property (gwidget, "decorated");
      glade_command_set_property (property, TRUE);
      property = glade_widget_get_property (gwidget, "hide-titlebar-when-maximized");
      glade_command_set_property (property, FALSE);
    }

  glade_command_pop_group ();

  glade_editable_unblock (GLADE_EDITABLE (window_editor));

  /* reload buttons and sensitivity and stuff... */
  glade_editable_load (GLADE_EDITABLE (window_editor), gwidget);
}
Exemple #23
0
static void
glade_editor_table_load (GladeEditable *editable, GladeWidget *widget)
{
  GladeEditorTable *table = GLADE_EDITOR_TABLE (editable);
  GladeEditorProperty *property;
  GList *list;

  /* Setup the table the first time the widget is loaded */
  if (widget && table->priv->adaptor == NULL)
    {
      table->priv->adaptor = glade_widget_get_adaptor (widget);

      if (table->priv->type == GLADE_PAGE_GENERAL)
	append_name_field (table);

      append_items (table, table->priv->adaptor, table->priv->type);
    }

  /* abort mission */
  if (table->priv->loaded_widget == widget)
    return;

  if (table->priv->loaded_widget)
    {
      g_signal_handlers_disconnect_by_func (G_OBJECT (table->priv->loaded_widget),
                                            G_CALLBACK (widget_name_changed),
                                            table);
      g_signal_handlers_disconnect_by_func (G_OBJECT (table->priv->loaded_widget),
                                            G_CALLBACK (widget_composite_changed),
                                            table);

      /* The widget could die unexpectedly... */
      g_object_weak_unref (G_OBJECT (table->priv->loaded_widget),
                           (GWeakNotify) widget_finalized, table);
    }

  table->priv->loaded_widget = widget;

  BLOCK_NAME_ENTRY_CB (table);

  if (table->priv->loaded_widget)
    {
      g_signal_connect (G_OBJECT (table->priv->loaded_widget), "notify::name",
                        G_CALLBACK (widget_name_changed), table);

      g_signal_connect (G_OBJECT (table->priv->loaded_widget), "notify::composite",
                        G_CALLBACK (widget_composite_changed), table);

      /* The widget could die unexpectedly... */
      g_object_weak_ref (G_OBJECT (table->priv->loaded_widget),
                         (GWeakNotify) widget_finalized, table);

      if (table->priv->composite_check)
	{
	  GObject *object = glade_widget_get_object (table->priv->loaded_widget);

	  if (GTK_IS_WIDGET (object) && 
	      glade_widget_get_parent (table->priv->loaded_widget) == NULL)
	    gtk_widget_show (table->priv->composite_check);
	  else
	    gtk_widget_hide (table->priv->composite_check);
	}

      if (table->priv->name_entry)
        gtk_entry_set_text (GTK_ENTRY (table->priv->name_entry), 
			    glade_widget_get_name (widget));

      if (table->priv->name_label)
	widget_composite_changed (widget, NULL, table);
    }
  else if (table->priv->name_entry)
    gtk_entry_set_text (GTK_ENTRY (table->priv->name_entry), "");

  UNBLOCK_NAME_ENTRY_CB (table);

  /* Sync up properties, even if widget is NULL */
  for (list = table->priv->properties; list; list = list->next)
    {
      property = list->data;
      glade_editor_property_load_by_widget (property, widget);
    }
}
Exemple #24
0
static gboolean
glade_property_set_value_impl (GladeProperty * property, const GValue * value)
{
  GladeProject *project = property->priv->widget ?
      glade_widget_get_project (property->priv->widget) : NULL;
  gboolean changed = FALSE;
  GValue old_value = { 0, };
  gboolean warn_before, warn_after;

#ifdef GLADE_ENABLE_DEBUG
  if (glade_get_debug_flags () & GLADE_DEBUG_PROPERTIES)
    {
      g_print ("PROPERTY: Setting %s property %s on %s ",
	       glade_property_class_get_is_packing (property->priv->klass) ? "packing" : "normal",
	       glade_property_class_id (property->priv->klass),
	       property->priv->widget ? glade_widget_get_name (property->priv->widget) : "unknown");

      gchar *str1 =
	glade_widget_adaptor_string_from_value (glade_property_class_get_adaptor (property->priv->klass),
						property->priv->klass, property->priv->value);
      gchar *str2 =
	glade_widget_adaptor_string_from_value (glade_property_class_get_adaptor (property->priv->klass),
						property->priv->klass, value);
      g_print ("from %s to %s\n", str1, str2);
      g_free (str1);
      g_free (str2);
    }
#endif /* GLADE_ENABLE_DEBUG */

  if (!g_value_type_compatible (G_VALUE_TYPE (property->priv->value), G_VALUE_TYPE (value)))
    {
      g_warning ("Trying to assign an incompatible value to property %s\n",
                 glade_property_class_id (property->priv->klass));
      return FALSE;
    }

  /* Check if the backend doesnt give us permission to
   * set this value.
   */
  if (glade_property_superuser () == FALSE && property->priv->widget &&
      project && glade_project_is_loading (project) == FALSE &&
      glade_property_verify (property, value) == FALSE)
    {
      return FALSE;
    }

  /* save "changed" state.
   */
  changed = !glade_property_equals_value (property, value);

  /* Add/Remove references from widget ref stacks here
   * (before assigning the value)
   */
  if (property->priv->widget && changed &&
      glade_property_class_is_object (property->priv->klass))
    glade_property_update_prop_refs (property, property->priv->value, value);

  /* Check pre-changed warning state */
  warn_before = glade_property_warn_usage (property);

  /* Make a copy of the old value */
  g_value_init (&old_value, G_VALUE_TYPE (property->priv->value));
  g_value_copy (property->priv->value, &old_value);

  /* Assign property first so that; if the object need be
   * rebuilt, it will reflect the new value
   */
  g_value_reset (property->priv->value);
  g_value_copy (value, property->priv->value);

  GLADE_PROPERTY_GET_KLASS (property)->sync (property);

  glade_property_fix_state (property);

  if (changed && property->priv->widget)
    {
      g_signal_emit (G_OBJECT (property),
                     glade_property_signals[VALUE_CHANGED],
                     0, &old_value, property->priv->value);

      glade_project_verify_property (property);

      /* Check post change warning state */
      warn_after = glade_property_warn_usage (property);

      /* Update owning widget's warning state if need be */
      if (property->priv->widget != NULL && warn_before != warn_after)
	glade_widget_verify (property->priv->widget);
    }

  /* Special case parentless widget properties */
  if (glade_property_class_parentless_widget (property->priv->klass))
    {
      GladeWidget *gobj;
      GObject *obj;
      
      if ((obj = g_value_get_object (&old_value)) &&
          (gobj = glade_widget_get_from_gobject (obj)))
        glade_widget_show (gobj);

      if ((obj = g_value_get_object (value)) &&
          (gobj = glade_widget_get_from_gobject (obj)))
        glade_widget_hide (gobj);  
    }

  g_value_unset (&old_value);
  return TRUE;
}