fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / view / tabvwsh2.cxx
blob1efe8d62b7d8aab69f33172ee0bfe53304114b8d
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 "fuinsert.hxx"
40 #include "global.hxx"
41 #include "sc.hrc"
42 #include "scmod.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 const_cast<ScTabViewShell*>(this)->GetScDrawView(); // GetScDrawView ist nicht-const
57 void ScTabViewShell::WindowChanged()
59 vcl::Window* pWin = GetActiveWin();
61 ScDrawView* pDrView = GetScDrawView();
62 if (pDrView)
63 pDrView->SetActualWin(pWin);
65 FuPoor* pFunc = GetDrawFuncPtr();
66 if (pFunc)
67 pFunc->SetWindow(pWin);
69 // when font from InputContext is used,
70 // this must be moved to change of cursor position:
71 UpdateInputContext();
74 void ScTabViewShell::ExecDraw(SfxRequest& rReq)
76 SC_MOD()->InputEnterHandler();
77 UpdateInputHandler();
79 MakeDrawLayer();
81 ScTabView* pTabView = GetViewData().GetView();
82 SfxBindings& rBindings = GetViewFrame()->GetBindings();
84 vcl::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);
95 return;
98 // Pseudo-Slots von Draw-Toolbox auswerten
99 //! wird das ueberhaupt noch gebraucht ?????
101 if (nNewId == SID_INSERT_DRAW && pArgs)
103 const SfxPoolItem* pItem;
104 if ( pArgs->GetItemState( SID_INSERT_DRAW, true, &pItem ) == SfxItemState::SET &&
105 pItem->ISA( SvxDrawToolItem ) )
107 SvxDrawToolEnum eSel = (SvxDrawToolEnum)static_cast<const SvxDrawToolItem*>(pItem)->GetValue();
108 switch (eSel)
110 case SVX_SNAP_DRAW_SELECT: nNewId = SID_OBJECT_SELECT; break;
111 case SVX_SNAP_DRAW_LINE: nNewId = SID_DRAW_LINE; break;
112 case SVX_SNAP_DRAW_RECT: nNewId = SID_DRAW_RECT; break;
113 case SVX_SNAP_DRAW_ELLIPSE: nNewId = SID_DRAW_ELLIPSE; break;
114 case SVX_SNAP_DRAW_POLYGON_NOFILL: nNewId = SID_DRAW_POLYGON_NOFILL; break;
115 case SVX_SNAP_DRAW_BEZIER_NOFILL: nNewId = SID_DRAW_BEZIER_NOFILL; break;
116 case SVX_SNAP_DRAW_FREELINE_NOFILL: nNewId = SID_DRAW_FREELINE_NOFILL; break;
117 case SVX_SNAP_DRAW_ARC: nNewId = SID_DRAW_ARC; break;
118 case SVX_SNAP_DRAW_PIE: nNewId = SID_DRAW_PIE; break;
119 case SVX_SNAP_DRAW_CIRCLECUT: nNewId = SID_DRAW_CIRCLECUT; break;
120 case SVX_SNAP_DRAW_TEXT: nNewId = SID_DRAW_TEXT; break;
121 case SVX_SNAP_DRAW_TEXT_VERTICAL: nNewId = SID_DRAW_TEXT_VERTICAL; break;
122 case SVX_SNAP_DRAW_TEXT_MARQUEE: nNewId = SID_DRAW_TEXT_MARQUEE; break;
123 case SVX_SNAP_DRAW_CAPTION: nNewId = SID_DRAW_CAPTION; break;
124 case SVX_SNAP_DRAW_CAPTION_VERTICAL: nNewId = SID_DRAW_CAPTION_VERTICAL; break;
127 else // sal_uInt16-Item vom Controller
129 rReq.Done();
130 return;
134 if ( nNewId == SID_DRAW_SELECT )
135 nNewId = SID_OBJECT_SELECT;
137 sal_uInt16 nNewFormId = 0;
138 if ( nNewId == SID_FM_CREATE_CONTROL && pArgs )
140 const SfxPoolItem* pItem;
141 if ( pArgs->GetItemState( SID_FM_CONTROL_IDENTIFIER, true, &pItem ) == SfxItemState::SET &&
142 pItem->ISA( SfxUInt16Item ) )
143 nNewFormId = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
146 OUString sStringItemValue;
147 if ( pArgs )
149 const SfxPoolItem* pItem;
150 if ( pArgs->GetItemState( nNewId, true, &pItem ) == SfxItemState::SET && pItem->ISA( SfxStringItem ) )
151 sStringItemValue = static_cast<const SfxStringItem*>(pItem)->GetValue();
153 bool bSwitchCustom = ( !sStringItemValue.isEmpty() && !sDrawCustom.isEmpty() && sStringItemValue != sDrawCustom );
155 if (nNewId == SID_INSERT_FRAME) // vom Tbx-Button
156 nNewId = SID_DRAW_TEXT;
158 // CTRL-SID_OBJECT_SELECT is used to select the first object,
159 // but not if SID_OBJECT_SELECT is the result of clicking a create function again,
160 // so this must be tested before changing nNewId below.
161 bool bSelectFirst = ( nNewId == SID_OBJECT_SELECT && (rReq.GetModifier() & KEY_MOD1) );
163 bool bEx = IsDrawSelMode();
164 if ( rReq.GetModifier() & KEY_MOD1 )
166 // always allow keyboard selection also on background layer
167 // also allow creation of default objects if the same object type
168 // was already active
169 bEx = true;
171 else if ( nNewId == nDrawSfxId && ( nNewId != SID_FM_CREATE_CONTROL ||
172 nNewFormId == nFormSfxId || nNewFormId == 0 ) && !bSwitchCustom )
174 // #i52871# if a different custom shape is selected, the slot id can be the same,
175 // so the custom shape type string has to be compared, too.
177 // SID_FM_CREATE_CONTROL mit nNewFormId==0 (ohne Parameter) kommt beim Deaktivieren
178 // aus FuConstruct::SimpleMouseButtonUp
179 // Execute fuer die Form-Shell, um im Controller zu deselektieren
180 if ( nNewId == SID_FM_CREATE_CONTROL )
182 GetViewData().GetDispatcher().Execute(SID_FM_LEAVE_CREATE);
183 GetViewFrame()->GetBindings().InvalidateAll(false);
184 //! was fuer einen Slot braucht der komische Controller wirklich, um das anzuzeigen????
187 bEx = !bEx;
188 nNewId = SID_OBJECT_SELECT;
190 else
191 bEx = true;
193 if ( nDrawSfxId == SID_FM_CREATE_CONTROL && nNewId != nDrawSfxId )
195 // Wechsel von Control- zu Zeichenfunktion -> im Control-Controller deselektieren
196 GetViewData().GetDispatcher().Execute(SID_FM_LEAVE_CREATE);
197 GetViewFrame()->GetBindings().InvalidateAll(false);
198 //! was fuer einen Slot braucht der komische Controller wirklich, um das anzuzeigen????
201 SetDrawSelMode(bEx);
203 pView->LockBackgroundLayer( !bEx );
205 if ( bSelectFirst )
207 // select first draw object if none is selected yet
208 if(!pView->AreObjectsMarked())
210 // select first object
211 pView->UnmarkAllObj();
212 pView->MarkNextObj(true);
214 // ...and make it visible
215 if(pView->AreObjectsMarked())
216 pView->MakeVisible(pView->GetAllMarkedRect(), *pWin);
220 nDrawSfxId = nNewId;
221 sDrawCustom.clear(); // value is set below for custom shapes
223 if ( nNewId != SID_DRAW_CHART ) // Chart nicht mit DrawShell
225 if ( nNewId == SID_DRAW_TEXT || nNewId == SID_DRAW_TEXT_VERTICAL ||
226 nNewId == SID_DRAW_TEXT_MARQUEE || nNewId == SID_DRAW_NOTEEDIT )
227 SetDrawTextShell( true );
228 else
230 if ( bEx || pView->GetMarkedObjectList().GetMarkCount() != 0 )
231 SetDrawShellOrSub();
232 else
233 SetDrawShell( false );
237 if (pTabView->GetDrawFuncPtr())
239 if (pTabView->GetDrawFuncOldPtr() != pTabView->GetDrawFuncPtr())
240 delete pTabView->GetDrawFuncOldPtr();
242 pTabView->GetDrawFuncPtr()->Deactivate();
243 pTabView->SetDrawFuncOldPtr(pTabView->GetDrawFuncPtr());
244 pTabView->SetDrawFuncPtr(NULL);
247 SfxRequest aNewReq(rReq);
248 aNewReq.SetSlot(nDrawSfxId);
250 assert(nNewId != SID_DRAW_CHART); //#i71254# handled already above
252 switch (nNewId)
254 case SID_OBJECT_SELECT:
255 // Nicht immer zurueckschalten
256 if(pView->GetMarkedObjectList().GetMarkCount() == 0) SetDrawShell(bEx);
257 pTabView->SetDrawFuncPtr(new FuSelection(this, pWin, pView, pDoc, aNewReq));
258 break;
260 case SID_DRAW_LINE:
261 case SID_DRAW_RECT:
262 case SID_DRAW_ELLIPSE:
263 pTabView->SetDrawFuncPtr(new FuConstRectangle(this, pWin, pView, pDoc, aNewReq));
264 break;
266 case SID_DRAW_CAPTION:
267 case SID_DRAW_CAPTION_VERTICAL:
268 pTabView->SetDrawFuncPtr(new FuConstRectangle(this, pWin, pView, pDoc, aNewReq));
269 pView->SetFrameDragSingles( false );
270 rBindings.Invalidate( SID_BEZIER_EDIT );
271 break;
273 case SID_DRAW_POLYGON:
274 case SID_DRAW_POLYGON_NOFILL:
275 case SID_DRAW_BEZIER_NOFILL:
276 case SID_DRAW_FREELINE_NOFILL:
277 pTabView->SetDrawFuncPtr(new FuConstPolygon(this, pWin, pView, pDoc, aNewReq));
278 break;
280 case SID_DRAW_ARC:
281 case SID_DRAW_PIE:
282 case SID_DRAW_CIRCLECUT:
283 pTabView->SetDrawFuncPtr(new FuConstArc(this, pWin, pView, pDoc, aNewReq));
284 break;
286 case SID_DRAW_TEXT:
287 case SID_DRAW_TEXT_VERTICAL:
288 case SID_DRAW_TEXT_MARQUEE:
289 case SID_DRAW_NOTEEDIT:
290 pTabView->SetDrawFuncPtr(new FuText(this, pWin, pView, pDoc, aNewReq));
291 break;
293 case SID_FM_CREATE_CONTROL:
294 SetDrawFormShell(true);
295 pTabView->SetDrawFuncPtr(new FuConstUnoControl(this, pWin, pView, pDoc, aNewReq));
296 nFormSfxId = nNewFormId;
297 break;
299 case SID_DRAWTBX_CS_BASIC :
300 case SID_DRAWTBX_CS_SYMBOL :
301 case SID_DRAWTBX_CS_ARROW :
302 case SID_DRAWTBX_CS_FLOWCHART :
303 case SID_DRAWTBX_CS_CALLOUT :
304 case SID_DRAWTBX_CS_STAR :
305 case SID_DRAW_CS_ID :
307 pTabView->SetDrawFuncPtr( new FuConstCustomShape( this, pWin, pView, pDoc, aNewReq ));
308 if ( nNewId != SID_DRAW_CS_ID )
310 SFX_REQUEST_ARG( rReq, pEnumCommand, SfxStringItem, nNewId, false );
311 if ( pEnumCommand )
313 aCurrShapeEnumCommand[ nNewId - SID_DRAWTBX_CS_BASIC ] = pEnumCommand->GetValue();
314 SfxBindings& rBind = GetViewFrame()->GetBindings();
315 rBind.Invalidate( nNewId );
316 rBind.Update( nNewId );
318 sDrawCustom = pEnumCommand->GetValue(); // to detect when a different shape type is selected
322 break;
324 default:
325 break;
328 if (pTabView->GetDrawFuncPtr())
329 pTabView->GetDrawFuncPtr()->Activate();
331 rReq.Done();
333 rBindings.Invalidate( SID_INSERT_DRAW );
334 rBindings.Update( SID_INSERT_DRAW );
336 // Create default drawing objects via keyboard
337 // with qualifier construct directly
338 FuPoor* pFuActual = GetDrawFuncPtr();
340 if(pFuActual && (rReq.GetModifier() & KEY_MOD1))
342 // Create default drawing objects via keyboard
343 const ScAppOptions& rAppOpt = SC_MOD()->GetAppOptions();
344 sal_uInt32 nDefaultObjectSizeWidth = rAppOpt.GetDefaultObjectSizeWidth();
345 sal_uInt32 nDefaultObjectSizeHeight = rAppOpt.GetDefaultObjectSizeHeight();
347 // calc position and size
348 Rectangle aVisArea = pWin->PixelToLogic(Rectangle(Point(0,0), pWin->GetOutputSizePixel()));
349 Point aPagePos = aVisArea.Center();
350 aPagePos.X() -= nDefaultObjectSizeWidth / 2;
351 aPagePos.Y() -= nDefaultObjectSizeHeight / 2;
352 Rectangle aNewObjectRectangle(aPagePos, Size(nDefaultObjectSizeWidth, nDefaultObjectSizeHeight));
354 ScDrawView* pDrView = GetScDrawView();
356 if(pDrView)
358 SdrPageView* pPageView = pDrView->GetSdrPageView();
360 if(pPageView)
362 // create the default object
363 SdrObject* pObj = pFuActual->CreateDefaultObject(nNewId, aNewObjectRectangle);
365 if(pObj)
367 // insert into page
368 pView->InsertObjectAtView(pObj, *pPageView);
370 if ( nNewId == SID_DRAW_CAPTION || nNewId == SID_DRAW_CAPTION_VERTICAL )
372 // use KeyInput to start edit mode (FuText is created).
373 // For FuText objects, edit mode is handled within CreateDefaultObject.
374 // KEY_F2 is handled in FuDraw::KeyInput.
376 pFuActual->KeyInput( KeyEvent( 0, vcl::KeyCode( KEY_F2 ) ) );
384 void ScTabViewShell::GetDrawState(SfxItemSet &rSet)
386 SfxWhichIter aIter(rSet);
387 sal_uInt16 nWhich = aIter.FirstWhich();
389 while ( nWhich )
391 switch ( nWhich )
393 case SID_INSERT_DRAW:
395 // SID_OBJECT_SELECT nur, wenn "harter" Selektionsmodus
396 sal_uInt16 nPutId = nDrawSfxId;
397 if ( nPutId == SID_OBJECT_SELECT && !IsDrawSelMode() )
398 nPutId = USHRT_MAX;
399 // nur die Images, die auch auf dem Controller liegen
400 if ( nPutId != SID_OBJECT_SELECT &&
401 nPutId != SID_DRAW_LINE &&
402 nPutId != SID_DRAW_RECT &&
403 nPutId != SID_DRAW_ELLIPSE &&
404 nPutId != SID_DRAW_POLYGON_NOFILL &&
405 nPutId != SID_DRAW_BEZIER_NOFILL &&
406 nPutId != SID_DRAW_FREELINE_NOFILL &&
407 nPutId != SID_DRAW_ARC &&
408 nPutId != SID_DRAW_PIE &&
409 nPutId != SID_DRAW_CIRCLECUT &&
410 nPutId != SID_DRAW_TEXT &&
411 nPutId != SID_DRAW_TEXT_VERTICAL &&
412 nPutId != SID_DRAW_TEXT_MARQUEE &&
413 nPutId != SID_DRAW_CAPTION &&
414 nPutId != SID_DRAW_CAPTION_VERTICAL )
415 nPutId = USHRT_MAX;
416 SfxAllEnumItem aItem( nWhich, nPutId );
417 if ( !SvtLanguageOptions().IsVerticalTextEnabled() )
419 aItem.DisableValue( SID_DRAW_TEXT_VERTICAL );
420 aItem.DisableValue( SID_DRAW_CAPTION_VERTICAL );
422 rSet.Put( aItem );
424 break;
426 case SID_DRAW_CHART:
428 bool bOle = GetViewFrame()->GetFrame().IsInPlace();
429 if ( bOle || !SvtModuleOptions().IsChart() )
430 rSet.DisableItem( nWhich );
432 break;
434 case SID_OBJECT_SELECT: // wichtig fuer den ollen Control-Controller
435 rSet.Put( SfxBoolItem( nWhich, nDrawSfxId == SID_OBJECT_SELECT && IsDrawSelMode() ) );
436 break;
438 nWhich = aIter.NextWhich();
442 bool ScTabViewShell::SelectObject( const OUString& rName )
444 ScDrawView* pView = GetViewData().GetScDrawView();
445 if (!pView)
446 return false;
448 bool bFound = pView->SelectObject( rName );
449 // DrawShell etc. is handled in MarkListHasChanged
451 return bFound;
454 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */