mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 18:14:25 +03:00
Send new widget size as parameter of MSG_RESIZE message.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
parent
7329f53da5
commit
04f04ba130
@ -496,43 +496,13 @@ dlg_widget_set_position (gpointer data, gpointer user_data)
|
||||
else if ((c->pos_flags & WPOS_KEEP_BOTTOM) != 0)
|
||||
r.y += wss->shift_y + wss->scale_y;
|
||||
|
||||
widget_set_size_rect (c, &r);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/** Clean the dialog area, draw the frame and the title */
|
||||
void
|
||||
dlg_default_repaint (WDialog * h)
|
||||
{
|
||||
Widget *wh = WIDGET (h);
|
||||
|
||||
int space;
|
||||
|
||||
if (!widget_get_state (wh, WST_ACTIVE))
|
||||
return;
|
||||
|
||||
space = h->compact ? 0 : 1;
|
||||
|
||||
tty_setcolor (h->color[DLG_COLOR_NORMAL]);
|
||||
dlg_erase (h);
|
||||
tty_draw_box (wh->y + space, wh->x + space, wh->lines - 2 * space, wh->cols - 2 * space, FALSE);
|
||||
|
||||
if (h->title != NULL)
|
||||
{
|
||||
/* TODO: truncate long title */
|
||||
tty_setcolor (h->color[DLG_COLOR_TITLE]);
|
||||
widget_gotoyx (h, space, (wh->cols - str_term_width1 (h->title)) / 2);
|
||||
tty_print_string (h->title);
|
||||
}
|
||||
send_message (c, NULL, MSG_RESIZE, 0, &r);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** this function allows to set dialog position */
|
||||
|
||||
void
|
||||
static void
|
||||
dlg_set_position (WDialog * h, const WRect * r)
|
||||
{
|
||||
WGroup *g = GROUP (h);
|
||||
@ -568,13 +538,55 @@ dlg_set_position (WDialog * h, const WRect * r)
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/** Set dialog size and position */
|
||||
|
||||
void
|
||||
dlg_set_size (WDialog * h, int lines, int cols)
|
||||
static void
|
||||
dlg_default_resize (WDialog * h, WRect * r)
|
||||
{
|
||||
WRect r = { 0, 0, lines, cols };
|
||||
/* This is default resizing mechanism.
|
||||
* The main idea of this code is to resize dialog according to flags
|
||||
* (if any of flags require automatic resizing, like WPOS_CENTER,
|
||||
* end after that reposition controls in dialog according to flags of widget)
|
||||
*/
|
||||
|
||||
widget_adjust_position (WIDGET (h)->pos_flags, &r.y, &r.x, &r.lines, &r.cols);
|
||||
dlg_set_position (h, &r);
|
||||
Widget *w = WIDGET (h);
|
||||
WRect r0;
|
||||
|
||||
if (r == NULL)
|
||||
rect_init (&r0, w->y, w->x, w->lines, w->cols);
|
||||
else
|
||||
r0 = *r;
|
||||
|
||||
widget_adjust_position (w->pos_flags, &r0.y, &r0.x, &r0.lines, &r0.cols);
|
||||
dlg_set_position (h, &r0);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** public functions ****************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
/** Clean the dialog area, draw the frame and the title */
|
||||
void
|
||||
dlg_default_repaint (WDialog * h)
|
||||
{
|
||||
Widget *wh = WIDGET (h);
|
||||
|
||||
int space;
|
||||
|
||||
if (!widget_get_state (wh, WST_ACTIVE))
|
||||
return;
|
||||
|
||||
space = h->compact ? 0 : 1;
|
||||
|
||||
tty_setcolor (h->color[DLG_COLOR_NORMAL]);
|
||||
dlg_erase (h);
|
||||
tty_draw_box (wh->y + space, wh->x + space, wh->lines - 2 * space, wh->cols - 2 * space, FALSE);
|
||||
|
||||
if (h->title != NULL)
|
||||
{
|
||||
/* TODO: truncate long title */
|
||||
tty_setcolor (h->color[DLG_COLOR_TITLE]);
|
||||
widget_gotoyx (h, space, (wh->cols - str_term_width1 (h->title)) / 2);
|
||||
tty_print_string (h->title);
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
@ -605,12 +617,7 @@ dlg_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, v
|
||||
return MSG_HANDLED;
|
||||
|
||||
case MSG_RESIZE:
|
||||
/* this is default resizing mechanism */
|
||||
/* the main idea of this code is to resize dialog
|
||||
according to flags (if any of flags require automatic
|
||||
resizing, like WPOS_CENTER, end after that reposition
|
||||
controls in dialog according to flags of widget) */
|
||||
dlg_set_size (h, w->lines, w->cols);
|
||||
dlg_default_resize (h, RECT (data));
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
|
@ -109,11 +109,6 @@ WDialog *dlg_create (gboolean modal, int y1, int x1, int lines, int cols,
|
||||
|
||||
void dlg_set_default_colors (void);
|
||||
|
||||
/* sets size of dialog, leaving positioning to automatic mehtods
|
||||
according to dialog flags */
|
||||
void dlg_set_size (WDialog * h, int lines, int cols);
|
||||
void dlg_set_position (WDialog * h, const WRect * r);
|
||||
|
||||
void dlg_init (WDialog * h);
|
||||
int dlg_run (WDialog * d);
|
||||
void dlg_destroy (WDialog * h);
|
||||
|
@ -104,9 +104,8 @@ history_dlg_reposition (WDialog * dlg_head)
|
||||
}
|
||||
|
||||
rect_init (&r, y, x, he, wi);
|
||||
dlg_set_position (dlg_head, &r);
|
||||
|
||||
return MSG_HANDLED;
|
||||
return dlg_default_callback (WIDGET (dlg_head), NULL, MSG_RESIZE, 0, &r);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -51,7 +51,32 @@
|
||||
|
||||
/*** file scope variables ************************************************************************/
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/*** file scope functions ************************************************************************/
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
hline_adjust_cols (WHLine * l)
|
||||
{
|
||||
if (l->auto_adjust_cols)
|
||||
{
|
||||
Widget *w = WIDGET (l);
|
||||
Widget *wo = WIDGET (w->owner);
|
||||
|
||||
if (DIALOG (wo)->compact)
|
||||
{
|
||||
w->x = wo->x;
|
||||
w->cols = wo->cols;
|
||||
}
|
||||
else
|
||||
{
|
||||
w->x = wo->x + 1;
|
||||
w->cols = wo->cols - 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
hline_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
@ -62,22 +87,12 @@ hline_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
|
||||
switch (msg)
|
||||
{
|
||||
case MSG_INIT:
|
||||
case MSG_RESIZE:
|
||||
if (l->auto_adjust_cols)
|
||||
{
|
||||
Widget *wo = WIDGET (h);
|
||||
hline_adjust_cols (l);
|
||||
return MSG_HANDLED;
|
||||
|
||||
if (h->compact)
|
||||
{
|
||||
w->x = wo->x;
|
||||
w->cols = wo->cols;
|
||||
}
|
||||
else
|
||||
{
|
||||
w->x = wo->x + 1;
|
||||
w->cols = wo->cols - 2;
|
||||
}
|
||||
}
|
||||
case MSG_RESIZE:
|
||||
hline_adjust_cols (l);
|
||||
w->y = RECT (data)->y;
|
||||
return MSG_HANDLED;
|
||||
|
||||
case MSG_DRAW:
|
||||
|
@ -492,9 +492,6 @@ listbox_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
|
||||
listbox_destroy (l);
|
||||
return MSG_HANDLED;
|
||||
|
||||
case MSG_RESIZE:
|
||||
return MSG_HANDLED;
|
||||
|
||||
default:
|
||||
return widget_default_callback (w, sender, msg, parm, data);
|
||||
}
|
||||
|
@ -670,6 +670,7 @@ menubar_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
|
||||
|
||||
case MSG_RESIZE:
|
||||
/* try show menu after screen resize */
|
||||
widget_default_callback (w, NULL, MSG_RESIZE, 0, data);
|
||||
menubar_refresh (menubar);
|
||||
return MSG_HANDLED;
|
||||
|
||||
|
@ -79,6 +79,22 @@ widget_set_id (void)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
widget_default_resize (Widget * w, const WRect * r)
|
||||
{
|
||||
if (r == NULL)
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
w->y = r->y;
|
||||
w->x = r->x;
|
||||
w->lines = r->lines;
|
||||
w->cols = r->cols;
|
||||
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
widget_do_focus (Widget * w, gboolean enable)
|
||||
{
|
||||
@ -311,10 +327,8 @@ widget_destroy (Widget * w)
|
||||
cb_ret_t
|
||||
widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
(void) w;
|
||||
(void) sender;
|
||||
(void) parm;
|
||||
(void) data;
|
||||
|
||||
switch (msg)
|
||||
{
|
||||
@ -329,6 +343,9 @@ widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm
|
||||
case MSG_IDLE:
|
||||
return MSG_HANDLED;
|
||||
|
||||
case MSG_RESIZE:
|
||||
return widget_default_resize (w, CONST_RECT (data));
|
||||
|
||||
default:
|
||||
return MSG_NOT_HANDLED;
|
||||
}
|
||||
@ -450,17 +467,25 @@ widget_adjust_position (widget_pos_flags_t pos_flags, int *y, int *x, int *lines
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
/**
|
||||
* Change widget position and size.
|
||||
*
|
||||
* @param w widget
|
||||
* @param y y coordinate of top-left corner
|
||||
* @param x x coordinate of top-left corner
|
||||
* @param lines width
|
||||
* @param cols height
|
||||
*/
|
||||
|
||||
void
|
||||
widget_set_size (Widget * widget, int y, int x, int lines, int cols)
|
||||
widget_set_size (Widget * w, int y, int x, int lines, int cols)
|
||||
{
|
||||
widget->x = x;
|
||||
widget->y = y;
|
||||
widget->cols = cols;
|
||||
widget->lines = lines;
|
||||
send_message (widget, NULL, MSG_RESIZE, 0, NULL);
|
||||
if (widget->owner != NULL && widget_get_state (WIDGET (widget->owner), WST_ACTIVE))
|
||||
send_message (widget, NULL, MSG_DRAW, 0, NULL);
|
||||
WRect r = { y, x, lines, cols };
|
||||
|
||||
send_message (w, NULL, MSG_RESIZE, 0, &r);
|
||||
|
||||
if (w->owner != NULL && widget_get_state (WIDGET (w->owner), WST_ACTIVE))
|
||||
send_message (w, NULL, MSG_DRAW, 0, NULL);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
@ -190,7 +190,7 @@ cb_ret_t widget_default_callback (Widget * w, Widget * sender, widget_msg_t msg,
|
||||
void widget_set_options (Widget * w, widget_options_t options, gboolean enable);
|
||||
cb_ret_t widget_set_state (Widget * w, widget_state_t state, gboolean enable);
|
||||
void widget_adjust_position (widget_pos_flags_t pos_flags, int *y, int *x, int *lines, int *cols);
|
||||
void widget_set_size (Widget * widget, int y, int x, int lines, int cols);
|
||||
void widget_set_size (Widget * w, int y, int x, int lines, int cols);
|
||||
/* select color for widget in dependance of state */
|
||||
void widget_selectcolor (Widget * w, gboolean focused, gboolean hotkey);
|
||||
void widget_draw (Widget * w);
|
||||
|
@ -103,9 +103,8 @@ query_default_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
|
||||
|
||||
/* set position */
|
||||
rect_init (&r, ypos, xpos, w->lines, w->cols);
|
||||
dlg_set_position (h, &r);
|
||||
|
||||
return MSG_HANDLED;
|
||||
return dlg_default_callback (w, NULL, MSG_RESIZE, 0, &r);
|
||||
}
|
||||
MC_FALLTHROUGH;
|
||||
|
||||
|
@ -3336,6 +3336,7 @@ dview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
|
||||
return i;
|
||||
|
||||
case MSG_RESIZE:
|
||||
widget_default_callback (w, NULL, MSG_RESIZE, 0, data);
|
||||
dview_compute_areas (dview);
|
||||
return MSG_HANDLED;
|
||||
|
||||
|
@ -197,9 +197,8 @@ skin_dlg_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
|
||||
y = wd->y + (wd->lines - w->lines) / 2;
|
||||
x = wd->x + wd->cols / 2;
|
||||
rect_init (&r, y, x, w->lines, w->cols);
|
||||
dlg_set_position (d, &r);
|
||||
|
||||
return MSG_HANDLED;
|
||||
return dlg_default_callback (w, NULL, MSG_RESIZE, 0, &r);
|
||||
}
|
||||
|
||||
default:
|
||||
@ -373,10 +372,12 @@ tree_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *da
|
||||
{
|
||||
case MSG_RESIZE:
|
||||
{
|
||||
WRect r;
|
||||
Widget *bar;
|
||||
|
||||
/* simply call dlg_set_size() with new size */
|
||||
dlg_set_size (h, LINES - 9, COLS - 20);
|
||||
rect_init (&r, w->y, w->x, LINES - 9, COLS - 20);
|
||||
dlg_default_callback (w, NULL, MSG_RESIZE, 0, &r);
|
||||
|
||||
bar = WIDGET (find_buttonbar (h));
|
||||
bar->x = 0;
|
||||
bar->y = LINES - 1;
|
||||
|
@ -3153,9 +3153,10 @@ dirsize_status_update_cb (status_msg_t * sm)
|
||||
/* enlarge dialog if required */
|
||||
if (WIDGET (dsm->count_size)->cols + 6 > wd->cols)
|
||||
{
|
||||
dlg_set_size (sm->dlg, wd->lines, WIDGET (dsm->count_size)->cols + 6);
|
||||
widget_set_size (wd, wd->y, wd->x, wd->lines, WIDGET (dsm->count_size)->cols + 6);
|
||||
dirsize_status_locate_buttons (dsm);
|
||||
dlg_draw (sm->dlg);
|
||||
/* TODO: ret rid of double redraw */
|
||||
}
|
||||
|
||||
/* adjust first label */
|
||||
|
@ -799,6 +799,7 @@ file_op_context_create_ui (file_op_context_t * ctx, gboolean with_eta,
|
||||
filegui_dialog_type_t dialog_type)
|
||||
{
|
||||
file_op_context_ui_t *ui;
|
||||
Widget *w;
|
||||
WGroup *g;
|
||||
int buttons_width;
|
||||
int dlg_width = 58, dlg_height = 17;
|
||||
@ -827,6 +828,7 @@ file_op_context_create_ui (file_op_context_t * ctx, gboolean with_eta,
|
||||
ui->op_dlg =
|
||||
dlg_create (TRUE, 0, 0, dlg_height, dlg_width, WPOS_CENTER, FALSE, dialog_colors, NULL,
|
||||
NULL, NULL, op_names[ctx->operation]);
|
||||
w = WIDGET (ui->op_dlg);
|
||||
g = GROUP (ui->op_dlg);
|
||||
|
||||
if (dialog_type != FILEGUI_DIALOG_DELETE_ITEM)
|
||||
@ -926,7 +928,7 @@ file_op_context_create_ui (file_op_context_t * ctx, gboolean with_eta,
|
||||
progress_buttons[3].len;
|
||||
|
||||
/* adjust dialog sizes */
|
||||
dlg_set_size (ui->op_dlg, y + 3, MAX (COLS * 2 / 3, buttons_width + 6));
|
||||
widget_set_size (w, w->y, w->x, y + 3, MAX (COLS * 2 / 3, buttons_width + 6));
|
||||
|
||||
place_progress_buttons (ui->op_dlg, FALSE);
|
||||
|
||||
|
@ -1544,6 +1544,22 @@ find_relocate_buttons (const WDialog * h, gboolean all_buttons)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
find_resize (WDialog * h)
|
||||
{
|
||||
Widget *w = WIDGET (h);
|
||||
WRect r;
|
||||
|
||||
rect_init (&r, w->y, w->x, LINES - 4, COLS - 16);
|
||||
dlg_default_callback (w, NULL, MSG_RESIZE, 0, &r);
|
||||
find_adjust_header (h);
|
||||
find_relocate_buttons (h, TRUE);
|
||||
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
find_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -1568,10 +1584,7 @@ find_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *da
|
||||
return MSG_NOT_HANDLED;
|
||||
|
||||
case MSG_RESIZE:
|
||||
dlg_set_size (h, LINES - 4, COLS - 16);
|
||||
find_adjust_header (h);
|
||||
find_relocate_buttons (h, TRUE);
|
||||
return MSG_HANDLED;
|
||||
return find_resize (h);
|
||||
|
||||
case MSG_IDLE:
|
||||
do_search (h);
|
||||
|
@ -607,9 +607,13 @@ hotlist_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void
|
||||
return MSG_HANDLED;
|
||||
|
||||
case MSG_RESIZE:
|
||||
/* simply call dlg_set_size() with new size */
|
||||
dlg_set_size (h, LINES - (h == hotlist_dlg ? 2 : 6), COLS - 6);
|
||||
return MSG_HANDLED;
|
||||
{
|
||||
WRect r;
|
||||
|
||||
rect_init (&r, w->y, w->x, LINES - (h == hotlist_dlg ? 2 : 6), COLS - 6);
|
||||
|
||||
return dlg_default_callback (w, NULL, MSG_RESIZE, 0, &r);
|
||||
}
|
||||
|
||||
default:
|
||||
return dlg_default_callback (w, sender, msg, parm, data);
|
||||
|
29
src/help.c
29
src/help.c
@ -860,6 +860,24 @@ help_handle_key (WDialog * h, int c)
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
help_resize (WDialog * h)
|
||||
{
|
||||
Widget *w = WIDGET (h);
|
||||
WButtonBar *bb;
|
||||
WRect r;
|
||||
|
||||
help_lines = MIN (LINES - 4, MAX (2 * LINES / 3, 18));
|
||||
rect_init (&r, w->y, w->x, help_lines + 4, HELP_WINDOW_WIDTH + 4);
|
||||
dlg_default_callback (w, NULL, MSG_RESIZE, 0, &r);
|
||||
bb = find_buttonbar (h);
|
||||
widget_set_size (WIDGET (bb), LINES - 1, 0, 1, COLS);
|
||||
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------------------------- */
|
||||
|
||||
static cb_ret_t
|
||||
help_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
|
||||
{
|
||||
@ -868,15 +886,7 @@ help_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *da
|
||||
switch (msg)
|
||||
{
|
||||
case MSG_RESIZE:
|
||||
{
|
||||
WButtonBar *bb;
|
||||
|
||||
help_lines = MIN (LINES - 4, MAX (2 * LINES / 3, 18));
|
||||
dlg_set_size (h, help_lines + 4, HELP_WINDOW_WIDTH + 4);
|
||||
bb = find_buttonbar (h);
|
||||
widget_set_size (WIDGET (bb), LINES - 1, 0, 1, COLS);
|
||||
return MSG_HANDLED;
|
||||
}
|
||||
return help_resize (h);
|
||||
|
||||
case MSG_DRAW:
|
||||
dlg_default_repaint (h);
|
||||
@ -942,6 +952,7 @@ md_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data
|
||||
switch (msg)
|
||||
{
|
||||
case MSG_RESIZE:
|
||||
widget_default_callback (w, NULL, MSG_RESIZE, 0, data);
|
||||
w->lines = help_lines;
|
||||
return MSG_HANDLED;
|
||||
|
||||
|
@ -725,6 +725,7 @@ mcview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *
|
||||
return MSG_HANDLED;
|
||||
|
||||
case MSG_RESIZE:
|
||||
widget_default_callback (w, NULL, MSG_RESIZE, 0, data);
|
||||
mcview_resize (view);
|
||||
return MSG_HANDLED;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user