]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/xscreen.C
drop a few fitCursor() and draw() calls
[lyx.git] / src / frontends / xforms / xscreen.C
1 /**
2  * \file xscreen.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #include <config.h>
13
14
15 #include <algorithm>
16 #include <X11/Xlib.h>
17
18 #include "frontends/screen.h"
19 #include "frontends/font_metrics.h"
20 #include "XWorkArea.h"
21 #include "xscreen.h"
22 #include "lyxtext.h"
23 #include "lyxrow.h"
24 #include "Painter.h"
25 #include "WorkArea.h"
26 #include "buffer.h"
27 #include "BufferView.h"
28 #include "insets/insettext.h"
29 #include "ColorHandler.h"
30 #include "language.h"
31 #include "debug.h"
32
33 using std::endl;
34 using std::max;
35 using std::min;
36
37 namespace {
38
39 GC createGC()
40 {
41         XGCValues val;
42         val.foreground = BlackPixel(fl_get_display(),
43                                     DefaultScreen(fl_get_display()));
44
45         val.function = GXcopy;
46         val.graphics_exposures = false;
47         val.line_style = LineSolid;
48         val.line_width = 0;
49         return XCreateGC(fl_get_display(), RootWindow(fl_get_display(), 0),
50                          GCForeground | GCFunction | GCGraphicsExposures
51                          | GCLineWidth | GCLineStyle, &val);
52 }
53
54 } // namespace anon
55
56
57 XScreen::XScreen(XWorkArea & o)
58         : LyXScreen(), owner_(o), nocursor_pixmap_(0),
59         cursor_x_(0), cursor_y_(0), cursor_w_(0), cursor_h_(0)
60 {
61         // We need this GC
62         gc_copy = createGC();
63 }
64
65
66 XScreen::~XScreen()
67 {
68         XFreeGC(fl_get_display(), gc_copy);
69 }
70
71
72 void XScreen::setCursorColor()
73 {
74         if (!lyxColorHandler.get())
75                 return;
76
77         GC gc = lyxColorHandler->getGCForeground(LColor::cursor);
78
79         XGCValues val;
80         XGetGCValues(fl_get_display(),
81                      gc, GCForeground, &val);
82         XChangeGC(fl_get_display(), gc_copy, GCForeground, &val);
83 }
84
85
86 void XScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
87 {
88         // Update the cursor color. (a little slow dooing it like this ??)
89         setCursorColor();
90
91         cursor_x_ = x;
92         cursor_y_ = y;
93         cursor_h_ = h;
94
95         switch (shape) {
96                 case BAR_SHAPE:
97                         cursor_w_ = 1;
98                         break;
99                 case L_SHAPE:
100                         cursor_w_ = cursor_h_ / 3;
101                         break;
102                 case REVERSED_L_SHAPE:
103                         cursor_w_ = cursor_h_ / 3;
104                         cursor_x_ = x - cursor_w_ + 1;
105                         break;
106         }
107
108         if (nocursor_pixmap_) {
109                 XFreePixmap(fl_get_display(), nocursor_pixmap_);
110                 nocursor_pixmap_ = 0;
111         }
112         nocursor_pixmap_ = XCreatePixmap(fl_get_display(),
113                 fl_root, cursor_w_, cursor_h_, fl_get_visual_depth());
114
115         // save old area
116         XCopyArea(fl_get_display(),
117                 owner_.getWin(), nocursor_pixmap_, gc_copy,
118                 owner_.xpos() + cursor_x_,
119                 owner_.ypos() + cursor_y_,
120                 cursor_w_, cursor_h_, 0, 0);
121
122 // xforms equivalent needed here
123 #if 0
124         if (!qApp->focusWidget())
125                 return;
126 #endif
127
128         XDrawLine(fl_get_display(), owner_.getWin(), gc_copy,
129                 owner_.xpos() + x, owner_.ypos() + y,
130                 owner_.xpos() + x, owner_.ypos() + y + h - 1);
131
132         switch (shape) {
133                 case BAR_SHAPE:
134                         break;
135                 case REVERSED_L_SHAPE:
136                 case L_SHAPE:
137                         XDrawLine(fl_get_display(), owner_.getWin(), gc_copy,
138                                 owner_.xpos() + cursor_x_,
139                                 owner_.ypos() + y + h - 1,
140                                 owner_.xpos() + cursor_x_ + cursor_w_ - 1,
141                                 owner_.ypos() + y + h - 1);
142                         break;
143         }
144 }
145
146
147 void XScreen::removeCursor()
148 {
149         // before first showCursor
150         if (!nocursor_pixmap_)
151                 return;
152
153         XCopyArea(fl_get_display(), nocursor_pixmap_, owner_.getWin(),
154                 gc_copy, 0, 0, cursor_w_, cursor_h_,
155                 owner_.xpos() + cursor_x_,
156                 owner_.ypos() + cursor_y_);
157 }
158
159
160 void XScreen::expose(int x, int y, int w, int h)
161 {
162         lyxerr[Debug::GUI] << "expose " << w << 'x' << h
163                 << '+' << x << '+' << y << endl;
164         XCopyArea(fl_get_display(),
165                   owner_.getPixmap(),
166                   owner_.getWin(),
167                   gc_copy,
168                   x, y, w, h,
169                   x + owner_.xpos(),
170                   y + owner_.ypos());
171 }