1999-09-27 18:44:28 +00:00
|
|
|
|
// -*- C++ -*-
|
2002-08-04 23:11:50 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file BufferView.h
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
1999-11-04 01:40:20 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* \author Alfredo Braustein
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
|
|
|
|
* \author John Levon
|
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
1999-11-04 01:40:20 +00:00
|
|
|
|
#ifndef BUFFER_VIEW_H
|
|
|
|
|
#define BUFFER_VIEW_H
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2000-10-02 00:55:02 +00:00
|
|
|
|
#include <boost/utility.hpp>
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
#include <string>
|
|
|
|
|
|
2003-09-06 19:16:30 +00:00
|
|
|
|
class Buffer;
|
2003-02-08 19:18:01 +00:00
|
|
|
|
class Change;
|
2003-09-06 19:16:30 +00:00
|
|
|
|
class Encoding;
|
|
|
|
|
class ErrorList;
|
|
|
|
|
class FuncRequest;
|
|
|
|
|
class InsetOld;
|
|
|
|
|
class Language;
|
2003-11-04 12:36:59 +00:00
|
|
|
|
class LCursor;
|
2000-02-04 09:38:32 +00:00
|
|
|
|
class LyXText;
|
2002-06-18 15:44:30 +00:00
|
|
|
|
class LyXScreen;
|
2003-09-06 19:16:30 +00:00
|
|
|
|
class LyXView;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
class Painter;
|
2003-09-06 19:16:30 +00:00
|
|
|
|
class TeXErrors;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
class UpdatableInset;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* A buffer view encapsulates a view onto a particular
|
|
|
|
|
* buffer, and allows access to operate upon it. A view
|
|
|
|
|
* is a sliding window of the entire document rendering.
|
|
|
|
|
*
|
|
|
|
|
* Eventually we will allow several views onto a single
|
|
|
|
|
* buffer, but not yet.
|
|
|
|
|
*/
|
2001-04-17 13:43:57 +00:00
|
|
|
|
class BufferView : boost::noncopyable {
|
1999-09-27 18:44:28 +00:00
|
|
|
|
public:
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Create a view with the given owner main window,
|
|
|
|
|
* of the given dimensions.
|
|
|
|
|
*/
|
|
|
|
|
BufferView(LyXView * owner, int x, int y, int w, int h);
|
|
|
|
|
|
1999-12-10 00:07:59 +00:00
|
|
|
|
~BufferView();
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// set the buffer we are viewing
|
|
|
|
|
void buffer(Buffer * b);
|
|
|
|
|
/// return the buffer being viewed
|
2000-04-08 17:02:02 +00:00
|
|
|
|
Buffer * buffer() const;
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// return the painter object for drawing onto the view
|
2002-06-12 02:54:19 +00:00
|
|
|
|
Painter & painter() const;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// return the screen object for handling re-drawing
|
2002-06-18 15:44:30 +00:00
|
|
|
|
LyXScreen & screen() const;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// return the owning main view
|
|
|
|
|
LyXView * owner() const;
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2003-08-27 14:55:20 +00:00
|
|
|
|
/// return the visible top y
|
|
|
|
|
int top_y() const;
|
2003-08-28 07:41:31 +00:00
|
|
|
|
|
2003-08-27 14:55:20 +00:00
|
|
|
|
/// set the visible top y
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void top_y(int);
|
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// resize event has happened
|
1999-09-27 18:44:28 +00:00
|
|
|
|
void resize();
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2003-03-08 05:37:54 +00:00
|
|
|
|
/// reload the contained buffer
|
|
|
|
|
void reload();
|
2003-07-07 08:37:02 +00:00
|
|
|
|
/// create a new buffer based on template
|
2003-10-06 15:43:21 +00:00
|
|
|
|
bool newFile(std::string const & fname, std::string const & tname,
|
2003-07-07 08:37:02 +00:00
|
|
|
|
bool named = true);
|
2003-06-20 12:46:28 +00:00
|
|
|
|
/// load a buffer into the view
|
2003-10-06 15:43:21 +00:00
|
|
|
|
bool loadLyXFile(std::string const & name, bool tolastfiles = true);
|
2003-03-08 05:37:54 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// fit the user cursor within the visible view
|
2002-03-29 15:49:45 +00:00
|
|
|
|
bool fitCursor();
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// perform pending painting updates
|
1999-09-27 18:44:28 +00:00
|
|
|
|
void update();
|
2003-08-27 13:51:18 +00:00
|
|
|
|
/** update for a particular inset. Gets a pointer and not a
|
|
|
|
|
* reference because we really need the pointer information
|
|
|
|
|
* to find it in the buffer.
|
2003-11-10 09:06:48 +00:00
|
|
|
|
*
|
|
|
|
|
* Extracted from Matthias notes:
|
|
|
|
|
*
|
|
|
|
|
* If a inset wishes any redraw and/or update it just has to call
|
|
|
|
|
* updateInset(this). It's is completly irrelevant, where the inset is.
|
|
|
|
|
* UpdateInset will find it in any paragraph in any buffer.
|
|
|
|
|
* Of course the insets in the current paragraph/buffer
|
|
|
|
|
* are checked first, so no performance problem should occur.
|
2003-08-27 13:51:18 +00:00
|
|
|
|
*/
|
|
|
|
|
void updateInset(InsetOld const *);
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// reset the scrollbar to reflect current view position
|
1999-09-27 18:44:28 +00:00
|
|
|
|
void updateScrollbar();
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// FIXME
|
1999-09-27 18:44:28 +00:00
|
|
|
|
void redoCurrentBuffer();
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// FIXME
|
1999-09-27 18:44:28 +00:00
|
|
|
|
bool available() const;
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// Save the current position as bookmark i
|
2002-03-21 17:27:08 +00:00
|
|
|
|
void savePosition(unsigned int i);
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// Restore the position from bookmark i
|
2002-03-21 17:27:08 +00:00
|
|
|
|
void restorePosition(unsigned int i);
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// does the given bookmark have a saved position ?
|
2001-01-28 18:31:36 +00:00
|
|
|
|
bool isSavedPosition(unsigned int i);
|
2003-03-04 09:27:27 +00:00
|
|
|
|
|
2003-02-08 19:18:01 +00:00
|
|
|
|
/// return the current change at the cursor
|
|
|
|
|
Change const getCurrentChange();
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* This holds the mapping between buffer paragraphs and screen rows.
|
|
|
|
|
* This should be private...but not yet. (Lgb)
|
|
|
|
|
*/
|
1999-12-10 00:07:59 +00:00
|
|
|
|
LyXText * text;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// return the lyxtext we are using
|
2000-12-17 06:09:35 +00:00
|
|
|
|
LyXText * getLyXText() const;
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
/// update paragraph dialogs
|
|
|
|
|
void updateParagraphDialog();
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2003-01-05 22:38:42 +00:00
|
|
|
|
/// return the current encoding at the cursor
|
|
|
|
|
Encoding const * getEncoding() const;
|
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// return the parent language of the given inset
|
2003-07-25 21:20:24 +00:00
|
|
|
|
Language const * getParentLanguage(InsetOld * inset) const;
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// replace the currently selected word
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void replaceWord(std::string const & replacestring);
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// move cursor to the named label
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void gotoLabel(std::string const & label);
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// undo last action
|
|
|
|
|
void undo();
|
|
|
|
|
/// redo last action
|
|
|
|
|
void redo();
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2003-05-20 16:51:31 +00:00
|
|
|
|
/// get the stored error list
|
|
|
|
|
ErrorList const & getErrorList() const;
|
2003-05-13 21:15:48 +00:00
|
|
|
|
/// show the error list to the user
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void showErrorList(std::string const &) const;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// set the cursor based on the given TeX source row
|
2000-01-08 21:02:58 +00:00
|
|
|
|
void setCursorFromRow(int row);
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* Insert an inset into the buffer.
|
|
|
|
|
* Place it in a layout of lout,
|
|
|
|
|
*/
|
2003-10-06 15:43:21 +00:00
|
|
|
|
bool insertInset(InsetOld * inset, std::string const & lout = std::string());
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// Inserts a lyx file at cursor position. return false if it fails
|
2003-10-06 15:43:21 +00:00
|
|
|
|
bool insertLyXFile(std::string const & file);
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// FIXME
|
2002-03-29 15:49:45 +00:00
|
|
|
|
bool fitLockedInsetCursor(int x, int y, int asc, int desc);
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2003-05-03 18:05:53 +00:00
|
|
|
|
/// hide the cursor if it is visible
|
|
|
|
|
void hideCursor();
|
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// center the document view around the cursor
|
2000-02-17 19:59:08 +00:00
|
|
|
|
void center();
|
2002-10-21 00:15:48 +00:00
|
|
|
|
/// scroll document by the given number of lines of default height
|
|
|
|
|
void scroll(int lines);
|
2002-06-12 15:01:32 +00:00
|
|
|
|
/// Scroll the view by a number of pixels
|
|
|
|
|
void scrollDocView(int);
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// return the pixel width of the document view
|
|
|
|
|
int workWidth() const;
|
|
|
|
|
/// return the pixel height of the document view
|
|
|
|
|
int workHeight() const;
|
|
|
|
|
|
|
|
|
|
/// switch between primary and secondary keymaps for RTL entry
|
2002-07-17 04:13:41 +00:00
|
|
|
|
void switchKeyMap();
|
2000-02-03 19:51:27 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// FIXME
|
2003-10-06 15:43:21 +00:00
|
|
|
|
bool ChangeRefsIfUnique(std::string const & from, std::string const & to);
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// get the contents of the window system clipboard
|
2003-10-06 15:43:21 +00:00
|
|
|
|
std::string const getClipboard() const;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// fill the window system clipboard
|
2003-10-06 15:43:21 +00:00
|
|
|
|
void stuffClipboard(std::string const &) const;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// tell the window system we have a selection
|
2002-08-29 13:41:58 +00:00
|
|
|
|
void haveSelection(bool sel);
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// execute the given function
|
|
|
|
|
bool dispatch(FuncRequest const & argument);
|
2003-11-04 07:43:03 +00:00
|
|
|
|
|
|
|
|
|
/// set target x position of cursor
|
|
|
|
|
void BufferView::x_target(int x);
|
|
|
|
|
/// return target x position of cursor
|
|
|
|
|
int BufferView::x_target() const;
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2003-11-04 12:36:59 +00:00
|
|
|
|
/// access to cursor
|
|
|
|
|
LCursor & cursor();
|
|
|
|
|
/// access to cursor
|
|
|
|
|
LCursor const & cursor() const;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
///
|
|
|
|
|
UpdatableInset * innerInset() const;
|
2003-11-04 12:36:59 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
private:
|
|
|
|
|
struct Pimpl;
|
2000-06-26 10:29:33 +00:00
|
|
|
|
friend struct BufferView::Pimpl;
|
2002-10-21 16:21:56 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
Pimpl * pimpl_;
|
2003-11-04 07:43:03 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The target x position of the cursor. This is used for when
|
|
|
|
|
* we have text like :
|
|
|
|
|
*
|
|
|
|
|
* blah blah blah blah| blah blah blah
|
|
|
|
|
* blah blah blah
|
|
|
|
|
* blah blah blah blah blah blah
|
|
|
|
|
*
|
|
|
|
|
* When we move onto row 3, we would like to be vertically aligned
|
|
|
|
|
* with where we were in row 1, despite the fact that row 2 is
|
|
|
|
|
* shorter than x()
|
|
|
|
|
*/
|
|
|
|
|
int x_target_;
|
|
|
|
|
|
1999-09-27 18:44:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
#endif // BUFFERVIEW_H
|