]> git.lyx.org Git - lyx.git/blob - src/CutAndPaste.h
e3ba435b03416560aa8cffe6192800d3aaae8bbb
[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 "TextClassPtr.h"
18
19 #include "support/types.h"
20 #include "support/docstring.h"
21
22 #include "frontends/Clipboard.h"
23
24 #include <vector>
25
26 using lyx::frontend::Clipboard;
27
28 namespace lyx {
29
30 class Buffer;
31 class ErrorList;
32 class InsetText;
33 class Cursor;
34 class ParagraphList;
35
36 namespace cap {
37
38 /// Get all elements of the cut buffer in plain text format.
39 std::vector<docstring> const availableSelections(Buffer const & buffer);
40 /// Get the number of available elements in the cut buffer.
41 size_type numberOfSelections();
42 /// Get the sel_index-th element of the cut buffer in plain text format.
43 docstring getSelection(Buffer const & buffer, size_t sel_index);
44
45 /**
46  * Replace using the font of the first selected character and select
47  * the new string. When \c backwards == false, set anchor before
48  * cursor; otherwise set cursor before anchor.
49  * Does handle undo.
50  */
51 void replaceSelectionWithString(Cursor & cur, docstring const & str,
52                                 bool backwards);
53 /// If a selection exists, delete it without pushing it to the cut buffer.
54 /// Does handle undo.
55 void replaceSelection(Cursor & cur);
56
57 /**
58  * Cut the current selection and possibly push it to the cut buffer and
59  * system clipboard.
60  * Does handle undo. Calls saveSelection.
61  * \param doclear If this is true: Delete leading spaces in paragraphs before
62  *                they get merged.
63  * \param realcut If this is true: Push the selection to the cut buffer and
64  *                system clipboard. Set this to false to only delete the
65  *                selection.
66  */
67 void cutSelection(Cursor & cur, bool doclear = true, bool realcut = true);
68 /// Push the current selection to the cut buffer and the system clipboard.
69 void copySelection(Cursor & cur);
70 /**
71  * Push the current selection to the cut buffer and the system clipboard.
72  * \param plaintext plain text version of the selection for the system
73  *        clipboard
74  */
75 void copySelection(Cursor & cur, docstring const & plaintext);
76 /// Push the selection buffer to the cut buffer.
77 void copySelectionToStack();
78 /// Store the current selection in the internal selection buffer
79 void saveSelection(Cursor & cur);
80 /// Is a selection available in our selection buffer?
81 bool selection();
82 /// Clear our selection buffer
83 void clearSelection();
84 /// Clear our cut stack.
85 void clearCutStack();
86 /// Paste the current selection at \p cur
87 /// Does handle undo. Does only work in text, not mathed.
88 void pasteSelection(Cursor & cur, ErrorList &);
89 /// Replace the current selection with the clipboard contents as text
90 /// (internal or external: which is newer).
91 /// Does handle undo. Does only work in text, not mathed.
92 void pasteClipboardText(Cursor & cur, ErrorList & errorList,
93         bool asParagraphs = true);
94 /// Replace the current selection with the clipboard contents as graphic.
95 /// Does handle undo. Does only work in text, not mathed.
96 void pasteClipboardGraphics(Cursor & cur, ErrorList & errorList,
97         Clipboard::GraphicsType preferedType = Clipboard::AnyGraphicsType);
98 /// Replace the current selection with cut buffer \c sel_index
99 /// Does handle undo. Does only work in text, not mathed.
100 void pasteFromStack(Cursor & cur, ErrorList & errorList, size_t sel_index);
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                         TextClassPtr 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(TextClassPtr const & c1, 
113         TextClassPtr const & 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 /// Erase the selection and return it as a string.
123 /// Does not handle undo. Does only work if the whole selection is in mathed.
124 docstring grabAndEraseSelection(Cursor & cur);
125 // other selection methods
126 /// Erase the selection if one exists.
127 /// Does not handle undo. Does only work if the whole selection is in mathed.
128 void selDel(Cursor & cur);
129 /// Clear or delete the selection if one exists, depending on lyxrc setting.
130 /// Does not handle undo. Does only work if the whole selection is in mathed.
131 void selClearOrDel(Cursor & cur);
132
133 /** Tabular has its own paste stack for multiple cells
134  *  but it needs to know whether there is a more recent
135  *  ordinary paste. Therefore which one is newer.
136  */
137 //FIXME: this is a workaround for bug 1919. Replace this by
138 //an all-for-one-paste mechanism in 1.5
139 /// store whether tabular or ordinary paste stack is newer
140 void dirtyTabularStack(bool b);
141 /// is the tabular paste stack newer than the ordinary one?
142 bool tabularStackDirty();
143 } // namespace cap
144 } // namespce lyx
145
146 #endif