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