WTree * tree_new (int y, int x, int lines, int cols, gboolean is_panel) { WTree *tree; Widget *w; tree = g_new (WTree, 1); w = WIDGET (tree); widget_init (w, y, x, lines, cols, tree_callback, tree_event); tree->is_panel = is_panel; tree->selected_ptr = 0; tree->store = tree_store_get (); tree_store_add_entry_remove_hook (remove_callback, tree); tree->tree_shown = 0; tree->search_buffer[0] = 0; tree->topdiff = w->lines / 2; tree->searching = 0; tree->active = 0; /* We do not want to keep the cursor */ widget_want_cursor (w, FALSE); load_tree (tree); return tree; }
int edit_file (const char *_file, int line) { static gboolean made_directory = FALSE; Dlg_head *edit_dlg; WEdit *wedit; WMenuBar *menubar; if (!made_directory) { char *dir = concat_dir_and_file (mc_config_get_cache_path (), EDIT_DIR); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); g_free (dir); dir = concat_dir_and_file (mc_config_get_path (), EDIT_DIR); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); g_free (dir); dir = concat_dir_and_file (mc_config_get_data_path (), EDIT_DIR); made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST); g_free (dir); } wedit = edit_init (NULL, 1, 0, LINES - 2, COLS, _file, line); if (wedit == NULL) return 0; /* Create a new dialog and add it widgets to it */ edit_dlg = create_dlg (FALSE, 0, 0, LINES, COLS, NULL, edit_dialog_callback, "[Internal File Editor]", NULL, DLG_WANT_TAB); edit_dlg->get_shortcut = edit_get_shortcut; edit_dlg->get_title = edit_get_title; menubar = menubar_new (0, 0, COLS, NULL); add_widget (edit_dlg, menubar); edit_init_menu (menubar); init_widget (&wedit->widget, wedit->widget.y, wedit->widget.x, wedit->widget.lines, wedit->widget.cols, edit_callback, edit_event); widget_want_cursor (wedit->widget, TRUE); add_widget (edit_dlg, wedit); add_widget (edit_dlg, buttonbar_new (TRUE)); run_dlg (edit_dlg); if (edit_dlg->state == DLG_CLOSED) destroy_dlg (edit_dlg); return 1; }
static Widget * mousedispatch_new (int y, int x, int yl, int xl) { Widget *w; w = g_new0 (Widget, 1); widget_init (w, y, x, yl, xl, md_callback, help_mouse_callback); widget_want_cursor (w, TRUE); return w; }
void mcview_toggle_hex_mode (mcview_t * view) { view->hex_mode = !view->hex_mode; if (view->hex_mode) { view->hex_cursor = view->dpy_start; view->dpy_start = mcview_offset_rounddown (view->dpy_start, view->bytes_per_line); widget_want_cursor (WIDGET (view), TRUE); } else { view->dpy_start = mcview_bol (view, view->hex_cursor, 0); view->hex_cursor = view->dpy_start; widget_want_cursor (WIDGET (view), FALSE); } mcview_altered_hex_mode = 1; view->dpy_bbar_dirty = TRUE; view->dirty++; }
WMenuBar * menubar_new (int y, int x, int cols, GList * menu) { WMenuBar *menubar; menubar = g_new0 (WMenuBar, 1); init_widget (&menubar->widget, y, x, 1, cols, menubar_callback, menubar_event); widget_want_cursor (menubar->widget, FALSE); menubar->is_visible = TRUE; /* by default */ menubar_set_menu (menubar, menu); return menubar; }
WButtonBar * buttonbar_new (gboolean visible) { WButtonBar *bb; bb = g_new0 (WButtonBar, 1); init_widget (&bb->widget, LINES - 1, 0, 1, COLS, buttonbar_callback, buttonbar_event); bb->widget.pos_flags = WPOS_KEEP_HORZ | WPOS_KEEP_BOTTOM; bb->visible = visible; widget_want_hotkey (bb->widget, 1); widget_want_cursor (bb->widget, 0); return bb; }
WHLine * hline_new (int y, int x, int width) { WHLine *l; int lines = 1; l = g_new (WHLine, 1); init_widget (&l->widget, y, x, lines, width, hline_callback, NULL); l->auto_adjust_cols = (width < 0); l->transparent = FALSE; widget_want_cursor (l->widget, FALSE); widget_want_hotkey (l->widget, FALSE); return l; }
WMenuBar * menubar_new (int y, int x, int cols, GList * menu, gboolean visible) { WMenuBar *menubar; Widget *w; menubar = g_new0 (WMenuBar, 1); w = WIDGET (menubar); widget_init (w, y, x, 1, cols, menubar_callback, menubar_event); menubar->is_visible = visible; widget_want_cursor (w, FALSE); menubar_set_menu (menubar, menu); return menubar; }
WCheck * check_new (int y, int x, int state, const char *text) { WCheck *c; Widget *w; c = g_new (WCheck, 1); w = WIDGET (c); c->text = parse_hotkey (text); /* 4 is width of "[X] " */ widget_init (w, y, x, 1, 4 + hotkey_width (c->text), check_callback, check_mouse_callback); c->state = state ? C_BOOL : 0; widget_want_cursor (w, TRUE); widget_want_hotkey (w, TRUE); return c; }
WButtonBar * buttonbar_new (gboolean visible) { WButtonBar *bb; Widget *w; bb = g_new0 (WButtonBar, 1); w = WIDGET (bb); widget_init (w, LINES - 1, 0, 1, COLS, buttonbar_callback, buttonbar_event); w->pos_flags = WPOS_KEEP_HORZ | WPOS_KEEP_BOTTOM; bb->visible = visible; widget_want_hotkey (w, TRUE); widget_want_cursor (w, FALSE); return bb; }
WHLine * hline_new (int y, int x, int width) { WHLine *l; Widget *w; int lines = 1; l = g_new (WHLine, 1); w = WIDGET (l); widget_init (w, y, x, lines, width < 0 ? 1 : width, hline_callback, NULL); l->text = NULL; l->auto_adjust_cols = (width < 0); l->transparent = FALSE; widget_want_cursor (w, FALSE); widget_want_hotkey (w, FALSE); return l; }
WGroupbox * groupbox_new (int y, int x, int height, int width, const char *title) { WGroupbox *g; Widget *w; g = g_new (WGroupbox, 1); w = WIDGET (g); widget_init (w, y, x, height, width, groupbox_callback, NULL); widget_want_cursor (w, FALSE); widget_want_hotkey (w, FALSE); g->title = NULL; groupbox_set_title (g, title); return g; }
WDialog * dlg_create (gboolean modal, int y1, int x1, int lines, int cols, const int *colors, widget_cb_fn callback, mouse_h mouse_handler, const char *help_ctx, const char *title, dlg_flags_t flags) { WDialog *new_d; Widget *w; new_d = g_new0 (WDialog, 1); w = WIDGET (new_d); widget_init (w, y1, x1, lines, cols, (callback != NULL) ? callback : dlg_default_callback, 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->flags = flags; new_d->data = NULL; dlg_set_size (new_d, lines, cols); new_d->fullscreen = (w->x == 0 && w->y == 0 && w->cols == COLS && w->lines == LINES); new_d->mouse_status = MOU_UNHANDLED; /* Strip existing spaces, add one space before and after the title */ if (title != NULL && *title != '\0') { char *t; t = g_strstrip (g_strdup (title)); if (*t != '\0') new_d->title = g_strdup_printf (" %s ", t); g_free (t); } /* unique name got event group for this dialog */ new_d->event_group = g_strdup_printf ("%s_%p", MCEVENT_GROUP_DIALOG, (void *) new_d); return new_d; }
WGauge * gauge_new (int y, int x, gboolean shown, int max, int current) { WGauge *g; g = g_new (WGauge, 1); init_widget (&g->widget, y, x, 1, gauge_len, gauge_callback, NULL); g->shown = shown; if (max == 0) max = 1; /* I do not like division by zero :) */ g->max = max; g->current = current; g->from_left_to_right = TRUE; widget_want_cursor (g->widget, FALSE); widget_want_hotkey (g->widget, FALSE); return g; }
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; }
WLabel * label_new (int y, int x, const char *text) { WLabel *l; int cols = 1; int lines = 1; if (text != NULL) str_msg_term_size (text, &lines, &cols); l = g_new (WLabel, 1); init_widget (&l->widget, y, x, lines, cols, label_callback, NULL); l->text = g_strdup (text); l->auto_adjust_cols = TRUE; l->transparent = FALSE; widget_want_cursor (l->widget, FALSE); widget_want_hotkey (l->widget, FALSE); return l; }
int xdiff_view (const char *file1, const char *file2) { int error; WDiff *view; WButtonBar *bar; Dlg_head *view_dlg; /* Create dialog and widgets, put them on the dialog */ view_dlg = create_dlg(0, 0, LINES, COLS, NULL, view_dialog_callback, "[Binary Diff Viewer]", NULL, DLG_WANT_TAB); view = g_new0(WDiff, 1); init_widget(&view->widget, 0, 0, LINES - 1, COLS, (callback_fn)view_callback, (mouse_h)view_event); widget_want_cursor(view->widget, 0); bar = buttonbar_new(1); add_widget(view_dlg, bar); add_widget(view_dlg, view); error = view_init(view, file1, file2); /* Please note that if you add another widget, * you have to modify view_adjust_size to * be aware of it */ if (!error) { run_dlg(view_dlg); view_search(view, -1); view_fini(view, 1); } destroy_dlg(view_dlg); return error; }
WGauge * gauge_new (int y, int x, int cols, gboolean shown, int max, int current) { WGauge *g; Widget *w; g = g_new (WGauge, 1); w = WIDGET (g); widget_init (w, y, x, 1, cols, gauge_callback, NULL); widget_want_cursor (w, FALSE); widget_want_hotkey (w, FALSE); g->shown = shown; if (max == 0) max = 1; /* I do not like division by zero :) */ g->max = max; g->current = current; g->from_left_to_right = TRUE; return g; }
WTree * tree_new (int is_panel, int y, int x, int lines, int cols) { WTree *tree = g_new (WTree, 1); init_widget (&tree->widget, y, x, lines, cols, tree_callback, event_callback); tree->is_panel = is_panel; tree->selected_ptr = 0; tree->store = tree_store_get (); tree_store_add_entry_remove_hook (remove_callback, tree); tree->tree_shown = 0; tree->search_buffer[0] = 0; tree->topdiff = tree->widget.lines / 2; tree->searching = 0; tree->active = 0; /* We do not want to keep the cursor */ widget_want_cursor (tree->widget, 0); load_tree (tree); return tree; }
WGroupbox * groupbox_new (int y, int x, int height, int width, const char *title) { WGroupbox *g; g = g_new (WGroupbox, 1); init_widget (&g->widget, y, x, height, width, groupbox_callback, NULL); widget_want_cursor (g->widget, FALSE); widget_want_hotkey (g->widget, FALSE); /* Strip existing spaces, add one space before and after the title */ if (title != NULL) { char *t; t = g_strstrip (g_strdup (title)); g->title = g_strconcat (" ", t, " ", (char *) NULL); g_free (t); } return g; }
WListbox * listbox_new (int y, int x, int height, int width, gboolean deletable, lcback_fn callback) { WListbox *l; Widget *w; if (height <= 0) height = 1; l = g_new (WListbox, 1); w = WIDGET (l); widget_init (w, y, x, height, width, listbox_callback, listbox_event); l->list = NULL; l->top = l->pos = 0; l->deletable = deletable; l->callback = callback; l->allow_duplicates = TRUE; l->scrollbar = !mc_global.tty.slow_terminal; widget_want_hotkey (w, TRUE); widget_want_cursor (w, FALSE); return l; }