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 "svuidlg.hrc"
32 : #include <sot/formats.hxx>
33 : #include <sot/stg.hxx>
34 : #include <svtools/sores.hxx>
35 : #include <vcl/svapp.hxx>
36 :
37 : #include <dialmgr.hxx>
38 :
39 0 : SvPasteObjectDialog::SvPasteObjectDialog( Window* pParent )
40 :
41 0 : : ModalDialog( pParent, CUI_RES( MD_PASTE_OBJECT ) ),
42 0 : aFtSource( this, CUI_RES( FT_SOURCE ) ),
43 0 : aFtObjectSource( this, CUI_RES( FT_OBJECT_SOURCE ) ),
44 0 : aRbPaste( this, CUI_RES( RB_PASTE ) ),
45 0 : aRbPasteLink( this, CUI_RES( RB_PASTE_LINK ) ),
46 0 : aCbDisplayAsIcon( this, CUI_RES( CB_DISPLAY_AS_ICON ) ),
47 0 : aPbChangeIcon( this, CUI_RES( PB_CHANGE_ICON ) ),
48 0 : aFlChoice( this, CUI_RES( FL_CHOICE ) ),
49 0 : aLbInsertList( this, CUI_RES( LB_INSERT_LIST ) ),
50 0 : aOKButton1( this, CUI_RES( 1 ) ),
51 0 : aCancelButton1( this, CUI_RES( 1 ) ),
52 0 : aHelpButton1( this, CUI_RES( 1 ) )
53 : {
54 0 : FreeResource();
55 0 : SetHelpId( HID_PASTE_DLG );
56 0 : SetUniqueId( HID_PASTE_DLG );
57 :
58 0 : Font aFont = aFtObjectSource.GetFont();
59 0 : aFont.SetWeight( WEIGHT_LIGHT );
60 0 : aFtObjectSource.SetFont( aFont );
61 0 : aOKButton1.Disable();
62 :
63 0 : ObjectLB().SetSelectHdl( LINK( this, SvPasteObjectDialog, SelectHdl ) );
64 0 : ObjectLB().SetDoubleClickHdl( LINK( this, SvPasteObjectDialog, DoubleClickHdl ) );
65 0 : SetDefault();
66 :
67 0 : aLbInsertList.SetAccessibleName(aFlChoice.GetText());
68 0 : }
69 :
70 0 : void SvPasteObjectDialog::SelectObject()
71 : {
72 0 : if ( aLbInsertList.GetEntryCount() &&
73 0 : !aRbPaste.IsVisible() && !aRbPasteLink.IsVisible() )
74 : {
75 0 : aLbInsertList.SelectEntryPos(0);
76 0 : SelectHdl( &aLbInsertList );
77 : }
78 0 : }
79 :
80 0 : IMPL_LINK( SvPasteObjectDialog, SelectHdl, ListBox *, pListBox )
81 : {
82 : (void)pListBox;
83 :
84 0 : if ( !aOKButton1.IsEnabled() )
85 0 : aOKButton1.Enable();
86 0 : return 0;
87 : }
88 :
89 0 : IMPL_LINK_INLINE_START( SvPasteObjectDialog, DoubleClickHdl, ListBox *, pListBox )
90 : {
91 : (void)pListBox;
92 :
93 0 : EndDialog( RET_OK );
94 0 : return 0;
95 : }
96 0 : IMPL_LINK_INLINE_END( SvPasteObjectDialog, DoubleClickHdl, ListBox *, pListBox )
97 :
98 0 : void SvPasteObjectDialog::SetDefault()
99 : {
100 0 : bLink = sal_False;
101 0 : nAspect = (sal_uInt16)::com::sun::star::embed::Aspects::MSOLE_CONTENT;
102 0 : }
103 :
104 0 : SvPasteObjectDialog::~SvPasteObjectDialog()
105 : {
106 0 : }
107 :
108 : /*************************************************************************
109 : |* SvPasteObjectDialog::Insert()
110 : *************************************************************************/
111 0 : void SvPasteObjectDialog::Insert( SotFormatStringId nFormat, const String& rFormatName )
112 : {
113 0 : aSupplementMap.insert( ::std::make_pair( nFormat, rFormatName ) );
114 0 : }
115 :
116 0 : sal_uLong SvPasteObjectDialog::GetFormat( const TransferableDataHelper& rHelper,
117 : const DataFlavorExVector* pFormats,
118 : const TransferableObjectDescriptor* )
119 : {
120 : //TODO/LATER: why is the Descriptor never used?!
121 0 : TransferableObjectDescriptor aDesc;
122 0 : if( rHelper.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
123 : ((TransferableDataHelper&)rHelper).GetTransferableObjectDescriptor(
124 0 : SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aDesc );
125 0 : if ( !pFormats )
126 0 : pFormats = &rHelper.GetDataFlavorExVector();
127 :
128 : // create and fill dialog box
129 0 : String aSourceName, aTypeName;
130 0 : sal_uLong nSelFormat = 0;
131 0 : SvGlobalName aEmptyNm;
132 :
133 0 : ObjectLB().SetUpdateMode( sal_False );
134 :
135 0 : DataFlavorExVector::iterator aIter( ((DataFlavorExVector&)*pFormats).begin() ),
136 0 : aEnd( ((DataFlavorExVector&)*pFormats).end() );
137 0 : while( aIter != aEnd )
138 : {
139 0 : ::com::sun::star::datatransfer::DataFlavor aFlavor( *aIter );
140 0 : SotFormatStringId nFormat = (*aIter++).mnSotId;
141 :
142 : ::std::map< SotFormatStringId, String >::iterator itName =
143 0 : aSupplementMap.find( nFormat );
144 :
145 : // if there is an "Embed Source" or and "Embedded Object" on the
146 : // Clipboard we read the Description and the Source of this object
147 : // from an accompanied "Object Descriptor" format on the clipboard
148 : // Remember: these formats mostly appear together on the clipboard
149 0 : String aName;
150 0 : const String* pName = NULL;
151 0 : if ( itName == aSupplementMap.end() )
152 : {
153 0 : SvPasteObjectHelper::GetEmbeddedName(rHelper,aName,aSourceName,nFormat);
154 0 : if ( aName.Len() )
155 0 : pName = &aName;
156 : }
157 : else
158 : {
159 0 : pName = &(itName->second);
160 : }
161 :
162 0 : if( pName )
163 : {
164 0 : aName = *pName;
165 :
166 0 : if( SOT_FORMATSTR_ID_EMBED_SOURCE == nFormat )
167 : {
168 0 : if( aDesc.maClassName != aEmptyNm )
169 : {
170 0 : aSourceName = aDesc.maDisplayName;
171 :
172 0 : if( aDesc.maClassName == aObjClassName )
173 0 : aName = aObjName;
174 : else
175 0 : aName = aTypeName = aDesc.maTypeName;
176 : }
177 : }
178 0 : else if( SOT_FORMATSTR_ID_LINK_SOURCE == nFormat )
179 : {
180 0 : PasteLink().Enable();
181 0 : continue;
182 : }
183 0 : else if( !aName.Len() )
184 0 : aName = SvPasteObjectHelper::GetSotFormatUIName( nFormat );
185 :
186 0 : if( LISTBOX_ENTRY_NOTFOUND == ObjectLB().GetEntryPos( aName ) )
187 0 : ObjectLB().SetEntryData(
188 0 : ObjectLB().InsertEntry( aName ), (void*) nFormat );
189 : }
190 0 : }
191 :
192 0 : if( !aTypeName.Len() && !aSourceName.Len() )
193 : {
194 0 : if( aDesc.maClassName != aEmptyNm )
195 : {
196 0 : aSourceName = aDesc.maDisplayName;
197 0 : aTypeName = aDesc.maTypeName;
198 : }
199 :
200 0 : if( !aTypeName.Len() && !aSourceName.Len() )
201 : {
202 0 : com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILanguageTag().getLocale();
203 0 : ResMgr* pMgr = ResMgr::CreateResMgr( "svt", aLocale );
204 : // global resource from svtools (former so3 resource)
205 0 : if( pMgr )
206 0 : aSourceName = String( ResId( STR_UNKNOWN_SOURCE, *pMgr ) );
207 0 : delete pMgr;
208 : }
209 : }
210 :
211 0 : ObjectLB().SetUpdateMode( sal_True );
212 0 : SelectObject();
213 :
214 0 : if( aSourceName.Len() )
215 : {
216 0 : if( aTypeName.Len() )
217 0 : aTypeName += '\n';
218 :
219 0 : aTypeName += aSourceName;
220 0 : aTypeName = convertLineEnd(aTypeName, GetSystemLineEnd());
221 : }
222 :
223 0 : ObjectSource().SetText( aTypeName );
224 :
225 0 : SetDefault();
226 :
227 0 : if( Dialog::Execute() == RET_OK )
228 : {
229 0 : bLink = PasteLink().IsChecked();
230 :
231 0 : if( AsIconBox().IsChecked() )
232 0 : nAspect = (sal_uInt16)com::sun::star::embed::Aspects::MSOLE_ICON;
233 :
234 0 : nSelFormat = (sal_uLong)ObjectLB().GetEntryData( ObjectLB().GetSelectEntryPos() );
235 : }
236 :
237 0 : return nSelFormat;
238 : }
239 :
240 0 : void SvPasteObjectDialog::SetObjName( const SvGlobalName & rClass, const String & rObjName )
241 : {
242 0 : aObjClassName = rClass;
243 0 : aObjName = rObjName;
244 0 : }
245 :
246 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|