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