]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GScreen.C
Minipage is no more (long live the box inset)
[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 #include <gtkmm.h>
13
14 #include "GScreen.h"
15
16 #include "GWorkArea.h"
17
18 #include "buffer.h"
19 #include "BufferView.h"
20 #include "debug.h"
21 #include "language.h"
22 #include "LColor.h"
23 #include "lyxtext.h"
24 #include "lyxrow.h"
25
26 #include "frontends/screen.h"
27 #include "frontends/font_metrics.h"
28 #include "frontends/Painter.h"
29 #include "frontends/WorkArea.h"
30
31 #include "insets/insettext.h"
32
33 #include <algorithm>
34
35
36 GScreen::GScreen(GWorkArea & o)
37         : LyXScreen(), owner_(o)
38 {
39         // the cursor isnt yet visible
40         cursorX_ = 0;
41         cursorY_ = 0;
42         cursorW_ = 0;
43         cursorH_ = 0;
44 }
45
46
47 GScreen::~GScreen()
48 {
49 }
50
51
52 WorkArea & GScreen::workarea() const
53 {
54         return owner_;
55 }
56
57
58 void GScreen::setCursorColor(Glib::RefPtr<Gdk::GC> gc)
59 {
60         Gdk::Color * clr = owner_.getColorHandler().
61                 getGdkColor(LColor::cursor);
62         gc->set_foreground(*clr);
63 }
64
65
66 void GScreen::showCursor(int x, int y,
67                          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 }