4 * Author: Teemu Rantanen <tvr@cs.hut.fi>
5 * Copyright (c) 1992 Teemu Rantanen
8 * Created: Tue Mar 3 02:59:10 1992 tvr
9 * Last modified: Tue Apr 21 00:34:09 1992 tvr
14 #include <sys/types.h>
20 #include "../HText/HText.h"
25 #include "XlFormatText.h"
28 * Make cursor positioning more intelligent
30 #define Y_MULTIPLIER 50
33 * Is there spaces at the end of data ?
35 int xl_space_index(data, length)
44 for (i = 0; i < length; i++)
53 * Draw one Xl object to screen
55 void xl_draw_object(htext, object)
57 HTextObject_t *object;
60 * If this object is cursor, clear area or else partial updating
61 * does not work correctly
64 if (object == htext->cursor) {
65 XClearArea(htext->xl_global->dpy,
66 htext->xl_global->window,
67 object->x - htext->xl_global->x,
68 object->y - htext->xl_global->y,
73 XDrawString(htext->xl_global->dpy,
74 htext->xl_global->window,
76 object->x - htext->xl_global->x,
77 object->y - htext->xl_global->y +
78 object->xl_data->style->fontinfo->ascent,
83 * Draw underline for anchors
90 y = object->y + object->xl_data->style->fontinfo->ascent +
91 object->xl_data->style->fontinfo->descent -
94 x = object->x - htext->xl_global->x;
96 width = object->width;
98 if (object->next && (object->anchor == object->next->anchor) &&
99 (object->y == object->next->y)) {
100 width += xl_wordgap(object);
102 XDrawLine(htext->xl_global->dpy,
103 htext->xl_global->window,
109 * Is this object cursor ?
111 if (object == htext->cursor) {
115 * If cursor is on raw mode, get rid of spaces at the end
117 if (xl_object_mode(object) & STYLE_RAW) {
118 int i = xl_space_index(object->data, object->length);
121 cursorwidth = (int) XTextWidth(object->xl_data->style->fontinfo,
125 cursorwidth = object->width;
128 cursorwidth = object->width;
131 XDrawRectangle(htext->xl_global->dpy,
132 htext->xl_global->window,
133 htext->xl_global->xorgc,
134 object->x - htext->xl_global->x,
135 object->y - htext->xl_global->y,
143 * Check is object is on wanted region. Return 0 if point is on region.
144 * Otherwise return distance. NOTE. y-distance is multiplied by a big
145 * number because this way cursor positioning works more intelligently than
148 int xl_object_on_region(htext, object, x, y, w, h)
150 HTextObject_t *object;
157 * Change real coordinates to virtual coordinates
159 x += htext->xl_global->x;
160 y += htext->xl_global->y;
162 if ((object->y + object->height) < y)
163 r += (y - (object->y + object->height)) * Y_MULTIPLIER;
165 if (object->y > (y + h))
166 r += (object->y - (y + h)) * Y_MULTIPLIER;
168 if ((object->x + object->width) < x)
169 r += x - (object->x + object->width);
171 if (object->x > (x + w))
172 r += object->x - (x + w);
180 * Redraw region of the window. Draw all objects (or parts of the objects)
183 void XlRedraw(windowx, windowy, width, height, htext)
184 int windowx, windowy;
191 * This is stupid. This has to be written again
197 if (xl_object_on_region(htext, p, windowx, windowy, width, height) == 0) {
198 xl_draw_object(htext, p);
206 * Move window to other coordinates. Xl can optimize window moving by using
207 * regioncopy and updating only parts of display.
209 void XlMoveWindow(newvx, newvy, htext)
218 * Need to know window dimensions
220 XGetWindowAttributes(htext->xl_global->dpy,
221 htext->xl_global->window,
227 deltax = newvx - htext->xl_global->x;
228 deltay = newvy - htext->xl_global->y;
231 * Can move be optimized ?
233 if ((abs(deltax) < a.width) && (abs(deltay) < a.height)) {
234 XCopyArea(htext->xl_global->dpy,
235 htext->xl_global->window,
236 htext->xl_global->window,
237 htext->xl_global->gcs[0], /* dummy GC */
238 deltax < 0 ? 0 : deltax,
239 deltay < 0 ? 0 : deltay,
240 a.width - abs(deltax),
241 a.height - abs(deltay),
242 deltax < 0 ? -deltax : 0,
243 deltay < 0 ? -deltay : 0);
246 * Set new corner coordinates
249 XlSetPageCoordinates(newvx, newvy, htext);
252 * Clear borders to be updated again
255 XClearArea(htext->xl_global->dpy,
256 htext->xl_global->window,
257 deltax > 0 ? a.width - deltax : 0,
264 XClearArea(htext->xl_global->dpy,
265 htext->xl_global->window,
267 deltay > 0 ? a.height - deltay : 0,
279 void XlClearWindow(width, height, htext)
284 XClearArea(htext->xl_global->dpy,
285 htext->xl_global->window,
286 0, 0, width, height, True);
291 * Setup cursorposition on a page
293 void XlSetCursor(htext, object)
295 HTextObject_t *object;
298 HTextObject_t *old_object;
301 if (!htext || !htext->xl_global ||
302 !htext->xl_global->dpy ||
303 !htext->xl_global->window)
307 * Need to know window dimensions
309 XGetWindowAttributes(htext->xl_global->dpy,
310 htext->xl_global->window,
317 if (xl_object_on_region(htext, htext->cursor, 0, 0,
318 a.width, a.height) == 0) {
319 XClearArea(htext->xl_global->dpy,
320 htext->xl_global->window,
321 htext->cursor->x - htext->xl_global->x,
322 htext->cursor->y - htext->xl_global->y,
323 htext->cursor->width,
324 htext->cursor->height,
328 * When drawing old area, must clear htext->cursor for a while
330 old_object = htext->cursor;
334 xl_draw_object(htext, old_object);
338 htext->cursor = object;
341 if (xl_object_on_region(htext, object, 0, 0, a.width, a.height) == 0) {
344 * This is moved to draw object. partial drawing updating of
345 * cursor causes otherwise problems
347 XClearArea(htext->xl_global->dpy,
348 htext->xl_global->window,
349 htext->cursor->x - htext->xl_global->x,
350 htext->cursor->y - htext->xl_global->y,
351 htext->cursor->width,
352 htext->cursor->height,
355 xl_draw_object(htext, htext->cursor);