Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / basctl / source / basicide / brkdlg.cxx
blobf661b114264cc37c0f7670a1bfdc0e40b1c8ad83
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include "breakpoint.hxx"
23 #include "brkdlg.hxx"
24 #include <basidesh.hxx>
26 #include <sfx2/dispatch.hxx>
28 namespace basctl
31 // FIXME Why does BreakPointDialog allow only sal_uInt16 for break-point line
32 // numbers, whereas BreakPoint supports sal_uLong?
34 namespace
37 bool lcl_ParseText(OUString const &rText, size_t& rLineNr )
39 // aText should look like "# n" where
40 // n > 0 && n < std::numeric_limits< sal_uInt16 >::max().
41 // All spaces are ignored, so there can even be spaces within the
42 // number n. (Maybe it would be better to ignore all whitespace instead
43 // of just spaces.)
44 OUString aText(
45 rText.replaceAll(" ", ""));
46 if (aText.isEmpty())
47 return false;
48 sal_Unicode cFirst = aText[0];
49 if (cFirst != '#' && !(cFirst >= '0' && cFirst <= '9'))
50 return false;
51 if (cFirst == '#')
52 aText = aText.copy(1);
53 // XXX Assumes that sal_uInt16 is contained within sal_Int32:
54 sal_Int32 n = aText.toInt32();
55 if ( n <= 0 )
56 return false;
57 rLineNr = static_cast< size_t >(n);
58 return true;
61 } // namespace
63 BreakPointDialog::BreakPointDialog( vcl::Window* pParent, BreakPointList& rBrkPntList )
64 : ModalDialog(pParent, "ManageBreakpointsDialog",
65 "modules/BasicIDE/ui/managebreakpoints.ui")
66 , m_rOriginalBreakPointList(rBrkPntList)
67 , m_aModifiedBreakPointList(rBrkPntList)
69 get(m_pComboBox, "entries");
70 m_pComboBox->set_height_request(m_pComboBox->GetTextHeight() * 12);
71 m_pComboBox->set_width_request(m_pComboBox->approximate_char_width() * 32);
72 get(m_pOKButton, "ok");
73 get(m_pNewButton, "new");
74 get(m_pDelButton, "delete");
75 get(m_pCheckBox, "active");
76 get(m_pNumericField, "pass-nospin");
78 m_pComboBox->SetUpdateMode(false);
79 for ( size_t i = 0, n = m_aModifiedBreakPointList.size(); i < n; ++i )
81 BreakPoint* pBrk = m_aModifiedBreakPointList.at( i );
82 OUString aEntryStr( "# " + OUString::number(pBrk->nLine) );
83 m_pComboBox->InsertEntry( aEntryStr );
85 m_pComboBox->SetUpdateMode(true);
87 m_pOKButton->SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
88 m_pNewButton->SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
89 m_pDelButton->SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
91 m_pCheckBox->SetClickHdl( LINK( this, BreakPointDialog, CheckBoxHdl ) );
92 m_pComboBox->SetSelectHdl( LINK( this, BreakPointDialog, ComboBoxHighlightHdl ) );
93 m_pComboBox->SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
94 m_pComboBox->GrabFocus();
96 m_pNumericField->SetMin( 0 );
97 m_pNumericField->SetMax( 0x7FFFFFFF );
98 m_pNumericField->SetSpinSize( 1 );
99 m_pNumericField->SetStrictFormat(true);
100 m_pNumericField->SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
102 m_pComboBox->SetText( m_pComboBox->GetEntry( 0 ) );
103 UpdateFields( m_aModifiedBreakPointList.at( 0 ) );
105 CheckButtons();
108 BreakPointDialog::~BreakPointDialog()
110 disposeOnce();
113 void BreakPointDialog::dispose()
115 m_pComboBox.clear();
116 m_pOKButton.clear();
117 m_pNewButton.clear();
118 m_pDelButton.clear();
119 m_pNumericField.clear();
120 m_pCheckBox.clear();
121 ModalDialog::dispose();
124 void BreakPointDialog::SetCurrentBreakPoint( BreakPoint const * pBrk )
126 OUString aStr( "# " + OUString::number(pBrk->nLine) );
127 m_pComboBox->SetText( aStr );
128 UpdateFields( pBrk );
131 void BreakPointDialog::CheckButtons()
133 // "New" button is enabled if the combo box edit contains a valid line
134 // number that is not already present in the combo box list; otherwise
135 // "OK" and "Delete" buttons are enabled:
136 size_t nLine;
137 if (lcl_ParseText(m_pComboBox->GetText(), nLine)
138 && m_aModifiedBreakPointList.FindBreakPoint(nLine) == nullptr)
140 m_pNewButton->Enable();
141 m_pOKButton->Disable();
142 m_pDelButton->Disable();
144 else
146 m_pNewButton->Disable();
147 m_pOKButton->Enable();
148 m_pDelButton->Enable();
152 IMPL_LINK( BreakPointDialog, CheckBoxHdl, Button *, pButton, void )
154 ::CheckBox * pChkBx = static_cast<::CheckBox*>(pButton);
155 BreakPoint* pBrk = GetSelectedBreakPoint();
156 if ( pBrk )
157 pBrk->bEnabled = pChkBx->IsChecked();
160 IMPL_LINK( BreakPointDialog, ComboBoxHighlightHdl, ComboBox&, rBox, void )
162 m_pNewButton->Disable();
163 m_pOKButton->Enable();
164 m_pDelButton->Enable();
166 sal_Int32 nEntry = rBox.GetEntryPos( rBox.GetText() );
167 BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
168 DBG_ASSERT( pBrk, "No matching break point to list?" );
169 UpdateFields( pBrk );
173 IMPL_LINK( BreakPointDialog, EditModifyHdl, Edit&, rEdit, void )
175 if (&rEdit == m_pComboBox)
176 CheckButtons();
177 else if (&rEdit == m_pNumericField)
179 BreakPoint* pBrk = GetSelectedBreakPoint();
180 if ( pBrk )
181 pBrk->nStopAfter = rEdit.GetText().toInt32();
186 IMPL_LINK( BreakPointDialog, ButtonHdl, Button *, pButton, void )
188 if (pButton == m_pOKButton)
190 m_rOriginalBreakPointList.transfer(m_aModifiedBreakPointList);
191 EndDialog( 1 );
193 else if (pButton == m_pNewButton)
195 // keep checkbox in mind!
196 OUString aText( m_pComboBox->GetText() );
197 size_t nLine;
198 bool bValid = lcl_ParseText( aText, nLine );
199 if ( bValid )
201 BreakPoint* pBrk = new BreakPoint( nLine );
202 pBrk->bEnabled = m_pCheckBox->IsChecked();
203 pBrk->nStopAfter = static_cast<size_t>(m_pNumericField->GetValue());
204 m_aModifiedBreakPointList.InsertSorted( pBrk );
205 OUString aEntryStr( "# " + OUString::number(pBrk->nLine) );
206 m_pComboBox->InsertEntry( aEntryStr );
207 if (SfxDispatcher* pDispatcher = GetDispatcher())
208 pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
210 else
212 m_pComboBox->SetText( aText );
213 m_pComboBox->GrabFocus();
215 CheckButtons();
217 else if (pButton == m_pDelButton)
219 sal_Int32 nEntry = m_pComboBox->GetEntryPos( m_pComboBox->GetText() );
220 BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
221 if ( pBrk )
223 delete m_aModifiedBreakPointList.remove( pBrk );
224 m_pComboBox->RemoveEntryAt(nEntry);
225 if ( nEntry && nEntry >= m_pComboBox->GetEntryCount() )
226 nEntry--;
227 m_pComboBox->SetText( m_pComboBox->GetEntry( nEntry ) );
228 if (SfxDispatcher* pDispatcher = GetDispatcher())
229 pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
231 CheckButtons();
236 void BreakPointDialog::UpdateFields( BreakPoint const * pBrk )
238 if ( pBrk )
240 m_pCheckBox->Check( pBrk->bEnabled );
241 m_pNumericField->SetValue( pBrk->nStopAfter );
246 BreakPoint* BreakPointDialog::GetSelectedBreakPoint()
248 size_t nEntry = m_pComboBox->GetEntryPos( m_pComboBox->GetText() );
249 BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
250 return pBrk;
253 } // namespace basctl
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */