LibreOffice Module sw (master) 1
FrameControlsManager.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#include <edtwin.hxx>
11#include <cntfrm.hxx>
13#include <HeaderFooterWin.hxx>
14#include <PageBreakWin.hxx>
16#include <pagefrm.hxx>
17#include <flyfrm.hxx>
18#include <viewopt.hxx>
19#include <view.hxx>
20#include <wrtsh.hxx>
22#include <vcl/settings.hxx>
23#include <vcl/svapp.hxx>
24#include <vcl/weldutils.hxx>
26
28 m_pEditWin( pEditWin )
29{
30}
31
33{
34}
35
37{
38 m_aControls.clear();
39}
40
42{
44
45 SwFrameControlPtrMap::iterator aIt = rControls.find(pFrame);
46
47 if (aIt != rControls.end())
48 return aIt->second;
49
50 return SwFrameControlPtr();
51}
52
54{
55 for ( auto& rEntry : m_aControls )
56 {
57 SwFrameControlPtrMap& rMap = rEntry.second;
58 rMap.erase(pFrame);
59 }
60}
61
63{
65 rMap.erase(pFrame);
66}
67
69{
70 for ( const auto& rCtrl : m_aControls[eType] )
71 rCtrl.second->ShowAll( false );
72}
73
75{
76 for ( auto& rEntry : m_aControls )
77 for ( auto& rCtrl : rEntry.second )
78 rCtrl.second->SetReadonly( bReadonly );
79}
80
82{
84
85 // Check if we already have the control
86 SwFrameControlPtr pControl;
87 const bool bHeader = ( eType == FrameControlType::Header );
88
90
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
95 {
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 );
103 }
104
105 tools::Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrame->getFrameArea().SVRect() );
106
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() );
111
112 if (!pWin->IsVisible())
113 pControl->ShowAll( true );
114}
115
117{
118 // Check if we already have the control
119 SwFrameControlPtr pControl;
120
122
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
127 {
128 SwFrameControlPtr pNewControl = std::make_shared<SwFrameControl>(
130 const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
131 pNewControl->SetReadonly( pViewOpt->IsReadonly() );
132
133 rControls.insert(lb, make_pair(pPageFrame, pNewControl));
134
135 pControl.swap( pNewControl );
136 }
137
138 SwBreakDashedLine* pWin = static_cast<SwBreakDashedLine*>(pControl->GetWindow());
139 assert (pWin != nullptr);
140 pWin->UpdatePosition();
141 if (!pWin->IsVisible())
142 pControl->ShowAll( true );
143}
144
145void SwFrameControlsManager::SetUnfloatTableButton( const SwFlyFrame* pFlyFrame, bool bShow, Point aTopRightPixel )
146{
147 if(pFlyFrame == nullptr)
148 return;
149
150 // Check if we already have the control
151 SwFrameControlPtr pControl;
152
154
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
161 {
162 SwFrameControlPtr pNewControl = std::make_shared<SwFrameControl>(
164 const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
165 pNewControl->SetReadonly( pViewOpt->IsReadonly() );
166
167 rControls.insert(lb, make_pair(pFlyFrame, pNewControl));
168
169 pControl.swap( pNewControl );
170 }
171
172 UnfloatTableButton* pButton = dynamic_cast<UnfloatTableButton*>(pControl->GetWindow());
173 assert(pButton != nullptr);
174 pButton->SetOffset(aTopRightPixel);
175 pControl->ShowAll( bShow );
176}
177
179 Point aTopLeftPixel)
180{
181 SwFrameControlPtr pControl;
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
189 {
190 pControl = std::make_shared<SwFrameControl>(
192 const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
193 pControl->SetReadonly(pViewOpt->IsReadonly());
194 rControls[nullptr] = pControl;
195 }
196
197 auto pButton = dynamic_cast<SwContentControlAliasButton*>(pControl->GetWindow());
198 assert(pButton);
199 pButton->SetOffset(aTopLeftPixel);
200 pButton->SetContentControl(pContentControl);
201 pControl->ShowAll(true);
202}
203
205 const OUString& rUIXMLDescription, const OUString& rID)
206 : InterimItemWindow(pEditWin, rUIXMLDescription, rID)
207 , m_pEditWin(pEditWin)
208 , m_pFrame(pFrame)
209{
210}
211
213{
214 // Check if we already have the control
215 SwFrameControlPtr pControl;
216
218
219 SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pContentFrame);
220 if (lb != rControls.end() && !(rControls.key_comp()(pContentFrame, lb->first)))
221 {
222 pControl = lb->second;
223 }
224 else
225 {
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);
231 }
232
233 SwOutlineContentVisibilityWin* pWin = dynamic_cast<SwOutlineContentVisibilityWin *>(pControl->GetWindow());
234 assert(pWin != nullptr);
235 pWin->Set();
236
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);
241}
242
244{
245 if (pFrame->IsPageFrame())
246 return static_cast<const SwPageFrame*>(pFrame);
247
248 if (pFrame->IsFlyFrame())
249 return static_cast<const SwFlyFrame*>(pFrame)->GetAnchorFrame()->FindPageFrame();
250
251 return pFrame->FindPageFrame();
252}
253
255{
257}
258
260{
262 m_pFrame = nullptr;
265}
266
268{
269 // Get the font and configure it
271 weld::SetPointFont(rVirDev, aFont);
272}
273
275{
277}
278
280{
281 assert(static_cast<bool>(pWindow));
282 mxWindow.reset( pWindow );
283 mpIFace = dynamic_cast<ISwFrameControl *>( pWindow.get() );
284}
285
287{
288 mpIFace = nullptr;
290}
291
292ISwFrameControl::~ISwFrameControl()
293{
294}
295
296/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::map< const SwFrame *, SwFrameControlPtr > SwFrameControlPtrMap
std::shared_ptr< SwFrameControl > SwFrameControlPtr
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
virtual void dispose() override
const vcl::Font & GetToolFont() const
const SwFrame * GetAnchorFrame() const
Class for the page break control window.
void UpdatePosition(const std::optional< Point > &xEvtPt=std::optional< Point >())
In case the content control has an alias/title, this widget shows it above the top left corner of the...
Stores the properties of a content control.
SwContentFrame is the layout for content nodes: a common base class for text (paragraph) and non-text...
Definition: cntfrm.hxx:59
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:61
general base class for all free-flowing frames
Definition: flyfrm.hxx:79
SwFrameControl(const VclPtr< vcl::Window > &pWindow)
ISwFrameControl * mpIFace
VclPtr< vcl::Window > mxWindow
void HideControls(FrameControlType eType)
void SetReadonlyControls(bool bReadonly)
std::map< FrameControlType, SwFrameControlPtrMap > m_aControls
void SetHeaderFooterControl(const SwPageFrame *pPageFrame, FrameControlType eType, Point aOffset)
void SetContentControlAliasButton(SwContentControl *pContentControl, Point aTopLeftPixel)
void SetPageBreakControl(const SwPageFrame *pPageFrame)
void RemoveControlsByType(FrameControlType eType, const SwFrame *pFrame)
VclPtr< SwEditWin > m_pEditWin
void SetOutlineContentVisibilityButton(const SwContentFrame *pContentFrame)
void SetUnfloatTableButton(const SwFlyFrame *pFlyFrame, bool bShow, Point aTopRightPixel=Point())
SwFrameControlsManager(SwEditWin *pEditWin)
SwFrameControlPtr GetControl(FrameControlType eType, const SwFrame *pFrame)
void RemoveControls(const SwFrame *pFrame)
VclPtr< VirtualDevice > m_xVirDev
const SwFrame * m_pFrame
SwFrameMenuButtonBase(SwEditWin *pEditWin, const SwFrame *pFrame, const OUString &rUIXMLDescription, const OUString &rID)
const SwPageFrame * GetPageFrame() const
virtual void dispose() override
VclPtr< SwEditWin > m_pEditWin
Base class of the Writer layout elements.
Definition: frame.hxx:315
bool IsPageFrame() const
Definition: frame.hxx:1184
bool IsFlyFrame() const
Definition: frame.hxx:1216
SwPageFrame * FindPageFrame()
Definition: frame.hxx:686
Class for the header and footer separator control window.
void SetOffset(Point aOffset, tools::Long nXLineStart, tools::Long nXLineEnd)
virtual void ShowAll(bool bShow) override
A page of the document layout.
Definition: pagefrm.hxx:60
bool IsReadonly() const
Definition: viewopt.hxx:627
Class for unfloat table button.
void SetOffset(Point aTopRightPixel)
void disposeAndClear()
void clear()
void reset(reference_type *pBody)
reference_type * get() const
constexpr tools::Long Right() const
constexpr tools::Long Left() const
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
bool IsVisible() const
DocumentType eType
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
void SetPointFont(OutputDevice &rDevice, const vcl::Font &rFont)
FrameControlType
Definition: swtypes.hxx:246