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