Exemple #1
0
void
tty_draw_box (int y, int x, int ys, int xs, gboolean single)
{
    int y2, x2;

    if (ys <= 0 || xs <= 0)
        return;

    ys--;
    xs--;

    y2 = y + ys;
    x2 = x + xs;

    tty_draw_vline (y, x, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT], ys);
    tty_draw_vline (y, x2, mc_tty_frm[single ? MC_TTY_FRM_VERT : MC_TTY_FRM_DVERT], ys);
    tty_draw_hline (y, x, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ], xs);
    tty_draw_hline (y2, x, mc_tty_frm[single ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ], xs);
    tty_gotoyx (y, x);
    tty_print_alt_char (ACS_ULCORNER, single);
    tty_gotoyx (y2, x);
    tty_print_alt_char (ACS_LLCORNER, single);
    tty_gotoyx (y, x2);
    tty_print_alt_char (ACS_URCORNER, single);
    tty_gotoyx (y2, x2);
    tty_print_alt_char (ACS_LRCORNER, single);
}
Exemple #2
0
static void
menubar_paint_idx (WMenuBar * menubar, unsigned int idx, int color)
{
    const Menu *menu = g_list_nth_data (menubar->menu, menubar->selected);
    const menu_entry_t *entry = g_list_nth_data (menu->entries, idx);
    const int y = 2 + idx;
    int x = menu->start_x;

    if (x + menu->max_entry_len + 4 > (gsize) menubar->widget.cols)
        x = menubar->widget.cols - menu->max_entry_len - 4;

    if (entry == NULL)
    {
        /* menu separator */
        tty_setcolor (MENU_ENTRY_COLOR);

        widget_move (&menubar->widget, y, x - 1);
        tty_print_alt_char (ACS_LTEE, FALSE);

        tty_draw_hline (menubar->widget.y + y, menubar->widget.x + x,
                        ACS_HLINE, menu->max_entry_len + 3);

        widget_move (&menubar->widget, y, x + menu->max_entry_len + 3);
        tty_print_alt_char (ACS_RTEE, FALSE);
    }
    else
    {
        int yt, xt;

        /* menu text */
        tty_setcolor (color);
        widget_move (&menubar->widget, y, x);
        tty_print_char ((unsigned char) entry->first_letter);
        tty_getyx (&yt, &xt);
        tty_draw_hline (yt, xt, ' ', menu->max_entry_len + 2);  /* clear line */
        tty_print_string (entry->text.start);

        if (entry->text.hotkey != NULL)
        {
            tty_setcolor (color == MENU_SELECTED_COLOR ? MENU_HOTSEL_COLOR : MENU_HOT_COLOR);
            tty_print_string (entry->text.hotkey);
            tty_setcolor (color);
        }

        if (entry->text.end != NULL)
            tty_print_string (entry->text.end);

        if (entry->shortcut != NULL)
        {
            widget_move (&menubar->widget, y, x + menu->max_hotkey_len + 3);
            tty_print_string (entry->shortcut);
        }

        /* move cursor to the start of entry text */
        widget_move (&menubar->widget, y, x + 1);
    }
}
Exemple #3
0
static void
tree_frame (WDialog * h, WTree * tree)
{
    Widget *w = WIDGET (tree);

    (void) h;

    tty_setcolor (NORMAL_COLOR);
    widget_erase (w);
    if (tree->is_panel)
    {
        const char *title = _("Directory tree");
        const int len = str_term_width1 (title);

        tty_draw_box (w->y, w->x, w->lines, w->cols, FALSE);

        widget_move (w, 0, (w->cols - len - 2) / 2);
        tty_printf (" %s ", title);

        if (panels_options.show_mini_info)
        {
            int y;

            y = w->lines - 3;
            widget_move (w, y, 0);
            tty_print_alt_char (ACS_LTEE, FALSE);
            widget_move (w, y, w->cols - 1);
            tty_print_alt_char (ACS_RTEE, FALSE);
            tty_draw_hline (w->y + y, w->x + 1, ACS_HLINE, w->cols - 2);
        }
    }
}
Exemple #4
0
static void tree_show_mini_info (WTree *tree, int tree_lines, int tree_cols)
{
    Dlg_head *h = tree->widget.parent;
    int      line;

    /* Show mini info */
    if (tree->is_panel){
	if (!show_mini_info)
	    return;
	line = tree_lines+2;
    } else
	line = tree_lines+1;

    tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols);
    widget_move (&tree->widget, line, 1);

    if (tree->searching){
	/* Show search string */
	tty_setcolor (TREE_NORMALC (h));
	tty_setcolor (DLG_FOCUSC (h));
	tty_print_char (PATH_SEP);

	tty_print_string (str_fit_to_term (tree->search_buffer, 
		tree_cols - 2, J_LEFT_FIT));
	tty_print_char (' ');
	tty_setcolor (DLG_FOCUSC (h));
    } else {
	/* Show full name of selected directory */
	tty_print_string (str_fit_to_term (tree->selected_ptr->name, 
		tree_cols, J_LEFT_FIT));
    }
}
Exemple #5
0
static void
tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols)
{
    Dlg_head *h = tree->widget.owner;
    int line;

    /* Show mini info */
    if (tree->is_panel)
    {
        if (!panels_options.show_mini_info)
            return;
        line = tree_lines + 2;
    }
    else
        line = tree_lines + 1;

    if (tree->searching)
    {
        /* Show search string */
        tty_setcolor (INPUT_COLOR);
        tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols);
        widget_move (&tree->widget, line, 1);
        tty_print_char (PATH_SEP);
        tty_print_string (str_fit_to_term (tree->search_buffer, tree_cols - 2, J_LEFT_FIT));
        tty_print_char (' ');
    }
    else
    {
        /* Show full name of selected directory */
        char *tmp_path;

        tty_setcolor (tree->is_panel ? NORMAL_COLOR : TREE_NORMALC (h));
        tty_draw_hline (tree->widget.y + line, tree->widget.x + 1, ' ', tree_cols);
        widget_move (&tree->widget, line, 1);
        tmp_path = vfs_path_to_str (tree->selected_ptr->name);
        tty_print_string (str_fit_to_term (tmp_path, tree_cols, J_LEFT_FIT));
        g_free (tmp_path);
    }
}
Exemple #6
0
static void
tree_show_mini_info (WTree * tree, int tree_lines, int tree_cols)
{
    Widget *w = WIDGET (tree);
    int line;

    /* Show mini info */
    if (tree->is_panel)
    {
        if (!panels_options.show_mini_info)
            return;
        line = tree_lines + 2;
    }
    else
        line = tree_lines + 1;

    if (tree->searching)
    {
        /* Show search string */
        tty_setcolor (INPUT_COLOR);
        tty_draw_hline (w->y + line, w->x + 1, ' ', tree_cols);
        widget_move (w, line, 1);
        tty_print_char (PATH_SEP);
        tty_print_string (str_fit_to_term (tree->search_buffer, tree_cols - 2, J_LEFT_FIT));
        tty_print_char (' ');
    }
    else
    {
        /* Show full name of selected directory */
        WDialog *h = w->owner;

        tty_setcolor (tree->is_panel ? NORMAL_COLOR : TREE_NORMALC (h));
        tty_draw_hline (w->y + line, w->x + 1, ' ', tree_cols);
        widget_move (w, line, 1);
        tty_print_string (str_fit_to_term
                          (vfs_path_as_str (tree->selected_ptr->name), tree_cols, J_LEFT_FIT));
    }
}
Exemple #7
0
static cb_ret_t
hline_callback (Widget * w, widget_msg_t msg, int parm)
{
    WHLine *l = (WHLine *) w;
    Dlg_head *h = l->widget.owner;

    switch (msg)
    {
    case WIDGET_INIT:
    case WIDGET_RESIZED:
        if (l->auto_adjust_cols)
        {
            if (((w->owner->flags & DLG_COMPACT) != 0))
            {
                w->x = w->owner->x;
                w->cols = w->owner->cols;
            }
            else
            {
                w->x = w->owner->x + 1;
                w->cols = w->owner->cols - 2;
            }
        }

    case WIDGET_FOCUS:
        /* We don't want to get the focus */
        return MSG_NOT_HANDLED;

    case WIDGET_DRAW:
        if (l->transparent)
            tty_setcolor (DEFAULT_COLOR);
        else
            tty_setcolor (h->color[DLG_COLOR_NORMAL]);

        tty_draw_hline (w->y, w->x + 1, ACS_HLINE, w->cols - 2);

        if (l->auto_adjust_cols)
        {
            widget_move (w, 0, 0);
            tty_print_alt_char (ACS_LTEE, FALSE);
            widget_move (w, 0, w->cols - 1);
            tty_print_alt_char (ACS_RTEE, FALSE);
        }
        return MSG_HANDLED;

    default:
        return default_proc (msg, parm);
    }
}
Exemple #8
0
static void
tree_frame (Dlg_head *h, WTree *tree)
{
    tty_setcolor (NORMAL_COLOR);
    widget_erase ((Widget*) tree);
    if (tree->is_panel) {
	draw_box (h, tree->widget.y, tree->widget.x, tree->widget.lines,
		     tree->widget.cols);

	if (show_mini_info)
	    tty_draw_hline (tree->widget.y + tlines (tree) + 1,
			    tree->widget.x + 1,
			    ACS_HLINE, tree->widget.cols - 2);
    }
}
Exemple #9
0
static void
mcview_display_status (WView * view)
{
    const screen_dimen top = view->status_area.top;
    const screen_dimen left = view->status_area.left;
    const screen_dimen width = view->status_area.width;
    const screen_dimen height = view->status_area.height;
    const char *file_label;

    if (height < 1)
        return;

    tty_setcolor (STATUSBAR_COLOR);
    tty_draw_hline (WIDGET (view)->y + top, WIDGET (view)->x + left, ' ', width);

    file_label =
        view->filename_vpath != NULL ?
        vfs_path_get_last_path_str (view->filename_vpath) : view->command != NULL ?
        view->command : "";

    if (width > 40)
    {
        widget_move (view, top, width - 32);
        if (view->hex_mode)
            tty_printf ("0x%08" PRIxMAX, (uintmax_t) view->hex_cursor);
        else
        {
            char buffer[BUF_TRUNC_LEN + 1];

            size_trunc_len (buffer, BUF_TRUNC_LEN, mcview_get_filesize (view), 0,
                            panels_options.kilobyte_si);
            tty_printf ("%9" PRIuMAX "/%s%s %s", (uintmax_t) view->dpy_end,
                        buffer, mcview_may_still_grow (view) ? "+" : " ",
#ifdef HAVE_CHARSET
                        mc_global.source_codepage >= 0 ?
                        get_codepage_id (mc_global.source_codepage) :
#endif
                        "");
        }
    }
    widget_move (view, top, left);
    if (width > 40)
        tty_print_string (str_fit_to_term (file_label, width - 34, J_LEFT_FIT));
    else
        tty_print_string (str_fit_to_term (file_label, width - 5, J_LEFT_FIT));
    if (width > 26)
        mcview_display_percent (view, view->hex_mode ? view->hex_cursor : view->dpy_end);
}
Exemple #10
0
static void
mcview_display_status (mcview_t * view)
{
    const screen_dimen top = view->status_area.top;
    const screen_dimen left = view->status_area.left;
    const screen_dimen width = view->status_area.width;
    const screen_dimen height = view->status_area.height;
    const char *file_label;
    screen_dimen file_label_width;

    if (height < 1)
        return;

    tty_setcolor (STATUSBAR_COLOR);
    widget_move (view, top, left);
    tty_draw_hline (-1, -1, ' ', width);

    file_label = view->filename ? view->filename : view->command ? view->command : "";
    file_label_width = str_term_width1 (file_label) - 2;
    if (width > 40)
    {
        char buffer[BUF_TINY];
        widget_move (view, top, width - 32);
        if (view->hex_mode)
            tty_printf ("0x%08" PRIxMAX, (uintmax_t) view->hex_cursor);
        else
        {
            size_trunc_len (buffer, 5, mcview_get_filesize (view), 0, panels_options.kilobyte_si);
            tty_printf ("%9" PRIuMAX "/%s%s %s", (uintmax_t) view->dpy_end,
                        buffer, mcview_may_still_grow (view) ? "+" : " ",
#ifdef HAVE_CHARSET
                        mc_global.source_codepage >=
                        0 ? get_codepage_id (mc_global.source_codepage) : ""
#else
                        ""
#endif
                );
        }
    }
    widget_move (view, top, left);
    if (width > 40)
        tty_print_string (str_fit_to_term (file_label, width - 34, J_LEFT_FIT));
    else
        tty_print_string (str_fit_to_term (file_label, width - 5, J_LEFT_FIT));
    if (width > 26)
        mcview_percent (view, view->hex_mode ? view->hex_cursor : view->dpy_end);
}
Exemple #11
0
static void
menubar_draw (WMenuBar * menubar)
{
    Widget *w = WIDGET (menubar);
    GList *i;

    /* First draw the complete menubar */
    tty_setcolor (menubar->is_active ? MENU_ENTRY_COLOR : MENU_INACTIVE_COLOR);
    tty_draw_hline (w->y, w->x, ' ', w->cols);

    /* Now each one of the entries */
    for (i = menubar->menu; i != NULL; i = g_list_next (i))
    {
        menu_t *menu = MENU (i->data);
        gboolean is_selected = (menubar->selected == (gsize) g_list_position (menubar->menu, i));

        menubar_set_color (menubar, is_selected, FALSE);
        widget_move (w, 0, menu->start_x);

        tty_print_char (' ');
        tty_print_string (menu->text.start);

        if (menu->text.hotkey != NULL)
        {
            menubar_set_color (menubar, is_selected, TRUE);
            tty_print_string (menu->text.hotkey);
            menubar_set_color (menubar, is_selected, FALSE);
        }

        if (menu->text.end != NULL)
            tty_print_string (menu->text.end);

        tty_print_char (' ');
    }

    if (menubar->is_dropped)
        menubar_draw_drop (menubar);
    else
        widget_move (w, 0, MENU (g_list_nth_data (menubar->menu, menubar->selected))->start_x);
}
Exemple #12
0
static void
tree_frame (Dlg_head * h, WTree * tree)
{
    tty_setcolor (NORMAL_COLOR);
    widget_erase ((Widget *) tree);
    if (tree->is_panel)
    {
        const char *title = _("Directory tree");
        const int len = str_term_width1 (title);

        draw_box (h, tree->widget.y, tree->widget.x, tree->widget.lines, tree->widget.cols, FALSE);

        widget_move (&tree->widget, 0, (tree->widget.cols - len - 2) / 2);
        tty_printf (" %s ", title);

        if (panels_options.show_mini_info)
            widget_move (&tree->widget, tlines (tree) + 1, 0);
        tty_print_alt_char (ACS_LTEE, FALSE);
        widget_move (&tree->widget, tlines (tree) + 1, tree->widget.cols - 1);
        tty_print_alt_char (ACS_RTEE, FALSE);
        tty_draw_hline (tree->widget.y + tlines (tree) + 1,
                        tree->widget.x + 1, ACS_HLINE, tree->widget.cols - 2);
    }
}
Exemple #13
0
static inline void
print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
                 long end_col, struct line_s line[], char *status, int bookmarked)
{
    struct line_s *p;

    int x = start_col_real;
    int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
    int y = row + EDIT_TEXT_VERTICAL_OFFSET;
    int cols_to_skip = abs (x);
    int i;
    int wrap_start;
    int len;

    tty_setcolor (EDITOR_NORMAL_COLOR);
    if (bookmarked != 0)
        tty_setcolor (bookmarked);

    len = end_col + 1 - start_col;
    wrap_start = option_word_wrap_line_length + edit->start_col;

    if (len > 0 && edit->widget.y + y >= 0)
    {
        if (!show_right_margin || wrap_start > end_col)
            tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len);
        else if (wrap_start < 0)
        {
            tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
            tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', len);
        }
        else
        {
            if (wrap_start > 0)
                tty_draw_hline (edit->widget.y + y, edit->widget.x + x1, ' ', wrap_start);

            len -= wrap_start;
            if (len > 0)
            {
                tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
                tty_draw_hline (edit->widget.y + y, edit->widget.x + x1 + wrap_start, ' ', len);
            }
        }
    }

    if (option_line_state)
    {
        tty_setcolor (LINE_STATE_COLOR);
        for (i = 0; i < LINE_STATE_WIDTH; i++)
        {
            edit_move (x1 + i - option_line_state_width, y);
            if (status[i] == '\0')
                status[i] = ' ';
            tty_print_char (status[i]);
        }
    }

    edit_move (x1, y);
    p = line;
    i = 1;
    while (p->ch)
    {
        int style;
        unsigned int textchar;
        int color;

        if (cols_to_skip)
        {
            p++;
            cols_to_skip--;
            continue;
        }

        style = p->style & 0xFF00;
        textchar = p->ch;
        color = p->style >> 16;

        if (style & MOD_ABNORMAL)
        {
            /* Non-printable - use black background */
            color = 0;
        }

        if (style & MOD_WHITESPACE)
        {
            if (style & MOD_MARKED)
            {
                textchar = ' ';
                tty_setcolor (EDITOR_MARKED_COLOR);
            }
            else
            {
#if 0
                if (color != EDITOR_NORMAL_COLOR)
                {
                    textchar = ' ';
                    tty_lowlevel_setcolor (color);
                }
                else
#endif
                    tty_setcolor (EDITOR_WHITESPACE_COLOR);
            }
        }
        else
        {
            if (style & MOD_BOLD)
            {
                tty_setcolor (EDITOR_BOLD_COLOR);
            }
            else if (style & MOD_MARKED)
            {
                tty_setcolor (EDITOR_MARKED_COLOR);
            }
            else
            {
                tty_lowlevel_setcolor (color);
            }
        }
        if (show_right_margin)
        {
            if (i > option_word_wrap_line_length + edit->start_col)
                tty_setcolor (EDITOR_RIGHT_MARGIN_COLOR);
            i++;
        }
        tty_print_anychar (textchar);
        p++;
    }
}
Exemple #14
0
static cb_ret_t
hline_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WHLine *l = HLINE (w);
    WDialog *h = w->owner;

    switch (msg)
    {
    case MSG_INIT:
    case MSG_RESIZE:
        if (l->auto_adjust_cols)
        {
            Widget *wo = WIDGET (h);

            if (((h->flags & DLG_COMPACT) != 0))
            {
                w->x = wo->x;
                w->cols = wo->cols;
            }
            else
            {
                w->x = wo->x + 1;
                w->cols = wo->cols - 2;
            }
        }
        return MSG_HANDLED;

    case MSG_FOCUS:
        /* We don't want to get the focus */
        return MSG_NOT_HANDLED;

    case MSG_DRAW:
        if (l->transparent)
            tty_setcolor (DEFAULT_COLOR);
        else
            tty_setcolor (h->color[DLG_COLOR_NORMAL]);

        tty_draw_hline (w->y, w->x + 1, ACS_HLINE, w->cols - 2);

        if (l->auto_adjust_cols)
        {
            widget_move (w, 0, 0);
            tty_print_alt_char (ACS_LTEE, FALSE);
            widget_move (w, 0, w->cols - 1);
            tty_print_alt_char (ACS_RTEE, FALSE);
        }

        if (l->text != NULL)
        {
            int text_width;

            text_width = str_term_width1 (l->text);
            widget_move (w, 0, (w->cols - text_width) / 2);
            tty_print_string (l->text);
        }
        return MSG_HANDLED;

    case MSG_DESTROY:
        g_free (l->text);
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}
Exemple #15
0
static void
show_tree (WTree * tree)
{
    Widget *w = WIDGET (tree);
    WDialog *h = w->owner;
    tree_entry *current;
    int i, j, topsublevel;
    int x = 0, y = 0;
    int tree_lines, tree_cols;

    /* Initialize */
    tree_lines = tlines (tree);
    tree_cols = w->cols;

    widget_move (w, y, x);
    if (tree->is_panel)
    {
        tree_cols -= 2;
        x = y = 1;
    }

    g_free (tree->tree_shown);
    tree->tree_shown = g_new0 (tree_entry *, tree_lines);

    if (tree->store->tree_first)
        topsublevel = tree->store->tree_first->sublevel;
    else
        topsublevel = 0;
    if (!tree->selected_ptr)
    {
        tree->selected_ptr = tree->store->tree_first;
        tree->topdiff = 0;
    }
    current = tree->selected_ptr;

    /* Calculate the directory which is to be shown on the topmost line */
    if (!tree_navigation_flag)
        current = back_ptr (current, &tree->topdiff);
    else
    {
        i = 0;
        while (current->prev && i < tree->topdiff)
        {
            current = current->prev;

            if (current->sublevel < tree->selected_ptr->sublevel)
            {
                if (vfs_path_equal (current->name, tree->selected_ptr->name))
                    i++;
            }
            else if (current->sublevel == tree->selected_ptr->sublevel)
            {
                const char *cname;

                cname = vfs_path_as_str (current->name);
                for (j = strlen (cname) - 1; !IS_PATH_SEP (cname[j]); j--)
                    ;
                if (vfs_path_equal_len (current->name, tree->selected_ptr->name, j))
                    i++;
            }
            else if (current->sublevel == tree->selected_ptr->sublevel + 1)
            {
                j = vfs_path_len (tree->selected_ptr->name);
                if (j > 1 && vfs_path_equal_len (current->name, tree->selected_ptr->name, j))
                    i++;
            }
        }
        tree->topdiff = i;
    }

    /* Loop for every line */
    for (i = 0; i < tree_lines; i++)
    {
        tty_setcolor (tree->is_panel ? NORMAL_COLOR : TREE_NORMALC (h));

        /* Move to the beginning of the line */
        tty_draw_hline (w->y + y + i, w->x + x, ' ', tree_cols);

        if (current == NULL)
            continue;

        if (tree->is_panel)
            tty_setcolor (widget_get_state (w, WST_FOCUSED) && current == tree->selected_ptr
                          ? SELECTED_COLOR : NORMAL_COLOR);
        else
            tty_setcolor (current == tree->selected_ptr ? TREE_CURRENTC (h) : TREE_NORMALC (h));

        tree->tree_shown[i] = current;
        if (current->sublevel == topsublevel)
            /* Show full name */
            tty_print_string (str_fit_to_term
                              (vfs_path_as_str (current->name),
                               tree_cols + (tree->is_panel ? 0 : 1), J_LEFT_FIT));
        else
        {
            /* Sub level directory */
            tty_set_alt_charset (TRUE);

            /* Output branch parts */
            for (j = 0; j < current->sublevel - topsublevel - 1; j++)
            {
                if (tree_cols - 8 - 3 * j < 9)
                    break;
                tty_print_char (' ');
                if (current->submask & (1 << (j + topsublevel + 1)))
                    tty_print_char (ACS_VLINE);
                else
                    tty_print_char (' ');
                tty_print_char (' ');
            }
            tty_print_char (' ');
            j++;
            if (!current->next || !(current->next->submask & (1 << current->sublevel)))
                tty_print_char (ACS_LLCORNER);
            else
                tty_print_char (ACS_LTEE);
            tty_print_char (ACS_HLINE);
            tty_set_alt_charset (FALSE);

            /* Show sub-name */
            tty_print_char (' ');
            tty_print_string (str_fit_to_term
                              (current->subname, tree_cols - x - 3 * j, J_LEFT_FIT));
        }

        /* Calculate the next value for current */
        current = current->next;
        if (tree_navigation_flag)
        {
            while (current != NULL)
            {
                if (current->sublevel < tree->selected_ptr->sublevel)
                {
                    if (vfs_path_equal_len (current->name, tree->selected_ptr->name,
                                            vfs_path_len (current->name)))
                        break;
                }
                else if (current->sublevel == tree->selected_ptr->sublevel)
                {
                    const char *cname;

                    cname = vfs_path_as_str (current->name);
                    for (j = strlen (cname) - 1; !IS_PATH_SEP (cname[j]); j--)
                        ;
                    if (vfs_path_equal_len (current->name, tree->selected_ptr->name, j))
                        break;
                }
                else if (current->sublevel == tree->selected_ptr->sublevel + 1
                         && vfs_path_len (tree->selected_ptr->name) > 1)
                {
                    if (vfs_path_equal_len (current->name, tree->selected_ptr->name,
                                            vfs_path_len (tree->selected_ptr->name)))
                        break;
                }
                current = current->next;
            }
        }
    }

    tree_show_mini_info (tree, tree_lines, tree_cols);
}
Exemple #16
0
static void show_tree (WTree *tree)
{
    Dlg_head *h = tree->widget.parent;
    tree_entry *current;
    int i, j, topsublevel;
    int x, y;
    int tree_lines, tree_cols;

    /* Initialize */
    x = y = 0;
    tree_lines = tlines (tree);
    tree_cols  = tree->widget.cols;

    tty_setcolor (TREE_NORMALC (h));
    widget_move ((Widget*)tree, y, x);
    if (tree->is_panel){
	tree_cols  -= 2;
	x = y = 1;
    }

    g_free (tree->tree_shown);
    tree->tree_shown = g_new (tree_entry*, tree_lines);

    for (i = 0; i < tree_lines; i++)
	tree->tree_shown [i] = NULL;
    if (tree->store->tree_first)
	topsublevel = tree->store->tree_first->sublevel;
    else
	topsublevel = 0;
    if (!tree->selected_ptr){
	tree->selected_ptr = tree->store->tree_first;
	tree->topdiff = 0;
    }
    current = tree->selected_ptr;

    /* Calculate the directory which is to be shown on the topmost line */
    if (tree_navigation_flag){
	i = 0;
	while (current->prev && i < tree->topdiff){
	    current = current->prev;
	    if (current->sublevel < tree->selected_ptr->sublevel){
		if (strncmp (current->name, tree->selected_ptr->name,
			     strlen (current->name)) == 0)
		    i++;
	    } else if (current->sublevel == tree->selected_ptr->sublevel){
		for (j = strlen (current->name) - 1; current->name [j] != PATH_SEP; j--);
		if (strncmp (current->name, tree->selected_ptr->name, j) == 0)
		    i++;
	    } else if (current->sublevel == tree->selected_ptr->sublevel + 1
		       && strlen (tree->selected_ptr->name) > 1){
		if (strncmp (current->name, tree->selected_ptr->name,
			     strlen (tree->selected_ptr->name)) == 0)
		    i++;
	    }
	}
	tree->topdiff = i;
    } else
	current = back_ptr (current, &tree->topdiff);

    /* Loop for every line */
    for (i = 0; i < tree_lines; i++){
	/* Move to the beginning of the line */
	tty_draw_hline (tree->widget.y + y + i, tree->widget.x + x, ' ', tree_cols);

	if (!current)
	    continue;

	tree->tree_shown [i] = current;
	if (current->sublevel == topsublevel){

	    /* Top level directory */
	    if (tree->active && current == tree->selected_ptr) {
		if (!tty_use_colors () && !tree->is_panel)
			tty_setcolor (MARKED_COLOR);
		else
			tty_setcolor (SELECTED_COLOR);
	    }

	    /* Show full name */
	    tty_print_string (str_fit_to_term (current->name, tree_cols - 6, J_LEFT_FIT));
	} else{
	    /* Sub level directory */

	    tty_set_alt_charset (TRUE);
	    /* Output branch parts */
	    for (j = 0; j < current->sublevel - topsublevel - 1; j++){
		if (tree_cols - 8 - 3 * j < 9)
		    break;
		tty_print_char (' ');
		if (current->submask & (1 << (j + topsublevel + 1)))
		    tty_print_char (ACS_VLINE);
		else
		    tty_print_char (' ');
		tty_print_char (' ');
	    }
	    tty_print_char (' '); j++;
	    if (!current->next || !(current->next->submask & (1 << current->sublevel)))
		tty_print_char (ACS_LLCORNER);
	    else
		tty_print_char (ACS_LTEE);
	    tty_print_char (ACS_HLINE);
	    tty_set_alt_charset (FALSE);

	    if (tree->active && current == tree->selected_ptr) {
		/* Selected directory -> change color */
		if (!tty_use_colors () && !tree->is_panel)
		    tty_setcolor (MARKED_COLOR);
		else
		    tty_setcolor (SELECTED_COLOR);
	    }

	    /* Show sub-name */
	    tty_print_char (' ');
	    tty_print_string (str_fit_to_term (current->subname, 
		    tree_cols - 2 - 4 - 3 * j, J_LEFT_FIT));
	}
	tty_print_char (' ');

	/* Return to normal color */
	tty_setcolor (TREE_NORMALC (h));

	/* Calculate the next value for current */
	current = current->next;
	if (tree_navigation_flag){
	    while (current){
		if (current->sublevel < tree->selected_ptr->sublevel){
		    if (strncmp (current->name, tree->selected_ptr->name,
				 strlen (current->name)) == 0)
			break;
		} else if (current->sublevel == tree->selected_ptr->sublevel){
		    for (j = strlen (current->name) - 1; current->name [j] != PATH_SEP; j--);
		    if (strncmp (current->name,tree->selected_ptr->name,j)== 0)
			break;
		} else if (current->sublevel == tree->selected_ptr->sublevel+1
			   && strlen (tree->selected_ptr->name) > 1){
		    if (strncmp (current->name, tree->selected_ptr->name,
				 strlen (tree->selected_ptr->name)) == 0)
			break;
		}
		current = current->next;
	    }
	}
    }
    tree_show_mini_info (tree, tree_lines, tree_cols);
}
Exemple #17
0
static cb_ret_t
radio_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data)
{
    WRadio *r = RADIO (w);
    int i;

    switch (msg)
    {
    case MSG_HOTKEY:
        {
            for (i = 0; i < r->count; i++)
            {
                if (r->texts[i].hotkey != NULL)
                {
                    int c = g_ascii_tolower ((gchar) r->texts[i].hotkey[0]);

                    if (c != parm)
                        continue;
                    r->pos = i;

                    /* Take action */
                    send_message (w, sender, MSG_KEY, ' ', data);
                    return MSG_HANDLED;
                }
            }
        }
        return MSG_NOT_HANDLED;

    case MSG_KEY:
        switch (parm)
        {
        case ' ':
            r->sel = r->pos;
            send_message (w->owner, w, MSG_ACTION, 0, NULL);
            send_message (w, sender, MSG_FOCUS, ' ', data);
            return MSG_HANDLED;

        case KEY_UP:
        case KEY_LEFT:
            if (r->pos > 0)
            {
                r->pos--;
                return MSG_HANDLED;
            }
            return MSG_NOT_HANDLED;

        case KEY_DOWN:
        case KEY_RIGHT:
            if (r->count - 1 > r->pos)
            {
                r->pos++;
                return MSG_HANDLED;
            }
        }
        return MSG_NOT_HANDLED;

    case MSG_CURSOR:
        send_message (w->owner, w, MSG_ACTION, 0, NULL);
        send_message (w, sender, MSG_FOCUS, ' ', data);
        widget_move (r, r->pos, 1);
        return MSG_HANDLED;

    case MSG_UNFOCUS:
    case MSG_FOCUS:
    case MSG_DRAW:
        for (i = 0; i < r->count; i++)
        {
            const gboolean focused = (i == r->pos && msg == MSG_FOCUS);

            widget_selectcolor (w, focused, FALSE);
            widget_move (r, i, 0);
            tty_draw_hline (w->y + i, w->x, ' ', w->cols);
            tty_print_string ((r->sel == i) ? "(*) " : "( ) ");
            hotkey_draw (w, r->texts[i], focused);
        }
        return MSG_HANDLED;

    case MSG_DESTROY:
        for (i = 0; i < r->count; i++)
            release_hotkey (r->texts[i]);
        g_free (r->texts);
        return MSG_HANDLED;

    default:
        return widget_default_callback (w, sender, msg, parm, data);
    }
}