1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/svxdlg.hxx>
21 #include <svx/dialogs.hrc>
23 #include "scitems.hxx"
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>
38 #include "drwlayer.hxx"
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>
53 #include "scslots.hxx"
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>
63 TYPEINIT1( ScDrawShell
, SfxShell
);
65 SFX_IMPL_INTERFACE(ScDrawShell
, SfxShell
)
67 void ScDrawShell::InitInterface_Impl()
69 GetStaticInterface()->RegisterObjectBar(SFX_OBJECTBAR_OBJECT
|SFX_VISIBILITY_STANDARD
|SFX_VISIBILITY_SERVER
,
72 GetStaticInterface()->RegisterPopupMenu(ScResId(RID_POPUP_DRAW
));
74 GetStaticInterface()->RegisterChildWindow(SvxFontWorkChildWindow::GetChildWindowId());
77 // abschalten der nicht erwuenschten Acceleratoren:
79 void ScDrawShell::StateDisableItems( SfxItemSet
&rSet
)
81 SfxWhichIter
aIter(rSet
);
82 sal_uInt16 nWhich
= aIter
.FirstWhich();
86 rSet
.DisableItem( nWhich
);
87 nWhich
= aIter
.NextWhich();
91 static void lcl_setModified( SfxObjectShell
* pShell
)
95 com::sun::star::uno::Reference
< com::sun::star::util::XModifiable
> xModif( pShell
->GetModel(), com::sun::star::uno::UNO_QUERY
);
97 xModif
->setModified( sal_True
);
101 void ScDrawShell::ExecDrawAttr( SfxRequest
& rReq
)
103 sal_uInt16 nSlot
= rReq
.GetSlot();
104 vcl::Window
* pWin
= pViewData
->GetActiveWin();
105 ScDrawView
* pView
= pViewData
->GetScDrawView();
106 SdrModel
* pDoc
= pViewData
->GetDocument()->GetDrawLayer();
108 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
109 const size_t nMarkCount
= rMarkList
.GetMarkCount();
110 SdrObject
* pSingleSelectedObj
= NULL
;
111 if ( nMarkCount
> 0 )
112 pSingleSelectedObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
116 case SID_ASSIGNMACRO
:
118 if ( pSingleSelectedObj
)
119 ExecuteMacroAssign( pSingleSelectedObj
, pWin
);
123 case SID_TEXT_STANDARD
: // Harte Textattributierung loeschen
125 SfxItemSet
aEmptyAttr(GetPool(), EE_ITEMS_START
, EE_ITEMS_END
);
126 pView
->SetAttributes(aEmptyAttr
, true);
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
:
149 case SID_ATTR_FILL_SHADOW
:
151 // Wenn ToolBar vertikal :
152 if ( !rReq
.GetArgs() )
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 ExecuteLineDlg( rReq
);
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
:
175 case SID_ATTR_FILL_SHADOW
:
177 ExecuteAreaDlg( rReq
);
188 if( pView
->AreObjectsMarked() )
189 pView
->SetAttrToMarked( *rReq
.GetArgs(), false );
191 pView
->SetDefaultAttr( *rReq
.GetArgs(), false);
192 pView
->InvalidateAttribs();
196 case SID_ATTRIBUTES_LINE
:
197 ExecuteLineDlg( rReq
);
200 case SID_ATTRIBUTES_AREA
:
201 ExecuteAreaDlg( rReq
);
204 case SID_DRAWTEXT_ATTR_DLG
:
205 ExecuteTextAttrDlg( rReq
);
208 case SID_DRAW_HLINK_EDIT
:
209 if ( pSingleSelectedObj
)
210 pViewData
->GetDispatcher().Execute( SID_HYPERLINK_DIALOG
);
213 case SID_DRAW_HLINK_DELETE
:
214 if ( pSingleSelectedObj
)
215 SetHlinkForObject( pSingleSelectedObj
, OUString() );
218 case SID_OPEN_HYPERLINK
:
219 if ( nMarkCount
== 1 )
221 SdrObject
* pObj
= rMarkList
.GetMark( 0 )->GetMarkedSdrObj();
222 if ( pObj
->IsGroupObject() )
224 SdrPageView
* pPV
= 0;
226 if ( pView
->PickObj( pWin
->PixelToLogic( pViewData
->GetMousePosPixel() ), pView
->getHitTolLog(), pHit
, pPV
, SdrSearchOptions::DEEP
) )
230 ScMacroInfo
* pInfo
= ScDrawLayer::GetMacroInfo( pObj
);
231 if ( pInfo
&& !pInfo
->GetHlink().isEmpty() )
232 ScGlobal::OpenURL( pInfo
->GetHlink(), OUString() );
236 case SID_ATTR_TRANSFORM
:
239 if ( pView
->AreObjectsMarked() )
241 const SfxItemSet
* pArgs
= rReq
.GetArgs();
245 if( rMarkList
.GetMark(0) != 0 )
247 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
248 if( pObj
->GetObjIdentifier() == OBJ_CAPTION
)
250 // --------- Itemset fuer Caption --------
251 SfxItemSet
aNewAttr(pDoc
->GetItemPool());
252 pView
->GetAttributes(aNewAttr
);
253 // --------- Itemset fuer Groesse und Position --------
254 SfxItemSet
aNewGeoAttr(pView
->GetGeoAttrFromMarked());
256 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
259 boost::scoped_ptr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateCaptionDialog( pWin
, pView
));
261 const sal_uInt16
* pRange
= pDlg
->GetInputRanges( *aNewAttr
.GetPool() );
262 SfxItemSet
aCombSet( *aNewAttr
.GetPool(), pRange
);
263 aCombSet
.Put( aNewAttr
);
264 aCombSet
.Put( aNewGeoAttr
);
265 pDlg
->SetInputSet( &aCombSet
);
267 if (pDlg
->Execute() == RET_OK
)
269 rReq
.Done(*(pDlg
->GetOutputItemSet()));
270 pView
->SetAttributes(*pDlg
->GetOutputItemSet());
271 pView
->SetGeoAttrToMarked(*pDlg
->GetOutputItemSet());
277 SfxItemSet
aNewAttr(pView
->GetGeoAttrFromMarked());
278 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
281 boost::scoped_ptr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateSvxTransformTabDialog( pWin
, &aNewAttr
,pView
));
282 OSL_ENSURE(pDlg
, "Dialog creation failed!");
283 if (pDlg
->Execute() == RET_OK
)
285 rReq
.Done(*(pDlg
->GetOutputItemSet()));
286 pView
->SetGeoAttrToMarked(*pDlg
->GetOutputItemSet());
294 pView
->SetGeoAttrToMarked( *pArgs
);
298 ScTabViewShell
* pViewShell
= pViewData
->GetViewShell();
299 SfxBindings
& rBindings
=pViewShell
->GetViewFrame()->GetBindings();
300 rBindings
.Invalidate(SID_ATTR_TRANSFORM_WIDTH
);
301 rBindings
.Invalidate(SID_ATTR_TRANSFORM_HEIGHT
);
302 rBindings
.Invalidate(SID_ATTR_TRANSFORM_POS_X
);
303 rBindings
.Invalidate(SID_ATTR_TRANSFORM_POS_Y
);
304 rBindings
.Invalidate(SID_ATTR_TRANSFORM_ANGLE
);
305 rBindings
.Invalidate(SID_ATTR_TRANSFORM_ROT_X
);
306 rBindings
.Invalidate(SID_ATTR_TRANSFORM_ROT_Y
);
307 rBindings
.Invalidate(SID_ATTR_TRANSFORM_AUTOWIDTH
);
308 rBindings
.Invalidate(SID_ATTR_TRANSFORM_AUTOHEIGHT
);
317 void ScDrawShell::ExecuteMacroAssign( SdrObject
* pObj
, vcl::Window
* pWin
)
319 SvxMacroItem
aItem ( SfxGetpApp()->GetPool().GetWhich( SID_ATTR_MACROITEM
) );
320 ScMacroInfo
* pInfo
= ScDrawLayer::GetMacroInfo( pObj
, true );
321 if ( !pInfo
->GetMacro().isEmpty() )
323 SvxMacroTableDtor aTab
;
324 OUString sMacro
= pInfo
->GetMacro();
325 aTab
.Insert(SFX_EVENT_MOUSECLICK_OBJECT
, SvxMacro(sMacro
, OUString()));
326 aItem
.SetMacroTable( aTab
);
329 // create empty itemset for macro-dlg
330 boost::scoped_ptr
<SfxItemSet
> pItemSet(new SfxItemSet(SfxGetpApp()->GetPool(), SID_ATTR_MACROITEM
, SID_ATTR_MACROITEM
, SID_EVENTCONFIG
, SID_EVENTCONFIG
, 0 ));
331 pItemSet
->Put ( aItem
, SID_ATTR_MACROITEM
);
333 SfxEventNamesItem
aNamesItem(SID_EVENTCONFIG
);
334 aNamesItem
.AddEvent( ScResId(RID_SCSTR_ONCLICK
), OUString(), SFX_EVENT_MOUSECLICK_OBJECT
);
335 pItemSet
->Put( aNamesItem
, SID_EVENTCONFIG
);
337 com::sun::star::uno::Reference
< com::sun::star::frame::XFrame
> xFrame
;
339 xFrame
= GetViewShell()->GetViewFrame()->GetFrame().GetFrameInterface();
341 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
342 boost::scoped_ptr
<SfxAbstractDialog
> pMacroDlg(pFact
->CreateSfxDialog( pWin
, *pItemSet
, xFrame
, SID_EVENTCONFIG
));
343 if ( pMacroDlg
&& pMacroDlg
->Execute() == RET_OK
)
345 const SfxItemSet
* pOutSet
= pMacroDlg
->GetOutputItemSet();
346 const SfxPoolItem
* pItem
;
347 if( SfxItemState::SET
== pOutSet
->GetItemState( SID_ATTR_MACROITEM
, false, &pItem
))
350 const SvxMacro
* pMacro
= static_cast<const SvxMacroItem
*>(pItem
)->GetMacroTable().Get( SFX_EVENT_MOUSECLICK_OBJECT
);
352 sMacro
= pMacro
->GetMacName();
354 if ( pObj
->IsGroupObject() )
356 SdrObjList
* pOL
= pObj
->GetSubList();
357 const size_t nObj
= pOL
->GetObjCount();
358 for ( size_t index
=0; index
<nObj
; ++index
)
360 pInfo
= ScDrawLayer::GetMacroInfo( pOL
->GetObj(index
), true );
361 pInfo
->SetMacro( sMacro
);
365 pInfo
->SetMacro( sMacro
);
366 lcl_setModified( GetObjectShell() );
371 void ScDrawShell::ExecuteLineDlg( SfxRequest
& rReq
, sal_uInt16 nTabPage
)
373 ScDrawView
* pView
= pViewData
->GetScDrawView();
374 bool bHasMarked
= pView
->AreObjectsMarked();
375 const SdrObject
* pObj
= NULL
;
376 const SdrMarkList
& rMarkList
= pView
->GetMarkedObjectList();
378 if( rMarkList
.GetMarkCount() == 1 )
379 pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
381 SfxItemSet
aNewAttr( pView
->GetDefaultAttr() );
383 pView
->MergeAttrFromMarked( aNewAttr
, false );
385 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
386 OSL_ENSURE(pFact
, "Dialog creation failed!");
387 boost::scoped_ptr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateSvxLineTabDialog( pViewData
->GetDialogParent(),
389 pViewData
->GetDocument()->GetDrawLayer(),
392 OSL_ENSURE(pDlg
, "Dialog creation failed!");
393 if ( nTabPage
!= 0xffff )
394 pDlg
->SetCurPageId( nTabPage
);
396 if ( pDlg
->Execute() == RET_OK
)
399 pView
->SetAttrToMarked( *pDlg
->GetOutputItemSet(), false );
401 pView
->SetDefaultAttr( *pDlg
->GetOutputItemSet(), false );
403 pView
->InvalidateAttribs();
408 void ScDrawShell::ExecuteAreaDlg( SfxRequest
& rReq
, sal_uInt16 nTabPage
)
410 ScDrawView
* pView
= pViewData
->GetScDrawView();
411 bool bHasMarked
= pView
->AreObjectsMarked();
413 SfxItemSet
aNewAttr( pView
->GetDefaultAttr() );
415 pView
->MergeAttrFromMarked( aNewAttr
, false );
417 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
418 boost::scoped_ptr
<AbstractSvxAreaTabDialog
> pDlg(pFact
->CreateSvxAreaTabDialog(
419 pViewData
->GetDialogParent(), &aNewAttr
,
420 pViewData
->GetDocument()->GetDrawLayer(), true));
422 if ( nTabPage
!= 0xffff )
423 pDlg
->SetCurPageId( nTabPage
);
425 if ( pDlg
->Execute() == RET_OK
)
428 pView
->SetAttrToMarked( *pDlg
->GetOutputItemSet(), false );
430 pView
->SetDefaultAttr( *pDlg
->GetOutputItemSet(), false );
432 pView
->InvalidateAttribs();
437 void ScDrawShell::ExecuteTextAttrDlg( SfxRequest
& rReq
, sal_uInt16
/* nTabPage */ )
439 ScDrawView
* pView
= pViewData
->GetScDrawView();
440 bool bHasMarked
= pView
->AreObjectsMarked();
441 SfxItemSet
aNewAttr ( pView
->GetDefaultAttr() );
444 pView
->MergeAttrFromMarked( aNewAttr
, false );
446 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
447 boost::scoped_ptr
<SfxAbstractTabDialog
> pDlg(pFact
->CreateTextTabDialog( pViewData
->GetDialogParent(), &aNewAttr
, pView
));
449 sal_uInt16 nResult
= pDlg
->Execute();
451 if ( RET_OK
== nResult
)
454 pView
->SetAttributes( *pDlg
->GetOutputItemSet() );
456 pView
->SetDefaultAttr( *pDlg
->GetOutputItemSet(), false );
458 pView
->InvalidateAttribs();
463 void ScDrawShell::SetHlinkForObject( SdrObject
* pObj
, const OUString
& rHlnk
)
467 ScMacroInfo
* pInfo
= ScDrawLayer::GetMacroInfo( pObj
, true );
468 pInfo
->SetHlink( rHlnk
);
469 lcl_setModified( GetObjectShell() );
473 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */