Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / ribbar / conrect.cxx
blob8d9d468a92f244acfcab1224a2486604640dcf9c
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 <sfx2/bindings.hxx>
21 #include <sfx2/viewfrm.hxx>
22 #include <svx/sdtacitm.hxx>
23 #include <svx/svdobj.hxx>
24 #include <svx/sdtagitm.hxx>
25 #include <svx/sdtakitm.hxx>
26 #include <svx/sdtaditm.hxx>
27 #include <svx/sdtaaitm.hxx>
28 #include <svx/svdview.hxx>
29 #include <svx/svdocapt.hxx>
30 #include <editeng/outlobj.hxx>
31 #include <cmdid.h>
32 #include <view.hxx>
33 #include <edtwin.hxx>
34 #include <wrtsh.hxx>
35 #include <drawbase.hxx>
36 #include <conrect.hxx>
38 ConstRectangle::ConstRectangle( SwWrtShell* pWrtShell, SwEditWin* pEditWin,
39 SwView* pSwView )
40 : SwDrawBase( pWrtShell, pEditWin, pSwView )
41 , m_bMarquee(false)
42 , m_bCapVertical(false)
43 , mbVertical(false)
47 bool ConstRectangle::MouseButtonDown(const MouseEvent& rMEvt)
49 bool bReturn = SwDrawBase::MouseButtonDown(rMEvt);
51 if (bReturn)
53 if (m_pWin->GetSdrDrawMode() == SdrObjKind::Caption)
55 m_pView->NoRotate();
56 if (m_pView->IsDrawSelMode())
58 m_pView->FlipDrawSelMode();
59 m_pSh->GetDrawView()->SetFrameDragSingles(m_pView->IsDrawSelMode());
62 else
64 SdrObject* pObj = m_pView->GetDrawView()->GetCreateObj();
65 if (pObj)
67 SfxItemSet aAttr(pObj->getSdrModelFromSdrObject().GetItemPool());
68 SwFEShell::SetLineEnds(aAttr, *pObj, m_nSlotId);
69 pObj->SetMergedItemSet(aAttr);
74 return bReturn;
77 bool ConstRectangle::MouseButtonUp(const MouseEvent& rMEvt)
79 bool bRet = SwDrawBase::MouseButtonUp(rMEvt);
80 if( bRet )
82 SdrView *pSdrView = m_pSh->GetDrawView();
83 const SdrMarkList& rMarkList = pSdrView->GetMarkedObjectList();
84 SdrObject* pObj = rMarkList.GetMark(0) ? rMarkList.GetMark(0)->GetMarkedSdrObj()
85 : nullptr;
86 switch( m_pWin->GetSdrDrawMode() )
88 case SdrObjKind::Text:
89 if( m_bMarquee )
91 m_pSh->ChgAnchor(RndStdIds::FLY_AS_CHAR);
93 if( pObj )
95 // Set the attributes needed for scrolling
96 SfxItemSetFixed<SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST>
97 aItemSet(pSdrView->GetModel().GetItemPool());
99 aItemSet.Put( makeSdrTextAutoGrowWidthItem( false ) );
100 aItemSet.Put( makeSdrTextAutoGrowHeightItem( false ) );
101 aItemSet.Put( SdrTextAniKindItem( SdrTextAniKind::Scroll ) );
102 aItemSet.Put( SdrTextAniDirectionItem( SdrTextAniDirection::Left ) );
103 aItemSet.Put( SdrTextAniCountItem( 0 ) );
104 aItemSet.Put( SdrTextAniAmountItem(
105 static_cast<sal_Int16>(m_pWin->PixelToLogic(Size(2,1)).Width())) );
107 pObj->SetMergedItemSetAndBroadcast(aItemSet);
110 else if(mbVertical)
112 if (SdrTextObj* pText = DynCastSdrTextObj(pObj))
114 SfxItemSet aSet(pSdrView->GetModel().GetItemPool());
116 pText->SetVerticalWriting(true);
118 aSet.Put(makeSdrTextAutoGrowWidthItem(true));
119 aSet.Put(makeSdrTextAutoGrowHeightItem(false));
120 aSet.Put(SdrTextVertAdjustItem(SDRTEXTVERTADJUST_TOP));
121 aSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_RIGHT));
123 pText->SetMergedItemSet(aSet);
127 if( pObj )
129 SdrPageView* pPV = pSdrView->GetSdrPageView();
130 m_pView->BeginTextEdit( pObj, pPV, m_pWin, true );
132 m_pView->LeaveDrawCreate(); // Switch to selection mode
133 m_pSh->GetView().GetViewFrame().GetBindings().Invalidate(SID_INSERT_DRAW);
134 break;
136 case SdrObjKind::Caption:
138 SdrCaptionObj* pCaptObj = dynamic_cast<SdrCaptionObj*>(pObj);
139 if( m_bCapVertical && pCaptObj )
141 pCaptObj->ForceOutlinerParaObject();
142 OutlinerParaObject* pOPO = pCaptObj->GetOutlinerParaObject();
143 if( pOPO && !pOPO->IsEffectivelyVertical() )
144 pOPO->SetVertical( true );
147 break;
148 default:; //prevent warning
151 return bRet;
154 void ConstRectangle::Activate(const sal_uInt16 nSlotId)
156 m_bMarquee = m_bCapVertical = false;
157 mbVertical = false;
159 switch (nSlotId)
161 case SID_LINE_ARROW_END:
162 case SID_LINE_ARROW_CIRCLE:
163 case SID_LINE_ARROW_SQUARE:
164 case SID_LINE_ARROW_START:
165 case SID_LINE_CIRCLE_ARROW:
166 case SID_LINE_SQUARE_ARROW:
167 case SID_LINE_ARROWS:
168 case SID_DRAW_LINE:
169 case SID_DRAW_XLINE:
170 m_pWin->SetSdrDrawMode(SdrObjKind::Line);
171 break;
173 case SID_DRAW_MEASURELINE:
174 m_pWin->SetSdrDrawMode(SdrObjKind::Measure);
175 break;
177 case SID_DRAW_RECT:
178 m_pWin->SetSdrDrawMode(SdrObjKind::Rectangle);
179 break;
181 case SID_DRAW_ELLIPSE:
182 m_pWin->SetSdrDrawMode(SdrObjKind::CircleOrEllipse);
183 break;
185 case SID_DRAW_TEXT_MARQUEE:
186 m_bMarquee = true;
187 m_pWin->SetSdrDrawMode(SdrObjKind::Text);
188 break;
190 case SID_DRAW_TEXT_VERTICAL:
191 mbVertical = true;
192 m_pWin->SetSdrDrawMode(SdrObjKind::Text);
193 break;
195 case SID_DRAW_TEXT:
196 m_pWin->SetSdrDrawMode(SdrObjKind::Text);
197 break;
199 case SID_DRAW_CAPTION_VERTICAL:
200 m_bCapVertical = true;
201 [[fallthrough]];
202 case SID_DRAW_CAPTION:
203 m_pWin->SetSdrDrawMode(SdrObjKind::Caption);
204 break;
206 default:
207 m_pWin->SetSdrDrawMode(SdrObjKind::NONE);
208 break;
211 SwDrawBase::Activate(nSlotId);
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */