1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
12 #include <FrameControlsManager.hxx>
13 #include <HeaderFooterWin.hxx>
14 #include <PageBreakWin.hxx>
15 #include <UnfloatTableButton.hxx>
16 #include <pagefrm.hxx>
18 #include <viewopt.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()
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())
50 return SwFrameControlPtr();
53 void SwFrameControlsManager::RemoveControls( const SwFrame
* pFrame
)
55 for ( auto& rEntry
: m_aControls
)
57 SwFrameControlPtrMap
& rMap
= rEntry
.second
;
62 void SwFrameControlsManager::RemoveControlsByType( FrameControlType eType
, const SwFrame
* pFrame
)
64 SwFrameControlPtrMap
& rMap
= m_aControls
[eType
];
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
;
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
;
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)
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
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
,
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
;
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());
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
)
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
;
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);
237 if (pWin
->GetSymbol() == ButtonSymbol::SHOW
)
238 pWin
->Show(); // show the SHOW button immediately
239 else if (!pWin
->IsVisible() && pWin
->GetSymbol() == ButtonSymbol::HIDE
)
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()
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()
289 mxWindow
.disposeAndClear();
292 ISwFrameControl::~ISwFrameControl()
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */