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>
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>
22 #include <vcl/settings.hxx>
23 #include <vcl/svapp.hxx>
24 #include <vcl/weldutils.hxx>
25 
27  m_pEditWin( pEditWin )
28 {
29 }
30 
32 {
33 }
34 
36 {
37  m_aControls.clear();
38 }
39 
41 {
42  SwFrameControlPtrMap& rControls = m_aControls[eType];
43 
44  SwFrameControlPtrMap::iterator aIt = rControls.find(pFrame);
45 
46  if (aIt != rControls.end())
47  return aIt->second;
48 
49  return SwFrameControlPtr();
50 }
51 
53 {
54  for ( auto& rEntry : m_aControls )
55  {
56  SwFrameControlPtrMap& rMap = rEntry.second;
57  rMap.erase(pFrame);
58  }
59 }
60 
62 {
63  SwFrameControlPtrMap& rMap = m_aControls[eType];
64  rMap.erase(pFrame);
65 }
66 
68 {
69  for ( const auto& rCtrl : m_aControls[eType] )
70  rCtrl.second->ShowAll( false );
71 }
72 
74 {
75  for ( auto& rEntry : m_aControls )
76  for ( auto& rCtrl : rEntry.second )
77  rCtrl.second->SetReadonly( bReadonly );
78 }
79 
80 void SwFrameControlsManager::SetHeaderFooterControl( const SwPageFrame* pPageFrame, FrameControlType eType, Point aOffset )
81 {
82  assert( eType == FrameControlType::Header || eType == FrameControlType::Footer );
83 
84  // Check if we already have the control
85  SwFrameControlPtr pControl;
86  const bool bHeader = ( eType == FrameControlType::Header );
87 
88  SwFrameControlPtrMap& rControls = m_aControls[eType];
89 
90  SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrame);
91  if (lb != rControls.end() && !(rControls.key_comp()(pPageFrame, lb->first)))
92  pControl = lb->second;
93  else
94  {
95  SwFrameControlPtr pNewControl =
96  std::make_shared<SwFrameControl>( VclPtr<SwHeaderFooterWin>::Create(
97  m_pEditWin, pPageFrame, bHeader ).get() );
98  const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
99  pNewControl->SetReadonly( pViewOpt->IsReadonly() );
100  rControls.insert(lb, make_pair(pPageFrame, pNewControl));
101  pControl.swap( pNewControl );
102  }
103 
104  tools::Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrame->getFrameArea().SVRect() );
105 
106  SwHeaderFooterWin* pWin = dynamic_cast<SwHeaderFooterWin *>(pControl->GetWindow());
107  assert( pWin != nullptr) ;
108  assert( pWin->IsHeader() == bHeader );
109  pWin->SetOffset( aOffset, aPageRect.Left(), aPageRect.Right() );
110 
111  if (!pWin->IsVisible())
112  pControl->ShowAll( true );
113 }
114 
116 {
117  // Check if we already have the control
118  SwFrameControlPtr pControl;
119 
121 
122  SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrame);
123  if (lb != rControls.end() && !(rControls.key_comp()(pPageFrame, lb->first)))
124  pControl = lb->second;
125  else
126  {
127  SwFrameControlPtr pNewControl = std::make_shared<SwFrameControl>(
128  VclPtr<SwPageBreakWin>::Create( m_pEditWin, pPageFrame ).get() );
129  const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
130  pNewControl->SetReadonly( pViewOpt->IsReadonly() );
131 
132  rControls.insert(lb, make_pair(pPageFrame, pNewControl));
133 
134  pControl.swap( pNewControl );
135  }
136 
137  SwPageBreakWin* pWin = static_cast<SwPageBreakWin *>(pControl->GetWindow());
138  assert (pWin != nullptr);
139  pWin->UpdatePosition();
140  if (!pWin->IsVisible())
141  pControl->ShowAll( true );
142 }
143 
144 void SwFrameControlsManager::SetUnfloatTableButton( const SwFlyFrame* pFlyFrame, bool bShow, Point aTopRightPixel )
145 {
146  if(pFlyFrame == nullptr)
147  return;
148 
149  // Check if we already have the control
150  SwFrameControlPtr pControl;
151 
153 
154  SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pFlyFrame);
155  if (lb != rControls.end() && !(rControls.key_comp()(pFlyFrame, lb->first)))
156  pControl = lb->second;
157  else if (!bShow) // Do not create the control when it's not shown
158  return;
159  else
160  {
161  SwFrameControlPtr pNewControl = std::make_shared<SwFrameControl>(
162  VclPtr<UnfloatTableButton>::Create( m_pEditWin, pFlyFrame ).get() );
163  const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
164  pNewControl->SetReadonly( pViewOpt->IsReadonly() );
165 
166  rControls.insert(lb, make_pair(pFlyFrame, pNewControl));
167 
168  pControl.swap( pNewControl );
169  }
170 
171  UnfloatTableButton* pButton = dynamic_cast<UnfloatTableButton*>(pControl->GetWindow());
172  assert(pButton != nullptr);
173  pButton->SetOffset(aTopRightPixel);
174  pControl->ShowAll( bShow );
175 }
176 
178  const OUString& rUIXMLDescription, const OString& rID)
179  : InterimItemWindow(pEditWin, rUIXMLDescription, rID)
180  , m_pEditWin(pEditWin)
181  , m_pFrame(pFrame)
182 {
183 }
184 
186 {
187  // Check if we already have the control
188  SwFrameControlPtr pControl;
189 
191 
192  SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pContentFrame);
193  if (lb != rControls.end() && !(rControls.key_comp()(pContentFrame, lb->first)))
194  {
195  pControl = lb->second;
196  }
197  else
198  {
199  SwFrameControlPtr pNewControl =
200  std::make_shared<SwFrameControl>(VclPtr<SwOutlineContentVisibilityWin>::Create(
201  m_pEditWin, pContentFrame).get());
202  rControls.insert(lb, make_pair(pContentFrame, pNewControl));
203  pControl.swap(pNewControl);
204  }
205 
206  SwOutlineContentVisibilityWin* pWin = dynamic_cast<SwOutlineContentVisibilityWin *>(pControl->GetWindow());
207  assert(pWin != nullptr);
208  pWin->Set();
209 
210  if (pWin->GetSymbol() == ButtonSymbol::SHOW)
211  pWin->Show(); // show the SHOW button immediately
212  else if (!pWin->IsVisible() && pWin->GetSymbol() == ButtonSymbol::HIDE)
213  pWin->ShowAll(true);
214 }
215 
217 {
218  if (m_pFrame->IsPageFrame())
219  return static_cast<const SwPageFrame*>( m_pFrame );
220 
221  if (m_pFrame->IsFlyFrame())
222  return static_cast<const SwFlyFrame*>(m_pFrame)->GetAnchorFrame()->FindPageFrame();
223 
224  return m_pFrame->FindPageFrame();
225 }
226 
228 {
229  m_pEditWin.clear();
230  m_pFrame = nullptr;
233 }
234 
236 {
237  // Get the font and configure it
239  weld::SetPointFont(*m_xVirDev, aFont);
240 }
241 
243 {
244  assert(static_cast<bool>(pWindow));
245  mxWindow.reset( pWindow );
246  mpIFace = dynamic_cast<ISwFrameControl *>( pWindow.get() );
247 }
248 
250 {
251  mpIFace = nullptr;
253 }
254 
256 {
257 }
258 
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetOffset(Point aTopRightPixel)
Base class of the Writer layout elements.
Definition: frame.hxx:314
VclPtr< SwEditWin > m_pEditWin
virtual void dispose() override
void SetReadonly(bool bSet)
Definition: viewopt.hxx:464
constexpr tools::Long Left() const
const SwView & GetView() const
Definition: edtwin.hxx:245
void UpdatePosition(const std::optional< Point > &xEvtPt=std::optional< Point >())
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
SwFrameMenuButtonBase(SwEditWin *pEditWin, const SwFrame *pFrame, const OUString &rUIXMLDescription, const OString &rID)
void HideControls(FrameControlType eType)
void RemoveControls(const SwFrame *pFrame)
void SetOutlineContentVisibilityButton(const SwContentFrame *pContentFrame)
SwWrtShell & GetWrtShell() const
Definition: view.hxx:413
bool IsFlyFrame() const
Definition: frame.hxx:1210
bool IsReadonly() const
Definition: viewopt.hxx:463
Class for the page break control window.
void SetHeaderFooterControl(const SwPageFrame *pPageFrame, FrameControlType eType, Point aOffset)
Abstract interface to be implemented by writer FrameControls.
void SetPageBreakControl(const SwPageFrame *pPageFrame)
void SetReadonlyControls(bool bReadonly)
void RemoveControlsByType(FrameControlType eType, const SwFrame *pFrame)
void clear()
const vcl::Font & GetToolFont() const
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:59
SwPageFrame * FindPageFrame()
Definition: frame.hxx:680
constexpr tools::Long Right() const
void SetOffset(Point aOffset, tools::Long nXLineStart, tools::Long nXLineEnd)
VclPtr< vcl::Window > mxWindow
virtual void ShowAll(bool bShow) override
A page of the document layout.
Definition: pagefrm.hxx:57
void reset(vcl::Window *pBody)
Class for the header and footer separator control window.
const SwFrame * m_pFrame
FrameControlType
Definition: swtypes.hxx:233
VclPtr< SwEditWin > m_pEditWin
const SwPageFrame * GetPageFrame() const
general base class for all free-flowing frames
Definition: flyfrm.hxx:78
Class for unfloat table button.
std::map< FrameControlType, SwFrameControlPtrMap > m_aControls
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:428
virtual void dispose() override
bool IsVisible() const
if(aStr!=aBuf) UpdateName_Impl(m_xFollowLb.get()
static VclPtr< reference_type > Create(Arg &&...arg)
void SetPointFont(OutputDevice &rDevice, const vcl::Font &rFont)
bool IsPageFrame() const
Definition: frame.hxx:1178
SwFrameControlPtr GetControl(FrameControlType eType, const SwFrame *pFrame)
bool IsHeader() const
ISwFrameControl * mpIFace
VclPtr< VirtualDevice > m_xVirDev
reference_type * get() const
void SetUnfloatTableButton(const SwFlyFrame *pFlyFrame, bool bShow, Point aTopRightPixel=Point())
std::map< const SwFrame *, SwFrameControlPtr > SwFrameControlPtrMap
std::shared_ptr< SwFrameControl > SwFrameControlPtr
SwFrameControlsManager(SwEditWin *pEditWin)
SwFrameControl(const VclPtr< vcl::Window > &pWindow)
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)