]> git.lyx.org Git - features.git/blob - src/lyxscreen.h
remove bogus backslashed from iso-8859-1, try to fix insert and encodeString, fixes...
[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-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 fillArc(GC gc, int x, int y,
114                      unsigned int w, unsigned int h,
115                      int a1, int a2);
116         ///
117         void drawArc(GC gc, int x, int y,
118                      unsigned int w, unsigned int h,
119                      int a1, int a2);
120         ///
121         void drawSegments(GC gc, XSegment * s, int ns);
122         ///
123         void fillRectangle(gc_type t, int, int, int, int);
124         ///
125         void drawRectangle(gc_type t, int x, int y, int width, int height);
126         ///
127         void drawFrame(int ft, int x, int y, int w, int h,
128                        FL_COLOR col, int b); 
129         ///
130         int drawText(LyXFont const & font, char const *,
131                      int n, int baseline, int x);
132         ///
133         int drawString(LyXFont const & font, string const & str,
134                        int baseline, int x);
135                 
136         /// first visible pixel-row
137         long first;
138
139         ///
140         bool cursor_visible;
141 private:
142         /// Copies specified area of pixmap to screen
143         void expose(int x, int y, int exp_width, int exp_height); 
144
145         /// y1 and y2 are coordinates of the screen
146         void DrawFromTo(int y1, int y2);
147    
148         /// y is a coordinate of the text
149         void DrawOneRow(Row * row, long & y_text);
150
151         ///
152         LyXText * text;
153
154         ///
155         Pixmap foreground;
156         ///
157         Pixmap cursor_pixmap;
158         ///
159         int cursor_pixmap_x;
160         ///
161         int cursor_pixmap_y;
162         ///
163         int cursor_pixmap_w;
164         ///
165         int cursor_pixmap_h;
166         ///
167         Window _window;
168         ///
169         Dimension _width;
170         ///
171         Dimension _height;
172         ///
173         Dimension _offset_x;
174         ///
175         Dimension _offset_y;
176         ///
177         long screen_refresh_y;
178         ///
179         Row * screen_refresh_row;
180         ///
181         friend class InsetFormula;  
182 };
183
184 // Some of the easy to inline draw methods:
185
186 inline
187 void LyXScreen::drawPoint(GC gc, int x, int y)
188 {
189         XDrawPoint(fl_display, foreground, gc,
190                    x, y);
191 }
192
193
194 inline
195 void LyXScreen::drawLine(GC gc, int a, int b, int c, int d)
196 {
197         XDrawLine(fl_display, foreground, gc, a, b, c, d);
198 }
199
200
201 inline
202 void LyXScreen::drawLine(gc_type t, int baseline, int x, int length)
203 {
204         drawLine(getGC(t), x, baseline, x + length, baseline);
205 }
206
207
208 inline
209 void LyXScreen::drawLines(GC gc, XPoint * p, int np)
210 {
211         XDrawLines(fl_display, foreground, gc, p, np, CoordModeOrigin);
212 }
213
214
215 inline
216 void LyXScreen::drawVerticalLine(gc_type t, int x, int y1, int y2)
217 {
218         drawLine(getGC(t),
219                  x,
220                  y1,
221                  x,
222                  y2);
223 }
224
225
226 inline
227 void LyXScreen::drawOnOffLine(int baseline, int x, int length)
228 {
229         drawLine(getGC(gc_on_off_line),
230                  x,
231                  baseline,
232                  x + length,
233                  baseline);
234 }
235
236         
237 inline
238 void LyXScreen::drawThickLine(int baseline, int x, int length)
239 {
240         drawLine(getGC(gc_thick_line),
241                  x,
242                  baseline,
243                  x + length,
244                  baseline);
245 }
246
247
248 inline
249 void LyXScreen::drawVerticalOnOffLine(int x, int y1, int y2)
250 {
251         drawLine(getGC(gc_fill),
252                  x,
253                  y1,
254                  x,
255                  y2);
256 }       
257
258
259 inline
260 void LyXScreen::fillArc(GC gc, int x, int y,
261                         unsigned int w, unsigned int h,
262                         int a1, int a2)
263 {
264         XFillArc(fl_display, foreground, gc,
265                  x, y,
266                  w, h, a1, a2);
267 }
268
269
270 inline
271 void LyXScreen::drawArc(GC gc, int x, int y,
272                         unsigned int w, unsigned int h,
273                         int a1, int a2)
274 {
275         XDrawArc(fl_display, foreground, gc,
276                  x, y,
277                  w, h, a1, a2);
278 }
279
280
281 inline
282 void LyXScreen::drawSegments(GC gc, XSegment * s, int ns)
283 {
284         XDrawSegments(fl_display, foreground, gc, s, ns);
285 }
286
287
288 inline
289 void LyXScreen::fillRectangle(gc_type t, int a, int b, int c, int d)
290 {
291         XFillRectangle(fl_display, foreground, getGC(t),
292                        a, b, c, d);
293 }
294
295
296 inline
297 void LyXScreen::drawRectangle(gc_type t, int x, int y, int width, int height)
298 {
299         XDrawRectangle(fl_display, foreground, getGC(t),
300                        x, y, width, height);
301 }
302
303
304 inline
305 int LyXScreen::drawText(LyXFont const & font, char const * fs,
306                         int n, int baseline, int x)
307 {
308         return font.drawText(fs, n, foreground, baseline, x);
309 }
310
311
312 inline
313 int LyXScreen::drawString(LyXFont const & font, string const & str,
314                           int baseline, int x)
315 {
316         return font.drawString(str, foreground, baseline, x);
317 }
318
319 #endif