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 "brkdlg.hrc"
25 : #include "basidesh.hxx"
26 : #include "basidesh.hrc"
27 : #include "iderdll.hxx"
28 :
29 : #include <sfx2/dispatch.hxx>
30 : #include <sfx2/viewfrm.hxx>
31 :
32 : namespace basctl
33 : {
34 :
35 : // FIXME Why does BreakPointDialog allow only sal_uInt16 for break-point line
36 : // numbers, whereas BreakPoint supports sal_uLong?
37 :
38 : namespace
39 : {
40 :
41 0 : bool lcl_ParseText(OUString const &rText, size_t& rLineNr )
42 : {
43 : // aText should look like "# n" where
44 : // n > 0 && n < std::numeric_limits< sal_uInt16 >::max().
45 : // All spaces are ignored, so there can even be spaces within the
46 : // number n. (Maybe it would be better to ignore all whitespace instead
47 : // of just spaces.)
48 : OUString aText(
49 0 : rText.replaceAll(" ", OUString()));
50 0 : sal_Unicode cFirst = aText[0];
51 0 : if (cFirst != '#' && !(cFirst >= '0' && cFirst <= '9'))
52 0 : return false;
53 0 : if (cFirst == '#')
54 0 : aText = aText.copy(1);
55 : // XXX Assumes that sal_uInt16 is contained within sal_Int32:
56 0 : sal_Int32 n = aText.toInt32();
57 0 : if ( n <= 0 )
58 0 : return false;
59 0 : rLineNr = static_cast< size_t >(n);
60 0 : return true;
61 : }
62 :
63 : } // namespace
64 :
65 0 : BreakPointDialog::BreakPointDialog( Window* pParent, BreakPointList& rBrkPntList ) :
66 : ModalDialog( pParent, IDEResId( RID_BASICIDE_BREAKPOINTDLG ) ),
67 : aComboBox( this, IDEResId( RID_CB_BRKPOINTS ) ),
68 : aOKButton( this, IDEResId( RID_PB_OK ) ),
69 : aCancelButton( this, IDEResId( RID_PB_CANCEL ) ),
70 : aNewButton( this, IDEResId( RID_PB_NEW ) ),
71 : aDelButton( this, IDEResId( RID_PB_DEL ) ),
72 : aCheckBox( this, IDEResId( RID_CHKB_ACTIVE ) ),
73 : aBrkText( this, IDEResId( RID_FT_BRKPOINTS ) ),
74 : aPassText( this, IDEResId( RID_FT_PASS ) ),
75 : aNumericField( this, IDEResId( RID_FLD_PASS ) ),
76 : m_rOriginalBreakPointList(rBrkPntList),
77 0 : m_aModifiedBreakPointList(rBrkPntList)
78 : {
79 0 : FreeResource();
80 :
81 0 : aComboBox.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( "# " );
86 0 : aEntryStr += String::CreateFromInt32( pBrk->nLine );
87 0 : aComboBox.InsertEntry( aEntryStr, COMBOBOX_APPEND );
88 0 : }
89 0 : aComboBox.SetUpdateMode(true);
90 :
91 0 : aOKButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
92 0 : aNewButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
93 0 : aDelButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
94 :
95 0 : aCheckBox.SetClickHdl( LINK( this, BreakPointDialog, CheckBoxHdl ) );
96 0 : aComboBox.SetSelectHdl( LINK( this, BreakPointDialog, ComboBoxHighlightHdl ) );
97 0 : aComboBox.SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
98 0 : aComboBox.GrabFocus();
99 :
100 0 : aNumericField.SetMin( 0 );
101 0 : aNumericField.SetMax( 0x7FFFFFFF );
102 0 : aNumericField.SetSpinSize( 1 );
103 0 : aNumericField.SetStrictFormat(true);
104 0 : aNumericField.SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
105 :
106 0 : aComboBox.SetText( aComboBox.GetEntry( 0 ) );
107 0 : UpdateFields( m_aModifiedBreakPointList.at( 0 ) );
108 :
109 0 : CheckButtons();
110 0 : }
111 :
112 0 : void BreakPointDialog::SetCurrentBreakPoint( BreakPoint* pBrk )
113 : {
114 0 : String aStr( "# " );
115 0 : aStr += String::CreateFromInt32( pBrk->nLine );
116 0 : aComboBox.SetText( aStr );
117 0 : UpdateFields( pBrk );
118 0 : }
119 :
120 0 : void BreakPointDialog::CheckButtons()
121 : {
122 : // "New" button is enabled if the combo box edit contains a valid line
123 : // number that is not already present in the combo box list; otherwise
124 : // "OK" and "Delete" buttons are enabled:
125 : size_t nLine;
126 0 : if (lcl_ParseText(aComboBox.GetText(), nLine)
127 0 : && m_aModifiedBreakPointList.FindBreakPoint(nLine) == 0)
128 : {
129 0 : aNewButton.Enable();
130 0 : aOKButton.Disable();
131 0 : aDelButton.Disable();
132 : }
133 : else
134 : {
135 0 : aNewButton.Disable();
136 0 : aOKButton.Enable();
137 0 : aDelButton.Enable();
138 : }
139 0 : }
140 :
141 0 : IMPL_LINK_INLINE_START( BreakPointDialog, CheckBoxHdl, ::CheckBox *, pChkBx )
142 : {
143 0 : BreakPoint* pBrk = GetSelectedBreakPoint();
144 0 : if ( pBrk )
145 0 : pBrk->bEnabled = pChkBx->IsChecked();
146 :
147 0 : return 0;
148 : }
149 0 : IMPL_LINK_INLINE_END( BreakPointDialog, CheckBoxHdl, ::CheckBox *, pChkBx )
150 :
151 :
152 :
153 0 : IMPL_LINK( BreakPointDialog, ComboBoxHighlightHdl, ComboBox *, pBox )
154 : {
155 0 : aNewButton.Disable();
156 0 : aOKButton.Enable();
157 0 : aDelButton.Enable();
158 :
159 0 : sal_uInt16 nEntry = pBox->GetEntryPos( pBox->GetText() );
160 0 : BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
161 : DBG_ASSERT( pBrk, "Kein passender Breakpoint zur Liste ?" );
162 0 : UpdateFields( pBrk );
163 :
164 0 : return 0;
165 : }
166 :
167 :
168 :
169 0 : IMPL_LINK( BreakPointDialog, EditModifyHdl, Edit *, pEdit )
170 : {
171 0 : if ( pEdit == &aComboBox )
172 0 : CheckButtons();
173 0 : else if ( pEdit == &aNumericField )
174 : {
175 0 : BreakPoint* pBrk = GetSelectedBreakPoint();
176 0 : if ( pBrk )
177 0 : pBrk->nStopAfter = pEdit->GetText().ToInt32();
178 : }
179 0 : return 0;
180 : }
181 :
182 :
183 :
184 0 : IMPL_LINK( BreakPointDialog, ButtonHdl, Button *, pButton )
185 : {
186 0 : if ( pButton == &aOKButton )
187 : {
188 0 : m_rOriginalBreakPointList.transfer(m_aModifiedBreakPointList);
189 0 : EndDialog( 1 );
190 : }
191 0 : else if ( pButton == &aNewButton )
192 : {
193 : // keep checkbox in mind!
194 0 : String aText( aComboBox.GetText() );
195 : size_t nLine;
196 0 : bool bValid = lcl_ParseText( aText, nLine );
197 0 : if ( bValid )
198 : {
199 0 : BreakPoint* pBrk = new BreakPoint( nLine );
200 0 : pBrk->bEnabled = aCheckBox.IsChecked();
201 0 : pBrk->nStopAfter = (size_t) aNumericField.GetValue();
202 0 : m_aModifiedBreakPointList.InsertSorted( pBrk );
203 0 : OUString aEntryStr( "# " );
204 0 : aEntryStr += String::CreateFromInt32( pBrk->nLine );
205 0 : aComboBox.InsertEntry( aEntryStr, COMBOBOX_APPEND );
206 0 : if (SfxDispatcher* pDispatcher = GetDispatcher())
207 0 : pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
208 : }
209 : else
210 : {
211 0 : aComboBox.SetText( aText );
212 0 : aComboBox.GrabFocus();
213 : }
214 0 : CheckButtons();
215 : }
216 0 : else if ( pButton == &aDelButton )
217 : {
218 0 : size_t nEntry = aComboBox.GetEntryPos( aComboBox.GetText() );
219 0 : BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
220 0 : if ( pBrk )
221 : {
222 0 : delete m_aModifiedBreakPointList.remove( pBrk );
223 0 : aComboBox.RemoveEntry( nEntry );
224 0 : if ( nEntry && !( nEntry < aComboBox.GetEntryCount() ) )
225 0 : nEntry--;
226 0 : aComboBox.SetText( aComboBox.GetEntry( nEntry ) );
227 0 : if (SfxDispatcher* pDispatcher = GetDispatcher())
228 0 : pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
229 : }
230 0 : CheckButtons();
231 : }
232 :
233 0 : return 0;
234 : }
235 :
236 :
237 :
238 0 : void BreakPointDialog::UpdateFields( BreakPoint* pBrk )
239 : {
240 0 : if ( pBrk )
241 : {
242 0 : aCheckBox.Check( pBrk->bEnabled );
243 0 : aNumericField.SetValue( pBrk->nStopAfter );
244 : }
245 0 : }
246 :
247 :
248 :
249 0 : BreakPoint* BreakPointDialog::GetSelectedBreakPoint()
250 : {
251 0 : size_t nEntry = aComboBox.GetEntryPos( aComboBox.GetText() );
252 0 : BreakPoint* pBrk = m_aModifiedBreakPointList.at( nEntry );
253 0 : return pBrk;
254 : }
255 :
256 : } // namespace basctl
257 :
258 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|