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