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