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