]> git.lyx.org Git - lyx.git/blob - src/screen.C
3eb74d34a319680b5ecaff650bc13d99c79a4f88
[lyx.git] / src / screen.C
1 /* This file is part of
2 * ======================================================
3
4 *           LyX, The Document Processor
5 *        
6 *           Copyright 1995 Matthias Ettrich
7 *           Copyright 1995-1998 The LyX Team
8 *
9 *======================================================*/
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation "lyxscreen.h"
15 #endif
16
17 #include "lyxscreen.h"
18 #include "lyxdraw.h"
19 #include "lyxtext.h"
20
21 extern int mono_video;
22 extern int fast_selection;
23
24
25 // Constructor
26 LyXScreen::LyXScreen(Window window,
27                      Dimension width, 
28                      Dimension height,
29                      Dimension offset_x,
30                      Dimension offset_y,
31                      LyXText *text_ptr)
32         : text(text_ptr),_window(window), 
33           _width(width),_height(height),
34           _offset_x(offset_x), _offset_y(offset_y)
35 {
36         first = 0;
37    
38         /* the cursor isnt yet visible */ 
39         cursor_visible = false;
40         screen_refresh_y = -1;
41
42         /* create the foreground pixmap */
43         foreground = XCreatePixmap (fl_display,
44                                     fl_root,
45                                     _width, _height, 
46                                     fl_get_visual_depth());
47         cursor_pixmap = 0;
48         cursor_pixmap_x = 0;
49         cursor_pixmap_y = 0;
50         cursor_pixmap_w = 0;
51         cursor_pixmap_h = 0;
52 }
53
54
55 // Destructor
56 LyXScreen::~LyXScreen()
57 {
58         XFreePixmap(fl_display, foreground);
59 }
60
61
62 void LyXScreen::Redraw()
63 {
64         DrawFromTo(0, _height);
65         screen_refresh_y = -1;
66         expose(0, 0, _width, _height);
67         if (cursor_visible) {
68                 cursor_visible = false;
69                 ShowCursor();
70         }
71 }
72
73
74 void LyXScreen::expose(int x, int y, int exp_width, int exp_height)
75 {
76         XCopyArea(fl_display,
77                   foreground,
78                   _window,
79                   getGC(gc_copy),
80                   x, y,
81                   exp_width, exp_height,
82                   x+_offset_x, y+_offset_y);
83 }
84
85
86 void LyXScreen::DrawFromTo(int y1, int y2)
87 {
88         Row* row = 0;
89         long  y_text = 0;
90         long y = 0;
91         
92         y_text = first + y1;
93    
94         /* get the first needed row */ 
95         row = text->GetRowNearY(y_text);
96         /* y_text is now the real beginning of the row */
97    
98         y = y_text - first;
99         /* y1 is now the real beginning of row on the screen */
100         
101         while (row != 0 && y < y2) {
102
103                 text->GetVisibleRow(*this, y, row, y + first);
104                 y += row->height;
105                 row = row -> next;
106
107         }
108    
109         /* maybe we have to clear the screen at the bottom */ 
110         if (y < y2) {
111                 fillRectangle(gc_lighted,
112                               0,
113                               y,
114                               _width,
115                               y2 - y);
116         }
117 }
118
119
120 void LyXScreen::DrawOneRow(Row *row, long &y_text)
121 {
122         long y = 0;
123    
124         y = y_text - first;
125       
126         if (y + row->height > 0 && y - row->height <= _height) {
127                 /* ok there is something visible */
128                 text->GetVisibleRow(*this, y, row, y + first);
129         }
130         y_text+=row->height;
131 }
132
133
134 /* draws the screen, starting with textposition y. uses as much already
135 * printed pixels as possible */
136 void LyXScreen::Draw(long  y)
137 {
138         if (cursor_visible) HideCursor();
139
140         if (y<0) y = 0;
141         long old_first = first;
142         first = y;
143
144         /* is any optimiziation possible? */ 
145         if ((y - old_first) < _height 
146             && (old_first - y) < _height) {
147                 if (first < old_first) {
148                         DrawFromTo(0, old_first - first);
149                         XCopyArea (fl_display,
150                                    _window,
151                                    _window,
152                                    getGC(gc_copy),
153                                    _offset_x, _offset_y, 
154                                    _width , _height - old_first + first,
155                                    _offset_x, _offset_y + old_first - first);
156                         // expose the area drawn
157                         expose(0, 0, _width, old_first - first);
158                 } else  {
159                         DrawFromTo(_height + old_first - first, _height);
160                         XCopyArea (fl_display,
161                                    _window,
162                                    _window,
163                                    getGC(gc_copy),
164                                    _offset_x, _offset_y + first - old_first, 
165                                    _width , _height + old_first - first, 
166                                    _offset_x, _offset_y);
167                         // expose the area drawn
168                         expose(0, _height + old_first - first, 
169                                _width, first - old_first);
170                 }
171         } else {
172                 /* make a dumb new-draw */ 
173                 DrawFromTo(0, _height);
174                 expose(0, 0, _width, _height);
175         }
176 }
177
178
179 void LyXScreen::ShowCursor()
180 {
181         long x = 0;
182         long y1 = 0;
183         long y2 = 0;
184    
185         if (cursor_visible) return;
186    
187         x = text->cursor.x;
188         
189         y1 = text->cursor.y - text->real_current_font.maxAscent() - first;
190         if (y1 < 0) y1 = 0;
191         
192         y2 = text->cursor.y + text->real_current_font.maxDescent() - first;
193         if (y2 > _height) y2 = _height;
194
195         // Secure against very strange situations
196         if (y2 < y1) y2 = y1;
197
198         if (fast_selection || mono_video) {
199                 if (y2 > 0 && y1 < _height) {
200                         XDrawLine(fl_display,
201                                   _window, getGC(gc_select),
202                                   x + _offset_x,
203                                   y1 + _offset_y,
204                                   x + _offset_x,
205                                   y2 + _offset_y);
206                         cursor_visible = true;
207                 }
208         } else {
209                 if (cursor_pixmap){
210                         XFreePixmap(fl_display, cursor_pixmap);
211                         cursor_pixmap = 0;
212                 }
213    
214                 if (y2 > 0 && y1 < _height) {
215                         cursor_pixmap_w = 1;
216                         cursor_pixmap_h = y2 - y1 + 1;
217                         cursor_pixmap_x = x;
218                         cursor_pixmap_y = y1;
219                         cursor_pixmap =
220                                 XCreatePixmap(fl_display,
221                                               fl_root,
222                                               cursor_pixmap_w,
223                                               cursor_pixmap_h,
224                                               fl_get_visual_depth());
225                         XCopyArea(fl_display,
226                                   _window,
227                                   cursor_pixmap,
228                                   getGC(gc_copy),
229                                   _offset_x + cursor_pixmap_x, 
230                                   _offset_y + cursor_pixmap_y,
231                                   cursor_pixmap_w, cursor_pixmap_h,
232                                   0, 0);
233                         XDrawLine(fl_display,
234                                   _window, getGC(gc_copy),
235                                   x + _offset_x,
236                                   y1 + _offset_y,
237                                   x + _offset_x,
238                                   y2 + _offset_y); 
239                         cursor_visible = true;
240                 }
241         }
242 }
243
244
245 /* returns 1 if first has changed, otherwise 0 */ 
246 int LyXScreen::FitManualCursor(long /*x*/, long y, int asc, int desc)
247 {
248         long  newtop = first;
249   
250         if (y + desc  - first >= _height)
251                 newtop = y - 3*_height / 4;   /* the scroll region must be so big!! */
252         else if (y - asc < first 
253                  && first > 0) {
254                 newtop = y - _height / 4;
255         }
256         if (newtop < 0)
257                 newtop = 0;
258   
259         if (newtop != first){
260                 Draw(newtop);
261                 first = newtop;
262                 return 1;
263         }
264         return 0;
265 }
266
267
268 void  LyXScreen::HideManualCursor(long x, long y, int asc, int desc){
269         if (fast_selection || mono_video)
270                 ShowManualCursor(x,y,asc,desc);
271         else
272                 HideCursor();
273 }
274
275
276 void  LyXScreen::ShowManualCursor(long x, long y, int asc, int desc)
277 {
278         long y1 = 0;
279         long y2 = 0;
280         
281         y1 = y - first - asc;
282         if (y1 < 0)
283                 y1 =0;
284         y2 = y -first + desc;
285         if (y2 > _height)
286                 y2 = _height;
287         
288         if (fast_selection || mono_video){
289                 if (y2 > 0 && y1 < _height) {
290                         XDrawLine(fl_display,
291                                   _window, getGC(gc_select),
292                                   x+_offset_x,
293                                   y1+_offset_y,
294                                   x+_offset_x,
295                                   y2+_offset_y);
296                 }
297         } else {
298                 if (cursor_pixmap){
299                         XFreePixmap(fl_display, cursor_pixmap);
300                         cursor_pixmap = 0;
301                 }
302                 
303                 if (y2 > 0 && y1 < _height) {
304                         cursor_pixmap_w = 1;
305                         cursor_pixmap_h = y2 - y1 + 1;
306                         cursor_pixmap_x = x,
307                         cursor_pixmap_y = y1;
308                         cursor_pixmap =
309                                 XCreatePixmap (fl_display,
310                                                fl_root,
311                                                cursor_pixmap_w,
312                                                cursor_pixmap_h,
313                                                fl_get_visual_depth());
314
315                         XCopyArea (fl_display,
316                                    _window,
317                                    cursor_pixmap,
318                                    getGC(gc_copy),
319                                    _offset_x + cursor_pixmap_x,
320                                    _offset_y + cursor_pixmap_y,
321                                    cursor_pixmap_w,
322                                    cursor_pixmap_h,
323                                    0, 0);
324                         XDrawLine(fl_display,
325                                   _window, getGC(gc_copy),
326                                   x+_offset_x,
327                                   y1+_offset_y,
328                                   x+_offset_x,
329                                   y2+_offset_y);                        
330                 }
331                 cursor_visible = true;
332         }
333 }
334
335
336 void LyXScreen::HideCursor()
337 {
338         if (!cursor_visible) return;
339         
340         if (fast_selection || mono_video){
341                 cursor_visible = false;
342                 ShowCursor();
343                 cursor_visible = false;
344         } else {
345                 if (cursor_pixmap){
346                         XCopyArea (fl_display, 
347                                    cursor_pixmap,
348                                    _window,
349                                    getGC(gc_copy),
350                                    0, 0, 
351                                    cursor_pixmap_w, cursor_pixmap_h,
352                                    cursor_pixmap_x + _offset_x,
353                                    cursor_pixmap_y + _offset_y);
354                 }
355                 cursor_visible = false;
356         }
357 }
358
359
360 void LyXScreen::CursorToggle()
361 {
362         if (cursor_visible)
363                 HideCursor();
364         else
365                 ShowCursor();
366 }
367
368
369 /* returns a new top so that the cursor is visible */ 
370 long LyXScreen::TopCursorVisible()
371 {
372         long  newtop = first;
373
374         if (text->cursor.y
375             - text->cursor.row->baseline
376             + text->cursor.row->height
377             - first >= _height) {
378                 if (text->cursor.row->height < _height
379                     && text->cursor.row->height > _height/4)
380                         newtop = text->cursor.y
381                                 + text->cursor.row->height
382                                 - text->cursor.row->baseline - _height;
383                 else
384                         newtop = text->cursor.y
385                                 - 3*_height / 4;   /* the scroll region must be so big!! */
386         } else if (text->cursor.y - text->cursor.row->baseline < first 
387                    && first > 0) {
388                 if (text->cursor.row->height < _height
389                     && text->cursor.row->height > _height/4)
390                         newtop = text->cursor.y - text->cursor.row->baseline;
391                 else {
392                         newtop = text->cursor.y - _height / 4;
393                         if (newtop > first)
394                                 newtop = first;
395                 }
396         }
397         if (newtop < 0)
398                 newtop = 0;
399         
400         return newtop;
401 }
402
403
404 /* scrolls the screen so that the cursor is visible, if necessary.
405 * returns 1 if a change was made, otherwise 0 */ 
406 int LyXScreen::FitCursor()
407 {
408         /* is a change necessary */ 
409         long  newtop = TopCursorVisible();
410         int result = (newtop != first);
411         if (result)
412                 Draw(newtop);
413         return result;
414 }
415
416    
417 void LyXScreen::Update()
418 {
419         long y = 0;
420
421         if (text->status == LyXText::NEED_MORE_REFRESH
422             || screen_refresh_y > -1 ) {
423                 if (screen_refresh_y > -1
424                     && screen_refresh_y < text->refresh_y)
425                         y = screen_refresh_y;
426                 else
427                         y = text->refresh_y;
428                 
429                 if (y < first) y = first;
430                 
431                 DrawFromTo(y - first, _height);
432                 text->refresh_y = 0;
433                 text->status = LyXText::UNCHANGED;
434                 screen_refresh_y = -1;
435                 expose(0, y-first, _width, _height - (y - first));
436         } else if (text->status == LyXText::NEED_VERY_LITTLE_REFRESH) {
437                 /* ok I will update the current cursor row */
438                 y = text->refresh_y;
439                 DrawOneRow(text->refresh_row, y);
440                 text->status = LyXText::UNCHANGED;
441                 expose(0, text->refresh_y-first,
442                      _width, text->refresh_row->height);
443         }
444 }
445
446
447 void LyXScreen::SmallUpdate()
448 {
449         Row *row = 0;
450         long y = 0;
451         long y2 = 0;
452         
453         if (text->status == LyXText::NEED_MORE_REFRESH){
454                 /* ok I will update till the current cursor row */
455                 row = text->refresh_row;
456                 y = text->refresh_y;
457                 y2 = y;
458       
459                 if (y > text->cursor.y) {
460                         Update();
461                         return;
462                 }
463          
464                 while (row && row != text->cursor.row && y < first + _height) {
465                         DrawOneRow(row, y);
466                         row = row->next;
467                 }
468       
469                 DrawOneRow(row, y);
470                 screen_refresh_y = y;
471                 screen_refresh_row = row->next;
472                 text->status = LyXText::UNCHANGED;
473                 // Is the right regin exposed?
474                 expose(0, y2-first, _width, y-y2);
475         } else if (text->status == LyXText::NEED_VERY_LITTLE_REFRESH) {
476                 /* ok I will update the current cursor row */
477                 row = text->refresh_row;
478                 y = text->refresh_y;
479                 DrawOneRow(row, y);
480                 text->status = LyXText::UNCHANGED;
481                 expose(0, text->refresh_y - first,
482                        _width, row->height);
483         }
484 }
485
486
487 void LyXScreen::ToggleSelection(bool kill_selection)
488 {
489         long top = 0;
490         long bottom = 0;
491    
492         /* only if there is a selection */ 
493         if (!text->selection)
494                 return;
495         
496         if (fast_selection || mono_video){
497                 
498                 /* selection only in one row ?*/ 
499                 if (text->sel_start_cursor.y == text->sel_end_cursor.y) {
500                         
501                         /* only if something is visible */ 
502                         if (text->sel_start_cursor.y
503                             - text->sel_start_cursor.row->baseline
504                             - first < _height
505                             && text->sel_start_cursor.y
506                             - text->sel_start_cursor.row->baseline + 
507                             text->sel_start_cursor.row->height - first > 0) {
508                                 top = text->sel_start_cursor.y
509                                         - text->sel_start_cursor.row->baseline
510                                         - first;
511                                 bottom = top
512                                         + text->sel_start_cursor.row->height;
513                                 if (top<0)
514                                         top = 0;
515                                 if (bottom > _height)
516                                         bottom = _height;
517                                 XFillRectangle(fl_display,_window,
518                                                getGC(gc_select),
519                                                text->sel_start_cursor.x
520                                                +_offset_x, 
521                                                top+_offset_y,
522                                                text->sel_end_cursor.x
523                                                - text->sel_start_cursor.x,
524                                                bottom - top);
525                         }
526                 } else {
527                         /* the sel_start_cursor row first */ 
528                         /* only if anything is visible */ 
529                         if (text->sel_start_cursor.y
530                             - text->sel_start_cursor.row->baseline
531                             - first < _height
532                             && text->sel_start_cursor.y
533                             - text->sel_start_cursor.row->baseline + 
534                             text->sel_start_cursor.row->height - first > 0) {
535                                 top = text->sel_start_cursor.y
536                                         - text->sel_start_cursor.row->baseline
537                                         - first;
538                                 bottom = top
539                                         + text->sel_start_cursor.row->height;
540                                 if (top<0)
541                                         top = 0;
542                                 if (bottom > _height)
543                                         bottom = _height;
544                                 XFillRectangle(fl_display,_window,
545                                                getGC(gc_select),
546                                                text->sel_start_cursor.x
547                                                +_offset_x, 
548                                                top+_offset_y,
549                                                _width
550                                                - text->sel_start_cursor.x,
551                                                bottom - top);
552                         }
553                         
554                         /* the main body */ 
555                         
556                         if (text->sel_start_cursor.row->next !=
557                             text->sel_end_cursor.row) {
558                                 top = text->sel_start_cursor.y
559                                         - text->sel_start_cursor.row->baseline
560                                         + text->sel_start_cursor.row->height;
561                                 bottom = text->sel_end_cursor.y
562                                         - text->sel_end_cursor.row->baseline;
563                                 
564                                 if (top - first < 0)
565                                         top = first;
566                                 if (bottom - first < 0)
567                                         bottom = first;
568                                 
569                                 if (bottom - first > _height)
570                                         bottom = first + _height;
571                                 if (top - first > _height)
572                                         top = first + _height;
573                                 
574                                 if (top != bottom) {
575                                         XFillRectangle(fl_display,
576                                                        _window,
577                                                        getGC(gc_select),
578                                                        0+_offset_x, 
579                                                        top - first+_offset_y,
580                                                        _width,
581                                                        bottom - top);
582                                 }
583                         }
584                         
585                         /* the sel_end_cursor row last */ 
586                         if (text->sel_end_cursor.y
587                             - text->sel_end_cursor.row->baseline
588                             - first < _height
589                             && text->sel_end_cursor.y
590                             - text->sel_end_cursor.row->baseline +
591                             text->sel_end_cursor.row->height - first > 0) {
592                                 top = text->sel_end_cursor.y
593                                         - text->sel_end_cursor.row->baseline
594                                         - first;
595                                 bottom = top
596                                         + text->sel_end_cursor.row->height;
597                                 if (top<0)
598                                         top = 0;
599                                 if (bottom > _height)
600                                         bottom = _height;
601                                 XFillRectangle(fl_display,_window,
602                                                getGC(gc_select),
603                                                0+_offset_x, 
604                                                top+_offset_y,
605                                                text->sel_end_cursor.x,
606                                                bottom - top);
607                         }
608                 }
609         } else {
610                 top = text->sel_start_cursor.y
611                         - text->sel_start_cursor.row->baseline;
612                 bottom = text->sel_end_cursor.y
613                         - text->sel_end_cursor.row->baseline 
614                         + text->sel_end_cursor.row->height;
615                 
616                 if (top - first < 0)
617                         top = first;
618                 if (bottom - first < 0)
619                         bottom = first;
620                 
621                 if (bottom - first > _height)
622                         bottom = first + _height;
623                 if (top - first > _height)
624                         top = first + _height;
625                 
626                 if (kill_selection)
627                         text->selection = 0;
628                 DrawFromTo(top - first, bottom - first);
629                 expose(0, top - first, _width, bottom - first - (top - first));
630         }
631 }
632   
633    
634 void LyXScreen::ToggleToggle()
635 {
636         long top = 0;
637         long bottom = 0;
638         
639         if (text->toggle_cursor.par == text->toggle_end_cursor.par
640             && text->toggle_cursor.pos == text->toggle_end_cursor.pos)
641                 return;
642
643         if (fast_selection || mono_video){
644                 
645                 /* selection only in one row ?*/ 
646                 if (text->toggle_cursor.y == text->toggle_end_cursor.y) {
647                         
648                         /* only if anything is visible */ 
649                         if (text->toggle_cursor.y - text->toggle_cursor.row->baseline - first < _height
650                             && text->toggle_cursor.y - text->toggle_cursor.row->baseline + 
651                             text->toggle_cursor.row->height - first > 0) {
652                                 top = text->toggle_cursor.y - text->toggle_cursor.row->baseline - first;
653                                 bottom = top + text->toggle_cursor.row->height;
654                                 if (top < 0) top = 0;
655                                 if (bottom > _height) bottom = _height;
656                                 XFillRectangle(fl_display,_window,
657                                                getGC(gc_select),
658                                                text->toggle_cursor.x+_offset_x, 
659                                                top+_offset_y,
660                                                text->toggle_end_cursor.x  -
661                                                text->toggle_cursor.x,
662                                                bottom - top);
663                         }
664                 } else {
665                         /* the toggle_cursor row first */ 
666                         /* only if anything is visible */ 
667                         if (text->toggle_cursor.y - text->toggle_cursor.row->baseline - first < _height
668                             && text->toggle_cursor.y - text->toggle_cursor.row->baseline + 
669                             text->toggle_cursor.row->height - first > 0) {
670                                 top = text->toggle_cursor.y - text->toggle_cursor.row->baseline - first;
671                                 bottom = top + text->toggle_cursor.row->height;
672                                 if (top<0)
673                                         top = 0;
674                                 if (bottom > _height)
675                                         bottom = _height;
676                                 XFillRectangle(fl_display,_window,
677                                                getGC(gc_select),
678                                                text->toggle_cursor.x+_offset_x, 
679                                                top+_offset_y,
680                                                _width - text->toggle_cursor.x,
681                                                bottom - top);
682                         }
683                         
684                         /* the main body */ 
685                         
686                         if (text->toggle_cursor.row->next !=
687                             text->toggle_end_cursor.row) {
688                                 top = text->toggle_cursor.y
689                                         - text->toggle_cursor.row->baseline
690                                         + text->toggle_cursor.row->height;
691                                 bottom = text->toggle_end_cursor.y
692                                         - text->toggle_end_cursor.row->baseline;
693                                 
694                                 if (top - first < 0)
695                                         top = first;
696                                 if (bottom - first < 0)
697                                         bottom = first;
698                                 
699                                 if (bottom - first > _height)
700                                         bottom = first + _height;
701                                 if (top - first > _height)
702                                         top = first + _height;
703                                 
704                                 if (top != bottom) {
705                                         XFillRectangle(fl_display,_window,
706                                                        getGC(gc_select),
707                                                        0+_offset_x, 
708                                                        top - first+_offset_y,
709                                                        _width,
710                                                        bottom - top);
711                                 }
712                         }
713                         
714                         /* the toggle_end_cursor row last */ 
715                         if (text->toggle_end_cursor.y - text->toggle_end_cursor.row->baseline - first < _height
716                             && text->toggle_end_cursor.y - text->toggle_end_cursor.row->baseline +
717                             text->toggle_end_cursor.row->height - first > 0) {
718                                 top = text->toggle_end_cursor.y
719                                         - text->toggle_end_cursor.row->baseline
720                                         - first;
721                                 bottom = top
722                                         + text->toggle_end_cursor.row->height;
723                                 if (top<0)
724                                         top = 0;
725                                 if (bottom > _height)
726                                         bottom = _height;
727                                 XFillRectangle(fl_display,_window,
728                                                getGC(gc_select),
729                                                0+_offset_x, 
730                                                top+_offset_y,
731                                                text->toggle_end_cursor.x,
732                                                bottom - top);
733                         }
734                 }
735         } else {
736                 top = text->toggle_cursor.y
737                         - text->toggle_cursor.row->baseline;
738                 bottom = text->toggle_end_cursor.y
739                         - text->toggle_end_cursor.row->baseline 
740                         + text->toggle_end_cursor.row->height;
741                 
742                 if (top - first < 0)
743                         top = first;
744                 if (bottom - first < 0)
745                         bottom = first;
746                 
747                 if (bottom - first > _height)
748                         bottom = first + _height;
749                 if (top - first > _height)
750                         top = first + _height;
751                 
752                 DrawFromTo(top - first, bottom - first);
753                 expose(0, top - first, _width, bottom - first - (top - first));
754         }
755 }
756
757
758         
759 void LyXScreen::drawTableLine(int baseline, int x, int length, bool on_off)
760 {
761         GC gc;
762         if (on_off)
763                 gc = getGC(gc_thin_on_off_line);
764         else
765                 gc = getGC(gc_copy);
766         drawLine(gc,
767                  x,
768                  baseline,
769                  x + length,
770                  baseline);
771 }
772
773         
774 void LyXScreen::drawVerticalTableLine(int x, int y1, int y2, bool on_off)
775 {
776         GC gc;
777         if (on_off)
778                 gc = getGC(gc_thin_on_off_line);
779         else
780                 gc = getGC(gc_copy);
781         drawLine(gc,
782                  x,
783                  y1,
784                  x,
785                  y2);
786 }
787
788
789 void LyXScreen::drawFrame(int /*ft*/, int x, int y, int w, int h,
790                           FL_COLOR /*col*/, int /*b*/)
791 {
792 // Implement this using X11 calls, and the repaint problems are gone!
793 // At least, I think that should do it since we only have them after
794 // one of these buttons are displayed now! Lars, it seems you've hit the
795 // nail :-) (Asger)
796 //      fl_winset(foreground);
797 //      fl_drw_frame(ft, x,  y,  w,  h, col, b);
798         // This should be changed to draw a button like frame, in the
799         // mean time we'll just use a regular rectangle
800      
801          // I want the buttons back before 0.12. OK, this is very simple,
802          // like what is done in xforms sources.  (Ale)
803
804         // This one is too dirty. Get rid of it.
805         extern GC fl_gc;
806
807         // Please comment this annonymous variable.
808         int d = 2;
809
810         // I think these calls to fl_color might make xforms sometimes
811         // draw the wrong color on other objects.
812         fl_color(FL_TOP_BCOL);
813         XFillRectangle(fl_display, foreground, fl_gc,x-d,y-d,w+2*d,d);
814         fl_color(FL_BOTTOM_BCOL);
815         XFillRectangle(fl_display, foreground, fl_gc,x-d,y+h,w+2*d,d);
816  
817         // Now a couple of trapezoids
818         XPoint pl[4], pr[4]; 
819  
820         pl[0].x = x-d;   pl[0].y = y-d;
821         pl[1].x = x-d;   pl[1].y = y+h+d;
822         pl[2].x = x;     pl[2].y = y+h;
823         pl[3].x = x;     pl[3].y = y;
824         
825         pr[0].x = x+w+d; pr[0].y = y-d;
826         pr[1].x = x+w+d; pr[1].y = y+h+d;
827         pr[2].x = x+w;   pr[2].y = y+h;
828         pr[3].x = x+w;   pr[3].y = y;
829         
830         fl_color(FL_LEFT_BCOL);
831         XFillPolygon(fl_display,
832                      foreground,
833                      fl_gc, pl, 4,
834                      Convex, CoordModeOrigin); 
835         fl_color(FL_RIGHT_BCOL);
836         XFillPolygon(fl_display,
837                      foreground,
838                      fl_gc, pr, 4,
839                      Convex, CoordModeOrigin); 
840 }