merge the formfield patch from ooo-build
[ooovba.git] / sc / source / ui / view / tabvwsh2.cxx
blobb57a369519a3d6ba20976f58597a8deddbedf212
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabvwsh2.cxx,v $
10 * $Revision: 1.27.128.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #ifdef _MSC_VER
39 #pragma optimize ("", off)
40 #endif
42 #include <sfx2/bindings.hxx>
43 #include <sfx2/viewfrm.hxx>
44 #include <svtools/aeitem.hxx>
45 #include <svtools/whiter.hxx>
46 #include <svtools/moduleoptions.hxx>
47 #include <svtools/languageoptions.hxx>
48 #include <sfx2/dispatch.hxx>
50 #include "tabvwsh.hxx"
51 #include "drawattr.hxx"
52 #include "drawsh.hxx"
53 #include "drawview.hxx"
54 #include "fupoor.hxx"
55 #include "fuconrec.hxx"
56 #include "fuconpol.hxx"
57 #include "fuconarc.hxx"
58 #include "fuconuno.hxx"
59 #include "fusel.hxx"
60 #include "futext.hxx"
61 #include "fumark.hxx"
62 #include "fuinsert.hxx"
63 #include "global.hxx"
64 #include "sc.hrc"
65 #include "scmod.hxx"
66 #include "appoptio.hxx"
68 // #98185# Create default drawing objects via keyboard
69 #include <svx/svdpagv.hxx>
70 #include <svtools/stritem.hxx>
71 #include <svx/svdpage.hxx>
72 #include <fuconcustomshape.hxx>
74 // -----------------------------------------------------------------------
76 SdrView* __EXPORT ScTabViewShell::GetDrawView() const
78 return ((ScTabViewShell*)this)->GetScDrawView(); // GetScDrawView ist nicht-const
81 void ScTabViewShell::WindowChanged()
83 Window* pWin = GetActiveWin();
85 ScDrawView* pDrView = GetScDrawView();
86 if (pDrView)
87 pDrView->SetActualWin(pWin);
89 FuPoor* pFunc = GetDrawFuncPtr();
90 if (pFunc)
91 pFunc->SetWindow(pWin);
93 // when font from InputContext is used,
94 // this must be moved to change of cursor position:
95 UpdateInputContext();
98 void ScTabViewShell::ExecDraw(SfxRequest& rReq)
100 SC_MOD()->InputEnterHandler();
101 UpdateInputHandler();
103 MakeDrawLayer();
105 ScTabView* pTabView = GetViewData()->GetView();
106 SfxBindings& rBindings = GetViewFrame()->GetBindings();
108 Window* pWin = pTabView->GetActiveWin();
109 ScDrawView* pView = pTabView->GetScDrawView();
110 SdrModel* pDoc = pView->GetModel();
112 const SfxItemSet *pArgs = rReq.GetArgs();
113 USHORT nNewId = rReq.GetSlot();
115 if ( nNewId == SID_DRAW_CHART )
117 // #i71254# directly insert a chart instead of drawing its output rectangle
118 FuInsertChart(this, pWin, pView, pDoc, rReq);
119 return;
123 // Pseudo-Slots von Draw-Toolbox auswerten
124 //! wird das ueberhaupt noch gebraucht ?????
127 if (nNewId == SID_INSERT_DRAW && pArgs)
129 const SfxPoolItem* pItem;
130 if ( pArgs->GetItemState( SID_INSERT_DRAW, TRUE, &pItem ) == SFX_ITEM_SET &&
131 pItem->ISA( SvxDrawToolItem ) )
133 SvxDrawToolEnum eSel = (SvxDrawToolEnum)((const SvxDrawToolItem*)pItem)->GetValue();
134 switch (eSel)
136 case SVX_SNAP_DRAW_SELECT: nNewId = SID_OBJECT_SELECT; break;
137 case SVX_SNAP_DRAW_LINE: nNewId = SID_DRAW_LINE; break;
138 case SVX_SNAP_DRAW_RECT: nNewId = SID_DRAW_RECT; break;
139 case SVX_SNAP_DRAW_ELLIPSE: nNewId = SID_DRAW_ELLIPSE; break;
140 case SVX_SNAP_DRAW_POLYGON_NOFILL: nNewId = SID_DRAW_POLYGON_NOFILL; break;
141 case SVX_SNAP_DRAW_BEZIER_NOFILL: nNewId = SID_DRAW_BEZIER_NOFILL; break;
142 case SVX_SNAP_DRAW_FREELINE_NOFILL: nNewId = SID_DRAW_FREELINE_NOFILL; break;
143 case SVX_SNAP_DRAW_ARC: nNewId = SID_DRAW_ARC; break;
144 case SVX_SNAP_DRAW_PIE: nNewId = SID_DRAW_PIE; break;
145 case SVX_SNAP_DRAW_CIRCLECUT: nNewId = SID_DRAW_CIRCLECUT; break;
146 case SVX_SNAP_DRAW_TEXT: nNewId = SID_DRAW_TEXT; break;
147 case SVX_SNAP_DRAW_TEXT_VERTICAL: nNewId = SID_DRAW_TEXT_VERTICAL; break;
148 case SVX_SNAP_DRAW_TEXT_MARQUEE: nNewId = SID_DRAW_TEXT_MARQUEE; break;
149 case SVX_SNAP_DRAW_CAPTION: nNewId = SID_DRAW_CAPTION; break;
150 case SVX_SNAP_DRAW_CAPTION_VERTICAL: nNewId = SID_DRAW_CAPTION_VERTICAL; break;
153 else // USHORT-Item vom Controller
155 rReq.Done();
156 return;
160 if ( nNewId == SID_DRAW_SELECT )
161 nNewId = SID_OBJECT_SELECT;
163 USHORT nNewFormId = 0;
164 if ( nNewId == SID_FM_CREATE_CONTROL && pArgs )
166 const SfxPoolItem* pItem;
167 if ( pArgs->GetItemState( SID_FM_CONTROL_IDENTIFIER, TRUE, &pItem ) == SFX_ITEM_SET &&
168 pItem->ISA( SfxUInt16Item ) )
169 nNewFormId = ((const SfxUInt16Item*)pItem)->GetValue();
172 String sStringItemValue;
173 if ( pArgs )
175 const SfxPoolItem* pItem;
176 if ( pArgs->GetItemState( nNewId, TRUE, &pItem ) == SFX_ITEM_SET && pItem->ISA( SfxStringItem ) )
177 sStringItemValue = static_cast<const SfxStringItem*>(pItem)->GetValue();
179 bool bSwitchCustom = ( sStringItemValue.Len() && sDrawCustom.Len() && sStringItemValue != sDrawCustom );
181 if (nNewId == SID_INSERT_FRAME) // vom Tbx-Button
182 nNewId = SID_DRAW_TEXT;
184 // #97016# CTRL-SID_OBJECT_SELECT is used to select the first object,
185 // but not if SID_OBJECT_SELECT is the result of clicking a create function again,
186 // so this must be tested before changing nNewId below.
187 BOOL bSelectFirst = ( nNewId == SID_OBJECT_SELECT && (rReq.GetModifier() & KEY_MOD1) );
189 BOOL bEx = IsDrawSelMode();
190 if ( rReq.GetModifier() & KEY_MOD1 )
192 // #97016# always allow keyboard selection also on background layer
193 // #98185# also allow creation of default objects if the same object type
194 // was already active
195 bEx = TRUE;
197 else if ( nNewId == nDrawSfxId && ( nNewId != SID_FM_CREATE_CONTROL ||
198 nNewFormId == nFormSfxId || nNewFormId == 0 ) && !bSwitchCustom )
200 // #i52871# if a different custom shape is selected, the slot id can be the same,
201 // so the custom shape type string has to be compared, too.
203 // SID_FM_CREATE_CONTROL mit nNewFormId==0 (ohne Parameter) kommt beim Deaktivieren
204 // aus FuConstruct::SimpleMouseButtonUp
205 // #59280# Execute fuer die Form-Shell, um im Controller zu deselektieren
206 if ( nNewId == SID_FM_CREATE_CONTROL )
208 GetViewData()->GetDispatcher().Execute(SID_FM_LEAVE_CREATE);
209 GetViewFrame()->GetBindings().InvalidateAll(FALSE);
210 //! was fuer einen Slot braucht der komische Controller wirklich, um das anzuzeigen????
213 bEx = !bEx;
214 nNewId = SID_OBJECT_SELECT;
216 else
217 bEx = TRUE;
219 if ( nDrawSfxId == SID_FM_CREATE_CONTROL && nNewId != nDrawSfxId )
221 // Wechsel von Control- zu Zeichenfunktion -> im Control-Controller deselektieren
222 GetViewData()->GetDispatcher().Execute(SID_FM_LEAVE_CREATE);
223 GetViewFrame()->GetBindings().InvalidateAll(FALSE);
224 //! was fuer einen Slot braucht der komische Controller wirklich, um das anzuzeigen????
227 SetDrawSelMode(bEx);
229 pView->LockBackgroundLayer( !bEx );
231 if ( bSelectFirst )
233 // #97016# select first draw object if none is selected yet
234 if(!pView->AreObjectsMarked())
236 // select first object
237 pView->UnmarkAllObj();
238 pView->MarkNextObj(TRUE);
240 // ...and make it visible
241 if(pView->AreObjectsMarked())
242 pView->MakeVisible(pView->GetAllMarkedRect(), *pWin);
246 nDrawSfxId = nNewId;
247 sDrawCustom.Erase(); // value is set below for custom shapes
249 if ( nNewId != SID_DRAW_CHART ) // Chart nicht mit DrawShell
251 if ( nNewId == SID_DRAW_TEXT || nNewId == SID_DRAW_TEXT_VERTICAL ||
252 nNewId == SID_DRAW_TEXT_MARQUEE || nNewId == SID_DRAW_NOTEEDIT )
253 SetDrawTextShell( TRUE );
254 else
256 if ( bEx || pView->GetMarkedObjectList().GetMarkCount() != 0 )
257 SetDrawShellOrSub();
258 else
259 SetDrawShell( FALSE );
263 if (pTabView->GetDrawFuncPtr())
265 if (pTabView->GetDrawFuncOldPtr() != pTabView->GetDrawFuncPtr())
266 delete pTabView->GetDrawFuncOldPtr();
268 pTabView->GetDrawFuncPtr()->Deactivate();
269 pTabView->SetDrawFuncOldPtr(pTabView->GetDrawFuncPtr());
270 pTabView->SetDrawFuncPtr(NULL);
273 SfxRequest aNewReq(rReq);
274 aNewReq.SetSlot(nDrawSfxId);
276 switch (nNewId)
278 case SID_OBJECT_SELECT:
279 //@#70206# Nicht immer zurueckschalten
280 if(pView->GetMarkedObjectList().GetMarkCount() == 0) SetDrawShell(bEx);
281 pTabView->SetDrawFuncPtr(new FuSelection(this, pWin, pView, pDoc, aNewReq));
282 break;
284 case SID_DRAW_LINE:
285 case SID_DRAW_RECT:
286 case SID_DRAW_ELLIPSE:
287 pTabView->SetDrawFuncPtr(new FuConstRectangle(this, pWin, pView, pDoc, aNewReq));
288 break;
290 case SID_DRAW_CAPTION:
291 case SID_DRAW_CAPTION_VERTICAL:
292 pTabView->SetDrawFuncPtr(new FuConstRectangle(this, pWin, pView, pDoc, aNewReq));
293 pView->SetFrameDragSingles( FALSE );
294 rBindings.Invalidate( SID_BEZIER_EDIT );
295 break;
297 case SID_DRAW_POLYGON:
298 case SID_DRAW_POLYGON_NOFILL:
299 case SID_DRAW_BEZIER_NOFILL:
300 case SID_DRAW_FREELINE_NOFILL:
301 pTabView->SetDrawFuncPtr(new FuConstPolygon(this, pWin, pView, pDoc, aNewReq));
302 break;
304 case SID_DRAW_ARC:
305 case SID_DRAW_PIE:
306 case SID_DRAW_CIRCLECUT:
307 pTabView->SetDrawFuncPtr(new FuConstArc(this, pWin, pView, pDoc, aNewReq));
308 break;
310 case SID_DRAW_TEXT:
311 case SID_DRAW_TEXT_VERTICAL:
312 case SID_DRAW_TEXT_MARQUEE:
313 case SID_DRAW_NOTEEDIT:
314 pTabView->SetDrawFuncPtr(new FuText(this, pWin, pView, pDoc, aNewReq));
315 break;
317 case SID_FM_CREATE_CONTROL:
318 SetDrawFormShell(TRUE);
319 pTabView->SetDrawFuncPtr(new FuConstUnoControl(this, pWin, pView, pDoc, aNewReq));
320 nFormSfxId = nNewFormId;
321 break;
323 case SID_DRAW_CHART:
324 //UNUSED2008-05 bChartDlgIsEdit = FALSE;
325 pTabView->SetDrawFuncPtr(new FuMarkRect(this, pWin, pView, pDoc, aNewReq));
326 break;
328 case SID_DRAWTBX_CS_BASIC :
329 case SID_DRAWTBX_CS_SYMBOL :
330 case SID_DRAWTBX_CS_ARROW :
331 case SID_DRAWTBX_CS_FLOWCHART :
332 case SID_DRAWTBX_CS_CALLOUT :
333 case SID_DRAWTBX_CS_STAR :
334 case SID_DRAW_CS_ID :
336 pTabView->SetDrawFuncPtr( new FuConstCustomShape( this, pWin, pView, pDoc, aNewReq ));
337 if ( nNewId != SID_DRAW_CS_ID )
339 SFX_REQUEST_ARG( rReq, pEnumCommand, SfxStringItem, nNewId, sal_False );
340 if ( pEnumCommand )
342 aCurrShapeEnumCommand[ nNewId - SID_DRAWTBX_CS_BASIC ] = pEnumCommand->GetValue();
343 SfxBindings& rBind = GetViewFrame()->GetBindings();
344 rBind.Invalidate( nNewId );
345 rBind.Update( nNewId );
347 sDrawCustom = pEnumCommand->GetValue(); // to detect when a different shape type is selected
351 break;
353 default:
354 break;
357 if (pTabView->GetDrawFuncPtr())
358 pTabView->GetDrawFuncPtr()->Activate();
360 rReq.Done();
362 rBindings.Invalidate( SID_INSERT_DRAW );
363 rBindings.Update( SID_INSERT_DRAW );
365 // #98185# Create default drawing objects via keyboard
366 // with qualifier construct directly
367 FuPoor* pFuActual = GetDrawFuncPtr();
369 if(pFuActual && (rReq.GetModifier() & KEY_MOD1))
371 // #98185# Create default drawing objects via keyboard
372 const ScAppOptions& rAppOpt = SC_MOD()->GetAppOptions();
373 sal_uInt32 nDefaultObjectSizeWidth = rAppOpt.GetDefaultObjectSizeWidth();
374 sal_uInt32 nDefaultObjectSizeHeight = rAppOpt.GetDefaultObjectSizeHeight();
376 // calc position and size
377 Rectangle aVisArea = pWin->PixelToLogic(Rectangle(Point(0,0), pWin->GetOutputSizePixel()));
378 Point aPagePos = aVisArea.Center();
379 aPagePos.X() -= nDefaultObjectSizeWidth / 2;
380 aPagePos.Y() -= nDefaultObjectSizeHeight / 2;
381 Rectangle aNewObjectRectangle(aPagePos, Size(nDefaultObjectSizeWidth, nDefaultObjectSizeHeight));
383 ScDrawView* pDrView = GetScDrawView();
385 if(pDrView)
387 SdrPageView* pPageView = pDrView->GetSdrPageView();
389 if(pPageView)
391 // create the default object
392 SdrObject* pObj = pFuActual->CreateDefaultObject(nNewId, aNewObjectRectangle);
394 if(pObj)
396 // insert into page
397 pView->InsertObjectAtView(pObj, *pPageView);
399 if ( nNewId == SID_DRAW_CAPTION || nNewId == SID_DRAW_CAPTION_VERTICAL )
401 // #105815# use KeyInput to start edit mode (FuText is created).
402 // For FuText objects, edit mode is handled within CreateDefaultObject.
403 // KEY_F2 is handled in FuDraw::KeyInput.
405 pFuActual->KeyInput( KeyEvent( 0, KeyCode( KEY_F2 ) ) );
413 void ScTabViewShell::GetDrawState(SfxItemSet &rSet)
415 SfxWhichIter aIter(rSet);
416 USHORT nWhich = aIter.FirstWhich();
418 while ( nWhich )
420 switch ( nWhich )
422 case SID_INSERT_DRAW:
424 // SID_OBJECT_SELECT nur, wenn "harter" Selektionsmodus
425 USHORT nPutId = nDrawSfxId;
426 if ( nPutId == SID_OBJECT_SELECT && !IsDrawSelMode() )
427 nPutId = USHRT_MAX;
428 // nur die Images, die auch auf dem Controller liegen
429 if ( nPutId != SID_OBJECT_SELECT &&
430 nPutId != SID_DRAW_LINE &&
431 nPutId != SID_DRAW_RECT &&
432 nPutId != SID_DRAW_ELLIPSE &&
433 nPutId != SID_DRAW_POLYGON_NOFILL &&
434 nPutId != SID_DRAW_BEZIER_NOFILL &&
435 nPutId != SID_DRAW_FREELINE_NOFILL &&
436 nPutId != SID_DRAW_ARC &&
437 nPutId != SID_DRAW_PIE &&
438 nPutId != SID_DRAW_CIRCLECUT &&
439 nPutId != SID_DRAW_TEXT &&
440 nPutId != SID_DRAW_TEXT_VERTICAL &&
441 nPutId != SID_DRAW_TEXT_MARQUEE &&
442 nPutId != SID_DRAW_CAPTION &&
443 nPutId != SID_DRAW_CAPTION_VERTICAL )
444 nPutId = USHRT_MAX;
445 SfxAllEnumItem aItem( nWhich, nPutId );
446 if ( !SvtLanguageOptions().IsVerticalTextEnabled() )
448 aItem.DisableValue( SID_DRAW_TEXT_VERTICAL );
449 aItem.DisableValue( SID_DRAW_CAPTION_VERTICAL );
451 rSet.Put( aItem );
453 break;
455 case SID_DRAW_CHART:
457 BOOL bOle = GetViewFrame()->GetFrame()->IsInPlace();
458 if ( bOle || !SvtModuleOptions().IsChart() )
459 rSet.DisableItem( nWhich );
461 break;
463 case SID_OBJECT_SELECT: // wichtig fuer den ollen Control-Controller
464 rSet.Put( SfxBoolItem( nWhich, nDrawSfxId == SID_OBJECT_SELECT && IsDrawSelMode() ) );
465 break;
467 nWhich = aIter.NextWhich();
471 BOOL ScTabViewShell::SelectObject( const String& rName )
473 ScDrawView* pView = GetViewData()->GetScDrawView();
474 if (!pView)
475 return FALSE;
477 BOOL bFound = pView->SelectObject( rName );
478 // DrawShell etc. is handled in MarkListHasChanged
480 return bFound;