xref: /trunk/main/basctl/source/basicide/basides3.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basctl.hxx"
30 
31 #define SI_NOCONTROL
32 #define SI_NOSBXCONTROLS
33 
34 #include <basidesh.hrc>
35 #include <ide_pch.hxx>
36 
37 
38 #define _SOLAR__PRIVATE 1
39 
40 #include <basidesh.hxx>
41 #include <baside2.hxx>
42 #include <baside3.hxx>
43 #include <basobj.hxx>
44 #include <localizationmgr.hxx>
45 #include <dlgedview.hxx>
46 #include <comphelper/processfactory.hxx>
47 #include <com/sun/star/script/XLibraryContainer.hpp>
48 #include <com/sun/star/container/XNameContainer.hpp>
49 #include <xmlscript/xmldlg_imexp.hxx>
50 #include <tools/diagnose_ex.h>
51 
52 using namespace comphelper;
53 using namespace ::com::sun::star;
54 using namespace ::com::sun::star::uno;
55 using namespace ::com::sun::star::io;
56 
57 
58 DialogWindow* BasicIDEShell::CreateDlgWin( const ScriptDocument& rDocument, const String& rLibName, const String& rDlgName )
59 {
60 	bCreatingWindow = sal_True;
61 
62 	sal_uLong nKey = 0;
63 	DialogWindow* pWin = 0;
64     String aLibName( rLibName );
65     String aDlgName( rDlgName );
66 
67     if ( !aLibName.Len() )
68         aLibName = String::CreateFromAscii( "Standard" );
69 
70     rDocument.getOrCreateLibrary( E_DIALOGS, aLibName );
71 
72 	if ( !aDlgName.Len() )
73 		aDlgName = rDocument.createObjectName( E_DIALOGS, aLibName );
74 
75 	// Vielleicht gibt es ein suspendiertes?
76 	pWin = FindDlgWin( rDocument, aLibName, aDlgName, sal_False, sal_True );
77 
78 	if ( !pWin )
79 	{
80 		try
81 		{
82 			Reference< io::XInputStreamProvider > xISP;
83 			if ( rDocument.hasDialog( aLibName, aDlgName ) )
84 				rDocument.getDialog( aLibName, aDlgName, xISP );
85             else
86                 rDocument.createDialog( aLibName, aDlgName, xISP );
87 
88 			if ( xISP.is() )
89 			{
90 				// create dialog model
91 				Reference< lang::XMultiServiceFactory > xMSF = getProcessServiceFactory();
92 				Reference< container::XNameContainer > xDialogModel( xMSF->createInstance
93 					( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY );
94 				Reference< XInputStream > xInput( xISP->createInputStream() );
95                 Reference< XComponentContext > xContext;
96                 Reference< beans::XPropertySet > xProps( xMSF, UNO_QUERY );
97                 OSL_ASSERT( xProps.is() );
98                 OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
99 				::xmlscript::importDialogModel( xInput, xDialogModel, xContext );
100 				LocalizationMgr::setStringResourceAtDialog( rDocument, rLibName, aDlgName, xDialogModel );
101 
102 				// new dialog window
103 				pWin = new DialogWindow( &GetViewFrame()->GetWindow(), rDocument, aLibName, aDlgName, xDialogModel );
104 				nKey = InsertWindowInTable( pWin );
105 			}
106 		}
107 		catch ( uno::Exception& )
108 		{
109 			DBG_UNHANDLED_EXCEPTION();
110 		}
111 	}
112 	else
113 	{
114 		pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
115 		IDEBaseWindow* pTmp = aIDEWindowTable.First();
116 		while ( pTmp && !nKey )
117 		{
118 			if ( pTmp == pWin )
119 				nKey = aIDEWindowTable.GetCurKey();
120 			pTmp = aIDEWindowTable.Next();
121 		}
122 		DBG_ASSERT( nKey, "CreateDlgWin: Kein Key - Fenster nicht gefunden!" );
123 	}
124 
125     if( pWin )
126     {
127 	    pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
128 	    pTabBar->InsertPage( (sal_uInt16)nKey, aDlgName );
129 	    pTabBar->Sort();
130 	    if ( !pCurWin )
131 		    SetCurWindow( pWin, sal_False, sal_False );
132     }
133 
134 	bCreatingWindow = sal_False;
135 	return pWin;
136 }
137 
138 DialogWindow* BasicIDEShell::FindDlgWin( const ScriptDocument& rDocument, const String& rLibName, const String& rDlgName, sal_Bool bCreateIfNotExist, sal_Bool bFindSuspended )
139 {
140 	DialogWindow* pDlgWin = 0;
141 	IDEBaseWindow* pWin = aIDEWindowTable.First();
142 	while ( pWin && !pDlgWin )
143 	{
144 		if ( ( !pWin->IsSuspended() || bFindSuspended ) && pWin->IsA( TYPE( DialogWindow ) ) )
145 		{
146 			if ( !rLibName.Len() )	// nur irgendeins finden...
147 				pDlgWin = (DialogWindow*)pWin;
148             else if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName && pWin->GetName() == rDlgName )
149                 pDlgWin = (DialogWindow*)pWin;
150 		}
151 		pWin = aIDEWindowTable.Next();
152 	}
153 	if ( !pDlgWin && bCreateIfNotExist )
154         pDlgWin = CreateDlgWin( rDocument, rLibName, rDlgName );
155 
156 	return pDlgWin;
157 }
158 
159 SdrView* BasicIDEShell::GetCurDlgView() const
160 {
161 	if ( !pCurWin || !pCurWin->IsA( TYPE( DialogWindow ) ) )
162 		return NULL;
163 
164 	DialogWindow* pWin = (DialogWindow*)pCurWin;
165 	return pWin->GetView();
166 }
167 
168 // Nur wenn Dialogfenster oben:
169 void __EXPORT BasicIDEShell::ExecuteDialog( SfxRequest& rReq )
170 {
171 	if ( pCurWin && ( pCurWin->IsA( TYPE( DialogWindow) ) ||
172 		(rReq.GetSlot() == SID_IMPORT_DIALOG &&pCurWin->IsA( TYPE( ModulWindow) ) ) ) )
173 	{
174 		pCurWin->ExecuteCommand( rReq );
175 	}
176 }
177 
178