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