1*31598a22SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*31598a22SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*31598a22SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*31598a22SAndrew Rist * distributed with this work for additional information
6*31598a22SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*31598a22SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*31598a22SAndrew Rist * "License"); you may not use this file except in compliance
9*31598a22SAndrew Rist * with the License. You may obtain a copy of the License at
10*31598a22SAndrew Rist *
11*31598a22SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*31598a22SAndrew Rist *
13*31598a22SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*31598a22SAndrew Rist * software distributed under the License is distributed on an
15*31598a22SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*31598a22SAndrew Rist * KIND, either express or implied. See the License for the
17*31598a22SAndrew Rist * specific language governing permissions and limitations
18*31598a22SAndrew Rist * under the License.
19*31598a22SAndrew Rist *
20*31598a22SAndrew Rist *************************************************************/
21*31598a22SAndrew Rist
22*31598a22SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_basctl.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "docsignature.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #define SI_NOCONTROL
30cdf0e10cSrcweir #define SI_NOSBXCONTROLS
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <ide_pch.hxx>
33cdf0e10cSrcweir #include <basic/sbx.hxx>
34cdf0e10cSrcweir #include "basicrenderable.hxx"
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <com/sun/star/frame/XTitle.hpp>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include <vcl/sound.hxx>
39cdf0e10cSrcweir #include <basidesh.hxx>
40cdf0e10cSrcweir #include <basidesh.hrc>
41cdf0e10cSrcweir #include <baside2.hxx>
42cdf0e10cSrcweir #include <basdoc.hxx>
43cdf0e10cSrcweir #include <basobj.hxx>
44cdf0e10cSrcweir #include <svtools/texteng.hxx>
45cdf0e10cSrcweir #include <svtools/textview.hxx>
46cdf0e10cSrcweir #include <svtools/xtextedt.hxx>
47cdf0e10cSrcweir #include <tools/diagnose_ex.h>
48cdf0e10cSrcweir #include <sfx2/sfxdefs.hxx>
49cdf0e10cSrcweir #include <sfx2/signaturestate.hxx>
50cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
51cdf0e10cSrcweir #include <com/sun/star/container/XNamed.hpp>
52cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
53cdf0e10cSrcweir
54cdf0e10cSrcweir using namespace ::com::sun::star;
55cdf0e10cSrcweir using namespace ::com::sun::star::uno;
56cdf0e10cSrcweir namespace css = ::com::sun::star;
57cdf0e10cSrcweir
IMPL_LINK_INLINE_START(BasicIDEShell,ObjectDialogCancelHdl,ObjectCatalog *,EMPTYARG)58cdf0e10cSrcweir IMPL_LINK_INLINE_START( BasicIDEShell, ObjectDialogCancelHdl, ObjectCatalog *, EMPTYARG )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir ShowObjectDialog( sal_False, sal_True );
61cdf0e10cSrcweir return 0;
62cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(BasicIDEShell,ObjectDialogCancelHdl,ObjectCatalog *,EMPTYARG)63cdf0e10cSrcweir IMPL_LINK_INLINE_END( BasicIDEShell, ObjectDialogCancelHdl, ObjectCatalog *, EMPTYARG )
64cdf0e10cSrcweir
65cdf0e10cSrcweir /*
66cdf0e10cSrcweir IMPL_LINK( BasicIDEShell, ObjectDialogInsertHdl, ObjectCatalog *, pObjCat )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir if ( !pCurWin )
69cdf0e10cSrcweir return 0;
70cdf0e10cSrcweir
71cdf0e10cSrcweir if ( pCurWin->IsA( TYPE( ModulWindow ) ) )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir ModulWindow* pEditWin = (ModulWindow*)pCurWin;
74cdf0e10cSrcweir pEditWin->InsertFromObjectCatalog( pObjCat );
75cdf0e10cSrcweir }
76cdf0e10cSrcweir else
77cdf0e10cSrcweir Sound::Beep();
78cdf0e10cSrcweir
79cdf0e10cSrcweir return 0;
80cdf0e10cSrcweir }
81cdf0e10cSrcweir */
82cdf0e10cSrcweir
83cdf0e10cSrcweir Reference< view::XRenderable > BasicIDEShell::GetRenderable()
84cdf0e10cSrcweir {
85cdf0e10cSrcweir return Reference< view::XRenderable >( new basicide::BasicRenderable( pCurWin ) );
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
88cdf0e10cSrcweir #if 0
89cdf0e10cSrcweir sal_uInt16 __EXPORT BasicIDEShell::Print( SfxProgress &rProgress, sal_Bool bIsAPI, PrintDialog *pPrintDialog )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir if ( pCurWin )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir SfxPrinter* pPrinter = GetPrinter( sal_True );
94cdf0e10cSrcweir if ( pPrinter )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir SfxViewShell::Print( rProgress, bIsAPI, pPrintDialog );
97cdf0e10cSrcweir pCurWin->PrintData( pPrinter );
98cdf0e10cSrcweir }
99cdf0e10cSrcweir }
100cdf0e10cSrcweir return 0;
101cdf0e10cSrcweir }
102cdf0e10cSrcweir #endif
103cdf0e10cSrcweir
HasSelection(sal_Bool) const104cdf0e10cSrcweir sal_Bool BasicIDEShell::HasSelection( sal_Bool /* bText */ ) const
105cdf0e10cSrcweir {
106cdf0e10cSrcweir sal_Bool bSel = sal_False;
107cdf0e10cSrcweir if ( pCurWin && pCurWin->ISA( ModulWindow ) )
108cdf0e10cSrcweir {
109cdf0e10cSrcweir TextView* pEditView = ((ModulWindow*)pCurWin)->GetEditView();
110cdf0e10cSrcweir if ( pEditView && pEditView->HasSelection() )
111cdf0e10cSrcweir bSel = sal_True;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir return bSel;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
GetSelectionText(sal_Bool bWholeWord)116cdf0e10cSrcweir String BasicIDEShell::GetSelectionText( sal_Bool bWholeWord )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir String aText;
119cdf0e10cSrcweir if ( pCurWin && pCurWin->ISA( ModulWindow ) )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir TextView* pEditView = ((ModulWindow*)pCurWin)->GetEditView();
122cdf0e10cSrcweir if ( pEditView )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir if ( bWholeWord && !pEditView->HasSelection() )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir // String aStrCurrentDelimiters = pEngine->GetWordDelimiters();
127cdf0e10cSrcweir // pEngine->SetWordDelimiters( " .,;\"'" );
128cdf0e10cSrcweir aText = pEditView->GetTextEngine()->GetWord( pEditView->GetSelection().GetEnd() );
129cdf0e10cSrcweir // pEngine->SetWordDelimiters( aStrCurrentDelimiters );
130cdf0e10cSrcweir }
131cdf0e10cSrcweir else
132cdf0e10cSrcweir {
133cdf0e10cSrcweir TextSelection aSel = pEditView->GetSelection();
134cdf0e10cSrcweir if ( !bWholeWord || ( aSel.GetStart().GetPara() == aSel.GetEnd().GetPara() ) )
135cdf0e10cSrcweir aText = pEditView->GetSelected();
136cdf0e10cSrcweir }
137cdf0e10cSrcweir }
138cdf0e10cSrcweir }
139cdf0e10cSrcweir return aText;
140cdf0e10cSrcweir }
141cdf0e10cSrcweir
GetPrinter(sal_Bool bCreate)142cdf0e10cSrcweir SfxPrinter* __EXPORT BasicIDEShell::GetPrinter( sal_Bool bCreate )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir if ( pCurWin ) // && pCurWin->ISA( ModulWindow ) )
145cdf0e10cSrcweir {
146cdf0e10cSrcweir BasicDocShell* pDocShell = (BasicDocShell*)GetViewFrame()->GetObjectShell();
147cdf0e10cSrcweir DBG_ASSERT( pDocShell, "DocShell ?!" );
148cdf0e10cSrcweir return pDocShell->GetPrinter( bCreate );
149cdf0e10cSrcweir }
150cdf0e10cSrcweir return 0;
151cdf0e10cSrcweir }
152cdf0e10cSrcweir
SetPrinter(SfxPrinter * pNewPrinter,sal_uInt16 nDiffFlags,bool)153cdf0e10cSrcweir sal_uInt16 __EXPORT BasicIDEShell::SetPrinter( SfxPrinter *pNewPrinter, sal_uInt16 nDiffFlags, bool )
154cdf0e10cSrcweir {
155cdf0e10cSrcweir (void)nDiffFlags;
156cdf0e10cSrcweir BasicDocShell* pDocShell = (BasicDocShell*)GetViewFrame()->GetObjectShell();
157cdf0e10cSrcweir DBG_ASSERT( pDocShell, "DocShell ?!" );
158cdf0e10cSrcweir pDocShell->SetPrinter( pNewPrinter );
159cdf0e10cSrcweir return 0;
160cdf0e10cSrcweir }
161cdf0e10cSrcweir
SetMDITitle()162cdf0e10cSrcweir void BasicIDEShell::SetMDITitle()
163cdf0e10cSrcweir {
164cdf0e10cSrcweir String aTitle;
165cdf0e10cSrcweir
166cdf0e10cSrcweir if ( m_aCurLibName.Len() )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName );
169cdf0e10cSrcweir aTitle = m_aCurDocument.getTitle( eLocation );
170cdf0e10cSrcweir aTitle += '.';
171cdf0e10cSrcweir aTitle += m_aCurLibName;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir else
174cdf0e10cSrcweir {
175cdf0e10cSrcweir aTitle = String( IDEResId( RID_STR_ALL ) );
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
178cdf0e10cSrcweir ::basctl::DocumentSignature aCurSignature( m_aCurDocument );
179cdf0e10cSrcweir if ( aCurSignature.getScriptingSignatureState() == SIGNATURESTATE_SIGNATURES_OK )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir aTitle += String::CreateFromAscii( " " );
182cdf0e10cSrcweir aTitle += String( IDEResId( RID_STR_SIGNED ) );
183cdf0e10cSrcweir aTitle += String::CreateFromAscii( " " );
184cdf0e10cSrcweir }
185cdf0e10cSrcweir
186cdf0e10cSrcweir SfxViewFrame* pViewFrame = GetViewFrame();
187cdf0e10cSrcweir if ( pViewFrame )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir SfxObjectShell* pShell = pViewFrame->GetObjectShell();
190cdf0e10cSrcweir if ( pShell && aTitle != pShell->GetTitle( SFX_TITLE_CAPTION ) )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir pShell->SetTitle( aTitle );
193cdf0e10cSrcweir pShell->SetModified( sal_False );
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
196cdf0e10cSrcweir css::uno::Reference< css::frame::XController > xController = GetController ();
197cdf0e10cSrcweir css::uno::Reference< css::frame::XTitle > xTitle (xController, css::uno::UNO_QUERY);
198cdf0e10cSrcweir if (xTitle.is ())
199cdf0e10cSrcweir xTitle->setTitle (aTitle);
200cdf0e10cSrcweir }
201cdf0e10cSrcweir }
202cdf0e10cSrcweir
DestroyModulWindowLayout()203cdf0e10cSrcweir void BasicIDEShell::DestroyModulWindowLayout()
204cdf0e10cSrcweir {
205cdf0e10cSrcweir delete pModulLayout;
206cdf0e10cSrcweir pModulLayout = 0;
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir
UpdateModulWindowLayout(bool bBasicStopped)210cdf0e10cSrcweir void BasicIDEShell::UpdateModulWindowLayout( bool bBasicStopped )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir if ( pModulLayout )
213cdf0e10cSrcweir {
214cdf0e10cSrcweir pModulLayout->GetStackWindow().UpdateCalls();
215cdf0e10cSrcweir pModulLayout->GetWatchWindow().UpdateWatches( bBasicStopped );
216cdf0e10cSrcweir }
217cdf0e10cSrcweir }
218cdf0e10cSrcweir
CreateModulWindowLayout()219cdf0e10cSrcweir void BasicIDEShell::CreateModulWindowLayout()
220cdf0e10cSrcweir {
221cdf0e10cSrcweir pModulLayout = new ModulWindowLayout( &GetViewFrame()->GetWindow() );
222cdf0e10cSrcweir }
223cdf0e10cSrcweir
CreateBasWin(const ScriptDocument & rDocument,const String & rLibName,const String & rModName)224cdf0e10cSrcweir ModulWindow* BasicIDEShell::CreateBasWin( const ScriptDocument& rDocument, const String& rLibName, const String& rModName )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir bCreatingWindow = sal_True;
227cdf0e10cSrcweir
228cdf0e10cSrcweir sal_uLong nKey = 0;
229cdf0e10cSrcweir ModulWindow* pWin = 0;
230cdf0e10cSrcweir
231cdf0e10cSrcweir String aLibName( rLibName );
232cdf0e10cSrcweir String aModName( rModName );
233cdf0e10cSrcweir
234cdf0e10cSrcweir if ( !aLibName.Len() )
235cdf0e10cSrcweir aLibName = String::CreateFromAscii( "Standard" );
236cdf0e10cSrcweir
237cdf0e10cSrcweir uno::Reference< container::XNameContainer > xLib = rDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
238cdf0e10cSrcweir
239cdf0e10cSrcweir if ( !aModName.Len() )
240cdf0e10cSrcweir aModName = rDocument.createObjectName( E_SCRIPTS, aLibName );
241cdf0e10cSrcweir
242cdf0e10cSrcweir // Vielleicht gibt es ein suspendiertes?
243cdf0e10cSrcweir pWin = FindBasWin( rDocument, aLibName, aModName, sal_False, sal_True );
244cdf0e10cSrcweir
245cdf0e10cSrcweir if ( !pWin )
246cdf0e10cSrcweir {
247cdf0e10cSrcweir ::rtl::OUString aModule;
248cdf0e10cSrcweir bool bSuccess = false;
249cdf0e10cSrcweir if ( rDocument.hasModule( aLibName, aModName ) )
250cdf0e10cSrcweir bSuccess = rDocument.getModule( aLibName, aModName, aModule );
251cdf0e10cSrcweir else
252cdf0e10cSrcweir bSuccess = rDocument.createModule( aLibName, aModName, sal_True, aModule );
253cdf0e10cSrcweir
254cdf0e10cSrcweir if ( bSuccess )
255cdf0e10cSrcweir {
256cdf0e10cSrcweir pWin = FindBasWin( rDocument, aLibName, aModName, sal_False, sal_True );
257cdf0e10cSrcweir if( !pWin )
258cdf0e10cSrcweir {
259cdf0e10cSrcweir // new module window
260cdf0e10cSrcweir pWin = new ModulWindow( pModulLayout, rDocument, aLibName, aModName, aModule );
261cdf0e10cSrcweir nKey = InsertWindowInTable( pWin );
262cdf0e10cSrcweir }
263cdf0e10cSrcweir else // we've gotten called recursively ( via listener from createModule above ), get outta here
264cdf0e10cSrcweir return pWin;
265cdf0e10cSrcweir }
266cdf0e10cSrcweir }
267cdf0e10cSrcweir else
268cdf0e10cSrcweir {
269cdf0e10cSrcweir pWin->SetStatus( pWin->GetStatus() & ~BASWIN_SUSPENDED );
270cdf0e10cSrcweir IDEBaseWindow* pTmp = aIDEWindowTable.First();
271cdf0e10cSrcweir while ( pTmp && !nKey )
272cdf0e10cSrcweir {
273cdf0e10cSrcweir if ( pTmp == pWin )
274cdf0e10cSrcweir nKey = aIDEWindowTable.GetCurKey();
275cdf0e10cSrcweir pTmp = aIDEWindowTable.Next();
276cdf0e10cSrcweir }
277cdf0e10cSrcweir DBG_ASSERT( nKey, "CreateBasWin: Kein Key- Fenster nicht gefunden!" );
278cdf0e10cSrcweir }
279cdf0e10cSrcweir if( nKey && xLib.is() && rDocument.isInVBAMode() )
280cdf0e10cSrcweir {
281cdf0e10cSrcweir // display a nice friendly name in the ObjectModule tab,
282cdf0e10cSrcweir // combining the objectname and module name, e.g. Sheet1 ( Financials )
283cdf0e10cSrcweir String sObjName;
284cdf0e10cSrcweir ModuleInfoHelper::getObjectName( xLib, rModName, sObjName );
285cdf0e10cSrcweir if( sObjName.Len() )
286cdf0e10cSrcweir {
287cdf0e10cSrcweir aModName.AppendAscii(" (").Append(sObjName).AppendAscii(")");
288cdf0e10cSrcweir }
289cdf0e10cSrcweir }
290cdf0e10cSrcweir pTabBar->InsertPage( (sal_uInt16)nKey, aModName );
291cdf0e10cSrcweir pTabBar->Sort();
292cdf0e10cSrcweir pWin->GrabScrollBars( &aHScrollBar, &aVScrollBar );
293cdf0e10cSrcweir if ( !pCurWin )
294cdf0e10cSrcweir SetCurWindow( pWin, sal_False, sal_False );
295cdf0e10cSrcweir
296cdf0e10cSrcweir bCreatingWindow = sal_False;
297cdf0e10cSrcweir return pWin;
298cdf0e10cSrcweir }
299cdf0e10cSrcweir
FindBasWin(const ScriptDocument & rDocument,const String & rLibName,const String & rModName,sal_Bool bCreateIfNotExist,sal_Bool bFindSuspended)300cdf0e10cSrcweir ModulWindow* BasicIDEShell::FindBasWin( const ScriptDocument& rDocument, const String& rLibName, const String& rModName, sal_Bool bCreateIfNotExist, sal_Bool bFindSuspended )
301cdf0e10cSrcweir {
302cdf0e10cSrcweir ModulWindow* pModWin = 0;
303cdf0e10cSrcweir IDEBaseWindow* pWin = aIDEWindowTable.First();
304cdf0e10cSrcweir while ( pWin && !pModWin )
305cdf0e10cSrcweir {
306cdf0e10cSrcweir if ( ( !pWin->IsSuspended() || bFindSuspended ) && pWin->IsA( TYPE( ModulWindow ) ) )
307cdf0e10cSrcweir {
308cdf0e10cSrcweir if ( !rLibName.Len() ) // nur irgendeins finden...
309cdf0e10cSrcweir pModWin = (ModulWindow*)pWin;
310cdf0e10cSrcweir else if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName && pWin->GetName() == rModName )
311cdf0e10cSrcweir pModWin = (ModulWindow*)pWin;
312cdf0e10cSrcweir }
313cdf0e10cSrcweir pWin = aIDEWindowTable.Next();
314cdf0e10cSrcweir }
315cdf0e10cSrcweir if ( !pModWin && bCreateIfNotExist )
316cdf0e10cSrcweir pModWin = CreateBasWin( rDocument, rLibName, rModName );
317cdf0e10cSrcweir
318cdf0e10cSrcweir return pModWin;
319cdf0e10cSrcweir }
320cdf0e10cSrcweir
Move()321cdf0e10cSrcweir void __EXPORT BasicIDEShell::Move()
322cdf0e10cSrcweir {
323cdf0e10cSrcweir if ( pCurWin && pCurWin->ISA( ModulWindow ) )
324cdf0e10cSrcweir ((ModulWindow*)pCurWin)->FrameWindowMoved();
325cdf0e10cSrcweir }
326cdf0e10cSrcweir
ShowCursor(FASTBOOL bOn)327cdf0e10cSrcweir void __EXPORT BasicIDEShell::ShowCursor( FASTBOOL bOn )
328cdf0e10cSrcweir {
329cdf0e10cSrcweir if ( pCurWin && pCurWin->ISA( ModulWindow ) )
330cdf0e10cSrcweir ((ModulWindow*)pCurWin)->ShowCursor( (sal_Bool)bOn );
331cdf0e10cSrcweir }
332cdf0e10cSrcweir
333cdf0e10cSrcweir // Hack for #101048
334cdf0e10cSrcweir sal_Int32 getBasicIDEShellCount( void );
335cdf0e10cSrcweir
336cdf0e10cSrcweir // Nur wenn Basicfenster oben:
ExecuteBasic(SfxRequest & rReq)337cdf0e10cSrcweir void __EXPORT BasicIDEShell::ExecuteBasic( SfxRequest& rReq )
338cdf0e10cSrcweir {
339cdf0e10cSrcweir if ( !pCurWin || !pCurWin->IsA( TYPE( ModulWindow ) ) )
340cdf0e10cSrcweir return;
341cdf0e10cSrcweir
342cdf0e10cSrcweir pCurWin->ExecuteCommand( rReq );
343cdf0e10cSrcweir sal_Int32 nCount = getBasicIDEShellCount();
344cdf0e10cSrcweir if( nCount )
345cdf0e10cSrcweir CheckWindows();
346cdf0e10cSrcweir }
347cdf0e10cSrcweir
348