making layout printable, b.g.o#502961
svn path=/trunk/; revision=8327
This commit is contained in:
parent
6f1adeb10e
commit
f5208b90ed
7 changed files with 259 additions and 43 deletions
|
@ -1,3 +1,11 @@
|
|||
2007-12-11 Sergey Udaltsov <svu@gnome.org>
|
||||
|
||||
* gnome-keyboard-properties-xkb.c, gnome-keyboard-properties-xkblt.c,
|
||||
gnome-keyboard-properties-xkb.h, gnome-keyboard-properties-xkbpv.c,
|
||||
gnome-keyboard-properties.glade, gnome-keyboard-properties-xkbltadd.c:
|
||||
making printing available,
|
||||
http://bugzilla.gnome.org/show_bug.cgi?id=502961
|
||||
|
||||
2007-12-06 Jens Granseuer <jensgr@gmx.net>
|
||||
|
||||
* gnome-keyboard-properties.glade: don't mark padding strings and stock
|
||||
|
|
|
@ -170,6 +170,11 @@ setup_xkb_tabs (GladeXML * dialog, GConfChangeSet * changeset)
|
|||
g_signal_connect (peditor, "value-changed", (GCallback)
|
||||
chk_separate_group_per_window_toggled, dialog);
|
||||
|
||||
#ifdef HAVE_X11_EXTENSIONS_XKB_H
|
||||
if (strcmp (xkl_engine_get_backend_name (engine), "XKB"))
|
||||
#endif
|
||||
gtk_widget_hide (WID ("xkb_layouts_print"));
|
||||
|
||||
xkb_layouts_prepare_selected_tree (dialog, changeset);
|
||||
xkb_layouts_fill_selected_tree (dialog);
|
||||
|
||||
|
|
|
@ -56,6 +56,8 @@ extern void clear_xkb_elements_list (GSList * list);
|
|||
|
||||
extern char *xci_desc_to_utf8 (XklConfigItem * ci);
|
||||
|
||||
extern gchar *xkb_layout_description_utf8 (const gchar *visible);
|
||||
|
||||
extern void enable_disable_restoring (GladeXML * dialog);
|
||||
|
||||
extern void preview_toggled (GladeXML * dialog, GtkWidget * button);
|
||||
|
@ -86,6 +88,13 @@ extern GtkWidget *xkb_layout_preview_create_widget (GladeXML *
|
|||
|
||||
extern void xkb_layout_preview_update (GladeXML * chooser_dialog);
|
||||
|
||||
extern void xkb_layout_preview_set_drawing_layout (GtkWidget *kbdraw,
|
||||
const gchar *id);
|
||||
|
||||
extern void xkb_layout_preview_print (GtkWidget *kbdraw,
|
||||
GtkWindow *parent_window,
|
||||
const gchar *id);
|
||||
|
||||
extern gchar *xkb_layout_chooser_get_selected_id (GladeXML *
|
||||
chooser_dialog);
|
||||
|
||||
|
|
|
@ -179,6 +179,7 @@ static void
|
|||
xkb_layouts_enable_disable_buttons (GladeXML * dialog)
|
||||
{
|
||||
GtkWidget *add_layout_btn = WID ("xkb_layouts_add");
|
||||
GtkWidget *print_layout_btn = WID ("xkb_layouts_print");
|
||||
GtkWidget *del_layout_btn = WID ("xkb_layouts_remove");
|
||||
GtkWidget *selected_layouts_tree = WID ("xkb_layouts_selected");
|
||||
|
||||
|
@ -202,6 +203,8 @@ xkb_layouts_enable_disable_buttons (GladeXML * dialog)
|
|||
|| max_selected_layouts == 0));
|
||||
gtk_widget_set_sensitive (del_layout_btn, (n_selected_layouts > 1)
|
||||
&& (n_selected_selected_layouts > 0));
|
||||
gtk_widget_set_sensitive (print_layout_btn,
|
||||
(n_selected_selected_layouts > 0));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -353,6 +356,19 @@ xkb_layouts_prepare_selected_tree (GladeXML * dialog,
|
|||
dialog);
|
||||
}
|
||||
|
||||
gchar *xkb_layout_description_utf8 (const gchar *visible)
|
||||
{
|
||||
char *l, *sl, *v, *sv;
|
||||
char *v1, *utf_visible;
|
||||
if (gkbd_keyboard_config_get_descriptions (config_registry, visible,
|
||||
&sl, &l, &sv, &v))
|
||||
visible = gkbd_keyboard_config_format_full_layout (l, v);
|
||||
v1 = g_strdup (visible);
|
||||
utf_visible = g_locale_to_utf8 (g_strstrip (v1), -1, NULL, NULL, NULL);
|
||||
g_free (v1);
|
||||
return utf_visible;
|
||||
}
|
||||
|
||||
void
|
||||
xkb_layouts_fill_selected_tree (GladeXML * dialog)
|
||||
{
|
||||
|
@ -373,18 +389,9 @@ xkb_layouts_fill_selected_tree (GladeXML * dialog)
|
|||
for (cur_layout = layouts; cur_layout != NULL;
|
||||
cur_layout = cur_layout->next) {
|
||||
GtkTreeIter iter;
|
||||
char *l, *sl, *v, *sv;
|
||||
char *v1, *utf_visible;
|
||||
const char *visible = (char *) cur_layout->data;
|
||||
gchar *utf_visible = xkb_layout_description_utf8 (visible);
|
||||
gtk_list_store_append (list_store, &iter);
|
||||
if (gkbd_keyboard_config_get_descriptions
|
||||
(config_registry, visible, &sl, &l, &sv, &v))
|
||||
visible =
|
||||
gkbd_keyboard_config_format_full_layout (l, v);
|
||||
v1 = g_strdup (visible);
|
||||
utf_visible =
|
||||
g_locale_to_utf8 (g_strstrip (v1), -1, NULL, NULL,
|
||||
NULL);
|
||||
gtk_list_store_set (list_store, &iter,
|
||||
SEL_LAYOUT_TREE_COL_DESCRIPTION,
|
||||
utf_visible,
|
||||
|
@ -392,7 +399,6 @@ xkb_layouts_fill_selected_tree (GladeXML * dialog)
|
|||
SEL_LAYOUT_TREE_COL_ID,
|
||||
cur_layout->data, -1);
|
||||
g_free (utf_visible);
|
||||
g_free (v1);
|
||||
}
|
||||
|
||||
clear_xkb_elements_list (layouts);
|
||||
|
@ -433,6 +439,27 @@ add_selected_layout (GtkWidget * button, GladeXML * dialog)
|
|||
xkb_layout_choose (dialog);
|
||||
}
|
||||
|
||||
static void
|
||||
print_selected_layout (GtkWidget * button, GladeXML * dialog)
|
||||
{
|
||||
gint idx = find_selected_layout_idx (dialog);
|
||||
|
||||
if (idx != -1) {
|
||||
GSList *layouts_list = xkb_layouts_get_selected_list ();
|
||||
const gchar *id = g_slist_nth_data (layouts_list, idx);
|
||||
|
||||
GtkWidget *window = WID ("keyboard_dialog");
|
||||
GtkWidget *kbdraw = xkb_layout_preview_create_widget (NULL);
|
||||
g_object_ref_sink (kbdraw);
|
||||
gtk_widget_set_parent (kbdraw, window);
|
||||
xkb_layout_preview_set_drawing_layout (kbdraw, id);
|
||||
xkb_layout_preview_print (kbdraw, GTK_WINDOW (window), id);
|
||||
g_object_unref (kbdraw);
|
||||
|
||||
clear_xkb_elements_list (layouts_list);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
remove_selected_layout (GtkWidget * button, GladeXML * dialog)
|
||||
{
|
||||
|
@ -465,6 +492,8 @@ xkb_layouts_register_buttons_handlers (GladeXML * dialog)
|
|||
{
|
||||
g_signal_connect (G_OBJECT (WID ("xkb_layouts_add")), "clicked",
|
||||
G_CALLBACK (add_selected_layout), dialog);
|
||||
g_signal_connect (G_OBJECT (WID ("xkb_layouts_print")), "clicked",
|
||||
G_CALLBACK (print_selected_layout), dialog);
|
||||
g_signal_connect (G_OBJECT (WID ("xkb_layouts_remove")), "clicked",
|
||||
G_CALLBACK (remove_selected_layout), dialog);
|
||||
}
|
||||
|
|
|
@ -113,6 +113,7 @@ xkb_layout_chooser_enable_disable_buttons (GladeXML * chooser_dialog)
|
|||
gtk_dialog_set_response_sensitive (GTK_DIALOG
|
||||
(CWID ("xkb_layout_chooser")),
|
||||
GTK_RESPONSE_OK, enable_ok);
|
||||
gtk_widget_set_sensitive (CWID ("btnPrint"), enable_ok);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -354,6 +355,17 @@ xkl_layout_chooser_add_default_switcher_if_necessary (GSList *
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
xkb_layout_chooser_print (GladeXML * chooser_dialog)
|
||||
{
|
||||
GtkWidget *chooser = CWID ("xkb_layout_chooser");
|
||||
GtkWidget *kbdraw =
|
||||
GTK_WIDGET (g_object_get_data (G_OBJECT (chooser), "kbdraw"));
|
||||
const char *id = xkb_layout_chooser_get_selected_id (chooser_dialog);
|
||||
xkb_layout_preview_print (kbdraw,
|
||||
GTK_WINDOW (CWID ("xkb_layout_chooser")), id);
|
||||
}
|
||||
|
||||
static void
|
||||
xkb_layout_chooser_response (GtkDialog * dialog,
|
||||
gint response, GladeXML * chooser_dialog)
|
||||
|
@ -379,6 +391,11 @@ xkb_layout_chooser_response (GtkDialog * dialog,
|
|||
|
||||
clear_xkb_elements_list (layouts_list);
|
||||
}
|
||||
} else if (response == gtk_dialog_get_response_for_widget
|
||||
(dialog, CWID ("btnPrint"))) {
|
||||
xkb_layout_chooser_print (chooser_dialog);
|
||||
g_signal_stop_emission_by_name (dialog, "response");
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_window_get_position (GTK_WINDOW (dialog), &rect.x, &rect.y);
|
||||
|
@ -387,7 +404,6 @@ xkb_layout_chooser_response (GtkDialog * dialog,
|
|||
gkbd_preview_save_position (&rect);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
xkb_layout_choose (GladeXML * dialog)
|
||||
{
|
||||
|
@ -413,10 +429,14 @@ xkb_layout_choose (GladeXML * dialog)
|
|||
gtk_container_add (GTK_CONTAINER (CWID ("previewFrame")),
|
||||
kbdraw);
|
||||
gtk_widget_show_all (kbdraw);
|
||||
gtk_button_box_set_child_secondary (GTK_BUTTON_BOX
|
||||
(CWID ("hbtnBox")),
|
||||
CWID ("btnPrint"), TRUE);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
gtk_widget_hide_all (CWID ("vboxPreview"));
|
||||
gtk_widget_hide (CWID ("btnPrint"));
|
||||
}
|
||||
|
||||
g_signal_connect (G_OBJECT (chooser),
|
||||
|
|
|
@ -75,7 +75,15 @@ xkb_layout_preview_update (GladeXML * chooser_dialog)
|
|||
GtkWidget *kbdraw =
|
||||
GTK_WIDGET (g_object_get_data (G_OBJECT (chooser), "kbdraw"));
|
||||
gchar *id = xkb_layout_chooser_get_selected_id (chooser_dialog);
|
||||
xkb_layout_preview_set_drawing_layout (kbdraw, id);
|
||||
g_free (id);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
xkb_layout_preview_set_drawing_layout (GtkWidget * kbdraw, const gchar * id)
|
||||
{
|
||||
#ifdef HAVE_X11_EXTENSIONS_XKB_H
|
||||
if (kbdraw != NULL && id != NULL) {
|
||||
XklConfigRec *data;
|
||||
char **p, *layout, *variant;
|
||||
|
@ -118,7 +126,94 @@ xkb_layout_preview_update (GladeXML * chooser_dialog)
|
|||
}
|
||||
g_object_unref (G_OBJECT (data));
|
||||
}
|
||||
|
||||
g_free (id);
|
||||
#endif
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GtkWidget *kbdraw;
|
||||
const gchar *id;
|
||||
} XkbLayoutPreviewPrintData;
|
||||
|
||||
|
||||
static void
|
||||
xkb_layout_preview_begin_print (GtkPrintOperation *operation,
|
||||
GtkPrintContext *context,
|
||||
XkbLayoutPreviewPrintData *data)
|
||||
{
|
||||
gtk_print_operation_set_n_pages (operation, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
xkb_layout_preview_draw_page (GtkPrintOperation *operation,
|
||||
GtkPrintContext *context,
|
||||
gint page_nr,
|
||||
XkbLayoutPreviewPrintData *data)
|
||||
{
|
||||
cairo_t *cr = gtk_print_context_get_cairo_context (context);
|
||||
PangoLayout *layout = gtk_print_context_create_pango_layout (context);
|
||||
PangoFontDescription *desc =
|
||||
pango_font_description_from_string ("sans 8");
|
||||
gdouble width = gtk_print_context_get_width (context);
|
||||
gdouble height = gtk_print_context_get_height (context);
|
||||
gdouble dpi_x = gtk_print_context_get_dpi_x (context);
|
||||
gdouble dpi_y = gtk_print_context_get_dpi_y (context);
|
||||
gchar *header, *description;
|
||||
|
||||
gtk_print_operation_set_unit (operation, GTK_PIXELS);
|
||||
|
||||
description = xkb_layout_description_utf8 (data->id);
|
||||
header = g_strdup_printf
|
||||
(_("%s keyboard drawn by Gnome Control Center\n"
|
||||
"Copyright © X.Org Foundation and "
|
||||
"XKeyboardConfig contributors\n"
|
||||
"For licensing see package metadata"), description);
|
||||
g_free (description);
|
||||
pango_layout_set_markup (layout, header, -1);
|
||||
pango_layout_set_font_description (layout, desc);
|
||||
pango_font_description_free (desc);
|
||||
pango_layout_set_width (layout, pango_units_from_double (width));
|
||||
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
|
||||
cairo_set_source_rgb (cr, 0, 0, 0);
|
||||
cairo_move_to (cr, 0, 0);
|
||||
pango_cairo_show_layout (cr, layout);
|
||||
|
||||
gkbd_keyboard_drawing_render (GKBD_KEYBOARD_DRAWING (data->kbdraw),
|
||||
cr, layout,
|
||||
0.0, 0.0, width, height, dpi_x, dpi_y);
|
||||
|
||||
g_object_unref (layout);
|
||||
}
|
||||
|
||||
void
|
||||
xkb_layout_preview_print (GtkWidget *kbdraw, GtkWindow *parent_window,
|
||||
const gchar *id)
|
||||
{
|
||||
GtkPrintOperation *print;
|
||||
GtkPrintOperationResult res;
|
||||
static GtkPrintSettings *settings = NULL;
|
||||
XkbLayoutPreviewPrintData data = { kbdraw, id };
|
||||
|
||||
print = gtk_print_operation_new ();
|
||||
|
||||
if (settings != NULL)
|
||||
gtk_print_operation_set_print_settings (print, settings);
|
||||
|
||||
g_signal_connect (print, "begin_print",
|
||||
G_CALLBACK (xkb_layout_preview_begin_print), &data);
|
||||
g_signal_connect (print, "draw_page",
|
||||
G_CALLBACK (xkb_layout_preview_draw_page), &data);
|
||||
|
||||
res = gtk_print_operation_run (print,
|
||||
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
|
||||
parent_window,
|
||||
NULL);
|
||||
|
||||
if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
|
||||
if (settings != NULL)
|
||||
g_object_unref (settings);
|
||||
settings = gtk_print_operation_get_print_settings (print);
|
||||
g_object_ref (settings);
|
||||
}
|
||||
|
||||
g_object_unref (print);
|
||||
}
|
||||
|
|
|
@ -506,11 +506,15 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHButtonBox" id="hbuttonbox2">
|
||||
<widget class="GtkHBox" id="hbox2">
|
||||
<property name="visible">True</property>
|
||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||
<property name="spacing">6</property>
|
||||
<property name="layout_style">GTK_BUTTONBOX_END</property>
|
||||
<child>
|
||||
<widget class="GtkHButtonBox" id="hbuttonbox2">
|
||||
<property name="visible">True</property>
|
||||
<property name="spacing">6</property>
|
||||
<property name="layout_style">GTK_BUTTONBOX_START</property>
|
||||
<child>
|
||||
<widget class="GtkButton" id="xkb_layouts_remove">
|
||||
<property name="visible">True</property>
|
||||
|
@ -525,6 +529,20 @@
|
|||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkButton" id="xkb_layouts_print">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="label">gtk-print</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="response_id">0</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkButton" id="xkb_layouts_add">
|
||||
<property name="visible">True</property>
|
||||
|
@ -536,7 +554,13 @@
|
|||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="position">2</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -551,7 +575,7 @@
|
|||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
<property name="pack_type">GTK_PACK_END</property>
|
||||
<property name="position">2</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
|
@ -1059,6 +1083,10 @@
|
|||
</child>
|
||||
<child>
|
||||
<widget class="GtkVBox" id="vboxPreview">
|
||||
<property name="visible">True</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<widget class="GtkHBox" id="hbox1">
|
||||
<property name="visible">True</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
|
@ -1072,6 +1100,12 @@
|
|||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">False</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkFrame" id="previewFrame">
|
||||
<property name="visible">True</property>
|
||||
|
@ -1096,9 +1130,22 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child internal-child="action_area">
|
||||
<widget class="GtkHButtonBox" id="dialog-action_area2">
|
||||
<widget class="GtkHButtonBox" id="hbtnBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="layout_style">GTK_BUTTONBOX_END</property>
|
||||
<child>
|
||||
<widget class="GtkButton" id="btnPrint">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="can_default">True</property>
|
||||
<property name="label">gtk-print</property>
|
||||
<property name="use_stock">True</property>
|
||||
<property name="response_id">1</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="secondary">True</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkButton" id="cancelbutton2">
|
||||
<property name="visible">True</property>
|
||||
|
@ -1108,6 +1155,9 @@
|
|||
<property name="use_stock">True</property>
|
||||
<property name="response_id">-6</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkButton" id="btnOk">
|
||||
|
@ -1119,7 +1169,7 @@
|
|||
<property name="response_id">-5</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue