~ubuntu-branches/ubuntu/lucid/mc/lucid

« back to all changes in this revision

Viewing changes to edit/editwidget.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2008-09-16 10:38:59 UTC
  • mfrom: (3.1.6 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080916103859-2uwn8w61xk5mbxxq
Tags: 2:4.6.2~git20080311-4
Corrected fix for odt2txt issue (Closes: #492019) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* editor initialisation and callback handler.
2
2
 
3
 
   Copyright (C) 1996, 1997 the Free Software Foundation
 
3
   Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
 
4
   2007 Free Software Foundation, Inc.
4
5
 
5
6
   Authors: 1996, 1997 Paul Sheer
6
7
 
21
22
 */
22
23
 
23
24
#include <config.h>
 
25
 
 
26
#include <stdio.h>
 
27
#include <stdarg.h>
 
28
#include <sys/types.h>
 
29
#ifdef HAVE_UNISTD_H
 
30
#    include <unistd.h>
 
31
#endif
 
32
#include <string.h>
 
33
#include <ctype.h>
 
34
#include <errno.h>
 
35
#include <sys/stat.h>
 
36
 
 
37
#include <stdlib.h>
 
38
 
 
39
#include "../src/global.h"
 
40
 
24
41
#include "edit.h"
25
42
#include "edit-widget.h"
26
43
 
27
44
#include "../src/tty.h"         /* LINES */
28
 
#include "../src/widget.h"      /* redraw_labels() */
 
45
#include "../src/widget.h"      /* buttonbar_redraw() */
29
46
#include "../src/menu.h"        /* menubar_new() */
30
47
#include "../src/key.h"         /* is_idle() */
31
48
 
34
51
 
35
52
int column_highlighting = 0;
36
53
 
37
 
static cb_ret_t edit_callback (WEdit *edit, widget_msg_t msg, int parm);
 
54
static cb_ret_t edit_callback (Widget *, widget_msg_t msg, int parm);
38
55
 
39
56
static int
40
57
edit_event (WEdit * edit, Gpm_Event * event, int *result)
70
87
    if (event->type & (GPM_DOWN | GPM_UP))
71
88
        edit_push_key_press (edit);
72
89
 
73
 
    edit_cursor_move (edit, edit_bol (edit, edit->curs1) - edit->curs1);
 
90
    edit->prev_col = event->x - edit->start_col - 1;
74
91
 
75
92
    if (--event->y > (edit->curs_row + 1))
76
 
        edit_cursor_move (edit,
77
 
                          edit_move_forward (edit, edit->curs1,
78
 
                                             event->y - (edit->curs_row +
79
 
                                                         1), 0)
80
 
                          - edit->curs1);
81
 
 
82
 
    if (event->y < (edit->curs_row + 1))
83
 
        edit_cursor_move (edit,
84
 
                          edit_move_backward (edit, edit->curs1,
85
 
                                              (edit->curs_row + 1) -
86
 
                                              event->y) - edit->curs1);
87
 
 
88
 
    edit_cursor_move (edit,
89
 
                      (int) edit_move_forward3 (edit, edit->curs1,
90
 
                                                event->x -
91
 
                                                edit->start_col - 1,
92
 
                                                0) - edit->curs1);
93
 
 
94
 
    edit->prev_col = edit_get_col (edit);
 
93
        edit_move_down (edit, event->y - (edit->curs_row + 1), 0);
 
94
    else if (event->y < (edit->curs_row + 1))
 
95
        edit_move_up (edit, (edit->curs_row + 1) - event->y, 0);
 
96
    else
 
97
        edit_move_to_prev_col (edit, edit_bol (edit, edit->curs1));
95
98
 
96
99
    if (event->type & GPM_DOWN) {
97
100
        edit_mark_cmd (edit, 1);        /* reset */
102
105
        edit_mark_cmd (edit, 0);
103
106
 
104
107
  update:
 
108
    edit_find_bracket (edit);
105
109
    edit->force |= REDRAW_COMPLETELY;
106
110
    edit_update_curs_row (edit);
107
111
    edit_update_curs_col (edit);
127
131
    WEdit *edit;
128
132
    WButtonBar *edit_bar;
129
133
 
130
 
    edit = (WEdit *) find_widget_type (h, (callback_fn) edit_callback);
 
134
    edit = (WEdit *) find_widget_type (h, edit_callback);
131
135
    edit_bar = find_buttonbar (h);
132
136
 
133
137
    widget_set_size (&edit->widget, 0, 0, LINES - 1, COLS);
134
 
    widget_set_size (&edit_bar->widget, LINES - 1, 0, 1, COLS);
 
138
    widget_set_size ((Widget *) edit_bar, LINES - 1, 0, 1, COLS);
135
139
    widget_set_size (&edit_menubar->widget, 0, 0, 1, COLS);
136
140
 
137
141
#ifdef RESIZABLE_MENUBAR
151
155
        return MSG_HANDLED;
152
156
 
153
157
    case DLG_VALIDATE:
154
 
        edit = (WEdit *) find_widget_type (h, (callback_fn) edit_callback);
 
158
        edit = (WEdit *) find_widget_type (h, edit_callback);
155
159
        if (!edit_ok_to_exit (edit)) {
156
160
            h->running = 1;
157
161
        }
169
173
    Dlg_head *edit_dlg;
170
174
    WButtonBar *edit_bar;
171
175
 
172
 
    if (option_backup_ext_int != -1) {
173
 
        option_backup_ext = g_malloc (sizeof (int) + 1);
174
 
        option_backup_ext[sizeof (int)] = '\0';
175
 
        memcpy (option_backup_ext, (char *) &option_backup_ext_int,
176
 
                sizeof (int));
177
 
    }
178
176
    if (!made_directory) {
179
 
        mkdir (catstrs (home_dir, EDIT_DIR, (char *) NULL), 0700);
180
 
        made_directory = 1;
 
177
        char *dir = concat_dir_and_file (home_dir, EDIT_DIR);
 
178
        made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
 
179
        g_free (dir);
181
180
    }
182
181
 
183
182
    if (!(wedit = edit_init (NULL, LINES - 2, COLS, _file, line))) {
190
189
                    "[Internal File Editor]", NULL, DLG_WANT_TAB);
191
190
 
192
191
    init_widget (&(wedit->widget), 0, 0, LINES - 1, COLS,
193
 
                 (callback_fn) edit_callback,
194
 
                 (mouse_h) edit_mouse_event);
 
192
                 edit_callback,
 
193
                 edit_mouse_event);
195
194
 
196
195
    widget_want_cursor (wedit->widget, 1);
197
196
 
198
197
    edit_bar = buttonbar_new (1);
199
198
 
200
 
    switch (edit_key_emulation) {
201
 
    case EDIT_KEY_EMULATION_NORMAL:
202
 
        edit_init_menu_normal ();       /* editmenu.c */
203
 
        break;
204
 
    case EDIT_KEY_EMULATION_EMACS:
205
 
        edit_init_menu_emacs ();        /* editmenu.c */
206
 
        break;
207
 
    }
208
 
    edit_menubar = menubar_new (0, 0, COLS, EditMenuBar, N_menus);
 
199
    edit_menubar = edit_init_menu ();
209
200
 
210
201
    add_widget (edit_dlg, edit_bar);
211
202
    add_widget (edit_dlg, wedit);
213
204
 
214
205
    run_dlg (edit_dlg);
215
206
 
216
 
    edit_done_menu ();          /* editmenu.c */
 
207
    edit_done_menu (edit_menubar);              /* editmenu.c */
217
208
 
218
209
    destroy_dlg (edit_dlg);
219
210
 
223
214
static void edit_my_define (Dlg_head * h, int idx, const char *text,
224
215
                            void (*fn) (WEdit *), WEdit * edit)
225
216
{
226
 
    define_label_data (h, idx, text, (buttonbarfn) fn, edit);
 
217
    text = edit->labels[idx - 1]? edit->labels[idx - 1] : text;
 
218
    /* function-cast ok */
 
219
    buttonbar_set_label_data (h, idx, text, (buttonbarfn) fn, edit);
227
220
}
228
221
 
229
222
 
295
288
    edit_my_define (h, 9, _("PullDn"), edit_menu_cmd, edit);
296
289
    edit_my_define (h, 10, _("Quit"), cmd_F10, edit);
297
290
 
298
 
    redraw_labels (h);
 
291
    buttonbar_redraw (h);
299
292
}
300
293
 
301
294
void edit_update_screen (WEdit * e)
317
310
}
318
311
 
319
312
static cb_ret_t
320
 
edit_callback (WEdit *e, widget_msg_t msg, int parm)
 
313
edit_callback (Widget *w, widget_msg_t msg, int parm)
321
314
{
 
315
    WEdit *e = (WEdit *) w;
 
316
 
322
317
    switch (msg) {
323
318
    case WIDGET_INIT:
324
319
        e->force |= REDRAW_COMPLETELY;
339
334
        {
340
335
            int cmd, ch;
341
336
 
342
 
            /* first check alt-f, alt-e, alt-s, etc for drop menus */
343
 
            if (edit_drop_hotkey_menu (e, parm))
344
 
                return MSG_HANDLED;
345
 
            if (!edit_translate_key (e, parm, &cmd, &ch))
 
337
            /* The user may override the access-keys for the menu bar. */
 
338
            if (edit_translate_key (e, parm, &cmd, &ch)) {
 
339
                edit_execute_key_command (e, cmd, ch);
 
340
                edit_update_screen (e);
 
341
                return MSG_HANDLED;
 
342
            } else  if (edit_drop_hotkey_menu (e, parm)) {
 
343
                return MSG_HANDLED;
 
344
            } else {
346
345
                return MSG_NOT_HANDLED;
347
 
            edit_execute_key_command (e, cmd, ch);
348
 
            edit_update_screen (e);
 
346
            }
349
347
        }
350
 
        return MSG_HANDLED;
351
348
 
352
349
    case WIDGET_CURSOR:
353
350
        widget_move (&e->widget, e->curs_row + EDIT_TEXT_VERTICAL_OFFSET,