]> git.lyx.org Git - features.git/blob - src/lyxscreen.h
some small updates to Painter, and make the new painter the default.
[features.git] / src / lyxscreen.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ====================================================== 
4  * 
5  *           LyX, The Document Processor
6  *       
7  *           Copyright 1995 Matthias Ettrich
8  *           Copyright 1995-2000 The LyX Team
9  *
10  * ====================================================== */
11
12 #ifndef LYXSCREEN_H
13 #define LYXSCREEN_H
14
15 #ifdef __GNUG__
16 #pragma interface
17 #endif
18
19 #include FORMS_H_LOCATION
20 #include <X11/Xlib.h>
21
22 #define USE_PAINTER 1
23
24 #ifndef USE_PAINTER
25 #include "lyxdraw.h"
26 #endif
27
28 class LyXText;
29 struct Row;
30 typedef unsigned short Dimension;
31
32 class BufferView;
33
34 #define NEW_WA 1
35
36 /** The class LyXScreen is used for the main Textbody.
37     Concretely, the screen is held in a pixmap.  This pixmap is kept up to
38     date and used to optimize drawing on the screen.
39     This class also handles the drawing of the cursor and partly the selection.
40  */
41 class LyXScreen {
42 public:
43         ///
44         LyXScreen(BufferView *, Window window,
45 #ifdef NEW_WA
46                   Pixmap p,
47 #endif
48                   Dimension width, 
49                   Dimension height,
50                   Dimension offset_x,
51                   Dimension offset_y,
52                   LyXText * text_ptr);
53         ///
54         ~LyXScreen();
55
56 #ifndef USE_PAINTER
57         /** Return the forground pixmap. This function is a _hack_,
58             we should be rid of it as soon as possible. But to do that
59             a lot in the mathcode and the figinset has to be rewritten.
60             Tasks for 0.13. */
61         Pixmap getForeground() { return foreground; };
62 #endif
63         
64         /** Draws the screen form textposition y. Uses as much of
65             the already printed pixmap as possible */
66         void Draw(long y );
67
68         /// Redraws the screen, without using existing pixmap
69         void Redraw();
70    
71         /// Returns a new top so that the cursor is visible
72         long TopCursorVisible();
73         /// Redraws the screen such that the cursor is visible
74         int FitCursor();
75         ///
76         void ShowCursor();
77         ///
78         void HideCursor();
79         ///
80         void CursorToggle();
81         ///
82         void ShowManualCursor(long x, long y, int asc, int desc);
83         ///
84         void HideManualCursor(long x, long y, int asc, int desc);
85         /// returns 1 if first has changed, otherwise 0
86         int  FitManualCursor(long, long, int, int);
87         ///
88         void ToggleSelection(bool = true);
89         ///
90         void ToggleToggle();
91         
92         /** Updates part of the screen. If text->status is
93             LyXText::NEED_MORE_REFRESH, we update from the
94             point of change and to the end of the screen.
95             If text->status is LyXText::NEED_VERY_LITTLE_REFRESH,
96             we only update the current row. */
97         void Update();
98
99         /** Updates part of the screen. Updates till row with cursor,
100             or only current row */
101         void SmallUpdate();
102
103 #ifndef USE_PAINTER
104         /** Functions for drawing into the LyXScreen. The number of
105             drawing functions should be minimized, now there
106             is too many. And also there is mixed X and XForms drawing
107             functions called. Not good. */
108         void drawPoint(GC gc, int x, int y);
109         ///
110         void drawLine(gc_type t, int baseline, int x, int length);
111         ///
112         void drawLine(GC gc, int a, int b, int c, int d);
113         ///
114         void drawLines(GC gc, XPoint * p, int np);
115         ///
116         void drawVerticalLine(gc_type t, int x, int y1, int y2);
117         ///
118         void drawOnOffLine(int baseline, int x, int length);
119         ///
120         void drawThickLine(int baseline, int x, int length);
121         ///
122         void drawTableLine(int baseline, int x, int length, bool on_off);
123         ///
124         void drawVerticalTableLine(int x, int y1, int y2, bool on_off);
125         ///
126         void drawVerticalOnOffLine(int x, int y1, int y2);
127         ///
128         void fillArc(GC gc, int x, int y,
129                      unsigned int w, unsigned int h,
130                      int a1, int a2);
131         ///
132         void drawArc(GC gc, int x, int y,
133                      unsigned int w, unsigned int h,
134                      int a1, int a2);
135         ///
136         void drawSegments(GC gc, XSegment * s, int ns);
137         ///
138         void fillRectangle(gc_type t, int, int, int, int);
139         ///
140         void drawRectangle(gc_type t, int x, int y, int width, int height);
141         ///
142         void drawFrame(int ft, int x, int y, int w, int h,
143                        FL_COLOR col, int b); 
144         ///
145         int drawText(LyXFont const & font, char const *,
146                      int n, int baseline, int x);
147         ///
148         int drawString(LyXFont const & font, string const & str,
149                        int baseline, int x);
150 #endif
151         /// first visible pixel-row
152         long first;
153
154         ///
155         bool cursor_visible;
156 private:
157         /// Copies specified area of pixmap to screen
158         void expose(int x, int y, int exp_width, int exp_height); 
159
160         /// y1 and y2 are coordinates of the screen
161         void DrawFromTo(int y1, int y2);
162    
163         /// y is a coordinate of the text
164         void DrawOneRow(Row * row, long & y_text);
165
166         ///
167         BufferView * owner;
168         
169         ///
170         LyXText * text;
171
172         ///
173         Pixmap foreground;
174         ///
175         Pixmap cursor_pixmap;
176         ///
177         int cursor_pixmap_x;
178         ///
179         int cursor_pixmap_y;
180         ///
181         int cursor_pixmap_w;
182         ///
183         int cursor_pixmap_h;
184         ///
185         Window _window;
186         ///
187         Dimension _width;
188         ///
189         Dimension _height;
190         ///
191         Dimension _offset_x;
192         ///
193         Dimension _offset_y;
194         ///
195         long screen_refresh_y;
196         ///
197         Row * screen_refresh_row;
198         ///
199         //friend class InsetFormula;
200 #ifdef USE_PAINTER
201         ///
202         GC gc_copy;
203 #endif
204 };
205
206 // Some of the easy to inline draw methods:
207 #ifndef USE_PAINTER
208 inline
209 void LyXScreen::drawPoint(GC gc, int x, int y)
210 {
211         XDrawPoint(fl_display, foreground, gc,
212                    x, y);
213 }
214
215
216 inline
217 void LyXScreen::drawLine(GC gc, int a, int b, int c, int d)
218 {
219         XDrawLine(fl_display, foreground, gc, a, b, c, d);
220 }
221
222
223 inline
224 void LyXScreen::drawLine(gc_type t, int baseline, int x, int length)
225 {
226         drawLine(getGC(t), x, baseline, x + length, baseline);
227 }
228
229
230 inline
231 void LyXScreen::drawLines(GC gc, XPoint * p, int np)
232 {
233         XDrawLines(fl_display, foreground, gc, p, np, CoordModeOrigin);
234 }
235
236
237 inline
238 void LyXScreen::drawVerticalLine(gc_type t, int x, int y1, int y2)
239 {
240         drawLine(getGC(t),
241                  x,
242                  y1,
243                  x,
244                  y2);
245 }
246
247
248 inline
249 void LyXScreen::drawOnOffLine(int baseline, int x, int length)
250 {
251         drawLine(getGC(gc_on_off_line),
252                  x,
253                  baseline,
254                  x + length,
255                  baseline);
256 }
257
258         
259 inline
260 void LyXScreen::drawThickLine(int baseline, int x, int length)
261 {
262         drawLine(getGC(gc_thick_line),
263                  x,
264                  baseline,
265                  x + length,
266                  baseline);
267 }
268
269
270 inline
271 void LyXScreen::drawVerticalOnOffLine(int x, int y1, int y2)
272 {
273         drawLine(getGC(gc_fill),
274                  x,
275                  y1,
276                  x,
277                  y2);
278 }       
279
280
281 inline
282 void LyXScreen::fillArc(GC gc, int x, int y,
283                         unsigned int w, unsigned int h,
284                         int a1, int a2)
285 {
286         XFillArc(fl_display, foreground, gc,
287                  x, y,
288                  w, h, a1, a2);
289 }
290
291
292 inline
293 void LyXScreen::drawArc(GC gc, int x, int y,
294                         unsigned int w, unsigned int h,
295                         int a1, int a2)
296 {
297         XDrawArc(fl_display, foreground, gc,
298                  x, y,
299                  w, h, a1, a2);
300 }
301
302
303 inline
304 void LyXScreen::drawSegments(GC gc, XSegment * s, int ns)
305 {
306         XDrawSegments(fl_display, foreground, gc, s, ns);
307 }
308
309
310 inline
311 void LyXScreen::fillRectangle(gc_type t, int a, int b, int c, int d)
312 {
313         XFillRectangle(fl_display, foreground, getGC(t),
314                        a, b, c, d);
315 }
316
317
318 inline
319 void LyXScreen::drawRectangle(gc_type t, int x, int y, int width, int height)
320 {
321         XDrawRectangle(fl_display, foreground, getGC(t),
322                        x, y, width, height);
323 }
324
325
326 inline
327 int LyXScreen::drawText(LyXFont const & font, char const * fs,
328                         int n, int baseline, int x)
329 {
330         return font.drawText(fs, n, foreground, baseline, x);
331 }
332
333
334 inline
335 int LyXScreen::drawString(LyXFont const & font, string const & str,
336                           int baseline, int x)
337 {
338         return font.drawString(str, foreground, baseline, x);
339 }
340 #endif
341
342 #endif