X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=unix%2Fgtkcols.c;h=e8223a726e3bab89fb6357419ccf4807632dddb1;hb=095072fa46b2d7b8beafaddb2f873d2f500a1e10;hp=c3df584a3d650f8579e8c579c05ab87e02b14407;hpb=e076959f6c1900af73271a27834e398a62d7332f;p=PuTTY.git diff --git a/unix/gtkcols.c b/unix/gtkcols.c index c3df584a..e8223a72 100644 --- a/unix/gtkcols.c +++ b/unix/gtkcols.c @@ -290,6 +290,14 @@ static void columns_remove(GtkContainer *container, GtkWidget *widget) gtk_widget_unparent(widget); cols->children = g_list_remove_link(cols->children, children); g_list_free(children); + + if (child->same_height_as) { + g_return_if_fail(child->same_height_as->same_height_as == child); + child->same_height_as->same_height_as = NULL; + if (gtk_widget_get_visible(child->same_height_as->widget)) + gtk_widget_queue_resize(GTK_WIDGET(container)); + } + g_free(child); if (was_visible) gtk_widget_queue_resize(GTK_WIDGET(container)); @@ -397,6 +405,7 @@ void columns_add(Columns *cols, GtkWidget *child, childdata->colstart = colstart; childdata->colspan = colspan; childdata->force_left = FALSE; + childdata->same_height_as = NULL; cols->children = g_list_append(cols->children, childdata); cols->taborder = g_list_append(cols->taborder, child); @@ -418,26 +427,56 @@ void columns_add(Columns *cols, GtkWidget *child, } } +static ColumnsChild *columns_find_child(Columns *cols, GtkWidget *widget) +{ + GList *children; + ColumnsChild *child; + + for (children = cols->children; + children && (child = children->data); + children = children->next) { + + if (child->widget == widget) + return child; + } + + return NULL; +} + void columns_force_left_align(Columns *cols, GtkWidget *widget) { ColumnsChild *child; - GList *children; g_return_if_fail(cols != NULL); g_return_if_fail(IS_COLUMNS(cols)); g_return_if_fail(widget != NULL); - for (children = cols->children; - children && (child = children->data); - children = children->next) { - if (child->widget != widget) - continue; + child = columns_find_child(cols, widget); + g_return_if_fail(child != NULL); - child->force_left = TRUE; - if (gtk_widget_get_visible(widget)) - gtk_widget_queue_resize(GTK_WIDGET(cols)); - break; - } + child->force_left = TRUE; + if (gtk_widget_get_visible(widget)) + gtk_widget_queue_resize(GTK_WIDGET(cols)); +} + +void columns_force_same_height(Columns *cols, GtkWidget *cw1, GtkWidget *cw2) +{ + ColumnsChild *child1, *child2; + + g_return_if_fail(cols != NULL); + g_return_if_fail(IS_COLUMNS(cols)); + g_return_if_fail(cw1 != NULL); + g_return_if_fail(cw2 != NULL); + + child1 = columns_find_child(cols, cw1); + g_return_if_fail(child1 != NULL); + child2 = columns_find_child(cols, cw2); + g_return_if_fail(child2 != NULL); + + child1->same_height_as = child2; + child2->same_height_as = child1; + if (gtk_widget_get_visible(cw1) || gtk_widget_get_visible(cw2)) + gtk_widget_queue_resize(GTK_WIDGET(cols)); } void columns_taborder_last(Columns *cols, GtkWidget *widget) @@ -549,6 +588,10 @@ static gint columns_compute_width(Columns *cols, widget_dim_fn_t get_width) const gint *percentages; static const gint onecol[] = { 100 }; +#ifdef COLUMNS_WIDTH_DIAGNOSTICS + printf("compute_width(%p): start\n", cols); +#endif + retwidth = 0; ncols = 1; @@ -572,6 +615,23 @@ static gint columns_compute_width(Columns *cols, widget_dim_fn_t get_width) childwidth = get_width(child); colspan = child->colspan ? child->colspan : ncols-child->colstart; +#ifdef COLUMNS_WIDTH_DIAGNOSTICS + printf("compute_width(%p): ", cols); + if (GTK_IS_LABEL(child->widget)) + printf("label %p '%s' wrap=%s: ", child->widget, + gtk_label_get_text(GTK_LABEL(child->widget)), + (gtk_label_get_line_wrap(GTK_LABEL(child->widget)) + ? "TRUE" : "FALSE")); + else + printf("widget %p: ", child->widget); + { + gint min, nat; + gtk_widget_get_preferred_width(child->widget, &min, &nat); + printf("minwidth=%d natwidth=%d ", min, nat); + } + printf("thiswidth=%d span=%d\n", childwidth, colspan); +#endif + /* * To compute width: we know that childwidth + cols->spacing * needs to equal a certain percentage of the full width of @@ -596,6 +656,10 @@ static gint columns_compute_width(Columns *cols, widget_dim_fn_t get_width) * before dividing by percent. */ fullwid = (thiswid * 100 + percent - 1) / percent; +#ifdef COLUMNS_WIDTH_DIAGNOSTICS + printf("compute_width(%p): after %p, thiswid=%d fullwid=%d\n", + cols, child->widget, thiswid, fullwid); +#endif /* * The above calculation assumes every widget gets @@ -610,6 +674,10 @@ static gint columns_compute_width(Columns *cols, widget_dim_fn_t get_width) retwidth += 2*gtk_container_get_border_width(GTK_CONTAINER(cols)); +#ifdef COLUMNS_WIDTH_DIAGNOSTICS + printf("compute_width(%p): done, returning %d\n", cols, retwidth); +#endif + return retwidth; } @@ -714,6 +782,11 @@ static gint columns_compute_height(Columns *cols, widget_dim_fn_t get_height) continue; childheight = get_height(child); + if (child->same_height_as) { + gint childheight2 = get_height(child->same_height_as); + if (childheight < childheight2) + childheight = childheight2; + } colspan = child->colspan ? child->colspan : ncols-child->colstart; /* @@ -754,7 +827,7 @@ static void columns_alloc_vert(Columns *cols, gint ourheight, { ColumnsChild *child; GList *children; - gint i, ncols, colspan, *colypos, childheight; + gint i, ncols, colspan, *colypos, realheight, fakeheight; ncols = 1; /* As in size_request, colypos is the lowest y reached in each column. */ @@ -781,7 +854,12 @@ static void columns_alloc_vert(Columns *cols, gint ourheight, if (!gtk_widget_get_visible(child->widget)) continue; - childheight = get_height(child); + realheight = fakeheight = get_height(child); + if (child->same_height_as) { + gint childheight2 = get_height(child->same_height_as); + if (fakeheight < childheight2) + fakeheight = childheight2; + } colspan = child->colspan ? child->colspan : ncols-child->colstart; /* @@ -799,9 +877,9 @@ static void columns_alloc_vert(Columns *cols, gint ourheight, if (topy < colypos[child->colstart+i]) topy = colypos[child->colstart+i]; } - child->y = topy; - child->h = childheight; - boty = topy + childheight + cols->spacing; + child->y = topy + fakeheight/2 - realheight/2; + child->h = realheight; + boty = topy + fakeheight + cols->spacing; for (i = 0; i < colspan; i++) { colypos[child->colstart+i] = boty; } @@ -902,14 +980,19 @@ static gint columns_gtk3_get_nat_width(ColumnsChild *child) { gint ret; - if (GTK_IS_LABEL(child->widget) && - gtk_label_get_line_wrap(GTK_LABEL(child->widget))) { + if ((GTK_IS_LABEL(child->widget) && + gtk_label_get_line_wrap(GTK_LABEL(child->widget))) || + GTK_IS_ENTRY(child->widget)) { /* * We treat wrapping GtkLabels as a special case in this * layout class, because the whole point of those is that I * _don't_ want them to take up extra horizontal space for * long text, but instead to wrap it to whatever size is used * by the rest of the layout. + * + * GtkEntry gets similar treatment, because in OS X GTK I've + * found that it requests a natural width regardless of the + * output of gtk_entry_set_width_chars. */ gtk_widget_get_preferred_width(child->widget, &ret, NULL); } else {