xref: /aoo4110/main/sfx2/source/dialog/partwnd.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sfx2.hxx"
26 
27 // includes ******************************************************************
28 #include <com/sun/star/awt/XWindow.hpp>
29 #include <com/sun/star/task/XStatusIndicator.hpp>
30 #include <com/sun/star/uno/Reference.h>
31 #include <com/sun/star/uno/Sequence.hxx>
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include <com/sun/star/util/URL.hpp>
34 #include <com/sun/star/frame/XFrame.hpp>
35 #include <com/sun/star/util/XCloseable.hpp>
36 #include <com/sun/star/util/CloseVetoException.hpp>
37 #include <com/sun/star/lang/XComponent.hpp>
38 #include <com/sun/star/lang/DisposedException.hpp>
39 #include <com/sun/star/frame/XController.hpp>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/awt/PosSize.hpp>
42 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
43 #include <comphelper/processfactory.hxx>
44 #endif
45 
46 #include <toolkit/helper/vclunohelper.hxx>
47 
48 #include <sfx2/sfxsids.hrc>
49 #include "partwnd.hxx"
50 #include <sfx2/bindings.hxx>
51 #include <sfx2/dispatch.hxx>
52 #include <sfx2/viewfrm.hxx>
53 #include <sfx2/frame.hxx>
54 #include <sfx2/sfxuno.hxx>
55 
56 //****************************************************************************
57 // SfxPartChildWnd_Impl
58 //****************************************************************************
59 
60 SFX_IMPL_DOCKINGWINDOW( SfxPartChildWnd_Impl, SID_BROWSER );
61 
SfxPartChildWnd_Impl(Window * pParentWnd,sal_uInt16 nId,SfxBindings * pBindings,SfxChildWinInfo * pInfo)62 SfxPartChildWnd_Impl::SfxPartChildWnd_Impl
63 (
64 	Window* pParentWnd,
65 	sal_uInt16 nId,
66 	SfxBindings* pBindings,
67 	SfxChildWinInfo* pInfo
68 )
69 	: SfxChildWindow( pParentWnd, nId )
70 {
71 	// Window erzeugen
72     pWindow = new SfxPartDockWnd_Impl( pBindings, this, pParentWnd, WB_STDDOCKWIN | WB_CLIPCHILDREN | WB_SIZEABLE | WB_3DLOOK );
73 	eChildAlignment = SFX_ALIGN_TOP;
74 	if ( pInfo )
75 		pInfo->nFlags |= SFX_CHILDWIN_FORCEDOCK;
76 
77 	((SfxDockingWindow*)pWindow)->SetFloatingSize( Size( 175, 175 ) );
78 	pWindow->SetSizePixel( Size( 175, 175 ) );
79 
80 	( ( SfxDockingWindow* ) pWindow )->Initialize( pInfo );
81     SetHideNotDelete( sal_True );
82 }
83 
~SfxPartChildWnd_Impl()84 SfxPartChildWnd_Impl::~SfxPartChildWnd_Impl()
85 {
86     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = GetFrame();
87 
88     // If xFrame=NULL release pMgr! Because this window lives longer then the manager!
89     // In these case we got a xFrame->dispose() call from outside ... and has release our
90     // frame reference in our own DisposingListener.
91     // But don't do it, if xFrame already exist. Then dispose() must come from inside ...
92     // and we need a valid pMgr for further operations ...
93 
94     SfxPartDockWnd_Impl* pWin = (SfxPartDockWnd_Impl*) pWindow;
95 //    if( pWin != NULL && !xFrame.is() )
96 //        pWin->ReleaseChildWindow_Impl();
97 /*
98     // Release frame and window.
99     // If frame reference is valid here ... start dieing from inside by calling dispose().
100     SetFrame( NULL );
101     pWindow = NULL;
102 */
103     if ( pWin && xFrame == pWin->GetBindings().GetActiveFrame() )
104         pWin->GetBindings().SetActiveFrame( NULL );
105 /*
106     if( xFrame.is() )
107     {
108         try
109         {
110             ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloseable > xCloseable  ( xFrame, ::com::sun::star::uno::UNO_QUERY );
111             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xDisposeable( xFrame, ::com::sun::star::uno::UNO_QUERY );
112             if (xCloseable.is())
113                 xCloseable->close(sal_True);
114             else
115             if (xDisposeable.is())
116                 xDisposeable->dispose();
117         }
118         catch( ::com::sun::star::util::CloseVetoException& )
119         {
120         }
121         catch( ::com::sun::star::lang::DisposedException& )
122         {
123         }
124     }
125  */
126 }
127 
QueryClose()128 sal_Bool SfxPartChildWnd_Impl::QueryClose()
129 {
130 	return ( (SfxPartDockWnd_Impl*)pWindow )->QueryClose();
131 }
132 
133 //****************************************************************************
134 // SfxPartDockWnd_Impl
135 //****************************************************************************
136 
SfxPartDockWnd_Impl(SfxBindings * pBind,SfxChildWindow * pChildWin,Window * pParent,WinBits nBits)137 SfxPartDockWnd_Impl::SfxPartDockWnd_Impl
138 (
139 	SfxBindings* pBind,
140 	SfxChildWindow* pChildWin,
141 	Window* pParent,
142 	WinBits nBits
143 )
144     : SfxDockingWindow( pBind, pChildWin, pParent, nBits )
145 {
146     ::com::sun::star::uno::Reference < ::com::sun::star::frame::XFrame > xFrame(
147             ::comphelper::getProcessServiceFactory()->createInstance(
148             DEFINE_CONST_UNICODE("com.sun.star.frame.Frame") ), ::com::sun::star::uno::UNO_QUERY );
149     xFrame->initialize( VCLUnoHelper::GetInterface ( this ) );
150 
151     ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xPropSet(
152         xFrame, ::com::sun::star::uno::UNO_QUERY );
153     try
154     {
155         const ::rtl::OUString aLayoutManager( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" ));
156         ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > xLMPropSet;
157 
158         ::com::sun::star::uno::Any a = xPropSet->getPropertyValue( aLayoutManager );
159         if ( a >>= xLMPropSet )
160         {
161             const ::rtl::OUString aAutomaticToolbars( RTL_CONSTASCII_USTRINGPARAM( "AutomaticToolbars" ));
162             xLMPropSet->setPropertyValue( aAutomaticToolbars, ::com::sun::star::uno::Any( sal_False ));
163         }
164     }
165     catch( ::com::sun::star::uno::RuntimeException& )
166     {
167         throw;
168     }
169     catch( ::com::sun::star::uno::Exception& )
170     {
171     }
172 
173     pChildWin->SetFrame( xFrame );
174 	if ( pBind->GetDispatcher() )
175 	{
176 		::com::sun::star::uno::Reference < ::com::sun::star::frame::XFramesSupplier >
177 				xSupp ( pBind->GetDispatcher()->GetFrame()->GetFrame().GetFrameInterface(), ::com::sun::star::uno::UNO_QUERY );
178 		if ( xSupp.is() )
179             xSupp->getFrames()->append( xFrame );
180 	}
181     else {
182         DBG_ERROR("Bindings without Dispatcher!");
183     }
184 }
185 
186 //****************************************************************************
187 
~SfxPartDockWnd_Impl()188 SfxPartDockWnd_Impl::~SfxPartDockWnd_Impl()
189 {
190 }
191 
192 //****************************************************************************
193 
impl_Rectangle_Struct2Object(const::com::sun::star::awt::Rectangle & aRectangleStruct)194 Rectangle impl_Rectangle_Struct2Object( const ::com::sun::star::awt::Rectangle& aRectangleStruct )
195 {
196 	return Rectangle(aRectangleStruct.X,aRectangleStruct.Y,aRectangleStruct.Width,aRectangleStruct.Height);
197 }
198 
Resize()199 void SfxPartDockWnd_Impl::Resize()
200 
201 /*	[Beschreibung]
202 	Anpassung der Gr"osse der Controls an die neue Windowgr"osse
203 */
204 
205 {
206 	SfxDockingWindow::Resize();
207 }
208 
209 //****************************************************************************
210 
QueryClose()211 sal_Bool SfxPartDockWnd_Impl::QueryClose()
212 {
213 	sal_Bool bClose = sal_True;
214     SfxChildWindow* pChild = GetChildWindow_Impl();
215     if( pChild )
216     {
217         ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = pChild->GetFrame();
218         if( xFrame.is() )
219         {
220             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >  xCtrl = xFrame->getController();
221             if( xCtrl.is() )
222                 bClose = xCtrl->suspend( sal_True );
223         }
224     }
225 
226     return bClose;
227 }
228 
229 //****************************************************************************
230 
Notify(NotifyEvent & rEvt)231 long SfxPartDockWnd_Impl::Notify( NotifyEvent& rEvt )
232 {
233     if( rEvt.GetType() == EVENT_GETFOCUS )
234     {
235         SfxChildWindow* pChild = GetChildWindow_Impl();
236         if( pChild )
237         {
238             ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame = pChild->GetFrame();
239             if( xFrame.is() )
240                 xFrame->activate();
241         }
242     }
243 
244 	return SfxDockingWindow::Notify( rEvt );
245 }
246 
FillInfo(SfxChildWinInfo & rInfo) const247 void SfxPartDockWnd_Impl::FillInfo( SfxChildWinInfo& rInfo ) const
248 {
249 	SfxDockingWindow::FillInfo( rInfo );
250 	rInfo.bVisible = sal_False;
251 }
252 
253 
254