* qt_helpers.cpp:
[lyx.git] / src / CutAndPaste.h
bloba4e975b8a1483823c44ad6479f82fa5c4312661a
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.
7 * \author Jürgen Vigna
8 * \author Lars Gullik Bjønnes
9 * \author Alfredo Braunstein
11 * Full author contact details are available in file CREDITS.
14 #ifndef CUTANDPASTE_H
15 #define CUTANDPASTE_H
17 #include "support/docstring.h"
19 #include "frontends/Clipboard.h"
21 #include <vector>
23 using lyx::frontend::Clipboard;
25 namespace lyx {
27 class DocumentClass;
28 class ErrorList;
29 class InsetText;
30 class Cursor;
31 class ParagraphList;
33 namespace cap {
35 /// Get all elements of the cut buffer in plain text format.
36 std::vector<docstring> availableSelections(Buffer const *);
37 /// Get the number of available elements in the cut buffer.
38 size_type numberOfSelections();
39 /// Get the sel_index-th element of the cut buffer in plain text format.
40 docstring selection(size_t sel_index);
42 /**
43 * Replace using the font of the first selected character and select
44 * the new string. When \c backwards == false, set anchor before
45 * cursor; otherwise set cursor before anchor.
46 * Does handle undo.
48 void replaceSelectionWithString(Cursor & cur, docstring const & str,
49 bool backwards);
50 /// If a selection exists, delete it without pushing it to the cut buffer.
51 /// Does handle undo.
52 void replaceSelection(Cursor & cur);
54 /**
55 * Cut the current selection and possibly push it to the cut buffer and
56 * system clipboard.
57 * Does handle undo. Calls saveSelection.
58 * \param doclear If this is true: Delete leading spaces in paragraphs before
59 * they get merged.
60 * \param realcut If this is true: Push the selection to the cut buffer and
61 * system clipboard. Set this to false to only delete the
62 * selection.
64 void cutSelection(Cursor & cur, bool doclear = true, bool realcut = true);
65 /// Push the current selection to the cut buffer and the system clipboard.
66 void copySelection(Cursor const & cur);
67 ///
68 void copyInset(Cursor const & cur, Inset * inset, docstring const & plaintext);
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
74 void copySelection(Cursor const & 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 const & 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);
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 DocumentClass const * const textclass, ErrorList & errorList);
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.
111 void switchBetweenClasses(DocumentClass const * const c1,
112 DocumentClass const * const c2, InsetText & in, ErrorList &);
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 /// Reduce the selected text in mathed to only one cell. If it spans multiple
122 /// cells, the cursor is moved the end of the current cell and the anchor to the
123 /// start. If the selection is inside only one cell, nothing is done. Return
124 /// true if the selection now does not span multiple cells anymore.
125 bool reduceSelectionToOneCell(Cursor & cur);
126 /// Returns true if multiple cells are selected in mathed.
127 bool multipleCellsSelected(Cursor const & cur);
128 /// Erase the selection and return it as a string.
129 /// Does not handle undo. Does only work if the whole selection is in mathed.
130 docstring grabAndEraseSelection(Cursor & cur);
131 // other selection methods
132 /// Erase the selection if one exists.
133 /// Does not handle undo. Does only work if the whole selection is in mathed.
134 void selDel(Cursor & cur);
135 /// Clear or delete the selection if one exists, depending on lyxrc setting.
136 /// Does not handle undo. Does only work if the whole selection is in mathed.
137 void selClearOrDel(Cursor & cur);
138 /// Calculate rectangular region of cell between \c i1 and \c i2.
139 void region(CursorSlice const & i1, CursorSlice const & i2,
140 Inset::row_type & r1, Inset::row_type & r2,
141 Inset::col_type & c1, Inset::col_type & c2);
142 /** Tabular has its own paste stack for multiple cells
143 * but it needs to know whether there is a more recent
144 * ordinary paste. Therefore which one is newer.
146 //FIXME: this is a workaround for bug 1919. Replace this by
147 //an all-for-one-paste mechanism in 1.7
148 /// store whether tabular or ordinary paste stack is newer
149 void dirtyTabularStack(bool b);
150 /// is the tabular paste stack newer than the ordinary one?
151 bool tabularStackDirty();
152 } // namespace cap
153 } // namespce lyx
155 #endif