xref: /aoo4110/main/basctl/source/basicide/brkdlg.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_basctl.hxx"
26 
27 #include <limits>
28 
29 #include <vcl/sound.hxx>
30 
31 // #define ITEMID_SEARCH SID_SEARCH_ITEM
32 #define _SVX_NOIDERESIDS
33 #include <brkdlg.hxx>
34 #include <brkdlg.hrc>
35 #include <basidesh.hxx>
36 #include <basidesh.hrc>
37 #include <iderdll.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <sfx2/viewfrm.hxx>
40 
41 // FIXME  Why does BreakPointDialog allow only sal_uInt16 for break-point line
42 // numbers, whereas BreakPoint supports sal_uLong?
43 
lcl_ParseText(String aText,sal_uInt16 & rLineNr)44 bool lcl_ParseText( String aText, sal_uInt16& rLineNr )
45 {
46     // aText should look like "# n" where
47     // n > 0 && n < std::numeric_limits< sal_uInt16 >::max().
48     // All spaces are ignored, so there can even be spaces within the
49     // number n.  (Maybe it would be better to ignore all whitespace instead
50     // of just spaces.)
51     aText.EraseAllChars(' ');
52     sal_Unicode cFirst = aText.GetChar(0);
53     if (cFirst != '#' && !(cFirst >= '0' && cFirst <= '9'))
54         return false;
55     if (cFirst == '#')
56         aText.Erase(0, 1);
57     // XXX Assumes that sal_uInt16 is contained within sal_Int32:
58     sal_Int32 n = aText.ToInt32();
59     if (n <= 0 || n > std::numeric_limits< sal_uInt16 >::max())
60         return false;
61     rLineNr = static_cast< sal_uInt16 >(n);
62     return true;
63 }
64 
BreakPointDialog(Window * pParent,BreakPointList & rBrkPntList)65 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         m_aModifiedBreakPointList(rBrkPntList)
78 {
79 	FreeResource();
80 
81 	aComboBox.SetUpdateMode( sal_False );
82 	BreakPoint* pBrk = m_aModifiedBreakPointList.First();
83 	BreakPoint* pFirstBrk = pBrk;
84 	while ( pBrk )
85 	{
86 		String aEntryStr( RTL_CONSTASCII_USTRINGPARAM( "# " ) );
87 		aEntryStr += String::CreateFromInt32( pBrk->nLine );
88 		aComboBox.InsertEntry( aEntryStr, COMBOBOX_APPEND );
89 		pBrk = m_aModifiedBreakPointList.Next();
90 	}
91 	aComboBox.SetUpdateMode( sal_True );
92 
93 	aOKButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
94 	aNewButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
95 	aDelButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
96 //	aShowButton.SetClickHdl( LINK( this, BreakPointDialog, ButtonHdl ) );
97 
98 	aCheckBox.SetClickHdl( LINK( this, BreakPointDialog, CheckBoxHdl ) );
99 	aComboBox.SetSelectHdl( LINK( this, BreakPointDialog, ComboBoxHighlightHdl ) );
100 	aComboBox.SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
101 	aComboBox.GrabFocus();
102 
103 	aNumericField.SetMin( 0 );
104 	aNumericField.SetMax( 0x7FFFFFFF );
105 	aNumericField.SetSpinSize( 1 );
106 	aNumericField.SetStrictFormat( sal_True );
107 	aNumericField.SetModifyHdl( LINK( this, BreakPointDialog, EditModifyHdl ) );
108 
109 	aComboBox.SetText( aComboBox.GetEntry( 0 ) );
110 	UpdateFields( pFirstBrk );
111 
112 	CheckButtons();
113 }
114 
SetCurrentBreakPoint(BreakPoint * pBrk)115 void BreakPointDialog::SetCurrentBreakPoint( BreakPoint* pBrk )
116 {
117 	String aStr( RTL_CONSTASCII_USTRINGPARAM( "# " ) );
118 	aStr += String::CreateFromInt32( pBrk->nLine );
119     aComboBox.SetText( aStr );
120     UpdateFields( pBrk );
121 }
122 
CheckButtons()123 void BreakPointDialog::CheckButtons()
124 {
125     // "New" button is enabled if the combo box edit contains a valid line
126     // number that is not already present in the combo box list; otherwise
127     // "OK" and "Delete" buttons are enabled:
128     sal_uInt16 nLine;
129     if (lcl_ParseText(aComboBox.GetText(), nLine)
130         && m_aModifiedBreakPointList.FindBreakPoint(nLine) == 0)
131     {
132         aNewButton.Enable();
133         aOKButton.Disable();
134         aDelButton.Disable();
135     }
136     else
137     {
138         aNewButton.Disable();
139         aOKButton.Enable();
140         aDelButton.Enable();
141     }
142 }
143 
IMPL_LINK_INLINE_START(BreakPointDialog,CheckBoxHdl,CheckBox *,pChkBx)144 IMPL_LINK_INLINE_START( BreakPointDialog, CheckBoxHdl, CheckBox *, pChkBx )
145 {
146 	BreakPoint* pBrk = GetSelectedBreakPoint();
147 	if ( pBrk )
148 		pBrk->bEnabled = pChkBx->IsChecked();
149 
150 	return 0;
151 }
IMPL_LINK_INLINE_END(BreakPointDialog,CheckBoxHdl,CheckBox *,pChkBx)152 IMPL_LINK_INLINE_END( BreakPointDialog, CheckBoxHdl, CheckBox *, pChkBx )
153 
154 
155 
156 IMPL_LINK( BreakPointDialog, ComboBoxHighlightHdl, ComboBox *, pBox )
157 {
158 	aNewButton.Disable();
159 	aOKButton.Enable();
160 	aDelButton.Enable();
161 
162 	sal_uInt16 nEntry = pBox->GetEntryPos( pBox->GetText() );
163 	BreakPoint* pBrk = m_aModifiedBreakPointList.GetObject( nEntry );
164 	DBG_ASSERT( pBrk, "Kein passender Breakpoint zur Liste ?" );
165 	UpdateFields( pBrk );
166 
167 	return 0;
168 }
169 
170 
171 
IMPL_LINK(BreakPointDialog,EditModifyHdl,Edit *,pEdit)172 IMPL_LINK( BreakPointDialog, EditModifyHdl, Edit *, pEdit )
173 {
174 	if ( pEdit == &aComboBox )
175 		CheckButtons();
176 	else if ( pEdit == &aNumericField )
177 	{
178 		BreakPoint* pBrk = GetSelectedBreakPoint();
179 		if ( pBrk )
180 			pBrk->nStopAfter = pEdit->GetText().ToInt32();
181 	}
182 	return 0;
183 }
184 
185 
186 
IMPL_LINK(BreakPointDialog,ButtonHdl,Button *,pButton)187 IMPL_LINK( BreakPointDialog, ButtonHdl, Button *, pButton )
188 {
189 	if ( pButton == &aOKButton )
190     {
191         m_rOriginalBreakPointList.transfer(m_aModifiedBreakPointList);
192 		EndDialog( 1 );
193     }
194 	else if ( pButton == &aNewButton )
195 	{
196 		// Checkbox beruecksichtigen!
197 		String aText( aComboBox.GetText() );
198 		sal_uInt16 nLine;
199 		sal_Bool bValid = lcl_ParseText( aText, nLine );
200 		if ( bValid )
201 		{
202 			BreakPoint* pBrk = new BreakPoint( nLine );
203 			pBrk->bEnabled = aCheckBox.IsChecked();
204 			pBrk->nStopAfter = (sal_uLong) aNumericField.GetValue();
205 			m_aModifiedBreakPointList.InsertSorted( pBrk );
206 			String aEntryStr( RTL_CONSTASCII_USTRINGPARAM( "# " ) );
207 			aEntryStr += String::CreateFromInt32( pBrk->nLine );
208 			aComboBox.InsertEntry( aEntryStr, COMBOBOX_APPEND );
209             BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
210             SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
211 	        SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
212 			if( pDispatcher )
213 			{
214 				pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
215 			}
216 		}
217 		else
218 		{
219 			aComboBox.SetText( aText );
220 			aComboBox.GrabFocus();
221 			Sound::Beep();
222 		}
223 		CheckButtons();
224 	}
225 	else if ( pButton == &aDelButton )
226 	{
227 		sal_uInt16 nEntry = aComboBox.GetEntryPos( aComboBox.GetText() );
228 		BreakPoint* pBrk = m_aModifiedBreakPointList.GetObject( nEntry );
229 		if ( pBrk )
230 		{
231 			delete m_aModifiedBreakPointList.Remove( pBrk );
232 			aComboBox.RemoveEntry( nEntry );
233 			if ( nEntry && !( nEntry < aComboBox.GetEntryCount() ) )
234 				nEntry--;
235 			aComboBox.SetText( aComboBox.GetEntry( nEntry ) );
236             BasicIDEShell* pIDEShell = IDE_DLL()->GetShell();
237             SfxViewFrame* pViewFrame = pIDEShell ? pIDEShell->GetViewFrame() : NULL;
238 	        SfxDispatcher* pDispatcher = pViewFrame ? pViewFrame->GetDispatcher() : NULL;
239 
240             if( pDispatcher )
241 			{
242 				pDispatcher->Execute( SID_BASICIDE_BRKPNTSCHANGED );
243 			}
244 		}
245 		CheckButtons();
246 	}
247 //	else if ( pButton == &aShowButton )
248 //	{
249 //		;
250 //	}
251 
252 	return 0;
253 }
254 
255 
256 
UpdateFields(BreakPoint * pBrk)257 void BreakPointDialog::UpdateFields( BreakPoint* pBrk )
258 {
259 	if ( pBrk )
260 	{
261 		aCheckBox.Check( pBrk->bEnabled );
262 		aNumericField.SetValue( pBrk->nStopAfter );
263 	}
264 }
265 
266 
267 
GetSelectedBreakPoint()268 BreakPoint* BreakPointDialog::GetSelectedBreakPoint()
269 {
270 	sal_uInt16 nEntry = aComboBox.GetEntryPos( aComboBox.GetText() );
271 	BreakPoint* pBrk = m_aModifiedBreakPointList.GetObject( nEntry );
272 	return pBrk;
273 }
274 
275 
276 
277