bump product version to 6.3.0.0.beta1
[LibreOffice.git] / cui / source / dialogs / pastedlg.cxx
blob9b47043138a6da8c346d1bd394af07fe2feb7ba8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <memory>
21 #include <com/sun/star/embed/Aspects.hpp>
23 #include <pastedlg.hxx>
24 #include <svtools/insdlg.hxx>
25 #include <sot/exchange.hxx>
26 #include <sot/formats.hxx>
27 #include <svtools/strings.hrc>
28 #include <svtools/svtresid.hxx>
29 #include <tools/lineend.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/settings.hxx>
33 SvPasteObjectDialog::SvPasteObjectDialog(weld::Window* pParent)
34 : GenericDialogController(pParent, "cui/ui/pastespecial.ui", "PasteSpecialDialog")
35 , m_xFtObjectSource(m_xBuilder->weld_label("source"))
36 , m_xLbInsertList(m_xBuilder->weld_tree_view("list"))
37 , m_xOKButton(m_xBuilder->weld_button("ok"))
39 m_xLbInsertList->set_size_request(m_xLbInsertList->get_approximate_digit_width() * 40,
40 m_xLbInsertList->get_height_rows(6));
41 m_xOKButton->set_sensitive(false);
43 ObjectLB().connect_changed(LINK(this, SvPasteObjectDialog, SelectHdl));
44 ObjectLB().connect_row_activated(LINK( this, SvPasteObjectDialog, DoubleClickHdl));
47 void SvPasteObjectDialog::SelectObject()
49 if (m_xLbInsertList->n_children())
51 m_xLbInsertList->select(0);
52 SelectHdl(*m_xLbInsertList);
56 IMPL_LINK_NOARG(SvPasteObjectDialog, SelectHdl, weld::TreeView&, void)
58 if (!m_xOKButton->get_sensitive())
59 m_xOKButton->set_sensitive(true);
62 IMPL_LINK_NOARG(SvPasteObjectDialog, DoubleClickHdl, weld::TreeView&, void)
64 m_xDialog->response(RET_OK);
67 /*************************************************************************
68 |* SvPasteObjectDialog::Insert()
69 *************************************************************************/
70 void SvPasteObjectDialog::Insert( SotClipboardFormatId nFormat, const OUString& rFormatName )
72 aSupplementMap.insert( std::make_pair( nFormat, rFormatName ) );
75 SotClipboardFormatId SvPasteObjectDialog::GetFormat( const TransferableDataHelper& rHelper)
77 //TODO/LATER: why is the Descriptor never used?!
78 TransferableObjectDescriptor aDesc;
79 if (rHelper.HasFormat(SotClipboardFormatId::OBJECTDESCRIPTOR))
81 (void)const_cast<TransferableDataHelper&>(rHelper).GetTransferableObjectDescriptor(
82 SotClipboardFormatId::OBJECTDESCRIPTOR, aDesc);
84 const DataFlavorExVector* pFormats = &rHelper.GetDataFlavorExVector();
86 // create and fill dialog box
87 OUString aSourceName, aTypeName;
88 SotClipboardFormatId nSelFormat = SotClipboardFormatId::NONE;
89 SvGlobalName aEmptyNm;
91 ObjectLB().freeze();
93 for (auto const& format : *pFormats)
95 SotClipboardFormatId nFormat = format.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
104 OUString aName;
105 const OUString* pName = nullptr;
106 if ( itName == aSupplementMap.end() )
108 SvPasteObjectHelper::GetEmbeddedName(rHelper,aName,aSourceName,nFormat);
109 if ( !aName.isEmpty() )
110 pName = &aName;
112 else
114 pName = &(itName->second);
117 if( pName )
119 aName = *pName;
121 if( SotClipboardFormatId::EMBED_SOURCE == nFormat )
123 if( aDesc.maClassName != aEmptyNm )
125 aSourceName = aDesc.maDisplayName;
127 if( aDesc.maClassName == aObjClassName )
128 aName = aObjName;
129 else
130 aName = aTypeName = aDesc.maTypeName;
133 else if( SotClipboardFormatId::LINK_SOURCE == nFormat )
135 continue;
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;
147 continue;
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);
172 ObjectLB().thaw();
173 SelectObject();
175 if( !aSourceName.isEmpty() )
177 if( !aTypeName.isEmpty() )
178 aTypeName += "\n";
180 aTypeName += aSourceName;
181 aTypeName = convertLineEnd(aTypeName, GetSystemLineEnd());
184 m_xFtObjectSource->set_label(aTypeName);
186 if (run() == RET_OK)
188 nSelFormat = static_cast<SotClipboardFormatId>(ObjectLB().get_selected_id().toUInt32());
191 return nSelFormat;
194 void SvPasteObjectDialog::SetObjName( const SvGlobalName & rClass, const OUString & rObjName )
196 aObjClassName = rClass;
197 aObjName = rObjName;
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */