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 "fuconrec.hxx"
22 : #include "tabvwsh.hxx"
23 : #include "sc.hrc"
24 : #include "drawview.hxx"
25 :
26 : #include <editeng/outlobj.hxx>
27 : // Create default drawing objects via keyboard
28 : #include <svx/svdopath.hxx>
29 : #include <svx/svdocapt.hxx>
30 : #include <basegfx/polygon/b2dpolygon.hxx>
31 : #include <basegfx/point/b2dpoint.hxx>
32 :
33 : #include "scresid.hxx"
34 :
35 : //------------------------------------------------------------------------
36 :
37 :
38 : /*************************************************************************
39 : |*
40 : |* Konstruktor
41 : |*
42 : \************************************************************************/
43 :
44 0 : FuConstRectangle::FuConstRectangle(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
45 : SdrModel* pDoc, SfxRequest& rReq)
46 0 : : FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq)
47 : {
48 0 : }
49 :
50 : /*************************************************************************
51 : |*
52 : |* Destruktor
53 : |*
54 : \************************************************************************/
55 :
56 0 : FuConstRectangle::~FuConstRectangle()
57 : {
58 0 : }
59 :
60 : /*************************************************************************
61 : |*
62 : |* MouseButtonDown-event
63 : |*
64 : \************************************************************************/
65 :
66 0 : sal_Bool FuConstRectangle::MouseButtonDown(const MouseEvent& rMEvt)
67 : {
68 : // remember button state for creation of own MouseEvents
69 0 : SetMouseButtonCode(rMEvt.GetButtons());
70 :
71 0 : sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
72 :
73 0 : if ( rMEvt.IsLeft() && !pView->IsAction() )
74 : {
75 0 : Point aPos( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
76 : // Hack to align object to nearest grid position where object
77 : // would be anchored ( if it were cell anchored )
78 : // Get grid offset for current position ( note: aPnt is
79 : // also adjusted )
80 0 : Point aGridOff = CurrentGridSyncOffsetAndPos( aPos );
81 0 : pWindow->CaptureMouse();
82 :
83 0 : if ( pView->GetCurrentObjIdentifier() == OBJ_CAPTION )
84 : {
85 0 : Size aCaptionSize ( 2268, 1134 ); // 4x2cm
86 :
87 0 : bReturn = pView->BegCreateCaptionObj( aPos, aCaptionSize );
88 :
89 : // wie stellt man den Font ein, mit dem geschrieben wird
90 : }
91 : else
92 0 : bReturn = pView->BegCreateObj(aPos);
93 0 : if ( bReturn )
94 0 : pView->GetCreateObj()->SetGridOffset( aGridOff );
95 : }
96 0 : return bReturn;
97 : }
98 :
99 : /*************************************************************************
100 : |*
101 : |* MouseMove-event
102 : |*
103 : \************************************************************************/
104 :
105 0 : sal_Bool FuConstRectangle::MouseMove(const MouseEvent& rMEvt)
106 : {
107 0 : return FuConstruct::MouseMove(rMEvt);
108 : }
109 :
110 : /*************************************************************************
111 : |*
112 : |* MouseButtonUp-event
113 : |*
114 : \************************************************************************/
115 :
116 0 : sal_Bool FuConstRectangle::MouseButtonUp(const MouseEvent& rMEvt)
117 : {
118 : // remember button state for creation of own MouseEvents
119 0 : SetMouseButtonCode(rMEvt.GetButtons());
120 :
121 0 : sal_Bool bReturn = false;
122 :
123 0 : if ( pView->IsCreateObj() && rMEvt.IsLeft() )
124 : {
125 0 : pView->EndCreateObj(SDRCREATE_FORCEEND);
126 :
127 0 : if (aSfxRequest.GetSlot() == SID_DRAW_CAPTION_VERTICAL)
128 : {
129 : // set vertical flag for caption object
130 :
131 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
132 0 : if (rMarkList.GetMark(0))
133 : {
134 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
135 : // create OutlinerParaObject now so it can be set to vertical
136 0 : if ( pObj->ISA(SdrTextObj) )
137 0 : ((SdrTextObj*)pObj)->ForceOutlinerParaObject();
138 0 : OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
139 0 : if( pOPO && !pOPO->IsVertical() )
140 0 : pOPO->SetVertical( sal_True );
141 : }
142 : }
143 :
144 0 : bReturn = sal_True;
145 : }
146 0 : return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
147 : }
148 :
149 : /*************************************************************************
150 : |*
151 : |* Tastaturereignisse bearbeiten
152 : |*
153 : |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
154 : |* FALSE.
155 : |*
156 : \************************************************************************/
157 :
158 0 : sal_Bool FuConstRectangle::KeyInput(const KeyEvent& rKEvt)
159 : {
160 0 : sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
161 0 : return(bReturn);
162 : }
163 :
164 : /*************************************************************************
165 : |*
166 : |* Function aktivieren
167 : |*
168 : \************************************************************************/
169 :
170 0 : void FuConstRectangle::Activate()
171 : {
172 : SdrObjKind aObjKind;
173 :
174 0 : switch (aSfxRequest.GetSlot() )
175 : {
176 : case SID_DRAW_LINE:
177 0 : aNewPointer = Pointer( POINTER_DRAW_LINE );
178 0 : aObjKind = OBJ_LINE;
179 0 : break;
180 :
181 : case SID_DRAW_RECT:
182 0 : aNewPointer = Pointer( POINTER_DRAW_RECT );
183 0 : aObjKind = OBJ_RECT;
184 0 : break;
185 :
186 : case SID_DRAW_ELLIPSE:
187 0 : aNewPointer = Pointer( POINTER_DRAW_ELLIPSE );
188 0 : aObjKind = OBJ_CIRC;
189 0 : break;
190 :
191 : case SID_DRAW_CAPTION:
192 : case SID_DRAW_CAPTION_VERTICAL:
193 0 : aNewPointer = Pointer( POINTER_DRAW_CAPTION );
194 0 : aObjKind = OBJ_CAPTION;
195 0 : break;
196 :
197 : default:
198 0 : aNewPointer = Pointer( POINTER_CROSS );
199 0 : aObjKind = OBJ_RECT;
200 0 : break;
201 : }
202 :
203 0 : pView->SetCurrentObj(sal::static_int_cast<sal_uInt16>(aObjKind));
204 :
205 0 : aOldPointer = pWindow->GetPointer();
206 0 : pViewShell->SetActivePointer( aNewPointer );
207 :
208 0 : FuConstruct::Activate();
209 0 : }
210 :
211 : /*************************************************************************
212 : |*
213 : |* Function deaktivieren
214 : |*
215 : \************************************************************************/
216 :
217 0 : void FuConstRectangle::Deactivate()
218 : {
219 0 : FuConstruct::Deactivate();
220 0 : pViewShell->SetActivePointer( aOldPointer );
221 0 : }
222 :
223 : // Create default drawing objects via keyboard
224 0 : SdrObject* FuConstRectangle::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
225 : {
226 : SdrObject* pObj = SdrObjFactory::MakeNewObject(
227 0 : pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
228 0 : 0L, pDrDoc);
229 :
230 0 : if(pObj)
231 : {
232 0 : Rectangle aRect(rRectangle);
233 0 : Point aStart = aRect.TopLeft();
234 0 : Point aEnd = aRect.BottomRight();
235 :
236 0 : switch(nID)
237 : {
238 : case SID_DRAW_LINE:
239 : {
240 0 : if(pObj->ISA(SdrPathObj))
241 : {
242 0 : sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
243 0 : basegfx::B2DPolygon aPoly;
244 0 : aPoly.append(basegfx::B2DPoint(aStart.X(), nYMiddle));
245 0 : aPoly.append(basegfx::B2DPoint(aEnd.X(), nYMiddle));
246 0 : ((SdrPathObj*)pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aPoly));
247 : }
248 : else
249 : {
250 : OSL_FAIL("Object is NO line object");
251 : }
252 :
253 0 : break;
254 : }
255 : case SID_DRAW_CAPTION:
256 : case SID_DRAW_CAPTION_VERTICAL:
257 : {
258 0 : if(pObj->ISA(SdrCaptionObj))
259 : {
260 0 : sal_Bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
261 :
262 0 : ((SdrTextObj*)pObj)->SetVerticalWriting(bIsVertical);
263 :
264 0 : if(bIsVertical)
265 : {
266 0 : SfxItemSet aSet(pObj->GetMergedItemSet());
267 0 : aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
268 0 : aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
269 0 : pObj->SetMergedItemSet(aSet);
270 : }
271 :
272 : // don't set default text, start edit mode instead
273 : // (Edit mode is started in ScTabViewShell::ExecDraw, because
274 : // it must be handled by FuText)
275 : // String aText(ScResId(STR_CAPTION_DEFAULT_TEXT));
276 : // ((SdrCaptionObj*)pObj)->SetText(aText);
277 :
278 0 : ((SdrCaptionObj*)pObj)->SetLogicRect(aRect);
279 : ((SdrCaptionObj*)pObj)->SetTailPos(
280 0 : aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
281 : }
282 : else
283 : {
284 : OSL_FAIL("Object is NO caption object");
285 : }
286 :
287 0 : break;
288 : }
289 :
290 : default:
291 : {
292 0 : pObj->SetLogicRect(aRect);
293 :
294 0 : break;
295 : }
296 : }
297 :
298 0 : SfxItemSet aAttr(pDrDoc->GetItemPool());
299 0 : pObj->SetMergedItemSet(aAttr);
300 : }
301 :
302 0 : return pObj;
303 15 : }
304 :
305 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|