xref: /aoo42x/main/sfx2/source/view/frame.cxx (revision 30acf5e8)
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 #include <com/sun/star/embed/EmbedStates.hpp>
27 #include <com/sun/star/uno/Reference.h>
28 #include <com/sun/star/awt/XWindow.hpp>
29 #include <com/sun/star/util/XURLTransformer.hpp>
30 #include <com/sun/star/util/XCloseable.hpp>
31 #include <com/sun/star/util/CloseVetoException.hpp>
32 #include <com/sun/star/lang/XComponent.hpp>
33 #include <com/sun/star/lang/DisposedException.hpp>
34 #include <com/sun/star/container/XChild.hpp>
35 
36 #ifndef _MENU_HXX //autogen
37 #include <vcl/menu.hxx>
38 #endif
39 #include <svl/intitem.hxx>
40 #ifndef _SPLITWIN_HXX //autogen
41 #include <vcl/splitwin.hxx>
42 #endif
43 #include <svl/eitem.hxx>
44 #include <svl/stritem.hxx>
45 #ifndef _TOOLKIT_UNOHLP_HXX
46 #include <toolkit/helper/vclunohelper.hxx>
47 #endif
48 #include <com/sun/star/awt/PosSize.hpp>
49 #ifndef _UNOTOOLS_PROCESSFACTORY_HXX
50 #include <comphelper/processfactory.hxx>
51 #endif
52 #include <vcl/msgbox.hxx>
53 
54 #ifndef GCC
55 #endif
56 
57 // wg. pTopFrames
58 #include "appdata.hxx"
59 #include <sfx2/app.hxx>
60 #include <sfx2/event.hxx>
61 #include <sfx2/unoctitm.hxx>
62 #include <sfx2/frame.hxx>
63 #include "arrdecl.hxx"
64 #include <sfx2/objsh.hxx>
65 #include <sfx2/dispatch.hxx>
66 #include <sfx2/docfile.hxx>
67 #include <sfx2/docfilt.hxx>
68 #include <sfx2/frmdescr.hxx>
69 #include "openflag.hxx"
70 #include <sfx2/viewsh.hxx>
71 #include <sfx2/viewfrm.hxx>
72 #include <sfx2/request.hxx>
73 #include <sfx2/fcontnr.hxx>
74 #include "impframe.hxx"
75 #include <sfx2/appuno.hxx>
76 #include <sfx2/viewfrm.hxx>
77 #include "workwin.hxx"
78 #include <sfx2/sfxuno.hxx>
79 #include <sfx2/msgpool.hxx>
80 #include "objshimp.hxx"
81 #include <sfx2/ipclient.hxx>
82 
83 #ifdef DBG_UTIL
84 #include <sfx2/frmhtmlw.hxx>
85 #endif
86 
87 using namespace com::sun::star;
88 
89 static SfxFrameArr_Impl* pFramesArr_Impl=0;
90 
91 using namespace ::com::sun::star::uno;
92 using namespace ::com::sun::star::util;
93 using namespace ::com::sun::star::frame;
94 using namespace ::com::sun::star::container;
95 
96 TYPEINIT1(SfxFrame, SfxListener);
97 TYPEINIT1_AUTOFACTORY(SfxFrameItem, SfxPoolItem);
98 TYPEINIT1(SfxUsrAnyItem, SfxPoolItem);
99 TYPEINIT1_AUTOFACTORY(SfxUnoFrameItem, SfxPoolItem);
100 
GetHdl()101 SvCompatWeakHdl* SfxFrame::GetHdl()
102 {
103 	return pImp->GetHdl();
104 }
105 
106 //--------------------------------------------------------------------
Construct_Impl()107 void SfxFrame::Construct_Impl()
108 {
109 	pImp = new SfxFrame_Impl( this );
110     if ( !pFramesArr_Impl )
111         pFramesArr_Impl = new SfxFrameArr_Impl;
112     pFramesArr_Impl->Insert( this, pFramesArr_Impl->Count() );
113 }
114 
115 //--------------------------------------------------------------------
116 
~SfxFrame()117 SfxFrame::~SfxFrame()
118 {
119 	RemoveTopFrame_Impl( this );
120     DELETEZ( pWindow );
121 
122     pFramesArr_Impl->Remove( pFramesArr_Impl->GetPos( this ) );
123 
124     if ( pParentFrame )
125     {
126         pParentFrame->RemoveChildFrame_Impl( this );
127         pParentFrame = 0;
128     }
129 
130     delete pImp->pDescr;
131 
132 	if ( pChildArr )
133 	{
134 		DBG_ASSERT( !pChildArr->Count(), "Childs nicht entfernt!" );
135 		delete pChildArr;
136 	}
137 
138 	delete pImp;
139 }
140 
DoClose()141 sal_Bool SfxFrame::DoClose()
142 {
143 	// Eigentlich wird noch ein PrepareClose gebraucht !!!
144     sal_Bool bRet = sal_False;
145 	if ( !pImp->bClosing )
146 	{
147 		pImp->bClosing = sal_True;
148 		CancelTransfers();
149 
150         // now close frame; it will be deleted if this call is successful, so don't use any members after that!
151         bRet = sal_True;
152         try
153         {
154             Reference< XCloseable > xCloseable  ( pImp->xFrame, UNO_QUERY );
155             if ( (!GetCurrentDocument() || !GetCurrentDocument()->Get_Impl()->bDisposing ) && xCloseable.is())
156                 xCloseable->close(sal_True);
157             else if ( pImp->xFrame.is() )
158 			{
159 				Reference < XFrame > xFrame = pImp->xFrame;
160 				xFrame->setComponent( Reference < com::sun::star::awt::XWindow >(), Reference < XController >() );
161                 xFrame->dispose();
162 			}
163             else
164                 bRet = DoClose_Impl();
165         }
166         catch( ::com::sun::star::util::CloseVetoException& )
167         {
168             pImp->bClosing = sal_False;
169             bRet = sal_False;
170         }
171         catch( ::com::sun::star::lang::DisposedException& )
172         {
173         }
174     }
175 
176     return bRet;
177 }
178 
DoClose_Impl()179 sal_Bool SfxFrame::DoClose_Impl()
180 {
181     sal_Bool bRet = sal_True;
182     SfxBindings* pBindings = NULL;
183     if ( pImp->pCurrentViewFrame )
184         pBindings = &pImp->pCurrentViewFrame->GetBindings();
185 
186     // Bei internen Tasks m"ussen Controller und Tools abger"aumt werden
187     if ( pImp->pWorkWin )
188         pImp->pWorkWin->DeleteControllers_Impl();
189 
190     if ( pImp->pCurrentViewFrame )
191         bRet = pImp->pCurrentViewFrame->Close();
192 
193     if ( pImp->bOwnsBindings )
194         DELETEZ( pBindings );
195 
196     bRet = Close();
197     DBG_ASSERT( bRet, "Impossible state: frame closes, but controller refuses!");
198     return bRet;
199 }
200 
DocIsModified_Impl()201 sal_Bool SfxFrame::DocIsModified_Impl()
202 {
203 	if ( pImp->pCurrentViewFrame && pImp->pCurrentViewFrame->GetObjectShell() &&
204 			pImp->pCurrentViewFrame->GetObjectShell()->IsModified() )
205 		return sal_True;
206 	for( sal_uInt16 nPos = GetChildFrameCount(); nPos--; )
207 		if( pChildArr->GetObject( nPos )->DocIsModified_Impl() )
208 			return sal_True;
209 	return sal_False;
210 }
211 
PrepareClose_Impl(sal_Bool bUI,sal_Bool bForBrowsing)212 sal_uInt16 SfxFrame::PrepareClose_Impl( sal_Bool bUI, sal_Bool bForBrowsing )
213 {
214 	sal_uInt16 nRet = RET_OK;
215 
216     // prevent recursive calls
217 	if( !pImp->bPrepClosing )
218 	{
219 		pImp->bPrepClosing = sal_True;
220 
221         SfxObjectShell* pCur = GetCurrentDocument() ;
222         if( pCur )
223         {
224             // SFX components have a known behaviour
225             // First check if this frame is the only view to its current document
226             int bOther = sal_False;
227             for ( const SfxViewFrame *pFrame = SfxViewFrame::GetFirst( pCur );
228                     !bOther && pFrame; pFrame = SfxViewFrame::GetNext( *pFrame, pCur ) )
229             {
230                 bOther = ( &pFrame->GetFrame() != this );
231             }
232 
233 			SFX_APP()->NotifyEvent( SfxViewEventHint(SFX_EVENT_PREPARECLOSEVIEW, GlobalEventConfig::GetEventName( STR_EVENT_PREPARECLOSEVIEW ), pCur, GetController() ) );
234 
235             if ( bOther )
236                 // if there are other views only the current view of this frame must be asked
237                 nRet = GetCurrentViewFrame()->GetViewShell()->PrepareClose( bUI, bForBrowsing );
238             else
239                 // otherwise ask the document
240                 nRet = pCur->PrepareClose( bUI, bForBrowsing );
241         }
242 
243         if ( nRet == RET_OK )
244         {
245             // if this frame has child frames, ask them too
246             for( sal_uInt16 nPos = GetChildFrameCount(); nRet == RET_OK && nPos--; )
247                 nRet = pChildArr->GetObject( nPos )->PrepareClose_Impl( bUI, bForBrowsing );
248         }
249 
250 		pImp->bPrepClosing = sal_False;
251 	}
252 
253     if ( nRet == RET_OK && pImp->pWorkWin )
254         // if closing was accepted by the component the UI subframes must be asked also
255         nRet = pImp->pWorkWin->PrepareClose_Impl();
256 
257     return nRet;
258 }
259 
260 //--------------------------------------------------------------------
261 
GetChildFrame(sal_uInt16 nPos) const262 SfxFrame* SfxFrame::GetChildFrame( sal_uInt16 nPos ) const
263 {
264 	if ( pChildArr && pChildArr->Count() > nPos )
265 	{
266 		DBG_ASSERT( nPos < pChildArr->Count(), "Falscher Index!");
267 		return (*pChildArr)[nPos];
268 	}
269 
270 	return 0L;
271 }
272 
RemoveChildFrame_Impl(SfxFrame * pFrame)273 void SfxFrame::RemoveChildFrame_Impl( SfxFrame* pFrame )
274 {
275 	DBG_ASSERT( pChildArr, "Unbekannter Frame!");
276 	sal_uInt16 nPos = pChildArr->GetPos(pFrame);
277 	pChildArr->Remove( nPos );
278 };
279 
GetTopFrame() const280 SfxFrame& SfxFrame::GetTopFrame() const
281 {
282 	const SfxFrame* pParent = this;
283 	while ( pParent->pParentFrame )
284 		pParent = pParent->pParentFrame;
285 	return *const_cast< SfxFrame* >( pParent );
286 }
287 
IsClosing_Impl() const288 sal_Bool SfxFrame::IsClosing_Impl() const
289 {
290 	return pImp->bClosing;
291 }
292 
SetIsClosing_Impl()293 void SfxFrame::SetIsClosing_Impl()
294 {
295 	pImp->bClosing = sal_True;
296 }
297 
GetChildFrameCount() const298 sal_uInt16 SfxFrame::GetChildFrameCount() const
299 {
300 	return pChildArr ? pChildArr->Count() : 0;
301 }
302 
CancelTransfers(sal_Bool)303 void SfxFrame::CancelTransfers( sal_Bool /*bCancelLoadEnv*/ )
304 {
305 	if( !pImp->bInCancelTransfers )
306 	{
307 		pImp->bInCancelTransfers = sal_True;
308 		SfxObjectShell* pObj = GetCurrentDocument();
309 		if( pObj ) //&& !( pObj->Get_Impl()->nLoadedFlags & SFX_LOADED_ALL ))
310 		{
311 			SfxViewFrame* pFrm;
312 			for( pFrm = SfxViewFrame::GetFirst( pObj );
313 				 pFrm && &pFrm->GetFrame() == this;
314 				 pFrm = SfxViewFrame::GetNext( *pFrm, pObj ) ) ;
315 			// Keine anderer Frame mehr auf Doc -> Cancel
316 			if( !pFrm )
317 			{
318 				pObj->CancelTransfers();
319                 GetCurrentDocument()->Broadcast( SfxSimpleHint(SFX_HINT_TITLECHANGED) );
320 			}
321 		}
322 
323 		// zuerst Nachladende Frames stoppen
324 		sal_uInt16 nCount = GetChildFrameCount();
325 		for( sal_uInt16 n = 0; n<nCount; n++ )
326 			GetChildFrame( n )->CancelTransfers();
327 
328 		//  ggf. StarOne-Loader canceln
329 		SfxFrameWeak wFrame( this );
330 		if (wFrame.Is())
331 			pImp->bInCancelTransfers = sal_False;
332 	}
333 }
334 
GetCurrentViewFrame() const335 SfxViewFrame* SfxFrame::GetCurrentViewFrame() const
336 {
337 	return pImp->pCurrentViewFrame;
338 }
339 
GetDispatcher_Impl() const340 SfxDispatcher* SfxFrame::GetDispatcher_Impl() const
341 {
342 	if ( pImp->pCurrentViewFrame )
343 		return pImp->pCurrentViewFrame->GetDispatcher();
344 	return GetParentFrame()->GetDispatcher_Impl();
345 }
346 
GetCurrentDocument() const347 SfxObjectShell* SfxFrame::GetCurrentDocument() const
348 {
349 	return pImp->pCurrentViewFrame ?
350 			pImp->pCurrentViewFrame->GetObjectShell() :
351 			NULL;
352 }
353 
SetCurrentViewFrame_Impl(SfxViewFrame * pFrame)354 void SfxFrame::SetCurrentViewFrame_Impl( SfxViewFrame *pFrame )
355 {
356 	pImp->pCurrentViewFrame = pFrame;
357 }
358 
GetFrameType() const359 sal_uInt32 SfxFrame::GetFrameType() const
360 {
361 	return pImp->nType;
362 }
363 
SetFrameType_Impl(sal_uInt32 n)364 void SfxFrame::SetFrameType_Impl( sal_uInt32 n )
365 {
366 	pImp->nType = n;
367 }
368 
GetViewData_Impl()369 void SfxFrame::GetViewData_Impl()
370 {
371 	// Alle zwischen Laden und Entfernen "anderbaren Daten aktualisieren; die
372 	// festen Daten werden nur einmal ( nach PrepareForDoc_Impl in UpdateDescriptor )
373 	// geholt, um Zeit zu sparen.
374 	SfxViewFrame* pViewFrame = GetCurrentViewFrame();
375 	if( pViewFrame && pViewFrame->GetViewShell() )
376 	{
377 		const SfxMedium *pMed = GetCurrentDocument()->GetMedium();
378 		sal_Bool bReadOnly = pMed->GetOpenMode() == SFX_STREAM_READONLY;
379 		GetDescriptor()->SetReadOnly( bReadOnly );
380 
381 		SfxItemSet *pSet = GetDescriptor()->GetArgs();
382 		sal_Bool bGetViewData = sal_False;
383 		if ( GetController().is() && pSet->GetItemState( SID_VIEW_DATA ) != SFX_ITEM_SET )
384 		{
385 			::com::sun::star::uno::Any aData = GetController()->getViewData();
386             pSet->Put( SfxUsrAnyItem( SID_VIEW_DATA, aData ) );
387 			bGetViewData = sal_True;
388 		}
389 
390 		if ( pViewFrame->GetCurViewId() )
391 			pSet->Put( SfxUInt16Item( SID_VIEW_ID, pViewFrame->GetCurViewId() ) );
392 		if ( pChildArr )
393 		{
394 			// Bei Framesets m"ussen auch die Daten der ChildViews geholt werden
395 			sal_uInt16 nCount = pChildArr->Count();
396 			for ( sal_uInt16 n=nCount; n>0; n--)
397 			{
398 				SfxFrame* pFrame = (*pChildArr)[n-1];
399 				if ( bGetViewData )
400 					pFrame->GetDescriptor()->GetArgs()->ClearItem( SID_VIEW_DATA );
401 				pFrame->GetViewData_Impl();
402 			}
403 		}
404 	}
405 }
406 
UpdateDescriptor(SfxObjectShell * pDoc)407 void SfxFrame::UpdateDescriptor( SfxObjectShell *pDoc )
408 {
409 	// Beim PrepareForDoc_Impl wird der Descriptor des Frames aktualisiert
410 	// und sein ItemSet neu initialisiert. Alle Daten, die f"ur ein sp"ateres
411 	// Restaurieren der View n"otig sind, sind damit festgehalten.
412 	// Soll das Dokument ersetzt werden, wird durch GetViewData_Impl (s.o.)
413 	// die neueste Information hinzugef"ugt. Alles zusammen wird dann in der
414 	// Browse-History gesichert. Beim Aktivieren eines solchen FramePickEntry
415 	// wird das komplette ItemSet und der Descriptor im OpenDoc mitgeschickt.
416 	// Hier werden nur die festen Eigenschaften gesichert; die "anderbaren werden
417 	// durch GetViewData geholt ( spart Zeit ).
418 	DBG_ASSERT( pDoc, "NULL-Document inserted ?!" );
419 
420 	GetParentFrame();
421 	const SfxMedium *pMed = pDoc->GetMedium();
422 	GetDescriptor()->SetActualURL( pMed->GetOrigURL() );
423 
424 	SFX_ITEMSET_ARG( pMed->GetItemSet(), pItem, SfxBoolItem, SID_EDITDOC, sal_False );
425 	sal_Bool bEditable = ( !pItem || pItem->GetValue() );
426 
427 	GetDescriptor()->SetEditable( bEditable );
428 
429 	// FileOpen-Parameter merken
430 	SfxItemSet* pItemSet = pMed->GetItemSet();
431 	String aMedName( pMed->GetName() );
432 
433 	const SfxFilter* pFilter = pMed->GetOrigFilter();
434 	String aFilter;
435 	if ( pFilter )
436         aFilter = pFilter->GetFilterName();
437 
438 	SFX_ITEMSET_ARG( pItemSet, pRefererItem, SfxStringItem, SID_REFERER, sal_False);
439 	SFX_ITEMSET_ARG( pItemSet, pOptionsItem, SfxStringItem, SID_FILE_FILTEROPTIONS, sal_False);
440 	SFX_ITEMSET_ARG( pItemSet, pTitle1Item, SfxStringItem, SID_DOCINFO_TITLE, sal_False);
441 
442 	SfxItemSet *pSet = GetDescriptor()->GetArgs();
443 
444 	// Alle alten Items l"oschen
445 	pSet->ClearItem();
446 
447 	if ( pRefererItem )
448 		pSet->Put( *pRefererItem );
449 	else
450 		pSet->Put( SfxStringItem( SID_REFERER, String() ) );
451 
452 	if ( pOptionsItem )
453 		pSet->Put( *pOptionsItem );
454 
455 	if ( pTitle1Item )
456 		pSet->Put( *pTitle1Item );
457 
458 	pSet->Put( SfxStringItem( SID_FILTER_NAME, aFilter ));
459 }
460 
461 //-------------------------------------------------------------------------
462 
SetDescriptor(SfxFrameDescriptor * pD)463 void SfxFrame::SetDescriptor( SfxFrameDescriptor *pD )
464 {
465 	DBG_ASSERT( pD, "Kein Descriptor!" );
466 	DBG_ASSERT( pD != pImp->pDescr, "Descriptor ist schon gesetzt!" );
467 
468 	if ( pImp->pDescr )
469 	{
470 		// Nur TopLevel-Frames verwalten ihren Descriptor selbst, bei den
471 		// anderen tut es das Frameset
472 		if ( !pParentFrame )
473 			delete pImp->pDescr;
474 	}
475 	pImp->pDescr = pD;
476 }
477 
478 //-------------------------------------------------------------------------
479 
GetDescriptor() const480 SfxFrameDescriptor* SfxFrame::GetDescriptor() const
481 {
482 	// On Demand einen FrameDescriptor anlegen; wenn es kein TopLevel-Frame
483 	// ist, f"uhrt es zu Fehlern, da keine g"ulige Verkettung hergestellt wird
484 
485 	if ( !pImp->pDescr )
486 	{
487 		DBG_ASSERT( !GetParentFrame(), "Kein TopLevel-Frame, aber kein Descriptor!" );
488         pImp->pDescr = new SfxFrameDescriptor;
489 		if ( GetCurrentDocument() )
490 			pImp->pDescr->SetURL( GetCurrentDocument()->GetMedium()->GetOrigURL() );
491 	}
492 	return pImp->pDescr;
493 }
494 
495 //-------------------------------------------------------------------------
496 
GetTargetList(TargetList & rList) const497 void SfxFrame::GetTargetList( TargetList& rList ) const
498 {
499 	if ( !GetParentFrame() )
500 	{
501 		// Einen Leerstring f"ur 'Kein Target'
502 		rList.Insert( new String() );
503 		rList.Insert( new String( DEFINE_CONST_UNICODE( "_top" ) ) );
504 		rList.Insert( new String( DEFINE_CONST_UNICODE( "_parent" ) ) );
505 		rList.Insert( new String( DEFINE_CONST_UNICODE( "_blank" ) ) );
506 		rList.Insert( new String( DEFINE_CONST_UNICODE( "_self" ) ) );
507 	}
508 
509 	SfxViewFrame* pView = GetCurrentViewFrame();
510 	if( pView && pView->GetViewShell() && pChildArr )
511 	{
512 		sal_uInt16 nCount = pChildArr->Count();
513 		for ( sal_uInt16 n=0; n<nCount; n++)
514 		{
515 			SfxFrame* pFrame = (*pChildArr)[n];
516 			pFrame->GetTargetList( rList );
517 		}
518 	}
519 }
520 
521 //-------------------------------------------------------------------------
522 
GetBroadcaster() const523 SfxBroadcaster& SfxFrame::GetBroadcaster() const
524 {
525 	return *pImp;
526 }
527 
IsParent(SfxFrame * pFrame) const528 sal_Bool SfxFrame::IsParent( SfxFrame *pFrame ) const
529 {
530 	SfxFrame *pParent = pParentFrame;
531 	while ( pParent )
532 	{
533 		if ( pParent == pFrame )
534 			return sal_True;
535 		pParent = pParent->pParentFrame;
536 	}
537 
538 	return sal_False;
539 }
540 
InsertTopFrame_Impl(SfxFrame * pFrame)541 void SfxFrame::InsertTopFrame_Impl( SfxFrame* pFrame )
542 {
543 	SfxFrameArr_Impl& rArr = *SFX_APP()->Get_Impl()->pTopFrames;
544 	rArr.Insert( pFrame, rArr.Count() );
545 }
546 
RemoveTopFrame_Impl(SfxFrame * pFrame)547 void SfxFrame::RemoveTopFrame_Impl( SfxFrame* pFrame )
548 {
549 	SfxFrameArr_Impl& rArr = *SFX_APP()->Get_Impl()->pTopFrames;
550 	rArr.Remove( rArr.GetPos( pFrame ) );
551 }
552 
SfxFrameItem(sal_uInt16 nWhichId,SfxViewFrame * p)553 SfxFrameItem::SfxFrameItem( sal_uInt16 nWhichId, SfxViewFrame *p )
554 	: SfxPoolItem( nWhichId ), pFrame( p ? &p->GetFrame() : NULL )
555 {
556 	wFrame = pFrame;
557 }
558 
SfxFrameItem(sal_uInt16 nWhichId,SfxFrame * p)559 SfxFrameItem::SfxFrameItem( sal_uInt16 nWhichId, SfxFrame *p ):
560 	SfxPoolItem( nWhichId ),
561 	pFrame( p ), wFrame( p )
562 {
563 }
564 
SfxFrameItem(SfxFrame * p)565 SfxFrameItem::SfxFrameItem( SfxFrame *p ):
566 	SfxPoolItem( 0 ),
567 	pFrame( p ), wFrame( p )
568 {
569 }
570 
operator ==(const SfxPoolItem & rItem) const571 int SfxFrameItem::operator==( const SfxPoolItem &rItem ) const
572 {
573 	 return ((SfxFrameItem&)rItem).pFrame == pFrame &&
574 		 ((SfxFrameItem&)rItem).wFrame == wFrame;
575 }
576 
577 //--------------------------------------------------------------------
578 
GetValueText() const579 String SfxFrameItem::GetValueText() const
580 {
581 	return String();
582 }
583 
Clone(SfxItemPool *) const584 SfxPoolItem* SfxFrameItem::Clone( SfxItemPool *) const
585 {
586 	SfxFrameItem* pNew = new SfxFrameItem( wFrame);
587 	pNew->SetFramePtr_Impl( pFrame );
588 	return pNew;
589 }
590 
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const591 sal_Bool SfxFrameItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const
592 {
593 	if ( wFrame )
594 	{
595 		rVal <<= wFrame->GetFrameInterface();
596 		return sal_True;
597 	}
598 
599 	return sal_False;
600 }
601 
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)602 sal_Bool SfxFrameItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
603 {
604 	Reference < XFrame > xFrame;
605 	if ( (rVal >>= xFrame) && xFrame.is() )
606 	{
607 		SfxFrame* pFr = SfxFrame::GetFirst();
608 		while ( pFr )
609 		{
610 			if ( pFr->GetFrameInterface() == xFrame )
611 			{
612 				wFrame = pFrame = pFr;
613 				return sal_True;
614 			}
615 
616 			pFr = SfxFrame::GetNext( *pFr );
617 		}
618 		return sal_True;
619 	}
620 
621 	return sal_False;
622 }
623 
624 
SfxUsrAnyItem(sal_uInt16 nWhichId,const::com::sun::star::uno::Any & rAny)625 SfxUsrAnyItem::SfxUsrAnyItem( sal_uInt16 nWhichId, const ::com::sun::star::uno::Any& rAny )
626 	: SfxPoolItem( nWhichId )
627 {
628 	aValue = rAny;
629 }
630 
operator ==(const SfxPoolItem &) const631 int SfxUsrAnyItem::operator==( const SfxPoolItem& /*rItem*/ ) const
632 {
633 //   return rItem.ISA( SfxUsrAnyItem ) && ((SfxUsrAnyItem&)rItem).aValue == aValue;
634 	return sal_False;
635 }
636 
Clone(SfxItemPool *) const637 SfxPoolItem* SfxUsrAnyItem::Clone( SfxItemPool *) const
638 {
639     return new SfxUsrAnyItem( Which(), aValue );
640 }
641 
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const642 sal_Bool SfxUsrAnyItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
643 {
644     rVal = aValue;
645     return sal_True;
646 }
647 
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)648 sal_Bool SfxUsrAnyItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
649 {
650     aValue = rVal;
651     return sal_True;
652 }
653 
SfxUnoFrameItem()654 SfxUnoFrameItem::SfxUnoFrameItem()
655 	: SfxPoolItem()
656 	, m_xFrame()
657 {
658 }
659 
SfxUnoFrameItem(sal_uInt16 nWhichId,const::com::sun::star::uno::Reference<::com::sun::star::frame::XFrame> & i_rFrame)660 SfxUnoFrameItem::SfxUnoFrameItem( sal_uInt16 nWhichId, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& i_rFrame )
661 	: SfxPoolItem( nWhichId )
662 	, m_xFrame( i_rFrame )
663 {
664 }
665 
operator ==(const SfxPoolItem & i_rItem) const666 int SfxUnoFrameItem::operator==( const SfxPoolItem& i_rItem ) const
667 {
668     return i_rItem.ISA( SfxUnoFrameItem ) && static_cast< const SfxUnoFrameItem& >( i_rItem ).m_xFrame == m_xFrame;
669 }
670 
Clone(SfxItemPool *) const671 SfxPoolItem* SfxUnoFrameItem::Clone( SfxItemPool* ) const
672 {
673     return new SfxUnoFrameItem( Which(), m_xFrame );
674 }
675 
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const676 sal_Bool SfxUnoFrameItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) const
677 {
678     rVal <<= m_xFrame;
679     return sal_True;
680 }
681 
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)682 sal_Bool SfxUnoFrameItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 /*nMemberId*/ )
683 {
684     return ( rVal >>= m_xFrame );
685 }
686 
SfxFrameIterator(const SfxFrame & rFrame,sal_Bool bRecur)687 SfxFrameIterator::SfxFrameIterator( const SfxFrame& rFrame, sal_Bool bRecur )
688 	: pFrame( &rFrame )
689 	, bRecursive( bRecur )
690 {}
691 
FirstFrame()692 SfxFrame* SfxFrameIterator::FirstFrame()
693 {
694 	// GetFirst beginnt die Iteration beim ersten ChildFrame
695 	return pFrame->GetChildFrame( 0 );
696 }
697 
NextFrame(SfxFrame & rPrev)698 SfxFrame* SfxFrameIterator::NextFrame( SfxFrame& rPrev )
699 {
700 	// Zuerst auf Kinder testen, wenn Rekursion erw"unscht
701 	SfxFrame *pRet = NULL;
702 	if ( bRecursive )
703 		pRet = rPrev.GetChildFrame( 0 );
704 	if ( !pRet )
705 	{
706 		// Anderenfalls mit den Geschwistern von rPrev weitermachen
707 		pRet = NextSibling_Impl( rPrev );
708 	}
709 
710 	return pRet;
711 }
712 
713 
NextSibling_Impl(SfxFrame & rPrev)714 SfxFrame* SfxFrameIterator::NextSibling_Impl( SfxFrame& rPrev )
715 {
716 	SfxFrame *pRet = NULL;
717 	if ( &rPrev != pFrame )
718 	{
719 		SfxFrameArr_Impl& rArr = *rPrev.pParentFrame->pChildArr;
720 		sal_uInt16 nPos = rArr.GetPos( &rPrev );
721 		if ( nPos+1 < rArr.Count() )
722 			pRet = rArr[nPos+1];
723 
724 		if ( !pRet && rPrev.pParentFrame->pParentFrame )
725 			pRet = NextSibling_Impl( *rPrev.pParentFrame );
726 	}
727 
728 	return pRet;
729 }
730 
IsTop() const731 sal_Bool SfxFrame::IsTop() const
732 {
733     return GetFrameInterface().is() ? GetFrameInterface()->isTop() : sal_False;
734 }
735 
HasComponent() const736 sal_Bool SfxFrame::HasComponent() const
737 {
738     return sal_False;
739 }
740 
GetController() const741 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SfxFrame::GetController() const
742 {
743     if ( pImp->pCurrentViewFrame && pImp->pCurrentViewFrame->GetViewShell() )
744         return pImp->pCurrentViewFrame->GetViewShell()->GetController();
745     else
746         return ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > ();
747 }
748 
GetFrameInterface() const749 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >  SfxFrame::GetFrameInterface() const
750 {
751     return pImp->xFrame;
752 }
753 
SetFrameInterface_Impl(const::com::sun::star::uno::Reference<::com::sun::star::frame::XFrame> & rFrame)754 void SfxFrame::SetFrameInterface_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame )
755 {
756     pImp->xFrame = rFrame;
757     com::sun::star::uno::Reference< com::sun::star::frame::XDispatchRecorder > xRecorder;
758 	if ( !rFrame.is() && GetCurrentViewFrame() )
759 		GetCurrentViewFrame()->GetBindings().SetRecorder_Impl( xRecorder );
760 }
761 
Appear()762 void SfxFrame::Appear()
763 {
764 	if ( GetCurrentViewFrame() )
765 	{
766 		GetCurrentViewFrame()->Show();
767         GetWindow().Show();
768         pImp->xFrame->getContainerWindow()->setVisible( sal_True );
769 		if ( pParentFrame )
770 			pParentFrame->Appear();
771         Reference < ::com::sun::star::awt::XTopWindow > xTopWindow( pImp->xFrame->getContainerWindow(), UNO_QUERY );
772         if ( xTopWindow.is() )
773             xTopWindow->toFront();
774 	}
775 }
776 
AppearWithUpdate()777 void SfxFrame::AppearWithUpdate()
778 {
779 	Appear();
780 	if ( GetCurrentViewFrame() )
781         GetCurrentViewFrame()->GetDispatcher()->Update_Impl( sal_True );
782 }
783 
SetOwnsBindings_Impl(sal_Bool bSet)784 void SfxFrame::SetOwnsBindings_Impl( sal_Bool bSet )
785 {
786 	pImp->bOwnsBindings = bSet;
787 }
788 
OwnsBindings_Impl() const789 sal_Bool SfxFrame::OwnsBindings_Impl() const
790 {
791 	return pImp->bOwnsBindings;
792 }
793 
SetToolSpaceBorderPixel_Impl(const SvBorder & rBorder)794 void SfxFrame::SetToolSpaceBorderPixel_Impl( const SvBorder& rBorder )
795 {
796     pImp->aBorder = rBorder;
797     SfxViewFrame *pF = GetCurrentViewFrame();
798     if ( pF )
799     {
800         Point aPos ( rBorder.Left(), rBorder.Top() );
801         Size aSize( GetWindow().GetOutputSizePixel() );
802         long nDeltaX = rBorder.Left() + rBorder.Right();
803         if ( aSize.Width() > nDeltaX )
804             aSize.Width() -= nDeltaX;
805         else
806             aSize.Width() = 0;
807 
808         long nDeltaY = rBorder.Top() + rBorder.Bottom();
809         if ( aSize.Height() > nDeltaY )
810             aSize.Height() -= nDeltaY;
811         else
812             aSize.Height() = 0;
813 
814         if ( GetParentFrame() )
815         {
816             sal_Bool bHasTools = rBorder.Left() != rBorder.Right() || rBorder.Top() != rBorder.Bottom();
817             pF->GetWindow().SetBorderStyle( bHasTools ? WINDOW_BORDER_NORMAL : WINDOW_BORDER_NOBORDER );
818         }
819 
820         pF->GetWindow().SetPosSizePixel( aPos, aSize );
821     }
822 }
823 
GetTopOuterRectPixel_Impl() const824 Rectangle SfxFrame::GetTopOuterRectPixel_Impl() const
825 {
826 	Size aSize( GetWindow().GetOutputSizePixel() );
827 	Point aPoint;
828 	return ( Rectangle ( aPoint, aSize ) );
829 }
830 
GetWorkWindow_Impl() const831 SfxWorkWindow* SfxFrame::GetWorkWindow_Impl() const
832 {
833 	if ( pImp->pWorkWin )
834 		return pImp->pWorkWin;
835 	else if ( pParentFrame )
836 		return pParentFrame->GetWorkWindow_Impl();
837     else
838         return NULL;
839 }
840 
SetWorkWindow_Impl(SfxWorkWindow * pWorkwin)841 void SfxFrame::SetWorkWindow_Impl( SfxWorkWindow* pWorkwin )
842 {
843     pImp->pWorkWin = pWorkwin;
844 }
845 
CreateWorkWindow_Impl()846 void SfxFrame::CreateWorkWindow_Impl()
847 {
848     SfxFrame* pFrame = this;
849 
850 	if ( IsInPlace() )
851 	{
852 		// this makes sense only for inplace activated objects
853 		try
854 		{
855 	    	Reference < XChild > xChild( GetCurrentDocument()->GetModel(), UNO_QUERY );
856     		if ( xChild.is() )
857 	    	{
858     	    	Reference < XModel > xParent( xChild->getParent(), UNO_QUERY );
859         		if ( xParent.is() )
860 				{
861 					Reference< XController > xParentCtrler = xParent->getCurrentController();
862 					if ( xParentCtrler.is() )
863         			{
864 	            		Reference < XFrame > xFrame( xParentCtrler->getFrame() );
865     	        		SfxFrame* pFr = SfxFrame::GetFirst();
866         	    		while ( pFr )
867             			{
868                 			if ( pFr->GetFrameInterface() == xFrame )
869                 			{
870 	                    		pFrame = pFr;
871     	                		break;
872         	        		}
873 
874             	    		pFr = SfxFrame::GetNext( *pFr );
875             			}
876     	    		}
877 				}
878     		}
879 		}
880 		catch(Exception&)
881 		{
882 			OSL_ENSURE(0,"SfxFrame::CreateWorkWindow_Impl: Exception cachted. Please try to submit a repoducable bug !");
883 		}
884 	}
885 
886     pImp->pWorkWin = new SfxFrameWorkWin_Impl( &pFrame->GetWindow(), this, pFrame );
887 }
888 
GrabFocusOnComponent_Impl()889 void SfxFrame::GrabFocusOnComponent_Impl()
890 {
891 	if ( pImp->bReleasingComponent )
892 	{
893 		GetWindow().GrabFocus();
894 		return;
895 	}
896 
897     Window* pFocusWindow = &GetWindow();
898     if ( GetCurrentViewFrame() && GetCurrentViewFrame()->GetViewShell() && GetCurrentViewFrame()->GetViewShell()->GetWindow() )
899         pFocusWindow = GetCurrentViewFrame()->GetViewShell()->GetWindow();
900 
901     if( !pFocusWindow->HasChildPathFocus() )
902         pFocusWindow->GrabFocus();
903 }
904 
ReleasingComponent_Impl(sal_Bool bSet)905 void SfxFrame::ReleasingComponent_Impl( sal_Bool bSet )
906 {
907 	pImp->bReleasingComponent = bSet;
908 }
909 
IsInPlace() const910 sal_Bool SfxFrame::IsInPlace() const
911 {
912     return pImp->bInPlace;
913 }
914 
SetInPlace_Impl(sal_Bool bSet)915 void SfxFrame::SetInPlace_Impl( sal_Bool bSet )
916 {
917     pImp->bInPlace = bSet;
918 }
919 
Resize()920 void SfxFrame::Resize()
921 {
922     if ( IsClosing_Impl() )
923         return;
924 
925     if ( OwnsBindings_Impl() )
926 	{
927         if ( IsInPlace() )
928         {
929             SetToolSpaceBorderPixel_Impl( SvBorder() );
930         }
931         else
932         {
933             // check for IPClient that contains UIactive object or object that is currently UI activating
934             SfxWorkWindow *pWork = GetWorkWindow_Impl();
935             SfxInPlaceClient* pClient = GetCurrentViewFrame()->GetViewShell() ? GetCurrentViewFrame()->GetViewShell()->GetUIActiveIPClient_Impl() : 0;
936             if ( pClient )
937             {
938                 uno::Reference < lang::XUnoTunnel > xObj( pClient->GetObject()->getComponent(), uno::UNO_QUERY );
939                 uno::Sequence < sal_Int8 > aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
940                 sal_Int64 nHandle = (xObj.is()? xObj->getSomething( aSeq ): 0);
941                 if ( nHandle )
942                 {
943                     SfxObjectShell* pDoc = reinterpret_cast< SfxObjectShell* >( sal::static_int_cast< sal_IntPtr >( nHandle ));
944                     pWork = SfxViewFrame::GetFirst( pDoc )->GetFrame().GetWorkWindow_Impl();
945                 }
946             }
947 
948             if ( pWork )
949             {
950                 pWork->ArrangeChilds_Impl();
951                 pWork->ShowChilds_Impl();
952             }
953 
954             // problem in presence of UIActive object: when the window is resized, but the toolspace border
955             // remains the same, setting the toolspace border at the ContainerEnvironment doesn't force a
956             // resize on the IPEnvironment; without that no resize is called for the SfxViewFrame. So always
957             // set the window size of the SfxViewFrame explicit.
958             SetToolSpaceBorderPixel_Impl( pImp->aBorder );
959         }
960 	}
961     else if ( pImp->pCurrentViewFrame )
962     {
963         pImp->pCurrentViewFrame->GetWindow().SetSizePixel( GetWindow().GetOutputSizePixel() );
964     }
965 
966 }
967 
GetFirst()968 SfxFrame* SfxFrame::GetFirst()
969 {
970     if ( !pFramesArr_Impl )
971         return 0;
972     return pFramesArr_Impl->Count() ? pFramesArr_Impl->GetObject(0) : 0;
973 }
974 
GetNext(SfxFrame & rFrame)975 SfxFrame* SfxFrame::GetNext( SfxFrame& rFrame )
976 {
977     sal_uInt16 nPos = pFramesArr_Impl->GetPos( &rFrame );
978     if ( nPos+1 < pFramesArr_Impl->Count() )
979         return pFramesArr_Impl->GetObject(nPos+1);
980     else
981         return NULL;
982 }
983 
OpenDocumentSynchron(SfxItemSet & i_rSet,const Reference<XFrame> & i_rTargetFrame)984 const SfxPoolItem* SfxFrame::OpenDocumentSynchron( SfxItemSet& i_rSet, const Reference< XFrame >& i_rTargetFrame )
985 {
986     i_rSet.Put( SfxUnoFrameItem( SID_FILLFRAME, i_rTargetFrame ) );
987     i_rSet.ClearItem( SID_TARGETNAME );
988     return SFX_APP()->GetDispatcher_Impl()->Execute( SID_OPENDOC, SFX_CALLMODE_SYNCHRON, i_rSet );
989 }
990 
991