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