コード例 #1
0
ファイル: gtkcomboboxtext.c プロジェクト: sfeltman/gtk
/**
 * gtk_combo_box_text_insert_text:
 * @combo_box: A #GtkComboBoxText
 * @position: An index to insert @text
 * @text: A string
 *
 * Inserts @text at @position in the list of strings stored in @combo_box.
 *
 * If @position is negative then @text is appended.
 *
 * This is the same as calling gtk_combo_box_text_insert() with a %NULL
 * ID string.
 *
 * Since: 2.24
 */
void
gtk_combo_box_text_insert_text (GtkComboBoxText *combo_box,
                                gint             position,
                                const gchar     *text)
{
  gtk_combo_box_text_insert (combo_box, position, NULL, text);
}
コード例 #2
0
ファイル: gtkcomboboxtext.c プロジェクト: sfeltman/gtk
/**
 * gtk_combo_box_text_prepend:
 * @combo_box: A #GtkComboBox
 * @id: (allow-none): a string ID for this value, or %NULL
 * @text: a string
 *
 * Prepends @text to the list of strings stored in @combo_box.
 * If @id is non-%NULL then it is used as the ID of the row.
 *
 * This is the same as calling gtk_combo_box_text_insert() with a
 * position of 0.
 *
 * Since: 2.24
 */
void
gtk_combo_box_text_prepend (GtkComboBoxText *combo_box,
                            const gchar     *id,
                            const gchar     *text)
{
  gtk_combo_box_text_insert (combo_box, 0, id, text);
}
コード例 #3
0
ファイル: glade-icon-sources.c プロジェクト: kugel-/glade
static void
icon_name_entry_activated (GtkEntry * entry,
                           GladeEPropIconSources * eprop_sources)
{
  const gchar *text = gtk_entry_get_text (entry);
  GladeProperty *property;
  GladeIconSources *sources = NULL;

  if (!text || !text[0])
    return;

  property = glade_editor_property_get_property (GLADE_EDITOR_PROPERTY (eprop_sources));
  if (!property)
    return;

  glade_property_get (property, &sources);
  if (sources == NULL || g_hash_table_lookup (sources->sources, text) == NULL)
    {
      /* Add the new source if it doesnt already exist */
      gtk_combo_box_text_insert (GTK_COMBO_BOX_TEXT (eprop_sources->combo), -1, text, text);
    }

  /* Set the active id whether it existed or not */
  gtk_combo_box_set_active_id (GTK_COMBO_BOX (eprop_sources->combo), text);
}
コード例 #4
0
static VALUE
rg_insert(VALUE self, VALUE position, VALUE id, VALUE text)
{
    gtk_combo_box_text_insert(_SELF(self),
                              NUM2INT(position),
                              RVAL2CSTR_ACCEPT_NIL(id),
                              RVAL2CSTR(text));

    return self;
}
コード例 #5
0
ファイル: gtkcomboboxtext.c プロジェクト: sfeltman/gtk
/**
 * gtk_combo_box_text_prepend_text:
 * @combo_box: A #GtkComboBox
 * @text: A string
 *
 * Prepends @text to the list of strings stored in @combo_box.
 *
 * This is the same as calling gtk_combo_box_text_insert_text() with a
 * position of 0.
 *
 * Since: 2.24
 */
void
gtk_combo_box_text_prepend_text (GtkComboBoxText *combo_box,
                                 const gchar     *text)
{
  gtk_combo_box_text_insert (combo_box, 0, NULL, text);
}
コード例 #6
0
ファイル: action-dialog.c プロジェクト: cotigao/gupnp-tools
static GtkWidget *
create_widget_for_argument (GUPnPServiceActionArgInfo *arg_info,
                            GUPnPServiceIntrospection *introspection)
{
        GtkWidget                           *widget;
        const GUPnPServiceStateVariableInfo *variable;
        GValue                               default_value;

        variable = gupnp_service_introspection_get_state_variable (
                        introspection,
                        arg_info->related_state_variable);

        memset (&default_value, 0, sizeof (GValue));
        if (variable->is_numeric) {
                GValue min, max, step;

                memset (&min, 0, sizeof (GValue));
                memset (&max, 0, sizeof (GValue));
                memset (&step, 0, sizeof (GValue));

                g_value_init (&min, G_TYPE_DOUBLE);
                g_value_init (&max, G_TYPE_DOUBLE);
                g_value_init (&step, G_TYPE_DOUBLE);
                g_value_init (&default_value, G_TYPE_DOUBLE);

                g_value_transform (&variable->minimum, &min);
                g_value_transform (&variable->maximum, &max);
                g_value_transform (&variable->step, &step);
                g_value_transform (&variable->default_value, &default_value);

                widget = gtk_spin_button_new_with_range (
                                g_value_get_double (&min),
                                g_value_get_double (&max),
                                g_value_get_double (&step));
                gtk_spin_button_set_value (
                                GTK_SPIN_BUTTON (widget),
                                g_value_get_double (&default_value));

                if (arg_info->direction ==
                    GUPNP_SERVICE_ACTION_ARG_DIRECTION_OUT)
                        gtk_widget_set_sensitive (widget, FALSE);

                g_value_unset (&min);
                g_value_unset (&max);
                g_value_unset (&step);
                g_value_unset (&default_value);
        } else if (variable->type == G_TYPE_BOOLEAN) {
                gboolean active;

                widget = gtk_check_button_new ();

                active = g_value_get_boolean (&variable->default_value);
                gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget),
                                              active);

                if (arg_info->direction ==
                    GUPNP_SERVICE_ACTION_ARG_DIRECTION_OUT)
                        gtk_widget_set_sensitive (widget, FALSE);

        } else {
                const gchar *default_str;

                g_value_init (&default_value, G_TYPE_STRING);
                g_value_transform (&variable->default_value, &default_value);

                default_str = g_value_get_string (&default_value);

                /* Use a combobox if we are restricted to a list of values and
                 * it's an input argument */
                if (variable->allowed_values &&
                    arg_info->direction == GUPNP_SERVICE_ACTION_ARG_DIRECTION_IN) {
                        GList *node;
                        gint index = 0;

                        widget = gtk_combo_box_text_new ();
                        for (node = variable->allowed_values;
                             node;
                             node = node->next) {
                                gtk_combo_box_text_insert (
                                                GTK_COMBO_BOX_TEXT (widget),
                                                index,
                                                NULL,
                                                (const char *) node->data);

                                if (node == variable->allowed_values ||
                                    (default_str != NULL &&
                                     strcmp (default_str, node->data) == 0)) {
                                        gtk_combo_box_set_active (
                                                        GTK_COMBO_BOX (widget),
                                                        index);
                                }

                                index++;
                        }
                } else {
                        GtkTextView   *text_view;
                        GtkTextBuffer *text_buffer;

                        text_view = GTK_TEXT_VIEW (gtk_text_view_new ());
                        widget = gtk_scrolled_window_new (NULL, NULL);
                        g_object_set (widget,
                                      "shadow-type", GTK_SHADOW_IN,
                                      "hscrollbar-policy", GTK_POLICY_AUTOMATIC,
                                      "vscrollbar-policy", GTK_POLICY_AUTOMATIC,
                                      "min-content-height", DEFAULT_TEXTVIEW_HEIGHT,
                                      NULL);

                        gtk_container_add (GTK_CONTAINER (widget),
                                           GTK_WIDGET (text_view));
                        gtk_text_view_set_wrap_mode (text_view, GTK_WRAP_CHAR);
                        text_buffer = gtk_text_view_get_buffer (text_view);

                        if (default_str != NULL)
                                gtk_text_buffer_set_text (text_buffer,
                                                          default_str,
                                                          -1);

                        if (arg_info->direction ==
                            GUPNP_SERVICE_ACTION_ARG_DIRECTION_OUT)
                                gtk_text_view_set_editable (text_view, FALSE);

                }

                g_value_unset (&default_value);
        }

        g_object_set_data_full (G_OBJECT (widget),
                                "argument-name",
                                g_strdup (arg_info->name),
                                g_free);
        return widget;
}
コード例 #7
0
 /*!
 * \fn G_MODULE_EXPORT void openAssistantNewCsu(GtkWidget *widget, gpointer data)
 *  Open the assistant for a new csu file
 * \param[in] widget the widget which send the signal
 * \param[in] data the globalData
 */
G_MODULE_EXPORT void openAssistantNewCsu(GtkWidget *widget, gpointer data)
{
    globalData *user_data = (globalData*) data;
    char home_path[SIZE_MAX_FILE_NAME]="";
    gchar system_path[SIZE_MAX_FILE_NAME]="";
    list_game_config *ptr_list_config;
    gint i;

    #ifndef PORTABLE
    readHomePathSlash(home_path);
    readSystemPath(system_path);
    #else
    readHomePath(system_path);
    #endif // PORTABLE

    /* creating of the assistant */
    user_data->ptr_new_csu_file_assistant = gtk_assistant_new();

    /* Set the assistant windows */
    gtk_window_set_transient_for(GTK_WINDOW(user_data->ptr_new_csu_file_assistant),GTK_WINDOW(user_data->ptr_main_window));
    gtk_window_set_gravity(GTK_WINDOW(user_data->ptr_new_csu_file_assistant),GDK_GRAVITY_CENTER);
    gtk_window_set_position(GTK_WINDOW(user_data->ptr_new_csu_file_assistant),GTK_WIN_POS_CENTER_ON_PARENT);
    gtk_window_set_modal(GTK_WINDOW(user_data->ptr_new_csu_file_assistant),TRUE);
    gtk_window_set_type_hint(GTK_WINDOW(user_data->ptr_new_csu_file_assistant),GDK_WINDOW_TYPE_HINT_DIALOG);
    gtk_window_resize(GTK_WINDOW(user_data->ptr_new_csu_file_assistant),700,400);
    gtk_window_set_title(GTK_WINDOW(user_data->ptr_new_csu_file_assistant),_("New csu file assistant"));

    /*Set the signal of the assistant */
    g_signal_connect(user_data->ptr_new_csu_file_assistant,"delete-event", G_CALLBACK(deleteEventAssistantNewCsu),user_data);
    g_signal_connect(user_data->ptr_new_csu_file_assistant,"cancel", G_CALLBACK(deleteAssistantNewCsu),user_data);
    g_signal_connect(user_data->ptr_new_csu_file_assistant,"prepare", G_CALLBACK(preparePageAssistantNewCsu),user_data);
    g_signal_connect(user_data->ptr_new_csu_file_assistant,"close", G_CALLBACK(endAssistantNewCsu),user_data);


    /* Set the first page */
    GtkWidget *grid_1 = getWidgetFromBuilder(user_data->ptr_builder,"grid_new_csu_file_assistant_1");
    gtk_assistant_append_page(GTK_ASSISTANT(user_data->ptr_new_csu_file_assistant),grid_1);
    gtk_assistant_set_page_type(GTK_ASSISTANT(user_data->ptr_new_csu_file_assistant),grid_1,GTK_ASSISTANT_PAGE_INTRO);
    gtk_assistant_set_page_title(GTK_ASSISTANT(user_data->ptr_new_csu_file_assistant),grid_1,_("General information"));

    /* Configure the file chooser */
    gtk_entry_set_max_length(GTK_ENTRY(gtk_grid_get_child_at(GTK_GRID(grid_1),1,0)),SIZE_MAX_FILE_NAME/8);
    gtk_file_chooser_set_current_folder_file(GTK_FILE_CHOOSER(gtk_grid_get_child_at(GTK_GRID(grid_1),1,1)),g_file_new_for_path(g_locale_to_utf8(system_path,-1,NULL,NULL,NULL)),NULL);

    /* Set the combo  box of the game configuration */
    GtkWidget *combo_config = gtk_combo_box_text_new();
    ptr_list_config = readConfigListFile(home_path);
    for (i=0 ; i<ptr_list_config->nb_config ; i++)
        gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo_config),i,NULL,ptr_list_config->name_game_config[i]);
    gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo_config),ptr_list_config->nb_config,NULL,_("Add a new game configuration"));
    gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(combo_config),ptr_list_config->nb_config +1,NULL,_("Use an other game configuration"));
    gtk_grid_attach(GTK_GRID(grid_1),combo_config,1,3,1,1);
    g_signal_connect(combo_config,"changed", G_CALLBACK(chooseGameConfigurationNewAssistant),user_data);
    closeListGameConfig(ptr_list_config);


    /* Set the second page */
    GtkWidget *scrolled_window_name = getWidgetFromBuilder(user_data->ptr_builder,"scrolled_window_new_csu_file_assistant_2");
    gtk_assistant_append_page(GTK_ASSISTANT(user_data->ptr_new_csu_file_assistant),scrolled_window_name);
    gtk_assistant_set_page_type(GTK_ASSISTANT(user_data->ptr_new_csu_file_assistant),scrolled_window_name,GTK_ASSISTANT_PAGE_CONTENT);
    gtk_assistant_set_page_title(GTK_ASSISTANT(user_data->ptr_new_csu_file_assistant),scrolled_window_name,_("Player's names"));

    /* Set the grid */
    GtkWidget *grid_name = gtk_grid_new();
    gtk_grid_set_column_spacing(GTK_GRID(grid_name),10);
    gtk_grid_set_row_spacing(GTK_GRID(grid_name),10);
    gtk_grid_set_column_homogeneous(GTK_GRID(grid_name),TRUE);
    #if GTK_MINOR_VERSION >= 12
    gtk_widget_set_margin_end(grid_name,10);
    gtk_widget_set_margin_start(grid_name,10);
    #else
    gtk_widget_set_margin_right(grid_name,10);
    gtk_widget_set_margin_left(grid_name,10);
    #endif // GTK_MINOR_VERSION
    gtk_widget_set_margin_top(grid_name,10);
    gtk_widget_set_margin_bottom(grid_name,10);
    gtk_container_add(GTK_CONTAINER(gtk_bin_get_child(GTK_BIN(scrolled_window_name))),grid_name);


    /* Set the third page */
    GtkWidget *grid_3 = getWidgetFromBuilder(user_data->ptr_builder,"grid_new_csu_file_assistant_3");
    gtk_assistant_append_page(GTK_ASSISTANT(user_data->ptr_new_csu_file_assistant),grid_3);
    gtk_assistant_set_page_type(GTK_ASSISTANT(user_data->ptr_new_csu_file_assistant),grid_3,GTK_ASSISTANT_PAGE_CONFIRM);
    gtk_assistant_set_page_title(GTK_ASSISTANT(user_data->ptr_new_csu_file_assistant),grid_3,_("Distributor and validation"));

    GtkWidget *combo_distributor = gtk_combo_box_text_new();
    gtk_grid_attach(GTK_GRID(grid_3),combo_distributor,1,0,1,1);
    g_signal_connect(combo_distributor,"changed", G_CALLBACK(validAssistantNewCsuThree),user_data);

    cleanAssistantNewCsu(user_data);
    gtk_widget_show_all(user_data->ptr_new_csu_file_assistant);
}
コード例 #8
0
/*!
 * \fn G_MODULE_EXPORT void preparePageAssistantNewCsu(GtkAssistant *assistant,GtkWidget *widget, gpointer data)
 *  Prepare the new pages
 * \param[in] assistant the GtkAssistant
 * \param[in] widget the widget which send the signal
 * \param[in] data the globalData
 */
G_MODULE_EXPORT void preparePageAssistantNewCsu(GtkAssistant *assistant,GtkWidget *widget, gpointer data)
{
    globalData *user_data = (globalData*) data;
    gint page = gtk_assistant_get_current_page(assistant);
    gint nb_ligne=0;
    gint i;

    if (page == 1)
    {
        /* Calculate the number of line which already exist */
        GtkGrid *grid = GTK_GRID(gtk_bin_get_child(GTK_BIN(gtk_bin_get_child(GTK_BIN(widget)))));
        while(gtk_grid_get_child_at(grid,0,nb_ligne) != 0)
            nb_ligne++;

        /* Add the missing lines */
        for (i=nb_ligne ; i<user_data->ptr_csu_struct_tmp->nb_player ; i++)
        {
            gtk_grid_attach(grid,gtk_label_new(g_strdup_printf(_("Name of the %dth player"),i+1)),0,i,1,1);
            gtk_grid_attach(grid,gtk_entry_new(),1,i,1,1);
            gtk_entry_set_max_length(GTK_ENTRY(gtk_grid_get_child_at(GTK_GRID(grid),1,i)),SIZE_MAX_NAME);
            gtk_entry_set_placeholder_text(GTK_ENTRY(gtk_grid_get_child_at(GTK_GRID(grid),1,i)),g_strdup_printf(_("Type here the name of the %dth player"),i+1));
            gtk_entry_set_alignment(GTK_ENTRY(gtk_grid_get_child_at(GTK_GRID(grid),1,i)),0.5);
            g_signal_connect(gtk_grid_get_child_at(GTK_GRID(grid),1,i),"changed", G_CALLBACK(validAssistantNewCsuTwo),user_data);
        }

        /* Remove the unwanted lines */
        for (i = nb_ligne ; i > user_data->ptr_csu_struct_tmp->nb_player ; i--)
        {
            gtk_widget_destroy(gtk_grid_get_child_at(grid,0,i-1));
            gtk_widget_destroy(gtk_grid_get_child_at(grid,1,i-1));
        }
        validAssistantNewCsuTwo(NULL,user_data);
        gtk_widget_show_all(GTK_WIDGET(grid));
    }

    if (page == 2)
    {
        GtkGrid *grid = GTK_GRID(widget);

        /* If there is no distributor valid the page 3 */
        if (user_data->ptr_csu_struct_tmp->config.use_distributor == 0)
        {
            gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(gtk_grid_get_child_at(grid,1,0)));
            gtk_assistant_set_page_complete(GTK_ASSISTANT(user_data->ptr_new_csu_file_assistant),GTK_WIDGET(grid),TRUE);
        }
        /* Otherwise Create a combo box to choose the distributor */
        else
        {
            gint index = gtk_combo_box_get_active(GTK_COMBO_BOX(gtk_grid_get_child_at(grid,1,0)));
            gtk_combo_box_text_remove_all(GTK_COMBO_BOX_TEXT(gtk_grid_get_child_at(grid,1,0)));
            for (i = 0 ; i<user_data->ptr_csu_struct_tmp->nb_player ; i++)
                gtk_combo_box_text_insert(GTK_COMBO_BOX_TEXT(gtk_grid_get_child_at(grid,1,0)),i,NULL,user_data->ptr_csu_struct_tmp->player_names[i]);

            /* If the last distributor still exist, choose it */
            if (index <= user_data->ptr_csu_struct_tmp->nb_player)
                gtk_combo_box_set_active(GTK_COMBO_BOX(gtk_grid_get_child_at(grid,1,0)),index);

            validAssistantNewCsuThree(NULL,user_data);
        }
    }

    if (page == 0)
        validAssistantNewCsuOne(NULL,user_data);
}
コード例 #9
0
ファイル: glade-icon-sources.c プロジェクト: kugel-/glade
static void
populate_store_foreach (const gchar * icon_name,
                        GList * sources, GladeEPropIconSources * eprop_sources)
{
  GtkIconSource *source;
  GtkTreeIter parent_iter, iter;
  GList *l;

  /* Update the comboboxentry's store here... */
  gtk_combo_box_text_insert (GTK_COMBO_BOX_TEXT (eprop_sources->combo), -1, icon_name, icon_name);
  gtk_combo_box_set_active_id (GTK_COMBO_BOX (eprop_sources->combo), icon_name);

  /* Dont set COLUMN_ICON_NAME here */
  gtk_tree_store_append (eprop_sources->store, &parent_iter, NULL);
  gtk_tree_store_set (eprop_sources->store, &parent_iter,
                      COLUMN_TEXT, icon_name,
                      COLUMN_TEXT_EDITABLE, FALSE,
                      COLUMN_TEXT_WEIGHT, PANGO_WEIGHT_BOLD, -1);

  for (l = sources; l; l = l->next)
    {
      GdkPixbuf *pixbuf;
      gchar *str;

      source = l->data;
      pixbuf = gtk_icon_source_get_pixbuf (source);
      str = g_object_get_data (G_OBJECT (pixbuf), "GladeFileName");

      gtk_tree_store_append (eprop_sources->store, &iter, &parent_iter);
      gtk_tree_store_set (eprop_sources->store, &iter,
                          COLUMN_ICON_NAME, icon_name,
                          COLUMN_LIST_INDEX, g_list_index (sources, source),
                          COLUMN_TEXT, str,
                          COLUMN_TEXT_EDITABLE, TRUE,
                          COLUMN_TEXT_WEIGHT, PANGO_WEIGHT_NORMAL, -1);

      if (!gtk_icon_source_get_direction_wildcarded (source))
        {
          GtkTextDirection direction = gtk_icon_source_get_direction (source);
          str =
              glade_utils_enum_string_from_value_displayable
              (GTK_TYPE_TEXT_DIRECTION, direction);
          gtk_tree_store_set (eprop_sources->store, &iter,
                              COLUMN_DIRECTION_ACTIVE, TRUE, COLUMN_DIRECTION,
                              str, -1);
          g_free (str);
        }

      if (!gtk_icon_source_get_size_wildcarded (source))
        {
          GtkIconSize size = gtk_icon_source_get_size (source);
          str =
              glade_utils_enum_string_from_value_displayable
              (GTK_TYPE_ICON_SIZE, size);
          gtk_tree_store_set (eprop_sources->store, &iter, COLUMN_SIZE_ACTIVE,
                              TRUE, COLUMN_SIZE, str, -1);
          g_free (str);
        }

      if (!gtk_icon_source_get_state_wildcarded (source))
        {
          GtkStateType state = gtk_icon_source_get_state (source);
          str =
              glade_utils_enum_string_from_value_displayable
              (GTK_TYPE_STATE_TYPE, state);
          gtk_tree_store_set (eprop_sources->store, &iter, COLUMN_STATE_ACTIVE,
                              TRUE, COLUMN_STATE, str, -1);
          g_free (str);
        }

      if (!l->next)
        {
          GtkTreePath *path =
              gtk_tree_model_get_path (GTK_TREE_MODEL (eprop_sources->store),
                                       &iter);
          gtk_tree_view_expand_to_path (GTK_TREE_VIEW (eprop_sources->view),
                                        path);
          gtk_tree_path_free (path);
        }
    }
}