Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "fuconrec.hxx"
31 : : #include "tabvwsh.hxx"
32 : : #include "sc.hrc"
33 : : #include "drawview.hxx"
34 : :
35 : : #include <editeng/outlobj.hxx>
36 : : // Create default drawing objects via keyboard
37 : : #include <svx/svdopath.hxx>
38 : : #include <svx/svdocapt.hxx>
39 : : #include <basegfx/polygon/b2dpolygon.hxx>
40 : : #include <basegfx/point/b2dpoint.hxx>
41 : :
42 : : #include "scresid.hxx"
43 : :
44 : : //------------------------------------------------------------------------
45 : :
46 : :
47 : : /*************************************************************************
48 : : |*
49 : : |* Konstruktor
50 : : |*
51 : : \************************************************************************/
52 : :
53 : 0 : FuConstRectangle::FuConstRectangle(ScTabViewShell* pViewSh, Window* pWin, ScDrawView* pViewP,
54 : : SdrModel* pDoc, SfxRequest& rReq)
55 : 0 : : FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq)
56 : : {
57 : 0 : }
58 : :
59 : : /*************************************************************************
60 : : |*
61 : : |* Destruktor
62 : : |*
63 : : \************************************************************************/
64 : :
65 : 0 : FuConstRectangle::~FuConstRectangle()
66 : : {
67 [ # # ]: 0 : }
68 : :
69 : : /*************************************************************************
70 : : |*
71 : : |* MouseButtonDown-event
72 : : |*
73 : : \************************************************************************/
74 : :
75 : 0 : sal_Bool FuConstRectangle::MouseButtonDown(const MouseEvent& rMEvt)
76 : : {
77 : : // remember button state for creation of own MouseEvents
78 : 0 : SetMouseButtonCode(rMEvt.GetButtons());
79 : :
80 : 0 : sal_Bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
81 : :
82 [ # # ][ # # ]: 0 : if ( rMEvt.IsLeft() && !pView->IsAction() )
[ # # ]
83 : : {
84 [ # # ]: 0 : Point aPos( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
85 : :
86 [ # # ]: 0 : pWindow->CaptureMouse();
87 : :
88 [ # # ]: 0 : if ( pView->GetCurrentObjIdentifier() == OBJ_CAPTION )
89 : : {
90 : 0 : Size aCaptionSize ( 2268, 1134 ); // 4x2cm
91 : :
92 [ # # ]: 0 : bReturn = pView->BegCreateCaptionObj( aPos, aCaptionSize );
93 : :
94 : : // wie stellt man den Font ein, mit dem geschrieben wird
95 : : }
96 : : else
97 [ # # ]: 0 : bReturn = pView->BegCreateObj(aPos);
98 : : }
99 : 0 : return bReturn;
100 : : }
101 : :
102 : : /*************************************************************************
103 : : |*
104 : : |* MouseMove-event
105 : : |*
106 : : \************************************************************************/
107 : :
108 : 0 : sal_Bool FuConstRectangle::MouseMove(const MouseEvent& rMEvt)
109 : : {
110 : 0 : return FuConstruct::MouseMove(rMEvt);
111 : : }
112 : :
113 : : /*************************************************************************
114 : : |*
115 : : |* MouseButtonUp-event
116 : : |*
117 : : \************************************************************************/
118 : :
119 : 0 : sal_Bool FuConstRectangle::MouseButtonUp(const MouseEvent& rMEvt)
120 : : {
121 : : // remember button state for creation of own MouseEvents
122 : 0 : SetMouseButtonCode(rMEvt.GetButtons());
123 : :
124 : 0 : sal_Bool bReturn = false;
125 : :
126 [ # # ][ # # ]: 0 : if ( pView->IsCreateObj() && rMEvt.IsLeft() )
[ # # ]
127 : : {
128 : 0 : pView->EndCreateObj(SDRCREATE_FORCEEND);
129 : :
130 [ # # ]: 0 : if (aSfxRequest.GetSlot() == SID_DRAW_CAPTION_VERTICAL)
131 : : {
132 : : // set vertical flag for caption object
133 : :
134 : 0 : const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
135 [ # # ]: 0 : if (rMarkList.GetMark(0))
136 : : {
137 : 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
138 : : // create OutlinerParaObject now so it can be set to vertical
139 [ # # ]: 0 : if ( pObj->ISA(SdrTextObj) )
140 : 0 : ((SdrTextObj*)pObj)->ForceOutlinerParaObject();
141 : 0 : OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
142 [ # # ][ # # ]: 0 : if( pOPO && !pOPO->IsVertical() )
[ # # ]
143 : 0 : pOPO->SetVertical( sal_True );
144 : : }
145 : : }
146 : :
147 : 0 : bReturn = sal_True;
148 : : }
149 [ # # ][ # # ]: 0 : return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
150 : : }
151 : :
152 : : /*************************************************************************
153 : : |*
154 : : |* Tastaturereignisse bearbeiten
155 : : |*
156 : : |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
157 : : |* FALSE.
158 : : |*
159 : : \************************************************************************/
160 : :
161 : 0 : sal_Bool FuConstRectangle::KeyInput(const KeyEvent& rKEvt)
162 : : {
163 : 0 : sal_Bool bReturn = FuConstruct::KeyInput(rKEvt);
164 : 0 : return(bReturn);
165 : : }
166 : :
167 : : /*************************************************************************
168 : : |*
169 : : |* Function aktivieren
170 : : |*
171 : : \************************************************************************/
172 : :
173 : 0 : void FuConstRectangle::Activate()
174 : : {
175 : : SdrObjKind aObjKind;
176 : :
177 [ # # # # : 0 : switch (aSfxRequest.GetSlot() )
# ]
178 : : {
179 : : case SID_DRAW_LINE:
180 : 0 : aNewPointer = Pointer( POINTER_DRAW_LINE );
181 : 0 : aObjKind = OBJ_LINE;
182 : 0 : break;
183 : :
184 : : case SID_DRAW_RECT:
185 : 0 : aNewPointer = Pointer( POINTER_DRAW_RECT );
186 : 0 : aObjKind = OBJ_RECT;
187 : 0 : break;
188 : :
189 : : case SID_DRAW_ELLIPSE:
190 : 0 : aNewPointer = Pointer( POINTER_DRAW_ELLIPSE );
191 : 0 : aObjKind = OBJ_CIRC;
192 : 0 : break;
193 : :
194 : : case SID_DRAW_CAPTION:
195 : : case SID_DRAW_CAPTION_VERTICAL:
196 : 0 : aNewPointer = Pointer( POINTER_DRAW_CAPTION );
197 : 0 : aObjKind = OBJ_CAPTION;
198 : 0 : break;
199 : :
200 : : default:
201 : 0 : aNewPointer = Pointer( POINTER_CROSS );
202 : 0 : aObjKind = OBJ_RECT;
203 : 0 : break;
204 : : }
205 : :
206 : 0 : pView->SetCurrentObj(sal::static_int_cast<sal_uInt16>(aObjKind));
207 : :
208 : 0 : aOldPointer = pWindow->GetPointer();
209 : 0 : pViewShell->SetActivePointer( aNewPointer );
210 : :
211 : 0 : FuConstruct::Activate();
212 : 0 : }
213 : :
214 : : /*************************************************************************
215 : : |*
216 : : |* Function deaktivieren
217 : : |*
218 : : \************************************************************************/
219 : :
220 : 0 : void FuConstRectangle::Deactivate()
221 : : {
222 : 0 : FuConstruct::Deactivate();
223 : 0 : pViewShell->SetActivePointer( aOldPointer );
224 : 0 : }
225 : :
226 : : // Create default drawing objects via keyboard
227 : 0 : SdrObject* FuConstRectangle::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
228 : : {
229 : : SdrObject* pObj = SdrObjFactory::MakeNewObject(
230 : 0 : pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
231 : 0 : 0L, pDrDoc);
232 : :
233 [ # # ]: 0 : if(pObj)
234 : : {
235 : 0 : Rectangle aRect(rRectangle);
236 : 0 : Point aStart = aRect.TopLeft();
237 [ # # ]: 0 : Point aEnd = aRect.BottomRight();
238 : :
239 [ # # # ]: 0 : switch(nID)
240 : : {
241 : : case SID_DRAW_LINE:
242 : : {
243 [ # # ][ # # ]: 0 : if(pObj->ISA(SdrPathObj))
[ # # ]
244 : : {
245 : 0 : sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
246 [ # # ]: 0 : basegfx::B2DPolygon aPoly;
247 [ # # ]: 0 : aPoly.append(basegfx::B2DPoint(aStart.X(), nYMiddle));
248 [ # # ]: 0 : aPoly.append(basegfx::B2DPoint(aEnd.X(), nYMiddle));
249 [ # # ][ # # ]: 0 : ((SdrPathObj*)pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aPoly));
[ # # ][ # # ]
250 : : }
251 : : else
252 : : {
253 : : OSL_FAIL("Object is NO line object");
254 : : }
255 : :
256 : 0 : break;
257 : : }
258 : : case SID_DRAW_CAPTION:
259 : : case SID_DRAW_CAPTION_VERTICAL:
260 : : {
261 [ # # ][ # # ]: 0 : if(pObj->ISA(SdrCaptionObj))
[ # # ]
262 : : {
263 : 0 : sal_Bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
264 : :
265 [ # # ]: 0 : ((SdrTextObj*)pObj)->SetVerticalWriting(bIsVertical);
266 : :
267 [ # # ]: 0 : if(bIsVertical)
268 : : {
269 [ # # ][ # # ]: 0 : SfxItemSet aSet(pObj->GetMergedItemSet());
270 [ # # ][ # # ]: 0 : aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
[ # # ]
271 [ # # ][ # # ]: 0 : aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
[ # # ]
272 [ # # ][ # # ]: 0 : pObj->SetMergedItemSet(aSet);
273 : : }
274 : :
275 : : // don't set default text, start edit mode instead
276 : : // (Edit mode is started in ScTabViewShell::ExecDraw, because
277 : : // it must be handled by FuText)
278 : : // String aText(ScResId(STR_CAPTION_DEFAULT_TEXT));
279 : : // ((SdrCaptionObj*)pObj)->SetText(aText);
280 : :
281 [ # # ]: 0 : ((SdrCaptionObj*)pObj)->SetLogicRect(aRect);
282 : : ((SdrCaptionObj*)pObj)->SetTailPos(
283 [ # # ][ # # ]: 0 : aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
[ # # ]
284 : : }
285 : : else
286 : : {
287 : : OSL_FAIL("Object is NO caption object");
288 : : }
289 : :
290 : 0 : break;
291 : : }
292 : :
293 : : default:
294 : : {
295 [ # # ]: 0 : pObj->SetLogicRect(aRect);
296 : :
297 : 0 : break;
298 : : }
299 : : }
300 : :
301 [ # # ]: 0 : SfxItemSet aAttr(pDrDoc->GetItemPool());
302 [ # # ][ # # ]: 0 : pObj->SetMergedItemSet(aAttr);
303 : : }
304 : :
305 : 0 : return pObj;
306 : : }
307 : :
308 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|