1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: brkpnts.cxx,v $
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>
47 #include "brkpnts.hxx"
56 Breakpoint( USHORT nL
) { nLine
= nL
; }
60 ImageList
* BreakpointWindow::pImages
= NULL
;
63 BreakpointWindow::BreakpointWindow( Window
*pParent
)
66 , nMarkerPos( MARKER_NOMARKER
)
68 , bErrorMarker( FALSE
)
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
);
80 void BreakpointWindow::Reset()
82 Breakpoint
* pBrk
= First();
90 pModule
->ClearAllBP();
93 void BreakpointWindow::SetModule( SbModule
*pMod
)
97 for ( i
=0 ; i
< pModule
->GetBPCount() ; i
++ )
99 InsertBreakpoint( pModule
->GetBP( i
) );
105 void BreakpointWindow::SetBPsInModule()
107 pModule
->ClearAllBP();
109 Breakpoint
* pBrk
= First();
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" );
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();
133 if ( nLine
<= pBrk
->nLine
)
135 if ( pBrk
->nLine
!= nLine
)
145 // No insert position found => LIST_APPEND
147 Insert( pNewBrk
, LIST_APPEND
);
151 if ( pModule
->SetBP( nLine
) )
153 #if OSL_DEBUG_LEVEL > 1
154 DBG_ASSERT( !pModule
->IsCompiled() || pModule
->IsBP( nLine
), "Brechpunkt wurde nicht gesetzt" );
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" );
172 Breakpoint
* BreakpointWindow::FindBreakpoint( ULONG nLine
)
174 Breakpoint
* pBrk
= First();
177 if ( pBrk
->nLine
== nLine
)
183 return (Breakpoint
*)0;
187 void BreakpointWindow::AdjustBreakpoints( ULONG nLine
, BOOL bInserted
)
189 if ( nLine
== 0 ) //TODO: nLine == TEXT_PARA_ALL+1
191 Breakpoint
* pBrk
= First();
194 BOOL bDelBrk
= FALSE
;
195 if ( pBrk
->nLine
== nLine
)
202 else if ( pBrk
->nLine
> nLine
)
212 ULONG n
= GetCurPos();
213 delete Remove( pBrk
);
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
) );
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();
250 if ( aBreakpoints
.Len() )
253 aBreakpoints
+= ByteString::CreateFromInt32( pBrk
->nLine
);
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
);
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();
283 #if OSL_DEBUG_LEVEL > 1
284 DBG_ASSERT( !pModule
->IsCompiled() || pModule
->IsBP( pBrk
->nLine
), "Brechpunkt wurde nicht gesetzt" );
286 ULONG nLine
= pBrk
->nLine
-1;
287 ULONG nY
= nLine
*nLineHeight
- nCurYOffset
;
288 DrawImage( Point( 0, nY
) + aBmpOff
, aBrk
);
295 Breakpoint
* BreakpointWindow::FindBreakpoint( const Point
& rMousePos
)
297 long nLineHeight
= GetTextHeight();
298 long nYPos
= rMousePos
.Y() + nCurYOffset
;
300 Breakpoint
* pBrk
= First();
303 ULONG nLine
= pBrk
->nLine
-1;
304 long nY
= nLine
*nLineHeight
;
305 if ( ( nYPos
> nY
) && ( nYPos
< ( nY
+ nLineHeight
) ) )
313 void BreakpointWindow::ToggleBreakpoint( USHORT nLine
)
315 Breakpoint
* pBrk
= FindBreakpoint( nLine
);
316 if ( pBrk
) // remove
318 pModule
->ClearBP( nLine
);
319 delete Remove( pBrk
);
323 InsertBreakpoint( nLine
);
329 void BreakpointWindow::ShowMarker( BOOL bShow
)
331 if ( nMarkerPos
== MARKER_NOMARKER
)
334 Size
aOutSz( GetOutputSize() );
335 long nLineHeight
= GetTextHeight();
339 aMarker
= pImages
->GetImage( IMGID_ERRORMARKER
);
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
;
353 DrawImage( aPos
, aMarker
);
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
) );
373 void BreakpointWindow::SetMarkerPos( USHORT nLine
, BOOL bError
)
375 ShowMarker( FALSE
); // Remove old one
377 bErrorMarker
= bError
;
378 ShowMarker( TRUE
); // Draw new one
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
);