]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GScreen.C
some tabular fixes for the problems reported by Helge
[lyx.git] / src / frontends / gtk / GScreen.C
1 /**
2  * \file GScreen.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Huang Ying
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "GScreen.h"
22
23 #include "GWorkArea.h"
24
25 #include "buffer.h"
26 #include "BufferView.h"
27 #include "debug.h"
28 #include "language.h"
29 #include "LColor.h"
30 #include "lyxtext.h"
31 #include "lyxrow.h"
32
33 #include "frontends/screen.h"
34 #include "frontends/font_metrics.h"
35 #include "frontends/Painter.h"
36 #include "frontends/WorkArea.h"
37
38 #include "insets/insettext.h"
39
40 #include <algorithm>
41
42 namespace lyx {
43 namespace frontend {
44
45 GScreen::GScreen(GWorkArea & o)
46         : LyXScreen(), owner_(o)
47 {
48         // the cursor isnt yet visible
49         cursorX_ = 0;
50         cursorY_ = 0;
51         cursorW_ = 0;
52         cursorH_ = 0;
53 }
54
55
56 GScreen::~GScreen()
57 {
58 }
59
60
61 WorkArea & GScreen::workarea() const
62 {
63         return owner_;
64 }
65
66
67 void GScreen::setCursorColor(Glib::RefPtr<Gdk::GC> gc)
68 {
69         Gdk::Color * clr = owner_.getColorHandler().
70                 getGdkColor(LColor::cursor);
71         gc->set_foreground(*clr);
72 }
73
74
75 void GScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
76 {
77         // Update the cursor color.
78         setCursorColor(owner_.getGC());
79
80         cursorX_ = x;
81         cursorY_ = y;
82         cursorH_ = h;
83
84         switch (shape) {
85         case BAR_SHAPE:
86                 cursorW_ = 1;
87                 break;
88         case L_SHAPE:
89                 cursorW_ = cursorH_ / 3;
90                 break;
91         case REVERSED_L_SHAPE:
92                 cursorW_ = cursorH_ / 3;
93                 cursorX_ = x - cursorW_ + 1;
94                 break;
95         }
96
97         int fx, fy, fwidth, fheight, fdepth;
98         owner_.getWindow()->get_geometry(fx, fy, fwidth, fheight, fdepth);
99         cursorPixmap_ = Gdk::Pixmap::create(owner_.getWindow(),
100                                             cursorW_,
101                                             cursorH_,
102                                             fdepth);
103         cursorPixmap_->draw_drawable(owner_.getGC(),
104                                      owner_.getWindow(),
105                                      owner_.xpos() + cursorX_,
106                                      owner_.ypos() + cursorY_,
107                                      0, 0,
108                                      cursorW_,
109                                      cursorH_);
110         owner_.getWindow()->draw_line(owner_.getGC(),
111                                       x + owner_.xpos(),
112                                       y + owner_.ypos(),
113                                       x + owner_.xpos(),
114                                       y + h - 1 + owner_.ypos());
115         switch (shape) {
116         case BAR_SHAPE:
117                 break;
118         case L_SHAPE:
119         case REVERSED_L_SHAPE:
120                 owner_.getWindow()->draw_line(owner_.getGC(),
121                                               owner_.xpos() + cursorX_,
122                                               owner_.ypos() + y + h - 1,
123                                               owner_.xpos() + cursorX_ + cursorW_ - 1,
124                                               owner_.xpos() + y + h - 1);
125                 break;
126         }
127 }
128
129
130 void GScreen::removeCursor()
131 {
132         if (cursorPixmap_) {
133                 owner_.getWindow()->draw_drawable(owner_.getGC(),
134                                                   cursorPixmap_,
135                                                   0, 0,
136                                                   cursorX_ + owner_.xpos(),
137                                                   cursorY_ + owner_.ypos(),
138                                                   cursorW_, cursorH_);
139         }
140 }
141
142
143 void GScreen::expose(int x, int y, int w, int h)
144 {
145         lyxerr[Debug::GUI] << "expose " << w << 'x' << h
146                 << '+' << x << '+' << y << std::endl;
147         owner_.getWindow()->draw_drawable(owner_.getGC(),
148                                           owner_.getPixmap(),
149                                           x, y,
150                                           x + owner_.xpos(),
151                                           y + owner_.ypos(),
152                                           w, h);
153 }
154
155 } // namespace frontend
156 } // namespace lyx