2016-04-14 14:55:04 -05:00
|
|
|
// 14 april 2016
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
|
|
|
struct uiFontButton {
|
|
|
|
uiUnixControl c;
|
|
|
|
GtkWidget *widget;
|
|
|
|
GtkButton *button;
|
|
|
|
GtkFontButton *fb;
|
|
|
|
GtkFontChooser *fc;
|
2016-04-20 12:59:59 -05:00
|
|
|
void (*onChanged)(uiFontButton *, void *);
|
|
|
|
void *onChangedData;
|
2016-04-14 14:55:04 -05:00
|
|
|
};
|
|
|
|
|
2016-04-25 19:00:25 -05:00
|
|
|
uiUnixControlAllDefaults(uiFontButton)
|
2016-04-14 14:55:04 -05:00
|
|
|
|
|
|
|
// TODO NOTE no need to inhibit the signal; font-set is documented as only being sent when the user changes the font
|
|
|
|
static void onFontSet(GtkFontButton *button, gpointer data)
|
|
|
|
{
|
|
|
|
uiFontButton *b = uiFontButton(data);
|
|
|
|
|
2016-04-20 12:59:59 -05:00
|
|
|
(*(b->onChanged))(b, b->onChangedData);
|
2016-04-14 14:55:04 -05:00
|
|
|
}
|
|
|
|
|
2016-04-20 12:59:59 -05:00
|
|
|
static void defaultOnChanged(uiFontButton *b, void *data)
|
2016-04-14 14:55:04 -05:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2017-02-11 13:45:58 -06:00
|
|
|
void uiFontButtonFont(uiFontButton *b, uiDrawFontDescriptor *desc)
|
2016-04-14 14:55:04 -05:00
|
|
|
{
|
2017-02-11 13:45:58 -06:00
|
|
|
PangoFontDescription *pdesc;
|
2016-04-20 12:59:59 -05:00
|
|
|
|
2017-02-11 13:45:58 -06:00
|
|
|
pdesc = gtk_font_chooser_get_font_desc(b->fc);
|
|
|
|
fontdescFromPangoFontDescription(pdesc, desc);
|
2016-04-20 12:59:59 -05:00
|
|
|
// desc is transfer-full and thus is a copy
|
2017-02-11 13:45:58 -06:00
|
|
|
pango_font_description_free(pdesc);
|
2016-04-20 12:59:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void uiFontButtonOnChanged(uiFontButton *b, void (*f)(uiFontButton *, void *), void *data)
|
|
|
|
{
|
|
|
|
b->onChanged = f;
|
|
|
|
b->onChangedData = data;
|
2016-04-14 14:55:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uiFontButton *uiNewFontButton(void)
|
|
|
|
{
|
|
|
|
uiFontButton *b;
|
|
|
|
|
2016-04-25 19:00:25 -05:00
|
|
|
uiUnixNewControl(uiFontButton, b);
|
2016-04-14 14:55:04 -05:00
|
|
|
|
|
|
|
b->widget = gtk_font_button_new();
|
|
|
|
b->button = GTK_BUTTON(b->widget);
|
|
|
|
b->fb = GTK_FONT_BUTTON(b->widget);
|
|
|
|
b->fc = GTK_FONT_CHOOSER(b->widget);
|
|
|
|
|
|
|
|
// match behavior on other platforms
|
|
|
|
gtk_font_button_set_show_style(b->fb, TRUE);
|
|
|
|
gtk_font_button_set_show_size(b->fb, TRUE);
|
|
|
|
gtk_font_button_set_use_font(b->fb, FALSE);
|
|
|
|
gtk_font_button_set_use_size(b->fb, FALSE);
|
|
|
|
// other customizations
|
|
|
|
gtk_font_chooser_set_show_preview_entry(b->fc, TRUE);
|
|
|
|
|
|
|
|
g_signal_connect(b->widget, "font-set", G_CALLBACK(onFontSet), b);
|
2016-04-20 12:59:59 -05:00
|
|
|
uiFontButtonOnChanged(b, defaultOnChanged, NULL);
|
2016-04-14 14:55:04 -05:00
|
|
|
|
|
|
|
return b;
|
|
|
|
}
|