Commit f19646ce authored by Morten Welinder's avatar Morten Welinder

Stf: improve fixed-width ruler.

parent cd54ec63
2013-04-24 Morten Welinder <terra@gnome.org>
* dialog-stf-fixed-page.c (cb_treeview_motion): Take cell padding
into account.
* dialog-stf-preview.c (stf_preview_find_column): Cleanup using
gtk+ 3.2 functions. Take cell padding into account.
* dialog-stf-fixed-page.c (stf_dialog_fixed_page_init): Cleanup.
Gtk+ 3.2 has the required fix.
......
......@@ -86,7 +86,9 @@ calc_char_index (RenderData_t *renderdata, int col, int *dx)
GtkCellRenderer *cell = stf_preview_get_cell_renderer (renderdata, col);
PangoLayout *layout;
PangoFontDescription *font_desc;
int ci, width;
int ci, width, padx;
gtk_cell_renderer_get_padding (cell, &padx, NULL);
g_object_get (G_OBJECT (cell), "font_desc", &font_desc, NULL);
layout = gtk_widget_create_pango_layout (GTK_WIDGET (renderdata->tree_view), "x");
......@@ -96,7 +98,7 @@ calc_char_index (RenderData_t *renderdata, int col, int *dx)
pango_font_description_free (font_desc);
if (width < 1) width = 1;
ci = (*dx < 0) ? 0 : (*dx + width / 2) / width;
ci = (*dx < padx) ? 0 : (*dx - padx + width / 2) / width;
*dx -= ci * width;
return ci;
......@@ -522,8 +524,14 @@ cb_treeview_motion (GtkWidget *widget,
if (col >= 0 && col < renderdata->colcount) {
int ci = calc_char_index (renderdata, col, &dx);
if (ci <= colwidth)
pagedata->fixed.ruler_x = x - dx - 1;
if (ci <= colwidth) {
int padx;
GtkCellRenderer *cell =
stf_preview_get_cell_renderer (renderdata, col);
gtk_cell_renderer_get_padding (cell, &padx, NULL);
pagedata->fixed.ruler_x = x - dx + padx;
}
}
gdk_event_request_motions (event);
......
......@@ -314,17 +314,23 @@ stf_preview_find_column (RenderData_t *renderdata, int x, int *pcol, int *dx)
*dx = 0;
/* Figure out what column we pressed in. */
for (col = 0; 1; col++) {
GtkWidget *w;
GtkAllocation a;
for (col = 0; TRUE; col++) {
int cx, cw;
GtkTreeViewColumn *column =
stf_preview_get_column (renderdata, col);
if (!column)
GtkCellRenderer *cell =
stf_preview_get_cell_renderer (renderdata, col);
int padx;
if (!column || !cell)
break;
w = gtk_bin_get_child (GTK_BIN (gtk_tree_view_column_get_button (column)));
gtk_widget_get_allocation (w, &a);
if (x < a.x + a.width) {
*dx = x - a.x;
gtk_cell_renderer_get_padding (cell, &padx, NULL);
cx = gtk_tree_view_column_get_x_offset (column);
cw = gtk_tree_view_column_get_width (column);
if (x < (cx + padx) + cw) {
*dx = x - (cx + padx);
break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment