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