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 .
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>
36 #include <dialmgr.hxx>
38 SvPasteObjectDialog::SvPasteObjectDialog( Window
* pParent
)
39 : ModalDialog(pParent
, "PasteSpecialDialog", "cui/ui/pastespecial.ui")
41 get(m_pFtObjectSource
, "source");
42 get(m_pLbInsertList
, "list");
43 get(m_pOKButton
, "ok");
45 m_pLbInsertList
->SetDropDownLineCount(8);
46 m_pLbInsertList
->set_width_request(m_pLbInsertList
->approximate_char_width() * 32);
47 m_pOKButton
->Disable();
49 ObjectLB().SetSelectHdl( LINK( this, SvPasteObjectDialog
, SelectHdl
) );
50 ObjectLB().SetDoubleClickHdl( LINK( this, SvPasteObjectDialog
, DoubleClickHdl
) );
53 void SvPasteObjectDialog::SelectObject()
55 if (m_pLbInsertList
->GetEntryCount())
57 m_pLbInsertList
->SelectEntryPos(0);
58 SelectHdl(m_pLbInsertList
);
62 IMPL_LINK( SvPasteObjectDialog
, SelectHdl
, ListBox
*, pListBox
)
66 if ( !m_pOKButton
->IsEnabled() )
67 m_pOKButton
->Enable();
71 IMPL_LINK_INLINE_START( SvPasteObjectDialog
, DoubleClickHdl
, ListBox
*, pListBox
)
78 IMPL_LINK_INLINE_END( SvPasteObjectDialog
, DoubleClickHdl
, ListBox
*, pListBox
)
80 SvPasteObjectDialog::~SvPasteObjectDialog()
84 /*************************************************************************
85 |* SvPasteObjectDialog::Insert()
86 *************************************************************************/
87 void SvPasteObjectDialog::Insert( SotFormatStringId nFormat
, const String
& rFormatName
)
89 aSupplementMap
.insert( ::std::make_pair( nFormat
, rFormatName
) );
92 sal_uLong
SvPasteObjectDialog::GetFormat( const TransferableDataHelper
& rHelper
,
93 const DataFlavorExVector
* pFormats
,
94 const TransferableObjectDescriptor
* )
96 //TODO/LATER: why is the Descriptor never used?!
97 TransferableObjectDescriptor aDesc
;
98 if( rHelper
.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
) )
99 ((TransferableDataHelper
&)rHelper
).GetTransferableObjectDescriptor(
100 SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
, aDesc
);
102 pFormats
= &rHelper
.GetDataFlavorExVector();
104 // create and fill dialog box
105 String aSourceName
, aTypeName
;
106 sal_uLong nSelFormat
= 0;
107 SvGlobalName aEmptyNm
;
109 ObjectLB().SetUpdateMode( sal_False
);
111 DataFlavorExVector::iterator
aIter( ((DataFlavorExVector
&)*pFormats
).begin() ),
112 aEnd( ((DataFlavorExVector
&)*pFormats
).end() );
113 while( aIter
!= aEnd
)
115 ::com::sun::star::datatransfer::DataFlavor
aFlavor( *aIter
);
116 SotFormatStringId nFormat
= (*aIter
++).mnSotId
;
118 ::std::map
< SotFormatStringId
, String
>::iterator itName
=
119 aSupplementMap
.find( nFormat
);
121 // if there is an "Embed Source" or and "Embedded Object" on the
122 // Clipboard we read the Description and the Source of this object
123 // from an accompanied "Object Descriptor" format on the clipboard
124 // Remember: these formats mostly appear together on the clipboard
126 const String
* pName
= NULL
;
127 if ( itName
== aSupplementMap
.end() )
129 SvPasteObjectHelper::GetEmbeddedName(rHelper
,aName
,aSourceName
,nFormat
);
135 pName
= &(itName
->second
);
142 if( SOT_FORMATSTR_ID_EMBED_SOURCE
== nFormat
)
144 if( aDesc
.maClassName
!= aEmptyNm
)
146 aSourceName
= aDesc
.maDisplayName
;
148 if( aDesc
.maClassName
== aObjClassName
)
151 aName
= aTypeName
= aDesc
.maTypeName
;
154 else if( SOT_FORMATSTR_ID_LINK_SOURCE
== nFormat
)
158 else if( !aName
.Len() )
159 aName
= SvPasteObjectHelper::GetSotFormatUIName( nFormat
);
161 if( LISTBOX_ENTRY_NOTFOUND
== ObjectLB().GetEntryPos( aName
) )
162 ObjectLB().SetEntryData(
163 ObjectLB().InsertEntry( aName
), (void*) nFormat
);
167 if( !aTypeName
.Len() && !aSourceName
.Len() )
169 if( aDesc
.maClassName
!= aEmptyNm
)
171 aSourceName
= aDesc
.maDisplayName
;
172 aTypeName
= aDesc
.maTypeName
;
175 if( !aTypeName
.Len() && !aSourceName
.Len() )
177 ResMgr
* pMgr
= ResMgr::CreateResMgr( "svt", Application::GetSettings().GetUILanguageTag() );
178 // global resource from svtools (former so3 resource)
180 aSourceName
= String( ResId( STR_UNKNOWN_SOURCE
, *pMgr
) );
185 ObjectLB().SetUpdateMode( sal_True
);
188 if( aSourceName
.Len() )
190 if( aTypeName
.Len() )
193 aTypeName
+= aSourceName
;
194 aTypeName
= convertLineEnd(aTypeName
, GetSystemLineEnd());
197 ObjectSource().SetText( aTypeName
);
199 if( Dialog::Execute() == RET_OK
)
201 nSelFormat
= (sal_uLong
)ObjectLB().GetEntryData( ObjectLB().GetSelectEntryPos() );
207 void SvPasteObjectDialog::SetObjName( const SvGlobalName
& rClass
, const String
& rObjName
)
209 aObjClassName
= rClass
;
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */