Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef _SRCEDTW_HXX
20 : #define _SRCEDTW_HXX
21 :
22 : #include <vcl/window.hxx>
23 : #include <svl/lstner.hxx>
24 : #include <vcl/timer.hxx>
25 :
26 : #include <vcl/xtextedt.hxx>
27 : #include <set>
28 :
29 : namespace com { namespace sun { namespace star { namespace beans {
30 : class XMultiPropertySet;
31 : } } } }
32 :
33 : class ScrollBar;
34 : class SwSrcView;
35 : class SwSrcEditWindow;
36 : class TextEngine;
37 : class ExtTextView;
38 : class DataChangedEvent;
39 :
40 0 : class TextViewOutWin : public Window
41 : {
42 : ExtTextView* pTextView;
43 :
44 : protected:
45 : virtual void Paint( const Rectangle& );
46 : virtual void KeyInput( const KeyEvent& rKeyEvt );
47 : virtual void MouseMove( const MouseEvent& rMEvt );
48 : virtual void MouseButtonDown( const MouseEvent& rMEvt );
49 : virtual void MouseButtonUp( const MouseEvent& rMEvt );
50 : virtual void Command( const CommandEvent& rCEvt );
51 : virtual void DataChanged( const DataChangedEvent& );
52 :
53 : public:
54 0 : TextViewOutWin(Window* pParent, WinBits nBits) :
55 0 : Window(pParent, nBits), pTextView(0){}
56 :
57 0 : void SetTextView( ExtTextView* pView ) {pTextView = pView;}
58 :
59 : };
60 :
61 : //------------------------------------------------------------
62 : typedef std::set<sal_uInt16> SyntaxLineSet;
63 :
64 : class SwSrcEditWindow : public Window, public SfxListener
65 : {
66 : private:
67 : class ChangesListener;
68 : friend class ChangesListener;
69 : ExtTextView* pTextView;
70 : ExtTextEngine* pTextEngine;
71 :
72 : TextViewOutWin* pOutWin;
73 : ScrollBar *pHScrollbar,
74 : *pVScrollbar;
75 :
76 : SwSrcView* pSrcView;
77 :
78 : rtl::Reference< ChangesListener > listener_;
79 : osl::Mutex mutex_;
80 : com::sun::star::uno::Reference< com::sun::star::beans::XMultiPropertySet >
81 : notifier_;
82 :
83 : long nCurTextWidth;
84 : sal_uInt16 nStartLine;
85 : rtl_TextEncoding eSourceEncoding;
86 : sal_Bool bReadonly;
87 : sal_Bool bDoSyntaxHighlight;
88 : sal_Bool bHighlighting;
89 :
90 : Timer aSyntaxIdleTimer;
91 : SyntaxLineSet aSyntaxLineTable;
92 :
93 : void ImpDoHighlight( const String& rSource, sal_uInt16 nLineOff );
94 :
95 : using OutputDevice::SetFont;
96 : void SetFont();
97 :
98 : DECL_LINK( SyntaxTimerHdl, Timer * );
99 : DECL_LINK( TimeoutHdl, Timer * );
100 :
101 : using Window::Notify;
102 : using Window::Invalidate;
103 :
104 : protected:
105 :
106 : virtual void Resize();
107 : virtual void DataChanged( const DataChangedEvent& );
108 : virtual void GetFocus();
109 : // virtual void LoseFocus();
110 :
111 : void CreateTextEngine();
112 : void DoSyntaxHighlight( sal_uInt16 nPara );
113 :
114 : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
115 :
116 : DECL_LINK(ScrollHdl, ScrollBar*);
117 :
118 : public:
119 : SwSrcEditWindow( Window* pParent, SwSrcView* pParentView );
120 : ~SwSrcEditWindow();
121 :
122 : void SetScrollBarRanges();
123 : void InitScrollBars();
124 0 : sal_uLong Read( SvStream& rInput)
125 0 : {return pTextEngine->Read(rInput);}
126 0 : sal_uLong Write( SvStream& rOutput)
127 0 : {return pTextEngine->Write(rOutput);}
128 :
129 0 : ExtTextView* GetTextView()
130 0 : {return pTextView;}
131 0 : TextEngine* GetTextEngine()
132 0 : {return pTextEngine;}
133 0 : SwSrcView* GetSrcView() {return pSrcView;}
134 :
135 0 : TextViewOutWin* GetOutWin() {return pOutWin;}
136 :
137 : virtual void Invalidate( sal_uInt16 nFlags = 0 );
138 :
139 0 : void ClearModifyFlag()
140 0 : { pTextEngine->SetModified(sal_False); }
141 0 : sal_Bool IsModified() const
142 0 : { return pTextEngine->IsModified();}
143 : void CreateScrollbars();
144 :
145 0 : void SetReadonly(sal_Bool bSet){bReadonly = bSet;}
146 0 : sal_Bool IsReadonly(){return bReadonly;}
147 :
148 : void DoDelayedSyntaxHighlight( sal_uInt16 nPara );
149 :
150 0 : void SetStartLine(sal_uInt16 nLine){nStartLine = nLine;}
151 :
152 : virtual void Command( const CommandEvent& rCEvt );
153 : void HandleWheelCommand( const CommandEvent& rCEvt );
154 :
155 : void SetTextEncoding(rtl_TextEncoding eEncoding);
156 : };
157 :
158 : #endif
159 :
160 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|