LibreOffice Module cui (master) 1
pastedlg.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <memory>
21
22#include <pastedlg.hxx>
23#include <svtools/insdlg.hxx>
24#include <sot/exchange.hxx>
25#include <sot/formats.hxx>
26#include <svtools/strings.hrc>
27#include <svtools/svtresid.hxx>
28#include <tools/lineend.hxx>
30#include <com/sun/star/beans/PropertyValue.hpp>
31
33 : GenericDialogController(pParent, "cui/ui/pastespecial.ui", "PasteSpecialDialog")
34 , m_xFtObjectSource(m_xBuilder->weld_label("source"))
35 , m_xLbInsertList(m_xBuilder->weld_tree_view("list"))
36 , m_xOKButton(m_xBuilder->weld_button("ok"))
37{
38 m_xLbInsertList->set_size_request(m_xLbInsertList->get_approximate_digit_width() * 40,
39 m_xLbInsertList->get_height_rows(6));
40 m_xOKButton->set_sensitive(false);
41
43 ObjectLB().connect_row_activated(LINK( this, SvPasteObjectDialog, DoubleClickHdl));
44}
45
47{
48 if (m_xLbInsertList->n_children())
49 {
50 m_xLbInsertList->select(0);
51 SelectHdl(*m_xLbInsertList);
52 }
53}
54
56{
57 if (!m_xOKButton->get_sensitive())
58 m_xOKButton->set_sensitive(true);
59}
60
62{
63 m_xDialog->response(RET_OK);
64 return true;
65}
66
67/*************************************************************************
68|* SvPasteObjectDialog::Insert()
69*************************************************************************/
70void SvPasteObjectDialog::Insert( SotClipboardFormatId nFormat, const OUString& rFormatName )
71{
72 aSupplementMap.insert( std::make_pair( nFormat, rFormatName ) );
73}
74
75void SvPasteObjectDialog::InsertUno(const OUString& sCmd, const OUString& sLabel)
76{
77 aExtraCommand.first = sCmd;
78 aExtraCommand.second = sLabel;
79}
80
81
83{
84 //TODO/LATER: why is the Descriptor never used?!
86 if (rHelper.HasFormat(SotClipboardFormatId::OBJECTDESCRIPTOR))
87 {
89 SotClipboardFormatId::OBJECTDESCRIPTOR, aDesc);
90 }
91 const DataFlavorExVector* pFormats = &rHelper.GetDataFlavorExVector();
92
93 // create and fill dialog box
94 OUString aSourceName, aTypeName;
95 SvGlobalName aEmptyNm;
96
97 //ObjectLB().SetUpdateMode( false );
98 ObjectLB().freeze();
99
100 DataFlavorExVector::iterator aIter( const_cast<DataFlavorExVector&>(*pFormats).begin() ),
101 aEnd( const_cast<DataFlavorExVector&>(*pFormats).end() );
102 while( aIter != aEnd )
103 {
104 SotClipboardFormatId nFormat = (*aIter++).mnSotId;
105
106 std::map< SotClipboardFormatId, OUString >::iterator itName =
107 aSupplementMap.find( nFormat );
108
109 // if there is an "Embed Source" or and "Embedded Object" on the
110 // Clipboard we read the Description and the Source of this object
111 // from an accompanied "Object Descriptor" format on the clipboard
112 // Remember: these formats mostly appear together on the clipboard
113 OUString aName;
114 const OUString* pName = nullptr;
115 if ( itName == aSupplementMap.end() )
116 {
117 SvPasteObjectHelper::GetEmbeddedName(rHelper,aName,aSourceName,nFormat);
118 if ( !aName.isEmpty() )
119 pName = &aName;
120 }
121 else
122 {
123 pName = &(itName->second);
124 }
125
126 if( pName )
127 {
128 aName = *pName;
129
130 if( SotClipboardFormatId::EMBED_SOURCE == nFormat )
131 {
132 if( aDesc.maClassName != aEmptyNm )
133 {
134 aSourceName = aDesc.maDisplayName;
135
136 if( aDesc.maClassName == aObjClassName )
137 aName = aObjName;
138 else
139 aName = aTypeName = aDesc.maTypeName;
140 }
141 }
142 else if( SotClipboardFormatId::LINK_SOURCE == nFormat )
143 {
144 continue;
145 }
146 else if( aName.isEmpty() )
148
149 // Show RICHTEXT only in case RTF is not present.
150 if (nFormat == SotClipboardFormatId::RICHTEXT &&
151 std::any_of(pFormats->begin(), pFormats->end(),
152 [](const DataFlavorEx& rFlavor) {
153 return rFlavor.mnSotId == SotClipboardFormatId::RTF;
154 }))
155 {
156 continue;
157 }
158
159 if (ObjectLB().find_text(aName) == -1)
160 {
161 ObjectLB().append(OUString::number(static_cast<sal_uInt32>(nFormat)), aName);
162 }
163 }
164 }
165
166 if( aTypeName.isEmpty() && aSourceName.isEmpty() )
167 {
168 if( aDesc.maClassName != aEmptyNm )
169 {
170 aSourceName = aDesc.maDisplayName;
171 aTypeName = aDesc.maTypeName;
172 }
173
174 if( aTypeName.isEmpty() && aSourceName.isEmpty() )
175 {
176 // global resource from svtools (former so3 resource)
177 aSourceName = SvtResId(STR_UNKNOWN_SOURCE);
178 }
179 }
180
181 ObjectLB().thaw();
182 SelectObject();
183
184 if( !aSourceName.isEmpty() )
185 {
186 if( !aTypeName.isEmpty() )
187 aTypeName += "\n";
188
189 aTypeName += aSourceName;
190 aTypeName = convertLineEnd(aTypeName, GetSystemLineEnd());
191 }
192
193 m_xFtObjectSource->set_label(aTypeName);
194}
195
197{
198 return static_cast<SotClipboardFormatId>(ObjectLB().get_selected_id().toUInt32());
199}
200
202{
203 //TODO/LATER: why is the Descriptor never used?!
205 if (rHelper.HasFormat(SotClipboardFormatId::OBJECTDESCRIPTOR))
206 {
208 SotClipboardFormatId::OBJECTDESCRIPTOR, aDesc);
209 }
210 const DataFlavorExVector* pFormats = &rHelper.GetDataFlavorExVector();
211
212 // create and fill dialog box
213 OUString aSourceName, aTypeName;
214 SotClipboardFormatId nSelFormat = SotClipboardFormatId::NONE;
215 SvGlobalName aEmptyNm;
216
217 ObjectLB().freeze();
218
219 for (auto const& format : *pFormats)
220 {
221 SotClipboardFormatId nFormat = format.mnSotId;
222
223 std::map< SotClipboardFormatId, OUString >::iterator itName =
224 aSupplementMap.find( nFormat );
225
226 // if there is an "Embed Source" or and "Embedded Object" on the
227 // Clipboard we read the Description and the Source of this object
228 // from an accompanied "Object Descriptor" format on the clipboard
229 // Remember: these formats mostly appear together on the clipboard
230 OUString aName;
231 const OUString* pName = nullptr;
232 if ( itName == aSupplementMap.end() )
233 {
234 SvPasteObjectHelper::GetEmbeddedName(rHelper,aName,aSourceName,nFormat);
235 if ( !aName.isEmpty() )
236 pName = &aName;
237 }
238 else
239 {
240 pName = &(itName->second);
241 }
242
243 if( pName )
244 {
245 aName = *pName;
246
247 if( SotClipboardFormatId::EMBED_SOURCE == nFormat )
248 {
249 if( aDesc.maClassName != aEmptyNm )
250 {
251 aSourceName = aDesc.maDisplayName;
252
253 if( aDesc.maClassName == aObjClassName )
254 aName = aObjName;
255 else
256 aName = aTypeName = aDesc.maTypeName;
257 }
258 }
259 else if( SotClipboardFormatId::LINK_SOURCE == nFormat )
260 {
261 continue;
262 }
263 else if( aName.isEmpty() )
265
266 // Show RICHTEXT only in case RTF is not present.
267 if (nFormat == SotClipboardFormatId::RICHTEXT &&
268 std::any_of(pFormats->begin(), pFormats->end(),
269 [](const DataFlavorEx& rFlavor) {
270 return rFlavor.mnSotId == SotClipboardFormatId::RTF;
271 }))
272 {
273 continue;
274 }
275
276 if (ObjectLB().find_text(aName) == -1)
277 {
278 ObjectLB().append(OUString::number(static_cast<sal_uInt32>(nFormat)), aName);
279 }
280 }
281 }
282
283 if( aTypeName.isEmpty() && aSourceName.isEmpty() )
284 {
285 if( aDesc.maClassName != aEmptyNm )
286 {
287 aSourceName = aDesc.maDisplayName;
288 aTypeName = aDesc.maTypeName;
289 }
290
291 if( aTypeName.isEmpty() && aSourceName.isEmpty() )
292 {
293 // global resource from svtools (former so3 resource)
294 aSourceName = SvtResId(STR_UNKNOWN_SOURCE);
295 }
296 }
297
298 if (!aExtraCommand.first.isEmpty())
299 {
301 }
302
303 ObjectLB().thaw();
304 SelectObject();
305
306 if( !aSourceName.isEmpty() )
307 {
308 if( !aTypeName.isEmpty() )
309 aTypeName += "\n";
310
311 aTypeName += aSourceName;
312 aTypeName = convertLineEnd(aTypeName, GetSystemLineEnd());
313 }
314
315 m_xFtObjectSource->set_label(aTypeName);
316
317 if (run() == RET_OK)
318 {
319 if (ObjectLB().get_selected_id().startsWithIgnoreAsciiCase(".uno"))
320 {
322 nSelFormat = SotClipboardFormatId::NONE;
323 }
324 else
325 {
326 nSelFormat = static_cast<SotClipboardFormatId>(ObjectLB().get_selected_id().toUInt32());
327 }
328 }
329
330 return nSelFormat;
331}
332
333void SvPasteObjectDialog::SetObjName( const SvGlobalName & rClass, const OUString & rObjName )
334{
335 aObjClassName = rClass;
336 aObjName = rObjName;
337}
338
339/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char * pName
Reference< XExecutableDialog > m_xDialog
weld::TreeView & ObjectLB()
Definition: pastedlg.hxx:43
void InsertUno(const OUString &sUnoCmd, const OUString &sLabel)
Definition: pastedlg.cxx:75
SvGlobalName aObjClassName
Definition: pastedlg.hxx:36
std::unique_ptr< weld::Label > m_xFtObjectSource
Definition: pastedlg.hxx:39
std::unique_ptr< weld::Button > m_xOKButton
Definition: pastedlg.hxx:41
std::map< SotClipboardFormatId, OUString > aSupplementMap
Definition: pastedlg.hxx:33
std::unique_ptr< weld::TreeView > m_xLbInsertList
Definition: pastedlg.hxx:40
SvPasteObjectDialog(weld::Window *pParent)
Definition: pastedlg.cxx:32
void PreGetFormat(const TransferableDataHelper &aHelper)
PreGetFormat Prepares the dialog for running to get format of paste as a SotClipboardFormatId value b...
Definition: pastedlg.cxx:82
SotClipboardFormatId GetFormatOnly()
GetFormatOnly Returns a SotClipboardFormatId value.
Definition: pastedlg.cxx:196
void Insert(SotClipboardFormatId nFormat, const OUString &rFormatName)
Definition: pastedlg.cxx:70
std::pair< OUString, OUString > aExtraCommand
Definition: pastedlg.hxx:35
SotClipboardFormatId GetFormat(const TransferableDataHelper &aHelper)
GetFormat Prepares and runs the dialog, and returns a SotClipboardFormatId depending on the RET_OK re...
Definition: pastedlg.cxx:201
void SetObjName(const SvGlobalName &rClass, const OUString &rObjName)
Definition: pastedlg.cxx:333
static bool GetEmbeddedName(const TransferableDataHelper &rData, OUString &_rName, OUString &_rSource, SotClipboardFormatId const &_nFormat)
static OUString GetSotFormatUIName(SotClipboardFormatId nId)
bool GetTransferableObjectDescriptor(SotClipboardFormatId nFormat, TransferableObjectDescriptor &rDesc)
const DataFlavorExVector & GetDataFlavorExVector() const
bool HasFormat(SotClipboardFormatId nFormat) const
virtual short run()
void connect_row_activated(const Link< TreeView &, bool > &rLink)
virtual int find_text(const OUString &rText) const=0
void connect_changed(const Link< TreeView &, void > &rLink)
void append(TreeIter *pRet=nullptr)
virtual OUString get_selected_id() const=0
virtual void freeze()=0
virtual void thaw()=0
::std::vector< DataFlavorEx > DataFlavorExVector
SotClipboardFormatId
std::unique_ptr< weld::Button > m_xOKButton
OUString aName
LineEnd GetSystemLineEnd()
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
IMPL_LINK_NOARG(SvPasteObjectDialog, SelectHdl, weld::TreeView &, void)
Definition: pastedlg.cxx:55
SVT_DLLPUBLIC OUString SvtResId(TranslateId aId)
RET_OK