/src/libreoffice/sd/source/ui/func/fuconarc.cxx
Line | Count | Source |
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 <fuconarc.hxx> |
21 | | #include <svx/svdpagv.hxx> |
22 | | #include <svx/svdocirc.hxx> |
23 | | #include <sfx2/request.hxx> |
24 | | #include <svl/intitem.hxx> |
25 | | #include <sfx2/dispatch.hxx> |
26 | | #include <svx/svdobj.hxx> |
27 | | #include <sfx2/viewfrm.hxx> |
28 | | #include <osl/diagnose.h> |
29 | | |
30 | | #include <svx/svxids.hrc> |
31 | | |
32 | | #include <Window.hxx> |
33 | | #include <drawdoc.hxx> |
34 | | |
35 | | #include <View.hxx> |
36 | | #include <ViewShell.hxx> |
37 | | #include <ViewShellBase.hxx> |
38 | | #include <ToolBarManager.hxx> |
39 | | |
40 | | #include <svx/sxciaitm.hxx> |
41 | | #include <svx/xfillit0.hxx> |
42 | | |
43 | | using namespace com::sun::star; |
44 | | |
45 | | namespace sd { |
46 | | |
47 | | |
48 | | FuConstructArc::FuConstructArc ( |
49 | | ViewShell& rViewSh, |
50 | | ::sd::Window* pWin, |
51 | | ::sd::View* pView, |
52 | | SdDrawDocument& rDoc, |
53 | | SfxRequest& rReq ) |
54 | 0 | : FuConstruct( rViewSh, pWin, pView, rDoc, rReq ) |
55 | 0 | { |
56 | 0 | } |
57 | | |
58 | | rtl::Reference<FuPoor> FuConstructArc::Create( ViewShell& rViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument& rDoc, SfxRequest& rReq, bool bPermanent ) |
59 | 0 | { |
60 | 0 | FuConstructArc* pFunc; |
61 | 0 | rtl::Reference<FuPoor> xFunc( pFunc = new FuConstructArc( rViewSh, pWin, pView, rDoc, rReq ) ); |
62 | 0 | xFunc->DoExecute(rReq); |
63 | 0 | pFunc->SetPermanent(bPermanent); |
64 | 0 | return xFunc; |
65 | 0 | } |
66 | | |
67 | | void FuConstructArc::DoExecute( SfxRequest& rReq ) |
68 | 0 | { |
69 | 0 | FuConstruct::DoExecute( rReq ); |
70 | |
|
71 | 0 | mrViewShell.GetViewShellBase().GetToolBarManager()->SetToolBar( |
72 | 0 | ToolBarManager::ToolBarGroup::Function, |
73 | 0 | ToolBarManager::msDrawingObjectToolBar); |
74 | |
|
75 | 0 | const SfxItemSet *pArgs = rReq.GetArgs (); |
76 | |
|
77 | 0 | if (!pArgs) |
78 | 0 | return; |
79 | | |
80 | 0 | const SfxUInt32Item* pCenterX = rReq.GetArg<SfxUInt32Item>(ID_VAL_CENTER_X); |
81 | 0 | const SfxUInt32Item* pCenterY = rReq.GetArg<SfxUInt32Item>(ID_VAL_CENTER_Y); |
82 | 0 | const SfxUInt32Item* pAxisX = rReq.GetArg<SfxUInt32Item>(ID_VAL_AXIS_X); |
83 | 0 | const SfxUInt32Item* pAxisY = rReq.GetArg<SfxUInt32Item>(ID_VAL_AXIS_Y); |
84 | 0 | const SfxUInt32Item* pPhiStart = rReq.GetArg<SfxUInt32Item>(ID_VAL_ANGLESTART); |
85 | 0 | const SfxUInt32Item* pPhiEnd = rReq.GetArg<SfxUInt32Item>(ID_VAL_ANGLEEND); |
86 | |
|
87 | 0 | ::tools::Rectangle aNewRectangle (pCenterX->GetValue () - pAxisX->GetValue () / 2, |
88 | 0 | pCenterY->GetValue () - pAxisY->GetValue () / 2, |
89 | 0 | pCenterX->GetValue () + pAxisX->GetValue () / 2, |
90 | 0 | pCenterY->GetValue () + pAxisY->GetValue () / 2); |
91 | |
|
92 | 0 | Activate(); // sets aObjKind |
93 | 0 | rtl::Reference<SdrCircObj> pNewCircle = |
94 | 0 | new SdrCircObj( |
95 | 0 | mpView->getSdrModelFromSdrView(), |
96 | 0 | ToSdrCircKind(mpView->GetCurrentObjIdentifier()), |
97 | 0 | aNewRectangle, |
98 | 0 | Degree100(pPhiStart->GetValue() * 10), |
99 | 0 | Degree100(pPhiEnd->GetValue() * 10)); |
100 | 0 | SdrPageView *pPV = mpView->GetSdrPageView(); |
101 | |
|
102 | 0 | mpView->InsertObjectAtView(pNewCircle.get(), *pPV, SdrInsertFlags::SETDEFLAYER); |
103 | 0 | } |
104 | | |
105 | | bool FuConstructArc::MouseButtonDown( const MouseEvent& rMEvt ) |
106 | 0 | { |
107 | 0 | bool bReturn = FuConstruct::MouseButtonDown( rMEvt ); |
108 | |
|
109 | 0 | if ( rMEvt.IsLeft() && !mpView->IsAction() ) |
110 | 0 | { |
111 | 0 | Point aPnt( mpWindow->PixelToLogic( rMEvt.GetPosPixel() ) ); |
112 | 0 | mpWindow->CaptureMouse(); |
113 | 0 | sal_uInt16 nDrgLog = sal_uInt16 ( mpWindow->PixelToLogic(Size(mpView->GetDragThresholdPixels(),0)).Width() ); |
114 | 0 | mpView->BegCreateObj(aPnt, nullptr, nDrgLog); |
115 | |
|
116 | 0 | SdrObject* pObj = mpView->GetCreateObj(); |
117 | |
|
118 | 0 | if (pObj) |
119 | 0 | { |
120 | 0 | SfxItemSet aAttr(mrDoc.GetPool()); |
121 | 0 | SetStyleSheet(aAttr, pObj); |
122 | |
|
123 | 0 | pObj->SetMergedItemSet(aAttr); |
124 | 0 | } |
125 | |
|
126 | 0 | bReturn = true; |
127 | 0 | } |
128 | 0 | return bReturn; |
129 | 0 | } |
130 | | |
131 | | bool FuConstructArc::MouseButtonUp( const MouseEvent& rMEvt ) |
132 | 0 | { |
133 | 0 | if (rMEvt.IsLeft() && IsIgnoreUnexpectedMouseButtonUp()) |
134 | 0 | return false; |
135 | | |
136 | 0 | bool bReturn = false; |
137 | 0 | bool bCreated = false; |
138 | |
|
139 | 0 | if ( mpView->IsCreateObj() && rMEvt.IsLeft() ) |
140 | 0 | { |
141 | 0 | const size_t nCount = mpView->GetSdrPageView()->GetObjList()->GetObjCount(); |
142 | |
|
143 | 0 | if (mpView->EndCreateObj(SdrCreateCmd::NextPoint) ) |
144 | 0 | { |
145 | 0 | if (nCount != mpView->GetSdrPageView()->GetObjList()->GetObjCount()) |
146 | 0 | { |
147 | 0 | bCreated = true; |
148 | 0 | } |
149 | 0 | } |
150 | |
|
151 | 0 | bReturn = true; |
152 | 0 | } |
153 | |
|
154 | 0 | bReturn = FuConstruct::MouseButtonUp (rMEvt) || bReturn; |
155 | |
|
156 | 0 | if (!bPermanent && bCreated) |
157 | 0 | mrViewShell.GetViewFrame()->GetDispatcher()->Execute(SID_OBJECT_SELECT, SfxCallMode::ASYNCHRON); |
158 | |
|
159 | 0 | return bReturn; |
160 | 0 | } |
161 | | |
162 | | void FuConstructArc::Activate() |
163 | 0 | { |
164 | 0 | SdrObjKind aObjKind; |
165 | |
|
166 | 0 | switch( nSlotId ) |
167 | 0 | { |
168 | 0 | case SID_DRAW_ARC : |
169 | 0 | case SID_DRAW_CIRCLEARC: |
170 | 0 | { |
171 | 0 | aObjKind = SdrObjKind::CircleArc; |
172 | 0 | } |
173 | 0 | break; |
174 | | |
175 | 0 | case SID_DRAW_PIE : |
176 | 0 | case SID_DRAW_PIE_NOFILL : |
177 | 0 | case SID_DRAW_CIRCLEPIE : |
178 | 0 | case SID_DRAW_CIRCLEPIE_NOFILL: |
179 | 0 | { |
180 | 0 | aObjKind = SdrObjKind::CircleSection; |
181 | 0 | } |
182 | 0 | break; |
183 | | |
184 | 0 | case SID_DRAW_ELLIPSECUT : |
185 | 0 | case SID_DRAW_ELLIPSECUT_NOFILL: |
186 | 0 | case SID_DRAW_CIRCLECUT : |
187 | 0 | case SID_DRAW_CIRCLECUT_NOFILL : |
188 | 0 | { |
189 | 0 | aObjKind = SdrObjKind::CircleCut; |
190 | 0 | } |
191 | 0 | break; |
192 | | |
193 | 0 | default: |
194 | 0 | { |
195 | 0 | aObjKind = SdrObjKind::CircleArc; |
196 | 0 | } |
197 | 0 | break; |
198 | 0 | } |
199 | | |
200 | 0 | mpView->SetCurrentObj(aObjKind); |
201 | |
|
202 | 0 | FuConstruct::Activate(); |
203 | 0 | } |
204 | | |
205 | | rtl::Reference<SdrObject> FuConstructArc::CreateDefaultObject(const sal_uInt16 nID, const ::tools::Rectangle& rRectangle) |
206 | 0 | { |
207 | |
|
208 | 0 | rtl::Reference<SdrObject> pObj(SdrObjFactory::MakeNewObject( |
209 | 0 | mpView->getSdrModelFromSdrView(), |
210 | 0 | mpView->GetCurrentObjInventor(), |
211 | 0 | mpView->GetCurrentObjIdentifier())); |
212 | |
|
213 | 0 | if(pObj) |
214 | 0 | { |
215 | 0 | if( dynamic_cast< const SdrCircObj *>( pObj.get() ) != nullptr) |
216 | 0 | { |
217 | 0 | ::tools::Rectangle aRect(rRectangle); |
218 | |
|
219 | 0 | if(SID_DRAW_ARC == nID || |
220 | 0 | SID_DRAW_CIRCLEARC == nID || |
221 | 0 | SID_DRAW_CIRCLEPIE == nID || |
222 | 0 | SID_DRAW_CIRCLEPIE_NOFILL == nID || |
223 | 0 | SID_DRAW_CIRCLECUT == nID || |
224 | 0 | SID_DRAW_CIRCLECUT_NOFILL == nID) |
225 | 0 | { |
226 | | // force quadratic |
227 | 0 | ImpForceQuadratic(aRect); |
228 | 0 | } |
229 | |
|
230 | 0 | pObj->SetLogicRect(aRect); |
231 | |
|
232 | 0 | SfxItemSet aAttr(mrDoc.GetPool()); |
233 | 0 | aAttr.Put(makeSdrCircStartAngleItem(9000_deg100)); |
234 | 0 | aAttr.Put(makeSdrCircEndAngleItem(0_deg100)); |
235 | |
|
236 | 0 | if(SID_DRAW_PIE_NOFILL == nID || |
237 | 0 | SID_DRAW_CIRCLEPIE_NOFILL == nID || |
238 | 0 | SID_DRAW_ELLIPSECUT_NOFILL == nID || |
239 | 0 | SID_DRAW_CIRCLECUT_NOFILL == nID) |
240 | 0 | { |
241 | 0 | aAttr.Put(XFillStyleItem(drawing::FillStyle_NONE)); |
242 | 0 | } |
243 | |
|
244 | 0 | pObj->SetMergedItemSet(aAttr); |
245 | 0 | } |
246 | 0 | else |
247 | 0 | { |
248 | 0 | OSL_FAIL("Object is NO circle object"); |
249 | 0 | } |
250 | 0 | } |
251 | |
|
252 | 0 | return pObj; |
253 | 0 | } |
254 | | |
255 | | } // end of namespace sd |
256 | | |
257 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |