4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Lars Gullik Bjønnes
9 * \author Alfredo Braunstein
11 * Full author contact details are available in file CREDITS.
17 #include "DocumentClassPtr.h"
19 #include "support/docstring.h"
21 #include "frontends/Clipboard.h"
36 /// Get all elements of the cut buffer in plain text format.
37 std::vector<docstring> availableSelections(Buffer const *);
38 /// Get the number of available elements in the cut buffer.
39 size_type numberOfSelections();
40 /// Get the sel_index-th element of the cut buffer in plain text format.
41 docstring selection(size_t sel_index, DocumentClassConstPtr docclass);
44 * Replace using the font of the first selected character and select
45 * the new string. Does handle undo.
47 void replaceSelectionWithString(Cursor & cur, docstring const & str);
48 /// If a selection exists, delete it without pushing it to the cut buffer.
50 void replaceSelection(Cursor & cur);
53 * Cut the current selection and possibly push it to the cut buffer and
55 * Does handle undo. Calls saveSelection.
56 * \param doclear If this is true: Delete leading spaces in paragraphs before
58 * \param realcut If this is true: Push the selection to the cut buffer and
59 * system clipboard. Set this to false to only delete the
62 void cutSelection(Cursor & cur, bool realcut = true);
63 /// Like cutSelection, but only put to temporary cut buffer
64 void cutSelectionToTemp(Cursor & cur, bool realcut = true);
66 /// Push the current selection to the cut buffer and the system clipboard.
67 void copySelection(Cursor const & cur);
68 /// Like copySelection, but only put to temporary cut buffer
69 void copySelectionToTemp(Cursor & cur);
71 void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext);
73 * Push the current selection to the cut buffer and the system clipboard.
74 * \param plaintext plain text version of the selection for the system
77 void copySelection(Cursor const & cur, docstring const & plaintext);
78 /// Push the selection buffer to the cut buffer.
79 void copySelectionToStack();
80 /// Store the current selection in the internal selection buffer
81 void saveSelection(Cursor const & cur);
82 /// Is a selection available in our selection buffer?
84 /// Clear our selection buffer
85 void clearSelection();
86 /// Clear our cut stack.
88 /// Paste the current selection at \p cur
89 /// Does handle undo. Does only work in text, not mathed.
90 void pasteSelection(Cursor & cur, ErrorList &);
91 /// Replace the current selection with the clipboard contents as text
92 /// (internal or external: which is newer).
93 /// Does handle undo. Does only work in text, not mathed.
94 /// \p asParagraphs is only considered if plain text is pasted.
95 bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
96 frontend::Clipboard::TextType preferedType = frontend::Clipboard::LyXOrPlainTextType);
97 /// Replace the current selection with the clipboard contents as graphic.
98 /// Does handle undo. Does only work in text, not mathed.
99 void pasteClipboardGraphics(Cursor & cur, ErrorList & errorList,
100 frontend::Clipboard::GraphicsType preferedType = frontend::Clipboard::AnyGraphicsType);
101 /// Replace the current selection with cut buffer \c sel_index
102 /// Does handle undo. Does only work in text, not mathed.
103 bool pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index);
104 /// Replace the current selection with temporary cut buffer
105 /// Does handle undo. Does only work in text, not mathed.
106 bool pasteFromTemp(Cursor & cur, ErrorList & errorList);
107 /// Paste the clipboard as simple text, removing any formatting
108 void pasteSimpleText(Cursor & cur, bool asParagraphs);
110 // What to do with unknown branches?
112 BRANCH_ADD, // add the branch unconditionally
113 BRANCH_IGNORE, // leave the branch undefined
114 BRANCH_ASK // ask the user whether the branch should be added
116 /// Paste the paragraph list \p parlist at the position given by \p cur.
117 /// Does not handle undo. Does only work in text, not mathed.
118 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
119 DocumentClassConstPtr textclass, ErrorList & errorList,
120 BranchAction branchAction = BRANCH_ASK);
123 /** Needed to switch between different classes. This works
124 * for a list of paragraphs beginning with the specified par.
125 * It changes layouts and character styles.
127 void switchBetweenClasses(DocumentClassConstPtr c1,
128 DocumentClassConstPtr c2, InsetText & in, ErrorList &);
130 /// Get the current selection as a string. Does not change the selection.
131 /// Does only work if the whole selection is in mathed.
132 docstring grabSelection(CursorData const & cur);
133 /// Erase the current selection.
134 /// Does not handle undo. Does only work if the whole selection is in mathed.
135 /// Calls saveSelection.
136 void eraseSelection(Cursor & cur);
137 /// Reduce the selected text in mathed to only one cell. If it spans multiple
138 /// cells, the cursor is moved the end of the current cell and the anchor to the
139 /// start. If the selection is inside only one cell, nothing is done. Return
140 /// true if the selection now does not span multiple cells anymore.
141 bool reduceSelectionToOneCell(CursorData & cur);
142 /// Returns true if multiple cells are selected in mathed.
143 bool multipleCellsSelected(CursorData const & cur);
144 /// Erase the selection and return it as a string.
145 /// Does not handle undo. Does only work if the whole selection is in mathed.
146 docstring grabAndEraseSelection(Cursor & cur);
147 // other selection methods
148 /// Erase the selection if one exists.
149 /// Does not handle undo. Does only work if the whole selection is in mathed.
150 void selDel(Cursor & cur);
151 /// Clear or delete the selection if one exists, depending on lyxrc setting.
152 /// Does not handle undo. Does only work if the whole selection is in mathed.
153 void selClearOrDel(Cursor & cur);
154 /// Calculate rectangular region of cell between \c i1 and \c i2.
155 void region(CursorSlice const & i1, CursorSlice const & i2,
156 Inset::row_type & r1, Inset::row_type & r2,
157 Inset::col_type & c1, Inset::col_type & c2);
158 /** Tabular has its own paste stack for multiple cells
159 * but it needs to know whether there is a more recent
160 * ordinary paste. Therefore which one is newer.
162 //FIXME: this is a workaround for bug 1919. Replace this by
163 //an all-for-one-paste mechanism in 1.7
164 /// store whether tabular or ordinary paste stack is newer
165 void dirtyTabularStack(bool b);
166 /// is the tabular paste stack newer than the ordinary one?
167 bool tabularStackDirty();