Line data Source code
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 <com/sun/star/embed/Aspects.hpp>
21 :
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 :
36 : #include <dialmgr.hxx>
37 :
38 0 : SvPasteObjectDialog::SvPasteObjectDialog( Window* pParent )
39 0 : : ModalDialog(pParent, "PasteSpecialDialog", "cui/ui/pastespecial.ui")
40 : {
41 0 : get(m_pFtObjectSource, "source");
42 0 : get(m_pLbInsertList, "list");
43 0 : get(m_pOKButton, "ok");
44 :
45 0 : m_pLbInsertList->SetDropDownLineCount(8);
46 0 : m_pLbInsertList->set_width_request(m_pLbInsertList->approximate_char_width() * 32);
47 0 : m_pOKButton->Disable();
48 :
49 0 : ObjectLB().SetSelectHdl( LINK( this, SvPasteObjectDialog, SelectHdl ) );
50 0 : ObjectLB().SetDoubleClickHdl( LINK( this, SvPasteObjectDialog, DoubleClickHdl ) );
51 0 : }
52 :
53 0 : void SvPasteObjectDialog::SelectObject()
54 : {
55 0 : if (m_pLbInsertList->GetEntryCount())
56 : {
57 0 : m_pLbInsertList->SelectEntryPos(0);
58 0 : SelectHdl(m_pLbInsertList);
59 : }
60 0 : }
61 :
62 0 : IMPL_LINK( SvPasteObjectDialog, SelectHdl, ListBox *, pListBox )
63 : {
64 : (void)pListBox;
65 :
66 0 : if ( !m_pOKButton->IsEnabled() )
67 0 : m_pOKButton->Enable();
68 0 : return 0;
69 : }
70 :
71 0 : IMPL_LINK_INLINE_START( SvPasteObjectDialog, DoubleClickHdl, ListBox *, pListBox )
72 : {
73 : (void)pListBox;
74 :
75 0 : EndDialog( RET_OK );
76 0 : return 0;
77 : }
78 0 : IMPL_LINK_INLINE_END( SvPasteObjectDialog, DoubleClickHdl, ListBox *, pListBox )
79 :
80 0 : SvPasteObjectDialog::~SvPasteObjectDialog()
81 : {
82 0 : }
83 :
84 : /*************************************************************************
85 : |* SvPasteObjectDialog::Insert()
86 : *************************************************************************/
87 0 : void SvPasteObjectDialog::Insert( SotFormatStringId nFormat, const String& rFormatName )
88 : {
89 0 : aSupplementMap.insert( ::std::make_pair( nFormat, rFormatName ) );
90 0 : }
91 :
92 0 : sal_uLong SvPasteObjectDialog::GetFormat( const TransferableDataHelper& rHelper,
93 : const DataFlavorExVector* pFormats,
94 : const TransferableObjectDescriptor* )
95 : {
96 : //TODO/LATER: why is the Descriptor never used?!
97 0 : TransferableObjectDescriptor aDesc;
98 0 : if( rHelper.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
99 : ((TransferableDataHelper&)rHelper).GetTransferableObjectDescriptor(
100 0 : SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aDesc );
101 0 : if ( !pFormats )
102 0 : pFormats = &rHelper.GetDataFlavorExVector();
103 :
104 : // create and fill dialog box
105 0 : String aSourceName, aTypeName;
106 0 : sal_uLong nSelFormat = 0;
107 0 : SvGlobalName aEmptyNm;
108 :
109 0 : ObjectLB().SetUpdateMode( sal_False );
110 :
111 0 : DataFlavorExVector::iterator aIter( ((DataFlavorExVector&)*pFormats).begin() ),
112 0 : aEnd( ((DataFlavorExVector&)*pFormats).end() );
113 0 : while( aIter != aEnd )
114 : {
115 0 : ::com::sun::star::datatransfer::DataFlavor aFlavor( *aIter );
116 0 : SotFormatStringId nFormat = (*aIter++).mnSotId;
117 :
118 : ::std::map< SotFormatStringId, String >::iterator itName =
119 0 : aSupplementMap.find( nFormat );
120 :
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
125 0 : String aName;
126 0 : const String* pName = NULL;
127 0 : if ( itName == aSupplementMap.end() )
128 : {
129 0 : SvPasteObjectHelper::GetEmbeddedName(rHelper,aName,aSourceName,nFormat);
130 0 : if ( aName.Len() )
131 0 : pName = &aName;
132 : }
133 : else
134 : {
135 0 : pName = &(itName->second);
136 : }
137 :
138 0 : if( pName )
139 : {
140 0 : aName = *pName;
141 :
142 0 : if( SOT_FORMATSTR_ID_EMBED_SOURCE == nFormat )
143 : {
144 0 : if( aDesc.maClassName != aEmptyNm )
145 : {
146 0 : aSourceName = aDesc.maDisplayName;
147 :
148 0 : if( aDesc.maClassName == aObjClassName )
149 0 : aName = aObjName;
150 : else
151 0 : aName = aTypeName = aDesc.maTypeName;
152 : }
153 : }
154 0 : else if( SOT_FORMATSTR_ID_LINK_SOURCE == nFormat )
155 : {
156 0 : continue;
157 : }
158 0 : else if( !aName.Len() )
159 0 : aName = SvPasteObjectHelper::GetSotFormatUIName( nFormat );
160 :
161 0 : if( LISTBOX_ENTRY_NOTFOUND == ObjectLB().GetEntryPos( aName ) )
162 0 : ObjectLB().SetEntryData(
163 0 : ObjectLB().InsertEntry( aName ), (void*) nFormat );
164 : }
165 0 : }
166 :
167 0 : if( !aTypeName.Len() && !aSourceName.Len() )
168 : {
169 0 : if( aDesc.maClassName != aEmptyNm )
170 : {
171 0 : aSourceName = aDesc.maDisplayName;
172 0 : aTypeName = aDesc.maTypeName;
173 : }
174 :
175 0 : if( !aTypeName.Len() && !aSourceName.Len() )
176 : {
177 0 : ResMgr* pMgr = ResMgr::CreateResMgr( "svt", Application::GetSettings().GetUILanguageTag() );
178 : // global resource from svtools (former so3 resource)
179 0 : if( pMgr )
180 0 : aSourceName = String( ResId( STR_UNKNOWN_SOURCE, *pMgr ) );
181 0 : delete pMgr;
182 : }
183 : }
184 :
185 0 : ObjectLB().SetUpdateMode( sal_True );
186 0 : SelectObject();
187 :
188 0 : if( aSourceName.Len() )
189 : {
190 0 : if( aTypeName.Len() )
191 0 : aTypeName += '\n';
192 :
193 0 : aTypeName += aSourceName;
194 0 : aTypeName = convertLineEnd(aTypeName, GetSystemLineEnd());
195 : }
196 :
197 0 : ObjectSource().SetText( aTypeName );
198 :
199 0 : if( Dialog::Execute() == RET_OK )
200 : {
201 0 : nSelFormat = (sal_uLong)ObjectLB().GetEntryData( ObjectLB().GetSelectEntryPos() );
202 : }
203 :
204 0 : return nSelFormat;
205 : }
206 :
207 0 : void SvPasteObjectDialog::SetObjName( const SvGlobalName & rClass, const String & rObjName )
208 : {
209 0 : aObjClassName = rClass;
210 0 : aObjName = rObjName;
211 0 : }
212 :
213 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|