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