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