/src/libreoffice/vcl/source/weld/TextWidget.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp> |
11 | | #include <vcl/transfer.hxx> |
12 | | #include <vcl/unohelp2.hxx> |
13 | | #include <vcl/weld/TextWidget.hxx> |
14 | | |
15 | | namespace weld |
16 | | { |
17 | | void TextWidget::signal_changed() |
18 | 0 | { |
19 | 0 | if (notify_events_disabled()) |
20 | 0 | return; |
21 | 0 | m_aChangeHdl.Call(*this); |
22 | 0 | } |
23 | | |
24 | | void TextWidget::signal_cursor_position() |
25 | 0 | { |
26 | 0 | if (notify_events_disabled()) |
27 | 0 | return; |
28 | 0 | m_aCursorPositionHdl.Call(*this); |
29 | 0 | } |
30 | | |
31 | | void TextWidget::set_text(const OUString& rText) |
32 | 0 | { |
33 | 0 | disable_notify_events(); |
34 | 0 | do_set_text(rText); |
35 | 0 | enable_notify_events(); |
36 | 0 | } |
37 | | |
38 | | void TextWidget::set_position(int nCursorPos) |
39 | 0 | { |
40 | 0 | disable_notify_events(); |
41 | 0 | if (nCursorPos == -1) |
42 | 0 | nCursorPos = get_text().getLength(); |
43 | 0 | do_set_position(nCursorPos); |
44 | 0 | enable_notify_events(); |
45 | 0 | } |
46 | | |
47 | | void TextWidget::select_region(int nStartPos, int nEndPos) |
48 | 0 | { |
49 | 0 | disable_notify_events(); |
50 | 0 | do_select_region(nStartPos, nEndPos); |
51 | 0 | enable_notify_events(); |
52 | 0 | } |
53 | | |
54 | | void TextWidget::replace_selection(const OUString& rText) |
55 | 0 | { |
56 | 0 | disable_notify_events(); |
57 | 0 | do_replace_selection(rText); |
58 | 0 | enable_notify_events(); |
59 | 0 | } |
60 | | |
61 | | void TextWidget::cut_clipboard() |
62 | 0 | { |
63 | 0 | copy_clipboard(); |
64 | 0 | replace_selection(u""_ustr); |
65 | 0 | } |
66 | | |
67 | | void TextWidget::copy_clipboard() |
68 | 0 | { |
69 | 0 | int nSelectionStart = 0; |
70 | 0 | int nSelectionEnd = 0; |
71 | 0 | if (!get_selection_bounds(nSelectionStart, nSelectionEnd)) |
72 | 0 | return; |
73 | | |
74 | 0 | const OUString sText = get_text(); |
75 | 0 | assert(nSelectionStart >= 0 && nSelectionStart <= sText.getLength() && nSelectionEnd >= 0 |
76 | 0 | && nSelectionEnd <= sText.getLength()); |
77 | 0 | const OUString sSelectedText = sText.copy(std::min(nSelectionStart, nSelectionEnd), |
78 | 0 | std::abs(nSelectionEnd - nSelectionStart)); |
79 | 0 | vcl::unohelper::TextDataObject::CopyStringTo(sSelectedText, get_clipboard()); |
80 | 0 | } |
81 | | |
82 | | void TextWidget::paste_clipboard() |
83 | 0 | { |
84 | 0 | TransferableDataHelper aDataHelper |
85 | 0 | = TransferableDataHelper::CreateFromClipboard(get_clipboard()); |
86 | 0 | OUString sText; |
87 | 0 | if (aDataHelper.GetString(SotClipboardFormatId::STRING, sText)) |
88 | 0 | replace_selection(sText); |
89 | 0 | } |
90 | | } |
91 | | |
92 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |