Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

open-axiom repository from github

24005 views
1
/*
2
Copyright (C) 1991-2002, The Numerical Algorithms Group Ltd.
3
All rights reserved.
4
Copyright (C) 2007-2010, Gabriel Dos Reis.
5
All rights reserved.
6
7
Redistribution and use in source and binary forms, with or without
8
modification, are permitted provided that the following conditions are
9
met:
10
11
- Redistributions of source code must retain the above copyright
12
notice, this list of conditions and the following disclaimer.
13
14
- Redistributions in binary form must reproduce the above copyright
15
notice, this list of conditions and the following disclaimer in
16
the documentation and/or other materials provided with the
17
distribution.
18
19
- Neither the name of The Numerical Algorithms Group Ltd. nor the
20
names of its contributors may be used to endorse or promote products
21
derived from this software without specific prior written permission.
22
23
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
24
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
*/
35
36
/******************************************************************************
37
*
38
* display.c: HyperDoc functions to format and display a page.
39
*
40
* Copyright The Numerical Algorithms Group Limited 1991, 1992, 1993.
41
*
42
****************************************************************************/
43
44
/*
45
* Notes:
46
* Display is performed in two steps. First the page is formatted
47
* assuming that we have an infinitely long window. In this stage
48
* we compute and store the coordinates of every text node. Next
49
* the page is actually drawn on the screen. In this process we
50
* use the value of page->y_off as an offset into the scrolling
51
* region to compute what is actually to be displayed on the page.
52
*/
53
54
#define _DISPLAY_C
55
#include "openaxiom-c-macros.h"
56
57
#include "debug.h"
58
#include "sockio.h"
59
60
#include "extent.h"
61
#include "hyper.h"
62
#include "display.h"
63
#include "group.h"
64
#include "scrollbar.h"
65
#include "titlebar.h"
66
#include "parse-types.h"
67
68
69
extern ItemStack *gTopOfItemStack;
70
short int gDisplayRegion = 0;
71
int gRegionOffset = 0;
72
73
74
/* Display a HyperDoc page in the top-level window */
75
76
void
77
show_page(HyperDocPage *page)
78
{
79
XWindowChanges wc;
80
int doShowScrollBars = 1;
81
82
init_top_group();
83
84
/* Clear the areas so we can rewrite the page */
85
86
XClearWindow(gXDisplay, gWindow->fMainWindow);
87
XClearWindow(gXDisplay, gWindow->fScrollWindow);
88
89
/* Free the active button list */
90
91
free_button_list(page->s_button_list);
92
page->s_button_list = NULL;
93
free_button_list(page->button_list);
94
page->button_list = NULL;
95
96
/* The compute the text extents */
97
compute_title_extent(page);
98
compute_header_extent(page);
99
compute_footer_extent(page);
100
compute_scrolling_extent(page);
101
102
/*
103
* Now that we have all the extents computed, reconfigure and map the
104
* scroll window
105
*/
106
107
if (page->scrolling) {
108
int width, height;
109
calculateScrollBarMeasures();
110
wc.x = 0;
111
wc.y = page->top_scroll_margin + scroll_top_margin;
112
113
wc.height = gWindow->scrollheight;
114
if (gWindow->page->scrolling->height <= gWindow->scrollheight) {
115
gWindow->page->scroll_off = 0;
116
wc.width = gWindow->width;
117
}
118
else
119
wc.width = gWindow->width - gScrollbarWidth;
120
121
getScrollBarMinimumSize(&width, &height);
122
if (height > wc.height) {
123
wc.height = gWindow->scrollheight = 1;
124
doShowScrollBars = 0;
125
}
126
else
127
gWindow->scrollwidth = wc.width;
128
129
if (doShowScrollBars) {
130
XConfigureWindow(gXDisplay, gWindow->fScrollWindow, CWX | CWY | CWHeight | CWWidth, &wc);
131
XMapWindow(gXDisplay, gWindow->fScrollWindow);
132
}
133
else {
134
XUnmapWindow(gXDisplay, gWindow->fScrollWindow);
135
hideScrollBars(gWindow);
136
}
137
}
138
/* clear the group stack */
139
140
while (pop_group_stack() >= 0)
141
;
142
143
/* Now start displaying all the text */
144
145
gWindow->fDisplayedWindow = gWindow->fMainWindow;
146
gRegionOffset = 0;
147
y_off = 0;
148
gDisplayRegion = Header;
149
show_text(page->header->next, openaxiom_Endheader_token);
150
151
if (doShowScrollBars && page->scrolling) {
152
/* Show the footer */
153
if (page->footer->next) {
154
gDisplayRegion = Footer;
155
gRegionOffset = gWindow->page->bot_scroll_margin +
156
(!((gWindow->page->page_flags & NOLINES)) ? ((int) line_height / 2) : (0));
157
show_text(page->footer->next, openaxiom_Endfooter_token);
158
/* Show the scrolling region */
159
if (page->scrolling->next)
160
gDisplayRegion = Scrolling;
161
gRegionOffset = 0;
162
gWindow->fDisplayedWindow = gWindow->fScrollWindow;
163
y_off = gWindow->page->scroll_off;
164
show_text(page->scrolling->next, openaxiom_Endscrolling_token);
165
showScrollBars(gWindow);
166
}
167
drawScrollLines();
168
}
169
if (gTopOfItemStack != NULL) {
170
fprintf(stderr, "warning: unbalanced \\beginitems .. \\enditems\n");
171
gTopOfItemStack = NULL;
172
}
173
showTitleBar();
174
XFlush(gXDisplay);
175
}
176
177
void
178
expose_page(HyperDocPage *page)
179
{
180
int width, height, doShowScrollBars = 1;
181
init_top_group();
182
183
/*
184
* Now start displaying all the text
185
*/
186
187
y_off = 0;
188
gWindow->fDisplayedWindow = gWindow->fMainWindow;
189
gRegionOffset = 0;
190
gDisplayRegion = Header;
191
show_text(page->header->next, openaxiom_Endheader_token);
192
getScrollBarMinimumSize(&width, &height);
193
194
/*
195
* Now see If I have anything left to display
196
*/
197
if (page->scrolling) {
198
if (page->footer->next) {
199
gDisplayRegion = Footer;
200
gRegionOffset = gWindow->page->bot_scroll_margin +
201
(!((gWindow->page->page_flags & NOLINES)) ? ((int) line_height / 2) : (0));
202
show_text(page->footer->next, openaxiom_Endfooter_token);
203
}
204
205
if (height > gWindow->scrollheight) {
206
gWindow->scrollheight = 1;
207
doShowScrollBars = 0;
208
XUnmapWindow(gXDisplay, gWindow->fScrollWindow);
209
hideScrollBars(gWindow);
210
}
211
212
if (page->scrolling->next) {
213
gRegionOffset = page->top_scroll_margin;
214
gDisplayRegion = Scrolling;
215
gRegionOffset = 0;
216
gWindow->fDisplayedWindow = gWindow->fScrollWindow;
217
y_off = gWindow->page->scroll_off;
218
show_text(page->scrolling->next, openaxiom_Endscrolling_token);
219
if (doShowScrollBars)
220
showScrollBars(gWindow);
221
}
222
if (doShowScrollBars)
223
drawScrollLines();
224
}
225
showTitleBar();
226
XFlush(gXDisplay);
227
}
228
229
void
230
scroll_page(HyperDocPage *page)
231
{
232
init_top_group();
233
/* free the active button list */
234
free_button_list(page->s_button_list);
235
page->s_button_list = NULL;
236
/** Clear the scrolling area */
237
XUnmapSubwindows(gXDisplay, gWindow->fScrollWindow);
238
gDisplayRegion = Scrolling;
239
gRegionOffset = 0;
240
gWindow->fDisplayedWindow = gWindow->fScrollWindow;
241
y_off = gWindow->page->scroll_off;
242
show_text(page->scrolling->next, openaxiom_Endscrolling_token);
243
moveScroller(gWindow);
244
XFlush(gXDisplay);
245
}
246
247
void
248
paste_page(TextNode *node)
249
{
250
int width, height;
251
int old_off = gWindow->page->scroll_off;
252
253
/* free the active button list */
254
free_button_list(gWindow->page->s_button_list);
255
gWindow->page->s_button_list = NULL;
256
free_button_list(gWindow->page->button_list);
257
gWindow->page->button_list = NULL;
258
XUnmapSubwindows(gXDisplay, gWindow->fScrollWindow);
259
260
init_top_group();
261
262
/* recompute the extent of the scrolling region */
263
264
compute_scrolling_extent(gWindow->page);
265
266
calculateScrollBarMeasures();
267
getScrollBarMinimumSize(&width, &height);
268
269
/* get ready to show the scrolling area */
270
gRegionOffset = 0;
271
y_off = gWindow->page->scroll_off;
272
gDisplayRegion = Scrolling;
273
gWindow->fDisplayedWindow = gWindow->fScrollWindow;
274
if (gWindow->page->scroll_off == old_off) {
275
XClearArea(gXDisplay, gWindow->fScrollWindow, 0,
276
node->y - line_height + gRegionOffset + y_off,
277
gWindow->width,
278
gWindow->scrollheight - node->y + line_height - y_off,
279
False);
280
XFlush(gXDisplay);
281
}
282
else
283
XClearWindow(gXDisplay, gWindow->fScrollWindow);
284
285
show_text(gWindow->page->scrolling->next, openaxiom_Endscrolling_token);
286
XFlush(gXDisplay);
287
hideScrollBars(gWindow);
288
289
if (height > gWindow->scrollheight) {
290
gWindow->scrollheight = 1;
291
XUnmapWindow(gXDisplay, gWindow->fScrollWindow);
292
}
293
else {
294
showScrollBars(gWindow);
295
drawScrollLines();
296
/* moveScroller(); */
297
}
298
XFlush(gXDisplay);
299
}
300
301