2000-04-10 14:29:05 +00:00
|
|
|
// -*- C++ -*-
|
2003-08-23 00:17:00 +00:00
|
|
|
/**
|
|
|
|
* \file CutAndPaste.h
|
2003-05-06 09:34:56 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Vigna
|
|
|
|
* \author Lars Gullik Bjønnes
|
2003-06-28 01:23:11 +00:00
|
|
|
* \author Alfredo Braunstein
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-05-06 09:34:56 +00:00
|
|
|
*/
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
#ifndef CUTANDPASTE_H
|
|
|
|
#define CUTANDPASTE_H
|
|
|
|
|
2021-02-09 15:54:21 +00:00
|
|
|
#include "Author.h"
|
2012-03-13 16:13:31 +00:00
|
|
|
#include "DocumentClassPtr.h"
|
|
|
|
|
2020-10-20 08:36:59 +00:00
|
|
|
#include "support/strfwd.h"
|
2020-11-20 22:06:05 +00:00
|
|
|
#include "support/types.h"
|
2020-10-15 06:59:01 +00:00
|
|
|
|
2008-02-03 10:43:03 +00:00
|
|
|
#include "frontends/Clipboard.h"
|
|
|
|
|
2003-06-17 15:33:49 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2008-02-03 10:43:03 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2020-11-20 22:06:05 +00:00
|
|
|
class Buffer;
|
2003-05-20 16:51:31 +00:00
|
|
|
class ErrorList;
|
2020-11-20 22:06:05 +00:00
|
|
|
class Inset;
|
2006-05-21 17:33:03 +00:00
|
|
|
class InsetText;
|
2008-02-24 14:59:23 +00:00
|
|
|
class Cursor;
|
2020-10-15 06:59:01 +00:00
|
|
|
class CursorData;
|
|
|
|
class CursorSlice;
|
2007-04-26 08:30:11 +00:00
|
|
|
class ParagraphList;
|
2000-04-10 14:29:05 +00:00
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
namespace cap {
|
2003-06-17 15:33:49 +00:00
|
|
|
|
2007-01-04 16:50:03 +00:00
|
|
|
/// Get all elements of the cut buffer in plain text format.
|
2008-07-30 09:09:23 +00:00
|
|
|
std::vector<docstring> availableSelections(Buffer const *);
|
2007-01-04 16:50:03 +00:00
|
|
|
/// Get the number of available elements in the cut buffer.
|
2006-10-21 00:16:43 +00:00
|
|
|
size_type numberOfSelections();
|
2021-02-09 15:54:21 +00:00
|
|
|
///
|
|
|
|
typedef std::pair<DocumentClassConstPtr, AuthorList > DocInfoPair;
|
2021-01-30 00:32:40 +00:00
|
|
|
/**
|
|
|
|
* Get the sel_index-th element of the cut buffer in plain text format
|
|
|
|
* or, if \param for_math is true, in a format suitable for mathed.
|
|
|
|
*/
|
2021-02-09 15:54:21 +00:00
|
|
|
docstring selection(size_t sel_index, DocInfoPair docinfo, bool for_math = false);
|
2003-06-17 15:33:49 +00:00
|
|
|
|
2007-01-04 16:50:03 +00:00
|
|
|
/**
|
|
|
|
* Replace using the font of the first selected character and select
|
2012-04-18 10:44:31 +00:00
|
|
|
* the new string. Does handle undo.
|
2004-03-25 09:16:36 +00:00
|
|
|
*/
|
2012-04-18 10:44:31 +00:00
|
|
|
void replaceSelectionWithString(Cursor & cur, docstring const & str);
|
2007-02-08 10:40:46 +00:00
|
|
|
/// If a selection exists, delete it without pushing it to the cut buffer.
|
2007-01-04 16:50:03 +00:00
|
|
|
/// Does handle undo.
|
2007-04-26 14:56:30 +00:00
|
|
|
void replaceSelection(Cursor & cur);
|
2003-05-06 09:34:56 +00:00
|
|
|
|
2007-01-04 16:50:03 +00:00
|
|
|
/**
|
|
|
|
* Cut the current selection and possibly push it to the cut buffer and
|
|
|
|
* system clipboard.
|
2007-07-10 12:48:04 +00:00
|
|
|
* Does handle undo. Calls saveSelection.
|
2007-01-04 16:50:03 +00:00
|
|
|
* \param doclear If this is true: Delete leading spaces in paragraphs before
|
|
|
|
* they get merged.
|
|
|
|
* \param realcut If this is true: Push the selection to the cut buffer and
|
2007-02-08 10:40:46 +00:00
|
|
|
* system clipboard. Set this to false to only delete the
|
2007-05-28 22:27:45 +00:00
|
|
|
* selection.
|
2007-01-04 16:50:03 +00:00
|
|
|
*/
|
2018-07-22 20:18:50 +00:00
|
|
|
void cutSelection(Cursor & cur, bool realcut = true);
|
2016-11-09 14:13:41 +00:00
|
|
|
/// Like cutSelection, but only put to temporary cut buffer
|
2018-07-22 20:18:50 +00:00
|
|
|
void cutSelectionToTemp(Cursor & cur, bool realcut = true);
|
2016-11-09 14:13:41 +00:00
|
|
|
|
2007-01-04 16:50:03 +00:00
|
|
|
/// Push the current selection to the cut buffer and the system clipboard.
|
2008-08-13 13:46:19 +00:00
|
|
|
void copySelection(Cursor const & cur);
|
2018-04-26 01:48:25 +00:00
|
|
|
/// Like copySelection, but only put to temporary cut buffer
|
2020-10-01 10:34:15 +00:00
|
|
|
void copySelectionToTemp(Cursor const & cur);
|
2008-11-16 19:19:07 +00:00
|
|
|
///
|
|
|
|
void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext);
|
2022-11-04 20:44:24 +00:00
|
|
|
///
|
|
|
|
void copyInsetToTemp(Cursor const & cur, Inset * inset);
|
2007-01-13 18:29:50 +00:00
|
|
|
/**
|
|
|
|
* Push the current selection to the cut buffer and the system clipboard.
|
|
|
|
* \param plaintext plain text version of the selection for the system
|
|
|
|
* clipboard
|
|
|
|
*/
|
2008-08-13 13:46:19 +00:00
|
|
|
void copySelection(Cursor const & cur, docstring const & plaintext);
|
2007-02-02 03:10:15 +00:00
|
|
|
/// Push the selection buffer to the cut buffer.
|
|
|
|
void copySelectionToStack();
|
|
|
|
/// Store the current selection in the internal selection buffer
|
2008-08-13 13:46:19 +00:00
|
|
|
void saveSelection(Cursor const & cur);
|
2007-02-02 03:10:15 +00:00
|
|
|
/// Is a selection available in our selection buffer?
|
|
|
|
bool selection();
|
|
|
|
/// Clear our selection buffer
|
|
|
|
void clearSelection();
|
2007-09-15 17:24:08 +00:00
|
|
|
/// Clear our cut stack.
|
|
|
|
void clearCutStack();
|
2007-02-02 03:10:15 +00:00
|
|
|
/// Paste the current selection at \p cur
|
|
|
|
/// Does handle undo. Does only work in text, not mathed.
|
2007-04-26 14:56:30 +00:00
|
|
|
void pasteSelection(Cursor & cur, ErrorList &);
|
2008-02-03 10:43:03 +00:00
|
|
|
/// Replace the current selection with the clipboard contents as text
|
|
|
|
/// (internal or external: which is newer).
|
|
|
|
/// Does handle undo. Does only work in text, not mathed.
|
2013-04-14 17:45:36 +00:00
|
|
|
/// \p asParagraphs is only considered if plain text is pasted.
|
2013-07-13 08:29:54 +00:00
|
|
|
bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
|
2016-06-26 16:22:59 +00:00
|
|
|
frontend::Clipboard::TextType preferedType = frontend::Clipboard::LyXOrPlainTextType);
|
2008-02-03 10:43:03 +00:00
|
|
|
/// Replace the current selection with the clipboard contents as graphic.
|
2007-01-13 18:29:50 +00:00
|
|
|
/// Does handle undo. Does only work in text, not mathed.
|
2008-02-03 10:43:03 +00:00
|
|
|
void pasteClipboardGraphics(Cursor & cur, ErrorList & errorList,
|
2016-06-26 16:22:59 +00:00
|
|
|
frontend::Clipboard::GraphicsType preferedType = frontend::Clipboard::AnyGraphicsType);
|
2007-01-13 18:29:50 +00:00
|
|
|
/// Replace the current selection with cut buffer \c sel_index
|
2007-01-04 16:50:03 +00:00
|
|
|
/// Does handle undo. Does only work in text, not mathed.
|
2013-07-13 08:29:54 +00:00
|
|
|
bool pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index);
|
2016-11-09 14:13:41 +00:00
|
|
|
/// Replace the current selection with temporary cut buffer
|
|
|
|
/// Does handle undo. Does only work in text, not mathed.
|
|
|
|
bool pasteFromTemp(Cursor & cur, ErrorList & errorList);
|
2011-10-29 15:42:01 +00:00
|
|
|
/// Paste the clipboard as simple text, removing any formatting
|
|
|
|
void pasteSimpleText(Cursor & cur, bool asParagraphs);
|
2003-03-06 15:39:37 +00:00
|
|
|
|
2016-11-09 14:13:41 +00:00
|
|
|
// What to do with unknown branches?
|
|
|
|
enum BranchAction {
|
|
|
|
BRANCH_ADD, // add the branch unconditionally
|
|
|
|
BRANCH_IGNORE, // leave the branch undefined
|
|
|
|
BRANCH_ASK // ask the user whether the branch should be added
|
|
|
|
};
|
2006-11-17 19:52:45 +00:00
|
|
|
/// Paste the paragraph list \p parlist at the position given by \p cur.
|
|
|
|
/// Does not handle undo. Does only work in text, not mathed.
|
2007-04-26 14:56:30 +00:00
|
|
|
void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
|
2024-09-14 18:40:53 +00:00
|
|
|
DocumentClassConstPtr const & textclass, AuthorList const & authors,
|
2021-02-09 15:54:21 +00:00
|
|
|
ErrorList & errorList,
|
|
|
|
BranchAction branchAction = BRANCH_ASK);
|
2005-11-29 15:08:35 +00:00
|
|
|
|
|
|
|
|
2004-03-25 09:16:36 +00:00
|
|
|
/** Needed to switch between different classes. This works
|
2005-05-04 11:21:14 +00:00
|
|
|
* for a list of paragraphs beginning with the specified par.
|
2021-02-26 02:49:50 +00:00
|
|
|
* It changes layouts and character styles. Errors are reported
|
|
|
|
* in the passed ErrorList.
|
2004-10-05 10:11:42 +00:00
|
|
|
*/
|
2024-09-13 12:16:21 +00:00
|
|
|
void switchBetweenClasses(DocumentClassConstPtr const & oldone,
|
|
|
|
DocumentClassConstPtr const & newone, InsetText & in, ErrorList & el);
|
2021-02-26 02:49:50 +00:00
|
|
|
/// Same but without error reporting.
|
2024-09-13 12:16:21 +00:00
|
|
|
void switchBetweenClasses(DocumentClassConstPtr const & oldone,
|
|
|
|
DocumentClassConstPtr const & newone, InsetText & in);
|
2003-03-06 15:39:37 +00:00
|
|
|
|
2007-01-04 16:50:03 +00:00
|
|
|
/// Get the current selection as a string. Does not change the selection.
|
|
|
|
/// Does only work if the whole selection is in mathed.
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
docstring grabSelection(CursorData const & cur);
|
2007-01-04 16:50:03 +00:00
|
|
|
/// Erase the current selection.
|
|
|
|
/// Does not handle undo. Does only work if the whole selection is in mathed.
|
2007-07-10 12:48:04 +00:00
|
|
|
/// Calls saveSelection.
|
2007-04-26 14:56:30 +00:00
|
|
|
void eraseSelection(Cursor & cur);
|
2008-03-12 00:18:39 +00:00
|
|
|
/// Reduce the selected text in mathed to only one cell. If it spans multiple
|
|
|
|
/// cells, the cursor is moved the end of the current cell and the anchor to the
|
|
|
|
/// start. If the selection is inside only one cell, nothing is done. Return
|
|
|
|
/// true if the selection now does not span multiple cells anymore.
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
bool reduceSelectionToOneCell(CursorData & cur);
|
2008-03-12 00:59:29 +00:00
|
|
|
/// Returns true if multiple cells are selected in mathed.
|
Move some Cursor methods to CursorData
Basically, everything that does not depend on a BufferView should move
there. Some methods that do not seem to need a BufferView, like
selHandle or IdxFirst or push actually depend on it and could not be
moved.
This allows to simplify a few uses of recordUndo helpers.
- Move some methods to DocIterator: nextMath, prevMath, getPossibleLabel,
getEncoding;
- Move some methods to CursorData: setCursor, setCursorSelectionTo,
(setCursorTo|normal|reset)Anchor, (set|clear)Selection,
sel(|ection)(Begin|End), selectionAsString, info, currentState,
(mark|clear|check)NewWordPosition, fixIfBroken, sanitize, all undo
related methods, reset, isInside, leaveInset, current mode;
- kill some unused methods: macromode, replaceWord, setScreenPos, touch,
markInsert, markErase;
- Move code around to group things, and add a few comments (a lot remains to be done).
This changes lead to some related changes in other classes: removal,
change of parameter.
No intended change.
2017-07-23 16:13:33 +00:00
|
|
|
bool multipleCellsSelected(CursorData const & cur);
|
2007-01-04 16:50:03 +00:00
|
|
|
/// Erase the selection and return it as a string.
|
|
|
|
/// Does not handle undo. Does only work if the whole selection is in mathed.
|
2007-04-26 14:56:30 +00:00
|
|
|
docstring grabAndEraseSelection(Cursor & cur);
|
2004-04-18 07:32:34 +00:00
|
|
|
// other selection methods
|
2007-01-04 16:50:03 +00:00
|
|
|
/// Erase the selection if one exists.
|
|
|
|
/// Does not handle undo. Does only work if the whole selection is in mathed.
|
2007-04-26 14:56:30 +00:00
|
|
|
void selDel(Cursor & cur);
|
2007-01-04 16:50:03 +00:00
|
|
|
/// Clear or delete the selection if one exists, depending on lyxrc setting.
|
|
|
|
/// Does not handle undo. Does only work if the whole selection is in mathed.
|
2007-04-26 14:56:30 +00:00
|
|
|
void selClearOrDel(Cursor & cur);
|
2008-03-12 00:19:31 +00:00
|
|
|
/// Calculate rectangular region of cell between \c i1 and \c i2.
|
|
|
|
void region(CursorSlice const & i1, CursorSlice const & i2,
|
2020-11-20 22:06:05 +00:00
|
|
|
row_type & r1, row_type & r2,
|
|
|
|
col_type & c1, col_type & c2);
|
2005-09-06 17:39:39 +00:00
|
|
|
/** Tabular has its own paste stack for multiple cells
|
2006-04-05 23:56:29 +00:00
|
|
|
* but it needs to know whether there is a more recent
|
2005-09-06 17:39:39 +00:00
|
|
|
* ordinary paste. Therefore which one is newer.
|
|
|
|
*/
|
|
|
|
//FIXME: this is a workaround for bug 1919. Replace this by
|
2008-03-12 00:19:18 +00:00
|
|
|
//an all-for-one-paste mechanism in 1.7
|
2005-09-06 17:39:39 +00:00
|
|
|
/// store whether tabular or ordinary paste stack is newer
|
|
|
|
void dirtyTabularStack(bool b);
|
|
|
|
/// is the tabular paste stack newer than the ordinary one?
|
|
|
|
bool tabularStackDirty();
|
2004-03-25 09:16:36 +00:00
|
|
|
} // namespace cap
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace lyx
|
2000-04-10 14:29:05 +00:00
|
|
|
|
|
|
|
#endif
|