Bump version to 24.04.3.4
[LibreOffice.git] / basctl / source / basicide / baside2.hxx
blob116dab2bb9059eee8bcd06644e154b60fa2d37c0
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 #pragma once
22 #include <memory>
23 #include <mutex>
24 #include <layout.hxx>
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>
39 #include <set>
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>
47 class ExtTextEngine;
48 class TextView;
49 class SvxSearchItem;
50 namespace com::sun::star::beans { class XMultiPropertySet; }
52 namespace basctl
55 class ObjectCatalog;
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;
70 private:
71 class ChangesListener;
73 std::unique_ptr<TextView> pEditView;
74 std::unique_ptr<ExtTextEngine> pEditEngine;
75 ModulWindow& rModulWindow;
77 rtl::Reference< ChangesListener > listener_;
78 std::mutex mutex_;
79 css::uno::Reference< css::beans::XMultiPropertySet >
80 notifier_;
82 tools::Long nCurTextWidth;
84 ImplSVEvent* m_nSetSourceInBasicId;
86 SyntaxHighlighter aHighlighter;
87 Idle aSyntaxIdle;
88 std::set<sal_uInt16> aSyntaxLineTable;
89 DECL_LINK(SyntaxTimerHdl, Timer *, void);
90 DECL_LINK(SetSourceInBasicHdl, void*, void);
92 // progress bar
93 class ProgressInfo;
94 std::unique_ptr<ProgressInfo> pProgress;
96 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
98 void ImpDoHighlight( sal_uInt32 nLineOff );
99 void ImplSetFont();
100 sal_uInt16 nCurrentZoomLevel;
102 bool bHighlighting;
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();
130 bool ImpCanModify();
132 public:
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;
172 bool bErrorMarker;
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;
184 bool SyncYOffset();
186 public:
187 BreakPointWindow (vcl::Window* pParent, ModulWindow*);
189 void SetMarkerPos( sal_uInt16 nLine, bool bErrorMarker = false );
190 void SetNoMarker ();
192 void DoScroll( tools::Long nVertScroll );
193 tools::Long& GetCurYOffset() { return nCurYOffset; }
194 BreakPointList& GetBreakPoints() { return aBreakPointList; }
197 class WatchWindow final : public DockingWindow
199 private:
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);
226 public:
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
238 private:
239 std::unique_ptr<weld::Label> m_xTitle;
240 std::unique_ptr<weld::TreeView> m_xTreeListBox;
242 protected:
243 virtual void Resize() override;
244 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
246 public:
247 explicit StackWindow (Layout* pParent);
248 virtual ~StackWindow() override;
249 virtual void dispose() override;
251 void UpdateCalls();
255 class ComplexEditorWindow final : public vcl::Window
257 private:
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);
269 public:
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
285 private:
286 ModulWindowLayout& m_rLayout;
287 StarBASICRef m_xBasic;
288 short m_nValid;
289 VclPtr<ComplexEditorWindow> m_aXEditorWindow;
290 BasicStatus m_aStatus;
291 SbModuleRef m_xModule;
292 OUString m_aModule;
294 void CheckCompileBasic();
295 void BasicExecute();
297 sal_Int32 FormatAndPrint( Printer* pPrinter, sal_Int32 nPage );
298 SbModuleRef const & XModule();
299 protected:
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;
306 public:
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;
319 // print page
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();
333 void CompileBasic();
334 void BasicRun();
335 void BasicStepOver();
336 void BasicStepInto();
337 void BasicStepOut();
338 void BasicStop();
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();
349 void LoadBasic();
350 void SaveBasicSource();
351 void ImportDialog();
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
399 public:
400 ModulWindowLayout (vcl::Window* pParent, ObjectCatalog&);
401 virtual ~ModulWindowLayout() override;
402 virtual void dispose() override;
403 public:
404 // Layout:
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;
409 public:
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); }
420 protected:
421 // Window:
422 virtual void Paint (vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
423 // Layout:
424 virtual void OnFirstSize (tools::Long nWidth, tools::Long nHeight) override;
426 private:
427 // main child window
428 VclPtr<ModulWindow> pChild;
429 // dockable windows
430 VclPtr<WatchWindow> aWatchWindow;
431 VclPtr<StackWindow> aStackWindow;
432 ObjectCatalog& rObjectCatalog;
434 // SyntaxColors -- stores Basic syntax highlighting colors
435 class SyntaxColors : public utl::ConfigurationListener
437 public:
438 SyntaxColors ();
439 virtual ~SyntaxColors () override;
440 public:
441 void SetActiveEditor (EditorWindow* pEditor_) { pEditor = pEditor_; }
442 public:
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]; }
447 private:
448 virtual void ConfigurationChanged (utl::ConfigurationBroadcaster*, ConfigurationHints) override;
449 void NewConfig (bool bFirst);
451 private:
452 Color m_aBackgroundColor;
453 Color m_aFontColor;
454 // the color values (the indexes are TokenType, see comphelper/syntaxhighlight.hxx)
455 o3tl::enumarray<TokenType, Color> aColors;
456 // the configuration
457 svtools::ColorConfig aConfig;
458 // the active editor
459 VclPtr<EditorWindow> pEditor;
461 } aSyntaxColors;
464 class CodeCompleteWindow final : public InterimItemWindow
466 private:
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
473 * */
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);
484 public:
485 explicit CodeCompleteWindow( EditorWindow* pPar );
486 virtual ~CodeCompleteWindow() override;
487 virtual void dispose() override;
489 void InsertEntry( const OUString& aStr );
490 void ClearListBox();
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
499 * */
500 void ClearAndHide();
501 void HideAndRestoreFocus();
503 bool HandleKeyInput(const KeyEvent& rKeyEvt);
506 class UnoTypeCodeCompletetor
508 private:
509 css::uno::Reference< css::reflection::XIdlClass > xClass;
510 bool bCanComplete;
512 bool CheckField( const OUString& sFieldName );
513 bool CheckMethod( const OUString& sMethName );
515 public:
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: */