LCOV - code coverage report
Current view: top level - libreoffice/basctl/source/basicide - bastypes.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 410 0.0 %
Date: 2012-12-17 Functions: 0 94 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "baside2.hrc"
      21             : #include "basidesh.hrc"
      22             : #include "helpid.hrc"
      23             : 
      24             : #include "baside2.hxx" // unfortunately pModulWindow is needed partly...
      25             : #include "baside3.hxx"
      26             : #include "basobj.hxx"
      27             : #include "iderdll.hxx"
      28             : #include "iderdll2.hxx"
      29             : 
      30             : #include <basic/basmgr.hxx>
      31             : #include <com/sun/star/script/ModuleType.hpp>
      32             : #include <com/sun/star/script/XLibraryContainerPassword.hpp>
      33             : #include <sfx2/dispatch.hxx>
      34             : #include <sfx2/passwd.hxx>
      35             : #include <sfx2/viewfrm.hxx>
      36             : #include <svl/intitem.hxx>
      37             : #include <svl/stritem.hxx>
      38             : #include <vcl/msgbox.hxx>
      39             : 
      40             : namespace basctl
      41             : {
      42             : 
      43             : using namespace ::com::sun::star::uno;
      44             : using namespace ::com::sun::star;
      45             : 
      46             : 
      47             : //
      48             : // BaseWindow
      49             : // ==========
      50             : //
      51             : 
      52             : DBG_NAME( BaseWindow )
      53             : 
      54           0 : TYPEINIT0( BaseWindow )
      55           0 : TYPEINIT1( SbxItem, SfxPoolItem );
      56             : 
      57           0 : BaseWindow::BaseWindow( Window* pParent, const ScriptDocument& rDocument, OUString aLibName, OUString aName )
      58             :     :Window( pParent, WinBits( WB_3DLOOK ) )
      59             :     ,m_aDocument( rDocument )
      60             :     ,m_aLibName( aLibName )
      61           0 :     ,m_aName( aName )
      62             : {
      63             :     DBG_CTOR( BaseWindow, 0 );
      64           0 :     pShellHScrollBar = 0;
      65           0 :     pShellVScrollBar = 0;
      66           0 :     nStatus = 0;
      67           0 : }
      68             : 
      69           0 : BaseWindow::~BaseWindow()
      70             : {
      71             :     DBG_DTOR( BaseWindow, 0 );
      72           0 :     if ( pShellVScrollBar )
      73           0 :         pShellVScrollBar->SetScrollHdl( Link() );
      74           0 :     if ( pShellHScrollBar )
      75           0 :         pShellHScrollBar->SetScrollHdl( Link() );
      76           0 : }
      77             : 
      78             : 
      79             : 
      80           0 : void BaseWindow::Init()
      81             : {
      82             :     DBG_CHKTHIS( BaseWindow, 0 );
      83           0 :     if ( pShellVScrollBar )
      84           0 :         pShellVScrollBar->SetScrollHdl( LINK( this, BaseWindow, ScrollHdl ) );
      85           0 :     if ( pShellHScrollBar )
      86           0 :         pShellHScrollBar->SetScrollHdl( LINK( this, BaseWindow, ScrollHdl ) );
      87           0 :     DoInit();   // virtual...
      88           0 : }
      89             : 
      90             : 
      91             : 
      92           0 : void BaseWindow::DoInit()
      93           0 : { }
      94             : 
      95             : 
      96             : 
      97           0 : void BaseWindow::GrabScrollBars( ScrollBar* pHScroll, ScrollBar* pVScroll )
      98             : {
      99             :     DBG_CHKTHIS( BaseWindow, 0 );
     100           0 :     pShellHScrollBar = pHScroll;
     101           0 :     pShellVScrollBar = pVScroll;
     102             : //  Init(); // does not make sense, leads to flickering and errors...
     103           0 : }
     104             : 
     105             : 
     106             : 
     107           0 : IMPL_LINK_INLINE_START( BaseWindow, ScrollHdl, ScrollBar *, pCurScrollBar )
     108             : {
     109             :     DBG_CHKTHIS( BaseWindow, 0 );
     110           0 :     DoScroll( pCurScrollBar );
     111           0 :     return 0;
     112             : }
     113           0 : IMPL_LINK_INLINE_END( BaseWindow, ScrollHdl, ScrollBar *, pCurScrollBar )
     114             : 
     115             : 
     116           0 : void BaseWindow::ExecuteCommand (SfxRequest&)
     117           0 : { }
     118             : 
     119           0 : void BaseWindow::ExecuteGlobal (SfxRequest&)
     120           0 : { }
     121             : 
     122             : 
     123           0 : long BaseWindow::Notify( NotifyEvent& rNEvt )
     124             : {
     125           0 :     long nDone = 0;
     126             : 
     127           0 :     if ( rNEvt.GetType() == EVENT_KEYINPUT )
     128             :     {
     129           0 :         KeyEvent aKEvt = *rNEvt.GetKeyEvent();
     130           0 :         KeyCode aCode = aKEvt.GetKeyCode();
     131           0 :         sal_uInt16 nCode = aCode.GetCode();
     132             : 
     133           0 :         switch ( nCode )
     134             :         {
     135             :             case KEY_PAGEUP:
     136             :             case KEY_PAGEDOWN:
     137             :             {
     138           0 :                 if ( aCode.IsMod1() )
     139             :                 {
     140           0 :                     if (Shell* pShell = GetShell())
     141           0 :                         pShell->NextPage( nCode == KEY_PAGEUP );
     142           0 :                     nDone = 1;
     143             :                 }
     144             :             }
     145           0 :             break;
     146             :         }
     147             :     }
     148             : 
     149           0 :     return nDone ? nDone : Window::Notify( rNEvt );
     150             : }
     151             : 
     152             : 
     153           0 : void BaseWindow::DoScroll( ScrollBar* )
     154             : {
     155             :     DBG_CHKTHIS( BaseWindow, 0 );
     156           0 : }
     157             : 
     158             : 
     159           0 : void BaseWindow::StoreData()
     160             : {
     161           0 : }
     162             : 
     163           0 : bool BaseWindow::CanClose()
     164             : {
     165           0 :     return true;
     166             : }
     167             : 
     168           0 : bool BaseWindow::AllowUndo()
     169             : {
     170           0 :     return true;
     171             : }
     172             : 
     173             : 
     174             : 
     175           0 : void BaseWindow::UpdateData()
     176             : {
     177           0 : }
     178             : 
     179           0 : OUString BaseWindow::GetTitle()
     180             : {
     181           0 :     return OUString();
     182             : }
     183             : 
     184           0 : OUString BaseWindow::CreateQualifiedName()
     185             : {
     186           0 :     OUStringBuffer aName;
     187           0 :     if ( !m_aLibName.isEmpty() )
     188             :     {
     189           0 :         LibraryLocation eLocation = m_aDocument.getLibraryLocation( m_aLibName );
     190           0 :         aName.append(m_aDocument.getTitle(eLocation));
     191           0 :         aName.append('.');
     192           0 :         aName.append(m_aLibName);
     193           0 :         aName.append('.');
     194           0 :         aName.append(GetTitle());
     195             :     }
     196           0 :     return aName.makeStringAndClear();
     197             : }
     198             : 
     199           0 : void BaseWindow::SetReadOnly (bool)
     200             : {
     201           0 : }
     202             : 
     203           0 : bool BaseWindow::IsReadOnly ()
     204             : {
     205           0 :     return false;
     206             : }
     207             : 
     208           0 : void BaseWindow::BasicStarted()
     209             : {
     210           0 : }
     211             : 
     212           0 : void BaseWindow::BasicStopped()
     213             : {
     214           0 : }
     215             : 
     216           0 : bool BaseWindow::IsModified ()
     217             : {
     218           0 :     return true;
     219             : }
     220             : 
     221           0 : bool BaseWindow::IsPasteAllowed ()
     222             : {
     223           0 :     return false;
     224             : }
     225             : 
     226           0 : ::svl::IUndoManager* BaseWindow::GetUndoManager()
     227             : {
     228           0 :     return NULL;
     229             : }
     230             : 
     231           0 : sal_uInt16 BaseWindow::GetSearchOptions()
     232             : {
     233           0 :     return 0;
     234             : }
     235             : 
     236           0 : sal_uInt16 BaseWindow::StartSearchAndReplace (SvxSearchItem const&, bool bFromStart)
     237             : {
     238             :     static_cast<void>(bFromStart);
     239           0 :     return 0;
     240             : }
     241             : 
     242           0 : void BaseWindow::OnNewDocument ()
     243           0 : { }
     244             : 
     245           0 : void BaseWindow::InsertLibInfo () const
     246             : {
     247           0 :     if (ExtraData* pData = GetExtraData())
     248           0 :         pData->GetLibInfos().InsertInfo(m_aDocument, m_aLibName, m_aName, GetType());
     249           0 : }
     250             : 
     251           0 : bool BaseWindow::Is (
     252             :     ScriptDocument const& rDocument,
     253             :     OUString const& rLibName, OUString const& rName,
     254             :     ItemType eType, bool bFindSuspended
     255             : )
     256             : {
     257           0 :     if (bFindSuspended || !IsSuspended())
     258             :     {
     259             :         // any non-suspended window is ok
     260           0 :         if (rLibName.isEmpty() || rName.isEmpty() || eType == TYPE_UNKNOWN)
     261           0 :             return true;
     262             :         // ok if the parameters match
     263           0 :         if (m_aDocument == rDocument && m_aLibName == rLibName && m_aName == rName && GetType() == eType)
     264           0 :             return true;
     265             :     }
     266           0 :     return false;
     267             : }
     268             : 
     269           0 : bool BaseWindow::HasActiveEditor () const
     270             : {
     271           0 :     return false;
     272             : }
     273             : 
     274             : 
     275             : //
     276             : // DockingWindow
     277             : // =============
     278             : //
     279             : 
     280             : // style bits for DockingWindow
     281             : WinBits const DockingWindow::StyleBits =
     282             :     WB_BORDER | WB_3DLOOK | WB_CLIPCHILDREN |
     283             :     WB_MOVEABLE | WB_SIZEABLE | WB_ROLLABLE | WB_DOCKABLE;
     284             : 
     285           0 : DockingWindow::DockingWindow (Window* pParent) :
     286             :     ::DockingWindow(pParent, StyleBits),
     287             :     pLayout(0),
     288           0 :     nShowCount(0)
     289           0 : { }
     290             : 
     291           0 : DockingWindow::DockingWindow (Layout* pParent) :
     292             :     ::DockingWindow(pParent, StyleBits),
     293             :     pLayout(pParent),
     294           0 :     nShowCount(0)
     295           0 : { }
     296             : 
     297             : // Sets the position and the size of the docking window. This property is saved
     298             : // when the window is floating. Called by Layout.
     299           0 : void DockingWindow::ResizeIfDocking (Point const& rPos, Size const& rSize)
     300             : {
     301           0 :     Rectangle const rRect(rPos, rSize);
     302           0 :     if (rRect != aDockingRect)
     303             :     {
     304             :         // saving the position and the size
     305           0 :         aDockingRect = rRect;
     306             :         // resizing if actually docking
     307           0 :         if (!IsFloatingMode())
     308           0 :             SetPosSizePixel(rPos, rSize);
     309             :     }
     310           0 : }
     311           0 : void DockingWindow::ResizeIfDocking (Size const& rSize)
     312             : {
     313           0 :     ResizeIfDocking(aDockingRect.TopLeft(), rSize);
     314           0 : }
     315             : 
     316             : // Sets the parent Layout window.
     317             : // The physical parent is set only when the window is docking.
     318           0 : void DockingWindow::SetLayoutWindow (Layout* pLayout_)
     319             : {
     320           0 :     pLayout = pLayout_;
     321           0 :     if (!IsFloatingMode())
     322           0 :         SetParent(pLayout);
     323             : 
     324           0 : }
     325             : 
     326             : // Increases the "show" reference count.
     327             : // The window is shown when the reference count is positive.
     328           0 : void DockingWindow::Show (bool bShow) // = true
     329             : {
     330           0 :     if (bShow)
     331             :     {
     332           0 :         if (++nShowCount == 1)
     333           0 :             ::DockingWindow::Show();
     334             :     }
     335             :     else
     336             :     {
     337           0 :         if (--nShowCount == 0)
     338           0 :             ::DockingWindow::Hide();
     339             :     }
     340           0 : }
     341             : 
     342             : // Decreases the "show" reference count.
     343             : // The window is hidden when the reference count reaches zero.
     344           0 : void DockingWindow::Hide ()
     345             : {
     346           0 :     Show(false);
     347           0 : }
     348             : 
     349           0 : sal_Bool DockingWindow::Docking( const Point& rPos, Rectangle& rRect )
     350             : {
     351           0 :     if (!IsDockingPrevented() && aDockingRect.IsInside(rPos))
     352             :     {
     353           0 :         rRect.SetSize(aDockingRect.GetSize());
     354           0 :         return false; // dock
     355             :     }
     356             :     else // adjust old size
     357             :     {
     358           0 :         if (!aFloatingRect.IsEmpty())
     359           0 :             rRect.SetSize(aFloatingRect.GetSize());
     360           0 :         return true; // float
     361             :     }
     362             : }
     363             : 
     364           0 : void DockingWindow::EndDocking( const Rectangle& rRect, sal_Bool bFloatMode )
     365             : {
     366           0 :     if ( bFloatMode )
     367           0 :         ::DockingWindow::EndDocking( rRect, bFloatMode );
     368             :     else
     369             :     {
     370           0 :         SetFloatingMode(false);
     371           0 :         DockThis();
     372             :     }
     373           0 : }
     374             : 
     375           0 : void DockingWindow::ToggleFloatingMode()
     376             : {
     377           0 :     if (IsFloatingMode())
     378             :     {
     379           0 :         if (!aFloatingRect.IsEmpty())
     380             :             SetPosSizePixel(
     381           0 :                 GetParent()->ScreenToOutputPixel(aFloatingRect.TopLeft()),
     382           0 :                 aFloatingRect.GetSize()
     383           0 :             );
     384             :     }
     385           0 :     DockThis();
     386           0 : }
     387             : 
     388           0 : sal_Bool DockingWindow::PrepareToggleFloatingMode()
     389             : {
     390           0 :     if (IsFloatingMode())
     391             :     {
     392             :         // memorize position and size on the desktop...
     393             :         aFloatingRect = Rectangle(
     394           0 :             GetParent()->OutputToScreenPixel(GetPosPixel()),
     395           0 :             GetSizePixel()
     396           0 :         );
     397             :     }
     398           0 :     return true;
     399             : }
     400             : 
     401           0 : void DockingWindow::StartDocking()
     402             : {
     403           0 :     if (IsFloatingMode())
     404             :     {
     405             :         aFloatingRect = Rectangle(
     406           0 :             GetParent()->OutputToScreenPixel(GetPosPixel()),
     407           0 :             GetSizePixel()
     408           0 :         );
     409             :     }
     410           0 : }
     411             : 
     412           0 : void DockingWindow::DockThis ()
     413             : {
     414             :     // resizing when floating -> docking
     415           0 :     if (!IsFloatingMode())
     416             :     {
     417           0 :         Point const aPos = aDockingRect.TopLeft();
     418           0 :         Size const aSize = aDockingRect.GetSize();
     419           0 :         if (aSize != GetSizePixel() || aPos != GetPosPixel())
     420           0 :             SetPosSizePixel(aPos, aSize);
     421             :     }
     422             : 
     423           0 :     if (pLayout)
     424             :     {
     425           0 :         if (!IsFloatingMode() && GetParent() != pLayout)
     426           0 :             SetParent(pLayout);
     427           0 :         pLayout->DockaWindow(this);
     428             :     }
     429           0 : }
     430             : 
     431             : 
     432             : //
     433             : // ExtendedEdit
     434             : // ============
     435             : //
     436             : 
     437           0 : ExtendedEdit::ExtendedEdit( Window* pParent, IDEResId nRes ) :
     438           0 :     Edit( pParent, nRes )
     439             : {
     440           0 :     aAcc.SetSelectHdl( LINK( this, ExtendedEdit, EditAccHdl ) );
     441           0 :     Control::SetGetFocusHdl( LINK( this, ExtendedEdit, ImplGetFocusHdl ) );
     442           0 :     Control::SetLoseFocusHdl( LINK( this, ExtendedEdit, ImplLoseFocusHdl ) );
     443           0 : }
     444             : 
     445           0 : IMPL_LINK_NOARG(ExtendedEdit, ImplGetFocusHdl)
     446             : {
     447           0 :     Application::InsertAccel( &aAcc );
     448           0 :     aLoseFocusHdl.Call( this );
     449           0 :     return 0;
     450             : }
     451             : 
     452             : 
     453           0 : IMPL_LINK_NOARG(ExtendedEdit, ImplLoseFocusHdl)
     454             : {
     455           0 :     Application::RemoveAccel( &aAcc );
     456           0 :     return 0;
     457             : }
     458             : 
     459             : 
     460           0 : IMPL_LINK_INLINE_START( ExtendedEdit, EditAccHdl, Accelerator *, pAcc )
     461             : {
     462           0 :     aAccHdl.Call( pAcc );
     463           0 :     return 0;
     464             : }
     465           0 : IMPL_LINK_INLINE_END( ExtendedEdit, EditAccHdl, Accelerator *, pAcc )
     466             : 
     467             : 
     468             : //
     469             : //  TabBar
     470             : // ========
     471             : //
     472             : 
     473           0 : TabBar::TabBar( Window* pParent ) :
     474           0 :     ::TabBar( pParent, WinBits( WB_3DLOOK | WB_SCROLL | WB_BORDER | WB_SIZEABLE | WB_DRAG ) )
     475             : {
     476           0 :     EnableEditMode(true);
     477             : 
     478           0 :     SetHelpId( HID_BASICIDE_TABBAR );
     479           0 : }
     480             : 
     481           0 : void TabBar::MouseButtonDown( const MouseEvent& rMEvt )
     482             : {
     483           0 :     if ( rMEvt.IsLeft() && ( rMEvt.GetClicks() == 2 ) && !IsInEditMode() )
     484             :     {
     485           0 :         if (SfxDispatcher* pDispatcher = GetDispatcher())
     486           0 :             pDispatcher->Execute( SID_BASICIDE_MODULEDLG );
     487             :     }
     488             :     else
     489             :     {
     490           0 :         ::TabBar::MouseButtonDown( rMEvt ); // base class version
     491             :     }
     492           0 : }
     493             : 
     494           0 : void TabBar::Command( const CommandEvent& rCEvt )
     495             : {
     496           0 :     if ( ( rCEvt.GetCommand() == COMMAND_CONTEXTMENU ) && !IsInEditMode() )
     497             :     {
     498           0 :         Point aPos( rCEvt.IsMouseEvent() ? rCEvt.GetMousePosPixel() : Point(1,1) );
     499           0 :         if ( rCEvt.IsMouseEvent() )     // select right tab
     500             :         {
     501           0 :             Point aP = PixelToLogic( aPos );
     502           0 :             MouseEvent aMouseEvent( aP, 1, MOUSE_SIMPLECLICK, MOUSE_LEFT );
     503           0 :             ::TabBar::MouseButtonDown( aMouseEvent ); // base class
     504             :         }
     505             : 
     506           0 :         PopupMenu aPopup( IDEResId( RID_POPUP_TABBAR ) );
     507           0 :         if ( GetPageCount() == 0 )
     508             :         {
     509           0 :             aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
     510           0 :             aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
     511           0 :             aPopup.EnableItem(SID_BASICIDE_HIDECURPAGE, false);
     512             :         }
     513             : 
     514           0 :         if ( StarBASIC::IsRunning() )
     515             :         {
     516           0 :             aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
     517           0 :             aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
     518           0 :             aPopup.EnableItem(SID_BASICIDE_MODULEDLG, false);
     519             :         }
     520             : 
     521           0 :         if (Shell* pShell = GetShell())
     522             :         {
     523           0 :             ScriptDocument aDocument( pShell->GetCurDocument() );
     524           0 :             OUString       aOULibName( pShell->GetCurLibName() );
     525           0 :             Reference< script::XLibraryContainer2 > xModLibContainer( aDocument.getLibraryContainer( E_SCRIPTS ), UNO_QUERY );
     526           0 :             Reference< script::XLibraryContainer2 > xDlgLibContainer( aDocument.getLibraryContainer( E_DIALOGS ), UNO_QUERY );
     527           0 :             if ( ( xModLibContainer.is() && xModLibContainer->hasByName( aOULibName ) && xModLibContainer->isLibraryReadOnly( aOULibName ) ) ||
     528           0 :                  ( xDlgLibContainer.is() && xDlgLibContainer->hasByName( aOULibName ) && xDlgLibContainer->isLibraryReadOnly( aOULibName ) ) )
     529             :             {
     530           0 :                 aPopup.EnableItem(aPopup.GetItemId( 0 ), false);
     531           0 :                 aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
     532           0 :                 aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
     533           0 :                 aPopup.RemoveDisabledEntries();
     534             :             }
     535           0 :              if ( aDocument.isInVBAMode() )
     536             :             {
     537             :                 // disable to delete or remove object modules in IDE
     538           0 :                 if (BasicManager* pBasMgr = aDocument.getBasicManager())
     539             :                 {
     540           0 :                     if (StarBASIC* pBasic = pBasMgr->GetLib(aOULibName))
     541             :                     {
     542           0 :                         Shell::WindowTable& aWindowTable = pShell->GetWindowTable();
     543           0 :                         Shell::WindowTableIt it = aWindowTable.find( GetCurPageId() );
     544           0 :                         if (it != aWindowTable.end() && dynamic_cast<ModulWindow*>(it->second))
     545             :                         {
     546           0 :                             SbModule* pActiveModule = (SbModule*)pBasic->FindModule( it->second->GetName() );
     547           0 :                             if( pActiveModule && ( pActiveModule->GetModuleType() == script::ModuleType::DOCUMENT ) )
     548             :                             {
     549           0 :                                 aPopup.EnableItem(SID_BASICIDE_DELETECURRENT, false);
     550           0 :                                 aPopup.EnableItem(SID_BASICIDE_RENAMECURRENT, false);
     551             :                             }
     552             :                         }
     553             :                     }
     554             :                 }
     555           0 :             }
     556             :         }
     557           0 :         if (SfxDispatcher* pDispatcher = GetDispatcher())
     558           0 :             pDispatcher->Execute(aPopup.Execute(this, aPos));
     559             :     }
     560           0 : }
     561             : 
     562           0 : long TabBar::AllowRenaming()
     563             : {
     564           0 :     bool const bValid = IsValidSbxName(GetEditText());
     565             : 
     566           0 :     if ( !bValid )
     567           0 :         ErrorBox( this, WB_OK | WB_DEF_OK, String( IDEResId( RID_STR_BADSBXNAME ) ) ).Execute();
     568             : 
     569           0 :     return bValid ? TABBAR_RENAMING_YES : TABBAR_RENAMING_NO;
     570             : }
     571             : 
     572             : 
     573           0 : void TabBar::EndRenaming()
     574             : {
     575           0 :     if ( !IsEditModeCanceled() )
     576             :     {
     577           0 :         SfxUInt16Item aID( SID_BASICIDE_ARG_TABID, GetEditPageId() );
     578           0 :         SfxStringItem aNewName( SID_BASICIDE_ARG_MODULENAME, GetEditText() );
     579           0 :         if (SfxDispatcher* pDispatcher = GetDispatcher())
     580             :             pDispatcher->Execute( SID_BASICIDE_NAMECHANGEDONTAB,
     581           0 :                                   SFX_CALLMODE_SYNCHRON, &aID, &aNewName, 0L );
     582             :     }
     583           0 : }
     584             : 
     585             : 
     586             : namespace
     587             : {
     588             : 
     589             : // helper class for sorting TabBar
     590           0 : struct TabBarSortHelper
     591             : {
     592             :     sal_uInt16      nPageId;
     593             :     String          aPageText;
     594             : 
     595           0 :     bool operator < (TabBarSortHelper const& rComp) const
     596             :     {
     597           0 :         return aPageText.CompareIgnoreCaseToAscii(rComp.aPageText) == COMPARE_LESS;
     598             :     }
     599             : };
     600             : 
     601             : } // namespace
     602             : 
     603           0 : void TabBar::Sort()
     604             : {
     605           0 :     if (Shell* pShell = GetShell())
     606             :     {
     607           0 :         Shell::WindowTable& aWindowTable = pShell->GetWindowTable();
     608           0 :         TabBarSortHelper aTabBarSortHelper;
     609           0 :         std::vector<TabBarSortHelper> aModuleList;
     610           0 :         std::vector<TabBarSortHelper> aDialogList;
     611           0 :         sal_uInt16 nPageCount = GetPageCount();
     612             :         sal_uInt16 i;
     613             : 
     614             :         // create module and dialog lists for sorting
     615           0 :         for ( i = 0; i < nPageCount; i++)
     616             :         {
     617           0 :             sal_uInt16 nId = GetPageId( i );
     618           0 :             aTabBarSortHelper.nPageId = nId;
     619           0 :             aTabBarSortHelper.aPageText = GetPageText( nId );
     620           0 :             BaseWindow* pWin = aWindowTable[ nId ];
     621             : 
     622           0 :             if (dynamic_cast<ModulWindow*>(pWin))
     623             :             {
     624           0 :                 aModuleList.push_back( aTabBarSortHelper );
     625             :             }
     626           0 :             else if (dynamic_cast<DialogWindow*>(pWin))
     627             :             {
     628           0 :                 aDialogList.push_back( aTabBarSortHelper );
     629             :             }
     630             :         }
     631             : 
     632             :         // sort module and dialog lists by page text
     633           0 :         ::std::sort( aModuleList.begin() , aModuleList.end() );
     634           0 :         ::std::sort( aDialogList.begin() , aDialogList.end() );
     635             : 
     636             : 
     637           0 :         sal_uInt16 nModules = sal::static_int_cast<sal_uInt16>( aModuleList.size() );
     638           0 :         sal_uInt16 nDialogs = sal::static_int_cast<sal_uInt16>( aDialogList.size() );
     639             : 
     640             :         // move module pages to new positions
     641           0 :         for (i = 0; i < nModules; i++)
     642             :         {
     643           0 :             MovePage( aModuleList[i].nPageId , i );
     644             :         }
     645             : 
     646             :         // move dialog pages to new positions
     647           0 :         for (i = 0; i < nDialogs; i++)
     648             :         {
     649           0 :             MovePage( aDialogList[i].nPageId , nModules + i );
     650           0 :         }
     651             :     }
     652           0 : }
     653             : 
     654           0 : void CutLines( OUString& rStr, sal_Int32 nStartLine, sal_Int32 nLines, bool bEraseTrailingEmptyLines )
     655             : {
     656           0 :     sal_Int32 nStartPos = 0;
     657           0 :     sal_Int32 nLine = 0;
     658           0 :     while ( nLine < nStartLine )
     659             :     {
     660           0 :         nStartPos = searchEOL( rStr, nStartPos );
     661           0 :         if( nStartPos == -1 )
     662           0 :             break;
     663           0 :         nStartPos++;    // not the \n.
     664           0 :         nLine++;
     665             :     }
     666             : 
     667             :     DBG_ASSERTWARNING( nStartPos != -1, "CutLines: Startzeile nicht gefunden!" );
     668             : 
     669           0 :     if ( nStartPos != -1 )
     670             :     {
     671           0 :         sal_Int32 nEndPos = nStartPos;
     672             : 
     673           0 :         for ( sal_Int32 i = 0; i < nLines; i++ )
     674           0 :             nEndPos = searchEOL( rStr, nEndPos+1 );
     675             : 
     676           0 :         if ( nEndPos == -1 ) // might happen at the last line
     677           0 :             nEndPos = rStr.getLength();
     678             :         else
     679           0 :             nEndPos++;
     680             : 
     681           0 :         OUString aEndStr = rStr.copy( nEndPos );
     682           0 :         rStr = rStr.copy( 0, nStartPos );
     683           0 :         rStr += aEndStr;
     684             :     }
     685           0 :     if ( bEraseTrailingEmptyLines )
     686             :     {
     687           0 :         sal_Int32 n = nStartPos;
     688           0 :         sal_Int32 nLen = rStr.getLength();
     689           0 :         while ( ( n < nLen ) && ( rStr.getStr()[ n ] == LINE_SEP ||
     690           0 :                                   rStr.getStr()[ n ] == LINE_SEP_CR ) )
     691             :         {
     692           0 :             n++;
     693             :         }
     694             : 
     695           0 :         if ( n > nStartPos )
     696             :         {
     697           0 :             OUString aEndStr = rStr.copy( n );
     698           0 :             rStr = rStr.copy( 0, nStartPos );
     699           0 :             rStr += aEndStr;
     700             :         }
     701             :     }
     702           0 : }
     703             : 
     704           0 : sal_uLong CalcLineCount( SvStream& rStream )
     705             : {
     706           0 :     sal_uLong nLFs = 0;
     707           0 :     sal_uLong nCRs = 0;
     708             :     char c;
     709             : 
     710           0 :     rStream.Seek( 0 );
     711           0 :     rStream >> c;
     712           0 :     while ( !rStream.IsEof() )
     713             :     {
     714           0 :         if ( c == '\n' )
     715           0 :             nLFs++;
     716           0 :         else if ( c == '\r' )
     717           0 :             nCRs++;
     718           0 :         rStream >> c;
     719             :     }
     720             : 
     721           0 :     rStream.Seek( 0 );
     722           0 :     if ( nLFs > nCRs )
     723           0 :         return nLFs;
     724           0 :     return nCRs;
     725             : }
     726             : 
     727             : //
     728             : // LibInfos
     729             : // ========
     730             : //
     731             : 
     732           0 : LibInfos::LibInfos ()
     733           0 : { }
     734             : 
     735           0 : LibInfos::~LibInfos ()
     736           0 : { }
     737             : 
     738           0 : void LibInfos::InsertInfo (
     739             :     ScriptDocument const& rDocument,
     740             :     OUString const& rLibName,
     741             :     OUString const& rCurrentName,
     742             :     ItemType eCurrentType
     743             : )
     744             : {
     745           0 :     Key aKey(rDocument, rLibName);
     746           0 :     m_aMap.erase(aKey);
     747           0 :     m_aMap.insert(Map::value_type(aKey, Item(rDocument, rLibName, rCurrentName, eCurrentType)));
     748           0 : }
     749             : 
     750           0 : void LibInfos::RemoveInfoFor (ScriptDocument const& rDocument)
     751             : {
     752           0 :     Map::iterator it;
     753           0 :     for (it = m_aMap.begin(); it != m_aMap.end(); ++it)
     754           0 :         if (it->first.GetDocument() == rDocument)
     755           0 :             break;
     756           0 :     if (it != m_aMap.end())
     757           0 :         m_aMap.erase(it);
     758           0 : }
     759             : 
     760           0 : LibInfos::Item const* LibInfos::GetInfo (
     761             :     ScriptDocument const& rDocument, OUString const& rLibName
     762             : )
     763             : {
     764           0 :     Map::iterator it = m_aMap.find(Key(rDocument, rLibName));
     765           0 :     return it != m_aMap.end() ? &it->second : 0;
     766             : }
     767             : 
     768           0 : LibInfos::Key::Key (ScriptDocument const& rDocument, OUString const& rLibName) :
     769           0 :     m_aDocument(rDocument), m_aLibName(rLibName)
     770           0 : { }
     771             : 
     772           0 : LibInfos::Key::~Key ()
     773           0 : { }
     774             : 
     775           0 : bool LibInfos::Key::operator == (Key const& rKey) const
     776             : {
     777           0 :     return m_aDocument == rKey.m_aDocument && m_aLibName == rKey.m_aLibName;
     778             : }
     779             : 
     780           0 : size_t LibInfos::Key::Hash::operator () (Key const& rKey) const
     781             : {
     782           0 :     return rKey.m_aDocument.hashCode() + rKey.m_aLibName.hashCode();
     783             : }
     784             : 
     785           0 : LibInfos::Item::Item (
     786             :     ScriptDocument const& rDocument,
     787             :     OUString const& rLibName,
     788             :     OUString const& rCurrentName,
     789             :     ItemType eCurrentType
     790             : ) :
     791             :     m_aDocument(rDocument),
     792             :     m_aLibName(rLibName),
     793             :     m_aCurrentName(rCurrentName),
     794           0 :     m_eCurrentType(eCurrentType)
     795           0 : { }
     796             : 
     797           0 : LibInfos::Item::~Item ()
     798           0 : { }
     799             : 
     800           0 : bool QueryDel( const OUString& rName, const ResId& rId, Window* pParent )
     801             : {
     802           0 :     OUString aQuery(rId.toString());
     803           0 :     OUStringBuffer aNameBuf( rName );
     804           0 :     aNameBuf.append('\'');
     805           0 :     aNameBuf.insert(sal_Int32(0), sal_Unicode('\''));
     806           0 :     aQuery = aQuery.replaceAll("XX", aNameBuf.makeStringAndClear());
     807           0 :     QueryBox aQueryBox( pParent, WB_YES_NO | WB_DEF_YES, aQuery );
     808           0 :     return ( aQueryBox.Execute() == RET_YES );
     809             : }
     810             : 
     811           0 : bool QueryDelMacro( const OUString& rName, Window* pParent )
     812             : {
     813           0 :     return QueryDel( rName, IDEResId( RID_STR_QUERYDELMACRO ), pParent );
     814             : }
     815             : 
     816           0 : bool QueryReplaceMacro( const OUString& rName, Window* pParent )
     817             : {
     818           0 :     return QueryDel( rName, IDEResId( RID_STR_QUERYREPLACEMACRO ), pParent );
     819             : }
     820             : 
     821           0 : bool QueryDelDialog( const OUString& rName, Window* pParent )
     822             : {
     823           0 :     return QueryDel( rName, IDEResId( RID_STR_QUERYDELDIALOG ), pParent );
     824             : }
     825             : 
     826           0 : bool QueryDelLib( const OUString& rName, bool bRef, Window* pParent )
     827             : {
     828           0 :     return QueryDel( rName, IDEResId( bRef ? RID_STR_QUERYDELLIBREF : RID_STR_QUERYDELLIB ), pParent );
     829             : }
     830             : 
     831           0 : bool QueryDelModule( const OUString& rName, Window* pParent )
     832             : {
     833           0 :     return QueryDel( rName, IDEResId( RID_STR_QUERYDELMODULE ), pParent );
     834             : }
     835             : 
     836           0 : bool QueryPassword( const Reference< script::XLibraryContainer >& xLibContainer, const OUString& rLibName, OUString& rPassword, bool bRepeat, bool bNewTitle )
     837             : {
     838           0 :     bool bOK = false;
     839           0 :     sal_uInt16 nRet = 0;
     840             : 
     841           0 :     do
     842             :     {
     843             :         // password dialog
     844           0 :         SfxPasswordDialog aDlg(Application::GetDefDialogParent());
     845           0 :         aDlg.SetMinLen( 1 );
     846             : 
     847             :         // set new title
     848           0 :         if ( bNewTitle )
     849             :         {
     850           0 :             OUString aTitle(IDE_RESSTR(RID_STR_ENTERPASSWORD));
     851           0 :             aTitle = aTitle.replaceAll("XX", rLibName);
     852           0 :             aDlg.SetText( aTitle );
     853             :         }
     854             : 
     855             :         // execute dialog
     856           0 :         nRet = aDlg.Execute();
     857             : 
     858             :         // verify password
     859           0 :         if ( nRet == RET_OK )
     860             :         {
     861           0 :             if ( xLibContainer.is() && xLibContainer->hasByName( rLibName ) )
     862             :             {
     863           0 :                 Reference< script::XLibraryContainerPassword > xPasswd( xLibContainer, UNO_QUERY );
     864           0 :                 if ( xPasswd.is() && xPasswd->isLibraryPasswordProtected( rLibName ) && !xPasswd->isLibraryPasswordVerified( rLibName ) )
     865             :                 {
     866           0 :                     rPassword = aDlg.GetPassword();
     867             :                     //                    OUString aOUPassword( rPassword );
     868           0 :                     bOK = xPasswd->verifyLibraryPassword( rLibName, rPassword );
     869             : 
     870           0 :                     if ( !bOK )
     871             :                     {
     872           0 :                         ErrorBox aErrorBox( Application::GetDefDialogParent(), WB_OK, IDE_RESSTR(RID_STR_WRONGPASSWORD) );
     873           0 :                         aErrorBox.Execute();
     874             :                     }
     875           0 :                 }
     876             :             }
     877           0 :         }
     878             :     }
     879           0 :     while ( bRepeat && !bOK && nRet == RET_OK );
     880             : 
     881           0 :     return bOK;
     882             : }
     883             : 
     884             : 
     885           0 : } // namespace basctl
     886             : 
     887             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10