nss: upgrade to release 3.73
[LibreOffice.git] / basctl / source / basicide / baside2.cxx
blob41c0ff4413f32561bc6e5d66a21d3156b94eeb9a
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 "baside2.hxx"
21 #include <baside3.hxx>
22 #include <basobj.hxx>
23 #include <basidesh.hxx>
24 #include "brkdlg.hxx"
25 #include <iderdll.hxx>
26 #include <iderid.hxx>
27 #include "moduldlg.hxx"
28 #include <docsignature.hxx>
29 #include <officecfg/Office/BasicIDE.hxx>
31 #include <helpids.h>
32 #include <strings.hrc>
34 #include <basic/basmgr.hxx>
35 #include <basic/basrdll.hxx>
36 #include <basic/sbmeth.hxx>
37 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
38 #include <com/sun/star/script/ModuleType.hpp>
39 #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp>
40 #include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
41 #include <com/sun/star/ui/dialogs/FilePicker.hpp>
42 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
43 #include <comphelper/SetFlagContextHelper.hxx>
44 #include <comphelper/string.hxx>
45 #include <svl/srchdefs.hxx>
46 #include <sfx2/bindings.hxx>
47 #include <sfx2/docfile.hxx>
48 #include <sfx2/request.hxx>
49 #include <sfx2/viewfrm.hxx>
50 #include <sot/exchange.hxx>
51 #include <svl/eitem.hxx>
52 #include <svl/srchitem.hxx>
53 #include <svl/stritem.hxx>
54 #include <svl/visitem.hxx>
55 #include <svl/whiter.hxx>
56 #include <svx/svxids.hrc>
57 #include <tools/debug.hxx>
58 #include <vcl/waitobj.hxx>
59 #include <vcl/errinf.hxx>
60 #include <vcl/event.hxx>
61 #include <vcl/print.hxx>
62 #include <vcl/svapp.hxx>
63 #include <vcl/textview.hxx>
64 #include <vcl/weld.hxx>
65 #include <vcl/xtextedt.hxx>
66 #include <toolkit/helper/vclunohelper.hxx>
67 #include <cassert>
68 #include <osl/diagnose.h>
69 #include <officecfg/Office/Common.hxx>
71 namespace basctl
74 namespace
77 namespace Print
79 tools::Long const nLeftMargin = 1700;
80 tools::Long const nRightMargin = 900;
81 tools::Long const nTopMargin = 2000;
82 tools::Long const nBottomMargin = 1000;
83 tools::Long const nBorder = 300;
86 short const ValidWindow = 0x1234;
88 // What (who) are OW and MTF? Compare to baside3.cxx where an
89 // identically named variable, used in the same way, has the value
90 // "*.*" on Windows, "*" otherwise. Is that what should be done here,
91 // too?
93 #if defined(OW) || defined(MTF)
94 char const FilterMask_All[] = "*";
95 #else
96 char const FilterMask_All[] = "*.*";
97 #endif
99 } // end anonymous namespace
101 using namespace ::com::sun::star;
102 using namespace ::com::sun::star::uno;
103 using namespace ::com::sun::star::ui::dialogs;
104 using namespace utl;
105 using namespace comphelper;
107 namespace
110 void lcl_PrintHeader( Printer* pPrinter, sal_uInt16 nPages, sal_uInt16 nCurPage, const OUString& rTitle, bool bOutput )
112 Size const aSz = pPrinter->GetOutputSize();
114 const Color aOldLineColor( pPrinter->GetLineColor() );
115 const Color aOldFillColor( pPrinter->GetFillColor() );
116 const vcl::Font aOldFont( pPrinter->GetFont() );
118 pPrinter->SetLineColor( COL_BLACK );
119 pPrinter->SetFillColor();
121 vcl::Font aFont( aOldFont );
122 aFont.SetWeight( WEIGHT_BOLD );
123 aFont.SetAlignment( ALIGN_BOTTOM );
124 pPrinter->SetFont( aFont );
126 tools::Long nFontHeight = pPrinter->GetTextHeight();
128 // 1st Border => line, 2+3 Border = free space
129 tools::Long nYTop = Print::nTopMargin - 3*Print::nBorder - nFontHeight;
131 tools::Long nXLeft = Print::nLeftMargin - Print::nBorder;
132 tools::Long nXRight = aSz.Width() - Print::nRightMargin + Print::nBorder;
134 if( bOutput )
135 pPrinter->DrawRect(tools::Rectangle(
136 Point(nXLeft, nYTop),
137 Size(nXRight - nXLeft, aSz.Height() - nYTop - Print::nBottomMargin + Print::nBorder)
141 tools::Long nY = Print::nTopMargin - 2*Print::nBorder;
142 Point aPos(Print::nLeftMargin, nY);
143 if( bOutput )
144 pPrinter->DrawText( aPos, rTitle );
145 if ( nPages != 1 )
147 aFont.SetWeight( WEIGHT_NORMAL );
148 pPrinter->SetFont( aFont );
149 aPos.AdjustX(pPrinter->GetTextWidth( rTitle ) );
151 if( bOutput )
153 OUString aPageStr = " [" + IDEResId(RID_STR_PAGE) + " " + OUString::number( nCurPage ) + "]";
154 pPrinter->DrawText( aPos, aPageStr );
158 nY = Print::nTopMargin - Print::nBorder;
160 if( bOutput )
161 pPrinter->DrawLine( Point( nXLeft, nY ), Point( nXRight, nY ) );
163 pPrinter->SetFont( aOldFont );
164 pPrinter->SetFillColor( aOldFillColor );
165 pPrinter->SetLineColor( aOldLineColor );
168 void lcl_ConvertTabsToSpaces( OUString& rLine )
170 if ( rLine.isEmpty() )
171 return;
173 OUStringBuffer aResult( rLine );
174 sal_Int32 nPos = 0;
175 sal_Int32 nMax = aResult.getLength();
176 while ( nPos < nMax )
178 if ( aResult[nPos] == '\t' )
180 // not 4 Blanks, but at 4 TabPos:
181 OUStringBuffer aBlanker;
182 string::padToLength(aBlanker, ( 4 - ( nPos % 4 ) ), ' ');
183 aResult.remove( nPos, 1 );
184 aResult.insert( nPos, aBlanker.makeStringAndClear() );
185 nMax = aResult.getLength();
187 ++nPos;
189 rLine = aResult.makeStringAndClear();
192 } // namespace
194 ModulWindow::ModulWindow (ModulWindowLayout* pParent, ScriptDocument const& rDocument,
195 const OUString& aLibName, const OUString& aName, OUString const & aModule)
196 : BaseWindow(pParent, rDocument, aLibName, aName)
197 , m_rLayout(*pParent)
198 , m_nValid(ValidWindow)
199 , m_aXEditorWindow(VclPtr<ComplexEditorWindow>::Create(this))
200 , m_aModule(aModule)
202 m_aXEditorWindow->Show();
203 SetBackground();
206 SbModuleRef const & ModulWindow::XModule()
208 // ModuleWindows can now be created as a result of the
209 // modules getting created via the api. This is a result of an
210 // elementInserted event from the BasicLibrary container.
211 // However the SbModule is also created from a different listener to
212 // the same event ( in basmgr ) Therefore it is possible when we look
213 // for m_xModule it may not yet be available, here we keep trying to access
214 // the module until such time as it exists
216 if ( !m_xModule.is() )
218 BasicManager* pBasMgr = GetDocument().getBasicManager();
219 if ( pBasMgr )
221 StarBASIC* pBasic = pBasMgr->GetLib( GetLibName() );
222 if ( pBasic )
224 m_xBasic = pBasic;
225 m_xModule = pBasic->FindModule( GetName() );
229 return m_xModule;
232 ModulWindow::~ModulWindow()
234 disposeOnce();
237 void ModulWindow::dispose()
239 m_nValid = 0;
240 StarBASIC::Stop();
241 m_aXEditorWindow.disposeAndClear();
242 BaseWindow::dispose();
246 void ModulWindow::GetFocus()
248 if (m_nValid != ValidWindow)
249 return;
250 m_aXEditorWindow->GetEdtWindow().GrabFocus();
251 // don't call basic calls because focus is somewhere else...
254 void ModulWindow::DoInit()
256 if (GetVScrollBar())
257 GetVScrollBar()->Hide();
258 GetHScrollBar()->Show();
259 GetEditorWindow().InitScrollBars();
262 void ModulWindow::Paint(vcl::RenderContext& /*rRenderContext*/, const tools::Rectangle&)
266 void ModulWindow::Resize()
268 m_aXEditorWindow->SetPosSizePixel( Point( 0, 0 ), GetOutputSizePixel() );
271 void ModulWindow::CheckCompileBasic()
273 if ( !XModule().is() )
274 return;
276 // never compile while running!
277 bool const bRunning = StarBASIC::IsRunning();
278 bool const bModified = ( !m_xModule->IsCompiled() ||
279 ( GetEditEngine() && GetEditEngine()->IsModified() ) );
281 if ( bRunning || !bModified )
282 return;
284 bool bDone = false;
286 GetShell()->GetViewFrame()->GetWindow().EnterWait();
288 AssertValidEditEngine();
289 GetEditorWindow().SetSourceInBasic();
291 bool bWasModified = GetBasic()->IsModified();
294 // tdf#106529: only use strict compilation mode when compiling from the IDE
295 css::uno::ContextLayer layer(comphelper::NewFlagContext("BasicStrict"));
296 bDone = m_xModule->Compile();
298 if ( !bWasModified )
299 GetBasic()->SetModified(false);
301 if ( bDone )
303 GetBreakPoints().SetBreakPointsInBasic( m_xModule.get() );
306 GetShell()->GetViewFrame()->GetWindow().LeaveWait();
308 m_aStatus.bError = !bDone;
309 m_aStatus.bIsRunning = false;
312 void ModulWindow::BasicExecute()
314 // #116444# check security settings before macro execution
315 ScriptDocument aDocument( GetDocument() );
316 bool bMacrosDisabled = officecfg::Office::Common::Security::Scripting::DisableMacrosExecution::get();
317 if (bMacrosDisabled || (aDocument.isDocument() && !aDocument.allowMacros()))
319 std::unique_ptr<weld::MessageDialog> xBox(
320 Application::CreateMessageDialog(GetFrameWeld(), VclMessageType::Warning,
321 VclButtonsType::Ok, IDEResId(RID_STR_CANNOTRUNMACRO)));
322 xBox->run();
323 return;
326 CheckCompileBasic();
328 if ( !XModule().is() || !m_xModule->IsCompiled() || m_aStatus.bError )
329 return;
331 if ( GetBreakPoints().size() )
332 m_aStatus.nBasicFlags = m_aStatus.nBasicFlags | BasicDebugFlags::Break;
334 if ( !m_aStatus.bIsRunning )
336 DBG_ASSERT( m_xModule.is(), "No Module!" );
337 AddStatus( BASWIN_RUNNINGBASIC );
338 sal_uInt16 nStart, nEnd;
339 TextSelection aSel = GetEditView()->GetSelection();
340 // Init cursor to top
341 const sal_uInt32 nCurMethodStart = aSel.GetStart().GetPara() + 1;
342 SbMethod* pMethod = nullptr;
343 // first Macro, else blind "Main" (ExtSearch?)
344 for ( sal_uInt32 nMacro = 0; nMacro < m_xModule->GetMethods()->Count32(); nMacro++ )
346 SbMethod* pM = static_cast<SbMethod*>(m_xModule->GetMethods()->Get32( nMacro ));
347 assert(pM && "Method?");
348 pM->GetLineRange( nStart, nEnd );
349 if ( nCurMethodStart >= nStart && nCurMethodStart <= nEnd )
351 // matched a method to the cursor position
352 pMethod = pM;
353 break;
356 if ( !pMethod )
358 // If not in a method then prompt the user
359 ChooseMacro(GetFrameWeld(), uno::Reference<frame::XModel>());
360 return;
362 pMethod->SetDebugFlags(m_aStatus.nBasicFlags);
363 BasicDLL::SetDebugMode(true);
364 RunMethod(pMethod);
365 BasicDLL::SetDebugMode(false);
366 // if cancelled during Interactive=false
367 BasicDLL::EnableBreak(true);
368 ClearStatus( BASWIN_RUNNINGBASIC );
370 else
371 m_aStatus.bIsRunning = false; // cancel of Reschedule()
374 void ModulWindow::CompileBasic()
376 CheckCompileBasic();
378 XModule().is() && m_xModule->IsCompiled();
381 void ModulWindow::BasicRun()
383 m_aStatus.nBasicFlags = BasicDebugFlags::NONE;
384 BasicExecute();
387 void ModulWindow::BasicStepOver()
389 m_aStatus.nBasicFlags = BasicDebugFlags::StepInto | BasicDebugFlags::StepOver;
390 BasicExecute();
394 void ModulWindow::BasicStepInto()
396 m_aStatus.nBasicFlags = BasicDebugFlags::StepInto;
397 BasicExecute();
400 void ModulWindow::BasicStepOut()
402 m_aStatus.nBasicFlags = BasicDebugFlags::StepOut;
403 BasicExecute();
407 void ModulWindow::BasicStop()
409 StarBASIC::Stop();
410 m_aStatus.bIsRunning = false;
413 void ModulWindow::LoadBasic()
415 Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
416 Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILEOPEN_SIMPLE);
418 if ( !m_sCurPath.isEmpty() )
419 xFP->setDisplayDirectory ( m_sCurPath );
421 xFP->appendFilter( "BASIC" , "*.bas" );
422 xFP->appendFilter( IDEResId(RID_STR_FILTER_ALLFILES), FilterMask_All );
423 xFP->setCurrentFilter( "BASIC" );
425 if( xFP->execute() != RET_OK )
426 return;
428 Sequence< OUString > aPaths = xFP->getSelectedFiles();
429 m_sCurPath = aPaths[0];
430 SfxMedium aMedium( m_sCurPath, StreamMode::READ | StreamMode::SHARE_DENYWRITE | StreamMode::NOCREATE );
431 SvStream* pStream = aMedium.GetInStream();
432 if ( pStream )
434 AssertValidEditEngine();
435 sal_uInt32 nLines = CalcLineCount( *pStream );
436 // nLines*4: ReadText/Formatting/Highlighting/Formatting
437 GetEditorWindow().CreateProgress( IDEResId(RID_STR_GENERATESOURCE), nLines*4 );
438 GetEditEngine()->SetUpdateMode( false );
439 GetEditView()->Read( *pStream );
440 GetEditEngine()->SetUpdateMode( true );
441 GetEditorWindow().PaintImmediately();
442 GetEditorWindow().ForceSyntaxTimeout();
443 GetEditorWindow().DestroyProgress();
444 ErrCode nError = aMedium.GetError();
445 if ( nError )
446 ErrorHandler::HandleError( nError );
448 else
450 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
451 VclMessageType::Warning, VclButtonsType::Ok, IDEResId(RID_STR_COULDNTREAD)));
452 xBox->run();
457 void ModulWindow::SaveBasicSource()
459 Reference< uno::XComponentContext > xContext( ::comphelper::getProcessComponentContext() );
460 Reference < XFilePicker3 > xFP = FilePicker::createWithMode(xContext, TemplateDescription::FILESAVE_AUTOEXTENSION_PASSWORD);
462 Reference< XFilePickerControlAccess > xFPControl(xFP, UNO_QUERY);
463 xFPControl->enableControl(ExtendedFilePickerElementIds::CHECKBOX_PASSWORD, false);
464 Any aValue;
465 aValue <<= true;
466 xFPControl->setValue(ExtendedFilePickerElementIds::CHECKBOX_AUTOEXTENSION, 0, aValue);
468 if ( !m_sCurPath.isEmpty() )
469 xFP->setDisplayDirectory ( m_sCurPath );
471 xFP->appendFilter( "BASIC", "*.bas" );
472 xFP->appendFilter( IDEResId(RID_STR_FILTER_ALLFILES), FilterMask_All );
473 xFP->setCurrentFilter( "BASIC" );
475 if( xFP->execute() != RET_OK )
476 return;
478 Sequence< OUString > aPaths = xFP->getSelectedFiles();
479 m_sCurPath = aPaths[0];
480 SfxMedium aMedium( m_sCurPath, StreamMode::WRITE | StreamMode::SHARE_DENYWRITE | StreamMode::TRUNC );
481 SvStream* pStream = aMedium.GetOutStream();
482 if ( pStream )
484 EnterWait();
485 AssertValidEditEngine();
486 GetEditEngine()->Write( *pStream );
487 aMedium.Commit();
488 LeaveWait();
489 ErrCode nError = aMedium.GetError();
490 if ( nError )
491 ErrorHandler::HandleError( nError );
493 else
495 std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(GetFrameWeld(),
496 VclMessageType::Warning, VclButtonsType::Ok, IDEResId(RID_STR_COULDNTWRITE)));
497 xErrorBox->run();
501 void ModulWindow::ImportDialog()
503 const ScriptDocument& rDocument = GetDocument();
504 OUString aLibName = GetLibName();
505 implImportDialog(GetFrameWeld(), m_sCurPath, rDocument, aLibName);
508 void ModulWindow::ToggleBreakPoint( sal_uInt16 nLine )
510 DBG_ASSERT( XModule().is(), "No Module!" );
512 if ( !XModule().is() )
513 return;
515 CheckCompileBasic();
516 if ( m_aStatus.bError )
518 return;
521 BreakPoint* pBrk = GetBreakPoints().FindBreakPoint( nLine );
522 if ( pBrk ) // remove
524 m_xModule->ClearBP( nLine );
525 GetBreakPoints().remove( pBrk );
527 else // create one
529 if ( m_xModule->SetBP( nLine ))
531 GetBreakPoints().InsertSorted( BreakPoint( nLine ) );
532 if ( StarBASIC::IsRunning() )
534 for ( sal_uInt32 nMethod = 0; nMethod < m_xModule->GetMethods()->Count32(); nMethod++ )
536 SbMethod* pMethod = static_cast<SbMethod*>(m_xModule->GetMethods()->Get32( nMethod ));
537 assert(pMethod && "Method not found! (NULL)");
538 pMethod->SetDebugFlags( pMethod->GetDebugFlags() | BasicDebugFlags::Break );
545 void ModulWindow::UpdateBreakPoint( const BreakPoint& rBrk )
547 DBG_ASSERT( XModule().is(), "No Module!" );
549 if ( XModule().is() )
551 CheckCompileBasic();
553 if ( rBrk.bEnabled )
554 m_xModule->SetBP( rBrk.nLine );
555 else
556 m_xModule->ClearBP( rBrk.nLine );
561 void ModulWindow::BasicToggleBreakPoint()
563 AssertValidEditEngine();
565 TextSelection aSel = GetEditView()->GetSelection();
566 aSel.GetStart().GetPara()++; // Basic lines start at 1!
567 aSel.GetEnd().GetPara()++;
569 for ( sal_uInt32 nLine = aSel.GetStart().GetPara(); nLine <= aSel.GetEnd().GetPara(); ++nLine )
571 ToggleBreakPoint( nLine );
574 m_aXEditorWindow->GetBrkWindow().Invalidate();
578 void ModulWindow::BasicToggleBreakPointEnabled()
580 AssertValidEditEngine();
582 TextView* pView = GetEditView();
583 if ( !pView )
584 return;
586 TextSelection aSel = pView->GetSelection();
587 BreakPointList& rList = GetBreakPoints();
589 for ( sal_uInt32 nLine = ++aSel.GetStart().GetPara(), nEnd = ++aSel.GetEnd().GetPara(); nLine <= nEnd; ++nLine )
591 BreakPoint* pBrk = rList.FindBreakPoint( nLine );
592 if ( pBrk )
594 pBrk->bEnabled = !pBrk->bEnabled;
595 UpdateBreakPoint( *pBrk );
599 GetBreakPointWindow().Invalidate();
602 void ModulWindow::ManageBreakPoints()
604 BreakPointWindow& rBrkWin = GetBreakPointWindow();
605 BreakPointDialog aBrkDlg(rBrkWin.GetFrameWeld(), GetBreakPoints());
606 aBrkDlg.run();
607 rBrkWin.Invalidate();
610 void ModulWindow::BasicErrorHdl( StarBASIC const * pBasic )
612 GetShell()->GetViewFrame()->ToTop();
614 // Return value: BOOL
615 // FALSE: cancel
616 // TRUE: go on...
617 sal_uInt16 nErrorLine = StarBASIC::GetLine() - 1;
618 sal_uInt16 nErrCol1 = StarBASIC::GetCol1();
619 sal_uInt16 nErrCol2 = StarBASIC::GetCol2();
620 if ( nErrCol2 != 0xFFFF )
621 nErrCol2++;
623 AssertValidEditEngine();
624 GetEditView()->SetSelection( TextSelection( TextPaM( nErrorLine, nErrCol1 ), TextPaM( nErrorLine, nErrCol2 ) ) );
626 // if other basic, the IDE should try to display the correct module
627 bool const bMarkError = pBasic == GetBasic();
628 if ( bMarkError )
629 m_aXEditorWindow->GetBrkWindow().SetMarkerPos(nErrorLine, true);
631 // #i47002#
632 Reference< awt::XWindow > xWindow = VCLUnoHelper::GetInterface( this );
634 // tdf#118572 make a currently running dialog, regardless of what its modal
635 // to, insensitive to user input until after this error dialog goes away.
636 TopLevelWindowLocker aBusy;
637 aBusy.incBusy(nullptr);
639 ErrorHandler::HandleError(StarBASIC::GetErrorCode(), GetFrameWeld());
641 aBusy.decBusy();
643 // #i47002#
644 VclPtr<vcl::Window> pWindow = VCLUnoHelper::GetWindow( xWindow );
645 if ( !pWindow )
646 return;
648 if ( bMarkError )
649 m_aXEditorWindow->GetBrkWindow().SetNoMarker();
650 return;
653 BasicDebugFlags ModulWindow::BasicBreakHdl()
655 // Return value: sal_uInt16 => see SB-Debug-Flags
656 sal_uInt16 nErrorLine = StarBASIC::GetLine();
659 BreakPoint* pBrk = GetBreakPoints().FindBreakPoint( nErrorLine );
660 if ( pBrk )
662 pBrk->nHitCount++;
663 if ( pBrk->nHitCount <= pBrk->nStopAfter && GetBasic()->IsBreak() )
664 return m_aStatus.nBasicFlags; // go on...
667 nErrorLine--; // EditEngine starts at 0, Basic at 1
669 AssertValidEditEngine();
670 GetEditView()->SetSelection( TextSelection( TextPaM( nErrorLine, 0 ), TextPaM( nErrorLine, 0 ) ) );
671 m_aXEditorWindow->GetBrkWindow().SetMarkerPos( nErrorLine );
673 m_rLayout.UpdateDebug(false);
675 m_aStatus.bIsInReschedule = true;
676 m_aStatus.bIsRunning = true;
678 AddStatus( BASWIN_INRESCHEDULE );
680 InvalidateDebuggerSlots();
682 while( m_aStatus.bIsRunning )
683 Application::Yield();
685 m_aStatus.bIsInReschedule = false;
686 m_aXEditorWindow->GetBrkWindow().SetNoMarker();
688 ClearStatus( BASWIN_INRESCHEDULE );
690 return m_aStatus.nBasicFlags;
693 void ModulWindow::BasicAddWatch()
695 AssertValidEditEngine();
696 bool bAdd = true;
697 if ( !GetEditView()->HasSelection() )
699 // tdf#57307 - expand selection to include connector punctuations
700 TextSelection aSel;
701 OUString aWord = GetEditEngine()->GetWord( GetEditView()->GetSelection().GetEnd(), &aSel.GetStart(), &aSel.GetEnd() );
702 if ( !aWord.isEmpty() )
703 GetEditView()->SetSelection( aSel );
704 else
705 bAdd = false;
707 if ( bAdd )
709 TextSelection aSel = GetEditView()->GetSelection();
710 if ( aSel.GetStart().GetPara() == aSel.GetEnd().GetPara() ) // single line selection
711 m_rLayout.BasicAddWatch(GetEditView()->GetSelected());
716 void ModulWindow::EditMacro( const OUString& rMacroName )
718 DBG_ASSERT( XModule().is(), "No Module!" );
720 if ( !XModule().is() )
721 return;
723 CheckCompileBasic();
725 if ( m_aStatus.bError )
726 return;
728 sal_uInt16 nStart, nEnd;
729 SbMethod* pMethod = static_cast<SbMethod*>(m_xModule->Find( rMacroName, SbxClassType::Method ));
730 if ( !pMethod )
731 return;
733 pMethod->GetLineRange( nStart, nEnd );
734 if ( nStart )
736 nStart--;
737 nEnd--;
739 TextSelection aSel( TextPaM( nStart, 0 ), TextPaM( nStart, 0 ) );
740 AssertValidEditEngine();
741 TextView * pView = GetEditView();
742 // scroll if applicable so that first line is at the top
743 tools::Long nVisHeight = GetOutputSizePixel().Height();
744 if ( pView->GetTextEngine()->GetTextHeight() > nVisHeight )
746 tools::Long nMaxY = pView->GetTextEngine()->GetTextHeight() - nVisHeight;
747 tools::Long nOldStartY = pView->GetStartDocPos().Y();
748 tools::Long nNewStartY = static_cast<tools::Long>(nStart) * pView->GetTextEngine()->GetCharHeight();
749 nNewStartY = std::min( nNewStartY, nMaxY );
750 pView->Scroll( 0, -(nNewStartY-nOldStartY) );
751 pView->ShowCursor( false );
752 GetEditVScrollBar().SetThumbPos( pView->GetStartDocPos().Y() );
754 pView->SetSelection( aSel );
755 pView->ShowCursor();
756 pView->GetWindow()->GrabFocus();
759 void ModulWindow::StoreData()
761 // StoreData is called when the BasicManager is destroyed or
762 // this window is closed.
763 // => interrupts undesired!
764 GetEditorWindow().SetSourceInBasic();
767 bool ModulWindow::AllowUndo()
769 return GetEditorWindow().CanModify();
772 void ModulWindow::UpdateData()
774 DBG_ASSERT( XModule().is(), "No Module!" );
775 // UpdateData is called when the source has changed from outside
776 // => interrupts undesired!
778 if ( !XModule().is() )
779 return;
781 SetModule( m_xModule->GetSource32() );
783 if ( GetEditView() )
785 TextSelection aSel = GetEditView()->GetSelection();
786 setTextEngineText(*GetEditEngine(), m_xModule->GetSource32());
787 GetEditView()->SetSelection( aSel );
788 GetEditEngine()->SetModified( false );
789 MarkDocumentModified( GetDocument() );
793 sal_Int32 ModulWindow::countPages( Printer* pPrinter )
795 return FormatAndPrint( pPrinter, -1 );
798 void ModulWindow::printPage( sal_Int32 nPage, Printer* pPrinter )
800 FormatAndPrint( pPrinter, nPage );
803 /* implementation note: this is totally inefficient for the XRenderable interface
804 usage since the whole "document" will be format for every page. Should this ever
805 become a problem we should
806 - format only once for every new printer
807 - keep an index list for each page which is the starting paragraph
809 sal_Int32 ModulWindow::FormatAndPrint( Printer* pPrinter, sal_Int32 nPrintPage )
811 AssertValidEditEngine();
813 MapMode eOldMapMode( pPrinter->GetMapMode() );
814 vcl::Font aOldFont( pPrinter->GetFont() );
816 vcl::Font aFont( GetEditEngine()->GetFont() );
817 aFont.SetAlignment( ALIGN_BOTTOM );
818 aFont.SetTransparent( true );
819 aFont.SetFontSize( Size( 0, 360 ) );
820 pPrinter->SetFont( aFont );
821 pPrinter->SetMapMode(MapMode(MapUnit::Map100thMM));
823 OUString aTitle( CreateQualifiedName() );
825 sal_Int32 nLineHeight = pPrinter->GetTextHeight();
826 if(nLineHeight == 0)
828 nLineHeight = 1;
831 Size aPaperSz = pPrinter->GetOutputSize();
832 aPaperSz.AdjustWidth( -(Print::nLeftMargin + Print::nRightMargin) );
833 aPaperSz.AdjustHeight( -(Print::nTopMargin + Print::nBottomMargin) );
835 // nLinepPage is not correct if there's a line break
836 sal_Int32 nLinespPage = aPaperSz.Height()/nLineHeight;
837 tools::Long nXTextWidth = pPrinter->approximate_digit_width();
839 sal_Int32 nCharspLine = aPaperSz.Width() / std::max<tools::Long>(nXTextWidth, 1);
840 const sal_uInt32 nParas = GetEditEngine()->GetParagraphCount();
842 sal_Int32 nPages = nParas/nLinespPage+1;
843 sal_Int32 nCurPage = 1;
845 lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle, nPrintPage == 0 );
846 Point aPos( Print::nLeftMargin, Print::nTopMargin );
847 for ( sal_uInt32 nPara = 0; nPara < nParas; ++nPara )
849 OUString aLine( GetEditEngine()->GetText( nPara ) );
850 lcl_ConvertTabsToSpaces( aLine );
851 sal_Int32 nLines = aLine.getLength()/nCharspLine+1;
852 for (sal_Int32 nLine = 0; nLine < nLines; ++nLine)
854 sal_Int32 nBeginIndex = nLine*nCharspLine;
855 sal_Int32 nCopyCount = std::min<sal_Int32>(nCharspLine, aLine.getLength()-nBeginIndex);
856 OUString aTmpLine = aLine.copy(nBeginIndex, nCopyCount);
857 aPos.AdjustY(nLineHeight );
858 if ( aPos.Y() > ( aPaperSz.Height() + Print::nTopMargin ) )
860 nCurPage++;
861 lcl_PrintHeader( pPrinter, nPages, nCurPage, aTitle, nCurPage-1 == nPrintPage );
862 aPos = Point(Print::nLeftMargin, Print::nTopMargin + nLineHeight);
864 if( nCurPage-1 == nPrintPage )
865 pPrinter->DrawText( aPos, aTmpLine );
867 aPos.AdjustY(10 ); // nParaSpace
870 pPrinter->SetFont( aOldFont );
871 pPrinter->SetMapMode( eOldMapMode );
873 return nCurPage;
876 void ModulWindow::ExecuteCommand (SfxRequest& rReq)
878 AssertValidEditEngine();
879 switch (rReq.GetSlot())
881 case SID_DELETE:
883 if (!IsReadOnly())
885 KeyEvent aFakeDelete(0, KEY_DELETE);
886 (void)GetEditView()->KeyInput(aFakeDelete);
888 break;
890 case SID_SELECTALL:
892 TextSelection aSel( TextPaM( 0, 0 ), TextPaM( TEXT_PARA_ALL, TEXT_INDEX_ALL ) );
893 TextView * pView = GetEditView();
894 pView->SetSelection( aSel );
895 pView->GetWindow()->GrabFocus();
896 break;
898 case SID_BASICRUN:
900 BasicRun();
902 break;
903 case SID_BASICCOMPILE:
905 CompileBasic();
907 break;
908 case SID_BASICSTEPOVER:
910 BasicStepOver();
912 break;
913 case SID_BASICSTEPINTO:
915 BasicStepInto();
917 break;
918 case SID_BASICSTEPOUT:
920 BasicStepOut();
922 break;
923 case SID_BASICLOAD:
925 LoadBasic();
927 break;
928 case SID_BASICSAVEAS:
930 SaveBasicSource();
932 break;
933 case SID_IMPORT_DIALOG:
935 ImportDialog();
937 break;
938 case SID_BASICIDE_MATCHGROUP:
940 GetEditView()->MatchGroup();
942 break;
943 case SID_BASICIDE_TOGGLEBRKPNT:
945 BasicToggleBreakPoint();
947 break;
948 case SID_BASICIDE_MANAGEBRKPNTS:
950 ManageBreakPoints();
952 break;
953 case SID_BASICIDE_TOGGLEBRKPNTENABLED:
955 BasicToggleBreakPointEnabled();
957 break;
958 case SID_BASICIDE_ADDWATCH:
960 BasicAddWatch();
962 break;
963 case SID_BASICIDE_REMOVEWATCH:
965 m_rLayout.BasicRemoveWatch();
967 break;
968 case SID_CUT:
970 if ( !IsReadOnly() )
972 GetEditView()->Cut();
973 if (SfxBindings* pBindings = GetBindingsPtr())
974 pBindings->Invalidate( SID_DOC_MODIFIED );
977 break;
978 case SID_COPY:
980 GetEditView()->Copy();
982 break;
983 case SID_PASTE:
985 if ( !IsReadOnly() )
987 GetEditView()->Paste();
988 if (SfxBindings* pBindings = GetBindingsPtr())
989 pBindings->Invalidate( SID_DOC_MODIFIED );
992 break;
993 case SID_BASICIDE_BRKPNTSCHANGED:
995 GetBreakPointWindow().Invalidate();
997 break;
998 case SID_SHOWLINES:
1000 const SfxBoolItem* pItem = rReq.GetArg<SfxBoolItem>(rReq.GetSlot());
1001 bool bLineNumbers = pItem && pItem->GetValue();
1002 m_aXEditorWindow->SetLineNumberDisplay(bLineNumbers);
1004 std::shared_ptr<comphelper::ConfigurationChanges> batch(comphelper::ConfigurationChanges::create());
1005 officecfg::Office::BasicIDE::EditorSettings::LineNumbering::set(bLineNumbers, batch);
1006 batch->commit();
1008 break;
1009 case SID_BASICIDE_DELETECURRENT:
1011 if (QueryDelModule(m_aName, GetFrameWeld()))
1013 // tdf#134551 don't delete the window if last module is removed until this block
1014 // is complete
1015 VclPtr<ModulWindow> xKeepRef(this);
1016 if (m_aDocument.removeModule(m_aLibName, m_aName))
1017 MarkDocumentModified(m_aDocument);
1020 break;
1021 case FID_SEARCH_OFF:
1022 GrabFocus();
1023 break;
1024 case SID_GOTOLINE:
1026 GotoLineDialog aGotoDlg(GetFrameWeld());
1027 if (aGotoDlg.run() == RET_OK)
1029 if (sal_Int32 const nLine = aGotoDlg.GetLineNumber())
1031 TextSelection const aSel(TextPaM(nLine - 1, 0), TextPaM(nLine - 1, 0));
1032 GetEditView()->SetSelection(aSel);
1035 break;
1040 void ModulWindow::ExecuteGlobal (SfxRequest& rReq)
1042 switch (rReq.GetSlot())
1044 case SID_SIGNATURE:
1046 DocumentSignature aSignature(m_aDocument);
1047 if (aSignature.supportsSignatures())
1049 aSignature.signScriptingContent(rReq.GetFrameWeld());
1050 if (SfxBindings* pBindings = GetBindingsPtr())
1051 pBindings->Invalidate(SID_SIGNATURE);
1054 break;
1058 void ModulWindow::GetState( SfxItemSet &rSet )
1060 SfxWhichIter aIter(rSet);
1061 for ( sal_uInt16 nWh = aIter.FirstWhich(); nWh != 0; nWh = aIter.NextWhich() )
1063 switch ( nWh )
1065 case SID_CUT:
1067 if ( !GetEditView() || !GetEditView()->HasSelection() )
1068 rSet.DisableItem( nWh );
1070 if ( IsReadOnly() )
1071 rSet.DisableItem( nWh );
1073 break;
1074 case SID_COPY:
1076 if ( !GetEditView() || !GetEditView()->HasSelection() )
1077 rSet.DisableItem( nWh );
1079 break;
1080 case SID_PASTE:
1082 if ( !IsPasteAllowed() )
1083 rSet.DisableItem( nWh );
1085 if ( IsReadOnly() )
1086 rSet.DisableItem( nWh );
1088 break;
1089 case SID_BASICIDE_STAT_POS:
1091 TextView* pView = GetEditView();
1092 if ( pView )
1094 TextSelection aSel = pView->GetSelection();
1095 OUString aPos = IDEResId( RID_STR_LINE ) +
1096 " " +
1097 OUString::number(aSel.GetEnd().GetPara()+1) +
1098 ", " +
1099 IDEResId( RID_STR_COLUMN ) +
1100 " " +
1101 OUString::number(aSel.GetEnd().GetIndex()+1);
1102 SfxStringItem aItem( SID_BASICIDE_STAT_POS, aPos );
1103 rSet.Put( aItem );
1106 break;
1107 case SID_BASICIDE_STAT_TITLE:
1109 // search for current procedure name (Sub or Function)
1110 TextView* pView = GetEditView();
1111 if ( pView )
1113 OUString sProcName;
1115 TextSelection aSel = pView->GetSelection();
1117 sal_uInt32 i = aSel.GetStart().GetPara();
1120 OUString aCurrLine = GetEditEngine()->GetText( i );
1121 OUString sProcType;
1122 if (GetEditorWindow().GetProcedureName(aCurrLine, sProcType, sProcName))
1123 break;
1124 } while (i--);
1126 OUString aTitle = CreateQualifiedName();
1127 if (!sProcName.isEmpty())
1128 aTitle += "." + sProcName;
1130 SfxStringItem aTitleItem( SID_BASICIDE_STAT_TITLE, aTitle );
1131 rSet.Put( aTitleItem );
1134 break;
1135 case SID_ATTR_INSERT:
1137 TextView* pView = GetEditView();
1138 if ( pView )
1140 SfxBoolItem aItem( SID_ATTR_INSERT, pView->IsInsertMode() );
1141 rSet.Put( aItem );
1144 break;
1145 case SID_SHOWLINES:
1147 bool bLineNumbers = ::officecfg::Office::BasicIDE::EditorSettings::LineNumbering::get();
1148 rSet.Put(SfxBoolItem(nWh, bLineNumbers));
1149 break;
1151 case SID_SELECTALL:
1153 if ( !GetEditView() )
1154 rSet.DisableItem( nWh );
1156 break;
1161 void ModulWindow::DoScroll( ScrollBar* pCurScrollBar )
1163 if ( ( pCurScrollBar == GetHScrollBar() ) && GetEditView() )
1165 // don't scroll with the value but rather use the Thumb-Pos for the VisArea:
1166 tools::Long nDiff = GetEditView()->GetStartDocPos().X() - pCurScrollBar->GetThumbPos();
1167 GetEditView()->Scroll( nDiff, 0 );
1168 GetEditView()->ShowCursor( false );
1169 pCurScrollBar->SetThumbPos( GetEditView()->GetStartDocPos().X() );
1174 bool ModulWindow::IsModified()
1176 return GetEditEngine() && GetEditEngine()->IsModified();
1179 OUString ModulWindow::GetSbModuleName()
1181 OUString aModuleName;
1182 if ( XModule().is() )
1183 aModuleName = m_xModule->GetName();
1184 return aModuleName;
1187 OUString ModulWindow::GetTitle()
1189 return GetSbModuleName();
1192 void ModulWindow::ShowCursor( bool bOn )
1194 if ( GetEditEngine() )
1196 TextView* pView = GetEditEngine()->GetActiveView();
1197 if ( pView )
1199 if ( bOn )
1200 pView->ShowCursor();
1201 else
1202 pView->HideCursor();
1207 void ModulWindow::AssertValidEditEngine()
1209 if ( !GetEditEngine() )
1210 GetEditorWindow().CreateEditEngine();
1213 void ModulWindow::Activating ()
1215 bool bLineNumbers = ::officecfg::Office::BasicIDE::EditorSettings::LineNumbering::get();
1216 m_aXEditorWindow->SetLineNumberDisplay(bLineNumbers);
1217 Show();
1220 void ModulWindow::Deactivating()
1222 Hide();
1225 sal_uInt16 ModulWindow::StartSearchAndReplace( const SvxSearchItem& rSearchItem, bool bFromStart )
1227 if (IsSuspended())
1228 return 0;
1230 // one could also relinquish syntaxhighlighting/formatting instead of the stupid replace-everything...
1231 AssertValidEditEngine();
1232 TextView* pView = GetEditView();
1233 TextSelection aSel;
1234 if ( bFromStart )
1236 aSel = pView->GetSelection();
1237 if ( !rSearchItem.GetBackward() )
1238 pView->SetSelection( TextSelection() );
1239 else
1240 pView->SetSelection( TextSelection( TextPaM( TEXT_PARA_ALL, TEXT_INDEX_ALL ), TextPaM( TEXT_PARA_ALL, TEXT_INDEX_ALL ) ) );
1243 bool const bForward = !rSearchItem.GetBackward();
1244 sal_uInt16 nFound = 0;
1245 if ( ( rSearchItem.GetCommand() == SvxSearchCmd::FIND ) ||
1246 ( rSearchItem.GetCommand() == SvxSearchCmd::FIND_ALL ) )
1248 nFound = pView->Search( rSearchItem.GetSearchOptions() , bForward ) ? 1 : 0;
1250 else if ( ( rSearchItem.GetCommand() == SvxSearchCmd::REPLACE ) ||
1251 ( rSearchItem.GetCommand() == SvxSearchCmd::REPLACE_ALL ) )
1253 if ( !IsReadOnly() )
1255 bool const bAll = rSearchItem.GetCommand() == SvxSearchCmd::REPLACE_ALL;
1256 nFound = pView->Replace( rSearchItem.GetSearchOptions() , bAll , bForward );
1260 if ( bFromStart && !nFound )
1261 pView->SetSelection( aSel );
1263 return nFound;
1266 SfxUndoManager* ModulWindow::GetUndoManager()
1268 if ( GetEditEngine() )
1269 return &GetEditEngine()->GetUndoManager();
1270 return nullptr;
1273 SearchOptionFlags ModulWindow::GetSearchOptions()
1275 SearchOptionFlags nOptions = SearchOptionFlags::SEARCH |
1276 SearchOptionFlags::WHOLE_WORDS |
1277 SearchOptionFlags::BACKWARDS |
1278 SearchOptionFlags::REG_EXP |
1279 SearchOptionFlags::EXACT |
1280 SearchOptionFlags::SELECTION |
1281 SearchOptionFlags::SIMILARITY;
1283 if ( !IsReadOnly() )
1285 nOptions |= SearchOptionFlags::REPLACE;
1286 nOptions |= SearchOptionFlags::REPLACE_ALL;
1289 return nOptions;
1292 void ModulWindow::BasicStarted()
1294 if ( !XModule().is() )
1295 return;
1297 m_aStatus.bIsRunning = true;
1298 BreakPointList& rList = GetBreakPoints();
1299 if ( rList.size() )
1301 rList.ResetHitCount();
1302 rList.SetBreakPointsInBasic( m_xModule.get() );
1303 for ( sal_uInt32 nMethod = 0; nMethod < m_xModule->GetMethods()->Count32(); nMethod++ )
1305 SbMethod* pMethod = static_cast<SbMethod*>(m_xModule->GetMethods()->Get32( nMethod ));
1306 assert(pMethod && "Method not found! (NULL)");
1307 pMethod->SetDebugFlags( pMethod->GetDebugFlags() | BasicDebugFlags::Break );
1312 void ModulWindow::BasicStopped()
1314 m_aStatus.bIsRunning = false;
1315 GetBreakPointWindow().SetNoMarker();
1318 EntryDescriptor ModulWindow::CreateEntryDescriptor()
1320 ScriptDocument aDocument( GetDocument() );
1321 OUString aLibName( GetLibName() );
1322 LibraryLocation eLocation = aDocument.getLibraryLocation( aLibName );
1323 OUString aModName( GetName() );
1324 OUString aLibSubName;
1325 if( m_xBasic.is() && aDocument.isInVBAMode() && XModule().is() )
1327 switch( m_xModule->GetModuleType() )
1329 case script::ModuleType::DOCUMENT:
1331 aLibSubName = IDEResId( RID_STR_DOCUMENT_OBJECTS );
1332 uno::Reference< container::XNameContainer > xLib = aDocument.getOrCreateLibrary( E_SCRIPTS, aLibName );
1333 if( xLib.is() )
1335 OUString sObjName;
1336 ModuleInfoHelper::getObjectName( xLib, aModName, sObjName );
1337 if( !sObjName.isEmpty() )
1339 aModName += " (" + sObjName + ")";
1342 break;
1344 case script::ModuleType::FORM:
1345 aLibSubName = IDEResId( RID_STR_USERFORMS );
1346 break;
1347 case script::ModuleType::NORMAL:
1348 aLibSubName = IDEResId( RID_STR_NORMAL_MODULES );
1349 break;
1350 case script::ModuleType::CLASS:
1351 aLibSubName = IDEResId( RID_STR_CLASS_MODULES );
1352 break;
1355 return EntryDescriptor( aDocument, eLocation, aLibName, aLibSubName, aModName, OBJ_TYPE_MODULE );
1358 void ModulWindow::SetReadOnly (bool b)
1360 if ( GetEditView() )
1361 GetEditView()->SetReadOnly( b );
1364 bool ModulWindow::IsReadOnly()
1366 return GetEditView() && GetEditView()->IsReadOnly();
1369 bool ModulWindow::IsPasteAllowed()
1371 bool bPaste = false;
1373 // get clipboard
1374 Reference< datatransfer::clipboard::XClipboard > xClipboard = GetClipboard();
1375 if ( xClipboard.is() )
1378 Reference< datatransfer::XTransferable > xTransf;
1380 SolarMutexReleaser aReleaser;
1381 // get clipboard content
1382 xTransf = xClipboard->getContents();
1384 if ( xTransf.is() )
1386 datatransfer::DataFlavor aFlavor;
1387 SotExchange::GetFormatDataFlavor( SotClipboardFormatId::STRING, aFlavor );
1388 if ( xTransf->isDataFlavorSupported( aFlavor ) )
1389 bPaste = true;
1393 return bPaste;
1396 void ModulWindow::OnNewDocument ()
1398 bool bLineNumbers = ::officecfg::Office::BasicIDE::EditorSettings::LineNumbering::get();
1399 m_aXEditorWindow->SetLineNumberDisplay(bLineNumbers);
1402 char const* ModulWindow::GetHid () const
1404 return HID_BASICIDE_MODULWINDOW;
1406 ItemType ModulWindow::GetType () const
1408 return TYPE_MODULE;
1411 bool ModulWindow::HasActiveEditor () const
1413 return !IsSuspended();
1417 void ModulWindow::UpdateModule ()
1419 OUString const aModule = getTextEngineText(*GetEditEngine());
1421 // update module in basic
1422 assert(m_xModule.is());
1424 // update module in module window
1425 SetModule(aModule);
1427 // update module in library
1428 OSL_VERIFY(m_aDocument.updateModule(m_aLibName, m_aName, aModule));
1430 GetEditEngine()->SetModified(false);
1431 MarkDocumentModified(m_aDocument);
1434 ModulWindowLayout::ModulWindowLayout (vcl::Window* pParent, ObjectCatalog& rObjectCatalog_) :
1435 Layout(pParent),
1436 pChild(nullptr),
1437 aWatchWindow(VclPtr<WatchWindow>::Create(this)),
1438 aStackWindow(VclPtr<StackWindow>::Create(this)),
1439 rObjectCatalog(rObjectCatalog_)
1442 ModulWindowLayout::~ModulWindowLayout()
1444 disposeOnce();
1447 void ModulWindowLayout::dispose()
1449 aWatchWindow.disposeAndClear();
1450 aStackWindow.disposeAndClear();
1451 pChild.clear();
1452 Layout::dispose();
1455 void ModulWindowLayout::UpdateDebug (bool bBasicStopped)
1457 aWatchWindow->UpdateWatches(bBasicStopped);
1458 aStackWindow->UpdateCalls();
1461 void ModulWindowLayout::Paint (vcl::RenderContext& rRenderContext, tools::Rectangle const&)
1463 rRenderContext.DrawText(Point(), IDEResId(RID_STR_NOMODULE));
1466 void ModulWindowLayout::Activating (BaseWindow& rChild)
1468 assert(dynamic_cast<ModulWindow*>(&rChild));
1469 pChild = &static_cast<ModulWindow&>(rChild);
1470 aWatchWindow->Show();
1471 aStackWindow->Show();
1472 rObjectCatalog.Show();
1473 rObjectCatalog.SetLayoutWindow(this);
1474 rObjectCatalog.UpdateEntries();
1475 Layout::Activating(rChild);
1476 aSyntaxColors.SetActiveEditor(&pChild->GetEditorWindow());
1479 void ModulWindowLayout::Deactivating ()
1481 aSyntaxColors.SetActiveEditor(nullptr);
1482 Layout::Deactivating();
1483 aWatchWindow->Hide();
1484 aStackWindow->Hide();
1485 rObjectCatalog.Hide();
1486 pChild = nullptr;
1489 void ModulWindowLayout::GetState (SfxItemSet &rSet, unsigned nWhich)
1491 switch (nWhich)
1493 case SID_SHOW_PROPERTYBROWSER:
1494 rSet.Put(SfxVisibilityItem(nWhich, false));
1495 break;
1497 case SID_BASICIDE_CHOOSEMACRO:
1498 rSet.Put(SfxVisibilityItem(nWhich, true));
1499 break;
1503 void ModulWindowLayout::BasicAddWatch (OUString const& rWatchStr)
1505 aWatchWindow->AddWatch(rWatchStr);
1508 void ModulWindowLayout::BasicRemoveWatch ()
1510 aWatchWindow->RemoveSelectedWatch();
1513 void ModulWindowLayout::OnFirstSize (tools::Long const nWidth, tools::Long const nHeight)
1515 AddToLeft(&rObjectCatalog, Size(nWidth * 0.20, nHeight * 0.75));
1516 AddToBottom(aWatchWindow.get(), Size(nWidth * 0.67, nHeight * 0.25));
1517 AddToBottom(aStackWindow.get(), Size(nWidth * 0.33, nHeight * 0.25));
1520 ModulWindowLayout::SyntaxColors::SyntaxColors () :
1521 pEditor(nullptr)
1523 aConfig.AddListener(this);
1525 NewConfig(true);
1528 ModulWindowLayout::SyntaxColors::~SyntaxColors ()
1530 aConfig.RemoveListener(this);
1533 // virtual
1534 void ModulWindowLayout::SyntaxColors::ConfigurationChanged (utl::ConfigurationBroadcaster*, ConfigurationHints)
1536 NewConfig(false);
1539 // when a new configuration has to be set
1540 void ModulWindowLayout::SyntaxColors::NewConfig (bool bFirst)
1542 static struct
1544 TokenType eTokenType;
1545 svtools::ColorConfigEntry eEntry;
1547 const vIds[] =
1549 { TokenType::Unknown, svtools::FONTCOLOR },
1550 { TokenType::Identifier, svtools::BASICIDENTIFIER },
1551 { TokenType::Whitespace, svtools::FONTCOLOR },
1552 { TokenType::Number, svtools::BASICNUMBER },
1553 { TokenType::String, svtools::BASICSTRING },
1554 { TokenType::EOL, svtools::FONTCOLOR },
1555 { TokenType::Comment, svtools::BASICCOMMENT },
1556 { TokenType::Error, svtools::BASICERROR },
1557 { TokenType::Operator, svtools::BASICOPERATOR },
1558 { TokenType::Keywords, svtools::BASICKEYWORD },
1561 Color aDocColor = aConfig.GetColorValue(svtools::DOCCOLOR).nColor;
1562 if (bFirst || aDocColor != m_aBackgroundColor)
1564 m_aBackgroundColor = aDocColor;
1565 if (!bFirst && pEditor)
1567 pEditor->SetBackground(Wallpaper(m_aBackgroundColor));
1568 pEditor->Invalidate();
1572 Color aFontColor = aConfig.GetColorValue(svtools::FONTCOLOR).nColor;
1573 if (bFirst || aFontColor != m_aFontColor)
1575 m_aFontColor = aFontColor;
1576 if (!bFirst && pEditor)
1577 pEditor->ChangeFontColor(m_aFontColor);
1580 bool bChanged = false;
1581 for (unsigned i = 0; i != SAL_N_ELEMENTS(vIds); ++i)
1583 Color const aColor = aConfig.GetColorValue(vIds[i].eEntry).nColor;
1584 Color& rMyColor = aColors[vIds[i].eTokenType];
1585 if (bFirst || aColor != rMyColor)
1587 rMyColor = aColor;
1588 bChanged = true;
1591 if (bChanged && !bFirst && pEditor)
1592 pEditor->UpdateSyntaxHighlighting();
1595 } // namespace basctl
1597 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */