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