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 .
19 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_SRCEDTW_HXX
20 #define INCLUDED_SW_SOURCE_UIBASE_INC_SRCEDTW_HXX
22 #include <vcl/window.hxx>
23 #include <svl/lstner.hxx>
24 #include <vcl/timer.hxx>
25 #include <vcl/idle.hxx>
27 #include <vcl/xtextedt.hxx>
31 namespace com::sun::star::beans
{ class XMultiPropertySet
; }
32 namespace weld
{ class Scrollbar
; }
35 class SwSrcEditWindow
;
38 class DataChangedEvent
;
40 class TextViewOutWin final
: public vcl::Window
42 TextView
* m_pTextView
;
44 virtual void Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& ) override
;
45 virtual void KeyInput( const KeyEvent
& rKeyEvt
) override
;
46 virtual void MouseMove( const MouseEvent
& rMEvt
) override
;
47 virtual void MouseButtonDown( const MouseEvent
& rMEvt
) override
;
48 virtual void MouseButtonUp( const MouseEvent
& rMEvt
) override
;
49 virtual void Command( const CommandEvent
& rCEvt
) override
;
50 virtual void DataChanged( const DataChangedEvent
& ) override
;
53 TextViewOutWin(vcl::Window
* pParent
, WinBits nBits
) :
54 Window(pParent
, nBits
), m_pTextView(nullptr){}
56 void SetTextView( TextView
* pView
) {m_pTextView
= pView
;}
60 class SwSrcEditWindow final
: public vcl::Window
, public SfxListener
63 class ChangesListener
;
64 friend class ChangesListener
;
65 std::unique_ptr
<TextView
> m_pTextView
;
66 std::unique_ptr
<ExtTextEngine
> m_pTextEngine
;
68 VclPtr
<TextViewOutWin
> m_pOutWin
;
69 VclPtr
<ScrollAdaptor
> m_pHScrollbar
,
72 SwSrcView
* m_pSrcView
;
74 rtl::Reference
< ChangesListener
> m_xListener
;
76 css::uno::Reference
< css::beans::XMultiPropertySet
>
79 tools::Long m_nCurTextWidth
;
80 sal_uInt16 m_nStartLine
;
81 rtl_TextEncoding m_eSourceEncoding
;
86 std::set
<sal_uInt16
> m_aSyntaxLineTable
;
88 void ImpDoHighlight( std::u16string_view aSource
, sal_uInt16 nLineOff
);
92 DECL_LINK( SyntaxTimerHdl
, Timer
*, void );
94 using Window::Invalidate
;
96 virtual void Resize() override
;
97 virtual void DataChanged( const DataChangedEvent
& ) override
;
98 virtual void GetFocus() override
;
100 void CreateTextEngine();
101 void DoSyntaxHighlight( sal_uInt16 nPara
);
103 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
105 DECL_LINK(HorzScrollHdl
, weld::Scrollbar
&, void);
106 DECL_LINK(VertScrollHdl
, weld::Scrollbar
&, void);
109 SwSrcEditWindow( vcl::Window
* pParent
, SwSrcView
* pParentView
);
110 virtual ~SwSrcEditWindow() override
;
111 virtual void dispose() override
;
113 void SetScrollBarRanges();
114 void InitScrollBars();
115 void Read(SvStream
& rInput
) { m_pTextEngine
->Read(rInput
); }
116 void Write(SvStream
& rOutput
) { m_pTextEngine
->Write(rOutput
); }
118 TextView
* GetTextView()
119 {return m_pTextView
.get();}
120 TextEngine
* GetTextEngine()
121 {return m_pTextEngine
.get();}
122 SwSrcView
* GetSrcView() {return m_pSrcView
;}
124 TextViewOutWin
* GetOutWin() {return m_pOutWin
;}
126 virtual void Invalidate( InvalidateFlags nFlags
= InvalidateFlags::NONE
) override
;
128 void ClearModifyFlag()
129 { m_pTextEngine
->SetModified(false); }
130 bool IsModified() const
131 { return m_pTextEngine
->IsModified();}
133 void SetReadonly(bool bSet
){m_bReadonly
= bSet
;}
134 bool IsReadonly() const {return m_bReadonly
;}
136 void SetStartLine(sal_uInt16 nLine
){m_nStartLine
= nLine
;}
138 virtual void Command( const CommandEvent
& rCEvt
) override
;
139 void HandleWheelCommand( const CommandEvent
& rCEvt
);
141 void SetTextEncoding(rtl_TextEncoding eEncoding
);
146 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */