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 :
21 : #include "fuconarc.hxx"
22 : #include "sc.hrc"
23 : #include "tabvwsh.hxx"
24 : #include "drawview.hxx"
25 :
26 : // Create default drawing objects via keyboard
27 : #include <svx/svdocirc.hxx>
28 : #include <svx/sxciaitm.hxx>
29 :
30 : /*************************************************************************
31 : |*
32 : |* Konstruktor
33 : |*
34 : \************************************************************************/
35 :
36 0 : FuConstArc::FuConstArc( ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
37 : SdrModel* pDoc, SfxRequest& rReq )
38 0 : : FuConstruct( pViewSh, pWin, pViewP, pDoc, rReq )
39 : {
40 0 : }
41 :
42 : /*************************************************************************
43 : |*
44 : |* Destruktor
45 : |*
46 : \************************************************************************/
47 :
48 0 : FuConstArc::~FuConstArc()
49 : {
50 0 : }
51 :
52 : /*************************************************************************
53 : |*
54 : |* MouseButtonDown-event
55 : |*
56 : \************************************************************************/
57 :
58 0 : sal_Bool FuConstArc::MouseButtonDown( const MouseEvent& rMEvt )
59 : {
60 : // remember button state for creation of own MouseEvents
61 0 : SetMouseButtonCode(rMEvt.GetButtons());
62 :
63 0 : sal_Bool bReturn = FuConstruct::MouseButtonDown( rMEvt );
64 :
65 0 : if ( rMEvt.IsLeft() && !pView->IsAction() )
66 : {
67 0 : Point aPnt( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
68 : // Hack to align object to nearest grid position where object
69 : // would be anchored ( if it were cell anchored )
70 : // Get grid offset for current position ( note: aPnt is
71 : // also adjusted )
72 0 : Point aGridOff = CurrentGridSyncOffsetAndPos( aPnt );
73 0 : pWindow->CaptureMouse();
74 0 : pView->BegCreateObj( aPnt );
75 0 : pView->GetCreateObj()->SetGridOffset( aGridOff );
76 0 : bReturn = sal_True;
77 : }
78 0 : return bReturn;
79 : }
80 :
81 : /*************************************************************************
82 : |*
83 : |* MouseMove-event
84 : |*
85 : \************************************************************************/
86 :
87 0 : sal_Bool FuConstArc::MouseMove( const MouseEvent& rMEvt )
88 : {
89 0 : return FuConstruct::MouseMove(rMEvt);
90 : }
91 :
92 : /*************************************************************************
93 : |*
94 : |* MouseButtonUp-event
95 : |*
96 : \************************************************************************/
97 :
98 0 : sal_Bool FuConstArc::MouseButtonUp( const MouseEvent& rMEvt )
99 : {
100 : // remember button state for creation of own MouseEvents
101 0 : SetMouseButtonCode(rMEvt.GetButtons());
102 :
103 0 : sal_Bool bReturn = false;
104 :
105 0 : if ( pView->IsCreateObj() && rMEvt.IsLeft() )
106 : {
107 0 : pView->EndCreateObj( SDRCREATE_NEXTPOINT );
108 0 : bReturn = sal_True;
109 : }
110 0 : return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
111 : }
112 :
113 : /*************************************************************************
114 : |*
115 : |* Tastaturereignisse bearbeiten
116 : |*
117 : |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
118 : |* FALSE.
119 : |*
120 : \************************************************************************/
121 :
122 0 : sal_Bool FuConstArc::KeyInput(const KeyEvent& rKEvt)
123 : {
124 0 : sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
125 0 : return(bReturn);
126 : }
127 :
128 : /*************************************************************************
129 : |*
130 : |* Function aktivieren
131 : |*
132 : \************************************************************************/
133 :
134 0 : void FuConstArc::Activate()
135 : {
136 : SdrObjKind aObjKind;
137 :
138 0 : switch (aSfxRequest.GetSlot() )
139 : {
140 : case SID_DRAW_ARC:
141 0 : aNewPointer = Pointer( POINTER_DRAW_ARC );
142 0 : aObjKind = OBJ_CARC;
143 0 : break;
144 :
145 : case SID_DRAW_PIE:
146 0 : aNewPointer = Pointer( POINTER_DRAW_PIE );
147 0 : aObjKind = OBJ_SECT;
148 0 : break;
149 :
150 : case SID_DRAW_CIRCLECUT:
151 0 : aNewPointer = Pointer( POINTER_DRAW_CIRCLECUT );
152 0 : aObjKind = OBJ_CCUT;
153 0 : break;
154 :
155 : default:
156 0 : aNewPointer = Pointer( POINTER_CROSS );
157 0 : aObjKind = OBJ_CARC;
158 0 : break;
159 : }
160 :
161 0 : pView->SetCurrentObj( sal::static_int_cast<sal_uInt16>( aObjKind ) );
162 :
163 0 : aOldPointer = pWindow->GetPointer();
164 0 : pViewShell->SetActivePointer( aNewPointer );
165 :
166 0 : FuDraw::Activate();
167 0 : }
168 :
169 : /*************************************************************************
170 : |*
171 : |* Function deaktivieren
172 : |*
173 : \************************************************************************/
174 :
175 0 : void FuConstArc::Deactivate()
176 : {
177 0 : FuDraw::Deactivate();
178 0 : pViewShell->SetActivePointer( aOldPointer );
179 0 : }
180 :
181 : // Create default drawing objects via keyboard
182 0 : SdrObject* FuConstArc::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
183 : {
184 : // case SID_DRAW_ARC:
185 : // case SID_DRAW_PIE:
186 : // case SID_DRAW_CIRCLECUT:
187 :
188 : SdrObject* pObj = SdrObjFactory::MakeNewObject(
189 0 : pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
190 0 : 0L, pDrDoc);
191 :
192 0 : if(pObj)
193 : {
194 0 : if(pObj->ISA(SdrCircObj))
195 : {
196 0 : Rectangle aRect(rRectangle);
197 :
198 0 : if(SID_DRAW_ARC == nID || SID_DRAW_CIRCLECUT == nID)
199 : {
200 : // force quadratic
201 0 : ImpForceQuadratic(aRect);
202 : }
203 :
204 0 : pObj->SetLogicRect(aRect);
205 :
206 0 : SfxItemSet aAttr(pDrDoc->GetItemPool());
207 0 : aAttr.Put(SdrCircStartAngleItem(9000));
208 0 : aAttr.Put(SdrCircEndAngleItem(0));
209 :
210 0 : pObj->SetMergedItemSet(aAttr);
211 : }
212 : else
213 : {
214 : OSL_FAIL("Object is NO circle object");
215 : }
216 : }
217 :
218 0 : return pObj;
219 15 : }
220 :
221 :
222 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|