/src/libreoffice/sfx2/source/view/frame2.cxx
Line | Count | Source |
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 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | |
21 | | #include "impframe.hxx" |
22 | | #include <workwin.hxx> |
23 | | |
24 | | #include <sfx2/bindings.hxx> |
25 | | #include <sfx2/dispatch.hxx> |
26 | | #include <sfx2/docfile.hxx> |
27 | | #include <sfx2/sfxsids.hrc> |
28 | | #include <sfx2/sfxuno.hxx> |
29 | | #include <sfx2/viewsh.hxx> |
30 | | |
31 | | #include <com/sun/star/awt/XWindow2.hpp> |
32 | | #include <com/sun/star/beans/XPropertySet.hpp> |
33 | | #include <com/sun/star/frame/Desktop.hpp> |
34 | | #include <com/sun/star/frame/XComponentLoader.hpp> |
35 | | #include <com/sun/star/frame/Frame.hpp> |
36 | | #include <com/sun/star/frame/XLayoutManager.hpp> |
37 | | |
38 | | #include <comphelper/namedvaluecollection.hxx> |
39 | | #include <comphelper/processfactory.hxx> |
40 | | #include <toolkit/helper/vclunohelper.hxx> |
41 | | #include <comphelper/diagnose_ex.hxx> |
42 | | #include <vcl/event.hxx> |
43 | | #include <vcl/syswin.hxx> |
44 | | #include <sal/log.hxx> |
45 | | |
46 | | using namespace ::com::sun::star; |
47 | | using namespace ::com::sun::star::uno; |
48 | | using namespace ::com::sun::star::frame; |
49 | | using namespace ::com::sun::star::beans; |
50 | | using ::com::sun::star::frame::XComponentLoader; |
51 | | |
52 | | class SfxFrameWindow_Impl : public vcl::Window |
53 | | { |
54 | | DECL_LINK(ModalHierarchyHdl, bool, void); |
55 | | public: |
56 | | SfxFrame* m_pFrame; |
57 | | |
58 | | SfxFrameWindow_Impl( SfxFrame* pF, vcl::Window& i_rContainerWindow ); |
59 | | |
60 | | virtual void DataChanged( const DataChangedEvent& rDCEvt ) override; |
61 | | virtual void StateChanged( StateChangedType nStateChange ) override; |
62 | | virtual bool PreNotify( NotifyEvent& rNEvt ) override; |
63 | | virtual bool EventNotify( NotifyEvent& rEvt ) override; |
64 | | virtual void Resize() override; |
65 | | virtual void GetFocus() override; |
66 | | virtual void dispose() override; |
67 | | void DoResize(); |
68 | | }; |
69 | | |
70 | | SfxFrameWindow_Impl::SfxFrameWindow_Impl(SfxFrame* pF, vcl::Window& i_rContainerWindow) |
71 | 4.26k | : Window(&i_rContainerWindow, WB_BORDER | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_3DLOOK) |
72 | 4.26k | , m_pFrame(pF) |
73 | 4.26k | { |
74 | 4.26k | i_rContainerWindow.SetModalHierarchyHdl(LINK(this, SfxFrameWindow_Impl, ModalHierarchyHdl)); |
75 | 4.26k | } Unexecuted instantiation: SfxFrameWindow_Impl::SfxFrameWindow_Impl(SfxFrame*, vcl::Window&) SfxFrameWindow_Impl::SfxFrameWindow_Impl(SfxFrame*, vcl::Window&) Line | Count | Source | 71 | 4.26k | : Window(&i_rContainerWindow, WB_BORDER | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_3DLOOK) | 72 | 4.26k | , m_pFrame(pF) | 73 | 4.26k | { | 74 | 4.26k | i_rContainerWindow.SetModalHierarchyHdl(LINK(this, SfxFrameWindow_Impl, ModalHierarchyHdl)); | 75 | 4.26k | } |
|
76 | | |
77 | | void SfxFrameWindow_Impl::dispose() |
78 | 4.26k | { |
79 | 4.26k | GetParent()->SetModalHierarchyHdl(Link<bool, void>()); |
80 | 4.26k | vcl::Window::dispose(); |
81 | 4.26k | } |
82 | | |
83 | | void SfxFrameWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt ) |
84 | 0 | { |
85 | 0 | Window::DataChanged( rDCEvt ); |
86 | | // tdf#131613 the printers changing has no effect on window layout |
87 | 0 | if (rDCEvt.GetType() == DataChangedEventType::PRINTER) |
88 | 0 | return; |
89 | 0 | SfxWorkWindow *pWorkWin = m_pFrame->GetWorkWindow_Impl(); |
90 | 0 | if ( pWorkWin ) |
91 | 0 | pWorkWin->DataChanged_Impl(); |
92 | 0 | } |
93 | | |
94 | | bool SfxFrameWindow_Impl::EventNotify( NotifyEvent& rNEvt ) |
95 | 0 | { |
96 | 0 | if ( m_pFrame->IsClosing_Impl() || !m_pFrame->GetFrameInterface().is() ) |
97 | 0 | return false; |
98 | | |
99 | 0 | SfxViewFrame* pView = m_pFrame->GetCurrentViewFrame(); |
100 | 0 | if ( !pView || !pView->GetObjectShell() ) |
101 | 0 | return Window::EventNotify( rNEvt ); |
102 | | |
103 | 0 | if ( rNEvt.GetType() == NotifyEventType::GETFOCUS ) |
104 | 0 | { |
105 | 0 | if ( pView->GetViewShell() && !pView->GetViewShell()->GetUIActiveIPClient_Impl() && !m_pFrame->IsInPlace() ) |
106 | 0 | { |
107 | 0 | SAL_INFO("sfx", "SfxFrame: GotFocus"); |
108 | 0 | pView->MakeActive_Impl( false ); |
109 | 0 | } |
110 | | |
111 | | // if focus was on an external window, the clipboard content might have been changed |
112 | 0 | pView->GetBindings().Invalidate( SID_PASTE ); |
113 | 0 | pView->GetBindings().Invalidate( SID_PASTE_SPECIAL ); |
114 | 0 | return true; |
115 | 0 | } |
116 | 0 | else if( rNEvt.GetType() == NotifyEventType::KEYINPUT ) |
117 | 0 | { |
118 | 0 | if ( pView->GetViewShell()->KeyInput( *rNEvt.GetKeyEvent() ) ) |
119 | 0 | return true; |
120 | 0 | } |
121 | | |
122 | 0 | return Window::EventNotify( rNEvt ); |
123 | 0 | } |
124 | | |
125 | | IMPL_LINK(SfxFrameWindow_Impl, ModalHierarchyHdl, bool, bSetModal, void) |
126 | 0 | { |
127 | 0 | SfxViewFrame* pView = m_pFrame->GetCurrentViewFrame(); |
128 | 0 | if (!pView || !pView->GetObjectShell()) |
129 | 0 | return; |
130 | 0 | pView->SetModalMode(bSetModal); |
131 | 0 | } |
132 | | |
133 | | bool SfxFrameWindow_Impl::PreNotify( NotifyEvent& rNEvt ) |
134 | 0 | { |
135 | 0 | NotifyEventType nType = rNEvt.GetType(); |
136 | 0 | if ( nType == NotifyEventType::KEYINPUT || nType == NotifyEventType::KEYUP ) |
137 | 0 | { |
138 | 0 | SfxViewFrame* pView = m_pFrame->GetCurrentViewFrame(); |
139 | 0 | SfxViewShell* pShell = pView ? pView->GetViewShell() : nullptr; |
140 | 0 | if ( pShell && pShell->HasKeyListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) ) |
141 | 0 | return true; |
142 | 0 | } |
143 | 0 | else if ( nType == NotifyEventType::MOUSEBUTTONUP || nType == NotifyEventType::MOUSEBUTTONDOWN ) |
144 | 0 | { |
145 | 0 | vcl::Window* pWindow = rNEvt.GetWindow(); |
146 | 0 | SfxViewFrame* pView = m_pFrame->GetCurrentViewFrame(); |
147 | 0 | SfxViewShell* pShell = pView ? pView->GetViewShell() : nullptr; |
148 | 0 | if ( pShell ) |
149 | 0 | if ( pWindow == pShell->GetWindow() || pShell->GetWindow()->IsChild( pWindow ) ) |
150 | 0 | if ( pShell->HasMouseClickListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) ) |
151 | 0 | return true; |
152 | 0 | } |
153 | | |
154 | 0 | if ( nType == NotifyEventType::MOUSEBUTTONDOWN ) |
155 | 0 | { |
156 | 0 | vcl::Window* pWindow = rNEvt.GetWindow(); |
157 | 0 | const MouseEvent* pMEvent = rNEvt.GetMouseEvent(); |
158 | 0 | Point aPos = pWindow->OutputToScreenPixel( pMEvent->GetPosPixel() ); |
159 | 0 | SfxWorkWindow *pWorkWin = m_pFrame->GetWorkWindow_Impl(); |
160 | 0 | if ( pWorkWin ) |
161 | 0 | pWorkWin->EndAutoShow_Impl( aPos ); |
162 | 0 | } |
163 | |
|
164 | 0 | return Window::PreNotify( rNEvt ); |
165 | 0 | } |
166 | | |
167 | | void SfxFrameWindow_Impl::GetFocus() |
168 | 0 | { |
169 | 0 | if ( m_pFrame && !m_pFrame->IsClosing_Impl() && |
170 | 0 | m_pFrame->GetCurrentViewFrame() && |
171 | 0 | m_pFrame->GetFrameInterface().is() ) |
172 | 0 | m_pFrame->GetCurrentViewFrame()->MakeActive_Impl( true ); |
173 | 0 | } |
174 | | |
175 | | void SfxFrameWindow_Impl::Resize() |
176 | 4.26k | { |
177 | 4.26k | if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() ) |
178 | 0 | DoResize(); |
179 | 4.26k | } |
180 | | |
181 | | void SfxFrameWindow_Impl::StateChanged( StateChangedType nStateChange ) |
182 | 4.26k | { |
183 | 4.26k | if ( nStateChange == StateChangedType::InitShow ) |
184 | 0 | { |
185 | 0 | m_pFrame->m_pImpl->bHidden = false; |
186 | 0 | if ( m_pFrame->IsInPlace() ) |
187 | | // TODO/MBA: workaround for bug in LayoutManager: the final resize does not get through because the |
188 | | // LayoutManager works asynchronously and between resize and time execution the DockingAcceptor was exchanged so that |
189 | | // the resize event never is sent to the component |
190 | 0 | SetSizePixel( GetParent()->GetOutputSizePixel() ); |
191 | |
|
192 | 0 | DoResize(); |
193 | 0 | SfxViewFrame* pView = m_pFrame->GetCurrentViewFrame(); |
194 | 0 | if ( pView ) |
195 | 0 | pView->GetBindings().GetWorkWindow_Impl()->ShowChildren_Impl(); |
196 | 0 | } |
197 | | |
198 | 4.26k | Window::StateChanged( nStateChange ); |
199 | 4.26k | } |
200 | | |
201 | | void SfxFrameWindow_Impl::DoResize() |
202 | 0 | { |
203 | 0 | if ( !m_pFrame->m_pImpl->bLockResize ) |
204 | 0 | m_pFrame->Resize(); |
205 | 0 | } |
206 | | |
207 | | Reference < XFrame > SfxFrame::CreateBlankFrame() |
208 | 0 | { |
209 | 0 | Reference < XFrame > xFrame; |
210 | 0 | try |
211 | 0 | { |
212 | 0 | Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() ); |
213 | 0 | xFrame.set( xDesktop->findFrame( u"_blank"_ustr, 0 ), UNO_SET_THROW ); |
214 | 0 | } |
215 | 0 | catch( const Exception& ) |
216 | 0 | { |
217 | 0 | DBG_UNHANDLED_EXCEPTION("sfx.view"); |
218 | 0 | } |
219 | 0 | return xFrame; |
220 | 0 | } |
221 | | |
222 | | SfxFrame* SfxFrame::CreateHidden( SfxObjectShell const & rDoc, vcl::Window& rWindow, SfxInterfaceId nViewId ) |
223 | 0 | { |
224 | 0 | SfxFrame* pFrame = nullptr; |
225 | 0 | try |
226 | 0 | { |
227 | | // create and initialize new top level frame for this window |
228 | 0 | const Reference < XComponentContext >& xContext( ::comphelper::getProcessComponentContext() ); |
229 | 0 | Reference < XDesktop2 > xDesktop = Desktop::create( xContext ); |
230 | 0 | Reference < XFrame2 > xFrame = Frame::create( xContext ); |
231 | |
|
232 | 0 | Reference< awt::XWindow2 > xWin( VCLUnoHelper::GetInterface ( &rWindow ), uno::UNO_QUERY_THROW ); |
233 | 0 | xFrame->initialize( xWin ); |
234 | 0 | xDesktop->getFrames()->append( xFrame ); |
235 | |
|
236 | 0 | if ( xWin->isActive() ) |
237 | 0 | xFrame->activate(); |
238 | | |
239 | | // create load arguments |
240 | 0 | comphelper::SequenceAsHashMap aArgs = TransformItems(SID_OPENDOC, rDoc.GetMedium()->GetItemSet()); |
241 | 0 | aArgs[u"Model"_ustr] <<= rDoc.GetModel(); |
242 | 0 | aArgs[u"Hidden"_ustr] <<= true; |
243 | 0 | if ( nViewId != SFX_INTERFACE_NONE ) |
244 | 0 | aArgs[u"ViewId"_ustr] <<= static_cast<sal_uInt16>(nViewId); |
245 | | |
246 | | // load the doc into that frame |
247 | 0 | Reference< XComponentLoader > xLoader( xFrame, UNO_QUERY_THROW ); |
248 | 0 | xLoader->loadComponentFromURL( |
249 | 0 | u"private:object"_ustr, |
250 | 0 | u"_self"_ustr, |
251 | 0 | 0, |
252 | 0 | aArgs.getAsConstPropertyValueList() |
253 | 0 | ); |
254 | |
|
255 | 0 | for ( pFrame = SfxFrame::GetFirst(); |
256 | 0 | pFrame; |
257 | 0 | pFrame = SfxFrame::GetNext( *pFrame ) |
258 | 0 | ) |
259 | 0 | { |
260 | 0 | if ( pFrame->GetFrameInterface() == xFrame ) |
261 | 0 | break; |
262 | 0 | } |
263 | |
|
264 | 0 | OSL_ENSURE( pFrame, "SfxFrame::Create: load succeeded, but no SfxFrame was created during this!" ); |
265 | 0 | } |
266 | 0 | catch( const Exception& ) |
267 | 0 | { |
268 | 0 | DBG_UNHANDLED_EXCEPTION("sfx.view"); |
269 | 0 | } |
270 | |
|
271 | 0 | return pFrame; |
272 | 0 | } |
273 | | |
274 | | SfxFrame* SfxFrame::Create( const Reference < XFrame >& i_rFrame ) |
275 | 4.26k | { |
276 | | // create a new TopFrame to an external XFrame object ( wrap controller ) |
277 | 4.26k | ENSURE_OR_THROW( i_rFrame.is(), "NULL frame not allowed" ); |
278 | 4.26k | VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( i_rFrame->getContainerWindow() ); |
279 | 4.26k | ENSURE_OR_THROW( pWindow, "frame without container window not allowed" ); |
280 | | |
281 | 4.26k | SfxFrame* pFrame = new SfxFrame( *pWindow ); |
282 | 4.26k | pFrame->SetFrameInterface_Impl( i_rFrame ); |
283 | 4.26k | return pFrame; |
284 | 4.26k | } |
285 | | |
286 | | SfxFrame::SfxFrame( vcl::Window& i_rContainerWindow ) |
287 | 4.26k | :SvCompatWeakBase<SfxFrame>( this ) |
288 | 4.26k | ,m_pWindow( nullptr ) |
289 | 4.26k | { |
290 | 4.26k | Construct_Impl(); |
291 | | |
292 | 4.26k | m_pImpl->bHidden = false; |
293 | 4.26k | InsertTopFrame_Impl( this ); |
294 | 4.26k | m_pImpl->pExternalContainerWindow = &i_rContainerWindow; |
295 | | |
296 | 4.26k | m_pWindow = VclPtr<SfxFrameWindow_Impl>::Create( this, i_rContainerWindow ); |
297 | | |
298 | | // always show pWindow, which is the ComponentWindow of the XFrame we live in |
299 | | // nowadays, since SfxFrames can be created with an XFrame only, hiding or showing the complete XFrame |
300 | | // is not done at level of the container window, not at SFX level. Thus, the component window can |
301 | | // always be visible. |
302 | 4.26k | m_pWindow->Show(); |
303 | 4.26k | } |
304 | | |
305 | | void SfxFrame::SetPresentationMode( bool bSet ) |
306 | 0 | { |
307 | 0 | if ( GetCurrentViewFrame() ) |
308 | 0 | GetCurrentViewFrame()->GetWindow().SetBorderStyle( bSet ? WindowBorderStyle::NOBORDER : WindowBorderStyle::NORMAL ); |
309 | |
|
310 | 0 | Reference< css::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY ); |
311 | 0 | Reference< css::frame::XLayoutManager > xLayoutManager; |
312 | |
|
313 | 0 | if ( xPropSet.is() ) |
314 | 0 | { |
315 | 0 | Any aValue = xPropSet->getPropertyValue(u"LayoutManager"_ustr); |
316 | 0 | aValue >>= xLayoutManager; |
317 | 0 | } |
318 | |
|
319 | 0 | if ( xLayoutManager.is() ) |
320 | 0 | xLayoutManager->setVisible( !bSet ); // we don't want to have ui in presentation mode |
321 | |
|
322 | 0 | SetMenuBarOn_Impl( !bSet ); |
323 | 0 | if ( GetWorkWindow_Impl() ) |
324 | 0 | GetWorkWindow_Impl()->SetDockingAllowed( !bSet ); |
325 | 0 | if ( GetCurrentViewFrame() ) |
326 | 0 | GetCurrentViewFrame()->GetDispatcher()->Update_Impl( true ); |
327 | 0 | } |
328 | | |
329 | | SystemWindow* SfxFrame::GetSystemWindow() const |
330 | 4.26k | { |
331 | 4.26k | return GetTopWindow_Impl(); |
332 | 4.26k | } |
333 | | |
334 | | SystemWindow* SfxFrame::GetTopWindow_Impl() const |
335 | 4.26k | { |
336 | 4.26k | if ( m_pImpl->pExternalContainerWindow->IsSystemWindow() ) |
337 | 4.26k | return static_cast<SystemWindow*>( m_pImpl->pExternalContainerWindow.get() ); |
338 | 0 | else |
339 | 0 | return nullptr; |
340 | 4.26k | } |
341 | | |
342 | | |
343 | | void SfxFrame::LockResize_Impl( bool bLock ) |
344 | 0 | { |
345 | 0 | m_pImpl->bLockResize = bLock; |
346 | 0 | } |
347 | | |
348 | | void SfxFrame::SetMenuBarOn_Impl( bool bOn ) |
349 | 0 | { |
350 | 0 | m_pImpl->bMenuBarOn = bOn; |
351 | |
|
352 | 0 | Reference< css::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY ); |
353 | 0 | Reference< css::frame::XLayoutManager > xLayoutManager; |
354 | |
|
355 | 0 | if ( xPropSet.is() ) |
356 | 0 | { |
357 | 0 | Any aValue = xPropSet->getPropertyValue(u"LayoutManager"_ustr); |
358 | 0 | aValue >>= xLayoutManager; |
359 | 0 | } |
360 | |
|
361 | 0 | if ( xLayoutManager.is() ) |
362 | 0 | { |
363 | 0 | OUString aMenuBarURL( u"private:resource/menubar/menubar"_ustr ); |
364 | |
|
365 | 0 | if ( bOn ) |
366 | 0 | xLayoutManager->showElement( aMenuBarURL ); |
367 | 0 | else |
368 | 0 | xLayoutManager->hideElement( aMenuBarURL ); |
369 | 0 | } |
370 | 0 | } |
371 | | |
372 | | bool SfxFrame::IsMenuBarOn_Impl() const |
373 | 4.26k | { |
374 | 4.26k | return m_pImpl->bMenuBarOn; |
375 | 4.26k | } |
376 | | |
377 | | void SfxFrame::PrepareForDoc_Impl( const SfxObjectShell& i_rDoc ) |
378 | 4.26k | { |
379 | 4.26k | const ::comphelper::NamedValueCollection aDocumentArgs( i_rDoc.GetModel()->getArgs2( { u"Hidden"_ustr, u"PluginMode"_ustr } ) ); |
380 | | |
381 | | // hidden? |
382 | 4.26k | OSL_ENSURE( !m_pImpl->bHidden, "when does this happen?" ); |
383 | 4.26k | m_pImpl->bHidden = aDocumentArgs.getOrDefault( u"Hidden"_ustr, m_pImpl->bHidden ); |
384 | | |
385 | | // update our descriptor |
386 | 4.26k | UpdateDescriptor( &i_rDoc ); |
387 | | |
388 | | // plugin mode |
389 | 4.26k | sal_Int16 nPluginMode = aDocumentArgs.getOrDefault( u"PluginMode"_ustr, sal_Int16( 0 ) ); |
390 | 4.26k | if ( nPluginMode && ( nPluginMode != 2 ) ) |
391 | 0 | m_pImpl->bInPlace = true; |
392 | 4.26k | } |
393 | | |
394 | | bool SfxFrame::IsMarkedHidden_Impl() const |
395 | 4.26k | { |
396 | 4.26k | return m_pImpl->bHidden; |
397 | 4.26k | } |
398 | | |
399 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |