Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #ifndef BASCTL_BASIDE2_HXX
21 : : #define BASCTL_BASIDE2_HXX
22 : :
23 : : #include "layout.hxx"
24 : : #include <bastypes.hxx>
25 : : #include <bastype3.hxx>
26 : : #include <basidesh.hxx>
27 : :
28 : : #include <svheader.hxx>
29 : :
30 : : class ExtTextEngine;
31 : : class ExtTextView;
32 : : class SvxSearchItem;
33 : : #include <svtools/svtabbx.hxx>
34 : : #include <svtools/headbar.hxx>
35 : :
36 : : #include <vcl/button.hxx>
37 : : #include <basic/sbstar.hxx>
38 : : #include <basic/sbmod.hxx>
39 : : #include <vcl/split.hxx>
40 : : #include "svl/lstner.hxx"
41 : : #include <svtools/colorcfg.hxx>
42 : :
43 : : #include <sfx2/progress.hxx>
44 : : #include <unotools/options.hxx>
45 : :
46 : : #include "breakpoint.hxx"
47 : : #include "linenumberwindow.hxx"
48 : : #include <set>
49 : :
50 : : #define MARKER_NOMARKER 0xFFFF
51 : :
52 : : namespace com { namespace sun { namespace star { namespace beans {
53 : : class XMultiPropertySet;
54 : : } } } }
55 : :
56 : : namespace basctl
57 : : {
58 : :
59 : : class ObjectCatalog;
60 : :
61 : : DBG_NAMEEX( ModulWindow )
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 : 0 : 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 : : inline void StepProgress();
78 : : };
79 : :
80 : 0 : inline ProgressInfo::ProgressInfo( SfxObjectShell* pObjSh, const String& rText, sal_uLong nRange )
81 : 0 : : SfxProgress( pObjSh, rText, nRange )
82 : : {
83 : 0 : nCurState = 0;
84 : 0 : }
85 : :
86 : 0 : inline void ProgressInfo::StepProgress()
87 : : {
88 : 0 : SetState( ++nCurState );
89 : 0 : }
90 : :
91 : : typedef std::set<sal_uInt16> SyntaxLineSet;
92 : :
93 : : class EditorWindow : public Window, public SfxListener
94 : : {
95 : : private:
96 : : class ChangesListener;
97 : :
98 : : ExtTextView* pEditView;
99 : : ExtTextEngine* pEditEngine;
100 : : ModulWindow& rModulWindow;
101 : :
102 : : rtl::Reference< ChangesListener > listener_;
103 : : osl::Mutex mutex_;
104 : : com::sun::star::uno::Reference< com::sun::star::beans::XMultiPropertySet >
105 : : notifier_;
106 : :
107 : : long nCurTextWidth;
108 : :
109 : : SyntaxHighlighter aHighlighter;
110 : : Timer aSyntaxIdleTimer;
111 : : SyntaxLineSet aSyntaxLineTable;
112 : : DECL_LINK(SyntaxTimerHdl, void *);
113 : : ProgressInfo* pProgress;
114 : :
115 : : virtual void DataChanged(DataChangedEvent const & rDCEvt);
116 : :
117 : : using Window::Notify;
118 : : virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
119 : :
120 : : void ImpDoHighlight( sal_uLong nLineOff );
121 : : void ImplSetFont();
122 : :
123 : : bool bHighlightning;
124 : : bool bDoSyntaxHighlight;
125 : : bool bDelayHighlight;
126 : :
127 : : virtual
128 : : ::com::sun::star::uno::Reference< ::com::sun::star::awt::XWindowPeer >
129 : : GetComponentInterface(sal_Bool bCreate = true);
130 : :
131 : : protected:
132 : : virtual void Paint( const Rectangle& );
133 : : virtual void Resize();
134 : : virtual void KeyInput( const KeyEvent& rKeyEvt );
135 : : virtual void MouseMove( const MouseEvent& rMEvt );
136 : : virtual void MouseButtonDown( const MouseEvent& rMEvt );
137 : : virtual void MouseButtonUp( const MouseEvent& rMEvt );
138 : : virtual void Command( const CommandEvent& rCEvt );
139 : : virtual void LoseFocus();
140 : : virtual void RequestHelp( const HelpEvent& rHEvt );
141 : :
142 : : void DoSyntaxHighlight( sal_uLong nPara );
143 : : String GetWordAtCursor();
144 : : bool ImpCanModify();
145 : :
146 : : public:
147 : : EditorWindow (Window* pParent, ModulWindow*);
148 : : ~EditorWindow();
149 : :
150 : 0 : ExtTextEngine* GetEditEngine() const { return pEditEngine; }
151 : 0 : ExtTextView* GetEditView() const { return pEditView; }
152 : : ProgressInfo* GetProgress() const { return pProgress; }
153 : :
154 : : void CreateProgress( const String& rText, sal_uLong nRange );
155 : : void DestroyProgress();
156 : :
157 : : void ParagraphInsertedDeleted( sal_uLong nNewPara, bool bInserted );
158 : : void DoDelayedSyntaxHighlight( sal_uLong nPara );
159 : :
160 : : void CreateEditEngine();
161 : : void SetScrollBarRanges();
162 : : void InitScrollBars();
163 : :
164 : : void ForceSyntaxTimeout();
165 : : bool SetSourceInBasic();
166 : :
167 : 0 : bool CanModify() { return ImpCanModify(); }
168 : :
169 : : void UpdateSyntaxHighlighting ();
170 : : };
171 : :
172 : :
173 : : class BreakPointWindow : public Window
174 : : {
175 : : private:
176 : : ModulWindow& rModulWindow;
177 : : long nCurYOffset;
178 : : sal_uInt16 nMarkerPos;
179 : : BreakPointList aBreakPointList;
180 : : bool bErrorMarker;
181 : :
182 : : virtual void DataChanged(DataChangedEvent const & rDCEvt);
183 : :
184 : : void setBackgroundColor(Color aColor);
185 : :
186 : : protected:
187 : : virtual void Paint( const Rectangle& );
188 : : virtual void Resize();
189 : : BreakPoint* FindBreakPoint( const Point& rMousePos );
190 : : void ShowMarker( bool bShow );
191 : : virtual void MouseButtonDown( const MouseEvent& rMEvt );
192 : : virtual void Command( const CommandEvent& rCEvt );
193 : :
194 : : bool SyncYOffset();
195 : :
196 : : public:
197 : : BreakPointWindow (Window* pParent, ModulWindow*);
198 : : ~BreakPointWindow();
199 : :
200 : : void SetMarkerPos( sal_uInt16 nLine, bool bErrorMarker = false );
201 : :
202 : : void DoScroll( long nHorzScroll, long nVertScroll );
203 : 0 : long& GetCurYOffset() { return nCurYOffset; }
204 : 0 : BreakPointList& GetBreakPoints() { return aBreakPointList; }
205 : : };
206 : :
207 : :
208 : : class WatchTreeListBox : public SvHeaderTabListBox
209 : : {
210 : : String aEditingRes;
211 : :
212 : : protected:
213 : : virtual sal_Bool EditingEntry( SvLBoxEntry* pEntry, Selection& rSel );
214 : : virtual sal_Bool EditedEntry( SvLBoxEntry* pEntry, const rtl::OUString& rNewText );
215 : :
216 : : bool ImplBasicEntryEdited( SvLBoxEntry* pEntry, const String& rResult );
217 : : SbxBase* ImplGetSBXForEntry( SvLBoxEntry* pEntry, bool& rbArrayElement );
218 : :
219 : : public:
220 : : WatchTreeListBox( Window* pParent, WinBits nWinBits );
221 : : ~WatchTreeListBox();
222 : :
223 : : void RequestingChildren( SvLBoxEntry * pParent );
224 : : void UpdateWatches( bool bBasicStopped = false );
225 : :
226 : : using SvTabListBox::SetTabs;
227 : : virtual void SetTabs();
228 : : };
229 : :
230 : :
231 : :
232 : : class WatchWindow : public BasicDockingWindow
233 : : {
234 : : private:
235 : : String aWatchStr;
236 : : ExtendedEdit aXEdit;
237 : : ImageButton aRemoveWatchButton;
238 : : WatchTreeListBox aTreeListBox;
239 : : HeaderBar aHeaderBar;
240 : :
241 : : protected:
242 : : virtual void Resize();
243 : : virtual void Paint( const Rectangle& rRect );
244 : :
245 : : DECL_LINK( ButtonHdl, ImageButton * );
246 : : DECL_LINK(TreeListHdl, void *);
247 : : DECL_LINK( implEndDragHdl, HeaderBar * );
248 : : DECL_LINK( EditAccHdl, Accelerator * );
249 : :
250 : :
251 : : public:
252 : : WatchWindow (Layout* pParent);
253 : : ~WatchWindow();
254 : :
255 : : void AddWatch( const String& rVName );
256 : : bool RemoveSelectedWatch();
257 : : void UpdateWatches( bool bBasicStopped = false );
258 : :
259 : : WatchTreeListBox& GetWatchTreeListBox() { return aTreeListBox; }
260 : : };
261 : :
262 : :
263 : : class StackWindow : public BasicDockingWindow
264 : : {
265 : : private:
266 : : SvTreeListBox aTreeListBox;
267 : : String aStackStr;
268 : :
269 : : protected:
270 : : virtual void Resize();
271 : : virtual void Paint( const Rectangle& rRect );
272 : :
273 : : public:
274 : : StackWindow (Layout* pParent);
275 : : ~StackWindow();
276 : :
277 : : void UpdateCalls();
278 : : };
279 : :
280 : :
281 : 0 : class ComplexEditorWindow : public Window
282 : : {
283 : : private:
284 : : BreakPointWindow aBrkWindow;
285 : : LineNumberWindow aLineNumberWindow;
286 : : EditorWindow aEdtWindow;
287 : : ScrollBar aEWVScrollBar;
288 : :
289 : : virtual void DataChanged(DataChangedEvent const & rDCEvt);
290 : :
291 : : protected:
292 : : virtual void Resize();
293 : : DECL_LINK( ScrollHdl, ScrollBar * );
294 : :
295 : : public:
296 : : ComplexEditorWindow( ModulWindow* pParent );
297 : :
298 : 0 : BreakPointWindow& GetBrkWindow() { return aBrkWindow; }
299 : 0 : LineNumberWindow& GetLineNumberWindow() { return aLineNumberWindow; }
300 : 0 : EditorWindow& GetEdtWindow() { return aEdtWindow; }
301 : 0 : ScrollBar& GetEWVScrollBar() { return aEWVScrollBar; }
302 : :
303 : : void SetLineNumberDisplay(bool b);
304 : : };
305 : :
306 : :
307 : : class ModulWindow: public IDEBaseWindow
308 : : {
309 : : private:
310 : : ModulWindowLayout& rLayout;
311 : : StarBASICRef xBasic;
312 : : short nValid;
313 : : ComplexEditorWindow aXEditorWindow;
314 : : BasicStatus aStatus;
315 : : SbModuleRef xModule;
316 : : ::rtl::OUString aCurPath;
317 : : ::rtl::OUString m_aModule;
318 : :
319 : : void CheckCompileBasic();
320 : : bool BasicExecute();
321 : :
322 : : void GoOnTop();
323 : :
324 : : sal_Int32 FormatAndPrint( Printer* pPrinter, sal_Int32 nPage = -1 );
325 : : SbModuleRef XModule();
326 : : protected:
327 : : virtual void Resize();
328 : : virtual void GetFocus();
329 : : virtual void Paint( const Rectangle& );
330 : : virtual void DoInit();
331 : : virtual void DoScroll( ScrollBar* pCurScrollBar );
332 : :
333 : : public:
334 : : TYPEINFO();
335 : :
336 : : ModulWindow( ModulWindowLayout* pParent, const ScriptDocument& rDocument, ::rtl::OUString aLibName, ::rtl::OUString aName, ::rtl::OUString& aModule );
337 : :
338 : : ~ModulWindow();
339 : :
340 : : virtual void ExecuteCommand (SfxRequest& rReq);
341 : : virtual void ExecuteGlobal (SfxRequest& rReq);
342 : : virtual void GetState( SfxItemSet& );
343 : : virtual void StoreData();
344 : : virtual void UpdateData();
345 : : virtual bool CanClose();
346 : : // return number of pages to be printed
347 : : virtual sal_Int32 countPages( Printer* pPrinter );
348 : : // print page
349 : : virtual void printPage( sal_Int32 nPage, Printer* pPrinter );
350 : : virtual ::rtl::OUString GetTitle();
351 : : virtual BasicEntryDescriptor CreateEntryDescriptor();
352 : : virtual bool AllowUndo();
353 : : virtual void SetReadOnly (bool bReadOnly);
354 : : virtual bool IsReadOnly();
355 : :
356 : 0 : StarBASIC* GetBasic() { XModule(); return xBasic; }
357 : :
358 : : SbModule* GetSbModule() { return xModule; }
359 : 0 : void SetSbModule( SbModule* pModule ) { xModule = pModule; }
360 : : ::rtl::OUString GetSbModuleName();
361 : :
362 : : bool CompileBasic();
363 : : bool BasicRun();
364 : : bool BasicStepOver();
365 : : bool BasicStepInto();
366 : : bool BasicStepOut();
367 : : void BasicStop();
368 : : bool BasicToggleBreakPoint();
369 : : void BasicToggleBreakPointEnabled();
370 : : void ManageBreakPoints();
371 : : void UpdateBreakPoint( const BreakPoint& rBrk );
372 : : void BasicAddWatch();
373 : : void BasicRemoveWatch();
374 : :
375 : : long BasicErrorHdl( StarBASIC* pBasic );
376 : : long BasicBreakHdl( StarBASIC* pBasic );
377 : : void AssertValidEditEngine();
378 : :
379 : : bool LoadBasic();
380 : : bool SaveBasicSource();
381 : : bool ImportDialog();
382 : :
383 : : void EditMacro( const String& rMacroName );
384 : :
385 : : bool ToggleBreakPoint( sal_uLong nLine );
386 : :
387 : 0 : BasicStatus& GetBasicStatus() { return aStatus; }
388 : :
389 : : virtual bool IsModified ();
390 : : virtual bool IsPasteAllowed ();
391 : :
392 : : void FrameWindowMoved();
393 : : void ShowCursor( bool bOn );
394 : :
395 : : virtual sal_uInt16 GetSearchOptions();
396 : : virtual sal_uInt16 StartSearchAndReplace (SvxSearchItem const&, bool bFromStart = false);
397 : :
398 : 0 : EditorWindow& GetEditorWindow() { return aXEditorWindow.GetEdtWindow(); }
399 : 0 : BreakPointWindow& GetBreakPointWindow() { return aXEditorWindow.GetBrkWindow(); }
400 : 0 : LineNumberWindow& GetLineNumberWindow() { return aXEditorWindow.GetLineNumberWindow(); }
401 : 0 : ScrollBar& GetEditVScrollBar() { return aXEditorWindow.GetEWVScrollBar(); }
402 : 0 : ExtTextEngine* GetEditEngine() { return GetEditorWindow().GetEditEngine(); }
403 : 0 : ExtTextView* GetEditView() { return GetEditorWindow().GetEditView(); }
404 : 0 : BreakPointList& GetBreakPoints() { return GetBreakPointWindow().GetBreakPoints(); }
405 : 0 : ModulWindowLayout& GetLayout () { return rLayout; }
406 : :
407 : : virtual void BasicStarted();
408 : : virtual void BasicStopped();
409 : :
410 : : virtual ::svl::IUndoManager*
411 : : GetUndoManager();
412 : :
413 : 0 : const ::rtl::OUString& GetModule() const { return m_aModule; }
414 : 0 : void SetModule( const ::rtl::OUString& aModule ) { m_aModule = aModule; }
415 : :
416 : : virtual void Activating ();
417 : : virtual void Deactivating ();
418 : :
419 : : virtual void OnNewDocument ();
420 : : virtual char const* GetHid () const;
421 : : virtual BasicIDEType GetType () const;
422 : : virtual bool HasActiveEditor () const;
423 : :
424 : : void UpdateModule ();
425 : : };
426 : :
427 : 0 : class ModulWindowLayout: public Layout
428 : : {
429 : : public:
430 : : ModulWindowLayout (Window* pParent, ObjectCatalog&);
431 : : public:
432 : : // Layout:
433 : : virtual void Activating (IDEBaseWindow&);
434 : : virtual void Deactivating ();
435 : : virtual void GetState (SfxItemSet&, unsigned nWhich);
436 : : virtual void UpdateDebug (bool bBasicStopped);
437 : : public:
438 : : void BasicAddWatch (String const&);
439 : : void BasicRemoveWatch ();
440 : 0 : Color GetSyntaxColor (TokenTypes eType) const { return aSyntaxColors.GetColor(eType); }
441 : :
442 : : protected:
443 : : // Window:
444 : : virtual void Paint (const Rectangle& rRect);
445 : : // Layout:
446 : : virtual void OnFirstSize (int nWidth, int nHeight);
447 : :
448 : : private:
449 : : // main child window
450 : : ModulWindow* pChild;
451 : : // dockable windows
452 : : WatchWindow aWatchWindow;
453 : : StackWindow aStackWindow;
454 : : ObjectCatalog& rObjectCatalog;
455 : : private:
456 : : virtual void DataChanged (DataChangedEvent const& rDCEvt);
457 : : private:
458 : : // SyntaxColors -- stores Basic syntax highlighting colors
459 : : class SyntaxColors : public utl::ConfigurationListener
460 : : {
461 : : public:
462 : : SyntaxColors ();
463 : : ~SyntaxColors ();
464 : : public:
465 : 0 : void SetActiveEditor (EditorWindow* pEditor_) { pEditor = pEditor_; }
466 : : void SettingsChanged ();
467 : : public:
468 : 0 : Color GetColor (TokenTypes eType) const { return aColors[eType]; }
469 : :
470 : : private:
471 : : virtual void ConfigurationChanged (utl::ConfigurationBroadcaster*, sal_uInt32);
472 : : void NewConfig (bool bFirst);
473 : :
474 : : private:
475 : : // the color values (the indexes are TokenTypes, see svtools/syntaxhighlight.hxx)
476 : : Color aColors[TT_KEYWORDS + 1];
477 : : // the configuration
478 : : svtools::ColorConfig aConfig;
479 : : // the active editor
480 : : EditorWindow* pEditor;
481 : :
482 : : } aSyntaxColors;
483 : : };
484 : :
485 : : } // namespace basctl
486 : :
487 : : #endif // BASCTL_BASIDE2_HXX
488 : :
489 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|