Update ooo320-m1
[ooovba.git] / sfx2 / source / view / topfrm.cxx
blob303e51b0b84ab647ee17426472bed8628fc4d503
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: topfrm.cxx,v $
10 * $Revision: 1.97 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
33 #ifndef GCC
34 #endif
36 #include <sfx2/topfrm.hxx>
37 #include <sfx2/signaturestate.hxx>
38 #include <com/sun/star/frame/XModuleManager.hpp>
39 #include <com/sun/star/util/XURLTransformer.hpp>
40 #include <com/sun/star/uno/Reference.h>
41 #include <com/sun/star/frame/XFrame.hpp>
42 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
43 #include <comphelper/processfactory.hxx>
44 #endif
45 #include <com/sun/star/frame/XFramesSupplier.hpp>
46 #include <com/sun/star/util/XCloseable.hpp>
47 #include <com/sun/star/util/CloseVetoException.hpp>
48 #ifndef _TOOLKIT_UNOHLP_HXX
49 #include <toolkit/helper/vclunohelper.hxx>
50 #endif
51 #ifndef _UNO_COM_SUN_STAR_AWT_POSSIZE_HPP_
52 #include <com/sun/star/awt/PosSize.hpp>
53 #endif
54 #include <com/sun/star/container/XIndexAccess.hpp>
55 #ifndef _COM_SUN_STAR_CONTAINER_XPROPERTYSET_HPP_
56 #include <com/sun/star/beans/XPropertySet.hpp>
57 #endif
58 #include <com/sun/star/frame/XLayoutManager.hpp>
59 #include <com/sun/star/beans/NamedValue.hpp>
60 #include <com/sun/star/beans/XMaterialHolder.hpp>
61 #include <com/sun/star/awt/XWindow2.hpp>
62 #include <vcl/menu.hxx>
63 #include <svtools/rectitem.hxx>
64 #include <svtools/intitem.hxx>
65 #include <svtools/eitem.hxx>
66 #include <svtools/stritem.hxx>
67 #include <svtools/asynclink.hxx>
68 #include <svtools/sfxecode.hxx>
69 #include <vcl/dialog.hxx>
70 #include <svtools/urihelper.hxx>
71 #include <svtools/moduleoptions.hxx>
72 #include <unotools/configmgr.hxx>
73 #include <unotools/bootstrap.hxx>
75 #include <sfxresid.hxx>
77 // wg. pTopFrames
78 #include "appdata.hxx"
79 #include <sfx2/app.hxx>
80 #include <sfx2/sfx.hrc>
81 #include <sfx2/objsh.hxx>
82 #include <sfx2/docfile.hxx>
83 #include <sfx2/viewsh.hxx>
84 #include <sfx2/bindings.hxx>
85 #include <sfx2/dispatch.hxx>
86 #include <sfx2/request.hxx>
87 #include <sfx2/objitem.hxx>
88 #include <sfx2/objface.hxx>
89 #include <sfx2/msg.hxx>
90 #include "objshimp.hxx"
91 #include "workwin.hxx"
92 #include "sfxtypes.hxx"
93 #include "splitwin.hxx"
94 #include "arrdecl.hxx"
95 #include "sfxhelp.hxx"
96 #include <sfx2/fcontnr.hxx>
97 #include <sfx2/docfac.hxx>
98 #include "statcach.hxx"
99 #include <sfx2/event.hxx>
101 using namespace ::com::sun::star;
102 using namespace ::com::sun::star::uno;
103 using namespace ::com::sun::star::frame;
104 using namespace ::com::sun::star::util;
105 using namespace ::com::sun::star::container;
106 using namespace ::com::sun::star::beans;
108 //------------------------------------------------------------------------
110 #define SfxTopViewFrame
111 #include "sfxslots.hxx"
113 DBG_NAME(SfxTopViewFrame)
115 #include <comphelper/sequenceashashmap.hxx>
116 static ::rtl::OUString GetModuleName_Impl( const ::rtl::OUString& sDocService )
118 uno::Reference< container::XNameAccess > xMM( ::comphelper::getProcessServiceFactory()->createInstance(::rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager")), uno::UNO_QUERY );
119 ::rtl::OUString sVar;
120 if ( !xMM.is() )
121 return sVar;
125 ::comphelper::SequenceAsHashMap aAnalyzer( xMM->getByName(sDocService) );
126 sVar = aAnalyzer.getUnpackedValueOrDefault( ::rtl::OUString::createFromAscii("ooSetupFactoryUIName"), ::rtl::OUString() );
128 catch( uno::Exception& )
130 sVar = ::rtl::OUString();
133 return sVar;
136 class SfxTopFrame_Impl
138 public:
139 Window* pWindow; // maybe external
140 BOOL bHidden;
141 BOOL bLockResize;
142 BOOL bMenuBarOn;
145 class SfxTopWindow_Impl : public Window
147 public:
148 SfxTopFrame* pFrame;
150 SfxTopWindow_Impl( SfxTopFrame* pF );
151 // : Window( pF->pImp->pWindow, WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_3DLOOK )
152 // , pFrame( pF )
153 // { SetBackground(); }
154 ~SfxTopWindow_Impl( );
156 virtual void DataChanged( const DataChangedEvent& rDCEvt );
157 virtual void StateChanged( StateChangedType nStateChange );
158 virtual long PreNotify( NotifyEvent& rNEvt );
159 virtual long Notify( NotifyEvent& rEvt );
160 virtual void Resize();
161 virtual void GetFocus();
162 void DoResize();
163 DECL_LINK( CloserHdl, void* );
166 SfxTopWindow_Impl::SfxTopWindow_Impl( SfxTopFrame* pF )
167 : Window( pF->pImp->pWindow, WB_BORDER | WB_CLIPCHILDREN | WB_NODIALOGCONTROL | WB_3DLOOK )
168 , pFrame( pF )
172 SfxTopWindow_Impl::~SfxTopWindow_Impl( )
176 void SfxTopWindow_Impl::DataChanged( const DataChangedEvent& rDCEvt )
178 Window::DataChanged( rDCEvt );
179 SfxWorkWindow *pWorkWin = pFrame->GetWorkWindow_Impl();
180 if ( pWorkWin )
181 pWorkWin->DataChanged_Impl( rDCEvt );
184 long SfxTopWindow_Impl::Notify( NotifyEvent& rNEvt )
186 if ( pFrame->IsClosing_Impl() || !pFrame->GetFrameInterface().is() )
187 return sal_False;
189 SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
190 if ( !pView || !pView->GetObjectShell() )
191 return Window::Notify( rNEvt );
193 if ( rNEvt.GetType() == EVENT_GETFOCUS )
195 if ( pView->GetViewShell() && !pView->GetViewShell()->GetUIActiveIPClient_Impl() && !pFrame->IsInPlace() )
197 DBG_TRACE("SfxTopFrame: GotFocus");
198 pView->MakeActive_Impl( FALSE );
201 // TODO/LATER: do we still need this code?
202 Window* pWindow = rNEvt.GetWindow();
203 ULONG nHelpId = 0;
204 while ( !nHelpId && pWindow )
206 nHelpId = pWindow->GetHelpId();
207 pWindow = pWindow->GetParent();
210 if ( nHelpId )
211 SfxHelp::OpenHelpAgent( pFrame, nHelpId );
213 // if focus was on an external window, the clipboard content might have been changed
214 pView->GetBindings().Invalidate( SID_PASTE );
215 pView->GetBindings().Invalidate( SID_PASTE_SPECIAL );
216 return sal_True;
218 else if( rNEvt.GetType() == EVENT_KEYINPUT )
220 if ( pView->GetViewShell()->KeyInput( *rNEvt.GetKeyEvent() ) )
221 return TRUE;
223 else if ( rNEvt.GetType() == EVENT_EXECUTEDIALOG /*|| rNEvt.GetType() == EVENT_INPUTDISABLE*/ )
225 pView->SetModalMode( sal_True );
226 return sal_True;
228 else if ( rNEvt.GetType() == EVENT_ENDEXECUTEDIALOG /*|| rNEvt.GetType() == EVENT_INPUTENABLE*/ )
230 //EnableInput( sal_True, sal_True );
231 pView->SetModalMode( sal_False );
232 return sal_True;
235 return Window::Notify( rNEvt );
238 long SfxTopWindow_Impl::PreNotify( NotifyEvent& rNEvt )
240 USHORT nType = rNEvt.GetType();
241 if ( nType == EVENT_KEYINPUT || nType == EVENT_KEYUP )
243 SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
244 SfxViewShell* pShell = pView ? pView->GetViewShell() : NULL;
245 if ( pShell && pShell->HasKeyListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) )
246 return sal_True;
248 else if ( nType == EVENT_MOUSEBUTTONUP || nType == EVENT_MOUSEBUTTONDOWN )
250 Window* pWindow = rNEvt.GetWindow();
251 SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
252 SfxViewShell* pShell = pView ? pView->GetViewShell() : NULL;
253 if ( pShell )
254 if ( pWindow == pShell->GetWindow() || pShell->GetWindow()->IsChild( pWindow ) )
255 if ( pShell->HasMouseClickListeners_Impl() && pShell->HandleNotifyEvent_Impl( rNEvt ) )
256 return sal_True;
259 if ( nType == EVENT_MOUSEBUTTONDOWN )
261 Window* pWindow = rNEvt.GetWindow();
262 const MouseEvent* pMEvent = rNEvt.GetMouseEvent();
263 Point aPos = pWindow->OutputToScreenPixel( pMEvent->GetPosPixel() );
264 SfxWorkWindow *pWorkWin = pFrame->GetWorkWindow_Impl();
265 if ( pWorkWin )
266 pWorkWin->EndAutoShow_Impl( aPos );
269 return Window::PreNotify( rNEvt );
272 void SfxTopWindow_Impl::GetFocus()
274 if ( pFrame && !pFrame->IsClosing_Impl() && pFrame->GetCurrentViewFrame() && pFrame->GetFrameInterface().is() )
275 pFrame->GetCurrentViewFrame()->MakeActive_Impl( TRUE );
278 void SfxTopWindow_Impl::Resize()
280 if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
281 DoResize();
284 void SfxTopWindow_Impl::StateChanged( StateChangedType nStateChange )
286 if ( nStateChange == STATE_CHANGE_INITSHOW )
288 pFrame->pImp->bHidden = FALSE;
289 if ( pFrame->IsInPlace() )
290 // TODO/MBA: workaround for bug in LayoutManager: the final resize does not get through because the
291 // LayoutManager works asynchronously and between resize and time execution the DockingAcceptor was exchanged so that
292 // the resize event never is sent to the component
293 SetSizePixel( GetParent()->GetOutputSizePixel() );
295 DoResize();
296 SfxViewFrame* pView = pFrame->GetCurrentViewFrame();
297 if ( pView )
298 pView->GetBindings().GetWorkWindow_Impl()->ShowChilds_Impl();
301 Window::StateChanged( nStateChange );
304 void SfxTopWindow_Impl::DoResize()
306 if ( !pFrame->pImp->bLockResize )
307 pFrame->Resize();
310 class StopButtonTimer_Impl : public Timer
312 BOOL bState;
313 SfxViewFrame* pFrame;
314 protected:
315 virtual void Timeout();
316 public:
317 StopButtonTimer_Impl( SfxViewFrame*);
318 void SetButtonState( BOOL bStateP );
319 BOOL GetButtonState() const { return bState; }
322 StopButtonTimer_Impl::StopButtonTimer_Impl( SfxViewFrame*p)
323 : bState( FALSE )
324 , pFrame( p )
326 SetTimeout( 200 );
329 void StopButtonTimer_Impl::SetButtonState( BOOL bStateP )
331 if( bStateP )
333 bState = TRUE;
334 Stop();
336 else if( bState )
337 Start();
340 void StopButtonTimer_Impl::Timeout()
342 bState = FALSE;
343 pFrame->GetBindings().Invalidate( SID_BROWSE_STOP );
346 class SfxTopViewWin_Impl : public Window
348 friend class SfxInternalFrame;
350 BOOL bActive;
351 SfxTopViewFrame* pFrame;
353 public:
354 SfxTopViewWin_Impl( SfxTopViewFrame* p,
355 Window *pParent, WinBits nBits=0 ) :
356 Window( pParent, nBits | WB_BORDER | WB_CLIPCHILDREN ),
357 bActive( FALSE ),
358 pFrame( p )
360 p->GetFrame()->GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
363 virtual void Resize();
364 virtual void StateChanged( StateChangedType nStateChange );
367 //--------------------------------------------------------------------
368 void SfxTopViewWin_Impl::StateChanged( StateChangedType nStateChange )
370 if ( nStateChange == STATE_CHANGE_INITSHOW )
372 SfxObjectShell* pDoc = pFrame->GetObjectShell();
373 if ( pDoc && !pFrame->IsVisible_Impl() )
374 pFrame->Show();
376 pFrame->Resize();
378 else
379 Window::StateChanged( nStateChange );
382 void SfxTopViewWin_Impl::Resize()
384 if ( IsReallyVisible() || IsReallyShown() || GetOutputSizePixel().Width() )
385 pFrame->Resize();
388 class SfxTopViewFrame_Impl
390 public:
391 sal_Bool bActive;
392 Window* pWindow;
393 String aFactoryName;
394 StopButtonTimer_Impl* pStopButtonTimer;
396 SfxTopViewFrame_Impl()
397 : bActive( sal_False )
398 , pWindow( 0 )
399 , pStopButtonTimer( 0 )
403 static svtools::AsynchronLink* pPendingCloser = 0;
405 static String _getTabString()
407 String result;
409 Reference < XMaterialHolder > xHolder(
410 ::comphelper::getProcessServiceFactory()->createInstance(
411 DEFINE_CONST_UNICODE("com.sun.star.tab.tabreg") ), UNO_QUERY );
412 if (xHolder.is())
414 rtl::OUString aTabString;
415 Sequence< NamedValue > sMaterial;
416 if (xHolder->getMaterial() >>= sMaterial) {
417 for (int i=0; i < sMaterial.getLength(); i++) {
418 if ((sMaterial[i].Name.equalsAscii("title")) &&
419 (sMaterial[i].Value >>= aTabString))
421 result += ' ';
422 result += String(aTabString);
427 return result;
430 SfxTopFrame* SfxTopFrame::Create( SfxObjectShell* pDoc, USHORT nViewId, BOOL bHidden, const SfxItemSet* pSet )
432 Reference < XFrame > xDesktop ( ::comphelper::getProcessServiceFactory()->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
433 SfxTopFrame *pFrame = NULL;
434 BOOL bNewView = FALSE;
435 if ( pSet )
437 SFX_ITEMSET_ARG( pSet, pItem, SfxBoolItem, SID_OPEN_NEW_VIEW, sal_False );
438 bNewView = pItem && pItem->GetValue();
441 if ( pDoc && !bHidden && !bNewView )
443 URL aTargetURL;
444 aTargetURL.Complete = pDoc->GetMedium()->GetURLObject().GetMainURL( INetURLObject::NO_DECODE );
446 BOOL bIsBasic = FALSE;
447 if ( !aTargetURL.Complete.getLength() )
449 String sFactory = String::CreateFromAscii(pDoc->GetFactory().GetShortName());
450 bIsBasic = (sFactory.CompareIgnoreCaseToAscii("sbasic")==COMPARE_EQUAL);
452 if (!bIsBasic)
454 String aURL = String::CreateFromAscii("private:factory/");
455 aURL += sFactory;
456 aTargetURL.Complete = aURL;
460 if (bIsBasic)
462 Reference < XFramesSupplier > xSupplier( xDesktop, UNO_QUERY );
463 if (xSupplier.is())
465 Reference < XIndexAccess > xContainer(xSupplier->getFrames(), UNO_QUERY);
466 if (xContainer.is())
468 Reference< ::com::sun::star::frame::XModuleManager > xCheck(::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.frame.ModuleManager" )), UNO_QUERY);
469 sal_Int32 nCount = xContainer->getCount();
470 for (sal_Int32 i=0; i<nCount; ++i)
474 Reference < XFrame > xFrame;
475 if (!(xContainer->getByIndex(i) >>= xFrame) || !xFrame.is())
476 continue;
477 ::rtl::OUString sModule = xCheck->identify(xFrame);
478 if (sModule.equalsAscii("com.sun.star.frame.StartModule"))
480 pFrame = Create(xFrame);
481 break;
484 catch(const Exception&) {}
489 else
491 Reference < XURLTransformer > xTrans( ::comphelper::getProcessServiceFactory()->createInstance( rtl::OUString::createFromAscii("com.sun.star.util.URLTransformer" )), UNO_QUERY );
492 xTrans->parseStrict( aTargetURL );
494 Reference < ::com::sun::star::frame::XDispatchProvider > xProv( xDesktop, UNO_QUERY );
495 Reference < ::com::sun::star::frame::XDispatch > xDisp;
496 if ( xProv.is() )
498 Sequence < ::com::sun::star::beans::PropertyValue > aSeq(1);
499 aSeq[0].Name = ::rtl::OUString::createFromAscii("Model");
500 aSeq[0].Value <<= pDoc->GetModel();
501 ::rtl::OUString aTargetFrame( ::rtl::OUString::createFromAscii("_default") );
502 xDisp = xProv->queryDispatch( aTargetURL, aTargetFrame , 0 );
503 if ( xDisp.is() )
504 xDisp->dispatch( aTargetURL, aSeq );
507 SfxFrameArr_Impl& rArr = *SFX_APP()->Get_Impl()->pTopFrames;
508 for( USHORT nPos = rArr.Count(); nPos--; )
510 SfxTopFrame *pF = (SfxTopFrame*) rArr[ nPos ];
511 if ( pF->GetCurrentDocument() == pDoc )
513 pFrame = pF;
514 break;
520 if ( !pFrame )
522 Reference < XFrame > xFrame = xDesktop->findFrame( DEFINE_CONST_UNICODE("_blank"), 0 );
523 pFrame = Create( xFrame );
526 pFrame->pImp->bHidden = bHidden;
527 Window* pWindow = pFrame->GetTopWindow_Impl();
528 if ( pWindow && pDoc )
530 ::rtl::OUString aDocServiceName( pDoc->GetFactory().GetDocumentServiceName() );
531 ::rtl::OUString aProductName;
532 ::utl::ConfigManager::GetDirectConfigProperty(::utl::ConfigManager::PRODUCTNAME) >>= aProductName;
533 String aTitle = pDoc->GetTitle( SFX_TITLE_DETECT );
534 aTitle += String::CreateFromAscii( " - " );
535 aTitle += String(aProductName);
536 aTitle += ' ';
537 aTitle += String( GetModuleName_Impl( aDocServiceName ) );
538 #ifndef PRODUCT
539 ::rtl::OUString aDefault;
540 aTitle += DEFINE_CONST_UNICODE(" [");
541 String aVerId( utl::Bootstrap::getBuildIdData( aDefault ));
542 aTitle += aVerId;
543 aTitle += ']';
544 #endif
546 // append TAB string if available
547 aTitle += _getTabString();
549 /* AS_TITLE
550 pWindow->SetText( aTitle );
553 /* AS_ICON
554 if( pWindow->GetType() == WINDOW_WORKWINDOW )
556 SvtModuleOptions::EFactory eFactory;
557 if( SvtModuleOptions::ClassifyFactoryByName( aDocServiceName, eFactory ) )
559 WorkWindow* pWorkWindow = (WorkWindow*)pWindow;
560 pWorkWindow->SetIcon( (sal_uInt16) SvtModuleOptions().GetFactoryIcon( eFactory ) );
566 pFrame->SetItemSet_Impl( pSet );
567 if ( pDoc && pDoc != pFrame->GetCurrentDocument() )
569 if ( nViewId )
570 pDoc->GetMedium()->GetItemSet()->Put( SfxUInt16Item( SID_VIEW_ID, nViewId ) );
571 pFrame->InsertDocument( pDoc );
572 if ( pWindow && !bHidden )
573 pWindow->Show();
576 return pFrame;
579 SfxTopFrame* SfxTopFrame::Create( SfxObjectShell* pDoc, Window* pWindow, USHORT nViewId, BOOL bHidden, const SfxItemSet* pSet )
581 Reference < ::com::sun::star::lang::XMultiServiceFactory > xFact( ::comphelper::getProcessServiceFactory() );
582 Reference < XFramesSupplier > xDesktop ( xFact->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Desktop") ), UNO_QUERY );
583 Reference < XFrame > xFrame( xFact->createInstance( DEFINE_CONST_UNICODE("com.sun.star.frame.Frame") ), UNO_QUERY );
585 xFrame->initialize( VCLUnoHelper::GetInterface ( pWindow ) );
586 if ( xDesktop.is() )
587 xDesktop->getFrames()->append( xFrame );
589 uno::Reference< awt::XWindow2 > xWin( VCLUnoHelper::GetInterface ( pWindow ), uno::UNO_QUERY );
590 if ( xWin.is() && xWin->isActive() )
591 xFrame->activate();
593 SfxTopFrame* pFrame = new SfxTopFrame( pWindow );
594 pFrame->SetFrameInterface_Impl( xFrame );
595 pFrame->pImp->bHidden = bHidden;
597 pFrame->SetItemSet_Impl( pSet );
598 if ( pDoc )
600 if ( nViewId )
601 pDoc->GetMedium()->GetItemSet()->Put( SfxUInt16Item( SID_VIEW_ID, nViewId ) );
602 pFrame->InsertDocument( pDoc );
605 return pFrame;
608 SfxTopFrame* SfxTopFrame::Create( Reference < XFrame > xFrame )
610 // create a new TopFrame to an external XFrame object ( wrap controller )
611 DBG_ASSERT( xFrame.is(), "Wrong parameter!" );
613 Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
614 SfxTopFrame* pFrame = new SfxTopFrame( pWindow );
615 pFrame->SetFrameInterface_Impl( xFrame );
616 return pFrame;
619 SfxTopFrame::SfxTopFrame( Window* pExternal, sal_Bool bHidden )
620 : SfxFrame( NULL )
621 , pWindow( NULL )
623 pImp = new SfxTopFrame_Impl;
624 pImp->bHidden = bHidden;
625 pImp->bLockResize = FALSE;
626 pImp->bMenuBarOn = TRUE;
627 InsertTopFrame_Impl( this );
628 if ( pExternal )
630 pImp->pWindow = pExternal;
632 else
634 DBG_ERROR( "TopFrame without window created!" );
636 pImp->pWindow = new SfxTopFrameWindow_Impl( this );
637 pImp->pWindow->SetActivateMode( ACTIVATE_MODE_GRABFOCUS );
638 pImp->pWindow->SetPosSizePixel( Point( 20,20 ), Size( 800,600 ) );
639 if ( GetFrameInterface().is() )
640 GetFrameInterface()->initialize( VCLUnoHelper::GetInterface( pImp->pWindow ) );
641 pImp->pWindow->Show();
645 pWindow = new SfxTopWindow_Impl( this );
646 /** AS:
647 Hide this window till the component was realy loaded. Otherwhise it overpaint e.g. the old component hardly
648 and produce repaint errors.
649 pWindow->Show();
653 SfxTopFrame::~SfxTopFrame()
655 RemoveTopFrame_Impl( this );
656 DELETEZ( pWindow );
657 delete pImp;
660 void SfxTopFrame::SetPresentationMode( BOOL bSet )
662 if ( GetCurrentViewFrame() )
663 GetCurrentViewFrame()->GetWindow().SetBorderStyle( bSet ? WINDOW_BORDER_NOBORDER : WINDOW_BORDER_NORMAL );
665 Reference< com::sun::star::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
666 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
668 if ( xPropSet.is() )
670 Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
671 aValue >>= xLayoutManager;
674 if ( xLayoutManager.is() )
675 xLayoutManager->setVisible( !bSet ); // we don't want to have ui in presentation mode
677 SetMenuBarOn_Impl( !bSet );
678 if ( GetWorkWindow_Impl() )
679 GetWorkWindow_Impl()->SetDockingAllowed( !bSet );
680 if ( GetCurrentViewFrame() )
681 GetCurrentViewFrame()->GetDispatcher()->Update_Impl( TRUE );
684 SystemWindow*
685 SfxTopFrame::GetSystemWindow() const
687 return GetTopWindow_Impl();
690 SystemWindow* SfxTopFrame::GetTopWindow_Impl() const
692 if ( pImp->pWindow->IsSystemWindow() )
693 return (SystemWindow*) pImp->pWindow;
694 else
695 return NULL;
698 Window& SfxTopFrame::GetWindow() const
700 return *pWindow;
703 sal_Bool SfxTopFrame::Close()
705 delete this;
706 return sal_True;
709 void SfxTopFrame::LockResize_Impl( BOOL bLock )
711 pImp->bLockResize = bLock;
714 IMPL_LINK( SfxTopWindow_Impl, CloserHdl, void*, EMPTYARG )
716 if ( pFrame && !pFrame->PrepareClose_Impl( TRUE ) )
717 return 0L;
719 if ( pFrame )
720 pFrame->GetCurrentViewFrame()->GetBindings().Execute( SID_CLOSEWIN, 0, 0, SFX_CALLMODE_ASYNCHRON );
721 return 0L;
724 void SfxTopFrame::SetMenuBarOn_Impl( BOOL bOn )
726 pImp->bMenuBarOn = bOn;
728 Reference< com::sun::star::beans::XPropertySet > xPropSet( GetFrameInterface(), UNO_QUERY );
729 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
731 if ( xPropSet.is() )
733 Any aValue = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
734 aValue >>= xLayoutManager;
737 if ( xLayoutManager.is() )
739 rtl::OUString aMenuBarURL( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" ));
741 if ( bOn )
742 xLayoutManager->showElement( aMenuBarURL );
743 else
744 xLayoutManager->hideElement( aMenuBarURL );
748 BOOL SfxTopFrame::IsMenuBarOn_Impl() const
750 return pImp->bMenuBarOn;
753 String SfxTopFrame::GetWindowData()
755 String aActWinData;
756 char cToken = ',';
758 SfxViewFrame *pActFrame = SfxViewFrame::Current();
759 SfxViewFrame *pFrame = GetCurrentViewFrame();
760 const sal_Bool bActWin = ( pActFrame->GetTopViewFrame() == pFrame );
762 // ::com::sun::star::sdbcx::User-Daten der ViewShell
763 String aUserData;
764 pFrame->GetViewShell()->WriteUserData(aUserData);
766 // assemble ini-data
767 String aWinData;
768 aWinData += String::CreateFromInt32( pFrame->GetCurViewId() );
769 aWinData += cToken;
771 aWinData += '1'; // former attribute "isfloating"
772 aWinData += cToken;
774 // aktives kennzeichnen
775 aWinData += cToken;
776 aWinData += bActWin ? '1' : '0';
778 aWinData += cToken;
779 aWinData += aUserData;
781 return aWinData;
784 sal_Bool SfxTopFrame::InsertDocument( SfxObjectShell* pDoc )
785 /* [Beschreibung]
788 // Spezielle Bedingungen testen: nicht im ModalMode!
789 if ( !SfxFrame::InsertDocument( pDoc ) )
790 return sal_False;
792 SfxObjectShell *pOld = GetCurrentDocument();
794 // Position und Groesse testen
795 // Wenn diese schon gesetzt sind, soll offensichtlich nicht noch
796 // LoadWindows_Impl aufgerufen werden ( z.B. weil dieses ein CreateFrame()
797 // an einer Task aufgerufen hat! )
798 const SfxItemSet* pSet = GetItemSet_Impl();
799 if ( !pSet )
800 pSet = pDoc->GetMedium()->GetItemSet();
801 SetItemSet_Impl(0);
803 // Position und Gr"o\se
804 SFX_ITEMSET_ARG(
805 pSet, pAreaItem, SfxRectangleItem, SID_VIEW_POS_SIZE, sal_False );
806 // View-Id
807 SFX_ITEMSET_ARG(
808 pSet, pViewIdItem, SfxUInt16Item, SID_VIEW_ID, sal_False );
809 // Zoom
810 SFX_ITEMSET_ARG(
811 pSet, pModeItem, SfxUInt16Item, SID_VIEW_ZOOM_MODE, sal_False );
812 // Hidden
813 SFX_ITEMSET_ARG(
814 pSet, pHidItem, SfxBoolItem, SID_HIDDEN, sal_False);
815 // ViewDaten
816 SFX_ITEMSET_ARG(
817 pSet, pViewDataItem, SfxStringItem, SID_USER_DATA, sal_False );
818 // ViewOnly
819 SFX_ITEMSET_ARG(
820 pSet, pEditItem, SfxBoolItem, SID_VIEWONLY, sal_False);
821 // InPlace (Hack)
822 SFX_ITEMSET_ARG(
823 pSet, pPluginItem, SfxUInt16Item, SID_PLUGIN_MODE, sal_False );
825 // Plugin (external InPlace)
826 SFX_ITEMSET_ARG(
827 pSet, pPluginMode, SfxUInt16Item, SID_PLUGIN_MODE, sal_False);
828 // Jump (GotoBookmark)
829 SFX_ITEMSET_ARG(
830 pSet, pJumpItem, SfxStringItem, SID_JUMPMARK, sal_False);
832 if ( pEditItem && pEditItem->GetValue() )
833 SetMenuBarOn_Impl( FALSE );
835 if ( pHidItem )
836 pImp->bHidden = pHidItem->GetValue();
838 if( !pImp->bHidden )
839 pDoc->OwnerLock( sal_True );
841 // Wenn z.B. eine Fenstergr"o\se gesetzt wurde, soll keine Fensterinformation
842 // aus den Dokument geladen werden, z.B. weil InsertDocument seinerseits
843 // aus LoadWindows_Impl aufgerufen wurde!
844 if ( !pJumpItem && !pPluginMode && pDoc && !pAreaItem && !pViewIdItem && !pModeItem &&
845 pDoc->LoadWindows_Impl( this ) )
847 if ( GetCurrentDocument() != pDoc )
848 // something went wrong during insertion
849 return sal_False;
850 pDoc->OwnerLock( sal_False );
851 return sal_True;
854 if ( pDoc )
856 UpdateHistory( pDoc );
857 UpdateDescriptor( pDoc );
860 SetFrameType_Impl( GetFrameType() & ~SFXFRAME_FRAMESET );
861 sal_Bool bBrowsing = sal_True;
862 SfxViewFrame *pFrame = GetCurrentViewFrame();
863 if ( pFrame )
865 sal_Bool bChildActivated = sal_False;
866 if ( pFrame->GetActiveChildFrame_Impl() && pFrame->GetActiveChildFrame_Impl() == SfxViewFrame::Current() )
868 // ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFramesSupplier > xFrames( GetFrameInterface(), ::com::sun::star::uno::UNO_QUERY );
869 // if ( xFrames.is() )
870 // xFrames->setActiveFrame( ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > () );
871 pFrame->SetActiveChildFrame_Impl(0);
872 SfxViewFrame::SetViewFrame( pFrame );
873 bChildActivated = sal_True;
876 if ( pFrame->GetObjectShell() )
878 pFrame->ReleaseObjectShell_Impl( sal_False );
881 if ( pViewIdItem )
882 pFrame->SetViewData_Impl( pViewIdItem->GetValue(), String() );
883 if ( pDoc )
884 pFrame->SetObjectShell_Impl( *pDoc );
886 else
888 // 1: internal embedded object
889 // 2: external embedded object
890 // 3: OLE server
891 if ( pPluginItem && pPluginItem->GetValue() != 2 )
892 SetInPlace_Impl( TRUE );
894 bBrowsing = sal_False;
895 pFrame = new SfxTopViewFrame( this, pDoc, pViewIdItem ? pViewIdItem->GetValue() : 0 );
896 if ( !pFrame->GetViewShell() )
897 return sal_False;
899 if ( pPluginItem && pPluginItem->GetValue() == 1 )
901 pFrame->ForceOuterResize_Impl( FALSE );
902 pFrame->GetBindings().HidePopups(TRUE);
904 // MBA: layoutmanager of inplace frame starts locked and invisible
905 GetWorkWindow_Impl()->MakeVisible_Impl( FALSE );
906 GetWorkWindow_Impl()->Lock_Impl( TRUE );
908 GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
909 if ( GetCurrentViewFrame() )
910 GetCurrentViewFrame()->GetWindow().SetBorderStyle( WINDOW_BORDER_NOBORDER );
914 String aMark;
915 SFX_ITEMSET_ARG( pSet, pMarkItem, SfxStringItem, SID_JUMPMARK, FALSE );
916 if ( pMarkItem )
917 aMark = pMarkItem->GetValue();
919 // Position und Groesse setzen
920 //sal_uInt16 nWinMode = pModeItem ? pModeItem->GetValue() : 1;
921 if ( pAreaItem && !pOld )
923 Window *pWin = pImp->pWindow;
925 // Groesse setzen
926 const Rectangle aWinRect( pAreaItem->GetValue() );
927 const Size aAppWindow( pImp->pWindow->GetDesktopRectPixel().GetSize() );
928 Point aPos( aWinRect.TopLeft() );
929 Size aSz(aWinRect.GetSize());
930 if ( aSz.Width() && aSz.Height() )
932 aPos.X() = Min(aPos.X(),
933 long(aAppWindow.Width() - aSz.Width() + aSz.Width() / 2) );
934 aPos.Y() = Min(aPos.Y(),
935 long( aAppWindow.Height() - aSz.Height() + aSz.Height() / 2) );
936 if ( aPos.X() + aSz.Width() <
937 aAppWindow.Width() + aSz.Width() / 2 &&
938 aPos.Y() + aSz.Height() <
939 aAppWindow.Height() + aSz.Height() / 2 )
941 pWin->SetPosPixel( aPos );
942 pWin->SetOutputSizePixel( aSz );
947 if ( !pImp->bHidden )
949 if ( pDoc->IsHelpDocument() )
950 pFrame->GetDispatcher()->HideUI( TRUE );
951 else
952 pFrame->GetDispatcher()->HideUI( FALSE );
954 if ( IsInPlace() )
955 pFrame->LockAdjustPosSizePixel();
957 if ( pPluginMode && pPluginMode->GetValue() == 3)
958 GetWorkWindow_Impl()->SetInternalDockingAllowed(FALSE);
960 if ( !IsInPlace() )
961 pFrame->GetDispatcher()->Update_Impl();
962 pFrame->Show();
963 GetWindow().Show();
964 if ( !IsInPlace() || (pPluginItem && pPluginItem->GetValue() == 3) )
965 pFrame->MakeActive_Impl( GetFrameInterface()->isActive() );
966 pDoc->OwnerLock( sal_False );
968 // Dont show container window! Its done by framework or directly
969 // by SfxTopFrame::Create() or SfxViewFrame::ExecView_Impl() ...
971 if ( IsInPlace() )
973 pFrame->UnlockAdjustPosSizePixel();
974 // force resize for OLE server to fix layout problems of writer and math
975 // see i53651
976 if ( pPluginItem && pPluginItem->GetValue() == 3 )
977 pFrame->Resize(TRUE);
980 else
982 DBG_ASSERT( !IsInPlace() && !pPluginMode && !pPluginItem, "Special modes not compatible with hidden mode!" );
983 GetWindow().Show();
986 if ( pDoc->Get_Impl()->nLoadedFlags & SFX_LOADED_MAINDOCUMENT )
988 if ( pViewDataItem )
989 pFrame->GetViewShell()->ReadUserData( pViewDataItem->GetValue(), sal_True );
990 else if( aMark.Len() )
991 GetCurrentViewFrame()->GetViewShell()->JumpToMark( aMark );
993 else
995 // Daten setzen, die in FinishedLoading ausgewertet werden
996 MarkData_Impl*& rpMark = pDoc->Get_Impl()->pMarkData;
997 if (!rpMark)
998 rpMark = new MarkData_Impl;
999 rpMark->pFrame = GetCurrentViewFrame();
1000 if ( pViewDataItem )
1001 rpMark->aUserData = pViewDataItem->GetValue();
1002 else
1003 rpMark->aMark = aMark;
1006 // Jetzt UpdateTitle, hidden TopFrames haben sonst keinen Namen!
1007 pFrame->UpdateTitle();
1009 if ( !IsInPlace() )
1011 if ( pFrame->GetViewShell()->UseObjectSize() )
1013 GetCurrentViewFrame()->UnlockAdjustPosSizePixel();
1014 GetCurrentViewFrame()->Resize(TRUE);
1015 GetCurrentViewFrame()->ForceInnerResize_Impl( FALSE );
1016 GetCurrentViewFrame()->Resize(TRUE);
1018 else
1019 GetCurrentViewFrame()->Resize(TRUE);
1022 SFX_APP()->NotifyEvent( SfxEventHint(SFX_EVENT_VIEWCREATED, GlobalEventConfig::GetEventName( STR_EVENT_VIEWCREATED ), pDoc ) );
1023 return sal_True;
1027 //========================================================================
1029 long SfxViewFrameClose_Impl( void* /*pObj*/, void* pArg )
1031 ((SfxViewFrame*)pArg)->GetFrame()->DoClose();
1032 return 0;
1035 TYPEINIT1(SfxTopFrame, SfxFrame);
1036 TYPEINIT1(SfxTopViewFrame, SfxViewFrame);
1038 //--------------------------------------------------------------------
1039 SFX_IMPL_INTERFACE(SfxTopViewFrame,SfxViewFrame,SfxResId(0))
1043 //--------------------------------------------------------------------
1044 String SfxTopViewFrame::UpdateTitle()
1046 /* [Beschreibung]
1048 Mit dieser Methode kann der SfxTopViewFrame gezwungen werden, sich sofort
1049 den neuen Titel vom der <SfxObjectShell> zu besorgen.
1051 [Anmerkung]
1053 Dies ist z.B. dann notwendig, wenn man der SfxObjectShell als SfxListener
1054 zuh"ort und dort auf den <SfxSimpleHint> SFX_HINT_TITLECHANGED reagieren
1055 m"ochte, um dann die Titel seiner Views abzufragen. Diese Views (SfxTopViewFrames)
1056 jedoch sind ebenfalls SfxListener und da die Reihenfolge der Benachrichtigung
1057 nicht feststeht, mu\s deren Titel-Update vorab erzwungen werden.
1060 [Beispiel]
1062 void SwDocShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1064 if ( rHint.IsA(TYPE(SfxSimpleHint)) )
1066 switch( ( (SfxSimpleHint&) rHint ).GetId() )
1068 case SFX_HINT_TITLECHANGED:
1069 for ( SfxTopViewFrame *pTop = (SfxTopViewFrame*)
1070 SfxViewFrame::GetFirst(this, TYPE(SfxTopViewFrame));
1071 pTop;
1072 pTop = (SfxTopViewFrame*)
1073 SfxViewFrame::GetNext(this, TYPE(SfxTopViewFrame));
1075 pTop->UpdateTitle();
1076 ... pTop->GetName() ...
1078 break;
1086 DBG_CHKTHIS(SfxTopViewFrame, 0);
1088 const SfxObjectFactory &rFact = GetObjectShell()->GetFactory();
1089 pImp->aFactoryName = String::CreateFromAscii( rFact.GetShortName() );
1091 String aTitle = SfxViewFrame::UpdateTitle();
1093 ::rtl::OUString aProductName;
1094 ::utl::ConfigManager::GetDirectConfigProperty(::utl::ConfigManager::PRODUCTNAME) >>= aProductName;
1096 aTitle += String::CreateFromAscii( " - " );
1097 aTitle += String(aProductName);
1098 aTitle += ' ';
1099 ::rtl::OUString aDocServiceName( GetObjectShell()->GetFactory().GetDocumentServiceName() );
1100 aTitle += String( GetModuleName_Impl( aDocServiceName ) );
1101 #ifndef PRODUCT
1102 ::rtl::OUString aDefault;
1103 aTitle += DEFINE_CONST_UNICODE(" [");
1104 String aVerId( utl::Bootstrap::getBuildIdData( aDefault ));
1105 aTitle += aVerId;
1106 aTitle += ']';
1107 #endif
1109 // append TAB string if available
1110 aTitle += _getTabString();
1112 GetBindings().Invalidate( SID_NEWDOCDIRECT );
1114 /* AS_TITLE
1115 Window* pWindow = GetTopFrame_Impl()->GetTopWindow_Impl();
1116 if ( pWindow && pWindow->GetText() != aTitle )
1117 pWindow->SetText( aTitle );
1119 return aTitle;
1122 //--------------------------------------------------------------------
1123 void SfxTopViewFrame::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
1125 {DBG_CHKTHIS(SfxTopViewFrame, 0);}
1127 if( IsDowning_Impl())
1128 return;
1130 // we know only SimpleHints
1131 if ( rHint.IsA(TYPE(SfxSimpleHint)) )
1133 switch( ( (SfxSimpleHint&) rHint ).GetId() )
1135 case SFX_HINT_MODECHANGED:
1136 case SFX_HINT_TITLECHANGED:
1137 // when the document changes its title, change views too
1138 UpdateTitle();
1139 break;
1141 case SFX_HINT_DEINITIALIZING:
1142 // on all other changes force repaint
1143 GetFrame()->DoClose();
1144 return;
1148 SfxViewFrame::Notify( rBC, rHint );
1151 //--------------------------------------------------------------------
1152 sal_Bool SfxTopViewFrame::Close()
1154 {DBG_CHKTHIS(SfxTopViewFrame, 0);}
1156 // Modaler Dialog oben ??
1157 // if ( pImp->GetModalDialog() )
1158 // return sal_False;
1160 // eigentliches Schlie\sen
1161 if ( SfxViewFrame::Close() )
1163 if (SfxViewFrame::Current() == this)
1164 SfxViewFrame::SetViewFrame(0);
1166 // Da der Dispatcher leer ger"aumt wird, kann man ihn auch nicht mehr
1167 // vern"unftig verwenden - also besser still legen
1168 GetDispatcher()->Lock(sal_True);
1169 delete this;
1171 return sal_True;
1174 return sal_False;
1177 SfxTopViewFrame::SfxTopViewFrame
1179 SfxFrame* pFrame,
1180 SfxObjectShell* pObjShell,
1181 sal_uInt16 nViewId
1184 /* [Beschreibung]
1186 Ctor des SfxTopViewFrame f"ur eine <SfxObjectShell> aus der Ressource.
1187 Die 'nViewId' der zu erzeugenden <SfxViewShell> kann angegeben werden
1188 (default ist die zuerst registrierte SfxViewShell-Subklasse).
1191 : SfxViewFrame( *(new SfxBindings), pFrame, pObjShell, SFXFRAME_HASTITLE )
1193 DBG_CTOR(SfxTopViewFrame, 0);
1195 pCloser = 0;
1196 pImp = new SfxTopViewFrame_Impl;
1197 pImp->pStopButtonTimer = new StopButtonTimer_Impl(this);
1199 //(mba)/task if ( !pFrame->GetTask() )
1201 pImp->pWindow = new SfxTopViewWin_Impl( this, &pFrame->GetWindow() );
1202 pImp->pWindow->SetSizePixel( pFrame->GetWindow().GetOutputSizePixel() );
1203 SetWindow_Impl( pImp->pWindow );
1204 pFrame->SetOwnsBindings_Impl( sal_True );
1205 pFrame->CreateWorkWindow_Impl();
1208 sal_uInt32 nType = SFXFRAME_OWNSDOCUMENT | SFXFRAME_HASTITLE;
1209 if ( pObjShell && pObjShell->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1210 nType |= SFXFRAME_EXTERNAL;
1211 GetFrame()->SetFrameType_Impl( GetFrame()->GetFrameType() | nType );
1213 if ( GetFrame()->IsInPlace() )
1215 LockAdjustPosSizePixel();
1220 if ( pObjShell )
1221 SwitchToViewShell_Impl( nViewId );
1223 catch (com::sun::star::uno::Exception& )
1225 // make sure that the ctor is left regularly
1226 ReleaseObjectShell_Impl();
1227 return;
1230 if ( GetFrame()->IsInPlace() )
1232 UnlockAdjustPosSizePixel();
1234 else if ( GetViewShell() && GetViewShell()->UseObjectSize() )
1236 // initiale Gr"o\se festlegen
1237 // Zuerst die logischen Koordinaten von IP-Objekt und EditWindow
1238 // ber"ucksichtigen
1239 LockAdjustPosSizePixel();
1240 ForceInnerResize_Impl( TRUE );
1242 Window *pWindow = GetViewShell()->GetWindow();
1244 // Da in den Applikationen bei der R"ucktransformation immer die
1245 // Eckpunkte tranformiert werden und nicht die Size (um die Ecken
1246 // alignen zu k"onnen), transformieren wir hier auch die Punkte, um
1247 // m"oglichst wenig Rundungsfehler zu erhalten.
1249 Rectangle aRect = pWindow->LogicToLogic( GetObjectShell()->GetVisArea(),
1250 GetObjectShell()->GetMapUnit(),
1251 pWindow->GetMapMode() );
1253 Rectangle aRect = pWindow->LogicToPixel( GetObjectShell()->GetVisArea() );
1254 Size aSize = aRect.GetSize();
1255 GetViewShell()->GetWindow()->SetSizePixel( aSize );
1256 DoAdjustPosSizePixel(GetViewShell(), Point(), aSize );
1260 //------------------------------------------------------------------------
1261 SfxTopViewFrame::~SfxTopViewFrame()
1263 DBG_DTOR(SfxTopViewFrame, 0);
1265 SetDowning_Impl();
1267 if ( SfxViewFrame::Current() == this )
1268 SfxViewFrame::SetViewFrame(NULL);
1270 ReleaseObjectShell_Impl();
1271 if ( pPendingCloser == pCloser )
1272 pPendingCloser = 0;
1273 delete pCloser;
1274 if ( GetFrame()->OwnsBindings_Impl() )
1275 // Die Bindings l"oscht der Frame!
1276 KillDispatcher_Impl();
1278 delete pImp->pWindow;
1279 delete pImp->pStopButtonTimer;
1280 delete pImp;
1283 //------------------------------------------------------------------------
1284 sal_Bool SfxTopViewFrame::SetBorderPixelImpl( const SfxViewShell *pVSh, const SvBorder &rBorder )
1286 if( SfxViewFrame::SetBorderPixelImpl( GetViewShell(), rBorder ) )
1288 if ( IsResizeInToOut_Impl() && !GetFrame()->IsInPlace() )
1290 Size aSize = pVSh->GetWindow()->GetOutputSizePixel();
1291 if ( aSize.Width() && aSize.Height() )
1293 aSize.Width() += rBorder.Left() + rBorder.Right();
1294 aSize.Height() += rBorder.Top() + rBorder.Bottom();
1296 Size aOldSize = GetWindow().GetOutputSizePixel();
1297 GetWindow().SetOutputSizePixel( aSize );
1298 Window* pParent = &GetWindow();
1299 while ( pParent->GetParent() )
1300 pParent = pParent->GetParent();
1301 Size aOuterSize = pParent->GetOutputSizePixel();
1302 aOuterSize.Width() += ( aSize.Width() - aOldSize.Width() );
1303 aOuterSize.Height() += ( aSize.Height() - aOldSize.Height() );
1304 pParent->SetOutputSizePixel( aOuterSize );
1307 else
1309 Point aPoint;
1310 Rectangle aEditArea( aPoint, GetWindow().GetOutputSizePixel() );
1311 aEditArea.Left() += rBorder.Left();
1312 aEditArea.Right() -= rBorder.Right();
1313 aEditArea.Top() += rBorder.Top();
1314 aEditArea.Bottom() -= rBorder.Bottom();
1315 pVSh->GetWindow()->SetPosSizePixel( aEditArea.TopLeft(), aEditArea.GetSize() );
1317 return sal_True;
1320 return sal_False;
1323 void SfxTopViewFrame::Exec_Impl(SfxRequest &rReq )
1325 // Wenn gerade die Shells ausgetauscht werden...
1326 if ( !GetObjectShell() || !GetViewShell() )
1327 return;
1329 switch ( rReq.GetSlot() )
1331 case SID_SHOWPOPUPS :
1333 SFX_REQUEST_ARG(rReq, pShowItem, SfxBoolItem, SID_SHOWPOPUPS, FALSE);
1334 BOOL bShow = pShowItem ? pShowItem->GetValue() : TRUE;
1335 SFX_REQUEST_ARG(rReq, pIdItem, SfxUInt16Item, SID_CONFIGITEMID, FALSE);
1336 USHORT nId = pIdItem ? pIdItem->GetValue() : 0;
1338 // ausfuehren
1339 SfxWorkWindow *pWorkWin = GetFrame()->GetWorkWindow_Impl();
1340 if ( bShow )
1342 // Zuerst die Floats auch anzeigbar machen
1343 pWorkWin->MakeChildsVisible_Impl( bShow );
1344 GetDispatcher()->Update_Impl( TRUE );
1346 // Dann anzeigen
1347 GetBindings().HidePopups( !bShow );
1349 else
1351 // Alles hiden
1352 SfxBindings *pBind = &GetBindings();
1353 while ( pBind )
1355 pBind->HidePopupCtrls_Impl( !bShow );
1356 pBind = pBind->GetSubBindings_Impl();
1359 pWorkWin->HidePopups_Impl( !bShow, TRUE, nId );
1360 pWorkWin->MakeChildsVisible_Impl( bShow );
1363 Invalidate( rReq.GetSlot() );
1364 rReq.Done();
1365 break;
1368 case SID_ACTIVATE:
1370 MakeActive_Impl( TRUE );
1371 rReq.SetReturnValue( SfxObjectItem( 0, this ) );
1372 break;
1375 case SID_WIN_POSSIZE:
1376 break;
1378 case SID_NEWDOCDIRECT :
1380 SFX_REQUEST_ARG( rReq, pFactoryItem, SfxStringItem, SID_NEWDOCDIRECT, FALSE);
1381 String aFactName;
1382 if ( pFactoryItem )
1383 aFactName = pFactoryItem->GetValue();
1384 else if ( pImp->aFactoryName.Len() )
1385 aFactName = pImp->aFactoryName;
1386 else
1388 DBG_ERROR("Missing argument!");
1389 break;
1392 SfxRequest aReq( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, GetPool() );
1393 String aFact = String::CreateFromAscii("private:factory/");
1394 aFact += aFactName;
1395 aReq.AppendItem( SfxStringItem( SID_FILE_NAME, aFact ) );
1396 aReq.AppendItem( SfxFrameItem( SID_DOCFRAME, GetFrame() ) );
1397 aReq.AppendItem( SfxStringItem( SID_TARGETNAME, String::CreateFromAscii( "_blank" ) ) );
1398 SFX_APP()->ExecuteSlot( aReq );
1399 const SfxViewFrameItem* pItem = PTR_CAST( SfxViewFrameItem, aReq.GetReturnValue() );
1400 if ( pItem )
1401 rReq.SetReturnValue( SfxFrameItem( 0, pItem->GetFrame() ) );
1402 break;
1405 case SID_CLOSEWIN:
1407 // disable CloseWin, if frame is not a task
1408 Reference < XCloseable > xTask( GetFrame()->GetFrameInterface(), UNO_QUERY );
1409 if ( !xTask.is() )
1410 break;
1412 if ( GetViewShell()->PrepareClose() )
1414 // weitere Views auf dasselbe Doc?
1415 SfxObjectShell *pDocSh = GetObjectShell();
1416 int bOther = sal_False;
1417 for ( const SfxTopViewFrame *pFrame =
1418 (SfxTopViewFrame *)SfxViewFrame::GetFirst( pDocSh, TYPE(SfxTopViewFrame) );
1419 !bOther && pFrame;
1420 pFrame = (SfxTopViewFrame *)SfxViewFrame::GetNext( *pFrame, pDocSh, TYPE(SfxTopViewFrame) ) )
1421 bOther = (pFrame != this);
1423 // Doc braucht nur gefragt zu werden, wenn keine weitere View
1424 sal_Bool bClosed = sal_False;
1425 sal_Bool bUI = TRUE;
1426 if ( ( bOther || pDocSh->PrepareClose( bUI ) ) )
1428 if ( !bOther )
1429 pDocSh->SetModified( FALSE );
1430 rReq.Done(); // unbedingt vor Close() rufen!
1431 bClosed = sal_False;
1434 xTask->close(sal_True);
1435 bClosed = sal_True;
1437 catch( CloseVetoException& )
1439 bClosed = sal_False;
1443 rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bClosed ));
1445 return;
1449 rReq.Done();
1452 void SfxTopViewFrame::GetState_Impl( SfxItemSet &rSet )
1454 SfxObjectShell *pDocSh = GetObjectShell();
1456 if ( !pDocSh )
1457 return;
1459 const sal_uInt16 *pRanges = rSet.GetRanges();
1460 DBG_ASSERT(pRanges, "Set ohne Bereich");
1461 while ( *pRanges )
1463 for ( sal_uInt16 nWhich = *pRanges++; nWhich <= *pRanges; ++nWhich )
1465 switch(nWhich)
1467 case SID_NEWDOCDIRECT :
1469 if ( pImp->aFactoryName.Len() )
1471 String aFact = String::CreateFromAscii("private:factory/");
1472 aFact += pImp->aFactoryName;
1473 rSet.Put( SfxStringItem( nWhich, aFact ) );
1475 break;
1478 case SID_NEWWINDOW:
1479 rSet.DisableItem(nWhich);
1480 break;
1482 case SID_CLOSEWIN:
1484 // disable CloseWin, if frame is not a task
1485 Reference < XCloseable > xTask( GetFrame()->GetFrameInterface(), UNO_QUERY );
1486 if ( !xTask.is() )
1487 rSet.DisableItem(nWhich);
1488 break;
1491 case SID_SHOWPOPUPS :
1492 break;
1494 case SID_WIN_POSSIZE:
1496 rSet.Put( SfxRectangleItem( nWhich, Rectangle(
1497 GetWindow().GetPosPixel(), GetWindow().GetSizePixel() ) ) );
1498 break;
1501 default:
1502 DBG_ERROR( "invalid message-id" );
1505 ++pRanges;
1509 void SfxTopViewFrame::INetExecute_Impl( SfxRequest &rRequest )
1511 sal_uInt16 nSlotId = rRequest.GetSlot();
1512 switch( nSlotId )
1514 case SID_BROWSE_FORWARD:
1515 case SID_BROWSE_BACKWARD:
1517 // Anzeige der n"achsten oder vorherigen Seite aus der History
1518 SFX_REQUEST_ARG( rRequest, pSteps, SfxUInt16Item, nSlotId, sal_False );
1519 GetFrame()->Browse( nSlotId == SID_BROWSE_FORWARD, pSteps ? pSteps->GetValue() : 1,
1520 (rRequest.GetModifier() & KEY_MOD1) != 0 );
1521 break;
1523 case SID_CREATELINK:
1525 /*! (pb) we need new implementation to create a link
1527 break;
1529 case SID_BROWSE_STOP:
1531 if ( GetCancelManager() )
1532 GetCancelManager()->Cancel( TRUE );
1534 // cancel jobs in hidden tasks
1535 SfxFrameArr_Impl& rArr = *SFX_APP()->Get_Impl()->pTopFrames;
1536 for( USHORT nPos = rArr.Count(); nPos--; )
1538 SfxFrame *pFrame = rArr[ nPos ];
1539 if ( !pFrame->GetCurrentViewFrame() )
1540 pFrame->GetCancelManager()->Cancel( TRUE );
1543 break;
1545 case SID_FOCUSURLBOX:
1547 SfxStateCache *pCache = GetBindings().GetAnyStateCache_Impl( SID_OPENURL );
1548 if( pCache )
1550 SfxControllerItem* pCtrl = pCache->GetItemLink();
1551 while( pCtrl )
1553 pCtrl->StateChanged( SID_FOCUSURLBOX, SFX_ITEM_UNKNOWN, 0 );
1554 pCtrl = pCtrl->GetItemLink();
1560 // Recording
1561 rRequest.Done();
1564 void SfxTopViewFrame::INetState_Impl( SfxItemSet &rItemSet )
1566 if ( !GetFrame()->CanBrowseForward() )
1567 rItemSet.DisableItem( SID_BROWSE_FORWARD );
1569 if ( !GetFrame()->CanBrowseBackward() )
1570 rItemSet.DisableItem( SID_BROWSE_BACKWARD );
1572 // Add/SaveToBookmark bei BASIC-IDE, QUERY-EDITOR etc. disablen
1573 SfxObjectShell *pDocSh = GetObjectShell();
1574 sal_Bool bPseudo = pDocSh && !( pDocSh->GetFactory().GetFlags() & SFXOBJECTSHELL_HASOPENDOC );
1575 sal_Bool bEmbedded = pDocSh && pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED;
1576 if ( !pDocSh || bPseudo || bEmbedded || !pDocSh->HasName() )
1577 rItemSet.DisableItem( SID_CREATELINK );
1579 pImp->pStopButtonTimer->SetButtonState( GetCancelManager()->CanCancel() );
1580 if ( !pImp->pStopButtonTimer->GetButtonState() )
1581 rItemSet.DisableItem( SID_BROWSE_STOP );
1584 void SfxTopViewFrame::SetZoomFactor( const Fraction &rZoomX, const Fraction &rZoomY )
1586 GetViewShell()->SetZoomFactor( rZoomX, rZoomY );
1589 void SfxTopViewFrame::Activate( sal_Bool bMDI )
1591 DBG_ASSERT(GetViewShell(), "Keine Shell");
1592 if ( bMDI )
1593 pImp->bActive = sal_True;
1594 //(mba): hier evtl. wie in Beanframe NotifyEvent ?!
1597 void SfxTopViewFrame::Deactivate( sal_Bool bMDI )
1599 DBG_ASSERT(GetViewShell(), "Keine Shell");
1600 if ( bMDI )
1601 pImp->bActive = sal_False;
1602 //(mba): hier evtl. wie in Beanframe NotifyEvent ?!
1605 void SfxTopFrame::CheckMenuCloser_Impl( MenuBar* pMenuBar )
1607 Reference < ::com::sun::star::frame::XFrame > xFrame = GetFrameInterface();
1609 // checks if there is more than one "real" (not help) task window
1610 // in this case a close button is inserted into the menubar
1612 DBG_ASSERT( xFrame.is(), "Attention: this bug is very hard to reproduce. Please try to remember how you triggered it!");
1613 if ( !xFrame.is() || !xFrame->getController().is() )
1614 // dummy component
1615 return;
1617 Reference < ::com::sun::star::frame::XFramesSupplier > xDesktop( xFrame->getCreator(), UNO_QUERY );
1618 if ( !xDesktop.is() )
1619 // test only for task windows
1620 return;
1622 sal_Bool bLastTask = sal_False;
1623 Reference < ::com::sun::star::container::XIndexAccess >
1624 xList ( xDesktop->getFrames(), ::com::sun::star::uno::UNO_QUERY );
1625 sal_Int32 nCount = xList->getCount();
1626 if ( nCount<=1 )
1627 // only one task
1628 bLastTask = sal_True;
1629 else if ( nCount==2 )
1631 // if we have to tasks, one can be the help task, that should be ignored
1632 for( sal_Int32 i=0; i<nCount; ++i )
1634 Reference < ::com::sun::star::frame::XFrame > xTask;
1635 ::com::sun::star::uno::Any aVal = xList->getByIndex(i);
1636 if ( (aVal>>=xTask) && xTask.is() && xTask->getName().compareToAscii("OFFICE_HELP_TASK") == COMPARE_EQUAL )
1638 // one of the two open tasks was the help task -> ignored
1639 bLastTask = sal_True;
1640 break;
1645 pMenuBar->ShowCloser(bLastTask);