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