Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / basctl / source / basicide / basides1.cxx
blobda1c86f1872dc8d75924a80cbf5f260671063d34
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <memory>
21 #include <strings.hrc>
22 #include <helpids.h>
24 #include "baside2.hxx"
25 #include <baside3.hxx>
26 #include <docsignature.hxx>
27 #include <iderdll.hxx>
28 #include "iderdll2.hxx"
29 #include <localizationmgr.hxx>
30 #include <managelang.hxx>
32 #include <basic/basmgr.hxx>
33 #include <basic/sbmeth.hxx>
34 #include <com/sun/star/script/ModuleType.hpp>
35 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
36 #include <com/sun/star/frame/XLayoutManager.hpp>
37 #include <sfx2/childwin.hxx>
38 #include <sfx2/docfac.hxx>
39 #include <sfx2/dinfdlg.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <sfx2/minfitem.hxx>
42 #include <sfx2/printer.hxx>
43 #include <sfx2/request.hxx>
44 #include <svx/svxids.hrc>
45 #include <svl/aeitem.hxx>
46 #include <svl/intitem.hxx>
47 #include <svl/visitem.hxx>
48 #include <svl/whiter.hxx>
49 #include <vcl/xtextedt.hxx>
50 #include <vcl/svapp.hxx>
51 #include <vcl/weld.hxx>
53 namespace basctl
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::frame;
60 void Shell::ExecuteSearch( SfxRequest& rReq )
62 if ( !pCurWin )
63 return;
65 const SfxItemSet* pArgs = rReq.GetArgs();
66 sal_uInt16 nSlot = rReq.GetSlot();
68 // if searching has not been done before this time
69 if (nSlot == SID_BASICIDE_REPEAT_SEARCH && !mpSearchItem)
71 rReq.SetReturnValue(SfxBoolItem(nSlot, false));
72 nSlot = 0;
75 switch ( nSlot )
77 case SID_SEARCH_OPTIONS:
78 break;
79 case SID_SEARCH_ITEM:
80 mpSearchItem.reset( static_cast<SvxSearchItem*>( pArgs->Get(SID_SEARCH_ITEM).Clone() ));
81 break;
82 case FID_SEARCH_ON:
83 mbJustOpened = true;
84 GetViewFrame()->GetBindings().Invalidate(SID_SEARCH_ITEM);
85 break;
86 case SID_BASICIDE_REPEAT_SEARCH:
87 case FID_SEARCH_NOW:
89 if (!pCurWin->HasActiveEditor())
90 break;
92 // If it is a repeat searching
93 if ( nSlot == SID_BASICIDE_REPEAT_SEARCH )
95 if( !mpSearchItem )
96 mpSearchItem.reset( new SvxSearchItem( SID_SEARCH_ITEM ));
98 else
100 // Get SearchItem from request if it is the first searching
101 if ( pArgs )
103 mpSearchItem.reset( static_cast<SvxSearchItem*>( pArgs->Get( SID_SEARCH_ITEM ).Clone() ));
107 sal_Int32 nFound = 0;
109 if ( mpSearchItem->GetCommand() == SvxSearchCmd::REPLACE_ALL )
111 sal_uInt16 nActModWindows = 0;
112 for (auto const& window : aWindowTable)
114 BaseWindow* pWin = window.second;
115 if (pWin->HasActiveEditor())
116 nActModWindows++;
119 bool bAllModules = nActModWindows <= 1;
120 if (!bAllModules)
122 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pCurWin ? pCurWin->GetFrameWeld() : nullptr,
123 VclMessageType::Question, VclButtonsType::YesNo,
124 IDEResId(RID_STR_SEARCHALLMODULES)));
125 xQueryBox->set_default_response(RET_YES);
126 bAllModules = xQueryBox->run() == RET_YES;
129 if (bAllModules)
131 for (auto const& window : aWindowTable)
133 BaseWindow* pWin = window.second;
134 nFound += pWin->StartSearchAndReplace( *mpSearchItem );
137 else
138 nFound = pCurWin->StartSearchAndReplace( *mpSearchItem );
140 OUString aReplStr(IDEResId(RID_STR_SEARCHREPLACES));
141 aReplStr = aReplStr.replaceAll("XX", OUString::number(nFound));
143 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pCurWin->GetFrameWeld(),
144 VclMessageType::Info, VclButtonsType::Ok,
145 aReplStr));
146 xInfoBox->run();
148 else
150 bool bCanceled = false;
151 nFound = pCurWin->StartSearchAndReplace( *mpSearchItem );
152 if ( !nFound && !mpSearchItem->GetSelection() )
154 // search other modules...
155 bool bChangeCurWindow = false;
156 WindowTableIt it;
157 for (it = aWindowTable.begin(); it != aWindowTable.end(); ++it)
158 if (it->second == pCurWin)
159 break;
160 if (it != aWindowTable.end())
161 ++it;
162 BaseWindow* pWin = it != aWindowTable.end() ? it->second.get() : nullptr;
164 bool bSearchedFromStart = false;
165 while ( !nFound && !bCanceled && ( pWin || !bSearchedFromStart ) )
167 if ( !pWin )
169 SfxViewFrame* pViewFrame = GetViewFrame();
170 SfxChildWindow* pChildWin = pViewFrame ? pViewFrame->GetChildWindow( SID_SEARCH_DLG ) : nullptr;
171 vcl::Window* pParent = pChildWin ? pChildWin->GetWindow() : nullptr;
173 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pParent ? pParent->GetFrameWeld() : nullptr,
174 VclMessageType::Question, VclButtonsType::YesNo,
175 IDEResId(RID_STR_SEARCHFROMSTART)));
176 xQueryBox->set_default_response(RET_YES);
177 if (xQueryBox->run() == RET_YES)
179 it = aWindowTable.begin();
180 if ( it != aWindowTable.end() )
181 pWin = it->second;
182 bSearchedFromStart = true;
184 else
185 bCanceled = true;
188 if (pWin && pWin->HasActiveEditor())
190 if ( pWin != pCurWin )
192 if ( pCurWin )
193 pWin->SetSizePixel( pCurWin->GetSizePixel() );
194 nFound = pWin->StartSearchAndReplace( *mpSearchItem, true );
196 if ( nFound )
198 bChangeCurWindow = true;
199 break;
202 if ( pWin && ( pWin != pCurWin ) )
204 if ( it != aWindowTable.end() )
205 ++it;
206 pWin = it != aWindowTable.end() ? it->second.get() : nullptr;
208 else
209 pWin = nullptr;
211 if ( !nFound && bSearchedFromStart )
212 nFound = pCurWin->StartSearchAndReplace( *mpSearchItem, true );
213 if ( bChangeCurWindow )
214 SetCurWindow( pWin, true );
216 if ( !nFound && !bCanceled )
218 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pCurWin->GetFrameWeld(),
219 VclMessageType::Info, VclButtonsType::Ok,
220 IDEResId(RID_STR_SEARCHNOTFOUND)));
221 xInfoBox->run();
225 rReq.Done();
226 break;
228 default:
229 pCurWin->ExecuteCommand( rReq );
233 void Shell::ExecuteCurrent( SfxRequest& rReq )
235 if ( !pCurWin )
236 return;
238 switch ( rReq.GetSlot() )
240 case SID_BASICIDE_HIDECURPAGE:
242 pCurWin->StoreData();
243 RemoveWindow( pCurWin, false );
245 break;
246 case SID_BASICIDE_RENAMECURRENT:
248 pTabBar->StartEditMode( pTabBar->GetCurPageId() );
250 break;
251 case SID_UNDO:
252 case SID_REDO:
253 if ( GetUndoManager() && pCurWin->AllowUndo() )
254 GetViewFrame()->ExecuteSlot( rReq );
255 break;
256 default:
257 pCurWin->ExecuteCommand( rReq );
261 // no matter who's at the top, influence on the shell:
262 void Shell::ExecuteGlobal( SfxRequest& rReq )
264 sal_uInt16 nSlot = rReq.GetSlot();
265 switch ( nSlot )
267 case SID_BASICSTOP:
269 // maybe do not simply stop if on breakpoint!
270 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
271 pMCurWin->BasicStop();
272 StopBasic();
274 break;
276 case SID_SAVEDOC:
278 if ( pCurWin )
280 // rewrite date into the BASIC
281 StoreAllWindowData();
283 // document basic
284 ScriptDocument aDocument( pCurWin->GetDocument() );
285 if ( aDocument.isDocument() )
287 uno::Reference< task::XStatusIndicator > xStatusIndicator;
289 const SfxUnoAnyItem* pStatusIndicatorItem = rReq.GetArg<SfxUnoAnyItem>(SID_PROGRESS_STATUSBAR_CONTROL);
290 if ( pStatusIndicatorItem )
291 OSL_VERIFY( pStatusIndicatorItem->GetValue() >>= xStatusIndicator );
292 else
294 // get statusindicator
295 SfxViewFrame *pFrame_ = GetFrame();
296 if ( pFrame_ )
298 uno::Reference< task::XStatusIndicatorFactory > xStatFactory(
299 pFrame_->GetFrame().GetFrameInterface(),
300 uno::UNO_QUERY );
301 if( xStatFactory.is() )
302 xStatusIndicator = xStatFactory->createStatusIndicator();
305 if ( xStatusIndicator.is() )
306 rReq.AppendItem( SfxUnoAnyItem( SID_PROGRESS_STATUSBAR_CONTROL, uno::Any( xStatusIndicator ) ) );
309 aDocument.saveDocument( xStatusIndicator );
312 if (SfxBindings* pBindings = GetBindingsPtr())
314 pBindings->Invalidate( SID_DOC_MODIFIED );
315 pBindings->Invalidate( SID_SAVEDOC );
316 pBindings->Invalidate( SID_SIGNATURE );
320 break;
321 case SID_BASICIDE_MODULEDLG:
323 if ( rReq.GetArgs() )
325 const SfxUInt16Item &rTabId = rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
326 Organize( rTabId.GetValue() );
328 else
329 Organize( 0 );
331 break;
332 case SID_BASICIDE_CHOOSEMACRO:
334 ChooseMacro( nullptr );
336 break;
337 case SID_BASICIDE_CREATEMACRO:
338 case SID_BASICIDE_EDITMACRO:
340 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
341 const SfxMacroInfoItem& rInfo = rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
342 BasicManager* pBasMgr = const_cast<BasicManager*>(rInfo.GetBasicManager());
343 DBG_ASSERT( pBasMgr, "Nothing selected in basic tree?" );
345 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
347 StartListening(*pBasMgr, DuplicateHandling::Prevent /* log on only once */);
348 OUString aLibName( rInfo.GetLib() );
349 if ( aLibName.isEmpty() )
350 aLibName = "Standard" ;
351 StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
352 if ( !pBasic )
354 // load module and dialog library (if not loaded)
355 aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
356 aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
358 // get Basic
359 pBasic = pBasMgr->GetLib( aLibName );
361 DBG_ASSERT( pBasic, "No Basic!" );
363 SetCurLib( aDocument, aLibName );
365 if ( pBasic && rReq.GetSlot() == SID_BASICIDE_CREATEMACRO )
367 SbModule* pModule = pBasic->FindModule( rInfo.GetModule() );
368 if ( !pModule )
370 if ( !rInfo.GetModule().isEmpty() || pBasic->GetModules().empty() )
372 const OUString& aModName = rInfo.GetModule();
374 OUString sModuleCode;
375 if ( aDocument.createModule( aLibName, aModName, false, sModuleCode ) )
376 pModule = pBasic->FindModule( aModName );
378 else
379 pModule = pBasic->GetModules().front().get();
381 DBG_ASSERT( pModule, "No Module!" );
382 if ( pModule && !pModule->GetMethods()->Find( rInfo.GetMethod(), SbxClassType::Method ) )
383 CreateMacro( pModule, rInfo.GetMethod() );
385 SfxViewFrame* pViewFrame = GetViewFrame();
386 if ( pViewFrame )
387 pViewFrame->ToTop();
388 VclPtr<ModulWindow> pWin = FindBasWin( aDocument, aLibName, rInfo.GetModule(), true );
389 DBG_ASSERT( pWin, "Edit/Create Macro: Window was not created/found!" );
390 SetCurWindow( pWin, true );
391 pWin->EditMacro( rInfo.GetMethod() );
393 break;
395 case SID_BASICIDE_OBJCAT:
396 // toggling object catalog
397 aObjectCatalog->Show(!aObjectCatalog->IsVisible());
398 if (pLayout)
399 pLayout->ArrangeWindows();
400 // refresh the button state
401 if (SfxBindings* pBindings = GetBindingsPtr())
402 pBindings->Invalidate(SID_BASICIDE_OBJCAT);
403 break;
405 case SID_BASICIDE_NAMECHANGEDONTAB:
407 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
408 const SfxUInt16Item &rTabId = rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
409 const SfxStringItem &rModName = rReq.GetArgs()->Get(SID_BASICIDE_ARG_MODULENAME );
410 if ( aWindowTable.find( rTabId.GetValue() ) != aWindowTable.end() )
412 VclPtr<BaseWindow> pWin = aWindowTable[ rTabId.GetValue() ];
413 const OUString& aNewName( rModName.GetValue() );
414 OUString aOldName( pWin->GetName() );
415 if ( aNewName != aOldName )
417 bool bRenameOk = false;
418 if (ModulWindow* pModWin = dynamic_cast<ModulWindow*>(pWin.get()))
420 OUString aLibName = pModWin->GetLibName();
421 ScriptDocument aDocument( pWin->GetDocument() );
423 if (RenameModule(pModWin->GetFrameWeld(), aDocument, aLibName, aOldName, aNewName))
425 bRenameOk = true;
426 // Because we listen for container events for script
427 // modules, rename will delete the 'old' window
428 // pWin has been invalidated, restore now
429 pWin = FindBasWin( aDocument, aLibName, aNewName, true );
433 else if (DialogWindow* pDlgWin = dynamic_cast<DialogWindow*>(pWin.get()))
435 bRenameOk = pDlgWin->RenameDialog( aNewName );
437 if ( bRenameOk )
439 MarkDocumentModified( pWin->GetDocument() );
441 else
443 // set old name in TabWriter
444 sal_uInt16 nId = GetWindowId( pWin );
445 DBG_ASSERT( nId, "No entry in Tabbar!" );
446 if ( nId )
447 pTabBar->SetPageText( nId, aOldName );
451 // set focus to current window
452 pWin->GrabFocus();
455 break;
456 case SID_BASICIDE_STOREMODULESOURCE:
457 case SID_BASICIDE_UPDATEMODULESOURCE:
459 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
460 const SfxMacroInfoItem& rInfo = rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
461 BasicManager* pBasMgr = const_cast<BasicManager*>(rInfo.GetBasicManager());
462 DBG_ASSERT( pBasMgr, "Store source: No BasMgr?" );
463 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
464 VclPtr<ModulWindow> pWin = FindBasWin( aDocument, rInfo.GetLib(), rInfo.GetModule(), false, true );
465 if ( pWin )
467 if ( rReq.GetSlot() == SID_BASICIDE_STOREMODULESOURCE )
468 pWin->StoreData();
469 else
470 pWin->UpdateData();
473 break;
474 case SID_BASICIDE_STOREALLMODULESOURCES:
475 case SID_BASICIDE_UPDATEALLMODULESOURCES:
477 for (auto const& window : aWindowTable)
479 BaseWindow* pWin = window.second;
480 if (!pWin->IsSuspended() && dynamic_cast<ModulWindow*>(pWin))
482 if ( rReq.GetSlot() == SID_BASICIDE_STOREALLMODULESOURCES )
483 pWin->StoreData();
484 else
485 pWin->UpdateData();
489 break;
490 case SID_BASICIDE_LIBSELECTED:
491 case SID_BASICIDE_LIBREMOVED:
492 case SID_BASICIDE_LIBLOADED:
494 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
495 const SfxUnoAnyItem& rShellItem = rReq.GetArgs()->Get( SID_BASICIDE_ARG_DOCUMENT_MODEL );
496 uno::Reference< frame::XModel > xModel( rShellItem.GetValue(), UNO_QUERY );
497 ScriptDocument aDocument( xModel.is() ? ScriptDocument( xModel ) : ScriptDocument::getApplicationScriptDocument() );
498 const SfxStringItem& rLibNameItem = rReq.GetArgs()->Get( SID_BASICIDE_ARG_LIBNAME );
499 const OUString& aLibName( rLibNameItem.GetValue() );
501 if ( nSlot == SID_BASICIDE_LIBSELECTED )
503 // load module and dialog library (if not loaded)
504 aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
505 aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
507 // check password, if library is password protected and not verified
508 bool bOK = true;
509 Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ) );
510 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
512 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
513 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
515 OUString aPassword;
516 bOK = QueryPassword( xModLibContainer, aLibName, aPassword );
520 if ( bOK )
522 SetCurLib( aDocument, aLibName, true, false );
524 else
526 // adjust old value...
527 if (SfxBindings* pBindings = GetBindingsPtr())
528 pBindings->Invalidate(SID_BASICIDE_LIBSELECTOR, true);
531 else if ( nSlot == SID_BASICIDE_LIBREMOVED )
533 if ( m_aCurLibName.isEmpty() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
535 RemoveWindows( aDocument, aLibName );
536 if ( aDocument == m_aCurDocument && aLibName == m_aCurLibName )
538 m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
539 m_aCurLibName.clear();
540 // no UpdateWindows!
541 if (SfxBindings* pBindings = GetBindingsPtr())
542 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
546 else // Loaded...
547 UpdateWindows();
549 break;
550 case SID_BASICIDE_NEWMODULE:
552 VclPtr<ModulWindow> pWin = CreateBasWin( m_aCurDocument, m_aCurLibName, OUString() );
553 DBG_ASSERT( pWin, "New Module: Could not create window!" );
554 SetCurWindow( pWin, true );
556 break;
557 case SID_BASICIDE_NEWDIALOG:
559 VclPtr<DialogWindow> pWin = CreateDlgWin( m_aCurDocument, m_aCurLibName, OUString() );
560 DBG_ASSERT( pWin, "New Module: Could not create window!" );
561 SetCurWindow( pWin, true );
563 break;
564 case SID_BASICIDE_SBXRENAMED:
566 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
568 break;
569 case SID_BASICIDE_SBXINSERTED:
571 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
572 const SbxItem& rSbxItem = rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
573 const ScriptDocument& aDocument( rSbxItem.GetDocument() );
574 const OUString& aLibName( rSbxItem.GetLibName() );
575 const OUString& aName( rSbxItem.GetName() );
576 if ( m_aCurLibName.isEmpty() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
578 if ( rSbxItem.GetType() == TYPE_MODULE )
579 FindBasWin( aDocument, aLibName, aName, true );
580 else if ( rSbxItem.GetType() == TYPE_DIALOG )
581 FindDlgWin( aDocument, aLibName, aName, true );
584 break;
585 case SID_BASICIDE_SBXDELETED:
587 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
588 const SbxItem& rSbxItem = rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
589 const ScriptDocument& aDocument( rSbxItem.GetDocument() );
590 VclPtr<BaseWindow> pWin = FindWindow( aDocument, rSbxItem.GetLibName(), rSbxItem.GetName(), rSbxItem.GetType(), true );
591 if ( pWin )
592 RemoveWindow( pWin, true );
594 break;
595 case SID_BASICIDE_SHOWSBX:
597 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
598 const SbxItem& rSbxItem = rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
599 const ScriptDocument& aDocument( rSbxItem.GetDocument() );
600 const OUString& aLibName( rSbxItem.GetLibName() );
601 const OUString& aName( rSbxItem.GetName() );
602 SetCurLib( aDocument, aLibName );
603 BaseWindow* pWin = nullptr;
604 if ( rSbxItem.GetType() == TYPE_DIALOG )
606 pWin = FindDlgWin( aDocument, aLibName, aName, true );
608 else if ( rSbxItem.GetType() == TYPE_MODULE )
610 pWin = FindBasWin( aDocument, aLibName, aName, true );
612 else if ( rSbxItem.GetType() == TYPE_METHOD )
614 pWin = FindBasWin( aDocument, aLibName, aName, true );
615 static_cast<ModulWindow*>(pWin)->EditMacro( rSbxItem.GetMethodName() );
617 DBG_ASSERT( pWin, "Window was not created!" );
618 SetCurWindow( pWin, true );
619 pTabBar->MakeVisible( pTabBar->GetCurPageId() );
621 break;
622 case SID_BASICIDE_SHOWWINDOW:
624 std::unique_ptr< ScriptDocument > pDocument;
626 const SfxStringItem* pDocumentItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_DOCUMENT);
627 if ( pDocumentItem )
629 OUString sDocumentCaption = pDocumentItem->GetValue();
630 if ( !sDocumentCaption.isEmpty() )
631 pDocument.reset( new ScriptDocument( ScriptDocument::getDocumentWithURLOrCaption( sDocumentCaption ) ) );
634 const SfxUnoAnyItem* pDocModelItem = rReq.GetArg<SfxUnoAnyItem>(SID_BASICIDE_ARG_DOCUMENT_MODEL);
635 if ( !pDocument.get() && pDocModelItem )
637 uno::Reference< frame::XModel > xModel( pDocModelItem->GetValue(), UNO_QUERY );
638 if ( xModel.is() )
639 pDocument.reset( new ScriptDocument( xModel ) );
642 if ( !pDocument.get() )
643 break;
645 const SfxStringItem* pLibNameItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_LIBNAME);
646 if ( !pLibNameItem )
647 break;
649 OUString aLibName( pLibNameItem->GetValue() );
650 pDocument->loadLibraryIfExists( E_SCRIPTS, aLibName );
651 SetCurLib( *pDocument, aLibName );
652 const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_NAME);
653 if ( pNameItem )
655 OUString aName( pNameItem->GetValue() );
656 OUString aModType( "Module" );
657 OUString aType( aModType );
658 const SfxStringItem* pTypeItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_TYPE);
659 if ( pTypeItem )
660 aType = pTypeItem->GetValue();
662 BaseWindow* pWin = nullptr;
663 if ( aType == aModType )
664 pWin = FindBasWin( *pDocument, aLibName, aName );
665 else if ( aType == "Dialog" )
666 pWin = FindDlgWin( *pDocument, aLibName, aName );
668 if ( pWin )
670 SetCurWindow( pWin, true );
671 if ( pTabBar )
672 pTabBar->MakeVisible( pTabBar->GetCurPageId() );
674 if (ModulWindow* pModWin = dynamic_cast<ModulWindow*>(pWin))
676 const SfxUInt32Item* pLineItem = rReq.GetArg<SfxUInt32Item>(SID_BASICIDE_ARG_LINE);
677 if ( pLineItem )
679 pModWin->AssertValidEditEngine();
680 TextView* pTextView = pModWin->GetEditView();
681 if ( pTextView )
683 TextEngine* pTextEngine = pTextView->GetTextEngine();
684 if ( pTextEngine )
686 sal_uInt32 nLine = pLineItem->GetValue();
687 sal_uInt32 nLineCount = 0;
688 for ( sal_uInt32 i = 0, nCount = pTextEngine->GetParagraphCount(); i < nCount; ++i )
689 nLineCount += pTextEngine->GetLineCount( i );
690 if ( nLine > nLineCount )
691 nLine = nLineCount;
692 if ( nLine > 0 )
693 --nLine;
695 // scroll window and set selection
696 long nVisHeight = pModWin->GetOutputSizePixel().Height();
697 long nTextHeight = pTextEngine->GetTextHeight();
698 if ( nTextHeight > nVisHeight )
700 long nMaxY = nTextHeight - nVisHeight;
701 long nOldY = pTextView->GetStartDocPos().Y();
702 long nNewY = nLine * pTextEngine->GetCharHeight() - nVisHeight / 2;
703 nNewY = std::min( nNewY, nMaxY );
704 pTextView->Scroll( 0, -( nNewY - nOldY ) );
705 pTextView->ShowCursor( false );
706 pModWin->GetEditVScrollBar().SetThumbPos( pTextView->GetStartDocPos().Y() );
708 sal_uInt16 nCol1 = 0, nCol2 = 0;
709 const SfxUInt16Item* pCol1Item = rReq.GetArg<SfxUInt16Item>(SID_BASICIDE_ARG_COLUMN1);
710 if ( pCol1Item )
712 nCol1 = pCol1Item->GetValue();
713 if ( nCol1 > 0 )
714 --nCol1;
715 nCol2 = nCol1;
717 const SfxUInt16Item* pCol2Item = rReq.GetArg<SfxUInt16Item>(SID_BASICIDE_ARG_COLUMN2);
718 if ( pCol2Item )
720 nCol2 = pCol2Item->GetValue();
721 if ( nCol2 > 0 )
722 --nCol2;
724 TextSelection aSel( TextPaM( nLine, nCol1 ), TextPaM( nLine, nCol2 ) );
725 pTextView->SetSelection( aSel );
726 pTextView->ShowCursor();
727 vcl::Window* pWindow_ = pTextView->GetWindow();
728 if ( pWindow_ )
729 pWindow_->GrabFocus();
736 rReq.Done();
738 break;
740 case SID_BASICIDE_MANAGE_LANG:
742 ScopedVclPtrInstance< ManageLanguageDialog > aDlg(pCurWin, m_pCurLocalizationMgr);
743 aDlg->Execute();
744 rReq.Done();
746 break;
748 default:
749 if (pLayout)
750 pLayout->ExecuteGlobal(rReq);
751 if (pCurWin)
752 pCurWin->ExecuteGlobal(rReq);
753 break;
757 void Shell::GetState(SfxItemSet &rSet)
759 SfxWhichIter aIter(rSet);
760 for ( sal_uInt16 nWh = aIter.FirstWhich(); nWh != 0; nWh = aIter.NextWhich() )
762 switch ( nWh )
764 case SID_DOCINFO:
766 rSet.DisableItem( nWh );
768 break;
769 case SID_SAVEDOC:
771 bool bDisable = false;
773 if ( pCurWin )
775 if ( !pCurWin->IsModified() )
777 ScriptDocument aDocument( pCurWin->GetDocument() );
778 bDisable = ( !aDocument.isAlive() )
779 || ( aDocument.isDocument() ? !aDocument.isDocumentModified() : !IsAppBasicModified() );
782 else
784 bDisable = true;
787 if ( bDisable )
788 rSet.DisableItem( nWh );
790 break;
791 case SID_NEWWINDOW:
792 case SID_SAVEASDOC:
794 rSet.DisableItem( nWh );
796 break;
797 case SID_SIGNATURE:
799 SignatureState nState = SignatureState::NOSIGNATURES;
800 if ( pCurWin )
802 DocumentSignature aSignature( pCurWin->GetDocument() );
803 nState = aSignature.getScriptingSignatureState();
805 rSet.Put( SfxUInt16Item( SID_SIGNATURE, static_cast<sal_uInt16>(nState) ) );
807 break;
808 case SID_BASICIDE_MODULEDLG:
810 if ( StarBASIC::IsRunning() )
811 rSet.DisableItem( nWh );
813 break;
814 case SID_BASICIDE_OBJCAT:
815 if (pLayout)
816 rSet.Put(SfxBoolItem(nWh, aObjectCatalog->IsVisible()));
817 else
818 rSet.Put(SfxVisibilityItem(nWh, false));
819 break;
820 case SID_BASICIDE_SHOWSBX:
821 case SID_BASICIDE_CREATEMACRO:
822 case SID_BASICIDE_EDITMACRO:
823 case SID_BASICIDE_NAMECHANGEDONTAB:
827 break;
829 case SID_BASICIDE_ADDWATCH:
830 case SID_BASICIDE_REMOVEWATCH:
831 case SID_BASICLOAD:
832 case SID_BASICSAVEAS:
833 case SID_BASICIDE_MATCHGROUP:
835 if (!dynamic_cast<ModulWindow*>(pCurWin.get()))
836 rSet.DisableItem( nWh );
837 else if ( ( nWh == SID_BASICLOAD ) && ( StarBASIC::IsRunning() || ( pCurWin && pCurWin->IsReadOnly() ) ) )
838 rSet.DisableItem( nWh );
840 break;
841 case SID_BASICRUN:
842 case SID_BASICSTEPINTO:
843 case SID_BASICSTEPOVER:
844 case SID_BASICSTEPOUT:
845 case SID_BASICIDE_TOGGLEBRKPNT:
846 case SID_BASICIDE_MANAGEBRKPNTS:
848 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
850 if (StarBASIC::IsRunning() && !pMCurWin->GetBasicStatus().bIsInReschedule)
851 rSet.DisableItem(nWh);
853 else
854 rSet.DisableItem( nWh );
856 break;
857 case SID_BASICCOMPILE:
859 if (StarBASIC::IsRunning() || !dynamic_cast<ModulWindow*>(pCurWin.get()))
860 rSet.DisableItem( nWh );
862 break;
863 case SID_BASICSTOP:
865 // stop is always possible when some Basic is running...
866 if (!StarBASIC::IsRunning())
867 rSet.DisableItem( nWh );
869 break;
870 case SID_CHOOSE_CONTROLS:
871 case SID_DIALOG_TESTMODE:
872 case SID_INSERT_SELECT:
873 case SID_INSERT_PUSHBUTTON:
874 case SID_INSERT_RADIOBUTTON:
875 case SID_INSERT_CHECKBOX:
876 case SID_INSERT_LISTBOX:
877 case SID_INSERT_COMBOBOX:
878 case SID_INSERT_GROUPBOX:
879 case SID_INSERT_EDIT:
880 case SID_INSERT_FIXEDTEXT:
881 case SID_INSERT_IMAGECONTROL:
882 case SID_INSERT_PROGRESSBAR:
883 case SID_INSERT_HSCROLLBAR:
884 case SID_INSERT_VSCROLLBAR:
885 case SID_INSERT_HFIXEDLINE:
886 case SID_INSERT_VFIXEDLINE:
887 case SID_INSERT_DATEFIELD:
888 case SID_INSERT_TIMEFIELD:
889 case SID_INSERT_NUMERICFIELD:
890 case SID_INSERT_CURRENCYFIELD:
891 case SID_INSERT_FORMATTEDFIELD:
892 case SID_INSERT_PATTERNFIELD:
893 case SID_INSERT_FILECONTROL:
894 case SID_INSERT_SPINBUTTON:
895 case SID_INSERT_TREECONTROL:
896 case SID_INSERT_FORM_RADIO:
897 case SID_INSERT_FORM_CHECK:
898 case SID_INSERT_FORM_LIST:
899 case SID_INSERT_FORM_COMBO:
900 case SID_INSERT_FORM_VSCROLL:
901 case SID_INSERT_FORM_HSCROLL:
902 case SID_INSERT_FORM_SPIN:
904 if (!dynamic_cast<DialogWindow*>(pCurWin.get()))
905 rSet.DisableItem( nWh );
907 break;
908 case SID_SEARCH_OPTIONS:
910 SearchOptionFlags nOptions = SearchOptionFlags::NONE;
911 if( pCurWin )
912 nOptions = pCurWin->GetSearchOptions();
913 rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, static_cast<sal_uInt16>(nOptions) ) );
915 break;
916 case SID_BASICIDE_LIBSELECTOR:
918 OUString aName;
919 if ( !m_aCurLibName.isEmpty() )
921 LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName );
922 aName = CreateMgrAndLibStr( m_aCurDocument.getTitle( eLocation ), m_aCurLibName );
924 SfxStringItem aItem( SID_BASICIDE_LIBSELECTOR, aName );
925 rSet.Put( aItem );
927 break;
928 case SID_SEARCH_ITEM:
930 if ( !mpSearchItem )
932 mpSearchItem.reset( new SvxSearchItem( SID_SEARCH_ITEM ));
933 mpSearchItem->SetSearchString( GetSelectionText( true ));
936 if ( mbJustOpened && HasSelection() )
938 OUString aText = GetSelectionText( true );
940 if ( !aText.isEmpty() )
942 mpSearchItem->SetSearchString( aText );
943 mpSearchItem->SetSelection( false );
945 else
946 mpSearchItem->SetSelection( true );
949 mbJustOpened = false;
950 rSet.Put( *mpSearchItem );
952 break;
953 case SID_BASICIDE_STAT_DATE:
955 SfxStringItem aItem( SID_BASICIDE_STAT_DATE, "Datum?!" );
956 rSet.Put( aItem );
958 break;
959 case SID_DOC_MODIFIED:
961 bool bModified = false;
963 if ( pCurWin )
965 if ( pCurWin->IsModified() )
966 bModified = true;
967 else
969 ScriptDocument aDocument( pCurWin->GetDocument() );
970 bModified = aDocument.isDocument() ? aDocument.isDocumentModified() : IsAppBasicModified();
974 SfxBoolItem aItem(SID_DOC_MODIFIED, bModified);
975 rSet.Put( aItem );
977 break;
978 case SID_BASICIDE_STAT_TITLE:
980 if ( pCurWin )
982 OUString aTitle = pCurWin->CreateQualifiedName();
983 SfxStringItem aItem( SID_BASICIDE_STAT_TITLE, aTitle );
984 rSet.Put( aItem );
987 break;
988 // are interpreted by the controller:
989 case SID_ATTR_SIZE:
990 case SID_ATTR_INSERT:
991 break;
992 case SID_UNDO:
993 case SID_REDO:
995 if( GetUndoManager() ) // recursive GetState else
996 GetViewFrame()->GetSlotState( nWh, nullptr, &rSet );
998 break;
999 case SID_BASICIDE_CURRENT_LANG:
1001 if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().isEmpty() )
1002 rSet.DisableItem( nWh );
1003 else
1005 OUString aItemStr;
1006 std::shared_ptr<LocalizationMgr> pCurMgr(GetCurLocalizationMgr());
1007 if ( pCurMgr->isLibraryLocalized() )
1009 Sequence< lang::Locale > aLocaleSeq = pCurMgr->getStringResourceManager()->getLocales();
1010 const lang::Locale* pLocale = aLocaleSeq.getConstArray();
1011 sal_Int32 i, nCount = aLocaleSeq.getLength();
1013 // Force different results for any combination of locales and default locale
1014 OUString aLangStr;
1015 for ( i = 0; i <= nCount; ++i )
1017 lang::Locale aLocale;
1018 if( i < nCount )
1019 aLocale = pLocale[i];
1020 else
1021 aLocale = pCurMgr->getStringResourceManager()->getDefaultLocale();
1023 aLangStr += aLocale.Language + aLocale.Country + aLocale.Variant;
1025 aItemStr = aLangStr;
1027 rSet.Put( SfxStringItem( nWh, aItemStr ) );
1030 break;
1032 case SID_BASICIDE_MANAGE_LANG:
1034 if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().isEmpty() )
1035 rSet.DisableItem( nWh );
1037 break;
1038 case SID_GOTOLINE:
1040 // if this is not a module window hide the
1041 // setting, doesn't make sense for example if the
1042 // dialog editor is open
1043 if (pCurWin && !dynamic_cast<ModulWindow*>(pCurWin.get()))
1045 rSet.DisableItem( nWh );
1046 rSet.Put(SfxVisibilityItem(nWh, false));
1048 break;
1050 case SID_BASICIDE_HIDECURPAGE:
1052 if (pTabBar->GetPageCount() == 0)
1053 rSet.DisableItem(nWh);
1055 break;
1056 case SID_BASICIDE_DELETECURRENT:
1057 case SID_BASICIDE_RENAMECURRENT:
1059 if (pTabBar->GetPageCount() == 0 || StarBASIC::IsRunning())
1060 rSet.DisableItem(nWh);
1061 else if (m_aCurDocument.isInVBAMode())
1063 // disable to delete or rename object modules in IDE
1064 BasicManager* pBasMgr = m_aCurDocument.getBasicManager();
1065 StarBASIC* pBasic = pBasMgr ? pBasMgr->GetLib(m_aCurLibName) : nullptr;
1066 if (pBasic && dynamic_cast<ModulWindow*>(pCurWin.get()))
1068 SbModule* pActiveModule = pBasic->FindModule( pCurWin->GetName() );
1069 if ( pActiveModule && ( pActiveModule->GetModuleType() == script::ModuleType::DOCUMENT ) )
1070 rSet.DisableItem(nWh);
1074 SAL_FALLTHROUGH;
1076 case SID_BASICIDE_NEWMODULE:
1077 case SID_BASICIDE_NEWDIALOG:
1079 Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
1080 Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
1081 if ( ( xModLibContainer.is() && xModLibContainer->hasByName( m_aCurLibName ) && xModLibContainer->isLibraryReadOnly( m_aCurLibName ) ) ||
1082 ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( m_aCurLibName ) && xDlgLibContainer->isLibraryReadOnly( m_aCurLibName ) ) )
1083 rSet.DisableItem(nWh);
1085 break;
1086 default:
1087 if (pLayout)
1088 pLayout->GetState(rSet, nWh);
1091 if ( pCurWin )
1092 pCurWin->GetState( rSet );
1095 bool Shell::HasUIFeature(SfxShellFeature nFeature) const
1097 assert((nFeature & ~SfxShellFeature::BasicMask) == SfxShellFeature::NONE);
1098 bool bResult = false;
1100 if (nFeature & SfxShellFeature::BasicShowBrowser)
1102 // fade out (in) property browser in module (dialog) windows
1103 if (dynamic_cast<DialogWindow*>(pCurWin.get()) && !pCurWin->IsReadOnly())
1104 bResult = true;
1107 return bResult;
1110 void Shell::SetCurWindow( BaseWindow* pNewWin, bool bUpdateTabBar, bool bRememberAsCurrent )
1112 if ( pNewWin != pCurWin )
1114 pCurWin = pNewWin;
1115 if (pLayout)
1116 pLayout->Deactivating();
1117 if (pCurWin)
1119 if (pCurWin->GetType() == TYPE_MODULE)
1120 pLayout = pModulLayout.get();
1121 else
1122 pLayout = pDialogLayout.get();
1123 AdjustPosSizePixel(Point(0, 0), GetViewFrame()->GetWindow().GetOutputSizePixel());
1124 pLayout->Activating(*pCurWin);
1125 GetViewFrame()->GetWindow().SetHelpId(pCurWin->GetHid());
1126 if (bRememberAsCurrent)
1127 pCurWin->InsertLibInfo();
1128 if (GetViewFrame()->GetWindow().IsVisible()) // SFX will do it later otherwise
1129 pCurWin->Show();
1130 pCurWin->Init();
1131 if (!GetExtraData()->ShellInCriticalSection())
1133 vcl::Window* pFrameWindow = &GetViewFrame()->GetWindow();
1134 vcl::Window* pFocusWindow = Application::GetFocusWindow();
1135 while ( pFocusWindow && ( pFocusWindow != pFrameWindow ) )
1136 pFocusWindow = pFocusWindow->GetParent();
1137 if ( pFocusWindow ) // Focus in BasicIDE
1138 pCurWin->GrabFocus();
1141 else
1143 SetWindow(pLayout);
1144 pLayout = nullptr;
1146 if ( bUpdateTabBar )
1148 sal_uLong nKey = GetWindowId( pCurWin );
1149 if ( pCurWin && ( pTabBar->GetPagePos( static_cast<sal_uInt16>(nKey) ) == TAB_PAGE_NOTFOUND ) )
1150 pTabBar->InsertPage( static_cast<sal_uInt16>(nKey), pCurWin->GetTitle() ); // has just been faded in
1151 pTabBar->SetCurPageId( static_cast<sal_uInt16>(nKey) );
1153 if ( pCurWin && pCurWin->IsSuspended() ) // if the window is shown in the case of an error...
1154 pCurWin->SetStatus( pCurWin->GetStatus() & ~BASWIN_SUSPENDED );
1155 if ( pCurWin )
1157 SetWindow( pCurWin );
1158 if ( pCurWin->GetDocument().isDocument() )
1159 SfxObjectShell::SetCurrentComponent( pCurWin->GetDocument().getDocument() );
1161 else if (pLayout)
1163 SetWindow(pLayout);
1164 GetViewFrame()->GetWindow().SetHelpId( HID_BASICIDE_MODULWINDOW );
1165 SfxObjectShell::SetCurrentComponent(nullptr);
1167 aObjectCatalog->SetCurrentEntry(pCurWin);
1168 SetUndoManager( pCurWin ? pCurWin->GetUndoManager() : nullptr );
1169 InvalidateBasicIDESlots();
1170 InvalidateControlSlots();
1171 EnableScrollbars(pCurWin != nullptr);
1173 if ( m_pCurLocalizationMgr )
1174 m_pCurLocalizationMgr->handleTranslationbar();
1176 ManageToolbars();
1178 // fade out (in) property browser in module (dialog) windows
1179 UIFeatureChanged();
1183 void Shell::ManageToolbars()
1185 static const char aMacroBarResName[] = "private:resource/toolbar/macrobar";
1186 static const char aDialogBarResName[] = "private:resource/toolbar/dialogbar";
1187 static const char aInsertControlsBarResName[] = "private:resource/toolbar/insertcontrolsbar";
1188 static const char aFormControlsBarResName[] = "private:resource/toolbar/formcontrolsbar";
1190 if( !pCurWin )
1191 return;
1193 Reference< beans::XPropertySet > xFrameProps
1194 ( GetViewFrame()->GetFrame().GetFrameInterface(), uno::UNO_QUERY );
1195 if ( xFrameProps.is() )
1197 Reference< css::frame::XLayoutManager > xLayoutManager;
1198 uno::Any a = xFrameProps->getPropertyValue( "LayoutManager" );
1199 a >>= xLayoutManager;
1200 if ( xLayoutManager.is() )
1202 xLayoutManager->lock();
1203 if (dynamic_cast<DialogWindow*>(pCurWin.get()))
1205 xLayoutManager->destroyElement( aMacroBarResName );
1207 xLayoutManager->requestElement( aDialogBarResName );
1208 xLayoutManager->requestElement( aInsertControlsBarResName );
1209 xLayoutManager->requestElement( aFormControlsBarResName );
1211 else
1213 xLayoutManager->destroyElement( aDialogBarResName );
1214 xLayoutManager->destroyElement( aInsertControlsBarResName );
1215 xLayoutManager->destroyElement( aFormControlsBarResName );
1217 xLayoutManager->requestElement( aMacroBarResName );
1219 xLayoutManager->unlock();
1224 VclPtr<BaseWindow> Shell::FindApplicationWindow()
1226 return FindWindow( ScriptDocument::getApplicationScriptDocument(), "", "", TYPE_UNKNOWN );
1229 VclPtr<BaseWindow> Shell::FindWindow(
1230 ScriptDocument const& rDocument,
1231 OUString const& rLibName, OUString const& rName,
1232 ItemType eType, bool bFindSuspended
1235 for (auto const& window : aWindowTable)
1237 BaseWindow* const pWin = window.second;
1238 if (pWin->Is(rDocument, rLibName, rName, eType, bFindSuspended))
1239 return pWin;
1241 return nullptr;
1244 bool Shell::CallBasicErrorHdl( StarBASIC const * pBasic )
1246 bool bRet = false;
1247 VclPtr<ModulWindow> pModWin = ShowActiveModuleWindow( pBasic );
1248 if ( pModWin )
1249 bRet = pModWin->BasicErrorHdl( pBasic );
1250 return bRet;
1253 BasicDebugFlags Shell::CallBasicBreakHdl( StarBASIC const * pBasic )
1255 BasicDebugFlags nRet = BasicDebugFlags::NONE;
1256 VclPtr<ModulWindow> pModWin = ShowActiveModuleWindow( pBasic );
1257 if ( pModWin )
1259 bool bAppWindowDisabled, bDispatcherLocked;
1260 sal_uInt16 nWaitCount;
1261 SfxUInt16Item *pSWActionCount, *pSWLockViewCount;
1262 BasicStopped( &bAppWindowDisabled, &bDispatcherLocked,
1263 &nWaitCount, &pSWActionCount, &pSWLockViewCount );
1265 nRet = pModWin->BasicBreakHdl();
1267 if ( StarBASIC::IsRunning() ) // if cancelled...
1269 if ( bAppWindowDisabled )
1270 Application::GetDefDialogParent()->Enable(false);
1272 if ( nWaitCount )
1274 Shell* pShell = GetShell();
1275 for ( sal_uInt16 n = 0; n < nWaitCount; n++ )
1276 pShell->GetViewFrame()->GetWindow().EnterWait();
1280 return nRet;
1283 VclPtr<ModulWindow> Shell::ShowActiveModuleWindow( StarBASIC const * pBasic )
1285 SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
1287 SbModule* pActiveModule = StarBASIC::GetActiveModule();
1288 if (SbClassModuleObject* pCMO = dynamic_cast<SbClassModuleObject*>(pActiveModule))
1289 pActiveModule = pCMO->getClassModule();
1291 DBG_ASSERT( pActiveModule, "No active module in ErrorHdl!?" );
1292 if ( pActiveModule )
1294 VclPtr<ModulWindow> pWin;
1295 SbxObject* pParent = pActiveModule->GetParent();
1296 if (StarBASIC* pLib = dynamic_cast<StarBASIC*>(pParent))
1298 if (BasicManager* pBasMgr = FindBasicManager(pLib))
1300 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
1301 OUString aLibName = pLib->GetName();
1302 pWin = FindBasWin( aDocument, aLibName, pActiveModule->GetName(), true );
1303 DBG_ASSERT( pWin, "Error/Step-Hdl: Window was not created/found!" );
1304 SetCurLib( aDocument, aLibName );
1305 SetCurWindow( pWin, true );
1308 else
1309 SAL_WARN( "basctl.basicide", "No BASIC!");
1310 if (BasicManager* pBasicMgr = FindBasicManager(pBasic))
1311 StartListening(*pBasicMgr, DuplicateHandling::Prevent /* log on only once */);
1312 return pWin;
1314 return nullptr;
1317 void Shell::AdjustPosSizePixel( const Point &rPos, const Size &rSize )
1319 // not if iconified because the whole text would be displaced then at restore
1320 if ( GetViewFrame()->GetWindow().GetOutputSizePixel().Height() == 0 )
1321 return;
1323 Size aTabBarSize;
1324 aTabBarSize.setHeight( GetViewFrame()->GetWindow().GetFont().GetFontHeight() + 4 );
1325 aTabBarSize.setWidth( rSize.Width() );
1327 Size aSz( rSize );
1328 Size aScrollBarBoxSz( aScrollBarBox->GetSizePixel() );
1329 aSz.AdjustHeight( -(aScrollBarBoxSz.Height()) );
1330 aSz.AdjustHeight( -(aTabBarSize.Height()) );
1332 Size aOutSz( aSz );
1333 aSz.AdjustWidth( -(aScrollBarBoxSz.Width()) );
1334 aScrollBarBox->SetPosPixel( Point( rSize.Width() - aScrollBarBoxSz.Width(), rSize.Height() - aScrollBarBoxSz.Height() ) );
1335 aVScrollBar->SetPosSizePixel( Point( rPos.X()+aSz.Width(), rPos.Y() ), Size( aScrollBarBoxSz.Width(), aSz.Height() ) );
1336 aHScrollBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aSz.Height() ), Size( aSz.Width(), aScrollBarBoxSz.Height() ) );
1337 pTabBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aScrollBarBoxSz.Height()+aSz.Height()), aTabBarSize );
1339 if (pLayout)
1340 pLayout->SetPosSizePixel(rPos, dynamic_cast<DialogWindow*>(pCurWin.get()) ? aSz : aOutSz);
1343 Reference< XModel > Shell::GetCurrentDocument() const
1345 Reference< XModel > xDocument;
1346 if ( pCurWin && pCurWin->GetDocument().isDocument() )
1347 xDocument = pCurWin->GetDocument().getDocument();
1348 return xDocument;
1351 void Shell::Activate( bool bMDI )
1353 SfxViewShell::Activate( bMDI );
1355 if ( bMDI )
1357 if (DialogWindow* pDCurWin = dynamic_cast<DialogWindow*>(pCurWin.get()))
1358 pDCurWin->UpdateBrowser();
1362 void Shell::Deactivate( bool bMDI )
1364 // bMDI == true means that another MDI has been activated; in case of a
1365 // deactivate due to a MessageBox bMDI is false
1366 if ( bMDI )
1368 if (DialogWindow* pXDlgWin = dynamic_cast<DialogWindow*>(pCurWin.get()))
1370 pXDlgWin->DisableBrowser();
1371 if( pXDlgWin->IsModified() )
1372 MarkDocumentModified( pXDlgWin->GetDocument() );
1375 // test CanClose to also test during deactivating the BasicIDE whether
1376 // the sourcecode is too large in one of the modules...
1377 for (auto const& window : aWindowTable)
1379 BaseWindow* pWin = window.second;
1380 if ( /* !pWin->IsSuspended() && */ !pWin->CanClose() )
1382 if ( !m_aCurLibName.isEmpty() && ( pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName ) )
1383 SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
1384 SetCurWindow( pWin, true );
1385 break;
1391 } // namespace basctl
1393 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */