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 void copyInsetToTemp(Cursor const & cur, Inset * inset);
85 * Push the current selection to the cut buffer and the system clipboard.
86 * \param plaintext plain text version of the selection for the system
89 void copySelection(Cursor const & cur, docstring const & plaintext);
90 /// Push the selection buffer to the cut buffer.
91 void copySelectionToStack();
92 /// Store the current selection in the internal selection buffer
93 void saveSelection(Cursor const & cur);
94 /// Is a selection available in our selection buffer?
96 /// Clear our selection buffer
97 void clearSelection();
98 /// Clear our cut stack.
100 /// Paste the current selection at \p cur
101 /// Does handle undo. Does only work in text, not mathed.
102 void pasteSelection(Cursor & cur, ErrorList &);
103 /// Replace the current selection with the clipboard contents as text
104 /// (internal or external: which is newer).
105 /// Does handle undo. Does only work in text, not mathed.
106 /// \p asParagraphs is only considered if plain text is pasted.
107 bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
108 frontend::Clipboard::TextType preferedType = frontend::Clipboard::LyXOrPlainTextType);
109 /// Replace the current selection with the clipboard contents as graphic.
110 /// Does handle undo. Does only work in text, not mathed.
111 void pasteClipboardGraphics(Cursor & cur, ErrorList & errorList,
112 frontend::Clipboard::GraphicsType preferedType = frontend::Clipboard::AnyGraphicsType);
113 /// Replace the current selection with cut buffer \c sel_index
114 /// Does handle undo. Does only work in text, not mathed.
115 bool pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index);
116 /// Replace the current selection with temporary cut buffer
117 /// Does handle undo. Does only work in text, not mathed.
118 bool pasteFromTemp(Cursor & cur, ErrorList & errorList);
119 /// Paste the clipboard as simple text, removing any formatting
120 void pasteSimpleText(Cursor & cur, bool asParagraphs);
122 // What to do with unknown branches?
124 BRANCH_ADD, // add the branch unconditionally
125 BRANCH_IGNORE, // leave the branch undefined
126 BRANCH_ASK // ask the user whether the branch should be added
128 /// Paste the paragraph list \p parlist at the position given by \p cur.
129 /// Does not handle undo. Does only work in text, not mathed.
130 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
131 DocumentClassConstPtr textclass, AuthorList const & authors,
132 ErrorList & errorList,
133 BranchAction branchAction = BRANCH_ASK);
136 /** Needed to switch between different classes. This works
137 * for a list of paragraphs beginning with the specified par.
138 * It changes layouts and character styles. Errors are reported
139 * in the passed ErrorList.
141 void switchBetweenClasses(DocumentClassConstPtr oldone,
142 DocumentClassConstPtr newone, InsetText & in, ErrorList & el);
143 /// Same but without error reporting.
144 void switchBetweenClasses(DocumentClassConstPtr oldone,
145 DocumentClassConstPtr newone, InsetText & in);
147 /// Get the current selection as a string. Does not change the selection.
148 /// Does only work if the whole selection is in mathed.
149 docstring grabSelection(CursorData const & cur);
150 /// Erase the current selection.
151 /// Does not handle undo. Does only work if the whole selection is in mathed.
152 /// Calls saveSelection.
153 void eraseSelection(Cursor & cur);
154 /// Reduce the selected text in mathed to only one cell. If it spans multiple
155 /// cells, the cursor is moved the end of the current cell and the anchor to the
156 /// start. If the selection is inside only one cell, nothing is done. Return
157 /// true if the selection now does not span multiple cells anymore.
158 bool reduceSelectionToOneCell(CursorData & cur);
159 /// Returns true if multiple cells are selected in mathed.
160 bool multipleCellsSelected(CursorData const & cur);
161 /// Erase the selection and return it as a string.
162 /// Does not handle undo. Does only work if the whole selection is in mathed.
163 docstring grabAndEraseSelection(Cursor & cur);
164 // other selection methods
165 /// Erase the selection if one exists.
166 /// Does not handle undo. Does only work if the whole selection is in mathed.
167 void selDel(Cursor & cur);
168 /// Clear or delete the selection if one exists, depending on lyxrc setting.
169 /// Does not handle undo. Does only work if the whole selection is in mathed.
170 void selClearOrDel(Cursor & cur);
171 /// Calculate rectangular region of cell between \c i1 and \c i2.
172 void region(CursorSlice const & i1, CursorSlice const & i2,
173 row_type & r1, row_type & r2,
174 col_type & c1, col_type & c2);
175 /** Tabular has its own paste stack for multiple cells
176 * but it needs to know whether there is a more recent
177 * ordinary paste. Therefore which one is newer.
179 //FIXME: this is a workaround for bug 1919. Replace this by
180 //an all-for-one-paste mechanism in 1.7
181 /// store whether tabular or ordinary paste stack is newer
182 void dirtyTabularStack(bool b);
183 /// is the tabular paste stack newer than the ordinary one?
184 bool tabularStackDirty();