]> git.lyx.org Git - lyx.git/blob - src/frontends/GuiCursor.C
This is the merging of the GUI API cleanup branch that was developed in svn+ssh:...
[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 #include <boost/utility.hpp>
46 #include <boost/bind.hpp>
47 #include <boost/signals/trackable.hpp>
48
49 using lyx::support::libFileSearch;
50
51 using std::endl;
52 using std::min;
53 using std::max;
54 using std::string;
55
56 namespace lyx {
57 namespace frontend {
58
59 GuiCursor::GuiCursor()
60         : cursor_visible_(false), work_area_(NULL)
61 {
62 }
63
64
65 GuiCursor::~GuiCursor()
66 {
67 }
68
69 void GuiCursor::connect(WorkArea * work_area)
70 {
71         work_area_ = work_area;
72 }
73
74
75 void GuiCursor::show(BufferView & bv)
76 {
77         if (cursor_visible_)
78                 return;
79
80         if (!bv.available())
81                 return;
82
83         Cursor_Shape shape = BAR_SHAPE;
84
85         LyXText const & text = *bv.getLyXText();
86         LyXFont const & realfont = text.real_current_font;
87         BufferParams const & bp = bv.buffer()->params();
88         bool const samelang = realfont.language() == bp.language;
89         bool const isrtl = realfont.isVisibleRightToLeft();
90
91         if (!samelang || isrtl != bp.language->rightToLeft()) {
92                 shape = L_SHAPE;
93                 if (isrtl)
94                         shape = REVERSED_L_SHAPE;
95         }
96
97         // The ERT language hack needs fixing up
98         if (realfont.language() == latex_language)
99                 shape = BAR_SHAPE;
100
101         LyXFont const font = bv.cursor().getFont();
102         int const asc = font_metrics::maxAscent(font);
103         int const des = font_metrics::maxDescent(font);
104         int h = asc + des;
105         int x = 0;
106         int y = 0;
107         bv.cursor().getPos(x, y);
108         y -= asc;
109         //lyxerr << "Cursor::show x: " << x << " y: " << y << endl;
110
111         BOOST_ASSERT(work_area_);
112
113         // if it doesn't touch the screen, don't try to show it
114         if (y + h < 0 || y >= work_area_->height())
115                 return;
116
117         cursor_visible_ = true;
118         work_area_->showCursor(x, y, h, shape);
119 }
120
121
122 void GuiCursor::hide()
123 {
124         if (!cursor_visible_)
125                 return;
126
127         cursor_visible_ = false;
128         BOOST_ASSERT(work_area_);
129         work_area_->removeCursor();
130 }
131
132
133 void GuiCursor::toggle(BufferView & bv)
134 {
135         if (cursor_visible_)
136                 hide();
137         else
138                 show(bv);
139 }
140
141
142 void GuiCursor::prepare()
143 {
144         cursor_visible_ = false;
145 }
146
147 } // namespace frontend
148 } // namespace lyx
149