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