]> git.lyx.org Git - features.git/blob - src/frontends/xforms/xscreen.C
This is the merging of the GUI API cleanup branch that was developed in svn+ssh:...
[features.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         : 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 void XScreen::setCursorColor()
63 {
64         if (!lyxColorHandler.get())
65                 return;
66
67         GC gc = lyxColorHandler->getGCForeground(LColor::cursor);
68
69         XGCValues val;
70         XGetGCValues(fl_get_display(),
71                      gc, GCForeground, &val);
72         XChangeGC(fl_get_display(), gc_copy, GCForeground, &val);
73 }
74
75
76 void XScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
77 {
78         // Update the cursor color. (a little slow doing it like this ??)
79         setCursorColor();
80
81         cursor_x_ = x;
82         cursor_y_ = y;
83         cursor_h_ = h;
84
85         switch (shape) {
86                 case BAR_SHAPE:
87                         cursor_w_ = 1;
88                         break;
89                 case L_SHAPE:
90                         cursor_w_ = cursor_h_ / 3;
91                         break;
92                 case REVERSED_L_SHAPE:
93                         cursor_w_ = cursor_h_ / 3;
94                         cursor_x_ = x - cursor_w_ + 1;
95                         break;
96         }
97
98         if (nocursor_pixmap_) {
99                 XFreePixmap(fl_get_display(), nocursor_pixmap_);
100                 nocursor_pixmap_ = 0;
101         }
102         nocursor_pixmap_ = XCreatePixmap(fl_get_display(),
103                 fl_root, cursor_w_, cursor_h_, fl_get_visual_depth());
104
105         // save old area
106         XCopyArea(fl_get_display(),
107                 owner_.getWin(), nocursor_pixmap_, gc_copy,
108                 owner_.xpos() + cursor_x_,
109                 owner_.ypos() + cursor_y_,
110                 cursor_w_, cursor_h_, 0, 0);
111
112 // xforms equivalent needed here
113 #if 0
114         if (!qApp->focusWidget())
115                 return;
116 #endif
117
118         XDrawLine(fl_get_display(), owner_.getWin(), gc_copy,
119                 owner_.xpos() + x, owner_.ypos() + y,
120                 owner_.xpos() + x, owner_.ypos() + y + h - 1);
121
122         switch (shape) {
123                 case BAR_SHAPE:
124                         break;
125                 case REVERSED_L_SHAPE:
126                 case L_SHAPE:
127                         XDrawLine(fl_get_display(), owner_.getWin(), gc_copy,
128                                 owner_.xpos() + cursor_x_,
129                                 owner_.ypos() + y + h - 1,
130                                 owner_.xpos() + cursor_x_ + cursor_w_ - 1,
131                                 owner_.ypos() + y + h - 1);
132                         break;
133         }
134 }
135
136
137 void XScreen::removeCursor()
138 {
139         // before first showCursor
140         if (!nocursor_pixmap_)
141                 return;
142
143         XCopyArea(fl_get_display(), nocursor_pixmap_, owner_.getWin(),
144                 gc_copy, 0, 0, cursor_w_, cursor_h_,
145                 owner_.xpos() + cursor_x_,
146                 owner_.ypos() + cursor_y_);
147 }
148
149
150 void XScreen::expose(int x, int y, int w, int h)
151 {
152         lyxerr[Debug::GUI] << "XScreen::expose " << w << 'x' << h
153                 << '+' << x << '+' << y << endl;
154
155         XCopyArea(fl_get_display(),
156                   owner_.getPixmap(),
157                   owner_.getWin(),
158                   gc_copy,
159                   x, y, w, h,
160                   x + owner_.xpos(),
161                   y + owner_.ypos());
162 }
163
164 } // namespace frontend
165 } // namespace lyx