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