bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / view / tabvwsh2.cxx
blob8d137a8731cfbc2a650b8a5b037b13c108ebc918
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
30 #include "drawsh.hxx"
31 #include "drawview.hxx"
32 #include "fupoor.hxx"
33 #include "fuconrec.hxx"
34 #include "fuconpol.hxx"
35 #include "fuconarc.hxx"
36 #include "fuconuno.hxx"
37 #include "fusel.hxx"
38 #include "futext.hxx"
39 #include "fumark.hxx"
40 #include "fuinsert.hxx"
41 #include "global.hxx"
42 #include "sc.hrc"
43 #include "scmod.hxx"
44 #include "appoptio.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 // -----------------------------------------------------------------------
54 SdrView* ScTabViewShell::GetDrawView() const
56 return ((ScTabViewShell*)this)->GetScDrawView(); // GetScDrawView ist nicht-const
59 void ScTabViewShell::WindowChanged()
61 Window* pWin = GetActiveWin();
63 ScDrawView* pDrView = GetScDrawView();
64 if (pDrView)
65 pDrView->SetActualWin(pWin);
67 FuPoor* pFunc = GetDrawFuncPtr();
68 if (pFunc)
69 pFunc->SetWindow(pWin);
71 // when font from InputContext is used,
72 // this must be moved to change of cursor position:
73 UpdateInputContext();
76 void ScTabViewShell::ExecDraw(SfxRequest& rReq)
78 SC_MOD()->InputEnterHandler();
79 UpdateInputHandler();
81 MakeDrawLayer();
83 ScTabView* pTabView = GetViewData()->GetView();
84 SfxBindings& rBindings = GetViewFrame()->GetBindings();
86 Window* pWin = pTabView->GetActiveWin();
87 ScDrawView* pView = pTabView->GetScDrawView();
88 SdrModel* pDoc = pView->GetModel();
90 const SfxItemSet *pArgs = rReq.GetArgs();
91 sal_uInt16 nNewId = rReq.GetSlot();
93 if ( nNewId == SID_DRAW_CHART )
95 // #i71254# directly insert a chart instead of drawing its output rectangle
96 FuInsertChart(this, pWin, pView, pDoc, rReq);
97 return;
101 // Pseudo-Slots von Draw-Toolbox auswerten
102 //! wird das ueberhaupt noch gebraucht ?????
105 if (nNewId == SID_INSERT_DRAW && pArgs)
107 const SfxPoolItem* pItem;
108 if ( pArgs->GetItemState( SID_INSERT_DRAW, sal_True, &pItem ) == SFX_ITEM_SET &&
109 pItem->ISA( SvxDrawToolItem ) )
111 SvxDrawToolEnum eSel = (SvxDrawToolEnum)((const SvxDrawToolItem*)pItem)->GetValue();
112 switch (eSel)
114 case SVX_SNAP_DRAW_SELECT: nNewId = SID_OBJECT_SELECT; break;
115 case SVX_SNAP_DRAW_LINE: nNewId = SID_DRAW_LINE; break;
116 case SVX_SNAP_DRAW_RECT: nNewId = SID_DRAW_RECT; break;
117 case SVX_SNAP_DRAW_ELLIPSE: nNewId = SID_DRAW_ELLIPSE; break;
118 case SVX_SNAP_DRAW_POLYGON_NOFILL: nNewId = SID_DRAW_POLYGON_NOFILL; break;
119 case SVX_SNAP_DRAW_BEZIER_NOFILL: nNewId = SID_DRAW_BEZIER_NOFILL; break;
120 case SVX_SNAP_DRAW_FREELINE_NOFILL: nNewId = SID_DRAW_FREELINE_NOFILL; break;
121 case SVX_SNAP_DRAW_ARC: nNewId = SID_DRAW_ARC; break;
122 case SVX_SNAP_DRAW_PIE: nNewId = SID_DRAW_PIE; break;
123 case SVX_SNAP_DRAW_CIRCLECUT: nNewId = SID_DRAW_CIRCLECUT; break;
124 case SVX_SNAP_DRAW_TEXT: nNewId = SID_DRAW_TEXT; break;
125 case SVX_SNAP_DRAW_TEXT_VERTICAL: nNewId = SID_DRAW_TEXT_VERTICAL; break;
126 case SVX_SNAP_DRAW_TEXT_MARQUEE: nNewId = SID_DRAW_TEXT_MARQUEE; break;
127 case SVX_SNAP_DRAW_CAPTION: nNewId = SID_DRAW_CAPTION; break;
128 case SVX_SNAP_DRAW_CAPTION_VERTICAL: nNewId = SID_DRAW_CAPTION_VERTICAL; break;
131 else // sal_uInt16-Item vom Controller
133 rReq.Done();
134 return;
138 if ( nNewId == SID_DRAW_SELECT )
139 nNewId = SID_OBJECT_SELECT;
141 sal_uInt16 nNewFormId = 0;
142 if ( nNewId == SID_FM_CREATE_CONTROL && pArgs )
144 const SfxPoolItem* pItem;
145 if ( pArgs->GetItemState( SID_FM_CONTROL_IDENTIFIER, sal_True, &pItem ) == SFX_ITEM_SET &&
146 pItem->ISA( SfxUInt16Item ) )
147 nNewFormId = ((const SfxUInt16Item*)pItem)->GetValue();
150 String sStringItemValue;
151 if ( pArgs )
153 const SfxPoolItem* pItem;
154 if ( pArgs->GetItemState( nNewId, sal_True, &pItem ) == SFX_ITEM_SET && pItem->ISA( SfxStringItem ) )
155 sStringItemValue = static_cast<const SfxStringItem*>(pItem)->GetValue();
157 bool bSwitchCustom = ( sStringItemValue.Len() && sDrawCustom.Len() && sStringItemValue != sDrawCustom );
159 if (nNewId == SID_INSERT_FRAME) // vom Tbx-Button
160 nNewId = SID_DRAW_TEXT;
162 // CTRL-SID_OBJECT_SELECT is used to select the first object,
163 // but not if SID_OBJECT_SELECT is the result of clicking a create function again,
164 // so this must be tested before changing nNewId below.
165 sal_Bool bSelectFirst = ( nNewId == SID_OBJECT_SELECT && (rReq.GetModifier() & KEY_MOD1) );
167 sal_Bool bEx = IsDrawSelMode();
168 if ( rReq.GetModifier() & KEY_MOD1 )
170 // always allow keyboard selection also on background layer
171 // also allow creation of default objects if the same object type
172 // was already active
173 bEx = sal_True;
175 else if ( nNewId == nDrawSfxId && ( nNewId != SID_FM_CREATE_CONTROL ||
176 nNewFormId == nFormSfxId || nNewFormId == 0 ) && !bSwitchCustom )
178 // #i52871# if a different custom shape is selected, the slot id can be the same,
179 // so the custom shape type string has to be compared, too.
181 // SID_FM_CREATE_CONTROL mit nNewFormId==0 (ohne Parameter) kommt beim Deaktivieren
182 // aus FuConstruct::SimpleMouseButtonUp
183 // Execute fuer die Form-Shell, um im Controller zu deselektieren
184 if ( nNewId == SID_FM_CREATE_CONTROL )
186 GetViewData()->GetDispatcher().Execute(SID_FM_LEAVE_CREATE);
187 GetViewFrame()->GetBindings().InvalidateAll(false);
188 //! was fuer einen Slot braucht der komische Controller wirklich, um das anzuzeigen????
191 bEx = !bEx;
192 nNewId = SID_OBJECT_SELECT;
194 else
195 bEx = sal_True;
197 if ( nDrawSfxId == SID_FM_CREATE_CONTROL && nNewId != nDrawSfxId )
199 // Wechsel von Control- zu Zeichenfunktion -> im Control-Controller deselektieren
200 GetViewData()->GetDispatcher().Execute(SID_FM_LEAVE_CREATE);
201 GetViewFrame()->GetBindings().InvalidateAll(false);
202 //! was fuer einen Slot braucht der komische Controller wirklich, um das anzuzeigen????
205 SetDrawSelMode(bEx);
207 pView->LockBackgroundLayer( !bEx );
209 if ( bSelectFirst )
211 // select first draw object if none is selected yet
212 if(!pView->AreObjectsMarked())
214 // select first object
215 pView->UnmarkAllObj();
216 pView->MarkNextObj(sal_True);
218 // ...and make it visible
219 if(pView->AreObjectsMarked())
220 pView->MakeVisible(pView->GetAllMarkedRect(), *pWin);
224 nDrawSfxId = nNewId;
225 sDrawCustom.Erase(); // value is set below for custom shapes
227 if ( nNewId != SID_DRAW_CHART ) // Chart nicht mit DrawShell
229 if ( nNewId == SID_DRAW_TEXT || nNewId == SID_DRAW_TEXT_VERTICAL ||
230 nNewId == SID_DRAW_TEXT_MARQUEE || nNewId == SID_DRAW_NOTEEDIT )
231 SetDrawTextShell( sal_True );
232 else
234 if ( bEx || pView->GetMarkedObjectList().GetMarkCount() != 0 )
235 SetDrawShellOrSub();
236 else
237 SetDrawShell( false );
241 if (pTabView->GetDrawFuncPtr())
243 if (pTabView->GetDrawFuncOldPtr() != pTabView->GetDrawFuncPtr())
244 delete pTabView->GetDrawFuncOldPtr();
246 pTabView->GetDrawFuncPtr()->Deactivate();
247 pTabView->SetDrawFuncOldPtr(pTabView->GetDrawFuncPtr());
248 pTabView->SetDrawFuncPtr(NULL);
251 SfxRequest aNewReq(rReq);
252 aNewReq.SetSlot(nDrawSfxId);
254 switch (nNewId)
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));
260 break;
262 case SID_DRAW_LINE:
263 case SID_DRAW_RECT:
264 case SID_DRAW_ELLIPSE:
265 pTabView->SetDrawFuncPtr(new FuConstRectangle(this, pWin, pView, pDoc, aNewReq));
266 break;
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 );
273 break;
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));
280 break;
282 case SID_DRAW_ARC:
283 case SID_DRAW_PIE:
284 case SID_DRAW_CIRCLECUT:
285 pTabView->SetDrawFuncPtr(new FuConstArc(this, pWin, pView, pDoc, aNewReq));
286 break;
288 case SID_DRAW_TEXT:
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));
293 break;
295 case SID_FM_CREATE_CONTROL:
296 SetDrawFormShell(sal_True);
297 pTabView->SetDrawFuncPtr(new FuConstUnoControl(this, pWin, pView, pDoc, aNewReq));
298 nFormSfxId = nNewFormId;
299 break;
301 case SID_DRAW_CHART:
302 pTabView->SetDrawFuncPtr(new FuMarkRect(this, pWin, pView, pDoc, aNewReq));
303 break;
305 case SID_DRAWTBX_CS_BASIC :
306 case SID_DRAWTBX_CS_SYMBOL :
307 case SID_DRAWTBX_CS_ARROW :
308 case SID_DRAWTBX_CS_FLOWCHART :
309 case SID_DRAWTBX_CS_CALLOUT :
310 case SID_DRAWTBX_CS_STAR :
311 case SID_DRAW_CS_ID :
313 pTabView->SetDrawFuncPtr( new FuConstCustomShape( this, pWin, pView, pDoc, aNewReq ));
314 if ( nNewId != SID_DRAW_CS_ID )
316 SFX_REQUEST_ARG( rReq, pEnumCommand, SfxStringItem, nNewId, false );
317 if ( pEnumCommand )
319 aCurrShapeEnumCommand[ nNewId - SID_DRAWTBX_CS_BASIC ] = pEnumCommand->GetValue();
320 SfxBindings& rBind = GetViewFrame()->GetBindings();
321 rBind.Invalidate( nNewId );
322 rBind.Update( nNewId );
324 sDrawCustom = pEnumCommand->GetValue(); // to detect when a different shape type is selected
328 break;
330 default:
331 break;
334 if (pTabView->GetDrawFuncPtr())
335 pTabView->GetDrawFuncPtr()->Activate();
337 rReq.Done();
339 rBindings.Invalidate( SID_INSERT_DRAW );
340 rBindings.Update( SID_INSERT_DRAW );
342 // Create default drawing objects via keyboard
343 // with qualifier construct directly
344 FuPoor* pFuActual = GetDrawFuncPtr();
346 if(pFuActual && (rReq.GetModifier() & KEY_MOD1))
348 // Create default drawing objects via keyboard
349 const ScAppOptions& rAppOpt = SC_MOD()->GetAppOptions();
350 sal_uInt32 nDefaultObjectSizeWidth = rAppOpt.GetDefaultObjectSizeWidth();
351 sal_uInt32 nDefaultObjectSizeHeight = rAppOpt.GetDefaultObjectSizeHeight();
353 // calc position and size
354 Rectangle aVisArea = pWin->PixelToLogic(Rectangle(Point(0,0), pWin->GetOutputSizePixel()));
355 Point aPagePos = aVisArea.Center();
356 aPagePos.X() -= nDefaultObjectSizeWidth / 2;
357 aPagePos.Y() -= nDefaultObjectSizeHeight / 2;
358 Rectangle aNewObjectRectangle(aPagePos, Size(nDefaultObjectSizeWidth, nDefaultObjectSizeHeight));
360 ScDrawView* pDrView = GetScDrawView();
362 if(pDrView)
364 SdrPageView* pPageView = pDrView->GetSdrPageView();
366 if(pPageView)
368 // create the default object
369 SdrObject* pObj = pFuActual->CreateDefaultObject(nNewId, aNewObjectRectangle);
371 if(pObj)
373 // insert into page
374 pView->InsertObjectAtView(pObj, *pPageView);
376 if ( nNewId == SID_DRAW_CAPTION || nNewId == SID_DRAW_CAPTION_VERTICAL )
378 // use KeyInput to start edit mode (FuText is created).
379 // For FuText objects, edit mode is handled within CreateDefaultObject.
380 // KEY_F2 is handled in FuDraw::KeyInput.
382 pFuActual->KeyInput( KeyEvent( 0, KeyCode( KEY_F2 ) ) );
390 void ScTabViewShell::GetDrawState(SfxItemSet &rSet)
392 SfxWhichIter aIter(rSet);
393 sal_uInt16 nWhich = aIter.FirstWhich();
395 while ( nWhich )
397 switch ( nWhich )
399 case SID_INSERT_DRAW:
401 // SID_OBJECT_SELECT nur, wenn "harter" Selektionsmodus
402 sal_uInt16 nPutId = nDrawSfxId;
403 if ( nPutId == SID_OBJECT_SELECT && !IsDrawSelMode() )
404 nPutId = USHRT_MAX;
405 // nur die Images, die auch auf dem Controller liegen
406 if ( nPutId != SID_OBJECT_SELECT &&
407 nPutId != SID_DRAW_LINE &&
408 nPutId != SID_DRAW_RECT &&
409 nPutId != SID_DRAW_ELLIPSE &&
410 nPutId != SID_DRAW_POLYGON_NOFILL &&
411 nPutId != SID_DRAW_BEZIER_NOFILL &&
412 nPutId != SID_DRAW_FREELINE_NOFILL &&
413 nPutId != SID_DRAW_ARC &&
414 nPutId != SID_DRAW_PIE &&
415 nPutId != SID_DRAW_CIRCLECUT &&
416 nPutId != SID_DRAW_TEXT &&
417 nPutId != SID_DRAW_TEXT_VERTICAL &&
418 nPutId != SID_DRAW_TEXT_MARQUEE &&
419 nPutId != SID_DRAW_CAPTION &&
420 nPutId != SID_DRAW_CAPTION_VERTICAL )
421 nPutId = USHRT_MAX;
422 SfxAllEnumItem aItem( nWhich, nPutId );
423 if ( !SvtLanguageOptions().IsVerticalTextEnabled() )
425 aItem.DisableValue( SID_DRAW_TEXT_VERTICAL );
426 aItem.DisableValue( SID_DRAW_CAPTION_VERTICAL );
428 rSet.Put( aItem );
430 break;
432 case SID_DRAW_CHART:
434 sal_Bool bOle = GetViewFrame()->GetFrame().IsInPlace();
435 if ( bOle || !SvtModuleOptions().IsChart() )
436 rSet.DisableItem( nWhich );
438 break;
440 case SID_OBJECT_SELECT: // wichtig fuer den ollen Control-Controller
441 rSet.Put( SfxBoolItem( nWhich, nDrawSfxId == SID_OBJECT_SELECT && IsDrawSelMode() ) );
442 break;
444 nWhich = aIter.NextWhich();
448 sal_Bool ScTabViewShell::SelectObject( const String& rName )
450 ScDrawView* pView = GetViewData()->GetScDrawView();
451 if (!pView)
452 return false;
454 sal_Bool bFound = pView->SelectObject( rName );
455 // DrawShell etc. is handled in MarkListHasChanged
457 return bFound;
462 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */