Fri, 26 Apr 2019 05:30:00 -0400
Add private accessors for GntWidget->priv.{width,height}.
--- a/gnt-skel.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gnt-skel.c Fri Apr 26 05:30:00 2019 -0400 @@ -22,6 +22,8 @@ #include "gnt-skel.h" +#include "gntwidgetprivate.h" + struct _GntSkel { GntWidget parent; @@ -50,9 +52,12 @@ static void gnt_skel_map(GntWidget *widget) { - if (widget->priv.width == 0 || widget->priv.height == 0) + gint width, height; + + gnt_widget_get_internal_size(widget, &width, &height); + if (width == 0 || height == 0) { gnt_widget_size_request(widget); - GNTDEBUG; + } } static gboolean
--- a/gntbox.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gntbox.c Fri Apr 26 05:30:00 2019 -0400 @@ -25,6 +25,8 @@ #include "gntstyle.h" #include "gntutils.h" +#include "gntwidgetprivate.h" + #include <string.h> typedef struct @@ -77,14 +79,18 @@ static void get_title_thingies(GntBox *box, char *title, int *p, int *r) { - GntWidget *widget = GNT_WIDGET(box); + gint width; int len; - char *end = (char*)gnt_util_onscreen_width_to_pointer(title, widget->priv.width - 4, &len); + char *end; + + gnt_widget_get_internal_size(GNT_WIDGET(box), &width, NULL); + end = (char *)gnt_util_onscreen_width_to_pointer(title, width - 4, + &len); if (p) - *p = (widget->priv.width - len) / 2; + *p = (width - len) / 2; if (r) - *r = (widget->priv.width + len) / 2; + *r = (width + len) / 2; *end = '\0'; } @@ -183,13 +189,11 @@ if (priv->vertical) { gint widgety; gnt_widget_get_position(widget, NULL, &widgety); - widget->priv.width = max; - widget->priv.height = cury - widgety; + gnt_widget_set_internal_size(widget, max, cury - widgety); } else { gint widgetx; gnt_widget_get_position(widget, &widgetx, NULL); - widget->priv.width = curx - widgetx; - widget->priv.height = max; + gnt_widget_set_internal_size(widget, curx - widgetx, max); } } @@ -264,8 +268,10 @@ static void gnt_box_map(GntWidget *widget) { - if (widget->priv.width == 0 || widget->priv.height == 0) - { + gint width, height; + + gnt_widget_get_internal_size(widget, &width, &height); + if (width == 0 || height == 0) { gnt_widget_size_request(widget); find_focusable_widget(GNT_BOX(widget)); } @@ -443,6 +449,7 @@ GList *iter; GntBox *box = GNT_BOX(widget); GntBoxPrivate *priv = gnt_box_get_instance_private(box); + gint widget_width, widget_height; int wchange, hchange; GntWidget *child, *last; @@ -450,8 +457,9 @@ return TRUE; } - wchange = widget->priv.width - width; - hchange = widget->priv.height - height; + gnt_widget_get_internal_size(widget, &widget_width, &widget_height); + wchange = widget_width - width; + hchange = widget_height - height; if (wchange == 0 && hchange == 0) return TRUE; /* Quit playing games with my size */ @@ -486,26 +494,30 @@ if (child) { for (iter = priv->list; iter; iter = iter->next) { GntWidget *wid = iter->data; + gint cw, ch; int w, h; if (wid == child) continue; gnt_widget_get_size(wid, &w, &h); + gnt_widget_get_internal_size(child, &cw, &ch); if (priv->vertical) { /* For a vertical box, if we are changing the width, make sure the widgets * in the box will fit after resizing the width. */ - if (wchange > 0 && - w >= child->priv.width && - !gnt_widget_confirm_size(wid, w - wchange, h)) + if (wchange > 0 && w >= cw && + !gnt_widget_confirm_size(wid, w - wchange, + h)) { return FALSE; + } } else { /* If we are changing the height, make sure the widgets in the box fit after * the resize. */ - if (hchange > 0 && - h >= child->priv.height && - !gnt_widget_confirm_size(wid, w, h - hchange)) + if (hchange > 0 && h >= ch && + !gnt_widget_confirm_size(wid, w, + h - hchange)) { return FALSE; + } } } } @@ -516,6 +528,7 @@ static void gnt_box_size_changed(GntWidget *widget, int oldw, int oldh) { + gint widget_width, widget_height; int wchange, hchange; GList *i; GntBox *box = GNT_BOX(widget); @@ -523,8 +536,9 @@ GntWidget *wid; int tw, th; - wchange = widget->priv.width - oldw; - hchange = widget->priv.height - oldh; + gnt_widget_get_internal_size(widget, &widget_width, &widget_height); + wchange = widget_width - oldw; + hchange = widget_height - oldh; wid = priv->size_queued; if (wid) { @@ -792,7 +806,7 @@ GntBoxPrivate *priv = NULL; GntWidget *widget = NULL; GList *iter; - gint widgetx, widgety; + gint widgetx, widgety, widgetwidth, widgetheight; int pos; g_return_if_fail(GNT_IS_BOX(box)); @@ -800,6 +814,7 @@ widget = GNT_WIDGET(box); gnt_widget_get_position(widget, &widgetx, &widgety); + gnt_widget_get_internal_size(widget, &widgetwidth, &widgetheight); pos = gnt_widget_get_has_border(widget) ? 1 : 0; if (!priv->active) { @@ -831,21 +846,23 @@ if (priv->vertical) { x = pos; if (priv->alignment == GNT_ALIGN_RIGHT) { - x += widget->priv.width - width; + x += widgetwidth - width; } else if (priv->alignment == GNT_ALIGN_MID) { - x += (widget->priv.width - width)/2; + x += (widgetwidth - width) / 2; } - if (x + width > widget->priv.width - pos) - x -= x + width - (widget->priv.width - pos); + if (x + width > widgetwidth - pos) { + x -= x + width - (widgetwidth - pos); + } } else { y = pos; if (priv->alignment == GNT_ALIGN_BOTTOM) { - y += widget->priv.height - height; + y += widgetheight - height; } else if (priv->alignment == GNT_ALIGN_MID) { - y += (widget->priv.height - height)/2; + y += (widgetheight - height) / 2; } - if (y + height >= widget->priv.height - pos) - y = widget->priv.height - height - pos; + if (y + height >= widgetheight - pos) { + y = widgetheight - height - pos; + } } copywin(w->window, widget->window, 0, 0, @@ -902,8 +919,7 @@ g_list_free(priv->focus); priv->list = NULL; priv->focus = NULL; - GNT_WIDGET(box)->priv.width = 0; - GNT_WIDGET(box)->priv.height = 0; + gnt_widget_set_internal_size(GNT_WIDGET(box), 0, 0); } void gnt_box_readjust(GntBox *box) @@ -933,15 +949,13 @@ else { gnt_widget_set_mapped(w, FALSE); - w->priv.width = 0; - w->priv.height = 0; + gnt_widget_set_internal_size(w, 0, 0); } } wid = GNT_WIDGET(box); gnt_widget_set_mapped(wid, FALSE); - wid->priv.width = 0; - wid->priv.height = 0; + gnt_widget_set_internal_size(wid, 0, 0); if (gnt_widget_get_parent(wid) == NULL) { g_list_free(priv->focus);
--- a/gntbutton.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gntbutton.c Fri Apr 26 05:30:00 2019 -0400 @@ -60,8 +60,11 @@ wbkgdset(widget->window, '\0' | gnt_color_pair(type)); mvwaddstr(widget->window, (small_button) ? 0 : 1, 2, C_(priv->text)); if (small_button) { + gint width; type = GNT_COLOR_HIGHLIGHT; - mvwchgat(widget->window, 0, 0, widget->priv.width, focus ? A_BOLD : A_REVERSE, type, NULL); + gnt_widget_get_internal_size(widget, &width, NULL); + mvwchgat(widget->window, 0, 0, width, + focus ? A_BOLD : A_REVERSE, type, NULL); } GNTDEBUG; @@ -72,21 +75,25 @@ { GntButton *button = GNT_BUTTON(widget); GntButtonPrivate *priv = gnt_button_get_instance_private(button); + gint width, height; - gnt_util_get_text_bound(priv->text, &widget->priv.width, - &widget->priv.height); - widget->priv.width += 4; + gnt_util_get_text_bound(priv->text, &width, &height); + width += 4; if (gnt_widget_get_has_border(widget)) { - widget->priv.height += 2; + height += 2; } + gnt_widget_set_internal_size(widget, width, height); } static void gnt_button_map(GntWidget *widget) { - if (widget->priv.width == 0 || widget->priv.height == 0) + gint width, height; + + gnt_widget_get_internal_size(widget, &width, &height); + if (width == 0 || height == 0) { gnt_widget_size_request(widget); - GNTDEBUG; + } } static gboolean
--- a/gntcombobox.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gntcombobox.c Fri Apr 26 05:30:00 2019 -0400 @@ -70,8 +70,9 @@ static void hide_popup(GntComboBox *box, gboolean set) { - gnt_widget_set_size(box->dropdown, - box->dropdown->priv.width - 1, box->dropdown->priv.height); + gint width, height; + gnt_widget_get_internal_size(box->dropdown, &width, &height); + gnt_widget_set_size(box->dropdown, width - 1, height); if (set) set_selection(box, gnt_tree_get_selection_data(GNT_TREE(box->dropdown))); else @@ -85,6 +86,7 @@ GntComboBox *box = GNT_COMBO_BOX(widget); char *text = NULL, *s; GntColorType type; + gint width; int len; if (box->dropdown && box->selected) @@ -100,13 +102,16 @@ wbkgdset(widget->window, '\0' | gnt_color_pair(type)); - s = (char*)gnt_util_onscreen_width_to_pointer(text, widget->priv.width - 4, &len); + gnt_widget_get_internal_size(widget, &width, NULL); + s = (char *)gnt_util_onscreen_width_to_pointer(text, width - 4, &len); *s = '\0'; mvwaddstr(widget->window, 1, 1, C_(text)); - whline(widget->window, ' ' | gnt_color_pair(type), widget->priv.width - 4 - len); - mvwaddch(widget->window, 1, widget->priv.width - 3, ACS_VLINE | gnt_color_pair(GNT_COLOR_NORMAL)); - mvwaddch(widget->window, 1, widget->priv.width - 2, ACS_DARROW | gnt_color_pair(GNT_COLOR_NORMAL)); + whline(widget->window, ' ' | gnt_color_pair(type), width - 4 - len); + mvwaddch(widget->window, 1, width - 3, + ACS_VLINE | gnt_color_pair(GNT_COLOR_NORMAL)); + mvwaddch(widget->window, 1, width - 2, + ACS_DARROW | gnt_color_pair(GNT_COLOR_NORMAL)); (void)wmove(widget->window, 1, 1); g_free(text); @@ -118,18 +123,23 @@ { if (!gnt_widget_get_mapped(widget)) { GntWidget *dd = GNT_COMBO_BOX(widget)->dropdown; + gint width; gnt_widget_size_request(dd); - widget->priv.height = 3; /* For now, a combobox will have border */ - widget->priv.width = MAX(10, dd->priv.width + 2); + gnt_widget_get_internal_size(dd, &width, NULL); + /* For now, a combobox will have border */ + gnt_widget_set_internal_size(widget, MAX(10, width + 2), 3); } } static void gnt_combo_box_map(GntWidget *widget) { - if (widget->priv.width == 0 || widget->priv.height == 0) + gint width, height; + + gnt_widget_get_internal_size(widget, &width, &height); + if (width == 0 || height == 0) { gnt_widget_size_request(widget); - GNTDEBUG; + } } static void @@ -137,14 +147,15 @@ { GntWidget *widget = GNT_WIDGET(box); GntWidget *parent = gnt_widget_get_parent(box->dropdown); - gint widgetx, widgety; + gint widgetx, widgety, widgetwidth, widgetheight; gint height; gint y; gnt_widget_get_position(widget, &widgetx, &widgety); + gnt_widget_get_internal_size(widget, &widgetwidth, &widgetheight); height = g_list_length(gnt_tree_get_rows(GNT_TREE(box->dropdown))); - y = widgety + widget->priv.height - 1; - gnt_widget_set_size(box->dropdown, widget->priv.width, height + 2); + y = widgety + widgetheight - 1; + gnt_widget_set_size(box->dropdown, widgetwidth, height + 2); if (y + height + 2 >= getmaxy(stdscr)) y = widgety - height - 1; @@ -152,10 +163,9 @@ if (parent->window) { mvwin(parent->window, y, widgetx); - wresize(parent->window, height+2, widget->priv.width); + wresize(parent->window, height + 2, widgetwidth); } - parent->priv.width = widget->priv.width; - parent->priv.height = height + 2; + gnt_widget_set_internal_size(parent, widgetwidth, height + 2); gnt_widget_set_visible(parent, TRUE); gnt_widget_draw(parent); @@ -270,7 +280,11 @@ G_GNUC_UNUSED int oldh) { GntComboBox *box = GNT_COMBO_BOX(widget); - gnt_widget_set_size(box->dropdown, widget->priv.width - 1, box->dropdown->priv.height); + gint width, height; + + gnt_widget_get_internal_size(widget, &width, NULL); + gnt_widget_get_internal_size(box->dropdown, NULL, &height); + gnt_widget_set_size(box->dropdown, width - 1, height); } static gboolean
--- a/gntentry.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gntentry.c Fri Apr 26 05:30:00 2019 -0400 @@ -312,6 +312,7 @@ { GntEntry *entry = GNT_ENTRY(widget); GntEntryPrivate *priv = gnt_entry_get_instance_private(entry); + gint width; int stop; gboolean focus; int curpos; @@ -329,8 +330,9 @@ mvwprintw(widget->window, 0, 0, "%s", C_(priv->scroll)); stop = gnt_util_onscreen_width(priv->scroll, priv->end); - if (stop < widget->priv.width) { - mvwhline(widget->window, 0, stop, GNT_ENTRY_CHAR, widget->priv.width - stop); + gnt_widget_get_internal_size(GNT_WIDGET(entry), &width, NULL); + if (stop < width) { + mvwhline(widget->window, 0, stop, GNT_ENTRY_CHAR, width - stop); } curpos = gnt_util_onscreen_width(priv->scroll, priv->cursor); @@ -345,17 +347,19 @@ gnt_entry_size_request(GntWidget *widget) { if (!gnt_widget_get_mapped(widget)) { - widget->priv.height = 1; - widget->priv.width = 20; + gnt_widget_set_internal_size(widget, 20, 1); } } static void gnt_entry_map(GntWidget *widget) { - if (widget->priv.width == 0 || widget->priv.height == 0) + gint width, height; + + gnt_widget_get_internal_size(widget, &width, &height); + if (width == 0 || height == 0) { gnt_widget_size_request(widget); - GNTDEBUG; + } } static void @@ -395,9 +399,10 @@ scroll_to_fit(GntEntry *entry) { GntEntryPrivate *priv = gnt_entry_get_instance_private(entry); + gint width; - while (gnt_util_onscreen_width(priv->scroll, priv->cursor) >= - GNT_WIDGET(entry)->priv.width) { + gnt_widget_get_internal_size(GNT_WIDGET(entry), &width, NULL); + while (gnt_util_onscreen_width(priv->scroll, priv->cursor) >= width) { priv->scroll = g_utf8_find_next_char(priv->scroll, NULL); } } @@ -803,7 +808,9 @@ priv->end -= count; priv->cursor = iter; if (priv->cursor <= priv->scroll) { - priv->scroll = priv->cursor - widget->priv.width + 2; + gint width; + gnt_widget_get_internal_size(widget, &width, NULL); + priv->scroll = priv->cursor - width + 2; if (priv->scroll < priv->start) { priv->scroll = priv->start; }
--- a/gntfilesel.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gntfilesel.c Fri Apr 26 05:30:00 2019 -0400 @@ -31,6 +31,8 @@ #include "gntstyle.h" #include "gnttree.h" +#include "gntwidgetprivate.h" + #include <string.h> #include <sys/types.h> #include <sys/stat.h> @@ -513,13 +515,21 @@ gnt_file_sel_size_request(GntWidget *widget) { GntFileSelPrivate *priv = NULL; + gint width, height; - if (widget->priv.height > 0) + gnt_widget_get_internal_size(widget, NULL, &height); + if (height > 0) { return; + } priv = gnt_file_sel_get_instance_private(GNT_FILE_SEL(widget)); - priv->dirs->priv.height = 16; - priv->files->priv.height = 16; + + gnt_widget_get_internal_size(priv->dirs, &width, NULL); + gnt_widget_set_internal_size(priv->dirs, width, 16); + + gnt_widget_get_internal_size(priv->files, &width, NULL); + gnt_widget_set_internal_size(priv->files, width, 16); + orig_size_request(widget); }
--- a/gntlabel.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gntlabel.c Fri Apr 26 05:30:00 2019 -0400 @@ -73,9 +73,10 @@ gnt_label_size_request(GntWidget *widget) { GntLabel *label = GNT_LABEL(widget); + gint width, height; - gnt_util_get_text_bound(label->text, - &widget->priv.width, &widget->priv.height); + gnt_util_get_text_bound(label->text, &width, &height); + gnt_widget_set_internal_size(widget, width, height); } static void
--- a/gntline.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gntline.c Fri Apr 26 05:30:00 2019 -0400 @@ -49,35 +49,39 @@ gnt_line_draw(GntWidget *widget) { GntLine *line = GNT_LINE(widget); - if (line->vertical) - mvwvline(widget->window, 1, 0, ACS_VLINE | gnt_color_pair(GNT_COLOR_NORMAL), - widget->priv.height - 2); - else - mvwhline(widget->window, 0, 1, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), - widget->priv.width - 2); + gint width, height; + + gnt_widget_get_internal_size(widget, &width, &height); + if (line->vertical) { + mvwvline(widget->window, 1, 0, + ACS_VLINE | gnt_color_pair(GNT_COLOR_NORMAL), + height - 2); + } else { + mvwhline(widget->window, 0, 1, + ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), + width - 2); + } } static void gnt_line_size_request(GntWidget *widget) { - if (GNT_LINE(widget)->vertical) - { - widget->priv.width = 1; - widget->priv.height = 5; - } - else - { - widget->priv.width = 5; - widget->priv.height = 1; + if (GNT_LINE(widget)->vertical) { + gnt_widget_set_internal_size(widget, 1, 5); + } else { + gnt_widget_set_internal_size(widget, 5, 1); } } static void gnt_line_map(GntWidget *widget) { - if (widget->priv.width == 0 || widget->priv.height == 0) + gint width, height; + + gnt_widget_get_internal_size(widget, &width, &height); + if (width == 0 || height == 0) { gnt_widget_size_request(widget); - GNTDEBUG; + } } static void
--- a/gntmain.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gntmain.c Fri Apr 26 05:30:00 2019 -0400 @@ -54,6 +54,8 @@ #include "gntmenuprivate.h" #include "gntwsprivate.h" +#include "gntwidgetprivate.h" + #include <panel.h> #include <stdio.h> @@ -180,13 +182,14 @@ while ((p = panel_below(p)) != NULL) { const GntNode *node = panel_userptr(p); GntWidget *wid; - gint widx, widy; + gint widx, widy, width, height; if (!node) continue; wid = node->me; gnt_widget_get_position(wid, &widx, &widy); - if (widx <= x && x < widx + wid->priv.width) { - if (widy <= y && y < widy + wid->priv.height) { + gnt_widget_get_internal_size(wid, &width, &height); + if (widx <= x && x < widx + width) { + if (widy <= y && y < widy + height) { widget = wid; break; }
--- a/gntmenu.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gntmenu.c Fri Apr 26 05:30:00 2019 -0400 @@ -25,6 +25,7 @@ #include "gntmenuitemcheck.h" #include "gntmenuitemprivate.h" +#include "gntwidgetprivate.h" #include <ctype.h> #include <string.h> @@ -139,11 +140,13 @@ GntMenu *menu = GNT_MENU(widget); if (menu->type == GNT_MENU_TOPLEVEL) { - widget->priv.height = 1; - widget->priv.width = getmaxx(stdscr); + gnt_widget_set_internal_size(widget, getmaxx(stdscr), 1); } else { + gint width; org_size_request(widget); - widget->priv.height = g_list_length(menu->list) + 2; + gnt_widget_get_internal_size(widget, &width, NULL); + gnt_widget_set_internal_size(widget, width, + g_list_length(menu->list) + 2); } } @@ -269,9 +272,12 @@ sub->parentmenu = menu; if (menu->type != GNT_MENU_TOPLEVEL) { GntWidget *widget = GNT_WIDGET(menu); + gint width; gnt_widget_get_position(widget, &x, &y); + gnt_widget_get_internal_size(widget, &width, + NULL); gnt_menuitem_set_position( - item, x + widget->priv.width - 1, + item, x + width - 1, y + gnt_tree_get_selection_visible_line( GNT_TREE(menu))); }
--- a/gntprogressbar.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gntprogressbar.c Fri Apr 26 05:30:00 2019 -0400 @@ -48,32 +48,43 @@ GntProgressBarPrivate *priv = gnt_progress_bar_get_instance_private ( GNT_PROGRESS_BAR (widget)); gchar progress[8]; + gint width, height; gint start, end, i, pos; int color; + gnt_widget_get_internal_size(widget, &width, &height); + g_snprintf (progress, sizeof (progress), "%.1f%%", priv->fraction * 100); color = gnt_color_pair(GNT_COLOR_NORMAL); switch (priv->orientation) { case GNT_PROGRESS_LEFT_TO_RIGHT: case GNT_PROGRESS_RIGHT_TO_LEFT: - start = (priv->orientation == GNT_PROGRESS_LEFT_TO_RIGHT ? 0 : (1.0 - priv->fraction) * widget->priv.width); - end = (priv->orientation == GNT_PROGRESS_LEFT_TO_RIGHT ? widget->priv.width * priv->fraction : widget->priv.width); + start = (priv->orientation == GNT_PROGRESS_LEFT_TO_RIGHT + ? 0 + : (1.0 - priv->fraction) * width); + end = (priv->orientation == GNT_PROGRESS_LEFT_TO_RIGHT + ? width * priv->fraction + : width); /* background */ - for (i = 0; i < widget->priv.height; i++) - mvwhline (widget->window, i, 0, ' ' | color, widget->priv.width); + for (i = 0; i < height; i++) { + mvwhline(widget->window, i, 0, ' ' | color, + width); + } /* foreground */ - for (i = 0; i < widget->priv.height; i++) + for (i = 0; i < height; i++) { mvwhline (widget->window, i, start, ACS_CKBOARD | color | A_REVERSE, end); + } /* text */ if (priv->show_value) { - pos = widget->priv.width / 2 - strlen (progress) / 2; + pos = width / 2 - strlen(progress) / 2; for (i = 0; i < progress[i]; i++, pos++) { wattrset (widget->window, color | ((pos < start || pos > end) ? A_NORMAL : A_REVERSE)); - mvwprintw (widget->window, widget->priv.height / 2, pos, "%c", progress[i]); + mvwprintw(widget->window, height / 2, + pos, "%c", progress[i]); } wattrset (widget->window, color); } @@ -81,23 +92,32 @@ break; case GNT_PROGRESS_TOP_TO_BOTTOM: case GNT_PROGRESS_BOTTOM_TO_TOP: - start = (priv->orientation == GNT_PROGRESS_TOP_TO_BOTTOM ? 0 : (1.0 - priv->fraction) * widget->priv.height); - end = (priv->orientation == GNT_PROGRESS_TOP_TO_BOTTOM ? widget->priv.height * priv->fraction : widget->priv.height); + start = (priv->orientation == GNT_PROGRESS_TOP_TO_BOTTOM + ? 0 + : (1.0 - priv->fraction) * height); + end = (priv->orientation == GNT_PROGRESS_TOP_TO_BOTTOM + ? height * priv->fraction + : height); /* background */ - for (i = 0; i < widget->priv.width; i++) - mvwvline (widget->window, 0, i, ' ' | color, widget->priv.height); + for (i = 0; i < width; i++) { + mvwvline(widget->window, 0, i, ' ' | color, + height); + } /* foreground */ - for (i = 0; i < widget->priv.width; i++) + for (i = 0; i < width; i++) { mvwvline (widget->window, start, i, ACS_CKBOARD | color | A_REVERSE, end); + } /* text */ if (priv->show_value) { - pos = widget->priv.height / 2 - strlen (progress) / 2; + pos = height / 2 - strlen(progress) / 2; for (i = 0; i < progress[i]; i++, pos++) { wattrset (widget->window, color | ((pos < start || pos > end) ? A_NORMAL : A_REVERSE)); - mvwprintw (widget->window, pos, widget->priv.width / 2, "%c\n", progress[i]); + mvwprintw(widget->window, pos, + width / 2, "%c\n", + progress[i]); } wattrset (widget->window, color); }
--- a/gntslider.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gntslider.c Fri Apr 26 05:30:00 2019 -0400 @@ -86,9 +86,9 @@ int position, size = 0; if (priv->vertical) - size = widget->priv.height; + gnt_widget_get_internal_size(widget, NULL, &size); else - size = widget->priv.width; + gnt_widget_get_internal_size(widget, &size, NULL); if (gnt_widget_has_focus(widget)) attr |= GNT_COLOR_HIGHLIGHT; @@ -123,20 +123,21 @@ GntSliderPrivate *priv = gnt_slider_get_instance_private(GNT_SLIDER(widget)); if (priv->vertical) { - widget->priv.width = 1; - widget->priv.height = 5; + gnt_widget_set_internal_size(widget, 1, 5); } else { - widget->priv.width = 5; - widget->priv.height = 1; + gnt_widget_set_internal_size(widget, 5, 1); } } static void gnt_slider_map(GntWidget *widget) { - if (widget->priv.width == 0 || widget->priv.height == 0) + gint width, height; + + gnt_widget_get_internal_size(widget, &width, &height); + if (width == 0 || height == 0) { gnt_widget_size_request(widget); - GNTDEBUG; + } } static gboolean
--- a/gnttextview.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gnttextview.c Fri Apr 26 05:30:00 2019 -0400 @@ -85,6 +85,7 @@ gnt_text_view_draw(GntWidget *widget) { GntTextView *view = GNT_TEXT_VIEW(widget); + gint width, height; int n; int i = 0; GList *lines; @@ -92,29 +93,30 @@ int comp = 0; /* Used for top-aligned text */ gboolean has_scroll = !(view->flags & GNT_TEXT_VIEW_NO_SCROLL); + gnt_widget_get_internal_size(widget, &width, &height); + wbkgd(widget->window, gnt_color_pair(GNT_COLOR_NORMAL)); werase(widget->window); n = g_list_length(view->list); - if ((view->flags & GNT_TEXT_VIEW_TOP_ALIGN) && - n < widget->priv.height) { + if ((view->flags & GNT_TEXT_VIEW_TOP_ALIGN) && n < height) { GList *now = view->list; - comp = widget->priv.height - n; + comp = height - n; view->list = g_list_nth_prev(view->list, comp); if (!view->list) { view->list = g_list_first(now); - comp = widget->priv.height - g_list_length(view->list); + comp = height - g_list_length(view->list); } else { comp = 0; } } - for (i = 0, lines = view->list; i < widget->priv.height && lines; i++, lines = lines->next) - { + for (i = 0, lines = view->list; i < height && lines; + i++, lines = lines->next) { GList *iter; GntTextLine *line = lines->data; - (void)wmove(widget->window, widget->priv.height - 1 - i - comp, 0); + (void)wmove(widget->window, height - 1 - i - comp, 0); for (iter = line->segments; iter; iter = iter->next) { @@ -151,11 +153,11 @@ *end = back; } wattroff(widget->window, A_UNDERLINE | A_BLINK | A_REVERSE); - whline(widget->window, ' ', widget->priv.width - line->length - has_scroll); + whline(widget->window, ' ', width - line->length - has_scroll); } - scrcol = widget->priv.width - 1; - rows = widget->priv.height - 2; + scrcol = width - 1; + rows = height - 2; if (has_scroll && rows > 0) { int total = g_list_length(g_list_first(view->list)); @@ -186,9 +188,9 @@ if (has_scroll) { mvwaddch(widget->window, 0, scrcol, (lines ? ACS_UARROW : ' ') | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); - mvwaddch(widget->window, widget->priv.height - 1, scrcol, - ((view->list && view->list->prev) ? ACS_DARROW : ' ') | - gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); + mvwaddch(widget->window, height - 1, scrcol, + ((view->list && view->list->prev) ? ACS_DARROW : ' ') | + gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); } wmove(widget->window, 0, 0); @@ -205,9 +207,12 @@ static void gnt_text_view_map(GntWidget *widget) { - if (widget->priv.width == 0 || widget->priv.height == 0) + gint width, height; + + gnt_widget_get_internal_size(widget, &width, &height); + if (width == 0 || height == 0) { gnt_widget_size_request(widget); - GNTDEBUG; + } } static gboolean @@ -244,6 +249,7 @@ static char * gnt_text_view_get_p(GntTextView *view, int x, int y) { + gint height; int n; int i = 0; GntWidget *wid = GNT_WIDGET(view); @@ -254,7 +260,8 @@ gchar *pos; n = g_list_length(view->list); - y = wid->priv.height - y; + gnt_widget_get_internal_size(wid, NULL, &height); + y = height - y; if (n < y) { x = 0; y = n - 1; @@ -438,7 +445,9 @@ static void gnt_text_view_size_changed(GntWidget *widget, int w, G_GNUC_UNUSED int h) { - if (w != widget->priv.width && gnt_widget_get_mapped(widget)) { + gint width; + gnt_widget_get_internal_size(widget, &width, NULL); + if (w != width && gnt_widget_get_mapped(widget)) { gnt_text_view_reflow(GNT_TEXT_VIEW(widget)); } } @@ -493,6 +502,7 @@ GntTextFormatFlags flags, const char *tagname) { GntWidget *widget = GNT_WIDGET(view); + gint widget_width; chtype fl = 0; const char *start, *end; GList *list = view->list; @@ -504,6 +514,7 @@ if (text == NULL || *text == '\0') return; + gnt_widget_get_internal_size(widget, &widget_width, NULL); fl = gnt_text_format_flag_to_chtype(flags); len = view->string->len; @@ -536,7 +547,7 @@ } line = view->list->data; - if (line->length == widget->priv.width - has_scroll) { + if (line->length == widget_width - has_scroll) { /* The last added line was exactly the same width as the widget */ line = g_new0(GntTextLine, 1); line->soft = TRUE; @@ -546,15 +557,16 @@ if ((end = strchr(start, '\r')) != NULL || (end = strchr(start, '\n')) != NULL) { len = gnt_util_onscreen_width(start, end - has_scroll); - if (widget->priv.width > 0 && - len >= widget->priv.width - line->length - has_scroll) { + if (widget_width > 0 && + len >= widget_width - line->length - has_scroll) { end = NULL; } } if (end == NULL) - end = gnt_util_onscreen_width_to_pointer(start, - widget->priv.width - line->length - has_scroll, &len); + end = gnt_util_onscreen_width_to_pointer( + start, widget_width - line->length - has_scroll, + &len); /* Try to append to the previous segment if possible */ if (line->segments) { @@ -698,8 +710,10 @@ int gnt_text_view_get_lines_above(GntTextView *view) { int above = 0; + gint height; GList *list; - list = g_list_nth(view->list, GNT_WIDGET(view)->priv.height); + gnt_widget_get_internal_size(GNT_WIDGET(view), NULL, &height); + list = g_list_nth(view->list, height); if (!list) return 0; while ((list = list->next)) @@ -817,9 +831,13 @@ scroll_tv(G_GNUC_UNUSED GntWidget *wid, const char *key, GntTextView *tv) { if (strcmp(key, GNT_KEY_PGUP) == 0) { - gnt_text_view_scroll(tv, -(GNT_WIDGET(tv)->priv.height - 2)); + gint height; + gnt_widget_get_internal_size(GNT_WIDGET(tv), NULL, &height); + gnt_text_view_scroll(tv, -(height - 2)); } else if (strcmp(key, GNT_KEY_PGDOWN) == 0) { - gnt_text_view_scroll(tv, GNT_WIDGET(tv)->priv.height - 2); + gint height; + gnt_widget_get_internal_size(GNT_WIDGET(tv), NULL, &height); + gnt_text_view_scroll(tv, height - 2); } else if (strcmp(key, GNT_KEY_DOWN) == 0) { gnt_text_view_scroll(tv, 1); } else if (strcmp(key, GNT_KEY_UP) == 0) {
--- a/gnttree.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gnttree.c Fri Apr 26 05:30:00 2019 -0400 @@ -468,6 +468,7 @@ int start, i; GntWidget *widget = GNT_WIDGET(tree); GntTreeRow *row; + gint width, height; int pos, up, down = 0; int rows, scrcol; int current = 0; @@ -475,6 +476,7 @@ if (!gnt_widget_get_mapped(GNT_WIDGET(tree))) return; + gnt_widget_get_internal_size(widget, &width, &height); pos = gnt_widget_get_has_border(widget) ? 1 : 0; if (priv->top == NULL) { @@ -492,10 +494,12 @@ int i; int x = pos; - mvwhline(widget->window, pos + 1, pos, ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), - widget->priv.width - pos - 1); - mvwhline(widget->window, pos, pos, ' ' | gnt_color_pair(GNT_COLOR_NORMAL), - widget->priv.width - pos - 1); + mvwhline(widget->window, pos + 1, pos, + ACS_HLINE | gnt_color_pair(GNT_COLOR_NORMAL), + width - pos - 1); + mvwhline(widget->window, pos, pos, + ' ' | gnt_color_pair(GNT_COLOR_NORMAL), + width - pos - 1); for (i = 0; i < priv->ncol; i++) { if (COLUMN_INVISIBLE(priv, i)) { @@ -513,7 +517,7 @@ (priv->show_separator ? ACS_TTEE : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL)); tree_mark_columns( - tree, pos, widget->priv.height - pos, + tree, pos, height - pos, (priv->show_separator ? ACS_BTEE : ACS_HLINE) | gnt_color_pair(GNT_COLOR_NORMAL)); } @@ -527,7 +531,7 @@ start = 2; } - rows = widget->priv.height - pos * 2 - start - 1; + rows = height - pos * 2 - start - 1; priv->bottom = get_next_n_opt(priv->top, rows, &down); if (down < rows) { @@ -540,14 +544,15 @@ up = get_distance(priv->top, priv->current); if (up < 0) priv->top = priv->current; - else if (up >= widget->priv.height - pos) + else if (up >= height - pos) priv->top = get_prev_n(priv->current, rows); if (priv->top && !row_matches_search(priv->top)) { priv->top = get_next(priv->top); } row = priv->top; - scrcol = widget->priv.width - 1 - 2 * pos; /* exclude the borders and the scrollbar */ + /* exclude the borders and the scrollbar */ + scrcol = width - 1 - 2 * pos; if (priv->current && !row_matches_search(priv->current)) { GntTreeRow *old = priv->current; @@ -555,9 +560,8 @@ tree_selection_changed(tree, old, priv->current); } - for (i = start + pos; row && i < widget->priv.height - pos; - i++, row = get_next(row)) - { + for (i = start + pos; row && i < height - pos; + i++, row = get_next(row)) { char *str; int wr; @@ -613,16 +617,14 @@ } wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_NORMAL)); - while (i < widget->priv.height - pos) - { - mvwhline(widget->window, i, pos, ' ', - widget->priv.width - pos * 2 - 1); + while (i < height - pos) { + mvwhline(widget->window, i, pos, ' ', width - pos * 2 - 1); tree_mark_columns(tree, pos, i, (priv->show_separator ? ACS_VLINE : ' ')); i++; } - scrcol = widget->priv.width - pos - 1; /* position of the scrollbar */ + scrcol = width - pos - 1; /* position of the scrollbar */ rows--; if (rows > 0) { @@ -660,15 +662,16 @@ ((priv->top != priv->root) ? ACS_UARROW : ' ') | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); - mvwaddch(widget->window, widget->priv.height - pos - 1, scrcol, - (row ? ACS_DARROW : ' ') | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); + mvwaddch(widget->window, height - pos - 1, scrcol, + (row ? ACS_DARROW : ' ') | + gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); /* If there's a search-text, show it in the bottom of the tree */ if (SEARCHING(priv)) { const char *str = gnt_util_onscreen_width_to_pointer( priv->search->str, scrcol - 1, NULL); wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D)); - mvwaddnstr(widget->window, widget->priv.height - pos - 1, pos, + mvwaddnstr(widget->window, height - pos - 1, pos, priv->search->str, str - priv->search->str); } wmove(widget->window, current, pos); @@ -689,13 +692,18 @@ static void gnt_tree_size_request(GntWidget *widget) { - if (widget->priv.height == 0) - widget->priv.height = 10; /* XXX: Why?! */ - if (widget->priv.width == 0) - { + gint width, height; + + gnt_widget_get_internal_size(widget, &width, &height); + + if (height == 0) { + height = 10; /* XXX: Why?! */ + } + + if (width == 0) { GntTree *tree = GNT_TREE(widget); GntTreePrivate *priv = gnt_tree_get_instance_private(tree); - int i, width = 0; + int i; width = gnt_widget_get_has_border(GNT_WIDGET(tree)) ? 3 : 1; for (i = 0; i < priv->ncol; i++) { if (!COLUMN_INVISIBLE(priv, i)) { @@ -705,8 +713,9 @@ } } } - widget->priv.width = width; } + + gnt_widget_set_internal_size(widget, width, height); } static void @@ -714,8 +723,10 @@ { GntTree *tree = GNT_TREE(widget); GntTreePrivate *priv = gnt_tree_get_instance_private(tree); - if (widget->priv.width == 0 || widget->priv.height == 0) - { + gint width, height; + + gnt_widget_get_internal_size(widget, &width, &height); + if (width == 0 || height == 0) { gnt_widget_size_request(widget); } priv->top = priv->root; @@ -831,10 +842,11 @@ if (priv->top != priv->root) { int dist = get_distance(priv->top, priv->current); - row = get_prev_n( - priv->top, - widget->priv.height - 1 - priv->show_title * 2 - - (gnt_widget_get_has_border(widget) ? 2 : 0)); + gint height; + gnt_widget_get_internal_size(widget, NULL, &height); + height -= 1 + priv->show_title * 2 + + (gnt_widget_get_has_border(widget) ? 2 : 0); + row = get_prev_n(priv->top, height); if (row == NULL) row = priv->root; priv->top = row; @@ -1003,8 +1015,12 @@ G_GNUC_UNUSED int h) { GntTree *tree = GNT_TREE(widget); - if (widget->priv.width <= 0) + gint width; + + gnt_widget_get_internal_size(widget, &width, NULL); + if (width <= 0) { return; + } readjust_columns(tree); } @@ -1260,16 +1276,23 @@ void gnt_tree_set_visible_rows(GntTree *tree, int rows) { GntWidget *widget = GNT_WIDGET(tree); - widget->priv.height = rows; + gint width, height; + + height = rows; if (gnt_widget_get_has_border(widget)) { - widget->priv.height += 2; + height += 2; } + + gnt_widget_get_internal_size(widget, &width, NULL); + gnt_widget_set_internal_size(widget, width, height); } int gnt_tree_get_visible_rows(GntTree *tree) { GntWidget *widget = GNT_WIDGET(tree); - int ret = widget->priv.height; + gint ret; + + gnt_widget_get_internal_size(widget, NULL, &ret); if (gnt_widget_get_has_border(widget)) { ret -= 2; }
--- a/gntwidget.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gntwidget.c Fri Apr 26 05:30:00 2019 -0400 @@ -468,6 +468,21 @@ *height = wid->priv.height + shadow; } +/* Internal. + * Different from gnt_widget_get_size in that it ignores shadows. + */ +void +gnt_widget_get_internal_size(GntWidget *widget, gint *width, gint *height) +{ + g_return_if_fail(GNT_IS_WIDGET(widget)); + if (width) { + *width = widget->priv.width; + } + if (height) { + *height = widget->priv.height; + } +} + static void init_widget(GntWidget *widget) { @@ -558,6 +573,17 @@ return ret; } +/* Internal. + * Different from gnt_widget_set_size in that it sets the values directly. + */ +void +gnt_widget_set_internal_size(GntWidget *widget, gint width, gint height) +{ + g_return_if_fail(GNT_IS_WIDGET(widget)); + widget->priv.width = width; + widget->priv.height = height; +} + /* Internal. */ void gnt_widget_get_minimum_size(GntWidget *widget, gint *width, gint *height)
--- a/gntwidgetprivate.h Fri Apr 26 04:22:10 2019 -0400 +++ b/gntwidgetprivate.h Fri Apr 26 05:30:00 2019 -0400 @@ -31,6 +31,8 @@ /* Private access to some internals. Contact us if you need these. */ void gnt_widget_get_minimum_size(GntWidget *widget, gint *width, gint *height); void gnt_widget_set_minimum_size(GntWidget *widget, gint width, gint height); +void gnt_widget_get_internal_size(GntWidget *widget, gint *width, gint *height); +void gnt_widget_set_internal_size(GntWidget *widget, gint width, gint height); G_END_DECLS
--- a/gntwm.c Fri Apr 26 04:22:10 2019 -0400 +++ b/gntwm.c Fri Apr 26 05:30:00 2019 -0400 @@ -62,6 +62,7 @@ #include "gntboxprivate.h" #include "gntmenuprivate.h" +#include "gntwidgetprivate.h" #include "gntwsprivate.h" #define IDLE_CHECK_INTERVAL 5 /* 5 seconds */ @@ -133,10 +134,14 @@ if (GNT_IS_WINDOW(widget) || GNT_IS_BOX(widget)) { GntWidget *active = gnt_box_get_active(GNT_BOX(widget)); if (active) { - int curx = active->priv.x + getcurx(active->window); - int cury = active->priv.y + getcury(active->window); - if (wmove(node->window, cury - widget->priv.y, curx - widget->priv.x) != OK) + gint curx, cury, widgetx, widgety; + gnt_widget_get_position(active, &curx, &cury); + gnt_widget_get_position(widget, &widgetx, &widgety); + curx += getcurx(active->window) - widgetx; + cury += getcury(active->window) - widgety; + if (wmove(node->window, cury, curx) != OK) { (void)wmove(node->window, 0, 0); + } } } } @@ -1781,13 +1786,9 @@ #if 1 { int x, y, w, h, maxx, maxy; - gboolean shadow = TRUE; - if (!gnt_widget_has_shadow(widget)) - shadow = FALSE; gnt_widget_get_position(widget, &x, &y); - w = widget->priv.width + shadow; - h = widget->priv.height + shadow; + gnt_widget_get_size(widget, &w, &h); maxx = getmaxx(stdscr); maxy = getmaxy(stdscr) - 1; /* room for the taskbar */