]> git.lyx.org Git - lyx.git/blob - src/BufferView.h
update no.po
[lyx.git] / src / BufferView.h
1 // -*- C++ -*-
2 /**
3  * \file BufferView.h
4  * Copyright 2002 the LyX Team
5  * Read the file COPYING
6  *
7  *  \author Lars Gullik Bjønnes
8 */
9
10 #ifndef BUFFER_VIEW_H
11 #define BUFFER_VIEW_H
12
13 #ifdef __GNUG__
14 #pragma interface
15 #endif
16
17 #include "LString.h"
18 #include "undo.h"
19
20 #include "insets/inset.h"
21
22 #include <boost/utility.hpp>
23
24 class LyXView;
25 class LyXText;
26 class TeXErrors;
27 class Buffer;
28 class LyXScreen;
29 class Language;
30 class Painter;
31 class UpdatableInset;
32 class WordLangTuple;
33 class Encoding;
34
35 /**
36  * A buffer view encapsulates a view onto a particular
37  * buffer, and allows access to operate upon it. A view
38  * is a sliding window of the entire document rendering.
39  *
40  * Eventually we will allow several views onto a single
41  * buffer, but not yet.
42  */
43 class BufferView : boost::noncopyable {
44 public:
45         /**
46          * Codes to store necessary pending updates
47          * of the document rendering.
48          */
49         enum UpdateCodes {
50                 UPDATE = 0, //< FIXME
51                 SELECT = 1, //< selection change
52                 FITCUR = 2, //< the cursor needs fitting into the view
53                 CHANGE = 4  //< document data has changed
54         };
55
56         /**
57          * Create a view with the given owner main window,
58          * of the given dimensions.
59          */
60         BufferView(LyXView * owner, int x, int y, int w, int h);
61
62         ~BufferView();
63
64         /// set the buffer we are viewing
65         void buffer(Buffer * b);
66         /// return the buffer being viewed
67         Buffer * buffer() const;
68
69         /// return the painter object for drawing onto the view
70         Painter & painter() const;
71         /// return the screen object for handling re-drawing
72         LyXScreen & screen() const;
73         /// return the owning main view
74         LyXView * owner() const;
75
76         /// resize event has happened
77         void resize();
78         /**
79          * Repaint the pixmap. Used for when we don't want
80          * to go through the full update() logic, just a simple
81          * repaint of the whole screen.
82          */
83         void repaint();
84
85         /// fit the user cursor within the visible view
86         bool fitCursor();
87         /// perform pending painting updates
88         void update();
89         // update for a particular lyxtext
90         void update(LyXText *, UpdateCodes uc);
91         /// update for a particular inset
92         void updateInset(Inset * inset, bool mark_dirty);
93         /// reset the scrollbar to reflect current view position
94         void updateScrollbar();
95         /// FIXME
96         void redoCurrentBuffer();
97
98         /// FIXME
99         bool available() const;
100
101         /// FIXME
102         void beforeChange(LyXText *);
103
104         /// Save the current position as bookmark i
105         void savePosition(unsigned int i);
106         /// Restore the position from bookmark i
107         void restorePosition(unsigned int i);
108         /// does the given bookmark have a saved position ?
109         bool isSavedPosition(unsigned int i);
110
111         /**
112          * This holds the mapping between buffer paragraphs and screen rows.
113          * This should be private...but not yet. (Lgb)
114          */
115         LyXText * text;
116         /// return the lyxtext we are using
117         LyXText * getLyXText() const;
118
119         /// Return the current inset we are "locked" in
120         UpdatableInset * theLockingInset() const;
121         /// lock the given inset FIXME: return value ?
122         bool lockInset(UpdatableInset * inset);
123         /// unlock the given inset
124         int unlockInset(UpdatableInset * inset);
125         /// unlock the currently locked inset
126         void insetUnlock();
127
128         /// return the current encoding at the cursor
129         Encoding const * getEncoding() const;
130
131         /// return the parent language of the given inset
132         Language const * getParentLanguage(Inset * inset) const;
133
134         /// Select the "current" word
135         void selectLastWord();
136         /// replace the currently selected word
137         void replaceWord(string const & replacestring);
138         /// Update after spellcheck finishes
139         void endOfSpellCheck();
140         /// return the next word
141         WordLangTuple const nextWord(float & value);
142
143         /// move cursor to the named label
144         bool gotoLabel(string const & label);
145
146         /// copy the environment type from current paragraph
147         void copyEnvironment();
148         /// set the current paragraph's environment type
149         void pasteEnvironment();
150
151         /// undo last action
152         void undo();
153         /// redo last action
154         void redo();
155
156         /// removes all autodeletable insets
157         bool removeAutoInsets();
158         /// insert all errors found when running latex
159         void insertErrors(TeXErrors & terr);
160         /// set the cursor based on the given TeX source row
161         void setCursorFromRow(int row);
162
163         /**
164          * Insert an inset into the buffer.
165          * Place it in a layout of lout,
166          */
167         bool insertInset(Inset * inset, string const & lout = string());
168
169         /// Inserts a lyx file at cursor position. return false if it fails
170         bool insertLyXFile(string const & file);
171
172         /// show the user cursor
173         void showCursor();
174         /// hide the user cursor
175         void hideCursor();
176         /// FIXME
177         void showLockedInsetCursor(int x, int y, int asc, int desc);
178         /// FIXME
179         void hideLockedInsetCursor();
180         /// FIXME
181         bool fitLockedInsetCursor(int x, int y, int asc, int desc);
182         /// FIXME
183         void lockedInsetStoreUndo(Undo::undo_kind kind);
184         /// FIXME
185         void toggleSelection(bool = true);
186         /// FIXME: my word !
187         void toggleToggle();
188
189         /// center the document view around the cursor
190         void center();
191         /// scroll document by the given number of lines of default height
192         void scroll(int lines);
193         /// Scroll the view by a number of pixels
194         void scrollDocView(int);
195
196         /// height of a normal line in pixels (zoom factor considered)
197         int defaultHeight() const;
198         /// return the pixel width of the document view
199         int workWidth() const;
200         /// return the pixel height of the document view
201         int workHeight() const;
202
203         /// switch between primary and secondary keymaps for RTL entry
204         void switchKeyMap();
205
206         /// FIXME
207         bool ChangeRefsIfUnique(string const & from, string const & to);
208         /// FIXME
209         bool ChangeCitationsIfUnique(string const & from, string const & to);
210
211         /// get the contents of the window system clipboard
212         string const getClipboard() const;
213         /// fill the window system clipboard
214         void stuffClipboard(string const &) const;
215         /// tell the window system we have a selection
216         void haveSelection(bool sel);
217
218         /// execute the given function
219         bool dispatch(FuncRequest const & argument);
220
221 private:
222         /// Set the current locking inset
223         void theLockingInset(UpdatableInset * inset);
224
225         /// return the lyxtext containing this inset
226         LyXText * getParentText(Inset * inset) const;
227
228         /**
229          * Change all insets with the given code's contents to a new
230          * string. May only be used with InsetCommand-derived insets
231          * Returns true if a screen update is needed.
232          */
233         bool ChangeInsets(Inset::Code code, string const & from,
234                           string const & to);
235
236
237         struct Pimpl;
238         friend struct BufferView::Pimpl;
239
240         Pimpl * pimpl_;
241 };
242
243
244 BufferView::UpdateCodes operator|(BufferView::UpdateCodes uc1,
245                                   BufferView::UpdateCodes uc2);
246
247 #endif // BUFFERVIEW_H