FileProgressStatus check_progress_buttons (file_op_context_t * ctx) { int c; Gpm_Event event; file_op_context_ui_t *ui; if (ctx == NULL || ctx->ui == NULL) return FILE_CONT; ui = ctx->ui; get_event: event.x = -1; /* Don't show the GPM cursor */ c = tty_get_event (&event, FALSE, ctx->suspended); if (c == EV_NONE) return FILE_CONT; /* Reinitialize to avoid old values after events other than selecting a button */ ui->op_dlg->ret_value = FILE_CONT; dlg_process_event (ui->op_dlg, c, &event); switch (ui->op_dlg->ret_value) { case FILE_SKIP: if (ctx->suspended) { /* redraw dialog in case of Skip after Suspend */ place_progress_buttons (ui->op_dlg, FALSE); dlg_redraw (ui->op_dlg); } ctx->suspended = FALSE; return FILE_SKIP; case B_CANCEL: case FILE_ABORT: ctx->suspended = FALSE; return FILE_ABORT; case FILE_SUSPEND: ctx->suspended = !ctx->suspended; place_progress_buttons (ui->op_dlg, ctx->suspended); dlg_redraw (ui->op_dlg); /* fallthrough */ default: if (ctx->suspended) goto get_event; return FILE_CONT; } }
static void edit_window_move (WEdit * edit, unsigned long command) { Widget *w = (Widget *) edit; Dlg_head *h = w->owner; switch (command) { case CK_Up: if (w->y > h->y + 1) /* menubar */ w->y--; break; case CK_Down: if (w->y < h->y + h->lines - 2) /* buttonbar */ w->y++; break; case CK_Left: if (w->x + w->cols > h->x) w->x--; break; case CK_Right: if (w->x < h->x + h->cols) w->x++; break; default: return; } edit->force |= REDRAW_PAGE; dlg_redraw (h); }
/** delete widget from dialog */ void del_widget (void *w) { Dlg_head *h = ((Widget *) w)->owner; GList *d; /* Don't accept NULL widget. This shouldn't happen */ if (w == NULL) abort (); d = g_list_find (h->widgets, w); if (d == h->current) { if ((h->flags & DLG_REVERSE) != 0) h->current = dlg_widget_prev (h, d); else h->current = dlg_widget_next (h, d); } h->widgets = g_list_remove_link (h->widgets, d); send_message (d->data, WIDGET_DESTROY, 0); g_list_free_1 (d); /* widget has been deleted in runtime */ if (h->state == DLG_ACTIVE) { dlg_redraw (h); dlg_focus (h); } }
void init_dlg (Dlg_head * h) { if ((top_dlg != NULL) && ((Dlg_head *) top_dlg->data)->modal) h->modal = TRUE; /* add dialog to the stack */ top_dlg = g_list_prepend (top_dlg, h); /* Initialize dialog manager and widgets */ if (h->state == DLG_CONSTRUCT) { if (!h->modal) dialog_switch_add (h); h->callback (h, NULL, DLG_INIT, 0, NULL); dlg_broadcast_msg (h, WIDGET_INIT, FALSE); dlg_read_history (h); } h->state = DLG_ACTIVE; /* Select the first widget that takes focus */ while (h->current != NULL && !dlg_focus (h)) h->current = dlg_widget_next (h, h->current); dlg_redraw (h); h->ret_value = 0; }
static void edit_window_move (WEdit * edit, long command) { Widget *w = WIDGET (edit); Widget *wh = WIDGET (w->owner); switch (command) { case CK_Up: if (w->y > wh->y + 1) /* menubar */ w->y--; break; case CK_Down: if (w->y < wh->y + wh->lines - 2) /* buttonbar */ w->y++; break; case CK_Left: if (w->x + w->cols > wh->x) w->x--; break; case CK_Right: if (w->x < wh->x + wh->cols) w->x++; break; default: return; } edit->force |= REDRAW_PAGE; dlg_redraw (w->owner); }
static void edit_restore_size (WEdit * edit) { edit->drag_state = MCEDIT_DRAG_NORMAL; widget_set_size (WIDGET (edit), edit->y_prev, edit->x_prev, edit->lines_prev, edit->cols_prev); dlg_redraw (WIDGET (edit)->owner); }
static void edit_window_resize (WEdit * edit, long command) { Widget *w = WIDGET (edit); Widget *wh = WIDGET (w->owner); switch (command) { case CK_Up: if (w->lines > WINDOW_MIN_LINES) w->lines--; break; case CK_Down: if (w->y + w->lines < wh->y + wh->lines - 1) /* buttonbar */ w->lines++; break; case CK_Left: if (w->cols > WINDOW_MIN_COLS) w->cols--; break; case CK_Right: if (w->x + w->cols < wh->x + wh->cols) w->cols++; break; default: return; } edit->force |= REDRAW_COMPLETELY; dlg_redraw (w->owner); }
void dlg_init (WDialog * h) { if (top_dlg != NULL && DIALOG (top_dlg->data)->modal) h->modal = TRUE; /* add dialog to the stack */ top_dlg = g_list_prepend (top_dlg, h); /* Initialize dialog manager and widgets */ if (h->state == DLG_CONSTRUCT) { if (!h->modal) dialog_switch_add (h); send_message (h, NULL, MSG_INIT, 0, NULL); dlg_broadcast_msg (h, MSG_INIT); dlg_read_history (h); } h->state = DLG_ACTIVE; /* Select the first widget that takes focus */ while (h->current != NULL && !dlg_focus (h)) h->current = dlg_widget_next (h, h->current); dlg_redraw (h); h->ret_value = 0; }
void dlg_init (WDialog * h) { Widget *wh = WIDGET (h); if (top_dlg != NULL && widget_get_state (WIDGET (top_dlg->data), WST_MODAL)) widget_set_state (wh, WST_MODAL, TRUE); /* add dialog to the stack */ top_dlg = g_list_prepend (top_dlg, h); /* Initialize dialog manager and widgets */ if (widget_get_state (wh, WST_CONSTRUCT)) { if (!widget_get_state (wh, WST_MODAL)) dialog_switch_add (h); send_message (h, NULL, MSG_INIT, 0, NULL); dlg_broadcast_msg (h, MSG_INIT); dlg_read_history (h); } /* Select the first widget that takes focus */ while (h->current != NULL && !widget_get_options (WIDGET (h->current->data), WOP_SELECTABLE) && !widget_get_state (WIDGET (h->current->data), WST_DISABLED)) dlg_set_current_widget_next (h); widget_set_state (wh, WST_ACTIVE, TRUE); dlg_redraw (h); /* focus found widget */ if (h->current != NULL) widget_set_state (WIDGET (h->current->data), WST_FOCUSED, TRUE); h->ret_value = 0; }
/** delete widget from dialog */ void del_widget (void *w) { WDialog *h; GList *d; /* Don't accept NULL widget. This shouldn't happen */ if (w == NULL) abort (); h = WIDGET (w)->owner; d = g_list_find (h->widgets, w); if (d == h->current) h->current = dlg_widget_next (h, d); h->widgets = g_list_remove_link (h->widgets, d); send_message (d->data, NULL, MSG_DESTROY, 0, NULL); g_free (d->data); g_list_free_1 (d); /* widget has been deleted in runtime */ if (h->state == DLG_ACTIVE) { dlg_redraw (h); dlg_focus (h); } }
static void edit_window_resize (WEdit * edit, unsigned long command) { Widget *w = (Widget *) edit; Dlg_head *h = w->owner; switch (command) { case CK_Up: if (w->lines > WINDOW_MIN_LINES) w->lines--; break; case CK_Down: if (w->y + w->lines < h->y + h->lines - 1) /* buttonbar */ w->lines++; break; case CK_Left: if (w->cols > WINDOW_MIN_COLS) w->cols--; break; case CK_Right: if (w->x + w->cols < h->x + h->cols) w->cols++; break; default: return; } edit->force |= REDRAW_COMPLETELY; dlg_redraw (h); }
static int sel_charset_button (WButton * button, int action) { int new_dcp; (void) action; new_dcp = select_charset (-1, -1, new_display_codepage, TRUE); if (new_dcp != SELECT_CHARSET_CANCEL) { const char *cpname; new_display_codepage = new_dcp; cpname = (new_display_codepage == SELECT_CHARSET_OTHER_8BIT) ? _("Other 8 bit") : ((codepage_desc *) g_ptr_array_index (codepages, new_display_codepage))->name; if (cpname != NULL) mc_global.utf8_display = str_isutf8 (cpname); else cpname = _("7-bit ASCII"); /* FIXME */ button_set_text (button, cpname); dlg_redraw (WIDGET (button)->owner); } return 0; }
void button_set_text (WButton * b, const char *text) { release_hotkey (b->text); b->text = parse_hotkey (text); b->widget.cols = button_get_len (b); dlg_redraw (b->widget.owner); }
static void edit_restore_size (WEdit * edit) { Widget *w = WIDGET (edit); edit->drag_state = MCEDIT_DRAG_NONE; w->mouse.forced_capture = FALSE; widget_set_size (w, edit->y_prev, edit->x_prev, edit->lines_prev, edit->cols_prev); dlg_redraw (w->owner); }
void do_refresh (void) { GList *d = top_dlg; if (fast_refresh) { if (d != NULL) dlg_redraw (DIALOG (d->data)); } else { /* Search first fullscreen dialog */ for (; d != NULL; d = g_list_next (d)) if ((WIDGET (d->data)->pos_flags & WPOS_FULLSCREEN) != 0) break; /* back to top dialog */ for (; d != NULL; d = g_list_previous (d)) dlg_redraw (DIALOG (d->data)); } }
void do_refresh (void) { GList *d = top_dlg; if (fast_refresh) { if ((d != NULL) && (d->data != NULL)) dlg_redraw (DIALOG (d->data)); } else { /* Search first fullscreen dialog */ for (; d != NULL; d = g_list_next (d)) if (d->data != NULL && DIALOG (d->data)->fullscreen) break; /* back to top dialog */ for (; d != NULL; d = g_list_previous (d)) if (d->data != NULL) dlg_redraw (DIALOG (d->data)); } }
/** * Handle move/resize mouse events. */ static void edit_mouse_handle_move_resize (Widget * w, mouse_msg_t msg, mouse_event_t * event) { WEdit *edit = (WEdit *) (w); Widget *h = WIDGET (w->owner); int global_x, global_y; if (msg == MSG_MOUSE_UP) { /* Exit move/resize mode. */ edit_execute_cmd (edit, CK_Enter, -1); edit_update_screen (edit); /* Paint the buttonbar over our possibly overlapping frame. */ return; } if (msg != MSG_MOUSE_DRAG) /** * We ignore any other events. Specifically, MSG_MOUSE_DOWN. * * When the move/resize is initiated by the menu, we let the user * stop it by clicking with the mouse. Which is why we don't want * a mouse down to affect the window. */ return; /* Convert point to global coordinates for easier calculations. */ global_x = event->x + w->x; global_y = event->y + w->y; /* Clamp the point to the dialog's client area. */ global_y = CLAMP (global_y, h->y + 1, h->y + h->lines - 2); /* Status line, buttonbar */ global_x = CLAMP (global_x, h->x, h->x + h->cols - 1); /* Currently a no-op, as the dialog has no left/right margins. */ if (edit->drag_state == MCEDIT_DRAG_MOVE) { w->y = global_y; w->x = global_x - edit->drag_state_start; } else if (edit->drag_state == MCEDIT_DRAG_RESIZE) { w->lines = MAX (WINDOW_MIN_LINES, global_y - w->y + 1); w->cols = MAX (WINDOW_MIN_COLS, global_x - w->x + 1); } edit->force |= REDRAW_COMPLETELY; /* Not really needed as WEdit's MSG_DRAW already does this. */ /* We draw the whole dialog because dragging/resizing exposes area beneath. */ dlg_redraw (w->owner); }
static int task_cb (WButton * button, int action) { TaskList *tl; int sig = 0; (void) button; if (bg_list->list == NULL) return 0; /* Get this instance information */ listbox_get_current (bg_list, NULL, (void **) &tl); #ifdef SIGTSTP if (action == B_STOP) { sig = SIGSTOP; tl->state = Task_Stopped; } else if (action == B_RESUME) { sig = SIGCONT; tl->state = Task_Running; } else #endif if (action == B_KILL) { sig = SIGKILL; } if (sig == SIGKILL) unregister_task_running (tl->pid, tl->fd); kill (tl->pid, sig); listbox_remove_list (bg_list); jobs_fill_listbox (); /* This can be optimized to just redraw this widget :-) */ dlg_redraw (jobs_dlg); return 0; }
gboolean edit_add_window (WDialog * h, int y, int x, int lines, int cols, const vfs_path_t * f, long fline) { WEdit *edit; Widget *w; edit = edit_init (NULL, y, x, lines, cols, f, fline); if (edit == NULL) return FALSE; w = WIDGET (edit); w->callback = edit_callback; w->mouse = edit_event; add_widget (h, w); dlg_redraw (h); return TRUE; }
gboolean edit_add_window (Dlg_head * h, int y, int x, int lines, int cols, const vfs_path_t * f, long fline) { WEdit *edit; Widget *w; edit = edit_init (NULL, y, x, lines, cols, f, fline); if (edit == NULL) return FALSE; w = (Widget *) edit; w->callback = edit_callback; w->mouse = edit_event; widget_want_cursor (*w, TRUE); add_widget (h, w); dlg_redraw (h); return TRUE; }
static void viewer_size_changed (GtkWidget *widget, guint cols, guint lines, WView *view) { widget_set_size (&view->widget, 0, 0, lines, cols); dlg_redraw (view->widget.parent); }
static int edit_event (Gpm_Event * event, void *data) { WEdit *edit = (WEdit *) data; Widget *w = WIDGET (data); Gpm_Event local; if (!mouse_global_in_widget (event, w)) return MOU_UNHANDLED; local = mouse_get_local (event, w); /* Unknown event type */ if ((event->type & (GPM_DOWN | GPM_DRAG | GPM_UP)) == 0) return MOU_NORMAL; dlg_set_top_widget (w); edit_update_curs_row (edit); edit_update_curs_col (edit); if (edit->fullscreen || (local.buttons & GPM_B_LEFT) == 0 || (local.type & GPM_UP) != 0) edit->drag_state = MCEDIT_DRAG_NORMAL; else if (local.y == 1 && edit->drag_state != MCEDIT_DRAG_RESIZE) { /* click on the top line (move) */ int dx = edit->fullscreen ? 0 : 2; if (local.x == w->cols - dx - 1) { send_message (w->owner, NULL, MSG_ACTION, CK_Close, NULL); return MOU_NORMAL; } if (local.x == w->cols - dx - 4) { edit_toggle_fullscreen (edit); return MOU_NORMAL; } if ((local.type & (GPM_DOWN | GPM_DRAG)) != 0) { /* move if not fullscreen */ edit->drag_state_start = local.x; edit->drag_state = MCEDIT_DRAG_MOVE; edit->force |= REDRAW_COMPLETELY; edit_update_screen (edit); } } else if (!edit->fullscreen && local.y == w->lines && local.x == w->cols) { /* click on bottom-right corner (resize) */ if ((local.type & (GPM_DOWN | GPM_DRAG)) != 0) { edit->drag_state = MCEDIT_DRAG_RESIZE; edit->force |= REDRAW_COMPLETELY; edit_update_screen (edit); } } if (edit->drag_state == MCEDIT_DRAG_NORMAL) { gboolean done = TRUE; /* Double click */ if ((local.type & (GPM_DOUBLE | GPM_UP)) == (GPM_UP | GPM_DOUBLE)) { edit_mark_current_word_cmd (edit); goto update; } #if 0 /* Triple click */ if ((local.type & (GPM_TRIPLE | GPM_UP)) == (GPM_UP | GPM_TRIPLE)) { edit_mark_current_line_cmd (edit); goto update; } #endif /* Wheel events */ if ((local.buttons & GPM_B_UP) != 0 && (local.type & GPM_DOWN) != 0) { edit_move_up (edit, 2, 1); goto update; } if ((local.buttons & GPM_B_DOWN) != 0 && (local.type & GPM_DOWN) != 0) { edit_move_down (edit, 2, 1); goto update; } /* continue handle current event */ goto cont; /* handle DRAG mouse event, don't use standard way to continue * event handling outside of widget */ do { int c; c = tty_get_event (event, FALSE, TRUE); if (c == EV_NONE || c != EV_MOUSE) break; local = mouse_get_local (event, w); cont: /* A lone up mustn't do anything */ if (edit->mark2 != -1 && (local.type & (GPM_UP | GPM_DRAG)) != 0) return MOU_NORMAL; if ((local.type & (GPM_DOWN | GPM_UP)) != 0) edit_push_key_press (edit); if (!edit->fullscreen) local.x--; if (!option_cursor_beyond_eol) edit->prev_col = local.x - edit->start_col - option_line_state_width - 1; else { long line_len; line_len = edit_move_forward3 (edit, edit_buffer_get_current_bol (&edit->buffer), 0, edit_buffer_get_current_eol (&edit->buffer)); if (local.x > line_len) { edit->over_col = local.x - line_len - edit->start_col - option_line_state_width - 1; edit->prev_col = line_len; } else { edit->over_col = 0; edit->prev_col = local.x - option_line_state_width - edit->start_col - 1; } } if (!edit->fullscreen) local.y--; if (local.y > (edit->curs_row + 1)) edit_move_down (edit, local.y - (edit->curs_row + 1), 0); else if (local.y < (edit->curs_row + 1)) edit_move_up (edit, (edit->curs_row + 1) - local.y, 0); else edit_move_to_prev_col (edit, edit_buffer_get_current_bol (&edit->buffer)); if ((local.type & GPM_DOWN) != 0) { edit_mark_cmd (edit, TRUE); /* reset */ edit->highlight = 0; } done = (local.type & GPM_DRAG) == 0; if (done) edit_mark_cmd (edit, FALSE); update: edit_find_bracket (edit); edit->force |= REDRAW_COMPLETELY; edit_update_curs_row (edit); edit_update_curs_col (edit); edit_update_screen (edit); } while (!edit->fullscreen && !done); } else while (edit->drag_state != MCEDIT_DRAG_NORMAL) { int c; int y; c = tty_get_event (event, FALSE, TRUE); y = event->y - 1; if (c == EV_NONE || c != EV_MOUSE) { /* redraw frame */ edit->drag_state = MCEDIT_DRAG_NORMAL; edit->force |= REDRAW_COMPLETELY; edit_update_screen (edit); } else if (y == w->y && (event->type & (GPM_DOUBLE | GPM_UP)) == (GPM_DOUBLE | GPM_UP)) { /* double click on top line (toggle fullscreen) */ edit_toggle_fullscreen (edit); edit->drag_state = MCEDIT_DRAG_NORMAL; edit->force |= REDRAW_COMPLETELY; edit_update_screen (edit); } else if ((event->type & (GPM_DRAG | GPM_DOWN)) == 0) { /* redraw frame */ edit->drag_state = MCEDIT_DRAG_NORMAL; edit->force |= REDRAW_COMPLETELY; edit_update_screen (edit); } else if (!edit->fullscreen) { Widget *h = WIDGET (w->owner); if (edit->drag_state == MCEDIT_DRAG_MOVE) { int x = event->x - 1; y = max (y, h->y + 1); /* status line */ y = min (y, h->y + h->lines - 2); /* buttonbar */ x = max (x, h->x); x = min (x, h->x + h->cols - 1); /* don't use widget_set_size() here to avoid double draw */ w->y = y; w->x = x - edit->drag_state_start; edit->force |= REDRAW_COMPLETELY; } else if (edit->drag_state == MCEDIT_DRAG_RESIZE) { event->y = min (event->y, h->y + h->lines - 1); /* buttonbar */ event->x = min (event->x, h->x + h->cols); local = mouse_get_local (event, w); /* don't use widget_set_size() here to avoid double draw */ w->lines = max (WINDOW_MIN_LINES, local.y); w->cols = max (WINDOW_MIN_COLS, local.x); edit->force |= REDRAW_COMPLETELY; } dlg_redraw (w->owner); } } return MOU_NORMAL; }