mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 796736 - Register cell pop up columns width to narrow
On first start up, cells with a pop up were initialised with the sample text plus the cell height. This worked most of the time but with small fonts the height could be smaller than the minimum button width so the cell was too small. Add a function to retrieve the button width which can not be less than the minimum button width and add this to be the sample text width. Also when you double clicked on the header of a pop up cell column to auto size the cell width it did not take into account the button width and so was too narrow, this is also fixed by getting the button width.
This commit is contained in:
@@ -56,6 +56,8 @@ enum
|
|||||||
TARGET_COMPOUND_TEXT
|
TARGET_COMPOUND_TEXT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define MIN_BUTT_WIDTH 22 // minimum size for a button
|
||||||
|
|
||||||
static GtkBoxClass *gnc_item_edit_parent_class;
|
static GtkBoxClass *gnc_item_edit_parent_class;
|
||||||
|
|
||||||
static GtkToggleButtonClass *gnc_item_edit_tb_parent_class;
|
static GtkToggleButtonClass *gnc_item_edit_tb_parent_class;
|
||||||
@@ -114,9 +116,10 @@ gnc_item_edit_tb_get_preferred_width (GtkWidget *widget,
|
|||||||
gint x, y, w, h = 2, width = 0;
|
gint x, y, w, h = 2, width = 0;
|
||||||
gnc_item_edit_get_pixel_coords (GNC_ITEM_EDIT (item_edit), &x, &y, &w, &h);
|
gnc_item_edit_get_pixel_coords (GNC_ITEM_EDIT (item_edit), &x, &y, &w, &h);
|
||||||
width = ((h - 2)*2)/3;
|
width = ((h - 2)*2)/3;
|
||||||
if (width < 22) // minimum size for a button
|
if (width < MIN_BUTT_WIDTH)
|
||||||
width = 22;
|
width = MIN_BUTT_WIDTH;
|
||||||
*minimal_width = *natural_width = width;
|
*minimal_width = *natural_width = width;
|
||||||
|
item_edit->button_width = width;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -319,6 +322,7 @@ gnc_item_edit_init (GncItemEdit *item_edit)
|
|||||||
item_edit->popup_user_data = NULL;
|
item_edit->popup_user_data = NULL;
|
||||||
|
|
||||||
item_edit->style = NULL;
|
item_edit->style = NULL;
|
||||||
|
item_edit->button_width = MIN_BUTT_WIDTH;
|
||||||
|
|
||||||
gnc_virtual_location_init(&item_edit->virt_loc);
|
gnc_virtual_location_init(&item_edit->virt_loc);
|
||||||
}
|
}
|
||||||
@@ -797,6 +801,15 @@ gnc_item_edit_get_padding_border (GncItemEdit *item_edit, Sides side)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gint
|
||||||
|
gnc_item_edit_get_button_width (GncItemEdit *item_edit)
|
||||||
|
{
|
||||||
|
if (item_edit)
|
||||||
|
return item_edit->button_width;
|
||||||
|
else
|
||||||
|
return MIN_BUTT_WIDTH;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
button_press_cb (GtkWidget *widget, GdkEventButton *event, gpointer *pointer)
|
button_press_cb (GtkWidget *widget, GdkEventButton *event, gpointer *pointer)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ typedef struct
|
|||||||
GtkBorder padding;
|
GtkBorder padding;
|
||||||
GtkBorder margin;
|
GtkBorder margin;
|
||||||
GtkBorder border;
|
GtkBorder border;
|
||||||
|
gint button_width;
|
||||||
|
|
||||||
/* Where are we */
|
/* Where are we */
|
||||||
VirtualLocation virt_loc;
|
VirtualLocation virt_loc;
|
||||||
@@ -161,6 +162,8 @@ void gnc_item_edit_focus_out (GncItemEdit *item_edit);
|
|||||||
|
|
||||||
gint gnc_item_edit_get_margin (GncItemEdit *item_edit, Sides side);
|
gint gnc_item_edit_get_margin (GncItemEdit *item_edit, Sides side);
|
||||||
gint gnc_item_edit_get_padding_border (GncItemEdit *item_edit, Sides side);
|
gint gnc_item_edit_get_padding_border (GncItemEdit *item_edit, Sides side);
|
||||||
|
gint gnc_item_edit_get_button_width (GncItemEdit *item_edit);
|
||||||
|
|
||||||
|
|
||||||
GType gnc_item_edit_tb_get_type (void);
|
GType gnc_item_edit_tb_get_type (void);
|
||||||
GtkWidget *gnc_item_edit_tb_new (GnucashSheet *sheet);
|
GtkWidget *gnc_item_edit_tb_new (GnucashSheet *sheet);
|
||||||
|
|||||||
@@ -2268,6 +2268,7 @@ gnucash_sheet_col_max_width (GnucashSheet *sheet, gint virt_col, gint cell_col)
|
|||||||
SheetBlockStyle *style;
|
SheetBlockStyle *style;
|
||||||
PangoLayout *layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), "");
|
PangoLayout *layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), "");
|
||||||
GncItemEdit *item_edit = GNC_ITEM_EDIT(sheet->item_editor);
|
GncItemEdit *item_edit = GNC_ITEM_EDIT(sheet->item_editor);
|
||||||
|
const gchar *type_name;
|
||||||
|
|
||||||
g_return_val_if_fail (virt_col >= 0, 0);
|
g_return_val_if_fail (virt_col >= 0, 0);
|
||||||
g_return_val_if_fail (virt_col < sheet->num_virt_cols, 0);
|
g_return_val_if_fail (virt_col < sheet->num_virt_cols, 0);
|
||||||
@@ -2313,6 +2314,14 @@ gnucash_sheet_col_max_width (GnucashSheet *sheet, gint virt_col, gint cell_col)
|
|||||||
width += (gnc_item_edit_get_margin (item_edit, left_right) +
|
width += (gnc_item_edit_get_margin (item_edit, left_right) +
|
||||||
gnc_item_edit_get_padding_border (item_edit, left_right));
|
gnc_item_edit_get_padding_border (item_edit, left_right));
|
||||||
|
|
||||||
|
// get the cell type so we can add the button width to the
|
||||||
|
// text width if required.
|
||||||
|
type_name = gnc_table_get_cell_type_name (sheet->table, virt_loc);
|
||||||
|
if ((g_strcmp0 (type_name, DATE_CELL_TYPE_NAME) == 0)
|
||||||
|
|| (g_strcmp0 (type_name, COMBO_CELL_TYPE_NAME) == 0))
|
||||||
|
{
|
||||||
|
width += gnc_item_edit_get_button_width (item_edit);
|
||||||
|
}
|
||||||
max = MAX (max, width);
|
max = MAX (max, width);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -207,8 +207,7 @@ set_dimensions_pass_one (GnucashSheet *sheet, CellBlock *cursor,
|
|||||||
pango_layout_get_pixel_size (layout, &width, &cd->pixel_height);
|
pango_layout_get_pixel_size (layout, &width, &cd->pixel_height);
|
||||||
g_object_unref (layout);
|
g_object_unref (layout);
|
||||||
width += gnc_item_edit_get_margin (item_edit, left_right) +
|
width += gnc_item_edit_get_margin (item_edit, left_right) +
|
||||||
gnc_item_edit_get_padding_border (item_edit, left_right);
|
gnc_item_edit_get_padding_border (item_edit, left_right) + 2;
|
||||||
|
|
||||||
cd->pixel_height += gnc_item_edit_get_margin (item_edit, top_bottom) +
|
cd->pixel_height += gnc_item_edit_get_margin (item_edit, top_bottom) +
|
||||||
gnc_item_edit_get_padding_border (item_edit, top_bottom);
|
gnc_item_edit_get_padding_border (item_edit, top_bottom);
|
||||||
}
|
}
|
||||||
@@ -227,7 +226,7 @@ set_dimensions_pass_one (GnucashSheet *sheet, CellBlock *cursor,
|
|||||||
// This is used on new account popup cells to get the default
|
// This is used on new account popup cells to get the default
|
||||||
// width of text plus toggle button.
|
// width of text plus toggle button.
|
||||||
if (cell && cell->is_popup)
|
if (cell && cell->is_popup)
|
||||||
width += cd->pixel_height; // toggle button is square, use cell height
|
width += gnc_item_edit_get_button_width (item_edit);
|
||||||
|
|
||||||
cd->pixel_width = MAX (cd->pixel_width, width);
|
cd->pixel_width = MAX (cd->pixel_width, width);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user