From 19a4eb1ca6e723c66d8e638efe5305fca7df0646 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 23 Oct 2011 11:08:24 +0400 Subject: [PATCH] Added D_CENTER flag to query dialog flags ...to forced place a query dialog in the center of the screen. Signed-off-by: Andrew Borodin --- lib/utilunix.c | 5 ++++- lib/widget/wtools.c | 10 +++++++--- lib/widget/wtools.h | 3 ++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/utilunix.c b/lib/utilunix.c index 3e2ce72b8..9cb720187 100644 --- a/lib/utilunix.c +++ b/lib/utilunix.c @@ -390,7 +390,7 @@ close_error_pipe (int error, const char *text) if (error_pipe[0] == -1) return 0; - if (error) + if (error < 0 || (error > 0 && (error & D_ERROR) != 0)) title = MSG_ERROR; else title = _("Warning"); @@ -398,6 +398,9 @@ close_error_pipe (int error, const char *text) { if (dup2 (old_error, 2) == -1) { + if (error < 0) + error = D_ERROR; + message (error, MSG_ERROR, _("Error dup'ing old error pipe")); return 1; } diff --git a/lib/widget/wtools.c b/lib/widget/wtools.c index dccacc3d9..1b8a47f9f 100644 --- a/lib/widget/wtools.c +++ b/lib/widget/wtools.c @@ -68,6 +68,7 @@ default_query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, switch (msg) { case DLG_RESIZE: + if ((h->flags & DLG_CENTER) == 0) { Dlg_head *prev_dlg = NULL; int ypos, xpos; @@ -99,8 +100,10 @@ default_query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, /* set position */ dlg_set_position (h, ypos, xpos, ypos + h->lines, xpos + h->cols); + + return MSG_HANDLED; } - return MSG_HANDLED; + /* fallthrough */ default: return default_dlg_callback (h, sender, msg, parm, data); @@ -314,7 +317,8 @@ query_dialog (const char *header, const char *text, int flags, int count, ...) int result = -1; int cols, lines; char *cur_name; - const int *query_colors = (flags & D_ERROR) ? alarm_colors : dialog_colors; + const int *query_colors = (flags & D_ERROR) != 0 ? alarm_colors : dialog_colors; + dlg_flags_t dlg_flags = (flags & D_CENTER) != 0 ? (DLG_CENTER | DLG_TRYUP) : DLG_NONE; if (header == MSG_ERROR) header = _("Error"); @@ -340,7 +344,7 @@ query_dialog (const char *header, const char *text, int flags, int count, ...) /* prepare dialog */ query_dlg = create_dlg (TRUE, 0, 0, lines, cols, query_colors, default_query_callback, - "[QueryBox]", header, DLG_NONE); + "[QueryBox]", header, dlg_flags); if (count > 0) { diff --git a/lib/widget/wtools.h b/lib/widget/wtools.h index 16e4755cc..d6162625f 100644 --- a/lib/widget/wtools.h +++ b/lib/widget/wtools.h @@ -19,7 +19,8 @@ enum { D_NORMAL = 0, - D_ERROR = 1 + D_ERROR = (1 << 0), + D_CENTER = (1 << 1) } /* dialog options */ ; /*** structures declarations (and typedefs of structures)*****************************************/ -- 2.11.4.GIT