LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/dlg - RemoteDialogClientBox.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 316 0.0 %
Date: 2012-12-17 Functions: 0 29 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 "svtools/controldims.hrc"
      21             : 
      22             : #include "RemoteDialogClientBox.hxx"
      23             : #include "RemoteDialog.hrc"
      24             : 
      25             : #include "comphelper/processfactory.hxx"
      26             : #include "com/sun/star/i18n/CollatorOptions.hpp"
      27             : #include "com/sun/star/deployment/DependencyException.hpp"
      28             : #include "com/sun/star/deployment/DeploymentException.hpp"
      29             : 
      30             : #define USER_PACKAGE_MANAGER    "user"
      31             : #define SHARED_PACKAGE_MANAGER  "shared"
      32             : #define BUNDLED_PACKAGE_MANAGER "bundled"
      33             : 
      34             : using namespace ::com::sun::star;
      35             : 
      36             : namespace sd {
      37             : 
      38             : //------------------------------------------------------------------------------
      39             : //                          struct ClientBoxEntry
      40             : //------------------------------------------------------------------------------
      41           0 : ClientBoxEntry::ClientBoxEntry( ClientInfo* pClientInfo ) :
      42             :     m_bActive( false ),
      43           0 :     m_pClientInfo( pClientInfo )
      44             : {
      45           0 : }
      46             : 
      47             : //------------------------------------------------------------------------------
      48           0 : ClientBoxEntry::~ClientBoxEntry()
      49           0 : {}
      50             : 
      51             : 
      52             : //------------------------------------------------------------------------------
      53             : // ClientRemovedListener
      54             : //------------------------------------------------------------------------------
      55           0 : void ClientRemovedListener::disposing( lang::EventObject const & rEvt )
      56             :     throw ( uno::RuntimeException )
      57             : {
      58             :     (void) rEvt;
      59           0 : }
      60             : 
      61             : //------------------------------------------------------------------------------
      62           0 : ClientRemovedListener::~ClientRemovedListener()
      63             : {
      64           0 : }
      65             : 
      66             : //------------------------------------------------------------------------------
      67             : // ClientBox
      68             : //------------------------------------------------------------------------------
      69           0 : ClientBox::ClientBox( Dialog* pParent, RemoteServer *pServer,
      70             :                       const SdResId& aId ) :
      71             :     Control( pParent, aId ),
      72             :     m_bHasScrollBar( false ),
      73             :     m_bHasActive( false ),
      74             :     m_bNeedsRecalc( true ),
      75             :     m_bInCheckMode( false ),
      76             :     m_bAdjustActive( false ),
      77             :     m_bInDelete( false ),
      78             :     m_nActive( 0 ),
      79             :     m_nTopIndex( 0 ),
      80             :     m_nActiveHeight( 0 ),
      81             :     m_nExtraHeight( 2 ),
      82             :     m_aPinBox( this, SdResId( INPUT_PIN ) ),
      83             :     m_aPinDescription( this, SdResId( TEXT_PIN ) ),
      84           0 :     m_pScrollBar( new ScrollBar( this, WB_VERT ) ),
      85           0 :     m_pServer( pServer )
      86             : {
      87           0 :     m_pScrollBar->SetScrollHdl( LINK( this, ClientBox, ScrollHdl ) );
      88           0 :     m_pScrollBar->EnableDrag();
      89             : 
      90           0 :     m_aPinBox.SetUseThousandSep(false);
      91             : //     m_aPinDescription.SetText( String( SdResId( STR_ENTER_PIN ) ) );
      92             : 
      93           0 :     SetPaintTransparent( true );
      94           0 :     SetPosPixel( Point( RSC_SP_DLG_INNERBORDER_LEFT, RSC_SP_DLG_INNERBORDER_TOP ) );
      95           0 :     long nIconHeight = 2*TOP_OFFSET + SMALL_ICON_SIZE;
      96           0 :     long nTitleHeight = 2*TOP_OFFSET + GetTextHeight();
      97           0 :     if ( nIconHeight < nTitleHeight )
      98           0 :         m_nStdHeight = nTitleHeight;
      99             :     else
     100           0 :         m_nStdHeight = nIconHeight;
     101           0 :     m_nStdHeight += GetTextHeight() + TOP_OFFSET;
     102             : 
     103             : //     nIconHeight = ICON_HEIGHT + 2*TOP_OFFSET + 1;
     104             : //     if ( m_nStdHeight < nIconHeight )
     105             : //         m_nStdHeight = nIconHeight;
     106             : 
     107           0 :     m_nActiveHeight = m_nStdHeight;
     108             : 
     109           0 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     110           0 :     if( IsControlBackground() )
     111           0 :         SetBackground( GetControlBackground() );
     112             :     else
     113           0 :         SetBackground( rStyleSettings.GetFieldColor() );
     114             : 
     115           0 :     m_xRemoveListener = new ClientRemovedListener( this );
     116             : 
     117           0 :     Show();
     118           0 : }
     119             : 
     120             : //------------------------------------------------------------------------------
     121           0 : ClientBox::~ClientBox()
     122             : {
     123           0 :     if ( ! m_bInDelete )
     124           0 :         DeleteRemoved();
     125             : 
     126           0 :     m_bInDelete = true;
     127             : 
     128             :     typedef std::vector< TClientBoxEntry >::iterator ITER;
     129             : 
     130           0 :     for ( ITER iIndex = m_vEntries.begin(); iIndex < m_vEntries.end(); ++iIndex )
     131             :     {
     132             : //         (*iIndex)->m_xPackage->removeEventListener( uno::Reference< lang::XEventListener > ( m_xRemoveListener, uno::UNO_QUERY ) );
     133             :     }
     134             : 
     135           0 :     m_vEntries.clear();
     136             : 
     137           0 :     m_xRemoveListener.clear();
     138           0 : }
     139             : 
     140             : //------------------------------------------------------------------------------
     141             : // Title + description
     142           0 : void ClientBox::CalcActiveHeight( const long nPos )
     143             : {
     144             :     (void) nPos;
     145           0 :     const ::osl::MutexGuard aGuard( m_entriesMutex );
     146             : 
     147             :     // get title height
     148             :     long aTextHeight;
     149           0 :     long nIconHeight = 2*TOP_OFFSET + SMALL_ICON_SIZE;
     150           0 :     long nTitleHeight = 2*TOP_OFFSET + GetTextHeight();
     151           0 :     if ( nIconHeight < nTitleHeight )
     152           0 :         aTextHeight = nTitleHeight;
     153             :     else
     154           0 :         aTextHeight = nIconHeight;
     155             : 
     156             :     // Text entry height
     157           0 :     Size aSize = GetOutputSizePixel();
     158           0 :     if ( m_bHasScrollBar )
     159           0 :         aSize.Width() -= m_pScrollBar->GetSizePixel().Width();
     160             : 
     161           0 :     aSize.Width() -= ICON_OFFSET;
     162             : 
     163             :     aSize = LogicToPixel( Size( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ),
     164           0 :                                MapMode( MAP_APPFONT ) );
     165           0 :     aTextHeight += aSize.Height();
     166             : 
     167           0 :     if ( aTextHeight < m_nStdHeight )
     168           0 :         aTextHeight = m_nStdHeight;
     169             : 
     170           0 :     m_nActiveHeight = aTextHeight + 2;
     171           0 : }
     172             : 
     173             : //------------------------------------------------------------------------------
     174           0 : Rectangle ClientBox::GetEntryRect( const long nPos ) const
     175             : {
     176           0 :     const ::osl::MutexGuard aGuard( m_entriesMutex );
     177             : 
     178           0 :     Size aSize( GetOutputSizePixel() );
     179             : 
     180           0 :     if ( m_bHasScrollBar )
     181           0 :         aSize.Width() -= m_pScrollBar->GetSizePixel().Width();
     182             : 
     183           0 :     if ( m_vEntries[ nPos ]->m_bActive )
     184           0 :         aSize.Height() = m_nActiveHeight;
     185             :     else
     186           0 :         aSize.Height() = m_nStdHeight;
     187             : 
     188           0 :     Point aPos( 0, -m_nTopIndex + nPos * m_nStdHeight );
     189           0 :     if ( m_bHasActive && ( nPos < m_nActive ) )
     190           0 :         aPos.Y() += m_nActiveHeight - m_nStdHeight;
     191             : 
     192           0 :     return Rectangle( aPos, aSize );
     193             : }
     194             : 
     195             : //------------------------------------------------------------------------------
     196           0 : void ClientBox::DeleteRemoved()
     197             : {
     198           0 :     const ::osl::MutexGuard aGuard( m_entriesMutex );
     199             : 
     200           0 :     m_bInDelete = true;
     201             : 
     202           0 :     if ( ! m_vRemovedEntries.empty() )
     203             :     {
     204             :         typedef std::vector< TClientBoxEntry >::iterator ITER;
     205             : 
     206           0 :         m_vRemovedEntries.clear();
     207             :     }
     208             : 
     209           0 :     m_bInDelete = false;
     210           0 : }
     211             : 
     212           0 : long ClientBox::GetActiveEntryIndex()
     213             : {
     214           0 :     if ( m_bHasActive )
     215           0 :         return m_nActive;
     216             :     else
     217           0 :         return -1;
     218             : }
     219             : 
     220             : //------------------------------------------------------------------------------
     221             : //This function may be called with nPos < 0
     222           0 : void ClientBox::selectEntry( const long nPos )
     223             : {
     224             :     //ToDo whe should not use the guard at such a big scope here.
     225             :     //Currently it is used to gard m_vEntries and m_nActive. m_nActive will be
     226             :     //modified in this function.
     227             :     //It would be probably best to always use a copy of m_vEntries
     228             :     //and some other state variables from ClientBox for
     229             :     //the whole painting operation. See issue i86993
     230           0 :     ::osl::ClearableMutexGuard guard(m_entriesMutex);
     231             : 
     232           0 :     if ( m_bInCheckMode )
     233             :         return;
     234             : 
     235           0 :     if ( m_bHasActive )
     236             :     {
     237           0 :         if ( nPos == m_nActive )
     238             :             return;
     239             : 
     240           0 :         m_bHasActive = false;
     241           0 :         m_vEntries[ m_nActive ]->m_bActive = false;
     242             :     }
     243             : 
     244           0 :     if ( ( nPos >= 0 ) && ( nPos < (long) m_vEntries.size() ) )
     245             :     {
     246           0 :         m_bHasActive = true;
     247           0 :         m_nActive = nPos;
     248           0 :         m_vEntries[ nPos ]->m_bActive = true;
     249             : 
     250           0 :         if ( IsReallyVisible() )
     251             :         {
     252           0 :             m_bAdjustActive = true;
     253             :         }
     254             :     }
     255             : 
     256           0 :     if ( IsReallyVisible() )
     257             :     {
     258           0 :         m_bNeedsRecalc = true;
     259           0 :         Invalidate();
     260             :     }
     261             : 
     262           0 :     guard.clear();
     263             : }
     264             : 
     265             : // -----------------------------------------------------------------------
     266           0 : void ClientBox::DrawRow( const Rectangle& rRect, const TClientBoxEntry pEntry )
     267             : {
     268           0 :     const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
     269             : 
     270           0 :     if ( pEntry->m_bActive )
     271           0 :         SetTextColor( rStyleSettings.GetHighlightTextColor() );
     272             :     else
     273           0 :         SetTextColor( rStyleSettings.GetFieldTextColor() );
     274             : 
     275           0 :     if ( pEntry->m_bActive )
     276             :     {
     277           0 :         SetLineColor();
     278           0 :         SetFillColor( rStyleSettings.GetHighlightColor() );
     279           0 :         DrawRect( rRect );
     280             :     }
     281             :     else
     282             :     {
     283           0 :         if( IsControlBackground() )
     284           0 :             SetBackground( GetControlBackground() );
     285             :         else
     286           0 :             SetBackground( rStyleSettings.GetFieldColor() );
     287             : 
     288           0 :         SetTextFillColor();
     289           0 :         Erase( rRect );
     290             :     }
     291             : 
     292             :     // FIXME: draw bluetooth or wifi icon
     293           0 :      Point aPos( rRect.TopLeft() );
     294             : //     aPos += Point( TOP_OFFSET, TOP_OFFSET );
     295             : //     Image aImage;
     296             : //     if ( ! pEntry->m_aIcon )
     297             : //         aImage = m_aDefaultImage;
     298             : //     else
     299             : //         aImage = pEntry->m_aIcon;
     300             : //     Size aImageSize = aImage.GetSizePixel();
     301             : //     if ( ( aImageSize.Width() <= ICON_WIDTH ) && ( aImageSize.Height() <= ICON_HEIGHT ) )
     302             : //         DrawImage( Point( aPos.X()+((ICON_WIDTH-aImageSize.Width())/2), aPos.Y()+((ICON_HEIGHT-aImageSize.Height())/2) ), aImage );
     303             : //     else
     304             : //         DrawImage( aPos, Size( ICON_WIDTH, ICON_HEIGHT ), aImage );
     305             : 
     306             :     // Setup fonts
     307           0 :     Font aStdFont( GetFont() );
     308           0 :     Font aBoldFont( aStdFont );
     309           0 :     aBoldFont.SetWeight( WEIGHT_BOLD );
     310           0 :     SetFont( aBoldFont );
     311           0 :     long aTextHeight = GetTextHeight();
     312             : 
     313             :     // Get max title width
     314           0 :     long nMaxTitleWidth = rRect.GetWidth() - ICON_OFFSET;
     315           0 :     nMaxTitleWidth -= ( 2 * SMALL_ICON_SIZE ) + ( 4 * SPACE_BETWEEN );
     316             : 
     317           0 :     long aTitleWidth = GetTextWidth( String( pEntry->m_pClientInfo->mName ) ) + (aTextHeight / 3);
     318             : 
     319           0 :     aPos = rRect.TopLeft() + Point( ICON_OFFSET, TOP_OFFSET );
     320             : 
     321           0 :     if ( aTitleWidth > nMaxTitleWidth )
     322             :     {
     323           0 :         aTitleWidth = nMaxTitleWidth - (aTextHeight / 3);
     324           0 :         String aShortTitle = GetEllipsisString( pEntry->m_pClientInfo->mName,
     325           0 :                                                 aTitleWidth );
     326           0 :         DrawText( aPos, aShortTitle );
     327           0 :         aTitleWidth += (aTextHeight / 3);
     328             :     }
     329             :     else
     330           0 :         DrawText( aPos, pEntry->m_pClientInfo->mName );
     331             : 
     332           0 :     SetFont( aStdFont );
     333             : 
     334           0 :     aPos.Y() += aTextHeight;
     335           0 :     if ( pEntry->m_bActive )
     336             :     {
     337             :         Size aSize = LogicToPixel( Size( RSC_CD_PUSHBUTTON_WIDTH, RSC_CD_PUSHBUTTON_HEIGHT ),
     338           0 :                                MapMode( MAP_APPFONT ) );
     339           0 :         m_aPinBox.SetSizePixel( aSize );
     340           0 :         const Rectangle aRect( GetEntryRect( m_nActive ) );
     341           0 :         Size  aBtnSize( m_aPinBox.GetSizePixel() );
     342             :         Point aBtnPos( aRect.Left(),
     343           0 :                    aRect.Bottom() - TOP_OFFSET - aBtnSize.Height() );
     344             : //         m_aPinDescription.SetPosPixel( aBtnPos );
     345           0 :         DrawText( Rectangle( aBtnPos.X(), aBtnPos.Y(), rRect.Right(), rRect.Bottom() - TOP_OFFSET),
     346           0 :                   String( SdResId( STR_ENTER_PIN ) ), 0 );
     347             : 
     348           0 :         aBtnPos = Point( aRect.Left() + GetTextWidth( String( SdResId( STR_ENTER_PIN ) ) ),
     349           0 :                    aRect.Bottom() - TOP_OFFSET - aBtnSize.Height() );
     350             : 
     351           0 :         m_aPinBox.SetPosPixel( aBtnPos );
     352             : 
     353             : 
     354             : 
     355             : 
     356             : 
     357             : //         long nExtraHeight = 0;
     358             : //
     359             : //         if ( pEntry->m_bHasButtons )
     360             : //             nExtraHeight = m_nExtraHeight;
     361             : //
     362             : //         DrawText( Rectangle( aPos.X(), aPos.Y(), rRect.Right(), rRect.Bottom() - nExtraHeight ),
     363             : //                   sDescription, TEXT_DRAW_MULTILINE | TEXT_DRAW_WORDBREAK );
     364             :     }
     365             :     else
     366             :     {
     367             :     }
     368             : 
     369           0 :     SetLineColor( Color( COL_LIGHTGRAY ) );
     370           0 :     DrawLine( rRect.BottomLeft(), rRect.BottomRight() );
     371           0 : }
     372             : 
     373             : // -----------------------------------------------------------------------
     374           0 : void ClientBox::RecalcAll()
     375             : {
     376           0 :     if ( m_bHasActive )
     377           0 :         CalcActiveHeight( m_nActive );
     378             : 
     379           0 :     SetupScrollBar();
     380             : 
     381           0 :     if ( m_bHasActive )
     382             :     {
     383           0 :         Rectangle aEntryRect = GetEntryRect( m_nActive );
     384             : 
     385           0 :         if ( m_bAdjustActive )
     386             :         {
     387           0 :             m_bAdjustActive = false;
     388             : 
     389             :             // If the top of the selected entry isn't visible, make it visible
     390           0 :             if ( aEntryRect.Top() < 0 )
     391             :             {
     392           0 :                 m_nTopIndex += aEntryRect.Top();
     393           0 :                 aEntryRect.Move( 0, -aEntryRect.Top() );
     394             :             }
     395             : 
     396             :             // If the bottom of the selected entry isn't visible, make it visible even if now the top
     397             :             // isn't visible any longer ( the buttons are more important )
     398           0 :             Size aOutputSize = GetOutputSizePixel();
     399           0 :             if ( aEntryRect.Bottom() > aOutputSize.Height() )
     400             :             {
     401           0 :                 m_nTopIndex += ( aEntryRect.Bottom() - aOutputSize.Height() );
     402           0 :                 aEntryRect.Move( 0, -( aEntryRect.Bottom() - aOutputSize.Height() ) );
     403             :             }
     404             : 
     405             :             // If there is unused space below the last entry but all entries don't fit into the box,
     406             :             // move the content down to use the whole space
     407           0 :             const long nTotalHeight = GetTotalHeight();
     408           0 :             if ( m_bHasScrollBar && ( aOutputSize.Height() + m_nTopIndex > nTotalHeight ) )
     409             :             {
     410           0 :                 long nOffset = m_nTopIndex;
     411           0 :                 m_nTopIndex = nTotalHeight - aOutputSize.Height();
     412           0 :                 nOffset -= m_nTopIndex;
     413           0 :                 aEntryRect.Move( 0, nOffset );
     414             :             }
     415             : 
     416           0 :             if ( m_bHasScrollBar )
     417           0 :                 m_pScrollBar->SetThumbPos( m_nTopIndex );
     418             :         }
     419             :     }
     420             : 
     421           0 :     m_bNeedsRecalc = false;
     422           0 : }
     423             : 
     424             : // -----------------------------------------------------------------------
     425           0 : bool ClientBox::HandleTabKey( bool )
     426             : {
     427           0 :     return false;
     428             : }
     429             : 
     430             : // -----------------------------------------------------------------------
     431           0 : bool ClientBox::HandleCursorKey( sal_uInt16 nKeyCode )
     432             : {
     433           0 :     if ( m_vEntries.empty() )
     434           0 :         return true;
     435             : 
     436           0 :     long nSelect = 0;
     437             : 
     438           0 :     if ( m_bHasActive )
     439             :     {
     440           0 :         long nPageSize = GetOutputSizePixel().Height() / m_nStdHeight;
     441           0 :         if ( nPageSize < 2 )
     442           0 :             nPageSize = 2;
     443             : 
     444           0 :         if ( ( nKeyCode == KEY_DOWN ) || ( nKeyCode == KEY_RIGHT ) )
     445           0 :             nSelect = m_nActive + 1;
     446           0 :         else if ( ( nKeyCode == KEY_UP ) || ( nKeyCode == KEY_LEFT ) )
     447           0 :             nSelect = m_nActive - 1;
     448           0 :         else if ( nKeyCode == KEY_HOME )
     449           0 :             nSelect = 0;
     450           0 :         else if ( nKeyCode == KEY_END )
     451           0 :             nSelect = m_vEntries.size() - 1;
     452           0 :         else if ( nKeyCode == KEY_PAGEUP )
     453           0 :             nSelect = m_nActive - nPageSize + 1;
     454           0 :         else if ( nKeyCode == KEY_PAGEDOWN )
     455           0 :             nSelect = m_nActive + nPageSize - 1;
     456             :     }
     457             :     else // when there is no selected entry, we will select the first or the last.
     458             :     {
     459           0 :         if ( ( nKeyCode == KEY_DOWN ) || ( nKeyCode == KEY_PAGEDOWN ) || ( nKeyCode == KEY_HOME ) )
     460           0 :             nSelect = 0;
     461           0 :         else if ( ( nKeyCode == KEY_UP ) || ( nKeyCode == KEY_PAGEUP ) || ( nKeyCode == KEY_END ) )
     462           0 :             nSelect = m_vEntries.size() - 1;
     463             :     }
     464             : 
     465           0 :     if ( nSelect < 0 )
     466           0 :         nSelect = 0;
     467           0 :     if ( nSelect >= (long) m_vEntries.size() )
     468           0 :         nSelect = m_vEntries.size() - 1;
     469             : 
     470           0 :     selectEntry( nSelect );
     471             : 
     472           0 :     return true;
     473             : }
     474             : 
     475             : // -----------------------------------------------------------------------
     476           0 : void ClientBox::Paint( const Rectangle &/*rPaintRect*/ )
     477             : {
     478           0 :     if ( !m_bInDelete )
     479           0 :         DeleteRemoved();
     480             : 
     481           0 :     if ( m_bNeedsRecalc )
     482           0 :         RecalcAll();
     483             : 
     484           0 :     Point aStart( 0, -m_nTopIndex );
     485           0 :     Size aSize( GetOutputSizePixel() );
     486             : 
     487           0 :     if ( m_bHasScrollBar )
     488           0 :         aSize.Width() -= m_pScrollBar->GetSizePixel().Width();
     489             : 
     490           0 :     const ::osl::MutexGuard aGuard( m_entriesMutex );
     491             : 
     492             :     typedef std::vector< TClientBoxEntry >::iterator ITER;
     493           0 :     for ( ITER iIndex = m_vEntries.begin(); iIndex < m_vEntries.end(); ++iIndex )
     494             :     {
     495           0 :         aSize.Height() = (*iIndex)->m_bActive ? m_nActiveHeight : m_nStdHeight;
     496           0 :         Rectangle aEntryRect( aStart, aSize );
     497           0 :         DrawRow( aEntryRect, *iIndex );
     498           0 :         aStart.Y() += aSize.Height();
     499           0 :     }
     500           0 : }
     501             : 
     502             : // -----------------------------------------------------------------------
     503           0 : long ClientBox::GetTotalHeight() const
     504             : {
     505           0 :     long nHeight = m_vEntries.size() * m_nStdHeight;
     506             : 
     507           0 :     if ( m_bHasActive )
     508             :     {
     509           0 :         nHeight += m_nActiveHeight - m_nStdHeight;
     510             :     }
     511             : 
     512           0 :     return nHeight;
     513             : }
     514             : 
     515             : // -----------------------------------------------------------------------
     516           0 : void ClientBox::SetupScrollBar()
     517             : {
     518           0 :     const Size aSize = GetOutputSizePixel();
     519           0 :     const long nScrBarSize = GetSettings().GetStyleSettings().GetScrollBarSize();
     520           0 :     const long nTotalHeight = GetTotalHeight();
     521           0 :     const bool bNeedsScrollBar = ( nTotalHeight > aSize.Height() );
     522             : 
     523           0 :     if ( bNeedsScrollBar )
     524             :     {
     525           0 :         if ( m_nTopIndex + aSize.Height() > nTotalHeight )
     526           0 :             m_nTopIndex = nTotalHeight - aSize.Height();
     527             : 
     528           0 :         m_pScrollBar->SetPosSizePixel( Point( aSize.Width() - nScrBarSize, 0 ),
     529           0 :                                        Size( nScrBarSize, aSize.Height() ) );
     530           0 :         m_pScrollBar->SetRangeMax( nTotalHeight );
     531           0 :         m_pScrollBar->SetVisibleSize( aSize.Height() );
     532           0 :         m_pScrollBar->SetPageSize( ( aSize.Height() * 4 ) / 5 );
     533           0 :         m_pScrollBar->SetLineSize( m_nStdHeight );
     534           0 :         m_pScrollBar->SetThumbPos( m_nTopIndex );
     535             : 
     536           0 :         if ( !m_bHasScrollBar )
     537           0 :             m_pScrollBar->Show();
     538             :     }
     539           0 :     else if ( m_bHasScrollBar )
     540             :     {
     541           0 :         m_pScrollBar->Hide();
     542           0 :         m_nTopIndex = 0;
     543             :     }
     544             : 
     545           0 :     m_bHasScrollBar = bNeedsScrollBar;
     546           0 : }
     547             : 
     548             : // -----------------------------------------------------------------------
     549           0 : void ClientBox::Resize()
     550             : {
     551           0 :     RecalcAll();
     552           0 : }
     553             : 
     554             : //------------------------------------------------------------------------------
     555           0 : long ClientBox::PointToPos( const Point& rPos )
     556             : {
     557           0 :     long nPos = ( rPos.Y() + m_nTopIndex ) / m_nStdHeight;
     558             : 
     559           0 :     if ( m_bHasActive && ( nPos > m_nActive ) )
     560             :     {
     561           0 :         if ( rPos.Y() + m_nTopIndex <= m_nActive*m_nStdHeight + m_nActiveHeight )
     562           0 :             nPos = m_nActive;
     563             :         else
     564           0 :             nPos = ( rPos.Y() + m_nTopIndex - (m_nActiveHeight - m_nStdHeight) ) / m_nStdHeight;
     565             :     }
     566             : 
     567           0 :     return nPos;
     568             : }
     569             : 
     570           0 : OUString ClientBox::getPin()
     571             : {
     572           0 :     return OUString::valueOf( m_aPinBox.GetValue() );
     573             : }
     574             : 
     575             : //------------------------------------------------------------------------------
     576           0 : void ClientBox::MouseButtonDown( const MouseEvent& rMEvt )
     577             : {
     578           0 :     long nPos = PointToPos( rMEvt.GetPosPixel() );
     579             : 
     580           0 :     if ( rMEvt.IsLeft() )
     581             :     {
     582           0 :         if ( rMEvt.IsMod1() && m_bHasActive )
     583           0 :             selectEntry( m_vEntries.size() );   // Selecting an not existing entry will deselect the current one
     584             :         else
     585           0 :             selectEntry( nPos );
     586             :     }
     587           0 : }
     588             : 
     589             : //------------------------------------------------------------------------------
     590           0 : long ClientBox::Notify( NotifyEvent& rNEvt )
     591             : {
     592           0 :     if ( !m_bInDelete )
     593           0 :         DeleteRemoved();
     594             : 
     595           0 :     bool bHandled = false;
     596             : 
     597           0 :     if ( rNEvt.GetType() == EVENT_KEYINPUT )
     598             :     {
     599           0 :         const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
     600           0 :         KeyCode         aKeyCode = pKEvt->GetKeyCode();
     601           0 :         sal_uInt16          nKeyCode = aKeyCode.GetCode();
     602             : 
     603           0 :         if ( nKeyCode == KEY_TAB )
     604           0 :             bHandled = HandleTabKey( aKeyCode.IsShift() );
     605           0 :         else if ( aKeyCode.GetGroup() == KEYGROUP_CURSOR )
     606           0 :             bHandled = HandleCursorKey( nKeyCode );
     607             :     }
     608             : 
     609           0 :     if ( rNEvt.GetType() == EVENT_COMMAND )
     610             :     {
     611           0 :         if ( m_bHasScrollBar &&
     612           0 :              ( rNEvt.GetCommandEvent()->GetCommand() == COMMAND_WHEEL ) )
     613             :         {
     614           0 :             const CommandWheelData* pData = rNEvt.GetCommandEvent()->GetWheelData();
     615           0 :             if ( pData->GetMode() == COMMAND_WHEEL_SCROLL )
     616             :             {
     617           0 :                 long nThumbPos = m_pScrollBar->GetThumbPos();
     618           0 :                 if ( pData->GetDelta() < 0 )
     619           0 :                     m_pScrollBar->DoScroll( nThumbPos + m_nStdHeight );
     620             :                 else
     621           0 :                     m_pScrollBar->DoScroll( nThumbPos - m_nStdHeight );
     622           0 :                 bHandled = true;
     623             :             }
     624             :         }
     625             :     }
     626             : 
     627           0 :     if ( !bHandled )
     628           0 :         return Control::Notify( rNEvt );
     629             :     else
     630           0 :         return true;
     631             : }
     632             : 
     633             : 
     634             : //------------------------------------------------------------------------------
     635           0 : long ClientBox::addEntry( ClientInfo* pClientInfo )
     636             : {
     637           0 :     long         nPos = 0;
     638             : //     PackageState eState = m_pManager->getPackageState( xPackage );
     639             : //     bool         bLocked = m_pManager->isReadOnly( xPackage );
     640             : 
     641           0 :     TClientBoxEntry pEntry( new ClientBoxEntry( pClientInfo ) );
     642             : 
     643           0 :     bool bNewEntryInserted = false;
     644             : 
     645           0 :     ::osl::ClearableMutexGuard guard(m_entriesMutex);
     646           0 :     if ( m_vEntries.empty() )
     647             :     {
     648           0 :         m_vEntries.push_back( pEntry );
     649           0 :         bNewEntryInserted = true;
     650             :     }
     651             :     else
     652             :     {
     653             : //         if ( !FindEntryPos( pEntry, 0, m_vEntries.size()-1, nPos ) )
     654             : //         {
     655           0 :             m_vEntries.insert( m_vEntries.begin()+nPos, pEntry );
     656           0 :             bNewEntryInserted = true;
     657             : //         }
     658             : //         else if ( !m_bInCheckMode )
     659             : //         {
     660             : //             OSL_FAIL( "ClientBox::addEntry(): Will not add duplicate entries"  );
     661             : //         }
     662             :     }
     663             : 
     664             :     //Related: rhbz#702833 Only add a Listener if we're adding a new entry, to
     665             :     //keep in sync with removeEventListener logic
     666             :     if (bNewEntryInserted)
     667             :     {
     668             : 
     669             :         //         pEntry->m_xPackage->addEventListener(uno::Reference< lang::XEventListener > ( m_xRemoveListener, uno::UNO_QUERY ) );
     670             :     }
     671             : 
     672             : 
     673             : //     pEntry->m_bHasOptions = m_pManager->supportsOptions( xPackage );
     674             : //     pEntry->m_bUser       = xPackage->getRepositoryName().equals( USER_PACKAGE_MANAGER );
     675             : //     pEntry->m_bShared     = xPackage->getRepositoryName().equals( SHARED_PACKAGE_MANAGER );
     676             : //     pEntry->m_bNew        = m_bInCheckMode;
     677             : //     pEntry->m_bMissingLic = bLicenseMissing;
     678             : 
     679             : //     if ( bLicenseMissing )
     680             : //         pEntry->m_sErrorText = DialogHelper::getResourceString( RID_STR_ERROR_MISSING_LICENSE );
     681             : 
     682             :     //access to m_nActive must be guarded
     683           0 :     if ( !m_bInCheckMode && m_bHasActive && ( m_nActive >= nPos ) )
     684           0 :         m_nActive += 1;
     685             : 
     686           0 :     guard.clear();
     687             : 
     688           0 :     if ( IsReallyVisible() )
     689           0 :         Invalidate();
     690             : 
     691           0 :     m_bNeedsRecalc = true;
     692             : 
     693           0 :     return nPos;
     694             : }
     695             : 
     696             : // -----------------------------------------------------------------------
     697           0 : void ClientBox::DoScroll( long nDelta )
     698             : {
     699           0 :     m_nTopIndex += nDelta;
     700           0 :     Point aNewSBPt( m_pScrollBar->GetPosPixel() );
     701             : 
     702           0 :     Rectangle aScrRect( Point(), GetOutputSizePixel() );
     703           0 :     aScrRect.Right() -= m_pScrollBar->GetSizePixel().Width();
     704           0 :     Scroll( 0, -nDelta, aScrRect );
     705             : 
     706           0 :     m_pScrollBar->SetPosPixel( aNewSBPt );
     707           0 : }
     708             : 
     709             : // -----------------------------------------------------------------------
     710           0 : IMPL_LINK( ClientBox, ScrollHdl, ScrollBar*, pScrBar )
     711             : {
     712           0 :     DoScroll( pScrBar->GetDelta() );
     713             : 
     714           0 :     return 1;
     715             : }
     716             : 
     717             : } //namespace dp_gui
     718             : 
     719             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10