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