xref: /aoo42x/main/basctl/source/basicide/baside2.hxx (revision 96821c26)
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 
24 #ifndef _BASIDE2_HXX
25 #define _BASIDE2_HXX
26 
27 #include <svheader.hxx>
28 
29 #include <bastypes.hxx>
30 #include <bastype3.hxx>
31 #include <basidesh.hxx>
32 
33 class ExtTextEngine;
34 class ExtTextView;
35 class SvxSearchItem;
36 #include <svtools/svtabbx.hxx>
37 #include <svtools/headbar.hxx>
38 
39 #ifndef _SV_BUTTON_HXX //autogen
40 #include <vcl/button.hxx>
41 #endif
42 #include <basic/sbmod.hxx>
43 #include <vcl/split.hxx>
44 #include "svl/lstner.hxx"
45 #include <svtools/colorcfg.hxx>
46 
47 #include <sfx2/progress.hxx>
48 #include <svtools/syntaxhighlight.hxx>
49 
50 DBG_NAMEEX( ModulWindow )
51 
52 #define MARKER_NOMARKER	0xFFFF
53 
54 namespace utl
55 {
56     class SourceViewConfig;
57 }
58 
59 // #108672 Helper functions to get/set text in TextEngine
60 // using the stream interface (get/setText() only supports
61 // tools Strings limited to 64K).
62 ::rtl::OUString getTextEngineText( ExtTextEngine* pEngine );
63 void setTextEngineText( ExtTextEngine* pEngine, const ::rtl::OUString aStr );
64 
65 class ProgressInfo : public SfxProgress
66 {
67 private:
68 	sal_uLong					nCurState;
69 
70 public:
71 
72 	inline			ProgressInfo( SfxObjectShell* pObjSh, const String& rText, sal_uLong nRange );
73 
74 //	inline void		StartProgress( const String& rName, sal_uLong nStates );
75 //	inline void		EndProgress();
76 	inline void		StepProgress();
77 };
78 
ProgressInfo(SfxObjectShell * pObjSh,const String & rText,sal_uLong nRange)79 inline ProgressInfo::ProgressInfo( SfxObjectShell* pObjSh, const String& rText, sal_uLong nRange )
80 	: SfxProgress( pObjSh, rText, nRange )
81 {
82 	nCurState = 0;
83 }
84 
85 // inline void ProgressInfo::StartProgress( const String& rName, sal_uLong nStates )
86 // {
87 // 	nCurState = 0;
88 // 	if ( pStbMgr )
89 // 		pStbMgr->StartProgressMode( rName, nStates );
90 // }
91 
92 // inline void ProgressInfo::EndProgress()
93 // {
94 // 	if ( pStbMgr )
95 // 		pStbMgr->EndProgressMode();
96 //}
97 
StepProgress()98 inline void ProgressInfo::StepProgress()
99 {
100 	SetState( ++nCurState );
101 }
102 
103 
104 namespace svt {
105 class SourceViewConfig;
106 }
107 
108 class EditorWindow : public Window, public SfxListener, public utl::ConfigurationListener
109 {
110 private:
111 	ExtTextView*	pEditView;
112 	ExtTextEngine*	pEditEngine;
113 
114     utl::SourceViewConfig* pSourceViewConfig;
115 
116 	long			nCurTextWidth;
117 
118 	SyntaxHighlighter	aHighlighter;
119 	Timer			aSyntaxIdleTimer;
120 	Table			aSyntaxLineTable;
121 	DECL_LINK( SyntaxTimerHdl, Timer * );
122 	ProgressInfo*	pProgress;
123 	ModulWindow*	pModulWindow;
124 
125     virtual void DataChanged(DataChangedEvent const & rDCEvt);
126 
127 	using			Window::Notify;
128 	virtual void	Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
129 
130 	void			ImpDoHighlight( sal_uLong nLineOff );
131     void            ImplSetFont();
132 
133 	sal_Bool			bHighlightning;
134 	sal_Bool			bDoSyntaxHighlight;
135 	sal_Bool			bDelayHighlight;
136 
137     virtual
138     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >
139     GetComponentInterface(sal_Bool bCreate = sal_True);
140 
141 protected:
142 	virtual void	Paint( const Rectangle& );
143 	virtual void	Resize();
144 	virtual void	KeyInput( const KeyEvent& rKeyEvt );
145 	virtual void	MouseMove( const MouseEvent& rMEvt );
146 	virtual void	MouseButtonDown( const MouseEvent& rMEvt );
147 	virtual void	MouseButtonUp( const MouseEvent& rMEvt );
148 	virtual void	Command( const CommandEvent& rCEvt );
149 	virtual void	LoseFocus();
150 	virtual void	RequestHelp( const HelpEvent& rHEvt );
151     virtual void    ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 );
152 
153 	void			DoSyntaxHighlight( sal_uLong nPara );
154 	String			GetWordAtCursor();
155 	sal_Bool			ImpCanModify();
156 
157 public:
158 					EditorWindow( Window* pParent );
159 					~EditorWindow();
160 
GetEditEngine() const161 	ExtTextEngine*	GetEditEngine()	const	{ return (ExtTextEngine*)pEditEngine; }
GetEditView() const162 	ExtTextView*	GetEditView() const		{ return pEditView; }
GetProgress() const163 	ProgressInfo*	GetProgress() const		{ return pProgress; }
164 
165 	void			CreateProgress( const String& rText, sal_uLong nRange );
166 	void			DestroyProgress();
167 
168 	void			ParagraphInsertedDeleted( sal_uLong nNewPara, sal_Bool bInserted );
169 	void			DoDelayedSyntaxHighlight( sal_uLong nPara );
170 
171 	void			CreateEditEngine();
172 	void			SetScrollBarRanges();
173 	void			InitScrollBars();
SetModulWindow(ModulWindow * pWin)174 	void			SetModulWindow( ModulWindow* pWin )
175 						{ pModulWindow = pWin; }
176 
177 	void			ForceSyntaxTimeout();
178 	sal_Bool			SetSourceInBasic( sal_Bool bQuiet = sal_True );
179 
CanModify()180 	sal_Bool			CanModify() { return ImpCanModify(); }
181 };
182 
183 
184 class BreakPointWindow : public Window
185 {
186 private:
187 	long			nCurYOffset;
188 	sal_uInt16			nMarkerPos;
189 	BreakPointList	aBreakPointList;
190 	ModulWindow*	pModulWindow;
191 	sal_Bool			bErrorMarker;
192     bool m_bHighContrastMode;
193 
194     virtual void DataChanged(DataChangedEvent const & rDCEvt);
195 
196     void setBackgroundColor(Color aColor);
197 
198 protected:
199 	virtual void	Paint( const Rectangle& );
200 	virtual void	Resize();
201 	BreakPoint* 	FindBreakPoint( const Point& rMousePos );
202 	void			ShowMarker( sal_Bool bShow );
203 	virtual void	MouseButtonDown( const MouseEvent& rMEvt );
204 	virtual void	Command( const CommandEvent& rCEvt );
205 
206 	sal_Bool			SyncYOffset();
207 
208 public:
209 					BreakPointWindow( Window* pParent );
210 					~BreakPointWindow();
211 
SetModulWindow(ModulWindow * pWin)212 	void			SetModulWindow( ModulWindow* pWin )
213 						{ pModulWindow = pWin; }
214 
215 	void			SetMarkerPos( sal_uInt16 nLine, sal_Bool bErrorMarker = sal_False );
216 
217 	void			DoScroll( long nHorzScroll, long nVertScroll );
GetCurYOffset()218 	long&			GetCurYOffset() 		{ return nCurYOffset; }
GetBreakPoints()219 	BreakPointList&	GetBreakPoints()		{ return aBreakPointList; }
220 };
221 
222 
223 class WatchTreeListBox : public SvHeaderTabListBox
224 {
225 	String aEditingRes;
226 
227 protected:
228 	virtual sal_Bool	EditingEntry( SvLBoxEntry* pEntry, Selection& rSel  );
229 	virtual sal_Bool	EditedEntry( SvLBoxEntry* pEntry, const String& rNewText );
230 
231 	sal_Bool 			ImplBasicEntryEdited( SvLBoxEntry* pEntry, const String& rResult );
232 	SbxBase*		ImplGetSBXForEntry( SvLBoxEntry* pEntry, bool& rbArrayElement );
233 
234 //	virtual DragDropMode	NotifyBeginDrag( SvLBoxEntry* );
235 //	virtual sal_Bool	NotifyQueryDrop( SvLBoxEntry* );
236 
237 //	virtual sal_Bool	NotifyMoving( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
238 //						SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos );
239 //	virtual sal_Bool	NotifyCopying( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
240 //						SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos );
241 //	sal_Bool			NotifyCopyingMoving( SvLBoxEntry* pTarget, SvLBoxEntry* pEntry,
242 //						SvLBoxEntry*& rpNewParent, sal_uLong& rNewChildPos, sal_Bool bMove );
243 
244 public:
245 	WatchTreeListBox( Window* pParent, WinBits nWinBits );
246 	~WatchTreeListBox();
247 
248 	void			RequestingChilds( SvLBoxEntry * pParent );
249 	void			UpdateWatches( bool bBasicStopped = false );
250 
251 	using			SvTabListBox::SetTabs;
252 	virtual void	SetTabs();
253 };
254 
255 
256 
257 class WatchWindow : public BasicDockingWindow
258 {
259 private:
260 	String				aWatchStr;
261 	ExtendedEdit		aXEdit;
262 	ImageButton 		aRemoveWatchButton;
263 	WatchTreeListBox	aTreeListBox;
264 	HeaderBar			aHeaderBar;
265 
266 protected:
267 	virtual void	Resize();
268 	virtual void	Paint( const Rectangle& rRect );
269 
270 	DECL_LINK( ButtonHdl, ImageButton * );
271 	DECL_LINK( TreeListHdl, SvTreeListBox * );
272 	DECL_LINK( implEndDragHdl, HeaderBar * );
273 	DECL_LINK( EditAccHdl, Accelerator * );
274 
275 
276 public:
277 					WatchWindow( Window* pParent );
278 					~WatchWindow();
279 
280 	void			AddWatch( const String& rVName );
281 	sal_Bool			RemoveSelectedWatch();
282 	void			UpdateWatches( bool bBasicStopped = false );
283 
GetWatchTreeListBox()284 	WatchTreeListBox&	GetWatchTreeListBox() { return aTreeListBox; }
285 };
286 
287 
288 class StackWindow : public BasicDockingWindow
289 {
290 private:
291 	SvTreeListBox	aTreeListBox;
292 	ImageButton 	aGotoCallButton;
293 	String			aStackStr;
294 
295 protected:
296 	virtual void	Resize();
297 	virtual void	Paint( const Rectangle& rRect );
298 	DECL_LINK( ButtonHdl, ImageButton * );
299 
300 public:
301 					StackWindow( Window* pParent );
302 					~StackWindow();
303 
304 	void			UpdateCalls();
305 };
306 
307 
308 class ComplexEditorWindow : public Window
309 {
310 private:
311 	BreakPointWindow	aBrkWindow;
312 	EditorWindow		aEdtWindow;
313 	ScrollBar			aEWVScrollBar;
314 
315     virtual void DataChanged(DataChangedEvent const & rDCEvt);
316 
317 protected:
318 	virtual void		Resize();
319 	DECL_LINK( ScrollHdl, ScrollBar * );
320 
321 public:
322 						ComplexEditorWindow( ModulWindow* pParent );
323 
GetBrkWindow()324 	BreakPointWindow&	GetBrkWindow() 		{ return aBrkWindow; }
GetEdtWindow()325 	EditorWindow&		GetEdtWindow() 		{ return aEdtWindow; }
GetEWVScrollBar()326 	ScrollBar&			GetEWVScrollBar() 	{ return aEWVScrollBar; }
327 };
328 
329 
330 #define SYNTAX_COLOR_MAX	5
331 
332 class ModulWindow: public IDEBaseWindow
333 {
334 	friend class BasicIDEShell;
335 
336 private:
337     StarBASICRef        xBasic;
338 	short				nValid;
339 	ComplexEditorWindow aXEditorWindow;
340 	BasicStatus 		aStatus;
341 	SbModuleRef 		xModule;
342 	ModulWindowLayout*	pLayout;
343 	String				aCurPath;
344     ::rtl::OUString		m_aModule;
345 
346 	DECL_LINK( BasicErrorHdl, StarBASIC * );
347 	long				BasicBreakHdl( StarBASIC* pBasic );
348 
349 	void				CheckCompileBasic();
350 	sal_Bool				BasicExecute();
351 
352 	void				GoOnTop();
353 	void				AssertValidEditEngine();
354 
355     sal_Int32           FormatAndPrint( Printer* pPrinter, sal_Int32 nPage = -1 );
356 	SbModuleRef 		XModule();
357 protected:
358 	virtual void	Resize();
359 	virtual void	GetFocus();
360 	virtual void	Paint( const Rectangle& );
361 	virtual void	Deactivating();
362 	virtual void	DoInit();
363 	virtual void	DoScroll( ScrollBar* pCurScrollBar );
364 
365 public:
366 					TYPEINFO();
367 
368                     ModulWindow( ModulWindowLayout* pParent, const ScriptDocument& rDocument, String aLibName,
369                         String aName, ::rtl::OUString& aModule );
370 
371 					~ModulWindow();
372 
373 	virtual void	ExecuteCommand( SfxRequest& rReq );
374 	virtual void	GetState( SfxItemSet& );
375 	virtual void	StoreData();
376 	virtual void	UpdateData();
377 	virtual sal_Bool 	CanClose();
378 	// virtual void	PrintData( Printer* pPrinter );
379     // return number of pages to be printed
380     virtual sal_Int32 countPages( Printer* pPrinter );
381     // print page
382     virtual void printPage( sal_Int32 nPage, Printer* pPrinter );
383 	virtual String	GetTitle();
384     virtual BasicEntryDescriptor CreateEntryDescriptor();
385 	virtual sal_Bool	AllowUndo();
386 	virtual void	SetReadOnly( sal_Bool bReadOnly );
387     virtual sal_Bool    IsReadOnly();
388 
GetBasic()389     StarBASIC*      GetBasic() { XModule(); return xBasic; }
390 
GetSbModule()391 	SbModule*		GetSbModule() { return xModule; }
SetSbModule(SbModule * pModule)392     void			SetSbModule( SbModule* pModule ) { xModule = pModule; }
393 	String			GetSbModuleName();
394 
395 	sal_Bool			CompileBasic();
396 	sal_Bool			BasicRun();
397 	sal_Bool			BasicStepOver();
398 	sal_Bool			BasicStepInto();
399 	sal_Bool			BasicStepOut();
400 	void			BasicStop();
401 	sal_Bool			BasicToggleBreakPoint();
402 	void			BasicToggleBreakPointEnabled();
403 	void			ManageBreakPoints();
404 	void			UpdateBreakPoint( const BreakPoint& rBrk );
405 	void			BasicAddWatch();
406 	void			BasicRemoveWatch();
407 
408 	sal_Bool			LoadBasic();
409 	sal_Bool			SaveBasicSource();
410 	sal_Bool			ImportDialog();
411 
412 	void			EditMacro( const String& rMacroName );
413 
414 //	void			InsertFromObjectCatalog( ObjectCatalog* pObjDlg );
415 
416 	sal_Bool			ToggleBreakPoint( sal_uLong nLine );
417 
GetBasicStatus()418 	BasicStatus&	GetBasicStatus() { return aStatus; }
419 
420 	virtual sal_Bool	IsModified();
421     virtual sal_Bool    IsPasteAllowed();
422 
423 	void			FrameWindowMoved();
424 	void			ShowCursor( sal_Bool bOn );
425 
426 	virtual sal_uInt16	GetSearchOptions();
427 	sal_uInt16			StartSearchAndReplace( const SvxSearchItem& rSearchItem, sal_Bool bFromStart = sal_False );
428 
429 	virtual Window* GetLayoutWindow();
430 
GetEditorWindow()431 	EditorWindow&		GetEditorWindow() 		{ return aXEditorWindow.GetEdtWindow(); }
GetBreakPointWindow()432 	BreakPointWindow&	GetBreakPointWindow() 	{ return aXEditorWindow.GetBrkWindow(); }
GetEditVScrollBar()433 	ScrollBar&			GetEditVScrollBar() 	{ return aXEditorWindow.GetEWVScrollBar(); }
GetEditEngine()434 	ExtTextEngine*		GetEditEngine() 		{ return GetEditorWindow().GetEditEngine(); }
GetEditView()435 	ExtTextView*		GetEditView() 			{ return GetEditorWindow().GetEditView(); }
GetBreakPoints()436 	BreakPointList& 	GetBreakPoints()		{ return GetBreakPointWindow().GetBreakPoints(); }
GetLayout() const437 	ModulWindowLayout*	GetLayout() const 		{ return pLayout; }
438 
439 	virtual void		BasicStarted();
440 	virtual void		BasicStopped();
441 
442     virtual ::svl::IUndoManager*
443                         GetUndoManager();
444 
GetModule() const445     const ::rtl::OUString&	GetModule() const { return m_aModule; }
SetModule(const::rtl::OUString & aModule)446     void					SetModule( const ::rtl::OUString& aModule ) { m_aModule = aModule; }
447 };
448 
449 class ModulWindowLayout: public Window, public utl::ConfigurationListener
450 {
451 private:
452 
453 	Splitter		aVSplitter;
454 	Splitter		aHSplitter;
455 
456 	WatchWindow 	aWatchWindow;
457 	StackWindow 	aStackWindow;
458 
459 	sal_Bool			bVSplitted;
460 	sal_Bool			bHSplitted;
461 
462     ModulWindow * m_pModulWindow;
463 
464     Color m_aSyntaxColors[TT_KEYWORDS + 1];
465     svtools::ColorConfig m_aColorConfig;
466 
467     ImageList m_aImagesNormal;
468     ImageList m_aImagesHighContrast;
469 
470     virtual void DataChanged(DataChangedEvent const & rDCEvt);
471 
472     virtual void ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 );
473 
474     void updateSyntaxHighlighting();
475 
476     DECL_LINK( SplitHdl, Splitter * );
477 
478     void            ArrangeWindows();
479 
480 protected:
481 	virtual void	Resize();
482 	virtual void	Paint( const Rectangle& rRect );
483 
484 public:
485 					ModulWindowLayout( Window* pParent );
486 					~ModulWindowLayout();
487 
488 	void			DockaWindow( DockingWindow* pDockingWin );
489 	sal_Bool			IsToBeDocked( DockingWindow* pDockingWin, const Point& rPos, Rectangle& rRect );
490 
491 	void			SetModulWindow( ModulWindow* pModWin );
GetModulWindow() const492 	ModulWindow*	GetModulWindow() const { return m_pModulWindow; }
493 
GetWatchWindow()494 	WatchWindow& 	GetWatchWindow()	{ return aWatchWindow; }
GetStackWindow()495 	StackWindow& 	GetStackWindow()	{ return aStackWindow; }
496 
497     Image getImage(sal_uInt16 nId, bool bHighContrastMode) const;
498 
getSyntaxColor(TokenTypes eType) const499     inline Color const & getSyntaxColor(TokenTypes eType) const
500     { return m_aSyntaxColors[eType]; }
501 };
502 
503 #endif	// _BASIDE2_HXX
504