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 <ndtxt.hxx>
24 #include <vcl/settings.hxx>
25 #include <vcl/svapp.hxx>
26 #include <vcl/weldutils.hxx>
27 
29  m_pEditWin( pEditWin )
30 {
31 }
32 
34 {
35 }
36 
38 {
39  m_aControls.clear();
40 }
41 
43 {
44  SwFrameControlPtrMap& rControls = m_aControls[eType];
45 
46  SwFrameControlPtrMap::iterator aIt = rControls.find(pFrame);
47 
48  if (aIt != rControls.end())
49  return aIt->second;
50 
51  return SwFrameControlPtr();
52 }
53 
55 {
56  for ( auto& rEntry : m_aControls )
57  {
58  SwFrameControlPtrMap& rMap = rEntry.second;
59  rMap.erase(pFrame);
60  }
61 }
62 
64 {
65  SwFrameControlPtrMap& rMap = m_aControls[eType];
66  rMap.erase(pFrame);
67 }
68 
70 {
71  for ( const auto& rCtrl : m_aControls[eType] )
72  rCtrl.second->ShowAll( false );
73 }
74 
76 {
77  for ( auto& rEntry : m_aControls )
78  for ( auto& rCtrl : rEntry.second )
79  rCtrl.second->SetReadonly( bReadonly );
80 }
81 
82 void SwFrameControlsManager::SetHeaderFooterControl( const SwPageFrame* pPageFrame, FrameControlType eType, Point aOffset )
83 {
84  assert( eType == FrameControlType::Header || eType == FrameControlType::Footer );
85 
86  // Check if we already have the control
87  SwFrameControlPtr pControl;
88  const bool bHeader = ( eType == FrameControlType::Header );
89 
90  SwFrameControlPtrMap& rControls = m_aControls[eType];
91 
92  SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrame);
93  if (lb != rControls.end() && !(rControls.key_comp()(pPageFrame, lb->first)))
94  pControl = lb->second;
95  else
96  {
97  SwFrameControlPtr pNewControl =
98  std::make_shared<SwFrameControl>( VclPtr<SwHeaderFooterWin>::Create(
99  m_pEditWin, pPageFrame, bHeader ).get() );
100  const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
101  pNewControl->SetReadonly( pViewOpt->IsReadonly() );
102  rControls.insert(lb, make_pair(pPageFrame, pNewControl));
103  pControl.swap( pNewControl );
104  }
105 
106  tools::Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrame->getFrameArea().SVRect() );
107 
108  SwHeaderFooterWin* pWin = dynamic_cast<SwHeaderFooterWin *>(pControl->GetWindow());
109  assert( pWin != nullptr) ;
110  assert( pWin->IsHeader() == bHeader );
111  pWin->SetOffset( aOffset, aPageRect.Left(), aPageRect.Right() );
112 
113  if (!pWin->IsVisible())
114  pControl->ShowAll( true );
115 }
116 
118 {
119  // Check if we already have the control
120  SwFrameControlPtr pControl;
121 
123 
124  SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrame);
125  if (lb != rControls.end() && !(rControls.key_comp()(pPageFrame, lb->first)))
126  pControl = lb->second;
127  else
128  {
129  SwFrameControlPtr pNewControl = std::make_shared<SwFrameControl>(
130  VclPtr<SwPageBreakWin>::Create( m_pEditWin, pPageFrame ).get() );
131  const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
132  pNewControl->SetReadonly( pViewOpt->IsReadonly() );
133 
134  rControls.insert(lb, make_pair(pPageFrame, pNewControl));
135 
136  pControl.swap( pNewControl );
137  }
138 
139  SwPageBreakWin* pWin = static_cast<SwPageBreakWin *>(pControl->GetWindow());
140  assert (pWin != nullptr);
141  pWin->UpdatePosition();
142  if (!pWin->IsVisible())
143  pControl->ShowAll( true );
144 }
145 
146 void SwFrameControlsManager::SetUnfloatTableButton( const SwFlyFrame* pFlyFrame, bool bShow, Point aTopRightPixel )
147 {
148  if(pFlyFrame == nullptr)
149  return;
150 
151  // Check if we already have the control
152  SwFrameControlPtr pControl;
153 
155 
156  SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pFlyFrame);
157  if (lb != rControls.end() && !(rControls.key_comp()(pFlyFrame, lb->first)))
158  pControl = lb->second;
159  else if (!bShow) // Do not create the control when it's not shown
160  return;
161  else
162  {
163  SwFrameControlPtr pNewControl = std::make_shared<SwFrameControl>(
164  VclPtr<UnfloatTableButton>::Create( m_pEditWin, pFlyFrame ).get() );
165  const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
166  pNewControl->SetReadonly( pViewOpt->IsReadonly() );
167 
168  rControls.insert(lb, make_pair(pFlyFrame, pNewControl));
169 
170  pControl.swap( pNewControl );
171  }
172 
173  UnfloatTableButton* pButton = dynamic_cast<UnfloatTableButton*>(pControl->GetWindow());
174  assert(pButton != nullptr);
175  pButton->SetOffset(aTopRightPixel);
176  pControl->ShowAll( bShow );
177 }
178 
180  const OUString& rUIXMLDescription, const OString& rID)
181  : InterimItemWindow(pEditWin, rUIXMLDescription, rID)
182  , m_pEditWin(pEditWin)
183  , m_pFrame(pFrame)
184 {
185 }
186 
188 {
189  // Check if we already have the control
190  SwFrameControlPtr pControl;
191 
193 
194  SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pContentFrame);
195  if (lb != rControls.end() && !(rControls.key_comp()(pContentFrame, lb->first)))
196  {
197  pControl = lb->second;
198  }
199  else
200  {
201  SwFrameControlPtr pNewControl =
202  std::make_shared<SwFrameControl>(VclPtr<SwOutlineContentVisibilityWin>::Create(
203  m_pEditWin, pContentFrame).get());
204  rControls.insert(lb, make_pair(pContentFrame, pNewControl));
205  pControl.swap(pNewControl);
206  }
207 
208  SwOutlineContentVisibilityWin* pWin = dynamic_cast<SwOutlineContentVisibilityWin *>(pControl->GetWindow());
209  assert(pWin != nullptr);
210  pWin->Set();
211 
212  if (pWin->GetSymbol() == ButtonSymbol::SHOW)
213  pWin->Show(); // show the SHOW button immediately
214  else if (!pWin->IsVisible() && pWin->GetSymbol() == ButtonSymbol::HIDE)
215  pWin->ShowAll(true);
216 }
217 
219 {
220  if (m_pFrame->IsPageFrame())
221  return static_cast<const SwPageFrame*>( m_pFrame );
222 
223  if (m_pFrame->IsFlyFrame())
224  return static_cast<const SwFlyFrame*>(m_pFrame)->GetAnchorFrame()->FindPageFrame();
225 
226  return m_pFrame->FindPageFrame();
227 }
228 
230 {
231  m_pEditWin.clear();
232  m_pFrame = nullptr;
235 }
236 
238 {
239  // Get the font and configure it
241  weld::SetPointFont(*m_xVirDev, aFont);
242 }
243 
245 {
246  assert(static_cast<bool>(pWindow));
247  mxWindow.reset( pWindow );
248  mpIFace = dynamic_cast<ISwFrameControl *>( pWindow.get() );
249 }
250 
252 {
253  mpIFace = nullptr;
255 }
256 
258 {
259 }
260 
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetOffset(Point aTopRightPixel)
Base class of the Writer layout elements.
Definition: frame.hxx:315
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:244
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:1211
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:58
SwPageFrame * FindPageFrame()
Definition: frame.hxx:681
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:234
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:423
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:1179
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)