merge the formfield patch from ooo-build
[ooovba.git] / basctl / source / basicide / basides3.cxx
blob23f70e00c75284471fe05b8feb1aa136bd3f779f
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 <baside2.hxx>
45 #include <baside3.hxx>
46 #include <basobj.hxx>
47 #include <localizationmgr.hxx>
48 #include <dlgedview.hxx>
49 #include <comphelper/processfactory.hxx>
50 #include <com/sun/star/script/XLibraryContainer.hpp>
51 #include <com/sun/star/container/XNameContainer.hpp>
52 #include <xmlscript/xmldlg_imexp.hxx>
53 #include <tools/diagnose_ex.h>
55 using namespace comphelper;
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::io;
61 DialogWindow* BasicIDEShell::CreateDlgWin( const ScriptDocument& rDocument, const String& rLibName, const String& rDlgName )
63 bCreatingWindow = TRUE;
65 ULONG nKey = 0;
66 DialogWindow* pWin = 0;
67 String aLibName( rLibName );
68 String aDlgName( rDlgName );
70 if ( !aLibName.Len() )
71 aLibName = String::CreateFromAscii( "Standard" );
73 rDocument.getOrCreateLibrary( E_DIALOGS, aLibName );
75 if ( !aDlgName.Len() )
76 aDlgName = rDocument.createObjectName( E_DIALOGS, aLibName );
78 // Vielleicht gibt es ein suspendiertes?
79 pWin = FindDlgWin( rDocument, aLibName, aDlgName, FALSE, TRUE );
81 if ( !pWin )
83 try
85 Reference< io::XInputStreamProvider > xISP;
86 if ( rDocument.hasDialog( aLibName, aDlgName ) )
87 rDocument.getDialog( aLibName, aDlgName, xISP );
88 else
89 rDocument.createDialog( aLibName, aDlgName, xISP );
91 if ( xISP.is() )
93 // create dialog model
94 Reference< lang::XMultiServiceFactory > xMSF = getProcessServiceFactory();
95 Reference< container::XNameContainer > xDialogModel( xMSF->createInstance
96 ( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlDialogModel" ) ) ), UNO_QUERY );
97 Reference< XInputStream > xInput( xISP->createInputStream() );
98 Reference< XComponentContext > xContext;
99 Reference< beans::XPropertySet > xProps( xMSF, UNO_QUERY );
100 OSL_ASSERT( xProps.is() );
101 OSL_VERIFY( xProps->getPropertyValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext")) ) >>= xContext );
102 ::xmlscript::importDialogModel( xInput, xDialogModel, xContext, rDocument.getDocument() );
103 LocalizationMgr::setStringResourceAtDialog( rDocument, rLibName, aDlgName, xDialogModel );
105 // new dialog window
106 pWin = new DialogWindow( &GetViewFrame()->GetWindow(), rDocument, aLibName, aDlgName, xDialogModel );
107 nKey = InsertWindowInTable( pWin );
110 catch ( uno::Exception& )
112 DBG_UNHANDLED_EXCEPTION();
115 else
117 pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
118 IDEBaseWindow* pTmp = aIDEWindowTable.First();
119 while ( pTmp && !nKey )
121 if ( pTmp == pWin )
122 nKey = aIDEWindowTable.GetCurKey();
123 pTmp = aIDEWindowTable.Next();
125 DBG_ASSERT( nKey, "CreateDlgWin: Kein Key - Fenster nicht gefunden!" );
128 if( pWin )
130 pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
131 pTabBar->InsertPage( (USHORT)nKey, aDlgName );
132 pTabBar->Sort();
133 if ( !pCurWin )
134 SetCurWindow( pWin, FALSE, FALSE );
137 bCreatingWindow = FALSE;
138 return pWin;
141 DialogWindow* BasicIDEShell::FindDlgWin( const ScriptDocument& rDocument, const String& rLibName, const String& rDlgName, BOOL bCreateIfNotExist, BOOL bFindSuspended )
143 DialogWindow* pDlgWin = 0;
144 IDEBaseWindow* pWin = aIDEWindowTable.First();
145 while ( pWin && !pDlgWin )
147 if ( ( !pWin->IsSuspended() || bFindSuspended ) && pWin->IsA( TYPE( DialogWindow ) ) )
149 if ( !rLibName.Len() ) // nur irgendeins finden...
150 pDlgWin = (DialogWindow*)pWin;
151 else if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName && pWin->GetName() == rDlgName )
152 pDlgWin = (DialogWindow*)pWin;
154 pWin = aIDEWindowTable.Next();
156 if ( !pDlgWin && bCreateIfNotExist )
157 pDlgWin = CreateDlgWin( rDocument, rLibName, rDlgName );
159 return pDlgWin;
162 SdrView* BasicIDEShell::GetCurDlgView() const
164 if ( !pCurWin || !pCurWin->IsA( TYPE( DialogWindow ) ) )
165 return NULL;
167 DialogWindow* pWin = (DialogWindow*)pCurWin;
168 return pWin->GetView();
171 // Nur wenn Dialogfenster oben:
172 void __EXPORT BasicIDEShell::ExecuteDialog( SfxRequest& rReq )
174 if ( pCurWin && ( pCurWin->IsA( TYPE( DialogWindow) ) ||
175 (rReq.GetSlot() == SID_IMPORT_DIALOG &&pCurWin->IsA( TYPE( ModulWindow) ) ) ) )
177 pCurWin->ExecuteCommand( rReq );