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 :
27 : #include <sfx2/dispatch.hxx>
28 :
29 : namespace basctl
30 : {
31 :
32 : // FIXME Why does BreakPointDialog allow only sal_uInt16 for break-point line
33 : // numbers, whereas BreakPoint supports sal_uLong?
34 :
35 : namespace
36 : {
37 :
38 0 : bool lcl_ParseText(OUString const &rText, size_t& rLineNr )
39 : {
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 0 : rText.replaceAll(" ", OUString()));
47 0 : if (aText.isEmpty())
48 0 : return false;
49 0 : sal_Unicode cFirst = aText[0];
50 0 : if (cFirst != '#' && !(cFirst >= '0' && cFirst <= '9'))
51 0 : return false;
52 0 : if (cFirst == '#')
53 0 : aText = aText.copy(1);
54 : // XXX Assumes that sal_uInt16 is contained within sal_Int32:
55 0 : sal_Int32 n = aText.toInt32();
56 0 : if ( n <= 0 )
57 0 : return false;
58 0 : rLineNr = static_cast< size_t >(n);
59 0 : return true;
60 : }
61 :
62 : } // namespace
63 :
64 0 : BreakPointDialog::BreakPointDialog( vcl::Window* pParent, BreakPointList& rBrkPntList )
65 : : ModalDialog(pParent, "ManageBreakpointsDialog",
66 : "modules/BasicIDE/ui/managebreakpoints.ui")
67 : , m_rOriginalBreakPointList(rBrkPntList)
68 0 : , m_aModifiedBreakPointList(rBrkPntList)
69 : {
70 0 : get(m_pComboBox, "entries");
71 0 : m_pComboBox->set_height_request(m_pComboBox->GetTextHeight() * 12);
72 0 : m_pComboBox->set_width_request(m_pComboBox->approximate_char_width() * 32);
73 0 : get(m_pOKButton, "ok");
74 0 : get(m_pNewButton, "new");
75 0 : get(m_pDelButton, "delete");
76 0 : get(m_pCheckBox, "active");
77 0 : get(m_pNumericField, "pass-nospin");
78 :
79 0 : m_pComboBox->SetUpdateMode(false);
80 0 : for ( size_t i = 0, n = m_aModifiedBreakPointList.size(); i < n; ++i )
81 : {
82 0 : BreakPoint* pBrk = m_aModifiedBreakPointList.at( i );
83 0 : OUString aEntryStr( "# " + OUString::number(pBrk->nLine) );
84 0 : m_pComboBox->InsertEntry( aEntryStr, COMBOBOX_APPEND );
85 0 : }
86 0 : m_pComboBox->SetUpdateMode(true);
87 :
88 0 : m_pOKButton->SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
89 0 : m_pNewButton->SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
90 0 : m_pDelButton->SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
91 :
92 0 : m_pCheckBox->SetClickHdl( LINK( this, BreakPointDialog, CheckBoxHdl ) );
93 0 : m_pComboBox->SetSelectHdl( LINK( this, BreakPointDialog, ComboBoxHighlightHdl ) );
94 0 : m_pComboBox->SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
95 0 : m_pComboBox->GrabFocus();
96 :
97 0 : m_pNumericField->SetMin( 0 );
98 0 : m_pNumericField->SetMax( 0x7FFFFFFF );
99 0 : m_pNumericField->SetSpinSize( 1 );
100 0 : m_pNumericField->SetStrictFormat(true);
101 0 : m_pNumericField->SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
102 :
103 0 : m_pComboBox->SetText( m_pComboBox->GetEntry( 0 ) );
104 0 : UpdateFields( m_aModifiedBreakPointList.at( 0 ) );
105 :
106 0 : CheckButtons();
107 0 : }
108 :
109 0 : BreakPointDialog::~BreakPointDialog()
110 : {
111 0 : disposeOnce();
112 0 : }
113 :
114 0 : void BreakPointDialog::dispose()
115 : {
116 0 : m_pComboBox.clear();
117 0 : m_pOKButton.clear();
118 0 : m_pNewButton.clear();
119 0 : m_pDelButton.clear();
120 0 : m_pNumericField.clear();
121 0 : m_pCheckBox.clear();
122 0 : ModalDialog::dispose();
123 0 : }
124 :
125 0 : void BreakPointDialog::SetCurrentBreakPoint( BreakPoint* pBrk )
126 : {
127 0 : OUString aStr( "# " + OUString::number(pBrk->nLine) );
128 0 : m_pComboBox->SetText( aStr );
129 0 : UpdateFields( pBrk );
130 0 : }
131 :
132 0 : void BreakPointDialog::CheckButtons()
133 : {
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 0 : if (lcl_ParseText(m_pComboBox->GetText(), nLine)
139 0 : && m_aModifiedBreakPointList.FindBreakPoint(nLine) == 0)
140 : {
141 0 : m_pNewButton->Enable();
142 0 : m_pOKButton->Disable();
143 0 : m_pDelButton->Disable();
144 : }
145 : else
146 : {
147 0 : m_pNewButton->Disable();
148 0 : m_pOKButton->Enable();
149 0 : m_pDelButton->Enable();
150 : }
151 0 : }
152 :
153 0 : IMPL_LINK( BreakPointDialog, CheckBoxHdl, ::CheckBox *, pChkBx )
154 : {
155 0 : BreakPoint* pBrk = GetSelectedBreakPoint();
156 0 : if ( pBrk )
157 0 : pBrk->bEnabled = pChkBx->IsChecked();
158 :
159 0 : return 0;
160 : }
161 :
162 0 : IMPL_LINK( BreakPointDialog, ComboBoxHighlightHdl, ComboBox *, pBox )
163 : {
164 0 : m_pNewButton->Disable();
165 0 : m_pOKButton->Enable();
166 0 : m_pDelButton->Enable();
167 :
168 0 : sal_Int32 nEntry = pBox->GetEntryPos( pBox->GetText() );
169 0 : BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
170 : DBG_ASSERT( pBrk, "Kein passender Breakpoint zur Liste ?" );
171 0 : UpdateFields( pBrk );
172 :
173 0 : return 0;
174 : }
175 :
176 :
177 :
178 0 : IMPL_LINK( BreakPointDialog, EditModifyHdl, Edit *, pEdit )
179 : {
180 0 : if (pEdit == m_pComboBox)
181 0 : CheckButtons();
182 0 : else if (pEdit == m_pNumericField)
183 : {
184 0 : BreakPoint* pBrk = GetSelectedBreakPoint();
185 0 : if ( pBrk )
186 0 : pBrk->nStopAfter = pEdit->GetText().toInt32();
187 : }
188 0 : return 0;
189 : }
190 :
191 :
192 :
193 0 : IMPL_LINK( BreakPointDialog, ButtonHdl, Button *, pButton )
194 : {
195 0 : if (pButton == m_pOKButton)
196 : {
197 0 : m_rOriginalBreakPointList.transfer(m_aModifiedBreakPointList);
198 0 : EndDialog( 1 );
199 : }
200 0 : else if (pButton == m_pNewButton)
201 : {
202 : // keep checkbox in mind!
203 0 : OUString aText( m_pComboBox->GetText() );
204 : size_t nLine;
205 0 : bool bValid = lcl_ParseText( aText, nLine );
206 0 : if ( bValid )
207 : {
208 0 : BreakPoint* pBrk = new BreakPoint( nLine );
209 0 : pBrk->bEnabled = m_pCheckBox->IsChecked();
210 0 : pBrk->nStopAfter = (size_t) m_pNumericField->GetValue();
211 0 : m_aModifiedBreakPointList.InsertSorted( pBrk );
212 0 : OUString aEntryStr( "# " + OUString::number(pBrk->nLine) );
213 0 : m_pComboBox->InsertEntry( aEntryStr, COMBOBOX_APPEND );
214 0 : if (SfxDispatcher* pDispatcher = GetDispatcher())
215 0 : pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
216 : }
217 : else
218 : {
219 0 : m_pComboBox->SetText( aText );
220 0 : m_pComboBox->GrabFocus();
221 : }
222 0 : CheckButtons();
223 : }
224 0 : else if (pButton == m_pDelButton)
225 : {
226 0 : sal_Int32 nEntry = m_pComboBox->GetEntryPos( m_pComboBox->GetText() );
227 0 : BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
228 0 : if ( pBrk )
229 : {
230 0 : delete m_aModifiedBreakPointList.remove( pBrk );
231 0 : m_pComboBox->RemoveEntryAt(nEntry);
232 0 : if ( nEntry && !( nEntry < m_pComboBox->GetEntryCount() ) )
233 0 : nEntry--;
234 0 : m_pComboBox->SetText( m_pComboBox->GetEntry( nEntry ) );
235 0 : if (SfxDispatcher* pDispatcher = GetDispatcher())
236 0 : pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
237 : }
238 0 : CheckButtons();
239 : }
240 :
241 0 : return 0;
242 : }
243 :
244 :
245 :
246 0 : void BreakPointDialog::UpdateFields( BreakPoint* pBrk )
247 : {
248 0 : if ( pBrk )
249 : {
250 0 : m_pCheckBox->Check( pBrk->bEnabled );
251 0 : m_pNumericField->SetValue( pBrk->nStopAfter );
252 : }
253 0 : }
254 :
255 :
256 :
257 0 : BreakPoint* BreakPointDialog::GetSelectedBreakPoint()
258 : {
259 0 : size_t nEntry = m_pComboBox->GetEntryPos( m_pComboBox->GetText() );
260 0 : BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
261 0 : return pBrk;
262 : }
263 :
264 0 : } // namespace basctl
265 :
266 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|