Font selection panel as part of notebook

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

Font selection panel as part of notebook

Igor Korot
Hi, ALL,
I'm trying to implement a font selection as part of the notebook/wizard control.

1. In the GTK+2 I can write following:

    GtkWidget *names = gtk_font_selection_get_family_list(
(GtkFontSelection *) m_fontPanel );
    GtkWidget *sizes = gtk_font_selection_get_size_entry(
(GtkFontSelection *) m_fontPanel );
    g_signal_connect( names, "cursor-changed", G_CALLBACK(
font_name_change ), this );

And then in the handler I am enabling the "Apply" button.

However in GTK+3 there is no gtk_font_selection_get_family_list() call
according to the docs. Is it possible to implement something like this
for GTK+3?

2. In the handler I wrote the following code:

        GtkTreeIter iter;
        GValue value;
        GtkTreeSelection *sel = gtk_tree_view_get_selection( view );
        GtkTreeModel *model = gtk_tree_view_get_model( view );
        GList *selRows = gtk_tree_selection_get_selected_rows( sel, &model );
        gtk_tree_model_get_iter( model, &iter, (GtkTreePath *)
selRows[0].data );
        gtk_tree_model_get_value( model, &iter, 0, &value );

However it looks like the value is empty.

What am I missing?

Thank you.
_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Gtk+ - General mailing list


Hi Igor,

Initialize the GValue structure and see if that does the trick for getting the value.

GValue value=G_VALUE_INIT;

https://developer.gnome.org/gobject/stable/gobject-Generic-values.html#G-VALUE-INIT:CAPS

If that doesn't work, check the return value of gtk_tree_model_get_iter() to make sure that your iter is good.

Eric



_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Igor Korot
Eric,

On Sat, Sep 23, 2017 at 2:58 PM,  <[hidden email]> wrote:

>
>
> Hi Igor,
>
> Initialize the GValue structure and see if that does the trick for getting
> the value.
>
> GValue value=G_VALUE_INIT;
>
> https://developer.gnome.org/gobject/stable/gobject-Generic-values.html#G-VALUE-INIT:CAPS

It looks like G_VALUE_INT is available since 2.30.
What should I use for earlier version?

Thank you.

>
> If that doesn't work, check the return value of gtk_tree_model_get_iter() to
> make sure that your iter is good.
>
> Eric
>
_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Fwd: Font selection panel as part of notebook

Igor Korot
In reply to this post by Gtk+ - General mailing list
Sorry, this was sent privately and not to the list.


---------- Forwarded message ----------
From: Igor Korot <[hidden email]>
Date: Sat, Sep 23, 2017 at 5:40 PM
Subject: Re: Font selection panel as part of notebook
To: [hidden email]


Hi Eric,
What about my first question?

Thank you.


On Sep 23, 2017 2:58 PM, <[hidden email]> wrote:

>
>
>
> Hi Igor,
>
> Initialize the GValue structure and see if that does the trick for getting the value.
>
> GValue value=G_VALUE_INIT;
>
> https://developer.gnome.org/gobject/stable/gobject-Generic-values.html#G-VALUE-INIT:CAPS
>
> If that doesn't work, check the return value of gtk_tree_model_get_iter() to make sure that your iter is good.
>
> Eric
>
_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Igor Korot
In reply to this post by Gtk+ - General mailing list
Eric,

On Sat, Sep 23, 2017 at 2:58 PM,  <[hidden email]> wrote:
>
>
> Hi Igor,
>
> Initialize the GValue structure and see if that does the trick for getting
> the value.
>
> GValue value=G_VALUE_INIT;

I initialied it with:

        g_value_init( &value, G_TYPE_STRING );

but it didn't help.

>
> https://developer.gnome.org/gobject/stable/gobject-Generic-values.html#G-VALUE-INIT:CAPS
>
> If that doesn't work, check the return value of gtk_tree_model_get_iter() to
> make sure that your iter is good.

the function returns TRUE and so the iter is good.

Thank you.

>
> Eric
>
_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Gtk+ - General mailing list

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
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Igor Korot
Eric,

On Sun, Sep 24, 2017 at 12:33 AM,  <[hidden email]> wrote:
>
> 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..."?

This is what I see on the Terminal:

igor@IgorDellGentoo ~ $ ./fontsel
Cursor Changed
43
((PangoFcFamily*) 0xba5a40)
Cursor Changed
43
((PangoFcFamily*) 0xba5a40)
Cursor Changed
43
((PangoFcFamily*) 0xba5a40)
Cursor Changed
43
((PangoFcFamily*) 0xba5a40)
Cursor Changed
44
((PangoFcFamily*) 0xba5a80)

It initially selects "Sans" and then I select "Serif".

I'm testing with GTK+2.24 on Gentoo Linux.

Thank you.

>
> 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
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Igor Korot
Eric,

On Sun, Sep 24, 2017 at 1:51 AM, Igor Korot <[hidden email]> wrote:

> Eric,
>
> On Sun, Sep 24, 2017 at 12:33 AM,  <[hidden email]> wrote:
>>
>> 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..."?
>
> This is what I see on the Terminal:
>
> igor@IgorDellGentoo ~ $ ./fontsel
> Cursor Changed
> 43
> ((PangoFcFamily*) 0xba5a40)
> Cursor Changed
> 43
> ((PangoFcFamily*) 0xba5a40)
> Cursor Changed
> 43
> ((PangoFcFamily*) 0xba5a40)
> Cursor Changed
> 43
> ((PangoFcFamily*) 0xba5a40)
> Cursor Changed
> 44
> ((PangoFcFamily*) 0xba5a80)
>
> It initially selects "Sans" and then I select "Serif".
>
> I'm testing with GTK+2.24 on Gentoo Linux.

I was calling "g_value_get_string( &value )" and this function failed.
That's why I did see
an empty string.

I didn't look at the GTK+ sources but it looks like the value
retrieved is just an address
of the string and not the string itself.

I do have a workaround. I didn't test it yet, but I'd prefer to get
this info this way.

Is there anything else?

Thank you.

>
> Thank you.
>
>>
>> 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
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Igor Korot
Eric,

On Sun, Sep 24, 2017 at 1:47 PM, Igor Korot <[hidden email]> wrote:

> Eric,
>
> On Sun, Sep 24, 2017 at 1:51 AM, Igor Korot <[hidden email]> wrote:
>> Eric,
>>
>> On Sun, Sep 24, 2017 at 12:33 AM,  <[hidden email]> wrote:
>>>
>>> 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..."?
>>
>> This is what I see on the Terminal:
>>
>> igor@IgorDellGentoo ~ $ ./fontsel
>> Cursor Changed
>> 43
>> ((PangoFcFamily*) 0xba5a40)
>> Cursor Changed
>> 43
>> ((PangoFcFamily*) 0xba5a40)
>> Cursor Changed
>> 43
>> ((PangoFcFamily*) 0xba5a40)
>> Cursor Changed
>> 43
>> ((PangoFcFamily*) 0xba5a40)
>> Cursor Changed
>> 44
>> ((PangoFcFamily*) 0xba5a80)
>>
>> It initially selects "Sans" and then I select "Serif".
>>
>> I'm testing with GTK+2.24 on Gentoo Linux.
>
> I was calling "g_value_get_string( &value )" and this function failed.
> That's why I did see
> an empty string.
>
> I didn't look at the GTK+ sources but it looks like the value
> retrieved is just an address
> of the string and not the string itself.
>
> I do have a workaround. I didn't test it yet, but I'd prefer to get
> this info this way.
>
> Is there anything else?

I think I will just create a generic tab that will mimic the behaviour.
The reason being - I don't have access to the "Style" list box.

Now the only thing left is find what styles are available for a specific
font name? Is this info available on the PangoFont?

Thank you.

>
> Thank you.
>
>>
>> Thank you.
>>
>>>
>>> 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
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Gtk+ - General mailing list

Igor,

It sounds like you are determined to hack at this. I would recommend the newer GtkFontChooserWidget but OK. The PangoFcFamily* isn't much help. You need to get your widget pointers and setup up callbacks on your treeviews. Maybe all you need is to connect a "row-activated" to know if the user clicked on a row. To do this you need to find your pointers. If you use gtk_container_forall() you can find them. When doing this you are breaking the design of the font selection widget. It is poor practice. It might be just what you need though.

Eric

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

#include<gtk/gtk.h>

static void find_widgets(GtkWidget* widget, gint *count)
  {
    const char *name = gtk_widget_get_name(widget);
    printf("% *d. %s\n", (*count)*2, *count, name);

    //Recursive call for each container widget in the file chooser dialog.
    if(GTK_IS_CONTAINER(widget))
      {
        (*count)++;
        gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)find_widgets, count);
        (*count)--;
      }

  }
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();
    G_GNUC_END_IGNORE_DEPRECATIONS

    gtk_container_add(GTK_CONTAINER(window), m_fontPanel);

    gtk_widget_show_all(window);

    gint count=0;
    gtk_container_forall(GTK_CONTAINER(m_fontPanel), (GtkCallback)find_widgets, &count);

    gtk_main();

    return 0;
  } 


_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Igor Korot
Eric,
Why am I breaking the design?
Is it illegal to do?

Thank you.

On Sep 24, 2017 7:17 PM, <[hidden email]> wrote:

Igor,

It sounds like you are determined to hack at this. I would recommend the newer GtkFontChooserWidget but OK. The PangoFcFamily* isn't much help. You need to get your widget pointers and setup up callbacks on your treeviews. Maybe all you need is to connect a "row-activated" to know if the user clicked on a row. To do this you need to find your pointers. If you use gtk_container_forall() you can find them. When doing this you are breaking the design of the font selection widget. It is poor practice. It might be just what you need though.

Eric

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

#include<gtk/gtk.h>

static void find_widgets(GtkWidget* widget, gint *count)
  {
    const char *name = gtk_widget_get_name(widget);
    printf("% *d. %s\n", (*count)*2, *count, name);

    //Recursive call for each container widget in the file chooser dialog.
    if(GTK_IS_CONTAINER(widget))
      {
        (*count)++;
        gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)find_widgets, count);
        (*count)--;
      }

  }
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();
    G_GNUC_END_IGNORE_DEPRECATIONS

    gtk_container_add(GTK_CONTAINER(window), m_fontPanel);

    gtk_widget_show_all(window);

    gint count=0;
    gtk_container_forall(GTK_CONTAINER(m_fontPanel), (GtkCallback)find_widgets, &count);

    gtk_main();

    return 0;
  } 


_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Gtk+ - General mailing list

A widget has encapsulated functionality that the designer of the widget does not expect you to use or see in your application code. Changing a "private" widget may have negative consequences for how the widget works. If a widget doesn't have the functionality that you need then file a feature request in bugzilla so that it can be implemented. Or, create your own widget.

Is it illegal? No, and I would say it is something, as a developer, it is good to look at. You would want to look at the code of how the widget you are changing works to see if it is OK to do so. The font selection widget is deprecated so I don't think anymore changes are going to be made to it. A widget developer can change the private structure at any time which could break code that depends on a certain structure. Your code would be at risk of not working even across minor version changes in GTK. You are probably fairly safe that this widgets internal structure isn't going to change though. That isn't true for a lot of widgets.




_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Igor Korot
On Sun, Sep 24, 2017 at 10:54 PM,  <[hidden email]> wrote:

>
> A widget has encapsulated functionality that the designer of the widget does
> not expect you to use or see in your application code. Changing a "private"
> widget may have negative consequences for how the widget works. If a widget
> doesn't have the functionality that you need then file a feature request in
> bugzilla so that it can be implemented. Or, create your own widget.
>
> Is it illegal? No, and I would say it is something, as a developer, it is
> good to look at. You would want to look at the code of how the widget you
> are changing works to see if it is OK to do so. The font selection widget is
> deprecated so I don't think anymore changes are going to be made to it. A
> widget developer can change the private structure at any time which could
> break code that depends on a certain structure. Your code would be at risk
> of not working even across minor version changes in GTK. You are probably
> fairly safe that this widgets internal structure isn't going to change
> though. That isn't true for a lot of widgets.

OK, understood.

>
>
>
_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Igor Korot
In reply to this post by Gtk+ - General mailing list
Erc,

On Sun, Sep 24, 2017 at 7:17 PM,  <[hidden email]> wrote:

>
> Igor,
>
> It sounds like you are determined to hack at this. I would recommend the
> newer GtkFontChooserWidget but OK. The PangoFcFamily* isn't much help. You
> need to get your widget pointers and setup up callbacks on your treeviews.
> Maybe all you need is to connect a "row-activated" to know if the user
> clicked on a row. To do this you need to find your pointers. If you use
> gtk_container_forall() you can find them. When doing this you are breaking
> the design of the font selection widget. It is poor practice. It might be
> just what you need though.

It is not "row-activated" that I need, as I can click on the already
selected row.
The "Apply" button should be enabled only if the changes are made.

So how do I modify the code below with the gtk_container_forall()?

Thank you.

>
> Eric
>
> /*
>    gcc -Wall font_selection2.c -o font_selection2 `pkg-config --cflags
> --libs gtk+-2.0`
>    gcc -Wall font_selection2.c -o font_selection2 `pkg-config --cflags
> --libs gtk+-3.0`
>    Tested with GTK3.18 on Ubuntu16.04
> */
>
> #include<gtk/gtk.h>
>
> static void find_widgets(GtkWidget* widget, gint *count)
>   {
>     const char *name = gtk_widget_get_name(widget);
>     printf("% *d. %s\n", (*count)*2, *count, name);
>
>     //Recursive call for each container widget in the file chooser dialog.
>     if(GTK_IS_CONTAINER(widget))
>       {
>         (*count)++;
>         gtk_container_foreach(GTK_CONTAINER(widget),
> (GtkCallback)find_widgets, count);
>         (*count)--;
>       }
>
>   }
> 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();
>     G_GNUC_END_IGNORE_DEPRECATIONS
>
>     gtk_container_add(GTK_CONTAINER(window), m_fontPanel);
>
>     gtk_widget_show_all(window);
>
>     gint count=0;
>     gtk_container_forall(GTK_CONTAINER(m_fontPanel),
> (GtkCallback)find_widgets, &count);
>
>     gtk_main();
>
>     return 0;
>   }
_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Gtk+ - General mailing list


The code prints out the names of the widgets in the font selection widget. Using the names you can figure out the internal widget pointers you want to get from the selection widget. This might take a little trial and error to figure out. Maybe try, if it is a treeview, gtk_tree_view_set_grid_lines() so that you can distinguish the treeview that you have. Once you have the pointer you want, save it. Then try to set up your callback or get the value you need. It is messy but should work.

Eric



_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Igor Korot
Eric,

On Sun, Sep 24, 2017 at 11:56 PM,  <[hidden email]> wrote:
>
>
> The code prints out the names of the widgets in the font selection widget.
> Using the names you can figure out the internal widget pointers you want to
> get from the selection widget. This might take a little trial and error to
> figure out. Maybe try, if it is a treeview, gtk_tree_view_set_grid_lines()
> so that you can distinguish the treeview that you have. Once you have the
> pointer you want, save it. Then try to set up your callback or get the value
> you need. It is messy but should work.

Ticket created: https://bugzilla.gnome.org/show_bug.cgi?id=788154

Thx.

>
> Eric
>
_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Reply | Threaded
Open this post in threaded view
|

Re: Font selection panel as part of notebook

Igor Korot
In reply to this post by Gtk+ - General mailing list
Eric,

On Sun, Sep 24, 2017 at 7:17 PM,  <[hidden email]> wrote:

>
> Igor,
>
> It sounds like you are determined to hack at this. I would recommend the
> newer GtkFontChooserWidget but OK. The PangoFcFamily* isn't much help. You
> need to get your widget pointers and setup up callbacks on your treeviews.
> Maybe all you need is to connect a "row-activated" to know if the user
> clicked on a row. To do this you need to find your pointers. If you use
> gtk_container_forall() you can find them. When doing this you are breaking
> the design of the font selection widget. It is poor practice. It might be
> just what you need though.

I did make it work with this sample.
The only thing I found - apparently GtkTreeView is also a GtkContainer().

Thank you.

>
> Eric
>
> /*
>    gcc -Wall font_selection2.c -o font_selection2 `pkg-config --cflags
> --libs gtk+-2.0`
>    gcc -Wall font_selection2.c -o font_selection2 `pkg-config --cflags
> --libs gtk+-3.0`
>    Tested with GTK3.18 on Ubuntu16.04
> */
>
> #include<gtk/gtk.h>
>
> static void find_widgets(GtkWidget* widget, gint *count)
>   {
>     const char *name = gtk_widget_get_name(widget);
>     printf("% *d. %s\n", (*count)*2, *count, name);
>
>     //Recursive call for each container widget in the file chooser dialog.
>     if(GTK_IS_CONTAINER(widget))
>       {
>         (*count)++;
>         gtk_container_foreach(GTK_CONTAINER(widget),
> (GtkCallback)find_widgets, count);
>         (*count)--;
>       }
>
>   }
> 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();
>     G_GNUC_END_IGNORE_DEPRECATIONS
>
>     gtk_container_add(GTK_CONTAINER(window), m_fontPanel);
>
>     gtk_widget_show_all(window);
>
>     gint count=0;
>     gtk_container_forall(GTK_CONTAINER(m_fontPanel),
> (GtkCallback)find_widgets, &count);
>
>     gtk_main();
>
>     return 0;
>   }
_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list