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