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