LCOV - code coverage report
Current view: top level - basctl/source/basicide - brkdlg.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 125 0.0 %
Date: 2014-04-14 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #define _SVX_NOIDERESIDS
      22             : #include "breakpoint.hxx"
      23             : #include "brkdlg.hxx"
      24             : #include "basidesh.hxx"
      25             : #include "basidesh.hrc"
      26             : #include "iderdll.hxx"
      27             : 
      28             : #include <sfx2/dispatch.hxx>
      29             : #include <sfx2/viewfrm.hxx>
      30             : 
      31             : namespace basctl
      32             : {
      33             : 
      34             : // FIXME  Why does BreakPointDialog allow only sal_uInt16 for break-point line
      35             : // numbers, whereas BreakPoint supports sal_uLong?
      36             : 
      37             : namespace
      38             : {
      39             : 
      40           0 : bool lcl_ParseText(OUString const &rText, size_t& rLineNr )
      41             : {
      42             :     // aText should look like "# n" where
      43             :     // n > 0 && n < std::numeric_limits< sal_uInt16 >::max().
      44             :     // All spaces are ignored, so there can even be spaces within the
      45             :     // number n.  (Maybe it would be better to ignore all whitespace instead
      46             :     // of just spaces.)
      47             :     OUString aText(
      48           0 :         rText.replaceAll(" ", OUString()));
      49           0 :     if (aText.isEmpty())
      50           0 :         return false;
      51           0 :     sal_Unicode cFirst = aText[0];
      52           0 :     if (cFirst != '#' && !(cFirst >= '0' && cFirst <= '9'))
      53           0 :         return false;
      54           0 :     if (cFirst == '#')
      55           0 :         aText = aText.copy(1);
      56             :     // XXX Assumes that sal_uInt16 is contained within sal_Int32:
      57           0 :     sal_Int32 n = aText.toInt32();
      58           0 :     if ( n <= 0 )
      59           0 :         return false;
      60           0 :     rLineNr = static_cast< size_t >(n);
      61           0 :     return true;
      62             : }
      63             : 
      64             : } // namespace
      65             : 
      66           0 : BreakPointDialog::BreakPointDialog( Window* pParent, BreakPointList& rBrkPntList )
      67             :     : ModalDialog(pParent, "ManageBreakpointsDialog",
      68             :         "modules/BasicIDE/ui/managebreakpoints.ui")
      69             :     , m_rOriginalBreakPointList(rBrkPntList)
      70           0 :     , m_aModifiedBreakPointList(rBrkPntList)
      71             : {
      72           0 :     get(m_pComboBox, "entries");
      73           0 :     m_pComboBox->set_height_request(m_pComboBox->GetTextHeight() * 12);
      74           0 :     m_pComboBox->set_width_request(m_pComboBox->approximate_char_width() * 32);
      75           0 :     get(m_pOKButton, "ok");
      76           0 :     get(m_pNewButton, "new");
      77           0 :     get(m_pDelButton, "delete");
      78           0 :     get(m_pCheckBox, "active");
      79           0 :     get(m_pNumericField, "pass-nospin");
      80             : 
      81           0 :     m_pComboBox->SetUpdateMode(false);
      82           0 :     for ( size_t i = 0, n = m_aModifiedBreakPointList.size(); i < n; ++i )
      83             :     {
      84           0 :         BreakPoint* pBrk = m_aModifiedBreakPointList.at( i );
      85           0 :         OUString aEntryStr( "# " + OUString::number(pBrk->nLine) );
      86           0 :         m_pComboBox->InsertEntry( aEntryStr, COMBOBOX_APPEND );
      87           0 :     }
      88           0 :     m_pComboBox->SetUpdateMode(true);
      89             : 
      90           0 :     m_pOKButton->SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
      91           0 :     m_pNewButton->SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
      92           0 :     m_pDelButton->SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
      93             : 
      94           0 :     m_pCheckBox->SetClickHdl( LINK( this, BreakPointDialog, CheckBoxHdl ) );
      95           0 :     m_pComboBox->SetSelectHdl( LINK( this, BreakPointDialog, ComboBoxHighlightHdl ) );
      96           0 :     m_pComboBox->SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
      97           0 :     m_pComboBox->GrabFocus();
      98             : 
      99           0 :     m_pNumericField->SetMin( 0 );
     100           0 :     m_pNumericField->SetMax( 0x7FFFFFFF );
     101           0 :     m_pNumericField->SetSpinSize( 1 );
     102           0 :     m_pNumericField->SetStrictFormat(true);
     103           0 :     m_pNumericField->SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
     104             : 
     105           0 :     m_pComboBox->SetText( m_pComboBox->GetEntry( 0 ) );
     106           0 :     UpdateFields( m_aModifiedBreakPointList.at( 0 ) );
     107             : 
     108           0 :     CheckButtons();
     109           0 : }
     110             : 
     111           0 : void BreakPointDialog::SetCurrentBreakPoint( BreakPoint* pBrk )
     112             : {
     113           0 :     OUString aStr( "# " + OUString::number(pBrk->nLine) );
     114           0 :     m_pComboBox->SetText( aStr );
     115           0 :     UpdateFields( pBrk );
     116           0 : }
     117             : 
     118           0 : void BreakPointDialog::CheckButtons()
     119             : {
     120             :     // "New" button is enabled if the combo box edit contains a valid line
     121             :     // number that is not already present in the combo box list; otherwise
     122             :     // "OK" and "Delete" buttons are enabled:
     123             :     size_t nLine;
     124           0 :     if (lcl_ParseText(m_pComboBox->GetText(), nLine)
     125           0 :         && m_aModifiedBreakPointList.FindBreakPoint(nLine) == 0)
     126             :     {
     127           0 :         m_pNewButton->Enable();
     128           0 :         m_pOKButton->Disable();
     129           0 :         m_pDelButton->Disable();
     130             :     }
     131             :     else
     132             :     {
     133           0 :         m_pNewButton->Disable();
     134           0 :         m_pOKButton->Enable();
     135           0 :         m_pDelButton->Enable();
     136             :     }
     137           0 : }
     138             : 
     139           0 : IMPL_LINK_INLINE_START( BreakPointDialog, CheckBoxHdl, ::CheckBox *, pChkBx )
     140             : {
     141           0 :     BreakPoint* pBrk = GetSelectedBreakPoint();
     142           0 :     if ( pBrk )
     143           0 :         pBrk->bEnabled = pChkBx->IsChecked();
     144             : 
     145           0 :     return 0;
     146             : }
     147           0 : IMPL_LINK_INLINE_END( BreakPointDialog, CheckBoxHdl, ::CheckBox *, pChkBx )
     148             : 
     149             : 
     150             : 
     151           0 : IMPL_LINK( BreakPointDialog, ComboBoxHighlightHdl, ComboBox *, pBox )
     152             : {
     153           0 :     m_pNewButton->Disable();
     154           0 :     m_pOKButton->Enable();
     155           0 :     m_pDelButton->Enable();
     156             : 
     157           0 :     sal_Int32 nEntry = pBox->GetEntryPos( pBox->GetText() );
     158           0 :     BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
     159             :     DBG_ASSERT( pBrk, "Kein passender Breakpoint zur Liste ?" );
     160           0 :     UpdateFields( pBrk );
     161             : 
     162           0 :     return 0;
     163             : }
     164             : 
     165             : 
     166             : 
     167           0 : IMPL_LINK( BreakPointDialog, EditModifyHdl, Edit *, pEdit )
     168             : {
     169           0 :     if (pEdit == m_pComboBox)
     170           0 :         CheckButtons();
     171           0 :     else if (pEdit == m_pNumericField)
     172             :     {
     173           0 :         BreakPoint* pBrk = GetSelectedBreakPoint();
     174           0 :         if ( pBrk )
     175           0 :             pBrk->nStopAfter = pEdit->GetText().toInt32();
     176             :     }
     177           0 :     return 0;
     178             : }
     179             : 
     180             : 
     181             : 
     182           0 : IMPL_LINK( BreakPointDialog, ButtonHdl, Button *, pButton )
     183             : {
     184           0 :     if (pButton == m_pOKButton)
     185             :     {
     186           0 :         m_rOriginalBreakPointList.transfer(m_aModifiedBreakPointList);
     187           0 :         EndDialog( 1 );
     188             :     }
     189           0 :     else if (pButton == m_pNewButton)
     190             :     {
     191             :         // keep checkbox in mind!
     192           0 :         OUString aText( m_pComboBox->GetText() );
     193             :         size_t nLine;
     194           0 :         bool bValid = lcl_ParseText( aText, nLine );
     195           0 :         if ( bValid )
     196             :         {
     197           0 :             BreakPoint* pBrk = new BreakPoint( nLine );
     198           0 :             pBrk->bEnabled = m_pCheckBox->IsChecked();
     199           0 :             pBrk->nStopAfter = (size_t) m_pNumericField->GetValue();
     200           0 :             m_aModifiedBreakPointList.InsertSorted( pBrk );
     201           0 :             OUString aEntryStr( "# " + OUString::number(pBrk->nLine) );
     202           0 :             m_pComboBox->InsertEntry( aEntryStr, COMBOBOX_APPEND );
     203           0 :             if (SfxDispatcher* pDispatcher = GetDispatcher())
     204           0 :                 pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
     205             :         }
     206             :         else
     207             :         {
     208           0 :             m_pComboBox->SetText( aText );
     209           0 :             m_pComboBox->GrabFocus();
     210             :         }
     211           0 :         CheckButtons();
     212             :     }
     213           0 :     else if (pButton == m_pDelButton)
     214             :     {
     215           0 :         sal_Int32 nEntry = m_pComboBox->GetEntryPos( m_pComboBox->GetText() );
     216           0 :         BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
     217           0 :         if ( pBrk )
     218             :         {
     219           0 :             delete m_aModifiedBreakPointList.remove( pBrk );
     220           0 :             m_pComboBox->RemoveEntryAt(nEntry);
     221           0 :             if ( nEntry && !( nEntry < m_pComboBox->GetEntryCount() ) )
     222           0 :                 nEntry--;
     223           0 :             m_pComboBox->SetText( m_pComboBox->GetEntry( nEntry ) );
     224           0 :             if (SfxDispatcher* pDispatcher = GetDispatcher())
     225           0 :                 pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
     226             :         }
     227           0 :         CheckButtons();
     228             :     }
     229             : 
     230           0 :     return 0;
     231             : }
     232             : 
     233             : 
     234             : 
     235           0 : void BreakPointDialog::UpdateFields( BreakPoint* pBrk )
     236             : {
     237           0 :     if ( pBrk )
     238             :     {
     239           0 :         m_pCheckBox->Check( pBrk->bEnabled );
     240           0 :         m_pNumericField->SetValue( pBrk->nStopAfter );
     241             :     }
     242           0 : }
     243             : 
     244             : 
     245             : 
     246           0 : BreakPoint* BreakPointDialog::GetSelectedBreakPoint()
     247             : {
     248           0 :     size_t nEntry = m_pComboBox->GetEntryPos( m_pComboBox->GetText() );
     249           0 :     BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
     250           0 :     return pBrk;
     251             : }
     252             : 
     253             : } // namespace basctl
     254             : 
     255             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10