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