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