nss: upgrade to release 3.73
[LibreOffice.git] / basctl / source / basicide / baside2.hxx
blob0f304adb83b03207863f6ac7529acbbf836e52da
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 <layout.hxx>
24 #include "breakpoint.hxx"
25 #include "linenumberwindow.hxx"
27 #include <basic/sbmod.hxx>
28 #include <basic/sbstar.hxx>
29 #include <vcl/InterimItemWindow.hxx>
30 #include <vcl/idle.hxx>
31 #include <vcl/weld.hxx>
33 #include <svtools/colorcfg.hxx>
34 #include <o3tl/enumarray.hxx>
35 #include <rtl/ustrbuf.hxx>
37 #include <set>
39 #include <vcl/textdata.hxx>
40 #include <basic/codecompletecache.hxx>
41 #include <com/sun/star/reflection/XIdlClass.hpp>
42 #include <comphelper/syntaxhighlight.hxx>
44 class ExtTextEngine;
45 class TextView;
46 class SvxSearchItem;
47 namespace com::sun::star::beans { class XMultiPropertySet; }
49 namespace basctl
52 class ObjectCatalog;
53 class CodeCompleteWindow;
54 class ModulWindowLayout;
56 // #108672 Helper functions to get/set text in TextEngine
57 // using the stream interface (get/setText() only supports
58 // tools Strings limited to 64K).
59 // defined in baside2b.cxx
60 OUString getTextEngineText (ExtTextEngine&);
61 void setTextEngineText (ExtTextEngine&, OUString const&);
63 class EditorWindow final : public vcl::Window, public SfxListener
65 friend class CodeCompleteWindow;
66 friend class EditorWindowUIObject;
67 private:
68 class ChangesListener;
70 std::unique_ptr<TextView> pEditView;
71 std::unique_ptr<ExtTextEngine> pEditEngine;
72 ModulWindow& rModulWindow;
74 rtl::Reference< ChangesListener > listener_;
75 osl::Mutex mutex_;
76 css::uno::Reference< css::beans::XMultiPropertySet >
77 notifier_;
79 tools::Long nCurTextWidth;
81 ImplSVEvent* m_nSetSourceInBasicId;
83 SyntaxHighlighter aHighlighter;
84 Idle aSyntaxIdle;
85 std::set<sal_uInt16> aSyntaxLineTable;
86 DECL_LINK(SyntaxTimerHdl, Timer *, void);
87 DECL_LINK(SetSourceInBasicHdl, void*, void);
89 // progress bar
90 class ProgressInfo;
91 std::unique_ptr<ProgressInfo> pProgress;
93 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
95 void ImpDoHighlight( sal_uLong nLineOff );
96 void ImplSetFont();
98 bool bHighlighting;
99 bool bDoSyntaxHighlight;
100 bool bDelayHighlight;
102 virtual css::uno::Reference< css::awt::XWindowPeer > GetComponentInterface(bool bCreate = true) override;
103 CodeCompleteDataCache aCodeCompleteCache;
104 VclPtr<CodeCompleteWindow> pCodeCompleteWnd;
105 OUString GetActualSubName( sal_uLong nLine ); // gets the actual subroutine name according to line number
106 void SetupAndShowCodeCompleteWnd(const std::vector< OUString >& aEntryVect, TextSelection aSel );
107 void HandleAutoCorrect();
108 void HandleAutoCloseParen();
109 void HandleAutoCloseDoubleQuotes();
110 void HandleCodeCompletion();
111 void HandleProcedureCompletion();
112 TextSelection GetLastHighlightPortionTextSelection() const;
114 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) override;
115 virtual void Resize() override;
116 virtual void KeyInput( const KeyEvent& rKeyEvt ) override;
117 virtual void MouseMove( const MouseEvent& rMEvt ) override;
118 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
119 virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
120 virtual void Command( const CommandEvent& rCEvt ) override;
121 virtual void LoseFocus() override;
122 virtual void RequestHelp( const HelpEvent& rHEvt ) override;
124 void DoSyntaxHighlight( sal_uLong nPara );
125 OUString GetWordAtCursor();
126 bool ImpCanModify();
128 public:
129 EditorWindow (vcl::Window* pParent, ModulWindow*);
130 virtual ~EditorWindow() override;
131 virtual void dispose() override;
133 ExtTextEngine* GetEditEngine() const { return pEditEngine.get(); }
134 TextView* GetEditView() const { return pEditView.get(); }
136 void CreateProgress( const OUString& rText, sal_uInt32 nRange );
137 void DestroyProgress();
139 void ParagraphInsertedDeleted( sal_uLong nNewPara, bool bInserted );
140 void DoDelayedSyntaxHighlight( sal_uLong nPara );
142 void CreateEditEngine();
143 void SetScrollBarRanges();
144 void InitScrollBars();
146 void ForceSyntaxTimeout();
147 void SetSourceInBasic();
149 bool CanModify() { return ImpCanModify(); }
151 void ChangeFontColor( Color aColor );
152 void UpdateSyntaxHighlighting ();
154 bool GetProcedureName(OUString const & rLine, OUString& rProcType, OUString& rProcName) const;
156 FactoryFunction GetUITestFactory() const override;
159 class BreakPointWindow final : public vcl::Window
161 ModulWindow& rModulWindow;
162 tools::Long nCurYOffset;
163 sal_uInt16 nMarkerPos;
164 BreakPointList aBreakPointList;
165 bool bErrorMarker;
166 std::unique_ptr<VclBuilder> mpUIBuilder;
168 virtual void DataChanged(DataChangedEvent const & rDCEvt) override;
170 void setBackgroundColor(Color aColor);
172 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override;
173 BreakPoint* FindBreakPoint( const Point& rMousePos );
174 void ShowMarker(vcl::RenderContext& rRenderContext);
175 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
176 virtual void Command( const CommandEvent& rCEvt ) override;
178 bool SyncYOffset();
180 public:
181 BreakPointWindow (vcl::Window* pParent, ModulWindow*);
182 virtual void dispose() override;
184 void SetMarkerPos( sal_uInt16 nLine, bool bErrorMarker = false );
185 void SetNoMarker ();
187 void DoScroll( tools::Long nVertScroll );
188 tools::Long& GetCurYOffset() { return nCurYOffset; }
189 BreakPointList& GetBreakPoints() { return aBreakPointList; }
192 class WatchWindow final : public DockingWindow
194 private:
195 std::unique_ptr<weld::Container> m_xTitleArea;
196 std::unique_ptr<weld::Label> m_xTitle;
197 std::unique_ptr<weld::Entry> m_xEdit;
198 std::unique_ptr<weld::Button> m_xRemoveWatchButton;
199 std::unique_ptr<weld::TreeView> m_xTreeListBox;
201 ImplSVEvent* m_nUpdateWatchesId;
202 OUString aEditingRes;
204 virtual void Resize() override;
205 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
207 SbxBase* ImplGetSBXForEntry(const weld::TreeIter& rEntry, bool& rbArrayElement);
209 void implEnableChildren(const weld::TreeIter& rEntry, bool bEnable);
211 DECL_STATIC_LINK(WatchWindow, ButtonHdl, weld::Button&, void);
212 DECL_LINK(TreeListHdl, weld::TreeView&, void);
213 DECL_LINK(RequestingChildrenHdl, const weld::TreeIter&, bool);
214 DECL_LINK(ActivateHdl, weld::Entry&, bool);
215 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
216 DECL_LINK(EditingEntryHdl, const weld::TreeIter&, bool);
217 typedef std::pair<const weld::TreeIter&, OUString> IterString;
218 DECL_LINK(EditedEntryHdl, const IterString&, bool);
219 DECL_LINK(ExecuteUpdateWatches, void*, void);
221 public:
222 explicit WatchWindow (Layout* pParent);
223 virtual ~WatchWindow() override;
224 virtual void dispose() override;
226 void AddWatch( const OUString& rVName );
227 void RemoveSelectedWatch();
228 void UpdateWatches(bool bBasicStopped = false);
231 class StackWindow : public DockingWindow
233 private:
234 std::unique_ptr<weld::Label> m_xTitle;
235 std::unique_ptr<weld::TreeView> m_xTreeListBox;
237 protected:
238 virtual void Resize() override;
239 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
241 public:
242 explicit StackWindow (Layout* pParent);
243 virtual ~StackWindow() override;
244 virtual void dispose() override;
246 void UpdateCalls();
250 class ComplexEditorWindow final : public vcl::Window
252 private:
253 VclPtr<BreakPointWindow> aBrkWindow;
254 VclPtr<LineNumberWindow> aLineNumberWindow;
255 VclPtr<EditorWindow> aEdtWindow;
256 VclPtr<ScrollBar> aEWVScrollBar;
258 virtual void DataChanged(DataChangedEvent const & rDCEvt) override;
260 virtual void Resize() override;
261 DECL_LINK( ScrollHdl, ScrollBar*, void );
263 public:
264 explicit ComplexEditorWindow( ModulWindow* pParent );
265 virtual ~ComplexEditorWindow() override;
266 virtual void dispose() override;
267 BreakPointWindow& GetBrkWindow() { return *aBrkWindow; }
268 LineNumberWindow& GetLineNumberWindow() { return *aLineNumberWindow; }
269 EditorWindow& GetEdtWindow() { return *aEdtWindow; }
270 ScrollBar& GetEWVScrollBar() { return *aEWVScrollBar; }
272 void SetLineNumberDisplay(bool b);
276 class ModulWindow: public BaseWindow
278 private:
279 ModulWindowLayout& m_rLayout;
280 StarBASICRef m_xBasic;
281 short m_nValid;
282 VclPtr<ComplexEditorWindow> m_aXEditorWindow;
283 BasicStatus m_aStatus;
284 SbModuleRef m_xModule;
285 OUString m_sCurPath;
286 OUString m_aModule;
288 void CheckCompileBasic();
289 void BasicExecute();
291 sal_Int32 FormatAndPrint( Printer* pPrinter, sal_Int32 nPage );
292 SbModuleRef const & XModule();
293 protected:
294 virtual void Resize() override;
295 virtual void GetFocus() override;
296 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& ) override;
297 virtual void DoInit() override;
298 virtual void DoScroll( ScrollBar* pCurScrollBar ) override;
300 public:
301 ModulWindow( ModulWindowLayout* pParent, const ScriptDocument& rDocument, const OUString& aLibName, const OUString& aName, OUString const & aModule );
303 virtual ~ModulWindow() override;
304 virtual void dispose() override;
306 virtual void ExecuteCommand (SfxRequest& rReq) override;
307 virtual void ExecuteGlobal (SfxRequest& rReq) override;
308 virtual void GetState( SfxItemSet& ) override;
309 virtual void StoreData() override;
310 virtual void UpdateData() override;
311 // return number of pages to be printed
312 virtual sal_Int32 countPages( Printer* pPrinter ) override;
313 // print page
314 virtual void printPage( sal_Int32 nPage, Printer* pPrinter ) override;
315 virtual OUString GetTitle() override;
316 virtual EntryDescriptor CreateEntryDescriptor() override;
317 virtual bool AllowUndo() override;
318 virtual void SetReadOnly (bool bReadOnly) override;
319 virtual bool IsReadOnly() override;
321 StarBASIC* GetBasic() { XModule(); return m_xBasic.get(); }
323 SbModule* GetSbModule() { return m_xModule.get(); }
324 void SetSbModule( SbModule* pModule ) { m_xModule = pModule; }
325 OUString GetSbModuleName();
327 void CompileBasic();
328 void BasicRun();
329 void BasicStepOver();
330 void BasicStepInto();
331 void BasicStepOut();
332 void BasicStop();
333 void BasicToggleBreakPoint();
334 void BasicToggleBreakPointEnabled();
335 void ManageBreakPoints();
336 void UpdateBreakPoint( const BreakPoint& rBrk );
337 void BasicAddWatch();
339 void BasicErrorHdl( StarBASIC const * pBasic );
340 BasicDebugFlags BasicBreakHdl();
341 void AssertValidEditEngine();
343 void LoadBasic();
344 void SaveBasicSource();
345 void ImportDialog();
347 void EditMacro( const OUString& rMacroName );
349 void ToggleBreakPoint( sal_uInt16 nLine );
351 BasicStatus& GetBasicStatus() { return m_aStatus; }
353 virtual bool IsModified () override;
354 bool IsPasteAllowed ();
356 void ShowCursor( bool bOn );
358 virtual SearchOptionFlags GetSearchOptions() override;
359 virtual sal_uInt16 StartSearchAndReplace (SvxSearchItem const&, bool bFromStart = false) override;
361 EditorWindow& GetEditorWindow() { return m_aXEditorWindow->GetEdtWindow(); }
362 BreakPointWindow& GetBreakPointWindow() { return m_aXEditorWindow->GetBrkWindow(); }
363 LineNumberWindow& GetLineNumberWindow() { return m_aXEditorWindow->GetLineNumberWindow(); }
364 ScrollBar& GetEditVScrollBar() { return m_aXEditorWindow->GetEWVScrollBar(); }
365 ExtTextEngine* GetEditEngine() { return GetEditorWindow().GetEditEngine(); }
366 TextView* GetEditView() { return GetEditorWindow().GetEditView(); }
367 BreakPointList& GetBreakPoints() { return GetBreakPointWindow().GetBreakPoints(); }
368 ModulWindowLayout& GetLayout () { return m_rLayout; }
370 virtual void BasicStarted() override;
371 virtual void BasicStopped() override;
373 virtual SfxUndoManager*
374 GetUndoManager() override;
376 const OUString& GetModule() const { return m_aModule; }
377 void SetModule( const OUString& aModule ) { m_aModule = aModule; }
379 virtual void Activating () override;
380 virtual void Deactivating () override;
382 virtual void OnNewDocument () override;
383 virtual char const* GetHid () const override;
384 virtual ItemType GetType () const override;
385 virtual bool HasActiveEditor () const override;
387 void UpdateModule ();
390 class ModulWindowLayout: public Layout
392 public:
393 ModulWindowLayout (vcl::Window* pParent, ObjectCatalog&);
394 virtual ~ModulWindowLayout() override;
395 virtual void dispose() override;
396 public:
397 // Layout:
398 virtual void Activating (BaseWindow&) override;
399 virtual void Deactivating () override;
400 virtual void GetState (SfxItemSet&, unsigned nWhich) override;
401 virtual void UpdateDebug (bool bBasicStopped) override;
402 public:
403 void BasicAddWatch (OUString const&);
404 void BasicRemoveWatch ();
405 Color const & GetSyntaxBackgroundColor () const { return aSyntaxColors.GetBackgroundColor(); }
406 Color const & GetFontColor () const { return aSyntaxColors.GetFontColor(); }
407 Color const & GetSyntaxColor (TokenType eType) const { return aSyntaxColors.GetColor(eType); }
409 protected:
410 // Window:
411 virtual void Paint (vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
412 // Layout:
413 virtual void OnFirstSize (tools::Long nWidth, tools::Long nHeight) override;
415 private:
416 // main child window
417 VclPtr<ModulWindow> pChild;
418 // dockable windows
419 VclPtr<WatchWindow> aWatchWindow;
420 VclPtr<StackWindow> aStackWindow;
421 ObjectCatalog& rObjectCatalog;
423 // SyntaxColors -- stores Basic syntax highlighting colors
424 class SyntaxColors : public utl::ConfigurationListener
426 public:
427 SyntaxColors ();
428 virtual ~SyntaxColors () override;
429 public:
430 void SetActiveEditor (EditorWindow* pEditor_) { pEditor = pEditor_; }
431 public:
432 Color const & GetBackgroundColor () const { return m_aBackgroundColor; };
433 Color const & GetFontColor () const { return m_aFontColor; }
434 Color const & GetColor(TokenType eType) const { return aColors[eType]; }
436 private:
437 virtual void ConfigurationChanged (utl::ConfigurationBroadcaster*, ConfigurationHints) override;
438 void NewConfig (bool bFirst);
440 private:
441 Color m_aBackgroundColor;
442 Color m_aFontColor;
443 // the color values (the indexes are TokenType, see comphelper/syntaxhighlight.hxx)
444 o3tl::enumarray<TokenType, Color> aColors;
445 // the configuration
446 svtools::ColorConfig aConfig;
447 // the active editor
448 VclPtr<EditorWindow> pEditor;
450 } aSyntaxColors;
453 class CodeCompleteWindow final : public InterimItemWindow
455 private:
456 VclPtr<EditorWindow> pParent; // parent window
457 TextSelection m_aTextSelection;
458 std::unique_ptr<weld::TreeView> m_xListBox;
460 /* a buffer to build up function name when typing
461 * a function name, used for showing/hiding listbox values
462 * */
463 OUStringBuffer aFuncBuffer;
465 void InsertSelectedEntry(); // insert the selected entry
466 void SetMatchingEntries(); // sets the visible entries based on aFuncBuffer variable
467 TextView* GetParentEditView();
469 DECL_LINK(ImplDoubleClickHdl, weld::TreeView&, bool);
470 DECL_LINK(ImplSelectHdl, weld::TreeView&, void);
471 DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
473 public:
474 explicit CodeCompleteWindow( EditorWindow* pPar );
475 virtual ~CodeCompleteWindow() override;
476 virtual void dispose() override;
478 void InsertEntry( const OUString& aStr );
479 void ClearListBox();
480 void SetTextSelection( const TextSelection& aSel );
481 const TextSelection& GetTextSelection() const { return m_aTextSelection;}
482 void ResizeAndPositionListBox();
483 void SelectFirstEntry(); //selects first entry in ListBox
486 * clears if typed anything, then hides
487 * the window, clear internal variables
488 * */
489 void ClearAndHide();
490 void HideAndRestoreFocus();
492 bool HandleKeyInput(const KeyEvent& rKeyEvt);
495 class UnoTypeCodeCompletetor
497 private:
498 css::uno::Reference< css::reflection::XIdlClass > xClass;
499 bool bCanComplete;
501 bool CheckField( const OUString& sFieldName );
502 bool CheckMethod( const OUString& sMethName );
504 public:
505 UnoTypeCodeCompletetor( const std::vector< OUString >& aVect, const OUString& sVarType );
507 std::vector< OUString > GetXIdlClassMethods() const;
508 std::vector< OUString > GetXIdlClassFields() const;
510 bool CanCodeComplete() const { return bCanComplete;}
513 } // namespace basctl
515 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */