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