xref: /trunk/main/sw/source/ui/inc/srcedtw.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _SRCEDTW_HXX
28 #define _SRCEDTW_HXX
29 
30 #include <vcl/window.hxx>
31 #include <svl/lstner.hxx>
32 #include <unotools/options.hxx>
33 #include <vcl/timer.hxx>
34 
35 #ifndef _TABLE_HXX //autogen
36 #include <tools/table.hxx>
37 #endif
38 #include <svtools/xtextedt.hxx>
39 
40 class ScrollBar;
41 class SwSrcView;
42 class SwSrcEditWindow;
43 class TextEngine;
44 class ExtTextView;
45 class DataChangedEvent;
46 
47 namespace utl
48 {
49     class SourceViewConfig;
50 }
51 
52 class TextViewOutWin : public Window
53 {
54     ExtTextView*    pTextView;
55 
56 protected:
57     virtual void    Paint( const Rectangle& );
58     virtual void    KeyInput( const KeyEvent& rKeyEvt );
59     virtual void    MouseMove( const MouseEvent& rMEvt );
60     virtual void    MouseButtonDown( const MouseEvent& rMEvt );
61     virtual void    MouseButtonUp( const MouseEvent& rMEvt );
62     virtual void    Command( const CommandEvent& rCEvt );
63     virtual void    DataChanged( const DataChangedEvent& );
64 
65 public:
66         TextViewOutWin(Window* pParent, WinBits nBits) :
67             Window(pParent, nBits), pTextView(0){}
68 
69     void    SetTextView( ExtTextView* pView ) {pTextView = pView;}
70 
71 };
72 
73 //------------------------------------------------------------
74 namespace svt{ class SourceViewConfig;}
75 class SwSrcEditWindow : public Window, public SfxListener, public utl::ConfigurationListener
76 {
77 private:
78     ExtTextView*    pTextView;
79     ExtTextEngine*  pTextEngine;
80 
81     TextViewOutWin* pOutWin;
82     ScrollBar       *pHScrollbar,
83                     *pVScrollbar;
84 
85     SwSrcView*      pSrcView;
86     utl::SourceViewConfig* pSourceViewConfig;
87 
88     long            nCurTextWidth;
89     sal_uInt16          nStartLine;
90     rtl_TextEncoding eSourceEncoding;
91     sal_Bool            bReadonly;
92     sal_Bool            bDoSyntaxHighlight;
93     sal_Bool            bHighlighting;
94 
95     Timer           aSyntaxIdleTimer;
96     Table           aSyntaxLineTable;
97 
98     void            ImpDoHighlight( const String& rSource, sal_uInt16 nLineOff );
99 
100     using OutputDevice::SetFont;
101     void            SetFont();
102 
103     DECL_LINK( SyntaxTimerHdl, Timer * );
104     DECL_LINK( TimeoutHdl, Timer * );
105 
106     using Window::Notify;
107     using Window::Invalidate;
108 
109 protected:
110 
111     virtual void    Resize();
112     virtual void    DataChanged( const DataChangedEvent& );
113     virtual void    GetFocus();
114 //  virtual void    LoseFocus();
115 
116     void            CreateTextEngine();
117     void            DoSyntaxHighlight( sal_uInt16 nPara );
118 
119     virtual void    Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
120     virtual void    ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 );
121 
122     DECL_LINK(ScrollHdl, ScrollBar*);
123 
124 public:
125                     SwSrcEditWindow( Window* pParent, SwSrcView* pParentView );
126                     ~SwSrcEditWindow();
127 
128     void            SetScrollBarRanges();
129     void            InitScrollBars();
130     sal_uLong           Read( SvStream& rInput)
131                         {return pTextEngine->Read(rInput);}
132     sal_uLong           Write( SvStream& rOutput)
133                         {return pTextEngine->Write(rOutput);}
134 
135     ExtTextView*    GetTextView()
136                         {return pTextView;}
137     TextEngine*     GetTextEngine()
138                         {return pTextEngine;}
139     SwSrcView*      GetSrcView() {return pSrcView;}
140 
141     TextViewOutWin* GetOutWin() {return pOutWin;}
142 
143     virtual void    Invalidate( sal_uInt16 nFlags = 0 );
144 
145     void            ClearModifyFlag()
146                         { pTextEngine->SetModified(sal_False); }
147     sal_Bool            IsModified() const
148                         { return pTextEngine->IsModified();}
149     void            CreateScrollbars();
150 
151     void            SetReadonly(sal_Bool bSet){bReadonly = bSet;}
152     sal_Bool            IsReadonly(){return bReadonly;}
153 
154     void            DoDelayedSyntaxHighlight( sal_uInt16 nPara );
155 
156     void            SetStartLine(sal_uInt16 nLine){nStartLine = nLine;}
157 
158     virtual void    Command( const CommandEvent& rCEvt );
159     void            HandleWheelCommand( const CommandEvent& rCEvt );
160 
161     void            SetTextEncoding(rtl_TextEncoding eEncoding);
162 };
163 
164 #endif
165