sw: clean up Start/EndAction in SwViewShell hierarchy
[LibreOffice.git] / basctl / source / basicide / basides1.cxx
blob1417b3799fb6c4af5dd0216dce6acba0b063a441
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 <iderid.hxx>
22 #include <strings.hrc>
23 #include <helpids.h>
25 #include "baside2.hxx"
26 #include <baside3.hxx>
27 #include <basidesh.hxx>
28 #include <basobj.hxx>
29 #include <docsignature.hxx>
30 #include <iderdll.hxx>
31 #include "iderdll2.hxx"
32 #include <localizationmgr.hxx>
33 #include <managelang.hxx>
34 #include <ColorSchemeDialog.hxx>
36 #include <basic/basmgr.hxx>
37 #include <com/sun/star/script/ModuleType.hpp>
38 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
39 #include <com/sun/star/script/XLibraryContainer2.hpp>
40 #include <com/sun/star/frame/XLayoutManager.hpp>
41 #include <svl/srchdefs.hxx>
42 #include <sal/log.hxx>
43 #include <osl/diagnose.h>
44 #include <sfx2/app.hxx>
45 #include <sfx2/bindings.hxx>
46 #include <sfx2/childwin.hxx>
47 #include <sfx2/dinfdlg.hxx>
48 #include <sfx2/minfitem.hxx>
49 #include <sfx2/request.hxx>
50 #include <sfx2/viewfrm.hxx>
51 #include <svx/svxids.hrc>
52 #include <svl/eitem.hxx>
53 #include <svl/intitem.hxx>
54 #include <svl/visitem.hxx>
55 #include <svl/whiter.hxx>
56 #include <vcl/texteng.hxx>
57 #include <vcl/textview.hxx>
58 #include <vcl/svapp.hxx>
59 #include <vcl/weld.hxx>
60 #include <svx/zoomsliderctrl.hxx>
61 #include <svx/zoomslideritem.hxx>
62 #include <basegfx/utils/zoomtools.hxx>
63 #include <officecfg/Office/BasicIDE.hxx>
65 constexpr sal_Int32 TAB_HEIGHT_MARGIN = 10;
67 namespace basctl
70 using namespace ::com::sun::star;
71 using namespace ::com::sun::star::uno;
72 using namespace ::com::sun::star::frame;
74 static void lcl_InvalidateZoomSlots(SfxBindings* pBindings)
76 if (!pBindings)
77 return;
79 static sal_uInt16 const aInval[] = {
80 SID_ZOOM_OUT, SID_ZOOM_IN, SID_ATTR_ZOOMSLIDER, 0
82 pBindings->Invalidate(aInval);
85 void Shell::ExecuteSearch( SfxRequest& rReq )
87 if ( !pCurWin )
88 return;
90 const SfxItemSet* pArgs = rReq.GetArgs();
91 sal_uInt16 nSlot = rReq.GetSlot();
93 // if searching has not been done before this time
94 if (nSlot == SID_BASICIDE_REPEAT_SEARCH && !mpSearchItem)
96 rReq.SetReturnValue(SfxBoolItem(nSlot, false));
97 nSlot = 0;
100 switch ( nSlot )
102 case SID_SEARCH_OPTIONS:
103 break;
104 case SID_SEARCH_ITEM:
105 mpSearchItem.reset(pArgs->Get(SID_SEARCH_ITEM).Clone());
106 break;
107 case FID_SEARCH_ON:
108 mbJustOpened = true;
109 GetViewFrame().GetBindings().Invalidate(SID_SEARCH_ITEM);
110 break;
111 case SID_BASICIDE_REPEAT_SEARCH:
112 case FID_SEARCH_NOW:
114 if (!pCurWin->HasActiveEditor())
115 break;
117 // If it is a repeat searching
118 if ( nSlot == SID_BASICIDE_REPEAT_SEARCH )
120 if( !mpSearchItem )
121 mpSearchItem.reset( new SvxSearchItem( SID_SEARCH_ITEM ));
123 else
125 // Get SearchItem from request if it is the first searching
126 if ( pArgs )
128 mpSearchItem.reset(pArgs->Get(SID_SEARCH_ITEM).Clone());
132 sal_Int32 nFound = 0;
134 if ( mpSearchItem->GetCommand() == SvxSearchCmd::REPLACE_ALL )
136 sal_uInt16 nActModWindows = 0;
137 for (auto const& window : aWindowTable)
139 BaseWindow* pWin = window.second;
140 if (pWin->HasActiveEditor())
141 nActModWindows++;
144 bool bAllModules = nActModWindows <= 1;
145 if (!bAllModules)
147 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pCurWin ? pCurWin->GetFrameWeld() : nullptr,
148 VclMessageType::Question, VclButtonsType::YesNo,
149 IDEResId(RID_STR_SEARCHALLMODULES)));
150 xQueryBox->set_default_response(RET_YES);
151 bAllModules = xQueryBox->run() == RET_YES;
154 if (bAllModules)
156 for (auto const& window : aWindowTable)
158 BaseWindow* pWin = window.second;
159 nFound += pWin->StartSearchAndReplace( *mpSearchItem );
162 else
163 nFound = pCurWin->StartSearchAndReplace( *mpSearchItem );
165 OUString aReplStr(IDEResId(RID_STR_SEARCHREPLACES));
166 aReplStr = aReplStr.replaceAll("XX", OUString::number(nFound));
168 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pCurWin->GetFrameWeld(),
169 VclMessageType::Info, VclButtonsType::Ok,
170 aReplStr));
171 xInfoBox->run();
173 else
175 bool bCanceled = false;
176 nFound = pCurWin->StartSearchAndReplace( *mpSearchItem );
177 if ( !nFound && !mpSearchItem->GetSelection() )
179 // search other modules...
180 bool bChangeCurWindow = false;
181 auto it = std::find_if(aWindowTable.cbegin(), aWindowTable.cend(),
182 [this](const WindowTable::value_type& item) { return item.second == pCurWin; });
183 if (it != aWindowTable.cend())
184 ++it;
185 BaseWindow* pWin = it != aWindowTable.cend() ? it->second.get() : nullptr;
187 bool bSearchedFromStart = false;
188 while ( !nFound && !bCanceled && ( pWin || !bSearchedFromStart ) )
190 if ( !pWin )
192 SfxViewFrame& rViewFrame = GetViewFrame();
193 SfxChildWindow* pChildWin = rViewFrame.GetChildWindow(SID_SEARCH_DLG);
194 auto xParent = pChildWin ? pChildWin->GetController() : nullptr;
196 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(xParent ? xParent->getDialog() : nullptr,
197 VclMessageType::Question, VclButtonsType::YesNo,
198 IDEResId(RID_STR_SEARCHFROMSTART)));
199 xQueryBox->set_default_response(RET_YES);
200 if (xQueryBox->run() == RET_YES)
202 it = aWindowTable.cbegin();
203 if ( it != aWindowTable.cend() )
204 pWin = it->second;
205 bSearchedFromStart = true;
207 else
208 bCanceled = true;
211 if (pWin && pWin->HasActiveEditor())
213 if ( pWin != pCurWin )
215 if ( pCurWin )
216 pWin->SetSizePixel( pCurWin->GetSizePixel() );
217 nFound = pWin->StartSearchAndReplace( *mpSearchItem, true );
219 if ( nFound )
221 bChangeCurWindow = true;
222 break;
225 if ( pWin && ( pWin != pCurWin ) )
227 if ( it != aWindowTable.cend() )
228 ++it;
229 pWin = it != aWindowTable.cend() ? it->second.get() : nullptr;
231 else
232 pWin = nullptr;
234 if ( !nFound && bSearchedFromStart )
235 nFound = pCurWin->StartSearchAndReplace( *mpSearchItem, true );
236 if ( bChangeCurWindow )
237 SetCurWindow( pWin, true );
239 if ( !nFound && !bCanceled )
241 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pCurWin->GetFrameWeld(),
242 VclMessageType::Info, VclButtonsType::Ok,
243 IDEResId(RID_STR_SEARCHNOTFOUND)));
244 xInfoBox->run();
248 rReq.Done();
249 break;
251 default:
252 pCurWin->ExecuteCommand( rReq );
256 void Shell::ExecuteCurrent( SfxRequest& rReq )
258 if ( !pCurWin )
259 return;
261 switch ( rReq.GetSlot() )
263 case SID_BASICIDE_HIDECURPAGE:
265 pCurWin->StoreData();
266 RemoveWindow( pCurWin, false );
268 break;
269 case SID_BASICIDE_RENAMECURRENT:
271 pTabBar->StartEditMode( pTabBar->GetCurPageId() );
273 break;
274 case SID_UNDO:
275 case SID_REDO:
276 if ( GetUndoManager() && pCurWin->AllowUndo() )
277 GetViewFrame().ExecuteSlot( rReq );
278 break;
279 default:
280 pCurWin->ExecuteCommand( rReq );
284 // no matter who's at the top, influence on the shell:
285 void Shell::ExecuteGlobal( SfxRequest& rReq )
287 sal_uInt16 nSlot = rReq.GetSlot();
288 switch ( nSlot )
290 case SID_NEWDOCDIRECT:
292 // we do not have a new document factory,
293 // so just forward to a fallback method.
294 SfxGetpApp()->ExecuteSlot(rReq);
296 break;
298 case SID_BASICSTOP:
300 // maybe do not simply stop if on breakpoint!
301 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
302 pMCurWin->BasicStop();
303 StopBasic();
305 break;
307 case SID_SAVEDOC:
309 if ( pCurWin )
311 // rewrite date into the BASIC
312 StoreAllWindowData();
314 // document basic
315 ScriptDocument aDocument( pCurWin->GetDocument() );
316 if ( aDocument.isDocument() )
318 uno::Reference< task::XStatusIndicator > xStatusIndicator;
320 const SfxUnoAnyItem* pStatusIndicatorItem = rReq.GetArg<SfxUnoAnyItem>(SID_PROGRESS_STATUSBAR_CONTROL);
321 if ( pStatusIndicatorItem )
322 OSL_VERIFY( pStatusIndicatorItem->GetValue() >>= xStatusIndicator );
323 else
325 // get statusindicator
326 SfxViewFrame *pFrame_ = GetFrame();
327 if ( pFrame_ )
329 uno::Reference< task::XStatusIndicatorFactory > xStatFactory(
330 pFrame_->GetFrame().GetFrameInterface(),
331 uno::UNO_QUERY );
332 if( xStatFactory.is() )
333 xStatusIndicator = xStatFactory->createStatusIndicator();
336 if ( xStatusIndicator.is() )
337 rReq.AppendItem( SfxUnoAnyItem( SID_PROGRESS_STATUSBAR_CONTROL, uno::Any( xStatusIndicator ) ) );
340 aDocument.saveDocument( xStatusIndicator );
343 if (SfxBindings* pBindings = GetBindingsPtr())
345 pBindings->Invalidate( SID_DOC_MODIFIED );
346 pBindings->Invalidate( SID_SAVEDOC );
347 pBindings->Invalidate( SID_SIGNATURE );
351 break;
352 case SID_BASICIDE_MODULEDLG:
354 if ( rReq.GetArgs() )
356 const SfxUInt16Item &rTabId = rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
357 Organize(rReq.GetFrameWeld(), nullptr, rTabId.GetValue());
359 else
360 Organize(rReq.GetFrameWeld(), nullptr, 0);
362 break;
363 case SID_BASICIDE_CHOOSEMACRO:
365 ChooseMacro(rReq.GetFrameWeld(), nullptr);
367 break;
368 case SID_BASICIDE_CREATEMACRO:
369 case SID_BASICIDE_EDITMACRO:
371 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
372 const SfxMacroInfoItem& rInfo = rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
373 BasicManager* pBasMgr = const_cast<BasicManager*>(rInfo.GetBasicManager());
374 DBG_ASSERT( pBasMgr, "Nothing selected in basic tree?" );
376 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
378 StartListening(*pBasMgr, DuplicateHandling::Prevent /* log on only once */);
379 OUString aLibName( rInfo.GetLib() );
380 if ( aLibName.isEmpty() )
381 aLibName = "Standard" ;
382 StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
383 if ( !pBasic )
385 // load module and dialog library (if not loaded)
386 aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
387 aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
389 // get Basic
390 pBasic = pBasMgr->GetLib( aLibName );
392 DBG_ASSERT( pBasic, "No Basic!" );
394 SetCurLib( aDocument, aLibName );
396 if ( pBasic && rReq.GetSlot() == SID_BASICIDE_CREATEMACRO )
398 SbModule* pModule = pBasic->FindModule( rInfo.GetModule() );
399 if ( !pModule )
401 if ( !rInfo.GetModule().isEmpty() || pBasic->GetModules().empty() )
403 const OUString& aModName = rInfo.GetModule();
405 OUString sModuleCode;
406 if ( aDocument.createModule( aLibName, aModName, false, sModuleCode ) )
407 pModule = pBasic->FindModule( aModName );
409 else
410 pModule = pBasic->GetModules().front().get();
412 DBG_ASSERT( pModule, "No Module!" );
413 if ( pModule && !pModule->GetMethods()->Find( rInfo.GetMethod(), SbxClassType::Method ) )
414 CreateMacro( pModule, rInfo.GetMethod() );
416 SfxViewFrame& rViewFrame = GetViewFrame();
417 rViewFrame.ToTop();
418 VclPtr<ModulWindow> pWin = FindBasWin( aDocument, aLibName, rInfo.GetModule(), true );
419 DBG_ASSERT( pWin, "Edit/Create Macro: Window was not created/found!" );
420 SetCurWindow( pWin, true );
421 pWin->EditMacro( rInfo.GetMethod() );
423 break;
425 case SID_BASICIDE_OBJCAT:
427 // Toggle the visibility of the object catalog
428 bool bVisible = aObjectCatalog->IsVisible();
429 aObjectCatalog->Show(!bVisible);
430 if (pLayout)
431 pLayout->ArrangeWindows();
432 // refresh the button state
433 if (SfxBindings* pBindings = GetBindingsPtr())
434 pBindings->Invalidate(SID_BASICIDE_OBJCAT);
436 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
437 officecfg::Office::BasicIDE::EditorSettings::ObjectCatalog::set(!bVisible, batch);
438 batch->commit();
440 break;
442 case SID_BASICIDE_WATCH:
444 // Toggling the watch window can only be done from a ModulWindow
445 if (!dynamic_cast<ModulWindowLayout*>(pLayout.get()))
446 return;
448 bool bVisible = pModulLayout->IsWatchWindowVisible();
449 pModulLayout->ShowWatchWindow(!bVisible);
450 if (SfxBindings* pBindings = GetBindingsPtr())
451 pBindings->Invalidate(SID_BASICIDE_WATCH);
453 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
454 officecfg::Office::BasicIDE::EditorSettings::WatchWindow::set(!bVisible, batch);
455 batch->commit();
457 break;
459 case SID_BASICIDE_STACK:
461 // Toggling the stack window can only be done from a ModulWindow
462 if (!dynamic_cast<ModulWindowLayout*>(pLayout.get()))
463 return;
465 bool bVisible = pModulLayout->IsStackWindowVisible();
466 pModulLayout->ShowStackWindow(!bVisible);
467 if (SfxBindings* pBindings = GetBindingsPtr())
468 pBindings->Invalidate(SID_BASICIDE_STACK);
470 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
471 officecfg::Office::BasicIDE::EditorSettings::StackWindow::set(!bVisible, batch);
472 batch->commit();
474 break;
476 case SID_BASICIDE_NAMECHANGEDONTAB:
478 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
479 const SfxUInt16Item &rTabId = rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
480 const SfxStringItem &rModName = rReq.GetArgs()->Get(SID_BASICIDE_ARG_MODULENAME );
481 if ( aWindowTable.find( rTabId.GetValue() ) != aWindowTable.end() )
483 VclPtr<BaseWindow> pWin = aWindowTable[ rTabId.GetValue() ];
484 const OUString& aNewName( rModName.GetValue() );
485 OUString aOldName( pWin->GetName() );
486 if ( aNewName != aOldName )
488 bool bRenameOk = false;
489 if (ModulWindow* pModWin = dynamic_cast<ModulWindow*>(pWin.get()))
491 const OUString& aLibName = pModWin->GetLibName();
492 ScriptDocument aDocument( pWin->GetDocument() );
494 if (RenameModule(pModWin->GetFrameWeld(), aDocument, aLibName, aOldName, aNewName))
496 bRenameOk = true;
497 // Because we listen for container events for script
498 // modules, rename will delete the 'old' window
499 // pWin has been invalidated, restore now
500 pWin = FindBasWin( aDocument, aLibName, aNewName, true );
504 else if (DialogWindow* pDlgWin = dynamic_cast<DialogWindow*>(pWin.get()))
506 bRenameOk = pDlgWin->RenameDialog( aNewName );
508 if ( bRenameOk )
510 MarkDocumentModified( pWin->GetDocument() );
512 else
514 // set old name in TabWriter
515 sal_uInt16 nId = GetWindowId( pWin );
516 DBG_ASSERT( nId, "No entry in Tabbar!" );
517 if ( nId )
518 pTabBar->SetPageText( nId, aOldName );
522 // set focus to current window
523 pWin->GrabFocus();
526 break;
527 case SID_BASICIDE_STOREMODULESOURCE:
528 case SID_BASICIDE_UPDATEMODULESOURCE:
530 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
531 const SfxMacroInfoItem& rInfo = rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
532 BasicManager* pBasMgr = const_cast<BasicManager*>(rInfo.GetBasicManager());
533 DBG_ASSERT( pBasMgr, "Store source: No BasMgr?" );
534 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
535 VclPtr<ModulWindow> pWin = FindBasWin( aDocument, rInfo.GetLib(), rInfo.GetModule(), false, true );
536 if ( pWin )
538 if ( rReq.GetSlot() == SID_BASICIDE_STOREMODULESOURCE )
539 pWin->StoreData();
540 else
541 pWin->UpdateData();
544 break;
545 case SID_BASICIDE_STOREALLMODULESOURCES:
546 case SID_BASICIDE_UPDATEALLMODULESOURCES:
548 for (auto const& window : aWindowTable)
550 BaseWindow* pWin = window.second;
551 if (!pWin->IsSuspended() && dynamic_cast<ModulWindow*>(pWin))
553 if ( rReq.GetSlot() == SID_BASICIDE_STOREALLMODULESOURCES )
554 pWin->StoreData();
555 else
556 pWin->UpdateData();
560 break;
561 case SID_BASICIDE_LIBSELECTED:
562 case SID_BASICIDE_LIBREMOVED:
563 case SID_BASICIDE_LIBLOADED:
565 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
566 const SfxUnoAnyItem& rShellItem = rReq.GetArgs()->Get( SID_BASICIDE_ARG_DOCUMENT_MODEL );
567 uno::Reference< frame::XModel > xModel( rShellItem.GetValue(), UNO_QUERY );
568 ScriptDocument aDocument( xModel.is() ? ScriptDocument( xModel ) : ScriptDocument::getApplicationScriptDocument() );
569 const SfxStringItem& rLibNameItem = rReq.GetArgs()->Get( SID_BASICIDE_ARG_LIBNAME );
570 const OUString& aLibName( rLibNameItem.GetValue() );
572 if ( nSlot == SID_BASICIDE_LIBSELECTED )
574 // load module and dialog library (if not loaded)
575 aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
576 aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
578 // check password, if library is password protected and not verified
579 bool bOK = true;
580 Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ) );
581 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
583 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
584 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
586 OUString aPassword;
587 bOK = QueryPassword(rReq.GetFrameWeld(), xModLibContainer, aLibName, aPassword);
591 if ( bOK )
593 SetCurLib( aDocument, aLibName, true, false );
595 else
597 // adjust old value...
598 if (SfxBindings* pBindings = GetBindingsPtr())
599 pBindings->Invalidate(SID_BASICIDE_LIBSELECTOR, true);
602 else if ( nSlot == SID_BASICIDE_LIBREMOVED )
604 if ( m_aCurLibName.isEmpty() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
606 RemoveWindows( aDocument, aLibName );
607 if ( aDocument == m_aCurDocument && aLibName == m_aCurLibName )
609 m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
610 m_aCurLibName.clear();
611 // no UpdateWindows!
612 if (SfxBindings* pBindings = GetBindingsPtr())
613 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
617 else // Loaded...
618 UpdateWindows();
620 break;
621 case SID_BASICIDE_NEWMODULE:
623 VclPtr<ModulWindow> pWin = CreateBasWin( m_aCurDocument, m_aCurLibName, OUString() );
624 DBG_ASSERT( pWin, "New Module: Could not create window!" );
625 SetCurWindow( pWin, true );
627 break;
628 case SID_BASICIDE_NEWDIALOG:
630 VclPtr<DialogWindow> pWin = CreateDlgWin( m_aCurDocument, m_aCurLibName, OUString() );
631 DBG_ASSERT( pWin, "New Module: Could not create window!" );
632 SetCurWindow( pWin, true );
634 break;
635 case SID_BASICIDE_SBXRENAMED:
637 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
639 break;
640 case SID_BASICIDE_SBXINSERTED:
642 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
643 const SbxItem& rSbxItem = rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
644 const ScriptDocument& aDocument( rSbxItem.GetDocument() );
645 const OUString& aLibName( rSbxItem.GetLibName() );
646 const OUString& aName( rSbxItem.GetName() );
647 if ( m_aCurLibName.isEmpty() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
649 if ( rSbxItem.GetSbxType() == SBX_TYPE_MODULE )
650 FindBasWin( aDocument, aLibName, aName, true );
651 else if ( rSbxItem.GetSbxType() == SBX_TYPE_DIALOG )
652 FindDlgWin( aDocument, aLibName, aName, true );
655 break;
656 case SID_BASICIDE_SBXDELETED:
658 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
659 const SbxItem& rSbxItem = rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
660 const ScriptDocument& aDocument( rSbxItem.GetDocument() );
661 VclPtr<BaseWindow> pWin = FindWindow( aDocument, rSbxItem.GetLibName(), rSbxItem.GetName(), rSbxItem.GetSbxType(), true );
662 if ( pWin )
663 RemoveWindow( pWin, true );
665 break;
666 case SID_BASICIDE_SHOWSBX:
668 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
669 const SbxItem& rSbxItem = rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
670 const ScriptDocument& aDocument( rSbxItem.GetDocument() );
671 const OUString& aLibName( rSbxItem.GetLibName() );
672 const OUString& aName( rSbxItem.GetName() );
673 SetCurLib( aDocument, aLibName );
674 BaseWindow* pWin = nullptr;
675 if ( rSbxItem.GetSbxType() == SBX_TYPE_DIALOG )
677 pWin = FindDlgWin( aDocument, aLibName, aName, true );
679 else if ( rSbxItem.GetSbxType() == SBX_TYPE_MODULE )
681 pWin = FindBasWin( aDocument, aLibName, aName, true );
683 else if ( rSbxItem.GetSbxType() == SBX_TYPE_METHOD )
685 pWin = FindBasWin( aDocument, aLibName, aName, true );
686 static_cast<ModulWindow*>(pWin)->EditMacro( rSbxItem.GetMethodName() );
688 DBG_ASSERT( pWin, "Window was not created!" );
689 SetCurWindow( pWin, true );
690 pTabBar->MakeVisible( pTabBar->GetCurPageId() );
692 break;
693 case SID_BASICIDE_SHOWWINDOW:
695 std::unique_ptr< ScriptDocument > pDocument;
697 const SfxStringItem* pDocumentItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_DOCUMENT);
698 if ( pDocumentItem )
700 const OUString& sDocumentCaption = pDocumentItem->GetValue();
701 if ( !sDocumentCaption.isEmpty() )
702 pDocument.reset( new ScriptDocument( ScriptDocument::getDocumentWithURLOrCaption( sDocumentCaption ) ) );
705 const SfxUnoAnyItem* pDocModelItem = rReq.GetArg<SfxUnoAnyItem>(SID_BASICIDE_ARG_DOCUMENT_MODEL);
706 if (!pDocument && pDocModelItem)
708 uno::Reference< frame::XModel > xModel( pDocModelItem->GetValue(), UNO_QUERY );
709 if ( xModel.is() )
710 pDocument.reset( new ScriptDocument( xModel ) );
713 if (!pDocument)
714 break;
716 const SfxStringItem* pLibNameItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_LIBNAME);
717 if ( !pLibNameItem )
718 break;
720 OUString aLibName( pLibNameItem->GetValue() );
721 pDocument->loadLibraryIfExists( E_SCRIPTS, aLibName );
722 SetCurLib( *pDocument, aLibName );
723 const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_NAME);
724 if ( pNameItem )
726 const OUString& aName( pNameItem->GetValue() );
727 OUString aModType( u"Module"_ustr );
728 OUString aType( aModType );
729 const SfxStringItem* pTypeItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_TYPE);
730 if ( pTypeItem )
731 aType = pTypeItem->GetValue();
733 BaseWindow* pWin = nullptr;
734 if ( aType == aModType )
735 pWin = FindBasWin( *pDocument, aLibName, aName );
736 else if ( aType == "Dialog" )
737 pWin = FindDlgWin( *pDocument, aLibName, aName );
739 if ( pWin )
741 SetCurWindow( pWin, true );
742 if ( pTabBar )
743 pTabBar->MakeVisible( pTabBar->GetCurPageId() );
745 if (ModulWindow* pModWin = dynamic_cast<ModulWindow*>(pWin))
747 const SfxUInt32Item* pLineItem = rReq.GetArg<SfxUInt32Item>(SID_BASICIDE_ARG_LINE);
748 if ( pLineItem )
750 pModWin->AssertValidEditEngine();
751 TextView* pTextView = pModWin->GetEditView();
752 if ( pTextView )
754 TextEngine* pTextEngine = pTextView->GetTextEngine();
755 if ( pTextEngine )
757 sal_uInt32 nLine = pLineItem->GetValue();
758 sal_uInt32 nLineCount = 0;
759 for ( sal_uInt32 i = 0, nCount = pTextEngine->GetParagraphCount(); i < nCount; ++i )
760 nLineCount += pTextEngine->GetLineCount( i );
761 if ( nLine > nLineCount )
762 nLine = nLineCount;
763 if ( nLine > 0 )
764 --nLine;
766 // scroll window and set selection
767 tools::Long nVisHeight = pModWin->GetOutputSizePixel().Height();
768 tools::Long nTextHeight = pTextEngine->GetTextHeight();
769 if ( nTextHeight > nVisHeight )
771 tools::Long nMaxY = nTextHeight - nVisHeight;
772 tools::Long nOldY = pTextView->GetStartDocPos().Y();
773 tools::Long nNewY = nLine * pTextEngine->GetCharHeight() - nVisHeight / 2;
774 nNewY = std::min( nNewY, nMaxY );
775 pTextView->Scroll( 0, -( nNewY - nOldY ) );
776 pTextView->ShowCursor( false );
777 pModWin->GetEditVScrollBar().SetThumbPos( pTextView->GetStartDocPos().Y() );
779 sal_uInt16 nCol1 = 0, nCol2 = 0;
780 const SfxUInt16Item* pCol1Item = rReq.GetArg<SfxUInt16Item>(SID_BASICIDE_ARG_COLUMN1);
781 if ( pCol1Item )
783 nCol1 = pCol1Item->GetValue();
784 if ( nCol1 > 0 )
785 --nCol1;
786 nCol2 = nCol1;
788 const SfxUInt16Item* pCol2Item = rReq.GetArg<SfxUInt16Item>(SID_BASICIDE_ARG_COLUMN2);
789 if ( pCol2Item )
791 nCol2 = pCol2Item->GetValue();
792 if ( nCol2 > 0 )
793 --nCol2;
795 TextSelection aSel( TextPaM( nLine, nCol1 ), TextPaM( nLine, nCol2 ) );
796 pTextView->SetSelection( aSel );
797 pTextView->ShowCursor();
798 vcl::Window* pWindow_ = pTextView->GetWindow();
799 if ( pWindow_ )
800 pWindow_->GrabFocus();
807 rReq.Done();
809 break;
811 case SID_BASICIDE_COLOR_SCHEME_DLG:
813 ModulWindowLayout* pMyLayout = dynamic_cast<ModulWindowLayout*>(pLayout.get());
814 if (!pMyLayout)
815 return;
817 OUString curScheme = pMyLayout->GetActiveColorSchemeId();
818 auto xDlg = std::make_shared<ColorSchemeDialog>(pCurWin ? pCurWin->GetFrameWeld() : nullptr,
819 pMyLayout);
820 weld::DialogController::runAsync(xDlg, [xDlg, pMyLayout, curScheme](sal_Int32 nResult){
821 OUString sNewScheme(xDlg->GetColorSchemeId());
822 // If the user canceled the dialog, restores the original color scheme
823 if (nResult != RET_OK)
825 if (curScheme != sNewScheme)
826 pMyLayout->ApplyColorSchemeToCurrentWindow(curScheme);
829 // If the user selects OK, apply the color scheme to all open ModulWindow
830 if (nResult == RET_OK)
832 // Set the global color scheme in ModulWindowLayout and update definitions in SyntaxColors
833 pMyLayout->ApplyColorSchemeToCurrentWindow(sNewScheme);
835 // Update color scheme for all windows
836 for (auto const& window : GetShell()->GetWindowTable())
838 ModulWindow* pModuleWindow = dynamic_cast<ModulWindow*>(window.second.get());
839 if (pModuleWindow)
841 // We need to set the current scheme for each window
842 pModuleWindow->SetEditorColorScheme(sNewScheme);
846 // Update registry with the new color scheme ID
847 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
848 officecfg::Office::BasicIDE::EditorSettings::ColorScheme::set(sNewScheme, batch);
849 batch->commit();
853 break;
855 case SID_BASICIDE_MANAGE_LANG:
857 auto xRequest = std::make_shared<SfxRequest>(rReq);
858 rReq.Ignore(); // the 'old' request is not relevant any more
859 auto xDlg = std::make_shared<ManageLanguageDialog>(pCurWin ? pCurWin->GetFrameWeld() : nullptr, m_pCurLocalizationMgr);
860 weld::DialogController::runAsync(xDlg, [xRequest=std::move(xRequest)](sal_Int32 /*nResult*/){
861 xRequest->Done();
864 break;
866 case SID_ATTR_ZOOMSLIDER:
868 const SfxItemSet *pArgs = rReq.GetArgs();
869 const SfxPoolItem* pItem;
871 if (pArgs && pArgs->GetItemState(SID_ATTR_ZOOMSLIDER, true, &pItem ) == SfxItemState::SET)
872 SetGlobalEditorZoomLevel(static_cast<const SvxZoomSliderItem*>(pItem)->GetValue());
874 lcl_InvalidateZoomSlots(GetBindingsPtr());
876 break;
878 case SID_ZOOM_IN:
879 case SID_ZOOM_OUT:
881 const sal_uInt16 nOldZoom = GetCurrentZoomSliderValue();
882 sal_uInt16 nNewZoom;
883 if (nSlot == SID_ZOOM_IN)
884 nNewZoom = std::min<sal_uInt16>(GetMaxZoom(), basegfx::zoomtools::zoomIn(nOldZoom));
885 else
886 nNewZoom = std::max<sal_uInt16>(GetMinZoom(), basegfx::zoomtools::zoomOut(nOldZoom));
887 SetGlobalEditorZoomLevel(nNewZoom);
888 lcl_InvalidateZoomSlots(GetBindingsPtr());
890 break;
892 default:
893 if (pLayout)
894 pLayout->ExecuteGlobal(rReq);
895 if (pCurWin)
896 pCurWin->ExecuteGlobal(rReq);
897 break;
901 void Shell::GetState(SfxItemSet &rSet)
903 SfxWhichIter aIter(rSet);
904 for ( sal_uInt16 nWh = aIter.FirstWhich(); nWh != 0; nWh = aIter.NextWhich() )
906 switch ( nWh )
908 case SID_NEWDOCDIRECT:
910 // we do not have a new document factory,
911 // so just forward to a fallback method.
912 SfxGetpApp()->GetSlotState(nWh, nullptr, &rSet);
914 break;
915 case SID_DOCINFO:
916 case SID_NEWWINDOW:
917 case SID_SAVEASDOC:
919 rSet.DisableItem( nWh );
921 break;
922 case SID_SAVEDOC:
924 bool bDisable = false;
926 if ( pCurWin )
928 if ( !pCurWin->IsModified() )
930 ScriptDocument aDocument( pCurWin->GetDocument() );
931 bDisable = ( !aDocument.isAlive() )
932 || ( aDocument.isDocument() ? !aDocument.isDocumentModified() : !IsAppBasicModified() );
935 else
937 bDisable = true;
940 if ( bDisable )
941 rSet.DisableItem( nWh );
943 break;
944 case SID_SIGNATURE:
946 SignatureState nState = SignatureState::NOSIGNATURES;
947 if ( pCurWin )
949 DocumentSignature aSignature( pCurWin->GetDocument() );
950 nState = aSignature.getScriptingSignatureState();
952 rSet.Put( SfxUInt16Item( SID_SIGNATURE, static_cast<sal_uInt16>(nState) ) );
954 break;
955 case SID_BASICIDE_MODULEDLG:
957 if ( StarBASIC::IsRunning() )
958 rSet.DisableItem( nWh );
960 break;
962 case SID_BASICIDE_OBJCAT:
964 if (pLayout)
965 rSet.Put(SfxBoolItem(nWh, aObjectCatalog->IsVisible()));
966 else
967 rSet.Put(SfxVisibilityItem(nWh, false));
969 break;
971 case SID_BASICIDE_WATCH:
973 if (pLayout)
975 rSet.Put(SfxBoolItem(nWh, pModulLayout->IsWatchWindowVisible()));
976 // Disable command if the visible window is not a ModulWindow
977 if (!dynamic_cast<ModulWindowLayout*>(pLayout.get()))
978 rSet.DisableItem(nWh);
980 else
981 rSet.Put(SfxVisibilityItem(nWh, false));
983 break;
985 case SID_BASICIDE_STACK:
987 if (pLayout)
989 rSet.Put(SfxBoolItem(nWh, pModulLayout->IsStackWindowVisible()));
990 // Disable command if the visible window is not a ModulWindow
991 if (!dynamic_cast<ModulWindowLayout*>(pLayout.get()))
992 rSet.DisableItem(nWh);
994 else
995 rSet.Put(SfxVisibilityItem(nWh, false));
997 break;
999 case SID_BASICIDE_SHOWSBX:
1000 case SID_BASICIDE_CREATEMACRO:
1001 case SID_BASICIDE_EDITMACRO:
1002 case SID_BASICIDE_NAMECHANGEDONTAB:
1006 break;
1008 case SID_BASICIDE_ADDWATCH:
1009 case SID_BASICIDE_REMOVEWATCH:
1010 case SID_BASICLOAD:
1011 case SID_BASICSAVEAS:
1012 case SID_BASICIDE_MATCHGROUP:
1014 if (!dynamic_cast<ModulWindow*>(pCurWin.get()))
1015 rSet.DisableItem( nWh );
1016 else if ( ( nWh == SID_BASICLOAD ) && ( StarBASIC::IsRunning() || ( pCurWin && pCurWin->IsReadOnly() ) ) )
1017 rSet.DisableItem( nWh );
1019 break;
1020 case SID_BASICRUN:
1021 case SID_BASICSTEPINTO:
1022 case SID_BASICSTEPOVER:
1023 case SID_BASICSTEPOUT:
1024 case SID_BASICIDE_TOGGLEBRKPNT:
1025 case SID_BASICIDE_MANAGEBRKPNTS:
1027 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
1029 if (StarBASIC::IsRunning() && !pMCurWin->GetBasicStatus().bIsInReschedule)
1030 rSet.DisableItem(nWh);
1032 else
1033 rSet.DisableItem( nWh );
1035 break;
1036 case SID_BASICCOMPILE:
1038 if (StarBASIC::IsRunning() || !dynamic_cast<ModulWindow*>(pCurWin.get()))
1039 rSet.DisableItem( nWh );
1041 break;
1042 case SID_BASICSTOP:
1044 // stop is always possible when some Basic is running...
1045 if (!StarBASIC::IsRunning())
1046 rSet.DisableItem( nWh );
1048 break;
1049 case SID_CHOOSE_CONTROLS:
1050 case SID_DIALOG_TESTMODE:
1051 case SID_INSERT_SELECT:
1052 case SID_INSERT_PUSHBUTTON:
1053 case SID_INSERT_RADIOBUTTON:
1054 case SID_INSERT_CHECKBOX:
1055 case SID_INSERT_LISTBOX:
1056 case SID_INSERT_COMBOBOX:
1057 case SID_INSERT_GROUPBOX:
1058 case SID_INSERT_EDIT:
1059 case SID_INSERT_FIXEDTEXT:
1060 case SID_INSERT_IMAGECONTROL:
1061 case SID_INSERT_PROGRESSBAR:
1062 case SID_INSERT_HSCROLLBAR:
1063 case SID_INSERT_VSCROLLBAR:
1064 case SID_INSERT_HFIXEDLINE:
1065 case SID_INSERT_VFIXEDLINE:
1066 case SID_INSERT_DATEFIELD:
1067 case SID_INSERT_TIMEFIELD:
1068 case SID_INSERT_NUMERICFIELD:
1069 case SID_INSERT_CURRENCYFIELD:
1070 case SID_INSERT_FORMATTEDFIELD:
1071 case SID_INSERT_PATTERNFIELD:
1072 case SID_INSERT_FILECONTROL:
1073 case SID_INSERT_SPINBUTTON:
1074 case SID_INSERT_GRIDCONTROL:
1075 case SID_INSERT_HYPERLINKCONTROL:
1076 case SID_INSERT_TREECONTROL:
1077 case SID_INSERT_FORM_RADIO:
1078 case SID_INSERT_FORM_CHECK:
1079 case SID_INSERT_FORM_LIST:
1080 case SID_INSERT_FORM_COMBO:
1081 case SID_INSERT_FORM_VSCROLL:
1082 case SID_INSERT_FORM_HSCROLL:
1083 case SID_INSERT_FORM_SPIN:
1085 if (!dynamic_cast<DialogWindow*>(pCurWin.get()))
1086 rSet.DisableItem( nWh );
1088 break;
1089 case SID_SEARCH_OPTIONS:
1091 SearchOptionFlags nOptions = SearchOptionFlags::NONE;
1092 if( pCurWin )
1093 nOptions = pCurWin->GetSearchOptions();
1094 rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, static_cast<sal_uInt16>(nOptions) ) );
1096 break;
1097 case SID_BASICIDE_LIBSELECTOR:
1099 OUString aName;
1100 if ( !m_aCurLibName.isEmpty() )
1102 LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName );
1103 aName = CreateMgrAndLibStr( m_aCurDocument.getTitle( eLocation ), m_aCurLibName );
1105 SfxStringItem aItem( SID_BASICIDE_LIBSELECTOR, aName );
1106 rSet.Put( aItem );
1108 break;
1109 case SID_SEARCH_ITEM:
1111 if ( !mpSearchItem )
1113 mpSearchItem.reset( new SvxSearchItem( SID_SEARCH_ITEM ));
1114 mpSearchItem->SetSearchString( GetSelectionText( true ));
1117 if ( mbJustOpened && HasSelection() )
1119 OUString aText = GetSelectionText( true );
1121 if ( !aText.isEmpty() )
1123 mpSearchItem->SetSearchString( aText );
1124 mpSearchItem->SetSelection( false );
1126 else
1127 mpSearchItem->SetSelection( true );
1130 mbJustOpened = false;
1131 rSet.Put( *mpSearchItem );
1133 break;
1134 case SID_BASICIDE_STAT_DATE:
1136 SfxStringItem aItem( SID_BASICIDE_STAT_DATE, u"Datum?!"_ustr );
1137 rSet.Put( aItem );
1139 break;
1140 case SID_DOC_MODIFIED:
1142 bool bModified = false;
1144 if ( pCurWin )
1146 if ( pCurWin->IsModified() )
1147 bModified = true;
1148 else
1150 ScriptDocument aDocument( pCurWin->GetDocument() );
1151 bModified = aDocument.isDocument() ? aDocument.isDocumentModified() : IsAppBasicModified();
1155 SfxBoolItem aItem(SID_DOC_MODIFIED, bModified);
1156 rSet.Put( aItem );
1158 break;
1159 case SID_BASICIDE_STAT_TITLE:
1161 if ( pCurWin )
1163 OUString aTitle = pCurWin->CreateQualifiedName();
1164 if (pCurWin->IsReadOnly())
1165 aTitle += " (" + IDEResId(RID_STR_READONLY) + ")";
1166 SfxStringItem aItem( SID_BASICIDE_STAT_TITLE, aTitle );
1167 rSet.Put( aItem );
1170 break;
1171 case SID_BASICIDE_CURRENT_ZOOM:
1173 // The current zoom value is only visible in a module window
1174 ModulWindow* pModuleWindow = dynamic_cast<ModulWindow*>(pCurWin.get());
1175 if (pModuleWindow)
1177 OUString sZoom;
1178 sZoom = OUString::number(m_nCurrentZoomSliderValue) + "%";
1179 SfxStringItem aItem( SID_BASICIDE_CURRENT_ZOOM, sZoom );
1180 rSet.Put( aItem );
1183 break;
1184 // are interpreted by the controller:
1185 case SID_ATTR_SIZE:
1186 case SID_ATTR_INSERT:
1187 break;
1188 case SID_UNDO:
1189 case SID_REDO:
1191 if( GetUndoManager() ) // recursive GetState else
1192 GetViewFrame().GetSlotState( nWh, nullptr, &rSet );
1194 break;
1195 case SID_BASICIDE_CURRENT_LANG:
1197 if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().isEmpty() )
1198 rSet.DisableItem( nWh );
1199 else
1201 OUString aItemStr;
1202 std::shared_ptr<LocalizationMgr> pCurMgr(GetCurLocalizationMgr());
1203 if ( pCurMgr->isLibraryLocalized() )
1205 Sequence< lang::Locale > aLocaleSeq = pCurMgr->getStringResourceManager()->getLocales();
1206 sal_Int32 i, nCount = aLocaleSeq.getLength();
1208 // Force different results for any combination of locales and default locale
1209 OUString aLangStr;
1210 for ( i = 0; i <= nCount; ++i )
1212 lang::Locale aLocale;
1213 if( i < nCount )
1214 aLocale = aLocaleSeq[i];
1215 else
1216 aLocale = pCurMgr->getStringResourceManager()->getDefaultLocale();
1218 aLangStr += aLocale.Language + aLocale.Country + aLocale.Variant;
1220 aItemStr = aLangStr;
1222 rSet.Put( SfxStringItem( nWh, aItemStr ) );
1225 break;
1227 case SID_BASICIDE_MANAGE_LANG:
1229 if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().isEmpty() )
1230 rSet.DisableItem( nWh );
1232 break;
1233 case SID_TOGGLE_COMMENT:
1235 // Only available in a ModulWindow if the document can be edited
1236 if (pCurWin && (!dynamic_cast<ModulWindow*>(pCurWin.get()) || pCurWin->IsReadOnly()))
1237 rSet.DisableItem(nWh);
1239 break;
1240 case SID_GOTOLINE:
1242 // if this is not a module window hide the
1243 // setting, doesn't make sense for example if the
1244 // dialog editor is open
1245 if (pCurWin && !dynamic_cast<ModulWindow*>(pCurWin.get()))
1247 rSet.DisableItem( nWh );
1248 rSet.Put(SfxVisibilityItem(nWh, false));
1250 break;
1252 case SID_BASICIDE_HIDECURPAGE:
1254 if (pTabBar->GetPageCount() == 0)
1255 rSet.DisableItem(nWh);
1257 break;
1258 case SID_BASICIDE_DELETECURRENT:
1259 case SID_BASICIDE_RENAMECURRENT:
1261 if (pTabBar->GetPageCount() == 0 || StarBASIC::IsRunning())
1262 rSet.DisableItem(nWh);
1263 else if (m_aCurDocument.isInVBAMode())
1265 // disable to delete or rename object modules in IDE
1266 BasicManager* pBasMgr = m_aCurDocument.getBasicManager();
1267 StarBASIC* pBasic = pBasMgr ? pBasMgr->GetLib(m_aCurLibName) : nullptr;
1268 if (pBasic && dynamic_cast<ModulWindow*>(pCurWin.get()))
1270 SbModule* pActiveModule = pBasic->FindModule( pCurWin->GetName() );
1271 if ( pActiveModule && ( pActiveModule->GetModuleType() == script::ModuleType::DOCUMENT ) )
1272 rSet.DisableItem(nWh);
1276 [[fallthrough]];
1278 case SID_BASICIDE_NEWMODULE:
1279 case SID_BASICIDE_NEWDIALOG:
1281 Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
1282 Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
1283 if ( ( xModLibContainer.is() && xModLibContainer->hasByName( m_aCurLibName ) && xModLibContainer->isLibraryReadOnly( m_aCurLibName ) ) ||
1284 ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( m_aCurLibName ) && xDlgLibContainer->isLibraryReadOnly( m_aCurLibName ) ) )
1285 rSet.DisableItem(nWh);
1287 break;
1289 case SID_ZOOM_IN:
1290 case SID_ZOOM_OUT:
1292 const sal_uInt16 nCurrentZoom = GetCurrentZoomSliderValue();
1293 if ((nWh == SID_ZOOM_IN && nCurrentZoom >= GetMaxZoom()) ||
1294 (nWh == SID_ZOOM_OUT && nCurrentZoom <= GetMinZoom()))
1295 rSet.DisableItem(nWh);
1297 break;
1299 case SID_BASICIDE_COLOR_SCHEME_DLG:
1301 if (!dynamic_cast<ModulWindowLayout*>(pLayout.get()))
1302 rSet.DisableItem(nWh);
1304 break;
1306 case SID_ATTR_ZOOMSLIDER:
1308 // The zoom slider is only visible in a module window
1309 ModulWindow* pModuleWindow = dynamic_cast<ModulWindow*>(pCurWin.get());
1310 if (pModuleWindow)
1312 SvxZoomSliderItem aZoomSliderItem(GetCurrentZoomSliderValue(), GetMinZoom(), GetMaxZoom());
1313 aZoomSliderItem.AddSnappingPoint(100);
1314 rSet.Put( aZoomSliderItem );
1317 break;
1319 default:
1320 if (pLayout)
1321 pLayout->GetState(rSet, nWh);
1324 if ( pCurWin )
1325 pCurWin->GetState( rSet );
1328 bool Shell::HasUIFeature(SfxShellFeature nFeature) const
1330 assert((nFeature & ~SfxShellFeature::BasicMask) == SfxShellFeature::NONE);
1331 bool bResult = false;
1333 if (nFeature & SfxShellFeature::BasicShowBrowser)
1335 // fade out (in) property browser in module (dialog) windows
1336 if (dynamic_cast<DialogWindow*>(pCurWin.get()) && !pCurWin->IsReadOnly())
1337 bResult = true;
1340 return bResult;
1343 void Shell::SetCurWindow( BaseWindow* pNewWin, bool bUpdateTabBar, bool bRememberAsCurrent )
1345 if ( pNewWin == pCurWin )
1346 return;
1348 pCurWin = pNewWin;
1349 if (pLayout)
1350 pLayout->Deactivating();
1351 if (pCurWin)
1353 if (pCurWin->GetSbxType() == SBX_TYPE_MODULE)
1354 pLayout = pModulLayout.get();
1355 else
1356 pLayout = pDialogLayout.get();
1357 AdjustPosSizePixel(Point(0, 0), GetViewFrame().GetWindow().GetOutputSizePixel());
1358 pLayout->Activating(*pCurWin);
1359 GetViewFrame().GetWindow().SetHelpId(pCurWin->GetHid());
1360 if (bRememberAsCurrent)
1361 pCurWin->InsertLibInfo();
1362 if (GetViewFrame().GetWindow().IsVisible()) // SFX will do it later otherwise
1363 pCurWin->Show();
1364 pCurWin->Init();
1365 if (!GetExtraData()->ShellInCriticalSection())
1367 vcl::Window* pFrameWindow = &GetViewFrame().GetWindow();
1368 vcl::Window* pFocusWindow = Application::GetFocusWindow();
1369 while ( pFocusWindow && ( pFocusWindow != pFrameWindow ) )
1370 pFocusWindow = pFocusWindow->GetParent();
1371 if ( pFocusWindow ) // Focus in BasicIDE
1372 pCurWin->GrabFocus();
1375 else
1377 SetWindow(pLayout);
1378 pLayout = nullptr;
1380 if ( bUpdateTabBar )
1382 sal_uInt16 nKey = GetWindowId( pCurWin );
1383 if ( pCurWin && ( pTabBar->GetPagePos( nKey ) == TabBar::PAGE_NOT_FOUND ) )
1384 pTabBar->InsertPage( nKey, pCurWin->GetTitle() ); // has just been faded in
1385 pTabBar->SetCurPageId( nKey );
1387 if ( pCurWin && pCurWin->IsSuspended() ) // if the window is shown in the case of an error...
1388 pCurWin->SetStatus( pCurWin->GetStatus() & ~BASWIN_SUSPENDED );
1389 if ( pCurWin )
1391 SetWindow( pCurWin );
1392 if ( pCurWin->GetDocument().isDocument() )
1393 SfxObjectShell::SetCurrentComponent( pCurWin->GetDocument().getDocument() );
1395 else if (pLayout)
1397 SetWindow(pLayout);
1398 GetViewFrame().GetWindow().SetHelpId( HID_BASICIDE_MODULWINDOW );
1399 SfxObjectShell::SetCurrentComponent(nullptr);
1401 aObjectCatalog->SetCurrentEntry(pCurWin);
1402 SetUndoManager( pCurWin ? pCurWin->GetUndoManager() : nullptr );
1403 InvalidateBasicIDESlots();
1404 InvalidateControlSlots();
1406 if ( m_pCurLocalizationMgr )
1407 m_pCurLocalizationMgr->handleTranslationbar();
1409 ManageToolbars();
1411 // fade out (in) property browser in module (dialog) windows
1412 UIFeatureChanged();
1415 void Shell::ManageToolbars()
1417 static constexpr OUString aMacroBarResName = u"private:resource/toolbar/macrobar"_ustr;
1418 static constexpr OUString aDialogBarResName = u"private:resource/toolbar/dialogbar"_ustr;
1419 static constexpr OUString aInsertControlsBarResName
1420 = u"private:resource/toolbar/insertcontrolsbar"_ustr;
1421 static constexpr OUString aFormControlsBarResName
1422 = u"private:resource/toolbar/formcontrolsbar"_ustr;
1424 if( !pCurWin )
1425 return;
1427 Reference< beans::XPropertySet > xFrameProps
1428 ( GetViewFrame().GetFrame().GetFrameInterface(), uno::UNO_QUERY );
1429 if ( !xFrameProps.is() )
1430 return;
1432 Reference< css::frame::XLayoutManager > xLayoutManager;
1433 uno::Any a = xFrameProps->getPropertyValue( u"LayoutManager"_ustr );
1434 a >>= xLayoutManager;
1435 if ( !xLayoutManager.is() )
1436 return;
1438 xLayoutManager->lock();
1439 if (dynamic_cast<DialogWindow*>(pCurWin.get()))
1441 xLayoutManager->destroyElement( aMacroBarResName );
1443 xLayoutManager->requestElement( aDialogBarResName );
1444 xLayoutManager->requestElement( aInsertControlsBarResName );
1445 xLayoutManager->requestElement( aFormControlsBarResName );
1447 else
1449 xLayoutManager->destroyElement( aDialogBarResName );
1450 xLayoutManager->destroyElement( aInsertControlsBarResName );
1451 xLayoutManager->destroyElement( aFormControlsBarResName );
1453 xLayoutManager->requestElement( aMacroBarResName );
1455 xLayoutManager->unlock();
1458 VclPtr<BaseWindow> Shell::FindApplicationWindow()
1460 return FindWindow( ScriptDocument::getApplicationScriptDocument(), u"", u"", SBX_TYPE_UNKNOWN );
1463 VclPtr<BaseWindow> Shell::FindWindow(
1464 ScriptDocument const& rDocument,
1465 std::u16string_view rLibName, std::u16string_view rName,
1466 SbxItemType eSbxItemType, bool bFindSuspended
1469 for (auto const& window : aWindowTable)
1471 BaseWindow* const pWin = window.second;
1472 if (pWin->Is(rDocument, rLibName, rName, eSbxItemType, bFindSuspended))
1473 return pWin;
1475 return nullptr;
1478 bool Shell::CallBasicErrorHdl( StarBASIC const * pBasic )
1480 VclPtr<ModulWindow> pModWin = ShowActiveModuleWindow( pBasic );
1481 if ( pModWin )
1482 pModWin->BasicErrorHdl( pBasic );
1483 return false;
1486 BasicDebugFlags Shell::CallBasicBreakHdl( StarBASIC const * pBasic )
1488 BasicDebugFlags nRet = BasicDebugFlags::NONE;
1489 VclPtr<ModulWindow> pModWin = ShowActiveModuleWindow( pBasic );
1490 if ( pModWin )
1492 bool bAppWindowDisabled, bDispatcherLocked;
1493 sal_uInt16 nWaitCount;
1494 SfxUInt16Item *pSWActionCount, *pSWLockViewCount;
1495 BasicStopped( &bAppWindowDisabled, &bDispatcherLocked,
1496 &nWaitCount, &pSWActionCount, &pSWLockViewCount );
1498 nRet = pModWin->BasicBreakHdl();
1500 if ( StarBASIC::IsRunning() ) // if cancelled...
1502 if ( bAppWindowDisabled )
1503 Application::GetDefDialogParent()->set_sensitive(false);
1505 if ( nWaitCount )
1507 Shell* pShell = GetShell();
1508 for ( sal_uInt16 n = 0; n < nWaitCount; n++ )
1509 pShell->GetViewFrame().GetWindow().EnterWait();
1513 return nRet;
1516 VclPtr<ModulWindow> Shell::ShowActiveModuleWindow( StarBASIC const * pBasic )
1518 SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
1520 SbModule* pActiveModule = StarBASIC::GetActiveModule();
1521 if (SbClassModuleObject* pCMO = dynamic_cast<SbClassModuleObject*>(pActiveModule))
1522 pActiveModule = &pCMO->getClassModule();
1524 DBG_ASSERT( pActiveModule, "No active module in ErrorHdl!?" );
1525 if ( pActiveModule )
1527 VclPtr<ModulWindow> pWin;
1528 SbxObject* pParent = pActiveModule->GetParent();
1529 if (StarBASIC* pLib = dynamic_cast<StarBASIC*>(pParent))
1531 if (BasicManager* pBasMgr = FindBasicManager(pLib))
1533 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
1534 const OUString& aLibName = pLib->GetName();
1535 pWin = FindBasWin( aDocument, aLibName, pActiveModule->GetName(), true );
1536 DBG_ASSERT( pWin, "Error/Step-Hdl: Window was not created/found!" );
1537 SetCurLib( aDocument, aLibName );
1538 SetCurWindow( pWin, true );
1541 else
1542 SAL_WARN( "basctl.basicide", "No BASIC!");
1543 if (BasicManager* pBasicMgr = FindBasicManager(pBasic))
1544 StartListening(*pBasicMgr, DuplicateHandling::Prevent /* log on only once */);
1545 return pWin;
1547 return nullptr;
1550 void Shell::AdjustPosSizePixel( const Point &rPos, const Size &rSize )
1552 // not if iconified because the whole text would be displaced then at restore
1553 if ( GetViewFrame().GetWindow().GetOutputSizePixel().Height() == 0 )
1554 return;
1556 Size aTabBarSize;
1557 aTabBarSize.setHeight( GetViewFrame().GetWindow().GetFont().GetFontHeight() + TAB_HEIGHT_MARGIN );
1558 aTabBarSize.setWidth( rSize.Width() );
1560 Size aSz( rSize );
1561 auto nScrollBarSz(Application::GetSettings().GetStyleSettings().GetScrollBarSize());
1562 aSz.AdjustHeight(-aTabBarSize.Height());
1564 Size aOutSz( aSz );
1565 aSz.AdjustWidth(-nScrollBarSz);
1566 aSz.AdjustHeight(-nScrollBarSz);
1567 aVScrollBar->SetPosSizePixel( Point( rPos.X()+aSz.Width(), rPos.Y() ), Size( nScrollBarSz, aSz.Height() ) );
1568 aHScrollBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aSz.Height() ), Size( aOutSz.Width(), nScrollBarSz ) );
1569 pTabBar->SetPosSizePixel( Point( rPos.X(), rPos.Y() + nScrollBarSz + aSz.Height()), aTabBarSize );
1571 // The size to be applied depends on whether it is a DialogWindow or a ModulWindow
1572 if (pLayout)
1574 if (dynamic_cast<DialogWindow*>(pCurWin.get()))
1576 pCurWin->ShowShellScrollBars();
1577 pLayout->SetPosSizePixel(rPos, aSz);
1579 else
1581 pCurWin->ShowShellScrollBars(false);
1582 pLayout->SetPosSizePixel(rPos, aOutSz);
1587 Reference< XModel > Shell::GetCurrentDocument() const
1589 Reference< XModel > xDocument;
1590 if ( pCurWin && pCurWin->GetDocument().isDocument() )
1591 xDocument = pCurWin->GetDocument().getDocument();
1592 return xDocument;
1595 void Shell::Activate( bool bMDI )
1597 SfxViewShell::Activate( bMDI );
1599 if ( bMDI )
1601 if (DialogWindow* pDCurWin = dynamic_cast<DialogWindow*>(pCurWin.get()))
1602 pDCurWin->UpdateBrowser();
1606 void Shell::Deactivate( bool bMDI )
1608 // bMDI == true means that another MDI has been activated; in case of a
1609 // deactivate due to a MessageBox bMDI is false
1610 if ( bMDI )
1612 if (DialogWindow* pXDlgWin = dynamic_cast<DialogWindow*>(pCurWin.get()))
1614 pXDlgWin->DisableBrowser();
1615 if( pXDlgWin->IsModified() )
1616 MarkDocumentModified( pXDlgWin->GetDocument() );
1621 } // namespace basctl
1623 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */