]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GScreen.C
Display accelerator (binding) labels in menus.
[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 #include "GScreen.h"
14
15 #include "GWorkArea.h"
16
17 #include "buffer.h"
18 #include "BufferView.h"
19 #include "debug.h"
20 #include "language.h"
21 #include "LColor.h"
22 #include "lyxtext.h"
23 #include "lyxrow.h"
24
25 #include "frontends/screen.h"
26 #include "frontends/font_metrics.h"
27 #include "frontends/Painter.h"
28 #include "frontends/WorkArea.h"
29
30 #include "insets/insettext.h"
31
32 #include <algorithm>
33
34 namespace lyx {
35 namespace frontend {
36
37 GScreen::GScreen(GWorkArea & o)
38         : LyXScreen(), owner_(o)
39 {
40         // the cursor isnt yet visible
41         cursorX_ = 0;
42         cursorY_ = 0;
43         cursorW_ = 0;
44         cursorH_ = 0;
45 }
46
47
48 GScreen::~GScreen()
49 {
50 }
51
52
53 WorkArea & GScreen::workarea() const
54 {
55         return owner_;
56 }
57
58
59 void GScreen::setCursorColor(Glib::RefPtr<Gdk::GC> gc)
60 {
61         Gdk::Color * clr = owner_.getColorHandler().
62                 getGdkColor(LColor::cursor);
63         gc->set_foreground(*clr);
64 }
65
66
67 void GScreen::showCursor(int x, int y, int h, Cursor_Shape shape)
68 {
69         // Update the cursor color.
70         setCursorColor(owner_.getGC());
71
72         cursorX_ = x;
73         cursorY_ = y;
74         cursorH_ = h;
75
76         switch (shape) {
77         case BAR_SHAPE:
78                 cursorW_ = 1;
79                 break;
80         case L_SHAPE:
81                 cursorW_ = cursorH_ / 3;
82                 break;
83         case REVERSED_L_SHAPE:
84                 cursorW_ = cursorH_ / 3;
85                 cursorX_ = x - cursorW_ + 1;
86                 break;
87         }
88
89         int fx, fy, fwidth, fheight, fdepth;
90         owner_.getWindow()->get_geometry(fx, fy, fwidth, fheight, fdepth);
91         cursorPixmap_ = Gdk::Pixmap::create(owner_.getWindow(),
92                                             cursorW_,
93                                             cursorH_,
94                                             fdepth);
95         cursorPixmap_->draw_drawable(owner_.getGC(),
96                                      owner_.getWindow(),
97                                      owner_.xpos() + cursorX_,
98                                      owner_.ypos() + cursorY_,
99                                      0, 0,
100                                      cursorW_,
101                                      cursorH_);
102         owner_.getWindow()->draw_line(owner_.getGC(),
103                                       x + owner_.xpos(),
104                                       y + owner_.ypos(),
105                                       x + owner_.xpos(),
106                                       y + h - 1 + owner_.ypos());
107         switch (shape) {
108         case BAR_SHAPE:
109                 break;
110         case L_SHAPE:
111         case REVERSED_L_SHAPE:
112                 owner_.getWindow()->draw_line(owner_.getGC(),
113                                               owner_.xpos() + cursorX_,
114                                               owner_.ypos() + y + h - 1,
115                                               owner_.xpos() + cursorX_ + cursorW_ - 1,
116                                               owner_.xpos() + y + h - 1);
117                 break;
118         }
119 }
120
121
122 void GScreen::removeCursor()
123 {
124         if (cursorPixmap_) {
125                 owner_.getWindow()->draw_drawable(owner_.getGC(),
126                                                   cursorPixmap_,
127                                                   0, 0,
128                                                   cursorX_ + owner_.xpos(),
129                                                   cursorY_ + owner_.ypos(),
130                                                   cursorW_, cursorH_);
131         }
132 }
133
134
135 void GScreen::expose(int x, int y, int w, int h)
136 {
137         lyxerr[Debug::GUI] << "expose " << w << 'x' << h
138                 << '+' << x << '+' << y << std::endl;
139         owner_.getWindow()->draw_drawable(owner_.getGC(),
140                                           owner_.getPixmap(),
141                                           x, y,
142                                           x + owner_.xpos(),
143                                           y + owner_.ypos(),
144                                           w, h);
145 }
146
147 } // namespace frontend
148 } // namespace lyx