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
|
|
|
|
|
2004-02-02 11:07:51 +00:00
|
|
|
|
#include "support/types.h"
|
|
|
|
|
|
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;
|
2004-03-31 19:11:56 +00:00
|
|
|
|
class DocIterator;
|
2003-09-06 19:16:30 +00:00
|
|
|
|
class ErrorList;
|
|
|
|
|
class FuncRequest;
|
2004-04-01 08:58:45 +00:00
|
|
|
|
class FuncStatus;
|
2003-09-06 19:16:30 +00:00
|
|
|
|
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;
|
2004-02-02 11:07:51 +00:00
|
|
|
|
class ParIterator;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
|
2005-05-31 14:40:30 +00:00
|
|
|
|
|
|
|
|
|
namespace Update {
|
2005-06-09 09:58:08 +00:00
|
|
|
|
enum flags {
|
|
|
|
|
FitCursor = 1,
|
2005-05-31 14:40:30 +00:00
|
|
|
|
Force = 2,
|
2005-06-09 09:58:08 +00:00
|
|
|
|
SinglePar = 4
|
2005-05-31 14:40:30 +00:00
|
|
|
|
};
|
|
|
|
|
|
2005-06-09 09:58:08 +00:00
|
|
|
|
inline flags operator|(flags const f, flags const g)
|
2005-05-31 14:40:30 +00:00
|
|
|
|
{
|
|
|
|
|
return static_cast<flags>(int(f) | int(g));
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-09 09:58:08 +00:00
|
|
|
|
inline flags operator&(flags const f, flags const g)
|
2005-05-31 14:40:30 +00:00
|
|
|
|
{
|
|
|
|
|
return static_cast<flags>(int(f) & int(g));
|
|
|
|
|
}
|
|
|
|
|
|
2005-06-09 09:58:08 +00:00
|
|
|
|
} // namespace
|
2005-05-31 14:40:30 +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.
|
|
|
|
|
*/
|
2004-04-28 17:22:05 +00:00
|
|
|
|
BufferView(LyXView * owner, int w, int h);
|
2002-10-21 16:21:56 +00:00
|
|
|
|
|
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
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void setBuffer(Buffer * b);
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// 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
|
|
|
|
|
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
|
2004-03-18 12:53:43 +00:00
|
|
|
|
void 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
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
/** perform pending painting updates. \c fitcursor means first
|
|
|
|
|
* to do a fitcursor, and to force an update if screen
|
|
|
|
|
* position changes. \c forceupdate means to force an update
|
2005-01-12 10:30:46 +00:00
|
|
|
|
* in any case.
|
2004-11-30 01:59:49 +00:00
|
|
|
|
*/
|
2005-05-31 14:40:30 +00:00
|
|
|
|
|
|
|
|
|
void update(Update::flags flags = Update::FitCursor | Update::Force);
|
2004-11-30 01:59:49 +00:00
|
|
|
|
/// move the screen to fit the cursor. Only to be called with
|
|
|
|
|
/// good y coordinates (after a bv::metrics)
|
2002-03-29 15:49:45 +00:00
|
|
|
|
bool fitCursor();
|
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-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
|
|
|
|
/// return the lyxtext we are using
|
2005-01-31 16:29:48 +00:00
|
|
|
|
LyXText * getLyXText();
|
|
|
|
|
|
|
|
|
|
/// return the lyxtext we are using
|
|
|
|
|
LyXText const * getLyXText() const;
|
2002-12-01 21:10:37 +00:00
|
|
|
|
|
2004-04-03 08:37:12 +00:00
|
|
|
|
/// simple replacing. Use the font of the first selected character
|
2004-01-14 17:21:39 +00:00
|
|
|
|
void replaceSelectionWithString(std::string const & str);
|
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
|
|
|
|
|
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
|
|
|
|
|
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
|
2004-08-14 19:55:00 +00:00
|
|
|
|
void scrollDocView(int pixels);
|
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
|
|
|
|
/// 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
|
|
|
|
|
2004-04-01 08:58:45 +00:00
|
|
|
|
/// return true for events that will handle
|
|
|
|
|
FuncStatus getStatus(FuncRequest const & cmd);
|
2002-10-21 16:21:56 +00:00
|
|
|
|
/// execute the given function
|
|
|
|
|
bool dispatch(FuncRequest const & argument);
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2003-12-12 15:19:35 +00:00
|
|
|
|
/// clear the X selection
|
|
|
|
|
void unsetXSel();
|
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
/// access to offset
|
|
|
|
|
int offset_ref() const;
|
|
|
|
|
/// access to anchor
|
|
|
|
|
lyx::pit_type anchor_ref() const;
|
2005-04-26 11:12:20 +00:00
|
|
|
|
|
2004-01-13 18:08:13 +00:00
|
|
|
|
/// access to full cursor
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor & cursor();
|
2004-01-13 18:08:13 +00:00
|
|
|
|
/// access to full cursor
|
2004-01-20 14:25:24 +00:00
|
|
|
|
LCursor const & cursor() const;
|
2003-11-28 08:55:12 +00:00
|
|
|
|
///
|
2003-11-28 15:08:38 +00:00
|
|
|
|
LyXText * text() const;
|
2005-12-01 10:28:50 +00:00
|
|
|
|
/// sets cursor and open all relevant collapsable insets.
|
2005-02-22 11:41:22 +00:00
|
|
|
|
void setCursor(DocIterator const &);
|
2005-12-01 10:28:50 +00:00
|
|
|
|
/// sets cursor; this is used when handling LFUN_MOUSE_PRESS.
|
|
|
|
|
void mouseSetCursor(LCursor & cur);
|
|
|
|
|
|
2004-09-17 16:28:47 +00:00
|
|
|
|
/* Sets the selection. When \c backwards == false, set anchor
|
|
|
|
|
* to \c cur and cursor to \c cur + \c length. When \c
|
|
|
|
|
* backwards == true, set anchor to \c cur and cursor to \c
|
|
|
|
|
* cur + \c length.
|
|
|
|
|
*/
|
2004-03-31 19:11:56 +00:00
|
|
|
|
void putSelectionAt(DocIterator const & cur,
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int length, bool backwards);
|
2004-01-14 14:16:11 +00:00
|
|
|
|
|
2004-11-30 01:59:49 +00:00
|
|
|
|
|
2000-04-08 17:02:02 +00:00
|
|
|
|
private:
|
2003-11-28 08:55:12 +00:00
|
|
|
|
///
|
2005-01-19 15:03:31 +00:00
|
|
|
|
class Pimpl;
|
2003-11-28 08:55:12 +00:00
|
|
|
|
///
|
2005-01-19 15:03:31 +00:00
|
|
|
|
friend class BufferView::Pimpl;
|
2003-11-28 08:55:12 +00:00
|
|
|
|
///
|
2000-04-08 17:02:02 +00:00
|
|
|
|
Pimpl * pimpl_;
|
1999-09-27 18:44:28 +00:00
|
|
|
|
};
|
|
|
|
|
|
2002-10-21 16:21:56 +00:00
|
|
|
|
#endif // BUFFERVIEW_H
|