]> git.lyx.org Git - lyx.git/blob - src/BufferView_pimpl.h
Extracted from r14281
[lyx.git] / src / BufferView_pimpl.h
1 // -*- C++ -*-
2 /**
3  * \file BufferView_pimpl.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Asger Alstrup
8  * \author Alfredo Braustein
9  * \author Lars Gullik Bjønnes
10  * \author John Levon
11  * \author André Pönitz
12  * \author Dekel Tsur
13  * \author Jürgen Vigna
14  *
15  * Full author contact details are available in file CREDITS.
16  */
17
18 #ifndef BUFFERVIEW_PIMPL_H
19 #define BUFFERVIEW_PIMPL_H
20
21 #include "BufferView.h"
22 #include "cursor.h"
23 #include "errorlist.h"
24 #include "metricsinfo.h"
25
26 #include "frontends/LyXKeySym.h"
27 #include "frontends/Timeout.h"
28
29 #include "support/types.h"
30
31 #include <boost/signals/trackable.hpp>
32
33 class Change;
34 class LyXView;
35
36 class FuncRequest;
37 class FuncStatus;
38 class ViewMetricsInfo;
39
40 namespace lyx {
41 namespace frontend {
42 class Gui;
43 }
44 }
45
46
47 ///
48 class BufferView::Pimpl : public boost::signals::trackable {
49 public:
50         ///
51         Pimpl(BufferView & bv, LyXView * owner);
52         ///
53         void setBuffer(Buffer * buf);
54         ///
55         void resizeCurrentBuffer();
56         //
57         bool fitCursor();
58         //
59         bool multiParSel();
60         ///
61         void update(Update::flags flags = Update::Force);
62         ///
63         void newFile(std::string const &, std::string const &, bool);
64         ///
65         bool loadLyXFile(std::string const &, bool);
66         ///
67         void workAreaResize(int width, int height);
68         ///
69         void updateScrollbar();
70         ///
71         ScrollbarParameters const & scrollbarParameters() const;
72         ///
73         void scrollDocView(int value);
74         /// Wheel mouse scroll, move by multiples of text->defaultRowHeight().
75         void scroll(int lines);
76         ///
77         void workAreaKeyPress(LyXKeySymPtr key, key_modifier::state state);
78         ///
79         void selectionRequested();
80         ///
81         void selectionLost();
82         ///
83         void cursorToggle();
84         ///
85         bool available() const;
86         /// get the change at the cursor position
87         Change const getCurrentChange();
88         ///
89         void savePosition(unsigned int i);
90         ///
91         void restorePosition(unsigned int i);
92         ///
93         bool isSavedPosition(unsigned int i);
94         /// save bookmarks to .lyx/session
95         void saveSavedPositions();
96         ///
97         void switchKeyMap();
98         ///
99         void center();
100         /// a function should be executed from the workarea
101         bool workAreaDispatch(FuncRequest const & ev);
102         /// return true for events that will handle
103         FuncStatus getStatus(FuncRequest const & cmd);
104         /// a function should be executed
105         bool dispatch(FuncRequest const & ev);
106
107         /// the frontend
108         lyx::frontend::Gui & gui() const;
109
110         /// Width and height of the BufferView in Pixels
111         /**
112         This is set externally by the workAreaResize method.
113         */
114         int width() const;
115         /// Height of the BufferView in Pixels
116         /**
117         This is set externally by the workAreaResize method.
118         */
119         int height() const;
120
121         ///
122         ViewMetricsInfo const & viewMetricsInfo();
123         ///
124         bool needsRedraw() const
125         {
126                 return needs_redraw_;
127         }
128         void needsRedraw(bool redraw_needed)
129         {
130                 needs_redraw_ = redraw_needed;
131         }
132 private:
133         ///
134         int width_;
135         ///
136         int height_;
137         ///
138         ScrollbarParameters scrollbarParameters_;
139         ///
140         bool needs_redraw_;
141
142         /// An error list (replaces the error insets)
143         ErrorList errorlist_;
144         /// add an error to the list
145         void addError(ErrorItem const &);
146         /// buffer errors signal connection
147         boost::signals::connection errorConnection_;
148         /// buffer messages signal connection
149         boost::signals::connection messageConnection_;
150         /// buffer busy status signal connection
151         boost::signals::connection busyConnection_;
152         /// buffer title changed signal connection
153         boost::signals::connection titleConnection_;
154         /// buffer reset timers signal connection
155         boost::signals::connection timerConnection_;
156         /// buffer readonly status changed signal connection
157         boost::signals::connection readonlyConnection_;
158         /// buffer closing signal connection
159         boost::signals::connection closingConnection_;
160         /// connect to signals in the given buffer
161         void connectBuffer(Buffer & buf);
162         /// disconnect from signals in the given buffer
163         void disconnectBuffer();
164         /// track changes for the document
165         void trackChanges();
166         /// notify readonly status
167         void showReadonly(bool);
168
169
170         ///
171         friend class BufferView;
172
173         ///
174         ViewMetricsInfo metrics_info_;
175         ///
176         void updateMetrics(bool singlepar = false);
177
178         ///
179         BufferView * bv_;
180         ///
181         LyXView * owner_;
182         ///
183         Buffer * buffer_;
184
185         /// Estimated average par height for scrollbar
186         int wh_;
187         ///
188         Timeout cursor_timeout;
189         ///
190         bool using_xterm_cursor;
191         ///
192         class Position {
193         public:
194                 /// Filename
195                 std::string filename;
196                 /// Cursor paragraph Id
197                 int par_id;
198                 /// Cursor position
199                 lyx::pos_type par_pos;
200                 ///
201                 Position() : par_id(0), par_pos(0) {}
202                 ///
203                 Position(std::string const & f, int id, lyx::pos_type pos)
204                         : filename(f), par_id(id), par_pos(pos) {}
205         };
206         ///
207         std::vector<Position> saved_positions;
208         ///
209         void menuInsertLyXFile(std::string const & filen);
210
211         /// this is used to handle XSelection events in the right manner
212         struct {
213                 CursorSlice cursor;
214                 CursorSlice anchor;
215                 bool set;
216         } xsel_cache_;
217         ///
218         LCursor cursor_;
219         ///
220         bool multiparsel_cache_;
221         ///
222         lyx::pit_type anchor_ref_;
223         ///
224         int offset_ref_;
225 };
226 #endif // BUFFERVIEW_PIMPL_H