~ubuntu-branches/ubuntu/feisty/elinks/feisty-updates

« back to all changes in this revision

Viewing changes to src/terminal/window.c

  • Committer: Bazaar Package Importer
  • Author(s): Peter Gervai
  • Date: 2004-01-21 22:13:45 UTC
  • Revision ID: james.westby@ubuntu.com-20040121221345-ju33hai1yhhqt6kn
Tags: upstream-0.9.1
ImportĀ upstreamĀ versionĀ 0.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Terminal windows stuff. */
 
2
/* $Id: window.c,v 1.13 2003/12/02 19:58:00 jonas Exp $ */
 
3
 
 
4
#ifdef HAVE_CONFIG_H
 
5
#include "config.h"
 
6
#endif
 
7
 
 
8
#include "elinks.h"
 
9
 
 
10
#include "terminal/event.h"
 
11
#include "terminal/tab.h"
 
12
#include "terminal/terminal.h"
 
13
#include "terminal/window.h"
 
14
#include "util/error.h"
 
15
#include "util/memory.h"
 
16
 
 
17
 
 
18
void
 
19
redraw_from_window(struct window *win)
 
20
{
 
21
        struct terminal *term = win->term;
 
22
        struct term_event ev = INIT_TERM_EVENT(EV_REDRAW, term->width, term->height, 0);
 
23
        struct window *end = (void *) &term->windows;
 
24
 
 
25
        if (term->redrawing != 0) return;
 
26
 
 
27
        term->redrawing = 1;
 
28
        for (win = win->prev; win != end; win = win->prev) {
 
29
                if (!inactive_tab(win))
 
30
                        win->handler(win, &ev, 0);
 
31
        }
 
32
        term->redrawing = 0;
 
33
}
 
34
 
 
35
void
 
36
redraw_below_window(struct window *win)
 
37
{
 
38
        struct terminal *term = win->term;
 
39
        struct term_event ev = INIT_TERM_EVENT(EV_REDRAW, term->width, term->height, 0);
 
40
        struct window *end = win;
 
41
        int tr = term->redrawing;
 
42
 
 
43
        if (term->redrawing > 1) return;
 
44
 
 
45
        term->redrawing = 2;
 
46
        for (win = term->windows.prev; win != end; win = win->prev) {
 
47
                if (!inactive_tab(win))
 
48
                        win->handler(win, &ev, 0);
 
49
        }
 
50
        term->redrawing = tr;
 
51
}
 
52
 
 
53
static void
 
54
add_window_at_pos(struct terminal *term,
 
55
                  void (*handler)(struct window *, struct term_event *, int),
 
56
                  void *data, struct window *at)
 
57
{
 
58
        struct window *win = mem_calloc(1, sizeof(struct window));
 
59
        struct term_event ev = INIT_TERM_EVENT(EV_INIT, term->width, term->height, 0);
 
60
 
 
61
        if (!win) {
 
62
                if (data) mem_free(data);
 
63
                return;
 
64
        }
 
65
 
 
66
        win->handler = handler;
 
67
        win->data = data; /* freed later in delete_window() */
 
68
        win->term = term;
 
69
        win->type = WT_NORMAL;
 
70
        add_at_pos(at, win);
 
71
        win->handler(win, &ev, 0);
 
72
}
 
73
 
 
74
void
 
75
add_window(struct terminal *term,
 
76
           void (*handler)(struct window *, struct term_event *, int),
 
77
           void *data)
 
78
{
 
79
        add_window_at_pos(term, handler, data, (struct window *) &term->windows);
 
80
}
 
81
 
 
82
void
 
83
delete_window(struct window *win)
 
84
{
 
85
        struct term_event ev = INIT_TERM_EVENT(EV_ABORT, 0, 0, 0);
 
86
 
 
87
        /* Updating the status when destroying tabs needs this before the win
 
88
         * handler call. */
 
89
        del_from_list(win);
 
90
        win->handler(win, &ev, 1);
 
91
        if (win->data) mem_free(win->data);
 
92
        redraw_terminal(win->term);
 
93
        mem_free(win);
 
94
}
 
95
 
 
96
void
 
97
delete_window_ev(struct window *win, struct term_event *ev)
 
98
{
 
99
        struct window *w = win->next;
 
100
 
 
101
        if ((void *) w == &win->term->windows) w = NULL;
 
102
        delete_window(win);
 
103
        if (ev && w && w->next != w) w->handler(w, ev, 1);
 
104
}
 
105
 
 
106
void
 
107
get_parent_ptr(struct window *win, int *x, int *y)
 
108
{
 
109
        struct window *parent = win->next;
 
110
 
 
111
#if 0
 
112
        if ((void*) parent == &win->term->windows)
 
113
                parent = NULL;
 
114
        else
 
115
#endif
 
116
        if (parent->type)
 
117
                parent = get_tab_by_number(win->term, win->term->current_tab);
 
118
 
 
119
        if (parent) {
 
120
                *x = parent->x;
 
121
                *y = parent->y;
 
122
        } else {
 
123
                *x = 0;
 
124
                *y = 0;
 
125
        }
 
126
}
 
127
 
 
128
 
 
129
struct ewd {
 
130
        void (*fn)(void *);
 
131
        void *data;
 
132
        int b;
 
133
};
 
134
 
 
135
static void
 
136
empty_window_handler(struct window *win, struct term_event *ev, int fwd)
 
137
{
 
138
        struct terminal *term = win->term;
 
139
        struct ewd *ewd = win->data;
 
140
        void (*fn)(void *) = ewd->fn;
 
141
        void *data = ewd->data;
 
142
 
 
143
        if (ewd->b) return;
 
144
 
 
145
        switch (ev->ev) {
 
146
                case EV_INIT:
 
147
                case EV_RESIZE:
 
148
                case EV_REDRAW:
 
149
                {
 
150
                        int x, y;
 
151
 
 
152
                        get_parent_ptr(win, &x, &y);
 
153
                        set_window_ptr(win, x, y);
 
154
                        return;
 
155
                }
 
156
                case EV_ABORT:
 
157
                        fn(data);
 
158
                        return;
 
159
                case EV_KBD:
 
160
                case EV_MOUSE:
 
161
                        /* Silence compiler warnings */
 
162
                        break;
 
163
        }
 
164
 
 
165
        ewd->b = 1;
 
166
        delete_window(win);
 
167
        fn(data);
 
168
        term_send_event(term, ev);
 
169
}
 
170
 
 
171
void
 
172
add_empty_window(struct terminal *term, void (*fn)(void *), void *data)
 
173
{
 
174
        struct ewd *ewd = mem_alloc(sizeof(struct ewd));
 
175
 
 
176
        if (!ewd) return;
 
177
        ewd->fn = fn;
 
178
        ewd->data = data;
 
179
        ewd->b = 0;
 
180
        add_window(term, empty_window_handler, ewd);
 
181
}