2 Editor initialisation and callback handler.
4 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
6 The Free Software Foundation, Inc.
11 This file is part of the Midnight Commander.
13 The Midnight Commander is free software: you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation, either version 3 of the License,
16 or (at your option) any later version.
18 The Midnight Commander is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 * \brief Source: editor initialisation and callback handler
37 #include <sys/types.h>
45 #include "lib/global.h"
47 #include "lib/tty/tty.h" /* LINES, COLS */
48 #include "lib/tty/key.h" /* is_idle() */
49 #include "lib/tty/color.h" /* tty_setcolor() */
50 #include "lib/skin.h" /* EDITOR_NORMAL_COLOR */
51 #include "lib/strutil.h" /* str_term_trim() */
52 #include "lib/util.h" /* mc_build_filename() */
53 #include "lib/widget.h"
54 #include "lib/mcconfig.h"
55 #include "lib/event.h" /* mc_event_raise() */
57 #include "src/keybind-defaults.h"
58 #include "src/main.h" /* home_dir */
59 #include "src/filemanager/cmd.h" /* view_other_cmd(), save_setup_cmd() */
60 #include "src/learn.h" /* learn_keys() */
62 #include "edit-impl.h"
63 #include "editwidget.h"
65 /*** global variables ****************************************************************************/
67 /*** file scope macro definitions ****************************************************************/
69 #define WINDOW_MIN_LINES (2 + 2)
70 #define WINDOW_MIN_COLS (2 + LINE_STATE_WIDTH)
72 /*** file scope type declarations ****************************************************************/
74 /*** file scope variables ************************************************************************/
76 /*** file scope functions ************************************************************************/
78 static cb_ret_t
edit_callback (Widget
* w
, widget_msg_t msg
, int parm
);
80 /* --------------------------------------------------------------------------------------------- */
82 * Show info about editor
88 const char *header
= N_("About");
89 const char *button_name
= N_("&OK");
90 const char *const version
= "MCEdit " VERSION
;
93 int win_len
, version_len
, button_len
;
100 button_name
= _(button_name
);
103 button_len
= str_term_width1 (button_name
) + 5;
104 version_len
= str_term_width1 (version
);
106 g_snprintf (text
, sizeof (text
),
107 _("Copyright (C) 1996-2012 the Free Software Foundation\n\n"
108 " A user friendly text editor\n"
109 " written for the Midnight Commander"));
111 win_len
= str_term_width1 (header
);
112 win_len
= max (win_len
, version_len
);
113 win_len
= max (win_len
, button_len
);
115 /* count width and height of text */
116 str_msg_term_size (text
, &lines
, &cols
);
118 cols
= max (win_len
, cols
) + 6;
121 about_dlg
= create_dlg (TRUE
, 0, 0, lines
, cols
, dialog_colors
, NULL
, NULL
,
122 "[Internal File Editor]", header
, DLG_CENTER
| DLG_TRYUP
);
124 add_widget (about_dlg
, label_new (3, (cols
- version_len
) / 2, version
));
125 add_widget (about_dlg
, label_new (5, 3, text
));
126 add_widget (about_dlg
, button_new (lines
- 3, (cols
- button_len
) / 2,
127 B_ENTER
, NORMAL_BUTTON
, button_name
, NULL
));
130 destroy_dlg (about_dlg
);
133 /* --------------------------------------------------------------------------------------------- */
141 ev_help_t event_data
= { NULL
, "[Internal File Editor]" };
142 mc_event_raise (MCEVENT_GROUP_CORE
, "help", &event_data
);
145 /* --------------------------------------------------------------------------------------------- */
147 * Restore saved window size.
149 * @param edit editor object
153 edit_restore_size (WEdit
* edit
)
155 edit
->drag_state
= MCEDIT_DRAG_NORMAL
;
156 widget_set_size ((Widget
*) edit
, edit
->y_prev
, edit
->x_prev
,
157 edit
->lines_prev
, edit
->cols_prev
);
158 dlg_redraw (((Widget
*) edit
)->owner
);
161 /* --------------------------------------------------------------------------------------------- */
163 * Move window by one row or column in any direction.
165 * @param edit editor object
166 * @param command direction (CK_Up, CK_Down, CK_Left, CK_Right)
170 edit_window_move (WEdit
* edit
, unsigned long command
)
172 Widget
*w
= (Widget
*) edit
;
173 Dlg_head
*h
= w
->owner
;
178 if (w
->y
> h
->y
+ 1) /* menubar */
182 if (w
->y
< h
->y
+ h
->lines
- 2) /* buttonbar */
186 if (w
->x
+ w
->cols
> h
->x
)
190 if (w
->x
< h
->x
+ h
->cols
)
197 edit
->force
|= REDRAW_PAGE
;
201 /* --------------------------------------------------------------------------------------------- */
203 * Resize window by one row or column in any direction.
205 * @param edit editor object
206 * @param command direction (CK_Up, CK_Down, CK_Left, CK_Right)
210 edit_window_resize (WEdit
* edit
, unsigned long command
)
212 Widget
*w
= (Widget
*) edit
;
213 Dlg_head
*h
= w
->owner
;
218 if (w
->lines
> WINDOW_MIN_LINES
)
222 if (w
->y
+ w
->lines
< h
->y
+ h
->lines
- 1) /* buttonbar */
226 if (w
->cols
> WINDOW_MIN_COLS
)
230 if (w
->x
+ w
->cols
< h
->x
+ h
->cols
)
237 edit
->force
|= REDRAW_COMPLETELY
;
241 /* --------------------------------------------------------------------------------------------- */
246 return (n
<= 9) ? '0' + n
: 'a' + n
- 10;
249 /* --------------------------------------------------------------------------------------------- */
252 edit_window_list (const Dlg_head
* h
)
254 const size_t offset
= 2; /* skip menu and buttonbar */
255 const size_t dlg_num
= g_list_length (h
->widgets
) - offset
;
262 lines
= min ((size_t) (LINES
* 2 / 3), dlg_num
);
265 listbox
= create_listbox_window (lines
, cols
, _("Open files"), "[Open files]");
267 for (w
= h
->widgets
; w
!= NULL
; w
= g_list_next (w
))
268 if (edit_widget_is_editor ((Widget
*) w
->data
))
270 WEdit
*e
= (WEdit
*) w
->data
;
273 if (e
->filename_vpath
== NULL
)
274 fname
= g_strdup_printf ("%c [%s]", e
->modified
? '*' : ' ', _("NoName"));
279 fname2
= vfs_path_to_str (e
->filename_vpath
);
280 fname
= g_strdup_printf ("%c%s", e
->modified
? '*' : ' ', fname2
);
284 listbox_add_item (listbox
->list
, LISTBOX_APPEND_AT_END
, get_hotkey (i
++),
285 str_term_trim (fname
, listbox
->list
->widget
.cols
- 2), NULL
);
289 rv
= g_list_position (h
->widgets
, h
->current
) - offset
;
290 listbox_select_entry (listbox
->list
, rv
);
291 rv
= run_listbox (listbox
);
294 w
= g_list_nth (h
->widgets
, rv
+ offset
);
295 dlg_set_top_widget (w
->data
);
299 /* --------------------------------------------------------------------------------------------- */
302 edit_get_shortcut (unsigned long command
)
305 const char *shortcut
= NULL
;
307 shortcut
= keybind_lookup_keymap_shortcut (editor_map
, command
);
308 if (shortcut
!= NULL
)
309 return g_strdup (shortcut
);
311 ext_map
= keybind_lookup_keymap_shortcut (editor_map
, CK_ExtendedKeyMap
);
313 shortcut
= keybind_lookup_keymap_shortcut (editor_x_map
, command
);
314 if (shortcut
!= NULL
)
315 return g_strdup_printf ("%s %s", ext_map
, shortcut
);
320 /* --------------------------------------------------------------------------------------------- */
323 edit_get_title (const Dlg_head
* h
, size_t len
)
325 const WEdit
*edit
= find_editor (h
);
326 const char *modified
= edit
->modified
? "(*) " : " ";
327 const char *file_label
;
332 filename
= vfs_path_to_str (edit
->filename_vpath
);
333 file_label
= str_term_trim (filename
, len
- str_term_width1 (_("Edit: ")));
336 return g_strconcat (_("Edit: "), modified
, file_label
, (char *) NULL
);
339 /* --------------------------------------------------------------------------------------------- */
342 edit_event (Gpm_Event
* event
, void *data
)
344 WEdit
*edit
= (WEdit
*) data
;
345 Widget
*w
= (Widget
*) data
;
348 if (!mouse_global_in_widget (event
, w
))
349 return MOU_UNHANDLED
;
351 local
= mouse_get_local (event
, w
);
353 /* Unknown event type */
354 if ((event
->type
& (GPM_DOWN
| GPM_DRAG
| GPM_UP
)) == 0)
357 dlg_set_top_widget (w
);
359 edit_update_curs_row (edit
);
360 edit_update_curs_col (edit
);
362 if (!EDIT_WITH_FRAME
|| (local
.buttons
& GPM_B_LEFT
) == 0 || (local
.type
& GPM_UP
) != 0)
363 edit
->drag_state
= MCEDIT_DRAG_NORMAL
;
364 else if (local
.y
== 1 && edit
->drag_state
!= MCEDIT_DRAG_RESIZE
)
366 /* click on the top line (move) */
368 /* start move; save x coordinate of mouse */
369 if ((local
.type
& GPM_DOWN
) != 0)
370 edit
->drag_state_start
= local
.x
;
373 if ((local
.type
& (GPM_DOWN
| GPM_DRAG
)) != 0)
374 edit
->drag_state
= MCEDIT_DRAG_MOVE
;
376 else if (local
.y
== w
->lines
&& local
.x
== w
->cols
)
378 /* click on bottom-right corner (resize) */
379 if ((local
.type
& (GPM_DOWN
| GPM_DRAG
)) != 0)
380 edit
->drag_state
= MCEDIT_DRAG_RESIZE
;
383 if (edit
->drag_state
== MCEDIT_DRAG_NORMAL
)
385 gboolean done
= TRUE
;
388 if ((local
.type
& (GPM_DOUBLE
| GPM_UP
)) == (GPM_UP
| GPM_DOUBLE
))
390 edit_mark_current_word_cmd (edit
);
395 if ((local
.type
& (GPM_TRIPLE
| GPM_UP
)) == (GPM_UP
| GPM_TRIPLE
))
397 edit_mark_current_line_cmd (edit
);
402 if ((local
.buttons
& GPM_B_UP
) != 0 && (local
.type
& GPM_DOWN
) != 0)
404 edit_move_up (edit
, 2, 1);
407 if ((local
.buttons
& GPM_B_DOWN
) != 0 && (local
.type
& GPM_DOWN
) != 0)
409 edit_move_down (edit
, 2, 1);
413 /* continue handle current event */
416 /* handle DRAG mouse event, don't use standard way to continue
417 * event handling outside of widget */
422 c
= tty_get_event (event
, FALSE
, TRUE
);
423 if (c
== EV_NONE
|| c
!= EV_MOUSE
)
426 local
= mouse_get_local (event
, w
);
429 /* A lone up mustn't do anything */
430 if (edit
->mark2
!= -1 && (local
.type
& (GPM_UP
| GPM_DRAG
)) != 0)
433 if ((local
.type
& (GPM_DOWN
| GPM_UP
)) != 0)
434 edit_push_key_press (edit
);
437 if (!option_cursor_beyond_eol
)
438 edit
->prev_col
= local
.x
- edit
->start_col
- option_line_state_width
- 1;
441 long line_len
= edit_move_forward3 (edit
, edit_bol (edit
, edit
->curs1
), 0,
442 edit_eol (edit
, edit
->curs1
));
444 if (local
.x
> line_len
)
447 local
.x
- line_len
- edit
->start_col
- option_line_state_width
- 1;
448 edit
->prev_col
= line_len
;
453 edit
->prev_col
= local
.x
- option_line_state_width
- edit
->start_col
- 1;
459 if (local
.y
> (edit
->curs_row
+ 1))
460 edit_move_down (edit
, local
.y
- (edit
->curs_row
+ 1), 0);
461 else if (local
.y
< (edit
->curs_row
+ 1))
462 edit_move_up (edit
, (edit
->curs_row
+ 1) - local
.y
, 0);
464 edit_move_to_prev_col (edit
, edit_bol (edit
, edit
->curs1
));
466 if ((local
.type
& GPM_DOWN
) != 0)
468 edit_mark_cmd (edit
, 1); /* reset */
472 done
= (local
.type
& GPM_DRAG
) == 0;
474 edit_mark_cmd (edit
, 0);
477 edit_find_bracket (edit
);
478 edit
->force
|= REDRAW_COMPLETELY
;
479 edit_update_curs_row (edit
);
480 edit_update_curs_col (edit
);
481 edit_update_screen (edit
);
483 while (EDIT_WITH_FRAME
&& !done
);
486 while (edit
->drag_state
!= MCEDIT_DRAG_NORMAL
)
490 c
= tty_get_event (event
, FALSE
, TRUE
);
492 if (c
== EV_NONE
|| c
!= EV_MOUSE
)
495 edit
->drag_state
= MCEDIT_DRAG_NORMAL
;
496 edit
->force
|= REDRAW_COMPLETELY
;
497 edit_update_screen (edit
);
501 Dlg_head
*h
= w
->owner
;
503 if (edit
->drag_state
== MCEDIT_DRAG_MOVE
)
505 int y
= event
->y
- 1;
506 int x
= event
->x
- 1;
508 y
= max (y
, h
->y
+ 1); /* status line */
509 y
= min (y
, h
->y
+ h
->lines
- 2); /* buttonbar */
511 x
= min (x
, h
->x
+ h
->cols
- 1);
512 /* don't use widget_set_size() here to avoid double draw */
514 w
->x
= x
- edit
->drag_state_start
;
515 edit
->force
|= REDRAW_PAGE
;
517 else if (edit
->drag_state
== MCEDIT_DRAG_RESIZE
)
519 event
->y
= min (event
->y
, h
->y
+ h
->lines
- 1); /* buttonbar */
520 event
->x
= min (event
->x
, h
->x
+ h
->cols
);
521 local
= mouse_get_local (event
, w
);
523 /* don't use widget_set_size() here to avoid double draw */
524 w
->lines
= max (WINDOW_MIN_LINES
, local
.y
);
525 w
->cols
= max (WINDOW_MIN_COLS
, local
.x
);
526 edit
->force
|= REDRAW_COMPLETELY
;
536 /* --------------------------------------------------------------------------------------------- */
539 edit_dialog_command_execute (Dlg_head
* h
, unsigned long command
)
541 gboolean ret
= MSG_HANDLED
;
546 edit_add_window (h
, h
->y
+ 1, h
->x
, h
->lines
- 2, h
->cols
, NULL
, 0);
551 case CK_EditSyntaxFile
:
552 edit_load_syntax_file (h
);
554 case CK_EditUserMenu
:
555 edit_load_menu_file (h
);
558 /* if there are no opened files anymore, close MC editor */
559 if (edit_widget_is_editor ((Widget
*) h
->current
->data
) &&
560 edit_close_cmd ((WEdit
*) h
->current
->data
) && find_editor (h
) == NULL
)
565 /* edit->force |= REDRAW_COMPLETELY; */
573 Widget
*w
= (Widget
*) h
->current
->data
;
575 if (!edit_widget_is_editor (w
) || ((WEdit
*) w
)->drag_state
== MCEDIT_DRAG_NORMAL
)
578 edit_restore_size ((WEdit
*) w
);
585 edit_syntax_onoff_cmd (h
);
588 edit_show_tabs_tws_cmd (h
);
591 edit_show_margin_cmd (h
);
594 edit_show_numbers_cmd (h
);
606 case CK_WindowResize
:
607 if (edit_widget_is_editor ((Widget
*) h
->current
->data
))
608 edit_handle_move_resize ((WEdit
*) h
->current
->data
, command
);
611 edit_window_list (h
);
615 dlg_set_top_widget (h
->current
->data
);
619 dlg_set_top_widget (h
->current
->data
);
622 edit_options_dialog (h
);
624 case CK_OptionsSaveMode
:
625 edit_save_mode_cmd ();
631 ret
= MSG_NOT_HANDLED
;
638 /* --------------------------------------------------------------------------------------------- */
641 edit_quit (Dlg_head
* h
)
646 h
->state
= DLG_ACTIVE
; /* don't stop the dialog before final decision */
648 for (l
= h
->widgets
; l
!= NULL
; l
= g_list_next (l
))
649 if (edit_widget_is_editor ((Widget
*) l
->data
))
651 e
= (WEdit
*) l
->data
;
653 if (e
->drag_state
!= MCEDIT_DRAG_NORMAL
)
655 edit_restore_size (e
);
661 dlg_select_widget (e
);
663 if (!edit_ok_to_exit (e
))
668 /* no editors in dialog at all or no any file required to be saved */
669 if (e
== NULL
|| l
== NULL
)
670 h
->state
= DLG_CLOSED
;
673 /* --------------------------------------------------------------------------------------------- */
676 edit_set_buttonbar (WEdit
* edit
, WButtonBar
* bb
)
678 buttonbar_set_label (bb
, 1, Q_ ("ButtonBar|Help"), editor_map
, NULL
);
679 buttonbar_set_label (bb
, 2, Q_ ("ButtonBar|Save"), editor_map
, (Widget
*) edit
);
680 buttonbar_set_label (bb
, 3, Q_ ("ButtonBar|Mark"), editor_map
, (Widget
*) edit
);
681 buttonbar_set_label (bb
, 4, Q_ ("ButtonBar|Replac"), editor_map
, (Widget
*) edit
);
682 buttonbar_set_label (bb
, 5, Q_ ("ButtonBar|Copy"), editor_map
, (Widget
*) edit
);
683 buttonbar_set_label (bb
, 6, Q_ ("ButtonBar|Move"), editor_map
, (Widget
*) edit
);
684 buttonbar_set_label (bb
, 7, Q_ ("ButtonBar|Search"), editor_map
, (Widget
*) edit
);
685 buttonbar_set_label (bb
, 8, Q_ ("ButtonBar|Delete"), editor_map
, (Widget
*) edit
);
686 buttonbar_set_label (bb
, 9, Q_ ("ButtonBar|PullDn"), editor_map
, NULL
);
687 buttonbar_set_label (bb
, 10, Q_ ("ButtonBar|Quit"), editor_map
, NULL
);
690 /* --------------------------------------------------------------------------------------------- */
691 /** Callback for the edit dialog */
694 edit_dialog_callback (Dlg_head
* h
, Widget
* sender
, dlg_msg_t msg
, int parm
, void *data
)
697 WButtonBar
*buttonbar
;
702 /* don't use common_dialog_repaint() -- we don't need a frame */
703 tty_setcolor (EDITOR_NORMAL_COLOR
);
708 menubar
= find_menubar (h
);
709 buttonbar
= find_buttonbar (h
);
710 /* dlg_set_size() is surplus for this case */
713 widget_set_size (&buttonbar
->widget
, h
->lines
- 1, h
->x
, 1, h
->cols
);
714 widget_set_size (&menubar
->widget
, h
->y
, h
->x
, 1, h
->cols
);
715 menubar_arrange (menubar
);
721 return edit_dialog_command_execute (h
, parm
);
722 /* message from menu */
723 menubar
= find_menubar (h
);
724 if (sender
== (Widget
*) menubar
)
726 if (edit_dialog_command_execute (h
, parm
) == MSG_HANDLED
)
728 /* try send command to the current window */
729 return send_message ((Widget
*) h
->current
->data
, WIDGET_COMMAND
, parm
);
731 /* message from buttonbar */
732 buttonbar
= find_buttonbar (h
);
733 if (sender
== (Widget
*) buttonbar
)
736 return send_message ((Widget
*) data
, WIDGET_COMMAND
, parm
);
737 return edit_dialog_command_execute (h
, parm
);
739 return MSG_NOT_HANDLED
;
743 Widget
*w
= h
->current
->data
;
744 cb_ret_t ret
= MSG_NOT_HANDLED
;
746 if (edit_widget_is_editor (w
))
748 WEdit
*e
= (WEdit
*) w
;
749 unsigned long command
;
752 command
= keybind_lookup_keymap_command (editor_map
, parm
);
756 command
= keybind_lookup_keymap_command (editor_x_map
, parm
);
759 if (command
!= CK_IgnoreKey
)
760 ret
= edit_dialog_command_execute (h
, command
);
766 /* hardcoded menu hotkeys (see edit_drop_hotkey_menu) */
767 case DLG_UNHANDLED_KEY
:
768 return edit_drop_hotkey_menu (h
, parm
) ? MSG_HANDLED
: MSG_NOT_HANDLED
;
775 return default_dlg_callback (h
, sender
, msg
, parm
, data
);
779 /* --------------------------------------------------------------------------------------------- */
782 edit_callback (Widget
* w
, widget_msg_t msg
, int parm
)
784 WEdit
*e
= (WEdit
*) w
;
789 edit_set_buttonbar (e
, find_buttonbar (e
->widget
.owner
));
790 e
->force
|= REDRAW_PAGE
;
791 edit_update_screen (e
);
795 e
->force
|= REDRAW_COMPLETELY
;
796 edit_update_screen (e
);
802 cb_ret_t ret
= MSG_NOT_HANDLED
;
804 /* The user may override the access-keys for the menu bar. */
805 if (macro_index
== -1 && edit_execute_macro (e
, parm
))
807 edit_update_screen (e
);
810 else if (edit_translate_key (e
, parm
, &cmd
, &ch
))
812 edit_execute_key_command (e
, cmd
, ch
);
813 edit_update_screen (e
);
821 /* command from menubar or buttonbar */
822 edit_execute_key_command (e
, parm
, -1);
823 edit_update_screen (e
);
827 widget_move (w
, e
->curs_row
+ EDIT_TEXT_VERTICAL_OFFSET
+ EDIT_WITH_FRAME
,
828 e
->curs_col
+ e
->start_col
+ e
->over_col
+
829 EDIT_TEXT_HORIZONTAL_OFFSET
+ EDIT_WITH_FRAME
+ option_line_state_width
);
837 return default_proc (msg
, parm
);
841 /* --------------------------------------------------------------------------------------------- */
842 /*** public functions ****************************************************************************/
843 /* --------------------------------------------------------------------------------------------- */
846 edit_file (const vfs_path_t
* _file_vpath
, int line
)
848 static gboolean made_directory
= FALSE
;
857 dir
= mc_build_filename (mc_config_get_cache_path (), EDIT_DIR
, NULL
);
858 made_directory
= (mkdir (dir
, 0700) != -1 || errno
== EEXIST
);
861 dir
= mc_build_filename (mc_config_get_path (), EDIT_DIR
, NULL
);
862 made_directory
= (mkdir (dir
, 0700) != -1 || errno
== EEXIST
);
865 dir
= mc_build_filename (mc_config_get_data_path (), EDIT_DIR
, NULL
);
866 made_directory
= (mkdir (dir
, 0700) != -1 || errno
== EEXIST
);
870 /* Create a new dialog and add it widgets to it */
872 create_dlg (FALSE
, 0, 0, LINES
, COLS
, NULL
, edit_dialog_callback
, NULL
,
873 "[Internal File Editor]", NULL
, DLG_WANT_TAB
);
875 edit_dlg
->get_shortcut
= edit_get_shortcut
;
876 edit_dlg
->get_title
= edit_get_title
;
878 menubar
= menubar_new (0, 0, COLS
, NULL
);
879 add_widget (edit_dlg
, menubar
);
880 edit_init_menu (menubar
);
882 add_widget (edit_dlg
, buttonbar_new (TRUE
));
884 ok
= edit_add_window (edit_dlg
, edit_dlg
->y
+ 1, edit_dlg
->x
,
885 edit_dlg
->lines
- 2, edit_dlg
->cols
, _file_vpath
, line
);
890 if (!ok
|| edit_dlg
->state
== DLG_CLOSED
)
891 destroy_dlg (edit_dlg
);
896 /* --------------------------------------------------------------------------------------------- */
899 edit_get_file_name (const WEdit
* edit
)
901 return vfs_path_to_str (edit
->filename_vpath
);
904 /* --------------------------------------------------------------------------------------------- */
907 find_editor (const Dlg_head
* h
)
909 return (WEdit
*) find_widget_type (h
, edit_callback
);
912 /* --------------------------------------------------------------------------------------------- */
914 * Check if widget is an WEdit class.
916 * @param w probably editor object
917 * @return TRUE if widget is an WEdit class, FALSE otherwise
921 edit_widget_is_editor (const Widget
* w
)
923 return (w
!= NULL
&& w
->callback
== edit_callback
);
926 /* --------------------------------------------------------------------------------------------- */
929 edit_update_screen (WEdit
* e
)
931 edit_scroll_screen_over_cursor (e
);
932 edit_update_curs_col (e
);
934 if (!EDIT_WITH_FRAME
)
938 if ((e
->force
& REDRAW_COMPLETELY
) != 0)
940 /* draw a frame around edit area */
941 tty_setcolor (EDITOR_NORMAL_COLOR
);
942 tty_draw_box (e
->widget
.y
, e
->widget
.x
, e
->widget
.lines
, e
->widget
.cols
, TRUE
);
945 edit_info_status (e
);
948 /* pop all events for this window for internal handling */
950 e
->force
|= REDRAW_PAGE
;
953 if (e
->force
& REDRAW_COMPLETELY
)
954 e
->force
|= REDRAW_PAGE
;
955 edit_render_keypress (e
);
958 buttonbar_redraw (find_buttonbar (((Widget
*) e
)->owner
));
961 /* --------------------------------------------------------------------------------------------- */
963 * Save current window size.
965 * @param edit editor object
969 edit_save_size (WEdit
* edit
)
971 edit
->y_prev
= edit
->widget
.y
;
972 edit
->x_prev
= edit
->widget
.x
;
973 edit
->lines_prev
= edit
->widget
.lines
;
974 edit
->cols_prev
= edit
->widget
.cols
;
977 /* --------------------------------------------------------------------------------------------- */
979 * Create new editor window and insert it into editor screen.
981 * @param h editor dialog (screen)
982 * @param y y coordinate
983 * @param x x coordinate
984 * @param lines window height
985 * @param cols window width
986 * @param f file object
987 * @param fline line number in file
988 * @return TRUE if new window was successfully created and inserted into editor screen,
993 edit_add_window (Dlg_head
* h
, int y
, int x
, int lines
, int cols
, const vfs_path_t
*f
, int fline
)
998 edit
= edit_init (NULL
, y
, x
, lines
, cols
, f
, fline
);
1002 w
= (Widget
*) edit
;
1003 w
->callback
= edit_callback
;
1004 w
->mouse
= edit_event
;
1005 widget_want_cursor (*w
, TRUE
);
1013 /* --------------------------------------------------------------------------------------------- */
1015 * Handle move/resize events.
1017 * @param edit editor object
1018 * @param command action id
1019 * @return TRUE if mouse actions was handled, FALSE otherwise
1023 edit_handle_move_resize (WEdit
* edit
, unsigned long command
)
1025 gboolean ret
= FALSE
;
1027 switch (edit
->drag_state
)
1029 case MCEDIT_DRAG_NORMAL
:
1030 /* possible start move/resize */
1034 edit
->drag_state
= MCEDIT_DRAG_MOVE
;
1035 edit_save_size (edit
);
1038 case CK_WindowResize
:
1039 edit
->drag_state
= MCEDIT_DRAG_RESIZE
;
1040 edit_save_size (edit
);
1048 case MCEDIT_DRAG_MOVE
:
1051 case CK_WindowResize
:
1052 edit
->drag_state
= MCEDIT_DRAG_RESIZE
;
1059 edit_window_move (edit
, command
);
1064 edit
->drag_state
= MCEDIT_DRAG_NORMAL
;
1071 case MCEDIT_DRAG_RESIZE
:
1075 edit
->drag_state
= MCEDIT_DRAG_MOVE
;
1082 edit_window_resize (edit
, command
);
1086 case CK_WindowResize
:
1087 edit
->drag_state
= MCEDIT_DRAG_NORMAL
;
1098 /* --------------------------------------------------------------------------------------------- */