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