示例#1
0
GladeEditable *
glade_gtk_window_create_editable (GladeWidgetAdaptor * adaptor,
				  GladeEditorPageType type)
{
  GladeEditable *editable;

  if (type == GLADE_PAGE_GENERAL &&
      /* Don't show all the GtkWindow properties for offscreen windows.
       *
       * We spoof the offscreen window type instead of using the real GType,
       * so don't check it by GType but use strcmp() instead.
       */
      strcmp (glade_widget_adaptor_get_name (adaptor), "GtkOffscreenWindow") != 0)
    {
      GType window_type = glade_widget_adaptor_get_object_type (adaptor);

      if (g_type_is_a (window_type, GTK_TYPE_ABOUT_DIALOG))
	editable = (GladeEditable *) glade_about_dialog_editor_new ();
      else if (g_type_is_a (window_type, GTK_TYPE_FILE_CHOOSER_DIALOG))
	editable = (GladeEditable *) glade_file_chooser_dialog_editor_new ();
      else if (g_type_is_a (window_type, GTK_TYPE_FONT_CHOOSER_DIALOG))
	editable = (GladeEditable *) glade_font_chooser_dialog_editor_new ();
      else if (g_type_is_a (window_type, GTK_TYPE_RECENT_CHOOSER_DIALOG))
	editable = (GladeEditable *) glade_recent_chooser_dialog_editor_new ();
      else if (g_type_is_a (window_type, GTK_TYPE_MESSAGE_DIALOG))
	editable = (GladeEditable *) glade_message_dialog_editor_new ();
      else
	editable = (GladeEditable *) glade_window_editor_new ();
    }
  else
    editable = GWA_GET_CLASS (GTK_TYPE_WIDGET)->create_editable (adaptor, type);

  return editable;
}
示例#2
0
static GladeEditorProperty *
append_item (GladeEditorTable   *table,
             GladePropertyClass *klass,
             gboolean            from_query_dialog)
{
  GladeEditorProperty *property;
  GtkWidget *label;

  if (!(property = glade_widget_adaptor_create_eprop
        (glade_property_class_get_adaptor (klass), klass, from_query_dialog == FALSE)))
    {
      g_critical ("Unable to create editor for property '%s' of class '%s'",
                  glade_property_class_id (klass), 
		  glade_widget_adaptor_get_name (glade_property_class_get_adaptor (klass)));
      return NULL;
    }

  gtk_widget_show (GTK_WIDGET (property));
  gtk_widget_show_all (glade_editor_property_get_item_label (property));

  label = glade_editor_property_get_item_label (property);
  gtk_widget_set_hexpand (label, FALSE);

  glade_editor_table_attach (table, label, 0, table->priv->rows);
  glade_editor_table_attach (table, GTK_WIDGET (property), 1, table->priv->rows);

  table->priv->rows++;

  return property;
}
示例#3
0
static void
glade_popup_docs_cb (GtkMenuItem *item, GladeWidgetAdaptor *adaptor)
{
  g_return_if_fail (GLADE_IS_WIDGET_ADAPTOR (adaptor));

  glade_app_search_docs (glade_widget_adaptor_get_book (adaptor),
                         glade_widget_adaptor_get_name (adaptor),
                         NULL);
}
示例#4
0
int
main (int   argc,
      char *argv[])
{
  GList *adaptors, *l;

  gtk_test_init (&argc, &argv, NULL);

  glade_init ();
  glade_app_get ();

  adaptors = g_list_sort (glade_widget_adaptor_list_adaptors (), adaptor_cmp);
    
  for (l = adaptors; l; l = l->next)
    {
      GladeWidgetAdaptor *adaptor = l->data;
      GType               adaptor_type;

      adaptor_type = glade_widget_adaptor_get_object_type (adaptor);

      if (G_TYPE_IS_INSTANTIATABLE (adaptor_type) && !G_TYPE_IS_ABSTRACT (adaptor_type) &&
	  /* FIXME: FileChooserButton leaks a GTask which will crash in the following test */
	  adaptor_type != GTK_TYPE_FILE_CHOOSER_BUTTON &&
          /* FIXME: GtkRecentChooser tries to remove an unknown source id */
	  !g_type_is_a (adaptor_type, GTK_TYPE_RECENT_CHOOSER))
	{
	  gchar *test_path = g_strdup_printf ("/CreateWidget/%s", glade_widget_adaptor_get_name (adaptor));

	  g_test_add_data_func (test_path, adaptor, test_create_widget);

	  g_free (test_path);
	}
    }
  g_list_free (adaptors);

  return g_test_run ();
}
示例#5
0
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);
}
示例#6
0
static gint
adaptor_cmp (gconstpointer a, gconstpointer b)
{
  return g_strcmp0 (glade_widget_adaptor_get_name ((gpointer)a),
                    glade_widget_adaptor_get_name ((gpointer)b));
}