Browse Source

Add toggle fullscreen mode of editor windows.

Initially, window is created in fullscreen mode.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Andrew Borodin 13 years ago
parent
commit
2bb6cb2a32

+ 1 - 0
lib/keybind.c

@@ -314,6 +314,7 @@ static name_keymap_t command_names[] = {
     {"ExecuteScript", CK_PipeBlock (0)},
     {"WindowMove", CK_WindowMove},
     {"WindowResize", CK_WindowResize},
+    {"WindowFullscreen", CK_WindowFullscreen},
     {"WindowList", CK_WindowList},
     {"WindowNext", CK_WindowNext},
     {"WindowPrev", CK_WindowPrev},

+ 1 - 0
lib/keybind.h

@@ -282,6 +282,7 @@ enum
     /* window commands */
     CK_WindowMove,
     CK_WindowResize,
+    CK_WindowFullscreen,
     CK_WindowList,
     CK_WindowNext,
     CK_WindowPrev,

+ 1 - 0
misc/mc.keymap.default

@@ -340,6 +340,7 @@ OptionsSaveMode =
 LearnKeys =
 WindowMove =
 WindowResize =
+WindowFullscreen =
 WindowList =
 WindowNext =
 WindowPrev =

+ 1 - 0
misc/mc.keymap.emacs

@@ -340,6 +340,7 @@ OptionsSaveMode =
 LearnKeys =
 WindowMove =
 WindowResize =
+WindowFullscreen =
 WindowList =
 WindowNext =
 WindowPrev =

+ 1 - 0
src/editor/edit-impl.h

@@ -264,6 +264,7 @@ void edit_execute_key_command (WEdit * edit, unsigned long command, int char_for
 void edit_update_screen (WEdit * edit);
 void edit_save_size (WEdit * edit);
 gboolean edit_handle_move_resize (WEdit * edit, unsigned long command);
+void edit_toggle_fullscreen (WEdit * edit);
 void edit_move_to_line (WEdit * e, long line);
 void edit_move_display (WEdit * e, long line);
 void edit_word_wrap (WEdit * edit);

+ 7 - 0
src/editor/edit.c

@@ -2219,6 +2219,7 @@ edit_init (WEdit * edit, int y, int x, int lines, int cols, const vfs_path_t * f
     edit->widget.lines = lines;
     edit->widget.cols = cols;
     edit_save_size (edit);
+    edit->fullscreen = TRUE;
 
     edit->stat1.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
     edit->stat1.st_uid = getuid ();
@@ -3450,6 +3451,12 @@ edit_execute_key_command (WEdit * edit, unsigned long command, int char_for_inse
 void
 edit_execute_cmd (WEdit * edit, unsigned long command, int char_for_insertion)
 {
+    if (EDIT_WITH_FRAME && command == CK_WindowFullscreen)
+    {
+        edit_toggle_fullscreen (edit);
+        return;
+    }
+
     /* handle window state */
     if (edit_handle_move_resize (edit, command))
         return;

+ 27 - 8
src/editor/editdraw.c

@@ -193,13 +193,16 @@ print_to_widget (WEdit * edit, long row, int start_col, int start_col_real,
     struct line_s *p;
 
     int x = start_col_real;
-    int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET + EDIT_WITH_FRAME + option_line_state_width;
+    int x1 = start_col + EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
     int y = row + EDIT_TEXT_VERTICAL_OFFSET + EDIT_WITH_FRAME;
     int cols_to_skip = abs (x);
     int i;
     int wrap_start;
     int len;
 
+    if (EDIT_WITH_FRAME && !edit->fullscreen)
+        x1++;
+
     tty_setcolor (EDITOR_NORMAL_COLOR);
     if (bookmarked != 0)
         tty_setcolor (bookmarked);
@@ -327,7 +330,15 @@ edit_draw_this_line (WEdit * edit, long b, long row, long start_col, long end_co
     else
         abn_style = MOD_ABNORMAL;
 
-    end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + 2 * EDIT_WITH_FRAME + option_line_state_width;
+    end_col -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
+    if (EDIT_WITH_FRAME && !edit->fullscreen)
+    {
+        const Widget *w = (const Widget *) edit;
+
+        end_col--;
+        if (w->x + w->cols <= w->owner->cols)
+            end_col--;
+    }
 
     edit_get_syntax_color (edit, b - 1, &color);
     q = edit_move_forward3 (edit, b, start_col - edit->start_col, 0);
@@ -889,14 +900,14 @@ edit_info_status (WEdit * edit)
             fname = _(fname);
 #endif
 
-        edit_move (2, 0);
+        edit_move (edit->fullscreen ? 0 : 2, 0);
         tty_printf ("[%s]", str_term_trim (fname, edit->widget.cols - 8 - 6));
         g_free (full_fname);
     }
 
     if (cols > 13)
     {
-        edit_move (edit->widget.cols - 8, 0);
+        edit_move (edit->widget.cols - (edit->fullscreen ? 6 : 8), 0);
         tty_printf ("[%c%c%c%c]",
                     edit->mark1 != edit->mark2 ? (edit->column_highlight ? 'C' : 'B') : '-',
                     edit->modified ? 'M' : '-',
@@ -962,8 +973,12 @@ edit_scroll_screen_over_cursor (WEdit * edit)
 
     edit->widget.y += EDIT_WITH_FRAME;
     edit->widget.lines -= EDIT_TEXT_VERTICAL_OFFSET + 2 * EDIT_WITH_FRAME;
-    edit->widget.x += EDIT_WITH_FRAME;
-    edit->widget.cols -= EDIT_TEXT_HORIZONTAL_OFFSET + 2 * EDIT_WITH_FRAME + option_line_state_width;
+    edit->widget.cols -= EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
+    if (EDIT_WITH_FRAME && !edit->fullscreen)
+    {
+        edit->widget.x++;
+        edit->widget.cols -= 2;
+    }
 
     r_extreme = EDIT_RIGHT_EXTREME;
     l_extreme = EDIT_LEFT_EXTREME;
@@ -1013,8 +1028,12 @@ edit_scroll_screen_over_cursor (WEdit * edit)
 
     edit->widget.y -= EDIT_WITH_FRAME;
     edit->widget.lines += EDIT_TEXT_VERTICAL_OFFSET + 2 * EDIT_WITH_FRAME;
-    edit->widget.x -= EDIT_WITH_FRAME;
-    edit->widget.cols += EDIT_TEXT_HORIZONTAL_OFFSET + 2 * EDIT_WITH_FRAME + option_line_state_width;
+    edit->widget.cols += EDIT_TEXT_HORIZONTAL_OFFSET + option_line_state_width;
+    if (EDIT_WITH_FRAME && !edit->fullscreen)
+    {
+        edit->widget.x--;
+        edit->widget.cols += 2;
+    }
 }
 
 /* --------------------------------------------------------------------------------------------- */

+ 2 - 0
src/editor/editmenu.c

@@ -216,6 +216,8 @@ create_window_menu (void)
 
     entries = g_list_prepend (entries, menu_entry_create (_("&Move"), CK_WindowMove));
     entries = g_list_prepend (entries, menu_entry_create (_("&Resize"), CK_WindowResize));
+    entries =
+        g_list_prepend (entries, menu_entry_create (_("&Toggle fullscreen"), CK_WindowFullscreen));
     entries = g_list_prepend (entries, menu_separator_create ());
     entries = g_list_prepend (entries, menu_entry_create (_("&Next"), CK_WindowNext));
     entries = g_list_prepend (entries, menu_entry_create (_("&Previous"), CK_WindowPrev));

+ 105 - 14
src/editor/editwidget.c

@@ -142,6 +142,53 @@ edit_help (void)
     mc_event_raise (MCEVENT_GROUP_CORE, "help", &event_data);
 }
 
+/* --------------------------------------------------------------------------------------------- */
+
+static void
+edit_draw_frame (const WEdit * edit)
+{
+    const Widget *w = (const Widget *) edit;
+
+    tty_setcolor (EDITOR_NORMAL_COLOR);
+
+    if (edit->fullscreen)
+    {
+        /* draw lines at top and bottom */
+        tty_draw_hline (w->y, w->x, ACS_HLINE, w->cols);
+        tty_draw_hline (w->y + w->lines - 1, w->x, ACS_HLINE, w->cols);
+    }
+    else
+    {
+        /* draw a frame around edit area */
+        tty_draw_box (w->y, w->x, w->lines, w->cols, TRUE);
+    }
+}
+
+/* --------------------------------------------------------------------------------------------- */
+/**
+ * Callback for the iteration of objects in the 'editors' array.
+ * Resize the editor window.
+ *
+ * @param data      probably WEdit object
+ * @param user_data unused
+ */
+
+static void
+edit_dialog_resize_cb (void *data, void *user_data)
+{
+    Widget *w = (Widget *) data;
+
+    (void) user_data;
+
+    if (edit_widget_is_editor (w) && ((WEdit *) w)->fullscreen)
+    {
+        Dlg_head *h = w->owner;
+
+        w->lines = h->lines - 2;
+        w->cols = h->cols;
+    }
+}
+
 /* --------------------------------------------------------------------------------------------- */
 /**
  * Restore saved window size.
@@ -369,11 +416,11 @@ edit_event (Gpm_Event * event, void *data)
         if ((local.type & GPM_DOWN) != 0)
             edit->drag_state_start = local.x;
 
-        /* moving */
+        /* move if not fullscreen */
         if ((local.type & (GPM_DOWN | GPM_DRAG)) != 0)
             edit->drag_state = MCEDIT_DRAG_MOVE;
     }
-    else if (local.y == w->lines && local.x == w->cols)
+    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)
@@ -433,7 +480,8 @@ edit_event (Gpm_Event * event, void *data)
             if ((local.type & (GPM_DOWN | GPM_UP)) != 0)
                 edit_push_key_press (edit);
 
-            local.x--;
+            if (!edit->fullscreen)
+                local.x--;
             if (!option_cursor_beyond_eol)
                 edit->prev_col = local.x - edit->start_col - option_line_state_width - 1;
             else
@@ -486,8 +534,10 @@ edit_event (Gpm_Event * event, void *data)
         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)
             {
@@ -496,13 +546,20 @@ edit_event (Gpm_Event * event, void *data)
                 edit->force |= REDRAW_COMPLETELY;
                 edit_update_screen (edit);
             }
-            else
+            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;
+            }
+            else if ((event->type & (GPM_DRAG | GPM_DOWN)) == 0)
+                edit->drag_state = MCEDIT_DRAG_NORMAL;
+            else if (!edit->fullscreen)
             {
                 Dlg_head *h = w->owner;
 
                 if (edit->drag_state == MCEDIT_DRAG_MOVE)
                 {
-                    int y = event->y - 1;
                     int x = event->x - 1;
 
                     y = max (y, h->y + 1);      /* status line */
@@ -713,6 +770,7 @@ edit_dialog_callback (Dlg_head * h, Widget * sender, dlg_msg_t msg, int parm, vo
         widget_set_size (&buttonbar->widget, h->lines - 1, h->x, 1, h->cols);
         widget_set_size (&menubar->widget, h->y, h->x, 1, h->cols);
         menubar_arrange (menubar);
+        g_list_foreach (h->widgets, (GFunc) edit_dialog_resize_cb, NULL);
         return MSG_HANDLED;
 
     case DLG_ACTION:
@@ -824,10 +882,15 @@ edit_callback (Widget * w, widget_msg_t msg, int parm)
         return MSG_HANDLED;
 
     case WIDGET_CURSOR:
-        widget_move (w, e->curs_row + EDIT_TEXT_VERTICAL_OFFSET + EDIT_WITH_FRAME,
-                     e->curs_col + e->start_col + e->over_col +
-                     EDIT_TEXT_HORIZONTAL_OFFSET + EDIT_WITH_FRAME + option_line_state_width);
-        return MSG_HANDLED;
+        {
+            int x = (EDIT_WITH_FRAME && !e->fullscreen) ? 1 : 0;
+
+            x += e->curs_col + e->start_col + e->over_col + EDIT_TEXT_HORIZONTAL_OFFSET +
+                 option_line_state_width;
+
+            widget_move (w, e->curs_row + EDIT_TEXT_VERTICAL_OFFSET + EDIT_WITH_FRAME, x);
+            return MSG_HANDLED;
+        }
 
     case WIDGET_DESTROY:
         edit_clean (e);
@@ -936,11 +999,7 @@ edit_update_screen (WEdit * e)
     else
     {
         if ((e->force & REDRAW_COMPLETELY) != 0)
-        {
-            /* draw a frame around edit area */
-            tty_setcolor (EDITOR_NORMAL_COLOR);
-            tty_draw_box (e->widget.y, e->widget.x, e->widget.lines, e->widget.cols, TRUE);
-        }
+            edit_draw_frame (e);
 
         edit_info_status (e);
     }
@@ -1024,6 +1083,12 @@ edit_handle_move_resize (WEdit * edit, unsigned long command)
 {
     gboolean ret = FALSE;
 
+    if (edit->fullscreen)
+    {
+        edit->drag_state = MCEDIT_DRAG_NORMAL;
+        return ret;
+    }
+
     switch (edit->drag_state)
     {
     case MCEDIT_DRAG_NORMAL:
@@ -1096,3 +1161,29 @@ edit_handle_move_resize (WEdit * edit, unsigned long command)
 }
 
 /* --------------------------------------------------------------------------------------------- */
+/**
+ * Toggle window fuulscreen mode.
+ *
+ * @param edit editor object
+ */
+
+void
+edit_toggle_fullscreen (WEdit * edit)
+{
+    Dlg_head *h = ((Widget *) edit)->owner;
+
+    edit->fullscreen = !edit->fullscreen;
+    edit->force = REDRAW_COMPLETELY;
+
+    if (!edit->fullscreen)
+        edit_restore_size (edit);
+    else
+    {
+        edit_save_size (edit);
+        widget_set_size ((Widget *) edit, h->y + 1, h->x, h->lines - 2, h->cols);
+        edit->force |= REDRAW_PAGE;
+        edit_update_screen (edit);
+    }
+}
+
+/* --------------------------------------------------------------------------------------------- */

+ 2 - 1
src/editor/editwidget.h

@@ -64,7 +64,7 @@ struct WEdit
     mcedit_drag_state_t drag_state;
     int drag_state_start;       /* save cursor position before window moving */
 
-    /* save location before move/resize */
+    /* save location before move/resize or toggle to fullscreen */
     int x_prev, y_prev;
     int cols_prev, lines_prev;
 
@@ -109,6 +109,7 @@ struct WEdit
     unsigned int highlight:1;   /* There is a selected block */
     unsigned int column_highlight:1;
     unsigned int utf8:1;        /* It's multibyte file codeset */
+    unsigned int fullscreen:1;  /* Is window fullscreen or not */
     long prev_col;              /* recent column position of the cursor - used when moving
                                    up or down past lines that are shorter than the current line */
     long curs_line;             /* line number of the cursor. */