1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
25 #include "breakpoint.hxx"
26 #include "linenumberwindow.hxx"
27 #include <colorscheme.hxx>
29 #include <basic/sbmod.hxx>
30 #include <basic/sbstar.hxx>
31 #include <vcl/InterimItemWindow.hxx>
32 #include <vcl/idle.hxx>
33 #include <vcl/weld.hxx>
35 #include <svtools/colorcfg.hxx>
36 #include <svtools/scrolladaptor.hxx>
37 #include <o3tl/enumarray.hxx>
38 #include <rtl/ustrbuf.hxx>
42 #include <string_view>
44 #include <vcl/textdata.hxx>
45 #include <basic/codecompletecache.hxx>
46 #include <com/sun/star/reflection/XIdlClass.hpp>
47 #include <comphelper/syntaxhighlight.hxx>
52 namespace com::sun::star::beans
{ class XMultiPropertySet
; }
58 class CodeCompleteWindow
;
59 class ModulWindowLayout
;
61 // #108672 Helper functions to get/set text in TextEngine
62 // using the stream interface (get/setText() only supports
63 // tools Strings limited to 64K).
64 // defined in baside2b.cxx
65 OUString
getTextEngineText (ExtTextEngine
&);
66 void setTextEngineText (ExtTextEngine
&, std::u16string_view
);
68 class EditorWindow final
: public vcl::Window
, public SfxListener
70 friend class CodeCompleteWindow
;
71 friend class EditorWindowUIObject
;
73 class ChangesListener
;
75 std::unique_ptr
<TextView
> pEditView
;
76 std::unique_ptr
<ExtTextEngine
> pEditEngine
;
77 ModulWindow
& rModulWindow
;
79 rtl::Reference
< ChangesListener
> listener_
;
81 css::uno::Reference
< css::beans::XMultiPropertySet
>
84 tools::Long nCurTextWidth
;
86 ImplSVEvent
* m_nSetSourceInBasicId
;
88 SyntaxHighlighter aHighlighter
;
90 std::set
<sal_uInt16
> aSyntaxLineTable
;
91 DECL_LINK(SyntaxTimerHdl
, Timer
*, void);
92 DECL_LINK(SetSourceInBasicHdl
, void*, void);
96 std::unique_ptr
<ProgressInfo
> pProgress
;
98 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
100 void ImpDoHighlight( sal_uInt32 nLineOff
);
102 sal_uInt16 nCurrentZoomLevel
;
105 bool bDoSyntaxHighlight
;
106 bool bDelayHighlight
;
108 // Used to determine if the highlighted line has changed, which would require redrawing the highlight
109 sal_uInt32 m_nLastHighlightPara
;
111 Color m_aLineHighlightColor
;
113 virtual css::uno::Reference
< css::awt::XVclWindowPeer
> GetComponentInterface(bool bCreate
= true) override
;
114 CodeCompleteDataCache aCodeCompleteCache
;
115 VclPtr
<CodeCompleteWindow
> pCodeCompleteWnd
;
116 OUString
GetActualSubName( sal_uInt32 nLine
); // gets the actual subroutine name according to line number
117 void SetupAndShowCodeCompleteWnd(const std::vector
< OUString
>& aEntryVect
, TextSelection aSel
);
118 void HandleAutoCorrect();
119 void HandleAutoCloseParen();
120 void HandleAutoCloseDoubleQuotes();
121 void HandleCodeCompletion();
122 void HandleProcedureCompletion();
123 TextSelection
GetLastHighlightPortionTextSelection() const;
125 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& ) override
;
126 virtual void Resize() override
;
127 virtual void KeyInput( const KeyEvent
& rKeyEvt
) override
;
128 virtual void MouseMove( const MouseEvent
& rMEvt
) override
;
129 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) override
;
130 virtual void MouseButtonUp( const MouseEvent
& rMEvt
) override
;
131 virtual void Command( const CommandEvent
& rCEvt
) override
;
132 virtual void LoseFocus() override
;
133 virtual void RequestHelp( const HelpEvent
& rHEvt
) override
;
135 void DoSyntaxHighlight( sal_uInt32 nPara
);
136 OUString
GetWordAtCursor();
138 void HighlightCurrentLine(vcl::RenderContext
& rRenderContext
);
141 EditorWindow (vcl::Window
* pParent
, ModulWindow
*);
142 virtual ~EditorWindow() override
;
143 virtual void dispose() override
;
145 ExtTextEngine
* GetEditEngine() const { return pEditEngine
.get(); }
146 TextView
* GetEditView() const { return pEditView
.get(); }
148 void CreateProgress( const OUString
& rText
, sal_uInt32 nRange
);
149 void DestroyProgress();
151 void ParagraphInsertedDeleted( sal_uInt32 nNewPara
, bool bInserted
);
152 void DoDelayedSyntaxHighlight( sal_uInt32 nPara
);
154 void CreateEditEngine();
155 void SetScrollBarRanges();
156 void InitScrollBars();
158 void ForceSyntaxTimeout();
159 void SetSourceInBasic();
161 bool CanModify() { return ImpCanModify(); }
163 void ChangeFontColor( Color aColor
);
164 void UpdateSyntaxHighlighting ();
165 void SetLineHighlightColor(Color aColor
);
167 void SetEditorZoomLevel(sal_uInt16 nNewZoomLevel
);
168 sal_uInt16
GetCurrentZoom() { return nCurrentZoomLevel
; }
170 bool GetProcedureName(std::u16string_view rLine
, OUString
& rProcType
, OUString
& rProcName
) const;
172 FactoryFunction
GetUITestFactory() const override
;
175 class BreakPointWindow final
: public vcl::Window
177 ModulWindow
& rModulWindow
;
178 tools::Long nCurYOffset
;
179 sal_uInt16 nMarkerPos
;
180 BreakPointList aBreakPointList
;
183 virtual void DataChanged(DataChangedEvent
const & rDCEvt
) override
;
185 void setBackgroundColor(Color aColor
);
187 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&) override
;
188 BreakPoint
* FindBreakPoint( const Point
& rMousePos
);
189 void ShowMarker(vcl::RenderContext
& rRenderContext
);
190 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) override
;
191 virtual void Command( const CommandEvent
& rCEvt
) override
;
196 BreakPointWindow (vcl::Window
* pParent
, ModulWindow
*);
198 void SetMarkerPos( sal_uInt16 nLine
, bool bErrorMarker
= false );
201 void DoScroll( tools::Long nVertScroll
);
202 tools::Long
& GetCurYOffset() { return nCurYOffset
; }
203 BreakPointList
& GetBreakPoints() { return aBreakPointList
; }
206 class WatchWindow final
: public DockingWindow
209 std::unique_ptr
<weld::Container
> m_xTitleArea
;
210 std::unique_ptr
<weld::Label
> m_xTitle
;
211 std::unique_ptr
<weld::Entry
> m_xEdit
;
212 std::unique_ptr
<weld::Button
> m_xRemoveWatchButton
;
213 std::unique_ptr
<weld::TreeView
> m_xTreeListBox
;
215 ImplSVEvent
* m_nUpdateWatchesId
;
216 OUString aEditingRes
;
218 virtual void Resize() override
;
219 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
221 SbxBase
* ImplGetSBXForEntry(const weld::TreeIter
& rEntry
, bool& rbArrayElement
);
223 void implEnableChildren(const weld::TreeIter
& rEntry
, bool bEnable
);
225 DECL_STATIC_LINK(WatchWindow
, ButtonHdl
, weld::Button
&, void);
226 DECL_LINK(TreeListHdl
, weld::TreeView
&, void);
227 DECL_LINK(RequestingChildrenHdl
, const weld::TreeIter
&, bool);
228 DECL_LINK(ActivateHdl
, weld::Entry
&, bool);
229 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
230 DECL_LINK(EditingEntryHdl
, const weld::TreeIter
&, bool);
231 typedef std::pair
<const weld::TreeIter
&, OUString
> IterString
;
232 DECL_LINK(EditedEntryHdl
, const IterString
&, bool);
233 DECL_LINK(ExecuteUpdateWatches
, void*, void);
236 explicit WatchWindow (Layout
* pParent
);
237 virtual ~WatchWindow() override
;
238 virtual void dispose() override
;
240 void AddWatch( const OUString
& rVName
);
241 void RemoveSelectedWatch();
242 void UpdateWatches(bool bBasicStopped
= false);
245 class StackWindow
: public DockingWindow
248 std::unique_ptr
<weld::Label
> m_xTitle
;
249 std::unique_ptr
<weld::TreeView
> m_xTreeListBox
;
252 virtual void Resize() override
;
253 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
256 explicit StackWindow (Layout
* pParent
);
257 virtual ~StackWindow() override
;
258 virtual void dispose() override
;
264 class ComplexEditorWindow final
: public vcl::Window
267 VclPtr
<BreakPointWindow
> aBrkWindow
;
268 VclPtr
<LineNumberWindow
> aLineNumberWindow
;
269 VclPtr
<EditorWindow
> aEdtWindow
;
270 VclPtr
<ScrollAdaptor
> aEWVScrollBar
;
271 VclPtr
<ScrollAdaptor
> aEWHScrollBar
;
273 virtual void DataChanged(DataChangedEvent
const & rDCEvt
) override
;
275 virtual void Resize() override
;
276 DECL_LINK(ScrollHdl
, weld::Scrollbar
&, void);
279 explicit ComplexEditorWindow( ModulWindow
* pParent
);
280 virtual ~ComplexEditorWindow() override
;
281 virtual void dispose() override
;
282 BreakPointWindow
& GetBrkWindow() { return *aBrkWindow
; }
283 LineNumberWindow
& GetLineNumberWindow() { return *aLineNumberWindow
; }
284 EditorWindow
& GetEdtWindow() { return *aEdtWindow
; }
285 ScrollAdaptor
& GetEWVScrollBar() { return *aEWVScrollBar
; }
286 ScrollAdaptor
& GetEWHScrollBar() { return *aEWHScrollBar
; }
288 void SetLineNumberDisplay(bool b
);
292 class ModulWindow
: public BaseWindow
295 ModulWindowLayout
& m_rLayout
;
296 StarBASICRef m_xBasic
;
298 VclPtr
<ComplexEditorWindow
> m_aXEditorWindow
;
299 BasicStatus m_aStatus
;
300 SbModuleRef m_xModule
;
302 OUString m_sWinColorScheme
;
304 void CheckCompileBasic();
307 sal_Int32
FormatAndPrint( Printer
* pPrinter
, sal_Int32 nPage
);
308 SbModuleRef
const & XModule();
310 virtual void Resize() override
;
311 virtual void GetFocus() override
;
312 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& ) override
;
313 virtual void DoInit() override
;
314 virtual void DoScroll(Scrollable
* pCurScrollBar
) override
;
317 ModulWindow( ModulWindowLayout
* pParent
, const ScriptDocument
& rDocument
, const OUString
& aLibName
, const OUString
& aName
, OUString aModule
);
319 virtual ~ModulWindow() override
;
320 virtual void dispose() override
;
322 virtual void ExecuteCommand (SfxRequest
& rReq
) override
;
323 virtual void ExecuteGlobal (SfxRequest
& rReq
) override
;
324 virtual void GetState( SfxItemSet
& ) override
;
325 virtual void StoreData() override
;
326 virtual void UpdateData() override
;
327 // return number of pages to be printed
328 virtual sal_Int32
countPages( Printer
* pPrinter
) override
;
330 virtual void printPage( sal_Int32 nPage
, Printer
* pPrinter
) override
;
331 virtual OUString
GetTitle() override
;
332 virtual EntryDescriptor
CreateEntryDescriptor() override
;
333 virtual bool AllowUndo() override
;
334 virtual void SetReadOnly (bool bReadOnly
) override
;
335 virtual bool IsReadOnly() override
;
337 StarBASIC
* GetBasic() { XModule(); return m_xBasic
.get(); }
339 SbModule
* GetSbModule() { return m_xModule
.get(); }
340 void SetSbModule( SbModule
* pModule
) { m_xModule
= pModule
; }
341 OUString
GetSbModuleName();
345 void BasicStepOver();
346 void BasicStepInto();
349 void BasicToggleBreakPoint();
350 void BasicToggleBreakPointEnabled();
351 void ManageBreakPoints();
352 void UpdateBreakPoint( const BreakPoint
& rBrk
);
353 void BasicAddWatch();
355 void BasicErrorHdl( StarBASIC
const * pBasic
);
356 BasicDebugFlags
BasicBreakHdl();
357 void AssertValidEditEngine();
360 void SaveBasicSource();
363 void EditMacro( const OUString
& rMacroName
);
365 void ToggleBreakPoint( sal_uInt16 nLine
);
367 BasicStatus
& GetBasicStatus() { return m_aStatus
; }
369 virtual bool IsModified () override
;
370 bool IsPasteAllowed ();
372 void ShowCursor( bool bOn
);
374 virtual SearchOptionFlags
GetSearchOptions() override
;
375 virtual sal_uInt16
StartSearchAndReplace (SvxSearchItem
const&, bool bFromStart
= false) override
;
377 EditorWindow
& GetEditorWindow() { return m_aXEditorWindow
->GetEdtWindow(); }
378 BreakPointWindow
& GetBreakPointWindow() { return m_aXEditorWindow
->GetBrkWindow(); }
379 LineNumberWindow
& GetLineNumberWindow() { return m_aXEditorWindow
->GetLineNumberWindow(); }
380 ScrollAdaptor
& GetEditVScrollBar() { return m_aXEditorWindow
->GetEWVScrollBar(); }
381 ScrollAdaptor
& GetEditHScrollBar() { return m_aXEditorWindow
->GetEWHScrollBar(); }
382 ExtTextEngine
* GetEditEngine() { return GetEditorWindow().GetEditEngine(); }
383 TextView
* GetEditView() { return GetEditorWindow().GetEditView(); }
384 BreakPointList
& GetBreakPoints() { return GetBreakPointWindow().GetBreakPoints(); }
385 ModulWindowLayout
& GetLayout () { return m_rLayout
; }
387 virtual void BasicStarted() override
;
388 virtual void BasicStopped() override
;
390 virtual SfxUndoManager
*
391 GetUndoManager() override
;
393 const OUString
& GetModule() const { return m_aModule
; }
394 void SetModule( const OUString
& aModule
) { m_aModule
= aModule
; }
396 virtual void Activating () override
;
397 virtual void Deactivating () override
;
399 virtual void OnNewDocument () override
;
400 virtual OUString
GetHid () const override
;
401 virtual SbxItemType
GetSbxType () const override
;
402 virtual bool HasActiveEditor () const override
;
404 void UpdateModule ();
405 const OUString
& GetEditorColorScheme() { return m_sWinColorScheme
; }
406 void SetEditorColorScheme(const OUString
& rColorScheme
);
409 class ModulWindowLayout
: public Layout
412 ModulWindowLayout (vcl::Window
* pParent
, ObjectCatalog
&);
413 virtual ~ModulWindowLayout() override
;
414 virtual void dispose() override
;
417 virtual void Activating (BaseWindow
&) override
;
418 virtual void Deactivating () override
;
419 virtual void GetState (SfxItemSet
&, unsigned nWhich
) override
;
420 virtual void UpdateDebug (bool bBasicStopped
) override
;
422 void BasicAddWatch (OUString
const&);
423 void BasicRemoveWatch ();
424 void ShowWatchWindow(bool bVisible
);
425 void ShowStackWindow(bool bVisible
);
426 bool IsWatchWindowVisible() { return aWatchWindow
->IsVisible(); }
427 bool IsStackWindowVisible() { return aStackWindow
->IsVisible(); }
428 Color
const & GetSyntaxBackgroundColor () const { return aSyntaxColors
.GetBackgroundColor(); }
429 Color
const & GetFontColor () const { return aSyntaxColors
.GetFontColor(); }
430 Color
const & GetSyntaxColor (TokenType eType
) const { return aSyntaxColors
.GetColor(eType
); }
431 const OUString
& GetActiveColorSchemeId() { return m_sColorSchemeId
; }
432 void ApplyColorSchemeToCurrentWindow(const OUString
& rSchemeId
);
436 virtual void Paint (vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
438 virtual void OnFirstSize (tools::Long nWidth
, tools::Long nHeight
) override
;
442 VclPtr
<ModulWindow
> pChild
;
444 VclPtr
<WatchWindow
> aWatchWindow
;
445 VclPtr
<StackWindow
> aStackWindow
;
446 ObjectCatalog
& rObjectCatalog
;
447 // Active color scheme ID
448 OUString m_sColorSchemeId
;
450 // SyntaxColors -- stores Basic syntax highlighting colors
451 class SyntaxColors
: public utl::ConfigurationListener
455 virtual ~SyntaxColors () override
;
457 void SetActiveEditor (EditorWindow
* pEditor_
) { pEditor
= pEditor_
; }
458 void SetActiveColorSchemeId(const OUString
& rColorSchemeId
) { m_sActiveSchemeId
= rColorSchemeId
; }
460 Color
const & GetBackgroundColor () const { return m_aBackgroundColor
; };
461 Color
const & GetFontColor () const { return m_aFontColor
; }
462 Color
const & GetColor(TokenType eType
) const { return aColors
[eType
]; }
463 void ApplyColorScheme(const OUString
& aSchemeId
, bool bFirst
);
466 virtual void ConfigurationChanged (utl::ConfigurationBroadcaster
*, ConfigurationHints
) override
;
469 Color m_aBackgroundColor
;
471 OUString m_sActiveSchemeId
;
472 // the color values (the indexes are TokenType, see comphelper/syntaxhighlight.hxx)
473 o3tl::enumarray
<TokenType
, Color
> aColors
;
475 svtools::ColorConfig aConfig
;
477 VclPtr
<EditorWindow
> pEditor
;
481 class CodeCompleteWindow final
: public InterimItemWindow
484 VclPtr
<EditorWindow
> pParent
; // parent window
485 TextSelection m_aTextSelection
;
486 std::unique_ptr
<weld::TreeView
> m_xListBox
;
488 /* a buffer to build up function name when typing
489 * a function name, used for showing/hiding listbox values
491 OUStringBuffer aFuncBuffer
;
493 void InsertSelectedEntry(); // insert the selected entry
494 void SetMatchingEntries(); // sets the visible entries based on aFuncBuffer variable
495 TextView
* GetParentEditView();
497 DECL_LINK(ImplDoubleClickHdl
, weld::TreeView
&, bool);
498 DECL_LINK(ImplSelectHdl
, weld::TreeView
&, void);
499 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
502 explicit CodeCompleteWindow( EditorWindow
* pPar
);
503 virtual ~CodeCompleteWindow() override
;
504 virtual void dispose() override
;
506 void InsertEntry( const OUString
& aStr
);
508 void SetTextSelection( const TextSelection
& aSel
);
509 const TextSelection
& GetTextSelection() const { return m_aTextSelection
;}
510 void ResizeAndPositionListBox();
511 void SelectFirstEntry(); //selects first entry in ListBox
514 * clears if typed anything, then hides
515 * the window, clear internal variables
518 void HideAndRestoreFocus();
520 bool HandleKeyInput(const KeyEvent
& rKeyEvt
);
523 class UnoTypeCodeCompletetor
526 css::uno::Reference
< css::reflection::XIdlClass
> xClass
;
529 bool CheckField( const OUString
& sFieldName
);
530 bool CheckMethod( const OUString
& sMethName
);
533 UnoTypeCodeCompletetor( const std::vector
< OUString
>& aVect
, const OUString
& sVarType
);
535 std::vector
< OUString
> GetXIdlClassMethods() const;
536 std::vector
< OUString
> GetXIdlClassFields() const;
538 bool CanCodeComplete() const { return bCanComplete
;}
541 } // namespace basctl
543 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */