lok: Don't attempt to select the exact text after a failed search.
[LibreOffice.git] / basctl / source / basicide / bastypes.cxx
blob77febec71f3ac41e5e848b0de890967acca32d69
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
21 #include "helpid.hrc"
23 #include "baside2.hxx"
24 #include "baside3.hxx"
25 #include "iderdll.hxx"
26 #include "iderdll2.hxx"
28 #include <basic/basmgr.hxx>
29 #include <com/sun/star/script/ModuleType.hpp>
30 #include <com/sun/star/script/XLibraryContainerPassword.hpp>
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/passwd.hxx>
33 #include <svl/intitem.hxx>
34 #include <svl/stritem.hxx>
35 #include <svl/srchdefs.hxx>
37 namespace basctl
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star;
43 TYPEINIT0( BaseWindow )
44 TYPEINIT1( SbxItem, SfxPoolItem );
46 BaseWindow::BaseWindow( vcl::Window* pParent, const ScriptDocument& rDocument, const OUString& aLibName, const OUString& aName )
47 :Window( pParent, WinBits( WB_3DLOOK ) )
48 ,m_aDocument( rDocument )
49 ,m_aLibName( aLibName )
50 ,m_aName( aName )
52 pShellHScrollBar = 0;
53 pShellVScrollBar = 0;
54 nStatus = 0;
57 BaseWindow::~BaseWindow()
59 disposeOnce();
62 void BaseWindow::dispose()
64 if ( pShellVScrollBar )
65 pShellVScrollBar->SetScrollHdl( Link<>() );
66 if ( pShellHScrollBar )
67 pShellHScrollBar->SetScrollHdl( Link<>() );
68 pShellVScrollBar.clear();
69 pShellHScrollBar.clear();
70 vcl::Window::dispose();
75 void BaseWindow::Init()
77 if ( pShellVScrollBar )
78 pShellVScrollBar->SetScrollHdl( LINK( this, BaseWindow, ScrollHdl ) );
79 if ( pShellHScrollBar )
80 pShellHScrollBar->SetScrollHdl( LINK( this, BaseWindow, ScrollHdl ) );
81 DoInit(); // virtual...
86 void BaseWindow::DoInit()
87 { }
91 void BaseWindow::GrabScrollBars( ScrollBar* pHScroll, ScrollBar* pVScroll )
93 pShellHScrollBar = pHScroll;
94 pShellVScrollBar = pVScroll;
95 // Init(); // does not make sense, leads to flickering and errors...
100 IMPL_LINK( BaseWindow, ScrollHdl, ScrollBar *, pCurScrollBar )
102 DoScroll( pCurScrollBar );
103 return 0;
106 void BaseWindow::ExecuteCommand (SfxRequest&)
109 void BaseWindow::ExecuteGlobal (SfxRequest&)
113 bool BaseWindow::Notify( NotifyEvent& rNEvt )
115 bool nDone = false;
117 if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
119 KeyEvent aKEvt = *rNEvt.GetKeyEvent();
120 vcl::KeyCode aCode = aKEvt.GetKeyCode();
121 sal_uInt16 nCode = aCode.GetCode();
123 switch ( nCode )
125 case KEY_PAGEUP:
126 case KEY_PAGEDOWN:
128 if ( aCode.IsMod1() )
130 if (Shell* pShell = GetShell())
131 pShell->NextPage( nCode == KEY_PAGEUP );
132 nDone = true;
135 break;
139 return nDone || Window::Notify( rNEvt );
143 void BaseWindow::DoScroll( ScrollBar* )
148 void BaseWindow::StoreData()
152 bool BaseWindow::CanClose()
154 return true;
157 bool BaseWindow::AllowUndo()
159 return true;
164 void BaseWindow::UpdateData()
168 OUString BaseWindow::GetTitle()
170 return OUString();
173 OUString BaseWindow::CreateQualifiedName()
175 OUString aName;
176 if ( !m_aLibName.isEmpty() )
178 LibraryLocation eLocation = m_aDocument.getLibraryLocation( m_aLibName );
179 aName = m_aDocument.getTitle(eLocation) + "." + m_aLibName + "." +
180 GetTitle();
182 return aName;
185 void BaseWindow::SetReadOnly (bool)
189 bool BaseWindow::IsReadOnly ()
191 return false;
194 void BaseWindow::BasicStarted()
198 void BaseWindow::BasicStopped()
202 bool BaseWindow::IsModified ()
204 return true;
207 bool BaseWindow::IsPasteAllowed ()
209 return false;
212 ::svl::IUndoManager* BaseWindow::GetUndoManager()
214 return NULL;
217 SearchOptionFlags BaseWindow::GetSearchOptions()
219 return SearchOptionFlags::NONE;
222 sal_uInt16 BaseWindow::StartSearchAndReplace (SvxSearchItem const&, bool bFromStart)
224 static_cast<void>(bFromStart);
225 return 0;
228 void BaseWindow::OnNewDocument ()
231 void BaseWindow::InsertLibInfo () const
233 if (ExtraData* pData = GetExtraData())
234 pData->GetLibInfos().InsertInfo(m_aDocument, m_aLibName, m_aName, GetType());
237 bool BaseWindow::Is (
238 ScriptDocument const& rDocument,
239 OUString const& rLibName, OUString const& rName,
240 ItemType eType, bool bFindSuspended
243 if (bFindSuspended || !IsSuspended())
245 // any non-suspended window is ok
246 if (rLibName.isEmpty() || rName.isEmpty() || eType == TYPE_UNKNOWN)
247 return true;
248 // ok if the parameters match
249 if (m_aDocument == rDocument && m_aLibName == rLibName && m_aName == rName && GetType() == eType)
250 return true;
252 return false;
255 bool BaseWindow::HasActiveEditor () const
257 return false;
262 // DockingWindow
266 // style bits for DockingWindow
267 WinBits const DockingWindow::StyleBits =
268 WB_BORDER | WB_3DLOOK | WB_CLIPCHILDREN |
269 WB_MOVEABLE | WB_SIZEABLE | WB_ROLLABLE | WB_DOCKABLE;
271 DockingWindow::DockingWindow (vcl::Window* pParent) :
272 ::DockingWindow(pParent, StyleBits),
273 pLayout(0),
274 nShowCount(0)
277 DockingWindow::DockingWindow (Layout* pParent) :
278 ::DockingWindow(pParent, StyleBits),
279 pLayout(pParent),
280 nShowCount(0)
283 DockingWindow::~DockingWindow()
285 disposeOnce();
288 void DockingWindow::dispose()
290 pLayout.clear();
291 ::DockingWindow::dispose();
294 // Sets the position and the size of the docking window. This property is saved
295 // when the window is floating. Called by Layout.
296 void DockingWindow::ResizeIfDocking (Point const& rPos, Size const& rSize)
298 Rectangle const rRect(rPos, rSize);
299 if (rRect != aDockingRect)
301 // saving the position and the size
302 aDockingRect = rRect;
303 // resizing if actually docking
304 if (!IsFloatingMode())
305 SetPosSizePixel(rPos, rSize);
308 void DockingWindow::ResizeIfDocking (Size const& rSize)
310 ResizeIfDocking(aDockingRect.TopLeft(), rSize);
313 // Sets the parent Layout window.
314 // The physical parent is set only when the window is docking.
315 void DockingWindow::SetLayoutWindow (Layout* pLayout_)
317 pLayout = pLayout_;
318 if (!IsFloatingMode())
319 SetParent(pLayout);
323 // Increases the "show" reference count.
324 // The window is shown when the reference count is positive.
325 void DockingWindow::Show (bool bShow) // = true
327 if (bShow)
329 if (++nShowCount == 1)
330 ::DockingWindow::Show();
332 else
334 if (--nShowCount == 0)
335 ::DockingWindow::Hide();
339 // Decreases the "show" reference count.
340 // The window is hidden when the reference count reaches zero.
341 void DockingWindow::Hide ()
343 Show(false);
346 bool DockingWindow::Docking( const Point& rPos, Rectangle& rRect )
348 if (!IsDockingPrevented() && aDockingRect.IsInside(rPos))
350 rRect.SetSize(aDockingRect.GetSize());
351 return false; // dock
353 else // adjust old size
355 if (!aFloatingRect.IsEmpty())
356 rRect.SetSize(aFloatingRect.GetSize());
357 return true; // float
361 void DockingWindow::EndDocking( const Rectangle& rRect, bool bFloatMode )
363 if ( bFloatMode )
364 ::DockingWindow::EndDocking( rRect, bFloatMode );
365 else
367 SetFloatingMode(false);
368 DockThis();
372 void DockingWindow::ToggleFloatingMode()
374 if (IsFloatingMode())
376 if (!aFloatingRect.IsEmpty())
377 SetPosSizePixel(
378 GetParent()->ScreenToOutputPixel(aFloatingRect.TopLeft()),
379 aFloatingRect.GetSize()
382 DockThis();
385 bool DockingWindow::PrepareToggleFloatingMode()
387 if (IsFloatingMode())
389 // memorize position and size on the desktop...
390 aFloatingRect = Rectangle(
391 GetParent()->OutputToScreenPixel(GetPosPixel()),
392 GetSizePixel()
395 return true;
398 void DockingWindow::StartDocking()
400 if (IsFloatingMode())
402 aFloatingRect = Rectangle(
403 GetParent()->OutputToScreenPixel(GetPosPixel()),
404 GetSizePixel()
409 void DockingWindow::DockThis ()
411 // resizing when floating -> docking
412 if (!IsFloatingMode())
414 Point const aPos = aDockingRect.TopLeft();
415 Size const aSize = aDockingRect.GetSize();
416 if (aSize != GetSizePixel() || aPos != GetPosPixel())
417 SetPosSizePixel(aPos, aSize);
420 if (pLayout)
422 if (!IsFloatingMode() && GetParent() != pLayout)
423 SetParent(pLayout);
424 pLayout->DockaWindow(this);
430 // ExtendedEdit
434 ExtendedEdit::ExtendedEdit( vcl::Window* pParent, IDEResId nRes ) :
435 Edit( pParent, nRes )
437 aAcc.SetSelectHdl( LINK( this, ExtendedEdit, EditAccHdl ) );
438 Control::SetGetFocusHdl( LINK( this, ExtendedEdit, ImplGetFocusHdl ) );
439 Control::SetLoseFocusHdl( LINK( this, ExtendedEdit, ImplLoseFocusHdl ) );
442 IMPL_LINK_NOARG(ExtendedEdit, ImplGetFocusHdl)
444 Application::InsertAccel( &aAcc );
445 aLoseFocusHdl.Call( this );
446 return 0;
450 IMPL_LINK_NOARG(ExtendedEdit, ImplLoseFocusHdl)
452 Application::RemoveAccel( &aAcc );
453 return 0;
457 IMPL_LINK( ExtendedEdit, EditAccHdl, Accelerator *, pAcc )
459 aAccHdl.Call( pAcc );
460 return 0;
463 // TabBar
467 TabBar::TabBar( vcl::Window* pParent ) :
468 ::TabBar( pParent, WinBits( WB_3DLOOK | WB_SCROLL | WB_BORDER | WB_SIZEABLE | WB_DRAG ) )
470 EnableEditMode(true);
472 SetHelpId( HID_BASICIDE_TABBAR );
475 void TabBar::MouseButtonDown( const MouseEvent& rMEvt )
477 if ( rMEvt.IsLeft() && ( rMEvt.GetClicks() == 2 ) && !IsInEditMode() )
479 if (SfxDispatcher* pDispatcher = GetDispatcher())
480 pDispatcher->Execute( SID_BASICIDE_MODULEDLG );
482 else
484 ::TabBar::MouseButtonDown( rMEvt ); // base class version
488 void TabBar::Command( const CommandEvent& rCEvt )
490 if ( ( rCEvt.GetCommand() == CommandEventId::ContextMenu ) && !IsInEditMode() )
492 Point aPos( rCEvt.IsMouseEvent() ? rCEvt.GetMousePosPixel() : Point(1,1) );
493 if ( rCEvt.IsMouseEvent() ) // select right tab
495 Point aP = PixelToLogic( aPos );
496 MouseEvent aMouseEvent( aP, 1, MouseEventModifiers::SIMPLECLICK, MOUSE_LEFT );
497 ::TabBar::MouseButtonDown( aMouseEvent ); // base class
500 PopupMenu aPopup( IDEResId( RID_POPUP_TABBAR ) );
501 if ( GetPageCount() == 0 )
503 aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
504 aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
505 aPopup.EnableItem(SID_BASICIDE_HIDECURPAGE, false);
508 if ( StarBASIC::IsRunning() )
510 aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
511 aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
512 aPopup.EnableItem(SID_BASICIDE_MODULEDLG, false);
515 if (Shell* pShell = GetShell())
517 ScriptDocument aDocument( pShell->GetCurDocument() );
518 OUString aOULibName( pShell->GetCurLibName() );
519 Reference< script::XLibraryContainer2 > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
520 Reference< script::XLibraryContainer2 > xDlgLibContainer( aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
521 if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
522 ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) )
524 aPopup.EnableItem(aPopup.GetItemId( 0 ), false);
525 aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
526 aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
527 aPopup.RemoveDisabledEntries();
529 if ( aDocument.isInVBAMode() )
531 // disable to delete or remove object modules in IDE
532 if (BasicManager* pBasMgr = aDocument.getBasicManager())
534 if (StarBASIC* pBasic = pBasMgr->GetLib(aOULibName))
536 Shell::WindowTable& aWindowTable = pShell->GetWindowTable();
537 Shell::WindowTableIt it = aWindowTable.find( GetCurPageId() );
538 if (it != aWindowTable.end() && dynamic_cast<ModulWindow*>(it->second.get()))
540 SbModule* pActiveModule = pBasic->FindModule( it->second->GetName() );
541 if( pActiveModule && ( pActiveModule->GetModuleType() == script::ModuleType::DOCUMENT ) )
543 aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
544 aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
551 if (SfxDispatcher* pDispatcher = GetDispatcher())
552 pDispatcher->Execute(aPopup.Execute(this, aPos));
556 TabBarAllowRenamingReturnCode TabBar::AllowRenaming()
558 bool const bValid = IsValidSbxName(GetEditText());
560 if ( !bValid )
561 ScopedVclPtrInstance<MessageDialog>::Create(this, IDEResId(RID_STR_BADSBXNAME))->Execute();
563 return bValid ? TABBAR_RENAMING_YES : TABBAR_RENAMING_NO;
567 void TabBar::EndRenaming()
569 if ( !IsEditModeCanceled() )
571 SfxUInt16Item aID( SID_BASICIDE_ARG_TABID, GetEditPageId() );
572 SfxStringItem aNewName( SID_BASICIDE_ARG_MODULENAME, GetEditText() );
573 if (SfxDispatcher* pDispatcher = GetDispatcher())
574 pDispatcher->Execute( SID_BASICIDE_NAMECHANGEDONTAB,
575 SfxCallMode::SYNCHRON, &aID, &aNewName, 0L );
580 namespace
583 // helper class for sorting TabBar
584 struct TabBarSortHelper
586 sal_uInt16 nPageId;
587 OUString aPageText;
589 bool operator < (TabBarSortHelper const& rComp) const
591 return aPageText.compareToIgnoreAsciiCase(rComp.aPageText) < 0;
595 } // namespace
597 void TabBar::Sort()
599 if (Shell* pShell = GetShell())
601 Shell::WindowTable& aWindowTable = pShell->GetWindowTable();
602 TabBarSortHelper aTabBarSortHelper;
603 std::vector<TabBarSortHelper> aModuleList;
604 std::vector<TabBarSortHelper> aDialogList;
605 sal_uInt16 nPageCount = GetPageCount();
606 sal_uInt16 i;
608 // create module and dialog lists for sorting
609 for ( i = 0; i < nPageCount; i++)
611 sal_uInt16 nId = GetPageId( i );
612 aTabBarSortHelper.nPageId = nId;
613 aTabBarSortHelper.aPageText = GetPageText( nId );
614 BaseWindow* pWin = aWindowTable[ nId ];
616 if (dynamic_cast<ModulWindow*>(pWin))
618 aModuleList.push_back( aTabBarSortHelper );
620 else if (dynamic_cast<DialogWindow*>(pWin))
622 aDialogList.push_back( aTabBarSortHelper );
626 // sort module and dialog lists by page text
627 ::std::sort( aModuleList.begin() , aModuleList.end() );
628 ::std::sort( aDialogList.begin() , aDialogList.end() );
631 sal_uInt16 nModules = sal::static_int_cast<sal_uInt16>( aModuleList.size() );
632 sal_uInt16 nDialogs = sal::static_int_cast<sal_uInt16>( aDialogList.size() );
634 // move module pages to new positions
635 for (i = 0; i < nModules; i++)
637 MovePage( aModuleList[i].nPageId , i );
640 // move dialog pages to new positions
641 for (i = 0; i < nDialogs; i++)
643 MovePage( aDialogList[i].nPageId , nModules + i );
648 void CutLines( OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, bool bEraseTrailingEmptyLines )
650 sal_Int32 nStartPos = 0;
651 sal_Int32 nLine = 0;
652 while ( nLine < nStartLine )
654 nStartPos = searchEOL( rStr, nStartPos );
655 if( nStartPos == -1 )
656 break;
657 nStartPos++; // not the \n.
658 nLine++;
661 DBG_ASSERTWARNING( nStartPos != -1, "CutLines: Startzeile nicht gefunden!" );
663 if ( nStartPos == -1 )
664 return;
666 sal_Int32 nEndPos = nStartPos;
668 for ( sal_Int32 i = 0; i < nLines; i++ )
669 nEndPos = searchEOL( rStr, nEndPos+1 );
671 if ( nEndPos == -1 ) // might happen at the last line
672 nEndPos = rStr.getLength();
673 else
674 nEndPos++;
676 OUString aEndStr = rStr.copy( nEndPos );
677 rStr = rStr.copy( 0, nStartPos );
678 rStr += aEndStr;
680 if ( bEraseTrailingEmptyLines )
682 sal_Int32 n = nStartPos;
683 sal_Int32 nLen = rStr.getLength();
684 while ( ( n < nLen ) && ( rStr[ n ] == LINE_SEP ||
685 rStr[ n ] == LINE_SEP_CR ) )
687 n++;
690 if ( n > nStartPos )
692 aEndStr = rStr.copy( n );
693 rStr = rStr.copy( 0, nStartPos );
694 rStr += aEndStr;
699 sal_uLong CalcLineCount( SvStream& rStream )
701 sal_uLong nLFs = 0;
702 sal_uLong nCRs = 0;
703 char c;
705 rStream.Seek( 0 );
706 rStream.ReadChar( c );
707 while ( !rStream.IsEof() )
709 if ( c == '\n' )
710 nLFs++;
711 else if ( c == '\r' )
712 nCRs++;
713 rStream.ReadChar( c );
716 rStream.Seek( 0 );
717 if ( nLFs > nCRs )
718 return nLFs;
719 return nCRs;
723 // LibInfos
727 LibInfos::LibInfos ()
730 LibInfos::~LibInfos ()
733 void LibInfos::InsertInfo (
734 ScriptDocument const& rDocument,
735 OUString const& rLibName,
736 OUString const& rCurrentName,
737 ItemType eCurrentType
740 Key aKey(rDocument, rLibName);
741 m_aMap.erase(aKey);
742 m_aMap.insert(Map::value_type(aKey, Item(rDocument, rLibName, rCurrentName, eCurrentType)));
745 void LibInfos::RemoveInfoFor (ScriptDocument const& rDocument)
747 Map::iterator it;
748 for (it = m_aMap.begin(); it != m_aMap.end(); ++it)
749 if (it->first.GetDocument() == rDocument)
750 break;
751 if (it != m_aMap.end())
752 m_aMap.erase(it);
755 LibInfos::Item const* LibInfos::GetInfo (
756 ScriptDocument const& rDocument, OUString const& rLibName
759 Map::iterator it = m_aMap.find(Key(rDocument, rLibName));
760 return it != m_aMap.end() ? &it->second : 0;
763 LibInfos::Key::Key (ScriptDocument const& rDocument, OUString const& rLibName) :
764 m_aDocument(rDocument), m_aLibName(rLibName)
767 LibInfos::Key::~Key ()
770 bool LibInfos::Key::operator == (Key const& rKey) const
772 return m_aDocument == rKey.m_aDocument && m_aLibName == rKey.m_aLibName;
775 size_t LibInfos::Key::Hash::operator () (Key const& rKey) const
777 return rKey.m_aDocument.hashCode() + rKey.m_aLibName.hashCode();
780 LibInfos::Item::Item (
781 ScriptDocument const& rDocument,
782 OUString const& rLibName,
783 OUString const& rCurrentName,
784 ItemType eCurrentType
786 m_aDocument(rDocument),
787 m_aLibName(rLibName),
788 m_aCurrentName(rCurrentName),
789 m_eCurrentType(eCurrentType)
792 LibInfos::Item::~Item ()
795 bool QueryDel( const OUString& rName, const ResId& rId, vcl::Window* pParent )
797 OUString aQuery(rId.toString());
798 OUStringBuffer aNameBuf( rName );
799 aNameBuf.append('\'');
800 aNameBuf.insert(0, '\'');
801 aQuery = aQuery.replaceAll("XX", aNameBuf.makeStringAndClear());
802 ScopedVclPtrInstance< MessageDialog > aQueryBox(pParent, aQuery, VCL_MESSAGE_QUESTION, VCL_BUTTONS_YES_NO);
803 return ( aQueryBox->Execute() == RET_YES );
806 bool QueryDelMacro( const OUString& rName, vcl::Window* pParent )
808 return QueryDel( rName, IDEResId( RID_STR_QUERYDELMACRO ), pParent );
811 bool QueryReplaceMacro( const OUString& rName, vcl::Window* pParent )
813 return QueryDel( rName, IDEResId( RID_STR_QUERYREPLACEMACRO ), pParent );
816 bool QueryDelDialog( const OUString& rName, vcl::Window* pParent )
818 return QueryDel( rName, IDEResId( RID_STR_QUERYDELDIALOG ), pParent );
821 bool QueryDelLib( const OUString& rName, bool bRef, vcl::Window* pParent )
823 return QueryDel( rName, IDEResId( bRef ? RID_STR_QUERYDELLIBREF : RID_STR_QUERYDELLIB ), pParent );
826 bool QueryDelModule( const OUString& rName, vcl::Window* pParent )
828 return QueryDel( rName, IDEResId( RID_STR_QUERYDELMODULE ), pParent );
831 bool QueryPassword( const Reference< script::XLibraryContainer >& xLibContainer, const OUString& rLibName, OUString& rPassword, bool bRepeat, bool bNewTitle )
833 bool bOK = false;
834 sal_uInt16 nRet = 0;
838 // password dialog
839 ScopedVclPtrInstance< SfxPasswordDialog > aDlg(Application::GetDefDialogParent());
840 aDlg->SetMinLen( 1 );
842 // set new title
843 if ( bNewTitle )
845 OUString aTitle(IDE_RESSTR(RID_STR_ENTERPASSWORD));
846 aTitle = aTitle.replaceAll("XX", rLibName);
847 aDlg->SetText( aTitle );
850 // execute dialog
851 nRet = aDlg->Execute();
853 // verify password
854 if ( nRet == RET_OK )
856 if ( xLibContainer.is() && xLibContainer->hasByName( rLibName ) )
858 Reference< script::XLibraryContainerPassword > xPasswd( xLibContainer, UNO_QUERY );
859 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( rLibName ) && !xPasswd->isLibraryPasswordVerified( rLibName ) )
861 rPassword = aDlg->GetPassword();
862 // OUString aOUPassword( rPassword );
863 bOK = xPasswd->verifyLibraryPassword( rLibName, rPassword );
865 if ( !bOK )
867 ScopedVclPtrInstance< MessageDialog > aErrorBox(Application::GetDefDialogParent(), IDE_RESSTR(RID_STR_WRONGPASSWORD));
868 aErrorBox->Execute();
874 while ( bRepeat && !bOK && nRet == RET_OK );
876 return bOK;
880 } // namespace basctl
882 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */