fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / drawfunc / fuconrec.cxx
blobe93322753be320cc689a3766074a783535eba16f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "fuconrec.hxx"
21 #include "tabvwsh.hxx"
22 #include "sc.hrc"
23 #include "drawview.hxx"
25 #include <editeng/outlobj.hxx>
26 // Create default drawing objects via keyboard
27 #include <svx/svdopath.hxx>
28 #include <svx/svdocapt.hxx>
29 #include <basegfx/polygon/b2dpolygon.hxx>
30 #include <basegfx/point/b2dpoint.hxx>
32 #include "scresid.hxx"
34 /*************************************************************************
36 |* Konstruktor
38 \************************************************************************/
40 FuConstRectangle::FuConstRectangle(ScTabViewShell* pViewSh, vcl::Window* pWin, ScDrawView* pViewP,
41 SdrModel* pDoc, SfxRequest& rReq)
42 : FuConstruct(pViewSh, pWin, pViewP, pDoc, rReq)
46 /*************************************************************************
48 |* Destruktor
50 \************************************************************************/
52 FuConstRectangle::~FuConstRectangle()
56 /*************************************************************************
58 |* MouseButtonDown-event
60 \************************************************************************/
62 bool FuConstRectangle::MouseButtonDown(const MouseEvent& rMEvt)
64 // remember button state for creation of own MouseEvents
65 SetMouseButtonCode(rMEvt.GetButtons());
67 bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
69 if ( rMEvt.IsLeft() && !pView->IsAction() )
71 Point aPos( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
72 // Hack to align object to nearest grid position where object
73 // would be anchored ( if it were cell anchored )
74 // Get grid offset for current position ( note: aPnt is
75 // also adjusted )
76 Point aGridOff = CurrentGridSyncOffsetAndPos( aPos );
77 pWindow->CaptureMouse();
79 if ( pView->GetCurrentObjIdentifier() == OBJ_CAPTION )
81 Size aCaptionSize ( 2268, 1134 ); // 4x2cm
83 bReturn = pView->BegCreateCaptionObj( aPos, aCaptionSize );
85 // wie stellt man den Font ein, mit dem geschrieben wird
87 else
88 bReturn = pView->BegCreateObj(aPos);
89 if ( bReturn )
90 pView->GetCreateObj()->SetGridOffset( aGridOff );
92 return bReturn;
95 /*************************************************************************
97 |* MouseMove-event
99 \************************************************************************/
101 bool FuConstRectangle::MouseMove(const MouseEvent& rMEvt)
103 return FuConstruct::MouseMove(rMEvt);
106 /*************************************************************************
108 |* MouseButtonUp-event
110 \************************************************************************/
112 bool FuConstRectangle::MouseButtonUp(const MouseEvent& rMEvt)
114 // remember button state for creation of own MouseEvents
115 SetMouseButtonCode(rMEvt.GetButtons());
117 bool bReturn = false;
119 if ( pView->IsCreateObj() && rMEvt.IsLeft() )
121 pView->EndCreateObj(SDRCREATE_FORCEEND);
123 if (aSfxRequest.GetSlot() == SID_DRAW_CAPTION_VERTICAL)
125 // set vertical flag for caption object
127 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
128 if (rMarkList.GetMark(0))
130 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
131 // create OutlinerParaObject now so it can be set to vertical
132 if ( pObj->ISA(SdrTextObj) )
133 static_cast<SdrTextObj*>(pObj)->ForceOutlinerParaObject();
134 OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
135 if( pOPO && !pOPO->IsVertical() )
136 pOPO->SetVertical( true );
140 bReturn = true;
142 return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
145 /*************************************************************************
147 |* Tastaturereignisse bearbeiten
149 |* Wird ein KeyEvent bearbeitet, so ist der Return-Wert sal_True, andernfalls
150 |* FALSE.
152 \************************************************************************/
154 bool FuConstRectangle::KeyInput(const KeyEvent& rKEvt)
156 return FuConstruct::KeyInput(rKEvt);
159 /*************************************************************************
161 |* Function aktivieren
163 \************************************************************************/
165 void FuConstRectangle::Activate()
167 SdrObjKind aObjKind;
169 switch (aSfxRequest.GetSlot() )
171 case SID_DRAW_LINE:
172 aNewPointer = Pointer( PointerStyle::DrawLine );
173 aObjKind = OBJ_LINE;
174 break;
176 case SID_DRAW_RECT:
177 aNewPointer = Pointer( PointerStyle::DrawRect );
178 aObjKind = OBJ_RECT;
179 break;
181 case SID_DRAW_ELLIPSE:
182 aNewPointer = Pointer( PointerStyle::DrawEllipse );
183 aObjKind = OBJ_CIRC;
184 break;
186 case SID_DRAW_CAPTION:
187 case SID_DRAW_CAPTION_VERTICAL:
188 aNewPointer = Pointer( PointerStyle::DrawCaption );
189 aObjKind = OBJ_CAPTION;
190 break;
192 default:
193 aNewPointer = Pointer( PointerStyle::Cross );
194 aObjKind = OBJ_RECT;
195 break;
198 pView->SetCurrentObj(sal::static_int_cast<sal_uInt16>(aObjKind));
200 aOldPointer = pWindow->GetPointer();
201 pViewShell->SetActivePointer( aNewPointer );
203 FuConstruct::Activate();
206 /*************************************************************************
208 |* Function deaktivieren
210 \************************************************************************/
212 void FuConstRectangle::Deactivate()
214 FuConstruct::Deactivate();
215 pViewShell->SetActivePointer( aOldPointer );
218 // Create default drawing objects via keyboard
219 SdrObject* FuConstRectangle::CreateDefaultObject(const sal_uInt16 nID, const Rectangle& rRectangle)
221 SdrObject* pObj = SdrObjFactory::MakeNewObject(
222 pView->GetCurrentObjInventor(), pView->GetCurrentObjIdentifier(),
223 0L, pDrDoc);
225 if(pObj)
227 Rectangle aRect(rRectangle);
228 Point aStart = aRect.TopLeft();
229 Point aEnd = aRect.BottomRight();
231 switch(nID)
233 case SID_DRAW_LINE:
235 if(pObj->ISA(SdrPathObj))
237 sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
238 basegfx::B2DPolygon aPoly;
239 aPoly.append(basegfx::B2DPoint(aStart.X(), nYMiddle));
240 aPoly.append(basegfx::B2DPoint(aEnd.X(), nYMiddle));
241 static_cast<SdrPathObj*>(pObj)->SetPathPoly(basegfx::B2DPolyPolygon(aPoly));
243 else
245 OSL_FAIL("Object is NO line object");
248 break;
250 case SID_DRAW_CAPTION:
251 case SID_DRAW_CAPTION_VERTICAL:
253 if(pObj->ISA(SdrCaptionObj))
255 bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
257 static_cast<SdrTextObj*>(pObj)->SetVerticalWriting(bIsVertical);
259 if(bIsVertical)
261 SfxItemSet aSet(pObj->GetMergedItemSet());
262 aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
263 aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
264 pObj->SetMergedItemSet(aSet);
267 // don't set default text, start edit mode instead
268 // (Edit mode is started in ScTabViewShell::ExecDraw, because
269 // it must be handled by FuText)
270 // String aText(ScResId(STR_CAPTION_DEFAULT_TEXT));
271 // ((SdrCaptionObj*)pObj)->SetText(aText);
273 static_cast<SdrCaptionObj*>(pObj)->SetLogicRect(aRect);
274 static_cast<SdrCaptionObj*>(pObj)->SetTailPos(
275 aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
277 else
279 OSL_FAIL("Object is NO caption object");
282 break;
285 default:
287 pObj->SetLogicRect(aRect);
289 break;
293 SfxItemSet aAttr(pDrDoc->GetItemPool());
294 pObj->SetMergedItemSet(aAttr);
297 return pObj;
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */