android: Update app-specific/MIME type icons
[LibreOffice.git] / basctl / source / basicide / basides1.cxx
blob66820cd21881228b906ae203bbb8d6dbd347d5a8
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>
35 #include <basic/basmgr.hxx>
36 #include <com/sun/star/script/ModuleType.hpp>
37 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
38 #include <com/sun/star/script/XLibraryContainer2.hpp>
39 #include <com/sun/star/frame/XLayoutManager.hpp>
40 #include <svl/srchdefs.hxx>
41 #include <sal/log.hxx>
42 #include <osl/diagnose.h>
43 #include <sfx2/app.hxx>
44 #include <sfx2/bindings.hxx>
45 #include <sfx2/childwin.hxx>
46 #include <sfx2/dinfdlg.hxx>
47 #include <sfx2/minfitem.hxx>
48 #include <sfx2/request.hxx>
49 #include <sfx2/viewfrm.hxx>
50 #include <svx/svxids.hrc>
51 #include <svl/eitem.hxx>
52 #include <svl/intitem.hxx>
53 #include <svl/visitem.hxx>
54 #include <svl/whiter.hxx>
55 #include <vcl/texteng.hxx>
56 #include <vcl/textview.hxx>
57 #include <vcl/svapp.hxx>
58 #include <vcl/weld.hxx>
59 #include <svx/zoomsliderctrl.hxx>
60 #include <svx/zoomslideritem.hxx>
61 #include <basegfx/utils/zoomtools.hxx>
63 constexpr sal_Int32 TAB_HEIGHT_MARGIN = 10;
65 namespace basctl
68 using namespace ::com::sun::star;
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::frame;
72 static void lcl_InvalidateZoomSlots(SfxBindings* pBindings)
74 if (!pBindings)
75 return;
77 static sal_uInt16 const aInval[] = {
78 SID_ZOOM_OUT, SID_ZOOM_IN, SID_ATTR_ZOOMSLIDER, 0
80 pBindings->Invalidate(aInval);
83 void Shell::ExecuteSearch( SfxRequest& rReq )
85 if ( !pCurWin )
86 return;
88 const SfxItemSet* pArgs = rReq.GetArgs();
89 sal_uInt16 nSlot = rReq.GetSlot();
91 // if searching has not been done before this time
92 if (nSlot == SID_BASICIDE_REPEAT_SEARCH && !mpSearchItem)
94 rReq.SetReturnValue(SfxBoolItem(nSlot, false));
95 nSlot = 0;
98 switch ( nSlot )
100 case SID_SEARCH_OPTIONS:
101 break;
102 case SID_SEARCH_ITEM:
103 mpSearchItem.reset(pArgs->Get(SID_SEARCH_ITEM).Clone());
104 break;
105 case FID_SEARCH_ON:
106 mbJustOpened = true;
107 GetViewFrame().GetBindings().Invalidate(SID_SEARCH_ITEM);
108 break;
109 case SID_BASICIDE_REPEAT_SEARCH:
110 case FID_SEARCH_NOW:
112 if (!pCurWin->HasActiveEditor())
113 break;
115 // If it is a repeat searching
116 if ( nSlot == SID_BASICIDE_REPEAT_SEARCH )
118 if( !mpSearchItem )
119 mpSearchItem.reset( new SvxSearchItem( SID_SEARCH_ITEM ));
121 else
123 // Get SearchItem from request if it is the first searching
124 if ( pArgs )
126 mpSearchItem.reset(pArgs->Get(SID_SEARCH_ITEM).Clone());
130 sal_Int32 nFound = 0;
132 if ( mpSearchItem->GetCommand() == SvxSearchCmd::REPLACE_ALL )
134 sal_uInt16 nActModWindows = 0;
135 for (auto const& window : aWindowTable)
137 BaseWindow* pWin = window.second;
138 if (pWin->HasActiveEditor())
139 nActModWindows++;
142 bool bAllModules = nActModWindows <= 1;
143 if (!bAllModules)
145 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(pCurWin ? pCurWin->GetFrameWeld() : nullptr,
146 VclMessageType::Question, VclButtonsType::YesNo,
147 IDEResId(RID_STR_SEARCHALLMODULES)));
148 xQueryBox->set_default_response(RET_YES);
149 bAllModules = xQueryBox->run() == RET_YES;
152 if (bAllModules)
154 for (auto const& window : aWindowTable)
156 BaseWindow* pWin = window.second;
157 nFound += pWin->StartSearchAndReplace( *mpSearchItem );
160 else
161 nFound = pCurWin->StartSearchAndReplace( *mpSearchItem );
163 OUString aReplStr(IDEResId(RID_STR_SEARCHREPLACES));
164 aReplStr = aReplStr.replaceAll("XX", OUString::number(nFound));
166 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pCurWin->GetFrameWeld(),
167 VclMessageType::Info, VclButtonsType::Ok,
168 aReplStr));
169 xInfoBox->run();
171 else
173 bool bCanceled = false;
174 nFound = pCurWin->StartSearchAndReplace( *mpSearchItem );
175 if ( !nFound && !mpSearchItem->GetSelection() )
177 // search other modules...
178 bool bChangeCurWindow = false;
179 auto it = std::find_if(aWindowTable.cbegin(), aWindowTable.cend(),
180 [this](const WindowTable::value_type& item) { return item.second == pCurWin; });
181 if (it != aWindowTable.cend())
182 ++it;
183 BaseWindow* pWin = it != aWindowTable.cend() ? it->second.get() : nullptr;
185 bool bSearchedFromStart = false;
186 while ( !nFound && !bCanceled && ( pWin || !bSearchedFromStart ) )
188 if ( !pWin )
190 SfxViewFrame& rViewFrame = GetViewFrame();
191 SfxChildWindow* pChildWin = rViewFrame.GetChildWindow(SID_SEARCH_DLG);
192 auto xParent = pChildWin ? pChildWin->GetController() : nullptr;
194 std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(xParent ? xParent->getDialog() : nullptr,
195 VclMessageType::Question, VclButtonsType::YesNo,
196 IDEResId(RID_STR_SEARCHFROMSTART)));
197 xQueryBox->set_default_response(RET_YES);
198 if (xQueryBox->run() == RET_YES)
200 it = aWindowTable.cbegin();
201 if ( it != aWindowTable.cend() )
202 pWin = it->second;
203 bSearchedFromStart = true;
205 else
206 bCanceled = true;
209 if (pWin && pWin->HasActiveEditor())
211 if ( pWin != pCurWin )
213 if ( pCurWin )
214 pWin->SetSizePixel( pCurWin->GetSizePixel() );
215 nFound = pWin->StartSearchAndReplace( *mpSearchItem, true );
217 if ( nFound )
219 bChangeCurWindow = true;
220 break;
223 if ( pWin && ( pWin != pCurWin ) )
225 if ( it != aWindowTable.cend() )
226 ++it;
227 pWin = it != aWindowTable.cend() ? it->second.get() : nullptr;
229 else
230 pWin = nullptr;
232 if ( !nFound && bSearchedFromStart )
233 nFound = pCurWin->StartSearchAndReplace( *mpSearchItem, true );
234 if ( bChangeCurWindow )
235 SetCurWindow( pWin, true );
237 if ( !nFound && !bCanceled )
239 std::unique_ptr<weld::MessageDialog> xInfoBox(Application::CreateMessageDialog(pCurWin->GetFrameWeld(),
240 VclMessageType::Info, VclButtonsType::Ok,
241 IDEResId(RID_STR_SEARCHNOTFOUND)));
242 xInfoBox->run();
246 rReq.Done();
247 break;
249 default:
250 pCurWin->ExecuteCommand( rReq );
254 void Shell::ExecuteCurrent( SfxRequest& rReq )
256 if ( !pCurWin )
257 return;
259 switch ( rReq.GetSlot() )
261 case SID_BASICIDE_HIDECURPAGE:
263 pCurWin->StoreData();
264 RemoveWindow( pCurWin, false );
266 break;
267 case SID_BASICIDE_RENAMECURRENT:
269 pTabBar->StartEditMode( pTabBar->GetCurPageId() );
271 break;
272 case SID_UNDO:
273 case SID_REDO:
274 if ( GetUndoManager() && pCurWin->AllowUndo() )
275 GetViewFrame().ExecuteSlot( rReq );
276 break;
277 default:
278 pCurWin->ExecuteCommand( rReq );
282 // no matter who's at the top, influence on the shell:
283 void Shell::ExecuteGlobal( SfxRequest& rReq )
285 sal_uInt16 nSlot = rReq.GetSlot();
286 switch ( nSlot )
288 case SID_NEWDOCDIRECT:
290 // we do not have a new document factory,
291 // so just forward to a fallback method.
292 SfxGetpApp()->ExecuteSlot(rReq);
294 break;
296 case SID_BASICSTOP:
298 // maybe do not simply stop if on breakpoint!
299 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
300 pMCurWin->BasicStop();
301 StopBasic();
303 break;
305 case SID_SAVEDOC:
307 if ( pCurWin )
309 // rewrite date into the BASIC
310 StoreAllWindowData();
312 // document basic
313 ScriptDocument aDocument( pCurWin->GetDocument() );
314 if ( aDocument.isDocument() )
316 uno::Reference< task::XStatusIndicator > xStatusIndicator;
318 const SfxUnoAnyItem* pStatusIndicatorItem = rReq.GetArg<SfxUnoAnyItem>(SID_PROGRESS_STATUSBAR_CONTROL);
319 if ( pStatusIndicatorItem )
320 OSL_VERIFY( pStatusIndicatorItem->GetValue() >>= xStatusIndicator );
321 else
323 // get statusindicator
324 SfxViewFrame *pFrame_ = GetFrame();
325 if ( pFrame_ )
327 uno::Reference< task::XStatusIndicatorFactory > xStatFactory(
328 pFrame_->GetFrame().GetFrameInterface(),
329 uno::UNO_QUERY );
330 if( xStatFactory.is() )
331 xStatusIndicator = xStatFactory->createStatusIndicator();
334 if ( xStatusIndicator.is() )
335 rReq.AppendItem( SfxUnoAnyItem( SID_PROGRESS_STATUSBAR_CONTROL, uno::Any( xStatusIndicator ) ) );
338 aDocument.saveDocument( xStatusIndicator );
341 if (SfxBindings* pBindings = GetBindingsPtr())
343 pBindings->Invalidate( SID_DOC_MODIFIED );
344 pBindings->Invalidate( SID_SAVEDOC );
345 pBindings->Invalidate( SID_SIGNATURE );
349 break;
350 case SID_BASICIDE_MODULEDLG:
352 if ( rReq.GetArgs() )
354 const SfxUInt16Item &rTabId = rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
355 Organize(rReq.GetFrameWeld(), nullptr, rTabId.GetValue());
357 else
358 Organize(rReq.GetFrameWeld(), nullptr, 0);
360 break;
361 case SID_BASICIDE_CHOOSEMACRO:
363 ChooseMacro(rReq.GetFrameWeld(), nullptr);
365 break;
366 case SID_BASICIDE_CREATEMACRO:
367 case SID_BASICIDE_EDITMACRO:
369 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
370 const SfxMacroInfoItem& rInfo = rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
371 BasicManager* pBasMgr = const_cast<BasicManager*>(rInfo.GetBasicManager());
372 DBG_ASSERT( pBasMgr, "Nothing selected in basic tree?" );
374 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
376 StartListening(*pBasMgr, DuplicateHandling::Prevent /* log on only once */);
377 OUString aLibName( rInfo.GetLib() );
378 if ( aLibName.isEmpty() )
379 aLibName = "Standard" ;
380 StarBASIC* pBasic = pBasMgr->GetLib( aLibName );
381 if ( !pBasic )
383 // load module and dialog library (if not loaded)
384 aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
385 aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
387 // get Basic
388 pBasic = pBasMgr->GetLib( aLibName );
390 DBG_ASSERT( pBasic, "No Basic!" );
392 SetCurLib( aDocument, aLibName );
394 if ( pBasic && rReq.GetSlot() == SID_BASICIDE_CREATEMACRO )
396 SbModule* pModule = pBasic->FindModule( rInfo.GetModule() );
397 if ( !pModule )
399 if ( !rInfo.GetModule().isEmpty() || pBasic->GetModules().empty() )
401 const OUString& aModName = rInfo.GetModule();
403 OUString sModuleCode;
404 if ( aDocument.createModule( aLibName, aModName, false, sModuleCode ) )
405 pModule = pBasic->FindModule( aModName );
407 else
408 pModule = pBasic->GetModules().front().get();
410 DBG_ASSERT( pModule, "No Module!" );
411 if ( pModule && !pModule->GetMethods()->Find( rInfo.GetMethod(), SbxClassType::Method ) )
412 CreateMacro( pModule, rInfo.GetMethod() );
414 SfxViewFrame& rViewFrame = GetViewFrame();
415 rViewFrame.ToTop();
416 VclPtr<ModulWindow> pWin = FindBasWin( aDocument, aLibName, rInfo.GetModule(), true );
417 DBG_ASSERT( pWin, "Edit/Create Macro: Window was not created/found!" );
418 SetCurWindow( pWin, true );
419 pWin->EditMacro( rInfo.GetMethod() );
421 break;
423 case SID_BASICIDE_OBJCAT:
424 // toggling object catalog
425 aObjectCatalog->Show(!aObjectCatalog->IsVisible());
426 if (pLayout)
427 pLayout->ArrangeWindows();
428 // refresh the button state
429 if (SfxBindings* pBindings = GetBindingsPtr())
430 pBindings->Invalidate(SID_BASICIDE_OBJCAT);
431 break;
433 case SID_BASICIDE_WATCH:
435 // Toggling the watch window can only be done from a ModulWindow
436 if (!dynamic_cast<ModulWindowLayout*>(pLayout.get()))
437 return;
439 pModulLayout->ShowWatchWindow(!pModulLayout->IsWatchWindowVisible());
440 if (SfxBindings* pBindings = GetBindingsPtr())
441 pBindings->Invalidate(SID_BASICIDE_WATCH);
443 break;
445 case SID_BASICIDE_STACK:
447 // Toggling the stack window can only be done from a ModulWindow
448 if (!dynamic_cast<ModulWindowLayout*>(pLayout.get()))
449 return;
451 pModulLayout->ShowStackWindow(!pModulLayout->IsStackWindowVisible());
452 if (SfxBindings* pBindings = GetBindingsPtr())
453 pBindings->Invalidate(SID_BASICIDE_STACK);
455 break;
457 case SID_BASICIDE_NAMECHANGEDONTAB:
459 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
460 const SfxUInt16Item &rTabId = rReq.GetArgs()->Get(SID_BASICIDE_ARG_TABID );
461 const SfxStringItem &rModName = rReq.GetArgs()->Get(SID_BASICIDE_ARG_MODULENAME );
462 if ( aWindowTable.find( rTabId.GetValue() ) != aWindowTable.end() )
464 VclPtr<BaseWindow> pWin = aWindowTable[ rTabId.GetValue() ];
465 const OUString& aNewName( rModName.GetValue() );
466 OUString aOldName( pWin->GetName() );
467 if ( aNewName != aOldName )
469 bool bRenameOk = false;
470 if (ModulWindow* pModWin = dynamic_cast<ModulWindow*>(pWin.get()))
472 const OUString& aLibName = pModWin->GetLibName();
473 ScriptDocument aDocument( pWin->GetDocument() );
475 if (RenameModule(pModWin->GetFrameWeld(), aDocument, aLibName, aOldName, aNewName))
477 bRenameOk = true;
478 // Because we listen for container events for script
479 // modules, rename will delete the 'old' window
480 // pWin has been invalidated, restore now
481 pWin = FindBasWin( aDocument, aLibName, aNewName, true );
485 else if (DialogWindow* pDlgWin = dynamic_cast<DialogWindow*>(pWin.get()))
487 bRenameOk = pDlgWin->RenameDialog( aNewName );
489 if ( bRenameOk )
491 MarkDocumentModified( pWin->GetDocument() );
493 else
495 // set old name in TabWriter
496 sal_uInt16 nId = GetWindowId( pWin );
497 DBG_ASSERT( nId, "No entry in Tabbar!" );
498 if ( nId )
499 pTabBar->SetPageText( nId, aOldName );
503 // set focus to current window
504 pWin->GrabFocus();
507 break;
508 case SID_BASICIDE_STOREMODULESOURCE:
509 case SID_BASICIDE_UPDATEMODULESOURCE:
511 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
512 const SfxMacroInfoItem& rInfo = rReq.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO );
513 BasicManager* pBasMgr = const_cast<BasicManager*>(rInfo.GetBasicManager());
514 DBG_ASSERT( pBasMgr, "Store source: No BasMgr?" );
515 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
516 VclPtr<ModulWindow> pWin = FindBasWin( aDocument, rInfo.GetLib(), rInfo.GetModule(), false, true );
517 if ( pWin )
519 if ( rReq.GetSlot() == SID_BASICIDE_STOREMODULESOURCE )
520 pWin->StoreData();
521 else
522 pWin->UpdateData();
525 break;
526 case SID_BASICIDE_STOREALLMODULESOURCES:
527 case SID_BASICIDE_UPDATEALLMODULESOURCES:
529 for (auto const& window : aWindowTable)
531 BaseWindow* pWin = window.second;
532 if (!pWin->IsSuspended() && dynamic_cast<ModulWindow*>(pWin))
534 if ( rReq.GetSlot() == SID_BASICIDE_STOREALLMODULESOURCES )
535 pWin->StoreData();
536 else
537 pWin->UpdateData();
541 break;
542 case SID_BASICIDE_LIBSELECTED:
543 case SID_BASICIDE_LIBREMOVED:
544 case SID_BASICIDE_LIBLOADED:
546 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
547 const SfxUnoAnyItem& rShellItem = rReq.GetArgs()->Get( SID_BASICIDE_ARG_DOCUMENT_MODEL );
548 uno::Reference< frame::XModel > xModel( rShellItem.GetValue(), UNO_QUERY );
549 ScriptDocument aDocument( xModel.is() ? ScriptDocument( xModel ) : ScriptDocument::getApplicationScriptDocument() );
550 const SfxStringItem& rLibNameItem = rReq.GetArgs()->Get( SID_BASICIDE_ARG_LIBNAME );
551 const OUString& aLibName( rLibNameItem.GetValue() );
553 if ( nSlot == SID_BASICIDE_LIBSELECTED )
555 // load module and dialog library (if not loaded)
556 aDocument.loadLibraryIfExists( E_SCRIPTS, aLibName );
557 aDocument.loadLibraryIfExists( E_DIALOGS, aLibName );
559 // check password, if library is password protected and not verified
560 bool bOK = true;
561 Reference< script::XLibraryContainer > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ) );
562 if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
564 Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
565 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
567 OUString aPassword;
568 bOK = QueryPassword(rReq.GetFrameWeld(), xModLibContainer, aLibName, aPassword);
572 if ( bOK )
574 SetCurLib( aDocument, aLibName, true, false );
576 else
578 // adjust old value...
579 if (SfxBindings* pBindings = GetBindingsPtr())
580 pBindings->Invalidate(SID_BASICIDE_LIBSELECTOR, true);
583 else if ( nSlot == SID_BASICIDE_LIBREMOVED )
585 if ( m_aCurLibName.isEmpty() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
587 RemoveWindows( aDocument, aLibName );
588 if ( aDocument == m_aCurDocument && aLibName == m_aCurLibName )
590 m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
591 m_aCurLibName.clear();
592 // no UpdateWindows!
593 if (SfxBindings* pBindings = GetBindingsPtr())
594 pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
598 else // Loaded...
599 UpdateWindows();
601 break;
602 case SID_BASICIDE_NEWMODULE:
604 VclPtr<ModulWindow> pWin = CreateBasWin( m_aCurDocument, m_aCurLibName, OUString() );
605 DBG_ASSERT( pWin, "New Module: Could not create window!" );
606 SetCurWindow( pWin, true );
608 break;
609 case SID_BASICIDE_NEWDIALOG:
611 VclPtr<DialogWindow> pWin = CreateDlgWin( m_aCurDocument, m_aCurLibName, OUString() );
612 DBG_ASSERT( pWin, "New Module: Could not create window!" );
613 SetCurWindow( pWin, true );
615 break;
616 case SID_BASICIDE_SBXRENAMED:
618 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
620 break;
621 case SID_BASICIDE_SBXINSERTED:
623 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
624 const SbxItem& rSbxItem = rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
625 const ScriptDocument& aDocument( rSbxItem.GetDocument() );
626 const OUString& aLibName( rSbxItem.GetLibName() );
627 const OUString& aName( rSbxItem.GetName() );
628 if ( m_aCurLibName.isEmpty() || ( aDocument == m_aCurDocument && aLibName == m_aCurLibName ) )
630 if ( rSbxItem.GetType() == TYPE_MODULE )
631 FindBasWin( aDocument, aLibName, aName, true );
632 else if ( rSbxItem.GetType() == TYPE_DIALOG )
633 FindDlgWin( aDocument, aLibName, aName, true );
636 break;
637 case SID_BASICIDE_SBXDELETED:
639 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
640 const SbxItem& rSbxItem = rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
641 const ScriptDocument& aDocument( rSbxItem.GetDocument() );
642 VclPtr<BaseWindow> pWin = FindWindow( aDocument, rSbxItem.GetLibName(), rSbxItem.GetName(), rSbxItem.GetType(), true );
643 if ( pWin )
644 RemoveWindow( pWin, true );
646 break;
647 case SID_BASICIDE_SHOWSBX:
649 DBG_ASSERT( rReq.GetArgs(), "arguments expected" );
650 const SbxItem& rSbxItem = rReq.GetArgs()->Get(SID_BASICIDE_ARG_SBX );
651 const ScriptDocument& aDocument( rSbxItem.GetDocument() );
652 const OUString& aLibName( rSbxItem.GetLibName() );
653 const OUString& aName( rSbxItem.GetName() );
654 SetCurLib( aDocument, aLibName );
655 BaseWindow* pWin = nullptr;
656 if ( rSbxItem.GetType() == TYPE_DIALOG )
658 pWin = FindDlgWin( aDocument, aLibName, aName, true );
660 else if ( rSbxItem.GetType() == TYPE_MODULE )
662 pWin = FindBasWin( aDocument, aLibName, aName, true );
664 else if ( rSbxItem.GetType() == TYPE_METHOD )
666 pWin = FindBasWin( aDocument, aLibName, aName, true );
667 static_cast<ModulWindow*>(pWin)->EditMacro( rSbxItem.GetMethodName() );
669 DBG_ASSERT( pWin, "Window was not created!" );
670 SetCurWindow( pWin, true );
671 pTabBar->MakeVisible( pTabBar->GetCurPageId() );
673 break;
674 case SID_BASICIDE_SHOWWINDOW:
676 std::unique_ptr< ScriptDocument > pDocument;
678 const SfxStringItem* pDocumentItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_DOCUMENT);
679 if ( pDocumentItem )
681 const OUString& sDocumentCaption = pDocumentItem->GetValue();
682 if ( !sDocumentCaption.isEmpty() )
683 pDocument.reset( new ScriptDocument( ScriptDocument::getDocumentWithURLOrCaption( sDocumentCaption ) ) );
686 const SfxUnoAnyItem* pDocModelItem = rReq.GetArg<SfxUnoAnyItem>(SID_BASICIDE_ARG_DOCUMENT_MODEL);
687 if (!pDocument && pDocModelItem)
689 uno::Reference< frame::XModel > xModel( pDocModelItem->GetValue(), UNO_QUERY );
690 if ( xModel.is() )
691 pDocument.reset( new ScriptDocument( xModel ) );
694 if (!pDocument)
695 break;
697 const SfxStringItem* pLibNameItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_LIBNAME);
698 if ( !pLibNameItem )
699 break;
701 OUString aLibName( pLibNameItem->GetValue() );
702 pDocument->loadLibraryIfExists( E_SCRIPTS, aLibName );
703 SetCurLib( *pDocument, aLibName );
704 const SfxStringItem* pNameItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_NAME);
705 if ( pNameItem )
707 const OUString& aName( pNameItem->GetValue() );
708 OUString aModType( "Module" );
709 OUString aType( aModType );
710 const SfxStringItem* pTypeItem = rReq.GetArg<SfxStringItem>(SID_BASICIDE_ARG_TYPE);
711 if ( pTypeItem )
712 aType = pTypeItem->GetValue();
714 BaseWindow* pWin = nullptr;
715 if ( aType == aModType )
716 pWin = FindBasWin( *pDocument, aLibName, aName );
717 else if ( aType == "Dialog" )
718 pWin = FindDlgWin( *pDocument, aLibName, aName );
720 if ( pWin )
722 SetCurWindow( pWin, true );
723 if ( pTabBar )
724 pTabBar->MakeVisible( pTabBar->GetCurPageId() );
726 if (ModulWindow* pModWin = dynamic_cast<ModulWindow*>(pWin))
728 const SfxUInt32Item* pLineItem = rReq.GetArg<SfxUInt32Item>(SID_BASICIDE_ARG_LINE);
729 if ( pLineItem )
731 pModWin->AssertValidEditEngine();
732 TextView* pTextView = pModWin->GetEditView();
733 if ( pTextView )
735 TextEngine* pTextEngine = pTextView->GetTextEngine();
736 if ( pTextEngine )
738 sal_uInt32 nLine = pLineItem->GetValue();
739 sal_uInt32 nLineCount = 0;
740 for ( sal_uInt32 i = 0, nCount = pTextEngine->GetParagraphCount(); i < nCount; ++i )
741 nLineCount += pTextEngine->GetLineCount( i );
742 if ( nLine > nLineCount )
743 nLine = nLineCount;
744 if ( nLine > 0 )
745 --nLine;
747 // scroll window and set selection
748 tools::Long nVisHeight = pModWin->GetOutputSizePixel().Height();
749 tools::Long nTextHeight = pTextEngine->GetTextHeight();
750 if ( nTextHeight > nVisHeight )
752 tools::Long nMaxY = nTextHeight - nVisHeight;
753 tools::Long nOldY = pTextView->GetStartDocPos().Y();
754 tools::Long nNewY = nLine * pTextEngine->GetCharHeight() - nVisHeight / 2;
755 nNewY = std::min( nNewY, nMaxY );
756 pTextView->Scroll( 0, -( nNewY - nOldY ) );
757 pTextView->ShowCursor( false );
758 pModWin->GetEditVScrollBar().SetThumbPos( pTextView->GetStartDocPos().Y() );
760 sal_uInt16 nCol1 = 0, nCol2 = 0;
761 const SfxUInt16Item* pCol1Item = rReq.GetArg<SfxUInt16Item>(SID_BASICIDE_ARG_COLUMN1);
762 if ( pCol1Item )
764 nCol1 = pCol1Item->GetValue();
765 if ( nCol1 > 0 )
766 --nCol1;
767 nCol2 = nCol1;
769 const SfxUInt16Item* pCol2Item = rReq.GetArg<SfxUInt16Item>(SID_BASICIDE_ARG_COLUMN2);
770 if ( pCol2Item )
772 nCol2 = pCol2Item->GetValue();
773 if ( nCol2 > 0 )
774 --nCol2;
776 TextSelection aSel( TextPaM( nLine, nCol1 ), TextPaM( nLine, nCol2 ) );
777 pTextView->SetSelection( aSel );
778 pTextView->ShowCursor();
779 vcl::Window* pWindow_ = pTextView->GetWindow();
780 if ( pWindow_ )
781 pWindow_->GrabFocus();
788 rReq.Done();
790 break;
792 case SID_BASICIDE_MANAGE_LANG:
794 auto pRequest = std::make_shared<SfxRequest>(rReq);
795 rReq.Ignore(); // the 'old' request is not relevant any more
796 auto xDlg = std::make_shared<ManageLanguageDialog>(pCurWin ? pCurWin->GetFrameWeld() : nullptr, m_pCurLocalizationMgr);
797 weld::DialogController::runAsync(xDlg, [=](sal_Int32 /*nResult*/){
798 pRequest->Done();
801 break;
803 case SID_ATTR_ZOOMSLIDER:
805 const SfxItemSet *pArgs = rReq.GetArgs();
806 const SfxPoolItem* pItem;
808 if (pArgs && pArgs->GetItemState(SID_ATTR_ZOOMSLIDER, true, &pItem ) == SfxItemState::SET)
809 SetGlobalEditorZoomLevel(static_cast<const SvxZoomSliderItem*>(pItem)->GetValue());
811 lcl_InvalidateZoomSlots(GetBindingsPtr());
813 break;
815 case SID_ZOOM_IN:
816 case SID_ZOOM_OUT:
818 const sal_uInt16 nOldZoom = GetCurrentZoomSliderValue();
819 sal_uInt16 nNewZoom;
820 if (nSlot == SID_ZOOM_IN)
821 nNewZoom = std::min<sal_uInt16>(GetMaxZoom(), basegfx::zoomtools::zoomIn(nOldZoom));
822 else
823 nNewZoom = std::max<sal_uInt16>(GetMinZoom(), basegfx::zoomtools::zoomOut(nOldZoom));
824 SetGlobalEditorZoomLevel(nNewZoom);
825 lcl_InvalidateZoomSlots(GetBindingsPtr());
827 break;
829 default:
830 if (pLayout)
831 pLayout->ExecuteGlobal(rReq);
832 if (pCurWin)
833 pCurWin->ExecuteGlobal(rReq);
834 break;
838 void Shell::GetState(SfxItemSet &rSet)
840 SfxWhichIter aIter(rSet);
841 for ( sal_uInt16 nWh = aIter.FirstWhich(); nWh != 0; nWh = aIter.NextWhich() )
843 switch ( nWh )
845 case SID_NEWDOCDIRECT:
847 // we do not have a new document factory,
848 // so just forward to a fallback method.
849 SfxGetpApp()->GetSlotState(nWh, nullptr, &rSet);
851 break;
852 case SID_DOCINFO:
854 rSet.DisableItem( nWh );
856 break;
857 case SID_SAVEDOC:
859 bool bDisable = false;
861 if ( pCurWin )
863 if ( !pCurWin->IsModified() )
865 ScriptDocument aDocument( pCurWin->GetDocument() );
866 bDisable = ( !aDocument.isAlive() )
867 || ( aDocument.isDocument() ? !aDocument.isDocumentModified() : !IsAppBasicModified() );
870 else
872 bDisable = true;
875 if ( bDisable )
876 rSet.DisableItem( nWh );
878 break;
879 case SID_NEWWINDOW:
880 case SID_SAVEASDOC:
882 rSet.DisableItem( nWh );
884 break;
885 case SID_SIGNATURE:
887 SignatureState nState = SignatureState::NOSIGNATURES;
888 if ( pCurWin )
890 DocumentSignature aSignature( pCurWin->GetDocument() );
891 nState = aSignature.getScriptingSignatureState();
893 rSet.Put( SfxUInt16Item( SID_SIGNATURE, static_cast<sal_uInt16>(nState) ) );
895 break;
896 case SID_BASICIDE_MODULEDLG:
898 if ( StarBASIC::IsRunning() )
899 rSet.DisableItem( nWh );
901 break;
903 case SID_BASICIDE_OBJCAT:
905 if (pLayout)
906 rSet.Put(SfxBoolItem(nWh, aObjectCatalog->IsVisible()));
907 else
908 rSet.Put(SfxVisibilityItem(nWh, false));
910 break;
912 case SID_BASICIDE_WATCH:
914 if (pLayout)
916 rSet.Put(SfxBoolItem(nWh, pModulLayout->IsWatchWindowVisible()));
917 // Disable command if the visible window is not a ModulWindow
918 if (!dynamic_cast<ModulWindowLayout*>(pLayout.get()))
919 rSet.DisableItem(nWh);
921 else
922 rSet.Put(SfxVisibilityItem(nWh, false));
924 break;
926 case SID_BASICIDE_STACK:
928 if (pLayout)
930 rSet.Put(SfxBoolItem(nWh, pModulLayout->IsStackWindowVisible()));
931 // Disable command if the visible window is not a ModulWindow
932 if (!dynamic_cast<ModulWindowLayout*>(pLayout.get()))
933 rSet.DisableItem(nWh);
935 else
936 rSet.Put(SfxVisibilityItem(nWh, false));
938 break;
940 case SID_BASICIDE_SHOWSBX:
941 case SID_BASICIDE_CREATEMACRO:
942 case SID_BASICIDE_EDITMACRO:
943 case SID_BASICIDE_NAMECHANGEDONTAB:
947 break;
949 case SID_BASICIDE_ADDWATCH:
950 case SID_BASICIDE_REMOVEWATCH:
951 case SID_BASICLOAD:
952 case SID_BASICSAVEAS:
953 case SID_BASICIDE_MATCHGROUP:
955 if (!dynamic_cast<ModulWindow*>(pCurWin.get()))
956 rSet.DisableItem( nWh );
957 else if ( ( nWh == SID_BASICLOAD ) && ( StarBASIC::IsRunning() || ( pCurWin && pCurWin->IsReadOnly() ) ) )
958 rSet.DisableItem( nWh );
960 break;
961 case SID_BASICRUN:
962 case SID_BASICSTEPINTO:
963 case SID_BASICSTEPOVER:
964 case SID_BASICSTEPOUT:
965 case SID_BASICIDE_TOGGLEBRKPNT:
966 case SID_BASICIDE_MANAGEBRKPNTS:
968 if (ModulWindow* pMCurWin = dynamic_cast<ModulWindow*>(pCurWin.get()))
970 if (StarBASIC::IsRunning() && !pMCurWin->GetBasicStatus().bIsInReschedule)
971 rSet.DisableItem(nWh);
973 else
974 rSet.DisableItem( nWh );
976 break;
977 case SID_BASICCOMPILE:
979 if (StarBASIC::IsRunning() || !dynamic_cast<ModulWindow*>(pCurWin.get()))
980 rSet.DisableItem( nWh );
982 break;
983 case SID_BASICSTOP:
985 // stop is always possible when some Basic is running...
986 if (!StarBASIC::IsRunning())
987 rSet.DisableItem( nWh );
989 break;
990 case SID_CHOOSE_CONTROLS:
991 case SID_DIALOG_TESTMODE:
992 case SID_INSERT_SELECT:
993 case SID_INSERT_PUSHBUTTON:
994 case SID_INSERT_RADIOBUTTON:
995 case SID_INSERT_CHECKBOX:
996 case SID_INSERT_LISTBOX:
997 case SID_INSERT_COMBOBOX:
998 case SID_INSERT_GROUPBOX:
999 case SID_INSERT_EDIT:
1000 case SID_INSERT_FIXEDTEXT:
1001 case SID_INSERT_IMAGECONTROL:
1002 case SID_INSERT_PROGRESSBAR:
1003 case SID_INSERT_HSCROLLBAR:
1004 case SID_INSERT_VSCROLLBAR:
1005 case SID_INSERT_HFIXEDLINE:
1006 case SID_INSERT_VFIXEDLINE:
1007 case SID_INSERT_DATEFIELD:
1008 case SID_INSERT_TIMEFIELD:
1009 case SID_INSERT_NUMERICFIELD:
1010 case SID_INSERT_CURRENCYFIELD:
1011 case SID_INSERT_FORMATTEDFIELD:
1012 case SID_INSERT_PATTERNFIELD:
1013 case SID_INSERT_FILECONTROL:
1014 case SID_INSERT_SPINBUTTON:
1015 case SID_INSERT_GRIDCONTROL:
1016 case SID_INSERT_HYPERLINKCONTROL:
1017 case SID_INSERT_TREECONTROL:
1018 case SID_INSERT_FORM_RADIO:
1019 case SID_INSERT_FORM_CHECK:
1020 case SID_INSERT_FORM_LIST:
1021 case SID_INSERT_FORM_COMBO:
1022 case SID_INSERT_FORM_VSCROLL:
1023 case SID_INSERT_FORM_HSCROLL:
1024 case SID_INSERT_FORM_SPIN:
1026 if (!dynamic_cast<DialogWindow*>(pCurWin.get()))
1027 rSet.DisableItem( nWh );
1029 break;
1030 case SID_SEARCH_OPTIONS:
1032 SearchOptionFlags nOptions = SearchOptionFlags::NONE;
1033 if( pCurWin )
1034 nOptions = pCurWin->GetSearchOptions();
1035 rSet.Put( SfxUInt16Item( SID_SEARCH_OPTIONS, static_cast<sal_uInt16>(nOptions) ) );
1037 break;
1038 case SID_BASICIDE_LIBSELECTOR:
1040 OUString aName;
1041 if ( !m_aCurLibName.isEmpty() )
1043 LibraryLocation eLocation = m_aCurDocument.getLibraryLocation( m_aCurLibName );
1044 aName = CreateMgrAndLibStr( m_aCurDocument.getTitle( eLocation ), m_aCurLibName );
1046 SfxStringItem aItem( SID_BASICIDE_LIBSELECTOR, aName );
1047 rSet.Put( aItem );
1049 break;
1050 case SID_SEARCH_ITEM:
1052 if ( !mpSearchItem )
1054 mpSearchItem.reset( new SvxSearchItem( SID_SEARCH_ITEM ));
1055 mpSearchItem->SetSearchString( GetSelectionText( true ));
1058 if ( mbJustOpened && HasSelection() )
1060 OUString aText = GetSelectionText( true );
1062 if ( !aText.isEmpty() )
1064 mpSearchItem->SetSearchString( aText );
1065 mpSearchItem->SetSelection( false );
1067 else
1068 mpSearchItem->SetSelection( true );
1071 mbJustOpened = false;
1072 rSet.Put( *mpSearchItem );
1074 break;
1075 case SID_BASICIDE_STAT_DATE:
1077 SfxStringItem aItem( SID_BASICIDE_STAT_DATE, "Datum?!" );
1078 rSet.Put( aItem );
1080 break;
1081 case SID_DOC_MODIFIED:
1083 bool bModified = false;
1085 if ( pCurWin )
1087 if ( pCurWin->IsModified() )
1088 bModified = true;
1089 else
1091 ScriptDocument aDocument( pCurWin->GetDocument() );
1092 bModified = aDocument.isDocument() ? aDocument.isDocumentModified() : IsAppBasicModified();
1096 SfxBoolItem aItem(SID_DOC_MODIFIED, bModified);
1097 rSet.Put( aItem );
1099 break;
1100 case SID_BASICIDE_STAT_TITLE:
1102 if ( pCurWin )
1104 OUString aTitle = pCurWin->CreateQualifiedName();
1105 if (pCurWin->IsReadOnly())
1106 aTitle += " (" + IDEResId(RID_STR_READONLY) + ")";
1107 SfxStringItem aItem( SID_BASICIDE_STAT_TITLE, aTitle );
1108 rSet.Put( aItem );
1111 break;
1112 case SID_BASICIDE_CURRENT_ZOOM:
1114 // The current zoom value is only visible in a module window
1115 ModulWindow* pModuleWindow = dynamic_cast<ModulWindow*>(pCurWin.get());
1116 if (pModuleWindow)
1118 OUString sZoom;
1119 sZoom = OUString::number(m_nCurrentZoomSliderValue) + "%";
1120 SfxStringItem aItem( SID_BASICIDE_CURRENT_ZOOM, sZoom );
1121 rSet.Put( aItem );
1124 break;
1125 // are interpreted by the controller:
1126 case SID_ATTR_SIZE:
1127 case SID_ATTR_INSERT:
1128 break;
1129 case SID_UNDO:
1130 case SID_REDO:
1132 if( GetUndoManager() ) // recursive GetState else
1133 GetViewFrame().GetSlotState( nWh, nullptr, &rSet );
1135 break;
1136 case SID_BASICIDE_CURRENT_LANG:
1138 if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().isEmpty() )
1139 rSet.DisableItem( nWh );
1140 else
1142 OUString aItemStr;
1143 std::shared_ptr<LocalizationMgr> pCurMgr(GetCurLocalizationMgr());
1144 if ( pCurMgr->isLibraryLocalized() )
1146 Sequence< lang::Locale > aLocaleSeq = pCurMgr->getStringResourceManager()->getLocales();
1147 const lang::Locale* pLocale = aLocaleSeq.getConstArray();
1148 sal_Int32 i, nCount = aLocaleSeq.getLength();
1150 // Force different results for any combination of locales and default locale
1151 OUString aLangStr;
1152 for ( i = 0; i <= nCount; ++i )
1154 lang::Locale aLocale;
1155 if( i < nCount )
1156 aLocale = pLocale[i];
1157 else
1158 aLocale = pCurMgr->getStringResourceManager()->getDefaultLocale();
1160 aLangStr += aLocale.Language + aLocale.Country + aLocale.Variant;
1162 aItemStr = aLangStr;
1164 rSet.Put( SfxStringItem( nWh, aItemStr ) );
1167 break;
1169 case SID_BASICIDE_MANAGE_LANG:
1171 if( (pCurWin && pCurWin->IsReadOnly()) || GetCurLibName().isEmpty() )
1172 rSet.DisableItem( nWh );
1174 break;
1175 case SID_GOTOLINE:
1177 // if this is not a module window hide the
1178 // setting, doesn't make sense for example if the
1179 // dialog editor is open
1180 if (pCurWin && !dynamic_cast<ModulWindow*>(pCurWin.get()))
1182 rSet.DisableItem( nWh );
1183 rSet.Put(SfxVisibilityItem(nWh, false));
1185 break;
1187 case SID_BASICIDE_HIDECURPAGE:
1189 if (pTabBar->GetPageCount() == 0)
1190 rSet.DisableItem(nWh);
1192 break;
1193 case SID_BASICIDE_DELETECURRENT:
1194 case SID_BASICIDE_RENAMECURRENT:
1196 if (pTabBar->GetPageCount() == 0 || StarBASIC::IsRunning())
1197 rSet.DisableItem(nWh);
1198 else if (m_aCurDocument.isInVBAMode())
1200 // disable to delete or rename object modules in IDE
1201 BasicManager* pBasMgr = m_aCurDocument.getBasicManager();
1202 StarBASIC* pBasic = pBasMgr ? pBasMgr->GetLib(m_aCurLibName) : nullptr;
1203 if (pBasic && dynamic_cast<ModulWindow*>(pCurWin.get()))
1205 SbModule* pActiveModule = pBasic->FindModule( pCurWin->GetName() );
1206 if ( pActiveModule && ( pActiveModule->GetModuleType() == script::ModuleType::DOCUMENT ) )
1207 rSet.DisableItem(nWh);
1211 [[fallthrough]];
1213 case SID_BASICIDE_NEWMODULE:
1214 case SID_BASICIDE_NEWDIALOG:
1216 Reference< script::XLibraryContainer2 > xModLibContainer( m_aCurDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
1217 Reference< script::XLibraryContainer2 > xDlgLibContainer( m_aCurDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
1218 if ( ( xModLibContainer.is() && xModLibContainer->hasByName( m_aCurLibName ) && xModLibContainer->isLibraryReadOnly( m_aCurLibName ) ) ||
1219 ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( m_aCurLibName ) && xDlgLibContainer->isLibraryReadOnly( m_aCurLibName ) ) )
1220 rSet.DisableItem(nWh);
1222 break;
1224 case SID_ZOOM_IN:
1225 case SID_ZOOM_OUT:
1227 const sal_uInt16 nCurrentZoom = GetCurrentZoomSliderValue();
1228 if ((nWh == SID_ZOOM_IN && nCurrentZoom >= GetMaxZoom()) ||
1229 (nWh == SID_ZOOM_OUT && nCurrentZoom <= GetMinZoom()))
1230 rSet.DisableItem(nWh);
1232 break;
1234 case SID_ATTR_ZOOMSLIDER:
1236 // The zoom slider is only visible in a module window
1237 ModulWindow* pModuleWindow = dynamic_cast<ModulWindow*>(pCurWin.get());
1238 if (pModuleWindow)
1240 SvxZoomSliderItem aZoomSliderItem(GetCurrentZoomSliderValue(), GetMinZoom(), GetMaxZoom());
1241 aZoomSliderItem.AddSnappingPoint(100);
1242 rSet.Put( aZoomSliderItem );
1245 break;
1247 default:
1248 if (pLayout)
1249 pLayout->GetState(rSet, nWh);
1252 if ( pCurWin )
1253 pCurWin->GetState( rSet );
1256 bool Shell::HasUIFeature(SfxShellFeature nFeature) const
1258 assert((nFeature & ~SfxShellFeature::BasicMask) == SfxShellFeature::NONE);
1259 bool bResult = false;
1261 if (nFeature & SfxShellFeature::BasicShowBrowser)
1263 // fade out (in) property browser in module (dialog) windows
1264 if (dynamic_cast<DialogWindow*>(pCurWin.get()) && !pCurWin->IsReadOnly())
1265 bResult = true;
1268 return bResult;
1271 void Shell::SetCurWindow( BaseWindow* pNewWin, bool bUpdateTabBar, bool bRememberAsCurrent )
1273 if ( pNewWin == pCurWin )
1274 return;
1276 pCurWin = pNewWin;
1277 if (pLayout)
1278 pLayout->Deactivating();
1279 if (pCurWin)
1281 if (pCurWin->GetType() == TYPE_MODULE)
1282 pLayout = pModulLayout.get();
1283 else
1284 pLayout = pDialogLayout.get();
1285 AdjustPosSizePixel(Point(0, 0), GetViewFrame().GetWindow().GetOutputSizePixel());
1286 pLayout->Activating(*pCurWin);
1287 GetViewFrame().GetWindow().SetHelpId(pCurWin->GetHid());
1288 if (bRememberAsCurrent)
1289 pCurWin->InsertLibInfo();
1290 if (GetViewFrame().GetWindow().IsVisible()) // SFX will do it later otherwise
1291 pCurWin->Show();
1292 pCurWin->Init();
1293 if (!GetExtraData()->ShellInCriticalSection())
1295 vcl::Window* pFrameWindow = &GetViewFrame().GetWindow();
1296 vcl::Window* pFocusWindow = Application::GetFocusWindow();
1297 while ( pFocusWindow && ( pFocusWindow != pFrameWindow ) )
1298 pFocusWindow = pFocusWindow->GetParent();
1299 if ( pFocusWindow ) // Focus in BasicIDE
1300 pCurWin->GrabFocus();
1303 else
1305 SetWindow(pLayout);
1306 pLayout = nullptr;
1308 if ( bUpdateTabBar )
1310 sal_uInt16 nKey = GetWindowId( pCurWin );
1311 if ( pCurWin && ( pTabBar->GetPagePos( nKey ) == TabBar::PAGE_NOT_FOUND ) )
1312 pTabBar->InsertPage( nKey, pCurWin->GetTitle() ); // has just been faded in
1313 pTabBar->SetCurPageId( nKey );
1315 if ( pCurWin && pCurWin->IsSuspended() ) // if the window is shown in the case of an error...
1316 pCurWin->SetStatus( pCurWin->GetStatus() & ~BASWIN_SUSPENDED );
1317 if ( pCurWin )
1319 SetWindow( pCurWin );
1320 if ( pCurWin->GetDocument().isDocument() )
1321 SfxObjectShell::SetCurrentComponent( pCurWin->GetDocument().getDocument() );
1323 else if (pLayout)
1325 SetWindow(pLayout);
1326 GetViewFrame().GetWindow().SetHelpId( HID_BASICIDE_MODULWINDOW );
1327 SfxObjectShell::SetCurrentComponent(nullptr);
1329 aObjectCatalog->SetCurrentEntry(pCurWin);
1330 SetUndoManager( pCurWin ? pCurWin->GetUndoManager() : nullptr );
1331 InvalidateBasicIDESlots();
1332 InvalidateControlSlots();
1334 if ( m_pCurLocalizationMgr )
1335 m_pCurLocalizationMgr->handleTranslationbar();
1337 ManageToolbars();
1339 // fade out (in) property browser in module (dialog) windows
1340 UIFeatureChanged();
1343 void Shell::ManageToolbars()
1345 static constexpr OUStringLiteral aMacroBarResName = u"private:resource/toolbar/macrobar";
1346 static constexpr OUStringLiteral aDialogBarResName = u"private:resource/toolbar/dialogbar";
1347 static constexpr OUStringLiteral aInsertControlsBarResName
1348 = u"private:resource/toolbar/insertcontrolsbar";
1349 static constexpr OUStringLiteral aFormControlsBarResName
1350 = u"private:resource/toolbar/formcontrolsbar";
1352 if( !pCurWin )
1353 return;
1355 Reference< beans::XPropertySet > xFrameProps
1356 ( GetViewFrame().GetFrame().GetFrameInterface(), uno::UNO_QUERY );
1357 if ( !xFrameProps.is() )
1358 return;
1360 Reference< css::frame::XLayoutManager > xLayoutManager;
1361 uno::Any a = xFrameProps->getPropertyValue( "LayoutManager" );
1362 a >>= xLayoutManager;
1363 if ( !xLayoutManager.is() )
1364 return;
1366 xLayoutManager->lock();
1367 if (dynamic_cast<DialogWindow*>(pCurWin.get()))
1369 xLayoutManager->destroyElement( aMacroBarResName );
1371 xLayoutManager->requestElement( aDialogBarResName );
1372 xLayoutManager->requestElement( aInsertControlsBarResName );
1373 xLayoutManager->requestElement( aFormControlsBarResName );
1375 else
1377 xLayoutManager->destroyElement( aDialogBarResName );
1378 xLayoutManager->destroyElement( aInsertControlsBarResName );
1379 xLayoutManager->destroyElement( aFormControlsBarResName );
1381 xLayoutManager->requestElement( aMacroBarResName );
1383 xLayoutManager->unlock();
1386 VclPtr<BaseWindow> Shell::FindApplicationWindow()
1388 return FindWindow( ScriptDocument::getApplicationScriptDocument(), u"", u"", TYPE_UNKNOWN );
1391 VclPtr<BaseWindow> Shell::FindWindow(
1392 ScriptDocument const& rDocument,
1393 std::u16string_view rLibName, std::u16string_view rName,
1394 ItemType eType, bool bFindSuspended
1397 for (auto const& window : aWindowTable)
1399 BaseWindow* const pWin = window.second;
1400 if (pWin->Is(rDocument, rLibName, rName, eType, bFindSuspended))
1401 return pWin;
1403 return nullptr;
1406 bool Shell::CallBasicErrorHdl( StarBASIC const * pBasic )
1408 VclPtr<ModulWindow> pModWin = ShowActiveModuleWindow( pBasic );
1409 if ( pModWin )
1410 pModWin->BasicErrorHdl( pBasic );
1411 return false;
1414 BasicDebugFlags Shell::CallBasicBreakHdl( StarBASIC const * pBasic )
1416 BasicDebugFlags nRet = BasicDebugFlags::NONE;
1417 VclPtr<ModulWindow> pModWin = ShowActiveModuleWindow( pBasic );
1418 if ( pModWin )
1420 bool bAppWindowDisabled, bDispatcherLocked;
1421 sal_uInt16 nWaitCount;
1422 SfxUInt16Item *pSWActionCount, *pSWLockViewCount;
1423 BasicStopped( &bAppWindowDisabled, &bDispatcherLocked,
1424 &nWaitCount, &pSWActionCount, &pSWLockViewCount );
1426 nRet = pModWin->BasicBreakHdl();
1428 if ( StarBASIC::IsRunning() ) // if cancelled...
1430 if ( bAppWindowDisabled )
1431 Application::GetDefDialogParent()->set_sensitive(false);
1433 if ( nWaitCount )
1435 Shell* pShell = GetShell();
1436 for ( sal_uInt16 n = 0; n < nWaitCount; n++ )
1437 pShell->GetViewFrame().GetWindow().EnterWait();
1441 return nRet;
1444 VclPtr<ModulWindow> Shell::ShowActiveModuleWindow( StarBASIC const * pBasic )
1446 SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
1448 SbModule* pActiveModule = StarBASIC::GetActiveModule();
1449 if (SbClassModuleObject* pCMO = dynamic_cast<SbClassModuleObject*>(pActiveModule))
1450 pActiveModule = pCMO->getClassModule();
1452 DBG_ASSERT( pActiveModule, "No active module in ErrorHdl!?" );
1453 if ( pActiveModule )
1455 VclPtr<ModulWindow> pWin;
1456 SbxObject* pParent = pActiveModule->GetParent();
1457 if (StarBASIC* pLib = dynamic_cast<StarBASIC*>(pParent))
1459 if (BasicManager* pBasMgr = FindBasicManager(pLib))
1461 ScriptDocument aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr ) );
1462 const OUString& aLibName = pLib->GetName();
1463 pWin = FindBasWin( aDocument, aLibName, pActiveModule->GetName(), true );
1464 DBG_ASSERT( pWin, "Error/Step-Hdl: Window was not created/found!" );
1465 SetCurLib( aDocument, aLibName );
1466 SetCurWindow( pWin, true );
1469 else
1470 SAL_WARN( "basctl.basicide", "No BASIC!");
1471 if (BasicManager* pBasicMgr = FindBasicManager(pBasic))
1472 StartListening(*pBasicMgr, DuplicateHandling::Prevent /* log on only once */);
1473 return pWin;
1475 return nullptr;
1478 void Shell::AdjustPosSizePixel( const Point &rPos, const Size &rSize )
1480 // not if iconified because the whole text would be displaced then at restore
1481 if ( GetViewFrame().GetWindow().GetOutputSizePixel().Height() == 0 )
1482 return;
1484 Size aTabBarSize;
1485 aTabBarSize.setHeight( GetViewFrame().GetWindow().GetFont().GetFontHeight() + TAB_HEIGHT_MARGIN );
1486 aTabBarSize.setWidth( rSize.Width() );
1488 Size aSz( rSize );
1489 auto nScrollBarSz(Application::GetSettings().GetStyleSettings().GetScrollBarSize());
1490 aSz.AdjustHeight(-aTabBarSize.Height());
1492 Size aOutSz( aSz );
1493 aSz.AdjustWidth(-nScrollBarSz);
1494 aSz.AdjustHeight(-nScrollBarSz);
1495 aVScrollBar->SetPosSizePixel( Point( rPos.X()+aSz.Width(), rPos.Y() ), Size( nScrollBarSz, aSz.Height() ) );
1496 aHScrollBar->SetPosSizePixel( Point( rPos.X(), rPos.Y()+aSz.Height() ), Size( aOutSz.Width(), nScrollBarSz ) );
1497 pTabBar->SetPosSizePixel( Point( rPos.X(), rPos.Y() + nScrollBarSz + aSz.Height()), aTabBarSize );
1499 // The size to be applied depends on whether it is a DialogWindow or a ModulWindow
1500 if (pLayout)
1502 if (dynamic_cast<DialogWindow*>(pCurWin.get()))
1504 pCurWin->ShowShellScrollBars();
1505 pLayout->SetPosSizePixel(rPos, aSz);
1507 else
1509 pCurWin->ShowShellScrollBars(false);
1510 pLayout->SetPosSizePixel(rPos, aOutSz);
1515 Reference< XModel > Shell::GetCurrentDocument() const
1517 Reference< XModel > xDocument;
1518 if ( pCurWin && pCurWin->GetDocument().isDocument() )
1519 xDocument = pCurWin->GetDocument().getDocument();
1520 return xDocument;
1523 void Shell::Activate( bool bMDI )
1525 SfxViewShell::Activate( bMDI );
1527 if ( bMDI )
1529 if (DialogWindow* pDCurWin = dynamic_cast<DialogWindow*>(pCurWin.get()))
1530 pDCurWin->UpdateBrowser();
1534 void Shell::Deactivate( bool bMDI )
1536 // bMDI == true means that another MDI has been activated; in case of a
1537 // deactivate due to a MessageBox bMDI is false
1538 if ( bMDI )
1540 if (DialogWindow* pXDlgWin = dynamic_cast<DialogWindow*>(pCurWin.get()))
1542 pXDlgWin->DisableBrowser();
1543 if( pXDlgWin->IsModified() )
1544 MarkDocumentModified( pXDlgWin->GetDocument() );
1549 } // namespace basctl
1551 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */