1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bastypes.cxx,v $
10 * $Revision: 1.32.30.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_basctl.hxx"
38 #include <ide_pch.hxx>
41 #include <basic/sbx.hxx>
43 #include <basidesh.hrc>
44 #include <bastypes.hxx>
45 #include <bastype2.hxx>
46 #include <baside2.hxx> // Leider brauche ich teilweise pModulWindow...
47 #include <baside3.hxx>
48 #include <baside2.hrc>
49 #include <svtools/textview.hxx>
50 #include <svtools/texteng.hxx>
52 #include <sbxitem.hxx>
53 #include <iderdll.hxx>
55 #ifndef _PASSWD_HXX //autogen
56 #include <sfx2/passwd.hxx>
59 #ifndef _COM_SUN_STAR_SCRIPT_XLIBRYARYCONTAINER2_HPP_
60 #include <com/sun/star/script/XLibraryContainer2.hpp>
62 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
63 #include <com/sun/star/script/ModuleType.hpp>
65 using namespace ::com::sun::star::uno
;
66 using namespace ::com::sun::star
;
69 DBG_NAME( IDEBaseWindow
)
71 const char* pRegName
= "BasicIDETabBar";
73 TYPEINIT0( IDEBaseWindow
)
74 TYPEINIT1( SbxItem
, SfxPoolItem
);
76 IDEBaseWindow::IDEBaseWindow( Window
* pParent
, const ScriptDocument
& rDocument
, String aLibName
, String aName
)
77 :Window( pParent
, WinBits( WB_3DLOOK
) )
78 ,m_aDocument( rDocument
)
79 ,m_aLibName( aLibName
)
82 DBG_CTOR( IDEBaseWindow
, 0 );
90 __EXPORT
IDEBaseWindow::~IDEBaseWindow()
92 DBG_DTOR( IDEBaseWindow
, 0 );
93 if ( pShellVScrollBar
)
94 pShellVScrollBar
->SetScrollHdl( Link() );
95 if ( pShellHScrollBar
)
96 pShellHScrollBar
->SetScrollHdl( Link() );
101 void IDEBaseWindow::Init()
103 DBG_CHKTHIS( IDEBaseWindow
, 0 );
104 if ( pShellVScrollBar
)
105 pShellVScrollBar
->SetScrollHdl( LINK( this, IDEBaseWindow
, ScrollHdl
) );
106 if ( pShellHScrollBar
)
107 pShellHScrollBar
->SetScrollHdl( LINK( this, IDEBaseWindow
, ScrollHdl
) );
108 DoInit(); // virtuell...
113 void __EXPORT
IDEBaseWindow::DoInit()
119 void IDEBaseWindow::GrabScrollBars( ScrollBar
* pHScroll
, ScrollBar
* pVScroll
)
121 DBG_CHKTHIS( IDEBaseWindow
, 0 );
122 pShellHScrollBar
= pHScroll
;
123 pShellVScrollBar
= pVScroll
;
124 // Init(); // macht kein Sinn, fuehrt zu flackern, fuehr zu Fehlern...
129 IMPL_LINK_INLINE_START( IDEBaseWindow
, ScrollHdl
, ScrollBar
*, pCurScrollBar
)
131 DBG_CHKTHIS( IDEBaseWindow
, 0 );
132 DoScroll( pCurScrollBar
);
135 IMPL_LINK_INLINE_END( IDEBaseWindow
, ScrollHdl
, ScrollBar
*, pCurScrollBar
)
139 void __EXPORT
IDEBaseWindow::ExecuteCommand( SfxRequest
& )
141 DBG_CHKTHIS( IDEBaseWindow
, 0 );
146 void __EXPORT
IDEBaseWindow::GetState( SfxItemSet
& )
148 DBG_CHKTHIS( IDEBaseWindow
, 0 );
152 long IDEBaseWindow::Notify( NotifyEvent
& rNEvt
)
156 if ( rNEvt
.GetType() == EVENT_KEYINPUT
)
158 KeyEvent aKEvt
= *rNEvt
.GetKeyEvent();
159 KeyCode aCode
= aKEvt
.GetKeyCode();
160 USHORT nCode
= aCode
.GetCode();
167 if ( aCode
.IsMod1() )
169 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
171 pIDEShell
->NextPage( nCode
== KEY_PAGEUP
);
180 return nDone
? nDone
: Window::Notify( rNEvt
);
184 void __EXPORT
IDEBaseWindow::DoScroll( ScrollBar
* )
186 DBG_CHKTHIS( IDEBaseWindow
, 0 );
190 void __EXPORT
IDEBaseWindow::StoreData()
194 BOOL __EXPORT
IDEBaseWindow::CanClose()
199 BOOL __EXPORT
IDEBaseWindow::AllowUndo()
206 void __EXPORT
IDEBaseWindow::UpdateData()
212 void __EXPORT
IDEBaseWindow::PrintData( Printer
* )
218 String __EXPORT
IDEBaseWindow::GetTitle()
225 String
IDEBaseWindow::CreateQualifiedName()
228 if ( m_aLibName
.Len() )
230 LibraryLocation eLocation
= m_aDocument
.getLibraryLocation( m_aLibName
);
231 aName
= m_aDocument
.getTitle( eLocation
);
241 void IDEBaseWindow::SetReadOnly( BOOL
)
245 BOOL
IDEBaseWindow::IsReadOnly()
250 void __EXPORT
IDEBaseWindow::BasicStarted()
254 void __EXPORT
IDEBaseWindow::BasicStopped()
258 BOOL __EXPORT
IDEBaseWindow::IsModified()
263 BOOL __EXPORT
IDEBaseWindow::IsPasteAllowed()
268 Window
* __EXPORT
IDEBaseWindow::GetLayoutWindow()
273 SfxUndoManager
* __EXPORT
IDEBaseWindow::GetUndoManager()
278 BreakPointList::BreakPointList()
281 BreakPointList::BreakPointList(BreakPointList
const & rList
):
282 BreakPL( sal::static_int_cast
<USHORT
>( rList
.Count() ))
284 for (ULONG i
= 0; i
< rList
.Count(); ++i
)
285 Insert(new BreakPoint(*rList
.GetObject(i
)), i
);
288 BreakPointList::~BreakPointList()
293 void BreakPointList::reset()
296 delete Remove(Count() - 1);
299 void BreakPointList::transfer(BreakPointList
& rList
)
302 for (ULONG i
= 0; i
< rList
.Count(); ++i
)
303 Insert(rList
.GetObject(i
), i
);
307 void BreakPointList::InsertSorted( BreakPoint
* pNewBrk
)
309 BreakPoint
* pBrk
= First();
312 if ( pNewBrk
->nLine
<= pBrk
->nLine
)
314 DBG_ASSERT( ( pBrk
->nLine
!= pNewBrk
->nLine
) || pNewBrk
->bTemp
, "BreakPoint existiert schon!" );
320 // Keine Einfuegeposition gefunden => LIST_APPEND
321 Insert( pNewBrk
, LIST_APPEND
);
324 void BreakPointList::SetBreakPointsInBasic( SbModule
* pModule
)
326 pModule
->ClearAllBP();
328 BreakPoint
* pBrk
= First();
331 if ( pBrk
->bEnabled
)
332 pModule
->SetBP( (USHORT
)pBrk
->nLine
);
337 BreakPoint
* BreakPointList::FindBreakPoint( ULONG nLine
)
339 BreakPoint
* pBrk
= First();
342 if ( pBrk
->nLine
== nLine
)
348 return (BreakPoint
*)0;
353 void BreakPointList::AdjustBreakPoints( ULONG nLine
, BOOL bInserted
)
355 BreakPoint
* pBrk
= First();
358 BOOL bDelBrk
= FALSE
;
359 if ( pBrk
->nLine
== nLine
)
366 else if ( pBrk
->nLine
> nLine
)
376 ULONG n
= GetCurPos();
377 delete Remove( pBrk
);
387 void BreakPointList::ResetHitCount()
389 BreakPoint
* pBrk
= First();
397 void IDEBaseWindow::Deactivating()
401 USHORT __EXPORT
IDEBaseWindow::GetSearchOptions()
407 BasicDockingWindow::BasicDockingWindow( Window
* pParent
) :
408 DockingWindow( pParent
, WB_BORDER
| WB_3DLOOK
| WB_DOCKABLE
| WB_MOVEABLE
|
409 WB_SIZEABLE
| WB_ROLLABLE
|
410 WB_DOCKABLE
| WB_CLIPCHILDREN
)
416 BOOL __EXPORT
BasicDockingWindow::Docking( const Point
& rPos
, Rectangle
& rRect
)
418 ModulWindowLayout
* pLayout
= (ModulWindowLayout
*)GetParent();
419 Rectangle
aTmpRec( rRect
);
420 BOOL bDock
= IsDockingPrevented() ? FALSE
: pLayout
->IsToBeDocked( this, rPos
, aTmpRec
);
423 rRect
.SetSize( aTmpRec
.GetSize() );
425 else // Alte Groesse einstellen
427 if ( !aFloatingPosAndSize
.IsEmpty() )
428 rRect
.SetSize( aFloatingPosAndSize
.GetSize() );
430 return !bDock
; // bFloat
435 void __EXPORT
BasicDockingWindow::EndDocking( const Rectangle
& rRect
, BOOL bFloatMode
)
438 DockingWindow::EndDocking( rRect
, bFloatMode
);
441 SetFloatingMode( FALSE
);
442 ModulWindowLayout
* pLayout
= (ModulWindowLayout
*)GetParent();
443 pLayout
->DockaWindow( this );
449 void __EXPORT
BasicDockingWindow::ToggleFloatingMode()
451 ModulWindowLayout
* pLayout
= (ModulWindowLayout
*)GetParent();
452 if ( IsFloatingMode() )
454 if ( !aFloatingPosAndSize
.IsEmpty() )
455 SetPosSizePixel( GetParent()->ScreenToOutputPixel( aFloatingPosAndSize
.TopLeft() ),
456 aFloatingPosAndSize
.GetSize() );
458 pLayout
->DockaWindow( this );
463 BOOL __EXPORT
BasicDockingWindow::PrepareToggleFloatingMode()
465 if ( IsFloatingMode() )
467 // Position und Groesse auf dem Desktop merken...
468 aFloatingPosAndSize
.SetPos( GetParent()->OutputToScreenPixel( GetPosPixel() ) );
469 aFloatingPosAndSize
.SetSize( GetSizePixel() );
476 void __EXPORT
BasicDockingWindow::StartDocking()
478 // Position und Groesse auf dem Desktop merken...
479 if ( IsFloatingMode() )
481 aFloatingPosAndSize
.SetPos( GetParent()->OutputToScreenPixel( GetPosPixel() ) );
482 aFloatingPosAndSize
.SetSize( GetSizePixel() );
488 ExtendedEdit::ExtendedEdit( Window
* pParent
, IDEResId nRes
) :
489 Edit( pParent
, nRes
)
491 aAcc
.SetSelectHdl( LINK( this, ExtendedEdit
, EditAccHdl
) );
492 Control::SetGetFocusHdl( LINK( this, ExtendedEdit
, ImplGetFocusHdl
) );
493 Control::SetLoseFocusHdl( LINK( this, ExtendedEdit
, ImplLoseFocusHdl
) );
496 IMPL_LINK( ExtendedEdit
, ImplGetFocusHdl
, Control
*, EMPTYARG
)
498 Application::InsertAccel( &aAcc
);
499 aLoseFocusHdl
.Call( this );
504 IMPL_LINK( ExtendedEdit
, ImplLoseFocusHdl
, Control
*, EMPTYARG
)
506 Application::RemoveAccel( &aAcc
);
511 IMPL_LINK_INLINE_START( ExtendedEdit
, EditAccHdl
, Accelerator
*, pAcc
)
513 aAccHdl
.Call( pAcc
);
516 IMPL_LINK_INLINE_END( ExtendedEdit
, EditAccHdl
, Accelerator
*, pAcc
)
525 TabBarDDInfo() { npTabBar
= 0; nPage
= 0; }
526 TabBarDDInfo( ULONG _npTabBar
, USHORT _nPage
) { npTabBar
= _npTabBar
; nPage
= _nPage
; }
530 BasicIDETabBar::BasicIDETabBar( Window
* pParent
) :
531 TabBar( pParent
, WinBits( WB_3DLOOK
| WB_SCROLL
| WB_BORDER
| WB_SIZEABLE
| WB_DRAG
) )
533 EnableEditMode( TRUE
);
535 SetHelpId( HID_BASICIDE_TABBAR
);
538 void __EXPORT
BasicIDETabBar::MouseButtonDown( const MouseEvent
& rMEvt
)
540 if ( rMEvt
.IsLeft() && ( rMEvt
.GetClicks() == 2 ) && !IsInEditMode() )
542 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
543 SfxViewFrame
* pViewFrame
= pIDEShell
? pIDEShell
->GetViewFrame() : NULL
;
544 SfxDispatcher
* pDispatcher
= pViewFrame
? pViewFrame
->GetDispatcher() : NULL
;
547 pDispatcher
->Execute( SID_BASICIDE_MODULEDLG
);
552 TabBar::MouseButtonDown( rMEvt
);
556 void __EXPORT
BasicIDETabBar::Command( const CommandEvent
& rCEvt
)
558 if ( ( rCEvt
.GetCommand() == COMMAND_CONTEXTMENU
) && !IsInEditMode() )
560 Point
aPos( rCEvt
.IsMouseEvent() ? rCEvt
.GetMousePosPixel() : Point(1,1) );
561 if ( rCEvt
.IsMouseEvent() ) // Richtige Tab selektieren
563 Point aP
= PixelToLogic( aPos
);
564 MouseEvent
aMouseEvent( aP
, 1, MOUSE_SIMPLECLICK
, MOUSE_LEFT
);
565 TabBar::MouseButtonDown( aMouseEvent
);
568 PopupMenu
aPopup( IDEResId( RID_POPUP_TABBAR
) );
569 if ( GetPageCount() == 0 )
571 aPopup
.EnableItem( SID_BASICIDE_DELETECURRENT
, FALSE
);
572 aPopup
.EnableItem( SID_BASICIDE_RENAMECURRENT
, FALSE
);
573 aPopup
.EnableItem( SID_BASICIDE_HIDECURPAGE
, FALSE
);
576 if ( StarBASIC::IsRunning() )
578 aPopup
.EnableItem(SID_BASICIDE_DELETECURRENT
, false);
579 aPopup
.EnableItem( SID_BASICIDE_RENAMECURRENT
, false);
580 aPopup
.EnableItem(SID_BASICIDE_MODULEDLG
, false);
583 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
586 ScriptDocument
aDocument( pIDEShell
->GetCurDocument() );
587 ::rtl::OUString
aOULibName( pIDEShell
->GetCurLibName() );
588 Reference
< script::XLibraryContainer2
> xModLibContainer( aDocument
.getLibraryContainer( E_SCRIPTS
), UNO_QUERY
);
589 Reference
< script::XLibraryContainer2
> xDlgLibContainer( aDocument
.getLibraryContainer( E_DIALOGS
), UNO_QUERY
);
590 if ( ( xModLibContainer
.is() && xModLibContainer
->hasByName( aOULibName
) && xModLibContainer
->isLibraryReadOnly( aOULibName
) ) ||
591 ( xDlgLibContainer
.is() && xDlgLibContainer
->hasByName( aOULibName
) && xDlgLibContainer
->isLibraryReadOnly( aOULibName
) ) )
593 aPopup
.EnableItem( aPopup
.GetItemId( 0 ), FALSE
);
594 aPopup
.EnableItem( SID_BASICIDE_DELETECURRENT
, FALSE
);
595 aPopup
.EnableItem( SID_BASICIDE_RENAMECURRENT
, FALSE
);
596 aPopup
.RemoveDisabledEntries();
599 // disable to delete or remove object modules in IDE
600 BasicManager
* pBasMgr
= aDocument
.getBasicManager();
603 StarBASIC
* pBasic
= pBasMgr
->GetLib( aOULibName
);
606 IDEWindowTable
& aIDEWindowTable
= pIDEShell
->GetIDEWindowTable();
607 IDEBaseWindow
* pWin
= aIDEWindowTable
.Get( GetCurPageId() );
608 if( pWin
&& pWin
->ISA( ModulWindow
) )
610 SbModule
* pActiveModule
= (SbModule
*)pBasic
->FindModule( pWin
->GetName() );
611 if( pActiveModule
&& ( pActiveModule
->GetModuleType() == script::ModuleType::Document
) )
613 aPopup
.EnableItem( SID_BASICIDE_DELETECURRENT
, FALSE
);
614 aPopup
.EnableItem( SID_BASICIDE_RENAMECURRENT
, FALSE
);
622 SfxViewFrame
* pViewFrame
= pIDEShell
? pIDEShell
->GetViewFrame() : NULL
;
623 SfxDispatcher
* pDispatcher
= pViewFrame
? pViewFrame
->GetDispatcher() : NULL
;
625 pDispatcher
->Execute( aPopup
.Execute( this, aPos
) );
629 long BasicIDETabBar::AllowRenaming()
631 BOOL bValid
= BasicIDE::IsValidSbxName( GetEditText() );
634 ErrorBox( this, WB_OK
| WB_DEF_OK
, String( IDEResId( RID_STR_BADSBXNAME
) ) ).Execute();
636 return bValid
? TABBAR_RENAMING_YES
: TABBAR_RENAMING_NO
;
640 void __EXPORT
BasicIDETabBar::EndRenaming()
642 if ( !IsEditModeCanceled() )
644 SfxUInt16Item
aID( SID_BASICIDE_ARG_TABID
, GetEditPageId() );
645 SfxStringItem
aNewName( SID_BASICIDE_ARG_MODULENAME
, GetEditText() );
646 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
647 SfxViewFrame
* pViewFrame
= pIDEShell
? pIDEShell
->GetViewFrame() : NULL
;
648 SfxDispatcher
* pDispatcher
= pViewFrame
? pViewFrame
->GetDispatcher() : NULL
;
651 pDispatcher
->Execute( SID_BASICIDE_NAMECHANGEDONTAB
,
652 SFX_CALLMODE_SYNCHRON
, &aID
, &aNewName
, 0L );
658 void BasicIDETabBar::Sort()
660 BasicIDEShell
* pIDEShell
= IDE_DLL()->GetShell();
663 IDEWindowTable
& aIDEWindowTable
= pIDEShell
->GetIDEWindowTable();
664 TabBarSortHelper aTabBarSortHelper
;
665 ::std::vector
<TabBarSortHelper
> aModuleList
;
666 ::std::vector
<TabBarSortHelper
> aDialogList
;
667 USHORT nPageCount
= GetPageCount();
670 // create module and dialog lists for sorting
671 for ( i
= 0; i
< nPageCount
; i
++)
673 USHORT nId
= GetPageId( i
);
674 aTabBarSortHelper
.nPageId
= nId
;
675 aTabBarSortHelper
.aPageText
= GetPageText( nId
);
676 IDEBaseWindow
* pWin
= aIDEWindowTable
.Get( nId
);
678 if ( pWin
->IsA( TYPE( ModulWindow
) ) )
680 aModuleList
.push_back( aTabBarSortHelper
);
682 else if ( pWin
->IsA( TYPE( DialogWindow
) ) )
684 aDialogList
.push_back( aTabBarSortHelper
);
688 // sort module and dialog lists by page text
689 ::std::sort( aModuleList
.begin() , aModuleList
.end() );
690 ::std::sort( aDialogList
.begin() , aDialogList
.end() );
693 USHORT nModules
= sal::static_int_cast
<USHORT
>( aModuleList
.size() );
694 USHORT nDialogs
= sal::static_int_cast
<USHORT
>( aDialogList
.size() );
696 // move module pages to new positions
697 for (i
= 0; i
< nModules
; i
++)
699 MovePage( aModuleList
[i
].nPageId
, i
);
702 // move dialog pages to new positions
703 for (i
= 0; i
< nDialogs
; i
++)
705 MovePage( aDialogList
[i
].nPageId
, nModules
+ i
);
710 void CutLines( ::rtl::OUString
& rStr
, sal_Int32 nStartLine
, sal_Int32 nLines
, BOOL bEraseTrailingEmptyLines
)
712 sal_Int32 nStartPos
= 0;
713 sal_Int32 nEndPos
= 0;
715 while ( nLine
< nStartLine
)
717 nStartPos
= searchEOL( rStr
, nStartPos
);
718 if( nStartPos
== -1 )
720 nStartPos
++; // nicht das \n.
724 DBG_ASSERTWARNING( nStartPos
!= -1, "CutLines: Startzeile nicht gefunden!" );
726 if ( nStartPos
!= -1 )
729 for ( sal_Int32 i
= 0; i
< nLines
; i
++ )
730 nEndPos
= searchEOL( rStr
, nEndPos
+1 );
732 if ( nEndPos
== -1 ) // kann bei letzter Zeile passieren
733 nEndPos
= rStr
.getLength();
737 ::rtl::OUString aEndStr
= rStr
.copy( nEndPos
);
738 rStr
= rStr
.copy( 0, nStartPos
);
741 if ( bEraseTrailingEmptyLines
)
743 sal_Int32 n
= nStartPos
;
744 sal_Int32 nLen
= rStr
.getLength();
745 while ( ( n
< nLen
) && ( rStr
.getStr()[ n
] == LINE_SEP
||
746 rStr
.getStr()[ n
] == LINE_SEP_CR
) )
753 ::rtl::OUString aEndStr
= rStr
.copy( n
);
754 rStr
= rStr
.copy( 0, nStartPos
);
760 ULONG
CalcLineCount( SvStream
& rStream
)
768 while ( !rStream
.IsEof() )
772 else if ( c
== '\r' )
783 LibInfoKey::LibInfoKey( const ScriptDocument
& rDocument
, const String
& rLibName
)
784 :m_aDocument( rDocument
)
785 ,m_aLibName( rLibName
)
789 LibInfoKey::~LibInfoKey()
793 LibInfoKey::LibInfoKey( const LibInfoKey
& rKey
)
794 :m_aDocument( rKey
.m_aDocument
)
795 ,m_aLibName( rKey
.m_aLibName
)
799 LibInfoKey
& LibInfoKey::operator=( const LibInfoKey
& rKey
)
801 m_aDocument
= rKey
.m_aDocument
;
802 m_aLibName
= rKey
.m_aLibName
;
806 bool LibInfoKey::operator==( const LibInfoKey
& rKey
) const
809 if ( m_aDocument
== rKey
.m_aDocument
&& m_aLibName
== rKey
.m_aLibName
)
814 LibInfoItem::LibInfoItem( const ScriptDocument
& rDocument
, const String
& rLibName
, const String
& rCurrentName
, USHORT nCurrentType
)
815 :m_aDocument( rDocument
)
816 ,m_aLibName( rLibName
)
817 ,m_aCurrentName( rCurrentName
)
818 ,m_nCurrentType( nCurrentType
)
822 LibInfoItem::~LibInfoItem()
826 LibInfoItem::LibInfoItem( const LibInfoItem
& rItem
)
827 :m_aDocument( rItem
.m_aDocument
)
828 ,m_aLibName( rItem
.m_aLibName
)
829 ,m_aCurrentName( rItem
.m_aCurrentName
)
830 ,m_nCurrentType( rItem
.m_nCurrentType
)
834 LibInfoItem
& LibInfoItem::operator=( const LibInfoItem
& rItem
)
836 m_aDocument
= rItem
.m_aDocument
;
837 m_aLibName
= rItem
.m_aLibName
;
838 m_aCurrentName
= rItem
.m_aCurrentName
;
839 m_nCurrentType
= rItem
.m_nCurrentType
;
848 LibInfos::~LibInfos()
850 LibInfoMap::iterator end
= m_aLibInfoMap
.end();
851 for ( LibInfoMap::iterator it
= m_aLibInfoMap
.begin(); it
!= end
; ++it
)
853 m_aLibInfoMap
.clear();
856 void LibInfos::InsertInfo( LibInfoItem
* pItem
)
858 LibInfoKey
aKey( pItem
->GetDocument(), pItem
->GetLibName() );
859 LibInfoMap::iterator it
= m_aLibInfoMap
.find( aKey
);
860 if ( it
!= m_aLibInfoMap
.end() )
862 LibInfoItem
* pI
= it
->second
;
863 m_aLibInfoMap
.erase( it
);
866 m_aLibInfoMap
.insert( LibInfoMap::value_type( aKey
, pItem
) );
869 void LibInfos::RemoveInfoFor( const ScriptDocument
& _rDocument
)
871 for ( LibInfoMap::iterator it
= m_aLibInfoMap
.begin();
872 it
!= m_aLibInfoMap
.end();
875 if ( it
->first
.GetDocument() != _rDocument
)
881 LibInfoItem
* pItem
= it
->second
;
883 LibInfoMap::iterator next_it
= it
; ++next_it
;
884 m_aLibInfoMap
.erase( it
);
891 LibInfoItem
* LibInfos::GetInfo( const LibInfoKey
& rKey
)
893 LibInfoItem
* pItem
= 0;
894 LibInfoMap::iterator it
= m_aLibInfoMap
.find( rKey
);
895 if ( it
!= m_aLibInfoMap
.end() )
900 SbxItem::SbxItem(USHORT nWhich_
, const ScriptDocument
& rDocument
, const String
& aLibName
, const String
& aName
, USHORT nType
)
901 :SfxPoolItem( nWhich_
)
902 ,m_aDocument(rDocument
)
903 ,m_aLibName(aLibName
)
909 SbxItem::SbxItem(USHORT nWhich_
, const ScriptDocument
& rDocument
, const String
& aLibName
, const String
& aName
, const String
& aMethodName
, USHORT nType
)
910 :SfxPoolItem( nWhich_
)
911 ,m_aDocument(rDocument
)
912 ,m_aLibName(aLibName
)
914 ,m_aMethodName(aMethodName
)
919 SbxItem::SbxItem(const SbxItem
& rCopy
)
920 :SfxPoolItem( rCopy
)
921 ,m_aDocument( rCopy
.m_aDocument
)
923 m_aLibName
= rCopy
.m_aLibName
;
924 m_aName
= rCopy
.m_aName
;
925 m_aMethodName
= rCopy
.m_aMethodName
;
926 m_nType
= rCopy
.m_nType
;
929 int SbxItem::operator==( const SfxPoolItem
& rCmp
) const
931 DBG_ASSERT( rCmp
.ISA( SbxItem
), "==: Kein SbxItem!" );
932 return ( SfxPoolItem::operator==( rCmp
) && ( m_aDocument
== ((const SbxItem
&)rCmp
).m_aDocument
)
933 && ( m_aLibName
== ((const SbxItem
&)rCmp
).m_aLibName
)
934 && ( m_aName
== ((const SbxItem
&)rCmp
).m_aName
)
935 && ( m_aMethodName
== ((const SbxItem
&)rCmp
).m_aMethodName
)
936 && ( m_nType
== ((const SbxItem
&)rCmp
).m_nType
) );
939 SfxPoolItem
*SbxItem::Clone( SfxItemPool
* ) const
941 return new SbxItem(*this);
944 BOOL
QueryDel( const String
& rName
, const ResId
& rId
, Window
* pParent
)
946 String
aQuery( rId
);
947 String
aName( rName
);
949 aName
.Insert( '\'', 0 );
950 aQuery
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "XX" ) ), aName
);
951 QueryBox
aQueryBox( pParent
, WB_YES_NO
| WB_DEF_YES
, aQuery
);
952 if ( aQueryBox
.Execute() == RET_YES
)
957 BOOL
QueryDelMacro( const String
& rName
, Window
* pParent
)
959 return QueryDel( rName
, IDEResId( RID_STR_QUERYDELMACRO
), pParent
);
962 BOOL
QueryReplaceMacro( const String
& rName
, Window
* pParent
)
964 return QueryDel( rName
, IDEResId( RID_STR_QUERYREPLACEMACRO
), pParent
);
967 BOOL
QueryDelDialog( const String
& rName
, Window
* pParent
)
969 return QueryDel( rName
, IDEResId( RID_STR_QUERYDELDIALOG
), pParent
);
972 BOOL
QueryDelLib( const String
& rName
, BOOL bRef
, Window
* pParent
)
974 return QueryDel( rName
, IDEResId( bRef
? RID_STR_QUERYDELLIBREF
: RID_STR_QUERYDELLIB
), pParent
);
977 BOOL
QueryDelModule( const String
& rName
, Window
* pParent
)
979 return QueryDel( rName
, IDEResId( RID_STR_QUERYDELMODULE
), pParent
);
982 BOOL
QueryPassword( const Reference
< script::XLibraryContainer
>& xLibContainer
, const String
& rLibName
, String
& rPassword
, BOOL bRepeat
, BOOL bNewTitle
)
990 SfxPasswordDialog
* pDlg
= new SfxPasswordDialog( Application::GetDefDialogParent() );
991 pDlg
->SetMinLen( 1 );
996 String
aTitle( IDEResId( RID_STR_ENTERPASSWORD
) );
997 aTitle
.SearchAndReplace( String( RTL_CONSTASCII_USTRINGPARAM( "XX" ) ), rLibName
);
998 pDlg
->SetText( aTitle
);
1002 nRet
= pDlg
->Execute();
1005 if ( nRet
== RET_OK
)
1007 ::rtl::OUString
aOULibName( rLibName
);
1008 if ( xLibContainer
.is() && xLibContainer
->hasByName( aOULibName
) )
1010 Reference
< script::XLibraryContainerPassword
> xPasswd( xLibContainer
, UNO_QUERY
);
1011 if ( xPasswd
.is() && xPasswd
->isLibraryPasswordProtected( aOULibName
) && !xPasswd
->isLibraryPasswordVerified( aOULibName
) )
1013 rPassword
= pDlg
->GetPassword();
1014 ::rtl::OUString
aOUPassword( rPassword
);
1015 bOK
= xPasswd
->verifyLibraryPassword( aOULibName
, aOUPassword
);
1019 ErrorBox
aErrorBox( Application::GetDefDialogParent(), WB_OK
, String( IDEResId( RID_STR_WRONGPASSWORD
) ) );
1020 aErrorBox
.Execute();
1028 while ( bRepeat
&& !bOK
&& nRet
== RET_OK
);