Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
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>
27 :
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"
45 :
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>
51 :
52 0 : SdrView* ScTabViewShell::GetDrawView() const
53 : {
54 0 : return ((ScTabViewShell*)this)->GetScDrawView(); // GetScDrawView ist nicht-const
55 : }
56 :
57 0 : void ScTabViewShell::WindowChanged()
58 : {
59 0 : Window* pWin = GetActiveWin();
60 :
61 0 : ScDrawView* pDrView = GetScDrawView();
62 0 : if (pDrView)
63 0 : pDrView->SetActualWin(pWin);
64 :
65 0 : FuPoor* pFunc = GetDrawFuncPtr();
66 0 : if (pFunc)
67 0 : pFunc->SetWindow(pWin);
68 :
69 : // when font from InputContext is used,
70 : // this must be moved to change of cursor position:
71 0 : UpdateInputContext();
72 0 : }
73 :
74 0 : void ScTabViewShell::ExecDraw(SfxRequest& rReq)
75 : {
76 0 : SC_MOD()->InputEnterHandler();
77 0 : UpdateInputHandler();
78 :
79 0 : MakeDrawLayer();
80 :
81 0 : ScTabView* pTabView = GetViewData()->GetView();
82 0 : SfxBindings& rBindings = GetViewFrame()->GetBindings();
83 :
84 0 : Window* pWin = pTabView->GetActiveWin();
85 0 : ScDrawView* pView = pTabView->GetScDrawView();
86 0 : SdrModel* pDoc = pView->GetModel();
87 :
88 0 : const SfxItemSet *pArgs = rReq.GetArgs();
89 0 : sal_uInt16 nNewId = rReq.GetSlot();
90 :
91 0 : if ( nNewId == SID_DRAW_CHART )
92 : {
93 : // #i71254# directly insert a chart instead of drawing its output rectangle
94 0 : FuInsertChart(this, pWin, pView, pDoc, rReq);
95 0 : return;
96 : }
97 :
98 :
99 : // Pseudo-Slots von Draw-Toolbox auswerten
100 : //! wird das ueberhaupt noch gebraucht ?????
101 :
102 :
103 0 : if (nNewId == SID_INSERT_DRAW && pArgs)
104 : {
105 : const SfxPoolItem* pItem;
106 0 : if ( pArgs->GetItemState( SID_INSERT_DRAW, true, &pItem ) == SFX_ITEM_SET &&
107 0 : pItem->ISA( SvxDrawToolItem ) )
108 : {
109 0 : SvxDrawToolEnum eSel = (SvxDrawToolEnum)((const SvxDrawToolItem*)pItem)->GetValue();
110 0 : switch (eSel)
111 : {
112 0 : case SVX_SNAP_DRAW_SELECT: nNewId = SID_OBJECT_SELECT; break;
113 0 : case SVX_SNAP_DRAW_LINE: nNewId = SID_DRAW_LINE; break;
114 0 : case SVX_SNAP_DRAW_RECT: nNewId = SID_DRAW_RECT; break;
115 0 : case SVX_SNAP_DRAW_ELLIPSE: nNewId = SID_DRAW_ELLIPSE; break;
116 0 : case SVX_SNAP_DRAW_POLYGON_NOFILL: nNewId = SID_DRAW_POLYGON_NOFILL; break;
117 0 : case SVX_SNAP_DRAW_BEZIER_NOFILL: nNewId = SID_DRAW_BEZIER_NOFILL; break;
118 0 : case SVX_SNAP_DRAW_FREELINE_NOFILL: nNewId = SID_DRAW_FREELINE_NOFILL; break;
119 0 : case SVX_SNAP_DRAW_ARC: nNewId = SID_DRAW_ARC; break;
120 0 : case SVX_SNAP_DRAW_PIE: nNewId = SID_DRAW_PIE; break;
121 0 : case SVX_SNAP_DRAW_CIRCLECUT: nNewId = SID_DRAW_CIRCLECUT; break;
122 0 : case SVX_SNAP_DRAW_TEXT: nNewId = SID_DRAW_TEXT; break;
123 0 : case SVX_SNAP_DRAW_TEXT_VERTICAL: nNewId = SID_DRAW_TEXT_VERTICAL; break;
124 0 : case SVX_SNAP_DRAW_TEXT_MARQUEE: nNewId = SID_DRAW_TEXT_MARQUEE; break;
125 0 : case SVX_SNAP_DRAW_CAPTION: nNewId = SID_DRAW_CAPTION; break;
126 0 : case SVX_SNAP_DRAW_CAPTION_VERTICAL: nNewId = SID_DRAW_CAPTION_VERTICAL; break;
127 : }
128 : }
129 : else // sal_uInt16-Item vom Controller
130 : {
131 0 : rReq.Done();
132 0 : return;
133 : }
134 : }
135 :
136 0 : if ( nNewId == SID_DRAW_SELECT )
137 0 : nNewId = SID_OBJECT_SELECT;
138 :
139 0 : sal_uInt16 nNewFormId = 0;
140 0 : if ( nNewId == SID_FM_CREATE_CONTROL && pArgs )
141 : {
142 : const SfxPoolItem* pItem;
143 0 : if ( pArgs->GetItemState( SID_FM_CONTROL_IDENTIFIER, true, &pItem ) == SFX_ITEM_SET &&
144 0 : pItem->ISA( SfxUInt16Item ) )
145 0 : nNewFormId = ((const SfxUInt16Item*)pItem)->GetValue();
146 : }
147 :
148 0 : OUString sStringItemValue;
149 0 : if ( pArgs )
150 : {
151 : const SfxPoolItem* pItem;
152 0 : if ( pArgs->GetItemState( nNewId, true, &pItem ) == SFX_ITEM_SET && pItem->ISA( SfxStringItem ) )
153 0 : sStringItemValue = static_cast<const SfxStringItem*>(pItem)->GetValue();
154 : }
155 0 : bool bSwitchCustom = ( !sStringItemValue.isEmpty() && !sDrawCustom.isEmpty() && sStringItemValue != sDrawCustom );
156 :
157 0 : if (nNewId == SID_INSERT_FRAME) // vom Tbx-Button
158 0 : nNewId = SID_DRAW_TEXT;
159 :
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 0 : bool bSelectFirst = ( nNewId == SID_OBJECT_SELECT && (rReq.GetModifier() & KEY_MOD1) );
164 :
165 0 : bool bEx = IsDrawSelMode();
166 0 : if ( rReq.GetModifier() & KEY_MOD1 )
167 : {
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
171 0 : bEx = true;
172 : }
173 0 : else if ( nNewId == nDrawSfxId && ( nNewId != SID_FM_CREATE_CONTROL ||
174 0 : nNewFormId == nFormSfxId || nNewFormId == 0 ) && !bSwitchCustom )
175 : {
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.
178 :
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 0 : if ( nNewId == SID_FM_CREATE_CONTROL )
183 : {
184 0 : GetViewData()->GetDispatcher().Execute(SID_FM_LEAVE_CREATE);
185 0 : GetViewFrame()->GetBindings().InvalidateAll(false);
186 : //! was fuer einen Slot braucht der komische Controller wirklich, um das anzuzeigen????
187 : }
188 :
189 0 : bEx = !bEx;
190 0 : nNewId = SID_OBJECT_SELECT;
191 : }
192 : else
193 0 : bEx = true;
194 :
195 0 : if ( nDrawSfxId == SID_FM_CREATE_CONTROL && nNewId != nDrawSfxId )
196 : {
197 : // Wechsel von Control- zu Zeichenfunktion -> im Control-Controller deselektieren
198 0 : GetViewData()->GetDispatcher().Execute(SID_FM_LEAVE_CREATE);
199 0 : GetViewFrame()->GetBindings().InvalidateAll(false);
200 : //! was fuer einen Slot braucht der komische Controller wirklich, um das anzuzeigen????
201 : }
202 :
203 0 : SetDrawSelMode(bEx);
204 :
205 0 : pView->LockBackgroundLayer( !bEx );
206 :
207 0 : if ( bSelectFirst )
208 : {
209 : // select first draw object if none is selected yet
210 0 : if(!pView->AreObjectsMarked())
211 : {
212 : // select first object
213 0 : pView->UnmarkAllObj();
214 0 : pView->MarkNextObj(true);
215 :
216 : // ...and make it visible
217 0 : if(pView->AreObjectsMarked())
218 0 : pView->MakeVisible(pView->GetAllMarkedRect(), *pWin);
219 : }
220 : }
221 :
222 0 : nDrawSfxId = nNewId;
223 0 : sDrawCustom = ""; // value is set below for custom shapes
224 :
225 0 : if ( nNewId != SID_DRAW_CHART ) // Chart nicht mit DrawShell
226 : {
227 0 : if ( nNewId == SID_DRAW_TEXT || nNewId == SID_DRAW_TEXT_VERTICAL ||
228 0 : nNewId == SID_DRAW_TEXT_MARQUEE || nNewId == SID_DRAW_NOTEEDIT )
229 0 : SetDrawTextShell( true );
230 : else
231 : {
232 0 : if ( bEx || pView->GetMarkedObjectList().GetMarkCount() != 0 )
233 0 : SetDrawShellOrSub();
234 : else
235 0 : SetDrawShell( false );
236 : }
237 : }
238 :
239 0 : if (pTabView->GetDrawFuncPtr())
240 : {
241 0 : if (pTabView->GetDrawFuncOldPtr() != pTabView->GetDrawFuncPtr())
242 0 : delete pTabView->GetDrawFuncOldPtr();
243 :
244 0 : pTabView->GetDrawFuncPtr()->Deactivate();
245 0 : pTabView->SetDrawFuncOldPtr(pTabView->GetDrawFuncPtr());
246 0 : pTabView->SetDrawFuncPtr(NULL);
247 : }
248 :
249 0 : SfxRequest aNewReq(rReq);
250 0 : aNewReq.SetSlot(nDrawSfxId);
251 :
252 0 : switch (nNewId)
253 : {
254 : case SID_OBJECT_SELECT:
255 : // Nicht immer zurueckschalten
256 0 : if(pView->GetMarkedObjectList().GetMarkCount() == 0) SetDrawShell(bEx);
257 0 : pTabView->SetDrawFuncPtr(new FuSelection(this, pWin, pView, pDoc, aNewReq));
258 0 : break;
259 :
260 : case SID_DRAW_LINE:
261 : case SID_DRAW_RECT:
262 : case SID_DRAW_ELLIPSE:
263 0 : pTabView->SetDrawFuncPtr(new FuConstRectangle(this, pWin, pView, pDoc, aNewReq));
264 0 : break;
265 :
266 : case SID_DRAW_CAPTION:
267 : case SID_DRAW_CAPTION_VERTICAL:
268 0 : pTabView->SetDrawFuncPtr(new FuConstRectangle(this, pWin, pView, pDoc, aNewReq));
269 0 : pView->SetFrameDragSingles( false );
270 0 : rBindings.Invalidate( SID_BEZIER_EDIT );
271 0 : break;
272 :
273 : case SID_DRAW_POLYGON:
274 : case SID_DRAW_POLYGON_NOFILL:
275 : case SID_DRAW_BEZIER_NOFILL:
276 : case SID_DRAW_FREELINE_NOFILL:
277 0 : pTabView->SetDrawFuncPtr(new FuConstPolygon(this, pWin, pView, pDoc, aNewReq));
278 0 : break;
279 :
280 : case SID_DRAW_ARC:
281 : case SID_DRAW_PIE:
282 : case SID_DRAW_CIRCLECUT:
283 0 : pTabView->SetDrawFuncPtr(new FuConstArc(this, pWin, pView, pDoc, aNewReq));
284 0 : break;
285 :
286 : case SID_DRAW_TEXT:
287 : case SID_DRAW_TEXT_VERTICAL:
288 : case SID_DRAW_TEXT_MARQUEE:
289 : case SID_DRAW_NOTEEDIT:
290 0 : pTabView->SetDrawFuncPtr(new FuText(this, pWin, pView, pDoc, aNewReq));
291 0 : break;
292 :
293 : case SID_FM_CREATE_CONTROL:
294 0 : SetDrawFormShell(true);
295 0 : pTabView->SetDrawFuncPtr(new FuConstUnoControl(this, pWin, pView, pDoc, aNewReq));
296 0 : nFormSfxId = nNewFormId;
297 0 : break;
298 :
299 : case SID_DRAW_CHART:
300 0 : pTabView->SetDrawFuncPtr(new FuMarkRect(this, pWin, pView, pDoc, aNewReq));
301 0 : break;
302 :
303 : case SID_DRAWTBX_CS_BASIC :
304 : case SID_DRAWTBX_CS_SYMBOL :
305 : case SID_DRAWTBX_CS_ARROW :
306 : case SID_DRAWTBX_CS_FLOWCHART :
307 : case SID_DRAWTBX_CS_CALLOUT :
308 : case SID_DRAWTBX_CS_STAR :
309 : case SID_DRAW_CS_ID :
310 : {
311 0 : pTabView->SetDrawFuncPtr( new FuConstCustomShape( this, pWin, pView, pDoc, aNewReq ));
312 0 : if ( nNewId != SID_DRAW_CS_ID )
313 : {
314 0 : SFX_REQUEST_ARG( rReq, pEnumCommand, SfxStringItem, nNewId, false );
315 0 : if ( pEnumCommand )
316 : {
317 0 : aCurrShapeEnumCommand[ nNewId - SID_DRAWTBX_CS_BASIC ] = pEnumCommand->GetValue();
318 0 : SfxBindings& rBind = GetViewFrame()->GetBindings();
319 0 : rBind.Invalidate( nNewId );
320 0 : rBind.Update( nNewId );
321 :
322 0 : sDrawCustom = pEnumCommand->GetValue(); // to detect when a different shape type is selected
323 : }
324 : }
325 : }
326 0 : break;
327 :
328 : default:
329 0 : break;
330 : }
331 :
332 0 : if (pTabView->GetDrawFuncPtr())
333 0 : pTabView->GetDrawFuncPtr()->Activate();
334 :
335 0 : rReq.Done();
336 :
337 0 : rBindings.Invalidate( SID_INSERT_DRAW );
338 0 : rBindings.Update( SID_INSERT_DRAW );
339 :
340 : // Create default drawing objects via keyboard
341 : // with qualifier construct directly
342 0 : FuPoor* pFuActual = GetDrawFuncPtr();
343 :
344 0 : if(pFuActual && (rReq.GetModifier() & KEY_MOD1))
345 : {
346 : // Create default drawing objects via keyboard
347 0 : const ScAppOptions& rAppOpt = SC_MOD()->GetAppOptions();
348 0 : sal_uInt32 nDefaultObjectSizeWidth = rAppOpt.GetDefaultObjectSizeWidth();
349 0 : sal_uInt32 nDefaultObjectSizeHeight = rAppOpt.GetDefaultObjectSizeHeight();
350 :
351 : // calc position and size
352 0 : Rectangle aVisArea = pWin->PixelToLogic(Rectangle(Point(0,0), pWin->GetOutputSizePixel()));
353 0 : Point aPagePos = aVisArea.Center();
354 0 : aPagePos.X() -= nDefaultObjectSizeWidth / 2;
355 0 : aPagePos.Y() -= nDefaultObjectSizeHeight / 2;
356 0 : Rectangle aNewObjectRectangle(aPagePos, Size(nDefaultObjectSizeWidth, nDefaultObjectSizeHeight));
357 :
358 0 : ScDrawView* pDrView = GetScDrawView();
359 :
360 0 : if(pDrView)
361 : {
362 0 : SdrPageView* pPageView = pDrView->GetSdrPageView();
363 :
364 0 : if(pPageView)
365 : {
366 : // create the default object
367 0 : SdrObject* pObj = pFuActual->CreateDefaultObject(nNewId, aNewObjectRectangle);
368 :
369 0 : if(pObj)
370 : {
371 : // insert into page
372 0 : pView->InsertObjectAtView(pObj, *pPageView);
373 :
374 0 : if ( nNewId == SID_DRAW_CAPTION || nNewId == SID_DRAW_CAPTION_VERTICAL )
375 : {
376 : // use KeyInput to start edit mode (FuText is created).
377 : // For FuText objects, edit mode is handled within CreateDefaultObject.
378 : // KEY_F2 is handled in FuDraw::KeyInput.
379 :
380 0 : pFuActual->KeyInput( KeyEvent( 0, KeyCode( KEY_F2 ) ) );
381 : }
382 : }
383 : }
384 : }
385 0 : }
386 : }
387 :
388 0 : void ScTabViewShell::GetDrawState(SfxItemSet &rSet)
389 : {
390 0 : SfxWhichIter aIter(rSet);
391 0 : sal_uInt16 nWhich = aIter.FirstWhich();
392 :
393 0 : while ( nWhich )
394 : {
395 0 : switch ( nWhich )
396 : {
397 : case SID_INSERT_DRAW:
398 : {
399 : // SID_OBJECT_SELECT nur, wenn "harter" Selektionsmodus
400 0 : sal_uInt16 nPutId = nDrawSfxId;
401 0 : if ( nPutId == SID_OBJECT_SELECT && !IsDrawSelMode() )
402 0 : nPutId = USHRT_MAX;
403 : // nur die Images, die auch auf dem Controller liegen
404 0 : if ( nPutId != SID_OBJECT_SELECT &&
405 0 : nPutId != SID_DRAW_LINE &&
406 0 : nPutId != SID_DRAW_RECT &&
407 0 : nPutId != SID_DRAW_ELLIPSE &&
408 0 : nPutId != SID_DRAW_POLYGON_NOFILL &&
409 0 : nPutId != SID_DRAW_BEZIER_NOFILL &&
410 0 : nPutId != SID_DRAW_FREELINE_NOFILL &&
411 0 : nPutId != SID_DRAW_ARC &&
412 0 : nPutId != SID_DRAW_PIE &&
413 0 : nPutId != SID_DRAW_CIRCLECUT &&
414 0 : nPutId != SID_DRAW_TEXT &&
415 0 : nPutId != SID_DRAW_TEXT_VERTICAL &&
416 0 : nPutId != SID_DRAW_TEXT_MARQUEE &&
417 0 : nPutId != SID_DRAW_CAPTION &&
418 : nPutId != SID_DRAW_CAPTION_VERTICAL )
419 0 : nPutId = USHRT_MAX;
420 0 : SfxAllEnumItem aItem( nWhich, nPutId );
421 0 : if ( !SvtLanguageOptions().IsVerticalTextEnabled() )
422 : {
423 0 : aItem.DisableValue( SID_DRAW_TEXT_VERTICAL );
424 0 : aItem.DisableValue( SID_DRAW_CAPTION_VERTICAL );
425 : }
426 0 : rSet.Put( aItem );
427 : }
428 0 : break;
429 :
430 : case SID_DRAW_CHART:
431 : {
432 0 : bool bOle = GetViewFrame()->GetFrame().IsInPlace();
433 0 : if ( bOle || !SvtModuleOptions().IsChart() )
434 0 : rSet.DisableItem( nWhich );
435 : }
436 0 : break;
437 :
438 : case SID_OBJECT_SELECT: // wichtig fuer den ollen Control-Controller
439 0 : rSet.Put( SfxBoolItem( nWhich, nDrawSfxId == SID_OBJECT_SELECT && IsDrawSelMode() ) );
440 0 : break;
441 : }
442 0 : nWhich = aIter.NextWhich();
443 0 : }
444 0 : }
445 :
446 0 : bool ScTabViewShell::SelectObject( const OUString& rName )
447 : {
448 0 : ScDrawView* pView = GetViewData()->GetScDrawView();
449 0 : if (!pView)
450 0 : return false;
451 :
452 0 : bool bFound = pView->SelectObject( rName );
453 : // DrawShell etc. is handled in MarkListHasChanged
454 :
455 0 : return bFound;
456 0 : }
457 :
458 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|