]> git.lyx.org Git - features.git/blob - src/CutAndPaste.h
progress on buffer-reference-in-insets. beware of instabilities...
[features.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/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 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();
38 /// Get the number of available elements in the cut buffer.
39 size_type numberOfSelections();
40 /// Get the sel_index-th element of the cut buffer in plain text format.
41 docstring selection(size_t sel_index);
42
43 /**
44  * Replace using the font of the first selected character and select
45  * the new string. When \c backwards == false, set anchor before
46  * cursor; otherwise set cursor before anchor.
47  * Does handle undo.
48  */
49 void replaceSelectionWithString(Cursor & cur, docstring const & str,
50                                 bool backwards);
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 doclear = true, bool realcut = true);
66 /// Push the current selection to the cut buffer and the system clipboard.
67 void copySelection(Cursor & cur);
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 & 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 & 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
100 /// Paste the paragraph list \p parlist at the position given by \p cur.
101 /// Does not handle undo. Does only work in text, not mathed.
102 void pasteParagraphList(Cursor & cur, ParagraphList const & parlist,
103                         TextClassPtr textclass, ErrorList & errorList);
104
105
106 /** Needed to switch between different classes. This works
107  *  for a list of paragraphs beginning with the specified par.
108  *  It changes layouts and character styles.
109  */
110 void switchBetweenClasses(TextClassPtr const & c1, 
111         TextClassPtr const & c2, InsetText & in, ErrorList &);
112
113 /// Get the current selection as a string. Does not change the selection.
114 /// Does only work if the whole selection is in mathed.
115 docstring grabSelection(Cursor const & cur);
116 /// Erase the current selection.
117 /// Does not handle undo. Does only work if the whole selection is in mathed.
118 /// Calls saveSelection.
119 void eraseSelection(Cursor & cur);
120 /// Erase the selection and return it as a string.
121 /// Does not handle undo. Does only work if the whole selection is in mathed.
122 docstring grabAndEraseSelection(Cursor & cur);
123 // other selection methods
124 /// Erase the selection if one exists.
125 /// Does not handle undo. Does only work if the whole selection is in mathed.
126 void selDel(Cursor & cur);
127 /// Clear or delete the selection if one exists, depending on lyxrc setting.
128 /// Does not handle undo. Does only work if the whole selection is in mathed.
129 void selClearOrDel(Cursor & cur);
130
131 /** Tabular has its own paste stack for multiple cells
132  *  but it needs to know whether there is a more recent
133  *  ordinary paste. Therefore which one is newer.
134  */
135 //FIXME: this is a workaround for bug 1919. Replace this by
136 //an all-for-one-paste mechanism in 1.5
137 /// store whether tabular or ordinary paste stack is newer
138 void dirtyTabularStack(bool b);
139 /// is the tabular paste stack newer than the ordinary one?
140 bool tabularStackDirty();
141 } // namespace cap
142 } // namespce lyx
143
144 #endif