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 GLOBALOVERFLOW2
30 #include <basic/sbx.hxx>
31 #define _SVSTDARR_STRINGS
32 #include <svl/svstdarr.hxx>
33 #include <ide_pch.hxx>
34 
35 #define _SOLAR__PRIVATE 1
36 
37 // #define _SVX_NOIDERESIDS
38 
39 #define SI_NOCONTROL
40 #define SI_NOSBXCONTROLS
41 #define SI_NOITEMS
42 #define SI_NODRW
43 #define _VCTRLS_HXX
44 
45 #include <basidesh.hrc>
46 #include <basidesh.hxx>
47 #include <baside2.hxx>
48 #include <baside3.hxx>
49 #include <basobj.hxx>
50 #include <iderdll.hxx>
51 #include <iderdll2.hxx>
52 #include <sbxitem.hxx>
53 #include <managelang.hxx>
54 #include <localizationmgr.hxx>
55 #include <helpid.hrc>
56 
57 #include <svtools/texteng.hxx>
58 #include <svtools/textview.hxx>
59 #include <svtools/xtextedt.hxx>
60 #include <tools/urlobj.hxx>
61 #include <tools/diagnose_ex.h>
62 #include <sfx2/minfitem.hxx>
63 #include <sfx2/docfile.hxx>
64 #include <com/sun/star/task/XStatusIndicator.hpp>
65 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
66 #include <com/sun/star/script/XLibraryContainer.hpp>
67 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
68 #include <com/sun/star/frame/XDispatchProvider.hpp>
69 #include <com/sun/star/frame/XLayoutManager.hpp>
70 
71 #include <algorithm>
72 #include <memory>
73 
74 
75 using namespace ::com::sun::star;
76 using namespace ::com::sun::star::uno;
77 using namespace ::com::sun::star::frame;
78 
79 class SvxSearchItem;
80 
81 //	Egal was, einfach ans aktuelle Fenster:
ExecuteCurrent(SfxRequest & rReq)82 void __EXPORT BasicIDEShell::ExecuteCurrent( SfxRequest& rReq )
83 {
84 	if ( !pCurWin )
85 		return;
86 
87 	switch ( rReq.GetSlot() )
88 	{
89 		case SID_BASICIDE_HIDECURPAGE:
90 		{
91 			pCurWin->StoreData();
92 			RemoveWindow( pCurWin, sal_False );
93 		}
94 		break;
95 		case SID_BASICIDE_DELETECURRENT:
96 		{
97             ScriptDocument aDocument( pCurWin->GetDocument() );
98 			String aLibName = pCurWin->GetLibName();
99 			String aName = pCurWin->GetName();
100 
101             if ( pCurWin->ISA( ModulWindow ) )
102 			{
103 				// module
104 				if ( QueryDelModule( aName, pCurWin ) )
105 				{
106                     if ( aDocument.removeModule( aLibName, aName ) )
107                     {
108 						BasicIDE::MarkDocumentModified( aDocument );
109 					}
110 				}
111 			}
112 			else
113 			{
114 				// dialog
115 				if ( QueryDelDialog( aName, pCurWin ) )
116 				{
117                     if ( BasicIDE::RemoveDialog( aDocument, aLibName, aName ) )
118                     {
119 					    RemoveWindow( pCurWin, sal_True );
120 					    BasicIDE::MarkDocumentModified( aDocument );
121                     }
122 				}
123 			}
124 		}
125 		break;
126 		case SID_BASICIDE_RENAMECURRENT:
127 		{
128 			pTabBar->StartEditMode( pTabBar->GetCurPageId() );
129 		}
130 		break;
131 		case FID_SEARCH_NOW:
132 		{
133 			if ( pCurWin->ISA( ModulWindow ) )
134 			{
135 				DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
136 				const SfxItemSet* pArgs = rReq.GetArgs();
137 				// Leider kenne ich die ID nicht:
138 				sal_uInt16 nWhich = pArgs->GetWhichByPos( 0 );
139 				DBG_ASSERT( nWhich, "Wich fuer SearchItem ?" );
140 				const SfxPoolItem& rItem = pArgs->Get( nWhich );
141 				DBG_ASSERT( rItem.ISA( SvxSearchItem ), "Kein Searchitem!" );
142 				if ( rItem.ISA( SvxSearchItem ) )
143 				{
144 					// Item wegen der Einstellungen merken...
145 					IDE_DLL()->GetExtraData()->SetSearchItem( (const SvxSearchItem&)rItem );
146 					sal_uInt16 nFound = 0;
147 					sal_Bool bCanceled = sal_False;
148 					if ( ((const SvxSearchItem&)rItem).GetCommand() == SVX_SEARCHCMD_REPLACE_ALL )
149 					{
150 						sal_uInt16 nActModWindows = 0;
151 						IDEBaseWindow* pWin = aIDEWindowTable.First();
152 						while ( pWin )
153 						{
154 							if ( !pWin->IsSuspended() && pWin->IsA( TYPE( ModulWindow ) ) )
155 								nActModWindows++;
156 							pWin = aIDEWindowTable.Next();
157 						}
158 
159 						if ( ( nActModWindows <= 1 ) || ( !((const SvxSearchItem&)rItem).GetSelection() && QueryBox( pCurWin, WB_YES_NO|WB_DEF_YES, String( IDEResId( RID_STR_SEARCHALLMODULES ) ) ).Execute() == RET_YES ) )
160 						{
161 							pWin = aIDEWindowTable.First();
162 							while ( pWin )
163 							{
164 								if ( !pWin->IsSuspended() && pWin->IsA( TYPE( ModulWindow ) ) )
165 									nFound = nFound + ((ModulWindow*)pWin)->StartSearchAndReplace( (const SvxSearchItem&)rItem );
166 								pWin = aIDEWindowTable.Next();
167 							}
168 						}
169 						else
170 							nFound = ((ModulWindow*)pCurWin)->StartSearchAndReplace( (const SvxSearchItem&)rItem );
171 
172 						IDEResId nId( RID_STR_SEARCHREPLACES );
173 						String aReplStr( nId );
174 						aReplStr.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "XX" ) ), String::CreateFromInt32( nFound ) );
175 						InfoBox( pCurWin, aReplStr ).Execute();
176 					}
177 					else
178 					{
179 						nFound = ((ModulWindow*)pCurWin)->StartSearchAndReplace( (const SvxSearchItem&)rItem );
180 						if ( !nFound && !((const SvxSearchItem&)rItem).GetSelection() )
181 						{
182 							// Andere Module durchsuchen...
183 							sal_Bool bChangeCurWindow = sal_False;
184 							aIDEWindowTable.Seek( pCurWin );
185 							// Erstmal beim naechsten Anfangen, ggf. spaeter von vorne
186 							IDEBaseWindow* pWin = aIDEWindowTable.Next();
187 							sal_Bool bSearchedFromStart = sal_False;
188 							while ( !nFound && !bCanceled && ( pWin || !bSearchedFromStart ) )
189 							{
190 								if ( !pWin )
191 								{
192                                     SfxViewFrame* pViewFrame = GetViewFrame();
193                                     SfxChildWindow* pChildWin = pViewFrame ? pViewFrame->GetChildWindow( SID_SEARCH_DLG ) : NULL;
194                                     Window* pParent = pChildWin ? pChildWin->GetWindow() : NULL;
195 									QueryBox aQuery( pParent, WB_YES_NO|WB_DEF_YES, String( IDEResId( RID_STR_SEARCHFROMSTART ) ) );
196 									if ( aQuery.Execute() == RET_YES )
197 									{
198 										pWin = aIDEWindowTable.First();
199 										bSearchedFromStart = sal_True;
200 									}
201 									else
202 										bCanceled = sal_True;
203 								}
204 
205 								if ( pWin && !pWin->IsSuspended() && pWin->IsA( TYPE( ModulWindow ) ) )
206 								{
207 									if ( pWin != pCurWin )
208 									{
209 										// Groesse einstellen, damit die View
210 										// gleich richtig justiert werden kann.
211 										if ( pCurWin )
212 											pWin->SetSizePixel( pCurWin->GetSizePixel() );
213 										nFound = ((ModulWindow*)pWin)->StartSearchAndReplace( (const SvxSearchItem&)rItem, sal_True );
214 									}
215 									if ( nFound )
216 									{
217 										bChangeCurWindow = sal_True;
218 										break;
219 									}
220 								}
221 								if ( pWin && ( pWin != pCurWin ) )
222 									pWin = aIDEWindowTable.Next();
223 								else
224 									pWin = 0;	// Dann sind wir durch...
225 							}
226 							if ( !nFound && bSearchedFromStart ) 	// Aktuelles von vorne...
227 								nFound = ((ModulWindow*)pCurWin)->StartSearchAndReplace( (const SvxSearchItem&)rItem, sal_True );
228 							if ( bChangeCurWindow )
229 								SetCurWindow( pWin, sal_True );
230 						}
231 						if ( !nFound && !bCanceled )
232 							InfoBox( pCurWin, String( IDEResId( RID_STR_SEARCHNOTFOUND ) ) ).Execute();
233 					}
234 
235 					rReq.Done();
236 				}
237 			}
238 		}
239 		break;
240         case FID_SEARCH_OFF:
241         {
242             if ( pCurWin && pCurWin->ISA( ModulWindow ) )
243                 pCurWin->GrabFocus();
244         }
245         break;
246 		case SID_UNDO:
247 		case SID_REDO:
248 		{
249 			if ( GetUndoManager() && pCurWin->AllowUndo() )
250 			{
251 				GetViewFrame()->ExecuteSlot( rReq );
252 			}
253 		}
254 		break;
255 		default:
256 		{
257 			pCurWin->ExecuteCommand( rReq );
258 		}
259 	}
260 }
261 
262 //	Egal, wer oben, Einfluss auf die Shell:
ExecuteGlobal(SfxRequest & rReq)263 void __EXPORT BasicIDEShell::ExecuteGlobal( SfxRequest& rReq )
264 {
265 	sal_uInt16 nSlot = rReq.GetSlot();
266 	switch ( nSlot )
267 	{
268 		case SID_BASICSTOP:
269 		{
270 			// Evtl. nicht einfach anhalten, falls auf Brechpunkt!
271 			if ( pCurWin && pCurWin->IsA( TYPE( ModulWindow ) ) )
272 				((ModulWindow*)pCurWin)->BasicStop();
273 			BasicIDE::StopBasic();
274 		}
275 		break;
276 
277 		case SID_SAVEDOC:
278 		{
279 			if ( pCurWin )
280 			{
281 				// Daten ins BASIC zurueckschreiben
282 				StoreAllWindowData();
283 
284                 // document basic
285                 ScriptDocument aDocument( pCurWin->GetDocument() );
286                 if ( aDocument.isDocument() )
287                 {
288                     uno::Reference< task::XStatusIndicator > xStatusIndicator;
289 
290                     SFX_REQUEST_ARG( rReq, pStatusIndicatorItem, SfxUnoAnyItem, SID_PROGRESS_STATUSBAR_CONTROL, sal_False );
291                     if ( pStatusIndicatorItem )
292                         OSL_VERIFY( pStatusIndicatorItem->GetValue() >>= xStatusIndicator );
293                     else
294                     {
295                         // get statusindicator
296                         SfxViewFrame *pFrame_ = GetFrame();
297                         if ( pFrame_ )
298                         {
299                             uno::Reference< task::XStatusIndicatorFactory > xStatFactory(
300                                                                         pFrame_->GetFrame().GetFrameInterface(),
301                                                                         uno::UNO_QUERY );
302                             if( xStatFactory.is() )
303                                 xStatusIndicator = xStatFactory->createStatusIndicator();
304                         }
305 
306                         if ( xStatusIndicator.is() )
307                             rReq.AppendItem( SfxUnoAnyItem( SID_PROGRESS_STATUSBAR_CONTROL, uno::makeAny( xStatusIndicator ) ) );
308                     }
309 
310                     aDocument.saveDocument( xStatusIndicator );
311                 }
312 
313                 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
314                 if ( pBindings )
315                 {
316                     pBindings->Invalidate( SID_DOC_MODIFIED );
317                     pBindings->Invalidate( SID_SAVEDOC );
318                     pBindings->Invalidate( SID_SIGNATURE );
319                 }
320 			}
321 		}
322 		break;
323         case SID_SIGNATURE:
324         {
325             if ( pCurWin )
326             {
327                 ::basctl::DocumentSignature aSignature( pCurWin->GetDocument() );
328                 if ( aSignature.supportsSignatures() )
329                 {
330                     aSignature.signScriptingContent();
331                     SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
332                     if ( pBindings )
333                         pBindings->Invalidate( SID_SIGNATURE );
334                 }
335             }
336         }
337         break;
338 
339 		case SID_BASICIDE_MODULEDLG:
340 		{
341             if ( rReq.GetArgs() )
342             {
343                 const SfxUInt16Item &rTabId = (const SfxUInt16Item&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
344                 BasicIDE::Organize( rTabId.GetValue() );
345             }
346             else
347                 BasicIDE::Organize( 0 );
348 		}
349 		break;
350 		case SID_BASICIDE_CHOOSEMACRO:
351 		{
352             BasicIDE::ChooseMacro( NULL, sal_False, ::rtl::OUString() );
353 		}
354 		break;
355 		case SID_BASICIDE_CREATEMACRO:
356 		case SID_BASICIDE_EDITMACRO:
357 		{
358 			DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
359 			const SfxMacroInfoItem& rInfo = (const SfxMacroInfoItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
360 			BasicManager* pBasMgr = (BasicManager*)rInfo.GetBasicManager();
361 			DBG_ASSERT( pBasMgr, "Nichts selektiert im Basic-Baum ?" );
362 
363             ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
364 
365             StartListening( *pBasMgr, sal_True /* Nur einmal anmelden */ );
366             String aLibName( rInfo.GetLib() );
367             if ( !aLibName.Len() )
368                 aLibName = String::CreateFromAscii( "Standard" );
369             StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
370 			if ( !pBasic )
371 			{
372                 // load module and dialog library (if not loaded)
373                 aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
374                 aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
375 
376                 // get Basic
377                 pBasic = pBasMgr->GetLib( aLibName );
378             }
379 			DBG_ASSERT( pBasic, "Kein Basic!" );
380 
381             SetCurLib( aDocument, aLibName );
382 
383 			if ( rReq.GetSlot() == SID_BASICIDE_CREATEMACRO )
384 			{
385 				SbModule* pModule = pBasic->FindModule( rInfo.GetModule() );
386 				if ( !pModule )
387 				{
388 					if ( rInfo.GetModule().Len() || !pBasic->GetModules()->Count() )
389                     {
390                         String aModName = rInfo.GetModule();
391 
392                         ::rtl::OUString sModuleCode;
393                         if ( aDocument.createModule( aLibName, aModName, sal_False, sModuleCode ) )
394             	            pModule = pBasic->FindModule( aModName );
395                     }
396 					else
397 						pModule = (SbModule*) pBasic->GetModules()->Get(0);
398 				}
399 				DBG_ASSERT( pModule, "Kein Modul!" );
400 				if ( !pModule->GetMethods()->Find( rInfo.GetMethod(), SbxCLASS_METHOD ) )
401 					BasicIDE::CreateMacro( pModule, rInfo.GetMethod() );
402 			}
403             SfxViewFrame* pViewFrame = GetViewFrame();
404             if ( pViewFrame )
405                 pViewFrame->ToTop();
406             ModulWindow* pWin = FindBasWin( aDocument, aLibName, rInfo.GetModule(), sal_True );
407 			DBG_ASSERT( pWin, "Edit/Create Macro: Fenster wurde nicht erzeugt/gefunden!" );
408 			SetCurWindow( pWin, sal_True );
409 			pWin->EditMacro( rInfo.GetMethod() );
410 		}
411 		break;
412 		case SID_BASICIDE_OBJCAT:
413 		{
414 			ShowObjectDialog( sal_True, sal_True );
415 		}
416 		break;
417 		case SID_BASICIDE_NAMECHANGEDONTAB:
418 		{
419 			DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
420 			const SfxUInt16Item &rTabId = (const SfxUInt16Item&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
421 			const SfxStringItem &rModName = (const SfxStringItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_MODULENAME );
422 			IDEBaseWindow* pWin = aIDEWindowTable.Get( rTabId.GetValue() );
423 			DBG_ASSERT( pWin, "Window nicht im Liste, aber in TabBar ?" );
424             if ( pWin )
425             {
426                 String aNewName( rModName.GetValue() );
427                 String aOldName( pWin->GetName() );
428                 if ( aNewName != aOldName )
429                 {
430                     bool bRenameOk = false;
431                     if ( pWin->IsA( TYPE( ModulWindow ) ) )
432                     {
433                         ModulWindow* pModWin = (ModulWindow*)pWin;
434                         String aLibName = ( pModWin->GetLibName() );
435                         ScriptDocument aDocument( pWin->GetDocument() );
436 
437                         if ( BasicIDE::RenameModule( pModWin, aDocument, aLibName,  aOldName, aNewName ) )
438                         {
439                             bRenameOk = true;
440                             // Because we listen for container events for script
441                             // modules, rename will delete the 'old' window
442                             // pWin has been invalidated, restore now
443                             pWin = FindBasWin( aDocument, aLibName, aNewName, sal_True );
444                         }
445 
446                     }
447                     else if ( pWin->IsA( TYPE( DialogWindow ) ) )
448                     {
449                         DialogWindow* pDlgWin = (DialogWindow*)pWin;
450                         bRenameOk = pDlgWin->RenameDialog( aNewName );
451                     }
452                     if ( bRenameOk )
453                     {
454                         BasicIDE::MarkDocumentModified( pWin->GetDocument() );
455                     }
456                     else
457                     {
458 					    // set old name in TabWriter
459 					    sal_uInt16 nId = (sal_uInt16)aIDEWindowTable.GetKey( pWin );
460 					    DBG_ASSERT( nId, "No entry in Tabbar!" );
461 					    if ( nId )
462 						    pTabBar->SetPageText( nId, aOldName );
463                     }
464                 }
465 
466 			    // set focus to current window
467 			    pWin->GrabFocus();
468             }
469 		}
470 		break;
471 		case SID_BASICIDE_STOREMODULESOURCE:
472 		case SID_BASICIDE_UPDATEMODULESOURCE:
473 		{
474 			DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
475 			const SfxMacroInfoItem& rInfo = (const SfxMacroInfoItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
476 			BasicManager* pBasMgr = (BasicManager*)rInfo.GetBasicManager();
477 			DBG_ASSERT( pBasMgr, "Store source: Kein BasMgr?" );
478             ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
479 			ModulWindow* pWin = FindBasWin( aDocument, rInfo.GetLib(), rInfo.GetModule(), sal_False, sal_True );
480 			if ( pWin )
481 			{
482 				if ( rReq.GetSlot() == SID_BASICIDE_STOREMODULESOURCE )
483 					pWin->StoreData();
484 				else
485 					pWin->UpdateData();
486 			}
487 		}
488 		break;
489 		case SID_BASICIDE_STOREALLMODULESOURCES:
490 		case SID_BASICIDE_UPDATEALLMODULESOURCES:
491 		{
492 			IDEBaseWindow* pWin = aIDEWindowTable.First();
493 			while ( pWin )
494 			{
495 				if ( !pWin->IsSuspended() && pWin->IsA( TYPE( ModulWindow ) ) )
496 				{
497 					if ( rReq.GetSlot() == SID_BASICIDE_STOREALLMODULESOURCES )
498 						pWin->StoreData();
499 					else
500 						pWin->UpdateData();
501 				}
502 				pWin = aIDEWindowTable.Next();
503 			}
504 		}
505 		break;
506 		case SID_BASICIDE_LIBSELECTED:
507 		case SID_BASICIDE_LIBREMOVED:
508 		case SID_BASICIDE_LIBLOADED:
509 		{
510             DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
511             const SfxUsrAnyItem& rShellItem = (const SfxUsrAnyItem&)rReq.GetArgs()->Get( SID_BASICIDE_ARG_DOCUMENT_MODEL );
512             uno::Reference< frame::XModel > xModel( rShellItem.GetValue(), UNO_QUERY );
513             ScriptDocument aDocument( xModel.is() ? ScriptDocument( xModel ) : ScriptDocument::getApplicationScriptDocument() );
514             const SfxStringItem& rLibNameItem = (const SfxStringItem&)rReq.GetArgs()->Get( SID_BASICIDE_ARG_LIBNAME );
515 			String aLibName( rLibNameItem.GetValue() );
516 
517 			if ( nSlot == SID_BASICIDE_LIBSELECTED )
518 			{
519                 // load module and dialog library (if not loaded)
520                 aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
521                 aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
522 
523                 // check password, if library is password protected and not verified
524 				sal_Bool bOK = sal_True;
525                 Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ) );
526                 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
527                 {
528                     Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
529                     if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
530                     {
531                         String aPassword;
532 				        bOK = QueryPassword( xModLibContainer, aLibName, aPassword );
533                     }
534                 }
535 
536                 if ( bOK )
537                 {
538                     SetCurLib( aDocument, aLibName, true, false );
539                 }
540 				else
541                 {
542                     // alten Wert einstellen...
543                     SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
544                     if ( pBindings )
545                         pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR, sal_True, sal_False );
546                 }
547 			}
548 			else if ( nSlot == SID_BASICIDE_LIBREMOVED )
549 			{
550                 if ( !m_aCurLibName.Len() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
551 				{
552 					RemoveWindows( aDocument, aLibName, sal_True );
553                     if ( aDocument == m_aCurDocument && aLibName == m_aCurLibName )
554 					{
555                         m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
556                         m_aCurLibName = String();
557 						// Kein UpdateWindows!
558                         SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
559                         if ( pBindings )
560                             pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
561 					}
562 				}
563 			}
564 			else	// Loaded...
565 				UpdateWindows();
566 		}
567 		break;
568 		case SID_BASICIDE_NEWMODULE:
569 		{
570             ModulWindow* pWin = CreateBasWin( m_aCurDocument, m_aCurLibName, String() );
571 			DBG_ASSERT( pWin, "New Module: Konnte Fenster nicht erzeugen!" );
572 			SetCurWindow( pWin, sal_True );
573 		}
574 		break;
575 		case SID_BASICIDE_NEWDIALOG:
576 		{
577 			DialogWindow* pWin = CreateDlgWin( m_aCurDocument, m_aCurLibName, String() );
578 			DBG_ASSERT( pWin, "New Module: Konnte Fenster nicht erzeugen!" );
579 			SetCurWindow( pWin, sal_True );
580 		}
581 		break;
582 		case SID_BASICIDE_SBXRENAMED:
583 		{
584 			DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
585 		}
586 		break;
587 		case SID_BASICIDE_SBXINSERTED:
588 		{
589 			DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
590 			const SbxItem& rSbxItem = (const SbxItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
591             ScriptDocument aDocument( rSbxItem.GetDocument() );
592             String aLibName( rSbxItem.GetLibName() );
593             String aName( rSbxItem.GetName() );
594             if ( !m_aCurLibName.Len() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
595 			{
596 				IDEBaseWindow* pWin = 0;
597 				if ( rSbxItem.GetType() == BASICIDE_TYPE_MODULE )
598 					pWin = FindBasWin( aDocument, aLibName, aName, sal_True );
599 				else if ( rSbxItem.GetType() == BASICIDE_TYPE_DIALOG )
600 					pWin = FindDlgWin( aDocument, aLibName, aName, sal_True );
601 			}
602 		}
603 		break;
604 		case SID_BASICIDE_SBXDELETED:
605 		{
606 			DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
607 			const SbxItem& rSbxItem = (const SbxItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
608             ScriptDocument aDocument( rSbxItem.GetDocument() );
609 			IDEBaseWindow* pWin = FindWindow( aDocument, rSbxItem.GetLibName(), rSbxItem.GetName(), rSbxItem.GetType(), sal_True );
610 			if ( pWin )
611 				RemoveWindow( pWin, sal_True );
612 		}
613 		break;
614 		case SID_BASICIDE_SHOWSBX:
615 		{
616 			DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
617 			const SbxItem& rSbxItem = (const SbxItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
618             ScriptDocument aDocument( rSbxItem.GetDocument() );
619             String aLibName( rSbxItem.GetLibName() );
620             String aName( rSbxItem.GetName() );
621             SetCurLib( aDocument, aLibName );
622 			IDEBaseWindow* pWin = 0;
623 			if ( rSbxItem.GetType() == BASICIDE_TYPE_DIALOG )
624 			{
625 				pWin = FindDlgWin( aDocument, aLibName, aName, sal_True );
626 			}
627 			else if ( rSbxItem.GetType() == BASICIDE_TYPE_MODULE )
628 			{
629 				pWin = FindBasWin( aDocument, aLibName, aName, sal_True );
630 			}
631 			else if ( rSbxItem.GetType() == BASICIDE_TYPE_METHOD )
632 			{
633 				pWin = FindBasWin( aDocument, aLibName, aName, sal_True );
634 				((ModulWindow*)pWin)->EditMacro( rSbxItem.GetMethodName() );
635 			}
636 			DBG_ASSERT( pWin, "Fenster wurde nicht erzeugt!" );
637 			SetCurWindow( pWin, sal_True );
638 			pTabBar->MakeVisible( pTabBar->GetCurPageId() );
639 		}
640 		break;
641         case SID_SHOW_PROPERTYBROWSER:
642         {
643             GetViewFrame()->ChildWindowExecute( rReq );
644             rReq.Done();
645         }
646         break;
647         case SID_BASICIDE_SHOWWINDOW:
648         {
649             ::std::auto_ptr< ScriptDocument > pDocument;
650 
651             SFX_REQUEST_ARG( rReq, pDocumentItem, SfxStringItem, SID_BASICIDE_ARG_DOCUMENT, sal_False );
652 			if ( pDocumentItem )
653             {
654                 String sDocumentCaption = pDocumentItem->GetValue();
655                 if ( sDocumentCaption.Len() )
656                     pDocument.reset( new ScriptDocument( ScriptDocument::getDocumentWithURLOrCaption( sDocumentCaption ) ) );
657             }
658 
659             SFX_REQUEST_ARG( rReq, pDocModelItem, SfxUsrAnyItem, SID_BASICIDE_ARG_DOCUMENT_MODEL, sal_False );
660 			if ( !pDocument.get() && pDocModelItem )
661             {
662                 uno::Reference< frame::XModel > xModel( pDocModelItem->GetValue(), UNO_QUERY );
663                 if ( xModel.is() )
664                     pDocument.reset( new ScriptDocument( xModel ) );
665             }
666 
667             if ( !pDocument.get() )
668                 break;
669 
670             SFX_REQUEST_ARG( rReq, pLibNameItem, SfxStringItem, SID_BASICIDE_ARG_LIBNAME, sal_False );
671 			if ( !pLibNameItem )
672                 break;
673 
674             String aLibName( pLibNameItem->GetValue() );
675             pDocument->loadLibraryIfExists( E_SCRIPTS, aLibName );
676             SetCurLib( *pDocument, aLibName );
677             SFX_REQUEST_ARG( rReq, pNameItem, SfxStringItem, SID_BASICIDE_ARG_NAME, sal_False );
678             if ( pNameItem )
679             {
680                 String aName( pNameItem->GetValue() );
681                 String aModType( String::CreateFromAscii( "Module" ) );
682                 String aDlgType( String::CreateFromAscii( "Dialog" ) );
683                 String aType( aModType );
684                 SFX_REQUEST_ARG( rReq, pTypeItem, SfxStringItem, SID_BASICIDE_ARG_TYPE, sal_False );
685                 if ( pTypeItem )
686                     aType = pTypeItem->GetValue();
687 
688                 IDEBaseWindow* pWin = 0;
689                 if ( aType == aModType )
690                     pWin = FindBasWin( *pDocument, aLibName, aName, sal_False );
691                 else if ( aType == aDlgType )
692                     pWin = FindDlgWin( *pDocument, aLibName, aName, sal_False );
693 
694                 if ( pWin )
695                 {
696                     SetCurWindow( pWin, sal_True );
697 			        if ( pTabBar )
698                         pTabBar->MakeVisible( pTabBar->GetCurPageId() );
699 
700                     if ( pWin->ISA( ModulWindow ) )
701                     {
702                         ModulWindow* pModWin = (ModulWindow*)pWin;
703                         SFX_REQUEST_ARG( rReq, pLineItem, SfxUInt32Item, SID_BASICIDE_ARG_LINE, sal_False );
704 			            if ( pLineItem )
705                         {
706 			                pModWin->AssertValidEditEngine();
707 			                TextView* pTextView = pModWin->GetEditView();
708                             if ( pTextView )
709                             {
710                                 TextEngine* pTextEngine = pTextView->GetTextEngine();
711                                 if ( pTextEngine )
712                                 {
713 				                    sal_uInt32 nLine = pLineItem->GetValue();
714                                     sal_uInt32 nLineCount = 0;
715                                     for ( sal_uInt32 i = 0, nCount = pTextEngine->GetParagraphCount(); i < nCount; ++i )
716                                         nLineCount += pTextEngine->GetLineCount( i );
717                                     if ( nLine > nLineCount )
718                                         nLine = nLineCount;
719                                     if ( nLine > 0 )
720                                         --nLine;
721 
722                                     // scroll window and set selection
723 			                        long nVisHeight = pModWin->GetOutputSizePixel().Height();
724                                     long nTextHeight = pTextEngine->GetTextHeight();
725 			                        if ( nTextHeight > nVisHeight )
726 			                        {
727 				                        long nMaxY = nTextHeight - nVisHeight;
728 				                        long nOldY = pTextView->GetStartDocPos().Y();
729                                         long nNewY = nLine * pTextEngine->GetCharHeight() - nVisHeight / 2;
730                                         nNewY = ::std::min( nNewY, nMaxY );
731 				                        pTextView->Scroll( 0, -( nNewY - nOldY ) );
732 				                        pTextView->ShowCursor( sal_False, sal_True );
733 				                        pModWin->GetEditVScrollBar().SetThumbPos( pTextView->GetStartDocPos().Y() );
734 			                        }
735                                     sal_uInt16 nCol1 = 0, nCol2 = 0;
736                                     SFX_REQUEST_ARG( rReq, pCol1Item, SfxUInt16Item, SID_BASICIDE_ARG_COLUMN1, sal_False );
737 			                        if ( pCol1Item )
738                                     {
739                                         nCol1 = pCol1Item->GetValue();
740                                         if ( nCol1 > 0 )
741                                             --nCol1;
742                                         nCol2 = nCol1;
743                                     }
744                                     SFX_REQUEST_ARG( rReq, pCol2Item, SfxUInt16Item, SID_BASICIDE_ARG_COLUMN2, sal_False );
745 			                        if ( pCol2Item )
746                                     {
747                                         nCol2 = pCol2Item->GetValue();
748                                         if ( nCol2 > 0 )
749                                             --nCol2;
750                                     }
751 			                        TextSelection aSel( TextPaM( nLine, nCol1 ), TextPaM( nLine, nCol2 ) );
752                                     pTextView->SetSelection( aSel );
753 			                        pTextView->ShowCursor();
754 			                        Window* pWindow_ = pTextView->GetWindow();
755                                     if ( pWindow_ )
756                                         pWindow_->GrabFocus();
757                                 }
758                             }
759                         }
760                     }
761                 }
762             }
763             rReq.Done();
764         }
765         break;
766 
767         case SID_BASICIDE_MANAGE_LANG:
768         {
769 			ManageLanguageDialog aDlg( GetCurWindow(), GetCurLocalizationMgr() );
770 			aDlg.Execute();
771             rReq.Done();
772         }
773         break;
774 	}
775 }
776 
GetState(SfxItemSet & rSet)777 void __EXPORT BasicIDEShell::GetState(SfxItemSet &rSet)
778 {
779 	SfxWhichIter aIter(rSet);
780 	for ( sal_uInt16 nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich() )
781 	{
782 		switch ( nWh )
783 		{
784 			case SID_DOCINFO:
785 			{
786 				rSet.DisableItem( nWh );
787 			}
788 			break;
789 			case SID_SAVEDOC:
790 			{
791                 sal_Bool bDisable = sal_False;
792 
793                 if ( pCurWin )
794                 {
795                     if ( !pCurWin->IsModified() )
796                     {
797                         ScriptDocument aDocument( pCurWin->GetDocument() );
798                         bDisable =  ( !aDocument.isAlive() )
799                                 ||  ( aDocument.isDocument() ? !aDocument.isDocumentModified() : !IsAppBasicModified() );
800                     }
801                 }
802                 else
803                 {
804     	            bDisable = sal_True;
805                 }
806 
807                 if ( bDisable )
808     	            rSet.DisableItem( nWh );
809             }
810 			break;
811 			case SID_NEWWINDOW:
812 			case SID_SAVEASDOC:
813 			{
814 				rSet.DisableItem( nWh );
815 			}
816 			break;
817 			case SID_SIGNATURE:
818 			{
819                 sal_uInt16 nState = 0;
820                 if ( pCurWin )
821                 {
822                     ::basctl::DocumentSignature aSignature( pCurWin->GetDocument() );
823                     nState = aSignature.getScriptingSignatureState();
824                 }
825 				rSet.Put( SfxUInt16Item( SID_SIGNATURE, nState ) );
826             }
827             break;
828 			case SID_BASICIDE_MODULEDLG:
829 			{
830 				if ( StarBASIC::IsRunning() )
831 					rSet.DisableItem( nWh );
832 			}
833 			break;
834 			case SID_BASICIDE_CHOOSEMACRO:
835 			case SID_BASICIDE_OBJCAT:
836 			case SID_BASICIDE_SHOWSBX:
837 			case SID_BASICIDE_CREATEMACRO:
838 			case SID_BASICIDE_EDITMACRO:
839 			case SID_BASICIDE_NAMECHANGEDONTAB:
840 			{
841 				;
842 			}
843 			break;
844 
845 			case SID_BASICIDE_ADDWATCH:
846 			case SID_BASICIDE_REMOVEWATCH:
847 			case SID_BASICLOAD:
848 			case SID_BASICSAVEAS:
849 			case SID_BASICIDE_MATCHGROUP:
850 			{
851 				if ( !pCurWin || !pCurWin->IsA( TYPE( ModulWindow ) ) )
852 					rSet.DisableItem( nWh );
853 				else if ( ( nWh == SID_BASICLOAD ) && ( StarBASIC::IsRunning() || ( pCurWin && pCurWin->IsReadOnly() ) ) )
854 					rSet.DisableItem( nWh );
855 			}
856 			break;
857 			case SID_BASICRUN:
858 			case SID_BASICSTEPINTO:
859 			case SID_BASICSTEPOVER:
860 			case SID_BASICSTEPOUT:
861 			case SID_BASICIDE_TOGGLEBRKPNT:
862 			case SID_BASICIDE_MANAGEBRKPNTS:
863 			{
864 				if ( !pCurWin || !pCurWin->IsA( TYPE( ModulWindow ) ) )
865 					rSet.DisableItem( nWh );
866 				else if ( StarBASIC::IsRunning() && !((ModulWindow*)pCurWin)->GetBasicStatus().bIsInReschedule )
867 					rSet.DisableItem( nWh );
868 			}
869 			break;
870 			case SID_BASICCOMPILE:
871 			{
872 				if ( !pCurWin || !pCurWin->IsA( TYPE( ModulWindow ) ) || StarBASIC::IsRunning() )
873 					rSet.DisableItem( nWh );
874 			}
875 			break;
876 			case SID_BASICSTOP:
877 			{
878 				// Stop immermoeglich, wenn irgendein Basic lauft...
879 				if ( !StarBASIC::IsRunning() )
880 					rSet.DisableItem( nWh );
881 			}
882 			break;
883 			case SID_CHOOSE_CONTROLS:
884 			case SID_DIALOG_TESTMODE:
885 			{
886 				if( !pCurWin || !pCurWin->IsA( TYPE( DialogWindow ) ) )
887 					rSet.DisableItem( nWh );
888             }
889 			break;
890 			case SID_SHOW_FORMS:
891 			case SID_SHOW_HIDDEN:
892 			{
893 				rSet.DisableItem( nWh );
894 			}
895 			break;
896 			case SID_SEARCH_OPTIONS:
897 			{
898 				sal_uInt16 nOptions = 0;
899 				if( pCurWin )
900 					nOptions = pCurWin->GetSearchOptions();
901 				rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, nOptions ) );
902 			}
903 			break;
904 			case SID_BASICIDE_LIBSELECTOR:
905 			{
906 				String aName;
907                 if ( m_aCurLibName.Len() )
908                 {
909                     LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName );
910                     aName = CreateMgrAndLibStr( m_aCurDocument.getTitle( eLocation ), m_aCurLibName );
911                 }
912                 SfxStringItem aItem( SID_BASICIDE_LIBSELECTOR, aName );
913 				rSet.Put( aItem );
914 			}
915 			break;
916 			case SID_SEARCH_ITEM:
917 			{
918 				String aSelected = GetSelectionText( sal_True );
919 				SvxSearchItem& rItem = IDE_DLL()->GetExtraData()->GetSearchItem();
920 				rItem.SetSearchString( aSelected );
921 				rSet.Put( rItem );
922 			}
923 			break;
924 			case SID_BASICIDE_STAT_DATE:
925 			{
926 				String aDate;
927 				aDate = String( RTL_CONSTASCII_USTRINGPARAM( "Datum?!" ) );
928 				SfxStringItem aItem( SID_BASICIDE_STAT_DATE, aDate );
929 				rSet.Put( aItem );
930 			}
931 			break;
932 			case SID_DOC_MODIFIED:
933 			{
934 				String aModifiedMarker;
935                 sal_Bool bModified = sal_False;
936 
937                 if ( pCurWin )
938                 {
939                     if ( pCurWin->IsModified() )
940                         bModified = sal_True;
941                     else
942                     {
943                         ScriptDocument aDocument( pCurWin->GetDocument() );
944                         bModified = aDocument.isDocument() ? aDocument.isDocumentModified() : IsAppBasicModified();
945                     }
946                 }
947 
948                 if ( bModified )
949 					aModifiedMarker = '*';
950 
951 				SfxStringItem aItem( SID_DOC_MODIFIED, aModifiedMarker );
952 				rSet.Put( aItem );
953 			}
954 			break;
955 			case SID_BASICIDE_STAT_TITLE:
956 			{
957 				if ( pCurWin )
958 				{
959 					String aTitle = pCurWin->CreateQualifiedName();
960 					SfxStringItem aItem( SID_BASICIDE_STAT_TITLE, aTitle );
961 					rSet.Put( aItem );
962 				}
963 			}
964 			break;
965 			// Werden vom Controller ausgewertet:
966 			case SID_ATTR_SIZE:
967 			case SID_ATTR_INSERT:
968 			break;
969 			case SID_UNDO:
970 			case SID_REDO:
971 			{
972 				if( GetUndoManager() )	// sonst rekursives GetState
973 					GetViewFrame()->GetSlotState( nWh, NULL, &rSet );
974 			}
975 			break;
976             case SID_SHOW_PROPERTYBROWSER:
977             {
978                 if ( GetViewFrame()->KnowsChildWindow( nWh ) )
979                     rSet.Put( SfxBoolItem( nWh, GetViewFrame()->HasChildWindow( nWh ) ) );
980                 else
981                     rSet.DisableItem( nWh );
982             }
983             break;
984 
985 			case SID_BASICIDE_CURRENT_LANG:
986 			{
987 				if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().Len() == 0 )
988 					rSet.DisableItem( nWh );
989 				else
990 				{
991 					String aItemStr;
992 					LocalizationMgr* pCurMgr = GetCurLocalizationMgr();
993 					if ( pCurMgr->isLibraryLocalized() )
994 					{
995 						Sequence< lang::Locale > aLocaleSeq = pCurMgr->getStringResourceManager()->getLocales();
996 						const lang::Locale* pLocale = aLocaleSeq.getConstArray();
997 						sal_Int32 i, nCount = aLocaleSeq.getLength();
998 
999 						// Force different results for any combination of locales and default locale
1000 						::rtl::OUString aLangStr;
1001 						for ( i = 0;  i <= nCount;  ++i )
1002 						{
1003 							lang::Locale aLocale;
1004 							if( i < nCount )
1005 								aLocale = pLocale[i];
1006 							else
1007 								aLocale = pCurMgr->getStringResourceManager()->getDefaultLocale();
1008 
1009 							aLangStr += aLocale.Language;
1010 							aLangStr += aLocale.Country;
1011 							aLangStr += aLocale.Variant;
1012 						}
1013 						aItemStr = aLangStr;
1014 					}
1015             		rSet.Put( SfxStringItem( nWh, aItemStr ) );
1016 				}
1017 			}
1018 			break;
1019 
1020 			case SID_BASICIDE_MANAGE_LANG:
1021 			{
1022 				if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().Len() == 0 )
1023 					rSet.DisableItem( nWh );
1024 			}
1025 			break;
1026 		}
1027 	}
1028 	if ( pCurWin )
1029 		pCurWin->GetState( rSet );
1030 }
1031 
HasUIFeature(sal_uInt32 nFeature)1032 sal_Bool BasicIDEShell::HasUIFeature( sal_uInt32 nFeature )
1033 {
1034     sal_Bool bResult = sal_False;
1035 
1036     if ( (nFeature & BASICIDE_UI_FEATURE_SHOW_BROWSER) == BASICIDE_UI_FEATURE_SHOW_BROWSER )
1037     {
1038         // fade out (in) property browser in module (dialog) windows
1039 	    if ( pCurWin && pCurWin->IsA( TYPE( DialogWindow ) ) && !pCurWin->IsReadOnly() )
1040             bResult = sal_True;
1041     }
1042 
1043     return bResult;
1044 }
1045 
SetCurWindow(IDEBaseWindow * pNewWin,sal_Bool bUpdateTabBar,sal_Bool bRememberAsCurrent)1046 void BasicIDEShell::SetCurWindow( IDEBaseWindow* pNewWin, sal_Bool bUpdateTabBar, sal_Bool bRememberAsCurrent )
1047 {
1048 	// Es muss ein EditWindow am Sfx gesetzt sein, sonst kommt kein
1049 	// Resize, also stehen die Controls auf den Wiese...
1050 	// Sieht dann sowieso besser aus, wenn das Modul-Layout angezeigt wird...
1051 	if ( !pNewWin && ( GetWindow() != pModulLayout ) )
1052 	{
1053 		pModulLayout->Show();
1054 		AdjustPosSizePixel( Point( 0, 0 ), GetViewFrame()->GetWindow().GetOutputSizePixel() );
1055 		SetWindow( pModulLayout );
1056 		EnableScrollbars( sal_False );
1057 		aVScrollBar.Hide();
1058 	}
1059 
1060 	if ( pNewWin != pCurWin )
1061 	{
1062 		IDEBaseWindow* pPrevCurWin = pCurWin;
1063 		pCurWin = pNewWin;
1064 		if ( pPrevCurWin )
1065 		{
1066 			pPrevCurWin->Hide();
1067 			pPrevCurWin->Deactivating();
1068 //			pPrevCurWin->GetLayoutWindow()->Hide();
1069 			if( pPrevCurWin->IsA( TYPE( DialogWindow ) ) )
1070 			{
1071 				((DialogWindow*)pPrevCurWin)->DisableBrowser();
1072 			}
1073 			else
1074 			{
1075 				pModulLayout->SetModulWindow( NULL );
1076 			}
1077 		}
1078 		if ( pCurWin )
1079 		{
1080 			AdjustPosSizePixel( Point( 0, 0 ), GetViewFrame()->GetWindow().GetOutputSizePixel() );
1081 			if( pCurWin->IsA( TYPE( ModulWindow ) ) )
1082 			{
1083 				GetViewFrame()->GetWindow().SetHelpId( HID_BASICIDE_MODULWINDOW );
1084 				pModulLayout->SetModulWindow( (ModulWindow*)pCurWin );
1085 				pModulLayout->Show();
1086 			}
1087 			else
1088 			{
1089 				pModulLayout->Hide();
1090 				GetViewFrame()->GetWindow().SetHelpId( HID_BASICIDE_DIALOGWINDOW );
1091 			}
1092 
1093 			if ( bRememberAsCurrent )
1094 			{
1095                 BasicIDEData* pData = IDE_DLL()->GetExtraData();
1096                 if ( pData )
1097                 {
1098                     sal_uInt16 nCurrentType = pCurWin->IsA( TYPE( ModulWindow ) ) ? BASICIDE_TYPE_MODULE : BASICIDE_TYPE_DIALOG;
1099                     LibInfoItem* pLibInfoItem = new LibInfoItem( pCurWin->GetDocument(), pCurWin->GetLibName(), pCurWin->GetName(), nCurrentType );
1100                     pData->GetLibInfos().InsertInfo( pLibInfoItem );
1101                 }
1102             }
1103 
1104 			if ( GetViewFrame()->GetWindow().IsVisible() ) // sonst macht es spaeter der SFX
1105 				pCurWin->Show();
1106 
1107 			pCurWin->Init();
1108 
1109 			if ( !IDE_DLL()->GetExtraData()->ShellInCriticalSection() )
1110 			{
1111 				Window* pFrameWindow = &GetViewFrame()->GetWindow();
1112 				Window* pFocusWindow = Application::GetFocusWindow();
1113 				while ( pFocusWindow && ( pFocusWindow != pFrameWindow ) )
1114 					pFocusWindow = pFocusWindow->GetParent();
1115 				if ( pFocusWindow )	// Focus in BasicIDE
1116 					pNewWin->GrabFocus();
1117 			}
1118 			if( pCurWin->IsA( TYPE( DialogWindow ) ) )
1119 				((DialogWindow*)pCurWin)->UpdateBrowser();
1120 		}
1121 		if ( bUpdateTabBar )
1122 		{
1123 			sal_uLong nKey = aIDEWindowTable.GetKey( pCurWin );
1124 			if ( pCurWin && ( pTabBar->GetPagePos( (sal_uInt16)nKey ) == TAB_PAGE_NOTFOUND ) )
1125 				pTabBar->InsertPage( (sal_uInt16)nKey, pCurWin->GetTitle() );	// wurde neu eingeblendet
1126 			pTabBar->SetCurPageId( (sal_uInt16)nKey );
1127 		}
1128 		if ( pCurWin && pCurWin->IsSuspended() ) 	// Wenn das Fenster im Fehlerfall angezeigt wird...
1129 			pCurWin->SetStatus( pCurWin->GetStatus() & ~BASWIN_SUSPENDED );
1130 		if ( pCurWin )
1131 		{
1132 			SetWindow( pCurWin );
1133             if ( pCurWin->GetDocument().isDocument() )
1134                 SfxObjectShell::SetCurrentComponent( pCurWin->GetDocument().getDocument() );
1135 		}
1136 		else
1137 		{
1138 			SetWindow( pModulLayout );
1139 			GetViewFrame()->GetWindow().SetHelpId( HID_BASICIDE_MODULWINDOW );
1140             SfxObjectShell::SetCurrentComponent( NULL );
1141 		}
1142 		SetUndoManager( pCurWin ? pCurWin->GetUndoManager() : 0 );
1143 		InvalidateBasicIDESlots();
1144 		EnableScrollbars( pCurWin ? sal_True : sal_False );
1145 
1146 		if ( m_pCurLocalizationMgr )
1147 			m_pCurLocalizationMgr->handleTranslationbar();
1148 
1149 		ManageToolbars();
1150 
1151         // fade out (in) property browser in module (dialog) windows
1152         UIFeatureChanged();
1153 	}
1154 }
1155 
ManageToolbars()1156 void BasicIDEShell::ManageToolbars()
1157 {
1158 	static ::rtl::OUString aLayoutManagerName = ::rtl::OUString::createFromAscii( "LayoutManager" );
1159 	static ::rtl::OUString aMacroBarResName =
1160 		::rtl::OUString::createFromAscii( "private:resource/toolbar/macrobar" );
1161 	static ::rtl::OUString aDialogBarResName =
1162 		::rtl::OUString::createFromAscii( "private:resource/toolbar/dialogbar" );
1163 	static ::rtl::OUString aInsertControlsBarResName =
1164 		::rtl::OUString::createFromAscii( "private:resource/toolbar/insertcontrolsbar" );
1165 	(void)aInsertControlsBarResName;
1166 
1167 	if( !pCurWin )
1168 		return;
1169 
1170 	Reference< beans::XPropertySet > xFrameProps
1171 		( GetViewFrame()->GetFrame().GetFrameInterface(), uno::UNO_QUERY );
1172 	if ( xFrameProps.is() )
1173     {
1174 		Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
1175 		uno::Any a = xFrameProps->getPropertyValue( aLayoutManagerName );
1176 		a >>= xLayoutManager;
1177         if ( xLayoutManager.is() )
1178         {
1179 			xLayoutManager->lock();
1180 			if( pCurWin->IsA( TYPE( DialogWindow ) ) )
1181             {
1182 				xLayoutManager->destroyElement( aMacroBarResName );
1183 
1184 				xLayoutManager->requestElement( aDialogBarResName );
1185 				xLayoutManager->requestElement( aInsertControlsBarResName );
1186             }
1187             else
1188             {
1189                 xLayoutManager->destroyElement( aDialogBarResName );
1190 				xLayoutManager->destroyElement( aInsertControlsBarResName );
1191 
1192 				xLayoutManager->requestElement( aMacroBarResName );
1193             }
1194 			xLayoutManager->unlock();
1195         }
1196     }
1197 }
1198 
FindApplicationWindow()1199 IDEBaseWindow* BasicIDEShell::FindApplicationWindow()
1200 {
1201     return FindWindow( ScriptDocument::getApplicationScriptDocument() );
1202 }
1203 
FindWindow(const ScriptDocument & rDocument,const String & rLibName,const String & rName,sal_uInt16 nType,sal_Bool bFindSuspended)1204 IDEBaseWindow* BasicIDEShell::FindWindow( const ScriptDocument& rDocument, const String& rLibName, const String& rName, sal_uInt16 nType, sal_Bool bFindSuspended )
1205 {
1206     IDEBaseWindow* pWin = aIDEWindowTable.First();
1207     while ( pWin )
1208     {
1209         if ( !pWin->IsSuspended() || bFindSuspended )
1210         {
1211             if ( !rLibName.Len() || !rName.Len() || nType == BASICIDE_TYPE_UNKNOWN )
1212             {
1213                 // return any non-suspended window
1214                 return pWin;
1215             }
1216             else if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName && pWin->GetName() == rName &&
1217                       ( ( pWin->IsA( TYPE( ModulWindow ) )  && nType == BASICIDE_TYPE_MODULE ) ||
1218                         ( pWin->IsA( TYPE( DialogWindow ) ) && nType == BASICIDE_TYPE_DIALOG ) ) )
1219             {
1220                 return pWin;
1221             }
1222         }
1223         pWin = aIDEWindowTable.Next();
1224     }
1225     return 0;
1226 }
1227 
CallBasicErrorHdl(StarBASIC * pBasic)1228 long BasicIDEShell::CallBasicErrorHdl( StarBASIC* pBasic )
1229 {
1230 	long nRet = 0;
1231 	ModulWindow* pModWin = ShowActiveModuleWindow( pBasic );
1232 	if ( pModWin )
1233 		nRet = pModWin->BasicErrorHdl( pBasic );
1234 	return nRet;
1235 }
1236 
CallBasicBreakHdl(StarBASIC * pBasic)1237 long BasicIDEShell::CallBasicBreakHdl( StarBASIC* pBasic )
1238 {
1239 	long nRet = 0;
1240 	ModulWindow* pModWin = ShowActiveModuleWindow( pBasic );
1241 	if ( pModWin )
1242 	{
1243 		sal_Bool bAppWindowDisabled, bDispatcherLocked;
1244 		sal_uInt16 nWaitCount;
1245 		SfxUInt16Item *pSWActionCount, *pSWLockViewCount;
1246 		BasicIDE::BasicStopped( &bAppWindowDisabled, &bDispatcherLocked,
1247 								&nWaitCount, &pSWActionCount, &pSWLockViewCount );
1248 
1249 		nRet = pModWin->BasicBreakHdl( pBasic );
1250 
1251 		if ( StarBASIC::IsRunning() )	// Falls abgebrochen...
1252 		{
1253 			if ( bAppWindowDisabled )
1254 				Application::GetDefDialogParent()->Enable( sal_False );
1255         /*
1256 			if ( bDispatcherLocked )
1257 				SFX_APP()->LockDispatcher( sal_True );
1258         */
1259 			if ( nWaitCount )
1260 			{
1261 				BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
1262 				for ( sal_uInt16 n = 0; n < nWaitCount; n++ )
1263 					pIDEShell->GetViewFrame()->GetWindow().EnterWait();
1264 			}
1265 		}
1266 	}
1267 	return nRet;
1268 }
1269 
ShowActiveModuleWindow(StarBASIC * pBasic)1270 ModulWindow* BasicIDEShell::ShowActiveModuleWindow( StarBASIC* pBasic )
1271 {
1272     SetCurLib( ScriptDocument::getApplicationScriptDocument(), String(), false );
1273 
1274 	SbModule* pActiveModule = StarBASIC::GetActiveModule();
1275 	SbClassModuleObject* pClassModuleObject = PTR_CAST(SbClassModuleObject,pActiveModule);
1276 	if( pClassModuleObject != NULL )
1277 		pActiveModule = pClassModuleObject->getClassModule();
1278 
1279 	DBG_ASSERT( pActiveModule, "Kein aktives Modul im ErrorHdl?!" );
1280 	if ( pActiveModule )
1281 	{
1282         ModulWindow* pWin = 0;
1283         SbxObject* pParent = pActiveModule->GetParent();
1284 		DBG_ASSERT( pParent && pParent->ISA( StarBASIC ), "Kein BASIC!" );
1285         StarBASIC* pLib = static_cast< StarBASIC* >( pParent );
1286         if ( pLib )
1287         {
1288 		    BasicManager* pBasMgr = BasicIDE::FindBasicManager( pLib );
1289             if ( pBasMgr )
1290             {
1291                 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
1292                 String aLibName = pLib->GetName();
1293                 pWin = FindBasWin( aDocument, aLibName, pActiveModule->GetName(), sal_True );
1294                 DBG_ASSERT( pWin, "Error/Step-Hdl: Fenster wurde nicht erzeugt/gefunden!" );
1295                 SetCurLib( aDocument, aLibName );
1296                 SetCurWindow( pWin, sal_True );
1297             }
1298         }
1299 		BasicManager* pBasicMgr = BasicIDE::FindBasicManager( pBasic );
1300 		if ( pBasicMgr )
1301 			StartListening( *pBasicMgr, sal_True /* Nur einmal anmelden */ );
1302 		return pWin;
1303 	}
1304 	return 0;
1305 }
1306 
AdjustPosSizePixel(const Point & rPos,const Size & rSize)1307 void __EXPORT BasicIDEShell::AdjustPosSizePixel( const Point &rPos, const Size &rSize )
1308 {
1309 	// Nicht wenn minimiert, weil dann bei Restore der Text verschoben ist.
1310 	if ( GetViewFrame()->GetWindow().GetOutputSizePixel().Height() == 0 )
1311 		return;
1312 
1313 	Size aSz( rSize );
1314 //	long nScrollbarWidthPixel = aVScrollBar.GetSizePixel().Width();
1315 	Size aScrollBarBoxSz( aScrollBarBox.GetSizePixel() );
1316 	aSz.Height() -= aScrollBarBoxSz.Height();
1317 
1318     Size aOutSz( aSz );
1319 	aSz.Width() -= aScrollBarBoxSz.Width();
1320 	aScrollBarBox.SetPosPixel( Point( rSize.Width() - aScrollBarBoxSz.Width(), rSize.Height() - aScrollBarBoxSz.Height() ) );
1321 	aVScrollBar.SetPosSizePixel( Point( rPos.X()+aSz.Width(), rPos.Y() ), Size( aScrollBarBoxSz.Width(), aSz.Height() ) );
1322 	if ( bTabBarSplitted )
1323 	{
1324 		// SplitSize ist beim Resize 0 !
1325 		long nSplitPos = pTabBar->GetSizePixel().Width();
1326 		if ( nSplitPos > aSz.Width() )
1327 			nSplitPos = aSz.Width();
1328 		pTabBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aSz.Height() ), Size( nSplitPos, aScrollBarBoxSz.Height() ) );
1329 		long nScrlStart = rPos.X() + nSplitPos;
1330 		aHScrollBar.SetPosSizePixel( Point( nScrlStart, rPos.Y()+aSz.Height() ), Size( aSz.Width() - nScrlStart + 1, aScrollBarBoxSz.Height() ) );
1331 		aHScrollBar.Update();
1332 	}
1333 	else
1334 	{
1335 		aHScrollBar.SetPosSizePixel( Point( rPos.X()+ aSz.Width()/2 - 1, rPos.Y()+aSz.Height() ), Size( aSz.Width()/2 + 2, aScrollBarBoxSz.Height() ) );
1336 		pTabBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aSz.Height() ), Size( aSz.Width()/2, aScrollBarBoxSz.Height() ) );
1337 	}
1338 
1339 	Window* pEdtWin = pCurWin ? pCurWin->GetLayoutWindow() : pModulLayout;
1340 	if ( pEdtWin )
1341 	{
1342 		if( pCurWin && pCurWin->IsA( TYPE( DialogWindow ) ) )
1343 			pEdtWin->SetPosSizePixel( rPos, aSz );	// Ohne ScrollBar
1344 		else
1345 			pEdtWin->SetPosSizePixel( rPos, aOutSz );
1346 	}
1347 }
1348 
GetCurrentDocument() const1349 Reference< XModel > BasicIDEShell::GetCurrentDocument() const
1350 {
1351     Reference< XModel > xDocument;
1352     if ( pCurWin && pCurWin->GetDocument().isDocument() )
1353         xDocument = pCurWin->GetDocument().getDocument();
1354     return xDocument;
1355 }
1356 
Activate(sal_Bool bMDI)1357 void __EXPORT BasicIDEShell::Activate( sal_Bool bMDI )
1358 {
1359     SfxViewShell::Activate( bMDI );
1360 
1361     if ( bMDI )
1362 	{
1363 		if( pCurWin && pCurWin->IsA( TYPE( DialogWindow ) ) )
1364 			((DialogWindow*)pCurWin)->UpdateBrowser();
1365 
1366 		ShowObjectDialog( sal_True, sal_False );
1367 	}
1368 }
1369 
Deactivate(sal_Bool bMDI)1370 void __EXPORT BasicIDEShell::Deactivate( sal_Bool bMDI )
1371 {
1372 	// bMDI sal_True heisst, dass ein anderes MDI aktiviert wurde, bei einem
1373 	// Deactivate durch eine MessageBox ist bMDI FALSE
1374 	if ( bMDI )
1375 	{
1376 		if( pCurWin && pCurWin->IsA( TYPE( DialogWindow ) ) )
1377 		{
1378 			DialogWindow* pXDlgWin = (DialogWindow*)pCurWin;
1379 			pXDlgWin->DisableBrowser();
1380 			if( pXDlgWin->IsModified() )
1381 				BasicIDE::MarkDocumentModified( pXDlgWin->GetDocument() );
1382 		}
1383 
1384 		// CanClose pruefen, damit auch beim deaktivieren der BasicIDE geprueft wird,
1385 		// ob in einem Modul der Sourcecode zu gross ist...
1386 		for ( sal_uLong nWin = 0; nWin < aIDEWindowTable.Count(); nWin++ )
1387 		{
1388 			IDEBaseWindow* pWin = aIDEWindowTable.GetObject( nWin );
1389 			if ( /* !pWin->IsSuspended() && */ !pWin->CanClose() )
1390 			{
1391                 if ( m_aCurLibName.Len() && ( pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName ) )
1392                     SetCurLib( ScriptDocument::getApplicationScriptDocument(), String(), false );
1393 				SetCurWindow( pWin, sal_True );
1394 				break;
1395 			}
1396 		}
1397 
1398         ShowObjectDialog( sal_False, sal_False );
1399 	}
1400 }
1401 
1402 
IMPL_LINK(BasicIDEShell,AccelSelectHdl,Accelerator *,pAccel)1403 IMPL_LINK( BasicIDEShell, AccelSelectHdl, Accelerator*, pAccel )
1404 {
1405 	sal_Bool bDone = sal_True;
1406     SfxViewFrame* pViewFrame = GetViewFrame();
1407 	SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
1408     if( !pDispatcher )
1409 		return sal_False;
1410 	switch ( pAccel->GetCurKeyCode().GetCode() )
1411 	{
1412         case KEY_F5:
1413             if ( pAccel->GetCurKeyCode().IsShift() )
1414                 pDispatcher->Execute( SID_BASICSTOP, SFX_CALLMODE_SYNCHRON );
1415             else
1416                 pDispatcher->Execute( SID_BASICRUN, SFX_CALLMODE_SYNCHRON );
1417 		break;
1418 		case KEY_F7:
1419 			pDispatcher->Execute( SID_BASICIDE_ADDWATCH, SFX_CALLMODE_SYNCHRON );
1420 		break;
1421 		case KEY_F8:
1422 			if ( pAccel->GetCurKeyCode().IsShift() )
1423 				pDispatcher->Execute( SID_BASICSTEPOVER, SFX_CALLMODE_SYNCHRON );
1424 			else
1425 				pDispatcher->Execute( SID_BASICSTEPINTO, SFX_CALLMODE_SYNCHRON );
1426 		break;
1427 		case KEY_F9:
1428 			if ( pAccel->GetCurKeyCode().IsShift() )
1429 				pDispatcher->Execute( SID_BASICIDE_TOGGLEBRKPNTENABLED, SFX_CALLMODE_SYNCHRON );
1430 			else
1431 				pDispatcher->Execute( SID_BASICIDE_TOGGLEBRKPNT, SFX_CALLMODE_SYNCHRON );
1432 		break;
1433 		default:	bDone = sal_False;
1434 	}
1435 	return bDone;
1436 }
1437 
1438