1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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 SvPasteObjectDialog::SvPasteObjectDialog(weld::Window
* pParent
)
31 : GenericDialogController(pParent
, "cui/ui/pastespecial.ui", "PasteSpecialDialog")
32 , m_xFtObjectSource(m_xBuilder
->weld_label("source"))
33 , m_xLbInsertList(m_xBuilder
->weld_tree_view("list"))
34 , m_xOKButton(m_xBuilder
->weld_button("ok"))
36 m_xLbInsertList
->set_size_request(m_xLbInsertList
->get_approximate_digit_width() * 40,
37 m_xLbInsertList
->get_height_rows(6));
38 m_xOKButton
->set_sensitive(false);
40 ObjectLB().connect_changed(LINK(this, SvPasteObjectDialog
, SelectHdl
));
41 ObjectLB().connect_row_activated(LINK( this, SvPasteObjectDialog
, DoubleClickHdl
));
44 void SvPasteObjectDialog::SelectObject()
46 if (m_xLbInsertList
->n_children())
48 m_xLbInsertList
->select(0);
49 SelectHdl(*m_xLbInsertList
);
53 IMPL_LINK_NOARG(SvPasteObjectDialog
, SelectHdl
, weld::TreeView
&, void)
55 if (!m_xOKButton
->get_sensitive())
56 m_xOKButton
->set_sensitive(true);
59 IMPL_LINK_NOARG(SvPasteObjectDialog
, DoubleClickHdl
, weld::TreeView
&, bool)
61 m_xDialog
->response(RET_OK
);
65 /*************************************************************************
66 |* SvPasteObjectDialog::Insert()
67 *************************************************************************/
68 void SvPasteObjectDialog::Insert( SotClipboardFormatId nFormat
, const OUString
& rFormatName
)
70 aSupplementMap
.insert( std::make_pair( nFormat
, rFormatName
) );
73 void SvPasteObjectDialog::PreGetFormat( const TransferableDataHelper
&rHelper
)
75 //TODO/LATER: why is the Descriptor never used?!
76 TransferableObjectDescriptor aDesc
;
77 if (rHelper
.HasFormat(SotClipboardFormatId::OBJECTDESCRIPTOR
))
79 (void)const_cast<TransferableDataHelper
&>(rHelper
).GetTransferableObjectDescriptor(
80 SotClipboardFormatId::OBJECTDESCRIPTOR
, aDesc
);
82 const DataFlavorExVector
* pFormats
= &rHelper
.GetDataFlavorExVector();
84 // create and fill dialog box
85 OUString aSourceName
, aTypeName
;
86 SvGlobalName aEmptyNm
;
88 //ObjectLB().SetUpdateMode( false );
91 DataFlavorExVector::iterator
aIter( const_cast<DataFlavorExVector
&>(*pFormats
).begin() ),
92 aEnd( const_cast<DataFlavorExVector
&>(*pFormats
).end() );
93 while( aIter
!= aEnd
)
95 SotClipboardFormatId nFormat
= (*aIter
++).mnSotId
;
97 std::map
< SotClipboardFormatId
, OUString
>::iterator itName
=
98 aSupplementMap
.find( nFormat
);
100 // if there is an "Embed Source" or and "Embedded Object" on the
101 // Clipboard we read the Description and the Source of this object
102 // from an accompanied "Object Descriptor" format on the clipboard
103 // Remember: these formats mostly appear together on the clipboard
105 const OUString
* pName
= nullptr;
106 if ( itName
== aSupplementMap
.end() )
108 SvPasteObjectHelper::GetEmbeddedName(rHelper
,aName
,aSourceName
,nFormat
);
109 if ( !aName
.isEmpty() )
114 pName
= &(itName
->second
);
121 if( SotClipboardFormatId::EMBED_SOURCE
== nFormat
)
123 if( aDesc
.maClassName
!= aEmptyNm
)
125 aSourceName
= aDesc
.maDisplayName
;
127 if( aDesc
.maClassName
== aObjClassName
)
130 aName
= aTypeName
= aDesc
.maTypeName
;
133 else if( SotClipboardFormatId::LINK_SOURCE
== nFormat
)
137 else if( aName
.isEmpty() )
138 aName
= SvPasteObjectHelper::GetSotFormatUIName( nFormat
);
140 // Show RICHTEXT only in case RTF is not present.
141 if (nFormat
== SotClipboardFormatId::RICHTEXT
&&
142 std::any_of(pFormats
->begin(), pFormats
->end(),
143 [](const DataFlavorEx
& rFlavor
) {
144 return rFlavor
.mnSotId
== SotClipboardFormatId::RTF
;
150 if (ObjectLB().find_text(aName
) == -1)
152 ObjectLB().append(OUString::number(static_cast<sal_uInt32
>(nFormat
)), aName
);
157 if( aTypeName
.isEmpty() && aSourceName
.isEmpty() )
159 if( aDesc
.maClassName
!= aEmptyNm
)
161 aSourceName
= aDesc
.maDisplayName
;
162 aTypeName
= aDesc
.maTypeName
;
165 if( aTypeName
.isEmpty() && aSourceName
.isEmpty() )
167 // global resource from svtools (former so3 resource)
168 aSourceName
= SvtResId(STR_UNKNOWN_SOURCE
);
175 if( !aSourceName
.isEmpty() )
177 if( !aTypeName
.isEmpty() )
180 aTypeName
+= aSourceName
;
181 aTypeName
= convertLineEnd(aTypeName
, GetSystemLineEnd());
184 m_xFtObjectSource
->set_label(aTypeName
);
187 SotClipboardFormatId
SvPasteObjectDialog::GetFormatOnly()
189 return static_cast<SotClipboardFormatId
>(ObjectLB().get_selected_id().toUInt32());
192 SotClipboardFormatId
SvPasteObjectDialog::GetFormat( const TransferableDataHelper
& rHelper
)
194 //TODO/LATER: why is the Descriptor never used?!
195 TransferableObjectDescriptor aDesc
;
196 if (rHelper
.HasFormat(SotClipboardFormatId::OBJECTDESCRIPTOR
))
198 (void)const_cast<TransferableDataHelper
&>(rHelper
).GetTransferableObjectDescriptor(
199 SotClipboardFormatId::OBJECTDESCRIPTOR
, aDesc
);
201 const DataFlavorExVector
* pFormats
= &rHelper
.GetDataFlavorExVector();
203 // create and fill dialog box
204 OUString aSourceName
, aTypeName
;
205 SotClipboardFormatId nSelFormat
= SotClipboardFormatId::NONE
;
206 SvGlobalName aEmptyNm
;
210 for (auto const& format
: *pFormats
)
212 SotClipboardFormatId nFormat
= format
.mnSotId
;
214 std::map
< SotClipboardFormatId
, OUString
>::iterator itName
=
215 aSupplementMap
.find( nFormat
);
217 // if there is an "Embed Source" or and "Embedded Object" on the
218 // Clipboard we read the Description and the Source of this object
219 // from an accompanied "Object Descriptor" format on the clipboard
220 // Remember: these formats mostly appear together on the clipboard
222 const OUString
* pName
= nullptr;
223 if ( itName
== aSupplementMap
.end() )
225 SvPasteObjectHelper::GetEmbeddedName(rHelper
,aName
,aSourceName
,nFormat
);
226 if ( !aName
.isEmpty() )
231 pName
= &(itName
->second
);
238 if( SotClipboardFormatId::EMBED_SOURCE
== nFormat
)
240 if( aDesc
.maClassName
!= aEmptyNm
)
242 aSourceName
= aDesc
.maDisplayName
;
244 if( aDesc
.maClassName
== aObjClassName
)
247 aName
= aTypeName
= aDesc
.maTypeName
;
250 else if( SotClipboardFormatId::LINK_SOURCE
== nFormat
)
254 else if( aName
.isEmpty() )
255 aName
= SvPasteObjectHelper::GetSotFormatUIName( nFormat
);
257 // Show RICHTEXT only in case RTF is not present.
258 if (nFormat
== SotClipboardFormatId::RICHTEXT
&&
259 std::any_of(pFormats
->begin(), pFormats
->end(),
260 [](const DataFlavorEx
& rFlavor
) {
261 return rFlavor
.mnSotId
== SotClipboardFormatId::RTF
;
267 if (ObjectLB().find_text(aName
) == -1)
269 ObjectLB().append(OUString::number(static_cast<sal_uInt32
>(nFormat
)), aName
);
274 if( aTypeName
.isEmpty() && aSourceName
.isEmpty() )
276 if( aDesc
.maClassName
!= aEmptyNm
)
278 aSourceName
= aDesc
.maDisplayName
;
279 aTypeName
= aDesc
.maTypeName
;
282 if( aTypeName
.isEmpty() && aSourceName
.isEmpty() )
284 // global resource from svtools (former so3 resource)
285 aSourceName
= SvtResId(STR_UNKNOWN_SOURCE
);
292 if( !aSourceName
.isEmpty() )
294 if( !aTypeName
.isEmpty() )
297 aTypeName
+= aSourceName
;
298 aTypeName
= convertLineEnd(aTypeName
, GetSystemLineEnd());
301 m_xFtObjectSource
->set_label(aTypeName
);
305 nSelFormat
= static_cast<SotClipboardFormatId
>(ObjectLB().get_selected_id().toUInt32());
311 void SvPasteObjectDialog::SetObjName( const SvGlobalName
& rClass
, const OUString
& rObjName
)
313 aObjClassName
= rClass
;
317 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */