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"
29 #include "drawattr.hxx"
31 #include "drawview.hxx"
33 #include "fuconrec.hxx"
34 #include "fuconpol.hxx"
35 #include "fuconarc.hxx"
36 #include "fuconuno.hxx"
39 #include "fuinsert.hxx"
43 #include "appoptio.hxx"
44 #include <gridwin.hxx>
46 // Create default drawing objects via keyboard
47 #include <svx/svdpagv.hxx>
48 #include <svl/stritem.hxx>
49 #include <svx/svdpage.hxx>
50 #include <fuconcustomshape.hxx>
52 SdrView
* ScTabViewShell::GetDrawView() const
54 return ((ScTabViewShell
*)this)->GetScDrawView(); // GetScDrawView ist nicht-const
57 void ScTabViewShell::WindowChanged()
59 Window
* pWin
= GetActiveWin();
61 ScDrawView
* pDrView
= GetScDrawView();
63 pDrView
->SetActualWin(pWin
);
65 FuPoor
* pFunc
= GetDrawFuncPtr();
67 pFunc
->SetWindow(pWin
);
69 // when font from InputContext is used,
70 // this must be moved to change of cursor position:
74 void ScTabViewShell::ExecDraw(SfxRequest
& rReq
)
76 SC_MOD()->InputEnterHandler();
81 ScTabView
* pTabView
= GetViewData()->GetView();
82 SfxBindings
& rBindings
= GetViewFrame()->GetBindings();
84 Window
* pWin
= pTabView
->GetActiveWin();
85 ScDrawView
* pView
= pTabView
->GetScDrawView();
86 SdrModel
* pDoc
= pView
->GetModel();
88 const SfxItemSet
*pArgs
= rReq
.GetArgs();
89 sal_uInt16 nNewId
= rReq
.GetSlot();
91 if ( nNewId
== SID_DRAW_CHART
)
93 // #i71254# directly insert a chart instead of drawing its output rectangle
94 FuInsertChart(this, pWin
, pView
, pDoc
, rReq
);
99 // Pseudo-Slots von Draw-Toolbox auswerten
100 //! wird das ueberhaupt noch gebraucht ?????
103 if (nNewId
== SID_INSERT_DRAW
&& pArgs
)
105 const SfxPoolItem
* pItem
;
106 if ( pArgs
->GetItemState( SID_INSERT_DRAW
, true, &pItem
) == SFX_ITEM_SET
&&
107 pItem
->ISA( SvxDrawToolItem
) )
109 SvxDrawToolEnum eSel
= (SvxDrawToolEnum
)((const SvxDrawToolItem
*)pItem
)->GetValue();
112 case SVX_SNAP_DRAW_SELECT
: nNewId
= SID_OBJECT_SELECT
; break;
113 case SVX_SNAP_DRAW_LINE
: nNewId
= SID_DRAW_LINE
; break;
114 case SVX_SNAP_DRAW_RECT
: nNewId
= SID_DRAW_RECT
; break;
115 case SVX_SNAP_DRAW_ELLIPSE
: nNewId
= SID_DRAW_ELLIPSE
; break;
116 case SVX_SNAP_DRAW_POLYGON_NOFILL
: nNewId
= SID_DRAW_POLYGON_NOFILL
; break;
117 case SVX_SNAP_DRAW_BEZIER_NOFILL
: nNewId
= SID_DRAW_BEZIER_NOFILL
; break;
118 case SVX_SNAP_DRAW_FREELINE_NOFILL
: nNewId
= SID_DRAW_FREELINE_NOFILL
; break;
119 case SVX_SNAP_DRAW_ARC
: nNewId
= SID_DRAW_ARC
; break;
120 case SVX_SNAP_DRAW_PIE
: nNewId
= SID_DRAW_PIE
; break;
121 case SVX_SNAP_DRAW_CIRCLECUT
: nNewId
= SID_DRAW_CIRCLECUT
; break;
122 case SVX_SNAP_DRAW_TEXT
: nNewId
= SID_DRAW_TEXT
; break;
123 case SVX_SNAP_DRAW_TEXT_VERTICAL
: nNewId
= SID_DRAW_TEXT_VERTICAL
; break;
124 case SVX_SNAP_DRAW_TEXT_MARQUEE
: nNewId
= SID_DRAW_TEXT_MARQUEE
; break;
125 case SVX_SNAP_DRAW_CAPTION
: nNewId
= SID_DRAW_CAPTION
; break;
126 case SVX_SNAP_DRAW_CAPTION_VERTICAL
: nNewId
= SID_DRAW_CAPTION_VERTICAL
; break;
129 else // sal_uInt16-Item vom Controller
136 if ( nNewId
== SID_DRAW_SELECT
)
137 nNewId
= SID_OBJECT_SELECT
;
139 sal_uInt16 nNewFormId
= 0;
140 if ( nNewId
== SID_FM_CREATE_CONTROL
&& pArgs
)
142 const SfxPoolItem
* pItem
;
143 if ( pArgs
->GetItemState( SID_FM_CONTROL_IDENTIFIER
, true, &pItem
) == SFX_ITEM_SET
&&
144 pItem
->ISA( SfxUInt16Item
) )
145 nNewFormId
= ((const SfxUInt16Item
*)pItem
)->GetValue();
148 OUString sStringItemValue
;
151 const SfxPoolItem
* pItem
;
152 if ( pArgs
->GetItemState( nNewId
, true, &pItem
) == SFX_ITEM_SET
&& pItem
->ISA( SfxStringItem
) )
153 sStringItemValue
= static_cast<const SfxStringItem
*>(pItem
)->GetValue();
155 bool bSwitchCustom
= ( !sStringItemValue
.isEmpty() && !sDrawCustom
.isEmpty() && sStringItemValue
!= sDrawCustom
);
157 if (nNewId
== SID_INSERT_FRAME
) // vom Tbx-Button
158 nNewId
= SID_DRAW_TEXT
;
160 // CTRL-SID_OBJECT_SELECT is used to select the first object,
161 // but not if SID_OBJECT_SELECT is the result of clicking a create function again,
162 // so this must be tested before changing nNewId below.
163 bool bSelectFirst
= ( nNewId
== SID_OBJECT_SELECT
&& (rReq
.GetModifier() & KEY_MOD1
) );
165 bool bEx
= IsDrawSelMode();
166 if ( rReq
.GetModifier() & KEY_MOD1
)
168 // always allow keyboard selection also on background layer
169 // also allow creation of default objects if the same object type
170 // was already active
173 else if ( nNewId
== nDrawSfxId
&& ( nNewId
!= SID_FM_CREATE_CONTROL
||
174 nNewFormId
== nFormSfxId
|| nNewFormId
== 0 ) && !bSwitchCustom
)
176 // #i52871# if a different custom shape is selected, the slot id can be the same,
177 // so the custom shape type string has to be compared, too.
179 // SID_FM_CREATE_CONTROL mit nNewFormId==0 (ohne Parameter) kommt beim Deaktivieren
180 // aus FuConstruct::SimpleMouseButtonUp
181 // Execute fuer die Form-Shell, um im Controller zu deselektieren
182 if ( nNewId
== SID_FM_CREATE_CONTROL
)
184 GetViewData()->GetDispatcher().Execute(SID_FM_LEAVE_CREATE
);
185 GetViewFrame()->GetBindings().InvalidateAll(false);
186 //! was fuer einen Slot braucht der komische Controller wirklich, um das anzuzeigen????
190 nNewId
= SID_OBJECT_SELECT
;
195 if ( nDrawSfxId
== SID_FM_CREATE_CONTROL
&& nNewId
!= nDrawSfxId
)
197 // Wechsel von Control- zu Zeichenfunktion -> im Control-Controller deselektieren
198 GetViewData()->GetDispatcher().Execute(SID_FM_LEAVE_CREATE
);
199 GetViewFrame()->GetBindings().InvalidateAll(false);
200 //! was fuer einen Slot braucht der komische Controller wirklich, um das anzuzeigen????
205 pView
->LockBackgroundLayer( !bEx
);
209 // select first draw object if none is selected yet
210 if(!pView
->AreObjectsMarked())
212 // select first object
213 pView
->UnmarkAllObj();
214 pView
->MarkNextObj(true);
216 // ...and make it visible
217 if(pView
->AreObjectsMarked())
218 pView
->MakeVisible(pView
->GetAllMarkedRect(), *pWin
);
223 sDrawCustom
= ""; // value is set below for custom shapes
225 if ( nNewId
!= SID_DRAW_CHART
) // Chart nicht mit DrawShell
227 if ( nNewId
== SID_DRAW_TEXT
|| nNewId
== SID_DRAW_TEXT_VERTICAL
||
228 nNewId
== SID_DRAW_TEXT_MARQUEE
|| nNewId
== SID_DRAW_NOTEEDIT
)
229 SetDrawTextShell( true );
232 if ( bEx
|| pView
->GetMarkedObjectList().GetMarkCount() != 0 )
235 SetDrawShell( false );
239 if (pTabView
->GetDrawFuncPtr())
241 if (pTabView
->GetDrawFuncOldPtr() != pTabView
->GetDrawFuncPtr())
242 delete pTabView
->GetDrawFuncOldPtr();
244 pTabView
->GetDrawFuncPtr()->Deactivate();
245 pTabView
->SetDrawFuncOldPtr(pTabView
->GetDrawFuncPtr());
246 pTabView
->SetDrawFuncPtr(NULL
);
249 SfxRequest
aNewReq(rReq
);
250 aNewReq
.SetSlot(nDrawSfxId
);
252 assert(nNewId
!= SID_DRAW_CHART
); //#i71254# handled already above
256 case SID_OBJECT_SELECT
:
257 // Nicht immer zurueckschalten
258 if(pView
->GetMarkedObjectList().GetMarkCount() == 0) SetDrawShell(bEx
);
259 pTabView
->SetDrawFuncPtr(new FuSelection(this, pWin
, pView
, pDoc
, aNewReq
));
264 case SID_DRAW_ELLIPSE
:
265 pTabView
->SetDrawFuncPtr(new FuConstRectangle(this, pWin
, pView
, pDoc
, aNewReq
));
268 case SID_DRAW_CAPTION
:
269 case SID_DRAW_CAPTION_VERTICAL
:
270 pTabView
->SetDrawFuncPtr(new FuConstRectangle(this, pWin
, pView
, pDoc
, aNewReq
));
271 pView
->SetFrameDragSingles( false );
272 rBindings
.Invalidate( SID_BEZIER_EDIT
);
275 case SID_DRAW_POLYGON
:
276 case SID_DRAW_POLYGON_NOFILL
:
277 case SID_DRAW_BEZIER_NOFILL
:
278 case SID_DRAW_FREELINE_NOFILL
:
279 pTabView
->SetDrawFuncPtr(new FuConstPolygon(this, pWin
, pView
, pDoc
, aNewReq
));
284 case SID_DRAW_CIRCLECUT
:
285 pTabView
->SetDrawFuncPtr(new FuConstArc(this, pWin
, pView
, pDoc
, aNewReq
));
289 case SID_DRAW_TEXT_VERTICAL
:
290 case SID_DRAW_TEXT_MARQUEE
:
291 case SID_DRAW_NOTEEDIT
:
292 pTabView
->SetDrawFuncPtr(new FuText(this, pWin
, pView
, pDoc
, aNewReq
));
295 case SID_FM_CREATE_CONTROL
:
296 SetDrawFormShell(true);
297 pTabView
->SetDrawFuncPtr(new FuConstUnoControl(this, pWin
, pView
, pDoc
, aNewReq
));
298 nFormSfxId
= nNewFormId
;
301 case SID_DRAWTBX_CS_BASIC
:
302 case SID_DRAWTBX_CS_SYMBOL
:
303 case SID_DRAWTBX_CS_ARROW
:
304 case SID_DRAWTBX_CS_FLOWCHART
:
305 case SID_DRAWTBX_CS_CALLOUT
:
306 case SID_DRAWTBX_CS_STAR
:
307 case SID_DRAW_CS_ID
:
309 pTabView
->SetDrawFuncPtr( new FuConstCustomShape( this, pWin
, pView
, pDoc
, aNewReq
));
310 if ( nNewId
!= SID_DRAW_CS_ID
)
312 SFX_REQUEST_ARG( rReq
, pEnumCommand
, SfxStringItem
, nNewId
, false );
315 aCurrShapeEnumCommand
[ nNewId
- SID_DRAWTBX_CS_BASIC
] = pEnumCommand
->GetValue();
316 SfxBindings
& rBind
= GetViewFrame()->GetBindings();
317 rBind
.Invalidate( nNewId
);
318 rBind
.Update( nNewId
);
320 sDrawCustom
= pEnumCommand
->GetValue(); // to detect when a different shape type is selected
330 if (pTabView
->GetDrawFuncPtr())
331 pTabView
->GetDrawFuncPtr()->Activate();
335 rBindings
.Invalidate( SID_INSERT_DRAW
);
336 rBindings
.Update( SID_INSERT_DRAW
);
338 // Create default drawing objects via keyboard
339 // with qualifier construct directly
340 FuPoor
* pFuActual
= GetDrawFuncPtr();
342 if(pFuActual
&& (rReq
.GetModifier() & KEY_MOD1
))
344 // Create default drawing objects via keyboard
345 const ScAppOptions
& rAppOpt
= SC_MOD()->GetAppOptions();
346 sal_uInt32 nDefaultObjectSizeWidth
= rAppOpt
.GetDefaultObjectSizeWidth();
347 sal_uInt32 nDefaultObjectSizeHeight
= rAppOpt
.GetDefaultObjectSizeHeight();
349 // calc position and size
350 Rectangle aVisArea
= pWin
->PixelToLogic(Rectangle(Point(0,0), pWin
->GetOutputSizePixel()));
351 Point aPagePos
= aVisArea
.Center();
352 aPagePos
.X() -= nDefaultObjectSizeWidth
/ 2;
353 aPagePos
.Y() -= nDefaultObjectSizeHeight
/ 2;
354 Rectangle
aNewObjectRectangle(aPagePos
, Size(nDefaultObjectSizeWidth
, nDefaultObjectSizeHeight
));
356 ScDrawView
* pDrView
= GetScDrawView();
360 SdrPageView
* pPageView
= pDrView
->GetSdrPageView();
364 // create the default object
365 SdrObject
* pObj
= pFuActual
->CreateDefaultObject(nNewId
, aNewObjectRectangle
);
370 pView
->InsertObjectAtView(pObj
, *pPageView
);
372 if ( nNewId
== SID_DRAW_CAPTION
|| nNewId
== SID_DRAW_CAPTION_VERTICAL
)
374 // use KeyInput to start edit mode (FuText is created).
375 // For FuText objects, edit mode is handled within CreateDefaultObject.
376 // KEY_F2 is handled in FuDraw::KeyInput.
378 pFuActual
->KeyInput( KeyEvent( 0, KeyCode( KEY_F2
) ) );
386 void ScTabViewShell::GetDrawState(SfxItemSet
&rSet
)
388 SfxWhichIter
aIter(rSet
);
389 sal_uInt16 nWhich
= aIter
.FirstWhich();
395 case SID_INSERT_DRAW
:
397 // SID_OBJECT_SELECT nur, wenn "harter" Selektionsmodus
398 sal_uInt16 nPutId
= nDrawSfxId
;
399 if ( nPutId
== SID_OBJECT_SELECT
&& !IsDrawSelMode() )
401 // nur die Images, die auch auf dem Controller liegen
402 if ( nPutId
!= SID_OBJECT_SELECT
&&
403 nPutId
!= SID_DRAW_LINE
&&
404 nPutId
!= SID_DRAW_RECT
&&
405 nPutId
!= SID_DRAW_ELLIPSE
&&
406 nPutId
!= SID_DRAW_POLYGON_NOFILL
&&
407 nPutId
!= SID_DRAW_BEZIER_NOFILL
&&
408 nPutId
!= SID_DRAW_FREELINE_NOFILL
&&
409 nPutId
!= SID_DRAW_ARC
&&
410 nPutId
!= SID_DRAW_PIE
&&
411 nPutId
!= SID_DRAW_CIRCLECUT
&&
412 nPutId
!= SID_DRAW_TEXT
&&
413 nPutId
!= SID_DRAW_TEXT_VERTICAL
&&
414 nPutId
!= SID_DRAW_TEXT_MARQUEE
&&
415 nPutId
!= SID_DRAW_CAPTION
&&
416 nPutId
!= SID_DRAW_CAPTION_VERTICAL
)
418 SfxAllEnumItem
aItem( nWhich
, nPutId
);
419 if ( !SvtLanguageOptions().IsVerticalTextEnabled() )
421 aItem
.DisableValue( SID_DRAW_TEXT_VERTICAL
);
422 aItem
.DisableValue( SID_DRAW_CAPTION_VERTICAL
);
430 bool bOle
= GetViewFrame()->GetFrame().IsInPlace();
431 if ( bOle
|| !SvtModuleOptions().IsChart() )
432 rSet
.DisableItem( nWhich
);
436 case SID_OBJECT_SELECT
: // wichtig fuer den ollen Control-Controller
437 rSet
.Put( SfxBoolItem( nWhich
, nDrawSfxId
== SID_OBJECT_SELECT
&& IsDrawSelMode() ) );
440 nWhich
= aIter
.NextWhich();
444 bool ScTabViewShell::SelectObject( const OUString
& rName
)
446 ScDrawView
* pView
= GetViewData()->GetScDrawView();
450 bool bFound
= pView
->SelectObject( rName
);
451 // DrawShell etc. is handled in MarkListHasChanged
456 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */