Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <svx/svxdlg.hxx>
21 : #include <svx/dialogs.hrc>
22 :
23 : #include "scitems.hxx"
24 :
25 : #include <editeng/eeitem.hxx>
26 : #include <svx/fontwork.hxx>
27 : #include <svl/srchitem.hxx>
28 : #include <svx/svdpage.hxx>
29 : #include <sfx2/app.hxx>
30 : #include <sfx2/objface.hxx>
31 : #include <sfx2/objsh.hxx>
32 : #include <sfx2/request.hxx>
33 : #include <sfx2/dispatch.hxx>
34 : #include <svl/whiter.hxx>
35 : #include <vcl/msgbox.hxx>
36 :
37 : #include "drawsh.hxx"
38 : #include "drwlayer.hxx"
39 : #include "sc.hrc"
40 : #include "viewdata.hxx"
41 : #include "document.hxx"
42 : #include "docpool.hxx"
43 : #include "drawview.hxx"
44 : #include "scresid.hxx"
45 : #include <svx/svdobj.hxx>
46 : #include <svx/drawitem.hxx>
47 : #include <svx/xtable.hxx>
48 : #include "tabvwsh.hxx"
49 : #include <gridwin.hxx>
50 : #include <sfx2/bindings.hxx>
51 :
52 : #define ScDrawShell
53 : #include "scslots.hxx"
54 :
55 : #include "userdat.hxx"
56 : #include <svl/macitem.hxx>
57 : #include <sfx2/evntconf.hxx>
58 : #include <sfx2/viewsh.hxx>
59 : #include <com/sun/star/util/XModifiable.hpp>
60 : #include <com/sun/star/frame/XFrame.hpp>
61 : #include <boost/scoped_ptr.hpp>
62 :
63 0 : TYPEINIT1( ScDrawShell, SfxShell );
64 :
65 760 : SFX_IMPL_INTERFACE(ScDrawShell, SfxShell, ScResId(SCSTR_DRAWSHELL))
66 :
67 76 : void ScDrawShell::InitInterface_Impl()
68 : {
69 : GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT|SFX_VISIBILITY_STANDARD|SFX_VISIBILITY_SERVER,
70 76 : ScResId(RID_DRAW_OBJECTBAR));
71 :
72 76 : GetStaticInterface()->RegisterPopupMenu(ScResId(RID_POPUP_DRAW));
73 :
74 76 : GetStaticInterface()->RegisterChildWindow(SvxFontWorkChildWindow::GetChildWindowId());
75 76 : }
76 :
77 : // abschalten der nicht erwuenschten Acceleratoren:
78 :
79 0 : void ScDrawShell::StateDisableItems( SfxItemSet &rSet )
80 : {
81 0 : SfxWhichIter aIter(rSet);
82 0 : sal_uInt16 nWhich = aIter.FirstWhich();
83 :
84 0 : while (nWhich)
85 : {
86 0 : rSet.DisableItem( nWhich );
87 0 : nWhich = aIter.NextWhich();
88 0 : }
89 0 : }
90 :
91 0 : static void lcl_setModified( SfxObjectShell* pShell )
92 : {
93 0 : if ( pShell )
94 : {
95 0 : com::sun::star::uno::Reference< com::sun::star::util::XModifiable > xModif( pShell->GetModel(), com::sun::star::uno::UNO_QUERY );
96 0 : if ( xModif.is() )
97 0 : xModif->setModified( sal_True );
98 : }
99 0 : }
100 :
101 0 : void ScDrawShell::ExecDrawAttr( SfxRequest& rReq )
102 : {
103 0 : sal_uInt16 nSlot = rReq.GetSlot();
104 0 : vcl::Window* pWin = pViewData->GetActiveWin();
105 0 : ScDrawView* pView = pViewData->GetScDrawView();
106 0 : SdrModel* pDoc = pViewData->GetDocument()->GetDrawLayer();
107 :
108 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
109 0 : const size_t nMarkCount = rMarkList.GetMarkCount();
110 0 : SdrObject* pSingleSelectedObj = NULL;
111 0 : if ( nMarkCount > 0 )
112 0 : pSingleSelectedObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
113 :
114 0 : switch ( nSlot )
115 : {
116 : case SID_ASSIGNMACRO:
117 : {
118 0 : if ( pSingleSelectedObj )
119 0 : ExecuteMacroAssign( pSingleSelectedObj, pWin );
120 : }
121 0 : break;
122 :
123 : case SID_TEXT_STANDARD: // Harte Textattributierung loeschen
124 : {
125 0 : SfxItemSet aEmptyAttr(GetPool(), EE_ITEMS_START, EE_ITEMS_END);
126 0 : pView->SetAttributes(aEmptyAttr, true);
127 : }
128 0 : break;
129 :
130 : case SID_ATTR_LINE_STYLE:
131 : case SID_ATTR_LINEEND_STYLE:
132 : case SID_ATTR_LINE_START:
133 : case SID_ATTR_LINE_END:
134 : case SID_ATTR_LINE_DASH:
135 : case SID_ATTR_LINE_WIDTH:
136 : case SID_ATTR_LINE_COLOR:
137 : case SID_ATTR_LINE_TRANSPARENCE:
138 : case SID_ATTR_LINE_JOINT:
139 : case SID_ATTR_LINE_CAP:
140 : case SID_ATTR_FILL_STYLE:
141 : case SID_ATTR_FILL_COLOR:
142 : case SID_ATTR_FILL_GRADIENT:
143 : case SID_ATTR_FILL_HATCH:
144 : case SID_ATTR_FILL_BITMAP:
145 : case SID_ATTR_FILL_TRANSPARENCE:
146 : case SID_ATTR_FILL_FLOATTRANSPARENCE:
147 :
148 : // #i25616#
149 : case SID_ATTR_FILL_SHADOW:
150 : {
151 : // Wenn ToolBar vertikal :
152 0 : if ( !rReq.GetArgs() )
153 : {
154 0 : switch ( nSlot )
155 : {
156 : case SID_ATTR_LINE_STYLE:
157 : case SID_ATTR_LINE_DASH:
158 : case SID_ATTR_LINE_WIDTH:
159 : case SID_ATTR_LINE_COLOR:
160 : case SID_ATTR_LINE_TRANSPARENCE:
161 : case SID_ATTR_LINE_JOINT:
162 : case SID_ATTR_LINE_CAP:
163 0 : ExecuteLineDlg( rReq );
164 0 : break;
165 :
166 : case SID_ATTR_FILL_STYLE:
167 : case SID_ATTR_FILL_COLOR:
168 : case SID_ATTR_FILL_GRADIENT:
169 : case SID_ATTR_FILL_HATCH:
170 : case SID_ATTR_FILL_BITMAP:
171 : case SID_ATTR_FILL_TRANSPARENCE:
172 : case SID_ATTR_FILL_FLOATTRANSPARENCE:
173 :
174 : // #i25616#
175 : case SID_ATTR_FILL_SHADOW:
176 :
177 0 : ExecuteAreaDlg( rReq );
178 0 : break;
179 :
180 : default:
181 0 : break;
182 : }
183 :
184 0 : return;
185 :
186 : }
187 :
188 0 : if( pView->AreObjectsMarked() )
189 0 : pView->SetAttrToMarked( *rReq.GetArgs(), false );
190 : else
191 0 : pView->SetDefaultAttr( *rReq.GetArgs(), false);
192 0 : pView->InvalidateAttribs();
193 : }
194 0 : break;
195 :
196 : case SID_ATTRIBUTES_LINE:
197 0 : ExecuteLineDlg( rReq );
198 0 : break;
199 :
200 : case SID_ATTRIBUTES_AREA:
201 0 : ExecuteAreaDlg( rReq );
202 0 : break;
203 :
204 : case SID_DRAWTEXT_ATTR_DLG:
205 0 : ExecuteTextAttrDlg( rReq );
206 0 : break;
207 :
208 : case SID_DRAW_HLINK_EDIT:
209 0 : if ( pSingleSelectedObj )
210 0 : pViewData->GetDispatcher().Execute( SID_HYPERLINK_DIALOG );
211 0 : break;
212 :
213 : case SID_DRAW_HLINK_DELETE:
214 0 : if ( pSingleSelectedObj )
215 0 : SetHlinkForObject( pSingleSelectedObj, OUString() );
216 0 : break;
217 :
218 : case SID_OPEN_HYPERLINK:
219 0 : if ( nMarkCount == 1 )
220 : {
221 0 : SdrObject* pObj = rMarkList.GetMark( 0 )->GetMarkedSdrObj();
222 0 : if ( pObj->IsGroupObject() )
223 : {
224 0 : SdrPageView* pPV = 0;
225 0 : SdrObject* pHit = 0;
226 0 : if ( pView->PickObj( pWin->PixelToLogic( pViewData->GetMousePosPixel() ), pView->getHitTolLog(), pHit, pPV, SDRSEARCH_DEEP ) )
227 0 : pObj = pHit;
228 : }
229 :
230 0 : ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj );
231 0 : if ( pInfo && !pInfo->GetHlink().isEmpty() )
232 0 : ScGlobal::OpenURL( pInfo->GetHlink(), OUString() );
233 : }
234 0 : break;
235 :
236 : case SID_ATTR_TRANSFORM:
237 : {
238 : {
239 0 : if ( pView->AreObjectsMarked() )
240 : {
241 0 : const SfxItemSet* pArgs = rReq.GetArgs();
242 :
243 0 : if( !pArgs )
244 : {
245 0 : if( rMarkList.GetMark(0) != 0 )
246 : {
247 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
248 0 : if( pObj->GetObjIdentifier() == OBJ_CAPTION )
249 : {
250 : // --------- Itemset fuer Caption --------
251 0 : SfxItemSet aNewAttr(pDoc->GetItemPool());
252 0 : pView->GetAttributes(aNewAttr);
253 : // --------- Itemset fuer Groesse und Position --------
254 0 : SfxItemSet aNewGeoAttr(pView->GetGeoAttrFromMarked());
255 :
256 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
257 0 : if ( pFact )
258 : {
259 0 : boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateCaptionDialog( pWin, pView ));
260 :
261 0 : const sal_uInt16* pRange = pDlg->GetInputRanges( *aNewAttr.GetPool() );
262 0 : SfxItemSet aCombSet( *aNewAttr.GetPool(), pRange );
263 0 : aCombSet.Put( aNewAttr );
264 0 : aCombSet.Put( aNewGeoAttr );
265 0 : pDlg->SetInputSet( &aCombSet );
266 :
267 0 : if (pDlg->Execute() == RET_OK)
268 : {
269 0 : rReq.Done(*(pDlg->GetOutputItemSet()));
270 0 : pView->SetAttributes(*pDlg->GetOutputItemSet());
271 0 : pView->SetGeoAttrToMarked(*pDlg->GetOutputItemSet());
272 0 : }
273 0 : }
274 : }
275 : else
276 : {
277 0 : SfxItemSet aNewAttr(pView->GetGeoAttrFromMarked());
278 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
279 0 : if(pFact)
280 : {
281 0 : boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxTransformTabDialog( pWin, &aNewAttr,pView ));
282 : OSL_ENSURE(pDlg, "Dialog creation failed!");
283 0 : if (pDlg->Execute() == RET_OK)
284 : {
285 0 : rReq.Done(*(pDlg->GetOutputItemSet()));
286 0 : pView->SetGeoAttrToMarked(*pDlg->GetOutputItemSet());
287 0 : }
288 0 : }
289 : }
290 : }
291 :
292 : }
293 : else
294 0 : pView->SetGeoAttrToMarked( *pArgs );
295 : }
296 : }
297 :
298 0 : ScTabViewShell* pViewShell = pViewData->GetViewShell();
299 0 : SfxBindings& rBindings=pViewShell->GetViewFrame()->GetBindings();
300 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_WIDTH);
301 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_HEIGHT);
302 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_POS_X);
303 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_POS_Y);
304 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_ANGLE);
305 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_ROT_X);
306 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_ROT_Y);
307 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_AUTOWIDTH);
308 0 : rBindings.Invalidate(SID_ATTR_TRANSFORM_AUTOHEIGHT);
309 0 : break;
310 : }
311 :
312 : default:
313 0 : break;
314 : }
315 : }
316 :
317 0 : void ScDrawShell::ExecuteMacroAssign( SdrObject* pObj, vcl::Window* pWin )
318 : {
319 0 : SvxMacroItem aItem ( SfxGetpApp()->GetPool().GetWhich( SID_ATTR_MACROITEM ) );
320 0 : ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj, true );
321 0 : if ( !pInfo->GetMacro().isEmpty() )
322 : {
323 0 : SvxMacroTableDtor aTab;
324 0 : OUString sMacro = pInfo->GetMacro();
325 0 : aTab.Insert(SFX_EVENT_MOUSECLICK_OBJECT, SvxMacro(sMacro, OUString()));
326 0 : aItem.SetMacroTable( aTab );
327 : }
328 :
329 : // create empty itemset for macro-dlg
330 0 : boost::scoped_ptr<SfxItemSet> pItemSet(new SfxItemSet(SfxGetpApp()->GetPool(), SID_ATTR_MACROITEM, SID_ATTR_MACROITEM, SID_EVENTCONFIG, SID_EVENTCONFIG, 0 ));
331 0 : pItemSet->Put ( aItem, SID_ATTR_MACROITEM );
332 :
333 0 : SfxEventNamesItem aNamesItem(SID_EVENTCONFIG);
334 0 : aNamesItem.AddEvent( ScResId(RID_SCSTR_ONCLICK), OUString(), SFX_EVENT_MOUSECLICK_OBJECT );
335 0 : pItemSet->Put( aNamesItem, SID_EVENTCONFIG );
336 :
337 0 : com::sun::star::uno::Reference < com::sun::star::frame::XFrame > xFrame;
338 0 : if (GetViewShell())
339 0 : xFrame = GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
340 :
341 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
342 0 : boost::scoped_ptr<SfxAbstractDialog> pMacroDlg(pFact->CreateSfxDialog( pWin, *pItemSet, xFrame, SID_EVENTCONFIG ));
343 0 : if ( pMacroDlg && pMacroDlg->Execute() == RET_OK )
344 : {
345 0 : const SfxItemSet* pOutSet = pMacroDlg->GetOutputItemSet();
346 : const SfxPoolItem* pItem;
347 0 : if( SfxItemState::SET == pOutSet->GetItemState( SID_ATTR_MACROITEM, false, &pItem ))
348 : {
349 0 : OUString sMacro;
350 0 : const SvxMacro* pMacro = static_cast<const SvxMacroItem*>(pItem)->GetMacroTable().Get( SFX_EVENT_MOUSECLICK_OBJECT );
351 0 : if ( pMacro )
352 0 : sMacro = pMacro->GetMacName();
353 :
354 0 : if ( pObj->IsGroupObject() )
355 : {
356 0 : SdrObjList* pOL = pObj->GetSubList();
357 0 : const size_t nObj = pOL->GetObjCount();
358 0 : for ( size_t index=0; index<nObj; ++index )
359 : {
360 0 : pInfo = ScDrawLayer::GetMacroInfo( pOL->GetObj(index), true );
361 0 : pInfo->SetMacro( sMacro );
362 : }
363 : }
364 : else
365 0 : pInfo->SetMacro( sMacro );
366 0 : lcl_setModified( GetObjectShell() );
367 : }
368 0 : }
369 0 : }
370 :
371 0 : void ScDrawShell::ExecuteLineDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
372 : {
373 0 : ScDrawView* pView = pViewData->GetScDrawView();
374 0 : bool bHasMarked = pView->AreObjectsMarked();
375 0 : const SdrObject* pObj = NULL;
376 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
377 :
378 0 : if( rMarkList.GetMarkCount() == 1 )
379 0 : pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
380 :
381 0 : SfxItemSet aNewAttr( pView->GetDefaultAttr() );
382 0 : if( bHasMarked )
383 0 : pView->MergeAttrFromMarked( aNewAttr, false );
384 :
385 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
386 : OSL_ENSURE(pFact, "Dialog creation failed!");
387 : boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateSvxLineTabDialog( pViewData->GetDialogParent(),
388 : &aNewAttr,
389 0 : pViewData->GetDocument()->GetDrawLayer(),
390 : pObj,
391 0 : bHasMarked));
392 : OSL_ENSURE(pDlg, "Dialog creation failed!");
393 0 : if ( nTabPage != 0xffff )
394 0 : pDlg->SetCurPageId( nTabPage );
395 :
396 0 : if ( pDlg->Execute() == RET_OK )
397 : {
398 0 : if( bHasMarked )
399 0 : pView->SetAttrToMarked( *pDlg->GetOutputItemSet(), false );
400 : else
401 0 : pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), false );
402 :
403 0 : pView->InvalidateAttribs();
404 0 : rReq.Done();
405 0 : }
406 0 : }
407 :
408 0 : void ScDrawShell::ExecuteAreaDlg( SfxRequest& rReq, sal_uInt16 nTabPage )
409 : {
410 0 : ScDrawView* pView = pViewData->GetScDrawView();
411 0 : bool bHasMarked = pView->AreObjectsMarked();
412 :
413 0 : SfxItemSet aNewAttr( pView->GetDefaultAttr() );
414 0 : if( bHasMarked )
415 0 : pView->MergeAttrFromMarked( aNewAttr, false );
416 :
417 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
418 : boost::scoped_ptr<AbstractSvxAreaTabDialog> pDlg(pFact->CreateSvxAreaTabDialog(
419 : pViewData->GetDialogParent(), &aNewAttr,
420 0 : pViewData->GetDocument()->GetDrawLayer(), true));
421 :
422 0 : if ( nTabPage != 0xffff )
423 0 : pDlg->SetCurPageId( nTabPage );
424 :
425 0 : if ( pDlg->Execute() == RET_OK )
426 : {
427 0 : if( bHasMarked )
428 0 : pView->SetAttrToMarked( *pDlg->GetOutputItemSet(), false );
429 : else
430 0 : pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), false );
431 :
432 0 : pView->InvalidateAttribs();
433 0 : rReq.Done();
434 0 : }
435 0 : }
436 :
437 0 : void ScDrawShell::ExecuteTextAttrDlg( SfxRequest& rReq, sal_uInt16 /* nTabPage */ )
438 : {
439 0 : ScDrawView* pView = pViewData->GetScDrawView();
440 0 : bool bHasMarked = pView->AreObjectsMarked();
441 0 : SfxItemSet aNewAttr ( pView->GetDefaultAttr() );
442 :
443 0 : if( bHasMarked )
444 0 : pView->MergeAttrFromMarked( aNewAttr, false );
445 :
446 0 : SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
447 0 : boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateTextTabDialog( pViewData->GetDialogParent(), &aNewAttr, pView ));
448 :
449 0 : sal_uInt16 nResult = pDlg->Execute();
450 :
451 0 : if ( RET_OK == nResult )
452 : {
453 0 : if ( bHasMarked )
454 0 : pView->SetAttributes( *pDlg->GetOutputItemSet() );
455 : else
456 0 : pView->SetDefaultAttr( *pDlg->GetOutputItemSet(), false );
457 :
458 0 : pView->InvalidateAttribs();
459 0 : rReq.Done();
460 0 : }
461 0 : }
462 :
463 0 : void ScDrawShell::SetHlinkForObject( SdrObject* pObj, const OUString& rHlnk )
464 : {
465 0 : if ( pObj )
466 : {
467 0 : ScMacroInfo* pInfo = ScDrawLayer::GetMacroInfo( pObj, true );
468 0 : pInfo->SetHlink( rHlnk );
469 0 : lcl_setModified( GetObjectShell() );
470 : }
471 228 : }
472 :
473 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|