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