1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "basidesh.hrc"
23 #include "baside2.hxx"
24 #include "baside3.hxx"
25 #include "docsignature.hxx"
26 #include "iderdll.hxx"
27 #include "iderdll2.hxx"
28 #include "localizationmgr.hxx"
29 #include "managelang.hxx"
31 #include <basic/basmgr.hxx>
32 #include <basic/sbmeth.hxx>
33 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
34 #include <com/sun/star/frame/XLayoutManager.hpp>
35 #include <sfx2/childwin.hxx>
36 #include <sfx2/docfac.hxx>
37 #include <sfx2/dinfdlg.hxx>
38 #include <sfx2/dispatch.hxx>
39 #include <sfx2/minfitem.hxx>
40 #include <sfx2/printer.hxx>
41 #include <sfx2/request.hxx>
42 #include <svl/aeitem.hxx>
43 #include <svl/intitem.hxx>
44 #include <svl/srchitem.hxx>
45 #include <svl/visitem.hxx>
46 #include <svl/whiter.hxx>
47 #include <vcl/xtextedt.hxx>
48 #include <vcl/msgbox.hxx>
53 using namespace ::com::sun::star
;
54 using namespace ::com::sun::star::uno
;
55 using namespace ::com::sun::star::frame
;
57 void Shell::ExecuteCurrent( SfxRequest
& rReq
)
62 switch ( rReq
.GetSlot() )
64 case SID_BASICIDE_HIDECURPAGE
:
67 RemoveWindow( pCurWin
, false );
70 case SID_BASICIDE_RENAMECURRENT
:
72 pTabBar
->StartEditMode( pTabBar
->GetCurPageId() );
77 if (!pCurWin
->HasActiveEditor())
79 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
80 SfxItemSet
const& rArgs
= *rReq
.GetArgs();
81 // unfortunately I don't know the ID:
82 sal_uInt16 nWhich
= rArgs
.GetWhichByPos( 0 );
83 DBG_ASSERT( nWhich
, "Which for SearchItem?" );
84 SfxPoolItem
const& rItem
= rArgs
.Get(nWhich
);
85 DBG_ASSERT(dynamic_cast<SvxSearchItem
const*>(&rItem
), "no searchitem!");
86 SvxSearchItem
const& rSearchItem
= static_cast<SvxSearchItem
const&>(rItem
);
87 // memorize item because of the adjustments...
88 GetExtraData()->SetSearchItem(rSearchItem
);
90 if (rSearchItem
.GetCommand() == SvxSearchCmd::REPLACE_ALL
)
92 sal_uInt16 nActModWindows
= 0;
93 for (WindowTableIt it
= aWindowTable
.begin(); it
!= aWindowTable
.end(); ++it
)
95 BaseWindow
* pWin
= it
->second
;
96 if (pWin
->HasActiveEditor())
100 if ( nActModWindows
<= 1 || ( !rSearchItem
.GetSelection() && QueryBox( pCurWin
, WB_YES_NO
|WB_DEF_YES
, IDEResId(RID_STR_SEARCHALLMODULES
).toString() ).Execute() == RET_YES
) )
102 for (WindowTableIt it
= aWindowTable
.begin(); it
!= aWindowTable
.end(); ++it
)
104 BaseWindow
* pWin
= it
->second
;
105 nFound
+= pWin
->StartSearchAndReplace(rSearchItem
);
109 nFound
= pCurWin
->StartSearchAndReplace(rSearchItem
);
111 OUString
aReplStr(IDE_RESSTR(RID_STR_SEARCHREPLACES
));
112 aReplStr
= aReplStr
.replaceAll("XX", OUString::number(nFound
));
113 InfoBox( pCurWin
, aReplStr
).Execute();
117 bool bCanceled
= false;
118 nFound
= pCurWin
->StartSearchAndReplace(rSearchItem
);
119 if ( !nFound
&& !rSearchItem
.GetSelection() )
121 // search other modules...
122 bool bChangeCurWindow
= false;
124 for (it
= aWindowTable
.begin(); it
!= aWindowTable
.end(); ++it
)
125 if (it
->second
== pCurWin
)
127 if (it
!= aWindowTable
.end())
129 BaseWindow
* pWin
= it
!= aWindowTable
.end() ? it
->second
.get() : 0;
131 bool bSearchedFromStart
= false;
132 while ( !nFound
&& !bCanceled
&& ( pWin
|| !bSearchedFromStart
) )
136 SfxViewFrame
* pViewFrame
= GetViewFrame();
137 SfxChildWindow
* pChildWin
= pViewFrame
? pViewFrame
->GetChildWindow( SID_SEARCH_DLG
) : NULL
;
138 vcl::Window
* pParent
= pChildWin
? pChildWin
->GetWindow() : NULL
;
139 ScopedVclPtrInstance
< QueryBox
> aQuery(pParent
, WB_YES_NO
|WB_DEF_YES
, IDE_RESSTR(RID_STR_SEARCHFROMSTART
));
140 if ( aQuery
->Execute() == RET_YES
)
142 it
= aWindowTable
.begin();
143 if ( it
!= aWindowTable
.end() )
145 bSearchedFromStart
= true;
151 if (pWin
&& pWin
->HasActiveEditor())
153 if ( pWin
!= pCurWin
)
156 pWin
->SetSizePixel( pCurWin
->GetSizePixel() );
157 nFound
= pWin
->StartSearchAndReplace(rSearchItem
, true);
161 bChangeCurWindow
= true;
165 if ( pWin
&& ( pWin
!= pCurWin
) )
167 if ( it
!= aWindowTable
.end() )
169 pWin
= it
!= aWindowTable
.end() ? it
->second
.get() : 0;
174 if ( !nFound
&& bSearchedFromStart
)
175 nFound
= pCurWin
->StartSearchAndReplace(rSearchItem
, true);
176 if ( bChangeCurWindow
)
177 SetCurWindow( pWin
, true );
179 if ( !nFound
&& !bCanceled
)
180 InfoBox( pCurWin
, IDEResId(RID_STR_SEARCHNOTFOUND
).toString() ).Execute();
188 if ( GetUndoManager() && pCurWin
->AllowUndo() )
189 GetViewFrame()->ExecuteSlot( rReq
);
192 pCurWin
->ExecuteCommand( rReq
);
196 // no matter who's at the top, influence on the shell:
197 void Shell::ExecuteGlobal( SfxRequest
& rReq
)
199 sal_uInt16 nSlot
= rReq
.GetSlot();
204 // maybe do not simply stop if on breakpoint!
205 if (ModulWindow
* pMCurWin
= dynamic_cast<ModulWindow
*>(pCurWin
.get()))
206 pMCurWin
->BasicStop();
215 // rewrite date into the BASIC
216 StoreAllWindowData();
219 ScriptDocument
aDocument( pCurWin
->GetDocument() );
220 if ( aDocument
.isDocument() )
222 uno::Reference
< task::XStatusIndicator
> xStatusIndicator
;
224 SFX_REQUEST_ARG( rReq
, pStatusIndicatorItem
, SfxUnoAnyItem
,
225 SID_PROGRESS_STATUSBAR_CONTROL
, false );
226 if ( pStatusIndicatorItem
)
227 OSL_VERIFY( pStatusIndicatorItem
->GetValue() >>= xStatusIndicator
);
230 // get statusindicator
231 SfxViewFrame
*pFrame_
= GetFrame();
234 uno::Reference
< task::XStatusIndicatorFactory
> xStatFactory(
235 pFrame_
->GetFrame().GetFrameInterface(),
237 if( xStatFactory
.is() )
238 xStatusIndicator
= xStatFactory
->createStatusIndicator();
241 if ( xStatusIndicator
.is() )
242 rReq
.AppendItem( SfxUnoAnyItem( SID_PROGRESS_STATUSBAR_CONTROL
, uno::makeAny( xStatusIndicator
) ) );
245 aDocument
.saveDocument( xStatusIndicator
);
248 if (SfxBindings
* pBindings
= GetBindingsPtr())
250 pBindings
->Invalidate( SID_DOC_MODIFIED
);
251 pBindings
->Invalidate( SID_SAVEDOC
);
252 pBindings
->Invalidate( SID_SIGNATURE
);
257 case SID_BASICIDE_MODULEDLG
:
259 if ( rReq
.GetArgs() )
261 const SfxUInt16Item
&rTabId
= static_cast<const SfxUInt16Item
&>(rReq
.GetArgs()->Get(SID_BASICIDE_ARG_TABID
));
262 Organize( rTabId
.GetValue() );
268 case SID_BASICIDE_CHOOSEMACRO
:
270 ChooseMacro( NULL
, false, OUString() );
273 case SID_BASICIDE_CREATEMACRO
:
274 case SID_BASICIDE_EDITMACRO
:
276 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
277 const SfxMacroInfoItem
& rInfo
= static_cast<const SfxMacroInfoItem
&>(rReq
.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO
));
278 BasicManager
* pBasMgr
= const_cast<BasicManager
*>(rInfo
.GetBasicManager());
279 DBG_ASSERT( pBasMgr
, "Nichts selektiert im Basic-Baum ?" );
281 ScriptDocument
aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr
) );
283 StartListening( *pBasMgr
, true /* log on only once */ );
284 OUString
aLibName( rInfo
.GetLib() );
285 if ( aLibName
.isEmpty() )
286 aLibName
= "Standard" ;
287 StarBASIC
* pBasic
= pBasMgr
->GetLib( aLibName
);
290 // load module and dialog library (if not loaded)
291 aDocument
.loadLibraryIfExists( E_SCRIPTS
, aLibName
);
292 aDocument
.loadLibraryIfExists( E_DIALOGS
, aLibName
);
295 pBasic
= pBasMgr
->GetLib( aLibName
);
297 DBG_ASSERT( pBasic
, "No Basic!" );
299 SetCurLib( aDocument
, aLibName
);
301 if ( pBasic
&& rReq
.GetSlot() == SID_BASICIDE_CREATEMACRO
)
303 SbModule
* pModule
= pBasic
->FindModule( rInfo
.GetModule() );
306 if ( !rInfo
.GetModule().isEmpty() || !pBasic
->GetModules()->Count() )
308 OUString aModName
= rInfo
.GetModule();
310 OUString sModuleCode
;
311 if ( aDocument
.createModule( aLibName
, aModName
, false, sModuleCode
) )
312 pModule
= pBasic
->FindModule( aModName
);
315 pModule
= static_cast<SbModule
*>( pBasic
->GetModules()->Get(0) );
317 DBG_ASSERT( pModule
, "Kein Modul!" );
318 if ( pModule
&& !pModule
->GetMethods()->Find( rInfo
.GetMethod(), SbxCLASS_METHOD
) )
319 CreateMacro( pModule
, rInfo
.GetMethod() );
321 SfxViewFrame
* pViewFrame
= GetViewFrame();
324 ModulWindow
* pWin
= FindBasWin( aDocument
, aLibName
, rInfo
.GetModule(), true );
325 DBG_ASSERT( pWin
, "Edit/Create Macro: Fenster wurde nicht erzeugt/gefunden!" );
326 SetCurWindow( pWin
, true );
327 pWin
->EditMacro( rInfo
.GetMethod() );
331 case SID_BASICIDE_OBJCAT
:
332 // toggling object catalog
333 aObjectCatalog
->Show(!aObjectCatalog
->IsVisible());
335 pLayout
->ArrangeWindows();
336 // refresh the button state
337 if (SfxBindings
* pBindings
= GetBindingsPtr())
338 pBindings
->Invalidate(SID_BASICIDE_OBJCAT
);
341 case SID_BASICIDE_NAMECHANGEDONTAB
:
343 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
344 const SfxUInt16Item
&rTabId
= static_cast<const SfxUInt16Item
&>(rReq
.GetArgs()->Get(SID_BASICIDE_ARG_TABID
));
345 const SfxStringItem
&rModName
= static_cast<const SfxStringItem
&>(rReq
.GetArgs()->Get(SID_BASICIDE_ARG_MODULENAME
));
346 if ( aWindowTable
.find( rTabId
.GetValue() ) != aWindowTable
.end() )
348 BaseWindow
* pWin
= aWindowTable
[ rTabId
.GetValue() ];
349 OUString
aNewName( rModName
.GetValue() );
350 OUString
aOldName( pWin
->GetName() );
351 if ( aNewName
!= aOldName
)
353 bool bRenameOk
= false;
354 if (ModulWindow
* pModWin
= dynamic_cast<ModulWindow
*>(pWin
))
356 OUString aLibName
= pModWin
->GetLibName();
357 ScriptDocument
aDocument( pWin
->GetDocument() );
359 if (RenameModule(pModWin
, aDocument
, aLibName
, aOldName
, aNewName
))
362 // Because we listen for container events for script
363 // modules, rename will delete the 'old' window
364 // pWin has been invalidated, restore now
365 pWin
= FindBasWin( aDocument
, aLibName
, aNewName
, true );
369 else if (DialogWindow
* pDlgWin
= dynamic_cast<DialogWindow
*>(pWin
))
371 bRenameOk
= pDlgWin
->RenameDialog( aNewName
);
375 MarkDocumentModified( pWin
->GetDocument() );
379 // set old name in TabWriter
380 sal_uInt16 nId
= GetWindowId( pWin
);
381 DBG_ASSERT( nId
, "No entry in Tabbar!" );
383 pTabBar
->SetPageText( nId
, aOldName
);
387 // set focus to current window
392 case SID_BASICIDE_STOREMODULESOURCE
:
393 case SID_BASICIDE_UPDATEMODULESOURCE
:
395 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
396 const SfxMacroInfoItem
& rInfo
= static_cast<const SfxMacroInfoItem
&>(rReq
.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO
));
397 BasicManager
* pBasMgr
= const_cast<BasicManager
*>(rInfo
.GetBasicManager());
398 DBG_ASSERT( pBasMgr
, "Store source: Kein BasMgr?" );
399 ScriptDocument
aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr
) );
400 ModulWindow
* pWin
= FindBasWin( aDocument
, rInfo
.GetLib(), rInfo
.GetModule(), false, true );
403 if ( rReq
.GetSlot() == SID_BASICIDE_STOREMODULESOURCE
)
410 case SID_BASICIDE_STOREALLMODULESOURCES
:
411 case SID_BASICIDE_UPDATEALLMODULESOURCES
:
413 for (WindowTableIt it
= aWindowTable
.begin(); it
!= aWindowTable
.end(); ++it
)
415 BaseWindow
* pWin
= it
->second
;
416 if (!pWin
->IsSuspended() && dynamic_cast<ModulWindow
*>(pWin
))
418 if ( rReq
.GetSlot() == SID_BASICIDE_STOREALLMODULESOURCES
)
426 case SID_BASICIDE_LIBSELECTED
:
427 case SID_BASICIDE_LIBREMOVED
:
428 case SID_BASICIDE_LIBLOADED
:
430 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
431 const SfxUsrAnyItem
& rShellItem
= static_cast<const SfxUsrAnyItem
&>(rReq
.GetArgs()->Get( SID_BASICIDE_ARG_DOCUMENT_MODEL
));
432 uno::Reference
< frame::XModel
> xModel( rShellItem
.GetValue(), UNO_QUERY
);
433 ScriptDocument
aDocument( xModel
.is() ? ScriptDocument( xModel
) : ScriptDocument::getApplicationScriptDocument() );
434 const SfxStringItem
& rLibNameItem
= static_cast<const SfxStringItem
&>(rReq
.GetArgs()->Get( SID_BASICIDE_ARG_LIBNAME
));
435 OUString
aLibName( rLibNameItem
.GetValue() );
437 if ( nSlot
== SID_BASICIDE_LIBSELECTED
)
439 // load module and dialog library (if not loaded)
440 aDocument
.loadLibraryIfExists( E_SCRIPTS
, aLibName
);
441 aDocument
.loadLibraryIfExists( E_DIALOGS
, aLibName
);
443 // check password, if library is password protected and not verified
445 Reference
< script::XLibraryContainer
> xModLibContainer( aDocument
.getLibraryContainer( E_SCRIPTS
) );
446 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) )
448 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContainer
, UNO_QUERY
);
449 if ( xPasswd
.is() && xPasswd
->isLibraryPasswordProtected( aLibName
) && !xPasswd
->isLibraryPasswordVerified( aLibName
) )
452 bOK
= QueryPassword( xModLibContainer
, aLibName
, aPassword
);
458 SetCurLib( aDocument
, aLibName
, true, false );
462 // adjust old value...
463 if (SfxBindings
* pBindings
= GetBindingsPtr())
464 pBindings
->Invalidate(SID_BASICIDE_LIBSELECTOR
, true, false);
467 else if ( nSlot
== SID_BASICIDE_LIBREMOVED
)
469 if ( m_aCurLibName
.isEmpty() || ( aDocument
== m_aCurDocument
&& aLibName
== m_aCurLibName
) )
471 RemoveWindows( aDocument
, aLibName
, true );
472 if ( aDocument
== m_aCurDocument
&& aLibName
== m_aCurLibName
)
474 m_aCurDocument
= ScriptDocument::getApplicationScriptDocument();
475 m_aCurLibName
.clear();
477 if (SfxBindings
* pBindings
= GetBindingsPtr())
478 pBindings
->Invalidate( SID_BASICIDE_LIBSELECTOR
);
486 case SID_BASICIDE_NEWMODULE
:
488 VclPtr
<ModulWindow
> pWin
= CreateBasWin( m_aCurDocument
, m_aCurLibName
, OUString() );
489 DBG_ASSERT( pWin
, "New Module: Konnte Fenster nicht erzeugen!" );
490 SetCurWindow( pWin
, true );
493 case SID_BASICIDE_NEWDIALOG
:
495 VclPtr
<DialogWindow
> pWin
= CreateDlgWin( m_aCurDocument
, m_aCurLibName
, OUString() );
496 DBG_ASSERT( pWin
, "New Module: Konnte Fenster nicht erzeugen!" );
497 SetCurWindow( pWin
, true );
500 case SID_BASICIDE_SBXRENAMED
:
502 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
505 case SID_BASICIDE_SBXINSERTED
:
507 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
508 const SbxItem
& rSbxItem
= static_cast<const SbxItem
&>(rReq
.GetArgs()->Get(SID_BASICIDE_ARG_SBX
));
509 ScriptDocument
aDocument( rSbxItem
.GetDocument() );
510 OUString
aLibName( rSbxItem
.GetLibName() );
511 OUString
aName( rSbxItem
.GetName() );
512 if ( m_aCurLibName
.isEmpty() || ( aDocument
== m_aCurDocument
&& aLibName
== m_aCurLibName
) )
514 if ( rSbxItem
.GetType() == TYPE_MODULE
)
515 FindBasWin( aDocument
, aLibName
, aName
, true );
516 else if ( rSbxItem
.GetType() == TYPE_DIALOG
)
517 FindDlgWin( aDocument
, aLibName
, aName
, true );
521 case SID_BASICIDE_SBXDELETED
:
523 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
524 const SbxItem
& rSbxItem
= static_cast<const SbxItem
&>(rReq
.GetArgs()->Get(SID_BASICIDE_ARG_SBX
));
525 ScriptDocument
aDocument( rSbxItem
.GetDocument() );
526 BaseWindow
* pWin
= FindWindow( aDocument
, rSbxItem
.GetLibName(), rSbxItem
.GetName(), rSbxItem
.GetType(), true );
528 RemoveWindow( pWin
, true );
531 case SID_BASICIDE_SHOWSBX
:
533 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
534 const SbxItem
& rSbxItem
= static_cast<const SbxItem
&>(rReq
.GetArgs()->Get(SID_BASICIDE_ARG_SBX
));
535 ScriptDocument
aDocument( rSbxItem
.GetDocument() );
536 OUString
aLibName( rSbxItem
.GetLibName() );
537 OUString
aName( rSbxItem
.GetName() );
538 SetCurLib( aDocument
, aLibName
);
539 BaseWindow
* pWin
= 0;
540 if ( rSbxItem
.GetType() == TYPE_DIALOG
)
542 pWin
= FindDlgWin( aDocument
, aLibName
, aName
, true );
544 else if ( rSbxItem
.GetType() == TYPE_MODULE
)
546 pWin
= FindBasWin( aDocument
, aLibName
, aName
, true );
548 else if ( rSbxItem
.GetType() == TYPE_METHOD
)
550 pWin
= FindBasWin( aDocument
, aLibName
, aName
, true );
551 static_cast<ModulWindow
*>(pWin
)->EditMacro( rSbxItem
.GetMethodName() );
553 DBG_ASSERT( pWin
, "Fenster wurde nicht erzeugt!" );
554 SetCurWindow( pWin
, true );
555 pTabBar
->MakeVisible( pTabBar
->GetCurPageId() );
558 case SID_BASICIDE_SHOWWINDOW
:
560 boost::scoped_ptr
< ScriptDocument
> pDocument
;
562 SFX_REQUEST_ARG( rReq
, pDocumentItem
, SfxStringItem
, SID_BASICIDE_ARG_DOCUMENT
, false );
565 OUString sDocumentCaption
= pDocumentItem
->GetValue();
566 if ( !sDocumentCaption
.isEmpty() )
567 pDocument
.reset( new ScriptDocument( ScriptDocument::getDocumentWithURLOrCaption( sDocumentCaption
) ) );
570 SFX_REQUEST_ARG( rReq
, pDocModelItem
, SfxUsrAnyItem
, SID_BASICIDE_ARG_DOCUMENT_MODEL
, false );
571 if ( !pDocument
.get() && pDocModelItem
)
573 uno::Reference
< frame::XModel
> xModel( pDocModelItem
->GetValue(), UNO_QUERY
);
575 pDocument
.reset( new ScriptDocument( xModel
) );
578 if ( !pDocument
.get() )
581 SFX_REQUEST_ARG( rReq
, pLibNameItem
, SfxStringItem
, SID_BASICIDE_ARG_LIBNAME
, false );
585 OUString
aLibName( pLibNameItem
->GetValue() );
586 pDocument
->loadLibraryIfExists( E_SCRIPTS
, aLibName
);
587 SetCurLib( *pDocument
, aLibName
);
588 SFX_REQUEST_ARG( rReq
, pNameItem
, SfxStringItem
, SID_BASICIDE_ARG_NAME
, false );
591 OUString
aName( pNameItem
->GetValue() );
592 OUString
aModType( "Module" );
593 OUString
aDlgType( "Dialog" );
594 OUString
aType( aModType
);
595 SFX_REQUEST_ARG( rReq
, pTypeItem
, SfxStringItem
, SID_BASICIDE_ARG_TYPE
, false );
597 aType
= pTypeItem
->GetValue();
599 BaseWindow
* pWin
= 0;
600 if ( aType
== aModType
)
601 pWin
= FindBasWin( *pDocument
, aLibName
, aName
, false );
602 else if ( aType
== aDlgType
)
603 pWin
= FindDlgWin( *pDocument
, aLibName
, aName
, false );
607 SetCurWindow( pWin
, true );
609 pTabBar
->MakeVisible( pTabBar
->GetCurPageId() );
611 if (ModulWindow
* pModWin
= dynamic_cast<ModulWindow
*>(pWin
))
613 SFX_REQUEST_ARG( rReq
, pLineItem
, SfxUInt32Item
, SID_BASICIDE_ARG_LINE
, false );
616 pModWin
->AssertValidEditEngine();
617 TextView
* pTextView
= pModWin
->GetEditView();
620 TextEngine
* pTextEngine
= pTextView
->GetTextEngine();
623 sal_uInt32 nLine
= pLineItem
->GetValue();
624 sal_uInt32 nLineCount
= 0;
625 for ( sal_uInt32 i
= 0, nCount
= pTextEngine
->GetParagraphCount(); i
< nCount
; ++i
)
626 nLineCount
+= pTextEngine
->GetLineCount( i
);
627 if ( nLine
> nLineCount
)
632 // scroll window and set selection
633 long nVisHeight
= pModWin
->GetOutputSizePixel().Height();
634 long nTextHeight
= pTextEngine
->GetTextHeight();
635 if ( nTextHeight
> nVisHeight
)
637 long nMaxY
= nTextHeight
- nVisHeight
;
638 long nOldY
= pTextView
->GetStartDocPos().Y();
639 long nNewY
= nLine
* pTextEngine
->GetCharHeight() - nVisHeight
/ 2;
640 nNewY
= ::std::min( nNewY
, nMaxY
);
641 pTextView
->Scroll( 0, -( nNewY
- nOldY
) );
642 pTextView
->ShowCursor( false, true );
643 pModWin
->GetEditVScrollBar().SetThumbPos( pTextView
->GetStartDocPos().Y() );
645 sal_uInt16 nCol1
= 0, nCol2
= 0;
646 SFX_REQUEST_ARG( rReq
, pCol1Item
, SfxUInt16Item
, SID_BASICIDE_ARG_COLUMN1
, false );
649 nCol1
= pCol1Item
->GetValue();
654 SFX_REQUEST_ARG( rReq
, pCol2Item
, SfxUInt16Item
, SID_BASICIDE_ARG_COLUMN2
, false );
657 nCol2
= pCol2Item
->GetValue();
661 TextSelection
aSel( TextPaM( nLine
, nCol1
), TextPaM( nLine
, nCol2
) );
662 pTextView
->SetSelection( aSel
);
663 pTextView
->ShowCursor();
664 vcl::Window
* pWindow_
= pTextView
->GetWindow();
666 pWindow_
->GrabFocus();
677 case SID_BASICIDE_MANAGE_LANG
:
679 ScopedVclPtrInstance
< ManageLanguageDialog
> aDlg(pCurWin
, m_pCurLocalizationMgr
);
687 pLayout
->ExecuteGlobal(rReq
);
689 pCurWin
->ExecuteGlobal(rReq
);
694 void Shell::GetState(SfxItemSet
&rSet
)
696 SfxWhichIter
aIter(rSet
);
697 for ( sal_uInt16 nWh
= aIter
.FirstWhich(); 0 != nWh
; nWh
= aIter
.NextWhich() )
703 rSet
.DisableItem( nWh
);
708 bool bDisable
= false;
712 if ( !pCurWin
->IsModified() )
714 ScriptDocument
aDocument( pCurWin
->GetDocument() );
715 bDisable
= ( !aDocument
.isAlive() )
716 || ( aDocument
.isDocument() ? !aDocument
.isDocumentModified() : !IsAppBasicModified() );
725 rSet
.DisableItem( nWh
);
731 rSet
.DisableItem( nWh
);
736 SignatureState nState
= SignatureState::NOSIGNATURES
;
739 DocumentSignature
aSignature( pCurWin
->GetDocument() );
740 nState
= aSignature
.getScriptingSignatureState();
742 rSet
.Put( SfxUInt16Item( SID_SIGNATURE
, static_cast<sal_uInt16
>(nState
) ) );
745 case SID_BASICIDE_MODULEDLG
:
747 if ( StarBASIC::IsRunning() )
748 rSet
.DisableItem( nWh
);
751 case SID_BASICIDE_OBJCAT
:
753 rSet
.Put(SfxBoolItem(nWh
, aObjectCatalog
->IsVisible()));
755 rSet
.Put(SfxVisibilityItem(nWh
, false));
757 case SID_BASICIDE_SHOWSBX
:
758 case SID_BASICIDE_CREATEMACRO
:
759 case SID_BASICIDE_EDITMACRO
:
760 case SID_BASICIDE_NAMECHANGEDONTAB
:
766 case SID_BASICIDE_ADDWATCH
:
767 case SID_BASICIDE_REMOVEWATCH
:
769 case SID_BASICSAVEAS
:
770 case SID_BASICIDE_MATCHGROUP
:
772 if (!dynamic_cast<ModulWindow
*>(pCurWin
.get()))
773 rSet
.DisableItem( nWh
);
774 else if ( ( nWh
== SID_BASICLOAD
) && ( StarBASIC::IsRunning() || ( pCurWin
&& pCurWin
->IsReadOnly() ) ) )
775 rSet
.DisableItem( nWh
);
779 case SID_BASICSTEPINTO
:
780 case SID_BASICSTEPOVER
:
781 case SID_BASICSTEPOUT
:
782 case SID_BASICIDE_TOGGLEBRKPNT
:
783 case SID_BASICIDE_MANAGEBRKPNTS
:
785 if (ModulWindow
* pMCurWin
= dynamic_cast<ModulWindow
*>(pCurWin
.get()))
787 if (StarBASIC::IsRunning() && !pMCurWin
->GetBasicStatus().bIsInReschedule
)
788 rSet
.DisableItem(nWh
);
791 rSet
.DisableItem( nWh
);
794 case SID_BASICCOMPILE
:
796 if (StarBASIC::IsRunning() || !dynamic_cast<ModulWindow
*>(pCurWin
.get()))
797 rSet
.DisableItem( nWh
);
802 // stop is always possible when some Basic is running...
803 if (!StarBASIC::IsRunning())
804 rSet
.DisableItem( nWh
);
807 case SID_CHOOSE_CONTROLS
:
808 case SID_DIALOG_TESTMODE
:
809 case SID_INSERT_FORM_RADIO
:
810 case SID_INSERT_FORM_CHECK
:
811 case SID_INSERT_FORM_LIST
:
812 case SID_INSERT_FORM_COMBO
:
813 case SID_INSERT_FORM_VSCROLL
:
814 case SID_INSERT_FORM_HSCROLL
:
815 case SID_INSERT_FORM_SPIN
:
817 if (!dynamic_cast<DialogWindow
*>(pCurWin
.get()))
818 rSet
.DisableItem( nWh
);
822 case SID_SHOW_HIDDEN
:
824 rSet
.DisableItem( nWh
);
827 case SID_SEARCH_OPTIONS
:
829 SearchOptionFlags nOptions
= SearchOptionFlags::NONE
;
831 nOptions
= pCurWin
->GetSearchOptions();
832 rSet
.Put( SfxUInt16Item( SID_SEARCH_OPTIONS
, static_cast<sal_uInt16
>(nOptions
) ) );
835 case SID_BASICIDE_LIBSELECTOR
:
838 if ( !m_aCurLibName
.isEmpty() )
840 LibraryLocation eLocation
= m_aCurDocument
.getLibraryLocation( m_aCurLibName
);
841 aName
= CreateMgrAndLibStr( m_aCurDocument
.getTitle( eLocation
), m_aCurLibName
);
843 SfxStringItem
aItem( SID_BASICIDE_LIBSELECTOR
, aName
);
847 case SID_SEARCH_ITEM
:
849 OUString aSelected
= GetSelectionText(true);
850 SvxSearchItem
& rItem
= GetExtraData()->GetSearchItem();
851 rItem
.SetSearchString( aSelected
);
855 case SID_BASICIDE_STAT_DATE
:
857 OUString
aDate( "Datum?!" );
858 SfxStringItem
aItem( SID_BASICIDE_STAT_DATE
, aDate
);
862 case SID_DOC_MODIFIED
:
864 bool bModified
= false;
868 if ( pCurWin
->IsModified() )
872 ScriptDocument
aDocument( pCurWin
->GetDocument() );
873 bModified
= aDocument
.isDocument() ? aDocument
.isDocumentModified() : IsAppBasicModified();
877 SfxBoolItem
aItem(SID_DOC_MODIFIED
, bModified
);
881 case SID_BASICIDE_STAT_TITLE
:
885 OUString aTitle
= pCurWin
->CreateQualifiedName();
886 SfxStringItem
aItem( SID_BASICIDE_STAT_TITLE
, aTitle
);
891 // are interpreted by the controller:
893 case SID_ATTR_INSERT
:
898 if( GetUndoManager() ) // recursive GetState else
899 GetViewFrame()->GetSlotState( nWh
, NULL
, &rSet
);
902 case SID_BASICIDE_CURRENT_LANG
:
904 if( (pCurWin
&& pCurWin
->IsReadOnly()) || GetCurLibName().isEmpty() )
905 rSet
.DisableItem( nWh
);
909 boost::shared_ptr
<LocalizationMgr
> pCurMgr(GetCurLocalizationMgr());
910 if ( pCurMgr
->isLibraryLocalized() )
912 Sequence
< lang::Locale
> aLocaleSeq
= pCurMgr
->getStringResourceManager()->getLocales();
913 const lang::Locale
* pLocale
= aLocaleSeq
.getConstArray();
914 sal_Int32 i
, nCount
= aLocaleSeq
.getLength();
916 // Force different results for any combination of locales and default locale
918 for ( i
= 0; i
<= nCount
; ++i
)
920 lang::Locale aLocale
;
922 aLocale
= pLocale
[i
];
924 aLocale
= pCurMgr
->getStringResourceManager()->getDefaultLocale();
926 aLangStr
+= aLocale
.Language
;
927 aLangStr
+= aLocale
.Country
;
928 aLangStr
+= aLocale
.Variant
;
932 rSet
.Put( SfxStringItem( nWh
, aItemStr
) );
937 case SID_BASICIDE_MANAGE_LANG
:
939 if( (pCurWin
&& pCurWin
->IsReadOnly()) || GetCurLibName().isEmpty() )
940 rSet
.DisableItem( nWh
);
945 // if this is not a module window hide the
946 // setting, doesn't make sense for example if the
947 // dialog editor is open
948 if (pCurWin
&& !dynamic_cast<ModulWindow
*>(pCurWin
.get()))
950 rSet
.DisableItem( nWh
);
951 rSet
.Put(SfxVisibilityItem(nWh
, false));
957 pLayout
->GetState(rSet
, nWh
);
961 pCurWin
->GetState( rSet
);
964 bool Shell::HasUIFeature( sal_uInt32 nFeature
)
966 bool bResult
= false;
968 if ( (nFeature
& BASICIDE_UI_FEATURE_SHOW_BROWSER
) == BASICIDE_UI_FEATURE_SHOW_BROWSER
)
970 // fade out (in) property browser in module (dialog) windows
971 if (dynamic_cast<DialogWindow
*>(pCurWin
.get()) && !pCurWin
->IsReadOnly())
978 void Shell::SetCurWindow( BaseWindow
* pNewWin
, bool bUpdateTabBar
, bool bRememberAsCurrent
)
980 if ( pNewWin
!= pCurWin
)
984 pLayout
->Deactivating();
987 if (pCurWin
->GetType() == TYPE_MODULE
)
988 pLayout
= pModulLayout
.get();
990 pLayout
= pDialogLayout
.get();
991 AdjustPosSizePixel(Point(0, 0), GetViewFrame()->GetWindow().GetOutputSizePixel());
992 pLayout
->Activating(*pCurWin
);
993 GetViewFrame()->GetWindow().SetHelpId(pCurWin
->GetHid());
994 if (bRememberAsCurrent
)
995 pCurWin
->InsertLibInfo();
996 if (GetViewFrame()->GetWindow().IsVisible()) // SFX will do it later otherwise
999 if (!GetExtraData()->ShellInCriticalSection())
1001 vcl::Window
* pFrameWindow
= &GetViewFrame()->GetWindow();
1002 vcl::Window
* pFocusWindow
= Application::GetFocusWindow();
1003 while ( pFocusWindow
&& ( pFocusWindow
!= pFrameWindow
) )
1004 pFocusWindow
= pFocusWindow
->GetParent();
1005 if ( pFocusWindow
) // Focus in BasicIDE
1006 pCurWin
->GrabFocus();
1014 if ( bUpdateTabBar
)
1016 sal_uLong nKey
= GetWindowId( pCurWin
);
1017 if ( pCurWin
&& ( pTabBar
->GetPagePos( (sal_uInt16
)nKey
) == TAB_PAGE_NOTFOUND
) )
1018 pTabBar
->InsertPage( (sal_uInt16
)nKey
, pCurWin
->GetTitle() ); // has just been faded in
1019 pTabBar
->SetCurPageId( (sal_uInt16
)nKey
);
1021 if ( pCurWin
&& pCurWin
->IsSuspended() ) // if the window is shown in the case of an error...
1022 pCurWin
->SetStatus( pCurWin
->GetStatus() & ~BASWIN_SUSPENDED
);
1025 SetWindow( pCurWin
);
1026 if ( pCurWin
->GetDocument().isDocument() )
1027 SfxObjectShell::SetCurrentComponent( pCurWin
->GetDocument().getDocument() );
1032 GetViewFrame()->GetWindow().SetHelpId( HID_BASICIDE_MODULWINDOW
);
1033 SfxObjectShell::SetCurrentComponent(0);
1035 aObjectCatalog
->SetCurrentEntry(pCurWin
);
1036 SetUndoManager( pCurWin
? pCurWin
->GetUndoManager() : 0 );
1037 InvalidateBasicIDESlots();
1038 EnableScrollbars(pCurWin
!= nullptr);
1040 if ( m_pCurLocalizationMgr
)
1041 m_pCurLocalizationMgr
->handleTranslationbar();
1045 // fade out (in) property browser in module (dialog) windows
1050 void Shell::ManageToolbars()
1052 static const char aMacroBarResName
[] = "private:resource/toolbar/macrobar";
1053 static const char aDialogBarResName
[] = "private:resource/toolbar/dialogbar";
1054 static const char aInsertControlsBarResName
[] = "private:resource/toolbar/insertcontrolsbar";
1055 static const char aFormControlsBarResName
[] = "private:resource/toolbar/formcontrolsbar";
1060 Reference
< beans::XPropertySet
> xFrameProps
1061 ( GetViewFrame()->GetFrame().GetFrameInterface(), uno::UNO_QUERY
);
1062 if ( xFrameProps
.is() )
1064 Reference
< ::com::sun::star::frame::XLayoutManager
> xLayoutManager
;
1065 uno::Any a
= xFrameProps
->getPropertyValue( "LayoutManager" );
1066 a
>>= xLayoutManager
;
1067 if ( xLayoutManager
.is() )
1069 xLayoutManager
->lock();
1070 if (dynamic_cast<DialogWindow
*>(pCurWin
.get()))
1072 xLayoutManager
->destroyElement( aMacroBarResName
);
1074 xLayoutManager
->requestElement( aDialogBarResName
);
1075 xLayoutManager
->requestElement( aInsertControlsBarResName
);
1076 xLayoutManager
->requestElement( aFormControlsBarResName
);
1080 xLayoutManager
->destroyElement( aDialogBarResName
);
1081 xLayoutManager
->destroyElement( aInsertControlsBarResName
);
1082 xLayoutManager
->destroyElement( aFormControlsBarResName
);
1084 xLayoutManager
->requestElement( aMacroBarResName
);
1086 xLayoutManager
->unlock();
1091 VclPtr
<BaseWindow
> Shell::FindApplicationWindow()
1093 return FindWindow( ScriptDocument::getApplicationScriptDocument() );
1096 VclPtr
<BaseWindow
> Shell::FindWindow(
1097 ScriptDocument
const& rDocument
,
1098 OUString
const& rLibName
, OUString
const& rName
,
1099 ItemType eType
, bool bFindSuspended
1102 for (WindowTableIt it
= aWindowTable
.begin(); it
!= aWindowTable
.end(); ++it
)
1104 BaseWindow
* const pWin
= it
->second
;
1105 if (pWin
->Is(rDocument
, rLibName
, rName
, eType
, bFindSuspended
))
1111 bool Shell::CallBasicErrorHdl( StarBASIC
* pBasic
)
1114 ModulWindow
* pModWin
= ShowActiveModuleWindow( pBasic
);
1116 nRet
= pModWin
->BasicErrorHdl( pBasic
);
1120 long Shell::CallBasicBreakHdl( StarBASIC
* pBasic
)
1123 ModulWindow
* pModWin
= ShowActiveModuleWindow( pBasic
);
1126 bool bAppWindowDisabled
, bDispatcherLocked
;
1127 sal_uInt16 nWaitCount
;
1128 SfxUInt16Item
*pSWActionCount
, *pSWLockViewCount
;
1129 BasicStopped( &bAppWindowDisabled
, &bDispatcherLocked
,
1130 &nWaitCount
, &pSWActionCount
, &pSWLockViewCount
);
1132 nRet
= pModWin
->BasicBreakHdl( pBasic
);
1134 if ( StarBASIC::IsRunning() ) // if cancelled...
1136 if ( bAppWindowDisabled
)
1137 Application::GetDefDialogParent()->Enable(false);
1141 Shell
* pShell
= GetShell();
1142 for ( sal_uInt16 n
= 0; n
< nWaitCount
; n
++ )
1143 pShell
->GetViewFrame()->GetWindow().EnterWait();
1150 VclPtr
<ModulWindow
> Shell::ShowActiveModuleWindow( StarBASIC
* pBasic
)
1152 SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
1154 SbModule
* pActiveModule
= StarBASIC::GetActiveModule();
1155 if (SbClassModuleObject
* pCMO
= dynamic_cast<SbClassModuleObject
*>(pActiveModule
))
1156 pActiveModule
= pCMO
->getClassModule();
1158 DBG_ASSERT( pActiveModule
, "Kein aktives Modul im ErrorHdl?!" );
1159 if ( pActiveModule
)
1161 VclPtr
<ModulWindow
> pWin
;
1162 SbxObject
* pParent
= pActiveModule
->GetParent();
1163 if (StarBASIC
* pLib
= dynamic_cast<StarBASIC
*>(pParent
))
1165 if (BasicManager
* pBasMgr
= FindBasicManager(pLib
))
1167 ScriptDocument
aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr
) );
1168 OUString aLibName
= pLib
->GetName();
1169 pWin
= FindBasWin( aDocument
, aLibName
, pActiveModule
->GetName(), true );
1170 DBG_ASSERT( pWin
, "Error/Step-Hdl: Fenster wurde nicht erzeugt/gefunden!" );
1171 SetCurLib( aDocument
, aLibName
);
1172 SetCurWindow( pWin
, true );
1176 DBG_ASSERT(false, "No BASIC!");
1177 if (BasicManager
* pBasicMgr
= FindBasicManager(pBasic
))
1178 StartListening( *pBasicMgr
, true /* log on only once */ );
1184 void Shell::AdjustPosSizePixel( const Point
&rPos
, const Size
&rSize
)
1186 // not if iconified because the whole text would be displaced then at restore
1187 if ( GetViewFrame()->GetWindow().GetOutputSizePixel().Height() == 0 )
1191 Size
aScrollBarBoxSz( aScrollBarBox
->GetSizePixel() );
1192 aSz
.Height() -= aScrollBarBoxSz
.Height();
1195 aSz
.Width() -= aScrollBarBoxSz
.Width();
1196 aScrollBarBox
->SetPosPixel( Point( rSize
.Width() - aScrollBarBoxSz
.Width(), rSize
.Height() - aScrollBarBoxSz
.Height() ) );
1197 aVScrollBar
->SetPosSizePixel( Point( rPos
.X()+aSz
.Width(), rPos
.Y() ), Size( aScrollBarBoxSz
.Width(), aSz
.Height() ) );
1198 if ( bTabBarSplitted
)
1200 // SplitSize is 0 at a resize!
1201 long nSplitPos
= pTabBar
->GetSizePixel().Width();
1202 if ( nSplitPos
> aSz
.Width() )
1203 nSplitPos
= aSz
.Width();
1204 pTabBar
->SetPosSizePixel( Point( rPos
.X(), rPos
.Y()+aSz
.Height() ), Size( nSplitPos
, aScrollBarBoxSz
.Height() ) );
1205 long nScrlStart
= rPos
.X() + nSplitPos
;
1206 aHScrollBar
->SetPosSizePixel( Point( nScrlStart
, rPos
.Y()+aSz
.Height() ), Size( aSz
.Width() - nScrlStart
+ 1, aScrollBarBoxSz
.Height() ) );
1207 aHScrollBar
->Update();
1211 aHScrollBar
->SetPosSizePixel( Point( rPos
.X()+ aSz
.Width()/2 - 1, rPos
.Y()+aSz
.Height() ), Size( aSz
.Width()/2 + 2, aScrollBarBoxSz
.Height() ) );
1212 pTabBar
->SetPosSizePixel( Point( rPos
.X(), rPos
.Y()+aSz
.Height() ), Size( aSz
.Width()/2, aScrollBarBoxSz
.Height() ) );
1216 pLayout
->SetPosSizePixel(rPos
, dynamic_cast<DialogWindow
*>(pCurWin
.get()) ? aSz
: aOutSz
);
1219 Reference
< XModel
> Shell::GetCurrentDocument() const
1221 Reference
< XModel
> xDocument
;
1222 if ( pCurWin
&& pCurWin
->GetDocument().isDocument() )
1223 xDocument
= pCurWin
->GetDocument().getDocument();
1227 void Shell::Activate( bool bMDI
)
1229 SfxViewShell::Activate( bMDI
);
1233 if (DialogWindow
* pDCurWin
= dynamic_cast<DialogWindow
*>(pCurWin
.get()))
1234 pDCurWin
->UpdateBrowser();
1238 void Shell::Deactivate( bool bMDI
)
1240 // bMDI == true means that another MDI has been activated; in case of a
1241 // deactivate due to a MessageBox bMDI is false
1244 if (DialogWindow
* pXDlgWin
= dynamic_cast<DialogWindow
*>(pCurWin
.get()))
1246 pXDlgWin
->DisableBrowser();
1247 if( pXDlgWin
->IsModified() )
1248 MarkDocumentModified( pXDlgWin
->GetDocument() );
1251 // test CanClose to also test during deactivating the BasicIDE whether
1252 // the sourcecode is too large in one of the modules...
1253 for (WindowTableIt it
= aWindowTable
.begin(); it
!= aWindowTable
.end(); ++it
)
1255 BaseWindow
* pWin
= it
->second
;
1256 if ( /* !pWin->IsSuspended() && */ !pWin
->CanClose() )
1258 if ( !m_aCurLibName
.isEmpty() && ( pWin
->IsDocument( m_aCurDocument
) || pWin
->GetLibName() != m_aCurLibName
) )
1259 SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
1260 SetCurWindow( pWin
, true );
1267 } // namespace basctl
1269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */