bump product version to 5.0.4.1
[LibreOffice.git] / cui / source / dialogs / pastedlg.cxx
blob4c1d5ab8db197b229d68634f038cf0e75d537fd7
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 <com/sun/star/embed/Aspects.hpp>
22 #include <pastedlg.hxx>
23 #include <svtools/svmedit.hxx>
24 #include <svtools/insdlg.hxx>
25 #include <vcl/dialog.hxx>
26 #include <vcl/button.hxx>
27 #include <vcl/fixed.hxx>
28 #include <vcl/group.hxx>
29 #include <vcl/lstbox.hxx>
30 #include <vcl/msgbox.hxx>
31 #include <sot/formats.hxx>
32 #include <sot/stg.hxx>
33 #include <svtools/sores.hxx>
34 #include <vcl/svapp.hxx>
35 #include <vcl/settings.hxx>
37 #include <dialmgr.hxx>
38 #include <boost/scoped_ptr.hpp>
40 SvPasteObjectDialog::SvPasteObjectDialog( vcl::Window* pParent )
41 : ModalDialog(pParent, "PasteSpecialDialog", "cui/ui/pastespecial.ui")
43 get(m_pFtObjectSource, "source");
44 get(m_pLbInsertList, "list");
45 get(m_pOKButton, "ok");
47 m_pLbInsertList->SetDropDownLineCount(8);
48 m_pLbInsertList->set_width_request(m_pLbInsertList->approximate_char_width() * 32);
49 m_pOKButton->Disable();
51 ObjectLB().SetSelectHdl( LINK( this, SvPasteObjectDialog, SelectHdl ) );
52 ObjectLB().SetDoubleClickHdl( LINK( this, SvPasteObjectDialog, DoubleClickHdl ) );
55 SvPasteObjectDialog::~SvPasteObjectDialog()
57 disposeOnce();
60 void SvPasteObjectDialog::dispose()
62 m_pFtObjectSource.clear();
63 m_pLbInsertList.clear();
64 m_pOKButton.clear();
65 ModalDialog::dispose();
68 void SvPasteObjectDialog::SelectObject()
70 if (m_pLbInsertList->GetEntryCount())
72 m_pLbInsertList->SelectEntryPos(0);
73 SelectHdl(m_pLbInsertList);
77 IMPL_LINK( SvPasteObjectDialog, SelectHdl, ListBox *, pListBox )
79 (void)pListBox;
81 if ( !m_pOKButton->IsEnabled() )
82 m_pOKButton->Enable();
83 return 0;
86 IMPL_LINK( SvPasteObjectDialog, DoubleClickHdl, ListBox *, pListBox )
88 (void)pListBox;
90 EndDialog( RET_OK );
91 return 0;
94 /*************************************************************************
95 |* SvPasteObjectDialog::Insert()
96 *************************************************************************/
97 void SvPasteObjectDialog::Insert( SotClipboardFormatId nFormat, const OUString& rFormatName )
99 aSupplementMap.insert( ::std::make_pair( nFormat, rFormatName ) );
102 SotClipboardFormatId SvPasteObjectDialog::GetFormat( const TransferableDataHelper& rHelper,
103 const DataFlavorExVector* pFormats,
104 const TransferableObjectDescriptor* )
106 //TODO/LATER: why is the Descriptor never used?!
107 TransferableObjectDescriptor aDesc;
108 if (rHelper.HasFormat(SotClipboardFormatId::OBJECTDESCRIPTOR))
110 (void)const_cast<TransferableDataHelper&>(rHelper).GetTransferableObjectDescriptor(
111 SotClipboardFormatId::OBJECTDESCRIPTOR, aDesc);
113 if ( !pFormats )
114 pFormats = &rHelper.GetDataFlavorExVector();
116 // create and fill dialog box
117 OUString aSourceName, aTypeName;
118 SotClipboardFormatId nSelFormat = SotClipboardFormatId::NONE;
119 SvGlobalName aEmptyNm;
121 ObjectLB().SetUpdateMode( false );
123 DataFlavorExVector::iterator aIter( ((DataFlavorExVector&)*pFormats).begin() ),
124 aEnd( ((DataFlavorExVector&)*pFormats).end() );
125 while( aIter != aEnd )
127 ::com::sun::star::datatransfer::DataFlavor aFlavor( *aIter );
128 SotClipboardFormatId nFormat = (*aIter++).mnSotId;
130 ::std::map< SotClipboardFormatId, OUString >::iterator itName =
131 aSupplementMap.find( nFormat );
133 // if there is an "Embed Source" or and "Embedded Object" on the
134 // Clipboard we read the Description and the Source of this object
135 // from an accompanied "Object Descriptor" format on the clipboard
136 // Remember: these formats mostly appear together on the clipboard
137 OUString aName;
138 const OUString* pName = NULL;
139 if ( itName == aSupplementMap.end() )
141 SvPasteObjectHelper::GetEmbeddedName(rHelper,aName,aSourceName,nFormat);
142 if ( !aName.isEmpty() )
143 pName = &aName;
145 else
147 pName = &(itName->second);
150 if( pName )
152 aName = *pName;
154 if( SotClipboardFormatId::EMBED_SOURCE == nFormat )
156 if( aDesc.maClassName != aEmptyNm )
158 aSourceName = aDesc.maDisplayName;
160 if( aDesc.maClassName == aObjClassName )
161 aName = aObjName;
162 else
163 aName = aTypeName = aDesc.maTypeName;
166 else if( SotClipboardFormatId::LINK_SOURCE == nFormat )
168 continue;
170 else if( aName.isEmpty() )
171 aName = SvPasteObjectHelper::GetSotFormatUIName( nFormat );
173 if( LISTBOX_ENTRY_NOTFOUND == ObjectLB().GetEntryPos( aName ) )
174 ObjectLB().SetEntryData(
175 ObjectLB().InsertEntry( aName ), reinterpret_cast<void*>(nFormat) );
179 if( aTypeName.isEmpty() && aSourceName.isEmpty() )
181 if( aDesc.maClassName != aEmptyNm )
183 aSourceName = aDesc.maDisplayName;
184 aTypeName = aDesc.maTypeName;
187 if( aTypeName.isEmpty() && aSourceName.isEmpty() )
189 boost::scoped_ptr<ResMgr> pMgr(ResMgr::CreateResMgr( "svt", Application::GetSettings().GetUILanguageTag() ));
190 // global resource from svtools (former so3 resource)
191 if( pMgr )
192 aSourceName = OUString( ResId( STR_UNKNOWN_SOURCE, *pMgr ) );
196 ObjectLB().SetUpdateMode( true );
197 SelectObject();
199 if( !aSourceName.isEmpty() )
201 if( !aTypeName.isEmpty() )
202 aTypeName += "\n";
204 aTypeName += aSourceName;
205 aTypeName = convertLineEnd(aTypeName, GetSystemLineEnd());
208 ObjectSource().SetText( aTypeName );
210 if( Dialog::Execute() == RET_OK )
212 nSelFormat = static_cast<SotClipboardFormatId>(reinterpret_cast<sal_uLong>(ObjectLB().GetSelectEntryData()));
215 return nSelFormat;
218 void SvPasteObjectDialog::SetObjName( const SvGlobalName & rClass, const OUString & rObjName )
220 aObjClassName = rClass;
221 aObjName = rObjName;
224 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */