merge the formfield patch from ooo-build
[ooovba.git] / basic / source / app / appedit.cxx
blob122aa9c7a1d2f2182f37e5503eec358c678d5cc5
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: appedit.cxx,v $
10 * $Revision: 1.12 $
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>
41 #endif
43 #include "basic.hrc"
44 #include "appedit.hxx"
45 #include "brkpnts.hxx"
47 TYPEINIT1(AppEdit,AppWin);
48 AppEdit::AppEdit( BasicFrame* pParent )
49 : AppWin( pParent )
50 , pVScroll( NULL )
51 , pHScroll( NULL )
52 , nCurTextWidth(5)
54 String aEmpty;
55 // perhaps load the Untitled-String:
57 pDataEdit = new TextEdit( this, WB_LEFT );
58 LoadIniFile();
59 // define Icon:
60 // pIcon = new Icon( ResId( RID_WORKICON ) );
61 // if( pIcon ) SetIcon( *pIcon );
63 pDataEdit->SetText( aEmpty );
65 pDataEdit->Show();
67 pVScroll = new ScrollBar( this, WB_VSCROLL|WB_DRAG );
68 pVScroll->Show();
69 pVScroll->SetScrollHdl( LINK( this, AppEdit, Scroll ) );
70 pHScroll = new ScrollBar( this, WB_HSCROLL|WB_DRAG );
71 pHScroll->Show();
72 pHScroll->SetScrollHdl( LINK( this, AppEdit, Scroll ) );
74 InitScrollBars();
77 AppEdit::~AppEdit()
79 DataEdit *pHold = pDataEdit;
80 pDataEdit = NULL;
81 delete pHold;
82 delete pHScroll;
83 delete pVScroll;
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 ));
108 #endif
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() ) {
126 case COMMAND_WHEEL:
128 HandleScrollCommand( rCEvt, pHScroll, pVScroll );
130 break;
131 default:
132 AppWin::Command( rCEvt );
137 IMPL_LINK( AppEdit, Scroll, ScrollBar*, pScroll )
139 (void) pScroll; /* avoid warning about unused parameter */
140 if ( !pHScroll || !pVScroll )
141 return 0;
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() );
150 return 0L;
154 void AppEdit::InitScrollBars()
156 if ( !pHScroll || !pVScroll )
157 return;
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() );
168 pVScroll->Show();
170 pHScroll->SetVisibleSize( aOutSz.Width() );
171 pHScroll->SetPageSize( aOutSz.Width() * 8 / 10 );
172 pHScroll->SetLineSize( GetTextWidth( CUniString("x") ) );
173 pHScroll->SetThumbPos( pTextView->GetStartDocPos().X() );
174 pHScroll->Show();
177 void AppEdit::SetScrollBarRanges()
179 // Extra-Method, not InitScrollBars, but for EditEngine-Events.
181 if ( !pHScroll || !pVScroll )
182 return;
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;
200 // Set up the menu
201 long AppEdit::InitMenu( Menu* pMenu )
203 AppWin::InitMenu (pMenu );
205 if( pDataEdit )
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 );
214 return TRUE;
217 long AppEdit::DeInitMenu( Menu* pMenu )
219 AppWin::DeInitMenu (pMenu );
221 pMenu->EnableItem( RID_EDITUNDO );
222 pMenu->EnableItem( RID_EDITREDO );
224 return TRUE;
227 void AppEdit::Resize()
229 if( !pDataEdit )
230 return;
232 Point rHStart,rVStart;
233 Size rHSize,rVSize;
234 Size rNewSize( GetOutputSizePixel() );
236 if ( pHScroll )
238 rHSize = pHScroll->GetSizePixel();
239 ULONG nHieght = rHSize.Height();
240 rNewSize.Height() -= nHieght;
241 rHStart.Y() = rNewSize.Height();
244 if ( pVScroll )
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();
255 if ( pHScroll )
257 pHScroll->SetPosPixel( rHStart );
258 pHScroll->SetSizePixel( rHSize );
261 if ( pVScroll )
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();
285 InitScrollBars();
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 );
302 ToTop();