]> git.lyx.org Git - lyx.git/blob - src/CutAndPaste.h
Add empty line after last \bibitem in bibliography (#12041)
[lyx.git] / src / CutAndPaste.h
1 // -*- C++ -*-
2 /**
3  * \file CutAndPaste.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jürgen Vigna
8  * \author Lars Gullik Bjønnes
9  * \author Alfredo Braunstein
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef CUTANDPASTE_H
15 #define CUTANDPASTE_H
16
17 #include "DocumentClassPtr.h"
18
19 #include "support/strfwd.h"
20 #include "support/types.h"
21
22 #include "frontends/Clipboard.h"
23
24 #include <vector>
25
26
27 namespace lyx {
28
29 class Buffer;
30 class ErrorList;
31 class Inset;
32 class InsetText;
33 class Cursor;
34 class CursorData;
35 class CursorSlice;
36 class ParagraphList;
37
38 namespace cap {
39
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();
44 /// Get the sel_index-th element of the cut buffer in plain text format.
45 docstring selection(size_t sel_index, DocumentClassConstPtr docclass);
46
47 /**
48  * Replace using the font of the first selected character and select
49  * the new string. Does handle undo.
50  */
51 void replaceSelectionWithString(Cursor & cur, docstring const & str);
52 /// If a selection exists, delete it without pushing it to the cut buffer.
53 /// Does handle undo.
54 void replaceSelection(Cursor & cur);
55
56 /**
57  * Cut the current selection and possibly push it to the cut buffer and
58  * system clipboard.
59  * Does handle undo. Calls saveSelection.
60  * \param doclear If this is true: Delete leading spaces in paragraphs before
61  *                they get merged.
62  * \param realcut If this is true: Push the selection to the cut buffer and
63  *                system clipboard. Set this to false to only delete the
64  *                selection.
65  */
66 void cutSelection(Cursor & cur, bool realcut = true);
67 /// Like cutSelection, but only put to temporary cut buffer
68 void cutSelectionToTemp(Cursor & cur, bool realcut = true);
69
70 /// Push the current selection to the cut buffer and the system clipboard.
71 void copySelection(Cursor const & cur);
72 /// Like copySelection, but only put to temporary cut buffer
73 void copySelectionToTemp(Cursor const & cur);
74 ///
75 void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext);
76 /**
77  * Push the current selection to the cut buffer and the system clipboard.
78  * \param plaintext plain text version of the selection for the system
79  *        clipboard
80  */
81 void copySelection(Cursor const & cur, docstring const & plaintext);
82 /// Push the selection buffer to the cut buffer.
83 void copySelectionToStack();
84 /// Store the current selection in the internal selection buffer
85 void saveSelection(Cursor const & cur);
86 /// Is a selection available in our selection buffer?
87 bool selection();
88 /// Clear our selection buffer
89 void clearSelection();
90 /// Clear our cut stack.
91 void clearCutStack();
92 /// Paste the current selection at \p cur
93 /// Does handle undo. Does only work in text, not mathed.
94 void pasteSelection(Cursor & cur, ErrorList &);
95 /// Replace the current selection with the clipboard contents as text
96 /// (internal or external: which is newer).
97 /// Does handle undo. Does only work in text, not mathed.
98 /// \p asParagraphs is only considered if plain text is pasted.
99 bool pasteClipboardText(Cursor & cur, ErrorList & errorList, bool asParagraphs,
100         frontend::Clipboard::TextType preferedType = frontend::Clipboard::LyXOrPlainTextType);
101 /// Replace the current selection with the clipboard contents as graphic.
102 /// Does handle undo. Does only work in text, not mathed.
103 void pasteClipboardGraphics(Cursor & cur, ErrorList & errorList,
104         frontend::Clipboard::GraphicsType preferedType = frontend::Clipboard::AnyGraphicsType);
105 /// Replace the current selection with cut buffer \c sel_index
106 /// Does handle undo. Does only work in text, not mathed.
107 bool pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index);
108 /// Replace the current selection with temporary cut buffer
109 /// Does handle undo. Does only work in text, not mathed.
110 bool pasteFromTemp(Cursor & cur, ErrorList & errorList);
111 /// Paste the clipboard as simple text, removing any formatting
112 void pasteSimpleText(Cursor & cur, bool asParagraphs);
113
114 // What to do with unknown branches?
115 enum BranchAction {
116         BRANCH_ADD, // add the branch unconditionally
117         BRANCH_IGNORE, // leave the branch undefined
118         BRANCH_ASK // ask the user whether the branch should be added
119 };
120 /// Paste the paragraph list \p parlist at the position given by \p cur.
121 /// Does not handle undo. Does only work in text, not mathed.
122 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
123                         DocumentClassConstPtr textclass, ErrorList & errorList,
124                         BranchAction branchAction = BRANCH_ASK);
125
126
127 /** Needed to switch between different classes. This works
128  *  for a list of paragraphs beginning with the specified par.
129  *  It changes layouts and character styles.
130  */
131 void switchBetweenClasses(DocumentClassConstPtr oldone,
132                         DocumentClassConstPtr newone, InsetText & in, ErrorList &);
133
134 /// Get the current selection as a string. Does not change the selection.
135 /// Does only work if the whole selection is in mathed.
136 docstring grabSelection(CursorData const & cur);
137 /// Erase the current selection.
138 /// Does not handle undo. Does only work if the whole selection is in mathed.
139 /// Calls saveSelection.
140 void eraseSelection(Cursor & cur);
141 /// Reduce the selected text in mathed to only one cell. If it spans multiple
142 /// cells, the cursor is moved the end of the current cell and the anchor to the
143 /// start. If the selection is inside only one cell, nothing is done. Return
144 /// true if the selection now does not span multiple cells anymore.
145 bool reduceSelectionToOneCell(CursorData & cur);
146 /// Returns true if multiple cells are selected in mathed.
147 bool multipleCellsSelected(CursorData const & cur);
148 /// Erase the selection and return it as a string.
149 /// Does not handle undo. Does only work if the whole selection is in mathed.
150 docstring grabAndEraseSelection(Cursor & cur);
151 // other selection methods
152 /// Erase the selection if one exists.
153 /// Does not handle undo. Does only work if the whole selection is in mathed.
154 void selDel(Cursor & cur);
155 /// Clear or delete the selection if one exists, depending on lyxrc setting.
156 /// Does not handle undo. Does only work if the whole selection is in mathed.
157 void selClearOrDel(Cursor & cur);
158 /// Calculate rectangular region of cell between \c i1 and \c i2.
159 void region(CursorSlice const & i1, CursorSlice const & i2,
160                         row_type & r1, row_type & r2,
161                         col_type & c1, col_type & c2);
162 /** Tabular has its own paste stack for multiple cells
163  *  but it needs to know whether there is a more recent
164  *  ordinary paste. Therefore which one is newer.
165  */
166 //FIXME: this is a workaround for bug 1919. Replace this by
167 //an all-for-one-paste mechanism in 1.7
168 /// store whether tabular or ordinary paste stack is newer
169 void dirtyTabularStack(bool b);
170 /// is the tabular paste stack newer than the ordinary one?
171 bool tabularStackDirty();
172 } // namespace cap
173 } // namespace lyx
174
175 #endif