Example #1
0
static gboolean
glade_gtk_grid_configure_child (GladeFixed   *fixed,
                                GladeWidget  *child,
                                GdkRectangle *rect,
                                GtkWidget    *grid)
{
  GladeGridChild configure = { child, };

  /* Sometimes we are unable to find a widget in the appropriate column,
   * usually because a placeholder hasnt had its size allocation yet.
   */
  if (glade_gtk_grid_get_attachments (fixed, GTK_GRID (grid), rect, &configure))
    {
      if (memcmp (&configure, &grid_cur_attach, sizeof (GladeGridChild)) != 0)
        {

          glade_property_push_superuser ();
          glade_widget_pack_property_set (child, "left-attach",
                                          configure.left_attach);
          glade_widget_pack_property_set (child, "width",
                                          configure.width);
          glade_widget_pack_property_set (child, "top-attach",
                                          configure.top_attach);
          glade_widget_pack_property_set (child, "height",
                                          configure.height);
          glade_property_pop_superuser ();

          memcpy (&grid_cur_attach, &configure, sizeof (GladeGridChild));
        }
    }
  return TRUE;
}
Example #2
0
static void
sync_row_positions (GtkListBox *listbox)
{
  GList *l, *rows;
  int position;
  static gboolean recursion = FALSE;

  /* Avoid feedback loop */
  if (recursion)
    return;

  rows = gtk_container_get_children (GTK_CONTAINER (listbox));

  position = 0;
  for (l = rows; l; l = g_list_next (l))
    {
      gint old_position;

      glade_widget_pack_property_get (glade_widget_get_from_gobject (l->data),
                                      "position", &old_position);
      if (position != old_position)
        {
          /* Update glade with the new value */
          recursion = TRUE;
          glade_widget_pack_property_set (glade_widget_get_from_gobject (l->data),
                                          "position", position);
          recursion = FALSE;
        }

      position++;
    }

  g_list_free (rows);
}
Example #3
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 ();
}
void
glade_gtk_tool_palette_add_child (GladeWidgetAdaptor * adaptor,
				  GObject * object, GObject * child)
{
  GtkToolPalette *palette;
  GtkToolItemGroup *group;

  g_return_if_fail (GTK_IS_TOOL_PALETTE (object));
  g_return_if_fail (GTK_IS_TOOL_ITEM_GROUP (child));

  palette = GTK_TOOL_PALETTE (object);
  group   = GTK_TOOL_ITEM_GROUP (child);

  gtk_container_add (GTK_CONTAINER (palette), GTK_WIDGET (group));

  if (glade_util_object_is_loading (object))
    {
      GladeWidget *gchild = glade_widget_get_from_gobject (child);

      /* Packing props arent around when parenting during a glade_widget_dup() */
      if (gchild && glade_widget_get_packing_properties (gchild))
	glade_widget_pack_property_set (gchild, "position",
					gtk_tool_palette_get_group_position (palette, group));
    }
}
void
glade_gtk_action_bar_add_child (GladeWidgetAdaptor * adaptor,
                                GObject * object,
                                GObject * child)
{
  GladeWidget *gbox, *gchild;
  gint num_children;
  gchar *special_child_type;

  gbox = glade_widget_get_from_gobject (object);

  special_child_type = g_object_get_data (child, "special-child-type");
  if (special_child_type && !strcmp (special_child_type, "center"))
    {
      gtk_action_bar_set_center_widget (GTK_ACTION_BAR (object), GTK_WIDGET (child));
       return;
    }

  /*
     Try to remove the last placeholder if any, this way GtkBox`s size 
     will not be changed.
   */
  if (!glade_widget_superuser () && !GLADE_IS_PLACEHOLDER (child))
    {
      GList *l, *children;

      children = gtk_container_get_children (GTK_CONTAINER (object));
      for (l = g_list_last (children); l; l = g_list_previous (l))
        {
          GtkWidget *child_widget = l->data;
          if (GLADE_IS_PLACEHOLDER (child_widget))
            {
              gtk_container_remove (GTK_CONTAINER (object), child_widget);
              break;
            }
        }
      g_list_free (children);
    }

  gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child));
  num_children = glade_gtk_action_bar_get_num_children (object);
  glade_widget_property_set (gbox, "size", num_children);

  if (glade_widget_superuser ())
    return;
  
  gchild = glade_widget_get_from_gobject (child);

  /* Packing props arent around when parenting during a glade_widget_dup() */
  if (gchild && glade_widget_get_packing_properties (gchild))
    glade_widget_pack_property_set (gchild, "position", num_children - 1);
}
Example #6
0
static void
glade_gtk_assistant_update_position (GtkAssistant * assistant)
{
  gint i, pages = gtk_assistant_get_n_pages (assistant);

  for (i = 0; i < pages; i++)
    {
      GtkWidget *page = gtk_assistant_get_nth_page (assistant, i);
      GladeWidget *gpage = glade_widget_get_from_gobject (G_OBJECT (page));
      if (gpage)
        glade_widget_pack_property_set (gpage, "position", i);
    }
}
static void
update_position (GtkWidget *widget, gpointer data)
{
  GtkContainer *parent = data;
  GladeWidget *gwidget;
  gint position;

  gwidget = glade_widget_get_from_gobject (widget);
  if (gwidget)
    {
      gtk_container_child_get (parent, widget, "position", &position, NULL);
      glade_widget_pack_property_set (gwidget, "position", position);
    }
}
Example #8
0
static void
glade_gtk_assistant_append_new_page (GladeWidget * parent,
                                     GladeProject * project,
                                     const gchar * label,
                                     GtkAssistantPageType type)
{
  static GladeWidgetAdaptor *adaptor = NULL;
  GladeWidget *page;

  if (adaptor == NULL)
    adaptor = glade_widget_adaptor_get_by_type (GTK_TYPE_LABEL);

  page = glade_widget_adaptor_create_widget (adaptor, FALSE,
                                             "parent", parent,
                                             "project", project, NULL);

  glade_widget_add_child (parent, page, FALSE);

  glade_widget_property_set (page, "label", label);
  glade_widget_pack_property_set (page, "page-type", type);
}
Example #9
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;
}
Example #10
0
void
glade_gtk_box_add_child (GladeWidgetAdaptor * adaptor,
                         GObject * object, GObject * child)
{
  GladeWidget *gbox, *gchild;
  gint num_children;
  gchar *special_child_type;

  g_return_if_fail (GTK_IS_BOX (object));
  g_return_if_fail (GTK_IS_WIDGET (child));

  gbox = glade_widget_get_from_gobject (object);

  special_child_type = g_object_get_data (child, "special-child-type");
  if (special_child_type && !strcmp (special_child_type, "center"))
    {
      gtk_box_set_center_widget (GTK_BOX (object), GTK_WIDGET (child));
       return;
    }

  /*
     Try to remove the last placeholder if any, this way GtkBox`s size 
     will not be changed.
   */
  if (glade_widget_superuser () == FALSE && !GLADE_IS_PLACEHOLDER (child))
    {
      GList *l, *children;
      GtkBox *box = GTK_BOX (object);

      children = gtk_container_get_children (GTK_CONTAINER (box));

      for (l = g_list_last (children); l; l = g_list_previous (l))
        {
          GtkWidget *child_widget = l->data;
          if (GLADE_IS_PLACEHOLDER (child_widget))
            {
              gtk_container_remove (GTK_CONTAINER (box), child_widget);
              break;
            }
        }
      g_list_free (children);
    }

  gtk_container_add (GTK_CONTAINER (object), GTK_WIDGET (child));
  num_children = glade_gtk_box_get_num_children (object);
  glade_widget_property_set (gbox, "size", num_children);

  gchild = glade_widget_get_from_gobject (child);

  /* The "Remove Slot" operation only makes sence on placeholders,
   * otherwise its a "Delete" operation on the child widget.
   */
  if (gchild)
    glade_widget_set_pack_action_visible (gchild, "remove_slot", FALSE);

  fix_response_id_on_child (gbox, child, TRUE);
  
  if (glade_widget_superuser ())
    return;
  
  /* Packing props arent around when parenting during a glade_widget_dup() */
  if (gchild && glade_widget_get_packing_properties (gchild))
    glade_widget_pack_property_set (gchild, "position", num_children - 1);
}
Example #11
0
void
glade_gtk_box_set_child_property (GladeWidgetAdaptor * adaptor,
                                  GObject * container,
                                  GObject * child,
                                  const gchar * property_name, GValue * value)
{
  GladeWidget *gbox, *gchild, *gchild_iter;
  GList *children, *list;
  gboolean is_position;
  gint old_position, iter_position, new_position;
  static gboolean recursion = FALSE;

  g_return_if_fail (GTK_IS_BOX (container));
  g_return_if_fail (GTK_IS_WIDGET (child));
  g_return_if_fail (property_name != NULL || value != NULL);

  gbox = glade_widget_get_from_gobject (container);
  gchild = glade_widget_get_from_gobject (child);

  g_return_if_fail (GLADE_IS_WIDGET (gbox));

  if (gtk_widget_get_parent (GTK_WIDGET (child)) != GTK_WIDGET (container))
    return;

  /* Get old position */
  if ((is_position = (strcmp (property_name, "position") == 0)) != FALSE)
    {
      gtk_container_child_get (GTK_CONTAINER (container),
                               GTK_WIDGET (child),
                               property_name, &old_position, NULL);


      /* Get the real value */
      new_position = g_value_get_int (value);
    }

  if (is_position && recursion == FALSE)
    {
      children = glade_widget_get_children (gbox);
      children = g_list_sort (children, (GCompareFunc) sort_box_children);

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

          if (gchild_iter == gchild)
            {
              gtk_box_reorder_child (GTK_BOX (container),
                                     GTK_WIDGET (child), new_position);
              continue;
            }

          /* Get the old value from glade */
          glade_widget_pack_property_get
              (gchild_iter, "position", &iter_position);

          /* Search for the child at the old position and update it */
          if (iter_position == new_position &&
              glade_property_superuser () == FALSE)
            {
              /* Update glade with the real value */
              recursion = TRUE;
              glade_widget_pack_property_set
                  (gchild_iter, "position", old_position);
              recursion = FALSE;
              continue;
            }
          else
            {
              gtk_box_reorder_child (GTK_BOX (container),
                                     GTK_WIDGET (list->data), iter_position);
            }
        }

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

          /* Refresh values yet again */
          glade_widget_pack_property_get
              (gchild_iter, "position", &iter_position);

          gtk_box_reorder_child (GTK_BOX (container),
                                 GTK_WIDGET (list->data), iter_position);

        }

      if (children)
        g_list_free (children);
    }

  /* Chain Up */
  if (!is_position)
    GWA_GET_CLASS
        (GTK_TYPE_CONTAINER)->child_set_property (adaptor,
                                                  container,
                                                  child, property_name, value);

  gtk_container_check_resize (GTK_CONTAINER (container));

}