1 /* editor initialisation and callback handler.
3 Copyright (C) 1996, 1997 the Free Software Foundation
5 Authors: 1996, 1997 Paul Sheer
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
30 int column_highlighting
= 0;
32 static int edit_callback (Dlg_head
* h
, WEdit
* edit
, int msg
, int par
);
34 int edit_event (WEdit
* edit
, Gpm_Event
* event
, int *result
)
37 edit_update_curs_row (edit
);
38 edit_update_curs_col (edit
);
39 if (event
->type
& (GPM_DOWN
| GPM_DRAG
| GPM_UP
)) {
40 if (event
->y
> 1 && event
->x
> 0
41 && event
->x
<= edit
->num_widget_columns
42 && event
->y
<= edit
->num_widget_lines
+ 1) {
43 if (edit
->mark2
!= -1 && event
->type
& (GPM_UP
| GPM_DRAG
))
44 return 1; /* a lone up mustn't do anything */
45 if (event
->type
& (GPM_DOWN
| GPM_UP
))
46 edit_push_key_press (edit
);
47 edit_cursor_move (edit
, edit_bol (edit
, edit
->curs1
) - edit
->curs1
);
48 if (--event
->y
> (edit
->curs_row
+ 1))
49 edit_cursor_move (edit
,
50 edit_move_forward (edit
, edit
->curs1
, event
->y
- (edit
->curs_row
+ 1), 0)
52 if (event
->y
< (edit
->curs_row
+ 1))
53 edit_cursor_move (edit
,
54 +edit_move_backward (edit
, edit
->curs1
, (edit
->curs_row
+ 1) - event
->y
)
56 edit_cursor_move (edit
, (int) edit_move_forward3 (edit
, edit
->curs1
,
57 event
->x
- edit
->start_col
- 1, 0) - edit
->curs1
);
58 edit
->prev_col
= edit_get_col (edit
);
59 if (event
->type
& GPM_DOWN
) {
60 edit_mark_cmd (edit
, 1); /* reset */
63 if (!(event
->type
& GPM_DRAG
))
64 edit_mark_cmd (edit
, 0);
65 edit
->force
|= REDRAW_COMPLETELY
;
66 edit_update_curs_row (edit
);
67 edit_update_curs_col (edit
);
68 edit_update_screen (edit
);
77 int menubar_event (Gpm_Event
* event
, WMenu
* menubar
); /* menu.c */
79 int edit_mouse_event (Gpm_Event
* event
, void *x
)
82 if (edit_event ((WEdit
*) x
, event
, &result
))
85 return menubar_event (event
, edit_menubar
);
89 edit (const char *_file
, int line
)
91 static int made_directory
= 0;
96 if (option_backup_ext_int
!= -1) {
97 option_backup_ext
= malloc (sizeof (int) + 1);
98 option_backup_ext
[sizeof (int)] = '\0';
99 memcpy (option_backup_ext
, (char *) &option_backup_ext_int
,
102 if (!made_directory
) {
103 mkdir (catstrs (home_dir
, EDIT_DIR
, 0), 0700);
114 if (!(wedit
= edit_init (NULL
, LINES
- 2, COLS
, _file
, text
, "", 0))) {
119 /* Create a new dialog and add it widgets to it */
121 create_dlg (0, 0, LINES
, COLS
, NULL
, NULL
,
122 "[Internal File Editor]", NULL
, DLG_WANT_TAB
);
124 init_widget (&(wedit
->widget
), 0, 0, LINES
- 1, COLS
,
125 (callback_fn
) edit_callback
, (destroy_fn
) edit_clean
,
126 (mouse_h
) edit_mouse_event
, 0);
128 widget_want_cursor (wedit
->widget
, 1);
130 edit_bar
= buttonbar_new (1);
133 switch (edit_key_emulation
) {
134 case EDIT_KEY_EMULATION_NORMAL
:
135 edit_init_menu_normal (); /* editmenu.c */
137 case EDIT_KEY_EMULATION_EMACS
:
138 edit_init_menu_emacs (); /* editmenu.c */
141 edit_menubar
= menubar_new (0, 0, COLS
, EditMenuBar
, N_menus
);
143 add_widget (edit_dlg
, wedit
);
146 add_widget (edit_dlg
, edit_menubar
);
148 add_widget (edit_dlg
, edit_bar
);
149 edit_move_display (wedit
, line
- 1);
150 edit_move_to_line (wedit
, line
- 1);
155 edit_done_menu (); /* editmenu.c */
157 destroy_dlg (edit_dlg
);
162 static void edit_my_define (Dlg_head
* h
, int idx
, char *text
,
163 void (*fn
) (WEdit
*), WEdit
* edit
)
165 define_label_data (h
, (Widget
*) edit
, idx
, text
, (buttonbarfn
) fn
, edit
);
169 static void cmd_F1 (WEdit
* edit
)
171 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (1));
174 static void cmd_F2 (WEdit
* edit
)
176 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (2));
179 static void cmd_F3 (WEdit
* edit
)
181 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (3));
184 static void cmd_F4 (WEdit
* edit
)
186 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (4));
189 static void cmd_F5 (WEdit
* edit
)
191 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (5));
194 static void cmd_F6 (WEdit
* edit
)
196 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (6));
199 static void cmd_F7 (WEdit
* edit
)
201 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (7));
204 static void cmd_F8 (WEdit
* edit
)
206 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (8));
210 static void cmd_F9 (WEdit
* edit
)
212 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (9));
216 static void cmd_F10 (WEdit
* edit
)
218 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (10));
221 void edit_labels (WEdit
* edit
)
223 Dlg_head
*h
= edit
->widget
.parent
;
225 edit_my_define (h
, 1, _ ("Help"), cmd_F1
, edit
);
226 edit_my_define (h
, 2, _ ("Save"), cmd_F2
, edit
);
227 edit_my_define (h
, 3, _ ("Mark"), cmd_F3
, edit
);
228 edit_my_define (h
, 4, _ ("Replac"), cmd_F4
, edit
);
229 edit_my_define (h
, 5, _ ("Copy"), cmd_F5
, edit
);
230 edit_my_define (h
, 6, _ ("Move"), cmd_F6
, edit
);
231 edit_my_define (h
, 7, _ ("Search"), cmd_F7
, edit
);
232 edit_my_define (h
, 8, _ ("Delete"), cmd_F8
, edit
);
233 if (!edit
->have_frame
)
234 edit_my_define (h
, 9, _ ("PullDn"), edit_menu_cmd
, edit
);
235 edit_my_define (h
, 10, _ ("Quit"), cmd_F10
, edit
);
237 redraw_labels (h
, (Widget
*) edit
);
241 long get_key_state (void)
243 return (long) get_modifier ();
246 void edit_adjust_size (Dlg_head
* h
)
249 WButtonBar
*edit_bar
;
251 edit
= (WEdit
*) find_widget_type (h
, (callback_fn
) edit_callback
);
252 edit_bar
= (WButtonBar
*) edit
->widget
.parent
->current
->next
->widget
;
253 widget_set_size (&edit
->widget
, 0, 0, LINES
- 1, COLS
);
254 widget_set_size (&edit_bar
->widget
, LINES
- 1, 0, 1, COLS
);
255 widget_set_size (&edit_menubar
->widget
, 0, 0, 1, COLS
);
257 #ifdef RESIZABLE_MENUBAR
258 menubar_arrange (edit_menubar
);
262 void edit_update_screen (WEdit
* e
)
264 edit_scroll_screen_over_cursor (e
);
266 edit_update_curs_col (e
);
269 /* pop all events for this window for internal handling */
272 e
->force
|= REDRAW_PAGE
;
275 if (e
->force
& REDRAW_COMPLETELY
)
276 e
->force
|= REDRAW_PAGE
;
277 edit_render_keypress (e
);
280 static int edit_callback (Dlg_head
* h
, WEdit
* e
, int msg
, int par
)
284 e
->force
|= REDRAW_COMPLETELY
;
288 e
->force
|= REDRAW_COMPLETELY
;
289 e
->num_widget_lines
= LINES
- 2;
290 e
->num_widget_columns
= COLS
;
292 edit_update_screen (e
);
296 if (edit_drop_hotkey_menu (e
, par
)) /* first check alt-f, alt-e, alt-s, etc for drop menus */
298 if (!edit_translate_key (e
, 0, par
, get_key_state (), &cmd
, &ch
))
300 edit_execute_key_command (e
, cmd
, ch
);
301 edit_update_screen (e
);
305 edit_execute_key_command (e
, par
, -1);
306 edit_update_screen (e
);
309 widget_move (&e
->widget
, e
->curs_row
+ EDIT_TEXT_VERTICAL_OFFSET
, e
->curs_col
+ e
->start_col
);
312 return default_proc (h
, msg
, par
);