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