xref: /trunk/main/sc/source/ui/drawfunc/fuconpol.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b3f79822SAndrew Rist  * distributed with this work for additional information
6*b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b3f79822SAndrew Rist  * specific language governing permissions and limitations
18*b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*b3f79822SAndrew Rist  *************************************************************/
21*b3f79822SAndrew Rist 
22*b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "fuconpol.hxx"
28cdf0e10cSrcweir #include "tabvwsh.hxx"
29cdf0e10cSrcweir #include "sc.hrc"
30cdf0e10cSrcweir #include "drawview.hxx"
31cdf0e10cSrcweir 
32cdf0e10cSrcweir // #98185# Create default drawing objects via keyboard
33cdf0e10cSrcweir #include <svx/svdopath.hxx>
34cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
35cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //  Pixelabstand zum Schliessen von Freihand-Zeichnungen
38cdf0e10cSrcweir #ifndef CLOSE_PIXDIST
39cdf0e10cSrcweir #define CLOSE_PIXDIST 5
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //------------------------------------------------------------------------
43cdf0e10cSrcweir 
44cdf0e10cSrcweir /*************************************************************************
45cdf0e10cSrcweir |*
46cdf0e10cSrcweir |* Konstruktor
47cdf0e10cSrcweir |*
48cdf0e10cSrcweir \************************************************************************/
49cdf0e10cSrcweir 
FuConstPolygon(ScTabViewShell * pViewSh,Window * pWin,ScDrawView * pViewP,SdrModel * pDoc,SfxRequest & rReq)50cdf0e10cSrcweir FuConstPolygon::FuConstPolygon(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
51cdf0e10cSrcweir                    SdrModel* pDoc, SfxRequest& rReq)
52cdf0e10cSrcweir     : FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq)
53cdf0e10cSrcweir {
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir /*************************************************************************
57cdf0e10cSrcweir |*
58cdf0e10cSrcweir |* Destruktor
59cdf0e10cSrcweir |*
60cdf0e10cSrcweir \************************************************************************/
61cdf0e10cSrcweir 
~FuConstPolygon()62cdf0e10cSrcweir FuConstPolygon::~FuConstPolygon()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir /*************************************************************************
67cdf0e10cSrcweir |*
68cdf0e10cSrcweir |* MouseButtonDown-event
69cdf0e10cSrcweir |*
70cdf0e10cSrcweir \************************************************************************/
71cdf0e10cSrcweir 
MouseButtonDown(const MouseEvent & rMEvt)72cdf0e10cSrcweir sal_Bool __EXPORT FuConstPolygon::MouseButtonDown(const MouseEvent& rMEvt)
73cdf0e10cSrcweir {
74cdf0e10cSrcweir     // #95491# remember button state for creation of own MouseEvents
75cdf0e10cSrcweir     SetMouseButtonCode(rMEvt.GetButtons());
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     SdrViewEvent aVEvt;
80cdf0e10cSrcweir     (void)pView->PickAnything(rMEvt, SDRMOUSEBUTTONDOWN, aVEvt);
81cdf0e10cSrcweir     if (aVEvt.eEvent == SDREVENT_BEGTEXTEDIT)
82cdf0e10cSrcweir     {
83cdf0e10cSrcweir         // Texteingabe hier nicht zulassen
84cdf0e10cSrcweir         aVEvt.eEvent = SDREVENT_BEGDRAGOBJ;
85cdf0e10cSrcweir         pView->EnableExtendedMouseEventDispatcher(sal_False);
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir     else
88cdf0e10cSrcweir     {
89cdf0e10cSrcweir         pView->EnableExtendedMouseEventDispatcher(sal_True);
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     if ( pView->MouseButtonDown(rMEvt, pWindow) )
93cdf0e10cSrcweir         bReturn = sal_True;
94cdf0e10cSrcweir 
95cdf0e10cSrcweir     return bReturn;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir /*************************************************************************
99cdf0e10cSrcweir |*
100cdf0e10cSrcweir |* MouseMove-event
101cdf0e10cSrcweir |*
102cdf0e10cSrcweir \************************************************************************/
103cdf0e10cSrcweir 
MouseMove(const MouseEvent & rMEvt)104cdf0e10cSrcweir sal_Bool __EXPORT FuConstPolygon::MouseMove(const MouseEvent& rMEvt)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir     pView->MouseMove(rMEvt, pWindow);
107cdf0e10cSrcweir     sal_Bool bReturn = FuConstruct::MouseMove(rMEvt);
108cdf0e10cSrcweir     return bReturn;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir /*************************************************************************
112cdf0e10cSrcweir |*
113cdf0e10cSrcweir |* MouseButtonUp-event
114cdf0e10cSrcweir |*
115cdf0e10cSrcweir \************************************************************************/
116cdf0e10cSrcweir 
MouseButtonUp(const MouseEvent & rMEvt)117cdf0e10cSrcweir sal_Bool __EXPORT FuConstPolygon::MouseButtonUp(const MouseEvent& rMEvt)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir     // #95491# remember button state for creation of own MouseEvents
120cdf0e10cSrcweir     SetMouseButtonCode(rMEvt.GetButtons());
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     sal_Bool bReturn = sal_False;
123cdf0e10cSrcweir     sal_Bool bSimple = sal_False;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     SdrViewEvent aVEvt;
126cdf0e10cSrcweir     (void)pView->PickAnything(rMEvt, SDRMOUSEBUTTONUP, aVEvt);
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     pView->MouseButtonUp(rMEvt, pWindow);
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     if (aVEvt.eEvent == SDREVENT_ENDCREATE)
131cdf0e10cSrcweir     {
132cdf0e10cSrcweir         bReturn = sal_True;
133cdf0e10cSrcweir         bSimple = sal_True;         // Doppelklick nicht weiterreichen
134cdf0e10cSrcweir     }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     sal_Bool bParent;
137cdf0e10cSrcweir     if (bSimple)
138cdf0e10cSrcweir         bParent = FuConstruct::SimpleMouseButtonUp(rMEvt);
139cdf0e10cSrcweir     else
140cdf0e10cSrcweir         bParent = FuConstruct::MouseButtonUp(rMEvt);
141cdf0e10cSrcweir 
142cdf0e10cSrcweir     return (bParent || bReturn);
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir /*************************************************************************
146cdf0e10cSrcweir |*
147cdf0e10cSrcweir |* Tastaturereignisse bearbeiten
148cdf0e10cSrcweir |*
149cdf0e10cSrcweir |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
150cdf0e10cSrcweir |* FALSE.
151cdf0e10cSrcweir |*
152cdf0e10cSrcweir \************************************************************************/
153cdf0e10cSrcweir 
KeyInput(const KeyEvent & rKEvt)154cdf0e10cSrcweir sal_Bool __EXPORT FuConstPolygon::KeyInput(const KeyEvent& rKEvt)
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     return(bReturn);
159cdf0e10cSrcweir }
160cdf0e10cSrcweir 
161cdf0e10cSrcweir /*************************************************************************
162cdf0e10cSrcweir |*
163cdf0e10cSrcweir |* Function aktivieren
164cdf0e10cSrcweir |*
165cdf0e10cSrcweir \************************************************************************/
166cdf0e10cSrcweir 
Activate()167cdf0e10cSrcweir void FuConstPolygon::Activate()
168cdf0e10cSrcweir {
169cdf0e10cSrcweir     pView->EnableExtendedMouseEventDispatcher(sal_True);
170cdf0e10cSrcweir 
171cdf0e10cSrcweir     SdrObjKind eKind;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     switch (GetSlotID())
174cdf0e10cSrcweir     {
175cdf0e10cSrcweir         case SID_DRAW_POLYGON_NOFILL:
176cdf0e10cSrcweir         case SID_DRAW_XPOLYGON_NOFILL:
177cdf0e10cSrcweir         {
178cdf0e10cSrcweir             eKind = OBJ_PLIN;
179cdf0e10cSrcweir         }
180cdf0e10cSrcweir         break;
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         case SID_DRAW_POLYGON:
183cdf0e10cSrcweir         case SID_DRAW_XPOLYGON:
184cdf0e10cSrcweir         {
185cdf0e10cSrcweir             eKind = OBJ_POLY;
186cdf0e10cSrcweir         }
187cdf0e10cSrcweir         break;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         case SID_DRAW_BEZIER_NOFILL:
190cdf0e10cSrcweir         {
191cdf0e10cSrcweir             eKind = OBJ_PATHLINE;
192cdf0e10cSrcweir         }
193cdf0e10cSrcweir         break;
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         case SID_DRAW_BEZIER_FILL:
196cdf0e10cSrcweir         {
197cdf0e10cSrcweir             eKind = OBJ_PATHFILL;
198cdf0e10cSrcweir         }
199cdf0e10cSrcweir         break;
200cdf0e10cSrcweir 
201cdf0e10cSrcweir         case SID_DRAW_FREELINE_NOFILL:
202cdf0e10cSrcweir         {
203cdf0e10cSrcweir             eKind = OBJ_FREELINE;
204cdf0e10cSrcweir         }
205cdf0e10cSrcweir         break;
206cdf0e10cSrcweir 
207cdf0e10cSrcweir         case SID_DRAW_FREELINE:
208cdf0e10cSrcweir         {
209cdf0e10cSrcweir             eKind = OBJ_FREEFILL;
210cdf0e10cSrcweir         }
211cdf0e10cSrcweir         break;
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         default:
214cdf0e10cSrcweir         {
215cdf0e10cSrcweir             eKind = OBJ_PATHLINE;
216cdf0e10cSrcweir         }
217cdf0e10cSrcweir         break;
218cdf0e10cSrcweir     }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     pView->SetCurrentObj(sal::static_int_cast<sal_uInt16>(eKind));
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     pView->SetEditMode(SDREDITMODE_CREATE);
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     FuConstruct::Activate();
225cdf0e10cSrcweir 
226cdf0e10cSrcweir     aNewPointer = Pointer( POINTER_DRAW_POLYGON );
227cdf0e10cSrcweir     aOldPointer = pWindow->GetPointer();
228cdf0e10cSrcweir     pViewShell->SetActivePointer( aNewPointer );
229cdf0e10cSrcweir }
230cdf0e10cSrcweir 
231cdf0e10cSrcweir /*************************************************************************
232cdf0e10cSrcweir |*
233cdf0e10cSrcweir |* Function deaktivieren
234cdf0e10cSrcweir |*
235cdf0e10cSrcweir \************************************************************************/
236cdf0e10cSrcweir 
Deactivate()237cdf0e10cSrcweir void FuConstPolygon::Deactivate()
238cdf0e10cSrcweir {
239cdf0e10cSrcweir     pView->SetEditMode(SDREDITMODE_EDIT);
240cdf0e10cSrcweir 
241cdf0e10cSrcweir     pView->EnableExtendedMouseEventDispatcher(sal_False);
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     FuConstruct::Deactivate();
244cdf0e10cSrcweir 
245cdf0e10cSrcweir     pViewShell->SetActivePointer( aOldPointer );
246cdf0e10cSrcweir }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir // #98185# Create default drawing objects via keyboard
CreateDefaultObject(const sal_uInt16 nID,const Rectangle & rRectangle)249cdf0e10cSrcweir SdrObject* FuConstPolygon::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
250cdf0e10cSrcweir {
251cdf0e10cSrcweir     // case SID_DRAW_POLYGON:
252cdf0e10cSrcweir     // case SID_DRAW_POLYGON_NOFILL:
253cdf0e10cSrcweir     // case SID_DRAW_BEZIER_NOFILL:
254cdf0e10cSrcweir     // case SID_DRAW_FREELINE_NOFILL:
255cdf0e10cSrcweir 
256cdf0e10cSrcweir     SdrObject* pObj = SdrObjFactory::MakeNewObject(
257cdf0e10cSrcweir         pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
258cdf0e10cSrcweir         0L, pDrDoc);
259cdf0e10cSrcweir 
260cdf0e10cSrcweir     if(pObj)
261cdf0e10cSrcweir     {
262cdf0e10cSrcweir         if(pObj->ISA(SdrPathObj))
263cdf0e10cSrcweir         {
264cdf0e10cSrcweir             basegfx::B2DPolyPolygon aPoly;
265cdf0e10cSrcweir 
266cdf0e10cSrcweir             switch(nID)
267cdf0e10cSrcweir             {
268cdf0e10cSrcweir                 case SID_DRAW_BEZIER_NOFILL:
269cdf0e10cSrcweir                 {
270cdf0e10cSrcweir                     basegfx::B2DPolygon aInnerPoly;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
273cdf0e10cSrcweir 
274cdf0e10cSrcweir                     const basegfx::B2DPoint aCenterBottom(rRectangle.Center().X(), rRectangle.Bottom());
275cdf0e10cSrcweir                     aInnerPoly.appendBezierSegment(
276cdf0e10cSrcweir                         aCenterBottom,
277cdf0e10cSrcweir                         aCenterBottom,
278cdf0e10cSrcweir                         basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
279cdf0e10cSrcweir 
280cdf0e10cSrcweir                     const basegfx::B2DPoint aCenterTop(rRectangle.Center().X(), rRectangle.Top());
281cdf0e10cSrcweir                     aInnerPoly.appendBezierSegment(
282cdf0e10cSrcweir                         aCenterTop,
283cdf0e10cSrcweir                         aCenterTop,
284cdf0e10cSrcweir                         basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
285cdf0e10cSrcweir 
286cdf0e10cSrcweir                     aPoly.append(aInnerPoly);
287cdf0e10cSrcweir                     break;
288cdf0e10cSrcweir                 }
289cdf0e10cSrcweir                 case SID_DRAW_FREELINE_NOFILL:
290cdf0e10cSrcweir                 {
291cdf0e10cSrcweir                     basegfx::B2DPolygon aInnerPoly;
292cdf0e10cSrcweir 
293cdf0e10cSrcweir                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
294cdf0e10cSrcweir 
295cdf0e10cSrcweir                     aInnerPoly.appendBezierSegment(
296cdf0e10cSrcweir                         basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top()),
297cdf0e10cSrcweir                         basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Top()),
298cdf0e10cSrcweir                         basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Center().Y()));
299cdf0e10cSrcweir 
300cdf0e10cSrcweir                     aInnerPoly.appendBezierSegment(
301cdf0e10cSrcweir                         basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()),
302cdf0e10cSrcweir                         basegfx::B2DPoint(rRectangle.Right(), rRectangle.Bottom()),
303cdf0e10cSrcweir                         basegfx::B2DPoint(rRectangle.Right(), rRectangle.Top()));
304cdf0e10cSrcweir 
305cdf0e10cSrcweir                     aPoly.append(aInnerPoly);
306cdf0e10cSrcweir                     break;
307cdf0e10cSrcweir                 }
308cdf0e10cSrcweir                 case SID_DRAW_POLYGON:
309cdf0e10cSrcweir                 case SID_DRAW_POLYGON_NOFILL:
310cdf0e10cSrcweir                 {
311cdf0e10cSrcweir                     basegfx::B2DPolygon aInnerPoly;
312cdf0e10cSrcweir                     const sal_Int32 nWdt(rRectangle.GetWidth());
313cdf0e10cSrcweir                     const sal_Int32 nHgt(rRectangle.GetHeight());
314cdf0e10cSrcweir 
315cdf0e10cSrcweir                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Bottom()));
316cdf0e10cSrcweir                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 30) / 100, rRectangle.Top() + (nHgt * 70) / 100));
317cdf0e10cSrcweir                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left(), rRectangle.Top() + (nHgt * 15) / 100));
318cdf0e10cSrcweir                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 65) / 100, rRectangle.Top()));
319cdf0e10cSrcweir                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + nWdt, rRectangle.Top() + (nHgt * 30) / 100));
320cdf0e10cSrcweir                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 50) / 100));
321cdf0e10cSrcweir                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Left() + (nWdt * 80) / 100, rRectangle.Top() + (nHgt * 75) / 100));
322cdf0e10cSrcweir                     aInnerPoly.append(basegfx::B2DPoint(rRectangle.Bottom(), rRectangle.Right()));
323cdf0e10cSrcweir 
324cdf0e10cSrcweir                     if(SID_DRAW_POLYGON_NOFILL == nID)
325cdf0e10cSrcweir                     {
326cdf0e10cSrcweir                         aInnerPoly.append(basegfx::B2DPoint(rRectangle.Center().X(), rRectangle.Bottom()));
327cdf0e10cSrcweir                     }
328cdf0e10cSrcweir                     else
329cdf0e10cSrcweir                     {
330cdf0e10cSrcweir                         aInnerPoly.setClosed(true);
331cdf0e10cSrcweir                     }
332cdf0e10cSrcweir 
333cdf0e10cSrcweir                     aPoly.append(aInnerPoly);
334cdf0e10cSrcweir                     break;
335cdf0e10cSrcweir                 }
336cdf0e10cSrcweir             }
337cdf0e10cSrcweir 
338cdf0e10cSrcweir             ((SdrPathObj*)pObj)->SetPathPoly(aPoly);
339cdf0e10cSrcweir         }
340cdf0e10cSrcweir         else
341cdf0e10cSrcweir         {
342cdf0e10cSrcweir             DBG_ERROR("Object is NO path object");
343cdf0e10cSrcweir         }
344cdf0e10cSrcweir 
345cdf0e10cSrcweir         pObj->SetLogicRect(rRectangle);
346cdf0e10cSrcweir     }
347cdf0e10cSrcweir 
348cdf0e10cSrcweir     return pObj;
349cdf0e10cSrcweir }
350cdf0e10cSrcweir 
351cdf0e10cSrcweir // eof
352