xref: /AOO41X/main/sd/source/ui/func/fuconarc.cxx (revision 79aad27f7f29270c03e208e3d687e8e3850af11d)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26 
27 #include "fuconarc.hxx"
28 #include <svx/svdpagv.hxx>
29 #include <svx/svdocirc.hxx>
30 #include <sfx2/request.hxx>
31 #include <svl/intitem.hxx>
32 #include <svl/aeitem.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <svx/svdobj.hxx>
35 #include <sfx2/viewfrm.hxx>
36 
37 
38 #include <svx/svxids.hrc>
39 #include <math.h>
40 
41 #include "app.hrc"
42 #include "Window.hxx"
43 #include "drawdoc.hxx"
44 #include "res_bmp.hrc"
45 #include "View.hxx"
46 #include "ViewShell.hxx"
47 #include "ViewShellBase.hxx"
48 #include "ToolBarManager.hxx"
49 
50 // #97016#
51 #include <svx/sxciaitm.hxx>
52 
53 namespace sd {
54 
55 TYPEINIT1( FuConstructArc, FuConstruct );
56 
57 /*************************************************************************
58 |*
59 |* Konstruktor
60 |*
61 \************************************************************************/
62 
FuConstructArc(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq)63 FuConstructArc::FuConstructArc (
64     ViewShell*  pViewSh,
65     ::sd::Window*       pWin,
66     ::sd::View*         pView,
67     SdDrawDocument* pDoc,
68     SfxRequest&     rReq )
69     : FuConstruct( pViewSh, pWin, pView, pDoc, rReq )
70 {
71 }
72 
Create(ViewShell * pViewSh,::sd::Window * pWin,::sd::View * pView,SdDrawDocument * pDoc,SfxRequest & rReq,bool bPermanent)73 FunctionReference FuConstructArc::Create( ViewShell* pViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument* pDoc, SfxRequest& rReq, bool bPermanent  )
74 {
75     FuConstructArc* pFunc;
76     FunctionReference xFunc( pFunc = new FuConstructArc( pViewSh, pWin, pView, pDoc, rReq ) );
77     xFunc->DoExecute(rReq);
78     pFunc->SetPermanent(bPermanent);
79     return xFunc;
80 }
81 
DoExecute(SfxRequest & rReq)82 void FuConstructArc::DoExecute( SfxRequest& rReq )
83 {
84     FuConstruct::DoExecute( rReq );
85 
86     mpViewShell->GetViewShellBase().GetToolBarManager()->SetToolBar(
87         ToolBarManager::TBG_FUNCTION,
88         ToolBarManager::msDrawingObjectToolBar);
89 
90     const SfxItemSet *pArgs = rReq.GetArgs ();
91 
92     if (pArgs)
93     {
94         SFX_REQUEST_ARG (rReq, pCenterX, SfxUInt32Item, ID_VAL_CENTER_X, sal_False);
95         SFX_REQUEST_ARG (rReq, pCenterY, SfxUInt32Item, ID_VAL_CENTER_Y, sal_False);
96         SFX_REQUEST_ARG (rReq, pAxisX, SfxUInt32Item, ID_VAL_AXIS_X, sal_False);
97         SFX_REQUEST_ARG (rReq, pAxisY, SfxUInt32Item, ID_VAL_AXIS_Y, sal_False);
98         SFX_REQUEST_ARG (rReq, pPhiStart, SfxUInt32Item, ID_VAL_ANGLESTART, sal_False);
99         SFX_REQUEST_ARG (rReq, pPhiEnd, SfxUInt32Item, ID_VAL_ANGLEEND, sal_False);
100 
101         Rectangle   aNewRectangle (pCenterX->GetValue () - pAxisX->GetValue () / 2,
102                                    pCenterY->GetValue () - pAxisY->GetValue () / 2,
103                                    pCenterX->GetValue () + pAxisX->GetValue () / 2,
104                                    pCenterY->GetValue () + pAxisY->GetValue () / 2);
105 
106         Activate();  // Setzt aObjKind
107         SdrCircObj* pNewCircle =
108         new SdrCircObj((SdrObjKind) mpView->GetCurrentObjIdentifier(),
109                        aNewRectangle,
110                        (long) (pPhiStart->GetValue () * 10.0),
111                        (long) (pPhiEnd->GetValue () * 10.0));
112         SdrPageView *pPV = mpView->GetSdrPageView();
113 
114         mpView->InsertObjectAtView(pNewCircle, *pPV, SDRINSERT_SETDEFLAYER);
115     }
116 }
117 
118 /*************************************************************************
119 |*
120 |* MouseButtonDown-event
121 |*
122 \************************************************************************/
123 
MouseButtonDown(const MouseEvent & rMEvt)124 sal_Bool FuConstructArc::MouseButtonDown( const MouseEvent& rMEvt )
125 {
126     sal_Bool bReturn = FuConstruct::MouseButtonDown( rMEvt );
127 
128     if ( rMEvt.IsLeft() && !mpView->IsAction() )
129     {
130         Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
131         mpWindow->CaptureMouse();
132         sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(DRGPIX,0)).Width() );
133         mpView->BegCreateObj(aPnt, (OutputDevice*) NULL, nDrgLog);
134 
135         SdrObject* pObj = mpView->GetCreateObj();
136 
137         if (pObj)
138         {
139             SfxItemSet aAttr(mpDoc->GetPool());
140             SetStyleSheet(aAttr, pObj);
141 
142 //-/            pObj->NbcSetAttributes(aAttr, sal_False);
143             pObj->SetMergedItemSet(aAttr);
144         }
145 
146         bReturn = sal_True;
147     }
148     return bReturn;
149 }
150 
151 /*************************************************************************
152 |*
153 |* MouseMove-event
154 |*
155 \************************************************************************/
156 
MouseMove(const MouseEvent & rMEvt)157 sal_Bool FuConstructArc::MouseMove( const MouseEvent& rMEvt )
158 {
159     return FuConstruct::MouseMove(rMEvt);
160 }
161 
162 /*************************************************************************
163 |*
164 |* MouseButtonUp-event
165 |*
166 \************************************************************************/
167 
MouseButtonUp(const MouseEvent & rMEvt)168 sal_Bool FuConstructArc::MouseButtonUp( const MouseEvent& rMEvt )
169 {
170     sal_Bool bReturn = sal_False;
171     sal_Bool bCreated = sal_False;
172 
173     if ( mpView->IsCreateObj() && rMEvt.IsLeft() )
174     {
175         Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
176 
177         sal_uLong nCount = mpView->GetSdrPageView()->GetObjList()->GetObjCount();
178 
179         if (mpView->EndCreateObj(SDRCREATE_NEXTPOINT) )
180         {
181             if (nCount != mpView->GetSdrPageView()->GetObjList()->GetObjCount())
182             {
183                 bCreated = sal_True;
184             }
185         }
186 
187         bReturn = sal_True;
188     }
189 
190     bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn;
191 
192     if (!bPermanent && bCreated)
193         mpViewShell->GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SFX_CALLMODE_ASYNCHRON);
194 
195     return bReturn;
196 }
197 
198 /*************************************************************************
199 |*
200 |* Tastaturereignisse bearbeiten
201 |*
202 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
203 |* sal_False.
204 |*
205 \************************************************************************/
206 
KeyInput(const KeyEvent & rKEvt)207 sal_Bool FuConstructArc::KeyInput(const KeyEvent& rKEvt)
208 {
209     sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
210     return(bReturn);
211 }
212 
213 /*************************************************************************
214 |*
215 |* Function aktivieren
216 |*
217 \************************************************************************/
218 
Activate()219 void FuConstructArc::Activate()
220 {
221     SdrObjKind aObjKind;
222 
223     switch( nSlotId )
224     {
225         case SID_DRAW_ARC      :
226         case SID_DRAW_CIRCLEARC:
227         {
228             aObjKind = OBJ_CARC;
229         }
230         break;
231 
232         case SID_DRAW_PIE             :
233         case SID_DRAW_PIE_NOFILL      :
234         case SID_DRAW_CIRCLEPIE       :
235         case SID_DRAW_CIRCLEPIE_NOFILL:
236         {
237             aObjKind = OBJ_SECT;
238         }
239         break;
240 
241         case SID_DRAW_ELLIPSECUT       :
242         case SID_DRAW_ELLIPSECUT_NOFILL:
243         case SID_DRAW_CIRCLECUT        :
244         case SID_DRAW_CIRCLECUT_NOFILL :
245         {
246             aObjKind = OBJ_CCUT;
247         }
248         break;
249 
250         default:
251         {
252             aObjKind = OBJ_CARC;
253         }
254         break;
255     }
256 
257     mpView->SetCurrentObj((sal_uInt16)aObjKind);
258 
259     FuConstruct::Activate();
260 //  FuDraw::Activate();
261 }
262 
263 /*************************************************************************
264 |*
265 |* Function deaktivieren
266 |*
267 \************************************************************************/
268 
Deactivate()269 void FuConstructArc::Deactivate()
270 {
271     FuConstruct::Deactivate();
272 //  FuDraw::Deactivate();
273 }
274 
275 // #97016#
CreateDefaultObject(const sal_uInt16 nID,const Rectangle & rRectangle)276 SdrObject* FuConstructArc::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
277 {
278     // case SID_DRAW_ARC:
279     // case SID_DRAW_CIRCLEARC:
280     // case SID_DRAW_PIE:
281     // case SID_DRAW_PIE_NOFILL:
282     // case SID_DRAW_CIRCLEPIE:
283     // case SID_DRAW_CIRCLEPIE_NOFILL:
284     // case SID_DRAW_ELLIPSECUT:
285     // case SID_DRAW_ELLIPSECUT_NOFILL:
286     // case SID_DRAW_CIRCLECUT:
287     // case SID_DRAW_CIRCLECUT_NOFILL:
288 
289     SdrObject* pObj = SdrObjFactory::MakeNewObject(
290         mpView->GetCurrentObjInventor(), mpView->GetCurrentObjIdentifier(),
291         0L, mpDoc);
292 
293     if(pObj)
294     {
295         if(pObj->ISA(SdrCircObj))
296         {
297             Rectangle aRect(rRectangle);
298 
299             if(SID_DRAW_ARC == nID ||
300                 SID_DRAW_CIRCLEARC == nID ||
301                 SID_DRAW_CIRCLEPIE == nID ||
302                 SID_DRAW_CIRCLEPIE_NOFILL == nID ||
303                 SID_DRAW_CIRCLECUT == nID ||
304                 SID_DRAW_CIRCLECUT_NOFILL == nID)
305             {
306                 // force quadratic
307                 ImpForceQuadratic(aRect);
308             }
309 
310             pObj->SetLogicRect(aRect);
311 
312             SfxItemSet aAttr(mpDoc->GetPool());
313             aAttr.Put(SdrCircStartAngleItem(9000));
314             aAttr.Put(SdrCircEndAngleItem(0));
315 
316             if(SID_DRAW_PIE_NOFILL == nID ||
317                 SID_DRAW_CIRCLEPIE_NOFILL == nID ||
318                 SID_DRAW_ELLIPSECUT_NOFILL == nID ||
319                 SID_DRAW_CIRCLECUT_NOFILL == nID)
320             {
321                 aAttr.Put(XFillStyleItem(XFILL_NONE));
322             }
323 
324             pObj->SetMergedItemSet(aAttr);
325         }
326         else
327         {
328             DBG_ERROR("Object is NO circle object");
329         }
330     }
331 
332     return pObj;
333 }
334 
335 } // end of namespace sd
336