Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / docvw / FrameControlsManager.cxx
blob6fb7aac7458f3159da701eac61ed868069c58343
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/.
8 */
10 #include <edtwin.hxx>
11 #include <cntfrm.hxx>
12 #include <FrameControlsManager.hxx>
13 #include <HeaderFooterWin.hxx>
14 #include <PageBreakWin.hxx>
15 #include <UnfloatTableButton.hxx>
16 #include <pagefrm.hxx>
17 #include <flyfrm.hxx>
18 #include <viewopt.hxx>
19 #include <view.hxx>
20 #include <wrtsh.hxx>
21 #include <OutlineContentVisibilityWin.hxx>
22 #include <vcl/settings.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/weldutils.hxx>
25 #include <contentcontrolaliasbutton.hxx>
27 SwFrameControlsManager::SwFrameControlsManager( SwEditWin* pEditWin ) :
28 m_pEditWin( pEditWin )
32 SwFrameControlsManager::~SwFrameControlsManager()
36 void SwFrameControlsManager::dispose()
38 m_aControls.clear();
41 SwFrameControlPtr SwFrameControlsManager::GetControl( FrameControlType eType, const SwFrame* pFrame )
43 SwFrameControlPtrMap& rControls = m_aControls[eType];
45 SwFrameControlPtrMap::iterator aIt = rControls.find(pFrame);
47 if (aIt != rControls.end())
48 return aIt->second;
50 return SwFrameControlPtr();
53 void SwFrameControlsManager::RemoveControls( const SwFrame* pFrame )
55 for ( auto& rEntry : m_aControls )
57 SwFrameControlPtrMap& rMap = rEntry.second;
58 rMap.erase(pFrame);
62 void SwFrameControlsManager::RemoveControlsByType( FrameControlType eType, const SwFrame* pFrame )
64 SwFrameControlPtrMap& rMap = m_aControls[eType];
65 rMap.erase(pFrame);
68 void SwFrameControlsManager::HideControls( FrameControlType eType )
70 for ( const auto& rCtrl : m_aControls[eType] )
71 rCtrl.second->ShowAll( false );
74 void SwFrameControlsManager::SetReadonlyControls( bool bReadonly )
76 for ( auto& rEntry : m_aControls )
77 for ( auto& rCtrl : rEntry.second )
78 rCtrl.second->SetReadonly( bReadonly );
81 void SwFrameControlsManager::SetHeaderFooterControl( const SwPageFrame* pPageFrame, FrameControlType eType, Point aOffset )
83 assert( eType == FrameControlType::Header || eType == FrameControlType::Footer );
85 // Check if we already have the control
86 SwFrameControlPtr pControl;
87 const bool bHeader = ( eType == FrameControlType::Header );
89 SwFrameControlPtrMap& rControls = m_aControls[eType];
91 SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrame);
92 if (lb != rControls.end() && !(rControls.key_comp()(pPageFrame, lb->first)))
93 pControl = lb->second;
94 else
96 SwFrameControlPtr pNewControl =
97 std::make_shared<SwFrameControl>( VclPtr<SwHeaderFooterDashedLine>::Create(
98 m_pEditWin, pPageFrame, bHeader ).get() );
99 const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
100 pNewControl->SetReadonly( pViewOpt->IsReadonly() );
101 rControls.insert(lb, make_pair(pPageFrame, pNewControl));
102 pControl.swap( pNewControl );
105 tools::Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrame->getFrameArea().SVRect() );
107 SwHeaderFooterDashedLine* pWin = dynamic_cast<SwHeaderFooterDashedLine*>(pControl->GetWindow());
108 assert( pWin != nullptr) ;
109 assert( pWin->IsHeader() == bHeader );
110 pWin->SetOffset( aOffset, aPageRect.Left(), aPageRect.Right() );
112 if (!pWin->IsVisible())
113 pControl->ShowAll( true );
116 void SwFrameControlsManager::SetPageBreakControl( const SwPageFrame* pPageFrame )
118 // Check if we already have the control
119 SwFrameControlPtr pControl;
121 SwFrameControlPtrMap& rControls = m_aControls[FrameControlType::PageBreak];
123 SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrame);
124 if (lb != rControls.end() && !(rControls.key_comp()(pPageFrame, lb->first)))
125 pControl = lb->second;
126 else
128 SwFrameControlPtr pNewControl = std::make_shared<SwFrameControl>(
129 VclPtr<SwBreakDashedLine>::Create( m_pEditWin, pPageFrame ).get() );
130 const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
131 pNewControl->SetReadonly( pViewOpt->IsReadonly() );
133 rControls.insert(lb, make_pair(pPageFrame, pNewControl));
135 pControl.swap( pNewControl );
138 SwBreakDashedLine* pWin = static_cast<SwBreakDashedLine*>(pControl->GetWindow());
139 assert (pWin != nullptr);
140 pWin->UpdatePosition();
141 if (!pWin->IsVisible())
142 pControl->ShowAll( true );
145 void SwFrameControlsManager::SetUnfloatTableButton( const SwFlyFrame* pFlyFrame, bool bShow, Point aTopRightPixel )
147 if(pFlyFrame == nullptr)
148 return;
150 // Check if we already have the control
151 SwFrameControlPtr pControl;
153 SwFrameControlPtrMap& rControls = m_aControls[FrameControlType::FloatingTable];
155 SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pFlyFrame);
156 if (lb != rControls.end() && !(rControls.key_comp()(pFlyFrame, lb->first)))
157 pControl = lb->second;
158 else if (!bShow) // Do not create the control when it's not shown
159 return;
160 else
162 SwFrameControlPtr pNewControl = std::make_shared<SwFrameControl>(
163 VclPtr<UnfloatTableButton>::Create( m_pEditWin, pFlyFrame ).get() );
164 const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
165 pNewControl->SetReadonly( pViewOpt->IsReadonly() );
167 rControls.insert(lb, make_pair(pFlyFrame, pNewControl));
169 pControl.swap( pNewControl );
172 UnfloatTableButton* pButton = dynamic_cast<UnfloatTableButton*>(pControl->GetWindow());
173 assert(pButton != nullptr);
174 pButton->SetOffset(aTopRightPixel);
175 pControl->ShowAll( bShow );
178 void SwFrameControlsManager::SetContentControlAliasButton(SwContentControl* pContentControl,
179 Point aTopLeftPixel)
181 SwFrameControlPtr pControl;
182 SwFrameControlPtrMap& rControls = m_aControls[FrameControlType::ContentControl];
183 // We don't really have a key, the SwPaM's mark decides what is the single content control in
184 // this view that can have an alias button.
185 SwFrameControlPtrMap::iterator it = rControls.find(nullptr);
186 if (it != rControls.end())
187 pControl = it->second;
188 else
190 pControl = std::make_shared<SwFrameControl>(
191 VclPtr<SwContentControlAliasButton>::Create(m_pEditWin, pContentControl).get());
192 const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
193 pControl->SetReadonly(pViewOpt->IsReadonly());
194 rControls[nullptr] = pControl;
197 auto pButton = dynamic_cast<SwContentControlAliasButton*>(pControl->GetWindow());
198 assert(pButton);
199 pButton->SetOffset(aTopLeftPixel);
200 pButton->SetContentControl(pContentControl);
201 pControl->ShowAll(true);
204 SwFrameMenuButtonBase::SwFrameMenuButtonBase(SwEditWin* pEditWin, const SwFrame* pFrame,
205 const OUString& rUIXMLDescription, const OUString& rID)
206 : InterimItemWindow(pEditWin, rUIXMLDescription, rID)
207 , m_pEditWin(pEditWin)
208 , m_pFrame(pFrame)
212 void SwFrameControlsManager::SetOutlineContentVisibilityButton(const SwContentFrame* pContentFrame)
214 // Check if we already have the control
215 SwFrameControlPtr pControl;
217 SwFrameControlPtrMap& rControls = m_aControls[FrameControlType::Outline];
219 SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pContentFrame);
220 if (lb != rControls.end() && !(rControls.key_comp()(pContentFrame, lb->first)))
222 pControl = lb->second;
224 else
226 SwFrameControlPtr pNewControl =
227 std::make_shared<SwFrameControl>(VclPtr<SwOutlineContentVisibilityWin>::Create(
228 m_pEditWin, pContentFrame).get());
229 rControls.insert(lb, make_pair(pContentFrame, pNewControl));
230 pControl.swap(pNewControl);
233 SwOutlineContentVisibilityWin* pWin = dynamic_cast<SwOutlineContentVisibilityWin *>(pControl->GetWindow());
234 assert(pWin != nullptr);
235 pWin->Set();
237 if (pWin->GetSymbol() == ButtonSymbol::SHOW)
238 pWin->Show(); // show the SHOW button immediately
239 else if (!pWin->IsVisible() && pWin->GetSymbol() == ButtonSymbol::HIDE)
240 pWin->ShowAll(true);
243 const SwPageFrame* SwFrameMenuButtonBase::GetPageFrame(const SwFrame* pFrame)
245 if (pFrame->IsPageFrame())
246 return static_cast<const SwPageFrame*>(pFrame);
248 if (pFrame->IsFlyFrame())
249 return static_cast<const SwFlyFrame*>(pFrame)->GetAnchorFrame()->FindPageFrame();
251 return pFrame->FindPageFrame();
254 const SwPageFrame* SwFrameMenuButtonBase::GetPageFrame() const
256 return SwFrameMenuButtonBase::GetPageFrame(m_pFrame);
259 void SwFrameMenuButtonBase::dispose()
261 m_pEditWin.clear();
262 m_pFrame = nullptr;
263 m_xVirDev.disposeAndClear();
264 InterimItemWindow::dispose();
267 void SwFrameMenuButtonBase::SetVirDevFont(OutputDevice& rVirDev)
269 // Get the font and configure it
270 vcl::Font aFont = Application::GetSettings().GetStyleSettings().GetToolFont();
271 weld::SetPointFont(rVirDev, aFont);
274 void SwFrameMenuButtonBase::SetVirDevFont()
276 SetVirDevFont(*m_xVirDev);
279 SwFrameControl::SwFrameControl( const VclPtr<vcl::Window> &pWindow )
281 assert(static_cast<bool>(pWindow));
282 mxWindow.reset( pWindow );
283 mpIFace = dynamic_cast<ISwFrameControl *>( pWindow.get() );
286 SwFrameControl::~SwFrameControl()
288 mpIFace = nullptr;
289 mxWindow.disposeAndClear();
292 ISwFrameControl::~ISwFrameControl()
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */