1*2ee96f1cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*2ee96f1cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*2ee96f1cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*2ee96f1cSAndrew Rist * distributed with this work for additional information
6*2ee96f1cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*2ee96f1cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*2ee96f1cSAndrew Rist * "License"); you may not use this file except in compliance
9*2ee96f1cSAndrew Rist * with the License. You may obtain a copy of the License at
10*2ee96f1cSAndrew Rist *
11*2ee96f1cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*2ee96f1cSAndrew Rist *
13*2ee96f1cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*2ee96f1cSAndrew Rist * software distributed under the License is distributed on an
15*2ee96f1cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2ee96f1cSAndrew Rist * KIND, either express or implied. See the License for the
17*2ee96f1cSAndrew Rist * specific language governing permissions and limitations
18*2ee96f1cSAndrew Rist * under the License.
19*2ee96f1cSAndrew Rist *
20*2ee96f1cSAndrew Rist *************************************************************/
21*2ee96f1cSAndrew Rist
22*2ee96f1cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_cui.hxx"
26cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <pastedlg.hxx>
29cdf0e10cSrcweir #include <svtools/svmedit.hxx>
30cdf0e10cSrcweir #include <svtools/insdlg.hxx>
31cdf0e10cSrcweir #include <vcl/dialog.hxx>
32cdf0e10cSrcweir #include <vcl/button.hxx>
33cdf0e10cSrcweir #include <vcl/fixed.hxx>
34cdf0e10cSrcweir #include <vcl/group.hxx>
35cdf0e10cSrcweir #include <vcl/lstbox.hxx>
36cdf0e10cSrcweir #include <vcl/msgbox.hxx>
37cdf0e10cSrcweir #include "svuidlg.hrc"
38cdf0e10cSrcweir #include <sot/formats.hxx>
39cdf0e10cSrcweir #include <sot/stg.hxx>
40cdf0e10cSrcweir #include <svtools/sores.hxx>
41cdf0e10cSrcweir #include <vcl/svapp.hxx>
42cdf0e10cSrcweir
43cdf0e10cSrcweir #include <dialmgr.hxx>
44cdf0e10cSrcweir
SvPasteObjectDialog(Window * pParent)45cdf0e10cSrcweir SvPasteObjectDialog::SvPasteObjectDialog( Window* pParent )
46cdf0e10cSrcweir
47cdf0e10cSrcweir : ModalDialog( pParent, CUI_RES( MD_PASTE_OBJECT ) ),
48cdf0e10cSrcweir aFtSource( this, CUI_RES( FT_SOURCE ) ),
49cdf0e10cSrcweir aFtObjectSource( this, CUI_RES( FT_OBJECT_SOURCE ) ),
50cdf0e10cSrcweir aRbPaste( this, CUI_RES( RB_PASTE ) ),
51cdf0e10cSrcweir aRbPasteLink( this, CUI_RES( RB_PASTE_LINK ) ),
52cdf0e10cSrcweir aCbDisplayAsIcon( this, CUI_RES( CB_DISPLAY_AS_ICON ) ),
53cdf0e10cSrcweir aPbChangeIcon( this, CUI_RES( PB_CHANGE_ICON ) ),
54cdf0e10cSrcweir aFlChoice( this, CUI_RES( FL_CHOICE ) ),
55cdf0e10cSrcweir aLbInsertList( this, CUI_RES( LB_INSERT_LIST ) ),
56cdf0e10cSrcweir aOKButton1( this, CUI_RES( 1 ) ),
57cdf0e10cSrcweir aCancelButton1( this, CUI_RES( 1 ) ),
58cdf0e10cSrcweir aHelpButton1( this, CUI_RES( 1 ) ),
59cdf0e10cSrcweir aSObject( CUI_RES( S_OBJECT ) )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir FreeResource();
62cdf0e10cSrcweir SetHelpId( HID_PASTE_DLG );
63cdf0e10cSrcweir SetUniqueId( HID_PASTE_DLG );
64cdf0e10cSrcweir
65cdf0e10cSrcweir Font aFont = aFtObjectSource.GetFont();
66cdf0e10cSrcweir aFont.SetWeight( WEIGHT_LIGHT );
67cdf0e10cSrcweir aFtObjectSource.SetFont( aFont );
68cdf0e10cSrcweir aOKButton1.Disable();
69cdf0e10cSrcweir
70cdf0e10cSrcweir ObjectLB().SetSelectHdl( LINK( this, SvPasteObjectDialog, SelectHdl ) );
71cdf0e10cSrcweir ObjectLB().SetDoubleClickHdl( LINK( this, SvPasteObjectDialog, DoubleClickHdl ) );
72cdf0e10cSrcweir SetDefault();
73cdf0e10cSrcweir
74cdf0e10cSrcweir aLbInsertList.SetAccessibleName(aFlChoice.GetText());
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
SelectObject()77cdf0e10cSrcweir void SvPasteObjectDialog::SelectObject()
78cdf0e10cSrcweir {
79cdf0e10cSrcweir if ( aLbInsertList.GetEntryCount() &&
80cdf0e10cSrcweir !aRbPaste.IsVisible() && !aRbPasteLink.IsVisible() )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir aLbInsertList.SelectEntryPos(0);
83cdf0e10cSrcweir SelectHdl( &aLbInsertList );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
IMPL_LINK(SvPasteObjectDialog,SelectHdl,ListBox *,pListBox)87cdf0e10cSrcweir IMPL_LINK( SvPasteObjectDialog, SelectHdl, ListBox *, pListBox )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir (void)pListBox;
90cdf0e10cSrcweir
91cdf0e10cSrcweir if ( !aOKButton1.IsEnabled() )
92cdf0e10cSrcweir aOKButton1.Enable();
93cdf0e10cSrcweir return 0;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
IMPL_LINK_INLINE_START(SvPasteObjectDialog,DoubleClickHdl,ListBox *,pListBox)96cdf0e10cSrcweir IMPL_LINK_INLINE_START( SvPasteObjectDialog, DoubleClickHdl, ListBox *, pListBox )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir (void)pListBox;
99cdf0e10cSrcweir
100cdf0e10cSrcweir EndDialog( RET_OK );
101cdf0e10cSrcweir return 0;
102cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(SvPasteObjectDialog,DoubleClickHdl,ListBox *,pListBox)103cdf0e10cSrcweir IMPL_LINK_INLINE_END( SvPasteObjectDialog, DoubleClickHdl, ListBox *, pListBox )
104cdf0e10cSrcweir
105cdf0e10cSrcweir void SvPasteObjectDialog::SetDefault()
106cdf0e10cSrcweir {
107cdf0e10cSrcweir bLink = sal_False;
108cdf0e10cSrcweir nAspect = (sal_uInt16)::com::sun::star::embed::Aspects::MSOLE_CONTENT;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir
~SvPasteObjectDialog()111cdf0e10cSrcweir SvPasteObjectDialog::~SvPasteObjectDialog()
112cdf0e10cSrcweir {
113cdf0e10cSrcweir void * pStr = aSupplementTable.First();
114cdf0e10cSrcweir while( pStr )
115cdf0e10cSrcweir {
116cdf0e10cSrcweir delete (String *)pStr;
117cdf0e10cSrcweir pStr = aSupplementTable.Next();
118cdf0e10cSrcweir }
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
121cdf0e10cSrcweir /*************************************************************************
122cdf0e10cSrcweir |* SvPasteObjectDialog::Insert()
123cdf0e10cSrcweir |*
124cdf0e10cSrcweir |* Beschreibung
125cdf0e10cSrcweir |* Ersterstellung MM 14.06.94
126cdf0e10cSrcweir |* Letzte Aenderung KA 16.03.2001
127cdf0e10cSrcweir *************************************************************************/
Insert(SotFormatStringId nFormat,const String & rFormatName)128cdf0e10cSrcweir void SvPasteObjectDialog::Insert( SotFormatStringId nFormat, const String& rFormatName )
129cdf0e10cSrcweir {
130cdf0e10cSrcweir String * pStr = new String( rFormatName );
131cdf0e10cSrcweir if( !aSupplementTable.Insert( nFormat, pStr ) )
132cdf0e10cSrcweir delete pStr;
133cdf0e10cSrcweir }
134cdf0e10cSrcweir
GetFormat(const TransferableDataHelper & rHelper,const DataFlavorExVector * pFormats,const TransferableObjectDescriptor *)135cdf0e10cSrcweir sal_uLong SvPasteObjectDialog::GetFormat( const TransferableDataHelper& rHelper,
136cdf0e10cSrcweir const DataFlavorExVector* pFormats,
137cdf0e10cSrcweir const TransferableObjectDescriptor* )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir //TODO/LATER: why is the Descriptor never used?!
140cdf0e10cSrcweir TransferableObjectDescriptor aDesc;
141cdf0e10cSrcweir if( rHelper.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR ) )
142cdf0e10cSrcweir ((TransferableDataHelper&)rHelper).GetTransferableObjectDescriptor(
143cdf0e10cSrcweir SOT_FORMATSTR_ID_OBJECTDESCRIPTOR, aDesc );
144cdf0e10cSrcweir if ( !pFormats )
145cdf0e10cSrcweir pFormats = &rHelper.GetDataFlavorExVector();
146cdf0e10cSrcweir
147cdf0e10cSrcweir //Dialogbox erzeugen und fuellen
148cdf0e10cSrcweir String aSourceName, aTypeName;
149cdf0e10cSrcweir sal_uLong nSelFormat = 0;
150cdf0e10cSrcweir SvGlobalName aEmptyNm;
151cdf0e10cSrcweir
152cdf0e10cSrcweir ObjectLB().SetUpdateMode( sal_False );
153cdf0e10cSrcweir
154cdf0e10cSrcweir DataFlavorExVector::iterator aIter( ((DataFlavorExVector&)*pFormats).begin() ),
155cdf0e10cSrcweir aEnd( ((DataFlavorExVector&)*pFormats).end() );
156cdf0e10cSrcweir while( aIter != aEnd )
157cdf0e10cSrcweir {
158cdf0e10cSrcweir ::com::sun::star::datatransfer::DataFlavor aFlavor( *aIter );
159cdf0e10cSrcweir SotFormatStringId nFormat = (*aIter++).mnSotId;
160cdf0e10cSrcweir
161cdf0e10cSrcweir String* pName = (String*) aSupplementTable.Get( nFormat );
162cdf0e10cSrcweir String aName;
163cdf0e10cSrcweir
164cdf0e10cSrcweir #ifdef WNT
165cdf0e10cSrcweir /*
166cdf0e10cSrcweir if( !pName &&
167cdf0e10cSrcweir ( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE_OLE || nFormat == SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ) )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir sal_Bool IsClipboardObject_Impl( SotDataObject * );
170cdf0e10cSrcweir if( IsClipboardObject_Impl( pDataObj ) )
171cdf0e10cSrcweir {
172cdf0e10cSrcweir IDataObject * pDO = NULL;
173cdf0e10cSrcweir OleGetClipboard( &pDO );
174cdf0e10cSrcweir if( pDO )
175cdf0e10cSrcweir {
176cdf0e10cSrcweir FORMATETC fe;
177cdf0e10cSrcweir STGMEDIUM stm;
178cdf0e10cSrcweir (fe).cfFormat=RegisterClipboardFormat( "Object Descriptor" );
179cdf0e10cSrcweir (fe).dwAspect=DVASPECT_CONTENT;
180cdf0e10cSrcweir (fe).ptd=NULL;
181cdf0e10cSrcweir (fe).tymed=TYMED_HGLOBAL;
182cdf0e10cSrcweir (fe).lindex=-1;
183cdf0e10cSrcweir
184cdf0e10cSrcweir if (SUCCEEDED(pDO->GetData(&fe, &stm)))
185cdf0e10cSrcweir {
186cdf0e10cSrcweir LPOBJECTDESCRIPTOR pOD=(LPOBJECTDESCRIPTOR)GlobalLock(stm.hGlobal);
187cdf0e10cSrcweir if( pOD->dwFullUserTypeName )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir OLECHAR * pN = (OLECHAR *)(((sal_uInt8 *)pOD) + pOD->dwFullUserTypeName);
190cdf0e10cSrcweir aName.Append( pN );
191cdf0e10cSrcweir pName = &aName;
192cdf0e10cSrcweir // set format to ole object
193cdf0e10cSrcweir nFormat = SOT_FORMATSTR_ID_EMBED_SOURCE_OLE;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir if( pOD->dwSrcOfCopy )
196cdf0e10cSrcweir {
197cdf0e10cSrcweir OLECHAR * pN = (OLECHAR *)(((sal_uInt8 *)pOD) + pOD->dwSrcOfCopy);
198cdf0e10cSrcweir aSourceName.Append( *pN++ );
199cdf0e10cSrcweir }
200cdf0e10cSrcweir else
201cdf0e10cSrcweir aSourceName = String( ResId( STR_UNKNOWN_SOURCE, SOAPP->GetResMgr() ) );
202cdf0e10cSrcweir GlobalUnlock(stm.hGlobal);
203cdf0e10cSrcweir ReleaseStgMedium(&stm);
204cdf0e10cSrcweir }
205cdf0e10cSrcweir }
206cdf0e10cSrcweir }
207cdf0e10cSrcweir }
208cdf0e10cSrcweir */
209cdf0e10cSrcweir #endif
210cdf0e10cSrcweir
211cdf0e10cSrcweir // if there is an "Embed Source" or and "Embedded Object" on the
212cdf0e10cSrcweir // Clipboard we read the Description and the Source of this object
213cdf0e10cSrcweir // from an accompanied "Object Descriptor" format on the clipboard
214cdf0e10cSrcweir // Remember: these formats mostly appear together on the clipboard
215cdf0e10cSrcweir if ( !pName )
216cdf0e10cSrcweir {
217cdf0e10cSrcweir SvPasteObjectHelper::GetEmbeddedName(rHelper,aName,aSourceName,nFormat);
218cdf0e10cSrcweir if ( aName.Len() )
219cdf0e10cSrcweir pName = &aName;
220cdf0e10cSrcweir }
221cdf0e10cSrcweir
222cdf0e10cSrcweir
223cdf0e10cSrcweir if( pName )
224cdf0e10cSrcweir {
225cdf0e10cSrcweir aName = *pName;
226cdf0e10cSrcweir
227cdf0e10cSrcweir if( SOT_FORMATSTR_ID_EMBED_SOURCE == nFormat )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir if( aDesc.maClassName != aEmptyNm ) {
230cdf0e10cSrcweir aSourceName = aDesc.maDisplayName;
231cdf0e10cSrcweir
232cdf0e10cSrcweir if( aDesc.maClassName == aObjClassName )
233cdf0e10cSrcweir aName = aObjName;
234cdf0e10cSrcweir else
235cdf0e10cSrcweir aName = aTypeName = aDesc.maTypeName;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir }
238cdf0e10cSrcweir else if( SOT_FORMATSTR_ID_LINK_SOURCE == nFormat )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir PasteLink().Enable();
241cdf0e10cSrcweir continue;
242cdf0e10cSrcweir }
243cdf0e10cSrcweir else if( !aName.Len() )
244cdf0e10cSrcweir aName = SvPasteObjectHelper::GetSotFormatUIName( nFormat );
245cdf0e10cSrcweir
246cdf0e10cSrcweir if( LISTBOX_ENTRY_NOTFOUND == ObjectLB().GetEntryPos( aName ) )
247cdf0e10cSrcweir ObjectLB().SetEntryData(
248cdf0e10cSrcweir ObjectLB().InsertEntry( aName ), (void*) nFormat );
249cdf0e10cSrcweir }
250cdf0e10cSrcweir }
251cdf0e10cSrcweir
252cdf0e10cSrcweir if( !aTypeName.Len() && !aSourceName.Len() )
253cdf0e10cSrcweir {
254cdf0e10cSrcweir if( aDesc.maClassName != aEmptyNm )
255cdf0e10cSrcweir {
256cdf0e10cSrcweir aSourceName = aDesc.maDisplayName;
257cdf0e10cSrcweir aTypeName = aDesc.maTypeName;
258cdf0e10cSrcweir }
259cdf0e10cSrcweir
260cdf0e10cSrcweir if( !aTypeName.Len() && !aSourceName.Len() )
261cdf0e10cSrcweir {
262cdf0e10cSrcweir com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
263cdf0e10cSrcweir ResMgr* pMgr = ResMgr::CreateResMgr( "svt", aLocale );
264cdf0e10cSrcweir // global resource from svtools (former so3 resource)
265cdf0e10cSrcweir if( pMgr )
266cdf0e10cSrcweir aSourceName = String( ResId( STR_UNKNOWN_SOURCE, *pMgr ) );
267cdf0e10cSrcweir delete pMgr;
268cdf0e10cSrcweir }
269cdf0e10cSrcweir }
270cdf0e10cSrcweir
271cdf0e10cSrcweir ObjectLB().SetUpdateMode( sal_True );
272cdf0e10cSrcweir SelectObject();
273cdf0e10cSrcweir
274cdf0e10cSrcweir if( aSourceName.Len() )
275cdf0e10cSrcweir {
276cdf0e10cSrcweir if( aTypeName.Len() )
277cdf0e10cSrcweir aTypeName += '\n';
278cdf0e10cSrcweir
279cdf0e10cSrcweir aTypeName += aSourceName;
280cdf0e10cSrcweir aTypeName.ConvertLineEnd();
281cdf0e10cSrcweir }
282cdf0e10cSrcweir
283cdf0e10cSrcweir ObjectSource().SetText( aTypeName );
284cdf0e10cSrcweir
285cdf0e10cSrcweir SetDefault();
286cdf0e10cSrcweir
287cdf0e10cSrcweir if( Dialog::Execute() == RET_OK )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir bLink = PasteLink().IsChecked();
290cdf0e10cSrcweir
291cdf0e10cSrcweir if( AsIconBox().IsChecked() )
292cdf0e10cSrcweir nAspect = (sal_uInt16)com::sun::star::embed::Aspects::MSOLE_ICON;
293cdf0e10cSrcweir
294cdf0e10cSrcweir nSelFormat = (sal_uLong)ObjectLB().GetEntryData( ObjectLB().GetSelectEntryPos() );
295cdf0e10cSrcweir }
296cdf0e10cSrcweir
297cdf0e10cSrcweir return nSelFormat;
298cdf0e10cSrcweir }
299cdf0e10cSrcweir
SetObjName(const SvGlobalName & rClass,const String & rObjName)300cdf0e10cSrcweir void SvPasteObjectDialog::SetObjName( const SvGlobalName & rClass, const String & rObjName )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir aObjClassName = rClass;
303cdf0e10cSrcweir aObjName = rObjName;
304cdf0e10cSrcweir }
305cdf0e10cSrcweir
306