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