diff --git a/lib/widget/dialog.c b/lib/widget/dialog.c index 0651b8da8..2fb95464a 100644 --- a/lib/widget/dialog.c +++ b/lib/widget/dialog.c @@ -683,24 +683,28 @@ dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2) int cols = c->cols; int lines = c->lines; - if ((c->pos_flags & WPOS_KEEP_LEFT) && (c->pos_flags & WPOS_KEEP_RIGHT)) + if ((c->pos_flags & WPOS_CENTER_HORZ) != 0) + x = wh->x + (wh->cols - c->cols) / 2; + else if ((c->pos_flags & WPOS_KEEP_LEFT) != 0 && (c->pos_flags & WPOS_KEEP_RIGHT) != 0) { x += shift_x; cols += scale_x; } - else if (c->pos_flags & WPOS_KEEP_LEFT) + else if ((c->pos_flags & WPOS_KEEP_LEFT) != 0) x += shift_x; - else if (c->pos_flags & WPOS_KEEP_RIGHT) + else if ((c->pos_flags & WPOS_KEEP_RIGHT) != 0) x += shift_x + scale_x; - if ((c->pos_flags & WPOS_KEEP_TOP) && (c->pos_flags & WPOS_KEEP_BOTTOM)) + if ((c->pos_flags & WPOS_CENTER_VERT) != 0) + y = wh->y + (wh->lines - c->lines) / 2; + else if ((c->pos_flags & WPOS_KEEP_TOP) != 0 && (c->pos_flags & WPOS_KEEP_BOTTOM) != 0) { y += shift_y; lines += scale_y; } - else if (c->pos_flags & WPOS_KEEP_TOP) + else if ((c->pos_flags & WPOS_KEEP_TOP) != 0) y += shift_y; - else if (c->pos_flags & WPOS_KEEP_BOTTOM) + else if ((c->pos_flags & WPOS_KEEP_BOTTOM) != 0) y += shift_y + scale_y; widget_set_size (c, y, x, lines, cols); @@ -865,14 +869,21 @@ set_idle_proc (Dlg_head * d, int enable) unsigned long add_widget_autopos (Dlg_head * h, void *w, widget_pos_flags_t pos_flags, const void *before) { + Widget *wh = WIDGET (h); Widget *widget = WIDGET (w); /* Don't accept 0 widgets */ if (w == NULL) abort (); - widget->x += WIDGET (h)->x; - widget->y += WIDGET (h)->y; + if ((pos_flags & WPOS_CENTER_HORZ) != 0) + widget->x = (wh->cols - widget->cols) / 2; + widget->x += wh->x; + + if ((pos_flags & WPOS_CENTER_VERT) != 0) + widget->y = (wh->lines - widget->lines) / 2; + widget->y += wh->y; + widget->owner = h; widget->pos_flags = pos_flags; widget->id = h->widget_id++; @@ -941,7 +952,7 @@ add_widget_autopos (Dlg_head * h, void *w, widget_pos_flags_t pos_flags, const v unsigned long add_widget (Dlg_head * h, void *w) { - return add_widget_autopos (h, w, WPOS_KEEP_LEFT | WPOS_KEEP_TOP, + return add_widget_autopos (h, w, WPOS_KEEP_DEFAULT, h->current != NULL ? h->current->data : NULL); } @@ -950,7 +961,7 @@ add_widget (Dlg_head * h, void *w) unsigned long add_widget_before (Dlg_head * h, void *w, void *before) { - return add_widget_autopos (h, w, WPOS_KEEP_LEFT | WPOS_KEEP_TOP, before); + return add_widget_autopos (h, w, WPOS_KEEP_DEFAULT, before); } /* --------------------------------------------------------------------------------------------- */ diff --git a/lib/widget/widget-common.h b/lib/widget/widget-common.h index 8f55eba83..8b276adf8 100644 --- a/lib/widget/widget-common.h +++ b/lib/widget/widget-common.h @@ -63,14 +63,22 @@ typedef enum /* Flags for widget repositioning on dialog resize */ typedef enum { - WPOS_KEEP_LEFT = (1 << 0), /* keep widget distance to left border of dialog */ - WPOS_KEEP_RIGHT = (1 << 1), /* keep widget distance to right border of dialog */ - WPOS_KEEP_TOP = (1 << 2), /* keep widget distance to top border of dialog */ - WPOS_KEEP_BOTTOM = (1 << 3), /* keep widget distance to bottom border of dialog */ + WPOS_CENTER_HORZ = (1 << 0), /* center widget in horizontal */ + WPOS_CENTER_VERT = (1 << 1), /* center widget in vertical */ + WPOS_KEEP_LEFT = (1 << 2), /* keep widget distance to left border of dialog */ + WPOS_KEEP_RIGHT = (1 << 3), /* keep widget distance to right border of dialog */ + WPOS_KEEP_TOP = (1 << 4), /* keep widget distance to top border of dialog */ + WPOS_KEEP_BOTTOM = (1 << 5), /* keep widget distance to bottom border of dialog */ WPOS_KEEP_HORZ = WPOS_KEEP_LEFT | WPOS_KEEP_RIGHT, WPOS_KEEP_VERT = WPOS_KEEP_TOP | WPOS_KEEP_BOTTOM, - WPOS_KEEP_ALL = WPOS_KEEP_HORZ | WPOS_KEEP_VERT + WPOS_KEEP_ALL = WPOS_KEEP_HORZ | WPOS_KEEP_VERT, + WPOS_KEEP_DEFAULT = WPOS_KEEP_LEFT | WPOS_KEEP_TOP } widget_pos_flags_t; +/* NOTE: if WPOS_CENTER_HORZ flag is used, other horizontal flags (WPOS_KEEP_LEFT, WPOS_KEEP_RIGHT, + * and WPOS_KEEP_HORZ are ignored). + * If WPOS_CENTER_VERT flag is used, other horizontal flags (WPOS_KEEP_TOP, WPOS_KEEP_BOTTOM, + * and WPOS_KEEP_VERT are ignored). + */ /*** structures declarations (and typedefs of structures)*****************************************/