summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/regedit_dialog.c42
1 files changed, 32 insertions, 10 deletions
diff --git a/source3/utils/regedit_dialog.c b/source3/utils/regedit_dialog.c
index 419c4081e0..b5e41ee901 100644
--- a/source3/utils/regedit_dialog.c
+++ b/source3/utils/regedit_dialog.c
@@ -86,15 +86,40 @@ fail:
}
-struct dialog *dialog_center_new(TALLOC_CTX *ctx, const char *title, int nlines,
- int ncols, WINDOW *below)
+static void center_dialog_above_window(WINDOW *below, int *nlines, int *ncols,
+ int *y, int *x)
{
- int y, x, maxy, maxx;
+ int maxy, maxx;
+ int centery, centerx;
getmaxyx(below, maxy, maxx);
- y = maxy / 2 - nlines;
- x = maxx / 2 - ncols;
+ centery = maxy / 2;
+ centerx = maxx / 2;
+ *y = 0;
+ *x = 0;
+
+ if (*nlines > maxy) {
+ *nlines = maxy;
+ }
+ if (*ncols > maxx) {
+ *ncols = maxx;
+ }
+
+ if (*nlines < centery) {
+ *y = centery - *nlines;
+ }
+ if (*ncols < centerx) {
+ *x = centerx - *ncols;
+ }
+}
+
+struct dialog *dialog_center_new(TALLOC_CTX *ctx, const char *title, int nlines,
+ int ncols, WINDOW *below)
+{
+ int y, x;
+
+ center_dialog_above_window(below, &nlines, &ncols, &y, &x);
return dialog_new(ctx, title, nlines, ncols, y, x);
}
@@ -161,12 +186,9 @@ struct dialog *dialog_choice_center_new(TALLOC_CTX *ctx, const char *title,
const char **choices, int nlines,
int ncols, WINDOW *below)
{
- int y, x, maxy, maxx;
-
- getmaxyx(below, maxy, maxx);
+ int y, x;
- y = maxy / 2 - nlines;
- x = maxx / 2 - ncols;
+ center_dialog_above_window(below, &nlines, &ncols, &y, &x);
return dialog_choice_new(ctx, title, choices, nlines, ncols, y, x);
}