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_basctl.hxx"
26 
27 #define SI_NOCONTROL
28 #define SI_NOSBXCONTROLS
29 
30 #include <basidesh.hrc>
31 #include <ide_pch.hxx>
32 
33 
34 #define _SOLAR__PRIVATE 1
35 
36 #include <basidesh.hxx>
37 #include <baside2.hxx>
38 #include <baside3.hxx>
39 #include <basobj.hxx>
40 #include <localizationmgr.hxx>
41 #include <dlgedview.hxx>
42 #include <comphelper/processfactory.hxx>
43 #include <com/sun/star/script/XLibraryContainer.hpp>
44 #include <com/sun/star/container/XNameContainer.hpp>
45 #include <xmlscript/xmldlg_imexp.hxx>
46 #include <tools/diagnose_ex.h>
47 
48 using namespace comphelper;
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::uno;
51 using namespace ::com::sun::star::io;
52 
53 
CreateDlgWin(const ScriptDocument & rDocument,const String & rLibName,const String & rDlgName)54 DialogWindow* BasicIDEShell::CreateDlgWin( const ScriptDocument& rDocument, const String& rLibName, const String& rDlgName )
55 {
56 	bCreatingWindow = sal_True;
57 
58 	sal_uLong nKey = 0;
59 	DialogWindow* pWin = 0;
60     String aLibName( rLibName );
61     String aDlgName( rDlgName );
62 
63     if ( !aLibName.Len() )
64         aLibName = String::CreateFromAscii( "Standard" );
65 
66     rDocument.getOrCreateLibrary( E_DIALOGS, aLibName );
67 
68 	if ( !aDlgName.Len() )
69 		aDlgName = rDocument.createObjectName( E_DIALOGS, aLibName );
70 
71 	// Vielleicht gibt es ein suspendiertes?
72 	pWin = FindDlgWin( rDocument, aLibName, aDlgName, sal_False, sal_True );
73 
74 	if ( !pWin )
75 	{
76 		try
77 		{
78 			Reference< io::XInputStreamProvider > xISP;
79 			if ( rDocument.hasDialog( aLibName, aDlgName ) )
80 				rDocument.getDialog( aLibName, aDlgName, xISP );
81             else
82                 rDocument.createDialog( aLibName, aDlgName, xISP );
83 
84 			if ( xISP.is() )
85 			{
86 				// create dialog model
87 				Reference< lang::XMultiServiceFactory > xMSF = getProcessServiceFactory();
88 				Reference< container::XNameContainer > xDialogModel( xMSF->createInstance
89 					( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY );
90 				Reference< XInputStream > xInput( xISP->createInputStream() );
91                 Reference< XComponentContext > xContext;
92                 Reference< beans::XPropertySet > xProps( xMSF, UNO_QUERY );
93                 OSL_ASSERT( xProps.is() );
94                 OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
95 				::xmlscript::importDialogModel( xInput, xDialogModel, xContext );
96 				LocalizationMgr::setStringResourceAtDialog( rDocument, rLibName, aDlgName, xDialogModel );
97 
98 				// new dialog window
99 				pWin = new DialogWindow( &GetViewFrame()->GetWindow(), rDocument, aLibName, aDlgName, xDialogModel );
100 				nKey = InsertWindowInTable( pWin );
101 			}
102 		}
103 		catch ( uno::Exception& )
104 		{
105 			DBG_UNHANDLED_EXCEPTION();
106 		}
107 	}
108 	else
109 	{
110 		pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
111 		IDEBaseWindow* pTmp = aIDEWindowTable.First();
112 		while ( pTmp && !nKey )
113 		{
114 			if ( pTmp == pWin )
115 				nKey = aIDEWindowTable.GetCurKey();
116 			pTmp = aIDEWindowTable.Next();
117 		}
118 		DBG_ASSERT( nKey, "CreateDlgWin: Kein Key - Fenster nicht gefunden!" );
119 	}
120 
121     if( pWin )
122     {
123 	    pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
124 	    pTabBar->InsertPage( (sal_uInt16)nKey, aDlgName );
125 	    pTabBar->Sort();
126 	    if ( !pCurWin )
127 		    SetCurWindow( pWin, sal_False, sal_False );
128     }
129 
130 	bCreatingWindow = sal_False;
131 	return pWin;
132 }
133 
FindDlgWin(const ScriptDocument & rDocument,const String & rLibName,const String & rDlgName,sal_Bool bCreateIfNotExist,sal_Bool bFindSuspended)134 DialogWindow* BasicIDEShell::FindDlgWin( const ScriptDocument& rDocument, const String& rLibName, const String& rDlgName, sal_Bool bCreateIfNotExist, sal_Bool bFindSuspended )
135 {
136 	DialogWindow* pDlgWin = 0;
137 	IDEBaseWindow* pWin = aIDEWindowTable.First();
138 	while ( pWin && !pDlgWin )
139 	{
140 		if ( ( !pWin->IsSuspended() || bFindSuspended ) && pWin->IsA( TYPE( DialogWindow ) ) )
141 		{
142 			if ( !rLibName.Len() )	// nur irgendeins finden...
143 				pDlgWin = (DialogWindow*)pWin;
144             else if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName && pWin->GetName() == rDlgName )
145                 pDlgWin = (DialogWindow*)pWin;
146 		}
147 		pWin = aIDEWindowTable.Next();
148 	}
149 	if ( !pDlgWin && bCreateIfNotExist )
150         pDlgWin = CreateDlgWin( rDocument, rLibName, rDlgName );
151 
152 	return pDlgWin;
153 }
154 
GetCurDlgView() const155 SdrView* BasicIDEShell::GetCurDlgView() const
156 {
157 	if ( !pCurWin || !pCurWin->IsA( TYPE( DialogWindow ) ) )
158 		return NULL;
159 
160 	DialogWindow* pWin = (DialogWindow*)pCurWin;
161 	return pWin->GetView();
162 }
163 
164 // Nur wenn Dialogfenster oben:
ExecuteDialog(SfxRequest & rReq)165 void __EXPORT BasicIDEShell::ExecuteDialog( SfxRequest& rReq )
166 {
167 	if ( pCurWin && ( pCurWin->IsA( TYPE( DialogWindow) ) ||
168 		(rReq.GetSlot() == SID_IMPORT_DIALOG &&pCurWin->IsA( TYPE( ModulWindow) ) ) ) )
169 	{
170 		pCurWin->ExecuteCommand( rReq );
171 	}
172 }
173 
174