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 _XMLFILEVIEW_HXX
24 #define _XMLFILEVIEW_HXX
25 
26 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
27 #include <svl/lstner.hxx>
28 #include <vcl/timer.hxx>
29 
30 #ifndef _TABLE_HXX //autogen
31 #include <tools/table.hxx>
32 #endif
33 #include <svtools/xtextedt.hxx>
34 #include <vcl/timer.hxx>
35 #ifndef _TABLE_HXX //autogen
36 #include <tools/table.hxx>
37 #endif
38 #include <vcl/wrkwin.hxx>
39 #include <vcl/ctrl.hxx>
40 #ifndef _SV_BUTTON_HXX
41 #include <vcl/button.hxx>
42 #endif
43 #include <vcl/lstbox.hxx>
44 
45 class ScrollBar;
46 class XMLFileWindow;
47 class TextEngine;
48 class TextView;
49 class DataChangedEvent;
50 class filter_info_impl;
51 
52 class TextViewOutWin : public Window
53 {
54 	TextView*	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:
TextViewOutWin(Window * pParent,WinBits nBits)66 		TextViewOutWin(Window* pParent, WinBits nBits) :
67 			Window(pParent, nBits), pTextView(0){}
68 
SetTextView(TextView * pView)69 	void	SetTextView( TextView* pView ) {pTextView = pView;}
70 
71 };
72 
73 //------------------------------------------------------------
74 
75 class XMLFileWindow : public Window, public SfxListener
76 {
77 	using Window::Notify;
78 
79 private:
80 	TextView*	pTextView;
81 	TextEngine*	pTextEngine;
82 
83 	TextViewOutWin*	pOutWin;
84 	ScrollBar	   	*pHScrollbar,
85 					*pVScrollbar;
86 
87 	long			nCurTextWidth;
88 	sal_uInt16			nStartLine;
89     rtl_TextEncoding eSourceEncoding;
90 
91 	Timer			aSyntaxIdleTimer;
92 	Table			aSyntaxLineTable;
93 
94 	bool			bHighlighting;
95 protected:
96 	DECL_LINK( SyntaxTimerHdl, Timer * );
97 	void			ImpDoHighlight( const String& rSource, sal_uInt16 nLineOff );
98 
99 	virtual void	Resize();
100 	virtual void	DataChanged( const DataChangedEvent& );
101 	virtual void 	GetFocus();
102 
103 	void 			CreateTextEngine();
104 
105 	virtual void	Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
106 
107 	DECL_LINK(ScrollHdl, ScrollBar*);
108 
109 	void			DoDelayedSyntaxHighlight( sal_uInt16 nPara );
110 
111 	void			DoSyntaxHighlight( sal_uInt16 nPara );
112 
113 public:
114 					XMLFileWindow( Window* pParent );
115 					~XMLFileWindow();
116 
117 	void			SetScrollBarRanges();
118 	void			InitScrollBars();
Read(SvStream & rInput)119 	sal_uLong			Read( SvStream& rInput)		{ return pTextEngine->Read(rInput); }
120 
121 	void			ShowWindow( const rtl::OUString& rFileName );
122 
GetTextView()123 	TextView*		GetTextView()				{ return pTextView; }
GetTextEngine()124 	TextEngine*		GetTextEngine()				{ return pTextEngine; }
125 
GetOutWin()126 	TextViewOutWin*	GetOutWin()					{ return pOutWin; }
127 	void			InvalidateWindow();
128 
129 	void			CreateScrollbars();
130 
SetStartLine(sal_uInt16 nLine)131 	void			SetStartLine(sal_uInt16 nLine)	{nStartLine = nLine;}
132 
133 	virtual void	Command( const CommandEvent& rCEvt );
134 	void 			HandleWheelCommand( const CommandEvent& rCEvt );
135 
getTextView()136 	TextView*		getTextView() { return pTextView; }
137 
138 	void			showLine( sal_Int32 nLine );
139 };
140 
141 class XMLSourceFileDialog : public WorkWindow
142 {
143 
144 public:
145 				XMLSourceFileDialog( Window* pParent, ResMgr& rResMgr, const com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory >& rxMSF  );
146 	virtual		~XMLSourceFileDialog();
147 
148 	void		ShowWindow( const rtl::OUString& rFileName, const filter_info_impl* pFilterInfo );
149 
150 	virtual void	Resize();
151 
152 	DECL_LINK(ClickHdl_Impl, PushButton * );
153 	DECL_LINK(SelectHdl_Impl, ListBox * );
154 
155 	void		showLine( sal_Int32 nLine );
156 
157 	sal_Int32	mnOutputHeight;
158 private:
159 	void		onValidate();
160 
161 	const filter_info_impl* mpFilterInfo;
162 	rtl::OUString	maFileURL;
163 
164 	com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > mxMSF;
165 	ResMgr&			mrResMgr;
166 
167 	XMLFileWindow*	mpTextWindow;
168 	ListBox			maLBOutput;
169 //	Control			maCtrlSourceView;
170 	PushButton		maPBValidate;
171 };
172 
173 #endif
174