merge the formfield patch from ooo-build
[ooovba.git] / basctl / source / basicide / basides1.cxx
blob231aebde5b062ec01a9bc4c653de0e47da991c59
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: basides1.cxx,v $
10 * $Revision: 1.56 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
34 #include "docsignature.hxx"
36 #define GLOBALOVERFLOW2
37 #include <basic/sbx.hxx>
38 #define _SVSTDARR_STRINGS
39 #include <svtools/svstdarr.hxx>
40 #include <ide_pch.hxx>
42 #define _SOLAR__PRIVATE 1
44 // #define _SVX_NOIDERESIDS
46 #define SI_NOCONTROL
47 #define SI_NOSBXCONTROLS
48 #define SI_NOITEMS
49 #define SI_NODRW
50 #define _VCTRLS_HXX
52 #include <basidesh.hrc>
53 #include <basidesh.hxx>
54 #include <baside2.hxx>
55 #include <baside3.hxx>
56 #include <basobj.hxx>
57 #include <iderdll.hxx>
58 #include <iderdll2.hxx>
59 #include <sbxitem.hxx>
60 #include <managelang.hxx>
61 #include <localizationmgr.hxx>
62 #include <helpid.hrc>
64 #include <svtools/texteng.hxx>
65 #include <svtools/textview.hxx>
66 #include <svtools/xtextedt.hxx>
67 #include <tools/urlobj.hxx>
68 #include <tools/diagnose_ex.h>
69 #include <sfx2/minfitem.hxx>
70 #include <sfx2/docfile.hxx>
71 #include <com/sun/star/task/XStatusIndicator.hpp>
72 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
73 #include <com/sun/star/script/XLibraryContainer.hpp>
74 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
75 #include <com/sun/star/frame/XDispatchProvider.hpp>
76 #include <com/sun/star/frame/XLayoutManager.hpp>
78 #include <algorithm>
79 #include <memory>
82 using namespace ::com::sun::star;
83 using namespace ::com::sun::star::uno;
84 using namespace ::com::sun::star::frame;
86 class SvxSearchItem;
88 // Egal was, einfach ans aktuelle Fenster:
89 void __EXPORT BasicIDEShell::ExecuteCurrent( SfxRequest& rReq )
91 if ( !pCurWin )
92 return;
94 switch ( rReq.GetSlot() )
96 case SID_BASICIDE_HIDECURPAGE:
98 pCurWin->StoreData();
99 RemoveWindow( pCurWin, FALSE );
101 break;
102 case SID_BASICIDE_DELETECURRENT:
104 ScriptDocument aDocument( pCurWin->GetDocument() );
105 String aLibName = pCurWin->GetLibName();
106 String aName = pCurWin->GetName();
108 if ( pCurWin->ISA( ModulWindow ) )
110 // module
111 if ( QueryDelModule( aName, pCurWin ) )
113 if ( aDocument.removeModule( aLibName, aName ) )
115 RemoveWindow( pCurWin, TRUE );
116 BasicIDE::MarkDocumentModified( aDocument );
120 else
122 // dialog
123 if ( QueryDelDialog( aName, pCurWin ) )
125 if ( BasicIDE::RemoveDialog( aDocument, aLibName, aName ) )
127 RemoveWindow( pCurWin, TRUE );
128 BasicIDE::MarkDocumentModified( aDocument );
133 break;
134 case SID_BASICIDE_RENAMECURRENT:
136 pTabBar->StartEditMode( pTabBar->GetCurPageId() );
138 break;
139 case FID_SEARCH_NOW:
141 if ( pCurWin->ISA( ModulWindow ) )
143 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
144 const SfxItemSet* pArgs = rReq.GetArgs();
145 // Leider kenne ich die ID nicht:
146 USHORT nWhich = pArgs->GetWhichByPos( 0 );
147 DBG_ASSERT( nWhich, "Wich fuer SearchItem ?" );
148 const SfxPoolItem& rItem = pArgs->Get( nWhich );
149 DBG_ASSERT( rItem.ISA( SvxSearchItem ), "Kein Searchitem!" );
150 if ( rItem.ISA( SvxSearchItem ) )
152 // Item wegen der Einstellungen merken...
153 IDE_DLL()->GetExtraData()->SetSearchItem( (const SvxSearchItem&)rItem );
154 USHORT nFound = 0;
155 BOOL bCanceled = FALSE;
156 if ( ((const SvxSearchItem&)rItem).GetCommand() == SVX_SEARCHCMD_REPLACE_ALL )
158 USHORT nActModWindows = 0;
159 IDEBaseWindow* pWin = aIDEWindowTable.First();
160 while ( pWin )
162 if ( !pWin->IsSuspended() && pWin->IsA( TYPE( ModulWindow ) ) )
163 nActModWindows++;
164 pWin = aIDEWindowTable.Next();
167 if ( ( nActModWindows <= 1 ) || ( !((const SvxSearchItem&)rItem).GetSelection() && QueryBox( pCurWin, WB_YES_NO|WB_DEF_YES, String( IDEResId( RID_STR_SEARCHALLMODULES ) ) ).Execute() == RET_YES ) )
169 pWin = aIDEWindowTable.First();
170 while ( pWin )
172 if ( !pWin->IsSuspended() && pWin->IsA( TYPE( ModulWindow ) ) )
173 nFound = nFound + ((ModulWindow*)pWin)->StartSearchAndReplace( (const SvxSearchItem&)rItem );
174 pWin = aIDEWindowTable.Next();
177 else
178 nFound = ((ModulWindow*)pCurWin)->StartSearchAndReplace( (const SvxSearchItem&)rItem );
180 IDEResId nId( RID_STR_SEARCHREPLACES );
181 String aReplStr( nId );
182 aReplStr.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "XX" ) ), String::CreateFromInt32( nFound ) );
183 InfoBox( pCurWin, aReplStr ).Execute();
185 else
187 nFound = ((ModulWindow*)pCurWin)->StartSearchAndReplace( (const SvxSearchItem&)rItem );
188 if ( !nFound && !((const SvxSearchItem&)rItem).GetSelection() )
190 // Andere Module durchsuchen...
191 BOOL bChangeCurWindow = FALSE;
192 aIDEWindowTable.Seek( pCurWin );
193 // Erstmal beim naechsten Anfangen, ggf. spaeter von vorne
194 IDEBaseWindow* pWin = aIDEWindowTable.Next();
195 BOOL bSearchedFromStart = FALSE;
196 while ( !nFound && !bCanceled && ( pWin || !bSearchedFromStart ) )
198 if ( !pWin )
200 SfxViewFrame* pViewFrame = GetViewFrame();
201 SfxChildWindow* pChildWin = pViewFrame ? pViewFrame->GetChildWindow( SID_SEARCH_DLG ) : NULL;
202 Window* pParent = pChildWin ? pChildWin->GetWindow() : NULL;
203 QueryBox aQuery( pParent, WB_YES_NO|WB_DEF_YES, String( IDEResId( RID_STR_SEARCHFROMSTART ) ) );
204 if ( aQuery.Execute() == RET_YES )
206 pWin = aIDEWindowTable.First();
207 bSearchedFromStart = TRUE;
209 else
210 bCanceled = TRUE;
213 if ( pWin && !pWin->IsSuspended() && pWin->IsA( TYPE( ModulWindow ) ) )
215 if ( pWin != pCurWin )
217 // Groesse einstellen, damit die View
218 // gleich richtig justiert werden kann.
219 if ( pCurWin )
220 pWin->SetSizePixel( pCurWin->GetSizePixel() );
221 nFound = ((ModulWindow*)pWin)->StartSearchAndReplace( (const SvxSearchItem&)rItem, TRUE );
223 if ( nFound )
225 bChangeCurWindow = TRUE;
226 break;
229 if ( pWin && ( pWin != pCurWin ) )
230 pWin = aIDEWindowTable.Next();
231 else
232 pWin = 0; // Dann sind wir durch...
234 if ( !nFound && bSearchedFromStart ) // Aktuelles von vorne...
235 nFound = ((ModulWindow*)pCurWin)->StartSearchAndReplace( (const SvxSearchItem&)rItem, TRUE );
236 if ( bChangeCurWindow )
237 SetCurWindow( pWin, TRUE );
239 if ( !nFound && !bCanceled )
240 InfoBox( pCurWin, String( IDEResId( RID_STR_SEARCHNOTFOUND ) ) ).Execute();
243 rReq.Done();
247 break;
248 case FID_SEARCH_OFF:
250 if ( pCurWin && pCurWin->ISA( ModulWindow ) )
251 pCurWin->GrabFocus();
253 break;
254 case SID_UNDO:
255 case SID_REDO:
257 if ( GetUndoManager() && pCurWin->AllowUndo() )
259 GetViewFrame()->ExecuteSlot( rReq );
262 break;
263 default:
265 pCurWin->ExecuteCommand( rReq );
270 // Egal, wer oben, Einfluss auf die Shell:
271 void __EXPORT BasicIDEShell::ExecuteGlobal( SfxRequest& rReq )
273 USHORT nSlot = rReq.GetSlot();
274 switch ( nSlot )
276 case SID_BASICSTOP:
278 // Evtl. nicht einfach anhalten, falls auf Brechpunkt!
279 if ( pCurWin && pCurWin->IsA( TYPE( ModulWindow ) ) )
280 ((ModulWindow*)pCurWin)->BasicStop();
281 BasicIDE::StopBasic();
283 break;
285 case SID_SAVEDOC:
287 if ( pCurWin )
289 // Daten ins BASIC zurueckschreiben
290 StoreAllWindowData();
292 // document basic
293 ScriptDocument aDocument( pCurWin->GetDocument() );
294 if ( aDocument.isDocument() )
296 uno::Reference< task::XStatusIndicator > xStatusIndicator;
298 SFX_REQUEST_ARG( rReq, pStatusIndicatorItem, SfxUnoAnyItem, SID_PROGRESS_STATUSBAR_CONTROL, FALSE );
299 if ( pStatusIndicatorItem )
300 OSL_VERIFY( pStatusIndicatorItem->GetValue() >>= xStatusIndicator );
301 else
303 // get statusindicator
304 SfxViewFrame *pFrame_ = GetFrame();
305 if ( pFrame_ && pFrame_->GetFrame() )
307 uno::Reference< task::XStatusIndicatorFactory > xStatFactory(
308 pFrame_->GetFrame()->GetFrameInterface(),
309 uno::UNO_QUERY );
310 if( xStatFactory.is() )
311 xStatusIndicator = xStatFactory->createStatusIndicator();
314 if ( xStatusIndicator.is() )
315 rReq.AppendItem( SfxUnoAnyItem( SID_PROGRESS_STATUSBAR_CONTROL, uno::makeAny( xStatusIndicator ) ) );
318 aDocument.saveDocument( xStatusIndicator );
321 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
322 if ( pBindings )
324 pBindings->Invalidate( SID_DOC_MODIFIED );
325 pBindings->Invalidate( SID_SAVEDOC );
326 pBindings->Invalidate( SID_SIGNATURE );
330 break;
331 case SID_SIGNATURE:
333 if ( pCurWin )
335 ::basctl::DocumentSignature aSignature( pCurWin->GetDocument() );
336 if ( aSignature.supportsSignatures() )
338 aSignature.signScriptingContent();
339 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
340 if ( pBindings )
341 pBindings->Invalidate( SID_SIGNATURE );
345 break;
347 case SID_BASICIDE_MODULEDLG:
349 if ( rReq.GetArgs() )
351 const SfxUInt16Item &rTabId = (const SfxUInt16Item&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
352 BasicIDE::Organize( rTabId.GetValue() );
354 else
355 BasicIDE::Organize( 0 );
357 break;
358 case SID_BASICIDE_CHOOSEMACRO:
360 BasicIDE::ChooseMacro( NULL, FALSE, ::rtl::OUString() );
362 break;
363 case SID_BASICIDE_CREATEMACRO:
364 case SID_BASICIDE_EDITMACRO:
366 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
367 const SfxMacroInfoItem& rInfo = (const SfxMacroInfoItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
368 BasicManager* pBasMgr = (BasicManager*)rInfo.GetBasicManager();
369 DBG_ASSERT( pBasMgr, "Nichts selektiert im Basic-Baum ?" );
371 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
373 StartListening( *pBasMgr, TRUE /* Nur einmal anmelden */ );
374 String aLibName( rInfo.GetLib() );
375 if ( !aLibName.Len() )
376 aLibName = String::CreateFromAscii( "Standard" );
377 StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
378 if ( !pBasic )
380 // load module and dialog library (if not loaded)
381 aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
382 aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
384 // get Basic
385 pBasic = pBasMgr->GetLib( aLibName );
387 DBG_ASSERT( pBasic, "Kein Basic!" );
389 SetCurLib( aDocument, aLibName );
391 if ( rReq.GetSlot() == SID_BASICIDE_CREATEMACRO )
393 SbModule* pModule = pBasic->FindModule( rInfo.GetModule() );
394 if ( !pModule )
396 if ( rInfo.GetModule().Len() || !pBasic->GetModules()->Count() )
398 String aModName = rInfo.GetModule();
400 ::rtl::OUString sModuleCode;
401 if ( aDocument.createModule( aLibName, aModName, FALSE, sModuleCode ) )
402 pModule = pBasic->FindModule( aModName );
404 else
405 pModule = (SbModule*) pBasic->GetModules()->Get(0);
407 DBG_ASSERT( pModule, "Kein Modul!" );
408 if ( !pModule->GetMethods()->Find( rInfo.GetMethod(), SbxCLASS_METHOD ) )
409 BasicIDE::CreateMacro( pModule, rInfo.GetMethod() );
411 SfxViewFrame* pViewFrame = GetViewFrame();
412 if ( pViewFrame )
413 pViewFrame->ToTop();
414 ModulWindow* pWin = FindBasWin( aDocument, aLibName, rInfo.GetModule(), TRUE );
415 DBG_ASSERT( pWin, "Edit/Create Macro: Fenster wurde nicht erzeugt/gefunden!" );
416 SetCurWindow( pWin, TRUE );
417 pWin->EditMacro( rInfo.GetMethod() );
419 break;
420 case SID_BASICIDE_OBJCAT:
422 ShowObjectDialog( TRUE, TRUE );
424 break;
425 case SID_BASICIDE_NAMECHANGEDONTAB:
427 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
428 const SfxUInt16Item &rTabId = (const SfxUInt16Item&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
429 const SfxStringItem &rModName = (const SfxStringItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_MODULENAME );
430 IDEBaseWindow* pWin = aIDEWindowTable.Get( rTabId.GetValue() );
431 DBG_ASSERT( pWin, "Window nicht im Liste, aber in TabBar ?" );
432 if ( pWin )
434 String aNewName( rModName.GetValue() );
435 String aOldName( pWin->GetName() );
437 if ( aNewName != aOldName )
439 if ( ( pWin->IsA( TYPE( ModulWindow ) ) && ((ModulWindow*)pWin)->RenameModule( aNewName ) )
440 || ( pWin->IsA( TYPE( DialogWindow ) ) && ((DialogWindow*)pWin)->RenameDialog( aNewName ) ) )
442 BasicIDE::MarkDocumentModified( pWin->GetDocument() );
444 else
446 // set old name in TabWriter
447 USHORT nId = (USHORT)aIDEWindowTable.GetKey( pWin );
448 DBG_ASSERT( nId, "No entry in Tabbar!" );
449 if ( nId )
450 pTabBar->SetPageText( nId, aOldName );
454 // set focus to current window
455 pWin->GrabFocus();
458 break;
459 case SID_BASICIDE_STOREMODULESOURCE:
460 case SID_BASICIDE_UPDATEMODULESOURCE:
462 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
463 const SfxMacroInfoItem& rInfo = (const SfxMacroInfoItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
464 BasicManager* pBasMgr = (BasicManager*)rInfo.GetBasicManager();
465 DBG_ASSERT( pBasMgr, "Store source: Kein BasMgr?" );
466 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
467 ModulWindow* pWin = FindBasWin( aDocument, rInfo.GetLib(), rInfo.GetModule(), FALSE, TRUE );
468 if ( pWin )
470 if ( rReq.GetSlot() == SID_BASICIDE_STOREMODULESOURCE )
471 pWin->StoreData();
472 else
473 pWin->UpdateData();
476 break;
477 case SID_BASICIDE_STOREALLMODULESOURCES:
478 case SID_BASICIDE_UPDATEALLMODULESOURCES:
480 IDEBaseWindow* pWin = aIDEWindowTable.First();
481 while ( pWin )
483 if ( !pWin->IsSuspended() && pWin->IsA( TYPE( ModulWindow ) ) )
485 if ( rReq.GetSlot() == SID_BASICIDE_STOREALLMODULESOURCES )
486 pWin->StoreData();
487 else
488 pWin->UpdateData();
490 pWin = aIDEWindowTable.Next();
493 break;
494 case SID_BASICIDE_LIBSELECTED:
495 case SID_BASICIDE_LIBREMOVED:
496 case SID_BASICIDE_LIBLOADED:
498 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
499 const SfxUsrAnyItem& rShellItem = (const SfxUsrAnyItem&)rReq.GetArgs()->Get( SID_BASICIDE_ARG_DOCUMENT_MODEL );
500 uno::Reference< frame::XModel > xModel( rShellItem.GetValue(), UNO_QUERY );
501 ScriptDocument aDocument( xModel.is() ? ScriptDocument( xModel ) : ScriptDocument::getApplicationScriptDocument() );
502 const SfxStringItem& rLibNameItem = (const SfxStringItem&)rReq.GetArgs()->Get( SID_BASICIDE_ARG_LIBNAME );
503 String aLibName( rLibNameItem.GetValue() );
505 if ( nSlot == SID_BASICIDE_LIBSELECTED )
507 // load module and dialog library (if not loaded)
508 aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
509 aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
511 // check password, if library is password protected and not verified
512 BOOL bOK = TRUE;
513 Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ) );
514 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
516 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
517 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
519 String aPassword;
520 bOK = QueryPassword( xModLibContainer, aLibName, aPassword );
524 if ( bOK )
526 SetCurLib( aDocument, aLibName, true, false );
528 else
530 // alten Wert einstellen...
531 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
532 if ( pBindings )
533 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR, TRUE, FALSE );
536 else if ( nSlot == SID_BASICIDE_LIBREMOVED )
538 if ( !m_aCurLibName.Len() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
540 RemoveWindows( aDocument, aLibName, TRUE );
541 if ( aDocument == m_aCurDocument && aLibName == m_aCurLibName )
543 m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
544 m_aCurLibName = String();
545 // Kein UpdateWindows!
546 SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
547 if ( pBindings )
548 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
552 else // Loaded...
553 UpdateWindows();
555 break;
556 case SID_BASICIDE_NEWMODULE:
558 ModulWindow* pWin = CreateBasWin( m_aCurDocument, m_aCurLibName, String() );
559 DBG_ASSERT( pWin, "New Module: Konnte Fenster nicht erzeugen!" );
560 SetCurWindow( pWin, TRUE );
562 break;
563 case SID_BASICIDE_NEWDIALOG:
565 DialogWindow* pWin = CreateDlgWin( m_aCurDocument, m_aCurLibName, String() );
566 DBG_ASSERT( pWin, "New Module: Konnte Fenster nicht erzeugen!" );
567 SetCurWindow( pWin, TRUE );
569 break;
570 case SID_BASICIDE_SBXRENAMED:
572 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
574 break;
575 case SID_BASICIDE_SBXINSERTED:
577 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
578 const SbxItem& rSbxItem = (const SbxItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
579 ScriptDocument aDocument( rSbxItem.GetDocument() );
580 String aLibName( rSbxItem.GetLibName() );
581 String aName( rSbxItem.GetName() );
582 if ( !m_aCurLibName.Len() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
584 IDEBaseWindow* pWin = 0;
585 if ( rSbxItem.GetType() == BASICIDE_TYPE_MODULE )
586 pWin = FindBasWin( aDocument, aLibName, aName, TRUE );
587 else if ( rSbxItem.GetType() == BASICIDE_TYPE_DIALOG )
588 pWin = FindDlgWin( aDocument, aLibName, aName, TRUE );
591 break;
592 case SID_BASICIDE_SBXDELETED:
594 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
595 const SbxItem& rSbxItem = (const SbxItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
596 ScriptDocument aDocument( rSbxItem.GetDocument() );
597 IDEBaseWindow* pWin = FindWindow( aDocument, rSbxItem.GetLibName(), rSbxItem.GetName(), rSbxItem.GetType(), TRUE );
598 if ( pWin )
599 RemoveWindow( pWin, TRUE );
601 break;
602 case SID_BASICIDE_SHOWSBX:
604 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
605 const SbxItem& rSbxItem = (const SbxItem&)rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
606 ScriptDocument aDocument( rSbxItem.GetDocument() );
607 String aLibName( rSbxItem.GetLibName() );
608 String aName( rSbxItem.GetName() );
609 SetCurLib( aDocument, aLibName );
610 IDEBaseWindow* pWin = 0;
611 if ( rSbxItem.GetType() == BASICIDE_TYPE_DIALOG )
613 pWin = FindDlgWin( aDocument, aLibName, aName, TRUE );
615 else if ( rSbxItem.GetType() == BASICIDE_TYPE_MODULE )
617 pWin = FindBasWin( aDocument, aLibName, aName, TRUE );
619 else if ( rSbxItem.GetType() == BASICIDE_TYPE_METHOD )
621 pWin = FindBasWin( aDocument, aLibName, aName, TRUE );
622 ((ModulWindow*)pWin)->EditMacro( rSbxItem.GetMethodName() );
624 DBG_ASSERT( pWin, "Fenster wurde nicht erzeugt!" );
625 SetCurWindow( pWin, TRUE );
626 pTabBar->MakeVisible( pTabBar->GetCurPageId() );
628 break;
629 case SID_SHOW_PROPERTYBROWSER:
631 GetViewFrame()->ChildWindowExecute( rReq );
632 rReq.Done();
634 break;
635 case SID_BASICIDE_SHOWWINDOW:
637 ::std::auto_ptr< ScriptDocument > pDocument;
639 SFX_REQUEST_ARG( rReq, pDocumentItem, SfxStringItem, SID_BASICIDE_ARG_DOCUMENT, sal_False );
640 if ( pDocumentItem )
642 String sDocumentCaption = pDocumentItem->GetValue();
643 if ( sDocumentCaption.Len() )
644 pDocument.reset( new ScriptDocument( ScriptDocument::getDocumentWithURLOrCaption( sDocumentCaption ) ) );
647 SFX_REQUEST_ARG( rReq, pDocModelItem, SfxUsrAnyItem, SID_BASICIDE_ARG_DOCUMENT_MODEL, sal_False );
648 if ( !pDocument.get() && pDocModelItem )
650 uno::Reference< frame::XModel > xModel( pDocModelItem->GetValue(), UNO_QUERY );
651 if ( xModel.is() )
652 pDocument.reset( new ScriptDocument( xModel ) );
655 if ( !pDocument.get() )
656 break;
658 SFX_REQUEST_ARG( rReq, pLibNameItem, SfxStringItem, SID_BASICIDE_ARG_LIBNAME, sal_False );
659 if ( !pLibNameItem )
660 break;
662 String aLibName( pLibNameItem->GetValue() );
663 pDocument->loadLibraryIfExists( E_SCRIPTS, aLibName );
664 SetCurLib( *pDocument, aLibName );
665 SFX_REQUEST_ARG( rReq, pNameItem, SfxStringItem, SID_BASICIDE_ARG_NAME, sal_False );
666 if ( pNameItem )
668 String aName( pNameItem->GetValue() );
669 String aModType( String::CreateFromAscii( "Module" ) );
670 String aDlgType( String::CreateFromAscii( "Dialog" ) );
671 String aType( aModType );
672 SFX_REQUEST_ARG( rReq, pTypeItem, SfxStringItem, SID_BASICIDE_ARG_TYPE, sal_False );
673 if ( pTypeItem )
674 aType = pTypeItem->GetValue();
676 IDEBaseWindow* pWin = 0;
677 if ( aType == aModType )
678 pWin = FindBasWin( *pDocument, aLibName, aName, FALSE );
679 else if ( aType == aDlgType )
680 pWin = FindDlgWin( *pDocument, aLibName, aName, FALSE );
682 if ( pWin )
684 SetCurWindow( pWin, TRUE );
685 if ( pTabBar )
686 pTabBar->MakeVisible( pTabBar->GetCurPageId() );
688 if ( pWin->ISA( ModulWindow ) )
690 ModulWindow* pModWin = (ModulWindow*)pWin;
691 SFX_REQUEST_ARG( rReq, pLineItem, SfxUInt32Item, SID_BASICIDE_ARG_LINE, sal_False );
692 if ( pLineItem )
694 pModWin->AssertValidEditEngine();
695 TextView* pTextView = pModWin->GetEditView();
696 if ( pTextView )
698 TextEngine* pTextEngine = pTextView->GetTextEngine();
699 if ( pTextEngine )
701 sal_uInt32 nLine = pLineItem->GetValue();
702 sal_uInt32 nLineCount = 0;
703 for ( sal_uInt32 i = 0, nCount = pTextEngine->GetParagraphCount(); i < nCount; ++i )
704 nLineCount += pTextEngine->GetLineCount( i );
705 if ( nLine > nLineCount )
706 nLine = nLineCount;
707 if ( nLine > 0 )
708 --nLine;
710 // scroll window and set selection
711 long nVisHeight = pModWin->GetOutputSizePixel().Height();
712 long nTextHeight = pTextEngine->GetTextHeight();
713 if ( nTextHeight > nVisHeight )
715 long nMaxY = nTextHeight - nVisHeight;
716 long nOldY = pTextView->GetStartDocPos().Y();
717 long nNewY = nLine * pTextEngine->GetCharHeight() - nVisHeight / 2;
718 nNewY = ::std::min( nNewY, nMaxY );
719 pTextView->Scroll( 0, -( nNewY - nOldY ) );
720 pTextView->ShowCursor( FALSE, TRUE );
721 pModWin->GetEditVScrollBar().SetThumbPos( pTextView->GetStartDocPos().Y() );
723 sal_uInt16 nCol1 = 0, nCol2 = 0;
724 SFX_REQUEST_ARG( rReq, pCol1Item, SfxUInt16Item, SID_BASICIDE_ARG_COLUMN1, sal_False );
725 if ( pCol1Item )
727 nCol1 = pCol1Item->GetValue();
728 if ( nCol1 > 0 )
729 --nCol1;
730 nCol2 = nCol1;
732 SFX_REQUEST_ARG( rReq, pCol2Item, SfxUInt16Item, SID_BASICIDE_ARG_COLUMN2, sal_False );
733 if ( pCol2Item )
735 nCol2 = pCol2Item->GetValue();
736 if ( nCol2 > 0 )
737 --nCol2;
739 TextSelection aSel( TextPaM( nLine, nCol1 ), TextPaM( nLine, nCol2 ) );
740 pTextView->SetSelection( aSel );
741 pTextView->ShowCursor();
742 Window* pWindow_ = pTextView->GetWindow();
743 if ( pWindow_ )
744 pWindow_->GrabFocus();
751 rReq.Done();
753 break;
755 case SID_BASICIDE_MANAGE_LANG:
757 ManageLanguageDialog aDlg( GetCurWindow(), GetCurLocalizationMgr() );
758 aDlg.Execute();
759 rReq.Done();
761 break;
765 void __EXPORT BasicIDEShell::GetState(SfxItemSet &rSet)
767 SfxWhichIter aIter(rSet);
768 for ( USHORT nWh = aIter.FirstWhich(); 0 != nWh; nWh = aIter.NextWhich() )
770 switch ( nWh )
772 case SID_DOCINFO:
774 rSet.DisableItem( nWh );
776 break;
777 case SID_SAVEDOC:
779 BOOL bDisable = FALSE;
781 if ( pCurWin )
783 if ( !pCurWin->IsModified() )
785 ScriptDocument aDocument( pCurWin->GetDocument() );
786 bDisable = ( !aDocument.isAlive() )
787 || ( aDocument.isDocument() ? !aDocument.isDocumentModified() : !IsAppBasicModified() );
790 else
792 bDisable = TRUE;
795 if ( bDisable )
796 rSet.DisableItem( nWh );
798 break;
799 case SID_NEWWINDOW:
800 case SID_SAVEASDOC:
802 rSet.DisableItem( nWh );
804 break;
805 case SID_SIGNATURE:
807 sal_uInt16 nState = 0;
808 if ( pCurWin )
810 ::basctl::DocumentSignature aSignature( pCurWin->GetDocument() );
811 nState = aSignature.getScriptingSignatureState();
813 rSet.Put( SfxUInt16Item( SID_SIGNATURE, nState ) );
815 break;
816 case SID_BASICIDE_MODULEDLG:
818 if ( StarBASIC::IsRunning() )
819 rSet.DisableItem( nWh );
821 break;
822 case SID_BASICIDE_CHOOSEMACRO:
823 case SID_BASICIDE_OBJCAT:
824 case SID_BASICIDE_SHOWSBX:
825 case SID_BASICIDE_CREATEMACRO:
826 case SID_BASICIDE_EDITMACRO:
827 case SID_BASICIDE_NAMECHANGEDONTAB:
831 break;
833 case SID_BASICIDE_ADDWATCH:
834 case SID_BASICIDE_REMOVEWATCH:
835 case SID_BASICLOAD:
836 case SID_BASICSAVEAS:
837 case SID_BASICIDE_MATCHGROUP:
839 if ( !pCurWin || !pCurWin->IsA( TYPE( ModulWindow ) ) )
840 rSet.DisableItem( nWh );
841 else if ( ( nWh == SID_BASICLOAD ) && ( StarBASIC::IsRunning() || ( pCurWin && pCurWin->IsReadOnly() ) ) )
842 rSet.DisableItem( nWh );
844 break;
845 case SID_BASICRUN:
846 case SID_BASICSTEPINTO:
847 case SID_BASICSTEPOVER:
848 case SID_BASICSTEPOUT:
849 case SID_BASICIDE_TOGGLEBRKPNT:
850 case SID_BASICIDE_MANAGEBRKPNTS:
852 if ( !pCurWin || !pCurWin->IsA( TYPE( ModulWindow ) ) )
853 rSet.DisableItem( nWh );
854 else if ( StarBASIC::IsRunning() && !((ModulWindow*)pCurWin)->GetBasicStatus().bIsInReschedule )
855 rSet.DisableItem( nWh );
857 break;
858 case SID_BASICCOMPILE:
860 if ( !pCurWin || !pCurWin->IsA( TYPE( ModulWindow ) ) || StarBASIC::IsRunning() )
861 rSet.DisableItem( nWh );
863 break;
864 case SID_BASICSTOP:
866 // Stop immermoeglich, wenn irgendein Basic lauft...
867 if ( !StarBASIC::IsRunning() )
868 rSet.DisableItem( nWh );
870 break;
871 case SID_CHOOSE_CONTROLS:
872 case SID_DIALOG_TESTMODE:
874 if( !pCurWin || !pCurWin->IsA( TYPE( DialogWindow ) ) )
875 rSet.DisableItem( nWh );
877 break;
878 case SID_SHOW_FORMS:
879 case SID_SHOW_HIDDEN:
881 rSet.DisableItem( nWh );
883 break;
884 case SID_SEARCH_OPTIONS:
886 USHORT nOptions = 0;
887 if( pCurWin )
888 nOptions = pCurWin->GetSearchOptions();
889 rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, nOptions ) );
891 break;
892 case SID_BASICIDE_LIBSELECTOR:
894 String aName;
895 if ( m_aCurLibName.Len() )
897 LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName );
898 aName = CreateMgrAndLibStr( m_aCurDocument.getTitle( eLocation ), m_aCurLibName );
900 SfxStringItem aItem( SID_BASICIDE_LIBSELECTOR, aName );
901 rSet.Put( aItem );
903 break;
904 case SID_SEARCH_ITEM:
906 String aSelected = GetSelectionText( TRUE );
907 SvxSearchItem& rItem = IDE_DLL()->GetExtraData()->GetSearchItem();
908 rItem.SetSearchString( aSelected );
909 rSet.Put( rItem );
911 break;
912 case SID_BASICIDE_STAT_DATE:
914 String aDate;
915 aDate = String( RTL_CONSTASCII_USTRINGPARAM( "Datum?!" ) );
916 SfxStringItem aItem( SID_BASICIDE_STAT_DATE, aDate );
917 rSet.Put( aItem );
919 break;
920 case SID_DOC_MODIFIED:
922 String aModifiedMarker;
923 BOOL bModified = FALSE;
925 if ( pCurWin )
927 if ( pCurWin->IsModified() )
928 bModified = TRUE;
929 else
931 ScriptDocument aDocument( pCurWin->GetDocument() );
932 bModified = aDocument.isDocument() ? aDocument.isDocumentModified() : IsAppBasicModified();
936 if ( bModified )
937 aModifiedMarker = '*';
939 SfxStringItem aItem( SID_DOC_MODIFIED, aModifiedMarker );
940 rSet.Put( aItem );
942 break;
943 case SID_BASICIDE_STAT_TITLE:
945 if ( pCurWin )
947 String aTitle = pCurWin->CreateQualifiedName();
948 SfxStringItem aItem( SID_BASICIDE_STAT_TITLE, aTitle );
949 rSet.Put( aItem );
952 break;
953 // Werden vom Controller ausgewertet:
954 case SID_ATTR_SIZE:
955 case SID_ATTR_INSERT:
956 break;
957 case SID_UNDO:
958 case SID_REDO:
960 if( GetUndoManager() ) // sonst rekursives GetState
961 GetViewFrame()->GetSlotState( nWh, NULL, &rSet );
963 break;
964 case SID_SHOW_PROPERTYBROWSER:
966 if ( GetViewFrame()->KnowsChildWindow( nWh ) )
967 rSet.Put( SfxBoolItem( nWh, GetViewFrame()->HasChildWindow( nWh ) ) );
968 else
969 rSet.DisableItem( nWh );
971 break;
973 case SID_BASICIDE_CURRENT_LANG:
975 if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().Len() == 0 )
976 rSet.DisableItem( nWh );
977 else
979 String aItemStr;
980 LocalizationMgr* pCurMgr = GetCurLocalizationMgr();
981 if ( pCurMgr->isLibraryLocalized() )
983 Sequence< lang::Locale > aLocaleSeq = pCurMgr->getStringResourceManager()->getLocales();
984 const lang::Locale* pLocale = aLocaleSeq.getConstArray();
985 INT32 i, nCount = aLocaleSeq.getLength();
987 // Force different results for any combination of locales and default locale
988 ::rtl::OUString aLangStr;
989 for ( i = 0; i <= nCount; ++i )
991 lang::Locale aLocale;
992 if( i < nCount )
993 aLocale = pLocale[i];
994 else
995 aLocale = pCurMgr->getStringResourceManager()->getDefaultLocale();
997 aLangStr += aLocale.Language;
998 aLangStr += aLocale.Country;
999 aLangStr += aLocale.Variant;
1001 aItemStr = aLangStr;
1003 rSet.Put( SfxStringItem( nWh, aItemStr ) );
1006 break;
1008 case SID_BASICIDE_MANAGE_LANG:
1010 if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().Len() == 0 )
1011 rSet.DisableItem( nWh );
1013 break;
1016 if ( pCurWin )
1017 pCurWin->GetState( rSet );
1020 sal_Bool BasicIDEShell::HasUIFeature( sal_uInt32 nFeature )
1022 sal_Bool bResult = sal_False;
1024 if ( (nFeature & BASICIDE_UI_FEATURE_SHOW_BROWSER) == BASICIDE_UI_FEATURE_SHOW_BROWSER )
1026 // fade out (in) property browser in module (dialog) windows
1027 if ( pCurWin && pCurWin->IsA( TYPE( DialogWindow ) ) && !pCurWin->IsReadOnly() )
1028 bResult = sal_True;
1031 return bResult;
1034 void BasicIDEShell::SetCurWindow( IDEBaseWindow* pNewWin, BOOL bUpdateTabBar, BOOL bRememberAsCurrent )
1036 // Es muss ein EditWindow am Sfx gesetzt sein, sonst kommt kein
1037 // Resize, also stehen die Controls auf den Wiese...
1038 // Sieht dann sowieso besser aus, wenn das Modul-Layout angezeigt wird...
1039 if ( !pNewWin && ( GetWindow() != pModulLayout ) )
1041 pModulLayout->Show();
1042 AdjustPosSizePixel( Point( 0, 0 ), GetViewFrame()->GetWindow().GetOutputSizePixel() );
1043 SetWindow( pModulLayout );
1044 EnableScrollbars( FALSE );
1045 aVScrollBar.Hide();
1048 if ( pNewWin != pCurWin )
1050 IDEBaseWindow* pPrevCurWin = pCurWin;
1051 pCurWin = pNewWin;
1052 if ( pPrevCurWin )
1054 pPrevCurWin->Hide();
1055 pPrevCurWin->Deactivating();
1056 // pPrevCurWin->GetLayoutWindow()->Hide();
1057 if( pPrevCurWin->IsA( TYPE( DialogWindow ) ) )
1059 ((DialogWindow*)pPrevCurWin)->DisableBrowser();
1061 else
1063 pModulLayout->SetModulWindow( NULL );
1066 if ( pCurWin )
1068 AdjustPosSizePixel( Point( 0, 0 ), GetViewFrame()->GetWindow().GetOutputSizePixel() );
1069 if( pCurWin->IsA( TYPE( ModulWindow ) ) )
1071 GetViewFrame()->GetWindow().SetHelpId( HID_BASICIDE_MODULWINDOW );
1072 pModulLayout->SetModulWindow( (ModulWindow*)pCurWin );
1073 pModulLayout->Show();
1075 else
1077 pModulLayout->Hide();
1078 GetViewFrame()->GetWindow().SetHelpId( HID_BASICIDE_DIALOGWINDOW );
1081 if ( bRememberAsCurrent )
1083 BasicIDEData* pData = IDE_DLL()->GetExtraData();
1084 if ( pData )
1086 USHORT nCurrentType = pCurWin->IsA( TYPE( ModulWindow ) ) ? BASICIDE_TYPE_MODULE : BASICIDE_TYPE_DIALOG;
1087 LibInfoItem* pLibInfoItem = new LibInfoItem( pCurWin->GetDocument(), pCurWin->GetLibName(), pCurWin->GetName(), nCurrentType );
1088 pData->GetLibInfos().InsertInfo( pLibInfoItem );
1092 if ( GetViewFrame()->GetWindow().IsVisible() ) // sonst macht es spaeter der SFX
1093 pCurWin->Show();
1095 pCurWin->Init();
1097 if ( !IDE_DLL()->GetExtraData()->ShellInCriticalSection() )
1099 Window* pFrameWindow = &GetViewFrame()->GetWindow();
1100 Window* pFocusWindow = Application::GetFocusWindow();
1101 while ( pFocusWindow && ( pFocusWindow != pFrameWindow ) )
1102 pFocusWindow = pFocusWindow->GetParent();
1103 if ( pFocusWindow ) // Focus in BasicIDE
1104 pNewWin->GrabFocus();
1106 if( pCurWin->IsA( TYPE( DialogWindow ) ) )
1107 ((DialogWindow*)pCurWin)->UpdateBrowser();
1109 if ( bUpdateTabBar )
1111 ULONG nKey = aIDEWindowTable.GetKey( pCurWin );
1112 if ( pCurWin && ( pTabBar->GetPagePos( (USHORT)nKey ) == TAB_PAGE_NOTFOUND ) )
1113 pTabBar->InsertPage( (USHORT)nKey, pCurWin->GetTitle() ); // wurde neu eingeblendet
1114 pTabBar->SetCurPageId( (USHORT)nKey );
1116 if ( pCurWin && pCurWin->IsSuspended() ) // Wenn das Fenster im Fehlerfall angezeigt wird...
1117 pCurWin->SetStatus( pCurWin->GetStatus() & ~BASWIN_SUSPENDED );
1118 if ( pCurWin )
1120 SetWindow( pCurWin );
1121 if ( pCurWin->GetDocument().isDocument() )
1122 SfxObjectShell::SetCurrentComponent( pCurWin->GetDocument().getDocument() );
1124 else
1126 SetWindow( pModulLayout );
1127 GetViewFrame()->GetWindow().SetHelpId( HID_BASICIDE_MODULWINDOW );
1128 SfxObjectShell::SetCurrentComponent( NULL );
1130 SetUndoManager( pCurWin ? pCurWin->GetUndoManager() : 0 );
1131 InvalidateBasicIDESlots();
1132 EnableScrollbars( pCurWin ? TRUE : FALSE );
1134 if ( m_pCurLocalizationMgr )
1135 m_pCurLocalizationMgr->handleTranslationbar();
1137 ManageToolbars();
1139 // fade out (in) property browser in module (dialog) windows
1140 UIFeatureChanged();
1144 void BasicIDEShell::ManageToolbars()
1146 static ::rtl::OUString aLayoutManagerName = ::rtl::OUString::createFromAscii( "LayoutManager" );
1147 static ::rtl::OUString aMacroBarResName =
1148 ::rtl::OUString::createFromAscii( "private:resource/toolbar/macrobar" );
1149 static ::rtl::OUString aDialogBarResName =
1150 ::rtl::OUString::createFromAscii( "private:resource/toolbar/dialogbar" );
1151 static ::rtl::OUString aInsertControlsBarResName =
1152 ::rtl::OUString::createFromAscii( "private:resource/toolbar/insertcontrolsbar" );
1153 (void)aInsertControlsBarResName;
1155 if( !pCurWin )
1156 return;
1158 Reference< beans::XPropertySet > xFrameProps
1159 ( GetViewFrame()->GetFrame()->GetFrameInterface(), uno::UNO_QUERY );
1160 if ( xFrameProps.is() )
1162 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
1163 uno::Any a = xFrameProps->getPropertyValue( aLayoutManagerName );
1164 a >>= xLayoutManager;
1165 if ( xLayoutManager.is() )
1167 xLayoutManager->lock();
1168 if( pCurWin->IsA( TYPE( DialogWindow ) ) )
1170 xLayoutManager->destroyElement( aMacroBarResName );
1172 xLayoutManager->requestElement( aDialogBarResName );
1173 xLayoutManager->requestElement( aInsertControlsBarResName );
1175 else
1177 xLayoutManager->destroyElement( aDialogBarResName );
1178 xLayoutManager->destroyElement( aInsertControlsBarResName );
1180 xLayoutManager->requestElement( aMacroBarResName );
1182 xLayoutManager->unlock();
1187 IDEBaseWindow* BasicIDEShell::FindApplicationWindow()
1189 return FindWindow( ScriptDocument::getApplicationScriptDocument() );
1192 IDEBaseWindow* BasicIDEShell::FindWindow( const ScriptDocument& rDocument, const String& rLibName, const String& rName, USHORT nType, BOOL bFindSuspended )
1194 IDEBaseWindow* pWin = aIDEWindowTable.First();
1195 while ( pWin )
1197 if ( !pWin->IsSuspended() || bFindSuspended )
1199 if ( !rLibName.Len() || !rName.Len() || nType == BASICIDE_TYPE_UNKNOWN )
1201 // return any non-suspended window
1202 return pWin;
1204 else if ( pWin->IsDocument( rDocument ) )
1206 OSL_TRACE("FindWindow pWin->GetLibName() %s rLibName %s",
1207 rtl::OUStringToOString( pWin->GetLibName(), RTL_TEXTENCODING_UTF8 ).getStr(),
1208 rtl::OUStringToOString( rLibName, RTL_TEXTENCODING_UTF8 ).getStr() );
1209 OSL_TRACE("pWin->pWin->IsA( TYPE( ModulWindow ) %d && nType %d = BASICIDE_TYPE_MODULE %d", pWin->IsA( TYPE( ModulWindow ) ), nType, BASICIDE_TYPE_MODULE );
1210 OSL_TRACE("pWin->pWin->IsA( TYPE( DialogWindow ) %d && nType %d = BASICIDE_TYPE_DIALOG %d", pWin->IsA( TYPE( DialogWindow ) ), nType, BASICIDE_TYPE_DIALOG );
1211 if ( pWin->GetLibName() == rLibName && pWin->GetName() == rName &&
1212 ( ( pWin->IsA( TYPE( ModulWindow ) ) && nType == BASICIDE_TYPE_MODULE ) ||
1213 ( pWin->IsA( TYPE( DialogWindow ) ) && nType == BASICIDE_TYPE_DIALOG ) ) )
1214 return pWin;
1217 pWin = aIDEWindowTable.Next();
1219 return 0;
1222 long BasicIDEShell::CallBasicErrorHdl( StarBASIC* pBasic )
1224 long nRet = 0;
1225 ModulWindow* pModWin = ShowActiveModuleWindow( pBasic );
1226 if ( pModWin )
1227 nRet = pModWin->BasicErrorHdl( pBasic );
1228 return nRet;
1231 long BasicIDEShell::CallBasicBreakHdl( StarBASIC* pBasic )
1233 long nRet = 0;
1234 ModulWindow* pModWin = ShowActiveModuleWindow( pBasic );
1235 if ( pModWin )
1237 BOOL bAppWindowDisabled, bDispatcherLocked;
1238 USHORT nWaitCount;
1239 SfxUInt16Item *pSWActionCount, *pSWLockViewCount;
1240 BasicIDE::BasicStopped( &bAppWindowDisabled, &bDispatcherLocked,
1241 &nWaitCount, &pSWActionCount, &pSWLockViewCount );
1243 nRet = pModWin->BasicBreakHdl( pBasic );
1245 if ( StarBASIC::IsRunning() ) // Falls abgebrochen...
1247 if ( bAppWindowDisabled )
1248 Application::GetDefDialogParent()->Enable( FALSE );
1250 if ( bDispatcherLocked )
1251 SFX_APP()->LockDispatcher( TRUE );
1253 if ( nWaitCount )
1255 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
1256 for ( USHORT n = 0; n < nWaitCount; n++ )
1257 pIDEShell->GetViewFrame()->GetWindow().EnterWait();
1261 return nRet;
1264 ModulWindow* BasicIDEShell::ShowActiveModuleWindow( StarBASIC* pBasic )
1266 SetCurLib( ScriptDocument::getApplicationScriptDocument(), String(), false );
1268 SbModule* pActiveModule = StarBASIC::GetActiveModule();
1269 SbClassModuleObject* pClassModuleObject = PTR_CAST(SbClassModuleObject,pActiveModule);
1270 if( pClassModuleObject != NULL )
1271 pActiveModule = pClassModuleObject->getClassModule();
1273 DBG_ASSERT( pActiveModule, "Kein aktives Modul im ErrorHdl?!" );
1274 if ( pActiveModule )
1276 ModulWindow* pWin = 0;
1277 SbxObject* pParent = pActiveModule->GetParent();
1278 DBG_ASSERT( pParent && pParent->ISA( StarBASIC ), "Kein BASIC!" );
1279 StarBASIC* pLib = static_cast< StarBASIC* >( pParent );
1280 if ( pLib )
1282 BasicManager* pBasMgr = BasicIDE::FindBasicManager( pLib );
1283 if ( pBasMgr )
1285 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
1286 String aLibName = pLib->GetName();
1287 pWin = FindBasWin( aDocument, aLibName, pActiveModule->GetName(), TRUE );
1288 DBG_ASSERT( pWin, "Error/Step-Hdl: Fenster wurde nicht erzeugt/gefunden!" );
1289 SetCurLib( aDocument, aLibName );
1290 SetCurWindow( pWin, TRUE );
1293 BasicManager* pBasicMgr = BasicIDE::FindBasicManager( pBasic );
1294 if ( pBasicMgr )
1295 StartListening( *pBasicMgr, TRUE /* Nur einmal anmelden */ );
1296 return pWin;
1298 return 0;
1301 void __EXPORT BasicIDEShell::AdjustPosSizePixel( const Point &rPos, const Size &rSize )
1303 // Nicht wenn minimiert, weil dann bei Restore der Text verschoben ist.
1304 if ( GetViewFrame()->GetWindow().GetOutputSizePixel().Height() == 0 )
1305 return;
1307 Size aSz( rSize );
1308 // long nScrollbarWidthPixel = aVScrollBar.GetSizePixel().Width();
1309 Size aScrollBarBoxSz( aScrollBarBox.GetSizePixel() );
1310 aSz.Height() -= aScrollBarBoxSz.Height();
1312 Size aOutSz( aSz );
1313 aSz.Width() -= aScrollBarBoxSz.Width();
1314 aScrollBarBox.SetPosPixel( Point( rSize.Width() - aScrollBarBoxSz.Width(), rSize.Height() - aScrollBarBoxSz.Height() ) );
1315 aVScrollBar.SetPosSizePixel( Point( rPos.X()+aSz.Width(), rPos.Y() ), Size( aScrollBarBoxSz.Width(), aSz.Height() ) );
1316 if ( bTabBarSplitted )
1318 // SplitSize ist beim Resize 0 !
1319 long nSplitPos = pTabBar->GetSizePixel().Width();
1320 if ( nSplitPos > aSz.Width() )
1321 nSplitPos = aSz.Width();
1322 pTabBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aSz.Height() ), Size( nSplitPos, aScrollBarBoxSz.Height() ) );
1323 long nScrlStart = rPos.X() + nSplitPos;
1324 aHScrollBar.SetPosSizePixel( Point( nScrlStart, rPos.Y()+aSz.Height() ), Size( aSz.Width() - nScrlStart + 1, aScrollBarBoxSz.Height() ) );
1325 aHScrollBar.Update();
1327 else
1329 aHScrollBar.SetPosSizePixel( Point( rPos.X()+ aSz.Width()/2 - 1, rPos.Y()+aSz.Height() ), Size( aSz.Width()/2 + 2, aScrollBarBoxSz.Height() ) );
1330 pTabBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aSz.Height() ), Size( aSz.Width()/2, aScrollBarBoxSz.Height() ) );
1333 Window* pEdtWin = pCurWin ? pCurWin->GetLayoutWindow() : pModulLayout;
1334 if ( pEdtWin )
1336 if( pCurWin && pCurWin->IsA( TYPE( DialogWindow ) ) )
1337 pEdtWin->SetPosSizePixel( rPos, aSz ); // Ohne ScrollBar
1338 else
1339 pEdtWin->SetPosSizePixel( rPos, aOutSz );
1343 Reference< XModel > BasicIDEShell::GetCurrentDocument() const
1345 Reference< XModel > xDocument;
1346 if ( pCurWin && pCurWin->GetDocument().isDocument() )
1347 xDocument = pCurWin->GetDocument().getDocument();
1348 return xDocument;
1351 void __EXPORT BasicIDEShell::Activate( BOOL bMDI )
1353 SfxViewShell::Activate( bMDI );
1355 if ( bMDI )
1357 if( pCurWin && pCurWin->IsA( TYPE( DialogWindow ) ) )
1358 ((DialogWindow*)pCurWin)->UpdateBrowser();
1360 ShowObjectDialog( TRUE, FALSE );
1364 void __EXPORT BasicIDEShell::Deactivate( BOOL bMDI )
1366 // bMDI TRUE heisst, dass ein anderes MDI aktiviert wurde, bei einem
1367 // Deactivate durch eine MessageBox ist bMDI FALSE
1368 if ( bMDI )
1370 if( pCurWin && pCurWin->IsA( TYPE( DialogWindow ) ) )
1372 DialogWindow* pXDlgWin = (DialogWindow*)pCurWin;
1373 pXDlgWin->DisableBrowser();
1374 if( pXDlgWin->IsModified() )
1375 BasicIDE::MarkDocumentModified( pXDlgWin->GetDocument() );
1378 // CanClose pruefen, damit auch beim deaktivieren der BasicIDE geprueft wird,
1379 // ob in einem Modul der Sourcecode zu gross ist...
1380 for ( ULONG nWin = 0; nWin < aIDEWindowTable.Count(); nWin++ )
1382 IDEBaseWindow* pWin = aIDEWindowTable.GetObject( nWin );
1383 if ( /* !pWin->IsSuspended() && */ !pWin->CanClose() )
1385 if ( m_aCurLibName.Len() && ( pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName ) )
1386 SetCurLib( ScriptDocument::getApplicationScriptDocument(), String(), false );
1387 SetCurWindow( pWin, TRUE );
1388 break;
1392 ShowObjectDialog( FALSE, FALSE );
1397 IMPL_LINK( BasicIDEShell, AccelSelectHdl, Accelerator*, pAccel )
1399 BOOL bDone = TRUE;
1400 SfxViewFrame* pViewFrame = GetViewFrame();
1401 SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
1402 if( !pDispatcher )
1403 return FALSE;
1404 switch ( pAccel->GetCurKeyCode().GetCode() )
1406 case KEY_F5:
1407 if ( pAccel->GetCurKeyCode().IsShift() )
1408 pDispatcher->Execute( SID_BASICSTOP, SFX_CALLMODE_SYNCHRON );
1409 else
1410 pDispatcher->Execute( SID_BASICRUN, SFX_CALLMODE_SYNCHRON );
1411 break;
1412 case KEY_F7:
1413 pDispatcher->Execute( SID_BASICIDE_ADDWATCH, SFX_CALLMODE_SYNCHRON );
1414 break;
1415 case KEY_F8:
1416 if ( pAccel->GetCurKeyCode().IsShift() )
1417 pDispatcher->Execute( SID_BASICSTEPOVER, SFX_CALLMODE_SYNCHRON );
1418 else
1419 pDispatcher->Execute( SID_BASICSTEPINTO, SFX_CALLMODE_SYNCHRON );
1420 break;
1421 case KEY_F9:
1422 if ( pAccel->GetCurKeyCode().IsShift() )
1423 pDispatcher->Execute( SID_BASICIDE_TOGGLEBRKPNTENABLED, SFX_CALLMODE_SYNCHRON );
1424 else
1425 pDispatcher->Execute( SID_BASICIDE_TOGGLEBRKPNT, SFX_CALLMODE_SYNCHRON );
1426 break;
1427 default: bDone = FALSE;
1429 return bDone;