Add icons to close window and toggle window state using mouse.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2012-05-14 22:36:39 +04:00
parent 4fa4e7568d
commit ba79784948
12 changed files with 114 additions and 8 deletions

View File

@ -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=

View File

@ -99,6 +99,8 @@
editframe=gray;
editframeactive=lightgray;
editframedrag=white;
window-state-char =
window-close-char = ×
[viewer]
viewbold=yellow;black

View File

@ -107,6 +107,8 @@
# editframe=lightgray;
editframeactive=white;
editframedrag=green;
window-state-char = *
window-close-char = X
[viewer]
viewbold=yellow;blue

View File

@ -106,6 +106,8 @@
# editframe=
editframeactive=white;
editframedrag=green;
window-state-char = *
window-close-char = X
[viewer]
viewbold=yellow;blue

View File

@ -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=

View File

@ -103,6 +103,8 @@
# editframe=
editframeactive=white;
editframedrag=green;
window-state-char = *
window-close-char = X
[viewer]
viewbold=brightred;black

View File

@ -98,6 +98,8 @@
# editframe=
editframeactive=lightgray;
editframedrag=cyan;
window-state-char = *
window-close-char = X
[viewer]
viewbold=yellow;blue

View File

@ -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 = »

View File

@ -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=

View File

@ -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=

View File

@ -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' : '-',

View File

@ -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 <aborodin@vmail.ru> 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);
}