xref: /aoo42x/main/sc/source/ui/drawfunc/drawsh.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 #include <svx/svxdlg.hxx> //CHINA001
32 #include <svx/dialogs.hrc> //CHINA001
33 
34 #include "scitems.hxx"
35 
36 #include <editeng/eeitem.hxx>
37 #include <svx/fontwork.hxx>
38 //#include <svx/labdlg.hxx>	CHINA001
39 #include <svl/srchitem.hxx>
40 #include <svx/tabarea.hxx>
41 #include <svx/tabline.hxx>
42 //CHINA001 #include <svx/transfrm.hxx>
43 #include <sfx2/app.hxx>
44 #include <sfx2/objface.hxx>
45 #include <sfx2/objsh.hxx>
46 #include <sfx2/request.hxx>
47 #include <sfx2/dispatch.hxx>
48 #include <svl/whiter.hxx>
49 #include <vcl/msgbox.hxx>
50 
51 #include "drawsh.hxx"
52 #include "drwlayer.hxx"
53 #include "sc.hrc"
54 #include "viewdata.hxx"
55 #include "document.hxx"
56 #include "docpool.hxx"
57 #include "drawview.hxx"
58 #include "scresid.hxx"
59 #include <svx/svdobj.hxx>
60 //add header of cui CHINA001
61 #include <svx/svxdlg.hxx>
62 #include <svx/dialogs.hrc>
63 #include <svx/drawitem.hxx>
64 #include <svx/xtable.hxx>
65 
66 #define ScDrawShell
67 #include "scslots.hxx"
68 
69 #include "userdat.hxx"
70 #include <sfx2/objsh.hxx>
71 #include <svl/macitem.hxx>
72 #include <sfx2/evntconf.hxx>
73 #include <sfx2/viewsh.hxx>
74 #include <com/sun/star/util/XModifiable.hpp>
75 #include <com/sun/star/frame/XFrame.hpp>
76 
77 //------------------------------------------------------------------
78 
79 TYPEINIT1( ScDrawShell, SfxShell );
80 
81 SFX_IMPL_INTERFACE(ScDrawShell, SfxShell, ScResId(SCSTR_DRAWSHELL) )
82 {
83 	SFX_OBJECTBAR_REGISTRATION( SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
84 								ScResId(RID_DRAW_OBJECTBAR) );
85 	SFX_POPUPMENU_REGISTRATION( ScResId(RID_POPUP_DRAW) );
86 	SFX_CHILDWINDOW_REGISTRATION( SvxFontWorkChildWindow::GetChildWindowId() );
87 }
88 
89 
90 // abschalten der nicht erwuenschten Acceleratoren:
91 
92 void ScDrawShell::StateDisableItems( SfxItemSet &rSet )
93 {
94 	SfxWhichIter aIter(rSet);
95 	sal_uInt16 nWhich = aIter.FirstWhich();
96 
97 	while (nWhich)
98 	{
99 		rSet.DisableItem( nWhich );
100 		nWhich = aIter.NextWhich();
101 	}
102 }
103 
104 void lcl_setModified( SfxObjectShell*  pShell )
105 {
106     if ( pShell )
107     {
108         com::sun::star::uno::Reference< com::sun::star::util::XModifiable > xModif( pShell->GetModel(), com::sun::star::uno::UNO_QUERY );
109         if ( xModif.is() )
110             xModif->setModified( sal_True );
111     }
112 }
113 
114 void ScDrawShell::ExecDrawAttr( SfxRequest& rReq )
115 {
116 	sal_uInt16				nSlot		= rReq.GetSlot();
117 	Window* 			pWin		= pViewData->GetActiveWin();
118 //	SfxViewFrame*		pViewFrame	= SfxViewShell::Current()->GetViewFrame(); //!!! koennte knallen
119 	ScDrawView* 		pView		= pViewData->GetScDrawView();
120 	SdrModel*			pDoc		= pViewData->GetDocument()->GetDrawLayer();
121 
122     const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
123     sal_uLong nMarkCount = rMarkList.GetMarkCount();
124     SdrObject* pSingleSelectedObj = NULL;
125     if ( nMarkCount > 0 )
126         pSingleSelectedObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
127 
128 	switch ( nSlot )
129 	{
130         case SID_ASSIGNMACRO:
131             {
132                 if ( pSingleSelectedObj )
133                     ExecuteMacroAssign( pSingleSelectedObj, pWin );
134             }
135             break;
136 
137 		case SID_TEXT_STANDARD:	// Harte Textattributierung loeschen
138 			{
139 				SfxItemSet aEmptyAttr(GetPool(), EE_ITEMS_START, EE_ITEMS_END);
140 				pView->SetAttributes(aEmptyAttr, sal_True);
141 			}
142 			break;
143 
144 		case SID_ATTR_LINE_STYLE:
145 		case SID_ATTR_LINEEND_STYLE:
146 		case SID_ATTR_LINE_DASH:
147 		case SID_ATTR_LINE_WIDTH:
148 		case SID_ATTR_LINE_COLOR:
149 		case SID_ATTR_FILL_STYLE:
150 		case SID_ATTR_FILL_COLOR:
151 		case SID_ATTR_FILL_GRADIENT:
152 		case SID_ATTR_FILL_HATCH:
153 		case SID_ATTR_FILL_BITMAP:
154 
155 		// #i25616#
156 		case SID_ATTR_FILL_SHADOW:
157 			{
158 				// Wenn ToolBar vertikal :
159 				if ( !rReq.GetArgs() )
160 				{
161 					switch ( nSlot )
162 					{
163 						case SID_ATTR_LINE_STYLE:
164 						case SID_ATTR_LINE_DASH:
165 						case SID_ATTR_LINE_WIDTH:
166 						case SID_ATTR_LINE_COLOR:
167 							ExecuteLineDlg( rReq );
168 							break;
169 
170 						case SID_ATTR_FILL_STYLE:
171 						case SID_ATTR_FILL_COLOR:
172 						case SID_ATTR_FILL_GRADIENT:
173 						case SID_ATTR_FILL_HATCH:
174 						case SID_ATTR_FILL_BITMAP:
175 
176 						// #i25616#
177 						case SID_ATTR_FILL_SHADOW:
178 
179 							ExecuteAreaDlg( rReq );
180 							break;
181 
182 						default:
183 							break;
184 					}
185 
186 					//=====
187 					return;
188 					//=====
189 				}
190 
191 				if( pView->AreObjectsMarked() )
192 					pView->SetAttrToMarked( *rReq.GetArgs(), sal_False );
193 				else
194 					pView->SetDefaultAttr( *rReq.GetArgs(), sal_False);
195 				pView->InvalidateAttribs();
196 			}
197 			break;
198 
199 		case SID_ATTRIBUTES_LINE:
200 			ExecuteLineDlg( rReq );
201 			break;
202 
203 		case SID_ATTRIBUTES_AREA:
204 			ExecuteAreaDlg( rReq );
205 			break;
206 
207 		case SID_DRAWTEXT_ATTR_DLG:
208 			ExecuteTextAttrDlg( rReq );
209 			break;
210 
211 #ifdef ISSUE66550_HLINK_FOR_SHAPES
212         case SID_DRAW_HLINK_EDIT:
213             if ( pSingleSelectedObj )
214                 pViewData->GetDispatcher().Execute( SID_HYPERLINK_DIALOG );
215             break;
216 
217         case SID_DRAW_HLINK_DELETE:
218             if ( pSingleSelectedObj )
219                 SetHlinkForObject( pSingleSelectedObj, rtl::OUString() );
220             break;
221 
222         case SID_OPEN_HYPERLINK:
223             if ( nMarkCount == 1 )
224             {
225                 SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
226                 if ( pObj->IsGroupObject() )
227                 {
228                     SdrPageView* pPV = 0;
229                     SdrObject* pHit = 0;
230                     if ( pView->PickObj( pWin->PixelToLogic( pViewData->GetMousePosPixel() ), pView->getHitTolLog(), pHit, pPV, SDRSEARCH_DEEP ) )
231                         pObj = pHit;
232                 }
233 
234                 ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
235                 if ( pInfo && (pInfo->GetHlink().getLength() > 0) )
236                     ScGlobal::OpenURL( pInfo->GetHlink(), String::EmptyString() );
237             }
238             break;
239 #endif
240 
241 		case SID_ATTR_TRANSFORM:
242 			{
243 				if ( pView->AreObjectsMarked() )
244 				{
245 					const SfxItemSet* pArgs = rReq.GetArgs();
246 
247 					if( !pArgs )
248 					{
249                         // const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
250 						if( rMarkList.GetMark(0) != 0 )
251 						{
252 							SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
253 							if( pObj->GetObjIdentifier() == OBJ_CAPTION )
254 							{
255 								// --------- Itemset fuer Caption --------
256 								SfxItemSet aNewAttr(pDoc->GetItemPool());
257 								pView->GetAttributes(aNewAttr);
258 								// --------- Itemset fuer Groesse und Position --------
259 								SfxItemSet aNewGeoAttr(pView->GetGeoAttrFromMarked());
260 
261 								//SvxCaptionTabDialog* pDlg = new SvxCaptionTabDialog(pWin, pView);
262 								//change for cui CHINA001
263 								SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
264 								if ( pFact )
265 								{
266 									SfxAbstractTabDialog *pDlg = pFact->CreateCaptionDialog( pWin, pView );
267 
268 									const sal_uInt16* pRange = pDlg->GetInputRanges( *aNewAttr.GetPool() );
269 									SfxItemSet aCombSet( *aNewAttr.GetPool(), pRange );
270 									aCombSet.Put( aNewAttr );
271 									aCombSet.Put( aNewGeoAttr );
272 									pDlg->SetInputSet( &aCombSet );
273 
274 									if (pDlg->Execute() == RET_OK)
275 									{
276 										rReq.Done(*(pDlg->GetOutputItemSet()));
277 										pView->SetAttributes(*pDlg->GetOutputItemSet());
278 										pView->SetGeoAttrToMarked(*pDlg->GetOutputItemSet());
279                                     }
280 
281 									delete pDlg;
282 								}// change for cui
283 							}
284 							else
285 							{
286 								SfxItemSet aNewAttr(pView->GetGeoAttrFromMarked());
287 								//CHINA001 SvxTransformTabDialog* pDlg = new SvxTransformTabDialog(pWin, &aNewAttr, pView);
288 								SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
289 								if(pFact)
290 								{
291 									SfxAbstractTabDialog* pDlg = pFact->CreateSvxTransformTabDialog( pWin, &aNewAttr,pView );
292 									DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
293 									if (pDlg->Execute() == RET_OK)
294 									{
295 										rReq.Done(*(pDlg->GetOutputItemSet()));
296 										pView->SetGeoAttrToMarked(*pDlg->GetOutputItemSet());
297 									}
298 									delete pDlg;
299 								}
300 							}
301 						}
302 
303 
304 					}
305 					else
306 						pView->SetGeoAttrToMarked( *pArgs );
307 				}
308 			}
309 			break;
310 
311 		default:
312 			break;
313 	}
314 }
315 
316 void ScDrawShell::ExecuteMacroAssign( SdrObject* pObj, Window* pWin )
317 {
318     SvxMacroItem aItem ( SFX_APP()->GetPool().GetWhich( SID_ATTR_MACROITEM ) );
319     ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj, sal_True );
320     if ( pInfo->GetMacro().getLength() > 0 )
321     {
322         SvxMacroTableDtor aTab;
323         String sMacro(  pInfo->GetMacro() );
324         aTab.Insert( SFX_EVENT_MOUSECLICK_OBJECT, new SvxMacro( sMacro, String() ) );
325         aItem.SetMacroTable( aTab );
326     }
327 
328 	// create empty itemset for macro-dlg
329     SfxItemSet* pItemSet = new SfxItemSet(SFX_APP()->GetPool(), SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, SID_EVENTCONFIG, SID_EVENTCONFIG, 0 );
330     pItemSet->Put ( aItem, SID_ATTR_MACROITEM );
331 
332 	SfxEventNamesItem aNamesItem(SID_EVENTCONFIG);
333 	aNamesItem.AddEvent( ScResId(RID_SCSTR_ONCLICK), String(), SFX_EVENT_MOUSECLICK_OBJECT );
334 	pItemSet->Put( aNamesItem, SID_EVENTCONFIG );
335 
336 	com::sun::star::uno::Reference < com::sun::star::frame::XFrame > xFrame;
337 	if (GetViewShell())
338 		xFrame = GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
339 
340 	SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
341 	SfxAbstractDialog* pMacroDlg = pFact->CreateSfxDialog( pWin, *pItemSet, xFrame, SID_EVENTCONFIG );
342 	if ( pMacroDlg && pMacroDlg->Execute() == RET_OK )
343     {
344         const SfxItemSet* pOutSet = pMacroDlg->GetOutputItemSet();
345         const SfxPoolItem* pItem;
346         if( SFX_ITEM_SET == pOutSet->GetItemState( SID_ATTR_MACROITEM, sal_False, &pItem ))
347         {
348             rtl::OUString sMacro;
349             SvxMacro* pMacro = ((SvxMacroItem*)pItem)->GetMacroTable().Get( SFX_EVENT_MOUSECLICK_OBJECT );
350             if ( pMacro )
351 				sMacro = pMacro->GetMacName();
352 
353             if ( pObj->IsGroupObject() )
354             {
355                 SdrObjList* pOL = pObj->GetSubList();
356                 sal_uLong nObj = pOL->GetObjCount();
357                 for ( sal_uLong index=0; index<nObj; ++index )
358                 {
359                     pInfo = ScDrawLayer::GetMacroInfo( pOL->GetObj(index), sal_True );
360                     pInfo->SetMacro( sMacro );
361                 }
362             }
363             else
364                 pInfo->SetMacro( sMacro );
365             lcl_setModified( GetObjectShell() );
366         }
367     }
368 
369 	delete pMacroDlg;
370 	delete pItemSet;
371 }
372 
373 void ScDrawShell::ExecuteLineDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
374 {
375 	ScDrawView*			pView		= pViewData->GetScDrawView();
376 	sal_Bool 				bHasMarked	= pView->AreObjectsMarked();
377 	const SdrObject* 	pObj		= NULL;
378 	const SdrMarkList&	rMarkList	= pView->GetMarkedObjectList();
379 
380 	if( rMarkList.GetMarkCount() == 1 )
381 		pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
382 
383 	SfxItemSet	aNewAttr( pView->GetDefaultAttr() );
384 	if( bHasMarked )
385 		pView->MergeAttrFromMarked( aNewAttr, sal_False );
386 
387 //CHINA001	SvxLineTabDialog* pDlg
388 //CHINA001	= new SvxLineTabDialog( pViewData->GetDialogParent(),
389 //CHINA001	&aNewAttr,
390 //CHINA001	pViewData->GetDocument()->GetDrawLayer(),
391 //CHINA001	pObj,
392 //CHINA001	bHasMarked );
393 		SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
394 		DBG_ASSERT(pFact, "Dialogdiet Factory fail!");//CHINA001
395 		SfxAbstractTabDialog * pDlg = pFact->CreateSvxLineTabDialog( pViewData->GetDialogParent(),
396 					&aNewAttr,
397 				pViewData->GetDocument()->GetDrawLayer(),
398 				pObj,
399 				bHasMarked);
400 		DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
401 	if ( nTabPage != 0xffff )
402 		pDlg->SetCurPageId( nTabPage );
403 
404 	if ( pDlg->Execute() == RET_OK )
405 	{
406 		if( bHasMarked )
407 			pView->SetAttrToMarked( *pDlg->GetOutputItemSet(), sal_False );
408 		else
409 			pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), sal_False );
410 
411 		pView->InvalidateAttribs();
412 		rReq.Done();
413 	}
414 
415 	delete pDlg;
416 }
417 
418 void ScDrawShell::ExecuteAreaDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
419 {
420 	ScDrawView*	pView		= pViewData->GetScDrawView();
421 	sal_Bool		bHasMarked	= pView->AreObjectsMarked();
422 
423 	SfxItemSet	aNewAttr( pView->GetDefaultAttr() );
424 	if( bHasMarked )
425 		pView->MergeAttrFromMarked( aNewAttr, sal_False );
426 
427 	//CHINA001 SvxAreaTabDialog* pDlg
428 	//CHINA001 	= new SvxAreaTabDialog( pViewData->GetDialogParent(),
429 //CHINA001 								&aNewAttr,
430 //CHINA001 								pViewData->GetDocument()->GetDrawLayer(),
431 //CHINA001 								pView );
432 
433 	SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
434 	DBG_ASSERT(pFact, "Dialogdiet Factory fail!");//CHINA001
435 	AbstractSvxAreaTabDialog * pDlg = pFact->CreateSvxAreaTabDialog( pViewData->GetDialogParent(),
436 																	&aNewAttr,
437 															pViewData->GetDocument()->GetDrawLayer(),
438 															pView);
439 	DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
440 
441     // #i74099# by default, the dialog deletes the current color table if a different one is loaded
442     // (see SwDrawShell::ExecDrawDlg)
443     const SvxColorTableItem* pColorItem =
444         static_cast<const SvxColorTableItem*>( pViewData->GetSfxDocShell()->GetItem(SID_COLOR_TABLE) );
445     if (pColorItem->GetColorTable() == XColorTable::GetStdColorTable())
446         pDlg->DontDeleteColorTable();
447 
448 	if ( nTabPage != 0xffff )
449 		pDlg->SetCurPageId( nTabPage );
450 
451 	if ( pDlg->Execute() == RET_OK )
452 	{
453 		if( bHasMarked )
454 			pView->SetAttrToMarked( *pDlg->GetOutputItemSet(), sal_False );
455 		else
456 			pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), sal_False );
457 
458 		pView->InvalidateAttribs();
459 		rReq.Done();
460 	}
461 
462 	delete pDlg;
463 }
464 
465 void ScDrawShell::ExecuteTextAttrDlg( SfxRequest& rReq, sal_uInt16 /* nTabPage */ )
466 {
467 	ScDrawView*	pView		= pViewData->GetScDrawView();
468 	sal_Bool		bHasMarked	= pView->AreObjectsMarked();
469 	SfxItemSet	aNewAttr	( pView->GetDefaultAttr() );
470 
471 	if( bHasMarked )
472 		pView->MergeAttrFromMarked( aNewAttr, sal_False );
473 
474 	SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
475 	SfxAbstractTabDialog *pDlg = pFact->CreateTextTabDialog( pViewData->GetDialogParent(), &aNewAttr, pView );
476 
477 	sal_uInt16 nResult = pDlg->Execute();
478 
479 	if ( RET_OK == nResult )
480 	{
481 		if ( bHasMarked )
482 			pView->SetAttributes( *pDlg->GetOutputItemSet() );
483 		else
484 			pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), sal_False );
485 
486 		pView->InvalidateAttribs();
487 		rReq.Done();
488 	}
489 	delete( pDlg );
490 }
491 
492 #ifdef ISSUE66550_HLINK_FOR_SHAPES
493 void ScDrawShell::SetHlinkForObject( SdrObject* pObj, const rtl::OUString& rHlnk )
494 {
495     if ( pObj )
496     {
497         ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj, sal_True );
498         pInfo->SetHlink( rHlnk );
499         lcl_setModified( GetObjectShell() );
500     }
501 }
502 #endif
503 
504