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