Beispiel #1
0
/* From contacts src/contacts-utils.c */
static GList *
contacts_set_widget_desensitive_recurse (GtkWidget *widget, GList **widgets)
{
	if (GTK_IS_WIDGET (widget)) {
		if (GTK_WIDGET_SENSITIVE (widget) &&
		    GTK_WIDGET_VISIBLE (widget)) {
			gtk_widget_set_sensitive (widget, FALSE);
			*widgets = g_list_append (*widgets, widget);
		}
		
		if (GTK_IS_TABLE (widget) || GTK_IS_HBOX (widget) ||
		    GTK_IS_VBOX (widget) || GTK_IS_EVENT_BOX (widget)) {
			GList *c, *children = gtk_container_get_children (
				GTK_CONTAINER (widget));
			
			for (c = children; c; c = c->next) {
				contacts_set_widget_desensitive_recurse (
					c->data, widgets);
			}
			g_list_free (children);
		}
	}
	
	return *widgets;
}
Beispiel #2
0
static void
psppire_dialog_get_property (GObject         *object,
			     guint            prop_id,
			     GValue          *value,
			     GParamSpec      *pspec)
{
  PsppireDialog *dialog = PSPPIRE_DIALOG (object);

  switch (prop_id)
    {
    case PROP_ORIENTATION:
      {
	if ( GTK_IS_VBOX (dialog->box) || GTK_VPANED (dialog->box))
	  g_value_set_enum (value, PSPPIRE_VERTICAL);
	else if ( GTK_IS_HBOX (dialog->box) || GTK_HPANED (dialog->box))
	  g_value_set_enum (value, PSPPIRE_HORIZONTAL);
	else if ( GTK_IS_TABLE (dialog->box))
	  g_value_set_enum (value, PSPPIRE_TABULAR);
      }
      break;
    case PROP_SLIDING:
      g_value_set_boolean (value, dialog->slidable);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    };
}
Beispiel #3
0
void
gimp_table_attach_stock (GtkTable    *table,
                         gint         row,
                         const gchar *stock_id,
                         GtkWidget   *widget,
                         gint         colspan,
                         gboolean     left_align)
{
  GtkWidget *image;

  g_return_if_fail (GTK_IS_TABLE (table));
  g_return_if_fail (stock_id != NULL);
  g_return_if_fail (GTK_IS_WIDGET (widget));

  image = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON);
  gtk_misc_set_alignment (GTK_MISC (image), 1.0, 0.5);
  gtk_table_attach (table, image, 0, 1, row, row + 1,
                    GTK_FILL, GTK_FILL, 0, 0);
  gtk_widget_show (image);

  if (left_align)
    {
      GtkWidget *hbox = gtk_hbox_new (FALSE, 0);

      gtk_box_pack_start (GTK_BOX (hbox), widget, FALSE, FALSE, 0);
      gtk_widget_show (widget);

      widget = hbox;
    }

  gtk_table_attach (table, widget, 1, 1 + colspan, row, row + 1,
                    GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
  gtk_widget_show (widget);
}
Beispiel #4
0
/*
 * Creates a new GtkWidget of class GtkLabel, performing any specialized
 * initialization needed for the widget to work correctly in this environment.
 * If a dialog box is used to initialize the widget, return NULL from this
 * function, and call data->callback with your new widget when it is done.
 * If the widget needs a special destroy handler, add a signal here.
 */
GtkWidget *
gb_label_new (GbWidgetNewData * data)
{
  GtkWidget *new_widget;

  new_widget = gtk_label_new (data->name);

  /* If we are creating a new label in a table or in an event box in a table
     set it to left-aligned, since that is what is usually wanted. */
  if (data->action == GB_CREATING && data->parent
      && (GTK_IS_TABLE (data->parent)
	  || (GTK_IS_EVENT_BOX (data->parent) && data->parent->parent
	      && GTK_IS_TABLE (data->parent->parent))))
    {
      gtk_misc_set_alignment (GTK_MISC (new_widget), 0.0, 0.5);
    }

  return new_widget;
}
/**
 * gwy_radio_buttons_attach_to_table:
 * @group: A radio button group.  Not necessarily created by
 *         gwy_radio_buttons_create().
 * @table: A table.
 * @colspan: The number of columns the radio buttons should span across.
 * @row: Table row to start attaching at.
 *
 * Attaches a group of radio buttons to table rows.
 *
 * Returns: The row after the last attached radio button.
 *
 * Since: 2.1
 **/
gint
gwy_radio_buttons_attach_to_table(GSList *group,
                                  GtkTable *table,
                                  gint colspan,
                                  gint row)
{
    g_return_val_if_fail(GTK_IS_TABLE(table), row);

    while (group) {
        gtk_table_attach(table, GTK_WIDGET(group->data),
                         0, colspan, row, row + 1,
                         GTK_EXPAND | GTK_FILL, 0, 0, 0);
        row++;
        group = g_slist_next(group);
    }

    return row;
}
void
quicklauncher_organize(t_quicklauncher *quicklauncher)
{
	gint i, j, launch_per_line, nb_lines;
	GList *toplace;

	DBG ("Organize quicklauncher");
	g_assert( (!quicklauncher->table || GTK_IS_TABLE(quicklauncher->table)) && GTK_IS_CONTAINER(quicklauncher->plugin));
	if (quicklauncher->launchers)
	{
		nb_lines = MIN(quicklauncher->nb_lines, quicklauncher->nb_launcher);
		toplace = g_list_first(quicklauncher->launchers);
		if(quicklauncher->nb_launcher % quicklauncher->nb_lines == 0)
			launch_per_line = quicklauncher->nb_launcher / quicklauncher->nb_lines;
		else
			launch_per_line = quicklauncher->nb_launcher / quicklauncher->nb_lines+1;
		if (quicklauncher->orientation != GTK_ORIENTATION_HORIZONTAL)
		{
			i = nb_lines;
			nb_lines = launch_per_line;
			launch_per_line = i;
		}
		if (quicklauncher->table)
			gtk_table_resize(GTK_TABLE(quicklauncher->table), nb_lines, launch_per_line);

		j = quicklauncher->nb_launcher;
		for (i=0; i < nb_lines; ++i)
		{
			for(j=0; (j < launch_per_line) && (toplace); ++j, toplace = g_list_next(toplace))
			{
				g_assert(toplace && GTK_IS_WIDGET(((t_launcher*)toplace->data)->widget) );
				gtk_table_attach_defaults( GTK_TABLE(quicklauncher->table),
											((t_launcher*)toplace->data)->widget,
											j, j+1, i, i+1);
				//gtk_container_add (GTK_CONTAINER (quicklauncher->hbox[i]), ((t_launcher*)toplace->data)->widget);
			}
		}
	}
}
Beispiel #7
0
static void
set_table_row (GtkTable *table,
               GtkWidget *label, GtkWidget *widget,
               gpointer user_data)
{
	static guint row = 0;
	guint col = 0;

	g_return_if_fail (GTK_IS_TABLE (table));
	g_return_if_fail (GTK_IS_WIDGET (widget));

	if (label) {
		gtk_label_set_mnemonic_widget (GTK_LABEL (label), widget);
		gtk_widget_set_halign (label, GTK_ALIGN_START);
		gtk_widget_set_valign (label, GTK_ALIGN_CENTER);
		gtk_widget_show (label);

		gtk_table_attach (GTK_TABLE (table), label,
	                          0, ++col, row, row + 1,
		                  GTK_FILL, 0, 0, 0);
	}

	if (GTK_IS_EDITABLE (widget)) {
		g_signal_connect_swapped (widget, "changed",
		                          G_CALLBACK (verify_input), user_data);
		g_signal_connect_swapped (widget, "activate",
		                          G_CALLBACK (cycle_focus), user_data);
	}

	gtk_widget_show (widget);

	gtk_table_attach (GTK_TABLE (table), widget,
	                  col, 2, row, row + 1,
	                  GTK_EXPAND | GTK_FILL, 0, 0, 0);
	row++;
}
Beispiel #8
0
/** At dialog creation time, this function will be called once per
 *  adds-in.  It performs the work of adding the page into the main
 *  dialog.  It handles both the case of a full page being added to
 *  the dialog, and a partial page being added.
 *
 *  @internal
 *
 *  @param data A pointer to an addition data structure.
 *
 *  @param user_data A pointer to the dialog.
 */
static void
gnc_preferences_build_page (gpointer data,
                            gpointer user_data)
{
    GtkBuilder *builder;
    GtkWidget *dialog, *existing_content, *new_content, *label;
    GtkNotebook *notebook;
    addition *add_in;
    struct copy_data copydata;
    gint rows, cols;
    gchar **widgetname;
    gint i;

    ENTER("add_in %p, dialog %p", data, user_data);
    add_in = (addition *)data;
    dialog = user_data;

    DEBUG("Opening %s to get %s", add_in->filename, add_in->widgetname);
    builder = gtk_builder_new();

    /* Adjustments etc... must come before dialog information */
    widgetname = g_strsplit(add_in->widgetname, ",", -1);

    for (i = 0; widgetname[i]; i++)
    {
        DEBUG("Opening %s to get content %s", add_in->filename, widgetname[i]);
        gnc_builder_add_from_file (builder, add_in->filename, widgetname[i]);
    }

    DEBUG("Widget Content is %s", widgetname[i - 1]);
    new_content = GTK_WIDGET(gtk_builder_get_object (builder, widgetname[i - 1]));

    g_strfreev(widgetname);
    DEBUG("done");

    /* Add to the list of interesting widgets */
    gnc_prefs_build_widget_table(builder, dialog);

    /* Connect the signals in this glade file. The dialog is passed in
     * so the the callback can find "interesting" widgets from other
     * glade files if necessary (via the GPREFS_WIDGET_HASH hash table). */
    gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, dialog);

    /* Prepare for recursion */
    notebook = g_object_get_data(G_OBJECT(dialog), NOTEBOOK);

    if (add_in->full_page)
    {
        label = gtk_label_new(add_in->tabname);
        gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
        gtk_notebook_append_page(notebook, new_content, label);
        g_object_unref(G_OBJECT(builder));
        LEAVE("appended page");
        return;
    }

    /* Copied tables must match the size of the main table */
    if (!GTK_IS_TABLE(new_content))
    {
        g_critical("The object name %s in file %s is not a GtkTable.  It cannot "
                   "be added to the preferences dialog.",
                   add_in->widgetname, add_in->filename);
        g_object_unref(G_OBJECT(builder));
        LEAVE("");
        return;
    }
    g_object_get(G_OBJECT(new_content), "n-columns", &cols, NULL);
    if (cols != 4)
    {
        g_critical("The table %s in file %s does not have four columns.  It cannot "
                   "be added to the preferences dialog.",
                   add_in->widgetname, add_in->filename);
        g_object_unref(G_OBJECT(builder));
        LEAVE("");
        return;
    }

    /* Does the page exist or must we create it */
    existing_content = gnc_prefs_find_page(notebook, add_in->tabname);

    if (!existing_content)
    {
        /* No existing content with this name.  Create a blank page */
        rows = 0;
        existing_content = gtk_table_new(0, 4, FALSE);
        gtk_container_set_border_width(GTK_CONTAINER(existing_content), 6);
        label = gtk_label_new(add_in->tabname);
        gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
        gtk_notebook_append_page(notebook, existing_content, label);
        gtk_widget_show_all(existing_content);
        DEBUG("created new page %s, appended it", add_in->tabname);
    }
    else
    {
        g_object_get(G_OBJECT(existing_content), "n-rows", &rows, NULL);
        DEBUG("found existing page %s", add_in->tabname);
    }

    /* Maybe add a spacer row */
    DEBUG("rows is %d", rows);
    if (rows > 0)
    {
        label = gtk_label_new("");
        gtk_widget_show(label);
        gtk_table_attach(GTK_TABLE(existing_content), label, 0, 1, rows, rows + 1,
                         GTK_FILL, GTK_FILL, 0, 0);
        rows++;
    }

    /* Now copy all the entries in the table */
    copydata.table_from = GTK_TABLE(new_content);
    copydata.table_to = GTK_TABLE(existing_content);
    copydata.row_offset = rows;
    gtk_container_foreach(GTK_CONTAINER(new_content), gnc_prefs_move_table_entry,
                          &copydata);

    g_object_ref_sink(new_content);
    g_object_unref(G_OBJECT(builder));

    LEAVE("added content to page");
}
Beispiel #9
0
/* Make the size of dialogs smaller by breaking GNOME HIG
 * http://library.gnome.org/devel/hig-book/stable/design-window.html.en
 * According to GNOME HIG, spacings are increased by the multiples of 6.
 * Change them to the multiples of 1 can greatly reduce the required size
 * while still keeping some degree of spacing.
 */
static void break_gnome_hig( GtkWidget* w, gpointer _factor )
{
    int factor = GPOINTER_TO_INT(_factor);

    /* g_debug( G_OBJECT_TYPE_NAME(w) ); */
    if( GTK_IS_CONTAINER(w) )
    {
        int val;
        val = gtk_container_get_border_width( (GtkContainer*)w );

        /* border of dialog defaults to 12 under gnome */
        if( GTK_IS_DIALOG(w) )
        {
            if( val > 0 )
                gtk_container_set_border_width( (GtkContainer*)w, val / factor );
        }
        else
        {
            if( GTK_IS_BOX(w) ) /* boxes, spacing defaults to 6, 12, 18 under gnome */
            {
                int spacing = gtk_box_get_spacing( (GtkBox*)w );
                gtk_box_set_spacing( (GtkBox*)w, spacing / factor );
            }
            else if( GTK_IS_TABLE(w) ) /* tables, spacing defaults to 6, 12, 18 under gnome */
            {
                int spacing;
                int col, row;
                g_object_get( w, "n-columns", &col, "n-rows", &row, NULL );
                if( col > 1 )
                {
                    --col;
                    while( --col >= 0 )
                    {
                        spacing = gtk_table_get_col_spacing( (GtkTable*)w, col );
                        if( spacing > 0 )
                            gtk_table_set_col_spacing( (GtkTable*)w, col, spacing / factor );
                    }
                }
                if( row > 1 )
                {
                    --row;
                    while( --row >= 0 )
                    {
                        spacing = gtk_table_get_row_spacing( (GtkTable*)w, row );
                        if( spacing > 0 )
                            gtk_table_set_row_spacing( (GtkTable*)w, row, spacing / factor );
                    }
                }
                /* FIXME: handle default spacings */
            }
            else if( GTK_IS_ALIGNMENT(w) ) /* groups, has 12 px indent by default */
            {
                int t, b, l, r;
                gtk_alignment_get_padding( (GtkAlignment*)w, &t, &b, &l, &r );
                if( l > 0 )
                {
                    l /= (factor / 2); /* groups still need proper indent not to hurt usability */
                    gtk_alignment_set_padding( (GtkAlignment*)w, t, b, l, r );
                }
            }
            if( val > 0 )
                gtk_container_set_border_width( (GtkContainer*)w, val * 2 / factor );
        }
        gtk_container_foreach( (GtkContainer*)w, break_gnome_hig, GINT_TO_POINTER(factor) );
    }
}
static GtkWidget *
sx_config_source_setup_ui (GtkWidget * parent, ESource * source)
{
    GtkWidget *button;
    GtkWidget *label;
    GtkWidget *text;
    GtkWidget *ret;
    char *uri_text;
    const char *uid;
    const char *ruri;
    const char *name;
    gboolean new_source;
    gulong *sig_id;

    uri_text = e_source_get_uri (source);

    if (!g_str_has_prefix (uri_text, "scalix")) {
        g_free (uri_text);
        return NULL;
    }
    g_free (uri_text);

    g_assert (GTK_IS_BOX (parent) || GTK_IS_TABLE (parent));

    /* Label */
    label = gtk_label_new_with_mnemonic (_("_Location:"));
    gtk_widget_show (label);

    gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);

    button = gtk_button_new ();

    g_signal_connect (G_OBJECT (button),
                      "clicked", G_CALLBACK (location_clicked), source);

    gtk_widget_show (button);

    uid = e_source_peek_uid (source);
    ruri = e_source_peek_relative_uri (source);
    name = e_source_peek_name (source);

    /* new source */
    new_source = (ruri == NULL || ruri[0] == '\0' || g_str_equal (ruri, uid));

    if (new_source) {

        if (name == NULL || name[0] == '\0')
            name = "nonameyet";

        e_source_set_relative_uri (source, name);
    }

    if (is_toplevel (ruri)) {
        text = gtk_label_new (_("Toplevel"));
    } else {
        text = gtk_label_new (ruri);
    }

    gtk_widget_show (text);

#if (GTK_CHECK_VERSION(2, 6, 0))
    gtk_label_set_ellipsize (GTK_LABEL (text), PANGO_ELLIPSIZE_START);
#endif
    gtk_container_add (GTK_CONTAINER (button), text);

    sig_id = (gulong *) g_malloc0 (sizeof (gulong));

    *sig_id = g_signal_connect (source,
                                "changed", G_CALLBACK (sn_changed), sig_id);

    /* We do not support renames (yet?!) */
    if (new_source == FALSE) {

        gtk_widget_set_sensitive (button, FALSE);

        /* Nasty nasty hack ey ey ey */
        find_entries_and_set_sensitive (parent, FALSE);

    }

    /* attach it */
    if (!GTK_IS_BOX (parent)) {
        int row;

        row = GTK_TABLE (parent)->nrows;

        gtk_table_attach (GTK_TABLE (parent),
                          label, 0, 1, row, row + 1, GTK_FILL, 0, 0, 0);

        gtk_table_attach (GTK_TABLE (parent),
                          button, 1, 2,
                          row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0);

        /* HACK for to have a return value != NULL */
        ret = button;

    } else {
        GtkWidget *hbox;

        hbox = gtk_hbox_new (FALSE, 6);
        gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 6);
        gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 6);
        gtk_box_pack_start (GTK_BOX (parent), hbox, FALSE, FALSE, 6);
        gtk_widget_show_all (hbox);
        ret = hbox;
    }

    return ret;
}