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"
28 #include <basic/sbmod.hxx>
29 #include <basic/sbstar.hxx>
30 #include <vcl/InterimItemWindow.hxx>
31 #include <vcl/idle.hxx>
32 #include <vcl/weld.hxx>
34 #include <svtools/colorcfg.hxx>
35 #include <svtools/scrolladaptor.hxx>
36 #include <o3tl/enumarray.hxx>
37 #include <rtl/ustrbuf.hxx>
40 #include <string_view>
42 #include <vcl/textdata.hxx>
43 #include <basic/codecompletecache.hxx>
44 #include <com/sun/star/reflection/XIdlClass.hpp>
45 #include <comphelper/syntaxhighlight.hxx>
50 namespace com::sun::star::beans
{ class XMultiPropertySet
; }
56 class CodeCompleteWindow
;
57 class ModulWindowLayout
;
59 // #108672 Helper functions to get/set text in TextEngine
60 // using the stream interface (get/setText() only supports
61 // tools Strings limited to 64K).
62 // defined in baside2b.cxx
63 OUString
getTextEngineText (ExtTextEngine
&);
64 void setTextEngineText (ExtTextEngine
&, std::u16string_view
);
66 class EditorWindow final
: public vcl::Window
, public SfxListener
68 friend class CodeCompleteWindow
;
69 friend class EditorWindowUIObject
;
71 class ChangesListener
;
73 std::unique_ptr
<TextView
> pEditView
;
74 std::unique_ptr
<ExtTextEngine
> pEditEngine
;
75 ModulWindow
& rModulWindow
;
77 rtl::Reference
< ChangesListener
> listener_
;
79 css::uno::Reference
< css::beans::XMultiPropertySet
>
82 tools::Long nCurTextWidth
;
84 ImplSVEvent
* m_nSetSourceInBasicId
;
86 SyntaxHighlighter aHighlighter
;
88 std::set
<sal_uInt16
> aSyntaxLineTable
;
89 DECL_LINK(SyntaxTimerHdl
, Timer
*, void);
90 DECL_LINK(SetSourceInBasicHdl
, void*, void);
94 std::unique_ptr
<ProgressInfo
> pProgress
;
96 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
98 void ImpDoHighlight( sal_uInt32 nLineOff
);
100 sal_uInt16 nCurrentZoomLevel
;
103 bool bDoSyntaxHighlight
;
104 bool bDelayHighlight
;
106 virtual css::uno::Reference
< css::awt::XVclWindowPeer
> GetComponentInterface(bool bCreate
= true) override
;
107 CodeCompleteDataCache aCodeCompleteCache
;
108 VclPtr
<CodeCompleteWindow
> pCodeCompleteWnd
;
109 OUString
GetActualSubName( sal_uInt32 nLine
); // gets the actual subroutine name according to line number
110 void SetupAndShowCodeCompleteWnd(const std::vector
< OUString
>& aEntryVect
, TextSelection aSel
);
111 void HandleAutoCorrect();
112 void HandleAutoCloseParen();
113 void HandleAutoCloseDoubleQuotes();
114 void HandleCodeCompletion();
115 void HandleProcedureCompletion();
116 TextSelection
GetLastHighlightPortionTextSelection() const;
118 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& ) override
;
119 virtual void Resize() override
;
120 virtual void KeyInput( const KeyEvent
& rKeyEvt
) override
;
121 virtual void MouseMove( const MouseEvent
& rMEvt
) override
;
122 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) override
;
123 virtual void MouseButtonUp( const MouseEvent
& rMEvt
) override
;
124 virtual void Command( const CommandEvent
& rCEvt
) override
;
125 virtual void LoseFocus() override
;
126 virtual void RequestHelp( const HelpEvent
& rHEvt
) override
;
128 void DoSyntaxHighlight( sal_uInt32 nPara
);
129 OUString
GetWordAtCursor();
133 EditorWindow (vcl::Window
* pParent
, ModulWindow
*);
134 virtual ~EditorWindow() override
;
135 virtual void dispose() override
;
137 ExtTextEngine
* GetEditEngine() const { return pEditEngine
.get(); }
138 TextView
* GetEditView() const { return pEditView
.get(); }
140 void CreateProgress( const OUString
& rText
, sal_uInt32 nRange
);
141 void DestroyProgress();
143 void ParagraphInsertedDeleted( sal_uInt32 nNewPara
, bool bInserted
);
144 void DoDelayedSyntaxHighlight( sal_uInt32 nPara
);
146 void CreateEditEngine();
147 void SetScrollBarRanges();
148 void InitScrollBars();
150 void ForceSyntaxTimeout();
151 void SetSourceInBasic();
153 bool CanModify() { return ImpCanModify(); }
155 void ChangeFontColor( Color aColor
);
156 void UpdateSyntaxHighlighting ();
158 void SetEditorZoomLevel(sal_uInt16 nNewZoomLevel
);
159 sal_uInt16
GetCurrentZoom() { return nCurrentZoomLevel
; }
161 bool GetProcedureName(std::u16string_view rLine
, OUString
& rProcType
, OUString
& rProcName
) const;
163 FactoryFunction
GetUITestFactory() const override
;
166 class BreakPointWindow final
: public vcl::Window
168 ModulWindow
& rModulWindow
;
169 tools::Long nCurYOffset
;
170 sal_uInt16 nMarkerPos
;
171 BreakPointList aBreakPointList
;
174 virtual void DataChanged(DataChangedEvent
const & rDCEvt
) override
;
176 void setBackgroundColor(Color aColor
);
178 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&) override
;
179 BreakPoint
* FindBreakPoint( const Point
& rMousePos
);
180 void ShowMarker(vcl::RenderContext
& rRenderContext
);
181 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) override
;
182 virtual void Command( const CommandEvent
& rCEvt
) override
;
187 BreakPointWindow (vcl::Window
* pParent
, ModulWindow
*);
189 void SetMarkerPos( sal_uInt16 nLine
, bool bErrorMarker
= false );
192 void DoScroll( tools::Long nVertScroll
);
193 tools::Long
& GetCurYOffset() { return nCurYOffset
; }
194 BreakPointList
& GetBreakPoints() { return aBreakPointList
; }
197 class WatchWindow final
: public DockingWindow
200 std::unique_ptr
<weld::Container
> m_xTitleArea
;
201 std::unique_ptr
<weld::Label
> m_xTitle
;
202 std::unique_ptr
<weld::Entry
> m_xEdit
;
203 std::unique_ptr
<weld::Button
> m_xRemoveWatchButton
;
204 std::unique_ptr
<weld::TreeView
> m_xTreeListBox
;
206 ImplSVEvent
* m_nUpdateWatchesId
;
207 OUString aEditingRes
;
209 virtual void Resize() override
;
210 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
212 SbxBase
* ImplGetSBXForEntry(const weld::TreeIter
& rEntry
, bool& rbArrayElement
);
214 void implEnableChildren(const weld::TreeIter
& rEntry
, bool bEnable
);
216 DECL_STATIC_LINK(WatchWindow
, ButtonHdl
, weld::Button
&, void);
217 DECL_LINK(TreeListHdl
, weld::TreeView
&, void);
218 DECL_LINK(RequestingChildrenHdl
, const weld::TreeIter
&, bool);
219 DECL_LINK(ActivateHdl
, weld::Entry
&, bool);
220 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
221 DECL_LINK(EditingEntryHdl
, const weld::TreeIter
&, bool);
222 typedef std::pair
<const weld::TreeIter
&, OUString
> IterString
;
223 DECL_LINK(EditedEntryHdl
, const IterString
&, bool);
224 DECL_LINK(ExecuteUpdateWatches
, void*, void);
227 explicit WatchWindow (Layout
* pParent
);
228 virtual ~WatchWindow() override
;
229 virtual void dispose() override
;
231 void AddWatch( const OUString
& rVName
);
232 void RemoveSelectedWatch();
233 void UpdateWatches(bool bBasicStopped
= false);
236 class StackWindow
: public DockingWindow
239 std::unique_ptr
<weld::Label
> m_xTitle
;
240 std::unique_ptr
<weld::TreeView
> m_xTreeListBox
;
243 virtual void Resize() override
;
244 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
247 explicit StackWindow (Layout
* pParent
);
248 virtual ~StackWindow() override
;
249 virtual void dispose() override
;
255 class ComplexEditorWindow final
: public vcl::Window
258 VclPtr
<BreakPointWindow
> aBrkWindow
;
259 VclPtr
<LineNumberWindow
> aLineNumberWindow
;
260 VclPtr
<EditorWindow
> aEdtWindow
;
261 VclPtr
<ScrollAdaptor
> aEWVScrollBar
;
262 VclPtr
<ScrollAdaptor
> aEWHScrollBar
;
264 virtual void DataChanged(DataChangedEvent
const & rDCEvt
) override
;
266 virtual void Resize() override
;
267 DECL_LINK(ScrollHdl
, weld::Scrollbar
&, void);
270 explicit ComplexEditorWindow( ModulWindow
* pParent
);
271 virtual ~ComplexEditorWindow() override
;
272 virtual void dispose() override
;
273 BreakPointWindow
& GetBrkWindow() { return *aBrkWindow
; }
274 LineNumberWindow
& GetLineNumberWindow() { return *aLineNumberWindow
; }
275 EditorWindow
& GetEdtWindow() { return *aEdtWindow
; }
276 ScrollAdaptor
& GetEWVScrollBar() { return *aEWVScrollBar
; }
277 ScrollAdaptor
& GetEWHScrollBar() { return *aEWHScrollBar
; }
279 void SetLineNumberDisplay(bool b
);
283 class ModulWindow
: public BaseWindow
286 ModulWindowLayout
& m_rLayout
;
287 StarBASICRef m_xBasic
;
289 VclPtr
<ComplexEditorWindow
> m_aXEditorWindow
;
290 BasicStatus m_aStatus
;
291 SbModuleRef m_xModule
;
294 void CheckCompileBasic();
297 sal_Int32
FormatAndPrint( Printer
* pPrinter
, sal_Int32 nPage
);
298 SbModuleRef
const & XModule();
300 virtual void Resize() override
;
301 virtual void GetFocus() override
;
302 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& ) override
;
303 virtual void DoInit() override
;
304 virtual void DoScroll(Scrollable
* pCurScrollBar
) override
;
307 ModulWindow( ModulWindowLayout
* pParent
, const ScriptDocument
& rDocument
, const OUString
& aLibName
, const OUString
& aName
, OUString aModule
);
309 virtual ~ModulWindow() override
;
310 virtual void dispose() override
;
312 virtual void ExecuteCommand (SfxRequest
& rReq
) override
;
313 virtual void ExecuteGlobal (SfxRequest
& rReq
) override
;
314 virtual void GetState( SfxItemSet
& ) override
;
315 virtual void StoreData() override
;
316 virtual void UpdateData() override
;
317 // return number of pages to be printed
318 virtual sal_Int32
countPages( Printer
* pPrinter
) override
;
320 virtual void printPage( sal_Int32 nPage
, Printer
* pPrinter
) override
;
321 virtual OUString
GetTitle() override
;
322 virtual EntryDescriptor
CreateEntryDescriptor() override
;
323 virtual bool AllowUndo() override
;
324 virtual void SetReadOnly (bool bReadOnly
) override
;
325 virtual bool IsReadOnly() override
;
327 StarBASIC
* GetBasic() { XModule(); return m_xBasic
.get(); }
329 SbModule
* GetSbModule() { return m_xModule
.get(); }
330 void SetSbModule( SbModule
* pModule
) { m_xModule
= pModule
; }
331 OUString
GetSbModuleName();
335 void BasicStepOver();
336 void BasicStepInto();
339 void BasicToggleBreakPoint();
340 void BasicToggleBreakPointEnabled();
341 void ManageBreakPoints();
342 void UpdateBreakPoint( const BreakPoint
& rBrk
);
343 void BasicAddWatch();
345 void BasicErrorHdl( StarBASIC
const * pBasic
);
346 BasicDebugFlags
BasicBreakHdl();
347 void AssertValidEditEngine();
350 void SaveBasicSource();
353 void EditMacro( const OUString
& rMacroName
);
355 void ToggleBreakPoint( sal_uInt16 nLine
);
357 BasicStatus
& GetBasicStatus() { return m_aStatus
; }
359 virtual bool IsModified () override
;
360 bool IsPasteAllowed ();
362 void ShowCursor( bool bOn
);
364 virtual SearchOptionFlags
GetSearchOptions() override
;
365 virtual sal_uInt16
StartSearchAndReplace (SvxSearchItem
const&, bool bFromStart
= false) override
;
367 EditorWindow
& GetEditorWindow() { return m_aXEditorWindow
->GetEdtWindow(); }
368 BreakPointWindow
& GetBreakPointWindow() { return m_aXEditorWindow
->GetBrkWindow(); }
369 LineNumberWindow
& GetLineNumberWindow() { return m_aXEditorWindow
->GetLineNumberWindow(); }
370 ScrollAdaptor
& GetEditVScrollBar() { return m_aXEditorWindow
->GetEWVScrollBar(); }
371 ScrollAdaptor
& GetEditHScrollBar() { return m_aXEditorWindow
->GetEWHScrollBar(); }
372 ExtTextEngine
* GetEditEngine() { return GetEditorWindow().GetEditEngine(); }
373 TextView
* GetEditView() { return GetEditorWindow().GetEditView(); }
374 BreakPointList
& GetBreakPoints() { return GetBreakPointWindow().GetBreakPoints(); }
375 ModulWindowLayout
& GetLayout () { return m_rLayout
; }
377 virtual void BasicStarted() override
;
378 virtual void BasicStopped() override
;
380 virtual SfxUndoManager
*
381 GetUndoManager() override
;
383 const OUString
& GetModule() const { return m_aModule
; }
384 void SetModule( const OUString
& aModule
) { m_aModule
= aModule
; }
386 virtual void Activating () override
;
387 virtual void Deactivating () override
;
389 virtual void OnNewDocument () override
;
390 virtual OUString
GetHid () const override
;
391 virtual ItemType
GetType () const override
;
392 virtual bool HasActiveEditor () const override
;
394 void UpdateModule ();
397 class ModulWindowLayout
: public Layout
400 ModulWindowLayout (vcl::Window
* pParent
, ObjectCatalog
&);
401 virtual ~ModulWindowLayout() override
;
402 virtual void dispose() override
;
405 virtual void Activating (BaseWindow
&) override
;
406 virtual void Deactivating () override
;
407 virtual void GetState (SfxItemSet
&, unsigned nWhich
) override
;
408 virtual void UpdateDebug (bool bBasicStopped
) override
;
410 void BasicAddWatch (OUString
const&);
411 void BasicRemoveWatch ();
412 void ShowWatchWindow(bool bVisible
);
413 void ShowStackWindow(bool bVisible
);
414 bool IsWatchWindowVisible() { return aWatchWindow
->IsVisible(); }
415 bool IsStackWindowVisible() { return aStackWindow
->IsVisible(); }
416 Color
const & GetSyntaxBackgroundColor () const { return aSyntaxColors
.GetBackgroundColor(); }
417 Color
const & GetFontColor () const { return aSyntaxColors
.GetFontColor(); }
418 Color
const & GetSyntaxColor (TokenType eType
) const { return aSyntaxColors
.GetColor(eType
); }
422 virtual void Paint (vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
424 virtual void OnFirstSize (tools::Long nWidth
, tools::Long nHeight
) override
;
428 VclPtr
<ModulWindow
> pChild
;
430 VclPtr
<WatchWindow
> aWatchWindow
;
431 VclPtr
<StackWindow
> aStackWindow
;
432 ObjectCatalog
& rObjectCatalog
;
434 // SyntaxColors -- stores Basic syntax highlighting colors
435 class SyntaxColors
: public utl::ConfigurationListener
439 virtual ~SyntaxColors () override
;
441 void SetActiveEditor (EditorWindow
* pEditor_
) { pEditor
= pEditor_
; }
443 Color
const & GetBackgroundColor () const { return m_aBackgroundColor
; };
444 Color
const & GetFontColor () const { return m_aFontColor
; }
445 Color
const & GetColor(TokenType eType
) const { return aColors
[eType
]; }
448 virtual void ConfigurationChanged (utl::ConfigurationBroadcaster
*, ConfigurationHints
) override
;
449 void NewConfig (bool bFirst
);
452 Color m_aBackgroundColor
;
454 // the color values (the indexes are TokenType, see comphelper/syntaxhighlight.hxx)
455 o3tl::enumarray
<TokenType
, Color
> aColors
;
457 svtools::ColorConfig aConfig
;
459 VclPtr
<EditorWindow
> pEditor
;
464 class CodeCompleteWindow final
: public InterimItemWindow
467 VclPtr
<EditorWindow
> pParent
; // parent window
468 TextSelection m_aTextSelection
;
469 std::unique_ptr
<weld::TreeView
> m_xListBox
;
471 /* a buffer to build up function name when typing
472 * a function name, used for showing/hiding listbox values
474 OUStringBuffer aFuncBuffer
;
476 void InsertSelectedEntry(); // insert the selected entry
477 void SetMatchingEntries(); // sets the visible entries based on aFuncBuffer variable
478 TextView
* GetParentEditView();
480 DECL_LINK(ImplDoubleClickHdl
, weld::TreeView
&, bool);
481 DECL_LINK(ImplSelectHdl
, weld::TreeView
&, void);
482 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
485 explicit CodeCompleteWindow( EditorWindow
* pPar
);
486 virtual ~CodeCompleteWindow() override
;
487 virtual void dispose() override
;
489 void InsertEntry( const OUString
& aStr
);
491 void SetTextSelection( const TextSelection
& aSel
);
492 const TextSelection
& GetTextSelection() const { return m_aTextSelection
;}
493 void ResizeAndPositionListBox();
494 void SelectFirstEntry(); //selects first entry in ListBox
497 * clears if typed anything, then hides
498 * the window, clear internal variables
501 void HideAndRestoreFocus();
503 bool HandleKeyInput(const KeyEvent
& rKeyEvt
);
506 class UnoTypeCodeCompletetor
509 css::uno::Reference
< css::reflection::XIdlClass
> xClass
;
512 bool CheckField( const OUString
& sFieldName
);
513 bool CheckMethod( const OUString
& sMethName
);
516 UnoTypeCodeCompletetor( const std::vector
< OUString
>& aVect
, const OUString
& sVarType
);
518 std::vector
< OUString
> GetXIdlClassMethods() const;
519 std::vector
< OUString
> GetXIdlClassFields() const;
521 bool CanCodeComplete() const { return bCanComplete
;}
524 } // namespace basctl
526 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */