Web lists-archives.com

Re: Font selection panel as part of notebook





When I test it out it looks like the font selection widget doesn't work very well in GTK3.

Not quite sure how you have it setup for GTK2 and what information you are using to activate the apply button. The GValue that I get returned is a PangoFcFamily*. I don't think this will help unless you pull in private data from Pango. You don't like "The quick brown fox..."?

Eric

/*
   gcc -Wall font_selection1.c -o font_selection1 `pkg-config --cflags --libs gtk+-3.0`
   gcc -Wall font_selection1.c -o font_selection1 `pkg-config --cflags --libs gtk+-2.0`
   Tested with GTK3.18 on Ubuntu16.04
*/

#include<gtk/gtk.h>

static void font_name_change(GtkTreeView *view, gpointer user_data)
  {
    g_print("Cursor Changed\n");
    GtkTreeIter iter;
    GValue value=G_VALUE_INIT;
    GList *selRows = NULL;
    GtkTreeSelection *sel = gtk_tree_view_get_selection( view );
    GtkTreeModel *model = gtk_tree_view_get_model( view );
    selRows = gtk_tree_selection_get_selected_rows( sel, &model );
    if(selRows!=NULL)
      {
        gchar *string1=gtk_tree_path_to_string((GtkTreePath *)selRows[0].data);
        g_print("%s\n", string1);
        g_free(string1);
        if(gtk_tree_model_get_iter( model, &iter, (GtkTreePath *)selRows[0].data ))
          {
            gtk_tree_model_get_value( model, &iter, 0, &value );
            gchar *string2=g_strdup_value_contents(&value);
            g_print("%s\n", string2);
            g_free(string2);
          }
        else
          {
            g_print("Need a valid iter.\n");
          }
      }
   else
      {
        g_print("No list.\n");
      }

   g_list_free_full(selRows, (GDestroyNotify) gtk_tree_path_free);

  }
int main(int argc, char *argv[])
  {
    gtk_init (&argc, &argv);

    GtkWidget *window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Font Selecton");
    gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    G_GNUC_BEGIN_IGNORE_DEPRECATIONS
    GtkWidget *m_fontPanel=gtk_font_selection_new();
    GtkWidget *names = gtk_font_selection_get_family_list((GtkFontSelection *) m_fontPanel );
    //For GTK3.
    gtk_tree_view_set_activate_on_single_click(GTK_TREE_VIEW(names), TRUE);
    //GtkWidget *sizes = gtk_font_selection_get_size_entry((GtkFontSelection *) m_fontPanel );
    g_signal_connect( names, "cursor-changed", G_CALLBACK(font_name_change), NULL );
    G_GNUC_END_IGNORE_DEPRECATIONS

    gtk_container_add(GTK_CONTAINER(window), m_fontPanel);

    gtk_widget_show_all(window);

    gtk_main();

    return 0;
  } 



_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
https://mail.gnome.org/mailman/listinfo/gtk-list