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 "fuinsert.hxx"
40 : #include "global.hxx"
41 : #include "sc.hrc"
42 : #include "scmod.hxx"
43 : #include "appoptio.hxx"
44 : #include <gridwin.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 772 : void ScTabViewShell::WindowChanged()
58 : {
59 772 : vcl::Window* pWin = GetActiveWin();
60 :
61 772 : ScDrawView* pDrView = GetScDrawView();
62 772 : if (pDrView)
63 772 : pDrView->SetActualWin(pWin);
64 :
65 772 : FuPoor* pFunc = GetDrawFuncPtr();
66 772 : if (pFunc)
67 772 : pFunc->SetWindow(pWin);
68 :
69 : // when font from InputContext is used,
70 : // this must be moved to change of cursor position:
71 772 : UpdateInputContext();
72 772 : }
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 : vcl::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 : // Pseudo-Slots von Draw-Toolbox auswerten
99 : //! wird das ueberhaupt noch gebraucht ?????
100 :
101 0 : if (nNewId == SID_INSERT_DRAW && pArgs)
102 : {
103 : const SfxPoolItem* pItem;
104 0 : if ( pArgs->GetItemState( SID_INSERT_DRAW, true, &pItem ) == SfxItemState::SET &&
105 0 : pItem->ISA( SvxDrawToolItem ) )
106 : {
107 0 : SvxDrawToolEnum eSel = (SvxDrawToolEnum)static_cast<const SvxDrawToolItem*>(pItem)->GetValue();
108 0 : switch (eSel)
109 : {
110 0 : case SVX_SNAP_DRAW_SELECT: nNewId = SID_OBJECT_SELECT; break;
111 0 : case SVX_SNAP_DRAW_LINE: nNewId = SID_DRAW_LINE; break;
112 0 : case SVX_SNAP_DRAW_RECT: nNewId = SID_DRAW_RECT; break;
113 0 : case SVX_SNAP_DRAW_ELLIPSE: nNewId = SID_DRAW_ELLIPSE; break;
114 0 : case SVX_SNAP_DRAW_POLYGON_NOFILL: nNewId = SID_DRAW_POLYGON_NOFILL; break;
115 0 : case SVX_SNAP_DRAW_BEZIER_NOFILL: nNewId = SID_DRAW_BEZIER_NOFILL; break;
116 0 : case SVX_SNAP_DRAW_FREELINE_NOFILL: nNewId = SID_DRAW_FREELINE_NOFILL; break;
117 0 : case SVX_SNAP_DRAW_ARC: nNewId = SID_DRAW_ARC; break;
118 0 : case SVX_SNAP_DRAW_PIE: nNewId = SID_DRAW_PIE; break;
119 0 : case SVX_SNAP_DRAW_CIRCLECUT: nNewId = SID_DRAW_CIRCLECUT; break;
120 0 : case SVX_SNAP_DRAW_TEXT: nNewId = SID_DRAW_TEXT; break;
121 0 : case SVX_SNAP_DRAW_TEXT_VERTICAL: nNewId = SID_DRAW_TEXT_VERTICAL; break;
122 0 : case SVX_SNAP_DRAW_TEXT_MARQUEE: nNewId = SID_DRAW_TEXT_MARQUEE; break;
123 0 : case SVX_SNAP_DRAW_CAPTION: nNewId = SID_DRAW_CAPTION; break;
124 0 : case SVX_SNAP_DRAW_CAPTION_VERTICAL: nNewId = SID_DRAW_CAPTION_VERTICAL; break;
125 : }
126 : }
127 : else // sal_uInt16-Item vom Controller
128 : {
129 0 : rReq.Done();
130 0 : return;
131 : }
132 : }
133 :
134 0 : if ( nNewId == SID_DRAW_SELECT )
135 0 : nNewId = SID_OBJECT_SELECT;
136 :
137 0 : sal_uInt16 nNewFormId = 0;
138 0 : if ( nNewId == SID_FM_CREATE_CONTROL && pArgs )
139 : {
140 : const SfxPoolItem* pItem;
141 0 : if ( pArgs->GetItemState( SID_FM_CONTROL_IDENTIFIER, true, &pItem ) == SfxItemState::SET &&
142 0 : pItem->ISA( SfxUInt16Item ) )
143 0 : nNewFormId = static_cast<const SfxUInt16Item*>(pItem)->GetValue();
144 : }
145 :
146 0 : OUString sStringItemValue;
147 0 : if ( pArgs )
148 : {
149 : const SfxPoolItem* pItem;
150 0 : if ( pArgs->GetItemState( nNewId, true, &pItem ) == SfxItemState::SET && pItem->ISA( SfxStringItem ) )
151 0 : sStringItemValue = static_cast<const SfxStringItem*>(pItem)->GetValue();
152 : }
153 0 : bool bSwitchCustom = ( !sStringItemValue.isEmpty() && !sDrawCustom.isEmpty() && sStringItemValue != sDrawCustom );
154 :
155 0 : if (nNewId == SID_INSERT_FRAME) // vom Tbx-Button
156 0 : nNewId = SID_DRAW_TEXT;
157 :
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 0 : bool bSelectFirst = ( nNewId == SID_OBJECT_SELECT && (rReq.GetModifier() & KEY_MOD1) );
162 :
163 0 : bool bEx = IsDrawSelMode();
164 0 : if ( rReq.GetModifier() & KEY_MOD1 )
165 : {
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 0 : bEx = true;
170 : }
171 0 : else if ( nNewId == nDrawSfxId && ( nNewId != SID_FM_CREATE_CONTROL ||
172 0 : nNewFormId == nFormSfxId || nNewFormId == 0 ) && !bSwitchCustom )
173 : {
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.
176 :
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 0 : if ( nNewId == SID_FM_CREATE_CONTROL )
181 : {
182 0 : GetViewData().GetDispatcher().Execute(SID_FM_LEAVE_CREATE);
183 0 : GetViewFrame()->GetBindings().InvalidateAll(false);
184 : //! was fuer einen Slot braucht der komische Controller wirklich, um das anzuzeigen????
185 : }
186 :
187 0 : bEx = !bEx;
188 0 : nNewId = SID_OBJECT_SELECT;
189 : }
190 : else
191 0 : bEx = true;
192 :
193 0 : if ( nDrawSfxId == SID_FM_CREATE_CONTROL && nNewId != nDrawSfxId )
194 : {
195 : // Wechsel von Control- zu Zeichenfunktion -> im Control-Controller deselektieren
196 0 : GetViewData().GetDispatcher().Execute(SID_FM_LEAVE_CREATE);
197 0 : GetViewFrame()->GetBindings().InvalidateAll(false);
198 : //! was fuer einen Slot braucht der komische Controller wirklich, um das anzuzeigen????
199 : }
200 :
201 0 : SetDrawSelMode(bEx);
202 :
203 0 : pView->LockBackgroundLayer( !bEx );
204 :
205 0 : if ( bSelectFirst )
206 : {
207 : // select first draw object if none is selected yet
208 0 : if(!pView->AreObjectsMarked())
209 : {
210 : // select first object
211 0 : pView->UnmarkAllObj();
212 0 : pView->MarkNextObj(true);
213 :
214 : // ...and make it visible
215 0 : if(pView->AreObjectsMarked())
216 0 : pView->MakeVisible(pView->GetAllMarkedRect(), *pWin);
217 : }
218 : }
219 :
220 0 : nDrawSfxId = nNewId;
221 0 : sDrawCustom = ""; // value is set below for custom shapes
222 :
223 0 : if ( nNewId != SID_DRAW_CHART ) // Chart nicht mit DrawShell
224 : {
225 0 : if ( nNewId == SID_DRAW_TEXT || nNewId == SID_DRAW_TEXT_VERTICAL ||
226 0 : nNewId == SID_DRAW_TEXT_MARQUEE || nNewId == SID_DRAW_NOTEEDIT )
227 0 : SetDrawTextShell( true );
228 : else
229 : {
230 0 : if ( bEx || pView->GetMarkedObjectList().GetMarkCount() != 0 )
231 0 : SetDrawShellOrSub();
232 : else
233 0 : SetDrawShell( false );
234 : }
235 : }
236 :
237 0 : if (pTabView->GetDrawFuncPtr())
238 : {
239 0 : if (pTabView->GetDrawFuncOldPtr() != pTabView->GetDrawFuncPtr())
240 0 : delete pTabView->GetDrawFuncOldPtr();
241 :
242 0 : pTabView->GetDrawFuncPtr()->Deactivate();
243 0 : pTabView->SetDrawFuncOldPtr(pTabView->GetDrawFuncPtr());
244 0 : pTabView->SetDrawFuncPtr(NULL);
245 : }
246 :
247 0 : SfxRequest aNewReq(rReq);
248 0 : aNewReq.SetSlot(nDrawSfxId);
249 :
250 : assert(nNewId != SID_DRAW_CHART); //#i71254# handled already above
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_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 :
306 : {
307 0 : pTabView->SetDrawFuncPtr( new FuConstCustomShape( this, pWin, pView, pDoc, aNewReq ));
308 0 : if ( nNewId != SID_DRAW_CS_ID )
309 : {
310 0 : SFX_REQUEST_ARG( rReq, pEnumCommand, SfxStringItem, nNewId, false );
311 0 : if ( pEnumCommand )
312 : {
313 0 : aCurrShapeEnumCommand[ nNewId - SID_DRAWTBX_CS_BASIC ] = pEnumCommand->GetValue();
314 0 : SfxBindings& rBind = GetViewFrame()->GetBindings();
315 0 : rBind.Invalidate( nNewId );
316 0 : rBind.Update( nNewId );
317 :
318 0 : sDrawCustom = pEnumCommand->GetValue(); // to detect when a different shape type is selected
319 : }
320 : }
321 : }
322 0 : break;
323 :
324 : default:
325 0 : break;
326 : }
327 :
328 0 : if (pTabView->GetDrawFuncPtr())
329 0 : pTabView->GetDrawFuncPtr()->Activate();
330 :
331 0 : rReq.Done();
332 :
333 0 : rBindings.Invalidate( SID_INSERT_DRAW );
334 0 : rBindings.Update( SID_INSERT_DRAW );
335 :
336 : // Create default drawing objects via keyboard
337 : // with qualifier construct directly
338 0 : FuPoor* pFuActual = GetDrawFuncPtr();
339 :
340 0 : if(pFuActual && (rReq.GetModifier() & KEY_MOD1))
341 : {
342 : // Create default drawing objects via keyboard
343 0 : const ScAppOptions& rAppOpt = SC_MOD()->GetAppOptions();
344 0 : sal_uInt32 nDefaultObjectSizeWidth = rAppOpt.GetDefaultObjectSizeWidth();
345 0 : sal_uInt32 nDefaultObjectSizeHeight = rAppOpt.GetDefaultObjectSizeHeight();
346 :
347 : // calc position and size
348 0 : Rectangle aVisArea = pWin->PixelToLogic(Rectangle(Point(0,0), pWin->GetOutputSizePixel()));
349 0 : Point aPagePos = aVisArea.Center();
350 0 : aPagePos.X() -= nDefaultObjectSizeWidth / 2;
351 0 : aPagePos.Y() -= nDefaultObjectSizeHeight / 2;
352 0 : Rectangle aNewObjectRectangle(aPagePos, Size(nDefaultObjectSizeWidth, nDefaultObjectSizeHeight));
353 :
354 0 : ScDrawView* pDrView = GetScDrawView();
355 :
356 0 : if(pDrView)
357 : {
358 0 : SdrPageView* pPageView = pDrView->GetSdrPageView();
359 :
360 0 : if(pPageView)
361 : {
362 : // create the default object
363 0 : SdrObject* pObj = pFuActual->CreateDefaultObject(nNewId, aNewObjectRectangle);
364 :
365 0 : if(pObj)
366 : {
367 : // insert into page
368 0 : pView->InsertObjectAtView(pObj, *pPageView);
369 :
370 0 : if ( nNewId == SID_DRAW_CAPTION || nNewId == SID_DRAW_CAPTION_VERTICAL )
371 : {
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.
375 :
376 0 : pFuActual->KeyInput( KeyEvent( 0, vcl::KeyCode( KEY_F2 ) ) );
377 : }
378 : }
379 : }
380 : }
381 0 : }
382 : }
383 :
384 242 : void ScTabViewShell::GetDrawState(SfxItemSet &rSet)
385 : {
386 242 : SfxWhichIter aIter(rSet);
387 242 : sal_uInt16 nWhich = aIter.FirstWhich();
388 :
389 726 : while ( nWhich )
390 : {
391 242 : switch ( nWhich )
392 : {
393 : case SID_INSERT_DRAW:
394 : {
395 : // SID_OBJECT_SELECT nur, wenn "harter" Selektionsmodus
396 242 : sal_uInt16 nPutId = nDrawSfxId;
397 242 : if ( nPutId == SID_OBJECT_SELECT && !IsDrawSelMode() )
398 0 : nPutId = USHRT_MAX;
399 : // nur die Images, die auch auf dem Controller liegen
400 242 : if ( nPutId != SID_OBJECT_SELECT &&
401 242 : nPutId != SID_DRAW_LINE &&
402 242 : nPutId != SID_DRAW_RECT &&
403 242 : nPutId != SID_DRAW_ELLIPSE &&
404 242 : nPutId != SID_DRAW_POLYGON_NOFILL &&
405 242 : nPutId != SID_DRAW_BEZIER_NOFILL &&
406 242 : nPutId != SID_DRAW_FREELINE_NOFILL &&
407 242 : nPutId != SID_DRAW_ARC &&
408 242 : nPutId != SID_DRAW_PIE &&
409 242 : nPutId != SID_DRAW_CIRCLECUT &&
410 242 : nPutId != SID_DRAW_TEXT &&
411 242 : nPutId != SID_DRAW_TEXT_VERTICAL &&
412 242 : nPutId != SID_DRAW_TEXT_MARQUEE &&
413 242 : nPutId != SID_DRAW_CAPTION &&
414 : nPutId != SID_DRAW_CAPTION_VERTICAL )
415 242 : nPutId = USHRT_MAX;
416 242 : SfxAllEnumItem aItem( nWhich, nPutId );
417 242 : if ( !SvtLanguageOptions().IsVerticalTextEnabled() )
418 : {
419 0 : aItem.DisableValue( SID_DRAW_TEXT_VERTICAL );
420 0 : aItem.DisableValue( SID_DRAW_CAPTION_VERTICAL );
421 : }
422 242 : rSet.Put( aItem );
423 : }
424 242 : break;
425 :
426 : case SID_DRAW_CHART:
427 : {
428 0 : bool bOle = GetViewFrame()->GetFrame().IsInPlace();
429 0 : if ( bOle || !SvtModuleOptions().IsChart() )
430 0 : rSet.DisableItem( nWhich );
431 : }
432 0 : break;
433 :
434 : case SID_OBJECT_SELECT: // wichtig fuer den ollen Control-Controller
435 0 : rSet.Put( SfxBoolItem( nWhich, nDrawSfxId == SID_OBJECT_SELECT && IsDrawSelMode() ) );
436 0 : break;
437 : }
438 242 : nWhich = aIter.NextWhich();
439 242 : }
440 242 : }
441 :
442 0 : bool ScTabViewShell::SelectObject( const OUString& rName )
443 : {
444 0 : ScDrawView* pView = GetViewData().GetScDrawView();
445 0 : if (!pView)
446 0 : return false;
447 :
448 0 : bool bFound = pView->SelectObject( rName );
449 : // DrawShell etc. is handled in MarkListHasChanged
450 :
451 0 : return bFound;
452 228 : }
453 :
454 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|