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 .
20 #ifndef INCLUDED_BASCTL_SOURCE_BASICIDE_BASIDE2_HXX
21 #define INCLUDED_BASCTL_SOURCE_BASICIDE_BASIDE2_HXX
24 #include "bastype3.hxx"
25 #include "basidesh.hxx"
26 #include "breakpoint.hxx"
27 #include "linenumberwindow.hxx"
32 #include <svtools/svtabbx.hxx>
33 #include <svtools/headbar.hxx>
35 #include <vcl/button.hxx>
36 #include <basic/sbmod.hxx>
37 #include <vcl/lstbox.hxx>
38 #include <vcl/idle.hxx>
40 #include <sfx2/progress.hxx>
43 #include <vcl/textdata.hxx>
44 #include <basic/codecompletecache.hxx>
45 #include <com/sun/star/reflection/XIdlClass.hpp>
46 #include <comphelper/namedvaluecollection.hxx>
47 #include <comphelper/processfactory.hxx>
48 #include <comphelper/syntaxhighlight.hxx>
49 #include <com/sun/star/reflection/XIdlReflection.hpp>
51 namespace com
{ namespace sun
{ namespace star
{ namespace beans
{
52 class XMultiPropertySet
;
59 class CodeCompleteListBox
;
60 class CodeCompleteWindow
;
62 // #108672 Helper functions to get/set text in TextEngine
63 // using the stream interface (get/setText() only supports
64 // tools Strings limited to 64K).
65 // defined in baside2b.cxx
66 OUString
getTextEngineText (ExtTextEngine
&);
67 void setTextEngineText (ExtTextEngine
&, OUString
const&);
69 class EditorWindow
: public vcl::Window
, public SfxListener
71 friend class CodeCompleteListBox
;
73 class ChangesListener
;
75 boost::scoped_ptr
<ExtTextView
> pEditView
;
76 boost::scoped_ptr
<ExtTextEngine
> pEditEngine
;
77 ModulWindow
& rModulWindow
;
79 rtl::Reference
< ChangesListener
> listener_
;
81 com::sun::star::uno::Reference
< com::sun::star::beans::XMultiPropertySet
>
86 SyntaxHighlighter aHighlighter
;
88 typedef std::set
<sal_uInt16
> SyntaxLineSet
;
89 SyntaxLineSet aSyntaxLineTable
;
90 DECL_LINK_TYPED(SyntaxTimerHdl
, Idle
*, void);
94 boost::scoped_ptr
<ProgressInfo
> pProgress
;
96 virtual void DataChanged(DataChangedEvent
const & rDCEvt
) SAL_OVERRIDE
;
99 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) SAL_OVERRIDE
;
101 void ImpDoHighlight( sal_uLong nLineOff
);
105 bool bDoSyntaxHighlight
;
106 bool bDelayHighlight
;
109 ::com::sun::star::uno::Reference
< ::com::sun::star::awt::XWindowPeer
>
110 GetComponentInterface(bool bCreate
= true) SAL_OVERRIDE
;
111 CodeCompleteDataCache aCodeCompleteCache
;
112 VclPtr
<CodeCompleteWindow
> pCodeCompleteWnd
;
113 OUString
GetActualSubName( sal_uLong nLine
); // gets the actual subroutine name according to line number
114 void SetupAndShowCodeCompleteWnd(const std::vector
< OUString
>& aEntryVect
, TextSelection aSel
);
115 void HandleAutoCorrect();
116 void HandleAutoCloseParen();
117 void HandleAutoCloseDoubleQuotes();
118 void HandleCodeCompletion();
119 void HandleProcedureCompletion();
120 TextSelection
GetLastHighlightPortionTextSelection();
123 virtual void Paint( vcl::RenderContext
& rRenderContext
, const Rectangle
& ) SAL_OVERRIDE
;
124 virtual void Resize() SAL_OVERRIDE
;
125 virtual void KeyInput( const KeyEvent
& rKeyEvt
) SAL_OVERRIDE
;
126 virtual void MouseMove( const MouseEvent
& rMEvt
) SAL_OVERRIDE
;
127 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) SAL_OVERRIDE
;
128 virtual void MouseButtonUp( const MouseEvent
& rMEvt
) SAL_OVERRIDE
;
129 virtual void Command( const CommandEvent
& rCEvt
) SAL_OVERRIDE
;
130 virtual void LoseFocus() SAL_OVERRIDE
;
131 virtual void RequestHelp( const HelpEvent
& rHEvt
) SAL_OVERRIDE
;
133 void DoSyntaxHighlight( sal_uLong nPara
);
134 OUString
GetWordAtCursor();
138 EditorWindow (vcl::Window
* pParent
, ModulWindow
*);
139 virtual ~EditorWindow();
140 virtual void dispose() SAL_OVERRIDE
;
142 ExtTextEngine
* GetEditEngine() const { return pEditEngine
.get(); }
143 ExtTextView
* GetEditView() const { return pEditView
.get(); }
145 void CreateProgress( const OUString
& rText
, sal_uLong nRange
);
146 void DestroyProgress();
148 void ParagraphInsertedDeleted( sal_uLong nNewPara
, bool bInserted
);
149 void DoDelayedSyntaxHighlight( sal_uLong nPara
);
151 void CreateEditEngine();
152 void SetScrollBarRanges();
153 void InitScrollBars();
155 void ForceSyntaxTimeout();
156 bool SetSourceInBasic();
158 bool CanModify() { return ImpCanModify(); }
160 void UpdateSyntaxHighlighting ();
162 bool GetProcedureName(OUString
& rLine
, OUString
& rProcType
, OUString
& rProcName
) const;
166 class BreakPointWindow
: public vcl::Window
169 ModulWindow
& rModulWindow
;
171 sal_uInt16 nMarkerPos
;
172 BreakPointList aBreakPointList
;
175 virtual void DataChanged(DataChangedEvent
const & rDCEvt
) SAL_OVERRIDE
;
177 void setBackgroundColor(Color aColor
);
180 virtual void Paint(vcl::RenderContext
& rRenderContext
, const Rectangle
&) SAL_OVERRIDE
;
181 BreakPoint
* FindBreakPoint( const Point
& rMousePos
);
182 void ShowMarker(vcl::RenderContext
& rRenderContext
);
183 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) SAL_OVERRIDE
;
184 virtual void Command( const CommandEvent
& rCEvt
) SAL_OVERRIDE
;
189 BreakPointWindow (vcl::Window
* pParent
, ModulWindow
*);
191 void SetMarkerPos( sal_uInt16 nLine
, bool bErrorMarker
= false );
194 void DoScroll( long nHorzScroll
, long nVertScroll
);
195 long& GetCurYOffset() { return nCurYOffset
; }
196 BreakPointList
& GetBreakPoints() { return aBreakPointList
; }
200 class WatchTreeListBox
: public SvHeaderTabListBox
202 OUString aEditingRes
;
205 virtual bool EditingEntry( SvTreeListEntry
* pEntry
, Selection
& rSel
) SAL_OVERRIDE
;
206 virtual bool EditedEntry( SvTreeListEntry
* pEntry
, const OUString
& rNewText
) SAL_OVERRIDE
;
208 bool ImplBasicEntryEdited( SvTreeListEntry
* pEntry
, const OUString
& rResult
);
209 SbxBase
* ImplGetSBXForEntry( SvTreeListEntry
* pEntry
, bool& rbArrayElement
);
212 WatchTreeListBox( vcl::Window
* pParent
, WinBits nWinBits
);
213 virtual ~WatchTreeListBox();
214 virtual void dispose() SAL_OVERRIDE
;
216 void RequestingChildren( SvTreeListEntry
* pParent
) SAL_OVERRIDE
;
217 void UpdateWatches( bool bBasicStopped
= false );
219 using SvTabListBox::SetTabs
;
220 virtual void SetTabs() SAL_OVERRIDE
;
225 class WatchWindow
: public DockingWindow
229 VclPtr
<ExtendedEdit
> aXEdit
;
230 VclPtr
<ImageButton
> aRemoveWatchButton
;
231 VclPtr
<WatchTreeListBox
> aTreeListBox
;
232 VclPtr
<HeaderBar
> aHeaderBar
;
235 virtual void Resize() SAL_OVERRIDE
;
236 virtual void Paint( vcl::RenderContext
& rRenderContext
, const Rectangle
& rRect
) SAL_OVERRIDE
;
238 DECL_LINK( ButtonHdl
, ImageButton
* );
239 DECL_LINK(TreeListHdl
, void *);
240 DECL_LINK( implEndDragHdl
, HeaderBar
* );
241 DECL_LINK_TYPED( EditAccHdl
, Accelerator
*, void );
245 explicit WatchWindow (Layout
* pParent
);
246 virtual ~WatchWindow();
247 virtual void dispose() SAL_OVERRIDE
;
249 void AddWatch( const OUString
& rVName
);
250 bool RemoveSelectedWatch();
251 void UpdateWatches( bool bBasicStopped
= false );
253 WatchTreeListBox
& GetWatchTreeListBox() { return *aTreeListBox
.get(); }
257 class StackWindow
: public DockingWindow
260 VclPtr
<SvTreeListBox
> aTreeListBox
;
264 virtual void Resize() SAL_OVERRIDE
;
265 virtual void Paint( vcl::RenderContext
& rRenderContext
, const Rectangle
& rRect
) SAL_OVERRIDE
;
268 explicit StackWindow (Layout
* pParent
);
269 virtual ~StackWindow();
270 virtual void dispose() SAL_OVERRIDE
;
276 class ComplexEditorWindow
: public vcl::Window
279 VclPtr
<BreakPointWindow
> aBrkWindow
;
280 VclPtr
<LineNumberWindow
> aLineNumberWindow
;
281 VclPtr
<EditorWindow
> aEdtWindow
;
282 VclPtr
<ScrollBar
> aEWVScrollBar
;
284 virtual void DataChanged(DataChangedEvent
const & rDCEvt
) SAL_OVERRIDE
;
287 virtual void Resize() SAL_OVERRIDE
;
288 DECL_LINK( ScrollHdl
, ScrollBar
* );
291 explicit ComplexEditorWindow( ModulWindow
* pParent
);
292 virtual ~ComplexEditorWindow();
293 virtual void dispose() SAL_OVERRIDE
;
294 BreakPointWindow
& GetBrkWindow() { return *aBrkWindow
.get(); }
295 LineNumberWindow
& GetLineNumberWindow() { return *aLineNumberWindow
.get(); }
296 EditorWindow
& GetEdtWindow() { return *aEdtWindow
.get(); }
297 ScrollBar
& GetEWVScrollBar() { return *aEWVScrollBar
.get(); }
299 void SetLineNumberDisplay(bool b
);
303 class ModulWindow
: public BaseWindow
306 ModulWindowLayout
& rLayout
;
309 VclPtr
<ComplexEditorWindow
> aXEditorWindow
;
315 void CheckCompileBasic();
318 static void GoOnTop();
320 sal_Int32
FormatAndPrint( Printer
* pPrinter
, sal_Int32 nPage
= -1 );
321 SbModuleRef
XModule();
323 virtual void Resize() SAL_OVERRIDE
;
324 virtual void GetFocus() SAL_OVERRIDE
;
325 virtual void Paint( vcl::RenderContext
& rRenderContext
, const Rectangle
& ) SAL_OVERRIDE
;
326 virtual void DoInit() SAL_OVERRIDE
;
327 virtual void DoScroll( ScrollBar
* pCurScrollBar
) SAL_OVERRIDE
;
332 ModulWindow( ModulWindowLayout
* pParent
, const ScriptDocument
& rDocument
, const OUString
& aLibName
, const OUString
& aName
, OUString
& aModule
);
334 virtual ~ModulWindow();
335 virtual void dispose() SAL_OVERRIDE
;
337 virtual void ExecuteCommand (SfxRequest
& rReq
) SAL_OVERRIDE
;
338 virtual void ExecuteGlobal (SfxRequest
& rReq
) SAL_OVERRIDE
;
339 virtual void GetState( SfxItemSet
& ) SAL_OVERRIDE
;
340 virtual void StoreData() SAL_OVERRIDE
;
341 virtual void UpdateData() SAL_OVERRIDE
;
342 virtual bool CanClose() SAL_OVERRIDE
;
343 // return number of pages to be printed
344 virtual sal_Int32
countPages( Printer
* pPrinter
) SAL_OVERRIDE
;
346 virtual void printPage( sal_Int32 nPage
, Printer
* pPrinter
) SAL_OVERRIDE
;
347 virtual OUString
GetTitle() SAL_OVERRIDE
;
348 virtual EntryDescriptor
CreateEntryDescriptor() SAL_OVERRIDE
;
349 virtual bool AllowUndo() SAL_OVERRIDE
;
350 virtual void SetReadOnly (bool bReadOnly
) SAL_OVERRIDE
;
351 virtual bool IsReadOnly() SAL_OVERRIDE
;
353 StarBASIC
* GetBasic() { XModule(); return xBasic
; }
355 SbModule
* GetSbModule() { return xModule
; }
356 void SetSbModule( SbModule
* pModule
) { xModule
= pModule
; }
357 OUString
GetSbModuleName();
361 bool BasicStepOver();
362 bool BasicStepInto();
365 bool BasicToggleBreakPoint();
366 void BasicToggleBreakPointEnabled();
367 void ManageBreakPoints();
368 void UpdateBreakPoint( const BreakPoint
& rBrk
);
369 void BasicAddWatch();
370 void BasicRemoveWatch();
372 bool BasicErrorHdl( StarBASIC
* pBasic
);
373 long BasicBreakHdl( StarBASIC
* pBasic
);
374 void AssertValidEditEngine();
377 bool SaveBasicSource();
380 void EditMacro( const OUString
& rMacroName
);
382 bool ToggleBreakPoint( sal_uLong nLine
);
384 BasicStatus
& GetBasicStatus() { return aStatus
; }
386 virtual bool IsModified () SAL_OVERRIDE
;
387 virtual bool IsPasteAllowed () SAL_OVERRIDE
;
389 void ShowCursor( bool bOn
);
391 virtual SearchOptionFlags
GetSearchOptions() SAL_OVERRIDE
;
392 virtual sal_uInt16
StartSearchAndReplace (SvxSearchItem
const&, bool bFromStart
= false) SAL_OVERRIDE
;
394 EditorWindow
& GetEditorWindow() { return aXEditorWindow
->GetEdtWindow(); }
395 BreakPointWindow
& GetBreakPointWindow() { return aXEditorWindow
->GetBrkWindow(); }
396 LineNumberWindow
& GetLineNumberWindow() { return aXEditorWindow
->GetLineNumberWindow(); }
397 ScrollBar
& GetEditVScrollBar() { return aXEditorWindow
->GetEWVScrollBar(); }
398 ExtTextEngine
* GetEditEngine() { return GetEditorWindow().GetEditEngine(); }
399 ExtTextView
* GetEditView() { return GetEditorWindow().GetEditView(); }
400 BreakPointList
& GetBreakPoints() { return GetBreakPointWindow().GetBreakPoints(); }
401 ModulWindowLayout
& GetLayout () { return rLayout
; }
403 virtual void BasicStarted() SAL_OVERRIDE
;
404 virtual void BasicStopped() SAL_OVERRIDE
;
406 virtual ::svl::IUndoManager
*
407 GetUndoManager() SAL_OVERRIDE
;
409 const OUString
& GetModule() const { return m_aModule
; }
410 void SetModule( const OUString
& aModule
) { m_aModule
= aModule
; }
412 virtual void Activating () SAL_OVERRIDE
;
413 virtual void Deactivating () SAL_OVERRIDE
;
415 virtual void OnNewDocument () SAL_OVERRIDE
;
416 virtual char const* GetHid () const SAL_OVERRIDE
;
417 virtual ItemType
GetType () const SAL_OVERRIDE
;
418 virtual bool HasActiveEditor () const SAL_OVERRIDE
;
420 void UpdateModule ();
423 class ModulWindowLayout
: public Layout
426 ModulWindowLayout (vcl::Window
* pParent
, ObjectCatalog
&);
427 virtual ~ModulWindowLayout();
428 virtual void dispose() SAL_OVERRIDE
;
431 virtual void Activating (BaseWindow
&) SAL_OVERRIDE
;
432 virtual void Deactivating () SAL_OVERRIDE
;
433 virtual void GetState (SfxItemSet
&, unsigned nWhich
) SAL_OVERRIDE
;
434 virtual void UpdateDebug (bool bBasicStopped
) SAL_OVERRIDE
;
436 void BasicAddWatch (OUString
const&);
437 void BasicRemoveWatch ();
438 Color
GetSyntaxColor (TokenTypes eType
) const { return aSyntaxColors
.GetColor(eType
); }
442 virtual void Paint (vcl::RenderContext
& rRenderContext
, const Rectangle
& rRect
) SAL_OVERRIDE
;
444 virtual void OnFirstSize (long nWidth
, long nHeight
) SAL_OVERRIDE
;
448 VclPtr
<ModulWindow
> pChild
;
450 VclPtr
<WatchWindow
> aWatchWindow
;
451 VclPtr
<StackWindow
> aStackWindow
;
452 ObjectCatalog
& rObjectCatalog
;
454 virtual void DataChanged (DataChangedEvent
const& rDCEvt
) SAL_OVERRIDE
;
456 // SyntaxColors -- stores Basic syntax highlighting colors
457 class SyntaxColors
: public utl::ConfigurationListener
461 virtual ~SyntaxColors ();
463 void SetActiveEditor (EditorWindow
* pEditor_
) { pEditor
= pEditor_
; }
464 void SettingsChanged ();
466 Color
GetColor (TokenTypes eType
) const { return aColors
[eType
]; }
469 virtual void ConfigurationChanged (utl::ConfigurationBroadcaster
*, sal_uInt32
) SAL_OVERRIDE
;
470 void NewConfig (bool bFirst
);
473 // the color values (the indexes are TokenTypes, see comphelper/syntaxhighlight.hxx)
474 Color aColors
[TT_KEYWORDS
+ 1];
476 svtools::ColorConfig aConfig
;
478 VclPtr
<EditorWindow
> pEditor
;
483 class CodeCompleteListBox
: public ListBox
485 friend class CodeCompleteWindow
;
486 friend class EditorWindow
;
488 OUStringBuffer aFuncBuffer
;
489 /* a buffer to build up function name when typing
490 * a function name, used for showing/hiding listbox values
492 VclPtr
<CodeCompleteWindow
> pCodeCompleteWindow
; // parent window
494 void SetMatchingEntries(); // sets the visible entries based on aFuncBuffer variable
495 void HideAndRestoreFocus();
496 ExtTextView
* GetParentEditView();
499 explicit CodeCompleteListBox( CodeCompleteWindow
* pPar
);
500 virtual ~CodeCompleteListBox();
501 virtual void dispose() SAL_OVERRIDE
;
502 void InsertSelectedEntry(); //insert the selected entry
504 DECL_LINK(ImplDoubleClickHdl
, void*);
505 DECL_LINK(ImplSelectHdl
, void*);
508 virtual void KeyInput( const KeyEvent
& rKeyEvt
) SAL_OVERRIDE
;
511 class CodeCompleteWindow
: public vcl::Window
513 friend class CodeCompleteListBox
;
515 VclPtr
<EditorWindow
> pParent
; // parent window
516 TextSelection aTextSelection
;
517 VclPtr
<CodeCompleteListBox
> pListBox
;
519 void InitListBox(); // initialize the ListBox
522 explicit CodeCompleteWindow( EditorWindow
* pPar
);
523 virtual ~CodeCompleteWindow();
524 virtual void dispose() SAL_OVERRIDE
;
526 void InsertEntry( const OUString
& aStr
);
528 void SetTextSelection( const TextSelection
& aSel
);
529 const TextSelection
& GetTextSelection() const { return aTextSelection
;}
530 void ResizeAndPositionListBox();
531 void SelectFirstEntry(); //selects first entry in ListBox
534 * clears if typed anything, then hides
535 * the window, clear internal variables
537 CodeCompleteListBox
* GetListBox(){return pListBox
;}
540 class UnoTypeCodeCompletetor
543 css::uno::Reference
< css::lang::XMultiServiceFactory
> xFactory
;
544 css::uno::Reference
< css::reflection::XIdlReflection
> xRefl
;
545 css::uno::Reference
< css::reflection::XIdlClass
> xClass
;
548 bool CheckField( const OUString
& sFieldName
);
549 bool CheckMethod( const OUString
& sMethName
);
552 UnoTypeCodeCompletetor( const std::vector
< OUString
>& aVect
, const OUString
& sVarType
);
553 ~UnoTypeCodeCompletetor(){}
555 std::vector
< OUString
> GetXIdlClassMethods() const;
556 std::vector
< OUString
> GetXIdlClassFields() const;
558 bool CanCodeComplete() const { return bCanComplete
;}
561 } // namespace basctl
563 #endif // INCLUDED_BASCTL_SOURCE_BASICIDE_BASIDE2_HXX
565 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */