Ticket #2919: widget system improvements and unifications.

First step: derive dialog from widget.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2012-06-20 12:05:13 +04:00
parent f45f155a12
commit 2a95cb2ffd
23 changed files with 201 additions and 172 deletions

View File

@ -359,6 +359,8 @@ dlg_handle_key (Dlg_head * h, int d_key)
static int
dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
{
Widget *wh = WIDGET (h);
GList *item;
GList *starting_widget = h->current;
int x = event->x;
@ -366,18 +368,18 @@ dlg_mouse_event (Dlg_head * h, Gpm_Event * event)
/* close the dialog by mouse click out of dialog area */
if (mouse_close_dialog && !h->fullscreen && ((event->buttons & GPM_B_LEFT) != 0) && ((event->type & GPM_DOWN) != 0) /* left click */
&& !((x > h->x) && (x <= h->x + h->cols) && (y > h->y) && (y <= h->y + h->lines)))
&& !((x > wh->x) && (x <= wh->x + wh->cols) && (y > wh->y) && (y <= wh->y + wh->lines)))
{
h->ret_value = B_CANCEL;
dlg_stop (h);
return MOU_NORMAL;
}
if (h->mouse != NULL)
if (wh->mouse != NULL)
{
int mou;
mou = h->mouse (event, h);
mou = wh->mouse (event, wh);
if (mou != MOU_UNHANDLED)
return mou;
}
@ -590,9 +592,11 @@ dlg_find_widget_by_id (gconstpointer a, gconstpointer b)
/** draw box in window */
void
draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single)
draw_box (const Dlg_head * h, int y, int x, int ys, int xs, gboolean single)
{
tty_draw_box (h->y + y, h->x + x, ys, xs, single);
const Widget *wh = WIDGET (h);
tty_draw_box (wh->y + y, wh->x + x, ys, xs, single);
}
/* --------------------------------------------------------------------------------------------- */
@ -601,6 +605,8 @@ draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single)
void
common_dialog_repaint (Dlg_head * h)
{
Widget *wh = WIDGET (h);
int space;
if (h->state != DLG_ACTIVE)
@ -610,12 +616,12 @@ common_dialog_repaint (Dlg_head * h)
tty_setcolor (h->color[DLG_COLOR_NORMAL]);
dlg_erase (h);
draw_box (h, space, space, h->lines - 2 * space, h->cols - 2 * space, FALSE);
draw_box (h, space, space, wh->lines - 2 * space, wh->cols - 2 * space, FALSE);
if (h->title != NULL)
{
tty_setcolor (h->color[DLG_COLOR_TITLE]);
dlg_move (h, space, (h->cols - str_term_width1 (h->title)) / 2);
widget_move (h, space, (wh->cols - str_term_width1 (h->title)) / 2);
tty_print_string (h->title);
}
}
@ -626,20 +632,22 @@ common_dialog_repaint (Dlg_head * h)
void
dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2)
{
Widget *wh = WIDGET (h);
/* save old positions, will be used to reposition childs */
int ox, oy, oc, ol;
int shift_x, shift_y, scale_x, scale_y;
/* save old positions, will be used to reposition childs */
ox = h->x;
oy = h->y;
oc = h->cols;
ol = h->lines;
ox = wh->x;
oy = wh->y;
oc = wh->cols;
ol = wh->lines;
h->x = x1;
h->y = y1;
h->lines = y2 - y1;
h->cols = x2 - x1;
wh->x = x1;
wh->y = y1;
wh->lines = y2 - y1;
wh->cols = x2 - x1;
/* dialog is empty */
if (h->widgets == NULL)
@ -649,10 +657,10 @@ dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2)
h->current = h->widgets;
/* values by which controls should be moved */
shift_x = h->x - ox;
shift_y = h->y - oy;
scale_x = h->cols - oc;
scale_y = h->lines - ol;
shift_x = wh->x - ox;
shift_y = wh->y - oy;
scale_x = wh->cols - oc;
scale_y = wh->lines - ol;
if ((shift_x != 0) || (shift_y != 0) || (scale_x != 0) || (scale_y != 0))
{
@ -706,8 +714,8 @@ dlg_set_position (Dlg_head * h, int y1, int x1, int y2, int x2)
void
dlg_set_size (Dlg_head * h, int lines, int cols)
{
int x = h->x;
int y = h->y;
int x = WIDGET (h)->x;
int y = WIDGET (h)->y;
if (h->flags & DLG_CENTER)
{
@ -751,7 +759,7 @@ default_dlg_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, vo
according to flags (if any of flags require automatic
resizing, like DLG_CENTER, end after that reposition
controls in dialog according to flags of widget) */
dlg_set_size (h, h->lines, h->cols);
dlg_set_size (h, WIDGET (h)->lines, WIDGET (h)->cols);
return MSG_HANDLED;
default:
@ -769,23 +777,24 @@ create_dlg (gboolean modal, int y1, int x1, int lines, int cols,
const char *help_ctx, const char *title, dlg_flags_t flags)
{
Dlg_head *new_d;
Widget *w;
new_d = g_new0 (Dlg_head, 1);
w = WIDGET (new_d);
init_widget (w, y1, x1, lines, cols, NULL, mouse_handler);
widget_want_cursor (*w, FALSE);
new_d->state = DLG_CONSTRUCT;
new_d->modal = modal;
if (colors != NULL)
memmove (new_d->color, colors, sizeof (dlg_colors_t));
new_d->help_ctx = help_ctx;
new_d->callback = (callback != NULL) ? callback : default_dlg_callback;
new_d->mouse = mouse_handler;
new_d->x = x1;
new_d->y = y1;
new_d->flags = flags;
new_d->data = NULL;
dlg_set_size (new_d, lines, cols);
new_d->fullscreen = (new_d->x == 0 && new_d->y == 0
&& new_d->cols == COLS && new_d->lines == LINES);
new_d->fullscreen = (w->x == 0 && w->y == 0 && w->cols == COLS && w->lines == LINES);
new_d->mouse_status = MOU_UNHANDLED;
@ -830,7 +839,11 @@ void
dlg_erase (Dlg_head * h)
{
if ((h != NULL) && (h->state == DLG_ACTIVE))
tty_fill_region (h->y, h->x, h->lines, h->cols, ' ');
{
Widget *wh = WIDGET (h);
tty_fill_region (wh->y, wh->x, wh->lines, wh->cols, ' ');
}
}
/* --------------------------------------------------------------------------------------------- */
@ -858,8 +871,8 @@ add_widget_autopos (Dlg_head * h, void *w, widget_pos_flags_t pos_flags, const v
if (w == NULL)
abort ();
widget->x += h->x;
widget->y += h->y;
widget->x += WIDGET (h)->x;
widget->y += WIDGET (h)->y;
widget->owner = h;
widget->pos_flags = pos_flags;
widget->id = h->widget_id++;

View File

@ -25,8 +25,6 @@
#define B_HELP 3
#define B_USER 100
#define dlg_move(h, _y, _x) tty_gotoyx (((Dlg_head *)(h))->y + (_y), ((Dlg_head *)(h))->x + (_x))
/*** enums ***************************************************************************************/
/* Dialog messages */
@ -101,6 +99,8 @@ typedef cb_ret_t (*menu_exec_fn) (int command);
struct Dlg_head
{
Widget widget;
/* Set by the user */
gboolean modal; /* type of dialog: modal or not */
dlg_flags_t flags; /* User flags */
@ -111,10 +111,6 @@ struct Dlg_head
/* Set and received by the user */
int ret_value; /* Result of run_dlg() */
/* Geometry */
int x, y; /* Position relative to screen origin */
int cols, lines; /* Width and height of the window */
/* Internal flags */
dlg_state_t state;
gboolean fullscreen; /* Parents dialogs don't need refresh */
@ -129,7 +125,6 @@ struct Dlg_head
char *event_group; /* Name of event group for this dialog */
dlg_cb_fn callback;
mouse_h mouse;
dlg_shortcut_str get_shortcut; /* Shortcut string */
dlg_title_str get_title; /* useless for modal dialogs */
};
@ -153,7 +148,7 @@ extern const global_keymap_t *dialog_map;
/*** declarations of public functions ************************************************************/
/* draw box in window */
void draw_box (Dlg_head * h, int y, int x, int ys, int xs, gboolean single);
void draw_box (const Dlg_head * h, int y, int x, int ys, int xs, gboolean single);
/* Creates a dialog head */
Dlg_head *create_dlg (gboolean modal, int y1, int x1, int lines, int cols,

View File

@ -67,16 +67,16 @@ groupbox_callback (Widget * w, widget_msg_t msg, int parm)
case WIDGET_DRAW:
{
Widget *wo = WIDGET (w->owner);
gboolean disabled = (w->options & W_DISABLED) != 0;
tty_setcolor (disabled ? DISABLED_COLOR : COLOR_NORMAL);
draw_box (g->widget.owner, g->widget.y - g->widget.owner->y,
g->widget.x - g->widget.owner->x, g->widget.lines, g->widget.cols, TRUE);
draw_box (w->owner, w->y - wo->y, w->x - wo->x, w->lines, w->cols, TRUE);
if (g->title != NULL)
{
tty_setcolor (disabled ? DISABLED_COLOR : COLOR_TITLE);
dlg_move (g->widget.owner, g->widget.y - g->widget.owner->y,
g->widget.x - g->widget.owner->x + 1);
widget_move (w->owner, w->y - wo->y, w->x - wo->x + 1);
tty_print_string (g->title);
}
return MSG_HANDLED;

View File

@ -338,7 +338,7 @@ history_show (GList ** history, Widget * widget, int current)
size. */
history_dlg_callback (query_dlg, NULL, DLG_RESIZE, 0, NULL);
if (query_dlg->y < widget->y)
if (WIDGET (query_dlg)->y < widget->y)
{
/* draw list entries from bottom upto top */
listbox_set_list (query_list, hlist);
@ -378,7 +378,7 @@ history_show (GList ** history, Widget * widget, int current)
}
/* restore history direction */
if (query_dlg->y < widget->y)
if (WIDGET (query_dlg)->y < widget->y)
z = g_list_reverse (z);
destroy_dlg (query_dlg);

View File

@ -65,15 +65,17 @@ hline_callback (Widget * w, widget_msg_t msg, int parm)
case WIDGET_RESIZED:
if (l->auto_adjust_cols)
{
Widget *wo = WIDGET (w->owner);
if (((w->owner->flags & DLG_COMPACT) != 0))
{
w->x = w->owner->x;
w->cols = w->owner->cols;
w->x = wo->x;
w->cols = wo->cols;
}
else
{
w->x = w->owner->x + 1;
w->cols = w->owner->cols - 2;
w->x = wo->x + 1;
w->cols = wo->cols - 2;
}
}

View File

@ -10,7 +10,9 @@
/*** typedefs(not structures) and defined constants **********************************************/
#define widget_move(w, _y, _x) tty_gotoyx (((Widget *)(w))->y + (_y), ((Widget *)(w))->x + (_x))
#define WIDGET(x) ((Widget *)(x))
#define widget_move(w, _y, _x) tty_gotoyx (WIDGET(w)->y + (_y), WIDGET(w)->x + (_x))
/* Sets/clear the specified flag in the options field */
#define widget_option(w,f,i) \
w.options = ((i) ? ((w).options | (f)) : ((w).options & (~(f))))

View File

@ -70,6 +70,7 @@ default_query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm,
case DLG_RESIZE:
if ((h->flags & DLG_CENTER) == 0)
{
Widget *wh = WIDGET (h);
Dlg_head *prev_dlg = NULL;
int ypos, xpos;
@ -92,14 +93,14 @@ default_query_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm,
/* if previous dialog is not fullscreen'd -- overlap it */
if (prev_dlg == NULL || prev_dlg->fullscreen)
ypos = LINES / 3 - (h->lines - 3) / 2;
ypos = LINES / 3 - (wh->lines - 3) / 2;
else
ypos = prev_dlg->y + 2;
ypos = WIDGET (prev_dlg)->y + 2;
xpos = COLS / 2 - h->cols / 2;
xpos = COLS / 2 - wh->cols / 2;
/* set position */
dlg_set_position (h, ypos, xpos, ypos + h->lines, xpos + h->cols);
dlg_set_position (h, ypos, xpos, ypos + wh->lines, xpos + wh->cols);
return MSG_HANDLED;
}

View File

@ -514,7 +514,9 @@ edit_save_cmd (WEdit * edit)
static inline gboolean
edit_load_file_from_filename (Dlg_head * h, const vfs_path_t * vpath)
{
return edit_add_window (h, h->y + 1, h->x, h->lines - 2, h->cols, vpath, 0);
Widget *w = WIDGET (h);
return edit_add_window (h, w->y + 1, w->x, w->lines - 2, w->cols, vpath, 0);
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -193,7 +193,8 @@ status_string (WEdit * edit, char *s, int w)
static inline void
edit_status_fullscreen (WEdit * edit, int color)
{
const int w = edit->widget.owner->cols;
Widget *h = WIDGET (WIDGET (edit)->owner);
const int w = h->cols;
const size_t status_size = w + 1;
char *const status = g_malloc (status_size);
int status_len;
@ -222,7 +223,7 @@ edit_status_fullscreen (WEdit * edit, int color)
fname = str_trunc (fname, fname_len);
}
dlg_move (edit->widget.owner, 0, 0);
widget_move (h, 0, 0);
tty_setcolor (color);
printwstr (fname, fname_len + gap);
printwstr (status, w - (fname_len + gap));
@ -233,7 +234,7 @@ edit_status_fullscreen (WEdit * edit, int color)
if (edit->total_lines + 1 != 0)
percent = (edit->curs_line + 1) * 100 / (edit->total_lines + 1);
dlg_move (edit->widget.owner, 0, w - 6 - 6);
widget_move (h, 0, w - 6 - 6);
tty_printf (" %3d%%", percent);
}
@ -250,8 +251,9 @@ edit_status_fullscreen (WEdit * edit, int color)
static inline void
edit_status_window (WEdit * edit)
{
Widget *w = WIDGET (edit);
int y, x;
int cols = edit->widget.cols;
int cols = w->cols;
tty_setcolor (STATUSBAR_COLOR);
@ -271,12 +273,12 @@ edit_status_window (WEdit * edit)
#endif
edit_move (2, 0);
tty_printf ("[%s]", str_term_trim (fname, edit->widget.cols - 8 - 6));
tty_printf ("[%s]", str_term_trim (fname, w->cols - 8 - 6));
g_free (full_fname);
}
tty_getyx (&y, &x);
x -= edit->widget.x;
x -= w->x;
x += 4;
if (x + 6 <= cols - 2 - 6)
{
@ -289,7 +291,7 @@ edit_status_window (WEdit * edit)
if (cols > 30)
{
edit_move (2, edit->widget.lines - 1);
edit_move (2, w->lines - 1);
tty_printf ("%3ld %5ld/%ld %6ld/%ld",
edit->curs_col + edit->over_col,
edit->curs_line + 1, edit->total_lines + 1, edit->curs1, edit->last_byte);
@ -302,7 +304,7 @@ edit_status_window (WEdit * edit)
*/
if (cols > 46)
{
edit_move (32, edit->widget.lines - 1);
edit_move (32, w->lines - 1);
if (edit->curs1 >= edit->last_byte)
tty_print_string ("[<EOF> ]");
#ifdef HAVE_CHARSET
@ -365,14 +367,14 @@ edit_draw_frame (const WEdit * edit, int color, gboolean active)
static inline void
edit_draw_window_icons (const WEdit * edit, int color)
{
const Widget *w = (const Widget *) edit;
const Widget *w = WIDGET (edit);
char tmp[17];
tty_setcolor (color);
if (edit->fullscreen)
dlg_move (w->owner, 0, w->owner->cols - 6);
widget_move (w->owner, 0, WIDGET (w->owner)->cols - 6);
else
widget_move (w, 0, edit->widget.cols - 8);
widget_move (w, 0, w->cols - 8);
g_snprintf (tmp, sizeof (tmp), "[%s][%s]", edit_window_state_char, edit_window_close_char);
tty_print_string (tmp);
}
@ -499,6 +501,8 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
static void
edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_col)
{
Widget *w = WIDGET (edit);
struct line_s line[MAX_LINE_LEN];
struct line_s *p = line;
@ -513,7 +517,7 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
int book_mark = 0;
char line_stat[LINE_STATE_WIDTH + 1] = "\0";
if (row > edit->widget.lines - 1 - EDIT_TEXT_VERTICAL_OFFSET - 2 * (edit->fullscreen ? 0 : 1))
if (row > w->lines - 1 - EDIT_TEXT_VERTICAL_OFFSET - 2 * (edit->fullscreen ? 0 : 1))
return;
if (book_mark_query_color (edit, edit->start_line + row, BOOK_MARK_COLOR))
@ -529,10 +533,8 @@ edit_draw_this_line (WEdit * edit, off_t b, long row, long start_col, long end_c
end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
if (!edit->fullscreen)
{
const Widget *w = (const Widget *) edit;
end_col--;
if (w->x + w->cols <= w->owner->cols)
if (w->x + w->cols <= WIDGET (w->owner)->cols)
end_col--;
}
@ -843,6 +845,7 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
Widget *w = (Widget *) edit;
Dlg_head *h = w->owner;
Widget *wh = WIDGET (h);
long row = 0, curs_row;
int force = edit->force;
@ -854,24 +857,24 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
/* draw only visible region */
last_line = h->y + h->lines - 1;
last_line = wh->y + wh->lines - 1;
y1 = w->y;
if (y1 > last_line - 1 /* buttonbar */ )
return;
last_column = h->x + h->cols - 1;
last_column = wh->x + wh->cols - 1;
x1 = w->x;
if (x1 > last_column)
return;
y2 = w->y + w->lines - 1;
if (y2 < h->y + 1 /* menubar */ )
if (y2 < wh->y + 1 /* menubar */ )
return;
x2 = w->x + w->cols - 1;
if (x2 < h->x)
if (x2 < wh->x)
return;
if ((force & REDRAW_IN_BOUNDS) == 0)
@ -881,17 +884,17 @@ render_edit_text (WEdit * edit, long start_row, long start_column, long end_row,
if (y2 <= last_line - 1 /* buttonbar */ )
end_row = w->lines - 1;
else if (y1 >= h->y + 1 /* menubar */ )
end_row = h->lines - 1 - y1 - 1;
else if (y1 >= wh->y + 1 /* menubar */ )
end_row = wh->lines - 1 - y1 - 1;
else
end_row = start_row + h->lines - 1 - 1;
end_row = start_row + wh->lines - 1 - 1;
if (x2 <= last_column)
end_column = w->cols - 1;
else if (x1 >= h->x)
end_column = h->cols - 1 - x1;
else if (x1 >= wh->x)
end_column = wh->cols - 1 - x1;
else
end_column = start_column + h->cols - 1;
end_column = start_column + wh->cols - 1;
}
/*

View File

@ -208,16 +208,16 @@ edit_help (void)
static void
edit_dialog_resize_cb (void *data, void *user_data)
{
Widget *w = (Widget *) data;
Widget *w = WIDGET (data);
(void) user_data;
if (edit_widget_is_editor (w) && ((WEdit *) w)->fullscreen)
{
Dlg_head *h = w->owner;
Widget *wh = WIDGET (w->owner);
w->lines = h->lines - 2;
w->cols = h->cols;
w->lines = wh->lines - 2;
w->cols = wh->cols;
}
}
@ -248,25 +248,25 @@ edit_restore_size (WEdit * edit)
static void
edit_window_move (WEdit * edit, unsigned long command)
{
Widget *w = (Widget *) edit;
Dlg_head *h = w->owner;
Widget *w = WIDGET (edit);
Widget *wh = WIDGET (w->owner);
switch (command)
{
case CK_Up:
if (w->y > h->y + 1) /* menubar */
if (w->y > wh->y + 1) /* menubar */
w->y--;
break;
case CK_Down:
if (w->y < h->y + h->lines - 2) /* buttonbar */
if (w->y < wh->y + wh->lines - 2) /* buttonbar */
w->y++;
break;
case CK_Left:
if (w->x + w->cols > h->x)
if (w->x + w->cols > wh->x)
w->x--;
break;
case CK_Right:
if (w->x < h->x + h->cols)
if (w->x < wh->x + wh->cols)
w->x++;
break;
default:
@ -274,7 +274,7 @@ edit_window_move (WEdit * edit, unsigned long command)
}
edit->force |= REDRAW_PAGE;
dlg_redraw (h);
dlg_redraw (w->owner);
}
/* --------------------------------------------------------------------------------------------- */
@ -288,8 +288,8 @@ edit_window_move (WEdit * edit, unsigned long command)
static void
edit_window_resize (WEdit * edit, unsigned long command)
{
Widget *w = (Widget *) edit;
Dlg_head *h = w->owner;
Widget *w = WIDGET (edit);
Widget *wh = WIDGET (w->owner);
switch (command)
{
@ -298,7 +298,7 @@ edit_window_resize (WEdit * edit, unsigned long command)
w->lines--;
break;
case CK_Down:
if (w->y + w->lines < h->y + h->lines - 1) /* buttonbar */
if (w->y + w->lines < wh->y + wh->lines - 1) /* buttonbar */
w->lines++;
break;
case CK_Left:
@ -306,7 +306,7 @@ edit_window_resize (WEdit * edit, unsigned long command)
w->cols--;
break;
case CK_Right:
if (w->x + w->cols < h->x + h->cols)
if (w->x + w->cols < wh->x + wh->cols)
w->cols++;
break;
default:
@ -314,7 +314,7 @@ edit_window_resize (WEdit * edit, unsigned long command)
}
edit->force |= REDRAW_COMPLETELY;
dlg_redraw (h);
dlg_redraw (w->owner);
}
/* --------------------------------------------------------------------------------------------- */
@ -628,7 +628,7 @@ edit_event (Gpm_Event * event, void *data)
}
else if (!edit->fullscreen)
{
Dlg_head *h = w->owner;
Widget *h = WIDGET (w->owner);
if (edit->drag_state == MCEDIT_DRAG_MOVE)
{
@ -655,7 +655,7 @@ edit_event (Gpm_Event * event, void *data)
edit->force |= REDRAW_COMPLETELY;
}
dlg_redraw (h);
dlg_redraw (w->owner);
}
}
@ -676,11 +676,12 @@ edit_dialog_event (Gpm_Event * event, void *data)
{
Dlg_head *h = (Dlg_head *) data;
Widget *w;
Widget *wh = WIDGET (h);
int ret = MOU_UNHANDLED;
w = (Widget *) find_menubar (h);
w = WIDGET (find_menubar (h));
if (event->y == h->y + 1 && (event->type & GPM_DOWN) != 0 && !((WMenuBar *) w)->is_active)
if (event->y == wh->y + 1 && (event->type & GPM_DOWN) != 0 && !((WMenuBar *) w)->is_active)
{
/* menubar */
@ -694,7 +695,7 @@ edit_dialog_event (Gpm_Event * event, void *data)
top = l;
/* Handle fullscreen/close buttons in the top line */
x = h->x + h->cols + 1 - 6;
x = wh->x + wh->cols + 1 - 6;
if (top != NULL && event->x >= x)
{
@ -730,12 +731,13 @@ edit_dialog_event (Gpm_Event * event, void *data)
static cb_ret_t
edit_dialog_command_execute (Dlg_head * h, unsigned long command)
{
Widget *wh = WIDGET (h);
gboolean ret = MSG_HANDLED;
switch (command)
{
case CK_EditNew:
edit_add_window (h, h->y + 1, h->x, h->lines - 2, h->cols, NULL, 0);
edit_add_window (h, wh->y + 1, wh->x, wh->lines - 2, wh->cols, NULL, 0);
break;
case CK_EditFile:
edit_load_cmd (h);
@ -887,6 +889,7 @@ edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, vo
{
WMenuBar *menubar;
WButtonBar *buttonbar;
Widget *wh = WIDGET (h);
switch (msg)
{
@ -904,10 +907,10 @@ edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, vo
menubar = find_menubar (h);
buttonbar = find_buttonbar (h);
/* dlg_set_size() is surplus for this case */
h->lines = LINES;
h->cols = COLS;
widget_set_size (&buttonbar->widget, h->lines - 1, h->x, 1, h->cols);
widget_set_size (&menubar->widget, h->y, h->x, 1, h->cols);
wh->lines = LINES;
wh->cols = COLS;
widget_set_size (&buttonbar->widget, wh->lines - 1, wh->x, 1, wh->cols);
widget_set_size (&menubar->widget, wh->y, wh->x, 1, wh->cols);
menubar_arrange (menubar);
g_list_foreach (h->widgets, (GFunc) edit_dialog_resize_cb, NULL);
return MSG_HANDLED;
@ -1117,11 +1120,12 @@ edit_files (const GList * files)
for (file = files; file != NULL; file = g_list_next (file))
{
Widget *w = WIDGET (edit_dlg);
mcedit_arg_t *f = (mcedit_arg_t *) file->data;
gboolean f_ok;
f_ok = edit_add_window (edit_dlg, edit_dlg->y + 1, edit_dlg->x,
edit_dlg->lines - 2, edit_dlg->cols, f->file_vpath, f->line_number);
f_ok = edit_add_window (edit_dlg, w->y + 1, w->x, w->lines - 2, w->cols, f->file_vpath,
f->line_number);
/* at least one file has been opened succefully */
ok = ok || f_ok;
}
@ -1348,8 +1352,6 @@ edit_handle_move_resize (WEdit * edit, unsigned long command)
void
edit_toggle_fullscreen (WEdit * edit)
{
Dlg_head *h = ((Widget *) edit)->owner;
edit->fullscreen = !edit->fullscreen;
edit->force = REDRAW_COMPLETELY;
@ -1357,8 +1359,11 @@ edit_toggle_fullscreen (WEdit * edit)
edit_restore_size (edit);
else
{
Widget *w = WIDGET (edit);
Widget *h = WIDGET (w->owner);
edit_save_size (edit);
widget_set_size ((Widget *) edit, h->y + 1, h->x, h->lines - 2, h->cols);
widget_set_size (w, h->y + 1, h->x, h->lines - 2, h->cols);
edit->force |= REDRAW_PAGE;
edit_update_screen (edit);
}

View File

@ -230,19 +230,19 @@ print_flags (void)
for (i = 0; i < 3; i++)
{
dlg_move (ch_dlg, BY + 1, 9 + i);
widget_move (ch_dlg, BY + 1, 9 + i);
tty_print_char (ch_flags[i]);
}
for (i = 0; i < 3; i++)
{
dlg_move (ch_dlg, BY + 1, 17 + i);
widget_move (ch_dlg, BY + 1, 17 + i);
tty_print_char (ch_flags[i + 3]);
}
for (i = 0; i < 3; i++)
{
dlg_move (ch_dlg, BY + 1, 25 + i);
widget_move (ch_dlg, BY + 1, 25 + i);
tty_print_char (ch_flags[i + 6]);
}
@ -250,12 +250,12 @@ print_flags (void)
for (i = 0; i < 15; i++)
{
dlg_move (ch_dlg, BY + 1, 35 + i);
widget_move (ch_dlg, BY + 1, 35 + i);
tty_print_char (ch_flags[9]);
}
for (i = 0; i < 15; i++)
{
dlg_move (ch_dlg, BY + 1, 53 + i);
widget_move (ch_dlg, BY + 1, 53 + i);
tty_print_char (ch_flags[10]);
}
}
@ -267,7 +267,7 @@ update_mode (Dlg_head * h)
{
print_flags ();
tty_setcolor (COLOR_NORMAL);
dlg_move (h, BY + 2, 9);
widget_move (h, BY + 2, 9);
tty_printf ("%12o", get_mode ());
send_message ((Widget *) h->current->data, WIDGET_FOCUS, 0);
}
@ -417,28 +417,28 @@ chown_refresh (void)
tty_setcolor (COLOR_NORMAL);
dlg_move (ch_dlg, BY - 1, 8);
widget_move (ch_dlg, BY - 1, 8);
tty_print_string (_("owner"));
dlg_move (ch_dlg, BY - 1, 16);
widget_move (ch_dlg, BY - 1, 16);
tty_print_string (_("group"));
dlg_move (ch_dlg, BY - 1, 24);
widget_move (ch_dlg, BY - 1, 24);
tty_print_string (_("other"));
dlg_move (ch_dlg, BY - 1, 35);
widget_move (ch_dlg, BY - 1, 35);
tty_print_string (_("owner"));
dlg_move (ch_dlg, BY - 1, 53);
widget_move (ch_dlg, BY - 1, 53);
tty_print_string (_("group"));
dlg_move (ch_dlg, 3, 4);
widget_move (ch_dlg, 3, 4);
tty_print_string (_("On"));
dlg_move (ch_dlg, BY + 1, 4);
widget_move (ch_dlg, BY + 1, 4);
tty_print_string (_("Flag"));
dlg_move (ch_dlg, BY + 2, 4);
widget_move (ch_dlg, BY + 2, 4);
tty_print_string (_("Mode"));
if (!single_set)
{
dlg_move (ch_dlg, 3, 54);
widget_move (ch_dlg, 3, 54);
tty_printf (_("%6d of %d"), files_on_begin - (current_panel->marked) + 1, files_on_begin);
}
@ -454,9 +454,9 @@ chown_info_update (void)
tty_setcolor (COLOR_NORMAL);
/* name && mode */
dlg_move (ch_dlg, 3, 8);
widget_move (ch_dlg, 3, 8);
tty_print_string (str_fit_to_term (fname, 45, J_LEFT_FIT));
dlg_move (ch_dlg, BY + 2, 9);
widget_move (ch_dlg, BY + 2, 9);
tty_printf ("%12o", get_mode ());
/* permissions */

View File

@ -898,6 +898,7 @@ tree_box (const char *current_dir)
{
WTree *mytree;
Dlg_head *dlg;
Widget *wd;
char *val = NULL;
WButtonBar *bar;
@ -907,10 +908,11 @@ tree_box (const char *current_dir)
dlg = create_dlg (TRUE, 0, 0, LINES - 9, COLS - 20, dialog_colors,
tree_callback, NULL, "[Directory Tree]",
_("Directory tree"), DLG_CENTER | DLG_REVERSE);
wd = WIDGET (dlg);
mytree = tree_new (2, 2, dlg->lines - 6, dlg->cols - 5, FALSE);
mytree = tree_new (2, 2, wd->lines - 6, wd->cols - 5, FALSE);
add_widget (dlg, mytree);
add_widget (dlg, hline_new (dlg->lines - 4, 1, -1));
add_widget (dlg, hline_new (wd->lines - 4, 1, -1));
bar = buttonbar_new (TRUE);
add_widget (dlg, bar);
/* restore ButtonBar coordinates after add_widget() */

View File

@ -185,9 +185,9 @@ chmod_toggle_select (Dlg_head * h, int Id)
tty_setcolor (COLOR_NORMAL);
check_perm[Id].selected = !check_perm[Id].selected;
dlg_move (h, PY + check_perm_num - Id, PX + 1);
widget_move (h, PY + check_perm_num - Id, PX + 1);
tty_print_char (check_perm[Id].selected ? '*' : ' ');
dlg_move (h, PY + check_perm_num - Id, PX + 3);
widget_move (h, PY + check_perm_num - Id, PX + 3);
}
/* --------------------------------------------------------------------------------------------- */
@ -311,13 +311,13 @@ init_chmod (const char *fname, const struct stat *sf_stat)
for (i = 0; i < chmod_but_num; i++)
{
add_widget (ch_dlg,
button_new (lines - chmod_but[i].y, ch_dlg->cols / 2 + 1,
button_new (lines - chmod_but[i].y, WIDGET (ch_dlg)->cols / 2 + 1,
chmod_but[i].ret_cmd, chmod_but[i].flags, chmod_but[i].text, 0));
i++;
add_widget (ch_dlg,
button_new (lines - chmod_but[i].y, ch_dlg->cols / 2 - chmod_but[i].len,
button_new (lines - chmod_but[i].y, WIDGET (ch_dlg)->cols / 2 - chmod_but[i].len,
chmod_but[i].ret_cmd, chmod_but[i].flags, chmod_but[i].text, 0));
if (single_set)

View File

@ -123,15 +123,15 @@ chown_refresh (Dlg_head * h)
tty_setcolor (COLOR_NORMAL);
dlg_move (h, TY + 1, TX + 2);
widget_move (h, TY + 1, TX + 2);
tty_print_string (_("Name"));
dlg_move (h, TY + 3, TX + 2);
widget_move (h, TY + 3, TX + 2);
tty_print_string (_("Owner name"));
dlg_move (h, TY + 5, TX + 2);
widget_move (h, TY + 5, TX + 2);
tty_print_string (_("Group name"));
dlg_move (h, TY + 7, TX + 2);
widget_move (h, TY + 7, TX + 2);
tty_print_string (_("Size"));
dlg_move (h, TY + 9, TX + 2);
widget_move (h, TY + 9, TX + 2);
tty_print_string (_("Permission"));
}

View File

@ -2420,7 +2420,7 @@ compute_dir_size_create_ui (void)
add_widget (ui->dlg, ui->dirname);
add_widget (ui->dlg,
button_new (5, (ui->dlg->cols - strlen (b_name)) / 2,
button_new (5, (WIDGET (ui->dlg)->cols - strlen (b_name)) / 2,
FILE_ABORT, NORMAL_BUTTON, b_name, NULL));
/* We will manage the dialog without any help,
@ -2461,7 +2461,7 @@ compute_dir_size_update_ui (const void *ui, const vfs_path_t * dirname_vpath)
return FILE_CONT;
dirname = vfs_path_to_str (dirname_vpath);
label_set_text (this->dirname, str_trunc (dirname, this->dlg->cols - 6));
label_set_text (this->dirname, str_trunc (dirname, WIDGET (this->dlg)->cols - 6));
g_free (dirname);
event.x = -1; /* Don't show the GPM cursor */

View File

@ -1140,7 +1140,7 @@ find_rotate_dash (const Dlg_head * h, gboolean finish)
{
pos = (pos + 1) % 4;
tty_setcolor (h->color[DLG_COLOR_NORMAL]);
dlg_move (h, FIND2_Y - 7, FIND2_X - 4);
widget_move (h, FIND2_Y - 7, FIND2_X - 4);
tty_print_char (finish ? ' ' : rotating_dash[pos]);
mc_refresh ();
}

View File

@ -248,14 +248,16 @@ static void add_dotdot_to_list (void);
/* --------------------------------------------------------------------------------------------- */
static void
hotlist_refresh (Dlg_head * dlg)
hotlist_refresh (Dlg_head * h)
{
Widget *wh = WIDGET (h);
/* TODO: use groupboxes here */
common_dialog_repaint (dlg);
common_dialog_repaint (h);
tty_setcolor (COLOR_NORMAL);
draw_box (dlg, 2, 5, dlg->lines - (hotlist_state.moving ? 6 : 10), dlg->cols - (UX * 2), TRUE);
draw_box (h, 2, 5, wh->lines - (hotlist_state.moving ? 6 : 10), wh->cols - (UX * 2), TRUE);
if (!hotlist_state.moving)
draw_box (dlg, dlg->lines - 8, 5, 3, dlg->cols - (UX * 2), TRUE);
draw_box (h, wh->lines - 8, 5, 3, wh->cols - (UX * 2), TRUE);
}
/* --------------------------------------------------------------------------------------------- */
@ -267,7 +269,8 @@ update_path_name (void)
const char *text = "";
char *p;
WListbox *list = hotlist_state.moving ? l_movelist : l_hotlist;
Dlg_head *dlg = list->widget.owner;
Dlg_head *owner = WIDGET (list)->owner;
Widget *wo = WIDGET (owner);
if (list->count != 0)
{
@ -288,16 +291,16 @@ update_path_name (void)
}
}
if (!hotlist_state.moving)
label_set_text (pname, str_trunc (text, dlg->cols - (UX * 2 + 4)));
label_set_text (pname, str_trunc (text, wo->cols - (UX * 2 + 4)));
p = g_strconcat (" ", current_group->label, " ", (char *) NULL);
if (!hotlist_state.moving)
label_set_text (pname_group, str_trunc (p, dlg->cols - (UX * 2 + 4)));
label_set_text (pname_group, str_trunc (p, wo->cols - (UX * 2 + 4)));
else
label_set_text (movelist_group, str_trunc (p, dlg->cols - (UX * 2 + 4)));
label_set_text (movelist_group, str_trunc (p, wo->cols - (UX * 2 + 4)));
g_free (p);
dlg_redraw (dlg);
dlg_redraw (owner);
}
/* --------------------------------------------------------------------------------------------- */
@ -863,8 +866,8 @@ init_movelist (int list_type, struct hotlist *item)
add_widget (movelist_dlg, movelist_group);
/* get new listbox */
l_movelist =
listbox_new (UY + 1, UX + 1, movelist_dlg->lines - 8,
movelist_dlg->cols - 2 * UX - 2, FALSE, l_call);
listbox_new (UY + 1, UX + 1, WIDGET (movelist_dlg)->lines - 8,
WIDGET (movelist_dlg)->cols - 2 * UX - 2, FALSE, l_call);
fill_listbox ();

View File

@ -237,19 +237,19 @@ update_split (const Dlg_head * h)
tty_setcolor (check_options[6].widget->state & C_BOOL ? DISABLED_COLOR : COLOR_NORMAL);
dlg_move (h, 6, 5);
widget_move (h, 6, 5);
if (_panels_layout.horizontal_split)
tty_printf ("%03d", _panels_layout.top_panel_size);
else
tty_printf ("%03d", _panels_layout.left_panel_size);
dlg_move (h, 6, 17);
widget_move (h, 6, 17);
if (_panels_layout.horizontal_split)
tty_printf ("%03d", height - _panels_layout.top_panel_size);
else
tty_printf ("%03d", COLS - _panels_layout.left_panel_size);
dlg_move (h, 6, 12);
widget_move (h, 6, 12);
tty_print_char ('=');
}
@ -329,9 +329,9 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d
{
old_output_lines = _output_lines;
tty_setcolor (mc_global.tty.console_flag != '\0' ? COLOR_NORMAL : DISABLED_COLOR);
dlg_move (h, 9, 5);
widget_move (h, 9, 5);
tty_print_string (output_lines_label);
dlg_move (h, 9, 5 + 3 + output_lines_label_len);
widget_move (h, 9, 5 + 3 + output_lines_label_len);
tty_printf ("%02d", _output_lines);
}
return MSG_HANDLED;
@ -367,7 +367,7 @@ layout_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void *d
{
old_output_lines = _output_lines;
tty_setcolor (mc_global.tty.console_flag != '\0' ? COLOR_NORMAL : DISABLED_COLOR);
dlg_move (h, 9, 5 + 3 + output_lines_label_len);
widget_move (h, 9, 5 + 3 + output_lines_label_len);
tty_printf ("%02d", _output_lines);
}
return MSG_HANDLED;

View File

@ -1604,10 +1604,10 @@ midnight_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
static int
midnight_event (Gpm_Event * event, void *data)
{
Dlg_head *h = (Dlg_head *) data;
Widget *wh = WIDGET (data);
int ret = MOU_UNHANDLED;
if (event->y == h->y + 1)
if (event->y == wh->y + 1)
{
/* menubar */
if (menubar_visible || the_menubar->is_active)

View File

@ -146,7 +146,7 @@ panelize_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, void
case DLG_DRAW:
common_dialog_repaint (h);
tty_setcolor (COLOR_NORMAL);
draw_box (h, UY, UX, h->lines - 10, h->cols - 10, TRUE);
draw_box (h, UY, UX, WIDGET (h)->lines - 10, WIDGET (h)->cols - 10, TRUE);
return MSG_HANDLED;
default:
@ -204,13 +204,13 @@ init_panelize (void)
pname =
input_new (UY + 14, UX, input_get_default_colors (),
panelize_dlg->cols - 10, "", "in", INPUT_COMPLETE_DEFAULT);
WIDGET (panelize_dlg)->cols - 10, "", "in", INPUT_COMPLETE_DEFAULT);
add_widget (panelize_dlg, pname);
add_widget (panelize_dlg, label_new (UY + 13, UX, _("Command")));
/* get new listbox */
l_panelize = listbox_new (UY + 1, UX + 1, 10, panelize_dlg->cols - 12, FALSE, NULL);
l_panelize = listbox_new (UY + 1, UX + 1, 10, WIDGET (panelize_dlg)->cols - 12, FALSE, NULL);
while (current)
{

View File

@ -640,7 +640,7 @@ tree_event (Gpm_Event * event, void *data)
return MOU_UNHANDLED;
/* rest of the upper frame - call menu */
if (tree->is_panel && (event->type & GPM_DOWN) != 0 && event->y == w->owner->y + 1)
if (tree->is_panel && (event->type & GPM_DOWN) != 0 && event->y == WIDGET (w->owner)->y + 1)
return MOU_UNHANDLED;
local = mouse_get_local (event, w);

View File

@ -422,7 +422,7 @@ help_print_word (Dlg_head * h, GString * word, int *col, int *line, gboolean add
g_string_set_size (word, 0);
else
{
dlg_move (h, *line + 2, *col + 2);
widget_move (h, *line + 2, *col + 2);
tty_print_string (word->str);
g_string_set_size (word, 0);
*col += w;
@ -514,7 +514,7 @@ help_show (Dlg_head * h, const char *paint_start)
acs = FALSE;
break;
case CHAR_VERSION:
dlg_move (h, line + 2, col + 2);
widget_move (h, line + 2, col + 2);
tty_print_string (VERSION);
col += str_term_width1 (VERSION);
break;
@ -555,7 +555,7 @@ help_show (Dlg_head * h, const char *paint_start)
g_string_append (word, buff);
else if (col < HELP_WINDOW_WIDTH)
{
dlg_move (h, line + 2, col + 2);
widget_move (h, line + 2, col + 2);
if ((c == ' ') || (c == '.'))
tty_print_char (c);
@ -563,7 +563,7 @@ help_show (Dlg_head * h, const char *paint_start)
#ifndef HAVE_SLANG
tty_print_char (acs_map[c]);
#else
SLsmg_draw_object (h->y + line + 2, h->x + col + 2, c);
SLsmg_draw_object (WIDGET (h)->y + line + 2, WIDGET (h)->x + col + 2, c);
#endif
col++;
}
@ -595,7 +595,7 @@ help_show (Dlg_head * h, const char *paint_start)
/* Position the cursor over a nice link */
if (active_col)
dlg_move (h, active_line, active_col);
widget_move (h, active_line, active_col);
}
/* --------------------------------------------------------------------------------------------- */
@ -1129,8 +1129,8 @@ help_interactive_display (const gchar * event_group_name, const gchar * event_na
}
help_bar = buttonbar_new (TRUE);
help_bar->widget.y -= whelp->y;
help_bar->widget.x -= whelp->x;
help_bar->widget.y -= WIDGET (whelp)->y;
help_bar->widget.x -= WIDGET (whelp)->x;
md = mousedispatch_new (1, 1, help_lines, HELP_WINDOW_WIDTH - 2);

View File

@ -93,7 +93,8 @@ do_mcview_event (mcview_t * view, Gpm_Event * event, int *result)
Widget *w = (Widget *) view;
/* rest of the upper frame - call menu */
if (mcview_is_in_panel (view) && (event->type & GPM_DOWN) != 0 && event->y == w->owner->y + 1)
if (mcview_is_in_panel (view) && (event->type & GPM_DOWN) != 0 &&
event->y == WIDGET (w->owner)->y + 1)
{
*result = MOU_UNHANDLED;
return FALSE; /* don't draw viewer over menu */