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 <sfx2/bindings.hxx>
21 #include <sfx2/viewfrm.hxx>
22 #include <svl/aeitem.hxx>
23 #include <svl/whiter.hxx>
24 #include <unotools/moduleoptions.hxx>
25 #include <svl/languageoptions.hxx>
26 #include <sfx2/dispatch.hxx>
28 #include "tabvwsh.hxx"
30 #include "drawview.hxx"
32 #include "fuconrec.hxx"
33 #include "fuconpol.hxx"
34 #include "fuconarc.hxx"
35 #include "fuconuno.hxx"
38 #include "fuinsert.hxx"
42 #include "appoptio.hxx"
43 #include <gridwin.hxx>
45 // Create default drawing objects via keyboard
46 #include <svx/svdpagv.hxx>
47 #include <svl/stritem.hxx>
48 #include <svx/svdpage.hxx>
49 #include <fuconcustomshape.hxx>
51 SdrView
* ScTabViewShell::GetDrawView() const
53 return const_cast<ScTabViewShell
*>(this)->GetScDrawView(); // GetScDrawView is non-const
56 void ScTabViewShell::WindowChanged()
58 vcl::Window
* pWin
= GetActiveWin();
60 ScDrawView
* pDrView
= GetScDrawView();
62 pDrView
->SetActualWin(pWin
);
64 FuPoor
* pFunc
= GetDrawFuncPtr();
66 pFunc
->SetWindow(pWin
);
68 // when font from InputContext is used,
69 // this must be moved to change of cursor position:
73 void ScTabViewShell::ExecDraw(SfxRequest
& rReq
)
75 SC_MOD()->InputEnterHandler();
80 ScTabView
* pTabView
= GetViewData().GetView();
81 SfxBindings
& rBindings
= GetViewFrame()->GetBindings();
83 vcl::Window
* pWin
= pTabView
->GetActiveWin();
84 ScDrawView
* pView
= pTabView
->GetScDrawView();
85 SdrModel
* pDoc
= pView
->GetModel();
87 const SfxItemSet
*pArgs
= rReq
.GetArgs();
88 sal_uInt16 nNewId
= rReq
.GetSlot();
90 if ( nNewId
== SID_DRAW_CHART
)
92 // #i71254# directly insert a chart instead of drawing its output rectangle
93 FuInsertChart(this, pWin
, pView
, pDoc
, rReq
);
97 if ( nNewId
== SID_DRAW_SELECT
)
98 nNewId
= SID_OBJECT_SELECT
;
100 sal_uInt16 nNewFormId
= 0;
101 if ( nNewId
== SID_FM_CREATE_CONTROL
&& pArgs
)
103 const SfxPoolItem
* pItem
;
104 if ( pArgs
->GetItemState( SID_FM_CONTROL_IDENTIFIER
, true, &pItem
) == SfxItemState::SET
&&
105 dynamic_cast<const SfxUInt16Item
*>( pItem
) != nullptr )
106 nNewFormId
= static_cast<const SfxUInt16Item
*>(pItem
)->GetValue();
109 OUString sStringItemValue
;
112 const SfxPoolItem
* pItem
;
113 if ( pArgs
->GetItemState( nNewId
, true, &pItem
) == SfxItemState::SET
&& dynamic_cast<const SfxStringItem
*>( pItem
) != nullptr )
114 sStringItemValue
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
116 bool bSwitchCustom
= ( !sStringItemValue
.isEmpty() && !sDrawCustom
.isEmpty() && sStringItemValue
!= sDrawCustom
);
118 if (nNewId
== SID_INSERT_FRAME
) // from Tbx button
119 nNewId
= SID_DRAW_TEXT
;
121 // CTRL-SID_OBJECT_SELECT is used to select the first object,
122 // but not if SID_OBJECT_SELECT is the result of clicking a create function again,
123 // so this must be tested before changing nNewId below.
124 bool bSelectFirst
= ( nNewId
== SID_OBJECT_SELECT
&& (rReq
.GetModifier() & KEY_MOD1
) );
126 bool bEx
= IsDrawSelMode();
127 if ( rReq
.GetModifier() & KEY_MOD1
)
129 // always allow keyboard selection also on background layer
130 // also allow creation of default objects if the same object type
131 // was already active
134 else if ( nNewId
== nDrawSfxId
&& ( nNewId
!= SID_FM_CREATE_CONTROL
||
135 nNewFormId
== nFormSfxId
|| nNewFormId
== 0 ) && !bSwitchCustom
)
137 // #i52871# if a different custom shape is selected, the slot id can be the same,
138 // so the custom shape type string has to be compared, too.
140 // SID_FM_CREATE_CONTROL with nNewFormId==0 (without parameter) comes
141 // from FuConstruct::SimpleMouseButtonUp when deactivating
142 // Execute for the form shell, to deselect the controller
143 if ( nNewId
== SID_FM_CREATE_CONTROL
)
145 GetViewData().GetDispatcher().Execute(SID_FM_LEAVE_CREATE
);
146 GetViewFrame()->GetBindings().InvalidateAll(false);
147 //! what kind of slot does the weird controller really need to display this????
151 nNewId
= SID_OBJECT_SELECT
;
156 if ( nDrawSfxId
== SID_FM_CREATE_CONTROL
&& nNewId
!= nDrawSfxId
)
158 // switching from control- to paint function -> deselect in control-controller
159 GetViewData().GetDispatcher().Execute(SID_FM_LEAVE_CREATE
);
160 GetViewFrame()->GetBindings().InvalidateAll(false);
161 //! what kind of slot does the weird controller really need to display this????
166 pView
->LockBackgroundLayer( !bEx
);
170 // select first draw object if none is selected yet
171 if(!pView
->AreObjectsMarked())
173 // select first object
174 pView
->UnmarkAllObj();
175 pView
->MarkNextObj(true);
177 // ...and make it visible
178 if(pView
->AreObjectsMarked())
179 pView
->MakeVisible(pView
->GetAllMarkedRect(), *pWin
);
184 sDrawCustom
.clear(); // value is set below for custom shapes
186 if ( nNewId
!= SID_DRAW_CHART
) // chart not with DrawShell
188 if ( nNewId
== SID_DRAW_TEXT
|| nNewId
== SID_DRAW_TEXT_VERTICAL
||
189 nNewId
== SID_DRAW_TEXT_MARQUEE
|| nNewId
== SID_DRAW_NOTEEDIT
)
190 SetDrawTextShell( true );
193 if ( bEx
|| pView
->GetMarkedObjectList().GetMarkCount() != 0 )
196 SetDrawShell( false );
200 if (pTabView
->GetDrawFuncPtr())
202 if (pTabView
->GetDrawFuncOldPtr() != pTabView
->GetDrawFuncPtr())
203 delete pTabView
->GetDrawFuncOldPtr();
205 pTabView
->GetDrawFuncPtr()->Deactivate();
206 pTabView
->SetDrawFuncOldPtr(pTabView
->GetDrawFuncPtr());
207 pTabView
->SetDrawFuncPtr(nullptr);
210 SfxRequest
aNewReq(rReq
);
211 aNewReq
.SetSlot(nDrawSfxId
);
213 assert(nNewId
!= SID_DRAW_CHART
); //#i71254# handled already above
217 case SID_OBJECT_SELECT
:
218 // Nicht immer zurueckschalten
219 if(pView
->GetMarkedObjectList().GetMarkCount() == 0) SetDrawShell(bEx
);
220 pTabView
->SetDrawFuncPtr(new FuSelection(this, pWin
, pView
, pDoc
, aNewReq
));
225 case SID_DRAW_ELLIPSE
:
226 pTabView
->SetDrawFuncPtr(new FuConstRectangle(this, pWin
, pView
, pDoc
, aNewReq
));
229 case SID_DRAW_CAPTION
:
230 case SID_DRAW_CAPTION_VERTICAL
:
231 pTabView
->SetDrawFuncPtr(new FuConstRectangle(this, pWin
, pView
, pDoc
, aNewReq
));
232 pView
->SetFrameDragSingles( false );
233 rBindings
.Invalidate( SID_BEZIER_EDIT
);
236 case SID_DRAW_XPOLYGON
:
237 case SID_DRAW_XPOLYGON_NOFILL
:
238 case SID_DRAW_POLYGON
:
239 case SID_DRAW_POLYGON_NOFILL
:
240 case SID_DRAW_BEZIER_NOFILL
:
241 case SID_DRAW_BEZIER_FILL
:
242 case SID_DRAW_FREELINE
:
243 case SID_DRAW_FREELINE_NOFILL
:
244 pTabView
->SetDrawFuncPtr(new FuConstPolygon(this, pWin
, pView
, pDoc
, aNewReq
));
249 case SID_DRAW_CIRCLECUT
:
250 pTabView
->SetDrawFuncPtr(new FuConstArc(this, pWin
, pView
, pDoc
, aNewReq
));
254 case SID_DRAW_TEXT_VERTICAL
:
255 case SID_DRAW_TEXT_MARQUEE
:
256 case SID_DRAW_NOTEEDIT
:
257 pTabView
->SetDrawFuncPtr(new FuText(this, pWin
, pView
, pDoc
, aNewReq
));
260 case SID_FM_CREATE_CONTROL
:
261 SetDrawFormShell(true);
262 pTabView
->SetDrawFuncPtr(new FuConstUnoControl(this, pWin
, pView
, pDoc
, aNewReq
));
263 nFormSfxId
= nNewFormId
;
266 case SID_DRAWTBX_CS_BASIC
:
267 case SID_DRAWTBX_CS_SYMBOL
:
268 case SID_DRAWTBX_CS_ARROW
:
269 case SID_DRAWTBX_CS_FLOWCHART
:
270 case SID_DRAWTBX_CS_CALLOUT
:
271 case SID_DRAWTBX_CS_STAR
:
272 case SID_DRAW_CS_ID
:
274 pTabView
->SetDrawFuncPtr( new FuConstCustomShape( this, pWin
, pView
, pDoc
, aNewReq
));
275 if ( nNewId
!= SID_DRAW_CS_ID
)
277 const SfxStringItem
* pEnumCommand
= rReq
.GetArg
<SfxStringItem
>(nNewId
);
280 SfxBindings
& rBind
= GetViewFrame()->GetBindings();
281 rBind
.Invalidate( nNewId
);
282 rBind
.Update( nNewId
);
284 sDrawCustom
= pEnumCommand
->GetValue(); // to detect when a different shape type is selected
294 if (pTabView
->GetDrawFuncPtr())
295 pTabView
->GetDrawFuncPtr()->Activate();
301 // Create default drawing objects via keyboard
302 // with qualifier construct directly
303 FuPoor
* pFuActual
= GetDrawFuncPtr();
305 if(pFuActual
&& (rReq
.GetModifier() & KEY_MOD1
))
307 // Create default drawing objects via keyboard
308 const ScAppOptions
& rAppOpt
= SC_MOD()->GetAppOptions();
309 sal_uInt32 nDefaultObjectSizeWidth
= rAppOpt
.GetDefaultObjectSizeWidth();
310 sal_uInt32 nDefaultObjectSizeHeight
= rAppOpt
.GetDefaultObjectSizeHeight();
312 // calc position and size
313 Rectangle aVisArea
= pWin
->PixelToLogic(Rectangle(Point(0,0), pWin
->GetOutputSizePixel()));
314 Point aPagePos
= aVisArea
.Center();
315 aPagePos
.X() -= nDefaultObjectSizeWidth
/ 2;
316 aPagePos
.Y() -= nDefaultObjectSizeHeight
/ 2;
317 Rectangle
aNewObjectRectangle(aPagePos
, Size(nDefaultObjectSizeWidth
, nDefaultObjectSizeHeight
));
319 ScDrawView
* pDrView
= GetScDrawView();
323 SdrPageView
* pPageView
= pDrView
->GetSdrPageView();
327 // create the default object
328 SdrObject
* pObj
= pFuActual
->CreateDefaultObject(nNewId
, aNewObjectRectangle
);
333 pView
->InsertObjectAtView(pObj
, *pPageView
);
335 if ( nNewId
== SID_DRAW_CAPTION
|| nNewId
== SID_DRAW_CAPTION_VERTICAL
)
337 // use KeyInput to start edit mode (FuText is created).
338 // For FuText objects, edit mode is handled within CreateDefaultObject.
339 // KEY_F2 is handled in FuDraw::KeyInput.
341 pFuActual
->KeyInput( KeyEvent( 0, vcl::KeyCode( KEY_F2
) ) );
349 void ScTabViewShell::GetDrawState(SfxItemSet
&rSet
)
351 SfxWhichIter
aIter(rSet
);
352 sal_uInt16 nWhich
= aIter
.FirstWhich();
360 bool bOle
= GetViewFrame()->GetFrame().IsInPlace();
361 if ( bOle
|| !SvtModuleOptions().IsChart() )
362 rSet
.DisableItem( nWhich
);
368 case SID_DRAW_ELLIPSE
:
369 case SID_DRAW_POLYGON
:
370 case SID_DRAW_POLYGON_NOFILL
:
371 case SID_DRAW_XPOLYGON
:
372 case SID_DRAW_XPOLYGON_NOFILL
:
373 case SID_DRAW_BEZIER_FILL
:
374 case SID_DRAW_BEZIER_NOFILL
:
375 case SID_DRAW_FREELINE
:
376 case SID_DRAW_FREELINE_NOFILL
:
379 case SID_DRAW_CIRCLECUT
:
381 case SID_DRAW_TEXT_MARQUEE
:
382 case SID_DRAW_CAPTION
:
383 rSet
.Put( SfxBoolItem( nWhich
, nDrawSfxId
== nWhich
) );
386 case SID_DRAW_TEXT_VERTICAL
:
387 case SID_DRAW_CAPTION_VERTICAL
:
388 if ( !SvtLanguageOptions().IsVerticalTextEnabled() )
389 rSet
.DisableItem( nWhich
);
391 rSet
.Put( SfxBoolItem( nWhich
, nDrawSfxId
== nWhich
) );
394 case SID_OBJECT_SELECT
: // important for the old control-controller
395 rSet
.Put( SfxBoolItem( nWhich
, nDrawSfxId
== SID_OBJECT_SELECT
&& IsDrawSelMode() ) );
398 case SID_DRAWTBX_CS_BASIC
:
399 case SID_DRAWTBX_CS_SYMBOL
:
400 case SID_DRAWTBX_CS_ARROW
:
401 case SID_DRAWTBX_CS_FLOWCHART
:
402 case SID_DRAWTBX_CS_CALLOUT
:
403 case SID_DRAWTBX_CS_STAR
:
404 rSet
.Put( SfxStringItem( nWhich
, nDrawSfxId
== nWhich
? sDrawCustom
: OUString() ) );
407 nWhich
= aIter
.NextWhich();
411 bool ScTabViewShell::SelectObject( const OUString
& rName
)
413 ScDrawView
* pView
= GetViewData().GetScDrawView();
417 bool bFound
= pView
->SelectObject( rName
);
418 // DrawShell etc. is handled in MarkListHasChanged
423 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */