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