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