From ba79784948a679e8a1aef8e56648e3d460653caf Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Mon, 14 May 2012 22:36:39 +0400 Subject: [PATCH] Add icons to close window and toggle window state using mouse. Signed-off-by: Andrew Borodin --- misc/skins/dark.ini | 3 ++ misc/skins/darkfar.ini | 2 + misc/skins/default.ini | 2 + misc/skins/double-lines.ini | 2 + misc/skins/featured.ini | 3 ++ misc/skins/gotar.ini | 2 + misc/skins/mc46.ini | 2 + misc/skins/nicedark.ini | 3 ++ misc/skins/sand256.ini | 3 ++ misc/skins/xoria256.ini | 3 ++ src/editor/editdraw.c | 8 +++- src/editor/editwidget.c | 89 ++++++++++++++++++++++++++++++++++--- 12 files changed, 114 insertions(+), 8 deletions(-) diff --git a/misc/skins/dark.ini b/misc/skins/dark.ini index d15b215bc..4f58e8603 100644 --- a/misc/skins/dark.ini +++ b/misc/skins/dark.ini @@ -99,6 +99,8 @@ editframe=gray; editframeactive=lightgray; editframedrag=red; + window-state-char = ↕ + window-close-char = ✕ [viewer] viewbold=yellow;black @@ -146,3 +148,4 @@ last-horiz-char=» current-char=■ background-char=▒ + diff --git a/misc/skins/darkfar.ini b/misc/skins/darkfar.ini index 769c9692f..c05367120 100644 --- a/misc/skins/darkfar.ini +++ b/misc/skins/darkfar.ini @@ -99,6 +99,8 @@ editframe=gray; editframeactive=lightgray; editframedrag=white; + window-state-char = ↕ + window-close-char = × [viewer] viewbold=yellow;black diff --git a/misc/skins/default.ini b/misc/skins/default.ini index 34ebd799f..aaeb89856 100644 --- a/misc/skins/default.ini +++ b/misc/skins/default.ini @@ -107,6 +107,8 @@ # editframe=lightgray; editframeactive=white; editframedrag=green; + window-state-char = * + window-close-char = X [viewer] viewbold=yellow;blue diff --git a/misc/skins/double-lines.ini b/misc/skins/double-lines.ini index da4731755..8a4a8ecfd 100644 --- a/misc/skins/double-lines.ini +++ b/misc/skins/double-lines.ini @@ -106,6 +106,8 @@ # editframe= editframeactive=white; editframedrag=green; + window-state-char = * + window-close-char = X [viewer] viewbold=yellow;blue diff --git a/misc/skins/featured.ini b/misc/skins/featured.ini index 2d48ac35d..26d049f26 100644 --- a/misc/skins/featured.ini +++ b/misc/skins/featured.ini @@ -108,6 +108,8 @@ # editframe= editframeactive=lightgray; editframedrag=cyan; + window-state-char = ↕ + window-close-char = ✕ [viewer] viewbold=yellow;blue @@ -151,3 +153,4 @@ leftmiddle=├ rightmiddle=┤ cross=┼ + diff --git a/misc/skins/gotar.ini b/misc/skins/gotar.ini index 72f1c2185..1cc61c91e 100644 --- a/misc/skins/gotar.ini +++ b/misc/skins/gotar.ini @@ -103,6 +103,8 @@ # editframe= editframeactive=white; editframedrag=green; + window-state-char = * + window-close-char = X [viewer] viewbold=brightred;black diff --git a/misc/skins/mc46.ini b/misc/skins/mc46.ini index 66880d8c4..ce486df24 100644 --- a/misc/skins/mc46.ini +++ b/misc/skins/mc46.ini @@ -98,6 +98,8 @@ # editframe= editframeactive=lightgray; editframedrag=cyan; + window-state-char = * + window-close-char = X [viewer] viewbold=yellow;blue diff --git a/misc/skins/nicedark.ini b/misc/skins/nicedark.ini index f36822fc1..54233e941 100644 --- a/misc/skins/nicedark.ini +++ b/misc/skins/nicedark.ini @@ -106,6 +106,8 @@ editframe=gray; editframeactive=lightgray; editframedrag=brightblue; + window-state-char = ↕ + window-close-char = ✕ [viewer] viewbold=brown;blue @@ -138,3 +140,4 @@ history-show-list-sign = ^ filename-scroll-left-char = « filename-scroll-right-char = » + diff --git a/misc/skins/sand256.ini b/misc/skins/sand256.ini index c775eb03d..7f2a55ce6 100644 --- a/misc/skins/sand256.ini +++ b/misc/skins/sand256.ini @@ -163,6 +163,8 @@ editframe=rgb530; editframeactive=black; editframedrag=rgb400; + window-state-char = ↕ + window-close-char = ✕ [viewer] viewunderline=;;underline @@ -196,3 +198,4 @@ last-horiz-char=» current-char=■ background-char=▒ + diff --git a/misc/skins/xoria256.ini b/misc/skins/xoria256.ini index ff09b02fc..e4f68dda6 100644 --- a/misc/skins/xoria256.ini +++ b/misc/skins/xoria256.ini @@ -152,6 +152,8 @@ editframe=color244; editframeactive=color250; editframedrag=color73; + window-state-char = ↕ + window-close-char = ✕ [viewer] viewunderline=;;underline @@ -187,3 +189,4 @@ last-horiz-char=» current-char=■ background-char=▒ + diff --git a/src/editor/editdraw.c b/src/editor/editdraw.c index db6177a02..70aea1b61 100644 --- a/src/editor/editdraw.c +++ b/src/editor/editdraw.c @@ -881,6 +881,7 @@ edit_status (WEdit * edit) void edit_info_status (WEdit * edit) { + int y, x; int cols = edit->widget.cols; tty_setcolor (STATUSBAR_COLOR); @@ -905,9 +906,12 @@ edit_info_status (WEdit * edit) g_free (full_fname); } - if (cols > 13) + tty_getyx (&y, &x); + x -= edit->widget.x; + x += 4; + if (x + 6 <= cols - (edit->fullscreen ? 0 : 2) - 6) { - edit_move (edit->widget.cols - (edit->fullscreen ? 6 : 8), 0); + edit_move (x, 0); tty_printf ("[%c%c%c%c]", edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-', edit->modified ? 'M' : '-', diff --git a/src/editor/editwidget.c b/src/editor/editwidget.c index ec26cf058..ce2d5a18d 100644 --- a/src/editor/editwidget.c +++ b/src/editor/editwidget.c @@ -2,11 +2,12 @@ Editor initialisation and callback handler. Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006, - 2007,2011 + 2007, 2011, 2012 The Free Software Foundation, Inc. Written by: Paul Sheer, 1996, 1997 + Andrew Borodin 2012 This file is part of the Midnight Commander. @@ -47,7 +48,7 @@ #include "lib/tty/tty.h" /* LINES, COLS */ #include "lib/tty/key.h" /* is_idle() */ #include "lib/tty/color.h" /* tty_setcolor() */ -#include "lib/skin.h" /* EDITOR_NORMAL_COLOR */ +#include "lib/skin.h" #include "lib/strutil.h" /* str_term_trim() */ #include "lib/util.h" /* mc_build_filename() */ #include "lib/widget.h" @@ -67,15 +68,56 @@ /*** file scope macro definitions ****************************************************************/ #define WINDOW_MIN_LINES (2 + 2) -#define WINDOW_MIN_COLS (2 + LINE_STATE_WIDTH) +#define WINDOW_MIN_COLS (2 + LINE_STATE_WIDTH + 2) /*** file scope type declarations ****************************************************************/ /*** file scope variables ************************************************************************/ +static char *edit_window_state_char = NULL; +static char *edit_window_close_char = NULL; +static unsigned int edit_dlg_init_refcounter = 0; + /*** file scope functions ************************************************************************/ static cb_ret_t edit_callback (Widget * w, widget_msg_t msg, int parm); +static cb_ret_t edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, + void *data); + +/* --------------------------------------------------------------------------------------------- */ +/** + * Init the 'edit' subsystem + */ + +static void +edit_dlg_init (void) +{ + if (edit_dlg_init_refcounter == 0) + { + edit_window_state_char = mc_skin_get ("editor", "window-state-char", "*"); + edit_window_close_char = mc_skin_get ("editor", "window-close-char", "X"); + } + + edit_dlg_init_refcounter++; +} + +/* --------------------------------------------------------------------------------------------- */ +/** + * Deinit the 'edit' subsystem + */ + +static void +edit_dlg_deinit (void) +{ + if (edit_dlg_init_refcounter != 0) + edit_dlg_init_refcounter--; + + if (edit_dlg_init_refcounter == 0) + { + g_free (edit_window_state_char); + g_free (edit_window_close_char); + } +} /* --------------------------------------------------------------------------------------------- */ /** @@ -148,6 +190,12 @@ static void edit_draw_frame (const WEdit * edit, gboolean active) { const Widget *w = (const Widget *) edit; + int dx; + char tmp[17]; + int color; + + color = edit->drag_state != MCEDIT_DRAG_NORMAL ? EDITOR_FRAME_DRAG : active ? + EDITOR_FRAME_ACTIVE : EDITOR_FRAME; if (edit->fullscreen) { @@ -158,12 +206,12 @@ edit_draw_frame (const WEdit * edit, gboolean active) w->cols); tty_draw_hline (w->y + w->lines - 1, w->x, mc_tty_frm[!active ? MC_TTY_FRM_HORIZ : MC_TTY_FRM_DHORIZ], w->cols); + dx = 6; } else { /* draw a frame around edit area */ - tty_setcolor (edit->drag_state != MCEDIT_DRAG_NORMAL ? EDITOR_FRAME_DRAG : - active ? EDITOR_FRAME_ACTIVE : EDITOR_FRAME); + tty_setcolor (color); /* draw double frame for active window if skin supports that */ tty_draw_box (w->y, w->x, w->lines, w->cols, !active); /* draw a drag marker */ @@ -173,7 +221,14 @@ edit_draw_frame (const WEdit * edit, gboolean active) widget_move (w, w->lines - 1, w->cols - 1); tty_print_alt_char (ACS_LRCORNER, TRUE); } + dx = 8; } + + /* toggle fullscreen mode and close icons */ + tty_setcolor (color); + widget_move (w, 0, edit->widget.cols - dx); + g_snprintf (tmp, sizeof (tmp), "[%s][%s]", edit_window_state_char, edit_window_close_char); + tty_print_string (tmp); } /* --------------------------------------------------------------------------------------------- */ @@ -423,9 +478,23 @@ edit_event (Gpm_Event * event, void *data) else if (local.y == 1 && edit->drag_state != MCEDIT_DRAG_RESIZE) { /* click on the top line (move) */ - /* move if not fullscreen */ + int dx = edit->fullscreen ? 0 : 2; + + if (local.x == edit->widget.cols - dx - 1) + { + edit_dialog_callback (w->owner, NULL, DLG_ACTION, CK_Close, NULL); + return MOU_NORMAL; + } + + if (local.x == edit->widget.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; @@ -778,6 +847,10 @@ edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, vo switch (msg) { + case DLG_INIT: + edit_dlg_init (); + return MSG_HANDLED; + case DLG_DRAW: /* don't use common_dialog_repaint() -- we don't need a frame */ tty_setcolor (EDITOR_BACKGROUND); @@ -852,6 +925,10 @@ edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, vo edit_quit (h); return MSG_HANDLED; + case DLG_END: + edit_dlg_deinit (); + return MSG_HANDLED; + default: return default_dlg_callback (h, sender, msg, parm, data); }