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