From b7f67bb387ebace7e2f043e1ec60d5e637cbb1d8 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Mon, 16 Dec 2019 12:36:37 +0000 Subject: [PATCH] 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. --- .../register/register-gnome/gnucash-item-edit.c | 17 +++++++++++++++-- .../register/register-gnome/gnucash-item-edit.h | 3 +++ gnucash/register/register-gnome/gnucash-sheet.c | 9 +++++++++ gnucash/register/register-gnome/gnucash-style.c | 5 ++--- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/gnucash/register/register-gnome/gnucash-item-edit.c b/gnucash/register/register-gnome/gnucash-item-edit.c index 4f27171f95..c603fdfbe9 100644 --- a/gnucash/register/register-gnome/gnucash-item-edit.c +++ b/gnucash/register/register-gnome/gnucash-item-edit.c @@ -56,6 +56,8 @@ enum TARGET_COMPOUND_TEXT }; +#define MIN_BUTT_WIDTH 22 // minimum size for a button + static GtkBoxClass *gnc_item_edit_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; gnc_item_edit_get_pixel_coords (GNC_ITEM_EDIT (item_edit), &x, &y, &w, &h); width = ((h - 2)*2)/3; - if (width < 22) // minimum size for a button - width = 22; + if (width < MIN_BUTT_WIDTH) + width = MIN_BUTT_WIDTH; *minimal_width = *natural_width = width; + item_edit->button_width = width; } static void @@ -319,6 +322,7 @@ gnc_item_edit_init (GncItemEdit *item_edit) item_edit->popup_user_data = NULL; item_edit->style = NULL; + item_edit->button_width = MIN_BUTT_WIDTH; 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 button_press_cb (GtkWidget *widget, GdkEventButton *event, gpointer *pointer) { diff --git a/gnucash/register/register-gnome/gnucash-item-edit.h b/gnucash/register/register-gnome/gnucash-item-edit.h index 2be4d249e4..09ffc91434 100644 --- a/gnucash/register/register-gnome/gnucash-item-edit.h +++ b/gnucash/register/register-gnome/gnucash-item-edit.h @@ -94,6 +94,7 @@ typedef struct GtkBorder padding; GtkBorder margin; GtkBorder border; + gint button_width; /* Where are we */ 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_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); GtkWidget *gnc_item_edit_tb_new (GnucashSheet *sheet); diff --git a/gnucash/register/register-gnome/gnucash-sheet.c b/gnucash/register/register-gnome/gnucash-sheet.c index fd5b8f6c54..e4ab6f398e 100644 --- a/gnucash/register/register-gnome/gnucash-sheet.c +++ b/gnucash/register/register-gnome/gnucash-sheet.c @@ -2268,6 +2268,7 @@ gnucash_sheet_col_max_width (GnucashSheet *sheet, gint virt_col, gint cell_col) SheetBlockStyle *style; PangoLayout *layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), ""); 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 < 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) + 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); } } diff --git a/gnucash/register/register-gnome/gnucash-style.c b/gnucash/register/register-gnome/gnucash-style.c index 13d801e4b5..181a24767f 100644 --- a/gnucash/register/register-gnome/gnucash-style.c +++ b/gnucash/register/register-gnome/gnucash-style.c @@ -207,8 +207,7 @@ set_dimensions_pass_one (GnucashSheet *sheet, CellBlock *cursor, pango_layout_get_pixel_size (layout, &width, &cd->pixel_height); g_object_unref (layout); 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) + 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 // width of text plus toggle button. 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); }