tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / drawfunc / fuconrec.cxx
blob2244003db843267b88da4d531fb75cd698422cf0
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 <drawview.hxx>
24 #include <editeng/outlobj.hxx>
25 #include <svx/constructhelper.hxx>
26 // Create default drawing objects via keyboard
27 #include <svx/svdopath.hxx>
28 #include <svx/svdocapt.hxx>
29 #include <svx/svxids.hrc>
30 #include <svx/svdomeas.hxx>
31 #include <osl/diagnose.h>
33 #include <basegfx/polygon/b2dpolygon.hxx>
34 #include <basegfx/point/b2dpoint.hxx>
36 FuConstRectangle::FuConstRectangle(ScTabViewShell& rViewSh, vcl::Window* pWin, ScDrawView* pViewP,
37 SdrModel* pDoc, const SfxRequest& rReq)
38 : FuConstruct(rViewSh, pWin, pViewP, pDoc, rReq)
42 FuConstRectangle::~FuConstRectangle()
46 bool FuConstRectangle::MouseButtonDown(const MouseEvent& rMEvt)
48 // remember button state for creation of own MouseEvents
49 SetMouseButtonCode(rMEvt.GetButtons());
51 bool bReturn = FuConstruct::MouseButtonDown(rMEvt);
53 if ( rMEvt.IsLeft() && !pView->IsAction() )
55 Point aPos( pWindow->PixelToLogic( rMEvt.GetPosPixel() ) );
56 pWindow->CaptureMouse();
58 if ( pView->GetCurrentObjIdentifier() == SdrObjKind::Caption )
60 Size aCaptionSize ( 2268, 1134 ); // 4x2cm
62 bReturn = pView->BegCreateCaptionObj( aPos, aCaptionSize );
64 // How do you set the font for writing
66 else
67 bReturn = pView->BegCreateObj(aPos);
69 SdrObject* pObj = pView->GetCreateObj();
71 if (pObj)
73 SfxItemSet aAttr(pObj->getSdrModelFromSdrObject().GetItemPool());
74 SetLineEnds(aAttr, *pObj, aSfxRequest.GetSlot());
75 pObj->SetMergedItemSet(aAttr);
78 return bReturn;
81 bool FuConstRectangle::MouseButtonUp(const MouseEvent& rMEvt)
83 // remember button state for creation of own MouseEvents
84 SetMouseButtonCode(rMEvt.GetButtons());
86 bool bReturn = false;
88 if ( pView->IsCreateObj() && rMEvt.IsLeft() )
90 pView->EndCreateObj(SdrCreateCmd::ForceEnd);
92 if (aSfxRequest.GetSlot() == SID_DRAW_CAPTION_VERTICAL)
94 // set vertical flag for caption object
96 const SdrMarkList& rMarkList = pView->GetMarkedObjectList();
97 if (rMarkList.GetMark(0))
99 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
100 // create OutlinerParaObject now so it can be set to vertical
101 if ( auto pSdrTextObj = DynCastSdrTextObj( pObj) )
102 pSdrTextObj->ForceOutlinerParaObject();
103 OutlinerParaObject* pOPO = pObj->GetOutlinerParaObject();
104 if( pOPO && !pOPO->IsEffectivelyVertical() )
105 pOPO->SetVertical( true );
109 bReturn = true;
111 return (FuConstruct::MouseButtonUp(rMEvt) || bReturn);
114 void FuConstRectangle::Activate()
116 SdrObjKind aObjKind;
118 switch (aSfxRequest.GetSlot() )
120 case SID_DRAW_LINE:
121 case SID_DRAW_XLINE:
122 case SID_LINE_ARROW_END:
123 case SID_LINE_ARROW_CIRCLE:
124 case SID_LINE_ARROW_SQUARE:
125 case SID_LINE_ARROW_START:
126 case SID_LINE_CIRCLE_ARROW:
127 case SID_LINE_SQUARE_ARROW:
128 case SID_LINE_ARROWS:
129 aNewPointer = PointerStyle::DrawLine;
130 aObjKind = SdrObjKind::Line;
131 break;
133 case SID_DRAW_MEASURELINE:
134 aNewPointer = PointerStyle::DrawLine;
135 aObjKind = SdrObjKind::Measure;
136 break;
138 case SID_DRAW_RECT:
139 aNewPointer = PointerStyle::DrawRect;
140 aObjKind = SdrObjKind::Rectangle;
141 break;
143 case SID_DRAW_ELLIPSE:
144 aNewPointer = PointerStyle::DrawEllipse;
145 aObjKind = SdrObjKind::CircleOrEllipse;
146 break;
148 case SID_DRAW_CAPTION:
149 case SID_DRAW_CAPTION_VERTICAL:
150 aNewPointer = PointerStyle::DrawCaption;
151 aObjKind = SdrObjKind::Caption;
152 break;
154 default:
155 aNewPointer = PointerStyle::Cross;
156 aObjKind = SdrObjKind::Rectangle;
157 break;
160 pView->SetCurrentObj(aObjKind);
162 aOldPointer = pWindow->GetPointer();
163 rViewShell.SetActivePointer( aNewPointer );
165 FuConstruct::Activate();
168 void FuConstRectangle::SetLineEnds(SfxItemSet& rAttr, const SdrObject& rObj, sal_uInt16 nSlotId)
170 ConstructHelper::SetLineEnds(rAttr, rObj, nSlotId, 200);
173 void FuConstRectangle::Deactivate()
175 FuConstruct::Deactivate();
176 rViewShell.SetActivePointer( aOldPointer );
179 // Create default drawing objects via keyboard
180 rtl::Reference<SdrObject> FuConstRectangle::CreateDefaultObject(const sal_uInt16 nID, const tools::Rectangle& rRectangle)
182 rtl::Reference<SdrObject> pObj(SdrObjFactory::MakeNewObject(
183 *pDrDoc,
184 pView->GetCurrentObjInventor(),
185 pView->GetCurrentObjIdentifier()));
187 if(pObj)
189 tools::Rectangle aRect(rRectangle);
190 Point aStart = aRect.TopLeft();
191 Point aEnd = aRect.BottomRight();
193 switch(nID)
195 case SID_DRAW_LINE:
196 case SID_DRAW_XLINE:
197 case SID_LINE_ARROW_END:
198 case SID_LINE_ARROW_CIRCLE:
199 case SID_LINE_ARROW_SQUARE:
200 case SID_LINE_ARROW_START:
201 case SID_LINE_CIRCLE_ARROW:
202 case SID_LINE_SQUARE_ARROW:
203 case SID_LINE_ARROWS:
205 if(auto pPathObj = dynamic_cast<SdrPathObj*>( pObj.get() ))
207 sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
208 basegfx::B2DPolygon aPoly;
209 aPoly.append(basegfx::B2DPoint(aStart.X(), nYMiddle));
210 aPoly.append(basegfx::B2DPoint(aEnd.X(), nYMiddle));
211 pPathObj->SetPathPoly(basegfx::B2DPolyPolygon(aPoly));
213 else
215 OSL_FAIL("Object is NO line object");
218 break;
221 case SID_DRAW_MEASURELINE:
223 if(auto pMeasureObj = dynamic_cast<SdrMeasureObj*>( pObj.get() ))
225 sal_Int32 nYMiddle((aRect.Top() + aRect.Bottom()) / 2);
226 pMeasureObj->SetPoint(Point(aStart.X(), nYMiddle), 0);
227 pMeasureObj->SetPoint(Point(aEnd.X(), nYMiddle), 1);
230 break;
233 case SID_DRAW_CAPTION:
234 case SID_DRAW_CAPTION_VERTICAL:
236 if(auto pCaptionObj = dynamic_cast<SdrCaptionObj*>( pObj.get() ))
238 bool bIsVertical(SID_DRAW_CAPTION_VERTICAL == nID);
240 pCaptionObj->SetVerticalWriting(bIsVertical);
242 if(bIsVertical)
244 SfxItemSet aSet(pObj->GetMergedItemSet());
245 aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_CENTER));
246 aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
247 pObj->SetMergedItemSet(aSet);
250 // don't set default text, start edit mode instead
251 // (Edit mode is started in ScTabViewShell::ExecDraw, because
252 // it must be handled by FuText)
254 pCaptionObj->SetLogicRect(aRect);
255 pCaptionObj->SetTailPos(
256 aRect.TopLeft() - Point(aRect.GetWidth() / 2, aRect.GetHeight() / 2));
258 else
260 OSL_FAIL("Object is NO caption object");
263 break;
266 default:
268 pObj->SetLogicRect(aRect);
270 break;
274 SfxItemSet aAttr(pDrDoc->GetItemPool());
275 SetLineEnds(aAttr, *pObj, nID);
276 pObj->SetMergedItemSet(aAttr);
279 return pObj;
282 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */