1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_basctl.hxx" 30 31 #include <limits> 32 33 #include <vcl/sound.hxx> 34 35 // #define ITEMID_SEARCH SID_SEARCH_ITEM 36 #define _SVX_NOIDERESIDS 37 #include <brkdlg.hxx> 38 #include <brkdlg.hrc> 39 #include <basidesh.hxx> 40 #include <basidesh.hrc> 41 #include <iderdll.hxx> 42 #include <sfx2/dispatch.hxx> 43 #include <sfx2/viewfrm.hxx> 44 45 // FIXME Why does BreakPointDialog allow only sal_uInt16 for break-point line 46 // numbers, whereas BreakPoint supports sal_uLong? 47 48 bool lcl_ParseText( String aText, sal_uInt16& rLineNr ) 49 { 50 // aText should look like "# n" where 51 // n > 0 && n < std::numeric_limits< sal_uInt16 >::max(). 52 // All spaces are ignored, so there can even be spaces within the 53 // number n. (Maybe it would be better to ignore all whitespace instead 54 // of just spaces.) 55 aText.EraseAllChars(' '); 56 sal_Unicode cFirst = aText.GetChar(0); 57 if (cFirst != '#' && !(cFirst >= '0' && cFirst <= '9')) 58 return false; 59 if (cFirst == '#') 60 aText.Erase(0, 1); 61 // XXX Assumes that sal_uInt16 is contained within sal_Int32: 62 sal_Int32 n = aText.ToInt32(); 63 if (n <= 0 || n > std::numeric_limits< sal_uInt16 >::max()) 64 return false; 65 rLineNr = static_cast< sal_uInt16 >(n); 66 return true; 67 } 68 69 BreakPointDialog::BreakPointDialog( Window* pParent, BreakPointList& rBrkPntList ) : 70 ModalDialog( pParent, IDEResId( RID_BASICIDE_BREAKPOINTDLG ) ), 71 aComboBox( this, IDEResId( RID_CB_BRKPOINTS ) ), 72 aOKButton( this, IDEResId( RID_PB_OK ) ), 73 aCancelButton( this, IDEResId( RID_PB_CANCEL ) ), 74 aNewButton( this, IDEResId( RID_PB_NEW ) ), 75 aDelButton( this, IDEResId( RID_PB_DEL ) ), 76 aCheckBox( this, IDEResId( RID_CHKB_ACTIVE ) ), 77 aBrkText( this, IDEResId( RID_FT_BRKPOINTS ) ), 78 aPassText( this, IDEResId( RID_FT_PASS ) ), 79 aNumericField( this, IDEResId( RID_FLD_PASS ) ), 80 m_rOriginalBreakPointList(rBrkPntList), 81 m_aModifiedBreakPointList(rBrkPntList) 82 { 83 FreeResource(); 84 85 aComboBox.SetUpdateMode( sal_False ); 86 BreakPoint* pBrk = m_aModifiedBreakPointList.First(); 87 BreakPoint* pFirstBrk = pBrk; 88 while ( pBrk ) 89 { 90 String aEntryStr( RTL_CONSTASCII_USTRINGPARAM( "# " ) ); 91 aEntryStr += String::CreateFromInt32( pBrk->nLine ); 92 aComboBox.InsertEntry( aEntryStr, COMBOBOX_APPEND ); 93 pBrk = m_aModifiedBreakPointList.Next(); 94 } 95 aComboBox.SetUpdateMode( sal_True ); 96 97 aOKButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) ); 98 aNewButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) ); 99 aDelButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) ); 100 // aShowButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) ); 101 102 aCheckBox.SetClickHdl( LINK( this, BreakPointDialog, CheckBoxHdl ) ); 103 aComboBox.SetSelectHdl( LINK( this, BreakPointDialog, ComboBoxHighlightHdl ) ); 104 aComboBox.SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) ); 105 aComboBox.GrabFocus(); 106 107 aNumericField.SetMin( 0 ); 108 aNumericField.SetMax( 0x7FFFFFFF ); 109 aNumericField.SetSpinSize( 1 ); 110 aNumericField.SetStrictFormat( sal_True ); 111 aNumericField.SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) ); 112 113 aComboBox.SetText( aComboBox.GetEntry( 0 ) ); 114 UpdateFields( pFirstBrk ); 115 116 CheckButtons(); 117 } 118 119 void BreakPointDialog::SetCurrentBreakPoint( BreakPoint* pBrk ) 120 { 121 String aStr( RTL_CONSTASCII_USTRINGPARAM( "# " ) ); 122 aStr += String::CreateFromInt32( pBrk->nLine ); 123 aComboBox.SetText( aStr ); 124 UpdateFields( pBrk ); 125 } 126 127 void BreakPointDialog::CheckButtons() 128 { 129 // "New" button is enabled if the combo box edit contains a valid line 130 // number that is not already present in the combo box list; otherwise 131 // "OK" and "Delete" buttons are enabled: 132 sal_uInt16 nLine; 133 if (lcl_ParseText(aComboBox.GetText(), nLine) 134 && m_aModifiedBreakPointList.FindBreakPoint(nLine) == 0) 135 { 136 aNewButton.Enable(); 137 aOKButton.Disable(); 138 aDelButton.Disable(); 139 } 140 else 141 { 142 aNewButton.Disable(); 143 aOKButton.Enable(); 144 aDelButton.Enable(); 145 } 146 } 147 148 IMPL_LINK_INLINE_START( BreakPointDialog, CheckBoxHdl, CheckBox *, pChkBx ) 149 { 150 BreakPoint* pBrk = GetSelectedBreakPoint(); 151 if ( pBrk ) 152 pBrk->bEnabled = pChkBx->IsChecked(); 153 154 return 0; 155 } 156 IMPL_LINK_INLINE_END( BreakPointDialog, CheckBoxHdl, CheckBox *, pChkBx ) 157 158 159 160 IMPL_LINK( BreakPointDialog, ComboBoxHighlightHdl, ComboBox *, pBox ) 161 { 162 aNewButton.Disable(); 163 aOKButton.Enable(); 164 aDelButton.Enable(); 165 166 sal_uInt16 nEntry = pBox->GetEntryPos( pBox->GetText() ); 167 BreakPoint* pBrk = m_aModifiedBreakPointList.GetObject( nEntry ); 168 DBG_ASSERT( pBrk, "Kein passender Breakpoint zur Liste ?" ); 169 UpdateFields( pBrk ); 170 171 return 0; 172 } 173 174 175 176 IMPL_LINK( BreakPointDialog, EditModifyHdl, Edit *, pEdit ) 177 { 178 if ( pEdit == &aComboBox ) 179 CheckButtons(); 180 else if ( pEdit == &aNumericField ) 181 { 182 BreakPoint* pBrk = GetSelectedBreakPoint(); 183 if ( pBrk ) 184 pBrk->nStopAfter = pEdit->GetText().ToInt32(); 185 } 186 return 0; 187 } 188 189 190 191 IMPL_LINK( BreakPointDialog, ButtonHdl, Button *, pButton ) 192 { 193 if ( pButton == &aOKButton ) 194 { 195 m_rOriginalBreakPointList.transfer(m_aModifiedBreakPointList); 196 EndDialog( 1 ); 197 } 198 else if ( pButton == &aNewButton ) 199 { 200 // Checkbox beruecksichtigen! 201 String aText( aComboBox.GetText() ); 202 sal_uInt16 nLine; 203 sal_Bool bValid = lcl_ParseText( aText, nLine ); 204 if ( bValid ) 205 { 206 BreakPoint* pBrk = new BreakPoint( nLine ); 207 pBrk->bEnabled = aCheckBox.IsChecked(); 208 pBrk->nStopAfter = (sal_uLong) aNumericField.GetValue(); 209 m_aModifiedBreakPointList.InsertSorted( pBrk ); 210 String aEntryStr( RTL_CONSTASCII_USTRINGPARAM( "# " ) ); 211 aEntryStr += String::CreateFromInt32( pBrk->nLine ); 212 aComboBox.InsertEntry( aEntryStr, COMBOBOX_APPEND ); 213 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 214 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 215 SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 216 if( pDispatcher ) 217 { 218 pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED ); 219 } 220 } 221 else 222 { 223 aComboBox.SetText( aText ); 224 aComboBox.GrabFocus(); 225 Sound::Beep(); 226 } 227 CheckButtons(); 228 } 229 else if ( pButton == &aDelButton ) 230 { 231 sal_uInt16 nEntry = aComboBox.GetEntryPos( aComboBox.GetText() ); 232 BreakPoint* pBrk = m_aModifiedBreakPointList.GetObject( nEntry ); 233 if ( pBrk ) 234 { 235 delete m_aModifiedBreakPointList.Remove( pBrk ); 236 aComboBox.RemoveEntry( nEntry ); 237 if ( nEntry && !( nEntry < aComboBox.GetEntryCount() ) ) 238 nEntry--; 239 aComboBox.SetText( aComboBox.GetEntry( nEntry ) ); 240 BasicIDEShell* pIDEShell = IDE_DLL()->GetShell(); 241 SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL; 242 SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL; 243 244 if( pDispatcher ) 245 { 246 pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED ); 247 } 248 } 249 CheckButtons(); 250 } 251 // else if ( pButton == &aShowButton ) 252 // { 253 // ; 254 // } 255 256 return 0; 257 } 258 259 260 261 void BreakPointDialog::UpdateFields( BreakPoint* pBrk ) 262 { 263 if ( pBrk ) 264 { 265 aCheckBox.Check( pBrk->bEnabled ); 266 aNumericField.SetValue( pBrk->nStopAfter ); 267 } 268 } 269 270 271 272 BreakPoint* BreakPointDialog::GetSelectedBreakPoint() 273 { 274 sal_uInt16 nEntry = aComboBox.GetEntryPos( aComboBox.GetText() ); 275 BreakPoint* pBrk = m_aModifiedBreakPointList.GetObject( nEntry ); 276 return pBrk; 277 } 278 279 280 281