merge the formfield patch from ooo-build
[ooovba.git] / basic / source / app / brkpnts.cxx
blobca75c2dd033d3b195d67d2a2cf0e4895f265173e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: brkpnts.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basic.hxx"
33 #include <tools/list.hxx>
34 #include <basic/sbx.hxx>
35 #include <basic/sbmod.hxx>
36 #include <basic/sbstar.hxx>
37 #include <basic/sbmeth.hxx>
38 #include <vcl/image.hxx>
39 #include <svtools/textdata.hxx>
40 #include <tools/config.hxx>
41 #include <vcl/gradient.hxx>
43 #ifndef _BASIC_TTRESHLP_HXX
44 #include <basic/ttstrhlp.hxx>
45 #endif
47 #include "brkpnts.hxx"
48 #include "basic.hrc"
49 #include "resids.hrc"
50 #include "basrid.hxx"
52 struct Breakpoint
54 USHORT nLine;
56 Breakpoint( USHORT nL ) { nLine = nL; }
60 ImageList* BreakpointWindow::pImages = NULL;
63 BreakpointWindow::BreakpointWindow( Window *pParent )
64 : Window( pParent )
65 , nCurYOffset( 0 )
66 , nMarkerPos( MARKER_NOMARKER )
67 , pModule( NULL )
68 , bErrorMarker( FALSE )
70 if ( !pImages )
71 pImages = new ImageList( SttResId( RID_IMGLST_LAYOUT ) );
73 Gradient aGradient( GRADIENT_AXIAL, Color( 185, 182, 215 ), Color( 250, 245, 255 ) );
74 aGradient.SetAngle(900);
75 SetBackground( aGradient );
76 Show();
80 void BreakpointWindow::Reset()
82 Breakpoint* pBrk = First();
83 while ( pBrk )
85 delete pBrk;
86 pBrk = Next();
88 Clear();
90 pModule->ClearAllBP();
93 void BreakpointWindow::SetModule( SbModule *pMod )
95 pModule = pMod;
96 USHORT i;
97 for ( i=0 ; i < pModule->GetBPCount() ; i++ )
99 InsertBreakpoint( pModule->GetBP( i ) );
101 SetBPsInModule();
105 void BreakpointWindow::SetBPsInModule()
107 pModule->ClearAllBP();
109 Breakpoint* pBrk = First();
110 while ( pBrk )
112 pModule->SetBP( (USHORT)pBrk->nLine );
113 #if OSL_DEBUG_LEVEL > 1
114 DBG_ASSERT( !pModule->IsCompiled() || pModule->IsBP( (USHORT)pBrk->nLine ), "Brechpunkt wurde nicht gesetzt" );
115 #endif
116 pBrk = Next();
118 for ( USHORT nMethod = 0; nMethod < pModule->GetMethods()->Count(); nMethod++ )
120 SbMethod* pMethod = (SbMethod*)pModule->GetMethods()->Get( nMethod );
121 DBG_ASSERT( pMethod, "Methode nicht gefunden! (NULL)" );
122 pMethod->SetDebugFlags( pMethod->GetDebugFlags() | SbDEBUG_BREAK );
127 void BreakpointWindow::InsertBreakpoint( USHORT nLine )
129 Breakpoint* pNewBrk = new Breakpoint( nLine );
130 Breakpoint* pBrk = First();
131 while ( pBrk )
133 if ( nLine <= pBrk->nLine )
135 if ( pBrk->nLine != nLine )
136 Insert( pNewBrk );
137 else
138 delete pNewBrk;
139 pNewBrk = NULL;
140 pBrk = NULL;
142 else
143 pBrk = Next();
145 // No insert position found => LIST_APPEND
146 if ( pNewBrk )
147 Insert( pNewBrk, LIST_APPEND );
149 Invalidate();
151 if ( pModule->SetBP( nLine ) )
153 #if OSL_DEBUG_LEVEL > 1
154 DBG_ASSERT( !pModule->IsCompiled() || pModule->IsBP( nLine ), "Brechpunkt wurde nicht gesetzt" );
155 #endif
156 if ( StarBASIC::IsRunning() )
158 for ( USHORT nMethod = 0; nMethod < pModule->GetMethods()->Count(); nMethod++ )
160 SbMethod* pMethod = (SbMethod*)pModule->GetMethods()->Get( nMethod );
161 DBG_ASSERT( pMethod, "Methode nicht gefunden! (NULL)" );
162 pMethod->SetDebugFlags( pMethod->GetDebugFlags() | SbDEBUG_BREAK );
166 #if OSL_DEBUG_LEVEL > 1
167 DBG_ASSERT( !pModule->IsCompiled() || pModule->IsBP( nLine ), "Brechpunkt wurde nicht gesetzt" );
168 #endif
172 Breakpoint* BreakpointWindow::FindBreakpoint( ULONG nLine )
174 Breakpoint* pBrk = First();
175 while ( pBrk )
177 if ( pBrk->nLine == nLine )
178 return pBrk;
180 pBrk = Next();
183 return (Breakpoint*)0;
187 void BreakpointWindow::AdjustBreakpoints( ULONG nLine, BOOL bInserted )
189 if ( nLine == 0 ) //TODO: nLine == TEXT_PARA_ALL+1
190 return;
191 Breakpoint* pBrk = First();
192 while ( pBrk )
194 BOOL bDelBrk = FALSE;
195 if ( pBrk->nLine == nLine )
197 if ( bInserted )
198 pBrk->nLine++;
199 else
200 bDelBrk = TRUE;
202 else if ( pBrk->nLine > nLine )
204 if ( bInserted )
205 pBrk->nLine++;
206 else
207 pBrk->nLine--;
210 if ( bDelBrk )
212 ULONG n = GetCurPos();
213 delete Remove( pBrk );
214 pBrk = Seek( n );
216 else
218 pBrk = Next();
221 Invalidate();
225 void BreakpointWindow::LoadBreakpoints( String aFilename )
227 Config aConfig(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
229 aConfig.SetGroup("Breakpoints");
231 ByteString aBreakpoints;
232 aBreakpoints = aConfig.ReadKey( ByteString( aFilename, RTL_TEXTENCODING_UTF8 ) );
234 xub_StrLen i;
236 for ( i = 0 ; i < aBreakpoints.GetTokenCount( ';' ) ; i++ )
238 InsertBreakpoint( (USHORT)aBreakpoints.GetToken( i, ';' ).ToInt32() );
243 void BreakpointWindow::SaveBreakpoints( String aFilename )
245 ByteString aBreakpoints;
247 Breakpoint* pBrk = First();
248 while ( pBrk )
250 if ( aBreakpoints.Len() )
251 aBreakpoints += ';';
253 aBreakpoints += ByteString::CreateFromInt32( pBrk->nLine );
254 pBrk = Next();
257 Config aConfig(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
259 aConfig.SetGroup("Breakpoints");
261 if ( aBreakpoints.Len() )
262 aConfig.WriteKey( ByteString( aFilename, RTL_TEXTENCODING_UTF8 ), aBreakpoints );
263 else
264 aConfig.DeleteKey( ByteString( aFilename, RTL_TEXTENCODING_UTF8 ) );
268 void BreakpointWindow::Paint( const Rectangle& )
270 Size aOutSz( GetOutputSize() );
271 long nLineHeight = GetTextHeight();
273 Image aBrk( pImages->GetImage( IMGID_BRKENABLED ) );
274 Size aBmpSz( aBrk.GetSizePixel() );
275 aBmpSz = PixelToLogic( aBmpSz );
276 Point aBmpOff( 0, 0 );
277 aBmpOff.X() = ( aOutSz.Width() - aBmpSz.Width() ) / 2;
278 aBmpOff.Y() = ( nLineHeight - aBmpSz.Height() ) / 2;
280 Breakpoint* pBrk = First();
281 while ( pBrk )
283 #if OSL_DEBUG_LEVEL > 1
284 DBG_ASSERT( !pModule->IsCompiled() || pModule->IsBP( pBrk->nLine ), "Brechpunkt wurde nicht gesetzt" );
285 #endif
286 ULONG nLine = pBrk->nLine-1;
287 ULONG nY = nLine*nLineHeight - nCurYOffset;
288 DrawImage( Point( 0, nY ) + aBmpOff, aBrk );
289 pBrk = Next();
291 ShowMarker( TRUE );
295 Breakpoint* BreakpointWindow::FindBreakpoint( const Point& rMousePos )
297 long nLineHeight = GetTextHeight();
298 long nYPos = rMousePos.Y() + nCurYOffset;
300 Breakpoint* pBrk = First();
301 while ( pBrk )
303 ULONG nLine = pBrk->nLine-1;
304 long nY = nLine*nLineHeight;
305 if ( ( nYPos > nY ) && ( nYPos < ( nY + nLineHeight ) ) )
306 return pBrk;
307 pBrk = Next();
309 return 0;
313 void BreakpointWindow::ToggleBreakpoint( USHORT nLine )
315 Breakpoint* pBrk = FindBreakpoint( nLine );
316 if ( pBrk ) // remove
318 pModule->ClearBP( nLine );
319 delete Remove( pBrk );
321 else // create one
323 InsertBreakpoint( nLine );
326 Invalidate();
329 void BreakpointWindow::ShowMarker( BOOL bShow )
331 if ( nMarkerPos == MARKER_NOMARKER )
332 return;
334 Size aOutSz( GetOutputSize() );
335 long nLineHeight = GetTextHeight();
337 Image aMarker;
338 if ( bErrorMarker )
339 aMarker = pImages->GetImage( IMGID_ERRORMARKER );
340 else
341 aMarker = pImages->GetImage( IMGID_STEPMARKER );
343 Size aMarkerSz( aMarker.GetSizePixel() );
344 aMarkerSz = PixelToLogic( aMarkerSz );
345 Point aMarkerOff( 0, 0 );
346 aMarkerOff.X() = ( aOutSz.Width() - aMarkerSz.Width() ) / 2;
347 aMarkerOff.Y() = ( nLineHeight - aMarkerSz.Height() ) / 2;
349 ULONG nY = nMarkerPos*nLineHeight - nCurYOffset;
350 Point aPos( 0, nY );
351 aPos += aMarkerOff;
352 if ( bShow )
353 DrawImage( aPos, aMarker );
354 else
355 Invalidate( Rectangle( aPos, aMarkerSz ) );
359 void BreakpointWindow::MouseButtonDown( const MouseEvent& rMEvt )
361 if ( rMEvt.GetClicks() == 2 )
363 Point aMousePos( PixelToLogic( rMEvt.GetPosPixel() ) );
364 long nLineHeight = GetTextHeight();
365 long nYPos = aMousePos.Y() + nCurYOffset;
366 long nLine = nYPos / nLineHeight + 1;
367 ToggleBreakpoint( sal::static_int_cast< USHORT >(nLine) );
368 Invalidate();
373 void BreakpointWindow::SetMarkerPos( USHORT nLine, BOOL bError )
375 ShowMarker( FALSE ); // Remove old one
376 nMarkerPos = nLine;
377 bErrorMarker = bError;
378 ShowMarker( TRUE ); // Draw new one
379 Update();
383 void BreakpointWindow::Scroll( long nHorzScroll, long nVertScroll, USHORT nFlags )
385 (void) nFlags; /* avoid warning about unused parameter */
386 nCurYOffset -= nVertScroll;
387 Window::Scroll( nHorzScroll, nVertScroll );