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"
26 #include "docsignature.hxx"
27 #include "iderdll.hxx"
28 #include "iderdll2.hxx"
29 #include "localizationmgr.hxx"
30 #include "managelang.hxx"
32 #include <basic/basmgr.hxx>
33 #include <basic/sbmeth.hxx>
34 #include <com/sun/star/frame/XLayoutManager.hpp>
35 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
36 #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
37 #include <sfx2/childwin.hxx>
38 #include <sfx2/docfac.hxx>
39 #include <sfx2/dinfdlg.hxx>
40 #include <sfx2/dispatch.hxx>
41 #include <sfx2/minfitem.hxx>
42 #include <sfx2/objface.hxx>
43 #include <sfx2/printer.hxx>
44 #include <sfx2/request.hxx>
45 #include <svl/aeitem.hxx>
46 #include <svl/intitem.hxx>
47 #include <svl/srchitem.hxx>
48 #include <svl/visitem.hxx>
49 #include <svl/whiter.hxx>
50 #include <vcl/xtextedt.hxx>
51 #include <vcl/msgbox.hxx>
56 using namespace ::com::sun::star
;
57 using namespace ::com::sun::star::uno
;
58 using namespace ::com::sun::star::frame
;
60 void Shell::ExecuteCurrent( SfxRequest
& rReq
)
65 switch ( rReq
.GetSlot() )
67 case SID_BASICIDE_HIDECURPAGE
:
70 RemoveWindow( pCurWin
, false );
73 case SID_BASICIDE_RENAMECURRENT
:
75 pTabBar
->StartEditMode( pTabBar
->GetCurPageId() );
80 if (!pCurWin
->HasActiveEditor())
82 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
83 SfxItemSet
const& rArgs
= *rReq
.GetArgs();
84 // unfortunately I don't know the ID:
85 sal_uInt16 nWhich
= rArgs
.GetWhichByPos( 0 );
86 DBG_ASSERT( nWhich
, "Wich fuer SearchItem ?" );
87 SfxPoolItem
const& rItem
= rArgs
.Get(nWhich
);
88 DBG_ASSERT(dynamic_cast<SvxSearchItem
const*>(&rItem
), "no searchitem!");
89 SvxSearchItem
const& rSearchItem
= static_cast<SvxSearchItem
const&>(rItem
);
90 // memorize item because of the adjustments...
91 GetExtraData()->SetSearchItem(rSearchItem
);
93 bool bCanceled
= false;
94 if (rSearchItem
.GetCommand() == SVX_SEARCHCMD_REPLACE_ALL
)
96 sal_uInt16 nActModWindows
= 0;
97 for (WindowTableIt it
= aWindowTable
.begin(); it
!= aWindowTable
.end(); ++it
)
99 BaseWindow
* pWin
= it
->second
;
100 if (pWin
->HasActiveEditor())
104 if ( nActModWindows
<= 1 || ( !rSearchItem
.GetSelection() && QueryBox( pCurWin
, WB_YES_NO
|WB_DEF_YES
, String(IDEResId(RID_STR_SEARCHALLMODULES
)) ).Execute() == RET_YES
) )
106 for (WindowTableIt it
= aWindowTable
.begin(); it
!= aWindowTable
.end(); ++it
)
108 BaseWindow
* pWin
= it
->second
;
109 nFound
+= pWin
->StartSearchAndReplace(rSearchItem
);
113 nFound
= pCurWin
->StartSearchAndReplace(rSearchItem
);
115 OUString
aReplStr(IDE_RESSTR(RID_STR_SEARCHREPLACES
));
116 aReplStr
= aReplStr
.replaceAll("XX", OUString::valueOf(nFound
));
117 InfoBox( pCurWin
, aReplStr
).Execute();
121 nFound
= pCurWin
->StartSearchAndReplace(rSearchItem
);
122 if ( !nFound
&& !rSearchItem
.GetSelection() )
124 // search other modules...
125 bool bChangeCurWindow
= false;
127 for (it
= aWindowTable
.begin(); it
!= aWindowTable
.end(); ++it
)
128 if (it
->second
== pCurWin
)
130 if (it
!= aWindowTable
.end())
132 BaseWindow
* pWin
= it
!= aWindowTable
.end() ? it
->second
: 0;
134 bool bSearchedFromStart
= false;
135 while ( !nFound
&& !bCanceled
&& ( pWin
|| !bSearchedFromStart
) )
139 SfxViewFrame
* pViewFrame
= GetViewFrame();
140 SfxChildWindow
* pChildWin
= pViewFrame
? pViewFrame
->GetChildWindow( SID_SEARCH_DLG
) : NULL
;
141 Window
* pParent
= pChildWin
? pChildWin
->GetWindow() : NULL
;
142 QueryBox
aQuery(pParent
, WB_YES_NO
|WB_DEF_YES
, IDE_RESSTR(RID_STR_SEARCHFROMSTART
));
143 if ( aQuery
.Execute() == RET_YES
)
145 it
= aWindowTable
.begin();
146 if ( it
!= aWindowTable
.end() )
148 bSearchedFromStart
= true;
154 if (pWin
&& pWin
->HasActiveEditor())
156 if ( pWin
!= pCurWin
)
159 pWin
->SetSizePixel( pCurWin
->GetSizePixel() );
160 nFound
= pWin
->StartSearchAndReplace(rSearchItem
, true);
164 bChangeCurWindow
= true;
168 if ( pWin
&& ( pWin
!= pCurWin
) )
170 if ( it
!= aWindowTable
.end() )
172 pWin
= it
!= aWindowTable
.end() ? it
->second
: 0;
177 if ( !nFound
&& bSearchedFromStart
)
178 nFound
= pCurWin
->StartSearchAndReplace(rSearchItem
, true);
179 if ( bChangeCurWindow
)
180 SetCurWindow( pWin
, true );
182 if ( !nFound
&& !bCanceled
)
183 InfoBox( pCurWin
, String(IDEResId(RID_STR_SEARCHNOTFOUND
)) ).Execute();
191 if ( GetUndoManager() && pCurWin
->AllowUndo() )
192 GetViewFrame()->ExecuteSlot( rReq
);
195 pCurWin
->ExecuteCommand( rReq
);
199 // no matter who's at the top, influence on the shell:
200 void Shell::ExecuteGlobal( SfxRequest
& rReq
)
202 sal_uInt16 nSlot
= rReq
.GetSlot();
207 // maybe do not simply stop if on breakpoint!
208 if (ModulWindow
* pMCurWin
= dynamic_cast<ModulWindow
*>(pCurWin
))
209 pMCurWin
->BasicStop();
218 // rewrite date into the BASIC
219 StoreAllWindowData();
222 ScriptDocument
aDocument( pCurWin
->GetDocument() );
223 if ( aDocument
.isDocument() )
225 uno::Reference
< task::XStatusIndicator
> xStatusIndicator
;
227 SFX_REQUEST_ARG( rReq
, pStatusIndicatorItem
, SfxUnoAnyItem
,
228 SID_PROGRESS_STATUSBAR_CONTROL
, false );
229 if ( pStatusIndicatorItem
)
230 OSL_VERIFY( pStatusIndicatorItem
->GetValue() >>= xStatusIndicator
);
233 // get statusindicator
234 SfxViewFrame
*pFrame_
= GetFrame();
237 uno::Reference
< task::XStatusIndicatorFactory
> xStatFactory(
238 pFrame_
->GetFrame().GetFrameInterface(),
240 if( xStatFactory
.is() )
241 xStatusIndicator
= xStatFactory
->createStatusIndicator();
244 if ( xStatusIndicator
.is() )
245 rReq
.AppendItem( SfxUnoAnyItem( SID_PROGRESS_STATUSBAR_CONTROL
, uno::makeAny( xStatusIndicator
) ) );
248 aDocument
.saveDocument( xStatusIndicator
);
251 if (SfxBindings
* pBindings
= GetBindingsPtr())
253 pBindings
->Invalidate( SID_DOC_MODIFIED
);
254 pBindings
->Invalidate( SID_SAVEDOC
);
255 pBindings
->Invalidate( SID_SIGNATURE
);
260 case SID_BASICIDE_MODULEDLG
:
262 if ( rReq
.GetArgs() )
264 const SfxUInt16Item
&rTabId
= (const SfxUInt16Item
&)rReq
.GetArgs()->Get(SID_BASICIDE_ARG_TABID
);
265 Organize( rTabId
.GetValue() );
271 case SID_BASICIDE_CHOOSEMACRO
:
273 ChooseMacro( NULL
, false, OUString() );
276 case SID_BASICIDE_CREATEMACRO
:
277 case SID_BASICIDE_EDITMACRO
:
279 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
280 const SfxMacroInfoItem
& rInfo
= (const SfxMacroInfoItem
&)rReq
.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO
);
281 BasicManager
* pBasMgr
= (BasicManager
*)rInfo
.GetBasicManager();
282 DBG_ASSERT( pBasMgr
, "Nichts selektiert im Basic-Baum ?" );
284 ScriptDocument
aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr
) );
286 StartListening( *pBasMgr
, true /* log on only once */ );
287 OUString
aLibName( rInfo
.GetLib() );
288 if ( aLibName
.isEmpty() )
289 aLibName
= "Standard" ;
290 StarBASIC
* pBasic
= pBasMgr
->GetLib( aLibName
);
293 // load module and dialog library (if not loaded)
294 aDocument
.loadLibraryIfExists( E_SCRIPTS
, aLibName
);
295 aDocument
.loadLibraryIfExists( E_DIALOGS
, aLibName
);
298 pBasic
= pBasMgr
->GetLib( aLibName
);
300 DBG_ASSERT( pBasic
, "No Basic!" );
302 SetCurLib( aDocument
, aLibName
);
304 if ( pBasic
&& rReq
.GetSlot() == SID_BASICIDE_CREATEMACRO
)
306 SbModule
* pModule
= pBasic
->FindModule( rInfo
.GetModule() );
309 if ( rInfo
.GetModule().Len() || !pBasic
->GetModules()->Count() )
311 OUString aModName
= rInfo
.GetModule();
313 OUString sModuleCode
;
314 if ( aDocument
.createModule( aLibName
, aModName
, false, sModuleCode
) )
315 pModule
= pBasic
->FindModule( aModName
);
318 pModule
= (SbModule
*) pBasic
->GetModules()->Get(0);
320 DBG_ASSERT( pModule
, "Kein Modul!" );
321 if ( pModule
&& !pModule
->GetMethods()->Find( rInfo
.GetMethod(), SbxCLASS_METHOD
) )
322 CreateMacro( pModule
, rInfo
.GetMethod() );
324 SfxViewFrame
* pViewFrame
= GetViewFrame();
327 ModulWindow
* pWin
= FindBasWin( aDocument
, aLibName
, rInfo
.GetModule(), true );
328 DBG_ASSERT( pWin
, "Edit/Create Macro: Fenster wurde nicht erzeugt/gefunden!" );
329 SetCurWindow( pWin
, true );
330 pWin
->EditMacro( rInfo
.GetMethod() );
334 case SID_BASICIDE_OBJCAT
:
335 // toggling object catalog
336 aObjectCatalog
.Show(!aObjectCatalog
.IsVisible());
338 pLayout
->ArrangeWindows();
339 // refresh the button state
340 if (SfxBindings
* pBindings
= GetBindingsPtr())
341 pBindings
->Invalidate(SID_BASICIDE_OBJCAT
);
344 case SID_BASICIDE_NAMECHANGEDONTAB
:
346 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
347 const SfxUInt16Item
&rTabId
= (const SfxUInt16Item
&)rReq
.GetArgs()->Get(SID_BASICIDE_ARG_TABID
);
348 const SfxStringItem
&rModName
= (const SfxStringItem
&)rReq
.GetArgs()->Get(SID_BASICIDE_ARG_MODULENAME
);
349 if ( aWindowTable
.find( rTabId
.GetValue() ) != aWindowTable
.end() )
351 BaseWindow
* pWin
= aWindowTable
[ rTabId
.GetValue() ];
352 OUString
aNewName( rModName
.GetValue() );
353 OUString
aOldName( pWin
->GetName() );
354 if ( aNewName
!= aOldName
)
356 bool bRenameOk
= false;
357 if (ModulWindow
* pModWin
= dynamic_cast<ModulWindow
*>(pWin
))
359 OUString aLibName
= pModWin
->GetLibName();
360 ScriptDocument
aDocument( pWin
->GetDocument() );
362 if (RenameModule(pModWin
, aDocument
, aLibName
, aOldName
, aNewName
))
365 // Because we listen for container events for script
366 // modules, rename will delete the 'old' window
367 // pWin has been invalidated, restore now
368 pWin
= FindBasWin( aDocument
, aLibName
, aNewName
, true );
372 else if (DialogWindow
* pDlgWin
= dynamic_cast<DialogWindow
*>(pWin
))
374 bRenameOk
= pDlgWin
->RenameDialog( aNewName
);
378 MarkDocumentModified( pWin
->GetDocument() );
382 // set old name in TabWriter
383 sal_uInt16 nId
= GetWindowId( pWin
);
384 DBG_ASSERT( nId
, "No entry in Tabbar!" );
386 pTabBar
->SetPageText( nId
, aOldName
);
390 // set focus to current window
395 case SID_BASICIDE_STOREMODULESOURCE
:
396 case SID_BASICIDE_UPDATEMODULESOURCE
:
398 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
399 const SfxMacroInfoItem
& rInfo
= (const SfxMacroInfoItem
&)rReq
.GetArgs()->Get(SID_BASICIDE_ARG_MACROINFO
);
400 BasicManager
* pBasMgr
= (BasicManager
*)rInfo
.GetBasicManager();
401 DBG_ASSERT( pBasMgr
, "Store source: Kein BasMgr?" );
402 ScriptDocument
aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr
) );
403 ModulWindow
* pWin
= FindBasWin( aDocument
, rInfo
.GetLib(), rInfo
.GetModule(), false, true );
406 if ( rReq
.GetSlot() == SID_BASICIDE_STOREMODULESOURCE
)
413 case SID_BASICIDE_STOREALLMODULESOURCES
:
414 case SID_BASICIDE_UPDATEALLMODULESOURCES
:
416 for (WindowTableIt it
= aWindowTable
.begin(); it
!= aWindowTable
.end(); ++it
)
418 BaseWindow
* pWin
= it
->second
;
419 if (!pWin
->IsSuspended() && dynamic_cast<ModulWindow
*>(pWin
))
421 if ( rReq
.GetSlot() == SID_BASICIDE_STOREALLMODULESOURCES
)
429 case SID_BASICIDE_LIBSELECTED
:
430 case SID_BASICIDE_LIBREMOVED
:
431 case SID_BASICIDE_LIBLOADED
:
433 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
434 const SfxUsrAnyItem
& rShellItem
= (const SfxUsrAnyItem
&)rReq
.GetArgs()->Get( SID_BASICIDE_ARG_DOCUMENT_MODEL
);
435 uno::Reference
< frame::XModel
> xModel( rShellItem
.GetValue(), UNO_QUERY
);
436 ScriptDocument
aDocument( xModel
.is() ? ScriptDocument( xModel
) : ScriptDocument::getApplicationScriptDocument() );
437 const SfxStringItem
& rLibNameItem
= (const SfxStringItem
&)rReq
.GetArgs()->Get( SID_BASICIDE_ARG_LIBNAME
);
438 OUString
aLibName( rLibNameItem
.GetValue() );
440 if ( nSlot
== SID_BASICIDE_LIBSELECTED
)
442 // load module and dialog library (if not loaded)
443 aDocument
.loadLibraryIfExists( E_SCRIPTS
, aLibName
);
444 aDocument
.loadLibraryIfExists( E_DIALOGS
, aLibName
);
446 // check password, if library is password protected and not verified
448 Reference
< script::XLibraryContainer
> xModLibContainer( aDocument
.getLibraryContainer( E_SCRIPTS
) );
449 if ( xModLibContainer
.is() && xModLibContainer
->hasByName( aLibName
) )
451 Reference
< script::XLibraryContainerPassword
> xPasswd( xModLibContainer
, UNO_QUERY
);
452 if ( xPasswd
.is() && xPasswd
->isLibraryPasswordProtected( aLibName
) && !xPasswd
->isLibraryPasswordVerified( aLibName
) )
455 bOK
= QueryPassword( xModLibContainer
, aLibName
, aPassword
);
461 SetCurLib( aDocument
, aLibName
, true, false );
465 // adjust old value...
466 if (SfxBindings
* pBindings
= GetBindingsPtr())
467 pBindings
->Invalidate(SID_BASICIDE_LIBSELECTOR
, true, false);
470 else if ( nSlot
== SID_BASICIDE_LIBREMOVED
)
472 if ( m_aCurLibName
.isEmpty() || ( aDocument
== m_aCurDocument
&& aLibName
== m_aCurLibName
) )
474 RemoveWindows( aDocument
, aLibName
, true );
475 if ( aDocument
== m_aCurDocument
&& aLibName
== m_aCurLibName
)
477 m_aCurDocument
= ScriptDocument::getApplicationScriptDocument();
478 m_aCurLibName
= String();
480 if (SfxBindings
* pBindings
= GetBindingsPtr())
481 pBindings
->Invalidate( SID_BASICIDE_LIBSELECTOR
);
489 case SID_BASICIDE_NEWMODULE
:
491 ModulWindow
* pWin
= CreateBasWin( m_aCurDocument
, m_aCurLibName
, String() );
492 DBG_ASSERT( pWin
, "New Module: Konnte Fenster nicht erzeugen!" );
493 SetCurWindow( pWin
, true );
496 case SID_BASICIDE_NEWDIALOG
:
498 DialogWindow
* pWin
= CreateDlgWin( m_aCurDocument
, m_aCurLibName
, String() );
499 DBG_ASSERT( pWin
, "New Module: Konnte Fenster nicht erzeugen!" );
500 SetCurWindow( pWin
, true );
503 case SID_BASICIDE_SBXRENAMED
:
505 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
508 case SID_BASICIDE_SBXINSERTED
:
510 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
511 const SbxItem
& rSbxItem
= (const SbxItem
&)rReq
.GetArgs()->Get(SID_BASICIDE_ARG_SBX
);
512 ScriptDocument
aDocument( rSbxItem
.GetDocument() );
513 OUString
aLibName( rSbxItem
.GetLibName() );
514 OUString
aName( rSbxItem
.GetName() );
515 if ( m_aCurLibName
.isEmpty() || ( aDocument
== m_aCurDocument
&& aLibName
== m_aCurLibName
) )
517 if ( rSbxItem
.GetType() == TYPE_MODULE
)
518 FindBasWin( aDocument
, aLibName
, aName
, true );
519 else if ( rSbxItem
.GetType() == TYPE_DIALOG
)
520 FindDlgWin( aDocument
, aLibName
, aName
, true );
524 case SID_BASICIDE_SBXDELETED
:
526 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
527 const SbxItem
& rSbxItem
= (const SbxItem
&)rReq
.GetArgs()->Get(SID_BASICIDE_ARG_SBX
);
528 ScriptDocument
aDocument( rSbxItem
.GetDocument() );
529 BaseWindow
* pWin
= FindWindow( aDocument
, rSbxItem
.GetLibName(), rSbxItem
.GetName(), rSbxItem
.GetType(), true );
531 RemoveWindow( pWin
, true );
534 case SID_BASICIDE_SHOWSBX
:
536 DBG_ASSERT( rReq
.GetArgs(), "arguments expected" );
537 const SbxItem
& rSbxItem
= (const SbxItem
&)rReq
.GetArgs()->Get(SID_BASICIDE_ARG_SBX
);
538 ScriptDocument
aDocument( rSbxItem
.GetDocument() );
539 OUString
aLibName( rSbxItem
.GetLibName() );
540 OUString
aName( rSbxItem
.GetName() );
541 SetCurLib( aDocument
, aLibName
);
542 BaseWindow
* pWin
= 0;
543 if ( rSbxItem
.GetType() == TYPE_DIALOG
)
545 pWin
= FindDlgWin( aDocument
, aLibName
, aName
, true );
547 else if ( rSbxItem
.GetType() == TYPE_MODULE
)
549 pWin
= FindBasWin( aDocument
, aLibName
, aName
, true );
551 else if ( rSbxItem
.GetType() == TYPE_METHOD
)
553 pWin
= FindBasWin( aDocument
, aLibName
, aName
, true );
554 static_cast<ModulWindow
*>(pWin
)->EditMacro( rSbxItem
.GetMethodName() );
556 DBG_ASSERT( pWin
, "Fenster wurde nicht erzeugt!" );
557 SetCurWindow( pWin
, true );
558 pTabBar
->MakeVisible( pTabBar
->GetCurPageId() );
561 case SID_BASICIDE_SHOWWINDOW
:
563 ::std::auto_ptr
< ScriptDocument
> pDocument
;
565 SFX_REQUEST_ARG( rReq
, pDocumentItem
, SfxStringItem
, SID_BASICIDE_ARG_DOCUMENT
, false );
568 OUString sDocumentCaption
= pDocumentItem
->GetValue();
569 if ( !sDocumentCaption
.isEmpty() )
570 pDocument
.reset( new ScriptDocument( ScriptDocument::getDocumentWithURLOrCaption( sDocumentCaption
) ) );
573 SFX_REQUEST_ARG( rReq
, pDocModelItem
, SfxUsrAnyItem
, SID_BASICIDE_ARG_DOCUMENT_MODEL
, false );
574 if ( !pDocument
.get() && pDocModelItem
)
576 uno::Reference
< frame::XModel
> xModel( pDocModelItem
->GetValue(), UNO_QUERY
);
578 pDocument
.reset( new ScriptDocument( xModel
) );
581 if ( !pDocument
.get() )
584 SFX_REQUEST_ARG( rReq
, pLibNameItem
, SfxStringItem
, SID_BASICIDE_ARG_LIBNAME
, false );
588 OUString
aLibName( pLibNameItem
->GetValue() );
589 pDocument
->loadLibraryIfExists( E_SCRIPTS
, aLibName
);
590 SetCurLib( *pDocument
, aLibName
);
591 SFX_REQUEST_ARG( rReq
, pNameItem
, SfxStringItem
, SID_BASICIDE_ARG_NAME
, false );
594 OUString
aName( pNameItem
->GetValue() );
595 OUString
aModType( "Module" );
596 OUString
aDlgType( "Dialog" );
597 OUString
aType( aModType
);
598 SFX_REQUEST_ARG( rReq
, pTypeItem
, SfxStringItem
, SID_BASICIDE_ARG_TYPE
, false );
600 aType
= pTypeItem
->GetValue();
602 BaseWindow
* pWin
= 0;
603 if ( aType
== aModType
)
604 pWin
= FindBasWin( *pDocument
, aLibName
, aName
, false );
605 else if ( aType
== aDlgType
)
606 pWin
= FindDlgWin( *pDocument
, aLibName
, aName
, false );
610 SetCurWindow( pWin
, true );
612 pTabBar
->MakeVisible( pTabBar
->GetCurPageId() );
614 if (ModulWindow
* pModWin
= dynamic_cast<ModulWindow
*>(pWin
))
616 SFX_REQUEST_ARG( rReq
, pLineItem
, SfxUInt32Item
, SID_BASICIDE_ARG_LINE
, false );
619 pModWin
->AssertValidEditEngine();
620 TextView
* pTextView
= pModWin
->GetEditView();
623 TextEngine
* pTextEngine
= pTextView
->GetTextEngine();
626 sal_uInt32 nLine
= pLineItem
->GetValue();
627 sal_uInt32 nLineCount
= 0;
628 for ( sal_uInt32 i
= 0, nCount
= pTextEngine
->GetParagraphCount(); i
< nCount
; ++i
)
629 nLineCount
+= pTextEngine
->GetLineCount( i
);
630 if ( nLine
> nLineCount
)
635 // scroll window and set selection
636 long nVisHeight
= pModWin
->GetOutputSizePixel().Height();
637 long nTextHeight
= pTextEngine
->GetTextHeight();
638 if ( nTextHeight
> nVisHeight
)
640 long nMaxY
= nTextHeight
- nVisHeight
;
641 long nOldY
= pTextView
->GetStartDocPos().Y();
642 long nNewY
= nLine
* pTextEngine
->GetCharHeight() - nVisHeight
/ 2;
643 nNewY
= ::std::min( nNewY
, nMaxY
);
644 pTextView
->Scroll( 0, -( nNewY
- nOldY
) );
645 pTextView
->ShowCursor( false, true );
646 pModWin
->GetEditVScrollBar().SetThumbPos( pTextView
->GetStartDocPos().Y() );
648 sal_uInt16 nCol1
= 0, nCol2
= 0;
649 SFX_REQUEST_ARG( rReq
, pCol1Item
, SfxUInt16Item
, SID_BASICIDE_ARG_COLUMN1
, false );
652 nCol1
= pCol1Item
->GetValue();
657 SFX_REQUEST_ARG( rReq
, pCol2Item
, SfxUInt16Item
, SID_BASICIDE_ARG_COLUMN2
, false );
660 nCol2
= pCol2Item
->GetValue();
664 TextSelection
aSel( TextPaM( nLine
, nCol1
), TextPaM( nLine
, nCol2
) );
665 pTextView
->SetSelection( aSel
);
666 pTextView
->ShowCursor();
667 Window
* pWindow_
= pTextView
->GetWindow();
669 pWindow_
->GrabFocus();
680 case SID_BASICIDE_MANAGE_LANG
:
682 ManageLanguageDialog
aDlg(pCurWin
, m_pCurLocalizationMgr
);
690 pLayout
->ExecuteGlobal(rReq
);
692 pCurWin
->ExecuteGlobal(rReq
);
697 void Shell::GetState(SfxItemSet
&rSet
)
699 SfxWhichIter
aIter(rSet
);
700 for ( sal_uInt16 nWh
= aIter
.FirstWhich(); 0 != nWh
; nWh
= aIter
.NextWhich() )
706 rSet
.DisableItem( nWh
);
711 bool bDisable
= false;
715 if ( !pCurWin
->IsModified() )
717 ScriptDocument
aDocument( pCurWin
->GetDocument() );
718 bDisable
= ( !aDocument
.isAlive() )
719 || ( aDocument
.isDocument() ? !aDocument
.isDocumentModified() : !IsAppBasicModified() );
728 rSet
.DisableItem( nWh
);
734 rSet
.DisableItem( nWh
);
739 sal_uInt16 nState
= 0;
742 DocumentSignature
aSignature( pCurWin
->GetDocument() );
743 nState
= aSignature
.getScriptingSignatureState();
745 rSet
.Put( SfxUInt16Item( SID_SIGNATURE
, nState
) );
748 case SID_BASICIDE_MODULEDLG
:
750 if ( StarBASIC::IsRunning() )
751 rSet
.DisableItem( nWh
);
754 case SID_BASICIDE_OBJCAT
:
756 rSet
.Put(SfxBoolItem(nWh
, aObjectCatalog
.IsVisible()));
758 rSet
.Put(SfxVisibilityItem(nWh
, false));
760 case SID_BASICIDE_SHOWSBX
:
761 case SID_BASICIDE_CREATEMACRO
:
762 case SID_BASICIDE_EDITMACRO
:
763 case SID_BASICIDE_NAMECHANGEDONTAB
:
769 case SID_BASICIDE_ADDWATCH
:
770 case SID_BASICIDE_REMOVEWATCH
:
772 case SID_BASICSAVEAS
:
773 case SID_BASICIDE_MATCHGROUP
:
775 if (!dynamic_cast<ModulWindow
*>(pCurWin
))
776 rSet
.DisableItem( nWh
);
777 else if ( ( nWh
== SID_BASICLOAD
) && ( StarBASIC::IsRunning() || ( pCurWin
&& pCurWin
->IsReadOnly() ) ) )
778 rSet
.DisableItem( nWh
);
782 case SID_BASICSTEPINTO
:
783 case SID_BASICSTEPOVER
:
784 case SID_BASICSTEPOUT
:
785 case SID_BASICIDE_TOGGLEBRKPNT
:
786 case SID_BASICIDE_MANAGEBRKPNTS
:
788 if (ModulWindow
* pMCurWin
= dynamic_cast<ModulWindow
*>(pCurWin
))
790 if (StarBASIC::IsRunning() && !pMCurWin
->GetBasicStatus().bIsInReschedule
)
791 rSet
.DisableItem(nWh
);
794 rSet
.DisableItem( nWh
);
797 case SID_BASICCOMPILE
:
799 if (StarBASIC::IsRunning() || !dynamic_cast<ModulWindow
*>(pCurWin
))
800 rSet
.DisableItem( nWh
);
805 // stop is always possible when some Basic is running...
806 if (!StarBASIC::IsRunning())
807 rSet
.DisableItem( nWh
);
810 case SID_CHOOSE_CONTROLS
:
811 case SID_DIALOG_TESTMODE
:
812 case SID_INSERT_FORM_RADIO
:
813 case SID_INSERT_FORM_CHECK
:
814 case SID_INSERT_FORM_LIST
:
815 case SID_INSERT_FORM_COMBO
:
816 case SID_INSERT_FORM_VSCROLL
:
817 case SID_INSERT_FORM_HSCROLL
:
818 case SID_INSERT_FORM_SPIN
:
820 if (!dynamic_cast<DialogWindow
*>(pCurWin
))
821 rSet
.DisableItem( nWh
);
825 case SID_SHOW_HIDDEN
:
827 rSet
.DisableItem( nWh
);
830 case SID_SEARCH_OPTIONS
:
832 sal_uInt16 nOptions
= 0;
834 nOptions
= pCurWin
->GetSearchOptions();
835 rSet
.Put( SfxUInt16Item( SID_SEARCH_OPTIONS
, nOptions
) );
838 case SID_BASICIDE_LIBSELECTOR
:
841 if ( !m_aCurLibName
.isEmpty() )
843 LibraryLocation eLocation
= m_aCurDocument
.getLibraryLocation( m_aCurLibName
);
844 aName
= CreateMgrAndLibStr( m_aCurDocument
.getTitle( eLocation
), m_aCurLibName
);
846 SfxStringItem
aItem( SID_BASICIDE_LIBSELECTOR
, aName
);
850 case SID_SEARCH_ITEM
:
852 OUString aSelected
= GetSelectionText(true);
853 SvxSearchItem
& rItem
= GetExtraData()->GetSearchItem();
854 rItem
.SetSearchString( aSelected
);
858 case SID_BASICIDE_STAT_DATE
:
860 OUString
aDate( "Datum?!" );
861 SfxStringItem
aItem( SID_BASICIDE_STAT_DATE
, aDate
);
865 case SID_DOC_MODIFIED
:
867 bool bModified
= false;
871 if ( pCurWin
->IsModified() )
875 ScriptDocument
aDocument( pCurWin
->GetDocument() );
876 bModified
= aDocument
.isDocument() ? aDocument
.isDocumentModified() : IsAppBasicModified();
880 SfxBoolItem
aItem(SID_DOC_MODIFIED
, bModified
);
884 case SID_BASICIDE_STAT_TITLE
:
888 OUString aTitle
= pCurWin
->CreateQualifiedName();
889 SfxStringItem
aItem( SID_BASICIDE_STAT_TITLE
, aTitle
);
894 // are interpreted by the controller:
896 case SID_ATTR_INSERT
:
901 if( GetUndoManager() ) // recursive GetState else
902 GetViewFrame()->GetSlotState( nWh
, NULL
, &rSet
);
905 case SID_BASICIDE_CURRENT_LANG
:
907 if( (pCurWin
&& pCurWin
->IsReadOnly()) || GetCurLibName().isEmpty() )
908 rSet
.DisableItem( nWh
);
912 boost::shared_ptr
<LocalizationMgr
> pCurMgr(GetCurLocalizationMgr());
913 if ( pCurMgr
->isLibraryLocalized() )
915 Sequence
< lang::Locale
> aLocaleSeq
= pCurMgr
->getStringResourceManager()->getLocales();
916 const lang::Locale
* pLocale
= aLocaleSeq
.getConstArray();
917 sal_Int32 i
, nCount
= aLocaleSeq
.getLength();
919 // Force different results for any combination of locales and default locale
921 for ( i
= 0; i
<= nCount
; ++i
)
923 lang::Locale aLocale
;
925 aLocale
= pLocale
[i
];
927 aLocale
= pCurMgr
->getStringResourceManager()->getDefaultLocale();
929 aLangStr
+= aLocale
.Language
;
930 aLangStr
+= aLocale
.Country
;
931 aLangStr
+= aLocale
.Variant
;
935 rSet
.Put( SfxStringItem( nWh
, aItemStr
) );
940 case SID_BASICIDE_MANAGE_LANG
:
942 if( (pCurWin
&& pCurWin
->IsReadOnly()) || GetCurLibName().isEmpty() )
943 rSet
.DisableItem( nWh
);
948 // if this is not a module window hide the
949 // setting, doesn't make sense for example if the
950 // dialog editor is open
951 if (pCurWin
&& !dynamic_cast<ModulWindow
*>(pCurWin
))
953 rSet
.DisableItem( nWh
);
954 rSet
.Put(SfxVisibilityItem(nWh
, false));
960 pLayout
->GetState(rSet
, nWh
);
964 pCurWin
->GetState( rSet
);
967 sal_Bool
Shell::HasUIFeature( sal_uInt32 nFeature
)
969 bool bResult
= false;
971 if ( (nFeature
& BASICIDE_UI_FEATURE_SHOW_BROWSER
) == BASICIDE_UI_FEATURE_SHOW_BROWSER
)
973 // fade out (in) property browser in module (dialog) windows
974 if (dynamic_cast<DialogWindow
*>(pCurWin
) && !pCurWin
->IsReadOnly())
981 void Shell::SetCurWindow( BaseWindow
* pNewWin
, bool bUpdateTabBar
, bool bRememberAsCurrent
)
983 if ( pNewWin
!= pCurWin
)
987 pLayout
->Deactivating();
990 if (pCurWin
->GetType() == TYPE_MODULE
)
991 pLayout
= pModulLayout
.get();
993 pLayout
= pDialogLayout
.get();
994 AdjustPosSizePixel(Point(0, 0), GetViewFrame()->GetWindow().GetOutputSizePixel());
995 pLayout
->Activating(*pCurWin
);
996 GetViewFrame()->GetWindow().SetHelpId(pCurWin
->GetHid());
997 if (bRememberAsCurrent
)
998 pCurWin
->InsertLibInfo();
999 if (GetViewFrame()->GetWindow().IsVisible()) // SFX will do it later otherwise
1002 if (!GetExtraData()->ShellInCriticalSection())
1004 Window
* pFrameWindow
= &GetViewFrame()->GetWindow();
1005 Window
* pFocusWindow
= Application::GetFocusWindow();
1006 while ( pFocusWindow
&& ( pFocusWindow
!= pFrameWindow
) )
1007 pFocusWindow
= pFocusWindow
->GetParent();
1008 if ( pFocusWindow
) // Focus in BasicIDE
1009 pNewWin
->GrabFocus();
1017 if ( bUpdateTabBar
)
1019 sal_uLong nKey
= GetWindowId( pCurWin
);
1020 if ( pCurWin
&& ( pTabBar
->GetPagePos( (sal_uInt16
)nKey
) == TAB_PAGE_NOTFOUND
) )
1021 pTabBar
->InsertPage( (sal_uInt16
)nKey
, pCurWin
->GetTitle() ); // has just been faded in
1022 pTabBar
->SetCurPageId( (sal_uInt16
)nKey
);
1024 if ( pCurWin
&& pCurWin
->IsSuspended() ) // if the window is shown in the case of an error...
1025 pCurWin
->SetStatus( pCurWin
->GetStatus() & ~BASWIN_SUSPENDED
);
1028 SetWindow( pCurWin
);
1029 if ( pCurWin
->GetDocument().isDocument() )
1030 SfxObjectShell::SetCurrentComponent( pCurWin
->GetDocument().getDocument() );
1035 GetViewFrame()->GetWindow().SetHelpId( HID_BASICIDE_MODULWINDOW
);
1036 SfxObjectShell::SetCurrentComponent(0);
1038 aObjectCatalog
.SetCurrentEntry(pCurWin
);
1039 SetUndoManager( pCurWin
? pCurWin
->GetUndoManager() : 0 );
1040 InvalidateBasicIDESlots();
1041 EnableScrollbars(pCurWin
!= 0);
1043 if ( m_pCurLocalizationMgr
)
1044 m_pCurLocalizationMgr
->handleTranslationbar();
1048 // fade out (in) property browser in module (dialog) windows
1053 void Shell::ManageToolbars()
1055 static OUString
aLayoutManagerName( "LayoutManager" );
1056 static OUString
aMacroBarResName( "private:resource/toolbar/macrobar" );
1057 static OUString
aDialogBarResName( "private:resource/toolbar/dialogbar" );
1058 static OUString
aInsertControlsBarResName( "private:resource/toolbar/insertcontrolsbar" );
1059 static OUString
aFormControlsBarResName( "private:resource/toolbar/formcontrolsbar" );
1060 (void)aInsertControlsBarResName
;
1065 Reference
< beans::XPropertySet
> xFrameProps
1066 ( GetViewFrame()->GetFrame().GetFrameInterface(), uno::UNO_QUERY
);
1067 if ( xFrameProps
.is() )
1069 Reference
< ::com::sun::star::frame::XLayoutManager
> xLayoutManager
;
1070 uno::Any a
= xFrameProps
->getPropertyValue( aLayoutManagerName
);
1071 a
>>= xLayoutManager
;
1072 if ( xLayoutManager
.is() )
1074 xLayoutManager
->lock();
1075 if (dynamic_cast<DialogWindow
*>(pCurWin
))
1077 xLayoutManager
->destroyElement( aMacroBarResName
);
1079 xLayoutManager
->requestElement( aDialogBarResName
);
1080 xLayoutManager
->requestElement( aInsertControlsBarResName
);
1081 xLayoutManager
->requestElement( aFormControlsBarResName
);
1085 xLayoutManager
->destroyElement( aDialogBarResName
);
1086 xLayoutManager
->destroyElement( aInsertControlsBarResName
);
1087 xLayoutManager
->destroyElement( aFormControlsBarResName
);
1089 xLayoutManager
->requestElement( aMacroBarResName
);
1091 xLayoutManager
->unlock();
1096 BaseWindow
* Shell::FindApplicationWindow()
1098 return FindWindow( ScriptDocument::getApplicationScriptDocument() );
1101 BaseWindow
* Shell::FindWindow(
1102 ScriptDocument
const& rDocument
,
1103 OUString
const& rLibName
, OUString
const& rName
,
1104 ItemType eType
, bool bFindSuspended
1107 for (WindowTableIt it
= aWindowTable
.begin(); it
!= aWindowTable
.end(); ++it
)
1109 BaseWindow
* const pWin
= it
->second
;
1110 if (pWin
->Is(rDocument
, rLibName
, rName
, eType
, bFindSuspended
))
1116 long Shell::CallBasicErrorHdl( StarBASIC
* pBasic
)
1119 ModulWindow
* pModWin
= ShowActiveModuleWindow( pBasic
);
1121 nRet
= pModWin
->BasicErrorHdl( pBasic
);
1125 long Shell::CallBasicBreakHdl( StarBASIC
* pBasic
)
1128 ModulWindow
* pModWin
= ShowActiveModuleWindow( pBasic
);
1131 bool bAppWindowDisabled
, bDispatcherLocked
;
1132 sal_uInt16 nWaitCount
;
1133 SfxUInt16Item
*pSWActionCount
, *pSWLockViewCount
;
1134 BasicStopped( &bAppWindowDisabled
, &bDispatcherLocked
,
1135 &nWaitCount
, &pSWActionCount
, &pSWLockViewCount
);
1137 nRet
= pModWin
->BasicBreakHdl( pBasic
);
1139 if ( StarBASIC::IsRunning() ) // if cancelled...
1141 if ( bAppWindowDisabled
)
1142 Application::GetDefDialogParent()->Enable(false);
1146 Shell
* pShell
= GetShell();
1147 for ( sal_uInt16 n
= 0; n
< nWaitCount
; n
++ )
1148 pShell
->GetViewFrame()->GetWindow().EnterWait();
1155 ModulWindow
* Shell::ShowActiveModuleWindow( StarBASIC
* pBasic
)
1157 SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
1159 SbModule
* pActiveModule
= StarBASIC::GetActiveModule();
1160 if (SbClassModuleObject
* pCMO
= dynamic_cast<SbClassModuleObject
*>(pActiveModule
))
1161 pActiveModule
= pCMO
->getClassModule();
1163 DBG_ASSERT( pActiveModule
, "Kein aktives Modul im ErrorHdl?!" );
1164 if ( pActiveModule
)
1166 ModulWindow
* pWin
= 0;
1167 SbxObject
* pParent
= pActiveModule
->GetParent();
1168 if (StarBASIC
* pLib
= dynamic_cast<StarBASIC
*>(pParent
))
1170 if (BasicManager
* pBasMgr
= FindBasicManager(pLib
))
1172 ScriptDocument
aDocument( ScriptDocument::getDocumentForBasicManager( pBasMgr
) );
1173 OUString aLibName
= pLib
->GetName();
1174 pWin
= FindBasWin( aDocument
, aLibName
, pActiveModule
->GetName(), true );
1175 DBG_ASSERT( pWin
, "Error/Step-Hdl: Fenster wurde nicht erzeugt/gefunden!" );
1176 SetCurLib( aDocument
, aLibName
);
1177 SetCurWindow( pWin
, true );
1181 DBG_ASSERT(false, "No BASIC!");
1182 if (BasicManager
* pBasicMgr
= FindBasicManager(pBasic
))
1183 StartListening( *pBasicMgr
, true /* log on only once */ );
1189 void Shell::AdjustPosSizePixel( const Point
&rPos
, const Size
&rSize
)
1191 // not if iconified because the whole text would be displaced then at restore
1192 if ( GetViewFrame()->GetWindow().GetOutputSizePixel().Height() == 0 )
1196 Size
aScrollBarBoxSz( aScrollBarBox
.GetSizePixel() );
1197 aSz
.Height() -= aScrollBarBoxSz
.Height();
1200 aSz
.Width() -= aScrollBarBoxSz
.Width();
1201 aScrollBarBox
.SetPosPixel( Point( rSize
.Width() - aScrollBarBoxSz
.Width(), rSize
.Height() - aScrollBarBoxSz
.Height() ) );
1202 aVScrollBar
.SetPosSizePixel( Point( rPos
.X()+aSz
.Width(), rPos
.Y() ), Size( aScrollBarBoxSz
.Width(), aSz
.Height() ) );
1203 if ( bTabBarSplitted
)
1205 // SplitSize is 0 at a resize!
1206 long nSplitPos
= pTabBar
->GetSizePixel().Width();
1207 if ( nSplitPos
> aSz
.Width() )
1208 nSplitPos
= aSz
.Width();
1209 pTabBar
->SetPosSizePixel( Point( rPos
.X(), rPos
.Y()+aSz
.Height() ), Size( nSplitPos
, aScrollBarBoxSz
.Height() ) );
1210 long nScrlStart
= rPos
.X() + nSplitPos
;
1211 aHScrollBar
.SetPosSizePixel( Point( nScrlStart
, rPos
.Y()+aSz
.Height() ), Size( aSz
.Width() - nScrlStart
+ 1, aScrollBarBoxSz
.Height() ) );
1212 aHScrollBar
.Update();
1216 aHScrollBar
.SetPosSizePixel( Point( rPos
.X()+ aSz
.Width()/2 - 1, rPos
.Y()+aSz
.Height() ), Size( aSz
.Width()/2 + 2, aScrollBarBoxSz
.Height() ) );
1217 pTabBar
->SetPosSizePixel( Point( rPos
.X(), rPos
.Y()+aSz
.Height() ), Size( aSz
.Width()/2, aScrollBarBoxSz
.Height() ) );
1221 pLayout
->SetPosSizePixel(rPos
, dynamic_cast<DialogWindow
*>(pCurWin
) ? aSz
: aOutSz
);
1224 Reference
< XModel
> Shell::GetCurrentDocument() const
1226 Reference
< XModel
> xDocument
;
1227 if ( pCurWin
&& pCurWin
->GetDocument().isDocument() )
1228 xDocument
= pCurWin
->GetDocument().getDocument();
1232 void Shell::Activate( sal_Bool bMDI
)
1234 SfxViewShell::Activate( bMDI
);
1238 if (DialogWindow
* pDCurWin
= dynamic_cast<DialogWindow
*>(pCurWin
))
1239 pDCurWin
->UpdateBrowser();
1243 void Shell::Deactivate( sal_Bool bMDI
)
1245 // bMDI == true means that another MDI has been activated; in case of a
1246 // deactivate due to a MessageBox bMDI is false
1249 if (DialogWindow
* pXDlgWin
= dynamic_cast<DialogWindow
*>(pCurWin
))
1251 pXDlgWin
->DisableBrowser();
1252 if( pXDlgWin
->IsModified() )
1253 MarkDocumentModified( pXDlgWin
->GetDocument() );
1256 // test CanClose to also test during deactivating the BasicIDE whether
1257 // the sourcecode is too large in one of the modules...
1258 for (WindowTableIt it
= aWindowTable
.begin(); it
!= aWindowTable
.end(); ++it
)
1260 BaseWindow
* pWin
= it
->second
;
1261 if ( /* !pWin->IsSuspended() && */ !pWin
->CanClose() )
1263 if ( !m_aCurLibName
.isEmpty() && ( pWin
->IsDocument( m_aCurDocument
) || pWin
->GetLibName() != m_aCurLibName
) )
1264 SetCurLib( ScriptDocument::getApplicationScriptDocument(), OUString(), false );
1265 SetCurWindow( pWin
, true );
1272 } // namespace basctl
1274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */