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