1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #ifndef _SRCEDTW_HXX 24 #define _SRCEDTW_HXX 25 26 #include <vcl/window.hxx> 27 #include <svl/lstner.hxx> 28 #include <unotools/options.hxx> 29 #include <vcl/timer.hxx> 30 31 #ifndef _TABLE_HXX //autogen 32 #include <tools/table.hxx> 33 #endif 34 #include <svtools/xtextedt.hxx> 35 36 class ScrollBar; 37 class SwSrcView; 38 class SwSrcEditWindow; 39 class TextEngine; 40 class ExtTextView; 41 class DataChangedEvent; 42 43 namespace utl 44 { 45 class SourceViewConfig; 46 } 47 48 class TextViewOutWin : public Window 49 { 50 ExtTextView* pTextView; 51 52 protected: 53 virtual void Paint( const Rectangle& ); 54 virtual void KeyInput( const KeyEvent& rKeyEvt ); 55 virtual void MouseMove( const MouseEvent& rMEvt ); 56 virtual void MouseButtonDown( const MouseEvent& rMEvt ); 57 virtual void MouseButtonUp( const MouseEvent& rMEvt ); 58 virtual void Command( const CommandEvent& rCEvt ); 59 virtual void DataChanged( const DataChangedEvent& ); 60 61 public: TextViewOutWin(Window * pParent,WinBits nBits)62 TextViewOutWin(Window* pParent, WinBits nBits) : 63 Window(pParent, nBits), pTextView(0){} 64 SetTextView(ExtTextView * pView)65 void SetTextView( ExtTextView* pView ) {pTextView = pView;} 66 67 }; 68 69 //------------------------------------------------------------ 70 namespace svt{ class SourceViewConfig;} 71 class SwSrcEditWindow : public Window, public SfxListener, public utl::ConfigurationListener 72 { 73 private: 74 ExtTextView* pTextView; 75 ExtTextEngine* pTextEngine; 76 77 TextViewOutWin* pOutWin; 78 ScrollBar *pHScrollbar, 79 *pVScrollbar; 80 81 SwSrcView* pSrcView; 82 utl::SourceViewConfig* pSourceViewConfig; 83 84 long nCurTextWidth; 85 sal_uInt16 nStartLine; 86 rtl_TextEncoding eSourceEncoding; 87 sal_Bool bReadonly; 88 sal_Bool bDoSyntaxHighlight; 89 sal_Bool bHighlighting; 90 91 Timer aSyntaxIdleTimer; 92 Table aSyntaxLineTable; 93 94 void ImpDoHighlight( const String& rSource, sal_uInt16 nLineOff ); 95 96 using OutputDevice::SetFont; 97 void SetFont(); 98 99 DECL_LINK( SyntaxTimerHdl, Timer * ); 100 DECL_LINK( TimeoutHdl, Timer * ); 101 102 using Window::Notify; 103 using Window::Invalidate; 104 105 protected: 106 107 virtual void Resize(); 108 virtual void DataChanged( const DataChangedEvent& ); 109 virtual void GetFocus(); 110 // virtual void LoseFocus(); 111 112 void CreateTextEngine(); 113 void DoSyntaxHighlight( sal_uInt16 nPara ); 114 115 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); 116 virtual void ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 ); 117 118 DECL_LINK(ScrollHdl, ScrollBar*); 119 120 public: 121 SwSrcEditWindow( Window* pParent, SwSrcView* pParentView ); 122 ~SwSrcEditWindow(); 123 124 void SetScrollBarRanges(); 125 void InitScrollBars(); Read(SvStream & rInput)126 sal_uLong Read( SvStream& rInput) 127 {return pTextEngine->Read(rInput);} Write(SvStream & rOutput)128 sal_uLong Write( SvStream& rOutput) 129 {return pTextEngine->Write(rOutput);} 130 GetTextView()131 ExtTextView* GetTextView() 132 {return pTextView;} GetTextEngine()133 TextEngine* GetTextEngine() 134 {return pTextEngine;} GetSrcView()135 SwSrcView* GetSrcView() {return pSrcView;} 136 GetOutWin()137 TextViewOutWin* GetOutWin() {return pOutWin;} 138 139 virtual void Invalidate( sal_uInt16 nFlags = 0 ); 140 ClearModifyFlag()141 void ClearModifyFlag() 142 { pTextEngine->SetModified(sal_False); } IsModified() const143 sal_Bool IsModified() const 144 { return pTextEngine->IsModified();} 145 void CreateScrollbars(); 146 SetReadonly(sal_Bool bSet)147 void SetReadonly(sal_Bool bSet){bReadonly = bSet;} IsReadonly()148 sal_Bool IsReadonly(){return bReadonly;} 149 150 void DoDelayedSyntaxHighlight( sal_uInt16 nPara ); 151 SetStartLine(sal_uInt16 nLine)152 void SetStartLine(sal_uInt16 nLine){nStartLine = nLine;} 153 154 virtual void Command( const CommandEvent& rCEvt ); 155 void HandleWheelCommand( const CommandEvent& rCEvt ); 156 157 void SetTextEncoding(rtl_TextEncoding eEncoding); 158 }; 159 160 #endif 161