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