Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / basctl / source / basicide / baside2.hxx
blob05b8bda07041a81fdcc88fd64bace0624fc7fc31
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 #ifndef INCLUDED_BASCTL_SOURCE_BASICIDE_BASIDE2_HXX
21 #define INCLUDED_BASCTL_SOURCE_BASICIDE_BASIDE2_HXX
23 #include <memory>
24 #include <layout.hxx>
25 #include "bastype3.hxx"
26 #include <basidesh.hxx>
27 #include "breakpoint.hxx"
28 #include "linenumberwindow.hxx"
30 #include <svtools/svtabbx.hxx>
31 #include <svtools/headbar.hxx>
33 #include <vcl/button.hxx>
34 #include <basic/sbmod.hxx>
35 #include <vcl/lstbox.hxx>
36 #include <vcl/idle.hxx>
38 #include <sfx2/progress.hxx>
39 #include <o3tl/enumarray.hxx>
41 #include <set>
43 #include <vcl/textdata.hxx>
44 #include <basic/codecompletecache.hxx>
45 #include <com/sun/star/reflection/XIdlClass.hpp>
46 #include <comphelper/syntaxhighlight.hxx>
47 #include <com/sun/star/reflection/XIdlReflection.hpp>
49 class ExtTextEngine;
50 class TextView;
51 class SvxSearchItem;
52 namespace com { namespace sun { namespace star { namespace beans {
53 class XMultiPropertySet;
54 } } } }
56 namespace basctl
59 class ObjectCatalog;
60 class CodeCompleteListBox;
61 class CodeCompleteWindow;
63 // #108672 Helper functions to get/set text in TextEngine
64 // using the stream interface (get/setText() only supports
65 // tools Strings limited to 64K).
66 // defined in baside2b.cxx
67 OUString getTextEngineText (ExtTextEngine&);
68 void setTextEngineText (ExtTextEngine&, OUString const&);
70 class EditorWindow final : public vcl::Window, public SfxListener
72 friend class CodeCompleteListBox;
73 private:
74 class ChangesListener;
76 std::unique_ptr<TextView> pEditView;
77 std::unique_ptr<ExtTextEngine> pEditEngine;
78 ModulWindow& rModulWindow;
80 rtl::Reference< ChangesListener > listener_;
81 osl::Mutex mutex_;
82 css::uno::Reference< css::beans::XMultiPropertySet >
83 notifier_;
85 long nCurTextWidth;
87 SyntaxHighlighter aHighlighter;
88 Idle aSyntaxIdle;
89 std::set<sal_uInt16> aSyntaxLineTable;
90 DECL_LINK(SyntaxTimerHdl, Timer *, 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_uLong nLineOff );
99 void ImplSetFont();
101 bool bHighlighting;
102 bool bDoSyntaxHighlight;
103 bool bDelayHighlight;
105 virtual css::uno::Reference< css::awt::XWindowPeer > GetComponentInterface(bool bCreate = true) override;
106 CodeCompleteDataCache aCodeCompleteCache;
107 VclPtr<CodeCompleteWindow> pCodeCompleteWnd;
108 OUString GetActualSubName( sal_uLong nLine ); // gets the actual subroutine name according to line number
109 void SetupAndShowCodeCompleteWnd(const std::vector< OUString >& aEntryVect, TextSelection aSel );
110 void HandleAutoCorrect();
111 void HandleAutoCloseParen();
112 void HandleAutoCloseDoubleQuotes();
113 void HandleCodeCompletion();
114 void HandleProcedureCompletion();
115 TextSelection GetLastHighlightPortionTextSelection();
117 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) override;
118 virtual void Resize() override;
119 virtual void KeyInput( const KeyEvent& rKeyEvt ) override;
120 virtual void MouseMove( const MouseEvent& rMEvt ) override;
121 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
122 virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
123 virtual void Command( const CommandEvent& rCEvt ) override;
124 virtual void LoseFocus() override;
125 virtual void RequestHelp( const HelpEvent& rHEvt ) override;
127 void DoSyntaxHighlight( sal_uLong nPara );
128 OUString GetWordAtCursor();
129 bool ImpCanModify();
131 public:
132 EditorWindow (vcl::Window* pParent, ModulWindow*);
133 virtual ~EditorWindow() override;
134 virtual void dispose() override;
136 ExtTextEngine* GetEditEngine() const { return pEditEngine.get(); }
137 TextView* GetEditView() const { return pEditView.get(); }
139 void CreateProgress( const OUString& rText, sal_uInt32 nRange );
140 void DestroyProgress();
142 void ParagraphInsertedDeleted( sal_uLong nNewPara, bool bInserted );
143 void DoDelayedSyntaxHighlight( sal_uLong nPara );
145 void CreateEditEngine();
146 void SetScrollBarRanges();
147 void InitScrollBars();
149 void ForceSyntaxTimeout();
150 void SetSourceInBasic();
152 bool CanModify() { return ImpCanModify(); }
154 void ChangeFontColor( Color aColor );
155 void UpdateSyntaxHighlighting ();
157 bool GetProcedureName(OUString const & rLine, OUString& rProcType, OUString& rProcName) const;
161 class BreakPointWindow final : public vcl::Window
163 ModulWindow& rModulWindow;
164 long nCurYOffset;
165 sal_uInt16 nMarkerPos;
166 BreakPointList aBreakPointList;
167 bool bErrorMarker;
168 std::unique_ptr<VclBuilder> mpUIBuilder;
170 virtual void DataChanged(DataChangedEvent const & rDCEvt) override;
172 void setBackgroundColor(Color aColor);
174 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override;
175 BreakPoint* FindBreakPoint( const Point& rMousePos );
176 void ShowMarker(vcl::RenderContext& rRenderContext);
177 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
178 virtual void Command( const CommandEvent& rCEvt ) override;
180 bool SyncYOffset();
182 public:
183 BreakPointWindow (vcl::Window* pParent, ModulWindow*);
184 virtual void dispose() override;
186 void SetMarkerPos( sal_uInt16 nLine, bool bErrorMarker = false );
187 void SetNoMarker ();
189 void DoScroll( long nVertScroll );
190 long& GetCurYOffset() { return nCurYOffset; }
191 BreakPointList& GetBreakPoints() { return aBreakPointList; }
195 class WatchTreeListBox final : public SvHeaderTabListBox
197 OUString aEditingRes;
199 virtual bool EditingEntry( SvTreeListEntry* pEntry, Selection& rSel ) override;
200 virtual bool EditedEntry( SvTreeListEntry* pEntry, const OUString& rNewText ) override;
202 bool ImplBasicEntryEdited( SvTreeListEntry* pEntry, const OUString& rResult );
203 SbxBase* ImplGetSBXForEntry( SvTreeListEntry* pEntry, bool& rbArrayElement );
205 public:
206 WatchTreeListBox( vcl::Window* pParent, WinBits nWinBits );
207 virtual ~WatchTreeListBox() override;
208 virtual void dispose() override;
210 void RequestingChildren( SvTreeListEntry * pParent ) override;
211 void UpdateWatches( bool bBasicStopped = false );
213 using SvTabListBox::SetTabs;
214 virtual void SetTabs() override;
218 class WatchWindow final : public DockingWindow
220 OUString aWatchStr;
221 VclPtr<ExtendedEdit> aXEdit;
222 VclPtr<ImageButton> aRemoveWatchButton;
223 VclPtr<WatchTreeListBox> aTreeListBox;
224 VclPtr<HeaderBar> aHeaderBar;
226 virtual void Resize() override;
227 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
229 DECL_LINK( ButtonHdl, Button *, void );
230 DECL_LINK(TreeListHdl, SvTreeListBox*, void);
231 DECL_LINK( implEndDragHdl, HeaderBar *, void );
232 DECL_LINK( EditAccHdl, Accelerator&, 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 );
246 class StackWindow : public DockingWindow
248 private:
249 VclPtr<SvTreeListBox> aTreeListBox;
250 OUString aStackStr;
252 protected:
253 virtual void Resize() override;
254 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
256 public:
257 explicit StackWindow (Layout* pParent);
258 virtual ~StackWindow() override;
259 virtual void dispose() override;
261 void UpdateCalls();
265 class ComplexEditorWindow final : public vcl::Window
267 private:
268 VclPtr<BreakPointWindow> aBrkWindow;
269 VclPtr<LineNumberWindow> aLineNumberWindow;
270 VclPtr<EditorWindow> aEdtWindow;
271 VclPtr<ScrollBar> aEWVScrollBar;
273 virtual void DataChanged(DataChangedEvent const & rDCEvt) override;
275 virtual void Resize() override;
276 DECL_LINK( ScrollHdl, ScrollBar*, void );
278 public:
279 explicit ComplexEditorWindow( ModulWindow* pParent );
280 virtual ~ComplexEditorWindow() override;
281 virtual void dispose() override;
282 BreakPointWindow& GetBrkWindow() { return *aBrkWindow.get(); }
283 LineNumberWindow& GetLineNumberWindow() { return *aLineNumberWindow.get(); }
284 EditorWindow& GetEdtWindow() { return *aEdtWindow.get(); }
285 ScrollBar& GetEWVScrollBar() { return *aEWVScrollBar.get(); }
287 void SetLineNumberDisplay(bool b);
291 class ModulWindow: public BaseWindow
293 private:
294 ModulWindowLayout& m_rLayout;
295 StarBASICRef m_xBasic;
296 short m_nValid;
297 VclPtr<ComplexEditorWindow> m_aXEditorWindow;
298 BasicStatus m_aStatus;
299 SbModuleRef m_xModule;
300 OUString m_sCurPath;
301 OUString m_aModule;
303 void CheckCompileBasic();
304 void BasicExecute();
306 sal_Int32 FormatAndPrint( Printer* pPrinter, sal_Int32 nPage );
307 SbModuleRef const & XModule();
308 protected:
309 virtual void Resize() override;
310 virtual void GetFocus() override;
311 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) override;
312 virtual void DoInit() override;
313 virtual void DoScroll( ScrollBar* pCurScrollBar ) override;
315 public:
316 ModulWindow( ModulWindowLayout* pParent, const ScriptDocument& rDocument, const OUString& aLibName, const OUString& aName, OUString const & aModule );
318 virtual ~ModulWindow() override;
319 virtual void dispose() override;
321 virtual void ExecuteCommand (SfxRequest& rReq) override;
322 virtual void ExecuteGlobal (SfxRequest& rReq) override;
323 virtual void GetState( SfxItemSet& ) override;
324 virtual void StoreData() override;
325 virtual void UpdateData() override;
326 virtual bool CanClose() 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 bool 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_uLong 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 ScrollBar& GetEditVScrollBar() { return m_aXEditorWindow->GetEWVScrollBar(); }
381 ExtTextEngine* GetEditEngine() { return GetEditorWindow().GetEditEngine(); }
382 TextView* GetEditView() { return GetEditorWindow().GetEditView(); }
383 BreakPointList& GetBreakPoints() { return GetBreakPointWindow().GetBreakPoints(); }
384 ModulWindowLayout& GetLayout () { return m_rLayout; }
386 virtual void BasicStarted() override;
387 virtual void BasicStopped() override;
389 virtual ::svl::IUndoManager*
390 GetUndoManager() override;
392 const OUString& GetModule() const { return m_aModule; }
393 void SetModule( const OUString& aModule ) { m_aModule = aModule; }
395 virtual void Activating () override;
396 virtual void Deactivating () override;
398 virtual void OnNewDocument () override;
399 virtual char const* GetHid () const override;
400 virtual ItemType GetType () const override;
401 virtual bool HasActiveEditor () const override;
403 void UpdateModule ();
406 class ModulWindowLayout: public Layout
408 public:
409 ModulWindowLayout (vcl::Window* pParent, ObjectCatalog&);
410 virtual ~ModulWindowLayout() override;
411 virtual void dispose() override;
412 public:
413 // Layout:
414 virtual void Activating (BaseWindow&) override;
415 virtual void Deactivating () override;
416 virtual void GetState (SfxItemSet&, unsigned nWhich) override;
417 virtual void UpdateDebug (bool bBasicStopped) override;
418 public:
419 void BasicAddWatch (OUString const&);
420 void BasicRemoveWatch ();
421 Color const & GetBackgroundColor () const { return aSyntaxColors.GetBackgroundColor(); }
422 Color const & GetFontColor () const { return aSyntaxColors.GetFontColor(); }
423 Color const & GetSyntaxColor (TokenType eType) const { return aSyntaxColors.GetColor(eType); }
425 protected:
426 // Window:
427 virtual void Paint (vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
428 // Layout:
429 virtual void OnFirstSize (long nWidth, long nHeight) override;
431 private:
432 // main child window
433 VclPtr<ModulWindow> pChild;
434 // dockable windows
435 VclPtr<WatchWindow> aWatchWindow;
436 VclPtr<StackWindow> aStackWindow;
437 ObjectCatalog& rObjectCatalog;
439 // SyntaxColors -- stores Basic syntax highlighting colors
440 class SyntaxColors : public utl::ConfigurationListener
442 public:
443 SyntaxColors ();
444 virtual ~SyntaxColors () override;
445 public:
446 void SetActiveEditor (EditorWindow* pEditor_) { pEditor = pEditor_; }
447 public:
448 Color const & GetBackgroundColor () const { return m_aBackgroundColor; };
449 Color const & GetFontColor () const { return m_aFontColor; }
450 Color const & GetColor(TokenType eType) const { return aColors[eType]; }
452 private:
453 virtual void ConfigurationChanged (utl::ConfigurationBroadcaster*, ConfigurationHints) override;
454 void NewConfig (bool bFirst);
456 private:
457 Color m_aBackgroundColor;
458 Color m_aFontColor;
459 // the color values (the indexes are TokenType, see comphelper/syntaxhighlight.hxx)
460 o3tl::enumarray<TokenType, Color> aColors;
461 // the configuration
462 svtools::ColorConfig aConfig;
463 // the active editor
464 VclPtr<EditorWindow> pEditor;
466 } aSyntaxColors;
469 class CodeCompleteListBox: public ListBox
471 friend class CodeCompleteWindow;
472 friend class EditorWindow;
473 private:
474 OUStringBuffer aFuncBuffer;
475 /* a buffer to build up function name when typing
476 * a function name, used for showing/hiding listbox values
477 * */
478 VclPtr<CodeCompleteWindow> pCodeCompleteWindow; // parent window
480 void SetMatchingEntries(); // sets the visible entries based on aFuncBuffer variable
481 void HideAndRestoreFocus();
482 TextView* GetParentEditView();
484 public:
485 explicit CodeCompleteListBox( CodeCompleteWindow* pPar );
486 virtual ~CodeCompleteListBox() override;
487 virtual void dispose() override;
488 void InsertSelectedEntry(); //insert the selected entry
490 DECL_LINK(ImplDoubleClickHdl, ListBox&, void);
491 DECL_LINK(ImplSelectHdl, ListBox&, void);
493 protected:
494 virtual void KeyInput( const KeyEvent& rKeyEvt ) override;
497 class CodeCompleteWindow: public vcl::Window
499 friend class CodeCompleteListBox;
500 private:
501 VclPtr<EditorWindow> pParent; // parent window
502 TextSelection aTextSelection;
503 VclPtr<CodeCompleteListBox> pListBox;
505 void InitListBox(); // initialize the ListBox
507 public:
508 explicit CodeCompleteWindow( EditorWindow* pPar );
509 virtual ~CodeCompleteWindow() override;
510 virtual void dispose() override;
512 void InsertEntry( const OUString& aStr );
513 void ClearListBox();
514 void SetTextSelection( const TextSelection& aSel );
515 const TextSelection& GetTextSelection() const { return aTextSelection;}
516 void ResizeAndPositionListBox();
517 void SelectFirstEntry(); //selects first entry in ListBox
518 void ClearAndHide();
520 * clears if typed anything, then hides
521 * the window, clear internal variables
522 * */
523 CodeCompleteListBox* GetListBox(){return pListBox;}
526 class UnoTypeCodeCompletetor
528 private:
529 css::uno::Reference< css::reflection::XIdlClass > xClass;
530 bool bCanComplete;
532 bool CheckField( const OUString& sFieldName );
533 bool CheckMethod( const OUString& sMethName );
535 public:
536 UnoTypeCodeCompletetor( const std::vector< OUString >& aVect, const OUString& sVarType );
538 std::vector< OUString > GetXIdlClassMethods() const;
539 std::vector< OUString > GetXIdlClassFields() const;
541 bool CanCodeComplete() const { return bCanComplete;}
544 } // namespace basctl
546 #endif // INCLUDED_BASCTL_SOURCE_BASICIDE_BASIDE2_HXX
548 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */