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 : : // CLOOKS:
21 : : #define _SPIN_HXX
22 : :
23 : : #define _SOLAR__PRIVATE 1
24 : : #include <tools/diagnose_ex.h>
25 : : #include <basic/basmgr.hxx>
26 : : #include <basidesh.hrc>
27 : : #include "baside2.hxx"
28 : : #include "baside3.hxx"
29 : : #include <basdoc.hxx>
30 : : #include <basicbox.hxx>
31 : : #include <editeng/sizeitem.hxx>
32 : : #include <objdlg.hxx>
33 : : #include <tbxctl.hxx>
34 : : #include <iderdll2.hxx>
35 : : #include <basidectrlr.hxx>
36 : : #include <localizationmgr.hxx>
37 : : #include <sfx2/app.hxx>
38 : : #include <sfx2/dinfdlg.hxx>
39 : : #include <sfx2/dispatch.hxx>
40 : : #include <sfx2/minfitem.hxx>
41 : : #include <sfx2/objface.hxx>
42 : : #include <svl/aeitem.hxx>
43 : : #include <svl/intitem.hxx>
44 : : #include <svl/srchitem.hxx>
45 : :
46 : : #define BasicIDEShell
47 : : #define SFX_TYPEMAP
48 : : #include <idetemp.hxx>
49 : : #include <basslots.hxx>
50 : : #include <iderdll.hxx>
51 : : #include <svx/pszctrl.hxx>
52 : : #include <svx/insctrl.hxx>
53 : : #include <svx/srchdlg.hxx>
54 : : #include <svx/tbcontrl.hxx>
55 : : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
56 : : #include <com/sun/star/container/XContainer.hpp>
57 : : #include <svx/xmlsecctrl.hxx>
58 : : #include <sfx2/viewfac.hxx>
59 : : #include <vcl/msgbox.hxx>
60 : :
61 : : using namespace ::com::sun::star::uno;
62 : : using namespace ::com::sun::star;
63 : : using ::rtl::OUString;
64 : :
65 : : typedef ::cppu::WeakImplHelper1< container::XContainerListener > ContainerListenerBASE;
66 : :
67 : : class ContainerListenerImpl : public ContainerListenerBASE
68 : : {
69 : : BasicIDEShell* mpShell;
70 : : public:
71 : :
72 : 0 : ContainerListenerImpl (BasicIDEShell* pShell) : mpShell(pShell) { }
73 : :
74 : 0 : ~ContainerListenerImpl()
75 : 0 : {
76 : 0 : }
77 : :
78 : 0 : void addContainerListener( const ScriptDocument& rScriptDocument, const ::rtl::OUString& aLibName )
79 : : {
80 : : try
81 : : {
82 : 0 : uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, false ), uno::UNO_QUERY );
83 : 0 : if ( xContainer.is() )
84 : : {
85 : 0 : uno::Reference< container::XContainerListener > xContainerListener( this );
86 : 0 : xContainer->addContainerListener( xContainerListener );
87 : 0 : }
88 : : }
89 : 0 : catch(const uno::Exception& ) {}
90 : 0 : }
91 : 0 : void removeContainerListener( const ScriptDocument& rScriptDocument, const ::rtl::OUString& aLibName )
92 : : {
93 : : try
94 : : {
95 : 0 : uno::Reference< container::XContainer > xContainer( rScriptDocument.getLibrary( E_SCRIPTS, aLibName, false ), uno::UNO_QUERY );
96 : 0 : if ( xContainer.is() )
97 : : {
98 : 0 : uno::Reference< container::XContainerListener > xContainerListener( this );
99 : 0 : xContainer->removeContainerListener( xContainerListener );
100 : 0 : }
101 : : }
102 : 0 : catch(const uno::Exception& ) {}
103 : 0 : }
104 : :
105 : : // XEventListener
106 : 0 : virtual void SAL_CALL disposing( const lang::EventObject& ) throw( uno::RuntimeException ) {}
107 : :
108 : : // XContainerListener
109 : 0 : virtual void SAL_CALL elementInserted( const container::ContainerEvent& Event ) throw( uno::RuntimeException )
110 : : {
111 : 0 : rtl::OUString sModuleName;
112 : 0 : if( mpShell && ( Event.Accessor >>= sModuleName ) )
113 : 0 : mpShell->FindBasWin( mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, true, false );
114 : 0 : }
115 : 0 : virtual void SAL_CALL elementReplaced( const container::ContainerEvent& ) throw( com::sun::star::uno::RuntimeException ) { }
116 : 0 : virtual void SAL_CALL elementRemoved( const container::ContainerEvent& Event ) throw( com::sun::star::uno::RuntimeException )
117 : : {
118 : 0 : rtl::OUString sModuleName;
119 : 0 : if( mpShell && ( Event.Accessor >>= sModuleName ) )
120 : : {
121 : 0 : basctl::ModulWindow* pWin = mpShell->FindBasWin(mpShell->m_aCurDocument, mpShell->m_aCurLibName, sModuleName, false, true);
122 : 0 : if( pWin )
123 : 0 : mpShell->RemoveWindow( pWin, true, true );
124 : 0 : }
125 : 0 : }
126 : :
127 : : };
128 : :
129 : 0 : TYPEINIT1( BasicIDEShell, SfxViewShell );
130 : :
131 : 0 : SFX_IMPL_NAMED_VIEWFACTORY( BasicIDEShell, "Default" )
132 : : {
133 : 0 : SFX_VIEW_REGISTRATION( BasicDocShell );
134 : 0 : }
135 : :
136 : :
137 : 0 : SFX_IMPL_INTERFACE( BasicIDEShell, SfxViewShell, IDEResId( RID_STR_IDENAME ) )
138 : : {
139 : 0 : SFX_CHILDWINDOW_REGISTRATION( SID_SEARCH_DLG );
140 : 0 : SFX_FEATURED_CHILDWINDOW_REGISTRATION(SID_SHOW_PROPERTYBROWSER, BASICIDE_UI_FEATURE_SHOW_BROWSER);
141 : 0 : SFX_POPUPMENU_REGISTRATION( IDEResId( RID_POPUP_DLGED ) );
142 : 0 : }
143 : :
144 : :
145 : :
146 : : #define IDE_VIEWSHELL_FLAGS SFX_VIEW_CAN_PRINT|SFX_VIEW_NO_NEWWINDOW
147 : :
148 : :
149 : : static sal_Int32 GnBasicIDEShellCount;
150 : 0 : sal_Int32 getBasicIDEShellCount( void )
151 : 0 : { return GnBasicIDEShellCount; }
152 : :
153 : 0 : BasicIDEShell::BasicIDEShell( SfxViewFrame* pFrame_, SfxViewShell* /* pOldShell */ ) :
154 : : SfxViewShell( pFrame_, IDE_VIEWSHELL_FLAGS ),
155 : 0 : m_aCurDocument( ScriptDocument::getApplicationScriptDocument() ),
156 : 0 : aHScrollBar( &GetViewFrame()->GetWindow(), WinBits( WB_HSCROLL | WB_DRAG ) ),
157 : 0 : aVScrollBar( &GetViewFrame()->GetWindow(), WinBits( WB_VSCROLL | WB_DRAG ) ),
158 : 0 : aScrollBarBox( &GetViewFrame()->GetWindow(), WinBits( WB_SIZEABLE ) ),
159 : : pLayout(0),
160 : 0 : aObjectCatalog(&GetViewFrame()->GetWindow()),
161 : : m_bAppBasicModified( false ),
162 : 0 : m_aNotifier( *this )
163 : : {
164 : 0 : m_xLibListener = new ContainerListenerImpl( this );
165 : 0 : Init();
166 : 0 : GnBasicIDEShellCount++;
167 : 0 : }
168 : :
169 : :
170 : :
171 : 0 : void BasicIDEShell::Init()
172 : : {
173 : 0 : TbxControls::RegisterControl( SID_CHOOSE_CONTROLS );
174 : 0 : SvxPosSizeStatusBarControl::RegisterControl();
175 : 0 : SvxInsertStatusBarControl::RegisterControl();
176 : 0 : XmlSecStatusBarControl::RegisterControl( SID_SIGNATURE );
177 : 0 : SvxSimpleUndoRedoController::RegisterControl( SID_UNDO );
178 : 0 : SvxSimpleUndoRedoController::RegisterControl( SID_REDO );
179 : :
180 : 0 : SvxSearchDialogWrapper::RegisterChildWindow(false);
181 : :
182 : 0 : BasicIDEGlobals::GetExtraData()->ShellInCriticalSection() = true;
183 : :
184 : 0 : SetName( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "BasicIDE" ) ) );
185 : 0 : SetHelpId( SVX_INTERFACE_BASIDE_VIEWSH );
186 : :
187 : 0 : LibBoxControl::RegisterControl( SID_BASICIDE_LIBSELECTOR );
188 : 0 : LanguageBoxControl::RegisterControl( SID_BASICIDE_CURRENT_LANG );
189 : :
190 : 0 : GetViewFrame()->GetWindow().SetBackground(
191 : 0 : GetViewFrame()->GetWindow().GetSettings().GetStyleSettings().GetWindowColor()
192 : 0 : );
193 : :
194 : 0 : pCurWin = 0;
195 : 0 : m_aCurDocument = ScriptDocument::getApplicationScriptDocument();
196 : 0 : bCreatingWindow = false;
197 : :
198 : 0 : pTabBar = new BasicIDETabBar( &GetViewFrame()->GetWindow() );
199 : 0 : pTabBar->SetSplitHdl( LINK( this, BasicIDEShell, TabBarSplitHdl ) );
200 : 0 : bTabBarSplitted = false;
201 : :
202 : 0 : nCurKey = 100;
203 : 0 : InitScrollBars();
204 : 0 : InitTabBar();
205 : :
206 : 0 : SetCurLib( ScriptDocument::getApplicationScriptDocument(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Standard")), false, false );
207 : :
208 : 0 : BasicIDEGlobals::ShellCreated(this);
209 : :
210 : 0 : BasicIDEGlobals::GetExtraData()->ShellInCriticalSection() = false;
211 : :
212 : : // It's enough to create the controller ...
213 : : // It will be public by using magic :-)
214 : 0 : new BasicIDEController( this );
215 : :
216 : : // Force updating the title ! Because it must be set to the controller
217 : : // it has to be called directly after creating those controller.
218 : 0 : SetMDITitle ();
219 : :
220 : 0 : UpdateWindows();
221 : 0 : }
222 : :
223 : 0 : BasicIDEShell::~BasicIDEShell()
224 : : {
225 : 0 : m_aNotifier.dispose();
226 : :
227 : 0 : BasicIDEGlobals::ShellDestroyed(this);
228 : :
229 : : // so that on a basic saving error, the shell doesn't pop right up again
230 : 0 : BasicIDEGlobals::GetExtraData()->ShellInCriticalSection() = true;
231 : :
232 : 0 : SetWindow( 0 );
233 : 0 : SetCurWindow( 0 );
234 : :
235 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it )
236 : : {
237 : : // no store; does already happen when the BasicManagers are destroyed
238 : 0 : delete it->second;
239 : : }
240 : :
241 : 0 : aIDEWindowTable.clear();
242 : 0 : delete pTabBar;
243 : :
244 : : // Destroy all ContainerListeners for Basic Container.
245 : 0 : if (ContainerListenerImpl* pListener = static_cast<ContainerListenerImpl*>(m_xLibListener.get()))
246 : 0 : pListener->removeContainerListener(m_aCurDocument, m_aCurLibName);
247 : :
248 : 0 : BasicIDEGlobals::GetExtraData()->ShellInCriticalSection() = false;
249 : :
250 : 0 : GnBasicIDEShellCount--;
251 : 0 : }
252 : :
253 : 0 : void BasicIDEShell::onDocumentCreated( const ScriptDocument& /*_rDocument*/ )
254 : : {
255 : 0 : if (pCurWin)
256 : 0 : pCurWin->OnNewDocument();
257 : 0 : UpdateWindows();
258 : 0 : }
259 : :
260 : 0 : void BasicIDEShell::onDocumentOpened( const ScriptDocument& /*_rDocument*/ )
261 : : {
262 : 0 : if (pCurWin)
263 : 0 : pCurWin->OnNewDocument();
264 : 0 : UpdateWindows();
265 : 0 : }
266 : :
267 : 0 : void BasicIDEShell::onDocumentSave( const ScriptDocument& /*_rDocument*/ )
268 : : {
269 : 0 : StoreAllWindowData();
270 : 0 : }
271 : :
272 : 0 : void BasicIDEShell::onDocumentSaveDone( const ScriptDocument& /*_rDocument*/ )
273 : : {
274 : : // #i115671: Update SID_SAVEDOC after saving is completed
275 : 0 : SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
276 : 0 : if ( pBindings )
277 : 0 : pBindings->Invalidate( SID_SAVEDOC );
278 : 0 : }
279 : :
280 : 0 : void BasicIDEShell::onDocumentSaveAs( const ScriptDocument& /*_rDocument*/ )
281 : : {
282 : 0 : StoreAllWindowData();
283 : 0 : }
284 : :
285 : 0 : void BasicIDEShell::onDocumentSaveAsDone( const ScriptDocument& /*_rDocument*/ )
286 : : {
287 : : // not interested in
288 : 0 : }
289 : :
290 : 0 : void BasicIDEShell::onDocumentClosed( const ScriptDocument& _rDocument )
291 : : {
292 : 0 : if ( !_rDocument.isValid() )
293 : 0 : return;
294 : :
295 : 0 : bool bSetCurWindow = false;
296 : 0 : bool bSetCurLib = ( _rDocument == m_aCurDocument );
297 : 0 : std::vector<IDEBaseWindow*> aDeleteVec;
298 : :
299 : : // remove all windows which belong to this document
300 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it )
301 : : {
302 : 0 : IDEBaseWindow* pWin = it->second;
303 : 0 : if ( pWin->IsDocument( _rDocument ) )
304 : : {
305 : 0 : if ( pWin->GetStatus() & (BASWIN_RUNNINGBASIC|BASWIN_INRESCHEDULE) )
306 : : {
307 : 0 : pWin->AddStatus( BASWIN_TOBEKILLED );
308 : 0 : pWin->Hide();
309 : 0 : StarBASIC::Stop();
310 : : // there's no notify
311 : 0 : pWin->BasicStopped();
312 : : }
313 : : else
314 : 0 : aDeleteVec.push_back( pWin );
315 : : }
316 : : }
317 : : // delete windows outside main loop so we don't invalidate the original iterator
318 : 0 : for( std::vector<IDEBaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
319 : : {
320 : 0 : IDEBaseWindow* pWin = *it;
321 : 0 : pWin->StoreData();
322 : 0 : if ( pWin == pCurWin )
323 : 0 : bSetCurWindow = true;
324 : 0 : RemoveWindow( pWin, true, false );
325 : : }
326 : :
327 : : // remove lib info
328 : 0 : BasicIDEData* pData = BasicIDEGlobals::GetExtraData();
329 : 0 : if ( pData )
330 : 0 : pData->GetLibInfos().RemoveInfoFor( _rDocument );
331 : :
332 : 0 : if ( bSetCurLib )
333 : 0 : SetCurLib( ScriptDocument::getApplicationScriptDocument(), ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Standard")), true, false );
334 : 0 : else if ( bSetCurWindow )
335 : 0 : SetCurWindow( FindApplicationWindow(), true );
336 : : }
337 : :
338 : 0 : void BasicIDEShell::onDocumentTitleChanged( const ScriptDocument& /*_rDocument*/ )
339 : : {
340 : 0 : SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
341 : 0 : if ( pBindings )
342 : 0 : pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR, true, false );
343 : 0 : SetMDITitle();
344 : 0 : }
345 : :
346 : 0 : void BasicIDEShell::onDocumentModeChanged( const ScriptDocument& _rDocument )
347 : : {
348 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it )
349 : : {
350 : 0 : IDEBaseWindow* pWin = it->second;
351 : 0 : if ( pWin->IsDocument( _rDocument ) && _rDocument.isDocument() )
352 : 0 : pWin->SetReadOnly( _rDocument.isReadOnly() );
353 : : }
354 : 0 : }
355 : :
356 : 0 : void BasicIDEShell::StoreAllWindowData( bool bPersistent )
357 : : {
358 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it )
359 : : {
360 : 0 : IDEBaseWindow* pWin = it->second;
361 : : DBG_ASSERT( pWin, "PrepareClose: NULL-Pointer in Table?" );
362 : 0 : if ( !pWin->IsSuspended() )
363 : 0 : pWin->StoreData();
364 : : }
365 : :
366 : 0 : if ( bPersistent )
367 : : {
368 : 0 : SFX_APP()->SaveBasicAndDialogContainer();
369 : 0 : SetAppBasicModified(false);
370 : :
371 : 0 : SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
372 : 0 : if ( pBindings )
373 : : {
374 : 0 : pBindings->Invalidate( SID_SAVEDOC );
375 : 0 : pBindings->Update( SID_SAVEDOC );
376 : : }
377 : : }
378 : 0 : }
379 : :
380 : :
381 : 0 : sal_uInt16 BasicIDEShell::PrepareClose( sal_Bool bUI, sal_Bool bForBrowsing )
382 : : {
383 : : (void)bForBrowsing;
384 : :
385 : : // reset here because it's modified after printing etc. (DocInfo)
386 : 0 : GetViewFrame()->GetObjectShell()->SetModified(false);
387 : :
388 : 0 : if ( StarBASIC::IsRunning() )
389 : : {
390 : 0 : if( bUI )
391 : : {
392 : 0 : Window *pParent = &GetViewFrame()->GetWindow();
393 : 0 : InfoBox( pParent, IDE_RESSTR(RID_STR_CANNOTCLOSE)).Execute();
394 : : }
395 : 0 : return false;
396 : : }
397 : : else
398 : : {
399 : 0 : bool bCanClose = true;
400 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); bCanClose && (it != aIDEWindowTable.end()); ++it)
401 : : {
402 : 0 : IDEBaseWindow* pWin = it->second;
403 : 0 : if ( !pWin->CanClose() )
404 : : {
405 : 0 : if ( !m_aCurLibName.isEmpty() && ( pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName ) )
406 : 0 : SetCurLib( ScriptDocument::getApplicationScriptDocument(), ::rtl::OUString(), false );
407 : 0 : SetCurWindow( pWin, true );
408 : 0 : bCanClose = false;
409 : : }
410 : : }
411 : :
412 : 0 : if ( bCanClose )
413 : 0 : StoreAllWindowData( false ); // don't write on the disk, that will be done later automatically
414 : :
415 : 0 : return bCanClose;
416 : : }
417 : : }
418 : :
419 : 0 : void BasicIDEShell::InitScrollBars()
420 : : {
421 : 0 : aVScrollBar.SetLineSize( 300 );
422 : 0 : aVScrollBar.SetPageSize( 2000 );
423 : 0 : aHScrollBar.SetLineSize( 300 );
424 : 0 : aHScrollBar.SetPageSize( 2000 );
425 : 0 : aHScrollBar.Enable();
426 : 0 : aVScrollBar.Enable();
427 : 0 : aVScrollBar.Show();
428 : 0 : aHScrollBar.Show();
429 : 0 : aScrollBarBox.Show();
430 : 0 : }
431 : :
432 : :
433 : :
434 : 0 : void BasicIDEShell::InitTabBar()
435 : : {
436 : 0 : pTabBar->Enable();
437 : 0 : pTabBar->Show();
438 : 0 : pTabBar->SetSelectHdl( LINK( this, BasicIDEShell, TabBarHdl ) );
439 : 0 : }
440 : :
441 : :
442 : 0 : Size BasicIDEShell::GetOptimalSizePixel() const
443 : : {
444 : 0 : return Size( 400, 300 );
445 : : }
446 : :
447 : :
448 : :
449 : 0 : void BasicIDEShell::OuterResizePixel( const Point &rPos, const Size &rSize )
450 : : {
451 : 0 : AdjustPosSizePixel( rPos, rSize );
452 : 0 : }
453 : :
454 : :
455 : 0 : IMPL_LINK_INLINE_START( BasicIDEShell, TabBarSplitHdl, TabBar *, pTBar )
456 : : {
457 : : (void)pTBar;
458 : 0 : bTabBarSplitted = true;
459 : 0 : ArrangeTabBar();
460 : :
461 : 0 : return 0;
462 : : }
463 : 0 : IMPL_LINK_INLINE_END( BasicIDEShell, TabBarSplitHdl, TabBar *, pTBar )
464 : :
465 : :
466 : :
467 : 0 : IMPL_LINK( BasicIDEShell, TabBarHdl, TabBar *, pCurTabBar )
468 : : {
469 : 0 : sal_uInt16 nCurId = pCurTabBar->GetCurPageId();
470 : 0 : IDEBaseWindow* pWin = aIDEWindowTable[ nCurId ];
471 : : DBG_ASSERT( pWin, "Eintrag in TabBar passt zu keinem Fenster!" );
472 : 0 : SetCurWindow( pWin );
473 : :
474 : 0 : return 0;
475 : : }
476 : :
477 : :
478 : :
479 : 0 : bool BasicIDEShell::NextPage( bool bPrev )
480 : : {
481 : 0 : bool bRet = false;
482 : 0 : sal_uInt16 nPos = pTabBar->GetPagePos( pTabBar->GetCurPageId() );
483 : :
484 : 0 : if ( bPrev )
485 : 0 : --nPos;
486 : : else
487 : 0 : ++nPos;
488 : :
489 : 0 : if ( nPos < pTabBar->GetPageCount() )
490 : : {
491 : 0 : IDEBaseWindow* pWin = aIDEWindowTable[ pTabBar->GetPageId( nPos ) ];
492 : 0 : SetCurWindow( pWin, true );
493 : 0 : bRet = true;
494 : : }
495 : :
496 : 0 : return bRet;
497 : : }
498 : :
499 : :
500 : :
501 : 0 : void BasicIDEShell::ArrangeTabBar()
502 : : {
503 : 0 : long nBoxPos = aScrollBarBox.GetPosPixel().X() - 1;
504 : 0 : long nPos = pTabBar->GetSplitSize();
505 : 0 : if ( nPos <= nBoxPos )
506 : : {
507 : 0 : Point aPnt( pTabBar->GetPosPixel() );
508 : 0 : long nH = aHScrollBar.GetSizePixel().Height();
509 : 0 : pTabBar->SetPosSizePixel( aPnt, Size( nPos, nH ) );
510 : 0 : long nScrlStart = aPnt.X() + nPos;
511 : 0 : aHScrollBar.SetPosSizePixel( Point( nScrlStart, aPnt.Y() ), Size( nBoxPos - nScrlStart + 2, nH ) );
512 : 0 : aHScrollBar.Update();
513 : : }
514 : 0 : }
515 : :
516 : :
517 : :
518 : 0 : ::svl::IUndoManager* BasicIDEShell::GetUndoManager()
519 : : {
520 : 0 : ::svl::IUndoManager* pMgr = NULL;
521 : 0 : if( pCurWin )
522 : 0 : pMgr = pCurWin->GetUndoManager();
523 : :
524 : 0 : return pMgr;
525 : : }
526 : :
527 : :
528 : :
529 : 0 : void BasicIDEShell::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId&,
530 : : const SfxHint& rHint, const TypeId& )
531 : : {
532 : 0 : if ( BasicIDEGlobals::GetShell() )
533 : : {
534 : 0 : if (SfxSimpleHint const* pSimpleHint = dynamic_cast<SfxSimpleHint const*>(&rHint))
535 : : {
536 : 0 : switch (pSimpleHint->GetId())
537 : : {
538 : : case SFX_HINT_DYING:
539 : : {
540 : 0 : EndListening( rBC, true /* log off all */ );
541 : 0 : aObjectCatalog.UpdateEntries();
542 : : }
543 : 0 : break;
544 : : }
545 : :
546 : 0 : if (SbxHint const* pSbxHint = dynamic_cast<SbxHint const*>(&rHint))
547 : : {
548 : 0 : sal_uLong nHintId = pSbxHint->GetId();
549 : 0 : if ( ( nHintId == SBX_HINT_BASICSTART ) ||
550 : : ( nHintId == SBX_HINT_BASICSTOP ) )
551 : : {
552 : 0 : if (SfxBindings* pBindings = BasicIDE::GetBindingsPtr())
553 : : {
554 : 0 : pBindings->Invalidate( SID_BASICRUN );
555 : 0 : pBindings->Update( SID_BASICRUN );
556 : 0 : pBindings->Invalidate( SID_BASICCOMPILE );
557 : 0 : pBindings->Update( SID_BASICCOMPILE );
558 : 0 : pBindings->Invalidate( SID_BASICSTEPOVER );
559 : 0 : pBindings->Update( SID_BASICSTEPOVER );
560 : 0 : pBindings->Invalidate( SID_BASICSTEPINTO );
561 : 0 : pBindings->Update( SID_BASICSTEPINTO );
562 : 0 : pBindings->Invalidate( SID_BASICSTEPOUT );
563 : 0 : pBindings->Update( SID_BASICSTEPOUT );
564 : 0 : pBindings->Invalidate( SID_BASICSTOP );
565 : 0 : pBindings->Update( SID_BASICSTOP );
566 : 0 : pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
567 : 0 : pBindings->Update( SID_BASICIDE_TOGGLEBRKPNT );
568 : 0 : pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
569 : 0 : pBindings->Update( SID_BASICIDE_MANAGEBRKPNTS );
570 : 0 : pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
571 : 0 : pBindings->Update( SID_BASICIDE_MODULEDLG );
572 : 0 : pBindings->Invalidate( SID_BASICLOAD );
573 : 0 : pBindings->Update( SID_BASICLOAD );
574 : : }
575 : :
576 : 0 : if ( nHintId == SBX_HINT_BASICSTOP )
577 : : {
578 : : // not only at error/break or explicit stoppage,
579 : : // if the update is turned off due to a programming bug
580 : 0 : BasicIDE::BasicStopped();
581 : 0 : if (pLayout)
582 : 0 : pLayout->UpdateDebug(true); // clear...
583 : 0 : if( m_pCurLocalizationMgr )
584 : 0 : m_pCurLocalizationMgr->handleBasicStopped();
585 : : }
586 : 0 : else if( m_pCurLocalizationMgr )
587 : : {
588 : 0 : m_pCurLocalizationMgr->handleBasicStarted();
589 : : }
590 : :
591 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it)
592 : : {
593 : 0 : IDEBaseWindow* pWin = it->second;
594 : 0 : if ( nHintId == SBX_HINT_BASICSTART )
595 : 0 : pWin->BasicStarted();
596 : : else
597 : 0 : pWin->BasicStopped();
598 : : }
599 : : }
600 : : }
601 : : }
602 : : }
603 : 0 : }
604 : :
605 : :
606 : :
607 : 0 : void BasicIDEShell::CheckWindows()
608 : : {
609 : 0 : bool bSetCurWindow = false;
610 : 0 : std::vector<IDEBaseWindow*> aDeleteVec;
611 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it)
612 : : {
613 : 0 : IDEBaseWindow* pWin = it->second;
614 : 0 : if ( pWin->GetStatus() & BASWIN_TOBEKILLED )
615 : 0 : aDeleteVec.push_back( pWin );
616 : : }
617 : 0 : for ( std::vector<IDEBaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
618 : : {
619 : 0 : IDEBaseWindow* pWin = *it;
620 : 0 : pWin->StoreData();
621 : 0 : if ( pWin == pCurWin )
622 : 0 : bSetCurWindow = true;
623 : 0 : RemoveWindow( pWin, true, false );
624 : : }
625 : 0 : if ( bSetCurWindow )
626 : 0 : SetCurWindow( FindApplicationWindow(), true );
627 : 0 : }
628 : :
629 : :
630 : :
631 : 0 : void BasicIDEShell::RemoveWindows( const ScriptDocument& rDocument, const ::rtl::OUString& rLibName, bool bDestroy )
632 : : {
633 : 0 : bool bChangeCurWindow = pCurWin ? false : true;
634 : 0 : std::vector<IDEBaseWindow*> aDeleteVec;
635 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it)
636 : : {
637 : 0 : IDEBaseWindow* pWin = it->second;
638 : 0 : if ( pWin->IsDocument( rDocument ) && pWin->GetLibName() == rLibName )
639 : 0 : aDeleteVec.push_back( pWin );
640 : : }
641 : 0 : for ( std::vector<IDEBaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
642 : : {
643 : 0 : IDEBaseWindow* pWin = *it;
644 : 0 : if ( pWin == pCurWin )
645 : 0 : bChangeCurWindow = true;
646 : 0 : pWin->StoreData();
647 : 0 : RemoveWindow( pWin, bDestroy, false );
648 : : }
649 : 0 : if ( bChangeCurWindow )
650 : 0 : SetCurWindow( FindApplicationWindow(), true );
651 : 0 : }
652 : :
653 : :
654 : :
655 : 0 : void BasicIDEShell::UpdateWindows()
656 : : {
657 : : // remove all windows that may not be displayed
658 : 0 : bool bChangeCurWindow = pCurWin ? false : true;
659 : 0 : if ( !m_aCurLibName.isEmpty() )
660 : : {
661 : 0 : std::vector<IDEBaseWindow*> aDeleteVec;
662 : 0 : for (WindowTableIt it = aIDEWindowTable.begin(); it != aIDEWindowTable.end(); ++it)
663 : : {
664 : 0 : IDEBaseWindow* pWin = it->second;
665 : 0 : if ( !pWin->IsDocument( m_aCurDocument ) || pWin->GetLibName() != m_aCurLibName )
666 : : {
667 : 0 : if ( pWin == pCurWin )
668 : 0 : bChangeCurWindow = true;
669 : 0 : pWin->StoreData();
670 : : // The request of RUNNING prevents the crash when in reschedule.
671 : : // Window is frozen at first, later the windows should be changed
672 : : // anyway to be marked as hidden instead of being deleted.
673 : 0 : if ( !(pWin->GetStatus() & ( BASWIN_TOBEKILLED | BASWIN_RUNNINGBASIC | BASWIN_SUSPENDED ) ) )
674 : 0 : aDeleteVec.push_back( pWin );
675 : : }
676 : : }
677 : 0 : for ( std::vector<IDEBaseWindow*>::const_iterator it = aDeleteVec.begin(); it != aDeleteVec.end(); ++it )
678 : : {
679 : 0 : RemoveWindow( *it, false, false );
680 : 0 : }
681 : : }
682 : :
683 : 0 : if ( bCreatingWindow )
684 : 0 : return;
685 : :
686 : 0 : IDEBaseWindow* pNextActiveWindow = 0;
687 : :
688 : : // show all windows that are to be shown
689 : 0 : ScriptDocuments aDocuments( ScriptDocument::getAllScriptDocuments( ScriptDocument::AllWithApplication ) );
690 : 0 : for ( ScriptDocuments::const_iterator doc = aDocuments.begin();
691 : 0 : doc != aDocuments.end();
692 : : ++doc
693 : : )
694 : : {
695 : 0 : StartListening( *doc->getBasicManager(), true /* log on only once */ );
696 : :
697 : : // libraries
698 : 0 : Sequence< ::rtl::OUString > aLibNames( doc->getLibraryNames() );
699 : 0 : sal_Int32 nLibCount = aLibNames.getLength();
700 : 0 : const ::rtl::OUString* pLibNames = aLibNames.getConstArray();
701 : :
702 : 0 : for ( sal_Int32 i = 0 ; i < nLibCount ; i++ )
703 : : {
704 : 0 : ::rtl::OUString aLibName = pLibNames[ i ];
705 : :
706 : 0 : if ( m_aCurLibName.isEmpty() || ( *doc == m_aCurDocument && aLibName == m_aCurLibName ) )
707 : : {
708 : : // check, if library is password protected and not verified
709 : 0 : bool bProtected = false;
710 : 0 : Reference< script::XLibraryContainer > xModLibContainer( doc->getLibraryContainer( E_SCRIPTS ) );
711 : 0 : if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
712 : : {
713 : 0 : Reference< script::XLibraryContainerPassword > xPasswd( xModLibContainer, UNO_QUERY );
714 : 0 : if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( aLibName ) && !xPasswd->isLibraryPasswordVerified( aLibName ) )
715 : : {
716 : 0 : bProtected = true;
717 : 0 : }
718 : : }
719 : :
720 : 0 : if ( !bProtected )
721 : : {
722 : 0 : LibInfoItem* pLibInfoItem = 0;
723 : 0 : BasicIDEData* pData = BasicIDEGlobals::GetExtraData();
724 : 0 : if ( pData )
725 : 0 : pLibInfoItem = pData->GetLibInfos().GetInfo( LibInfoKey( *doc, aLibName ) );
726 : :
727 : : // modules
728 : 0 : if ( xModLibContainer.is() && xModLibContainer->hasByName( aLibName ) )
729 : : {
730 : 0 : StarBASIC* pLib = doc->getBasicManager()->GetLib( aLibName );
731 : 0 : if ( pLib )
732 : 0 : ImplStartListening( pLib );
733 : :
734 : : try
735 : : {
736 : 0 : Sequence< ::rtl::OUString > aModNames( doc->getObjectNames( E_SCRIPTS, aLibName ) );
737 : 0 : sal_Int32 nModCount = aModNames.getLength();
738 : 0 : const ::rtl::OUString* pModNames = aModNames.getConstArray();
739 : :
740 : 0 : for ( sal_Int32 j = 0 ; j < nModCount ; j++ )
741 : : {
742 : 0 : ::rtl::OUString aModName = pModNames[ j ];
743 : 0 : basctl::ModulWindow* pWin = FindBasWin( *doc, aLibName, aModName, false );
744 : 0 : if ( !pWin )
745 : 0 : pWin = CreateBasWin( *doc, aLibName, aModName );
746 : 0 : if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aModName &&
747 : 0 : pLibInfoItem->GetCurrentType() == BASICIDE_TYPE_MODULE )
748 : : {
749 : 0 : pNextActiveWindow = (IDEBaseWindow*)pWin;
750 : : }
751 : 0 : }
752 : : }
753 : 0 : catch (const container::NoSuchElementException& )
754 : : {
755 : : DBG_UNHANDLED_EXCEPTION();
756 : : }
757 : : }
758 : :
759 : : // dialogs
760 : 0 : Reference< script::XLibraryContainer > xDlgLibContainer( doc->getLibraryContainer( E_DIALOGS ) );
761 : 0 : if ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aLibName ) )
762 : : {
763 : : try
764 : : {
765 : 0 : Sequence< ::rtl::OUString > aDlgNames = doc->getObjectNames( E_DIALOGS, aLibName );
766 : 0 : sal_Int32 nDlgCount = aDlgNames.getLength();
767 : 0 : const ::rtl::OUString* pDlgNames = aDlgNames.getConstArray();
768 : :
769 : 0 : for ( sal_Int32 j = 0 ; j < nDlgCount ; j++ )
770 : : {
771 : 0 : ::rtl::OUString aDlgName = pDlgNames[ j ];
772 : : // this find only looks for non-suspended windows;
773 : : // suspended windows are handled in CreateDlgWin
774 : 0 : basctl::DialogWindow* pWin = FindDlgWin( *doc, aLibName, aDlgName, false );
775 : 0 : if ( !pWin )
776 : 0 : pWin = CreateDlgWin( *doc, aLibName, aDlgName );
777 : 0 : if ( !pNextActiveWindow && pLibInfoItem && pLibInfoItem->GetCurrentName() == aDlgName &&
778 : 0 : pLibInfoItem->GetCurrentType() == BASICIDE_TYPE_DIALOG )
779 : : {
780 : 0 : pNextActiveWindow = (IDEBaseWindow*)pWin;
781 : : }
782 : 0 : }
783 : : }
784 : 0 : catch (const container::NoSuchElementException& )
785 : : {
786 : : DBG_UNHANDLED_EXCEPTION();
787 : : }
788 : 0 : }
789 : 0 : }
790 : : }
791 : 0 : }
792 : 0 : }
793 : :
794 : 0 : if ( bChangeCurWindow )
795 : : {
796 : 0 : if ( !pNextActiveWindow )
797 : 0 : pNextActiveWindow = FindApplicationWindow();
798 : 0 : SetCurWindow( pNextActiveWindow, true );
799 : 0 : }
800 : : }
801 : :
802 : 0 : void BasicIDEShell::RemoveWindow( IDEBaseWindow* pWindow_, bool bDestroy, bool bAllowChangeCurWindow )
803 : : {
804 : : DBG_ASSERT( pWindow_, "Kann keinen NULL-Pointer loeschen!" );
805 : 0 : sal_uLong nKey = GetIDEWindowId( pWindow_ );
806 : 0 : pTabBar->RemovePage( (sal_uInt16)nKey );
807 : 0 : aIDEWindowTable.erase( nKey );
808 : 0 : if ( pWindow_ == pCurWin )
809 : : {
810 : 0 : if ( bAllowChangeCurWindow )
811 : 0 : SetCurWindow( FindApplicationWindow(), true );
812 : : else
813 : 0 : SetCurWindow( NULL, false );
814 : : }
815 : 0 : if ( bDestroy )
816 : : {
817 : 0 : if ( !( pWindow_->GetStatus() & BASWIN_INRESCHEDULE ) )
818 : : {
819 : 0 : delete pWindow_;
820 : : }
821 : : else
822 : : {
823 : 0 : pWindow_->AddStatus( BASWIN_TOBEKILLED );
824 : 0 : pWindow_->Hide();
825 : : // In normal mode stop basic in windows to be deleted
826 : : // In VBA stop basic only if the running script is trying to delete
827 : : // its parent module
828 : 0 : bool bStop = true;
829 : 0 : if ( pWindow_->GetDocument().isInVBAMode() )
830 : : {
831 : 0 : SbModule* pMod = StarBASIC::GetActiveModule();
832 : 0 : if ( !pMod || ( pMod && ( !pMod->GetName().Equals(pWindow_->GetName()) ) ) )
833 : 0 : bStop = false;
834 : : }
835 : 0 : if ( bStop )
836 : : {
837 : 0 : StarBASIC::Stop();
838 : : // there will be no notify...
839 : 0 : pWindow_->BasicStopped();
840 : : }
841 : 0 : aIDEWindowTable[ nKey ] = pWindow_; // jump in again
842 : : }
843 : : }
844 : : else
845 : : {
846 : 0 : pWindow_->AddStatus( BASWIN_SUSPENDED );
847 : 0 : pWindow_->Deactivating();
848 : 0 : aIDEWindowTable[ nKey ] = pWindow_; // jump in again
849 : : }
850 : :
851 : 0 : }
852 : :
853 : :
854 : :
855 : 0 : sal_uInt16 BasicIDEShell::InsertWindowInTable( IDEBaseWindow* pNewWin )
856 : : {
857 : 0 : nCurKey++;
858 : 0 : aIDEWindowTable[ nCurKey ] = pNewWin;
859 : 0 : return nCurKey;
860 : : }
861 : :
862 : :
863 : :
864 : 0 : void BasicIDEShell::InvalidateBasicIDESlots()
865 : : {
866 : : // only those that have an optic effect...
867 : :
868 : 0 : if ( BasicIDEGlobals::GetShell() )
869 : : {
870 : 0 : SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
871 : 0 : if ( pBindings )
872 : : {
873 : 0 : pBindings->Invalidate( SID_UNDO );
874 : 0 : pBindings->Invalidate( SID_REDO );
875 : 0 : pBindings->Invalidate( SID_SAVEDOC );
876 : 0 : pBindings->Invalidate( SID_SIGNATURE );
877 : 0 : pBindings->Invalidate( SID_BASICIDE_CHOOSEMACRO );
878 : 0 : pBindings->Invalidate( SID_BASICIDE_MODULEDLG );
879 : 0 : pBindings->Invalidate( SID_BASICIDE_OBJCAT );
880 : 0 : pBindings->Invalidate( SID_BASICSTOP );
881 : 0 : pBindings->Invalidate( SID_BASICRUN );
882 : 0 : pBindings->Invalidate( SID_BASICCOMPILE );
883 : 0 : pBindings->Invalidate( SID_BASICLOAD );
884 : 0 : pBindings->Invalidate( SID_BASICSAVEAS );
885 : 0 : pBindings->Invalidate( SID_BASICIDE_MATCHGROUP );
886 : 0 : pBindings->Invalidate( SID_BASICSTEPINTO );
887 : 0 : pBindings->Invalidate( SID_BASICSTEPOVER );
888 : 0 : pBindings->Invalidate( SID_BASICSTEPOUT );
889 : 0 : pBindings->Invalidate( SID_BASICIDE_TOGGLEBRKPNT );
890 : 0 : pBindings->Invalidate( SID_BASICIDE_MANAGEBRKPNTS );
891 : 0 : pBindings->Invalidate( SID_BASICIDE_ADDWATCH );
892 : 0 : pBindings->Invalidate( SID_BASICIDE_REMOVEWATCH );
893 : 0 : pBindings->Invalidate( SID_CHOOSE_CONTROLS );
894 : 0 : pBindings->Invalidate( SID_PRINTDOC );
895 : 0 : pBindings->Invalidate( SID_PRINTDOCDIRECT );
896 : 0 : pBindings->Invalidate( SID_SETUPPRINTER );
897 : 0 : pBindings->Invalidate( SID_DIALOG_TESTMODE );
898 : :
899 : 0 : pBindings->Invalidate( SID_DOC_MODIFIED );
900 : 0 : pBindings->Invalidate( SID_BASICIDE_STAT_TITLE );
901 : 0 : pBindings->Invalidate( SID_BASICIDE_STAT_POS );
902 : 0 : pBindings->Invalidate( SID_ATTR_INSERT );
903 : 0 : pBindings->Invalidate( SID_ATTR_SIZE );
904 : : }
905 : : }
906 : 0 : }
907 : :
908 : 0 : void BasicIDEShell::EnableScrollbars( bool bEnable )
909 : : {
910 : 0 : if ( bEnable )
911 : : {
912 : 0 : aHScrollBar.Enable();
913 : 0 : aVScrollBar.Enable();
914 : : }
915 : : else
916 : : {
917 : 0 : aHScrollBar.Disable();
918 : 0 : aVScrollBar.Disable();
919 : : }
920 : 0 : }
921 : :
922 : 0 : void BasicIDEShell::SetCurLib( const ScriptDocument& rDocument, ::rtl::OUString aLibName, bool bUpdateWindows, bool bCheck )
923 : : {
924 : 0 : if ( !bCheck || ( rDocument != m_aCurDocument || aLibName != m_aCurLibName ) )
925 : : {
926 : 0 : ContainerListenerImpl* pListener = static_cast< ContainerListenerImpl* >( m_xLibListener.get() );
927 : :
928 : 0 : m_aCurDocument = rDocument;
929 : 0 : m_aCurLibName = aLibName;
930 : :
931 : 0 : if ( pListener )
932 : : {
933 : 0 : pListener->removeContainerListener( m_aCurDocument, m_aCurLibName );
934 : 0 : pListener->addContainerListener( m_aCurDocument, aLibName );
935 : : }
936 : :
937 : 0 : if ( bUpdateWindows )
938 : 0 : UpdateWindows();
939 : :
940 : 0 : SetMDITitle();
941 : :
942 : 0 : SetCurLibForLocalization( rDocument, aLibName );
943 : :
944 : 0 : SfxBindings* pBindings = BasicIDE::GetBindingsPtr();
945 : 0 : if ( pBindings )
946 : : {
947 : 0 : pBindings->Invalidate( SID_BASICIDE_LIBSELECTOR );
948 : 0 : pBindings->Invalidate( SID_BASICIDE_CURRENT_LANG );
949 : 0 : pBindings->Invalidate( SID_BASICIDE_MANAGE_LANG );
950 : : }
951 : : }
952 : 0 : }
953 : :
954 : 0 : void BasicIDEShell::SetCurLibForLocalization( const ScriptDocument& rDocument, ::rtl::OUString aLibName )
955 : : {
956 : : // Create LocalizationMgr
957 : 0 : Reference< resource::XStringResourceManager > xStringResourceManager;
958 : : try
959 : : {
960 : 0 : if( !aLibName.isEmpty() )
961 : : {
962 : 0 : Reference< container::XNameContainer > xDialogLib( rDocument.getLibrary( E_DIALOGS, aLibName, true ) );
963 : 0 : xStringResourceManager = LocalizationMgr::getStringResourceFromDialogLibrary( xDialogLib );
964 : : }
965 : : }
966 : 0 : catch (const container::NoSuchElementException& )
967 : : {}
968 : :
969 : 0 : m_pCurLocalizationMgr = boost::shared_ptr<LocalizationMgr>(new LocalizationMgr(this, rDocument, aLibName, xStringResourceManager));
970 : 0 : m_pCurLocalizationMgr->handleTranslationbar();
971 : 0 : }
972 : :
973 : 0 : void BasicIDEShell::ImplStartListening( StarBASIC* pBasic )
974 : : {
975 : 0 : StartListening( pBasic->GetBroadcaster(), true /* log on only once */ );
976 : 0 : }
977 : :
978 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|