]> git.lyx.org Git - lyx.git/blob - src/frontends/GuiCursor.C
Extracted from r14281
[lyx.git] / src / frontends / GuiCursor.C
1 /**
2  * \file GuiCursor.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * Splash screen code added by Angus Leeming
12  */
13
14 #include <config.h>
15
16 #include "frontends/GuiCursor.h"
17
18 #include "font_metrics.h"
19 #include "lyx_gui.h"
20 #include "frontends/Painter.h"
21 #include "frontends/WorkArea.h"
22
23 #include "BufferView.h"
24 #include "buffer.h"
25 #include "bufferparams.h"
26 #include "coordcache.h"
27 #include "cursor.h"
28 #include "debug.h"
29 #include "language.h"
30 #include "LColor.h"
31 #include "lyxfont.h"
32 #include "lyxrc.h"
33 #include "lyxrow.h"
34 #include "lyxtext.h"
35 #include "metricsinfo.h"
36 #include "paragraph.h"
37 #include "rowpainter.h"
38 #include "version.h"
39
40 #include "graphics/GraphicsImage.h"
41 #include "graphics/GraphicsLoader.h"
42
43 #include "support/filetools.h" // LibFileSearch
44
45 using lyx::support::libFileSearch;
46
47 using std::endl;
48 using std::min;
49 using std::max;
50 using std::string;
51
52 namespace lyx {
53 namespace frontend {
54
55 GuiCursor::GuiCursor()
56         : cursor_visible_(false), work_area_(0)
57 {
58 }
59
60
61 GuiCursor::~GuiCursor()
62 {
63 }
64
65 void GuiCursor::connect(WorkArea * work_area)
66 {
67         work_area_ = work_area;
68 }
69
70
71 void GuiCursor::show(BufferView & bv)
72 {
73         if (cursor_visible_)
74                 return;
75
76         if (!bv.available())
77                 return;
78
79         CursorShape shape = BAR_SHAPE;
80
81         LyXText const & text = *bv.getLyXText();
82         LyXFont const & realfont = text.real_current_font;
83         BufferParams const & bp = bv.buffer()->params();
84         bool const samelang = realfont.language() == bp.language;
85         bool const isrtl = realfont.isVisibleRightToLeft();
86
87         if (!samelang || isrtl != bp.language->rightToLeft()) {
88                 shape = L_SHAPE;
89                 if (isrtl)
90                         shape = REVERSED_L_SHAPE;
91         }
92
93         // The ERT language hack needs fixing up
94         if (realfont.language() == latex_language)
95                 shape = BAR_SHAPE;
96
97         LyXFont const font = bv.cursor().getFont();
98         int const asc = font_metrics::maxAscent(font);
99         int const des = font_metrics::maxDescent(font);
100         int h = asc + des;
101         int x = 0;
102         int y = 0;
103         bv.cursor().getPos(x, y);
104         y -= asc;
105         //lyxerr << "Cursor::show x: " << x << " y: " << y << endl;
106
107         BOOST_ASSERT(work_area_);
108
109         // if it doesn't touch the screen, don't try to show it
110         if (y + h < 0 || y >= work_area_->height())
111                 return;
112
113         cursor_visible_ = true;
114         work_area_->showCursor(x, y, h, shape);
115 }
116
117
118 void GuiCursor::hide()
119 {
120         if (!cursor_visible_)
121                 return;
122
123         cursor_visible_ = false;
124         BOOST_ASSERT(work_area_);
125         work_area_->removeCursor();
126 }
127
128
129 void GuiCursor::toggle(BufferView & bv)
130 {
131         if (cursor_visible_)
132                 hide();
133         else
134                 show(bv);
135 }
136
137
138 void GuiCursor::prepare()
139 {
140         cursor_visible_ = false;
141 }
142
143 } // namespace frontend
144 } // namespace lyx