LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / dialog / partwnd.cxx
blobe387d2c5ba1c145149e7537fa963f9fd5f44de70
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <com/sun/star/beans/XPropertySet.hpp>
21 #include <com/sun/star/frame/Frame.hpp>
22 #include <com/sun/star/frame/XController.hpp>
23 #include <com/sun/star/uno/Reference.h>
24 #include <comphelper/processfactory.hxx>
25 #include <osl/diagnose.h>
27 #include <toolkit/helper/vclunohelper.hxx>
29 #include <vcl/event.hxx>
30 #include <sfx2/sfxsids.hrc>
31 #include <partwnd.hxx>
32 #include <sfx2/bindings.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/viewfrm.hxx>
35 #include <sfx2/frame.hxx>
38 // SfxPartChildWnd_Impl
41 SFX_IMPL_DOCKINGWINDOW( SfxPartChildWnd_Impl, SID_BROWSER );
43 SfxPartChildWnd_Impl::SfxPartChildWnd_Impl
45 vcl::Window* pParentWnd,
46 sal_uInt16 nId,
47 SfxBindings* pBindings,
48 SfxChildWinInfo* pInfo
50 : SfxChildWindow( pParentWnd, nId )
52 // Create Window
53 SetWindow(VclPtr<SfxPartDockWnd_Impl>::Create( pBindings, this, pParentWnd, WB_STDDOCKWIN | WB_CLIPCHILDREN | WB_SIZEABLE | WB_3DLOOK ));
54 SetAlignment(SfxChildAlignment::TOP);
56 assert(pInfo);
57 pInfo->nFlags |= SfxChildWindowFlags::FORCEDOCK;
59 static_cast<SfxDockingWindow*>(GetWindow())->SetFloatingSize( Size( 175, 175 ) );
60 GetWindow()->SetSizePixel( Size( 175, 175 ) );
62 static_cast<SfxDockingWindow*>(GetWindow())->Initialize( pInfo );
63 SetHideNotDelete( true );
66 SfxPartChildWnd_Impl::~SfxPartChildWnd_Impl()
68 css::uno::Reference< css::frame::XFrame > xFrame = GetFrame();
70 // If xFrame=NULL release pMgr! Because this window lives longer then the manager!
71 // In these case we got a xFrame->dispose() call from outside ... and has release our
72 // frame reference in our own DisposingListener.
73 // But don't do it, if xFrame already exist. Then dispose() must come from inside ...
74 // and we need a valid pMgr for further operations ...
76 SfxPartDockWnd_Impl* pWin = static_cast<SfxPartDockWnd_Impl*>(GetWindow());
78 if ( pWin && xFrame == pWin->GetBindings().GetActiveFrame() )
79 pWin->GetBindings().SetActiveFrame( nullptr );
82 bool SfxPartChildWnd_Impl::QueryClose()
84 return static_cast<SfxPartDockWnd_Impl*>(GetWindow())->QueryClose();
88 // SfxPartDockWnd_Impl
91 SfxPartDockWnd_Impl::SfxPartDockWnd_Impl
93 SfxBindings* pBind,
94 SfxChildWindow* pChildWin,
95 vcl::Window* pParent,
96 WinBits nBits
98 : SfxDockingWindow( pBind, pChildWin, pParent, nBits )
100 css::uno::Reference < css::frame::XFrame2 > xFrame = css::frame::Frame::create(
101 ::comphelper::getProcessComponentContext() );
102 xFrame->initialize( VCLUnoHelper::GetInterface ( this ) );
106 css::uno::Reference< css::beans::XPropertySet > xLMPropSet( xFrame->getLayoutManager(), css::uno::UNO_QUERY_THROW );
108 xLMPropSet->setPropertyValue( "AutomaticToolbars", css::uno::Any( false ));
110 catch( css::uno::RuntimeException& )
112 throw;
114 catch( css::uno::Exception& )
118 pChildWin->SetFrame( css::uno::Reference<css::frame::XFrame>(xFrame,css::uno::UNO_QUERY_THROW) );
119 if ( pBind->GetDispatcher() )
121 css::uno::Reference < css::frame::XFramesSupplier >
122 xSupp ( pBind->GetDispatcher()->GetFrame()->GetFrame().GetFrameInterface(), css::uno::UNO_QUERY );
123 if ( xSupp.is() )
124 xSupp->getFrames()->append( css::uno::Reference<css::frame::XFrame>(xFrame, css::uno::UNO_QUERY_THROW) );
126 else {
127 OSL_FAIL("Bindings without Dispatcher!");
132 bool SfxPartDockWnd_Impl::QueryClose()
134 bool bClose = true;
135 SfxChildWindow* pChild = GetChildWindow_Impl();
136 if( pChild )
138 css::uno::Reference< css::frame::XFrame > xFrame = pChild->GetFrame();
139 if( xFrame.is() )
141 css::uno::Reference< css::frame::XController > xCtrl = xFrame->getController();
142 if( xCtrl.is() )
143 bClose = xCtrl->suspend( true );
147 return bClose;
151 bool SfxPartDockWnd_Impl::EventNotify( NotifyEvent& rEvt )
153 if( rEvt.GetType() == MouseNotifyEvent::GETFOCUS )
155 SfxChildWindow* pChild = GetChildWindow_Impl();
156 if( pChild )
158 css::uno::Reference< css::frame::XFrame > xFrame = pChild->GetFrame();
159 if( xFrame.is() )
160 xFrame->activate();
164 return SfxDockingWindow::EventNotify( rEvt );
167 void SfxPartDockWnd_Impl::FillInfo( SfxChildWinInfo& rInfo ) const
169 SfxDockingWindow::FillInfo( rInfo );
170 rInfo.bVisible = false;
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */