update dev300-m58
[ooovba.git] / basctl / source / basicide / basides2.cxx
blob21719c15228e277a9208fe5b44746102d281fc26
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: basides2.cxx,v $
10 * $Revision: 1.24 $
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 #include "docsignature.hxx"
36 #define SI_NOCONTROL
37 #define SI_NOSBXCONTROLS
39 #include <ide_pch.hxx>
40 #include <basic/sbx.hxx>
42 #define _SOLAR__PRIVATE 1
44 #include <com/sun/star/frame/XTitle.hpp>
46 #include <vcl/sound.hxx>
47 #include <basidesh.hxx>
48 #include <basidesh.hrc>
49 #include <baside2.hxx>
50 #include <basdoc.hxx>
51 #include <basobj.hxx>
52 #include <svtools/texteng.hxx>
53 #include <svtools/textview.hxx>
54 #include <svtools/xtextedt.hxx>
55 #include <tools/diagnose_ex.h>
56 #include <sfx2/sfxdefs.hxx>
57 #include <sfx2/signaturestate.hxx>
58 #include <com/sun/star/script/ModuleInfo.hpp>
59 #include <com/sun/star/container/XNameContainer.hpp>
60 #include <com/sun/star/container/XNamed.hpp>
61 #include <com/sun/star/lang/XServiceInfo.hpp>
63 using namespace ::com::sun::star;
64 using namespace ::com::sun::star::uno;
65 namespace css = ::com::sun::star;
67 void lcl_getObjectName( const uno::Reference< container::XNameContainer >& rLib, const String& rModName, String& rObjName )
69 try
71 uno::Any aElement( rLib->getByName( rModName ) );
72 script::ModuleInfo aModuleInfo;
73 if( aElement >>= aModuleInfo )
75 uno::Any aObject( aModuleInfo.ModuleObject );
76 uno::Reference< lang::XServiceInfo > xServiceInfo( aObject, uno::UNO_QUERY );
77 if( xServiceInfo.is() && xServiceInfo->supportsService( rtl::OUString::createFromAscii( "ooo.vba.excel.Worksheet" ) ) )
79 uno::Reference< container::XNamed > xNamed( aObject, uno::UNO_QUERY );
80 if( xNamed.is() )
81 rObjName = xNamed->getName();
85 catch( uno::Exception& )
90 IMPL_LINK_INLINE_START( BasicIDEShell, ObjectDialogCancelHdl, ObjectCatalog *, EMPTYARG )
92 ShowObjectDialog( FALSE, TRUE );
93 return 0;
95 IMPL_LINK_INLINE_END( BasicIDEShell, ObjectDialogCancelHdl, ObjectCatalog *, EMPTYARG )
98 IMPL_LINK( BasicIDEShell, ObjectDialogInsertHdl, ObjectCatalog *, pObjCat )
100 if ( !pCurWin )
101 return 0;
103 if ( pCurWin->IsA( TYPE( ModulWindow ) ) )
105 ModulWindow* pEditWin = (ModulWindow*)pCurWin;
106 pEditWin->InsertFromObjectCatalog( pObjCat );
108 else
109 Sound::Beep();
111 return 0;
115 USHORT __EXPORT BasicIDEShell::Print( SfxProgress &rProgress, BOOL bIsAPI, PrintDialog *pPrintDialog )
117 if ( pCurWin )
119 SfxPrinter* pPrinter = GetPrinter( TRUE );
120 if ( pPrinter )
122 SfxViewShell::Print( rProgress, bIsAPI, pPrintDialog );
123 pCurWin->PrintData( pPrinter );
126 return 0;
129 BOOL BasicIDEShell::HasSelection( BOOL /* bText */ ) const
131 BOOL bSel = FALSE;
132 if ( pCurWin && pCurWin->ISA( ModulWindow ) )
134 TextView* pEditView = ((ModulWindow*)pCurWin)->GetEditView();
135 if ( pEditView && pEditView->HasSelection() )
136 bSel = TRUE;
138 return bSel;
141 String BasicIDEShell::GetSelectionText( BOOL bWholeWord )
143 String aText;
144 if ( pCurWin && pCurWin->ISA( ModulWindow ) )
146 TextView* pEditView = ((ModulWindow*)pCurWin)->GetEditView();
147 if ( pEditView )
149 if ( bWholeWord && !pEditView->HasSelection() )
151 // String aStrCurrentDelimiters = pEngine->GetWordDelimiters();
152 // pEngine->SetWordDelimiters( " .,;\"'" );
153 aText = pEditView->GetTextEngine()->GetWord( pEditView->GetSelection().GetEnd() );
154 // pEngine->SetWordDelimiters( aStrCurrentDelimiters );
156 else
158 TextSelection aSel = pEditView->GetSelection();
159 if ( !bWholeWord || ( aSel.GetStart().GetPara() == aSel.GetEnd().GetPara() ) )
160 aText = pEditView->GetSelected();
164 return aText;
167 SfxPrinter* __EXPORT BasicIDEShell::GetPrinter( BOOL bCreate )
169 if ( pCurWin ) // && pCurWin->ISA( ModulWindow ) )
171 BasicDocShell* pDocShell = (BasicDocShell*)GetViewFrame()->GetObjectShell();
172 DBG_ASSERT( pDocShell, "DocShell ?!" );
173 return pDocShell->GetPrinter( bCreate );
175 return 0;
178 USHORT __EXPORT BasicIDEShell::SetPrinter( SfxPrinter *pNewPrinter, USHORT nDiffFlags, bool )
180 (void)nDiffFlags;
181 BasicDocShell* pDocShell = (BasicDocShell*)GetViewFrame()->GetObjectShell();
182 DBG_ASSERT( pDocShell, "DocShell ?!" );
183 pDocShell->SetPrinter( pNewPrinter );
184 return 0;
187 void BasicIDEShell::SetMDITitle()
189 String aTitle;
191 if ( m_aCurLibName.Len() )
193 LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName );
194 aTitle = m_aCurDocument.getTitle( eLocation );
195 aTitle += '.';
196 aTitle += m_aCurLibName;
198 else
200 aTitle = String( IDEResId( RID_STR_ALL ) );
203 ::basctl::DocumentSignature aCurSignature( m_aCurDocument );
204 if ( aCurSignature.getScriptingSignatureState() == SIGNATURESTATE_SIGNATURES_OK )
206 aTitle += String::CreateFromAscii( " " );
207 aTitle += String( IDEResId( RID_STR_SIGNED ) );
208 aTitle += String::CreateFromAscii( " " );
211 SfxViewFrame* pViewFrame = GetViewFrame();
212 if ( pViewFrame )
214 SfxObjectShell* pShell = pViewFrame->GetObjectShell();
215 if ( pShell && aTitle != pShell->GetTitle( SFX_TITLE_CAPTION ) )
217 pShell->SetTitle( aTitle );
218 pShell->SetModified( FALSE );
221 css::uno::Reference< css::frame::XController > xController = GetController ();
222 css::uno::Reference< css::frame::XTitle > xTitle (xController, css::uno::UNO_QUERY);
223 if (xTitle.is ())
224 xTitle->setTitle (aTitle);
228 void BasicIDEShell::DestroyModulWindowLayout()
230 delete pModulLayout;
231 pModulLayout = 0;
235 void BasicIDEShell::UpdateModulWindowLayout( bool bBasicStopped )
237 if ( pModulLayout )
239 pModulLayout->GetStackWindow().UpdateCalls();
240 pModulLayout->GetWatchWindow().UpdateWatches( bBasicStopped );
244 void BasicIDEShell::CreateModulWindowLayout()
246 pModulLayout = new ModulWindowLayout( &GetViewFrame()->GetWindow() );
249 ModulWindow* BasicIDEShell::CreateBasWin( const ScriptDocument& rDocument, const String& rLibName, const String& rModName )
251 bCreatingWindow = TRUE;
253 ULONG nKey = 0;
254 ModulWindow* pWin = 0;
256 String aLibName( rLibName );
257 String aModName( rModName );
259 if ( !aLibName.Len() )
260 aLibName = String::CreateFromAscii( "Standard" );
262 uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
264 if ( !aModName.Len() )
265 aModName = rDocument.createObjectName( E_SCRIPTS, aLibName );
267 // Vielleicht gibt es ein suspendiertes?
268 pWin = FindBasWin( rDocument, aLibName, aModName, FALSE, TRUE );
270 if ( !pWin )
272 ::rtl::OUString aModule;
273 bool bSuccess = false;
274 if ( rDocument.hasModule( aLibName, aModName ) )
275 bSuccess = rDocument.getModule( aLibName, aModName, aModule );
276 else
277 bSuccess = rDocument.createModule( aLibName, aModName, TRUE, aModule );
279 if ( bSuccess )
281 pWin = FindBasWin( rDocument, aLibName, aModName, FALSE, TRUE );
282 if( !pWin )
283 { // new module window
284 pWin = new ModulWindow( pModulLayout, rDocument, aLibName, aModName, aModule );
285 nKey = InsertWindowInTable( pWin );
289 else
291 pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
292 IDEBaseWindow* pTmp = aIDEWindowTable.First();
293 while ( pTmp && !nKey )
295 if ( pTmp == pWin )
296 nKey = aIDEWindowTable.GetCurKey();
297 pTmp = aIDEWindowTable.Next();
299 DBG_ASSERT( nKey, "CreateBasWin: Kein Key- Fenster nicht gefunden!" );
301 if( nKey )
303 if( xLib.is() )
305 // display a nice friendly name in the ObjectModule tab,
306 // combining the objectname and module name, e.g. Sheet1 ( Financials )
307 String sObjName;
308 lcl_getObjectName( xLib, rModName, sObjName );
309 if( sObjName.Len() )
311 aModName.AppendAscii(" (").Append(sObjName).AppendAscii(")");
314 pTabBar->InsertPage( (USHORT)nKey, aModName );
316 pTabBar->Sort();
317 pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
318 if ( !pCurWin )
319 SetCurWindow( pWin, FALSE, FALSE );
321 bCreatingWindow = FALSE;
322 return pWin;
325 ModulWindow* BasicIDEShell::FindBasWin( const ScriptDocument& rDocument, const String& rLibName, const String& rModName, BOOL bCreateIfNotExist, BOOL bFindSuspended )
327 ModulWindow* pModWin = 0;
328 IDEBaseWindow* pWin = aIDEWindowTable.First();
329 while ( pWin && !pModWin )
331 if ( ( !pWin->IsSuspended() || bFindSuspended ) && pWin->IsA( TYPE( ModulWindow ) ) )
333 if ( !rLibName.Len() ) // nur irgendeins finden...
334 pModWin = (ModulWindow*)pWin;
335 else if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName && pWin->GetName() == rModName )
336 pModWin = (ModulWindow*)pWin;
338 pWin = aIDEWindowTable.Next();
340 if ( !pModWin && bCreateIfNotExist )
341 pModWin = CreateBasWin( rDocument, rLibName, rModName );
343 return pModWin;
346 void __EXPORT BasicIDEShell::Move()
348 if ( pCurWin && pCurWin->ISA( ModulWindow ) )
349 ((ModulWindow*)pCurWin)->FrameWindowMoved();
352 void __EXPORT BasicIDEShell::ShowCursor( FASTBOOL bOn )
354 if ( pCurWin && pCurWin->ISA( ModulWindow ) )
355 ((ModulWindow*)pCurWin)->ShowCursor( (BOOL)bOn );
358 // Hack for #101048
359 sal_Int32 getBasicIDEShellCount( void );
361 // Nur wenn Basicfenster oben:
362 void __EXPORT BasicIDEShell::ExecuteBasic( SfxRequest& rReq )
364 if ( !pCurWin || !pCurWin->IsA( TYPE( ModulWindow ) ) )
365 return;
367 pCurWin->ExecuteCommand( rReq );
368 sal_Int32 nCount = getBasicIDEShellCount();
369 if( nCount )
370 CheckWindows();