mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-26 09:42:25 +00:00
Unified font selector dialog box. _Extremely_ unfinished - there's a
sizable TODO at the top of gtkfont.c - but it's basically functional enough to select fonts of both types, so I'm checking it in now before I accidentally break it. [originally from svn r7938]
This commit is contained in:
parent
debbee0fe4
commit
82a586792f
@ -13,6 +13,7 @@
|
|||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
|
|
||||||
#include "gtkcols.h"
|
#include "gtkcols.h"
|
||||||
|
#include "gtkfont.h"
|
||||||
|
|
||||||
#ifdef TESTMODE
|
#ifdef TESTMODE
|
||||||
#define PUTTY_DO_GLOBALS /* actually _define_ globals */
|
#define PUTTY_DO_GLOBALS /* actually _define_ globals */
|
||||||
@ -1221,11 +1222,12 @@ static void filesel_ok(GtkButton *button, gpointer data)
|
|||||||
static void fontsel_ok(GtkButton *button, gpointer data)
|
static void fontsel_ok(GtkButton *button, gpointer data)
|
||||||
{
|
{
|
||||||
/* struct dlgparam *dp = (struct dlgparam *)data; */
|
/* struct dlgparam *dp = (struct dlgparam *)data; */
|
||||||
gpointer fontsel = gtk_object_get_data(GTK_OBJECT(button), "user-data");
|
unifontsel *fontsel = (unifontsel *)gtk_object_get_data
|
||||||
struct uctrl *uc = gtk_object_get_data(GTK_OBJECT(fontsel), "user-data");
|
(GTK_OBJECT(button), "user-data");
|
||||||
const char *name = gtk_font_selection_dialog_get_font_name
|
struct uctrl *uc = (struct uctrl *)fontsel->user_data;
|
||||||
(GTK_FONT_SELECTION_DIALOG(fontsel));
|
char *name = unifontsel_get_name(fontsel);
|
||||||
gtk_entry_set_text(GTK_ENTRY(uc->entry), name);
|
gtk_entry_set_text(GTK_ENTRY(uc->entry), name);
|
||||||
|
sfree(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void coloursel_ok(GtkButton *button, gpointer data)
|
static void coloursel_ok(GtkButton *button, gpointer data)
|
||||||
@ -1279,60 +1281,25 @@ static void filefont_clicked(GtkButton *button, gpointer data)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (uc->ctrl->generic.type == CTRL_FONTSELECT) {
|
if (uc->ctrl->generic.type == CTRL_FONTSELECT) {
|
||||||
#if !GTK_CHECK_VERSION(2,0,0)
|
|
||||||
gchar *spacings[] = { "c", "m", NULL };
|
|
||||||
#endif
|
|
||||||
const gchar *fontname = gtk_entry_get_text(GTK_ENTRY(uc->entry));
|
const gchar *fontname = gtk_entry_get_text(GTK_ENTRY(uc->entry));
|
||||||
/* TODO: In GTK 2, this only seems to offer client-side fonts. */
|
unifontsel *fontsel = unifontsel_new("Select a font");
|
||||||
GtkWidget *fontsel =
|
|
||||||
gtk_font_selection_dialog_new("Select a font");
|
gtk_window_set_modal(fontsel->window, TRUE);
|
||||||
gtk_window_set_modal(GTK_WINDOW(fontsel), TRUE);
|
unifontsel_set_name(fontsel, fontname);
|
||||||
#if !GTK_CHECK_VERSION(2,0,0)
|
|
||||||
gtk_font_selection_dialog_set_filter
|
gtk_object_set_data(GTK_OBJECT(fontsel->ok_button),
|
||||||
(GTK_FONT_SELECTION_DIALOG(fontsel),
|
"user-data", (gpointer)fontsel);
|
||||||
GTK_FONT_FILTER_BASE, GTK_FONT_ALL,
|
fontsel->user_data = uc;
|
||||||
NULL, NULL, NULL, NULL, spacings, NULL);
|
gtk_signal_connect(GTK_OBJECT(fontsel->ok_button), "clicked",
|
||||||
#endif
|
GTK_SIGNAL_FUNC(fontsel_ok), (gpointer)dp);
|
||||||
if (!gtk_font_selection_dialog_set_font_name
|
gtk_signal_connect_object(GTK_OBJECT(fontsel->ok_button), "clicked",
|
||||||
(GTK_FONT_SELECTION_DIALOG(fontsel), fontname)) {
|
GTK_SIGNAL_FUNC(unifontsel_destroy),
|
||||||
/*
|
(gpointer)fontsel);
|
||||||
* If the font name wasn't found as it was, try opening
|
gtk_signal_connect_object(GTK_OBJECT(fontsel->cancel_button),"clicked",
|
||||||
* it and extracting its FONT property. This should
|
GTK_SIGNAL_FUNC(unifontsel_destroy),
|
||||||
* have the effect of mapping short aliases into true
|
(gpointer)fontsel);
|
||||||
* XLFDs.
|
|
||||||
*/
|
gtk_widget_show(GTK_WIDGET(fontsel->window));
|
||||||
GdkFont *font = gdk_font_load(fontname);
|
|
||||||
if (font) {
|
|
||||||
XFontStruct *xfs = GDK_FONT_XFONT(font);
|
|
||||||
Display *disp = GDK_FONT_XDISPLAY(font);
|
|
||||||
Atom fontprop = XInternAtom(disp, "FONT", False);
|
|
||||||
unsigned long ret;
|
|
||||||
gdk_font_ref(font);
|
|
||||||
if (XGetFontProperty(xfs, fontprop, &ret)) {
|
|
||||||
char *name = XGetAtomName(disp, (Atom)ret);
|
|
||||||
if (name)
|
|
||||||
gtk_font_selection_dialog_set_font_name
|
|
||||||
(GTK_FONT_SELECTION_DIALOG(fontsel), name);
|
|
||||||
}
|
|
||||||
gdk_font_unref(font);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
gtk_object_set_data
|
|
||||||
(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel)->ok_button),
|
|
||||||
"user-data", (gpointer)fontsel);
|
|
||||||
gtk_object_set_data(GTK_OBJECT(fontsel), "user-data", (gpointer)uc);
|
|
||||||
gtk_signal_connect
|
|
||||||
(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel)->ok_button),
|
|
||||||
"clicked", GTK_SIGNAL_FUNC(fontsel_ok), (gpointer)dp);
|
|
||||||
gtk_signal_connect_object
|
|
||||||
(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel)->ok_button),
|
|
||||||
"clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy),
|
|
||||||
(gpointer)fontsel);
|
|
||||||
gtk_signal_connect_object
|
|
||||||
(GTK_OBJECT(GTK_FONT_SELECTION_DIALOG(fontsel)->cancel_button),
|
|
||||||
"clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy),
|
|
||||||
(gpointer)fontsel);
|
|
||||||
gtk_widget_show(fontsel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
1387
unix/gtkfont.c
1387
unix/gtkfont.c
File diff suppressed because it is too large
Load Diff
@ -36,11 +36,32 @@ typedef struct unifont {
|
|||||||
int width, height, ascent, descent;
|
int width, height, ascent, descent;
|
||||||
} unifont;
|
} unifont;
|
||||||
|
|
||||||
unifont *unifont_create(GtkWidget *widget, char *name, int wide, int bold,
|
unifont *unifont_create(GtkWidget *widget, const char *name,
|
||||||
|
int wide, int bold,
|
||||||
int shadowoffset, int shadowalways);
|
int shadowoffset, int shadowalways);
|
||||||
void unifont_destroy(unifont *font);
|
void unifont_destroy(unifont *font);
|
||||||
void unifont_draw_text(GdkDrawable *target, GdkGC *gc, unifont *font,
|
void unifont_draw_text(GdkDrawable *target, GdkGC *gc, unifont *font,
|
||||||
int x, int y, const char *string, int len,
|
int x, int y, const char *string, int len,
|
||||||
int wide, int bold, int cellwidth);
|
int wide, int bold, int cellwidth);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unified font selector dialog. I can't be bothered to do a
|
||||||
|
* proper GTK subclassing today, so this will just be an ordinary
|
||||||
|
* data structure with some useful members.
|
||||||
|
*
|
||||||
|
* (Of course, these aren't the only members; this structure is
|
||||||
|
* contained within a bigger one which holds data visible only to
|
||||||
|
* the implementation.)
|
||||||
|
*/
|
||||||
|
typedef struct unifontsel {
|
||||||
|
void *user_data; /* settable by the user */
|
||||||
|
GtkWindow *window;
|
||||||
|
GtkWidget *ok_button, *cancel_button;
|
||||||
|
} unifontsel;
|
||||||
|
|
||||||
|
unifontsel *unifontsel_new(const char *wintitle);
|
||||||
|
void unifontsel_destroy(unifontsel *fontsel);
|
||||||
|
void unifontsel_set_name(unifontsel *fontsel, const char *fontname);
|
||||||
|
char *unifontsel_get_name(unifontsel *fontsel);
|
||||||
|
|
||||||
#endif /* PUTTY_GTKFONT_H */
|
#endif /* PUTTY_GTKFONT_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user