1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pastedlg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
37 #include <com/sun/star/embed/Aspects.hpp>
39 #include <pastedlg.hxx>
40 #include <svtools/svmedit.hxx>
41 #include <svtools/insdlg.hxx>
42 #include <vcl/dialog.hxx>
43 #include <vcl/button.hxx>
44 #include <vcl/fixed.hxx>
45 #include <vcl/group.hxx>
46 #include <vcl/lstbox.hxx>
47 #include <vcl/msgbox.hxx>
48 #include "svuidlg.hrc"
49 #include <sot/formats.hxx>
50 #include <sot/stg.hxx>
51 #include <svtools/sores.hxx>
52 #include <vcl/svapp.hxx>
54 #include <svx/dialmgr.hxx>
56 SvPasteObjectDialog::SvPasteObjectDialog( Window
* pParent
)
58 : ModalDialog( pParent
, SVX_RES( MD_PASTE_OBJECT
) ),
59 aFtSource( this, SVX_RES( FT_SOURCE
) ),
60 aFtObjectSource( this, SVX_RES( FT_OBJECT_SOURCE
) ),
61 aRbPaste( this, SVX_RES( RB_PASTE
) ),
62 aRbPasteLink( this, SVX_RES( RB_PASTE_LINK
) ),
63 aLbInsertList( this, SVX_RES( LB_INSERT_LIST
) ),
64 aCbDisplayAsIcon( this, SVX_RES( CB_DISPLAY_AS_ICON
) ),
65 aPbChangeIcon( this, SVX_RES( PB_CHANGE_ICON
) ),
66 aFlChoice( this, SVX_RES( FL_CHOICE
) ),
67 aOKButton1( this, SVX_RES( 1 ) ),
68 aCancelButton1( this, SVX_RES( 1 ) ),
69 aHelpButton1( this, SVX_RES( 1 ) ),
70 aSObject( SVX_RES( S_OBJECT
) )
73 SetHelpId( HID_PASTE_DLG
);
74 SetUniqueId( HID_PASTE_DLG
);
76 Font aFont
= aFtObjectSource
.GetFont();
77 aFont
.SetWeight( WEIGHT_LIGHT
);
78 aFtObjectSource
.SetFont( aFont
);
81 ObjectLB().SetSelectHdl( LINK( this, SvPasteObjectDialog
, SelectHdl
) );
82 ObjectLB().SetDoubleClickHdl( LINK( this, SvPasteObjectDialog
, DoubleClickHdl
) );
86 void SvPasteObjectDialog::SelectObject()
88 if ( aLbInsertList
.GetEntryCount() &&
89 !aRbPaste
.IsVisible() && !aRbPasteLink
.IsVisible() )
91 aLbInsertList
.SelectEntryPos(0);
92 SelectHdl( &aLbInsertList
);
96 IMPL_LINK( SvPasteObjectDialog
, SelectHdl
, ListBox
*, pListBox
)
100 if ( !aOKButton1
.IsEnabled() )
105 IMPL_LINK_INLINE_START( SvPasteObjectDialog
, DoubleClickHdl
, ListBox
*, pListBox
)
112 IMPL_LINK_INLINE_END( SvPasteObjectDialog
, DoubleClickHdl
, ListBox
*, pListBox
)
114 void SvPasteObjectDialog::SetDefault()
117 nAspect
= (USHORT
)::com::sun::star::embed::Aspects::MSOLE_CONTENT
;
120 SvPasteObjectDialog::~SvPasteObjectDialog()
122 void * pStr
= aSupplementTable
.First();
125 delete (String
*)pStr
;
126 pStr
= aSupplementTable
.Next();
130 /*************************************************************************
131 |* SvPasteObjectDialog::Insert()
134 |* Ersterstellung MM 14.06.94
135 |* Letzte Aenderung KA 16.03.2001
136 *************************************************************************/
137 void SvPasteObjectDialog::Insert( SotFormatStringId nFormat
, const String
& rFormatName
)
139 String
* pStr
= new String( rFormatName
);
140 if( !aSupplementTable
.Insert( nFormat
, pStr
) )
144 ULONG
SvPasteObjectDialog::GetFormat( const TransferableDataHelper
& rHelper
,
145 const DataFlavorExVector
* pFormats
,
146 const TransferableObjectDescriptor
* )
148 //TODO/LATER: why is the Descriptor never used?!
149 TransferableObjectDescriptor aDesc
;
150 if( rHelper
.HasFormat( SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
) )
151 ((TransferableDataHelper
&)rHelper
).GetTransferableObjectDescriptor(
152 SOT_FORMATSTR_ID_OBJECTDESCRIPTOR
, aDesc
);
154 pFormats
= &rHelper
.GetDataFlavorExVector();
156 //Dialogbox erzeugen und fuellen
157 String aSourceName
, aTypeName
;
158 ULONG nSelFormat
= 0;
159 SvGlobalName aEmptyNm
;
161 ObjectLB().SetUpdateMode( FALSE
);
163 DataFlavorExVector::iterator
aIter( ((DataFlavorExVector
&)*pFormats
).begin() ),
164 aEnd( ((DataFlavorExVector
&)*pFormats
).end() );
165 while( aIter
!= aEnd
)
167 ::com::sun::star::datatransfer::DataFlavor
aFlavor( *aIter
);
168 SotFormatStringId nFormat
= (*aIter
++).mnSotId
;
170 String
* pName
= (String
*) aSupplementTable
.Get( nFormat
);
176 ( nFormat == SOT_FORMATSTR_ID_EMBED_SOURCE_OLE || nFormat == SOT_FORMATSTR_ID_EMBEDDED_OBJ_OLE ) )
178 BOOL IsClipboardObject_Impl( SotDataObject * );
179 if( IsClipboardObject_Impl( pDataObj ) )
181 IDataObject * pDO = NULL;
182 OleGetClipboard( &pDO );
187 (fe).cfFormat=RegisterClipboardFormat( "Object Descriptor" );
188 (fe).dwAspect=DVASPECT_CONTENT;
190 (fe).tymed=TYMED_HGLOBAL;
193 if (SUCCEEDED(pDO->GetData(&fe, &stm)))
195 LPOBJECTDESCRIPTOR pOD=(LPOBJECTDESCRIPTOR)GlobalLock(stm.hGlobal);
196 if( pOD->dwFullUserTypeName )
198 OLECHAR * pN = (OLECHAR *)(((BYTE *)pOD) + pOD->dwFullUserTypeName);
201 // set format to ole object
202 nFormat = SOT_FORMATSTR_ID_EMBED_SOURCE_OLE;
204 if( pOD->dwSrcOfCopy )
206 OLECHAR * pN = (OLECHAR *)(((BYTE *)pOD) + pOD->dwSrcOfCopy);
207 aSourceName.Append( *pN++ );
210 aSourceName = String( ResId( STR_UNKNOWN_SOURCE, SOAPP->GetResMgr() ) );
211 GlobalUnlock(stm.hGlobal);
212 ReleaseStgMedium(&stm);
220 // if there is an "Embed Source" or and "Embedded Object" on the
221 // Clipboard we read the Description and the Source of this object
222 // from an accompanied "Object Descriptor" format on the clipboard
223 // Remember: these formats mostly appear together on the clipboard
226 SvPasteObjectHelper::GetEmbeddedName(rHelper
,aName
,aSourceName
,nFormat
);
236 if( SOT_FORMATSTR_ID_EMBED_SOURCE
== nFormat
)
238 if( aDesc
.maClassName
!= aEmptyNm
) {
239 aSourceName
= aDesc
.maDisplayName
;
241 if( aDesc
.maClassName
== aObjClassName
)
244 aName
= aTypeName
= aDesc
.maTypeName
;
247 else if( SOT_FORMATSTR_ID_LINK_SOURCE
== nFormat
)
249 PasteLink().Enable();
252 else if( !aName
.Len() )
253 aName
= SvPasteObjectHelper::GetSotFormatUIName( nFormat
);
255 if( LISTBOX_ENTRY_NOTFOUND
== ObjectLB().GetEntryPos( aName
) )
256 ObjectLB().SetEntryData(
257 ObjectLB().InsertEntry( aName
), (void*) nFormat
);
261 if( !aTypeName
.Len() && !aSourceName
.Len() )
263 if( aDesc
.maClassName
!= aEmptyNm
)
265 aSourceName
= aDesc
.maDisplayName
;
266 aTypeName
= aDesc
.maTypeName
;
269 if( !aTypeName
.Len() && !aSourceName
.Len() )
271 com::sun::star::lang::Locale aLocale
= Application::GetSettings().GetUILocale();
272 ResMgr
* pMgr
= ResMgr::CreateResMgr( "svt", aLocale
);
273 // global resource from svtools (former so3 resource)
275 aSourceName
= String( ResId( STR_UNKNOWN_SOURCE
, *pMgr
) );
280 ObjectLB().SetUpdateMode( TRUE
);
283 if( aSourceName
.Len() )
285 if( aTypeName
.Len() )
288 aTypeName
+= aSourceName
;
289 aTypeName
.ConvertLineEnd();
292 ObjectSource().SetText( aTypeName
);
296 if( Dialog::Execute() == RET_OK
)
298 bLink
= PasteLink().IsChecked();
300 if( AsIconBox().IsChecked() )
301 nAspect
= (USHORT
)com::sun::star::embed::Aspects::MSOLE_ICON
;
303 nSelFormat
= (ULONG
)ObjectLB().GetEntryData( ObjectLB().GetSelectEntryPos() );
309 void SvPasteObjectDialog::SetObjName( const SvGlobalName
& rClass
, const String
& rObjName
)
311 aObjClassName
= rClass
;