merge the formfield patch from ooo-build
[ooovba.git] / basctl / source / basicide / brkdlg.cxx
blob8ef8e0a22df3c00b09c641c46a3a03cdda9d78a5
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: brkdlg.cxx,v $
10 * $Revision: 1.11 $
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_basctl.hxx"
34 #include <limits>
36 #include <vcl/sound.hxx>
38 // #define ITEMID_SEARCH SID_SEARCH_ITEM
39 #define _SVX_NOIDERESIDS
40 #include <brkdlg.hxx>
41 #include <brkdlg.hrc>
42 #include <basidesh.hxx>
43 #include <basidesh.hrc>
44 #include <iderdll.hxx>
45 #include <sfx2/dispatch.hxx>
46 #include <sfx2/viewfrm.hxx>
48 // FIXME Why does BreakPointDialog allow only USHORT for break-point line
49 // numbers, whereas BreakPoint supports ULONG?
51 bool lcl_ParseText( String aText, USHORT& rLineNr )
53 // aText should look like "# n" where
54 // n > 0 && n < std::numeric_limits< USHORT >::max().
55 // All spaces are ignored, so there can even be spaces within the
56 // number n. (Maybe it would be better to ignore all whitespace instead
57 // of just spaces.)
58 aText.EraseAllChars(' ');
59 sal_Unicode cFirst = aText.GetChar(0);
60 if (cFirst != '#' && !(cFirst >= '0' && cFirst <= '9'))
61 return false;
62 if (cFirst == '#')
63 aText.Erase(0, 1);
64 // XXX Assumes that USHORT is contained within sal_Int32:
65 sal_Int32 n = aText.ToInt32();
66 if (n <= 0 || n > std::numeric_limits< USHORT >::max())
67 return false;
68 rLineNr = static_cast< USHORT >(n);
69 return true;
72 BreakPointDialog::BreakPointDialog( Window* pParent, BreakPointList& rBrkPntList ) :
73 ModalDialog( pParent, IDEResId( RID_BASICIDE_BREAKPOINTDLG ) ),
74 aComboBox( this, IDEResId( RID_CB_BRKPOINTS ) ),
75 aOKButton( this, IDEResId( RID_PB_OK ) ),
76 aCancelButton( this, IDEResId( RID_PB_CANCEL ) ),
77 aNewButton( this, IDEResId( RID_PB_NEW ) ),
78 aDelButton( this, IDEResId( RID_PB_DEL ) ),
79 aCheckBox( this, IDEResId( RID_CHKB_ACTIVE ) ),
80 aBrkText( this, IDEResId( RID_FT_BRKPOINTS ) ),
81 aPassText( this, IDEResId( RID_FT_PASS ) ),
82 aNumericField( this, IDEResId( RID_FLD_PASS ) ),
83 m_rOriginalBreakPointList(rBrkPntList),
84 m_aModifiedBreakPointList(rBrkPntList)
86 FreeResource();
88 aComboBox.SetUpdateMode( FALSE );
89 BreakPoint* pBrk = m_aModifiedBreakPointList.First();
90 BreakPoint* pFirstBrk = pBrk;
91 while ( pBrk )
93 String aEntryStr( RTL_CONSTASCII_USTRINGPARAM( "# " ) );
94 aEntryStr += String::CreateFromInt32( pBrk->nLine );
95 aComboBox.InsertEntry( aEntryStr, COMBOBOX_APPEND );
96 pBrk = m_aModifiedBreakPointList.Next();
98 aComboBox.SetUpdateMode( TRUE );
100 aOKButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
101 aNewButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
102 aDelButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
103 // aShowButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
105 aCheckBox.SetClickHdl( LINK( this, BreakPointDialog, CheckBoxHdl ) );
106 aComboBox.SetSelectHdl( LINK( this, BreakPointDialog, ComboBoxHighlightHdl ) );
107 aComboBox.SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
108 aComboBox.GrabFocus();
110 aNumericField.SetMin( 0 );
111 aNumericField.SetMax( 0x7FFFFFFF );
112 aNumericField.SetSpinSize( 1 );
113 aNumericField.SetStrictFormat( TRUE );
114 aNumericField.SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
116 aComboBox.SetText( aComboBox.GetEntry( 0 ) );
117 UpdateFields( pFirstBrk );
119 CheckButtons();
122 void BreakPointDialog::SetCurrentBreakPoint( BreakPoint* pBrk )
124 String aStr( RTL_CONSTASCII_USTRINGPARAM( "# " ) );
125 aStr += String::CreateFromInt32( pBrk->nLine );
126 aComboBox.SetText( aStr );
127 UpdateFields( pBrk );
130 void BreakPointDialog::CheckButtons()
132 // "New" button is enabled if the combo box edit contains a valid line
133 // number that is not already present in the combo box list; otherwise
134 // "OK" and "Delete" buttons are enabled:
135 USHORT nLine;
136 if (lcl_ParseText(aComboBox.GetText(), nLine)
137 && m_aModifiedBreakPointList.FindBreakPoint(nLine) == 0)
139 aNewButton.Enable();
140 aOKButton.Disable();
141 aDelButton.Disable();
143 else
145 aNewButton.Disable();
146 aOKButton.Enable();
147 aDelButton.Enable();
151 IMPL_LINK_INLINE_START( BreakPointDialog, CheckBoxHdl, CheckBox *, pChkBx )
153 BreakPoint* pBrk = GetSelectedBreakPoint();
154 if ( pBrk )
155 pBrk->bEnabled = pChkBx->IsChecked();
157 return 0;
159 IMPL_LINK_INLINE_END( BreakPointDialog, CheckBoxHdl, CheckBox *, pChkBx )
163 IMPL_LINK( BreakPointDialog, ComboBoxHighlightHdl, ComboBox *, pBox )
165 aNewButton.Disable();
166 aOKButton.Enable();
167 aDelButton.Enable();
169 USHORT nEntry = pBox->GetEntryPos( pBox->GetText() );
170 BreakPoint* pBrk = m_aModifiedBreakPointList.GetObject( nEntry );
171 DBG_ASSERT( pBrk, "Kein passender Breakpoint zur Liste ?" );
172 UpdateFields( pBrk );
174 return 0;
179 IMPL_LINK( BreakPointDialog, EditModifyHdl, Edit *, pEdit )
181 if ( pEdit == &aComboBox )
182 CheckButtons();
183 else if ( pEdit == &aNumericField )
185 BreakPoint* pBrk = GetSelectedBreakPoint();
186 if ( pBrk )
187 pBrk->nStopAfter = pEdit->GetText().ToInt32();
189 return 0;
194 IMPL_LINK( BreakPointDialog, ButtonHdl, Button *, pButton )
196 if ( pButton == &aOKButton )
198 m_rOriginalBreakPointList.transfer(m_aModifiedBreakPointList);
199 EndDialog( 1 );
201 else if ( pButton == &aNewButton )
203 // Checkbox beruecksichtigen!
204 String aText( aComboBox.GetText() );
205 USHORT nLine;
206 BOOL bValid = lcl_ParseText( aText, nLine );
207 if ( bValid )
209 BreakPoint* pBrk = new BreakPoint( nLine );
210 pBrk->bEnabled = aCheckBox.IsChecked();
211 pBrk->nStopAfter = (ULONG) aNumericField.GetValue();
212 m_aModifiedBreakPointList.InsertSorted( pBrk );
213 String aEntryStr( RTL_CONSTASCII_USTRINGPARAM( "# " ) );
214 aEntryStr += String::CreateFromInt32( pBrk->nLine );
215 aComboBox.InsertEntry( aEntryStr, COMBOBOX_APPEND );
216 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
217 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
218 SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
219 if( pDispatcher )
221 pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
224 else
226 aComboBox.SetText( aText );
227 aComboBox.GrabFocus();
228 Sound::Beep();
230 CheckButtons();
232 else if ( pButton == &aDelButton )
234 USHORT nEntry = aComboBox.GetEntryPos( aComboBox.GetText() );
235 BreakPoint* pBrk = m_aModifiedBreakPointList.GetObject( nEntry );
236 if ( pBrk )
238 delete m_aModifiedBreakPointList.Remove( pBrk );
239 aComboBox.RemoveEntry( nEntry );
240 if ( nEntry && !( nEntry < aComboBox.GetEntryCount() ) )
241 nEntry--;
242 aComboBox.SetText( aComboBox.GetEntry( nEntry ) );
243 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
244 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
245 SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
247 if( pDispatcher )
249 pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
252 CheckButtons();
254 // else if ( pButton == &aShowButton )
255 // {
256 // ;
257 // }
259 return 0;
264 void BreakPointDialog::UpdateFields( BreakPoint* pBrk )
266 if ( pBrk )
268 aCheckBox.Check( pBrk->bEnabled );
269 aNumericField.SetValue( pBrk->nStopAfter );
275 BreakPoint* BreakPointDialog::GetSelectedBreakPoint()
277 USHORT nEntry = aComboBox.GetEntryPos( aComboBox.GetText() );
278 BreakPoint* pBrk = m_aModifiedBreakPointList.GetObject( nEntry );
279 return pBrk;