1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: basides2.cxx,v $
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"
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>
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
)
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
);
81 rObjName
= xNamed
->getName();
85 catch( uno::Exception
& )
90 IMPL_LINK_INLINE_START( BasicIDEShell
, ObjectDialogCancelHdl
, ObjectCatalog
*, EMPTYARG
)
92 ShowObjectDialog( FALSE
, TRUE
);
95 IMPL_LINK_INLINE_END( BasicIDEShell
, ObjectDialogCancelHdl
, ObjectCatalog
*, EMPTYARG
)
98 IMPL_LINK( BasicIDEShell, ObjectDialogInsertHdl, ObjectCatalog *, pObjCat )
103 if ( pCurWin->IsA( TYPE( ModulWindow ) ) )
105 ModulWindow* pEditWin = (ModulWindow*)pCurWin;
106 pEditWin->InsertFromObjectCatalog( pObjCat );
115 USHORT __EXPORT
BasicIDEShell::Print( SfxProgress
&rProgress
, BOOL bIsAPI
, PrintDialog
*pPrintDialog
)
119 SfxPrinter
* pPrinter
= GetPrinter( TRUE
);
122 SfxViewShell::Print( rProgress
, bIsAPI
, pPrintDialog
);
123 pCurWin
->PrintData( pPrinter
);
129 BOOL
BasicIDEShell::HasSelection( BOOL
/* bText */ ) const
132 if ( pCurWin
&& pCurWin
->ISA( ModulWindow
) )
134 TextView
* pEditView
= ((ModulWindow
*)pCurWin
)->GetEditView();
135 if ( pEditView
&& pEditView
->HasSelection() )
141 String
BasicIDEShell::GetSelectionText( BOOL bWholeWord
)
144 if ( pCurWin
&& pCurWin
->ISA( ModulWindow
) )
146 TextView
* pEditView
= ((ModulWindow
*)pCurWin
)->GetEditView();
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 );
158 TextSelection aSel
= pEditView
->GetSelection();
159 if ( !bWholeWord
|| ( aSel
.GetStart().GetPara() == aSel
.GetEnd().GetPara() ) )
160 aText
= pEditView
->GetSelected();
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
);
178 USHORT __EXPORT
BasicIDEShell::SetPrinter( SfxPrinter
*pNewPrinter
, USHORT nDiffFlags
, bool )
181 BasicDocShell
* pDocShell
= (BasicDocShell
*)GetViewFrame()->GetObjectShell();
182 DBG_ASSERT( pDocShell
, "DocShell ?!" );
183 pDocShell
->SetPrinter( pNewPrinter
);
187 void BasicIDEShell::SetMDITitle()
191 if ( m_aCurLibName
.Len() )
193 LibraryLocation eLocation
= m_aCurDocument
.getLibraryLocation( m_aCurLibName
);
194 aTitle
= m_aCurDocument
.getTitle( eLocation
);
196 aTitle
+= m_aCurLibName
;
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();
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
);
224 xTitle
->setTitle (aTitle
);
228 void BasicIDEShell::DestroyModulWindowLayout()
235 void BasicIDEShell::UpdateModulWindowLayout( bool bBasicStopped
)
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
;
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
);
272 ::rtl::OUString aModule
;
273 bool bSuccess
= false;
274 if ( rDocument
.hasModule( aLibName
, aModName
) )
275 bSuccess
= rDocument
.getModule( aLibName
, aModName
, aModule
);
277 bSuccess
= rDocument
.createModule( aLibName
, aModName
, TRUE
, aModule
);
281 pWin
= FindBasWin( rDocument
, aLibName
, aModName
, FALSE
, TRUE
);
283 { // new module window
284 pWin
= new ModulWindow( pModulLayout
, rDocument
, aLibName
, aModName
, aModule
);
285 nKey
= InsertWindowInTable( pWin
);
291 pWin
->SetStatus( pWin
->GetStatus() & ~BASWIN_SUSPENDED
);
292 IDEBaseWindow
* pTmp
= aIDEWindowTable
.First();
293 while ( pTmp
&& !nKey
)
296 nKey
= aIDEWindowTable
.GetCurKey();
297 pTmp
= aIDEWindowTable
.Next();
299 DBG_ASSERT( nKey
, "CreateBasWin: Kein Key- Fenster nicht gefunden!" );
305 // display a nice friendly name in the ObjectModule tab,
306 // combining the objectname and module name, e.g. Sheet1 ( Financials )
308 lcl_getObjectName( xLib
, rModName
, sObjName
);
311 aModName
.AppendAscii(" (").Append(sObjName
).AppendAscii(")");
314 pTabBar
->InsertPage( (USHORT
)nKey
, aModName
);
317 pWin
->GrabScrollBars( &aHScrollBar
, &aVScrollBar
);
319 SetCurWindow( pWin
, FALSE
, FALSE
);
321 bCreatingWindow
= FALSE
;
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
);
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
);
359 sal_Int32
getBasicIDEShellCount( void );
361 // Nur wenn Basicfenster oben:
362 void __EXPORT
BasicIDEShell::ExecuteBasic( SfxRequest
& rReq
)
364 if ( !pCurWin
|| !pCurWin
->IsA( TYPE( ModulWindow
) ) )
367 pCurWin
->ExecuteCommand( rReq
);
368 sal_Int32 nCount
= getBasicIDEShellCount();