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: appedit.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/config.hxx>
34 #include <svtools/ctrltool.hxx>
35 #include <svtools/textview.hxx>
36 #include <svtools/texteng.hxx>
37 #include <svtools/undo.hxx>
39 #ifndef _BASIC_TTRESHLP_HXX
40 #include <basic/ttstrhlp.hxx>
44 #include "appedit.hxx"
45 #include "brkpnts.hxx"
47 TYPEINIT1(AppEdit
,AppWin
);
48 AppEdit::AppEdit( BasicFrame
* pParent
)
55 // perhaps load the Untitled-String:
57 pDataEdit
= new TextEdit( this, WB_LEFT
);
60 // pIcon = new Icon( ResId( RID_WORKICON ) );
61 // if( pIcon ) SetIcon( *pIcon );
63 pDataEdit
->SetText( aEmpty
);
67 pVScroll
= new ScrollBar( this, WB_VSCROLL
|WB_DRAG
);
69 pVScroll
->SetScrollHdl( LINK( this, AppEdit
, Scroll
) );
70 pHScroll
= new ScrollBar( this, WB_HSCROLL
|WB_DRAG
);
72 pHScroll
->SetScrollHdl( LINK( this, AppEdit
, Scroll
) );
79 DataEdit
*pHold
= pDataEdit
;
86 void AppEdit::LoadIniFile()
88 TextView
*pTextView
= ((TextEdit
*)pDataEdit
)->aEdit
.pTextView
;
89 BOOL bWasModified
= pTextView
->GetTextEngine()->IsModified();
90 pTextView
->GetTextEngine()->SetModified( FALSE
);
92 FontList
aFontList( pFrame
); // Just some Window is needed
93 Config
aConf(Config::GetConfigName( Config::GetDefDirectory(), CUniString("testtool") ));
94 aConf
.SetGroup("Misc");
95 String aFontName
= String( aConf
.ReadKey( "ScriptFontName", "Courier" ), RTL_TEXTENCODING_UTF8
);
96 String aFontStyle
= String( aConf
.ReadKey( "ScriptFontStyle", "normal" ), RTL_TEXTENCODING_UTF8
);
97 String aFontSize
= String( aConf
.ReadKey( "ScriptFontSize", "12" ), RTL_TEXTENCODING_UTF8
);
98 Font aFont
= aFontList
.Get( aFontName
, aFontStyle
);
99 // ULONG nFontSize = aFontSize.GetValue( FUNIT_POINT );
100 ULONG nFontSize
= aFontSize
.ToInt32();
101 // aFont.SetSize( Size( nFontSize, nFontSize ) );
102 aFont
.SetHeight( nFontSize
);
104 #if OSL_DEBUG_LEVEL > 1
106 Font
aFont2( OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED
, Application::GetSettings().GetUILanguage(), 0, pFrame
));
109 aFont
.SetTransparent( FALSE
);
110 // aFont.SetAlign( ALIGN_BOTTOM );
111 // aFont.SetHeight( aFont.GetHeight()+2 );
112 pDataEdit
->SetFont( aFont
);
114 if ( ((TextEdit
*)pDataEdit
)->GetBreakpointWindow() )
116 ((TextEdit
*)pDataEdit
)->GetBreakpointWindow()->SetFont( aFont
);
117 ((TextEdit
*)pDataEdit
)->GetBreakpointWindow()->Invalidate();
120 pTextView
->GetTextEngine()->SetModified( bWasModified
); // Perhaps reset the flag
123 void AppEdit::Command( const CommandEvent
& rCEvt
)
125 switch( rCEvt
.GetCommand() ) {
128 HandleScrollCommand( rCEvt
, pHScroll
, pVScroll
);
132 AppWin::Command( rCEvt
);
137 IMPL_LINK( AppEdit
, Scroll
, ScrollBar
*, pScroll
)
139 (void) pScroll
; /* avoid warning about unused parameter */
140 if ( !pHScroll
|| !pVScroll
)
143 TextView
*pTextView
= ((TextEdit
*)pDataEdit
)->aEdit
.pTextView
;
144 pTextView
->SetStartDocPos( Point( pHScroll
->GetThumbPos(), pVScroll
->GetThumbPos() ) );
145 pTextView
->Invalidate();
147 if ( ((TextEdit
*)pDataEdit
)->GetBreakpointWindow() )
148 ((TextEdit
*)pDataEdit
)->GetBreakpointWindow()->Scroll( 0, ((TextEdit
*)pDataEdit
)->GetBreakpointWindow()->GetCurYOffset() - pTextView
->GetStartDocPos().Y() );
154 void AppEdit::InitScrollBars()
156 if ( !pHScroll
|| !pVScroll
)
159 TextView
*pTextView
= ((TextEdit
*)pDataEdit
)->aEdit
.pTextView
;
161 SetScrollBarRanges();
163 Size
aOutSz( pTextView
->GetWindow()->GetOutputSizePixel() );
164 pVScroll
->SetVisibleSize( aOutSz
.Height() );
165 pVScroll
->SetPageSize( aOutSz
.Height() * 8 / 10 );
166 pVScroll
->SetLineSize( GetTextHeight() +2 ); // +2 is empirical. don't know why
167 pVScroll
->SetThumbPos( pTextView
->GetStartDocPos().Y() );
170 pHScroll
->SetVisibleSize( aOutSz
.Width() );
171 pHScroll
->SetPageSize( aOutSz
.Width() * 8 / 10 );
172 pHScroll
->SetLineSize( GetTextWidth( CUniString("x") ) );
173 pHScroll
->SetThumbPos( pTextView
->GetStartDocPos().X() );
177 void AppEdit::SetScrollBarRanges()
179 // Extra-Method, not InitScrollBars, but for EditEngine-Events.
181 if ( !pHScroll
|| !pVScroll
)
184 pHScroll
->SetRange( Range( 0, nCurTextWidth
) );
185 pVScroll
->SetRange( Range( 0, ((TextEdit
*)pDataEdit
)->aEdit
.pTextEngine
->GetTextHeight() ) );
190 USHORT
AppEdit::GetLineNr()
192 return pDataEdit
->GetLineNr();
195 FileType
AppEdit::GetFileType()
197 return FT_BASIC_SOURCE
;
201 long AppEdit::InitMenu( Menu
* pMenu
)
203 AppWin::InitMenu (pMenu
);
207 USHORT UndoCount
= ((TextEdit
*)pDataEdit
)->aEdit
.pTextEngine
->GetUndoManager().GetUndoActionCount();
208 USHORT RedoCount
= ((TextEdit
*)pDataEdit
)->aEdit
.pTextEngine
->GetUndoManager().GetRedoActionCount();
210 pMenu
->EnableItem( RID_EDITUNDO
, UndoCount
> 0 );
211 pMenu
->EnableItem( RID_EDITREDO
, RedoCount
> 0 );
217 long AppEdit::DeInitMenu( Menu
* pMenu
)
219 AppWin::DeInitMenu (pMenu
);
221 pMenu
->EnableItem( RID_EDITUNDO
);
222 pMenu
->EnableItem( RID_EDITREDO
);
227 void AppEdit::Resize()
232 Point rHStart
,rVStart
;
234 Size
rNewSize( GetOutputSizePixel() );
238 rHSize
= pHScroll
->GetSizePixel();
239 ULONG nHieght
= rHSize
.Height();
240 rNewSize
.Height() -= nHieght
;
241 rHStart
.Y() = rNewSize
.Height();
246 rVSize
= pVScroll
->GetSizePixel();
247 ULONG nWidth
= rVSize
.Width();
248 rNewSize
.Width() -= nWidth
;
249 rVStart
.X() = rNewSize
.Width();
252 rHSize
.Width() = rNewSize
.Width();
253 rVSize
.Height() = rNewSize
.Height();
257 pHScroll
->SetPosPixel( rHStart
);
258 pHScroll
->SetSizePixel( rHSize
);
263 pVScroll
->SetPosPixel( rVStart
);
264 pVScroll
->SetSizePixel( rVSize
);
266 pDataEdit
->SetPosPixel( Point() );
267 pDataEdit
->SetSizePixel( rNewSize
);
270 TextView
*pTextView
= ((TextEdit
*)pDataEdit
)->aEdit
.pTextView
;
271 long nVisY
= pTextView
->GetStartDocPos().Y();
272 pTextView
->ShowCursor();
273 Size
aOutSz( pTextView
->GetWindow()->GetOutputSizePixel() );
274 long nMaxVisAreaStart
= pTextView
->GetTextEngine()->GetTextHeight() - aOutSz
.Height();
275 if ( nMaxVisAreaStart
< 0 )
276 nMaxVisAreaStart
= 0;
277 if ( pTextView
->GetStartDocPos().Y() > nMaxVisAreaStart
)
279 Point
aStartDocPos( pTextView
->GetStartDocPos() );
280 aStartDocPos
.Y() = nMaxVisAreaStart
;
281 pTextView
->SetStartDocPos( aStartDocPos
);
282 pTextView
->ShowCursor();
283 // pModulWindow->GetBreakPointWindow().GetCurYOffset() = aStartDocPos.Y();
286 if ( nVisY
!= pTextView
->GetStartDocPos().Y() )
287 pTextView
->GetWindow()->Invalidate();
291 void AppEdit::PostLoad()
295 void AppEdit::PostSaveAs()
299 void AppEdit::Highlight( USHORT nLine
, USHORT nCol1
, USHORT nCol2
)
301 ((TextEdit
*)pDataEdit
)->Highlight( nLine
, nCol1
, nCol2
);