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