bump product version to 5.0.4.1
[LibreOffice.git] / basctl / source / basicide / brkdlg.cxx
blobeff2c10a4379b36a19aaa48f5a01954a20427335
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 .
21 #define _SVX_NOIDERESIDS
22 #include "breakpoint.hxx"
23 #include "brkdlg.hxx"
24 #include "basidesh.hxx"
25 #include "basidesh.hrc"
27 #include <sfx2/dispatch.hxx>
29 namespace basctl
32 // FIXME Why does BreakPointDialog allow only sal_uInt16 for break-point line
33 // numbers, whereas BreakPoint supports sal_uLong?
35 namespace
38 bool lcl_ParseText(OUString const &rText, size_t& rLineNr )
40 // aText should look like "# n" where
41 // n > 0 && n < std::numeric_limits< sal_uInt16 >::max().
42 // All spaces are ignored, so there can even be spaces within the
43 // number n. (Maybe it would be better to ignore all whitespace instead
44 // of just spaces.)
45 OUString aText(
46 rText.replaceAll(" ", OUString()));
47 if (aText.isEmpty())
48 return false;
49 sal_Unicode cFirst = aText[0];
50 if (cFirst != '#' && !(cFirst >= '0' && cFirst <= '9'))
51 return false;
52 if (cFirst == '#')
53 aText = aText.copy(1);
54 // XXX Assumes that sal_uInt16 is contained within sal_Int32:
55 sal_Int32 n = aText.toInt32();
56 if ( n <= 0 )
57 return false;
58 rLineNr = static_cast< size_t >(n);
59 return true;
62 } // namespace
64 BreakPointDialog::BreakPointDialog( vcl::Window* pParent, BreakPointList& rBrkPntList )
65 : ModalDialog(pParent, "ManageBreakpointsDialog",
66 "modules/BasicIDE/ui/managebreakpoints.ui")
67 , m_rOriginalBreakPointList(rBrkPntList)
68 , m_aModifiedBreakPointList(rBrkPntList)
70 get(m_pComboBox, "entries");
71 m_pComboBox->set_height_request(m_pComboBox->GetTextHeight() * 12);
72 m_pComboBox->set_width_request(m_pComboBox->approximate_char_width() * 32);
73 get(m_pOKButton, "ok");
74 get(m_pNewButton, "new");
75 get(m_pDelButton, "delete");
76 get(m_pCheckBox, "active");
77 get(m_pNumericField, "pass-nospin");
79 m_pComboBox->SetUpdateMode(false);
80 for ( size_t i = 0, n = m_aModifiedBreakPointList.size(); i < n; ++i )
82 BreakPoint* pBrk = m_aModifiedBreakPointList.at( i );
83 OUString aEntryStr( "# " + OUString::number(pBrk->nLine) );
84 m_pComboBox->InsertEntry( aEntryStr, COMBOBOX_APPEND );
86 m_pComboBox->SetUpdateMode(true);
88 m_pOKButton->SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
89 m_pNewButton->SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
90 m_pDelButton->SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
92 m_pCheckBox->SetClickHdl( LINK( this, BreakPointDialog, CheckBoxHdl ) );
93 m_pComboBox->SetSelectHdl( LINK( this, BreakPointDialog, ComboBoxHighlightHdl ) );
94 m_pComboBox->SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
95 m_pComboBox->GrabFocus();
97 m_pNumericField->SetMin( 0 );
98 m_pNumericField->SetMax( 0x7FFFFFFF );
99 m_pNumericField->SetSpinSize( 1 );
100 m_pNumericField->SetStrictFormat(true);
101 m_pNumericField->SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
103 m_pComboBox->SetText( m_pComboBox->GetEntry( 0 ) );
104 UpdateFields( m_aModifiedBreakPointList.at( 0 ) );
106 CheckButtons();
109 BreakPointDialog::~BreakPointDialog()
111 disposeOnce();
114 void BreakPointDialog::dispose()
116 m_pComboBox.clear();
117 m_pOKButton.clear();
118 m_pNewButton.clear();
119 m_pDelButton.clear();
120 m_pNumericField.clear();
121 m_pCheckBox.clear();
122 ModalDialog::dispose();
125 void BreakPointDialog::SetCurrentBreakPoint( BreakPoint* pBrk )
127 OUString aStr( "# " + OUString::number(pBrk->nLine) );
128 m_pComboBox->SetText( aStr );
129 UpdateFields( pBrk );
132 void BreakPointDialog::CheckButtons()
134 // "New" button is enabled if the combo box edit contains a valid line
135 // number that is not already present in the combo box list; otherwise
136 // "OK" and "Delete" buttons are enabled:
137 size_t nLine;
138 if (lcl_ParseText(m_pComboBox->GetText(), nLine)
139 && m_aModifiedBreakPointList.FindBreakPoint(nLine) == 0)
141 m_pNewButton->Enable();
142 m_pOKButton->Disable();
143 m_pDelButton->Disable();
145 else
147 m_pNewButton->Disable();
148 m_pOKButton->Enable();
149 m_pDelButton->Enable();
153 IMPL_LINK( BreakPointDialog, CheckBoxHdl, ::CheckBox *, pChkBx )
155 BreakPoint* pBrk = GetSelectedBreakPoint();
156 if ( pBrk )
157 pBrk->bEnabled = pChkBx->IsChecked();
159 return 0;
162 IMPL_LINK( BreakPointDialog, ComboBoxHighlightHdl, ComboBox *, pBox )
164 m_pNewButton->Disable();
165 m_pOKButton->Enable();
166 m_pDelButton->Enable();
168 sal_Int32 nEntry = pBox->GetEntryPos( pBox->GetText() );
169 BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
170 DBG_ASSERT( pBrk, "Kein passender Breakpoint zur Liste ?" );
171 UpdateFields( pBrk );
173 return 0;
178 IMPL_LINK( BreakPointDialog, EditModifyHdl, Edit *, pEdit )
180 if (pEdit == m_pComboBox)
181 CheckButtons();
182 else if (pEdit == m_pNumericField)
184 BreakPoint* pBrk = GetSelectedBreakPoint();
185 if ( pBrk )
186 pBrk->nStopAfter = pEdit->GetText().toInt32();
188 return 0;
193 IMPL_LINK( BreakPointDialog, ButtonHdl, Button *, pButton )
195 if (pButton == m_pOKButton)
197 m_rOriginalBreakPointList.transfer(m_aModifiedBreakPointList);
198 EndDialog( 1 );
200 else if (pButton == m_pNewButton)
202 // keep checkbox in mind!
203 OUString aText( m_pComboBox->GetText() );
204 size_t nLine;
205 bool bValid = lcl_ParseText( aText, nLine );
206 if ( bValid )
208 BreakPoint* pBrk = new BreakPoint( nLine );
209 pBrk->bEnabled = m_pCheckBox->IsChecked();
210 pBrk->nStopAfter = (size_t) m_pNumericField->GetValue();
211 m_aModifiedBreakPointList.InsertSorted( pBrk );
212 OUString aEntryStr( "# " + OUString::number(pBrk->nLine) );
213 m_pComboBox->InsertEntry( aEntryStr, COMBOBOX_APPEND );
214 if (SfxDispatcher* pDispatcher = GetDispatcher())
215 pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
217 else
219 m_pComboBox->SetText( aText );
220 m_pComboBox->GrabFocus();
222 CheckButtons();
224 else if (pButton == m_pDelButton)
226 sal_Int32 nEntry = m_pComboBox->GetEntryPos( m_pComboBox->GetText() );
227 BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
228 if ( pBrk )
230 delete m_aModifiedBreakPointList.remove( pBrk );
231 m_pComboBox->RemoveEntryAt(nEntry);
232 if ( nEntry && !( nEntry < m_pComboBox->GetEntryCount() ) )
233 nEntry--;
234 m_pComboBox->SetText( m_pComboBox->GetEntry( nEntry ) );
235 if (SfxDispatcher* pDispatcher = GetDispatcher())
236 pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
238 CheckButtons();
241 return 0;
246 void BreakPointDialog::UpdateFields( BreakPoint* pBrk )
248 if ( pBrk )
250 m_pCheckBox->Check( pBrk->bEnabled );
251 m_pNumericField->SetValue( pBrk->nStopAfter );
257 BreakPoint* BreakPointDialog::GetSelectedBreakPoint()
259 size_t nEntry = m_pComboBox->GetEntryPos( m_pComboBox->GetText() );
260 BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
261 return pBrk;
264 } // namespace basctl
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */