update dev300-m58
[ooovba.git] / basctl / source / basicide / basides3.cxx
blob2d58cc1ea7f9014b910e982400fd1bb6b1e78ad8
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: basides3.cxx,v $
10 * $Revision: 1.18 $
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_basctl.hxx"
34 #define SI_NOCONTROL
35 #define SI_NOSBXCONTROLS
37 #include <basidesh.hrc>
38 #include <ide_pch.hxx>
41 #define _SOLAR__PRIVATE 1
43 #include <basidesh.hxx>
44 #include <baside3.hxx>
45 #include <basobj.hxx>
46 #include <localizationmgr.hxx>
47 #include <dlgedview.hxx>
48 #include <comphelper/processfactory.hxx>
49 #include <com/sun/star/script/XLibraryContainer.hpp>
50 #include <com/sun/star/container/XNameContainer.hpp>
51 #include <xmlscript/xmldlg_imexp.hxx>
52 #include <tools/diagnose_ex.h>
54 using namespace comphelper;
55 using namespace ::com::sun::star;
56 using namespace ::com::sun::star::uno;
57 using namespace ::com::sun::star::io;
60 DialogWindow* BasicIDEShell::CreateDlgWin( const ScriptDocument& rDocument, const String& rLibName, const String& rDlgName )
62 bCreatingWindow = TRUE;
64 ULONG nKey = 0;
65 DialogWindow* pWin = 0;
66 String aLibName( rLibName );
67 String aDlgName( rDlgName );
69 if ( !aLibName.Len() )
70 aLibName = String::CreateFromAscii( "Standard" );
72 rDocument.getOrCreateLibrary( E_DIALOGS, aLibName );
74 if ( !aDlgName.Len() )
75 aDlgName = rDocument.createObjectName( E_DIALOGS, aLibName );
77 // Vielleicht gibt es ein suspendiertes?
78 pWin = FindDlgWin( rDocument, aLibName, aDlgName, FALSE, TRUE );
80 if ( !pWin )
82 try
84 Reference< io::XInputStreamProvider > xISP;
85 if ( rDocument.hasDialog( aLibName, aDlgName ) )
86 rDocument.getDialog( aLibName, aDlgName, xISP );
87 else
88 rDocument.createDialog( aLibName, aDlgName, xISP );
90 if ( xISP.is() )
92 // create dialog model
93 Reference< lang::XMultiServiceFactory > xMSF = getProcessServiceFactory();
94 Reference< container::XNameContainer > xDialogModel( xMSF->createInstance
95 ( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY );
96 Reference< XInputStream > xInput( xISP->createInputStream() );
97 Reference< XComponentContext > xContext;
98 Reference< beans::XPropertySet > xProps( xMSF, UNO_QUERY );
99 OSL_ASSERT( xProps.is() );
100 OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
101 ::xmlscript::importDialogModel( xInput, xDialogModel, xContext, rDocument.getDocument() );
102 LocalizationMgr::setStringResourceAtDialog( rDocument, rLibName, aDlgName, xDialogModel );
104 // new dialog window
105 pWin = new DialogWindow( &GetViewFrame()->GetWindow(), rDocument, aLibName, aDlgName, xDialogModel );
106 nKey = InsertWindowInTable( pWin );
109 catch ( uno::Exception& )
111 DBG_UNHANDLED_EXCEPTION();
114 else
116 pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
117 IDEBaseWindow* pTmp = aIDEWindowTable.First();
118 while ( pTmp && !nKey )
120 if ( pTmp == pWin )
121 nKey = aIDEWindowTable.GetCurKey();
122 pTmp = aIDEWindowTable.Next();
124 DBG_ASSERT( nKey, "CreateDlgWin: Kein Key - Fenster nicht gefunden!" );
127 if( pWin )
129 pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
130 pTabBar->InsertPage( (USHORT)nKey, aDlgName );
131 pTabBar->Sort();
132 if ( !pCurWin )
133 SetCurWindow( pWin, FALSE, FALSE );
136 bCreatingWindow = FALSE;
137 return pWin;
140 DialogWindow* BasicIDEShell::FindDlgWin( const ScriptDocument& rDocument, const String& rLibName, const String& rDlgName, BOOL bCreateIfNotExist, BOOL bFindSuspended )
142 DialogWindow* pDlgWin = 0;
143 IDEBaseWindow* pWin = aIDEWindowTable.First();
144 while ( pWin && !pDlgWin )
146 if ( ( !pWin->IsSuspended() || bFindSuspended ) && pWin->IsA( TYPE( DialogWindow ) ) )
148 if ( !rLibName.Len() ) // nur irgendeins finden...
149 pDlgWin = (DialogWindow*)pWin;
150 else if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName && pWin->GetName() == rDlgName )
151 pDlgWin = (DialogWindow*)pWin;
153 pWin = aIDEWindowTable.Next();
155 if ( !pDlgWin && bCreateIfNotExist )
156 pDlgWin = CreateDlgWin( rDocument, rLibName, rDlgName );
158 return pDlgWin;
161 SdrView* BasicIDEShell::GetCurDlgView() const
163 if ( !pCurWin || !pCurWin->IsA( TYPE( DialogWindow ) ) )
164 return NULL;
166 DialogWindow* pWin = (DialogWindow*)pCurWin;
167 return pWin->GetView();
170 // Nur wenn Dialogfenster oben:
171 void __EXPORT BasicIDEShell::ExecuteDialog( SfxRequest& rReq )
173 if ( !pCurWin || !pCurWin->IsA( TYPE( DialogWindow ) ) )
174 return;
176 pCurWin->ExecuteCommand( rReq );