LCOV - code coverage report
Current view: top level - basctl/source/basicide - bastypes.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 445 0.0 %
Date: 2012-08-25 Functions: 0 92 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

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

Generated by: LCOV version 1.10