131598a22SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
331598a22SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
431598a22SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
531598a22SAndrew Rist  * distributed with this work for additional information
631598a22SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
731598a22SAndrew Rist  * to you under the Apache License, Version 2.0 (the
831598a22SAndrew Rist  * "License"); you may not use this file except in compliance
931598a22SAndrew Rist  * with the License.  You may obtain a copy of the License at
1031598a22SAndrew Rist  *
1131598a22SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1231598a22SAndrew Rist  *
1331598a22SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1431598a22SAndrew Rist  * software distributed under the License is distributed on an
1531598a22SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1631598a22SAndrew Rist  * KIND, either express or implied.  See the License for the
1731598a22SAndrew Rist  * specific language governing permissions and limitations
1831598a22SAndrew Rist  * under the License.
1931598a22SAndrew Rist  *
2031598a22SAndrew Rist  *************************************************************/
2131598a22SAndrew Rist 
2231598a22SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_basctl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <vector>
28cdf0e10cSrcweir #define _BASIC_TEXTPORTIONS
29cdf0e10cSrcweir #include <basic/sbdef.hxx>
30cdf0e10cSrcweir #include <ide_pch.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <tools/urlobj.hxx>
34cdf0e10cSrcweir #include <unotools/charclass.hxx>
35cdf0e10cSrcweir #include <svl/urihelper.hxx>
36cdf0e10cSrcweir #include <basic/sbx.hxx>
37cdf0e10cSrcweir #include <vcl/sound.hxx>
38cdf0e10cSrcweir #include <svtools/xtextedt.hxx>
39cdf0e10cSrcweir #include <svtools/txtattr.hxx>
40cdf0e10cSrcweir #include <svtools/textwindowpeer.hxx>
41cdf0e10cSrcweir #include <basic/sbuno.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #include <helpid.hrc>
44cdf0e10cSrcweir #include <baside2.hrc>
45cdf0e10cSrcweir #include <baside2.hxx>
46cdf0e10cSrcweir #include <brkdlg.hxx>
47cdf0e10cSrcweir #include <objdlg.hxx>
48cdf0e10cSrcweir #include <basobj.hxx>
49cdf0e10cSrcweir #include <iderdll.hxx>
50cdf0e10cSrcweir #include <iderdll2.hxx>
51cdf0e10cSrcweir #include <vcl/taskpanelist.hxx>
52cdf0e10cSrcweir #include <vcl/help.hxx>
53cdf0e10cSrcweir 
54cdf0e10cSrcweir //#ifndef _SFX_HELP_HXX //autogen
55cdf0e10cSrcweir //#include <sfx2/sfxhelp.hxx>
56cdf0e10cSrcweir //#endif
57cdf0e10cSrcweir #include <unotools/sourceviewconfig.hxx>
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER2_HPP_
60cdf0e10cSrcweir #include <com/sun/star/script/XLibraryContainer2.hpp>
61cdf0e10cSrcweir #endif
62cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 
65cdf0e10cSrcweir using namespace ::com::sun::star;
66cdf0e10cSrcweir using namespace ::com::sun::star::uno;
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
69cdf0e10cSrcweir long nVirtToolBoxHeight;	// wird im WatchWindow init., im Stackwindow verw.
70cdf0e10cSrcweir long nHeaderBarHeight;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir #define SCROLL_LINE		12
73cdf0e10cSrcweir #define SCROLL_PAGE		60
74cdf0e10cSrcweir 
75cdf0e10cSrcweir #define DWBORDER		3
76cdf0e10cSrcweir 
77cdf0e10cSrcweir static const char cSuffixes[] = "%&!#@$";
78cdf0e10cSrcweir 
79cdf0e10cSrcweir MapUnit eEditMapUnit = MAP_100TH_MM;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 
82cdf0e10cSrcweir // #108672 Helper functions to get/set text in TextEngine
83cdf0e10cSrcweir // using the stream interface (get/setText() only supports
84cdf0e10cSrcweir // tools Strings limited to 64K).
85cdf0e10cSrcweir ::rtl::OUString getTextEngineText( ExtTextEngine* pEngine )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir     SvMemoryStream aMemStream;
88cdf0e10cSrcweir     aMemStream.SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
89cdf0e10cSrcweir     aMemStream.SetLineDelimiter( LINEEND_LF );
90cdf0e10cSrcweir     pEngine->Write( aMemStream );
91cdf0e10cSrcweir     sal_uLong nSize = aMemStream.Tell();
92cdf0e10cSrcweir     ::rtl::OUString aText( (const sal_Char*)aMemStream.GetData(),
93cdf0e10cSrcweir         nSize, RTL_TEXTENCODING_UTF8 );
94cdf0e10cSrcweir     return aText;
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir void setTextEngineText( ExtTextEngine* pEngine, const ::rtl::OUString aStr )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     pEngine->SetText( String() );
100cdf0e10cSrcweir     ::rtl::OString aUTF8Str = ::rtl::OUStringToOString( aStr, RTL_TEXTENCODING_UTF8 );
101cdf0e10cSrcweir 	SvMemoryStream aMemStream( (void*)aUTF8Str.getStr(), aUTF8Str.getLength(),
102cdf0e10cSrcweir         STREAM_READ | STREAM_SEEK_TO_BEGIN );
103cdf0e10cSrcweir     aMemStream.SetStreamCharSet( RTL_TEXTENCODING_UTF8 );
104cdf0e10cSrcweir     aMemStream.SetLineDelimiter( LINEEND_LF );
105cdf0e10cSrcweir 	pEngine->Read( aMemStream );
106cdf0e10cSrcweir }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir void lcl_DrawIDEWindowFrame( DockingWindow* pWin )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir     // The result of using explicit colors here appears to be harmless when
111cdf0e10cSrcweir     // switching to high contrast mode:
112cdf0e10cSrcweir 	if ( !pWin->IsFloatingMode() )
113cdf0e10cSrcweir 	{
114cdf0e10cSrcweir 		Size aSz = pWin->GetOutputSizePixel();
115cdf0e10cSrcweir 		const Color aOldLineColor( pWin->GetLineColor() );
116cdf0e10cSrcweir 		pWin->SetLineColor( Color( COL_WHITE ) );
117cdf0e10cSrcweir 		// oben eine weisse..
118cdf0e10cSrcweir 		pWin->DrawLine( Point( 0, 0 ), Point( aSz.Width(), 0 ) );
119cdf0e10cSrcweir 		// unten eine schwarze...
120cdf0e10cSrcweir 		pWin->SetLineColor( Color( COL_BLACK ) );
121cdf0e10cSrcweir 		pWin->DrawLine( Point( 0, aSz.Height() - 1 ), Point( aSz.Width(), aSz.Height() - 1 ) );
122cdf0e10cSrcweir 		pWin->SetLineColor( aOldLineColor );
123cdf0e10cSrcweir 	}
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir void lcl_SeparateNameAndIndex( const String& rVName, String& rVar, String& rIndex )
127cdf0e10cSrcweir {
128cdf0e10cSrcweir 	rVar = rVName;
129cdf0e10cSrcweir 	rIndex.Erase();
130cdf0e10cSrcweir 	sal_uInt16 nIndexStart = rVar.Search( '(' );
131cdf0e10cSrcweir 	if ( nIndexStart != STRING_NOTFOUND )
132cdf0e10cSrcweir 	{
133cdf0e10cSrcweir 		sal_uInt16 nIndexEnd = rVar.Search( ')', nIndexStart );
134cdf0e10cSrcweir 		if ( nIndexStart != STRING_NOTFOUND )
135cdf0e10cSrcweir 		{
136cdf0e10cSrcweir 			rIndex = rVar.Copy( nIndexStart+1, nIndexEnd-nIndexStart-1 );
137cdf0e10cSrcweir 			rVar.Erase( nIndexStart );
138cdf0e10cSrcweir 			rVar.EraseTrailingChars();
139cdf0e10cSrcweir 			rIndex.EraseLeadingChars();
140cdf0e10cSrcweir 			rIndex.EraseTrailingChars();
141cdf0e10cSrcweir 		}
142cdf0e10cSrcweir 	}
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	if ( rVar.Len() )
145cdf0e10cSrcweir 	{
146cdf0e10cSrcweir 		sal_uInt16 nLastChar = rVar.Len()-1;
147cdf0e10cSrcweir 		if ( strchr( cSuffixes, rVar.GetChar( nLastChar ) ) )
148cdf0e10cSrcweir 			rVar.Erase( nLastChar, 1 );
149cdf0e10cSrcweir 	}
150cdf0e10cSrcweir 	if ( rIndex.Len() )
151cdf0e10cSrcweir 	{
152cdf0e10cSrcweir 		sal_uInt16 nLastChar = rIndex.Len()-1;
153cdf0e10cSrcweir 		if ( strchr( cSuffixes, rIndex.GetChar( nLastChar ) ) )
154cdf0e10cSrcweir 			rIndex.Erase( nLastChar, 1 );
155cdf0e10cSrcweir 	}
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 
159cdf0e10cSrcweir EditorWindow::EditorWindow( Window* pParent ) :
160cdf0e10cSrcweir 	Window( pParent, WB_BORDER )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir 	bDoSyntaxHighlight = sal_True;
163cdf0e10cSrcweir 	bDelayHighlight = sal_True;
164cdf0e10cSrcweir 	pModulWindow = 0;
165cdf0e10cSrcweir 	pEditView = 0;
166cdf0e10cSrcweir 	pEditEngine = 0;
167cdf0e10cSrcweir     pSourceViewConfig = new utl::SourceViewConfig;
168cdf0e10cSrcweir 	bHighlightning = sal_False;
169cdf0e10cSrcweir 	pProgress = 0;
170cdf0e10cSrcweir 	nCurTextWidth = 0;
171cdf0e10cSrcweir 	SetBackground(
172cdf0e10cSrcweir         Wallpaper(GetSettings().GetStyleSettings().GetFieldColor()));
173cdf0e10cSrcweir 	SetPointer( Pointer( POINTER_TEXT ) );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	SetHelpId( HID_BASICIDE_EDITORWINDOW );
176cdf0e10cSrcweir     pSourceViewConfig->AddListener(this);
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 
181cdf0e10cSrcweir __EXPORT EditorWindow::~EditorWindow()
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     pSourceViewConfig->RemoveListener(this);
184cdf0e10cSrcweir     delete pSourceViewConfig;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 	aSyntaxIdleTimer.Stop();
187cdf0e10cSrcweir 
188cdf0e10cSrcweir 	if ( pEditEngine )
189cdf0e10cSrcweir 	{
190cdf0e10cSrcweir 		EndListening( *pEditEngine );
191cdf0e10cSrcweir 		pEditEngine->RemoveView( pEditView );
192cdf0e10cSrcweir //		pEditEngine->SetViewWin( 0 );
193cdf0e10cSrcweir 		delete pEditView;
194cdf0e10cSrcweir 		delete pEditEngine;
195cdf0e10cSrcweir 	}
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
198cdf0e10cSrcweir String EditorWindow::GetWordAtCursor()
199cdf0e10cSrcweir {
200cdf0e10cSrcweir     String aWord;
201cdf0e10cSrcweir 
202cdf0e10cSrcweir     if ( pEditView )
203cdf0e10cSrcweir     {
204cdf0e10cSrcweir         TextEngine* pTextEngine = pEditView->GetTextEngine();
205cdf0e10cSrcweir         if ( pTextEngine )
206cdf0e10cSrcweir         {
207cdf0e10cSrcweir             // check first, if the cursor is at a help URL
208cdf0e10cSrcweir             const TextSelection& rSelection = pEditView->GetSelection();
209cdf0e10cSrcweir             const TextPaM& rSelStart = rSelection.GetStart();
210cdf0e10cSrcweir             const TextPaM& rSelEnd = rSelection.GetEnd();
211cdf0e10cSrcweir             String aText = pTextEngine->GetText( rSelEnd.GetPara() );
212cdf0e10cSrcweir             CharClass aClass( ::comphelper::getProcessServiceFactory() , Application::GetSettings().GetLocale() );
213cdf0e10cSrcweir             xub_StrLen nSelStart = static_cast< xub_StrLen >( rSelStart.GetIndex() );
214cdf0e10cSrcweir             xub_StrLen nSelEnd = static_cast< xub_StrLen >( rSelEnd.GetIndex() );
215cdf0e10cSrcweir             xub_StrLen nLength = static_cast< xub_StrLen >( aText.Len() );
216cdf0e10cSrcweir             xub_StrLen nStart = 0;
217cdf0e10cSrcweir             xub_StrLen nEnd = nLength;
218cdf0e10cSrcweir             while ( nStart < nLength )
219cdf0e10cSrcweir             {
220cdf0e10cSrcweir                 String aURL( URIHelper::FindFirstURLInText( aText, nStart, nEnd, aClass ) );
221cdf0e10cSrcweir 	            INetURLObject aURLObj( aURL );
222cdf0e10cSrcweir                 if ( aURLObj.GetProtocol() == INET_PROT_VND_SUN_STAR_HELP
223cdf0e10cSrcweir                      && nSelStart >= nStart && nSelStart <= nEnd && nSelEnd >= nStart && nSelEnd <= nEnd )
224cdf0e10cSrcweir                 {
225cdf0e10cSrcweir                     aWord = aURL;
226cdf0e10cSrcweir                     break;
227cdf0e10cSrcweir                 }
228cdf0e10cSrcweir                 nStart = nEnd;
229cdf0e10cSrcweir                 nEnd = nLength;
230cdf0e10cSrcweir             }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir             // Nicht den Selektierten Bereich, sondern an der CursorPosition,
233cdf0e10cSrcweir             // falls Teil eines Worts markiert.
234cdf0e10cSrcweir             if ( !aWord.Len() )
235cdf0e10cSrcweir                 aWord = pTextEngine->GetWord( rSelEnd );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir             // Kann leer sein, wenn komplettes Word markiert, da Cursor dahinter.
238cdf0e10cSrcweir             if ( !aWord.Len() && pEditView->HasSelection() )
239cdf0e10cSrcweir                 aWord = pTextEngine->GetWord( rSelStart );
240cdf0e10cSrcweir         }
241cdf0e10cSrcweir     }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     return aWord;
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
246cdf0e10cSrcweir void __EXPORT EditorWindow::RequestHelp( const HelpEvent& rHEvt )
247cdf0e10cSrcweir {
248cdf0e10cSrcweir     sal_Bool bDone = sal_False;
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 	// Sollte eigentlich mal aktiviert werden...
251cdf0e10cSrcweir 	if ( pEditEngine )
252cdf0e10cSrcweir 	{
253cdf0e10cSrcweir         if ( rHEvt.GetMode() & HELPMODE_CONTEXT )
254cdf0e10cSrcweir 		{
255cdf0e10cSrcweir 			String aKeyword = GetWordAtCursor();
256cdf0e10cSrcweir 			Application::GetHelp()->SearchKeyword( aKeyword );
257cdf0e10cSrcweir             bDone = sal_True;
258cdf0e10cSrcweir         }
259cdf0e10cSrcweir 		else if ( rHEvt.GetMode() & HELPMODE_QUICK )
260cdf0e10cSrcweir 		{
261cdf0e10cSrcweir 			String aHelpText;
262cdf0e10cSrcweir 			Point aTopLeft;
263cdf0e10cSrcweir 			if ( StarBASIC::IsRunning() )
264cdf0e10cSrcweir 			{
265cdf0e10cSrcweir 				Point aWindowPos = rHEvt.GetMousePosPixel();
266cdf0e10cSrcweir 				aWindowPos = ScreenToOutputPixel( aWindowPos );
267cdf0e10cSrcweir 				Point aDocPos = GetEditView()->GetDocPos( aWindowPos );
268cdf0e10cSrcweir 				TextPaM aCursor = GetEditView()->GetTextEngine()->GetPaM( aDocPos, sal_False );
269cdf0e10cSrcweir 				TextPaM aStartOfWord;
270cdf0e10cSrcweir 				String aWord = GetEditView()->GetTextEngine()->GetWord( aCursor, &aStartOfWord );
271cdf0e10cSrcweir 				if ( aWord.Len() && !ByteString( aWord, RTL_TEXTENCODING_UTF8 ).IsNumericAscii() )
272cdf0e10cSrcweir 				{
273cdf0e10cSrcweir 					sal_uInt16 nLastChar =aWord.Len()-1;
274cdf0e10cSrcweir 					if ( strchr( cSuffixes, aWord.GetChar( nLastChar ) ) )
275cdf0e10cSrcweir 						aWord.Erase( nLastChar, 1 );
276cdf0e10cSrcweir 					SbxBase* pSBX = StarBASIC::FindSBXInCurrentScope( aWord );
277cdf0e10cSrcweir 					if ( pSBX && pSBX->ISA( SbxVariable ) && !pSBX->ISA( SbxMethod ) )
278cdf0e10cSrcweir 					{
279cdf0e10cSrcweir 						SbxVariable* pVar = (SbxVariable*)pSBX;
280cdf0e10cSrcweir 						SbxDataType eType = pVar->GetType();
281cdf0e10cSrcweir 						if ( (sal_uInt8)eType == (sal_uInt8)SbxOBJECT )
282cdf0e10cSrcweir 							// Kann zu Absturz, z.B. bei Selections-Objekt fuehren
283cdf0e10cSrcweir 							// Type == Object heisst nicht, dass pVar == Object!
284cdf0e10cSrcweir 							; // aHelpText = ((SbxObject*)pVar)->GetClassName();
285cdf0e10cSrcweir 						else if ( eType & SbxARRAY )
286cdf0e10cSrcweir 							; // aHelpText = "{...}";
287cdf0e10cSrcweir 						else if ( (sal_uInt8)eType != (sal_uInt8)SbxEMPTY )
288cdf0e10cSrcweir 						{
289cdf0e10cSrcweir 							aHelpText = pVar->GetName();
290cdf0e10cSrcweir 							if ( !aHelpText.Len() ) 	// Bei Uebergabeparametern wird der Name nicht kopiert
291cdf0e10cSrcweir 								aHelpText = aWord;
292cdf0e10cSrcweir 							aHelpText += '=';
293cdf0e10cSrcweir 							aHelpText += pVar->GetString();
294cdf0e10cSrcweir 						}
295cdf0e10cSrcweir 					}
296cdf0e10cSrcweir 					if ( aHelpText.Len() )
297cdf0e10cSrcweir 					{
298cdf0e10cSrcweir 						aTopLeft = GetEditView()->GetTextEngine()->PaMtoEditCursor( aStartOfWord ).BottomLeft();
299cdf0e10cSrcweir 						aTopLeft = GetEditView()->GetWindowPos( aTopLeft );
300cdf0e10cSrcweir 						aTopLeft.X() += 5;
301cdf0e10cSrcweir 						aTopLeft.Y() += 5;
302cdf0e10cSrcweir 						aTopLeft = OutputToScreenPixel( aTopLeft );
303cdf0e10cSrcweir 					}
304cdf0e10cSrcweir 				}
305cdf0e10cSrcweir 			}
306cdf0e10cSrcweir 			Help::ShowQuickHelp( this, Rectangle( aTopLeft, Size( 1, 1 ) ), aHelpText, QUICKHELP_TOP|QUICKHELP_LEFT);
307cdf0e10cSrcweir             bDone = sal_True;
308cdf0e10cSrcweir 		}
309cdf0e10cSrcweir 	}
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     if ( !bDone )
312cdf0e10cSrcweir         Window::RequestHelp( rHEvt );
313cdf0e10cSrcweir }
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 
316cdf0e10cSrcweir void __EXPORT EditorWindow::Resize()
317cdf0e10cSrcweir {
318cdf0e10cSrcweir 	// ScrollBars, etc. passiert in Adjust...
319cdf0e10cSrcweir 	if ( pEditView )
320cdf0e10cSrcweir 	{
321cdf0e10cSrcweir 		long nVisY = pEditView->GetStartDocPos().Y();
322cdf0e10cSrcweir //		pEditView->SetOutputArea( Rectangle( Point( 0, 0 ), GetOutputSize() ) );
323cdf0e10cSrcweir 		pEditView->ShowCursor();
324cdf0e10cSrcweir 		Size aOutSz( GetOutputSizePixel() );
325cdf0e10cSrcweir 		long nMaxVisAreaStart = pEditView->GetTextEngine()->GetTextHeight() - aOutSz.Height();
326cdf0e10cSrcweir 		if ( nMaxVisAreaStart < 0 )
327cdf0e10cSrcweir 			nMaxVisAreaStart = 0;
328cdf0e10cSrcweir 		if ( pEditView->GetStartDocPos().Y() > nMaxVisAreaStart )
329cdf0e10cSrcweir 		{
330cdf0e10cSrcweir 			Point aStartDocPos( pEditView->GetStartDocPos() );
331cdf0e10cSrcweir 			aStartDocPos.Y() = nMaxVisAreaStart;
332cdf0e10cSrcweir 			pEditView->SetStartDocPos( aStartDocPos );
333cdf0e10cSrcweir 			pEditView->ShowCursor();
334cdf0e10cSrcweir 			pModulWindow->GetBreakPointWindow().GetCurYOffset() = aStartDocPos.Y();
335cdf0e10cSrcweir 		}
336cdf0e10cSrcweir 		InitScrollBars();
337cdf0e10cSrcweir 		if ( nVisY != pEditView->GetStartDocPos().Y() )
338cdf0e10cSrcweir 			Invalidate();
339cdf0e10cSrcweir 	}
340cdf0e10cSrcweir }
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 
343cdf0e10cSrcweir 
344cdf0e10cSrcweir void __EXPORT EditorWindow::MouseMove( const MouseEvent &rEvt )
345cdf0e10cSrcweir {
346cdf0e10cSrcweir 	if ( pEditView )
347cdf0e10cSrcweir 		pEditView->MouseMove( rEvt );
348cdf0e10cSrcweir }
349cdf0e10cSrcweir 
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 
352cdf0e10cSrcweir void __EXPORT EditorWindow::MouseButtonUp( const MouseEvent &rEvt )
353cdf0e10cSrcweir {
354cdf0e10cSrcweir 	if ( pEditView )
355cdf0e10cSrcweir 	{
356cdf0e10cSrcweir 		pEditView->MouseButtonUp( rEvt );
357cdf0e10cSrcweir         SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
358cdf0e10cSrcweir         if ( pBindings )
359*74932c38SAriel Constenla-Haile         {
360*74932c38SAriel Constenla-Haile             pBindings->Invalidate( SID_COPY );
361*74932c38SAriel Constenla-Haile             pBindings->Invalidate( SID_CUT );
362cdf0e10cSrcweir             pBindings->Invalidate( SID_BASICIDE_STAT_POS );
363*74932c38SAriel Constenla-Haile         }
364cdf0e10cSrcweir 	}
365cdf0e10cSrcweir }
366cdf0e10cSrcweir 
367cdf0e10cSrcweir void __EXPORT EditorWindow::MouseButtonDown( const MouseEvent &rEvt )
368cdf0e10cSrcweir {
369cdf0e10cSrcweir 	GrabFocus();
370cdf0e10cSrcweir 	if ( pEditView )
371cdf0e10cSrcweir 	{
372cdf0e10cSrcweir 		pEditView->MouseButtonDown( rEvt );
373cdf0e10cSrcweir 	}
374cdf0e10cSrcweir }
375cdf0e10cSrcweir 
376cdf0e10cSrcweir void __EXPORT EditorWindow::Command( const CommandEvent& rCEvt )
377cdf0e10cSrcweir {
378cdf0e10cSrcweir 	if ( pEditView )
379cdf0e10cSrcweir 	{
380cdf0e10cSrcweir 		pEditView->Command( rCEvt );
381cdf0e10cSrcweir 		if ( ( rCEvt.GetCommand() == COMMAND_WHEEL ) ||
382cdf0e10cSrcweir 			 ( rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL ) ||
383cdf0e10cSrcweir 			 ( rCEvt.GetCommand() == COMMAND_AUTOSCROLL ) )
384cdf0e10cSrcweir 		{
385cdf0e10cSrcweir 			HandleScrollCommand( rCEvt, pModulWindow->GetHScrollBar(), &pModulWindow->GetEditVScrollBar() );
386cdf0e10cSrcweir 		}
387cdf0e10cSrcweir 	}
388cdf0e10cSrcweir }
389cdf0e10cSrcweir 
390cdf0e10cSrcweir sal_Bool EditorWindow::ImpCanModify()
391cdf0e10cSrcweir {
392cdf0e10cSrcweir 	sal_Bool bCanModify = sal_True;
393cdf0e10cSrcweir 	if ( StarBASIC::IsRunning() )
394cdf0e10cSrcweir 	{
395cdf0e10cSrcweir 		// Wenn im Trace-Mode, entweder Trace abbrechen oder
396cdf0e10cSrcweir 		// Eingabe verweigern
397cdf0e10cSrcweir 		// Im Notify bei Basic::Stoped die Markierungen in den Modulen
398cdf0e10cSrcweir 		// entfernen!
399cdf0e10cSrcweir 		if ( QueryBox( 0, WB_OK_CANCEL, String( IDEResId( RID_STR_WILLSTOPPRG ) ) ).Execute() == RET_OK )
400cdf0e10cSrcweir 		{
401cdf0e10cSrcweir 			pModulWindow->GetBasicStatus().bIsRunning = sal_False;
402cdf0e10cSrcweir 			BasicIDE::StopBasic();
403cdf0e10cSrcweir 		}
404cdf0e10cSrcweir 		else
405cdf0e10cSrcweir 			bCanModify = sal_False;
406cdf0e10cSrcweir 	}
407cdf0e10cSrcweir 	return bCanModify;
408cdf0e10cSrcweir }
409cdf0e10cSrcweir 
410cdf0e10cSrcweir void __EXPORT EditorWindow::KeyInput( const KeyEvent& rKEvt )
411cdf0e10cSrcweir {
412cdf0e10cSrcweir 	if ( !pEditView )	// Passiert unter W95 bei letzte Version, Ctrl-Tab
413cdf0e10cSrcweir 		return;
414cdf0e10cSrcweir 
415cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
416cdf0e10cSrcweir     Range aRange = pModulWindow->GetHScrollBar()->GetRange(); (void)aRange;
417cdf0e10cSrcweir     long nVisSz = pModulWindow->GetHScrollBar()->GetVisibleSize(); (void)nVisSz;
418cdf0e10cSrcweir     long nPapSz = pModulWindow->GetHScrollBar()->GetPageSize(); (void)nPapSz;
419cdf0e10cSrcweir     long nLinSz = pModulWindow->GetHScrollBar()->GetLineSize(); (void)nLinSz;
420cdf0e10cSrcweir     long nThumb = pModulWindow->GetHScrollBar()->GetThumbPos(); (void)nThumb;
421cdf0e10cSrcweir #endif
422cdf0e10cSrcweir 	sal_Bool bDone = sal_False;
423cdf0e10cSrcweir 	sal_Bool bWasModified = pEditEngine->IsModified();
424cdf0e10cSrcweir 	if ( !TextEngine::DoesKeyChangeText( rKEvt ) || ImpCanModify() )
425cdf0e10cSrcweir 	{
426cdf0e10cSrcweir 		if ( ( rKEvt.GetKeyCode().GetCode() == KEY_A) && rKEvt.GetKeyCode().IsMod1() )
427cdf0e10cSrcweir 			pEditView->SetSelection( TextSelection( TextPaM( 0, 0 ), TextPaM( 0xFFFFFFFF, 0xFFFF ) ) );
428cdf0e10cSrcweir 		else if ( ( rKEvt.GetKeyCode().GetCode() == KEY_Y ) && rKEvt.GetKeyCode().IsMod1() )
429cdf0e10cSrcweir 			bDone = sal_True; // CTRL-Y schlucken, damit kein Vorlagenkatalog
430cdf0e10cSrcweir 		else
431cdf0e10cSrcweir 		{
432cdf0e10cSrcweir 			if ( ( rKEvt.GetKeyCode().GetCode() == KEY_TAB ) && !rKEvt.GetKeyCode().IsMod1() &&
433cdf0e10cSrcweir 				  !rKEvt.GetKeyCode().IsMod2() && !GetEditView()->IsReadOnly() )
434cdf0e10cSrcweir 			{
435cdf0e10cSrcweir 				TextSelection aSel( pEditView->GetSelection() );
436cdf0e10cSrcweir 				if ( aSel.GetStart().GetPara() != aSel.GetEnd().GetPara() )
437cdf0e10cSrcweir 				{
438cdf0e10cSrcweir 					bDelayHighlight = sal_False;
439cdf0e10cSrcweir 					if ( !rKEvt.GetKeyCode().IsShift() )
440cdf0e10cSrcweir 						pEditView->IndentBlock();
441cdf0e10cSrcweir 					else
442cdf0e10cSrcweir 						pEditView->UnindentBlock();
443cdf0e10cSrcweir 					bDelayHighlight = sal_True;
444cdf0e10cSrcweir 					bDone = sal_True;
445cdf0e10cSrcweir 				}
446cdf0e10cSrcweir 			}
447cdf0e10cSrcweir 			if ( !bDone )
448cdf0e10cSrcweir 				bDone = pEditView->KeyInput( rKEvt );
449cdf0e10cSrcweir 		}
450cdf0e10cSrcweir 	}
451cdf0e10cSrcweir 	if ( !bDone )
452cdf0e10cSrcweir 	{
453cdf0e10cSrcweir 		if ( !SfxViewShell::Current()->KeyInput( rKEvt ) )
454cdf0e10cSrcweir 			Window::KeyInput( rKEvt );
455cdf0e10cSrcweir 	}
456cdf0e10cSrcweir 	else
457cdf0e10cSrcweir 	{
458cdf0e10cSrcweir         SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
459cdf0e10cSrcweir         if ( pBindings )
460cdf0e10cSrcweir         {
461*74932c38SAriel Constenla-Haile             pBindings->Invalidate( SID_CUT );
462*74932c38SAriel Constenla-Haile             pBindings->Invalidate( SID_COPY );
463cdf0e10cSrcweir             pBindings->Invalidate( SID_BASICIDE_STAT_POS );
464*74932c38SAriel Constenla-Haile 
465cdf0e10cSrcweir             if ( rKEvt.GetKeyCode().GetGroup() == KEYGROUP_CURSOR )
466cdf0e10cSrcweir                 pBindings->Update( SID_BASICIDE_STAT_POS );
467*74932c38SAriel Constenla-Haile 
468cdf0e10cSrcweir             if ( !bWasModified && pEditEngine->IsModified() )
469cdf0e10cSrcweir             {
470cdf0e10cSrcweir                 pBindings->Invalidate( SID_SAVEDOC );
471cdf0e10cSrcweir                 pBindings->Invalidate( SID_DOC_MODIFIED );
472cdf0e10cSrcweir                 pBindings->Invalidate( SID_UNDO );
473cdf0e10cSrcweir             }
474*74932c38SAriel Constenla-Haile 
475cdf0e10cSrcweir             if ( rKEvt.GetKeyCode().GetCode() == KEY_INSERT )
476cdf0e10cSrcweir                 pBindings->Invalidate( SID_ATTR_INSERT );
477cdf0e10cSrcweir         }
478cdf0e10cSrcweir 	}
479cdf0e10cSrcweir }
480cdf0e10cSrcweir 
481cdf0e10cSrcweir void __EXPORT EditorWindow::Paint( const Rectangle& rRect )
482cdf0e10cSrcweir {
483cdf0e10cSrcweir 	if ( !pEditEngine )		// spaetestens jetzt brauche ich sie...
484cdf0e10cSrcweir 		CreateEditEngine();
485cdf0e10cSrcweir 
486cdf0e10cSrcweir 	pEditView->Paint( rRect );
487cdf0e10cSrcweir }
488cdf0e10cSrcweir 
489cdf0e10cSrcweir void __EXPORT EditorWindow::LoseFocus()
490cdf0e10cSrcweir {
491cdf0e10cSrcweir 	SetSourceInBasic();
492cdf0e10cSrcweir 	Window::LoseFocus();
493cdf0e10cSrcweir }
494cdf0e10cSrcweir 
495cdf0e10cSrcweir sal_Bool EditorWindow::SetSourceInBasic( sal_Bool bQuiet )
496cdf0e10cSrcweir {
497cdf0e10cSrcweir 	(void)bQuiet;
498cdf0e10cSrcweir 
499cdf0e10cSrcweir 	sal_Bool bChanged = sal_False;
500cdf0e10cSrcweir 	if ( pEditEngine && pEditEngine->IsModified()
501cdf0e10cSrcweir 		&& !GetEditView()->IsReadOnly() )	// Added because of #i60626, otherwise
502cdf0e10cSrcweir 			// any read only bug in the text engine could lead to a crash later
503cdf0e10cSrcweir 	{
504cdf0e10cSrcweir         if ( !StarBASIC::IsRunning() ) // Nicht zur Laufzeit!
505cdf0e10cSrcweir 		{
506cdf0e10cSrcweir             ::rtl::OUString aModule = getTextEngineText( pEditEngine );
507cdf0e10cSrcweir 
508cdf0e10cSrcweir             // update module in basic
509cdf0e10cSrcweir #ifdef DBG_UTIL
510cdf0e10cSrcweir             SbModule* pModule = pModulWindow->GetSbModule();
511cdf0e10cSrcweir #endif
512cdf0e10cSrcweir             DBG_ASSERT(pModule, "EditorWindow::SetSourceInBasic: No Module found!");
513cdf0e10cSrcweir 
514cdf0e10cSrcweir             // update module in module window
515cdf0e10cSrcweir             pModulWindow->SetModule( aModule );
516cdf0e10cSrcweir 
517cdf0e10cSrcweir             // update module in library
518cdf0e10cSrcweir             ScriptDocument aDocument( pModulWindow->GetDocument() );
519cdf0e10cSrcweir             String aLibName = pModulWindow->GetLibName();
520cdf0e10cSrcweir 	        String aName = pModulWindow->GetName();
521cdf0e10cSrcweir             OSL_VERIFY( aDocument.updateModule( aLibName, aName, aModule ) );
522cdf0e10cSrcweir 
523cdf0e10cSrcweir             pEditEngine->SetModified( sal_False );
524cdf0e10cSrcweir             BasicIDE::MarkDocumentModified( aDocument );
525cdf0e10cSrcweir             bChanged = sal_True;
526cdf0e10cSrcweir 		}
527cdf0e10cSrcweir 	}
528cdf0e10cSrcweir 	return bChanged;
529cdf0e10cSrcweir }
530cdf0e10cSrcweir 
531cdf0e10cSrcweir 
532cdf0e10cSrcweir // Returns the position of the last character of any of the following
533cdf0e10cSrcweir // EOL char combinations: CR, CR/LF, LF, return -1 if no EOL is found
534cdf0e10cSrcweir sal_Int32 searchEOL( const ::rtl::OUString& rStr, sal_Int32 fromIndex )
535cdf0e10cSrcweir {
536cdf0e10cSrcweir 	sal_Int32 iRetPos = -1;
537cdf0e10cSrcweir 
538cdf0e10cSrcweir 	sal_Int32 iLF = rStr.indexOf( LINE_SEP, fromIndex );
539cdf0e10cSrcweir 	if( iLF != -1 )
540cdf0e10cSrcweir 	{
541cdf0e10cSrcweir 		iRetPos = iLF;
542cdf0e10cSrcweir 	}
543cdf0e10cSrcweir 	else
544cdf0e10cSrcweir 	{
545cdf0e10cSrcweir 		iRetPos = rStr.indexOf( LINE_SEP_CR, fromIndex );
546cdf0e10cSrcweir 	}
547cdf0e10cSrcweir 	return iRetPos;
548cdf0e10cSrcweir }
549cdf0e10cSrcweir 
550cdf0e10cSrcweir 
551cdf0e10cSrcweir void EditorWindow::CreateEditEngine()
552cdf0e10cSrcweir {
553cdf0e10cSrcweir 	if ( pEditEngine )
554cdf0e10cSrcweir 		return;
555cdf0e10cSrcweir 
556cdf0e10cSrcweir 	pEditEngine = new ExtTextEngine;
557cdf0e10cSrcweir 	pEditView = new ExtTextView( pEditEngine, this );
558cdf0e10cSrcweir 	pEditView->SetAutoIndentMode( sal_True );
559cdf0e10cSrcweir 	pEditEngine->SetUpdateMode( sal_False );
560cdf0e10cSrcweir 	pEditEngine->InsertView( pEditView );
561cdf0e10cSrcweir 
562cdf0e10cSrcweir 	ImplSetFont();
563cdf0e10cSrcweir 
564cdf0e10cSrcweir 	aSyntaxIdleTimer.SetTimeout( 200 );
565cdf0e10cSrcweir 	aSyntaxIdleTimer.SetTimeoutHdl( LINK( this, EditorWindow, SyntaxTimerHdl ) );
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 	aHighlighter.initialize( HIGHLIGHT_BASIC );
568cdf0e10cSrcweir 
569cdf0e10cSrcweir 	sal_Bool bWasDoSyntaxHighlight = bDoSyntaxHighlight;
570cdf0e10cSrcweir 	bDoSyntaxHighlight = sal_False;	// Bei grossen Texten zu langsam...
571cdf0e10cSrcweir     ::rtl::OUString aOUSource( pModulWindow->GetModule() );
572cdf0e10cSrcweir 	sal_Int32 nLines = 0;
573cdf0e10cSrcweir     sal_Int32 nIndex = -1;
574cdf0e10cSrcweir     do
575cdf0e10cSrcweir     {
576cdf0e10cSrcweir         nLines++;
577cdf0e10cSrcweir 		nIndex = searchEOL( aOUSource, nIndex+1 );
578cdf0e10cSrcweir     }
579cdf0e10cSrcweir     while ( nIndex >= 0 );
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 	// nLines*4: SetText+Formatting+DoHighlight+Formatting
582cdf0e10cSrcweir 	// 1 Formatting koennte eingespart werden, aber dann wartet man
583cdf0e10cSrcweir 	// bei einem langen Sourcecode noch laenger auf den Text...
584cdf0e10cSrcweir 	pProgress = new ProgressInfo( IDE_DLL()->GetShell()->GetViewFrame()->GetObjectShell(), String( IDEResId( RID_STR_GENERATESOURCE ) ), nLines*4 );
585cdf0e10cSrcweir     setTextEngineText( pEditEngine, aOUSource );
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 	pEditView->SetStartDocPos( Point( 0, 0 ) );
588cdf0e10cSrcweir 	pEditView->SetSelection( TextSelection() );
589cdf0e10cSrcweir 	pModulWindow->GetBreakPointWindow().GetCurYOffset() = 0;
590cdf0e10cSrcweir 	pEditEngine->SetUpdateMode( sal_True );
591cdf0e10cSrcweir 	Update();	// Es wurde bei UpdateMode = sal_True nur Invalidiert
592cdf0e10cSrcweir 
593cdf0e10cSrcweir 	// Die anderen Fenster auch, damit keine halben Sachen auf dem Bildschirm!
594cdf0e10cSrcweir 	pModulWindow->GetLayout()->GetWatchWindow().Update();
595cdf0e10cSrcweir 	pModulWindow->GetLayout()->GetStackWindow().Update();
596cdf0e10cSrcweir 	pModulWindow->GetBreakPointWindow().Update();
597cdf0e10cSrcweir 
598cdf0e10cSrcweir 	pEditView->ShowCursor( sal_True, sal_True );
599cdf0e10cSrcweir 
600cdf0e10cSrcweir 	StartListening( *pEditEngine );
601cdf0e10cSrcweir 
602cdf0e10cSrcweir 	// Das Syntax-Highlightning legt ein rel. groesse VDev an.
603cdf0e10cSrcweir 	aSyntaxIdleTimer.Stop();
604cdf0e10cSrcweir 	bDoSyntaxHighlight = bWasDoSyntaxHighlight;
605cdf0e10cSrcweir 
606cdf0e10cSrcweir 
607cdf0e10cSrcweir 	for ( sal_uInt16 nLine = 0; nLine < nLines; nLine++ )
608cdf0e10cSrcweir 		aSyntaxLineTable.Insert( nLine, (void*)(sal_uInt16)1 );
609cdf0e10cSrcweir 	ForceSyntaxTimeout();
610cdf0e10cSrcweir 
611cdf0e10cSrcweir 	DELETEZ( pProgress );
612cdf0e10cSrcweir 
613cdf0e10cSrcweir 	pEditView->EraseVirtualDevice();
614cdf0e10cSrcweir 	pEditEngine->SetModified( sal_False );
615cdf0e10cSrcweir 	pEditEngine->EnableUndo( sal_True );
616cdf0e10cSrcweir 
617cdf0e10cSrcweir 	InitScrollBars();
618cdf0e10cSrcweir 
619cdf0e10cSrcweir     SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
620cdf0e10cSrcweir     if ( pBindings )
621cdf0e10cSrcweir         pBindings->Invalidate( SID_BASICIDE_STAT_POS );
622cdf0e10cSrcweir 
623cdf0e10cSrcweir 	DBG_ASSERT( pModulWindow->GetBreakPointWindow().GetCurYOffset() == 0, "CreateEditEngine: Brechpunkte verschoben?" );
624cdf0e10cSrcweir 
625cdf0e10cSrcweir     // set readonly mode for readonly libraries
626cdf0e10cSrcweir     ScriptDocument aDocument( pModulWindow->GetDocument() );
627cdf0e10cSrcweir     ::rtl::OUString aOULibName( pModulWindow->GetLibName() );
628cdf0e10cSrcweir     Reference< script::XLibraryContainer2 > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
629cdf0e10cSrcweir     if ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) )
630cdf0e10cSrcweir     {
631cdf0e10cSrcweir         pModulWindow->SetReadOnly( sal_True );
632cdf0e10cSrcweir     }
633cdf0e10cSrcweir 
634cdf0e10cSrcweir     if ( aDocument.isDocument() && aDocument.isReadOnly() )
635cdf0e10cSrcweir 		pModulWindow->SetReadOnly( sal_True );
636cdf0e10cSrcweir }
637cdf0e10cSrcweir 
638cdf0e10cSrcweir // virtual
639cdf0e10cSrcweir void EditorWindow::DataChanged(DataChangedEvent const & rDCEvt)
640cdf0e10cSrcweir {
641cdf0e10cSrcweir     Window::DataChanged(rDCEvt);
642cdf0e10cSrcweir     if (rDCEvt.GetType() == DATACHANGED_SETTINGS
643cdf0e10cSrcweir         && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
644cdf0e10cSrcweir     {
645cdf0e10cSrcweir         Color aColor(GetSettings().GetStyleSettings().GetFieldColor());
646cdf0e10cSrcweir         if (aColor
647cdf0e10cSrcweir             != rDCEvt.GetOldSettings()->GetStyleSettings().GetFieldColor())
648cdf0e10cSrcweir         {
649cdf0e10cSrcweir             SetBackground(Wallpaper(aColor));
650cdf0e10cSrcweir             Invalidate();
651cdf0e10cSrcweir         }
652cdf0e10cSrcweir         if (pEditEngine != 0)
653cdf0e10cSrcweir         {
654cdf0e10cSrcweir             aColor = GetSettings().GetStyleSettings().GetFieldTextColor();
655cdf0e10cSrcweir             if (aColor != rDCEvt.GetOldSettings()->
656cdf0e10cSrcweir                 GetStyleSettings().GetFieldTextColor())
657cdf0e10cSrcweir             {
658cdf0e10cSrcweir                 Font aFont(pEditEngine->GetFont());
659cdf0e10cSrcweir                 aFont.SetColor(aColor);
660cdf0e10cSrcweir                 pEditEngine->SetFont(aFont);
661cdf0e10cSrcweir             }
662cdf0e10cSrcweir         }
663cdf0e10cSrcweir     }
664cdf0e10cSrcweir }
665cdf0e10cSrcweir 
666cdf0e10cSrcweir void EditorWindow::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
667cdf0e10cSrcweir {
668cdf0e10cSrcweir 	if ( rHint.ISA( TextHint ) )
669cdf0e10cSrcweir 	{
670cdf0e10cSrcweir 		const TextHint& rTextHint = (const TextHint&)rHint;
671cdf0e10cSrcweir 		if( rTextHint.GetId() == TEXT_HINT_VIEWSCROLLED )
672cdf0e10cSrcweir 		{
673cdf0e10cSrcweir 			if ( pModulWindow->GetHScrollBar() )
674cdf0e10cSrcweir 				pModulWindow->GetHScrollBar()->SetThumbPos( pEditView->GetStartDocPos().X() );
675cdf0e10cSrcweir 			pModulWindow->GetEditVScrollBar().SetThumbPos( pEditView->GetStartDocPos().Y() );
676cdf0e10cSrcweir 			pModulWindow->GetBreakPointWindow().DoScroll
677cdf0e10cSrcweir 				( 0, pModulWindow->GetBreakPointWindow().GetCurYOffset() - pEditView->GetStartDocPos().Y() );
678cdf0e10cSrcweir 		}
679cdf0e10cSrcweir 		else if( rTextHint.GetId() == TEXT_HINT_TEXTHEIGHTCHANGED )
680cdf0e10cSrcweir 		{
681cdf0e10cSrcweir 			if ( pEditView->GetStartDocPos().Y() )
682cdf0e10cSrcweir 			{
683cdf0e10cSrcweir 				long nOutHeight = GetOutputSizePixel().Height();
684cdf0e10cSrcweir 				long nTextHeight = pEditEngine->GetTextHeight();
685cdf0e10cSrcweir 				if ( nTextHeight < nOutHeight )
686cdf0e10cSrcweir 					pEditView->Scroll( 0, pEditView->GetStartDocPos().Y() );
687cdf0e10cSrcweir 			}
688cdf0e10cSrcweir 
689cdf0e10cSrcweir 			SetScrollBarRanges();
690cdf0e10cSrcweir 		}
691cdf0e10cSrcweir 		else if( rTextHint.GetId() == TEXT_HINT_TEXTFORMATTED )
692cdf0e10cSrcweir 		{
693cdf0e10cSrcweir 			if ( pModulWindow->GetHScrollBar() )
694cdf0e10cSrcweir 			{
695cdf0e10cSrcweir 				sal_uLong nWidth = pEditEngine->CalcTextWidth();
696cdf0e10cSrcweir 				if ( (long)nWidth != nCurTextWidth )
697cdf0e10cSrcweir 				{
698cdf0e10cSrcweir 					nCurTextWidth = nWidth;
699cdf0e10cSrcweir 					pModulWindow->GetHScrollBar()->SetRange( Range( 0, (long)nCurTextWidth-1) );
700cdf0e10cSrcweir 					pModulWindow->GetHScrollBar()->SetThumbPos( pEditView->GetStartDocPos().X() );
701cdf0e10cSrcweir 				}
702cdf0e10cSrcweir 			}
703cdf0e10cSrcweir 			long nPrevTextWidth = nCurTextWidth;
704cdf0e10cSrcweir 			nCurTextWidth = pEditEngine->CalcTextWidth();
705cdf0e10cSrcweir 			if ( nCurTextWidth != nPrevTextWidth )
706cdf0e10cSrcweir 				SetScrollBarRanges();
707cdf0e10cSrcweir 		}
708cdf0e10cSrcweir 		else if( rTextHint.GetId() == TEXT_HINT_PARAINSERTED )
709cdf0e10cSrcweir 		{
710cdf0e10cSrcweir 			ParagraphInsertedDeleted( rTextHint.GetValue(), sal_True );
711cdf0e10cSrcweir 			DoDelayedSyntaxHighlight( rTextHint.GetValue() );
712cdf0e10cSrcweir 		}
713cdf0e10cSrcweir 		else if( rTextHint.GetId() == TEXT_HINT_PARAREMOVED )
714cdf0e10cSrcweir 		{
715cdf0e10cSrcweir 			ParagraphInsertedDeleted( rTextHint.GetValue(), sal_False );
716cdf0e10cSrcweir 		}
717cdf0e10cSrcweir 		else if( rTextHint.GetId() == TEXT_HINT_PARACONTENTCHANGED )
718cdf0e10cSrcweir 		{
719cdf0e10cSrcweir 			DoDelayedSyntaxHighlight( rTextHint.GetValue() );
720cdf0e10cSrcweir 		}
721cdf0e10cSrcweir 	}
722cdf0e10cSrcweir }
723cdf0e10cSrcweir 
724cdf0e10cSrcweir void EditorWindow::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 )
725cdf0e10cSrcweir {
726cdf0e10cSrcweir     ImplSetFont();
727cdf0e10cSrcweir }
728cdf0e10cSrcweir 
729cdf0e10cSrcweir void EditorWindow::SetScrollBarRanges()
730cdf0e10cSrcweir {
731cdf0e10cSrcweir 	// Extra-Methode, nicht InitScrollBars, da auch fuer EditEngine-Events.
732cdf0e10cSrcweir 	if ( !pEditEngine )
733cdf0e10cSrcweir 		return;
734cdf0e10cSrcweir 
735cdf0e10cSrcweir 	if ( pModulWindow->GetHScrollBar() )
736cdf0e10cSrcweir 		pModulWindow->GetHScrollBar()->SetRange( Range( 0, nCurTextWidth-1 ) );
737cdf0e10cSrcweir 
738cdf0e10cSrcweir 	pModulWindow->GetEditVScrollBar().SetRange( Range( 0, pEditEngine->GetTextHeight()-1 ) );
739cdf0e10cSrcweir }
740cdf0e10cSrcweir 
741cdf0e10cSrcweir void EditorWindow::InitScrollBars()
742cdf0e10cSrcweir {
743cdf0e10cSrcweir 	if ( !pEditEngine )
744cdf0e10cSrcweir 		return;
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 	SetScrollBarRanges();
747cdf0e10cSrcweir 	Size aOutSz( GetOutputSizePixel() );
748cdf0e10cSrcweir 	pModulWindow->GetEditVScrollBar().SetVisibleSize( aOutSz.Height() );
749cdf0e10cSrcweir 	pModulWindow->GetEditVScrollBar().SetPageSize( aOutSz.Height() * 8 / 10 );
750cdf0e10cSrcweir 	pModulWindow->GetEditVScrollBar().SetLineSize( GetTextHeight() );
751cdf0e10cSrcweir 	pModulWindow->GetEditVScrollBar().SetThumbPos( pEditView->GetStartDocPos().Y() );
752cdf0e10cSrcweir 	pModulWindow->GetEditVScrollBar().Show();
753cdf0e10cSrcweir 
754cdf0e10cSrcweir 	if ( pModulWindow->GetHScrollBar() )
755cdf0e10cSrcweir 	{
756cdf0e10cSrcweir 		pModulWindow->GetHScrollBar()->SetVisibleSize( aOutSz.Width() );
757cdf0e10cSrcweir 		pModulWindow->GetHScrollBar()->SetPageSize( aOutSz.Width() * 8 / 10 );
758cdf0e10cSrcweir 		pModulWindow->GetHScrollBar()->SetLineSize( GetTextWidth( 'x' ) );
759cdf0e10cSrcweir 		pModulWindow->GetHScrollBar()->SetThumbPos( pEditView->GetStartDocPos().X() );
760cdf0e10cSrcweir 		pModulWindow->GetHScrollBar()->Show();
761cdf0e10cSrcweir 	}
762cdf0e10cSrcweir }
763cdf0e10cSrcweir 
764cdf0e10cSrcweir void EditorWindow::ImpDoHighlight( sal_uLong nLine )
765cdf0e10cSrcweir {
766cdf0e10cSrcweir 	if ( bDoSyntaxHighlight )
767cdf0e10cSrcweir 	{
768cdf0e10cSrcweir 		String aLine( pEditEngine->GetText( nLine ) );
769cdf0e10cSrcweir 		Range aChanges = aHighlighter.notifyChange( nLine, 0, &aLine, 1 );
770cdf0e10cSrcweir 		if ( aChanges.Len() )
771cdf0e10cSrcweir 		{
772cdf0e10cSrcweir 			for ( long n = aChanges.Min() + 1; n <= aChanges.Max(); n++ )
773cdf0e10cSrcweir 				aSyntaxLineTable.Insert( n, (void*)(sal_uLong)1 );
774cdf0e10cSrcweir 			aSyntaxIdleTimer.Start();
775cdf0e10cSrcweir 		}
776cdf0e10cSrcweir 
777cdf0e10cSrcweir 		sal_Bool bWasModified = pEditEngine->IsModified();
778cdf0e10cSrcweir 		pEditEngine->RemoveAttribs( nLine, sal_True );
779cdf0e10cSrcweir 		HighlightPortions aPortions;
780cdf0e10cSrcweir 		aHighlighter.getHighlightPortions( nLine, aLine, aPortions );
781cdf0e10cSrcweir 
782cdf0e10cSrcweir 		for ( size_t i = 0; i < aPortions.size(); i++ )
783cdf0e10cSrcweir 		{
784cdf0e10cSrcweir 			HighlightPortion& r = aPortions[i];
785cdf0e10cSrcweir 			const Color& rColor = ((ModulWindowLayout*)pModulWindow->GetLayoutWindow())->getSyntaxColor(r.tokenType);
786cdf0e10cSrcweir 			pEditEngine->SetAttrib( TextAttribFontColor( rColor ), nLine, r.nBegin, r.nEnd, sal_True );
787cdf0e10cSrcweir 		}
788cdf0e10cSrcweir 
789cdf0e10cSrcweir 		// Das Highlighten soll kein Modify setzen
790cdf0e10cSrcweir 		pEditEngine->SetModified( bWasModified );
791cdf0e10cSrcweir 	}
792cdf0e10cSrcweir }
793cdf0e10cSrcweir 
794cdf0e10cSrcweir void EditorWindow::ImplSetFont()
795cdf0e10cSrcweir {
796cdf0e10cSrcweir     if ( pSourceViewConfig )
797cdf0e10cSrcweir 	{
798cdf0e10cSrcweir 		String sFontName = pSourceViewConfig->GetFontName();
799cdf0e10cSrcweir 		if ( !sFontName.Len() )
800cdf0e10cSrcweir 		{
801cdf0e10cSrcweir 			Font aTmpFont( OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, Application::GetSettings().GetUILanguage(), 0 , this ) );
802cdf0e10cSrcweir 			sFontName = aTmpFont.GetName();
803cdf0e10cSrcweir 		}
804cdf0e10cSrcweir 		Size aFontSize( 0, pSourceViewConfig->GetFontHeight() );
805cdf0e10cSrcweir 		Font aFont( sFontName, aFontSize );
806cdf0e10cSrcweir 		aFont.SetColor( GetSettings().GetStyleSettings().GetFieldTextColor() );
807cdf0e10cSrcweir 		SetPointFont( aFont );
808cdf0e10cSrcweir 		aFont = GetFont();
809cdf0e10cSrcweir 
810cdf0e10cSrcweir 		if ( pModulWindow )
811cdf0e10cSrcweir 			pModulWindow->GetBreakPointWindow().SetFont( aFont );
812cdf0e10cSrcweir 
813cdf0e10cSrcweir 		if ( pEditEngine )
814cdf0e10cSrcweir 		{
815cdf0e10cSrcweir 			sal_Bool bModified = pEditEngine->IsModified();
816cdf0e10cSrcweir 			pEditEngine->SetFont( aFont );
817cdf0e10cSrcweir 			pEditEngine->SetModified( bModified );
818cdf0e10cSrcweir 		}
819cdf0e10cSrcweir 	}
820cdf0e10cSrcweir }
821cdf0e10cSrcweir 
822cdf0e10cSrcweir void EditorWindow::DoSyntaxHighlight( sal_uLong nPara )
823cdf0e10cSrcweir {
824cdf0e10cSrcweir 	// Durch das DelayedSyntaxHighlight kann es passieren,
825cdf0e10cSrcweir 	// dass die Zeile nicht mehr existiert!
826cdf0e10cSrcweir 	if ( nPara < pEditEngine->GetParagraphCount() )
827cdf0e10cSrcweir 	{
828cdf0e10cSrcweir 		// leider weis ich nicht, ob genau diese Zeile Modified() ...
829cdf0e10cSrcweir 		if ( pProgress )
830cdf0e10cSrcweir 			pProgress->StepProgress();
831cdf0e10cSrcweir 		ImpDoHighlight( nPara );
832cdf0e10cSrcweir 	}
833cdf0e10cSrcweir }
834cdf0e10cSrcweir 
835cdf0e10cSrcweir void EditorWindow::DoDelayedSyntaxHighlight( sal_uLong nPara )
836cdf0e10cSrcweir {
837cdf0e10cSrcweir 	// Zeile wird nur in 'Liste' aufgenommen, im TimerHdl abgearbeitet.
838cdf0e10cSrcweir 	// => Nicht Absaetze manipulieren, waehrend EditEngine formatiert.
839cdf0e10cSrcweir 	if ( pProgress )
840cdf0e10cSrcweir 		pProgress->StepProgress();
841cdf0e10cSrcweir 
842cdf0e10cSrcweir 	if ( !bHighlightning && bDoSyntaxHighlight )
843cdf0e10cSrcweir 	{
844cdf0e10cSrcweir 		if ( bDelayHighlight )
845cdf0e10cSrcweir 		{
846cdf0e10cSrcweir 			aSyntaxLineTable.Insert( nPara, (void*)(sal_uLong)1 );
847cdf0e10cSrcweir 			aSyntaxIdleTimer.Start();
848cdf0e10cSrcweir 		}
849cdf0e10cSrcweir 		else
850cdf0e10cSrcweir 			DoSyntaxHighlight( nPara );
851cdf0e10cSrcweir 	}
852cdf0e10cSrcweir }
853cdf0e10cSrcweir 
854cdf0e10cSrcweir IMPL_LINK( EditorWindow, SyntaxTimerHdl, Timer *, EMPTYARG )
855cdf0e10cSrcweir {
856cdf0e10cSrcweir 	DBG_ASSERT( pEditView, "Noch keine View, aber Syntax-Highlight ?!" );
857cdf0e10cSrcweir 
858cdf0e10cSrcweir 	sal_Bool bWasModified = pEditEngine->IsModified();
859cdf0e10cSrcweir 	// pEditEngine->SetUpdateMode( sal_False );
860cdf0e10cSrcweir 
861cdf0e10cSrcweir 	bHighlightning = sal_True;
862cdf0e10cSrcweir 	sal_uInt16 nLine;
863cdf0e10cSrcweir 	void* p = aSyntaxLineTable.First();
864cdf0e10cSrcweir 	while ( p )
865cdf0e10cSrcweir 	{
866cdf0e10cSrcweir 		nLine = (sal_uInt16)aSyntaxLineTable.GetCurKey();
867cdf0e10cSrcweir 		DoSyntaxHighlight( nLine );
868cdf0e10cSrcweir 		p = aSyntaxLineTable.Next();
869cdf0e10cSrcweir 	}
870cdf0e10cSrcweir 
871cdf0e10cSrcweir     // MT: Removed, because of idle format now when set/remove attribs...
872cdf0e10cSrcweir     // pEditView->SetAutoScroll( sal_False );  // #101043# Don't scroll because of syntax highlight
873cdf0e10cSrcweir     // pEditEngine->SetUpdateMode( sal_True );
874cdf0e10cSrcweir 	// pEditView->ShowCursor( sal_False, sal_True );
875cdf0e10cSrcweir     // pEditView->SetAutoScroll( sal_True );
876cdf0e10cSrcweir 
877cdf0e10cSrcweir     // #i45572#
878cdf0e10cSrcweir     if ( pEditView )
879cdf0e10cSrcweir         pEditView->ShowCursor( sal_False, sal_True );
880cdf0e10cSrcweir 
881cdf0e10cSrcweir 	pEditEngine->SetModified( bWasModified );
882cdf0e10cSrcweir 
883cdf0e10cSrcweir 	aSyntaxLineTable.Clear();
884cdf0e10cSrcweir 	bHighlightning = sal_False;
885cdf0e10cSrcweir 
886cdf0e10cSrcweir 	return 0;
887cdf0e10cSrcweir }
888cdf0e10cSrcweir 
889cdf0e10cSrcweir void EditorWindow::ParagraphInsertedDeleted( sal_uLong nPara, sal_Bool bInserted )
890cdf0e10cSrcweir {
891cdf0e10cSrcweir 	if ( pProgress )
892cdf0e10cSrcweir 		pProgress->StepProgress();
893cdf0e10cSrcweir 
894cdf0e10cSrcweir 	if ( !bInserted && ( nPara == TEXT_PARA_ALL ) )
895cdf0e10cSrcweir 	{
896cdf0e10cSrcweir 		pModulWindow->GetBreakPoints().reset();
897cdf0e10cSrcweir 		pModulWindow->GetBreakPointWindow().Invalidate();
898cdf0e10cSrcweir 		aHighlighter.initialize( HIGHLIGHT_BASIC );
899cdf0e10cSrcweir 	}
900cdf0e10cSrcweir 	else
901cdf0e10cSrcweir 	{
902cdf0e10cSrcweir 		// Brechpunkte Aktualisieren...
903cdf0e10cSrcweir 		// keine Sonderbehandlung fuer EditEngine-CTOR ( Erste-Zeile-Problem ),
904cdf0e10cSrcweir 		// da in diesem Moment noch keine BreakPoints.
905cdf0e10cSrcweir 		// +1: Basic-Zeilen beginnen bei 1!
906cdf0e10cSrcweir 		pModulWindow->GetBreakPoints().AdjustBreakPoints( (sal_uInt16)nPara+1, bInserted );
907cdf0e10cSrcweir 
908cdf0e10cSrcweir 		// Im BreakPointWindow invalidieren...
909cdf0e10cSrcweir 		long nLineHeight = GetTextHeight();
910cdf0e10cSrcweir 		Size aSz = pModulWindow->GetBreakPointWindow().GetOutputSize();
911cdf0e10cSrcweir 		Rectangle aInvRec( Point( 0, 0 ), aSz );
912cdf0e10cSrcweir 		long nY = nPara*nLineHeight - pModulWindow->GetBreakPointWindow().GetCurYOffset();
913cdf0e10cSrcweir 		aInvRec.Top() = nY;
914cdf0e10cSrcweir 		pModulWindow->GetBreakPointWindow().Invalidate( aInvRec );
915cdf0e10cSrcweir 
916cdf0e10cSrcweir 		if ( bDoSyntaxHighlight )
917cdf0e10cSrcweir 		{
918cdf0e10cSrcweir 			String aDummy;
919cdf0e10cSrcweir 			aHighlighter.notifyChange( nPara, bInserted ? 1 : (-1), &aDummy, 1 );
920cdf0e10cSrcweir 		}
921cdf0e10cSrcweir 	}
922cdf0e10cSrcweir }
923cdf0e10cSrcweir 
924cdf0e10cSrcweir void EditorWindow::CreateProgress( const String& rText, sal_uLong nRange )
925cdf0e10cSrcweir {
926cdf0e10cSrcweir 	DBG_ASSERT( !pProgress, "ProgressInfo existiert schon" );
927cdf0e10cSrcweir 	pProgress = new ProgressInfo( IDE_DLL()->GetShell()->GetViewFrame()->GetObjectShell(), rText, nRange );
928cdf0e10cSrcweir }
929cdf0e10cSrcweir 
930cdf0e10cSrcweir void EditorWindow::DestroyProgress()
931cdf0e10cSrcweir {
932cdf0e10cSrcweir 	DELETEZ( pProgress );
933cdf0e10cSrcweir }
934cdf0e10cSrcweir 
935cdf0e10cSrcweir void EditorWindow::ForceSyntaxTimeout()
936cdf0e10cSrcweir {
937cdf0e10cSrcweir 	aSyntaxIdleTimer.Stop();
938cdf0e10cSrcweir 	((Link&)aSyntaxIdleTimer.GetTimeoutHdl()).Call( &aSyntaxIdleTimer );
939cdf0e10cSrcweir }
940cdf0e10cSrcweir 
941cdf0e10cSrcweir 
942cdf0e10cSrcweir 
943cdf0e10cSrcweir BreakPointWindow::BreakPointWindow( Window* pParent ) :
944cdf0e10cSrcweir 	Window( pParent, WB_BORDER )
945cdf0e10cSrcweir {
946cdf0e10cSrcweir 	pModulWindow = 0;
947cdf0e10cSrcweir 	nCurYOffset = 0;
948cdf0e10cSrcweir     setBackgroundColor(GetSettings().GetStyleSettings().GetFieldColor());
949cdf0e10cSrcweir     m_bHighContrastMode = GetSettings().GetStyleSettings().GetHighContrastMode();
950cdf0e10cSrcweir 	nMarkerPos = MARKER_NOMARKER;
951cdf0e10cSrcweir 
952cdf0e10cSrcweir 	// nCurYOffset merken und nicht von EditEngine holen.
953cdf0e10cSrcweir 	// Falls in EditEngine autom. gescrollt wurde, wuesste ich sonst nicht,
954cdf0e10cSrcweir 	// wo ich gerade stehe.
955cdf0e10cSrcweir 
956cdf0e10cSrcweir 	SetHelpId( HID_BASICIDE_BREAKPOINTWINDOW );
957cdf0e10cSrcweir }
958cdf0e10cSrcweir 
959cdf0e10cSrcweir 
960cdf0e10cSrcweir 
961cdf0e10cSrcweir __EXPORT BreakPointWindow::~BreakPointWindow()
962cdf0e10cSrcweir {
963cdf0e10cSrcweir }
964cdf0e10cSrcweir 
965cdf0e10cSrcweir 
966cdf0e10cSrcweir 
967cdf0e10cSrcweir void __EXPORT BreakPointWindow::Resize()
968cdf0e10cSrcweir {
969cdf0e10cSrcweir ///	Invalidate();
970cdf0e10cSrcweir }
971cdf0e10cSrcweir 
972cdf0e10cSrcweir 
973cdf0e10cSrcweir 
974cdf0e10cSrcweir void __EXPORT BreakPointWindow::Paint( const Rectangle& )
975cdf0e10cSrcweir {
976cdf0e10cSrcweir 	if ( SyncYOffset() )
977cdf0e10cSrcweir 		return;
978cdf0e10cSrcweir 
979cdf0e10cSrcweir 	Size aOutSz( GetOutputSize() );
980cdf0e10cSrcweir 	long nLineHeight = GetTextHeight();
981cdf0e10cSrcweir 
982cdf0e10cSrcweir 	Image aBrk1(((ModulWindowLayout *) pModulWindow->GetLayoutWindow())->
983cdf0e10cSrcweir                 getImage(IMGID_BRKENABLED, m_bHighContrastMode));
984cdf0e10cSrcweir 	Image aBrk0(((ModulWindowLayout *) pModulWindow->GetLayoutWindow())->
985cdf0e10cSrcweir                 getImage(IMGID_BRKDISABLED, m_bHighContrastMode));
986cdf0e10cSrcweir 	Size aBmpSz( aBrk1.GetSizePixel() );
987cdf0e10cSrcweir 	aBmpSz = PixelToLogic( aBmpSz );
988cdf0e10cSrcweir 	Point aBmpOff( 0, 0 );
989cdf0e10cSrcweir 	aBmpOff.X() = ( aOutSz.Width() - aBmpSz.Width() ) / 2;
990cdf0e10cSrcweir 	aBmpOff.Y() = ( nLineHeight - aBmpSz.Height() ) / 2;
991cdf0e10cSrcweir 
992cdf0e10cSrcweir 	BreakPoint* pBrk = GetBreakPoints().First();
993cdf0e10cSrcweir 	while ( pBrk )
994cdf0e10cSrcweir 	{
995cdf0e10cSrcweir 		sal_uLong nLine = pBrk->nLine-1;
996cdf0e10cSrcweir 		sal_uLong nY = nLine*nLineHeight - nCurYOffset;
997cdf0e10cSrcweir 		DrawImage( Point( 0, nY ) + aBmpOff, pBrk->bEnabled ? aBrk1 : aBrk0 );
998cdf0e10cSrcweir 		pBrk = GetBreakPoints().Next();
999cdf0e10cSrcweir 	}
1000cdf0e10cSrcweir 	ShowMarker( sal_True );
1001cdf0e10cSrcweir }
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir 
1004cdf0e10cSrcweir 
1005cdf0e10cSrcweir void BreakPointWindow::DoScroll( long nHorzScroll, long nVertScroll )
1006cdf0e10cSrcweir {
1007cdf0e10cSrcweir 	nCurYOffset -= nVertScroll;
1008cdf0e10cSrcweir 	Window::Scroll( nHorzScroll, nVertScroll );
1009cdf0e10cSrcweir }
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir 
1012cdf0e10cSrcweir 
1013cdf0e10cSrcweir void BreakPointWindow::SetMarkerPos( sal_uInt16 nLine, sal_Bool bError )
1014cdf0e10cSrcweir {
1015cdf0e10cSrcweir 	if ( SyncYOffset() )
1016cdf0e10cSrcweir 		Update();
1017cdf0e10cSrcweir 
1018cdf0e10cSrcweir 	ShowMarker( sal_False );	// Alten wegzeichen...
1019cdf0e10cSrcweir 	nMarkerPos = nLine;
1020cdf0e10cSrcweir 	bErrorMarker = bError;
1021cdf0e10cSrcweir 	ShowMarker( sal_True );		// Neuen zeichnen...
1022cdf0e10cSrcweir }
1023cdf0e10cSrcweir 
1024cdf0e10cSrcweir void BreakPointWindow::ShowMarker( sal_Bool bShow )
1025cdf0e10cSrcweir {
1026cdf0e10cSrcweir 	if ( nMarkerPos == MARKER_NOMARKER )
1027cdf0e10cSrcweir 		return;
1028cdf0e10cSrcweir 
1029cdf0e10cSrcweir 	Size aOutSz( GetOutputSize() );
1030cdf0e10cSrcweir 	long nLineHeight = GetTextHeight();
1031cdf0e10cSrcweir 
1032cdf0e10cSrcweir 	Image aMarker(((ModulWindowLayout*)pModulWindow->GetLayoutWindow())->
1033cdf0e10cSrcweir                   getImage(bErrorMarker
1034cdf0e10cSrcweir                            ? IMGID_ERRORMARKER : IMGID_STEPMARKER,
1035cdf0e10cSrcweir                            m_bHighContrastMode));
1036cdf0e10cSrcweir 
1037cdf0e10cSrcweir 	Size aMarkerSz( aMarker.GetSizePixel() );
1038cdf0e10cSrcweir 	aMarkerSz = PixelToLogic( aMarkerSz );
1039cdf0e10cSrcweir 	Point aMarkerOff( 0, 0 );
1040cdf0e10cSrcweir 	aMarkerOff.X() = ( aOutSz.Width() - aMarkerSz.Width() ) / 2;
1041cdf0e10cSrcweir 	aMarkerOff.Y() = ( nLineHeight - aMarkerSz.Height() ) / 2;
1042cdf0e10cSrcweir 
1043cdf0e10cSrcweir 	sal_uLong nY = nMarkerPos*nLineHeight - nCurYOffset;
1044cdf0e10cSrcweir 	Point aPos( 0, nY );
1045cdf0e10cSrcweir 	aPos += aMarkerOff;
1046cdf0e10cSrcweir 	if ( bShow )
1047cdf0e10cSrcweir 		DrawImage( aPos, aMarker );
1048cdf0e10cSrcweir 	else
1049cdf0e10cSrcweir 		Invalidate( Rectangle( aPos, aMarkerSz ) );
1050cdf0e10cSrcweir }
1051cdf0e10cSrcweir 
1052cdf0e10cSrcweir 
1053cdf0e10cSrcweir 
1054cdf0e10cSrcweir 
1055cdf0e10cSrcweir BreakPoint*	BreakPointWindow::FindBreakPoint( const Point& rMousePos )
1056cdf0e10cSrcweir {
1057cdf0e10cSrcweir 	long nLineHeight = GetTextHeight();
1058cdf0e10cSrcweir 	long nYPos = rMousePos.Y() + nCurYOffset;
1059cdf0e10cSrcweir //	Image aBrk( ((ModulWindowLayout*)pModulWindow->GetLayoutWindow())->GetImage( IMGID_BRKENABLED ) );
1060cdf0e10cSrcweir //	Size aBmpSz( aBrk.GetSizePixel() );
1061cdf0e10cSrcweir //	aBmpSz = PixelToLogic( aBmpSz );
1062cdf0e10cSrcweir 
1063cdf0e10cSrcweir 	BreakPoint* pBrk = GetBreakPoints().First();
1064cdf0e10cSrcweir 	while ( pBrk )
1065cdf0e10cSrcweir 	{
1066cdf0e10cSrcweir 		sal_uLong nLine = pBrk->nLine-1;
1067cdf0e10cSrcweir 		long nY = nLine*nLineHeight;
1068cdf0e10cSrcweir 		if ( ( nYPos > nY ) && ( nYPos < ( nY + nLineHeight ) ) )
1069cdf0e10cSrcweir 			return pBrk;
1070cdf0e10cSrcweir 		pBrk = GetBreakPoints().Next();
1071cdf0e10cSrcweir 	}
1072cdf0e10cSrcweir 	return 0;
1073cdf0e10cSrcweir }
1074cdf0e10cSrcweir 
1075cdf0e10cSrcweir void __EXPORT BreakPointWindow::MouseButtonDown( const MouseEvent& rMEvt )
1076cdf0e10cSrcweir {
1077cdf0e10cSrcweir 	if ( rMEvt.GetClicks() == 2 )
1078cdf0e10cSrcweir 	{
1079cdf0e10cSrcweir 		Point aMousePos( PixelToLogic( rMEvt.GetPosPixel() ) );
1080cdf0e10cSrcweir 		long nLineHeight = GetTextHeight();
1081cdf0e10cSrcweir 		long nYPos = aMousePos.Y() + nCurYOffset;
1082cdf0e10cSrcweir 		long nLine = nYPos / nLineHeight + 1;
1083cdf0e10cSrcweir 		pModulWindow->ToggleBreakPoint( (sal_uLong)nLine );
1084cdf0e10cSrcweir 		// vielleicht mal etwas genauer...
1085cdf0e10cSrcweir 		Invalidate();
1086cdf0e10cSrcweir 	}
1087cdf0e10cSrcweir }
1088cdf0e10cSrcweir 
1089cdf0e10cSrcweir 
1090cdf0e10cSrcweir 
1091cdf0e10cSrcweir void __EXPORT BreakPointWindow::Command( const CommandEvent& rCEvt )
1092cdf0e10cSrcweir {
1093cdf0e10cSrcweir 	if ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU )
1094cdf0e10cSrcweir 	{
1095cdf0e10cSrcweir 		Point aPos( rCEvt.IsMouseEvent() ? rCEvt.GetMousePosPixel() : Point(1,1) );
1096cdf0e10cSrcweir 		Point aEventPos( PixelToLogic( aPos ) );
1097cdf0e10cSrcweir 		BreakPoint* pBrk = rCEvt.IsMouseEvent() ? FindBreakPoint( aEventPos ) : 0;
1098cdf0e10cSrcweir 		if ( pBrk )
1099cdf0e10cSrcweir 		{
1100cdf0e10cSrcweir 			// prueffen, ob Brechpunkt enabled....
1101cdf0e10cSrcweir 			PopupMenu aBrkPropMenu( IDEResId( RID_POPUP_BRKPROPS ) );
1102cdf0e10cSrcweir 			aBrkPropMenu.CheckItem( RID_ACTIV, pBrk->bEnabled );
1103cdf0e10cSrcweir 			switch ( aBrkPropMenu.Execute( this, aPos ) )
1104cdf0e10cSrcweir 			{
1105cdf0e10cSrcweir 				case RID_ACTIV:
1106cdf0e10cSrcweir 				{
1107cdf0e10cSrcweir 					pBrk->bEnabled = pBrk->bEnabled ? sal_False : sal_True;
1108cdf0e10cSrcweir 					pModulWindow->UpdateBreakPoint( *pBrk );
1109cdf0e10cSrcweir 					Invalidate();
1110cdf0e10cSrcweir 				}
1111cdf0e10cSrcweir 				break;
1112cdf0e10cSrcweir 				case RID_BRKPROPS:
1113cdf0e10cSrcweir 				{
1114cdf0e10cSrcweir 					BreakPointDialog aBrkDlg( this, GetBreakPoints() );
1115cdf0e10cSrcweir 					aBrkDlg.SetCurrentBreakPoint( pBrk );
1116cdf0e10cSrcweir 					aBrkDlg.Execute();
1117cdf0e10cSrcweir 					Invalidate();
1118cdf0e10cSrcweir 				}
1119cdf0e10cSrcweir 				break;
1120cdf0e10cSrcweir 			}
1121cdf0e10cSrcweir 		}
1122cdf0e10cSrcweir 		else
1123cdf0e10cSrcweir 		{
1124cdf0e10cSrcweir 			PopupMenu aBrkListMenu( IDEResId( RID_POPUP_BRKDLG ) );
1125cdf0e10cSrcweir 			switch ( aBrkListMenu.Execute( this, aPos ) )
1126cdf0e10cSrcweir 			{
1127cdf0e10cSrcweir 				case RID_BRKDLG:
1128cdf0e10cSrcweir 				{
1129cdf0e10cSrcweir 					BreakPointDialog aBrkDlg( this, GetBreakPoints() );
1130cdf0e10cSrcweir 					aBrkDlg.Execute();
1131cdf0e10cSrcweir 					Invalidate();
1132cdf0e10cSrcweir 				}
1133cdf0e10cSrcweir 				break;
1134cdf0e10cSrcweir 			}
1135cdf0e10cSrcweir 		}
1136cdf0e10cSrcweir 	}
1137cdf0e10cSrcweir }
1138cdf0e10cSrcweir 
1139cdf0e10cSrcweir sal_Bool BreakPointWindow::SyncYOffset()
1140cdf0e10cSrcweir {
1141cdf0e10cSrcweir 	TextView* pView = pModulWindow->GetEditView();
1142cdf0e10cSrcweir 	if ( pView )
1143cdf0e10cSrcweir 	{
1144cdf0e10cSrcweir 		long nViewYOffset = pView->GetStartDocPos().Y();
1145cdf0e10cSrcweir 		if ( nCurYOffset != nViewYOffset )
1146cdf0e10cSrcweir 		{
1147cdf0e10cSrcweir 			nCurYOffset = nViewYOffset;
1148cdf0e10cSrcweir 			Invalidate();
1149cdf0e10cSrcweir 			return sal_True;
1150cdf0e10cSrcweir 		}
1151cdf0e10cSrcweir 	}
1152cdf0e10cSrcweir 	return sal_False;
1153cdf0e10cSrcweir }
1154cdf0e10cSrcweir 
1155cdf0e10cSrcweir // virtual
1156cdf0e10cSrcweir void BreakPointWindow::DataChanged(DataChangedEvent const & rDCEvt)
1157cdf0e10cSrcweir {
1158cdf0e10cSrcweir     Window::DataChanged(rDCEvt);
1159cdf0e10cSrcweir     if (rDCEvt.GetType() == DATACHANGED_SETTINGS
1160cdf0e10cSrcweir         && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
1161cdf0e10cSrcweir     {
1162cdf0e10cSrcweir         Color aColor(GetSettings().GetStyleSettings().GetFieldColor());
1163cdf0e10cSrcweir         if (aColor
1164cdf0e10cSrcweir             != rDCEvt.GetOldSettings()->GetStyleSettings().GetFieldColor())
1165cdf0e10cSrcweir         {
1166cdf0e10cSrcweir             setBackgroundColor(aColor);
1167cdf0e10cSrcweir             m_bHighContrastMode = GetSettings().GetStyleSettings().GetHighContrastMode();
1168cdf0e10cSrcweir             Invalidate();
1169cdf0e10cSrcweir         }
1170cdf0e10cSrcweir     }
1171cdf0e10cSrcweir }
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir void BreakPointWindow::setBackgroundColor(Color aColor)
1174cdf0e10cSrcweir {
1175cdf0e10cSrcweir 	SetBackground(Wallpaper(aColor));
1176cdf0e10cSrcweir }
1177cdf0e10cSrcweir 
1178cdf0e10cSrcweir 
1179cdf0e10cSrcweir const sal_uInt16 ITEM_ID_VARIABLE = 1;
1180cdf0e10cSrcweir const sal_uInt16 ITEM_ID_VALUE = 2;
1181cdf0e10cSrcweir const sal_uInt16 ITEM_ID_TYPE = 3;
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir WatchWindow::WatchWindow( Window* pParent ) :
1184cdf0e10cSrcweir 	BasicDockingWindow( pParent ),
1185cdf0e10cSrcweir 	aWatchStr( IDEResId( RID_STR_REMOVEWATCH ) ),
1186cdf0e10cSrcweir 	aXEdit( this, IDEResId( RID_EDT_WATCHEDIT ) ),
1187cdf0e10cSrcweir 	aRemoveWatchButton( this, IDEResId( RID_IMGBTN_REMOVEWATCH ) ),
1188cdf0e10cSrcweir 	aTreeListBox( this, WB_BORDER | WB_3DLOOK | WB_HASBUTTONS | WB_HASLINES | WB_HSCROLL | WB_TABSTOP
1189cdf0e10cSrcweir 								  | WB_HASLINESATROOT | WB_HASBUTTONSATROOT ),
1190cdf0e10cSrcweir 	aHeaderBar( this, WB_BUTTONSTYLE | WB_BORDER )
1191cdf0e10cSrcweir {
1192cdf0e10cSrcweir 	aXEdit.SetAccessibleName(String(IDEResId( RID_STR_WATCHNAME)));
1193cdf0e10cSrcweir 	aTreeListBox.SetAccessibleName(String(IDEResId(RID_STR_WATCHNAME)));
1194cdf0e10cSrcweir 
1195cdf0e10cSrcweir 	nVirtToolBoxHeight = aXEdit.GetSizePixel().Height() + 7;
1196cdf0e10cSrcweir 	nHeaderBarHeight = 16;
1197cdf0e10cSrcweir 
1198cdf0e10cSrcweir     aTreeListBox.SetHelpId(HID_BASICIDE_WATCHWINDOW_LIST);
1199cdf0e10cSrcweir 	aTreeListBox.EnableInplaceEditing( sal_True );
1200cdf0e10cSrcweir 	aTreeListBox.SetSelectHdl( LINK( this, WatchWindow, TreeListHdl ) );
1201cdf0e10cSrcweir 	aTreeListBox.SetPosPixel( Point( DWBORDER, nVirtToolBoxHeight + nHeaderBarHeight ) );
1202cdf0e10cSrcweir 	aTreeListBox.SetHighlightRange( 1, 5 );
1203cdf0e10cSrcweir 
1204cdf0e10cSrcweir 	Point aPnt( DWBORDER, nVirtToolBoxHeight + 1 );
1205cdf0e10cSrcweir 	aHeaderBar.SetPosPixel( aPnt );
1206cdf0e10cSrcweir 	aHeaderBar.SetEndDragHdl( LINK( this, WatchWindow, implEndDragHdl ) );
1207cdf0e10cSrcweir 
1208cdf0e10cSrcweir 	long nVarTabWidth = 220;
1209cdf0e10cSrcweir 	long nValueTabWidth = 100;
1210cdf0e10cSrcweir 	long nTypeTabWidth = 1250;
1211cdf0e10cSrcweir     aHeaderBar.InsertItem( ITEM_ID_VARIABLE, String( IDEResId( RID_STR_WATCHVARIABLE ) ), nVarTabWidth );
1212cdf0e10cSrcweir     aHeaderBar.InsertItem( ITEM_ID_VALUE, String( IDEResId( RID_STR_WATCHVALUE ) ), nValueTabWidth );
1213cdf0e10cSrcweir     aHeaderBar.InsertItem( ITEM_ID_TYPE, String( IDEResId( RID_STR_WATCHTYPE ) ), nTypeTabWidth );
1214cdf0e10cSrcweir 
1215cdf0e10cSrcweir     long tabs[ 4 ];
1216cdf0e10cSrcweir     tabs[ 0 ] = 3; // two tabs
1217cdf0e10cSrcweir     tabs[ 1 ] = 0;
1218cdf0e10cSrcweir     tabs[ 2 ] = nVarTabWidth;
1219cdf0e10cSrcweir     tabs[ 3 ] = nVarTabWidth + nValueTabWidth;
1220cdf0e10cSrcweir 	aTreeListBox.SvHeaderTabListBox::SetTabs( tabs, MAP_PIXEL );
1221cdf0e10cSrcweir 	aTreeListBox.InitHeaderBar( &aHeaderBar );
1222cdf0e10cSrcweir 
1223cdf0e10cSrcweir 	aTreeListBox.SetNodeDefaultImages( );
1224cdf0e10cSrcweir 
1225cdf0e10cSrcweir 	aHeaderBar.Show();
1226cdf0e10cSrcweir 
1227cdf0e10cSrcweir 	aRemoveWatchButton.Disable();
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir 	aTreeListBox.Show();
1230cdf0e10cSrcweir 
1231cdf0e10cSrcweir 	long nTextLen = GetTextWidth( aWatchStr ) + DWBORDER;
1232cdf0e10cSrcweir 	aXEdit.SetPosPixel( Point( nTextLen, 3 ) );
1233cdf0e10cSrcweir 	aXEdit.SetAccHdl( LINK( this, WatchWindow, EditAccHdl ) );
1234cdf0e10cSrcweir 	aXEdit.GetAccelerator().InsertItem( 1, KeyCode( KEY_RETURN ) );
1235cdf0e10cSrcweir 	aXEdit.GetAccelerator().InsertItem( 2, KeyCode( KEY_ESCAPE ) );
1236cdf0e10cSrcweir 	aXEdit.Show();
1237cdf0e10cSrcweir 
1238cdf0e10cSrcweir     aRemoveWatchButton.SetModeImage(Image(IDEResId(RID_IMG_REMOVEWATCH_HC)),
1239cdf0e10cSrcweir                                     BMP_COLOR_HIGHCONTRAST);
1240cdf0e10cSrcweir 	aRemoveWatchButton.SetClickHdl( LINK( this, WatchWindow, ButtonHdl ) );
1241cdf0e10cSrcweir 	aRemoveWatchButton.SetPosPixel( Point( nTextLen + aXEdit.GetSizePixel().Width() + 4, 2 ) );
1242cdf0e10cSrcweir 	Size aSz( aRemoveWatchButton.GetModeImage().GetSizePixel() );
1243cdf0e10cSrcweir 	aSz.Width() += 6;
1244cdf0e10cSrcweir 	aSz.Height() += 6;
1245cdf0e10cSrcweir 	aRemoveWatchButton.SetSizePixel( aSz );
1246cdf0e10cSrcweir 	aRemoveWatchButton.Show();
1247cdf0e10cSrcweir 
1248cdf0e10cSrcweir 	SetText( String( IDEResId( RID_STR_WATCHNAME ) ) );
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir 	SetHelpId( HID_BASICIDE_WATCHWINDOW );
1251cdf0e10cSrcweir 
1252cdf0e10cSrcweir 	// make watch window keyboard accessible
1253cdf0e10cSrcweir 	GetSystemWindow()->GetTaskPaneList()->AddWindow( this );
1254cdf0e10cSrcweir }
1255cdf0e10cSrcweir 
1256cdf0e10cSrcweir 
1257cdf0e10cSrcweir 
1258cdf0e10cSrcweir __EXPORT WatchWindow::~WatchWindow()
1259cdf0e10cSrcweir {
1260cdf0e10cSrcweir 	GetSystemWindow()->GetTaskPaneList()->RemoveWindow( this );
1261cdf0e10cSrcweir }
1262cdf0e10cSrcweir 
1263cdf0e10cSrcweir 
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir void __EXPORT WatchWindow::Paint( const Rectangle& )
1266cdf0e10cSrcweir {
1267cdf0e10cSrcweir 	DrawText( Point( DWBORDER, 7 ), aWatchStr );
1268cdf0e10cSrcweir 	lcl_DrawIDEWindowFrame( this );
1269cdf0e10cSrcweir }
1270cdf0e10cSrcweir 
1271cdf0e10cSrcweir 
1272cdf0e10cSrcweir 
1273cdf0e10cSrcweir void __EXPORT WatchWindow::Resize()
1274cdf0e10cSrcweir {
1275cdf0e10cSrcweir 	Size aSz = GetOutputSizePixel();
1276cdf0e10cSrcweir 	Size aBoxSz( aSz.Width() - 2*DWBORDER, aSz.Height() - nVirtToolBoxHeight - DWBORDER );
1277cdf0e10cSrcweir 
1278cdf0e10cSrcweir 	if ( aBoxSz.Width() < 4 )	// < 4, weil noch Border...
1279cdf0e10cSrcweir 		aBoxSz.Width() = 0;
1280cdf0e10cSrcweir 	if ( aBoxSz.Height() < 4 )
1281cdf0e10cSrcweir 		aBoxSz.Height() = 0;
1282cdf0e10cSrcweir 
1283cdf0e10cSrcweir 	aBoxSz.Height() -= nHeaderBarHeight;
1284cdf0e10cSrcweir 	aTreeListBox.SetSizePixel( aBoxSz );
1285cdf0e10cSrcweir     aTreeListBox.GetHScroll()->SetPageSize( aTreeListBox.GetHScroll()->GetVisibleSize() );
1286cdf0e10cSrcweir 
1287cdf0e10cSrcweir 	aBoxSz.Height() = nHeaderBarHeight;
1288cdf0e10cSrcweir 	aHeaderBar.SetSizePixel( aBoxSz );
1289cdf0e10cSrcweir 
1290cdf0e10cSrcweir 	Invalidate();	//Wegen DrawLine im Paint...
1291cdf0e10cSrcweir }
1292cdf0e10cSrcweir 
1293cdf0e10cSrcweir struct MemberList
1294cdf0e10cSrcweir {
1295cdf0e10cSrcweir 	String*			mpMemberNames;
1296cdf0e10cSrcweir 	int				mnMemberCount;
1297cdf0e10cSrcweir 
1298cdf0e10cSrcweir 	MemberList( void )
1299cdf0e10cSrcweir 		: mpMemberNames( NULL )
1300cdf0e10cSrcweir 		, mnMemberCount( 0 )
1301cdf0e10cSrcweir 	{}
1302cdf0e10cSrcweir 	~MemberList()
1303cdf0e10cSrcweir 	{
1304cdf0e10cSrcweir 		clear();
1305cdf0e10cSrcweir 	}
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir 	void clear( void );
1308cdf0e10cSrcweir 	void allocList( int nCount );
1309cdf0e10cSrcweir };
1310cdf0e10cSrcweir 
1311cdf0e10cSrcweir void MemberList::clear( void )
1312cdf0e10cSrcweir {
1313cdf0e10cSrcweir 	if( mnMemberCount )
1314cdf0e10cSrcweir 	{
1315cdf0e10cSrcweir 		delete[] mpMemberNames;
1316cdf0e10cSrcweir 		mnMemberCount = 0;
1317cdf0e10cSrcweir 	}
1318cdf0e10cSrcweir }
1319cdf0e10cSrcweir 
1320cdf0e10cSrcweir void MemberList::allocList( int nCount )
1321cdf0e10cSrcweir {
1322cdf0e10cSrcweir 	clear();
1323cdf0e10cSrcweir 	if( nCount > 0 )
1324cdf0e10cSrcweir 	{
1325cdf0e10cSrcweir 		mnMemberCount = nCount;
1326cdf0e10cSrcweir 		mpMemberNames = new String[ mnMemberCount ];
1327cdf0e10cSrcweir 	}
1328cdf0e10cSrcweir }
1329cdf0e10cSrcweir 
1330cdf0e10cSrcweir struct WatchItem
1331cdf0e10cSrcweir {
1332cdf0e10cSrcweir     String          maName;
1333cdf0e10cSrcweir     String          maDisplayName;
1334cdf0e10cSrcweir     SbxObjectRef    mpObject;
1335cdf0e10cSrcweir 	MemberList		maMemberList;
1336cdf0e10cSrcweir 
1337cdf0e10cSrcweir     SbxDimArrayRef	mpArray;
1338cdf0e10cSrcweir 	int				nDimLevel;	// 0 = Root
1339cdf0e10cSrcweir 	int				nDimCount;
1340cdf0e10cSrcweir 	short*			pIndices;
1341cdf0e10cSrcweir 
1342cdf0e10cSrcweir 	WatchItem*		mpArrayParentItem;
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir     WatchItem( void )
1345cdf0e10cSrcweir 		: nDimLevel( 0 )
1346cdf0e10cSrcweir 		, nDimCount( 0 )
1347cdf0e10cSrcweir 		, pIndices( NULL )
1348cdf0e10cSrcweir 		, mpArrayParentItem( NULL )
1349cdf0e10cSrcweir     {}
1350cdf0e10cSrcweir     ~WatchItem()
1351cdf0e10cSrcweir 		{ clearWatchItem(); }
1352cdf0e10cSrcweir 
1353cdf0e10cSrcweir 	void clearWatchItem( bool bIncludeArrayData=true )
1354cdf0e10cSrcweir 	{
1355cdf0e10cSrcweir 		mpObject = NULL;
1356cdf0e10cSrcweir 		maMemberList.clear();
1357cdf0e10cSrcweir 		if( bIncludeArrayData )
1358cdf0e10cSrcweir 		{
1359cdf0e10cSrcweir 			mpArray = NULL;
1360cdf0e10cSrcweir 			nDimLevel = 0;
1361cdf0e10cSrcweir 			nDimCount = 0;
1362cdf0e10cSrcweir 			delete[] pIndices;
1363cdf0e10cSrcweir 			pIndices = NULL;
1364cdf0e10cSrcweir 		}
1365cdf0e10cSrcweir 	}
1366cdf0e10cSrcweir 
1367cdf0e10cSrcweir 	WatchItem* GetRootItem( void );
1368cdf0e10cSrcweir 	SbxDimArray* GetRootArray( void );
1369cdf0e10cSrcweir };
1370cdf0e10cSrcweir 
1371cdf0e10cSrcweir WatchItem* WatchItem::GetRootItem( void )
1372cdf0e10cSrcweir {
1373cdf0e10cSrcweir 	WatchItem* pItem = mpArrayParentItem;
1374cdf0e10cSrcweir 	while( pItem )
1375cdf0e10cSrcweir 	{
1376cdf0e10cSrcweir 		if( pItem->mpArray.Is() )
1377cdf0e10cSrcweir 			break;
1378cdf0e10cSrcweir 		pItem = pItem->mpArrayParentItem;
1379cdf0e10cSrcweir 	}
1380cdf0e10cSrcweir 	return pItem;
1381cdf0e10cSrcweir }
1382cdf0e10cSrcweir 
1383cdf0e10cSrcweir SbxDimArray* WatchItem::GetRootArray( void )
1384cdf0e10cSrcweir {
1385cdf0e10cSrcweir 	WatchItem* pRootItem = GetRootItem();
1386cdf0e10cSrcweir 	SbxDimArray* pRet = NULL;
1387cdf0e10cSrcweir 	if( pRootItem )
1388cdf0e10cSrcweir 		pRet = pRootItem->mpArray;
1389cdf0e10cSrcweir 	return pRet;
1390cdf0e10cSrcweir }
1391cdf0e10cSrcweir 
1392cdf0e10cSrcweir void WatchWindow::AddWatch( const String& rVName )
1393cdf0e10cSrcweir {
1394cdf0e10cSrcweir 	WatchItem* pWatchItem = new WatchItem;
1395cdf0e10cSrcweir 	String aVar, aIndex;
1396cdf0e10cSrcweir 	lcl_SeparateNameAndIndex( rVName, aVar, aIndex );
1397cdf0e10cSrcweir 	pWatchItem->maName = aVar;
1398cdf0e10cSrcweir 
1399cdf0e10cSrcweir 	String aWatchStr_( aVar );
1400cdf0e10cSrcweir 	aWatchStr_ += String( RTL_CONSTASCII_USTRINGPARAM( "\t\t" ) );
1401cdf0e10cSrcweir 	SvLBoxEntry* pNewEntry = aTreeListBox.InsertEntry( aWatchStr_, 0, sal_True, LIST_APPEND );
1402cdf0e10cSrcweir 	pNewEntry->SetUserData( pWatchItem );
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir 	aTreeListBox.Select( pNewEntry, sal_True );
1405cdf0e10cSrcweir 	aTreeListBox.MakeVisible( pNewEntry );
1406cdf0e10cSrcweir 	aRemoveWatchButton.Enable();
1407cdf0e10cSrcweir }
1408cdf0e10cSrcweir 
1409cdf0e10cSrcweir sal_Bool WatchWindow::RemoveSelectedWatch()
1410cdf0e10cSrcweir {
1411cdf0e10cSrcweir 	SvLBoxEntry* pEntry = aTreeListBox.GetCurEntry();
1412cdf0e10cSrcweir 	if ( pEntry )
1413cdf0e10cSrcweir 	{
1414cdf0e10cSrcweir 		aTreeListBox.GetModel()->Remove( pEntry );
1415cdf0e10cSrcweir 		pEntry = aTreeListBox.GetCurEntry();
1416cdf0e10cSrcweir 		if ( pEntry )
1417cdf0e10cSrcweir 			aXEdit.SetText( ((WatchItem*)pEntry->GetUserData())->maName );
1418cdf0e10cSrcweir 		else
1419cdf0e10cSrcweir 			aXEdit.SetText( String() );
1420cdf0e10cSrcweir 		if ( !aTreeListBox.GetEntryCount() )
1421cdf0e10cSrcweir 			aRemoveWatchButton.Disable();
1422cdf0e10cSrcweir 		return sal_True;
1423cdf0e10cSrcweir 	}
1424cdf0e10cSrcweir 	else
1425cdf0e10cSrcweir 		return sal_False;
1426cdf0e10cSrcweir }
1427cdf0e10cSrcweir 
1428cdf0e10cSrcweir 
1429cdf0e10cSrcweir IMPL_LINK_INLINE_START( WatchWindow, ButtonHdl, ImageButton *, pButton )
1430cdf0e10cSrcweir {
1431cdf0e10cSrcweir 	if ( pButton == &aRemoveWatchButton )
1432cdf0e10cSrcweir 	{
1433cdf0e10cSrcweir         BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
1434cdf0e10cSrcweir         SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
1435cdf0e10cSrcweir 	    SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
1436cdf0e10cSrcweir         if( pDispatcher )
1437cdf0e10cSrcweir 		{
1438cdf0e10cSrcweir 			pDispatcher->Execute( SID_BASICIDE_REMOVEWATCH );
1439cdf0e10cSrcweir 		}
1440cdf0e10cSrcweir 	}
1441cdf0e10cSrcweir 	return 0;
1442cdf0e10cSrcweir }
1443cdf0e10cSrcweir IMPL_LINK_INLINE_END( WatchWindow, ButtonHdl, ImageButton *, pButton )
1444cdf0e10cSrcweir 
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir 
1447cdf0e10cSrcweir IMPL_LINK_INLINE_START( WatchWindow, TreeListHdl, SvTreeListBox *, EMPTYARG )
1448cdf0e10cSrcweir {
1449cdf0e10cSrcweir 	SvLBoxEntry* pCurEntry = aTreeListBox.GetCurEntry();
1450cdf0e10cSrcweir 	if ( pCurEntry && pCurEntry->GetUserData() )
1451cdf0e10cSrcweir 		aXEdit.SetText( ((WatchItem*)pCurEntry->GetUserData())->maName );
1452cdf0e10cSrcweir 
1453cdf0e10cSrcweir 	return 0;
1454cdf0e10cSrcweir }
1455cdf0e10cSrcweir IMPL_LINK_INLINE_END( WatchWindow, TreeListHdl, SvTreeListBox *, EMPTYARG )
1456cdf0e10cSrcweir 
1457cdf0e10cSrcweir 
1458cdf0e10cSrcweir IMPL_LINK_INLINE_START( WatchWindow, implEndDragHdl, HeaderBar *, pBar )
1459cdf0e10cSrcweir {
1460cdf0e10cSrcweir 	(void)pBar;
1461cdf0e10cSrcweir 
1462cdf0e10cSrcweir     const sal_Int32 TAB_WIDTH_MIN = 10;
1463cdf0e10cSrcweir 	sal_Int32 nMaxWidth =
1464cdf0e10cSrcweir         aHeaderBar.GetSizePixel().getWidth() - 2 * TAB_WIDTH_MIN;
1465cdf0e10cSrcweir 
1466cdf0e10cSrcweir     sal_Int32 nVariableWith = aHeaderBar.GetItemSize( ITEM_ID_VARIABLE );
1467cdf0e10cSrcweir     if( nVariableWith < TAB_WIDTH_MIN )
1468cdf0e10cSrcweir         aHeaderBar.SetItemSize( ITEM_ID_VARIABLE, TAB_WIDTH_MIN );
1469cdf0e10cSrcweir     else if( nVariableWith > nMaxWidth )
1470cdf0e10cSrcweir         aHeaderBar.SetItemSize( ITEM_ID_VARIABLE, nMaxWidth );
1471cdf0e10cSrcweir 
1472cdf0e10cSrcweir     sal_Int32 nValueWith = aHeaderBar.GetItemSize( ITEM_ID_VALUE );
1473cdf0e10cSrcweir     if( nValueWith < TAB_WIDTH_MIN )
1474cdf0e10cSrcweir         aHeaderBar.SetItemSize( ITEM_ID_VALUE, TAB_WIDTH_MIN );
1475cdf0e10cSrcweir     else if( nValueWith > nMaxWidth )
1476cdf0e10cSrcweir         aHeaderBar.SetItemSize( ITEM_ID_VALUE, nMaxWidth );
1477cdf0e10cSrcweir 
1478cdf0e10cSrcweir     if (aHeaderBar.GetItemSize( ITEM_ID_TYPE ) < TAB_WIDTH_MIN)
1479cdf0e10cSrcweir         aHeaderBar.SetItemSize( ITEM_ID_TYPE, TAB_WIDTH_MIN );
1480cdf0e10cSrcweir 
1481cdf0e10cSrcweir     sal_Int32 nPos = 0;
1482cdf0e10cSrcweir 	sal_uInt16 nTabs = aHeaderBar.GetItemCount();
1483cdf0e10cSrcweir     // OSL_ASSERT( m_treelb->TabCount() == nTabs );
1484cdf0e10cSrcweir 	for( sal_uInt16 i = 1 ; i < nTabs ; ++i )
1485cdf0e10cSrcweir 	{
1486cdf0e10cSrcweir 		nPos += aHeaderBar.GetItemSize( i );
1487cdf0e10cSrcweir 		aTreeListBox.SetTab( i, nPos, MAP_PIXEL );
1488cdf0e10cSrcweir 	}
1489cdf0e10cSrcweir 	return 0;
1490cdf0e10cSrcweir }
1491cdf0e10cSrcweir IMPL_LINK_INLINE_END( WatchWindow, implEndDragHdl, HeaderBar *, pBar )
1492cdf0e10cSrcweir 
1493cdf0e10cSrcweir 
1494cdf0e10cSrcweir IMPL_LINK( WatchWindow, EditAccHdl, Accelerator *, pAcc )
1495cdf0e10cSrcweir {
1496cdf0e10cSrcweir 	switch ( pAcc->GetCurKeyCode().GetCode() )
1497cdf0e10cSrcweir 	{
1498cdf0e10cSrcweir 		case KEY_RETURN:
1499cdf0e10cSrcweir 		{
1500cdf0e10cSrcweir 			String aCurText( aXEdit.GetText() );
1501cdf0e10cSrcweir 			if ( aCurText.Len() )
1502cdf0e10cSrcweir 			{
1503cdf0e10cSrcweir 				AddWatch( aCurText );
1504cdf0e10cSrcweir 				aXEdit.SetSelection( Selection( 0, 0xFFFF ) );
1505cdf0e10cSrcweir 				UpdateWatches();
1506cdf0e10cSrcweir 			}
1507cdf0e10cSrcweir 			else
1508cdf0e10cSrcweir 				Sound::Beep();
1509cdf0e10cSrcweir 		}
1510cdf0e10cSrcweir 		break;
1511cdf0e10cSrcweir 		case KEY_ESCAPE:
1512cdf0e10cSrcweir 		{
1513cdf0e10cSrcweir 			aXEdit.SetText( String() );
1514cdf0e10cSrcweir 		}
1515cdf0e10cSrcweir 		break;
1516cdf0e10cSrcweir 	}
1517cdf0e10cSrcweir 
1518cdf0e10cSrcweir 	return 0;
1519cdf0e10cSrcweir }
1520cdf0e10cSrcweir 
1521cdf0e10cSrcweir void WatchWindow::UpdateWatches( bool bBasicStopped )
1522cdf0e10cSrcweir {
1523cdf0e10cSrcweir 	aTreeListBox.UpdateWatches( bBasicStopped );
1524cdf0e10cSrcweir }
1525cdf0e10cSrcweir 
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir StackWindow::StackWindow( Window* pParent ) :
1528cdf0e10cSrcweir 	BasicDockingWindow( pParent ),
1529cdf0e10cSrcweir 	aTreeListBox( this, WB_BORDER | WB_3DLOOK | WB_HSCROLL | WB_TABSTOP ),
1530cdf0e10cSrcweir 	aGotoCallButton( this, IDEResId( RID_IMGBTN_GOTOCALL ) ),
1531cdf0e10cSrcweir 	aStackStr( IDEResId( RID_STR_STACK ) )
1532cdf0e10cSrcweir {
1533cdf0e10cSrcweir    	aTreeListBox.SetHelpId(HID_BASICIDE_STACKWINDOW_LIST);
1534cdf0e10cSrcweir 	aTreeListBox.SetAccessibleName(String( IDEResId(RID_STR_STACKNAME)));
1535cdf0e10cSrcweir 	aTreeListBox.SetPosPixel( Point( DWBORDER, nVirtToolBoxHeight ) );
1536cdf0e10cSrcweir 	aTreeListBox.SetHighlightRange();
1537cdf0e10cSrcweir     aTreeListBox.SetSelectionMode( NO_SELECTION );
1538cdf0e10cSrcweir     aTreeListBox.InsertEntry( String(), 0, sal_False, LIST_APPEND );
1539cdf0e10cSrcweir 	aTreeListBox.Show();
1540cdf0e10cSrcweir 
1541cdf0e10cSrcweir 	SetText( String( IDEResId( RID_STR_STACKNAME ) ) );
1542cdf0e10cSrcweir 
1543cdf0e10cSrcweir 	SetHelpId( HID_BASICIDE_STACKWINDOW );
1544cdf0e10cSrcweir 
1545cdf0e10cSrcweir 	aGotoCallButton.SetClickHdl( LINK( this, StackWindow, ButtonHdl ) );
1546cdf0e10cSrcweir 	aGotoCallButton.SetPosPixel( Point( DWBORDER, 2 ) );
1547cdf0e10cSrcweir 	Size aSz( aGotoCallButton.GetModeImage().GetSizePixel() );
1548cdf0e10cSrcweir 	aSz.Width() += 6;
1549cdf0e10cSrcweir 	aSz.Height() += 6;
1550cdf0e10cSrcweir 	aGotoCallButton.SetSizePixel( aSz );
1551cdf0e10cSrcweir //	aGotoCallButton.Show();	// wird vom Basic noch nicht unterstuetzt!
1552cdf0e10cSrcweir 	aGotoCallButton.Hide();
1553cdf0e10cSrcweir 
1554cdf0e10cSrcweir 	// make stack window keyboard accessible
1555cdf0e10cSrcweir 	GetSystemWindow()->GetTaskPaneList()->AddWindow( this );
1556cdf0e10cSrcweir }
1557cdf0e10cSrcweir 
1558cdf0e10cSrcweir 
1559cdf0e10cSrcweir 
1560cdf0e10cSrcweir __EXPORT StackWindow::~StackWindow()
1561cdf0e10cSrcweir {
1562cdf0e10cSrcweir 	GetSystemWindow()->GetTaskPaneList()->RemoveWindow( this );
1563cdf0e10cSrcweir }
1564cdf0e10cSrcweir 
1565cdf0e10cSrcweir 
1566cdf0e10cSrcweir 
1567cdf0e10cSrcweir void __EXPORT StackWindow::Paint( const Rectangle& )
1568cdf0e10cSrcweir {
1569cdf0e10cSrcweir 	DrawText( Point( DWBORDER, 7 ), aStackStr );
1570cdf0e10cSrcweir 	lcl_DrawIDEWindowFrame( this );
1571cdf0e10cSrcweir }
1572cdf0e10cSrcweir 
1573cdf0e10cSrcweir 
1574cdf0e10cSrcweir 
1575cdf0e10cSrcweir void __EXPORT StackWindow::Resize()
1576cdf0e10cSrcweir {
1577cdf0e10cSrcweir 	Size aSz = GetOutputSizePixel();
1578cdf0e10cSrcweir 	Size aBoxSz( aSz.Width() - 2*DWBORDER, aSz.Height() - nVirtToolBoxHeight - DWBORDER );
1579cdf0e10cSrcweir 
1580cdf0e10cSrcweir 	if ( aBoxSz.Width() < 4 )	// < 4, weil noch Border...
1581cdf0e10cSrcweir 		aBoxSz.Width() = 0;
1582cdf0e10cSrcweir 	if ( aBoxSz.Height() < 4 )
1583cdf0e10cSrcweir 		aBoxSz.Height() = 0;
1584cdf0e10cSrcweir 
1585cdf0e10cSrcweir 	aTreeListBox.SetSizePixel( aBoxSz );
1586cdf0e10cSrcweir 
1587cdf0e10cSrcweir 	Invalidate();	//Wegen DrawLine im Paint...
1588cdf0e10cSrcweir }
1589cdf0e10cSrcweir 
1590cdf0e10cSrcweir 
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir IMPL_LINK_INLINE_START( StackWindow, ButtonHdl, ImageButton *, pButton )
1593cdf0e10cSrcweir {
1594cdf0e10cSrcweir 	if ( pButton == &aGotoCallButton )
1595cdf0e10cSrcweir 	{
1596cdf0e10cSrcweir         BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
1597cdf0e10cSrcweir         SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
1598cdf0e10cSrcweir 	    SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
1599cdf0e10cSrcweir         if( pDispatcher )
1600cdf0e10cSrcweir 		{
1601cdf0e10cSrcweir 			pDispatcher->Execute( SID_BASICIDE_GOTOCALL );
1602cdf0e10cSrcweir 		}
1603cdf0e10cSrcweir 	}
1604cdf0e10cSrcweir 	return 0;
1605cdf0e10cSrcweir }
1606cdf0e10cSrcweir IMPL_LINK_INLINE_END( StackWindow, ButtonHdl, ImageButton *, pButton )
1607cdf0e10cSrcweir 
1608cdf0e10cSrcweir 
1609cdf0e10cSrcweir 
1610cdf0e10cSrcweir void __EXPORT StackWindow::UpdateCalls()
1611cdf0e10cSrcweir {
1612cdf0e10cSrcweir 	aTreeListBox.SetUpdateMode( sal_False );
1613cdf0e10cSrcweir 	aTreeListBox.Clear();
1614cdf0e10cSrcweir 
1615cdf0e10cSrcweir     if ( StarBASIC::IsRunning() )
1616cdf0e10cSrcweir     {
1617cdf0e10cSrcweir 	    SbxError eOld = SbxBase::GetError();
1618cdf0e10cSrcweir         aTreeListBox.SetSelectionMode( SINGLE_SELECTION );
1619cdf0e10cSrcweir 
1620cdf0e10cSrcweir 	    sal_uInt16 nScope = 0;
1621cdf0e10cSrcweir 	    SbMethod* pMethod = StarBASIC::GetActiveMethod( nScope );
1622cdf0e10cSrcweir 	    while ( pMethod )
1623cdf0e10cSrcweir 	    {
1624cdf0e10cSrcweir 		    String aEntry( String::CreateFromInt32(nScope ));
1625cdf0e10cSrcweir 		    if ( aEntry.Len() < 2 )
1626cdf0e10cSrcweir 			    aEntry.Insert( ' ', 0 );
1627cdf0e10cSrcweir 		    aEntry += String( RTL_CONSTASCII_USTRINGPARAM( ": " ) );
1628cdf0e10cSrcweir 		    aEntry += pMethod->GetName();
1629cdf0e10cSrcweir 		    SbxArray* pParams = pMethod->GetParameters();
1630cdf0e10cSrcweir 		    SbxInfo* pInfo = pMethod->GetInfo();
1631cdf0e10cSrcweir 		    if ( pParams )
1632cdf0e10cSrcweir 		    {
1633cdf0e10cSrcweir 			    aEntry += '(';
1634cdf0e10cSrcweir 			    // 0 ist der Name der Sub...
1635cdf0e10cSrcweir 			    for ( sal_uInt16 nParam = 1; nParam < pParams->Count(); nParam++ )
1636cdf0e10cSrcweir 			    {
1637cdf0e10cSrcweir 				    SbxVariable* pVar = pParams->Get( nParam );
1638cdf0e10cSrcweir 				    DBG_ASSERT( pVar, "Parameter?!" );
1639cdf0e10cSrcweir 				    if ( pVar->GetName().Len() )
1640cdf0e10cSrcweir 					    aEntry += pVar->GetName();
1641cdf0e10cSrcweir 				    else if ( pInfo )
1642cdf0e10cSrcweir 				    {
1643cdf0e10cSrcweir 					    const SbxParamInfo* pParam = pInfo->GetParam( nParam );
1644cdf0e10cSrcweir 					    if ( pParam )
1645cdf0e10cSrcweir 						    aEntry += pParam->aName;
1646cdf0e10cSrcweir 				    }
1647cdf0e10cSrcweir 				    aEntry += '=';
1648cdf0e10cSrcweir 					SbxDataType eType = pVar->GetType();
1649cdf0e10cSrcweir 	    			if( eType & SbxARRAY )
1650cdf0e10cSrcweir 					    aEntry += String( RTL_CONSTASCII_USTRINGPARAM( "..." ) );
1651cdf0e10cSrcweir 				    else if( eType != SbxOBJECT )
1652cdf0e10cSrcweir 					    aEntry += pVar->GetString();
1653cdf0e10cSrcweir 				    if ( nParam < ( pParams->Count() - 1 ) )
1654cdf0e10cSrcweir 					    aEntry += String( RTL_CONSTASCII_USTRINGPARAM( ", " ) );
1655cdf0e10cSrcweir 			    }
1656cdf0e10cSrcweir 			    aEntry += ')';
1657cdf0e10cSrcweir 		    }
1658cdf0e10cSrcweir 		    aTreeListBox.InsertEntry( aEntry, 0, sal_False, LIST_APPEND );
1659cdf0e10cSrcweir 		    nScope++;
1660cdf0e10cSrcweir 		    pMethod = StarBASIC::GetActiveMethod( nScope );
1661cdf0e10cSrcweir 	    }
1662cdf0e10cSrcweir 
1663cdf0e10cSrcweir 	    SbxBase::ResetError();
1664cdf0e10cSrcweir 	    if( eOld != SbxERR_OK )
1665cdf0e10cSrcweir 		    SbxBase::SetError( eOld );
1666cdf0e10cSrcweir     }
1667cdf0e10cSrcweir     else
1668cdf0e10cSrcweir     {
1669cdf0e10cSrcweir         aTreeListBox.SetSelectionMode( NO_SELECTION );
1670cdf0e10cSrcweir         aTreeListBox.InsertEntry( String(), 0, sal_False, LIST_APPEND );
1671cdf0e10cSrcweir     }
1672cdf0e10cSrcweir 
1673cdf0e10cSrcweir 	aTreeListBox.SetUpdateMode( sal_True );
1674cdf0e10cSrcweir }
1675cdf0e10cSrcweir 
1676cdf0e10cSrcweir 
1677cdf0e10cSrcweir 
1678cdf0e10cSrcweir 
1679cdf0e10cSrcweir ComplexEditorWindow::ComplexEditorWindow( ModulWindow* pParent ) :
1680cdf0e10cSrcweir 	Window( pParent, WB_3DLOOK | WB_CLIPCHILDREN ),
1681cdf0e10cSrcweir 	aBrkWindow( this ),
1682cdf0e10cSrcweir 	aEdtWindow( this ),
1683cdf0e10cSrcweir 	aEWVScrollBar( this, WB_VSCROLL | WB_DRAG )
1684cdf0e10cSrcweir {
1685cdf0e10cSrcweir 	aEdtWindow.SetModulWindow( pParent );
1686cdf0e10cSrcweir 	aBrkWindow.SetModulWindow( pParent );
1687cdf0e10cSrcweir 	aEdtWindow.Show();
1688cdf0e10cSrcweir 	aBrkWindow.Show();
1689cdf0e10cSrcweir 
1690cdf0e10cSrcweir 	aEWVScrollBar.SetLineSize( SCROLL_LINE );
1691cdf0e10cSrcweir 	aEWVScrollBar.SetPageSize( SCROLL_PAGE );
1692cdf0e10cSrcweir 	aEWVScrollBar.SetScrollHdl( LINK( this, ComplexEditorWindow, ScrollHdl ) );
1693cdf0e10cSrcweir 	aEWVScrollBar.Show();
1694cdf0e10cSrcweir }
1695cdf0e10cSrcweir 
1696cdf0e10cSrcweir 
1697cdf0e10cSrcweir 
1698cdf0e10cSrcweir void __EXPORT ComplexEditorWindow::Resize()
1699cdf0e10cSrcweir {
1700cdf0e10cSrcweir 	Size aOutSz = GetOutputSizePixel();
1701cdf0e10cSrcweir 	Size aSz( aOutSz );
1702cdf0e10cSrcweir 	aSz.Width() -= 2*DWBORDER;
1703cdf0e10cSrcweir 	aSz.Height() -= 2*DWBORDER;
1704cdf0e10cSrcweir 	long nBrkWidth = 20;
1705cdf0e10cSrcweir 	long nSBWidth = aEWVScrollBar.GetSizePixel().Width();
1706cdf0e10cSrcweir 
1707cdf0e10cSrcweir 	Size aBrkSz( Size( nBrkWidth, aSz.Height() ) );
1708cdf0e10cSrcweir 	aBrkWindow.SetPosSizePixel( Point( DWBORDER, DWBORDER ), aBrkSz );
1709cdf0e10cSrcweir 
1710cdf0e10cSrcweir     Size aEWSz( Size( aSz.Width() - nBrkWidth - nSBWidth + 2, aSz.Height() ) );
1711cdf0e10cSrcweir 	aEdtWindow.SetPosSizePixel( Point( DWBORDER+aBrkSz.Width()-1, DWBORDER ), aEWSz );
1712cdf0e10cSrcweir 
1713cdf0e10cSrcweir 	aEWVScrollBar.SetPosSizePixel( Point( aOutSz.Width()-DWBORDER-nSBWidth, DWBORDER ), Size( nSBWidth, aSz.Height() ) );
1714cdf0e10cSrcweir 
1715cdf0e10cSrcweir 	// Macht das EditorWindow, ausserdem hier falsch, da Pixel
1716cdf0e10cSrcweir //	aEWVScrollBar.SetPageSize( aEWSz.Height() * 8 / 10 );
1717cdf0e10cSrcweir //	aEWVScrollBar.SetVisibleSize( aSz.Height() );
1718cdf0e10cSrcweir //	Invalidate();
1719cdf0e10cSrcweir }
1720cdf0e10cSrcweir 
1721cdf0e10cSrcweir IMPL_LINK( ComplexEditorWindow, ScrollHdl, ScrollBar *, pCurScrollBar )
1722cdf0e10cSrcweir {
1723cdf0e10cSrcweir 	if ( aEdtWindow.GetEditView() )
1724cdf0e10cSrcweir 	{
1725cdf0e10cSrcweir 		DBG_ASSERT( pCurScrollBar == &aEWVScrollBar, "Wer scrollt hier ?" );
1726cdf0e10cSrcweir 		long nDiff = aEdtWindow.GetEditView()->GetStartDocPos().Y() - pCurScrollBar->GetThumbPos();
1727cdf0e10cSrcweir 		aEdtWindow.GetEditView()->Scroll( 0, nDiff );
1728cdf0e10cSrcweir 		aBrkWindow.DoScroll( 0, nDiff );
1729cdf0e10cSrcweir 		aEdtWindow.GetEditView()->ShowCursor( sal_False, sal_True );
1730cdf0e10cSrcweir 		pCurScrollBar->SetThumbPos( aEdtWindow.GetEditView()->GetStartDocPos().Y() );
1731cdf0e10cSrcweir 	}
1732cdf0e10cSrcweir 
1733cdf0e10cSrcweir 	return 0;
1734cdf0e10cSrcweir }
1735cdf0e10cSrcweir 
1736cdf0e10cSrcweir // virtual
1737cdf0e10cSrcweir void ComplexEditorWindow::DataChanged(DataChangedEvent const & rDCEvt)
1738cdf0e10cSrcweir {
1739cdf0e10cSrcweir     Window::DataChanged(rDCEvt);
1740cdf0e10cSrcweir     if (rDCEvt.GetType() == DATACHANGED_SETTINGS
1741cdf0e10cSrcweir         && (rDCEvt.GetFlags() & SETTINGS_STYLE) != 0)
1742cdf0e10cSrcweir     {
1743cdf0e10cSrcweir         Color aColor(GetSettings().GetStyleSettings().GetFaceColor());
1744cdf0e10cSrcweir         if (aColor
1745cdf0e10cSrcweir             != rDCEvt.GetOldSettings()->GetStyleSettings().GetFaceColor())
1746cdf0e10cSrcweir         {
1747cdf0e10cSrcweir             SetBackground(Wallpaper(aColor));
1748cdf0e10cSrcweir             Invalidate();
1749cdf0e10cSrcweir         }
1750cdf0e10cSrcweir     }
1751cdf0e10cSrcweir }
1752cdf0e10cSrcweir 
1753cdf0e10cSrcweir // virtual
1754cdf0e10cSrcweir uno::Reference< awt::XWindowPeer >
1755cdf0e10cSrcweir EditorWindow::GetComponentInterface(sal_Bool bCreate)
1756cdf0e10cSrcweir {
1757cdf0e10cSrcweir     uno::Reference< awt::XWindowPeer > xPeer(
1758cdf0e10cSrcweir         Window::GetComponentInterface(false));
1759cdf0e10cSrcweir     if (!xPeer.is() && bCreate)
1760cdf0e10cSrcweir     {
1761cdf0e10cSrcweir         // Make sure edit engine and view are available:
1762cdf0e10cSrcweir         if (!pEditEngine)
1763cdf0e10cSrcweir             CreateEditEngine();
1764cdf0e10cSrcweir 
1765cdf0e10cSrcweir         xPeer = new ::svt::TextWindowPeer(*GetEditView());
1766cdf0e10cSrcweir         SetComponentInterface(xPeer);
1767cdf0e10cSrcweir     }
1768cdf0e10cSrcweir     return xPeer;
1769cdf0e10cSrcweir }
1770cdf0e10cSrcweir 
1771cdf0e10cSrcweir WatchTreeListBox::WatchTreeListBox( Window* pParent, WinBits nWinBits )
1772cdf0e10cSrcweir 	: SvHeaderTabListBox( pParent, nWinBits )
1773cdf0e10cSrcweir {}
1774cdf0e10cSrcweir 
1775cdf0e10cSrcweir WatchTreeListBox::~WatchTreeListBox()
1776cdf0e10cSrcweir {
1777cdf0e10cSrcweir 	// User-Daten zerstoeren...
1778cdf0e10cSrcweir 	SvLBoxEntry* pEntry = First();
1779cdf0e10cSrcweir 	while ( pEntry )
1780cdf0e10cSrcweir 	{
1781cdf0e10cSrcweir 		delete (WatchItem*)pEntry->GetUserData();
1782cdf0e10cSrcweir 		pEntry = Next( pEntry );
1783cdf0e10cSrcweir 	}
1784cdf0e10cSrcweir }
1785cdf0e10cSrcweir 
1786cdf0e10cSrcweir void WatchTreeListBox::SetTabs()
1787cdf0e10cSrcweir {
1788cdf0e10cSrcweir 	SvHeaderTabListBox::SetTabs();
1789cdf0e10cSrcweir 	sal_uInt16 nTabCount_ = aTabs.Count();
1790cdf0e10cSrcweir 	for( sal_uInt16 i = 0 ; i < nTabCount_ ; i++ )
1791cdf0e10cSrcweir 	{
1792cdf0e10cSrcweir 		SvLBoxTab* pTab = (SvLBoxTab*)aTabs.GetObject(i);
1793cdf0e10cSrcweir 		if( i == 2 )
1794cdf0e10cSrcweir 			pTab->nFlags |= SV_LBOXTAB_EDITABLE;
1795cdf0e10cSrcweir 		else
1796cdf0e10cSrcweir 			pTab->nFlags &= ~SV_LBOXTAB_EDITABLE;
1797cdf0e10cSrcweir 	}
1798cdf0e10cSrcweir }
1799cdf0e10cSrcweir 
1800cdf0e10cSrcweir void WatchTreeListBox::RequestingChilds( SvLBoxEntry * pParent )
1801cdf0e10cSrcweir {
1802cdf0e10cSrcweir 	if( !StarBASIC::IsRunning() )
1803cdf0e10cSrcweir         return;
1804cdf0e10cSrcweir 
1805cdf0e10cSrcweir     if( GetChildCount( pParent ) > 0 )
1806cdf0e10cSrcweir         return;
1807cdf0e10cSrcweir 
1808cdf0e10cSrcweir 	SvLBoxEntry * pEntry = pParent;
1809cdf0e10cSrcweir     WatchItem* pItem = (WatchItem*)pEntry->GetUserData();
1810cdf0e10cSrcweir 
1811cdf0e10cSrcweir 	SbxDimArray* pArray = pItem->mpArray;
1812cdf0e10cSrcweir 	SbxDimArray* pRootArray = pItem->GetRootArray();
1813cdf0e10cSrcweir 	bool bArrayIsRootArray = false;
1814cdf0e10cSrcweir 	if( !pArray && pRootArray )
1815cdf0e10cSrcweir 	{
1816cdf0e10cSrcweir 		pArray = pRootArray;
1817cdf0e10cSrcweir 		bArrayIsRootArray = true;
1818cdf0e10cSrcweir 	}
1819cdf0e10cSrcweir 
1820cdf0e10cSrcweir     SbxObject* pObj = pItem->mpObject;
1821cdf0e10cSrcweir     if( pObj )
1822cdf0e10cSrcweir     {
1823cdf0e10cSrcweir 		createAllObjectProperties( pObj );
1824cdf0e10cSrcweir  	    SbxArray* pProps = pObj->GetProperties();
1825cdf0e10cSrcweir 	    sal_uInt16 nPropCount = pProps->Count();
1826cdf0e10cSrcweir 		pItem->maMemberList.allocList( nPropCount );
1827cdf0e10cSrcweir 
1828cdf0e10cSrcweir 	    for( sal_uInt16 i = 0 ; i < nPropCount - 3 ; i++ )
1829cdf0e10cSrcweir 	    {
1830cdf0e10cSrcweir 		    SbxVariable* pVar = pProps->Get( i );
1831cdf0e10cSrcweir 
1832cdf0e10cSrcweir             String aName( pVar->GetName() );
1833cdf0e10cSrcweir 			pItem->maMemberList.mpMemberNames[i] = aName;
1834cdf0e10cSrcweir             SvLBoxEntry* pChildEntry = SvTreeListBox::InsertEntry( aName, pEntry );
1835cdf0e10cSrcweir             WatchItem* pChildItem = new WatchItem();
1836cdf0e10cSrcweir 			pChildItem->maName = aName;
1837cdf0e10cSrcweir 	        pChildEntry->SetUserData( pChildItem );
1838cdf0e10cSrcweir 	    }
1839cdf0e10cSrcweir 		if( nPropCount > 0 )
1840cdf0e10cSrcweir 		{
1841cdf0e10cSrcweir 			UpdateWatches();
1842cdf0e10cSrcweir 		}
1843cdf0e10cSrcweir     }
1844cdf0e10cSrcweir 	else if( pArray )
1845cdf0e10cSrcweir 	{
1846cdf0e10cSrcweir 	    sal_uInt16 nElementCount = 0;
1847cdf0e10cSrcweir 
1848cdf0e10cSrcweir 		// Loop through indices of current level
1849cdf0e10cSrcweir 		int nParentLevel = bArrayIsRootArray ? pItem->nDimLevel : 0;
1850cdf0e10cSrcweir 		int nThisLevel = nParentLevel + 1;
1851cdf0e10cSrcweir 		sal_Int32 nMin, nMax;
1852cdf0e10cSrcweir 		pArray->GetDim32( nThisLevel, nMin, nMax );
1853cdf0e10cSrcweir 		for( sal_Int32 i = nMin ; i <= nMax ; i++ )
1854cdf0e10cSrcweir 		{
1855cdf0e10cSrcweir             WatchItem* pChildItem = new WatchItem();
1856cdf0e10cSrcweir 
1857cdf0e10cSrcweir 			// Copy data and create name
1858cdf0e10cSrcweir             String aBaseName( pItem->maName );
1859cdf0e10cSrcweir 			pChildItem->maName = aBaseName;
1860cdf0e10cSrcweir 
1861cdf0e10cSrcweir 			String aIndexStr = String( RTL_CONSTASCII_USTRINGPARAM( "(" ) );
1862cdf0e10cSrcweir 			// pChildItem->mpArray = pItem->mpArray;
1863cdf0e10cSrcweir 			pChildItem->mpArrayParentItem = pItem;
1864cdf0e10cSrcweir 			pChildItem->nDimLevel = nThisLevel;
1865cdf0e10cSrcweir 			pChildItem->nDimCount = pItem->nDimCount;
1866cdf0e10cSrcweir 			pChildItem->pIndices = new short[ pChildItem->nDimCount ];
1867cdf0e10cSrcweir 			sal_uInt16 j;
1868cdf0e10cSrcweir 			for( j = 0 ; j < nParentLevel ; j++ )
1869cdf0e10cSrcweir 			{
1870cdf0e10cSrcweir 				short n = pChildItem->pIndices[j] = pItem->pIndices[j];
1871cdf0e10cSrcweir 				aIndexStr += String::CreateFromInt32( n );
1872cdf0e10cSrcweir 				aIndexStr += String( RTL_CONSTASCII_USTRINGPARAM( "," ) );
1873cdf0e10cSrcweir 			}
1874cdf0e10cSrcweir 			pChildItem->pIndices[ nParentLevel ] = sal::static_int_cast<short>( i );
1875cdf0e10cSrcweir 			aIndexStr += String::CreateFromInt32( i );
1876cdf0e10cSrcweir 			aIndexStr += String( RTL_CONSTASCII_USTRINGPARAM( ")" ) );
1877cdf0e10cSrcweir 
1878cdf0e10cSrcweir 			String aDisplayName;
1879cdf0e10cSrcweir 			WatchItem* pArrayRootItem = pChildItem->GetRootItem();
1880cdf0e10cSrcweir 			if( pArrayRootItem && pArrayRootItem->mpArrayParentItem )
1881cdf0e10cSrcweir 				aDisplayName = pItem->maDisplayName;
1882cdf0e10cSrcweir 			else
1883cdf0e10cSrcweir 				aDisplayName = aBaseName;
1884cdf0e10cSrcweir 			aDisplayName += aIndexStr;
1885cdf0e10cSrcweir 			pChildItem->maDisplayName = aDisplayName;
1886cdf0e10cSrcweir 
1887cdf0e10cSrcweir             SvLBoxEntry* pChildEntry = SvTreeListBox::InsertEntry( aDisplayName, pEntry );
1888cdf0e10cSrcweir 			nElementCount++;
1889cdf0e10cSrcweir 			pChildEntry->SetUserData( pChildItem );
1890cdf0e10cSrcweir 		}
1891cdf0e10cSrcweir 		if( nElementCount > 0 )
1892cdf0e10cSrcweir 		{
1893cdf0e10cSrcweir 			UpdateWatches();
1894cdf0e10cSrcweir 		}
1895cdf0e10cSrcweir 	}
1896cdf0e10cSrcweir }
1897cdf0e10cSrcweir 
1898cdf0e10cSrcweir SbxBase* WatchTreeListBox::ImplGetSBXForEntry( SvLBoxEntry* pEntry, bool& rbArrayElement )
1899cdf0e10cSrcweir {
1900cdf0e10cSrcweir 	SbxBase* pSBX = NULL;
1901cdf0e10cSrcweir 	rbArrayElement = false;
1902cdf0e10cSrcweir 
1903cdf0e10cSrcweir     WatchItem* pItem = (WatchItem*)pEntry->GetUserData();
1904cdf0e10cSrcweir 	String aVName( pItem->maName );
1905cdf0e10cSrcweir 
1906cdf0e10cSrcweir     SvLBoxEntry* pParentEntry = GetParent( pEntry );
1907cdf0e10cSrcweir 	WatchItem* pParentItem = pParentEntry ? (WatchItem*)pParentEntry->GetUserData() : NULL;
1908cdf0e10cSrcweir     if( pParentItem )
1909cdf0e10cSrcweir     {
1910cdf0e10cSrcweir         SbxObject* pObj = pParentItem->mpObject;
1911cdf0e10cSrcweir         SbxDimArray* pArray;
1912cdf0e10cSrcweir         if( pObj )
1913cdf0e10cSrcweir 		{
1914cdf0e10cSrcweir     		pSBX = pObj->Find( aVName, SbxCLASS_DONTCARE );
1915cdf0e10cSrcweir 
1916cdf0e10cSrcweir 			SbxVariable* pVar;
1917cdf0e10cSrcweir 			if ( pSBX && (pVar = PTR_CAST( SbxVariable, pSBX )) != NULL
1918cdf0e10cSrcweir 						&& !pSBX->ISA( SbxMethod ) )
1919cdf0e10cSrcweir 			{
1920cdf0e10cSrcweir 				// Force getting value
1921cdf0e10cSrcweir 				SbxValues aRes;
1922cdf0e10cSrcweir 				aRes.eType = SbxVOID;
1923cdf0e10cSrcweir 				pVar->Get( aRes );
1924cdf0e10cSrcweir 			}
1925cdf0e10cSrcweir 		}
1926cdf0e10cSrcweir 		// Array?
1927cdf0e10cSrcweir 		else if( (pArray = pItem->GetRootArray()) != NULL )
1928cdf0e10cSrcweir 		// else if( (pArray = pItem->mpArray) != NULL )
1929cdf0e10cSrcweir 		{
1930cdf0e10cSrcweir 			rbArrayElement = true;
1931cdf0e10cSrcweir 			if( pParentItem->nDimLevel + 1 == pParentItem->nDimCount )
1932cdf0e10cSrcweir 			// if( pItem->nDimLevel == pItem->nDimCount )
1933cdf0e10cSrcweir 				pSBX = pArray->Get( pItem->pIndices );
1934cdf0e10cSrcweir 			// else
1935cdf0e10cSrcweir 				// pSBX = pArray;
1936cdf0e10cSrcweir 		}
1937cdf0e10cSrcweir     }
1938cdf0e10cSrcweir 	else
1939cdf0e10cSrcweir 	{
1940cdf0e10cSrcweir 		pSBX = StarBASIC::FindSBXInCurrentScope( aVName );
1941cdf0e10cSrcweir 	}
1942cdf0e10cSrcweir 	return pSBX;
1943cdf0e10cSrcweir }
1944cdf0e10cSrcweir 
1945cdf0e10cSrcweir sal_Bool __EXPORT WatchTreeListBox::EditingEntry( SvLBoxEntry* pEntry, Selection& )
1946cdf0e10cSrcweir {
1947cdf0e10cSrcweir     WatchItem* pItem = (WatchItem*)pEntry->GetUserData();
1948cdf0e10cSrcweir 
1949cdf0e10cSrcweir 	sal_Bool bEdit = sal_False;
1950cdf0e10cSrcweir 	if ( StarBASIC::IsRunning() && StarBASIC::GetActiveMethod() && !SbxBase::IsError() )
1951cdf0e10cSrcweir 	{
1952cdf0e10cSrcweir 		// No out of scope entries
1953cdf0e10cSrcweir 		bool bArrayElement;
1954cdf0e10cSrcweir 		SbxBase* pSBX = ImplGetSBXForEntry( pEntry, bArrayElement );
1955cdf0e10cSrcweir 		if ( ( pSBX && pSBX->ISA( SbxVariable ) && !pSBX->ISA( SbxMethod ) ) || bArrayElement )
1956cdf0e10cSrcweir 		{
1957cdf0e10cSrcweir 			// Accept no objects and only end nodes of arrays for editing
1958cdf0e10cSrcweir 			if( !pItem->mpObject && (pItem->mpArray == NULL || pItem->nDimLevel == pItem->nDimCount) )
1959cdf0e10cSrcweir 			{
1960cdf0e10cSrcweir 				aEditingRes = SvHeaderTabListBox::GetEntryText( pEntry, ITEM_ID_VALUE-1 );
1961cdf0e10cSrcweir 				aEditingRes.EraseLeadingChars();
1962cdf0e10cSrcweir 				aEditingRes.EraseTrailingChars();
1963cdf0e10cSrcweir 				bEdit = sal_True;
1964cdf0e10cSrcweir 			}
1965cdf0e10cSrcweir 		}
1966cdf0e10cSrcweir 	}
1967cdf0e10cSrcweir 
1968cdf0e10cSrcweir 	if ( !bEdit )
1969cdf0e10cSrcweir 		Sound::Beep();
1970cdf0e10cSrcweir 
1971cdf0e10cSrcweir 	return bEdit;
1972cdf0e10cSrcweir }
1973cdf0e10cSrcweir 
1974cdf0e10cSrcweir sal_Bool __EXPORT WatchTreeListBox::EditedEntry( SvLBoxEntry* pEntry, const String& rNewText )
1975cdf0e10cSrcweir {
1976cdf0e10cSrcweir     WatchItem* pItem = (WatchItem*)pEntry->GetUserData();
1977cdf0e10cSrcweir 	String aVName( pItem->maName );
1978cdf0e10cSrcweir 
1979cdf0e10cSrcweir 	String aResult = rNewText;
1980cdf0e10cSrcweir 	aResult.EraseLeadingChars();
1981cdf0e10cSrcweir 	aResult.EraseTrailingChars();
1982cdf0e10cSrcweir 
1983cdf0e10cSrcweir 	sal_uInt16 nResultLen = aResult.Len();
1984cdf0e10cSrcweir 	sal_Unicode cFirst = aResult.GetChar( 0 );
1985cdf0e10cSrcweir 	sal_Unicode cLast  = aResult.GetChar( nResultLen - 1 );
1986cdf0e10cSrcweir 	if( cFirst == '\"' && cLast == '\"' )
1987cdf0e10cSrcweir 		aResult = aResult.Copy( 1, nResultLen - 2 );
1988cdf0e10cSrcweir 
1989cdf0e10cSrcweir 	sal_Bool bResModified = ( aResult != aEditingRes ) ? sal_True : sal_False;
1990cdf0e10cSrcweir 	sal_Bool bError = sal_False;
1991cdf0e10cSrcweir 	if ( !aVName.Len() )
1992cdf0e10cSrcweir 	{
1993cdf0e10cSrcweir 		bError = sal_True;
1994cdf0e10cSrcweir 	}
1995cdf0e10cSrcweir 
1996cdf0e10cSrcweir 	sal_Bool bRet = sal_False;
1997cdf0e10cSrcweir 
1998cdf0e10cSrcweir 	if ( bError )
1999cdf0e10cSrcweir 	{
2000cdf0e10cSrcweir 		Sound::Beep();
2001cdf0e10cSrcweir 	}
2002cdf0e10cSrcweir 	else if ( bResModified )
2003cdf0e10cSrcweir 	{
2004cdf0e10cSrcweir 		bRet = ImplBasicEntryEdited( pEntry, aResult );
2005cdf0e10cSrcweir 	}
2006cdf0e10cSrcweir 
2007cdf0e10cSrcweir 	return bRet;
2008cdf0e10cSrcweir }
2009cdf0e10cSrcweir 
2010cdf0e10cSrcweir sal_Bool WatchTreeListBox::ImplBasicEntryEdited( SvLBoxEntry* pEntry, const String& rResult )
2011cdf0e10cSrcweir {
2012cdf0e10cSrcweir     WatchItem* pItem = (WatchItem*)pEntry->GetUserData();
2013cdf0e10cSrcweir 	String aVName( pItem->maName );
2014cdf0e10cSrcweir 
2015cdf0e10cSrcweir 	sal_Bool bError = sal_False;
2016cdf0e10cSrcweir 	String aResult( rResult );
2017cdf0e10cSrcweir 	String aIndex;
2018cdf0e10cSrcweir 	bool bArrayElement;
2019cdf0e10cSrcweir 	SbxBase* pSBX = ImplGetSBXForEntry( pEntry, bArrayElement );
2020cdf0e10cSrcweir 
2021cdf0e10cSrcweir 	SbxBase* pToBeChanged = NULL;
2022cdf0e10cSrcweir 	if ( pSBX && pSBX->ISA( SbxVariable ) && !pSBX->ISA( SbxMethod ) )
2023cdf0e10cSrcweir 	{
2024cdf0e10cSrcweir 		SbxVariable* pVar = (SbxVariable*)pSBX;
2025cdf0e10cSrcweir 		SbxDataType eType = pVar->GetType();
2026cdf0e10cSrcweir 		if ( (sal_uInt8)eType == (sal_uInt8)SbxOBJECT )
2027cdf0e10cSrcweir 			bError = sal_True;
2028cdf0e10cSrcweir 		else if ( eType & SbxARRAY )
2029cdf0e10cSrcweir 			bError = sal_True;
2030cdf0e10cSrcweir 		else
2031cdf0e10cSrcweir 			pToBeChanged = pSBX;
2032cdf0e10cSrcweir 	}
2033cdf0e10cSrcweir 
2034cdf0e10cSrcweir 	if ( pToBeChanged )
2035cdf0e10cSrcweir 	{
2036cdf0e10cSrcweir 		if ( pToBeChanged->ISA( SbxVariable ) )
2037cdf0e10cSrcweir 		{
2038cdf0e10cSrcweir 			// Wenn der Typ variabel ist, macht die Konvertierung des SBX nichts,
2039cdf0e10cSrcweir 			// bei festem Typ wird der String konvertiert.
2040cdf0e10cSrcweir 			((SbxVariable*)pToBeChanged)->PutStringExt( aResult );
2041cdf0e10cSrcweir 		}
2042cdf0e10cSrcweir 		else
2043cdf0e10cSrcweir 			bError = sal_True;
2044cdf0e10cSrcweir 	}
2045cdf0e10cSrcweir 
2046cdf0e10cSrcweir 	// Wenn jemand z.B. einen zu grossen Wert fuer ein Int eingegeben hat,
2047cdf0e10cSrcweir 	// folgt beim naechsten Step() ein Runtime-Error.
2048cdf0e10cSrcweir 	if ( SbxBase::IsError() )
2049cdf0e10cSrcweir 	{
2050cdf0e10cSrcweir 		bError = sal_True;
2051cdf0e10cSrcweir 		SbxBase::ResetError();
2052cdf0e10cSrcweir 	}
2053cdf0e10cSrcweir 
2054cdf0e10cSrcweir 	if ( bError )
2055cdf0e10cSrcweir 		Sound::Beep();
2056cdf0e10cSrcweir 
2057cdf0e10cSrcweir 	UpdateWatches();
2058cdf0e10cSrcweir 
2059cdf0e10cSrcweir 	// Der Text soll niemals 1-zu-1 uebernommen werden, weil dann das
2060cdf0e10cSrcweir 	// UpdateWatches verlorengeht.
2061cdf0e10cSrcweir 	return sal_False;
2062cdf0e10cSrcweir }
2063cdf0e10cSrcweir 
2064cdf0e10cSrcweir 
2065cdf0e10cSrcweir static void implCollapseModifiedObjectEntry( SvLBoxEntry* pParent, WatchTreeListBox* pThis )
2066cdf0e10cSrcweir {
2067cdf0e10cSrcweir 	pThis->Collapse( pParent );
2068cdf0e10cSrcweir 
2069cdf0e10cSrcweir 	SvLBoxTreeList*	pModel = pThis->GetModel();
2070cdf0e10cSrcweir 	SvLBoxEntry* pDeleteEntry;
2071cdf0e10cSrcweir 	while( (pDeleteEntry = pThis->SvTreeListBox::GetEntry( pParent, 0 )) != NULL )
2072cdf0e10cSrcweir 	{
2073cdf0e10cSrcweir 		implCollapseModifiedObjectEntry( pDeleteEntry, pThis );
2074cdf0e10cSrcweir 
2075cdf0e10cSrcweir         WatchItem* pItem = (WatchItem*)pDeleteEntry->GetUserData();
2076cdf0e10cSrcweir 		delete pItem;
2077cdf0e10cSrcweir         pModel->Remove( pDeleteEntry );
2078cdf0e10cSrcweir 	}
2079cdf0e10cSrcweir }
2080cdf0e10cSrcweir 
2081cdf0e10cSrcweir static String implCreateTypeStringForDimArray( WatchItem* pItem, SbxDataType eType )
2082cdf0e10cSrcweir {
2083cdf0e10cSrcweir 	String aRetStr = getBasicTypeName( eType );
2084cdf0e10cSrcweir 
2085cdf0e10cSrcweir 	SbxDimArray* pArray = pItem->mpArray;
2086cdf0e10cSrcweir 	if( !pArray )
2087cdf0e10cSrcweir 		pArray = pItem->GetRootArray();
2088cdf0e10cSrcweir 	if( pArray )
2089cdf0e10cSrcweir 	{
2090cdf0e10cSrcweir 		int nDimLevel = pItem->nDimLevel;
2091cdf0e10cSrcweir 		int nDims = pItem->nDimCount;
2092cdf0e10cSrcweir 		if( nDimLevel < nDims )
2093cdf0e10cSrcweir 		{
2094cdf0e10cSrcweir 			aRetStr += '(';
2095cdf0e10cSrcweir 			for( int i = nDimLevel ; i < nDims ; i++ )
2096cdf0e10cSrcweir 			{
2097cdf0e10cSrcweir 				short nMin, nMax;
2098cdf0e10cSrcweir 				pArray->GetDim( sal::static_int_cast<short>( i+1 ), nMin, nMax );
2099cdf0e10cSrcweir 				aRetStr += String::CreateFromInt32( nMin );
2100cdf0e10cSrcweir 				aRetStr += String( RTL_CONSTASCII_USTRINGPARAM( " to " ) );
2101cdf0e10cSrcweir 				aRetStr += String::CreateFromInt32( nMax );
2102cdf0e10cSrcweir 				if( i < nDims - 1 )
2103cdf0e10cSrcweir 					aRetStr += String( RTL_CONSTASCII_USTRINGPARAM( ", " ) );
2104cdf0e10cSrcweir 			}
2105cdf0e10cSrcweir 			aRetStr += ')';
2106cdf0e10cSrcweir 		}
2107cdf0e10cSrcweir 	}
2108cdf0e10cSrcweir 	return aRetStr;
2109cdf0e10cSrcweir }
2110cdf0e10cSrcweir 
2111cdf0e10cSrcweir 
2112cdf0e10cSrcweir void implEnableChildren( SvLBoxEntry* pEntry, bool bEnable )
2113cdf0e10cSrcweir // inline void implEnableChildren( SvLBoxEntry* pEntry, bool bEnable )
2114cdf0e10cSrcweir {
2115cdf0e10cSrcweir 	if( bEnable )
2116cdf0e10cSrcweir 	{
2117cdf0e10cSrcweir 		pEntry->SetFlags(
2118cdf0e10cSrcweir 			(pEntry->GetFlags() &
2119cdf0e10cSrcweir 			~(SV_ENTRYFLAG_NO_NODEBMP | SV_ENTRYFLAG_HAD_CHILDREN))
2120cdf0e10cSrcweir 			| SV_ENTRYFLAG_CHILDS_ON_DEMAND );
2121cdf0e10cSrcweir 	}
2122cdf0e10cSrcweir 	else
2123cdf0e10cSrcweir 	{
2124cdf0e10cSrcweir 		pEntry->SetFlags(
2125cdf0e10cSrcweir 			(pEntry->GetFlags() & ~(SV_ENTRYFLAG_CHILDS_ON_DEMAND)) );
2126cdf0e10cSrcweir 	}
2127cdf0e10cSrcweir }
2128cdf0e10cSrcweir 
2129cdf0e10cSrcweir void WatchTreeListBox::UpdateWatches( bool bBasicStopped )
2130cdf0e10cSrcweir {
2131cdf0e10cSrcweir 	SbMethod* pCurMethod = StarBASIC::GetActiveMethod();
2132cdf0e10cSrcweir 
2133cdf0e10cSrcweir 	SbxError eOld = SbxBase::GetError();
2134cdf0e10cSrcweir 	setBasicWatchMode( true );
2135cdf0e10cSrcweir 
2136cdf0e10cSrcweir 	SvLBoxEntry* pEntry = First();
2137cdf0e10cSrcweir 	while ( pEntry )
2138cdf0e10cSrcweir 	{
2139cdf0e10cSrcweir         WatchItem* pItem = (WatchItem*)pEntry->GetUserData();
2140cdf0e10cSrcweir 		String aVName( pItem->maName );
2141cdf0e10cSrcweir 		DBG_ASSERT( aVName.Len(), "Var? - Darf nicht leer sein!" );
2142cdf0e10cSrcweir 		String aWatchStr;
2143cdf0e10cSrcweir 		String aTypeStr;
2144cdf0e10cSrcweir 		if ( pCurMethod )
2145cdf0e10cSrcweir 		{
2146cdf0e10cSrcweir 			bool bArrayElement;
2147cdf0e10cSrcweir 			SbxBase* pSBX = ImplGetSBXForEntry( pEntry, bArrayElement );
2148cdf0e10cSrcweir 
2149cdf0e10cSrcweir 			// Array? If no end node create type string
2150cdf0e10cSrcweir 			if( bArrayElement && pItem->nDimLevel < pItem->nDimCount )
2151cdf0e10cSrcweir 			{
2152cdf0e10cSrcweir 				SbxDimArray* pRootArray = pItem->GetRootArray();
2153cdf0e10cSrcweir 				SbxDataType eType = pRootArray->GetType();
2154cdf0e10cSrcweir 				// SbxDataType eType = pItem->mpArray->GetType();
2155cdf0e10cSrcweir 				aTypeStr = implCreateTypeStringForDimArray( pItem, eType );
2156cdf0e10cSrcweir 				implEnableChildren( pEntry, true );
2157cdf0e10cSrcweir 			}
2158cdf0e10cSrcweir 
2159cdf0e10cSrcweir 			bool bCollapse = false;
2160cdf0e10cSrcweir 			if ( pSBX && pSBX->ISA( SbxVariable ) && !pSBX->ISA( SbxMethod ) )
2161cdf0e10cSrcweir 			{
2162cdf0e10cSrcweir 				SbxVariable* pVar = (SbxVariable*)pSBX;
2163cdf0e10cSrcweir 				// Sonderbehandlung fuer Arrays:
2164cdf0e10cSrcweir 				SbxDataType eType = pVar->GetType();
2165cdf0e10cSrcweir 				if ( eType & SbxARRAY )
2166cdf0e10cSrcweir 				{
2167cdf0e10cSrcweir 					// Mehrdimensionale Arrays beruecksichtigen!
2168cdf0e10cSrcweir 					SbxBase* pBase = pVar->GetObject();
2169cdf0e10cSrcweir 					if ( pBase && pBase->ISA( SbxDimArray ) )
2170cdf0e10cSrcweir 					{
2171cdf0e10cSrcweir 						SbxDimArray* pNewArray = (SbxDimArray*)pBase;
2172cdf0e10cSrcweir 						SbxDimArray* pOldArray = pItem->mpArray;
2173cdf0e10cSrcweir 
2174cdf0e10cSrcweir 						bool bArrayChanged = false;
2175cdf0e10cSrcweir 						if( pNewArray != NULL && pOldArray != NULL )
2176cdf0e10cSrcweir 						{
2177cdf0e10cSrcweir 							// Compare Array dimensions to see if array has changed
2178cdf0e10cSrcweir 							// Can be a copy, so comparing pointers does not work
2179cdf0e10cSrcweir 							sal_uInt16 nOldDims = pOldArray->GetDims();
2180cdf0e10cSrcweir 							sal_uInt16 nNewDims = pNewArray->GetDims();
2181cdf0e10cSrcweir 							if( nOldDims != nNewDims )
2182cdf0e10cSrcweir 							{
2183cdf0e10cSrcweir 								bArrayChanged = true;
2184cdf0e10cSrcweir 							}
2185cdf0e10cSrcweir 							else
2186cdf0e10cSrcweir 							{
2187cdf0e10cSrcweir 								for( int i = 0 ; i < nOldDims ; i++ )
2188cdf0e10cSrcweir 								{
2189cdf0e10cSrcweir 									short nOldMin, nOldMax;
2190cdf0e10cSrcweir 									short nNewMin, nNewMax;
2191cdf0e10cSrcweir 
2192cdf0e10cSrcweir 									pOldArray->GetDim( sal::static_int_cast<short>( i+1 ), nOldMin, nOldMax );
2193cdf0e10cSrcweir 									pNewArray->GetDim( sal::static_int_cast<short>( i+1 ), nNewMin, nNewMax );
2194cdf0e10cSrcweir 									if( nOldMin != nNewMin || nOldMax != nNewMax )
2195cdf0e10cSrcweir 									{
2196cdf0e10cSrcweir 										bArrayChanged = true;
2197cdf0e10cSrcweir 										break;
2198cdf0e10cSrcweir 									}
2199cdf0e10cSrcweir 								}
2200cdf0e10cSrcweir 							}
2201cdf0e10cSrcweir 						}
2202cdf0e10cSrcweir 						else if( pNewArray == NULL || pOldArray == NULL )
2203cdf0e10cSrcweir 							bArrayChanged = true;
2204cdf0e10cSrcweir 
2205cdf0e10cSrcweir 						if( pNewArray )
2206cdf0e10cSrcweir 							implEnableChildren( pEntry, true );
2207cdf0e10cSrcweir 
2208cdf0e10cSrcweir 						// #i37227 Clear always and replace array
2209cdf0e10cSrcweir 						if( pNewArray != pOldArray )
2210cdf0e10cSrcweir 						{
2211cdf0e10cSrcweir 							pItem->clearWatchItem( false );
2212cdf0e10cSrcweir 							if( pNewArray )
2213cdf0e10cSrcweir 							{
2214cdf0e10cSrcweir 								implEnableChildren( pEntry, true );
2215cdf0e10cSrcweir 
2216cdf0e10cSrcweir 								pItem->mpArray = pNewArray;
2217cdf0e10cSrcweir 								sal_uInt16 nDims = pNewArray->GetDims();
2218cdf0e10cSrcweir 								pItem->nDimLevel = 0;
2219cdf0e10cSrcweir 								pItem->nDimCount = nDims;
2220cdf0e10cSrcweir 							}
2221cdf0e10cSrcweir 						}
2222cdf0e10cSrcweir 						if( bArrayChanged && pOldArray != NULL )
2223cdf0e10cSrcweir 							bCollapse = true;
2224cdf0e10cSrcweir 
2225cdf0e10cSrcweir 						aTypeStr = implCreateTypeStringForDimArray( pItem, eType );
2226cdf0e10cSrcweir 					}
2227cdf0e10cSrcweir 					else
2228cdf0e10cSrcweir 						aWatchStr += String( RTL_CONSTASCII_USTRINGPARAM( "<?>" ) );
2229cdf0e10cSrcweir 				}
2230cdf0e10cSrcweir 				else if ( (sal_uInt8)eType == (sal_uInt8)SbxOBJECT )
2231cdf0e10cSrcweir 				{
2232cdf0e10cSrcweir                     SbxObject* pObj = NULL;
2233cdf0e10cSrcweir 			        SbxBase* pBase = pVar->GetObject();
2234cdf0e10cSrcweir 			        if( pBase && pBase->ISA( SbxObject ) )
2235cdf0e10cSrcweir                         pObj = (SbxObject*)pBase;
2236cdf0e10cSrcweir 
2237cdf0e10cSrcweir                     if( pObj )
2238cdf0e10cSrcweir                     {
2239cdf0e10cSrcweir 						// Check if member list has changed
2240cdf0e10cSrcweir 						bool bObjChanged = false;
2241cdf0e10cSrcweir 						if( pItem->mpObject != NULL && pItem->maMemberList.mpMemberNames != NULL )
2242cdf0e10cSrcweir 						{
2243cdf0e10cSrcweir 							SbxArray* pProps = pObj->GetProperties();
2244cdf0e10cSrcweir 							sal_uInt16 nPropCount = pProps->Count();
2245cdf0e10cSrcweir 							for( sal_uInt16 i = 0 ; i < nPropCount - 3 ; i++ )
2246cdf0e10cSrcweir 							{
2247cdf0e10cSrcweir 								SbxVariable* pVar_ = pProps->Get( i );
2248cdf0e10cSrcweir 								String aName( pVar_->GetName() );
2249cdf0e10cSrcweir 								if( pItem->maMemberList.mpMemberNames[i] != aName )
2250cdf0e10cSrcweir 								{
2251cdf0e10cSrcweir 									bObjChanged = true;
2252cdf0e10cSrcweir 									break;
2253cdf0e10cSrcweir 								}
2254cdf0e10cSrcweir 							}
2255cdf0e10cSrcweir 							if( bObjChanged )
2256cdf0e10cSrcweir 								bCollapse = true;
2257cdf0e10cSrcweir 						}
2258cdf0e10cSrcweir 
2259cdf0e10cSrcweir 						pItem->mpObject = pObj;
2260cdf0e10cSrcweir 						implEnableChildren( pEntry, true );
2261cdf0e10cSrcweir 						aTypeStr = getBasicObjectTypeName( pObj );
2262cdf0e10cSrcweir 					}
2263cdf0e10cSrcweir 					else
2264cdf0e10cSrcweir 					{
2265cdf0e10cSrcweir 						aWatchStr = String( RTL_CONSTASCII_USTRINGPARAM( "Null" ) );
2266cdf0e10cSrcweir 						if( pItem->mpObject != NULL )
2267cdf0e10cSrcweir 						{
2268cdf0e10cSrcweir 							bCollapse = true;
2269cdf0e10cSrcweir 							pItem->clearWatchItem( false );
2270cdf0e10cSrcweir 
2271cdf0e10cSrcweir 							implEnableChildren( pEntry, false );
2272cdf0e10cSrcweir 						}
2273cdf0e10cSrcweir 					}
2274cdf0e10cSrcweir 				}
2275cdf0e10cSrcweir 				else
2276cdf0e10cSrcweir 				{
2277cdf0e10cSrcweir 					if( pItem->mpObject != NULL )
2278cdf0e10cSrcweir 					{
2279cdf0e10cSrcweir 						bCollapse = true;
2280cdf0e10cSrcweir 						pItem->clearWatchItem( false );
2281cdf0e10cSrcweir 
2282cdf0e10cSrcweir 						implEnableChildren( pEntry, false );
2283cdf0e10cSrcweir 					}
2284cdf0e10cSrcweir 
2285cdf0e10cSrcweir 					bool bString = ((sal_uInt8)eType == (sal_uInt8)SbxSTRING);
2286cdf0e10cSrcweir 					String aStrStr( RTL_CONSTASCII_USTRINGPARAM( "\"" ) );
2287cdf0e10cSrcweir 					if( bString )
2288cdf0e10cSrcweir 						aWatchStr += aStrStr;
2289cdf0e10cSrcweir 					aWatchStr += pVar->GetString();
2290cdf0e10cSrcweir 					if( bString )
2291cdf0e10cSrcweir 						aWatchStr += aStrStr;
2292cdf0e10cSrcweir 				}
2293cdf0e10cSrcweir 				if( !aTypeStr.Len() )
2294cdf0e10cSrcweir 				{
2295cdf0e10cSrcweir 					if( !pVar->IsFixed() )
2296cdf0e10cSrcweir 						aTypeStr = String( RTL_CONSTASCII_USTRINGPARAM( "Variant/" ) );
2297cdf0e10cSrcweir 					aTypeStr += getBasicTypeName( pVar->GetType() );
2298cdf0e10cSrcweir 				}
2299cdf0e10cSrcweir 			}
2300cdf0e10cSrcweir 			else if( !bArrayElement )
2301cdf0e10cSrcweir 				aWatchStr += String( RTL_CONSTASCII_USTRINGPARAM( "<Out of Scope>" ) );
2302cdf0e10cSrcweir 
2303cdf0e10cSrcweir 			if( bCollapse )
2304cdf0e10cSrcweir 				implCollapseModifiedObjectEntry( pEntry, this );
2305cdf0e10cSrcweir 
2306cdf0e10cSrcweir 		}
2307cdf0e10cSrcweir 		else if( bBasicStopped )
2308cdf0e10cSrcweir 		{
2309cdf0e10cSrcweir             if( pItem->mpObject || pItem->mpArray )
2310cdf0e10cSrcweir 			{
2311cdf0e10cSrcweir 				implCollapseModifiedObjectEntry( pEntry, this );
2312cdf0e10cSrcweir 				pItem->mpObject = NULL;
2313cdf0e10cSrcweir 			}
2314cdf0e10cSrcweir 		}
2315cdf0e10cSrcweir 
2316cdf0e10cSrcweir 		SvHeaderTabListBox::SetEntryText( aWatchStr, pEntry, ITEM_ID_VALUE-1 );
2317cdf0e10cSrcweir 		SvHeaderTabListBox::SetEntryText( aTypeStr, pEntry, ITEM_ID_TYPE-1 );
2318cdf0e10cSrcweir 
2319cdf0e10cSrcweir 		pEntry = Next( pEntry );
2320cdf0e10cSrcweir 	}
2321cdf0e10cSrcweir 
2322cdf0e10cSrcweir 	// Force redraw
2323cdf0e10cSrcweir     Invalidate();
2324cdf0e10cSrcweir 
2325cdf0e10cSrcweir 	SbxBase::ResetError();
2326cdf0e10cSrcweir 	if( eOld != SbxERR_OK )
2327cdf0e10cSrcweir 		SbxBase::SetError( eOld );
2328cdf0e10cSrcweir 	setBasicWatchMode( false );
2329cdf0e10cSrcweir }
2330cdf0e10cSrcweir 
2331