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 <FrameControlsManager.hxx>
12 #include <HeaderFooterWin.hxx>
13 #include <PageBreakWin.hxx>
14 #include <UnfloatTableButton.hxx>
15 #include <pagefrm.hxx>
16 #include <flyfrm.hxx>
17 #include <viewopt.hxx>
18 #include <view.hxx>
19 #include <wrtsh.hxx>
20 
21 using namespace std;
22 
24  m_pEditWin( pEditWin ),
25  m_aControls( )
26 {
27 }
28 
30 {
31 }
32 
34 {
35  m_aControls.clear();
36 }
37 
39 {
40  SwFrameControlPtrMap& rControls = m_aControls[eType];
41 
42  SwFrameControlPtrMap::iterator aIt = rControls.find(pFrame);
43 
44  if (aIt != rControls.end())
45  return aIt->second;
46 
47  return SwFrameControlPtr();
48 }
49 
51 {
52  for ( auto& rEntry : m_aControls )
53  {
54  SwFrameControlPtrMap& rMap = rEntry.second;
55  rMap.erase(pFrame);
56  }
57 }
58 
60 {
61  SwFrameControlPtrMap& rMap = m_aControls[eType];
62  rMap.erase(pFrame);
63 }
64 
66 {
67  for ( const auto& rCtrl : m_aControls[eType] )
68  rCtrl.second->ShowAll( false );
69 }
70 
72 {
73  for ( auto& rEntry : m_aControls )
74  for ( auto& rCtrl : rEntry.second )
75  rCtrl.second->SetReadonly( bReadonly );
76 }
77 
79 {
80  assert( eType == Header || eType == Footer );
81 
82  // Check if we already have the control
83  SwFrameControlPtr pControl;
84  const bool bHeader = ( eType == Header );
85 
86  SwFrameControlPtrMap& rControls = m_aControls[eType];
87 
88  SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrame);
89  if (lb != rControls.end() && !(rControls.key_comp()(pPageFrame, lb->first)))
90  pControl = lb->second;
91  else
92  {
93  SwFrameControlPtr pNewControl(
95  m_pEditWin, pPageFrame, bHeader ).get() ) );
96  const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
97  pNewControl->SetReadonly( pViewOpt->IsReadonly() );
98  rControls.insert(lb, make_pair(pPageFrame, pNewControl));
99  pControl.swap( pNewControl );
100  }
101 
102  tools::Rectangle aPageRect = m_pEditWin->LogicToPixel( pPageFrame->getFrameArea().SVRect() );
103 
104  SwHeaderFooterWin* pWin = dynamic_cast<SwHeaderFooterWin *>(pControl->GetWindow());
105  assert( pWin != nullptr) ;
106  assert( pWin->IsHeader() == bHeader );
107  pWin->SetOffset( aOffset, aPageRect.Left(), aPageRect.Right() );
108 
109  if (!pWin->IsVisible())
110  pControl->ShowAll( true );
111 }
112 
114 {
115  // Check if we already have the control
116  SwFrameControlPtr pControl;
117 
119 
120  SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pPageFrame);
121  if (lb != rControls.end() && !(rControls.key_comp()(pPageFrame, lb->first)))
122  pControl = lb->second;
123  else
124  {
125  SwFrameControlPtr pNewControl( new SwFrameControl(
126  VclPtr<SwPageBreakWin>::Create( m_pEditWin, pPageFrame ).get() ) );
127  const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
128  pNewControl->SetReadonly( pViewOpt->IsReadonly() );
129 
130  rControls.insert(lb, make_pair(pPageFrame, pNewControl));
131 
132  pControl.swap( pNewControl );
133  }
134 
135  SwPageBreakWin* pWin = dynamic_cast<SwPageBreakWin *>(pControl->GetWindow());
136  assert (pWin != nullptr);
137  pWin->UpdatePosition();
138  if (!pWin->IsVisible())
139  pControl->ShowAll( true );
140 }
141 
142 void SwFrameControlsManager::SetUnfloatTableButton( const SwFlyFrame* pFlyFrame, bool bShow, Point aTopRightPixel )
143 {
144  if(pFlyFrame == nullptr)
145  return;
146 
147  // Check if we already have the control
148  SwFrameControlPtr pControl;
149 
151 
152  SwFrameControlPtrMap::iterator lb = rControls.lower_bound(pFlyFrame);
153  if (lb != rControls.end() && !(rControls.key_comp()(pFlyFrame, lb->first)))
154  pControl = lb->second;
155  else if (!bShow) // Do not create the control when it's not shown
156  return;
157  else
158  {
159  SwFrameControlPtr pNewControl( new SwFrameControl(
160  VclPtr<UnfloatTableButton>::Create( m_pEditWin, pFlyFrame ).get() ) );
161  const SwViewOption* pViewOpt = m_pEditWin->GetView().GetWrtShell().GetViewOptions();
162  pNewControl->SetReadonly( pViewOpt->IsReadonly() );
163 
164  rControls.insert(lb, make_pair(pFlyFrame, pNewControl));
165 
166  pControl.swap( pNewControl );
167  }
168 
169  UnfloatTableButton* pButton = dynamic_cast<UnfloatTableButton*>(pControl->GetWindow());
170  assert(pButton != nullptr);
171  pButton->SetOffset(aTopRightPixel);
172  pControl->ShowAll( bShow );
173 }
174 
176  MenuButton( pEditWin, WB_DIALOGCONTROL ),
177  m_pEditWin( pEditWin ),
178  m_pFrame( pFrame )
179 {
180 }
181 
183 {
184  if (m_pFrame->IsPageFrame())
185  return static_cast<const SwPageFrame*>( m_pFrame );
186 
187  if (m_pFrame->IsFlyFrame())
188  return static_cast<const SwFlyFrame*>(m_pFrame)->GetAnchorFrame()->FindPageFrame();
189 
190  return m_pFrame->FindPageFrame();
191 }
192 
194 {
195  m_pEditWin.clear();
196  m_pFrame = nullptr;
198 }
199 
201 {
202  assert(static_cast<bool>(pWindow));
203  mxWindow.reset( pWindow );
204  mpIFace = dynamic_cast<ISwFrameControl *>( pWindow.get() );
205 }
206 
208 {
209  mpIFace = nullptr;
211 }
212 
214 {
215 }
216 
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetOffset(Point aTopRightPixel)
Base class of the Writer layout elements.
Definition: frame.hxx:295
VclPtr< SwEditWin > m_pEditWin
virtual void dispose() override
void SetReadonly(bool bSet)
Definition: viewopt.hxx:418
const SwView & GetView() const
Definition: edtwin.hxx:240
virtual void dispose() override
void HideControls(FrameControlType eType)
void RemoveControls(const SwFrame *pFrame)
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
bool IsFlyFrame() const
Definition: frame.hxx:1186
bool IsReadonly() const
Definition: viewopt.hxx:417
long Right() const
Class for the page break control window.
if(nullptr==pCandidateA||nullptr==pCandidateB)
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)
WinBits const WB_DIALOGCONTROL
void RemoveControlsByType(FrameControlType eType, const SwFrame *pFrame)
void clear()
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:658
VclPtr< vcl::Window > mxWindow
A page of the document layout.
Definition: pagefrm.hxx:40
void reset(vcl::Window *pBody)
Class for the header and footer separator control window.
const SwFrame * m_pFrame
FrameControlType
Definition: swtypes.hxx:246
void SetOffset(Point aOffset, long nXLineStart, long nXLineEnd)
VclPtr< SwEditWin > m_pEditWin
general base class for all free-flowing frames
Definition: flyfrm.hxx:60
Class for unfloat table button.
SwFrameMenuButtonBase(SwEditWin *pEditWin, const SwFrame *pFrame)
std::map< FrameControlType, SwFrameControlPtrMap > m_aControls
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:426
bool IsVisible() const
Header
bool IsPageFrame() const
Definition: frame.hxx:1154
SwFrameControlPtr GetControl(FrameControlType eType, const SwFrame *pFrame)
long Left() const
ISwFrameControl * mpIFace
const SwPageFrame * GetPageFrame()
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 UpdatePosition(const boost::optional< Point > &xEvtPt=boost::optional< Point >())