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
29 int column_highlighting
= 0;
31 static int edit_callback (Dlg_head
* h
, WEdit
* edit
, int msg
, int par
);
34 edit_event (WEdit
* edit
, Gpm_Event
* event
, int *result
)
37 edit_update_curs_row (edit
);
38 edit_update_curs_col (edit
);
40 /* Unknown event type */
41 if (!(event
->type
& (GPM_DOWN
| GPM_DRAG
| GPM_UP
)))
45 if ((event
->buttons
& GPM_B_UP
) && (event
->type
& GPM_DOWN
)) {
46 edit_move_up (edit
, 2, 1);
49 if ((event
->buttons
& GPM_B_DOWN
) && (event
->type
& GPM_DOWN
)) {
50 edit_move_down (edit
, 2, 1);
54 /* Outside editor window */
55 if (event
->y
<= 1 || event
->x
<= 0
56 || event
->x
> edit
->num_widget_columns
57 || event
->y
> edit
->num_widget_lines
+ 1)
60 /* A lone up mustn't do anything */
61 if (edit
->mark2
!= -1 && event
->type
& (GPM_UP
| GPM_DRAG
))
64 if (event
->type
& (GPM_DOWN
| GPM_UP
))
65 edit_push_key_press (edit
);
67 edit_cursor_move (edit
, edit_bol (edit
, edit
->curs1
) - edit
->curs1
);
69 if (--event
->y
> (edit
->curs_row
+ 1))
70 edit_cursor_move (edit
,
71 edit_move_forward (edit
, edit
->curs1
,
72 event
->y
- (edit
->curs_row
+
76 if (event
->y
< (edit
->curs_row
+ 1))
77 edit_cursor_move (edit
,
78 edit_move_backward (edit
, edit
->curs1
,
79 (edit
->curs_row
+ 1) -
80 event
->y
) - edit
->curs1
);
82 edit_cursor_move (edit
,
83 (int) edit_move_forward3 (edit
, edit
->curs1
,
88 edit
->prev_col
= edit_get_col (edit
);
90 if (event
->type
& GPM_DOWN
) {
91 edit_mark_cmd (edit
, 1); /* reset */
95 if (!(event
->type
& GPM_DRAG
))
96 edit_mark_cmd (edit
, 0);
99 edit
->force
|= REDRAW_COMPLETELY
;
100 edit_update_curs_row (edit
);
101 edit_update_curs_col (edit
);
102 edit_update_screen (edit
);
108 int menubar_event (Gpm_Event
* event
, WMenu
* menubar
); /* menu.c */
110 int edit_mouse_event (Gpm_Event
* event
, void *x
)
113 if (edit_event ((WEdit
*) x
, event
, &result
))
116 return menubar_event (event
, edit_menubar
);
120 edit_adjust_size (Dlg_head
* h
)
123 WButtonBar
*edit_bar
;
125 edit
= (WEdit
*) find_widget_type (h
, (callback_fn
) edit_callback
);
126 edit_bar
= (WButtonBar
*) edit
->widget
.parent
->current
->next
->widget
;
127 widget_set_size (&edit
->widget
, 0, 0, LINES
- 1, COLS
);
128 widget_set_size (&edit_bar
->widget
, LINES
- 1, 0, 1, COLS
);
129 widget_set_size (&edit_menubar
->widget
, 0, 0, 1, COLS
);
131 #ifdef RESIZABLE_MENUBAR
132 menubar_arrange (edit_menubar
);
136 /* Callback for the edit dialog */
138 edit_dialog_callback (Dlg_head
* h
, int id
, int msg
)
142 edit_adjust_size (h
);
145 return default_dlg_callback (h
, id
, msg
);
149 edit (const char *_file
, int line
)
151 static int made_directory
= 0;
155 WButtonBar
*edit_bar
;
157 if (option_backup_ext_int
!= -1) {
158 option_backup_ext
= malloc (sizeof (int) + 1);
159 option_backup_ext
[sizeof (int)] = '\0';
160 memcpy (option_backup_ext
, (char *) &option_backup_ext_int
,
163 if (!made_directory
) {
164 mkdir (catstrs (home_dir
, EDIT_DIR
, 0), 0700);
175 if (!(wedit
= edit_init (NULL
, LINES
- 2, COLS
, _file
, text
, "", 0))) {
180 /* Create a new dialog and add it widgets to it */
182 create_dlg (0, 0, LINES
, COLS
, NULL
, edit_dialog_callback
,
183 "[Internal File Editor]", NULL
, DLG_WANT_TAB
);
185 init_widget (&(wedit
->widget
), 0, 0, LINES
- 1, COLS
,
186 (callback_fn
) edit_callback
, (destroy_fn
) edit_clean
,
187 (mouse_h
) edit_mouse_event
, 0);
189 widget_want_cursor (wedit
->widget
, 1);
191 edit_bar
= buttonbar_new (1);
194 switch (edit_key_emulation
) {
195 case EDIT_KEY_EMULATION_NORMAL
:
196 edit_init_menu_normal (); /* editmenu.c */
198 case EDIT_KEY_EMULATION_EMACS
:
199 edit_init_menu_emacs (); /* editmenu.c */
202 edit_menubar
= menubar_new (0, 0, COLS
, EditMenuBar
, N_menus
);
204 add_widget (edit_dlg
, wedit
);
207 add_widget (edit_dlg
, edit_menubar
);
209 add_widget (edit_dlg
, edit_bar
);
210 edit_move_display (wedit
, line
- 1);
211 edit_move_to_line (wedit
, line
- 1);
216 edit_done_menu (); /* editmenu.c */
218 destroy_dlg (edit_dlg
);
223 static void edit_my_define (Dlg_head
* h
, int idx
, char *text
,
224 void (*fn
) (WEdit
*), WEdit
* edit
)
226 define_label_data (h
, (Widget
*) edit
, idx
, text
, (buttonbarfn
) fn
, edit
);
230 static void cmd_F1 (WEdit
* edit
)
232 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (1));
235 static void cmd_F2 (WEdit
* edit
)
237 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (2));
240 static void cmd_F3 (WEdit
* edit
)
242 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (3));
245 static void cmd_F4 (WEdit
* edit
)
247 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (4));
250 static void cmd_F5 (WEdit
* edit
)
252 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (5));
255 static void cmd_F6 (WEdit
* edit
)
257 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (6));
260 static void cmd_F7 (WEdit
* edit
)
262 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (7));
265 static void cmd_F8 (WEdit
* edit
)
267 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (8));
271 static void cmd_F9 (WEdit
* edit
)
273 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (9));
277 static void cmd_F10 (WEdit
* edit
)
279 send_message (edit
->widget
.parent
, (Widget
*) edit
, WIDGET_KEY
, KEY_F (10));
282 void edit_labels (WEdit
* edit
)
284 Dlg_head
*h
= edit
->widget
.parent
;
286 edit_my_define (h
, 1, _ ("Help"), cmd_F1
, edit
);
287 edit_my_define (h
, 2, _ ("Save"), cmd_F2
, edit
);
288 edit_my_define (h
, 3, _ ("Mark"), cmd_F3
, edit
);
289 edit_my_define (h
, 4, _ ("Replac"), cmd_F4
, edit
);
290 edit_my_define (h
, 5, _ ("Copy"), cmd_F5
, edit
);
291 edit_my_define (h
, 6, _ ("Move"), cmd_F6
, edit
);
292 edit_my_define (h
, 7, _ ("Search"), cmd_F7
, edit
);
293 edit_my_define (h
, 8, _ ("Delete"), cmd_F8
, edit
);
294 if (!edit
->have_frame
)
295 edit_my_define (h
, 9, _ ("PullDn"), edit_menu_cmd
, edit
);
296 edit_my_define (h
, 10, _ ("Quit"), cmd_F10
, edit
);
298 redraw_labels (h
, (Widget
*) edit
);
302 long get_key_state (void)
304 return (long) get_modifier ();
307 void edit_update_screen (WEdit
* e
)
309 edit_scroll_screen_over_cursor (e
);
311 edit_update_curs_col (e
);
314 /* pop all events for this window for internal handling */
317 e
->force
|= REDRAW_PAGE
;
320 if (e
->force
& REDRAW_COMPLETELY
)
321 e
->force
|= REDRAW_PAGE
;
322 edit_render_keypress (e
);
325 static int edit_callback (Dlg_head
* h
, WEdit
* e
, int msg
, int par
)
329 e
->force
|= REDRAW_COMPLETELY
;
333 e
->force
|= REDRAW_COMPLETELY
;
334 e
->num_widget_lines
= LINES
- 2;
335 e
->num_widget_columns
= COLS
;
337 edit_update_screen (e
);
341 if (edit_drop_hotkey_menu (e
, par
)) /* first check alt-f, alt-e, alt-s, etc for drop menus */
343 if (!edit_translate_key (e
, 0, par
, get_key_state (), &cmd
, &ch
))
345 edit_execute_key_command (e
, cmd
, ch
);
346 edit_update_screen (e
);
350 edit_execute_key_command (e
, par
, -1);
351 edit_update_screen (e
);
354 widget_move (&e
->widget
, e
->curs_row
+ EDIT_TEXT_VERTICAL_OFFSET
, e
->curs_col
+ e
->start_col
);
357 return default_proc (h
, msg
, par
);