xref: /trunk/main/sfx2/source/appl/childwin.cxx (revision 86e1cf34)
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 #ifndef _TOOLBOX_HXX //autogen
28 #include <vcl/toolbox.hxx>
29 #endif
30 #ifndef _RCID_H
31 #include <tools/rcid.h>
32 #endif
33 #include <unotools/viewoptions.hxx>
34 #include <com/sun/star/frame/XController.hpp>
35 #include <com/sun/star/frame/XFrame.hpp>
36 #include <com/sun/star/util/XCloseable.hpp>
37 #include <cppuhelper/implbase1.hxx>
38 
39 #ifndef GCC
40 #endif
41 
42 #include <sfx2/childwin.hxx>
43 #include <sfx2/app.hxx>
44 #include "arrdecl.hxx"
45 #include <sfx2/bindings.hxx>
46 #include <sfx2/module.hxx>
47 #include <sfx2/dockwin.hxx>
48 #include <sfx2/dispatch.hxx>
49 #include "workwin.hxx"
50 
51 static const sal_uInt16 nVersion = 2;
52 
53 DBG_NAME(SfxChildWindow)
54 
55 SV_IMPL_PTRARR( SfxChildWinContextArr_Impl, SfxChildWinContextFactory* );
56 
57 struct SfxChildWindow_Impl
58 {
59 	::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > 			xFrame;
60     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >      xListener;
61 	SfxChildWinFactory* pFact;
62 	sal_Bool				bHideNotDelete;
63 	sal_Bool				bVisible;
64 	sal_Bool				bHideAtToggle;
65 	sal_Bool				bWantsFocus;
66 	SfxModule*			pContextModule;
67 	SfxWorkWindow*		pWorkWin;
68 };
69 
70 // -----------------------------------------------------------------------
71 
72 class DisposeListener : public ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener >
73 {
74     public:
DisposeListener(SfxChildWindow * pOwner,SfxChildWindow_Impl * pData)75         DisposeListener( SfxChildWindow*      pOwner ,
76                          SfxChildWindow_Impl* pData  )
77             :   m_pOwner( pOwner )
78             ,   m_pData ( pData  )
79         {}
80 
disposing(const::com::sun::star::lang::EventObject & aSource)81         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& aSource ) throw (::com::sun::star::uno::RuntimeException)
82         {
83             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener > xSelfHold( this );
84 
85             ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > xComp( aSource.Source, ::com::sun::star::uno::UNO_QUERY );
86             if( xComp.is() )
87                 xComp->removeEventListener( this );
88 
89             if( m_pOwner && m_pData )
90             {
91 	            m_pData->xListener = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >();
92 
93 				if ( m_pData->pWorkWin )
94 				{
95 					// m_pOwner and m_pData will be killed
96 		            m_pData->xFrame    = ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >();
97 	                m_pData->pWorkWin->GetBindings().Execute( m_pOwner->GetType() );
98 				}
99 				else
100 				{
101 					delete m_pOwner;
102 				}
103 
104                 m_pOwner = NULL;
105                 m_pData  = NULL;
106             }
107         }
108 
109     private:
110         SfxChildWindow*      m_pOwner;
111         SfxChildWindow_Impl* m_pData ;
112 };
113 
114 // -----------------------------------------------------------------------
115 
GetPosSizeFromString(const String & rStr,Point & rPos,Size & rSize)116 sal_Bool GetPosSizeFromString( const String& rStr, Point& rPos, Size& rSize )
117 {
118 	if ( rStr.GetTokenCount('/') != 4 )
119 		return sal_False;
120 
121 	xub_StrLen nIdx = 0;
122 	rPos.X() = rStr.GetToken(0, '/', nIdx).ToInt32();
123 	rPos.Y() = rStr.GetToken(0, '/', nIdx).ToInt32();
124 	rSize.Width() = rStr.GetToken(0, '/', nIdx).ToInt32();
125 	rSize.Height() = rStr.GetToken(0, '/', nIdx).ToInt32();
126 
127 	// negative sizes are invalid
128 	if ( rSize.Width() < 0 || rSize.Height() < 0 )
129 		return sal_False;
130 
131 	return sal_True;
132 }
133 
GetSplitSizeFromString(const String & rStr,Size & rSize)134 sal_Bool GetSplitSizeFromString( const String& rStr, Size& rSize )
135 {
136     xub_StrLen nIndex = rStr.Search( ',' );
137     if ( nIndex != STRING_NOTFOUND )
138     {
139         String aStr = rStr.Copy( nIndex+1 );
140 
141         sal_Int32 nCount = aStr.GetTokenCount(';');
142         if ( nCount != 2 )
143             return sal_False;
144 
145 	    rSize.Width() = aStr.GetToken(0, ';' ).ToInt32();
146 	    rSize.Height() = aStr.GetToken(1, ';' ).ToInt32();
147 
148 	    // negative sizes are invalid
149 	    if ( rSize.Width() < 0 || rSize.Height() < 0 )
150 		    return sal_False;
151 
152 	    return sal_True;
153     }
154 
155     return sal_False;
156 }
157 
158 //=========================================================================
SfxChildWindow(Window * pParentWindow,sal_uInt16 nId)159 SfxChildWindow::SfxChildWindow(Window *pParentWindow, sal_uInt16 nId)
160 	: pParent(pParentWindow)
161 	, nType(nId)
162 	, eChildAlignment(SFX_ALIGN_NOALIGNMENT)
163 	, pWindow(0L)
164 {
165 	pImp = new SfxChildWindow_Impl;
166 	pImp->pFact = 0L;
167 	pImp->bHideNotDelete = sal_False;
168 	pImp->bHideAtToggle = sal_False;
169 	pImp->bWantsFocus = sal_True;
170 	pImp->bVisible = sal_True;
171 	pImp->pContextModule = NULL;
172 	pImp->pWorkWin = NULL;
173 
174 	pContext = 0L;
175 	DBG_CTOR(SfxChildWindow,0);
176 }
177 
Destroy()178 void SfxChildWindow::Destroy()
179 {
180 	if ( GetFrame().is() )
181 	{
182 		pImp->pWorkWin = NULL;
183 		try
184 		{
185 			::com::sun::star::uno::Reference < ::com::sun::star::util::XCloseable > xClose( GetFrame(), ::com::sun::star::uno::UNO_QUERY );
186 			if ( xClose.is() )
187 				xClose->close( sal_True );
188 			else
189 				GetFrame()->dispose();
190 		}
191 		catch ( com::sun::star::uno::Exception& )
192 		{
193 		}
194 	}
195 	else
196 		delete this;
197 }
198 
199 //-------------------------------------------------------------------------
~SfxChildWindow()200 SfxChildWindow::~SfxChildWindow()
201 {
202 	DBG_DTOR(SfxChildWindow,0);
203 	if ( pContext )
204 		delete pContext;
205 	if ( pWindow )
206 	    delete pWindow;
207 	delete pImp;
208 }
209 
210 //-------------------------------------------------------------------------
CreateChildWindow(sal_uInt16 nId,Window * pParent,SfxBindings * pBindings,SfxChildWinInfo & rInfo)211 SfxChildWindow* SfxChildWindow::CreateChildWindow( sal_uInt16 nId,
212 		Window *pParent, SfxBindings* pBindings, SfxChildWinInfo& rInfo)
213 {
214 	SfxChildWindow *pChild=0;
215 	SfxChildWinFactory* pFact=0;
216     sal_uInt16 nOldMode = Application::GetSystemWindowMode();
217 
218 	// Zuerst ChildWindow im SDT suchen; "Uberlagerungen m"ussen mit einem
219 	// ChildWindowContext realisiert werden
220 	SfxApplication *pApp = SFX_APP();
221     {
222 	    SfxChildWinFactArr_Impl &rFactories = pApp->GetChildWinFactories_Impl();
223 	    for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
224 	    {
225 		    pFact = rFactories[nFactory];
226 		    if ( pFact->nId == nId )
227 		    {
228 			    SfxChildWinInfo& rFactInfo = pFact->aInfo;
229 			    if ( rInfo.bVisible )
230 			    {
231 				    if ( pBindings )
232 					    pBindings->ENTERREGISTRATIONS();
233 				    SfxChildWinInfo aInfo = rFactInfo;
234                     Application::SetSystemWindowMode( SYSTEMWINDOW_MODE_NOAUTOMODE );
235 				    pChild = pFact->pCtor( pParent, nId, pBindings, &aInfo );
236                     Application::SetSystemWindowMode( nOldMode );
237 				    if ( pBindings )
238 					    pBindings->LEAVEREGISTRATIONS();
239 			    }
240 
241 			    break;
242 		    }
243 	    }
244     }
245 
246 	SfxDispatcher *pDisp = pBindings->GetDispatcher_Impl();
247     SfxModule *pMod = pDisp ? SfxModule::GetActiveModule( pDisp->GetFrame() ) :0;
248 	if ( !pChild &&  pMod )
249 	{
250 		SfxChildWinFactArr_Impl *pFactories = pMod->GetChildWinFactories_Impl();
251 		if ( pFactories )
252 		{
253 			SfxChildWinFactArr_Impl &rFactories = *pFactories;
254 			for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
255 			{
256 				pFact = rFactories[nFactory];
257 				if ( pFact->nId == nId )
258 				{
259 					SfxChildWinInfo& rFactInfo = pFact->aInfo;
260 					if ( rInfo.bVisible )
261 					{
262 						if ( pBindings )
263 							pBindings->ENTERREGISTRATIONS();
264 						SfxChildWinInfo aInfo = rFactInfo;
265                         Application::SetSystemWindowMode( SYSTEMWINDOW_MODE_NOAUTOMODE );
266 						pChild = pFact->pCtor( pParent, nId, pBindings, &aInfo );
267                         Application::SetSystemWindowMode( nOldMode );
268 						if ( pBindings )
269 							pBindings->LEAVEREGISTRATIONS();
270 					}
271 
272 					break;
273 				}
274 			}
275 		}
276 	}
277 
278 	if ( pChild )
279 		pChild->SetFactory_Impl( pFact );
280 
281 	DBG_ASSERT(pFact && (pChild || !rInfo.bVisible), "ChildWindow-Typ nicht registriert!");
282 
283 	if ( pChild && !pChild->pWindow )
284 	{
285 		DELETEZ(pChild);
286 		DBG_WARNING("ChildWindow hat kein Fenster!");
287 	}
288 
289 	return pChild;
290 }
291 
292 //-------------------------------------------------------------------------
SaveStatus(const SfxChildWinInfo & rInfo)293 void SfxChildWindow::SaveStatus(const SfxChildWinInfo& rInfo)
294 {
295     sal_uInt16 nID = GetType();
296 
297     String aWinData( 'V' );
298     aWinData += String::CreateFromInt32( nVersion );
299     aWinData += ',';
300     aWinData += rInfo.bVisible ? 'V' : 'H';
301     aWinData += ',';
302     aWinData += String::CreateFromInt32( rInfo.nFlags );
303     if ( rInfo.aExtraString.Len() )
304     {
305         aWinData += ',';
306         aWinData += rInfo.aExtraString;
307     }
308 
309     SvtViewOptions aWinOpt( E_WINDOW, String::CreateFromInt32( nID ) );
310     // aWinOpt.SetPosition( rInfo.aPos.X(), rInfo.aPos.Y() );
311     // aWinOpt.SetSize( rInfo.aSize.Width(), rInfo.aSize.Height() );
312     aWinOpt.SetWindowState( String( rInfo.aWinState, RTL_TEXTENCODING_UTF8 ) );
313 
314     ::com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue > aSeq(1);
315     aSeq[0].Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("Data") );
316     aSeq[0].Value <<= ::rtl::OUString( aWinData );
317     aWinOpt.SetUserData( aSeq );
318 
319     // ... but save status at runtime!
320     pImp->pFact->aInfo = rInfo;
321 }
322 
323 //-------------------------------------------------------------------------
SetAlignment(SfxChildAlignment eAlign)324 void SfxChildWindow::SetAlignment(SfxChildAlignment eAlign)
325 {
326 	DBG_CHKTHIS(SfxChildWindow,0);
327 
328 	eChildAlignment = eAlign;
329 }
330 
331 //-------------------------------------------------------------------------
SetPosSizePixel(const Point & rPoint,Size & rSize)332 void SfxChildWindow::SetPosSizePixel(const Point& rPoint, Size& rSize)
333 {
334 	DBG_CHKTHIS(SfxChildWindow,0);
335 
336 	pWindow->SetPosSizePixel(rPoint, rSize);
337 }
338 
339 //-------------------------------------------------------------------------
GetInfo() const340 SfxChildWinInfo SfxChildWindow::GetInfo() const
341 {
342 	DBG_CHKTHIS(SfxChildWindow,0);
343 
344 	SfxChildWinInfo aInfo;
345 	aInfo.aPos	= pWindow->GetPosPixel();
346 	aInfo.aSize = pWindow->GetSizePixel();
347     if ( pWindow->IsSystemWindow() )
348     {
349         sal_uIntPtr nMask = WINDOWSTATE_MASK_POS | WINDOWSTATE_MASK_STATE;
350         if ( pWindow->GetStyle() & WB_SIZEABLE )
351             nMask |= ( WINDOWSTATE_MASK_WIDTH | WINDOWSTATE_MASK_HEIGHT );
352         aInfo.aWinState = ((SystemWindow*)pWindow)->GetWindowState( nMask );
353     }
354     else if ( pWindow->GetType() == RSC_DOCKINGWINDOW )
355     {
356         if (((DockingWindow*)pWindow)->GetFloatingWindow() )
357             aInfo.aWinState = ((DockingWindow*)pWindow)->GetFloatingWindow()->GetWindowState();
358         else
359         {
360             SfxChildWinInfo aTmpInfo;
361             ((SfxDockingWindow*)pWindow)->FillInfo( aTmpInfo );
362             aInfo.aExtraString = aTmpInfo.aExtraString;
363         }
364     }
365 
366 	aInfo.bVisible = pImp->bVisible;
367 	aInfo.nFlags = 0;
368 	return aInfo;
369 }
370 
371 //-------------------------------------------------------------------------
GetPosition()372 sal_uInt16 SfxChildWindow::GetPosition()
373 {
374 	return pImp->pFact->nPos;
375 }
376 
377 #if 0
378 static void ImplWindowStateFromStr( Point rPos, Size rSize, const ByteString& rStr )
379 {
380     sal_uIntPtr       nValidMask  = 0;
381     xub_StrLen  nIndex      = 0;
382     ByteString  aTokenStr;
383 
384     aTokenStr = rStr.GetToken( 0, ',', nIndex );
385     if ( aTokenStr.Len() )
386     {
387         rPos.X() = aTokenStr.ToInt32();
388         nValidMask |= WINDOWSTATE_MASK_X;
389     }
390 
391     aTokenStr = rStr.GetToken( 0, ',', nIndex );
392     if ( aTokenStr.Len() )
393     {
394         rPos.Y() = aTokenStr.ToInt32();
395         nValidMask |= WINDOWSTATE_MASK_Y;
396     }
397 
398     aTokenStr = rStr.GetToken( 0, ',', nIndex );
399     if ( aTokenStr.Len() )
400     {
401         rSize.Width() = aTokenStr.ToInt32();
402         nValidMask |= WINDOWSTATE_MASK_WIDTH;
403     }
404 
405     aTokenStr = rStr.GetToken( 0, ';', nIndex );
406     if ( aTokenStr.Len() )
407     {
408         rSize.Height() = aTokenStr.ToInt32();
409         nValidMask |= WINDOWSTATE_MASK_HEIGHT;
410     }
411 }
412 #endif
413 
414 //-------------------------------------------------------------------------
InitializeChildWinFactory_Impl(sal_uInt16 nId,SfxChildWinInfo & rInfo)415 void SfxChildWindow::InitializeChildWinFactory_Impl( sal_uInt16 nId, SfxChildWinInfo& rInfo )
416 {
417 	// load configuration
418 	SvtViewOptions aWinOpt( E_WINDOW, String::CreateFromInt32( nId ) );
419 
420     if ( aWinOpt.Exists() )
421         rInfo.bVisible  = aWinOpt.IsVisible(); // set state from configuration. Can be overwritten by UserData, see below
422 
423     ::com::sun::star::uno::Sequence < ::com::sun::star::beans::NamedValue > aSeq = aWinOpt.GetUserData();
424 
425     ::rtl::OUString aTmp;
426     if ( aSeq.getLength() )
427         aSeq[0].Value >>= aTmp;
428 
429     String aWinData( aTmp );
430     rInfo.aWinState = ByteString( String(aWinOpt.GetWindowState()), RTL_TEXTENCODING_UTF8 );
431 
432     //ImplWindowStateFromStr( rInfo.aPos, rInfo.aSize, ByteString( aWinState, RTL_TEXTENCODING_UTF8 ) );
433 
434     if ( aWinData.Len() )
435 	{
436 		// Nach Versionskennung suchen
437 		if ( aWinData.GetChar((sal_uInt16)0) != 0x0056 ) // 'V' = 56h
438 			// Keine Versionskennung, daher nicht verwenden
439 			return;
440 
441 		// 'V' l"oschen
442 		aWinData.Erase(0,1);
443 
444 		// Version lesen
445 		char cToken = ',';
446 		sal_uInt16 nPos = aWinData.Search( cToken );
447         sal_uInt16 nActVersion = (sal_uInt16)aWinData.Copy( 0, nPos + 1 ).ToInt32();
448         if ( nActVersion != nVersion )
449             return;
450 
451 		aWinData.Erase(0,nPos+1);
452 
453         //aWinOpt.GetPosition( rInfo.aPos.X(), rInfo.aPos.Y() );
454         //aWinOpt.GetSize( rInfo.aSize.Width(), rInfo.aSize.Height() );
455 
456 		// Sichtbarkeit laden: ist als ein char codiert
457         rInfo.bVisible = (aWinData.GetChar(0) == 0x0056); // 'V' = 56h
458         aWinData.Erase(0,1);
459         nPos = aWinData.Search( cToken );
460 		if (nPos != STRING_NOTFOUND)
461 		{
462             sal_uInt16 nNextPos = aWinData.Search( cToken, 2 );
463             if ( nNextPos != STRING_NOTFOUND )
464             {
465                 // es gibt noch Extra-Information
466                 rInfo.nFlags = (sal_uInt16)aWinData.Copy( nPos+1, nNextPos - nPos - 1 ).ToInt32();
467                 aWinData.Erase( nPos, nNextPos-nPos+1 );
468                 rInfo.aExtraString = aWinData;
469             }
470             else
471                 rInfo.nFlags = (sal_uInt16)aWinData.Copy( nPos+1 ).ToInt32();
472 		}
473 	}
474 }
475 
CreateContext(sal_uInt16 nContextId,SfxBindings & rBindings)476 void SfxChildWindow::CreateContext( sal_uInt16 nContextId, SfxBindings& rBindings )
477 {
478 	SfxChildWindowContext *pCon = NULL;
479 	SfxChildWinFactory* pFact=0;
480 	SfxApplication *pApp = SFX_APP();
481 	SfxDispatcher *pDisp = rBindings.GetDispatcher_Impl();
482     SfxModule *pMod = pDisp ? SfxModule::GetActiveModule( pDisp->GetFrame() ) :0;
483 	if ( pMod )
484 	{
485 		SfxChildWinFactArr_Impl *pFactories = pMod->GetChildWinFactories_Impl();
486 		if ( pFactories )
487 		{
488 			SfxChildWinFactArr_Impl &rFactories = *pFactories;
489 			for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
490 			{
491 				pFact = rFactories[nFactory];
492 				if ( pFact->nId == GetType() )
493 				{
494 					DBG_ASSERT( pFact->pArr, "Kein Kontext angemeldet!" );
495 					if ( !pFact->pArr )
496 						break;
497 
498 					SfxChildWinContextFactory *pConFact=0;
499 					for ( sal_uInt16 n=0; n<pFact->pArr->Count(); ++n )
500 					{
501 						pConFact = (*pFact->pArr)[n];
502 						rBindings.ENTERREGISTRATIONS();
503 						if ( pConFact->nContextId == nContextId )
504 						{
505 							SfxChildWinInfo aInfo = pFact->aInfo;
506 							pCon = pConFact->pCtor( GetWindow(), &rBindings, &aInfo );
507 							pCon->nContextId = pConFact->nContextId;
508 							pImp->pContextModule = pMod;
509 						}
510 						rBindings.LEAVEREGISTRATIONS();
511 					}
512 					break;
513 				}
514 			}
515 		}
516 	}
517 
518 	if ( !pCon )
519 	{
520 		SfxChildWinFactArr_Impl &rFactories = pApp->GetChildWinFactories_Impl();
521 		for ( sal_uInt16 nFactory = 0; nFactory < rFactories.Count(); ++nFactory )
522 		{
523 			pFact = rFactories[nFactory];
524 			if ( pFact->nId == GetType() )
525 			{
526 				DBG_ASSERT( pFact->pArr, "Kein Kontext angemeldet!" );
527 				if ( !pFact->pArr )
528 					break;
529 
530 				SfxChildWinContextFactory *pConFact=0;
531 				for ( sal_uInt16 n=0; n<pFact->pArr->Count(); ++n )
532 				{
533 					pConFact = (*pFact->pArr)[n];
534 					rBindings.ENTERREGISTRATIONS();
535 					if ( pConFact->nContextId == nContextId )
536 					{
537 						SfxChildWinInfo aInfo = pFact->aInfo;
538 						pCon = pConFact->pCtor( GetWindow(), &rBindings, &aInfo );
539 						pCon->nContextId = pConFact->nContextId;
540 						pImp->pContextModule = NULL;
541 					}
542 					rBindings.LEAVEREGISTRATIONS();
543 				}
544 				break;
545 			}
546 		}
547 	}
548 
549 	if ( !pCon )
550 	{
551 		DBG_ERROR( "Kein geeigneter Context gefunden!" );
552 		return;
553 	}
554 
555 	if ( pContext )
556 		delete( pContext );
557 	pContext = pCon;
558 	pContext->GetWindow()->SetSizePixel( pWindow->GetOutputSizePixel() );
559 	pContext->GetWindow()->Show();
560 }
561 
SfxChildWindowContext(sal_uInt16 nId)562 SfxChildWindowContext::SfxChildWindowContext( sal_uInt16 nId )
563 	: pWindow( NULL )
564 	, nContextId( nId )
565 {
566 }
567 
~SfxChildWindowContext()568 SfxChildWindowContext::~SfxChildWindowContext()
569 {
570 	delete pWindow;
571 }
572 
GetFloatingWindow() const573 FloatingWindow*	SfxChildWindowContext::GetFloatingWindow() const
574 {
575 	Window *pParent = pWindow->GetParent();
576 	if ( pParent->GetType() == RSC_DOCKINGWINDOW || pParent->GetType() == RSC_TOOLBOX )
577 	{
578 		return ((DockingWindow*)pParent)->GetFloatingWindow();
579 	}
580 	else if ( pParent->GetType() == RSC_FLOATINGWINDOW )
581 	{
582 		return (FloatingWindow*) pParent;
583 	}
584 	else
585 	{
586 		DBG_ERROR("Kein FloatingWindow-Context!");
587 		return NULL;
588 	}
589 }
590 
GetAlignment() const591 SfxChildAlignment SfxChildWindowContext::GetAlignment() const
592 {
593 	Window *pParent = pWindow->GetParent();
594 	if ( pParent->GetType() == RSC_DOCKINGWINDOW )
595 	{
596 		return ((SfxDockingWindow*)pParent)->GetAlignment();
597 	}
598 	else if ( pParent->GetType() == RSC_TOOLBOX )
599 	{
600 		HACK(noch nicht verwendet und noch nicht implementiert);
601 		return SFX_ALIGN_NOALIGNMENT;
602 	}
603 	else
604 		return SFX_ALIGN_NOALIGNMENT;
605 }
606 
Resizing(Size &)607 void SfxChildWindowContext::Resizing( Size& )
608 {
609 }
610 
Close()611 sal_Bool SfxChildWindowContext::Close()
612 {
613 	return sal_True;
614 }
615 
SetFactory_Impl(SfxChildWinFactory * pF)616 void SfxChildWindow::SetFactory_Impl( SfxChildWinFactory *pF )
617 {
618 	pImp->pFact = pF;
619 }
620 
SetHideNotDelete(sal_Bool bOn)621 void SfxChildWindow::SetHideNotDelete( sal_Bool bOn )
622 {
623 	pImp->bHideNotDelete = bOn;
624 }
625 
IsHideNotDelete() const626 sal_Bool SfxChildWindow::IsHideNotDelete() const
627 {
628 	return pImp->bHideNotDelete;
629 }
630 
SetHideAtToggle(sal_Bool bOn)631 void SfxChildWindow::SetHideAtToggle( sal_Bool bOn )
632 {
633 	pImp->bHideAtToggle = bOn;
634 }
635 
IsHideAtToggle() const636 sal_Bool SfxChildWindow::IsHideAtToggle() const
637 {
638 	return pImp->bHideAtToggle;
639 }
640 
SetWantsFocus(sal_Bool bSet)641 void SfxChildWindow::SetWantsFocus( sal_Bool bSet )
642 {
643 	pImp->bWantsFocus = bSet;
644 }
645 
WantsFocus() const646 sal_Bool SfxChildWindow::WantsFocus() const
647 {
648 	return pImp->bWantsFocus;
649 }
650 
GetExtraData_Impl(SfxChildAlignment * pAlign,SfxChildAlignment * pLastAlign,Size * pSize,sal_uInt16 * pLine,sal_uInt16 * pPos) const651 sal_Bool SfxChildWinInfo::GetExtraData_Impl
652 (
653 	SfxChildAlignment	*pAlign,
654 	SfxChildAlignment	*pLastAlign,
655 	Size				*pSize,
656 	sal_uInt16			*pLine,
657 	sal_uInt16			*pPos
658 )   const
659 {
660 	// ung"ultig?
661 	if ( !aExtraString.Len() )
662 		return sal_False;
663 	String aStr;
664 	sal_uInt16 nPos = aExtraString.SearchAscii("AL:");
665 	if ( nPos == STRING_NOTFOUND )
666 		return sal_False;
667 
668 	// Versuche, den Alignment-String "ALIGN:(...)" einzulesen; wenn
669 	// er nicht vorhanden ist, liegt eine "altere Version vor
670 	if ( nPos != STRING_NOTFOUND )
671 	{
672 		sal_uInt16 n1 = aExtraString.Search('(', nPos);
673 		if ( n1 != STRING_NOTFOUND )
674 		{
675 			sal_uInt16 n2 = aExtraString.Search(')', n1);
676 			if ( n2 != STRING_NOTFOUND )
677 			{
678 				// Alignment-String herausschneiden
679 				aStr = aExtraString.Copy(nPos, n2 - nPos + 1);
680 				aStr.Erase(nPos, n1-nPos+1);
681 			}
682 		}
683 	}
684 
685 	// Zuerst das Alignment extrahieren
686 	if ( !aStr.Len() )
687 		return sal_False;
688 	if ( pAlign )
689 		*pAlign = (SfxChildAlignment) (sal_uInt16) aStr.ToInt32();
690 
691 	// Dann das LastAlignment
692 	nPos = aStr.Search(',');
693 	if ( nPos == STRING_NOTFOUND )
694 		return sal_False;
695 	aStr.Erase(0, nPos+1);
696 	if ( pLastAlign )
697 		*pLastAlign = (SfxChildAlignment) (sal_uInt16) aStr.ToInt32();
698 
699 	// Dann die Splitting-Informationen
700 	nPos = aStr.Search(',');
701 	if ( nPos == STRING_NOTFOUND )
702 		// Dockt nicht in einem Splitwindow
703 		return sal_True;
704 	aStr.Erase(0, nPos+1);
705 	Point aChildPos;
706 	Size aChildSize;
707 	if ( GetPosSizeFromString( aStr, aChildPos, aChildSize ) )
708 	{
709 		if ( pSize )
710 			*pSize = aChildSize;
711 		if ( pLine )
712 			*pLine = (sal_uInt16) aChildPos.X();
713 		if ( pPos )
714 			*pPos = (sal_uInt16) aChildPos.Y();
715 		return sal_True;
716 	}
717 	return sal_False;
718 }
719 
IsVisible() const720 sal_Bool SfxChildWindow::IsVisible() const
721 {
722 	return pImp->bVisible;
723 }
724 
SetVisible_Impl(sal_Bool bVis)725 void SfxChildWindow::SetVisible_Impl( sal_Bool bVis )
726 {
727 	pImp->bVisible = bVis;
728 }
729 
Hide()730 void SfxChildWindow::Hide()
731 {
732 	switch ( pWindow->GetType() )
733 	{
734 		case RSC_DOCKINGWINDOW :
735 			((DockingWindow*)pWindow)->Hide();
736 			break;
737 		case RSC_TOOLBOX :
738 			((ToolBox*)pWindow)->Hide();
739 			break;
740 		default:
741 			pWindow->Hide();
742 			break;
743 	}
744 }
745 
746 
747 
Show(sal_uInt16 nFlags)748 void SfxChildWindow::Show( sal_uInt16 nFlags )
749 {
750 	switch ( pWindow->GetType() )
751 	{
752 		case RSC_DOCKINGWINDOW :
753             ((DockingWindow*)pWindow)->Show( sal_True, nFlags );
754 			break;
755 		case RSC_TOOLBOX :
756             ((ToolBox*)pWindow)->Show( sal_True, nFlags );
757 			break;
758 		default:
759             pWindow->Show( sal_True, nFlags );
760 			break;
761 	}
762 }
763 
GetContextWindow(SfxModule * pModule) const764 Window*	SfxChildWindow::GetContextWindow( SfxModule *pModule ) const
765 {
766 	return pModule == pImp->pContextModule && pContext ? pContext->GetWindow(): 0;
767 }
768 
SetWorkWindow_Impl(SfxWorkWindow * pWin)769 void SfxChildWindow::SetWorkWindow_Impl( SfxWorkWindow* pWin )
770 {
771 	pImp->pWorkWin = pWin;
772 	if ( pWin && pWindow->HasChildPathFocus() )
773 		pImp->pWorkWin->SetActiveChild_Impl( pWindow );
774 }
775 
776 //SfxWorkWindow* SfxChildWindow::GetWorkWindow_Impl() const
777 //{
778 //	return pImp->pWorkWin;
779 //}
780 
Activate_Impl()781 void SfxChildWindow::Activate_Impl()
782 {
783 	if(pImp->pWorkWin!=NULL) //@#60568#
784 		pImp->pWorkWin->SetActiveChild_Impl( pWindow );
785 }
786 
Deactivate_Impl()787 void SfxChildWindow::Deactivate_Impl()
788 {
789 //	pImp->pWorkWin->SetActiveChild_Impl( NULL );
790 }
791 
QueryClose()792 sal_Bool SfxChildWindow::QueryClose()
793 {
794     sal_Bool bAllow = sal_True;
795 
796 	if ( pImp->xFrame.is() )
797 	{
798 		::com::sun::star::uno::Reference< ::com::sun::star::frame::XController >  xCtrl = pImp->xFrame->getController();
799 		if ( xCtrl.is() )
800 			bAllow = xCtrl->suspend( sal_True );
801 	}
802 
803 	if ( bAllow )
804 		bAllow = !GetWindow()->IsInModalMode();
805 
806 	return bAllow;
807 }
808 
GetFrame()809 ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >  SfxChildWindow::GetFrame()
810 {
811 	return pImp->xFrame;
812 }
813 
SetFrame(const::com::sun::star::uno::Reference<::com::sun::star::frame::XFrame> & rFrame)814 void SfxChildWindow::SetFrame( const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > & rFrame )
815 {
816     // Do nothing if nothing will be changed ...
817     if( pImp->xFrame != rFrame )
818     {
819         // ... but stop listening on old frame, if connection exist!
820         if( pImp->xFrame.is() )
821             pImp->xFrame->removeEventListener( pImp->xListener );
822 
823         // If new frame isnt NULL -> we must guarantee valid listener for disposing events.
824         // Use already existing or create new one.
825         if( rFrame.is() )
826             if( !pImp->xListener.is() )
827                 pImp->xListener = ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >( new DisposeListener( this, pImp ) );
828 
829         // Set new frame in data container
830         // and build new listener connection, if necessary.
831         pImp->xFrame = rFrame;
832         if( pImp->xFrame.is() )
833             pImp->xFrame->addEventListener( pImp->xListener );
834     }
835 }
836 
CanGetFocus() const837 sal_Bool SfxChildWindow::CanGetFocus() const
838 {
839 	return !(pImp->pFact->aInfo.nFlags & SFX_CHILDWIN_CANTGETFOCUS);
840 }
841 
RegisterChildWindowContext(SfxModule * pMod,sal_uInt16 nId,SfxChildWinContextFactory * pFact)842 void SfxChildWindowContext::RegisterChildWindowContext(SfxModule* pMod, sal_uInt16 nId, SfxChildWinContextFactory* pFact)
843 {
844     SFX_APP()->RegisterChildWindowContext_Impl( pMod, nId, pFact );
845 }
846 
RegisterChildWindow(SfxModule * pMod,SfxChildWinFactory * pFact)847 void SfxChildWindow::RegisterChildWindow(SfxModule* pMod, SfxChildWinFactory* pFact)
848 {
849     SFX_APP()->RegisterChildWindow_Impl( pMod, pFact );
850 }
851 
852