tdf#39468 translate German comments in ipwin.cxx
[LibreOffice.git] / basctl / source / basicide / baside2.hxx
blob2d0bad211007bd63ae9ca1c3127fa68b7b4f72f6
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"
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>
40 #include <set>
41 #include <map>
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>
49 class ExtTextEngine;
50 class TextView;
51 class SvxSearchItem;
52 namespace com::sun::star::beans { class XMultiPropertySet; }
54 namespace basctl
57 class ObjectCatalog;
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;
72 private:
73 class ChangesListener;
75 std::unique_ptr<TextView> pEditView;
76 std::unique_ptr<ExtTextEngine> pEditEngine;
77 ModulWindow& rModulWindow;
79 rtl::Reference< ChangesListener > listener_;
80 std::mutex mutex_;
81 css::uno::Reference< css::beans::XMultiPropertySet >
82 notifier_;
84 tools::Long nCurTextWidth;
86 ImplSVEvent* m_nSetSourceInBasicId;
88 SyntaxHighlighter aHighlighter;
89 Idle aSyntaxIdle;
90 std::set<sal_uInt16> aSyntaxLineTable;
91 DECL_LINK(SyntaxTimerHdl, Timer *, void);
92 DECL_LINK(SetSourceInBasicHdl, void*, void);
94 // progress bar
95 class ProgressInfo;
96 std::unique_ptr<ProgressInfo> pProgress;
98 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
100 void ImpDoHighlight( sal_uInt32 nLineOff );
101 void ImplSetFont();
102 sal_uInt16 nCurrentZoomLevel;
104 bool bHighlighting;
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();
137 bool ImpCanModify();
138 void HighlightCurrentLine(vcl::RenderContext& rRenderContext);
140 public:
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;
181 bool bErrorMarker;
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;
193 bool SyncYOffset();
195 public:
196 BreakPointWindow (vcl::Window* pParent, ModulWindow*);
198 void SetMarkerPos( sal_uInt16 nLine, bool bErrorMarker = false );
199 void SetNoMarker ();
201 void DoScroll( tools::Long nVertScroll );
202 tools::Long& GetCurYOffset() { return nCurYOffset; }
203 BreakPointList& GetBreakPoints() { return aBreakPointList; }
206 class WatchWindow final : public DockingWindow
208 private:
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);
235 public:
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
247 private:
248 std::unique_ptr<weld::Label> m_xTitle;
249 std::unique_ptr<weld::TreeView> m_xTreeListBox;
251 protected:
252 virtual void Resize() override;
253 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
255 public:
256 explicit StackWindow (Layout* pParent);
257 virtual ~StackWindow() override;
258 virtual void dispose() override;
260 void UpdateCalls();
264 class ComplexEditorWindow final : public vcl::Window
266 private:
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);
278 public:
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
294 private:
295 ModulWindowLayout& m_rLayout;
296 StarBASICRef m_xBasic;
297 short m_nValid;
298 VclPtr<ComplexEditorWindow> m_aXEditorWindow;
299 BasicStatus m_aStatus;
300 SbModuleRef m_xModule;
301 OUString m_aModule;
302 OUString m_sWinColorScheme;
304 void CheckCompileBasic();
305 void BasicExecute();
307 sal_Int32 FormatAndPrint( Printer* pPrinter, sal_Int32 nPage );
308 SbModuleRef const & XModule();
309 protected:
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;
316 public:
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;
329 // print page
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();
343 void CompileBasic();
344 void BasicRun();
345 void BasicStepOver();
346 void BasicStepInto();
347 void BasicStepOut();
348 void BasicStop();
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();
359 void LoadBasic();
360 void SaveBasicSource();
361 void ImportDialog();
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
411 public:
412 ModulWindowLayout (vcl::Window* pParent, ObjectCatalog&);
413 virtual ~ModulWindowLayout() override;
414 virtual void dispose() override;
415 public:
416 // Layout:
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;
421 public:
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);
434 protected:
435 // Window:
436 virtual void Paint (vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
437 // Layout:
438 virtual void OnFirstSize (tools::Long nWidth, tools::Long nHeight) override;
440 private:
441 // main child window
442 VclPtr<ModulWindow> pChild;
443 // dockable windows
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
453 public:
454 SyntaxColors ();
455 virtual ~SyntaxColors () override;
456 public:
457 void SetActiveEditor (EditorWindow* pEditor_) { pEditor = pEditor_; }
458 void SetActiveColorSchemeId(const OUString& rColorSchemeId) { m_sActiveSchemeId = rColorSchemeId; }
459 public:
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);
465 private:
466 virtual void ConfigurationChanged (utl::ConfigurationBroadcaster*, ConfigurationHints) override;
468 private:
469 Color m_aBackgroundColor;
470 Color m_aFontColor;
471 OUString m_sActiveSchemeId;
472 // the color values (the indexes are TokenType, see comphelper/syntaxhighlight.hxx)
473 o3tl::enumarray<TokenType, Color> aColors;
474 // the configuration
475 svtools::ColorConfig aConfig;
476 // the active editor
477 VclPtr<EditorWindow> pEditor;
478 } aSyntaxColors;
481 class CodeCompleteWindow final : public InterimItemWindow
483 private:
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
490 * */
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);
501 public:
502 explicit CodeCompleteWindow( EditorWindow* pPar );
503 virtual ~CodeCompleteWindow() override;
504 virtual void dispose() override;
506 void InsertEntry( const OUString& aStr );
507 void ClearListBox();
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
516 * */
517 void ClearAndHide();
518 void HideAndRestoreFocus();
520 bool HandleKeyInput(const KeyEvent& rKeyEvt);
523 class UnoTypeCodeCompletetor
525 private:
526 css::uno::Reference< css::reflection::XIdlClass > xClass;
527 bool bCanComplete;
529 bool CheckField( const OUString& sFieldName );
530 bool CheckMethod( const OUString& sMethName );
532 public:
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: */