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