LCOV - code coverage report
Current view: top level - libreoffice/desktop/source/deployment/gui - license_dialog.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 98 0.0 %
Date: 2012-12-27 Functions: 0 25 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             : 
      21             : #include "cppuhelper/implbase2.hxx"
      22             : #include "cppuhelper/implementationentry.hxx"
      23             : #include "unotools/configmgr.hxx"
      24             : #include "comphelper/servicedecl.hxx"
      25             : #include "comphelper/unwrapargs.hxx"
      26             : #include "i18npool/mslangid.hxx"
      27             : #include "vcl/svapp.hxx"
      28             : #include "vcl/msgbox.hxx"
      29             : #include "toolkit/helper/vclunohelper.hxx"
      30             : #include "com/sun/star/lang/XServiceInfo.hpp"
      31             : #include "com/sun/star/task/XJobExecutor.hpp"
      32             : #include "svtools/svmedit.hxx"
      33             : #include "svl/lstner.hxx"
      34             : #include "vcl/xtextedt.hxx"
      35             : #include <vcl/scrbar.hxx>
      36             : #include "vcl/threadex.hxx"
      37             : 
      38             : 
      39             : 
      40             : #include "boost/bind.hpp"
      41             : #include "dp_gui_shared.hxx"
      42             : #include "license_dialog.hxx"
      43             : #include "dp_gui.hrc"
      44             : 
      45             : using namespace ::dp_misc;
      46             : namespace cssu = ::com::sun::star::uno;
      47             : using namespace ::com::sun::star;
      48             : using namespace ::com::sun::star::uno;
      49             : using ::rtl::OUString;
      50             : 
      51             : namespace dp_gui {
      52             : 
      53             : class LicenseView : public MultiLineEdit, public SfxListener
      54             : {
      55             :     sal_Bool            mbEndReached;
      56             :     Link            maEndReachedHdl;
      57             :     Link            maScrolledHdl;
      58             : 
      59             : public:
      60             :     LicenseView( Window* pParent, const ResId& rResId );
      61             :     ~LicenseView();
      62             : 
      63             :     void ScrollDown( ScrollType eScroll );
      64             : 
      65             :     sal_Bool IsEndReached() const;
      66           0 :     sal_Bool EndReached() const { return mbEndReached; }
      67             :     void SetEndReached( sal_Bool bEnd ) { mbEndReached = bEnd; }
      68             : 
      69           0 :     void SetEndReachedHdl( const Link& rHdl )  { maEndReachedHdl = rHdl; }
      70             :     const Link& GetAutocompleteHdl() const { return maEndReachedHdl; }
      71             : 
      72           0 :     void SetScrolledHdl( const Link& rHdl )  { maScrolledHdl = rHdl; }
      73             :     const Link& GetScrolledHdl() const { return maScrolledHdl; }
      74             : 
      75             :     virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
      76             : 
      77             : protected:
      78             :     using MultiLineEdit::Notify;
      79             : };
      80             : 
      81             : struct LicenseDialogImpl : public ModalDialog
      82             : {
      83             :     cssu::Reference<cssu::XComponentContext> m_xComponentContext;
      84             :     FixedText m_ftHead;
      85             :     FixedText m_ftBody1;
      86             :     FixedText m_ftBody1Txt;
      87             :     FixedText m_ftBody2;
      88             :     FixedText m_ftBody2Txt;
      89             :     FixedImage m_fiArrow1;
      90             :     FixedImage m_fiArrow2;
      91             :     LicenseView m_mlLicense;
      92             :     PushButton m_pbDown;
      93             :     FixedLine m_flBottom;
      94             : 
      95             :     OKButton m_acceptButton;
      96             :     CancelButton m_declineButton;
      97             : 
      98             :     DECL_LINK(PageDownHdl, void *);
      99             :     DECL_LINK(ScrolledHdl, void *);
     100             :     DECL_LINK(EndReachedHdl, void *);
     101             : 
     102             :     bool m_bLicenseRead;
     103             : 
     104             :     virtual ~LicenseDialogImpl();
     105             : 
     106             :     LicenseDialogImpl(
     107             :         Window * pParent,
     108             :         css::uno::Reference< css::uno::XComponentContext > const & xContext,
     109             :         const ::rtl::OUString & sExtensionName,
     110             :         const ::rtl::OUString & sLicenseText);
     111             : 
     112             :     virtual void Activate();
     113             : 
     114             : };
     115             : 
     116           0 : LicenseView::LicenseView( Window* pParent, const ResId& rResId )
     117           0 :     : MultiLineEdit( pParent, rResId )
     118             : {
     119           0 :     SetLeftMargin( 5 );
     120           0 :     mbEndReached = IsEndReached();
     121           0 :     StartListening( *GetTextEngine() );
     122           0 : }
     123             : 
     124           0 : LicenseView::~LicenseView()
     125             : {
     126           0 :     maEndReachedHdl = Link();
     127           0 :     maScrolledHdl   = Link();
     128           0 :     EndListeningAll();
     129           0 : }
     130             : 
     131           0 : void LicenseView::ScrollDown( ScrollType eScroll )
     132             : {
     133           0 :     ScrollBar*  pScroll = GetVScrollBar();
     134           0 :     if ( pScroll )
     135           0 :         pScroll->DoScrollAction( eScroll );
     136           0 : }
     137             : 
     138           0 : sal_Bool LicenseView::IsEndReached() const
     139             : {
     140             :     sal_Bool bEndReached;
     141             : 
     142           0 :     ExtTextView*    pView = GetTextView();
     143           0 :     ExtTextEngine*  pEdit = GetTextEngine();
     144           0 :     sal_uLong           nHeight = pEdit->GetTextHeight();
     145           0 :     Size            aOutSize = pView->GetWindow()->GetOutputSizePixel();
     146           0 :     Point           aBottom( 0, aOutSize.Height() );
     147             : 
     148           0 :     if ( (sal_uLong) pView->GetDocPos( aBottom ).Y() >= nHeight - 1 )
     149           0 :         bEndReached = sal_True;
     150             :     else
     151           0 :         bEndReached = sal_False;
     152             : 
     153           0 :     return bEndReached;
     154             : }
     155             : 
     156           0 : void LicenseView::Notify( SfxBroadcaster&, const SfxHint& rHint )
     157             : {
     158           0 :     if ( rHint.IsA( TYPE(TextHint) ) )
     159             :     {
     160           0 :         sal_Bool    bLastVal = EndReached();
     161           0 :         sal_uLong   nId = ((const TextHint&)rHint).GetId();
     162             : 
     163           0 :         if ( nId == TEXT_HINT_PARAINSERTED )
     164             :         {
     165           0 :             if ( bLastVal )
     166           0 :                 mbEndReached = IsEndReached();
     167             :         }
     168           0 :         else if ( nId == TEXT_HINT_VIEWSCROLLED )
     169             :         {
     170           0 :             if ( ! mbEndReached )
     171           0 :                 mbEndReached = IsEndReached();
     172           0 :             maScrolledHdl.Call( this );
     173             :         }
     174             : 
     175           0 :         if ( EndReached() && !bLastVal )
     176             :         {
     177           0 :             maEndReachedHdl.Call( this );
     178             :         }
     179             :     }
     180           0 : }
     181             : 
     182             : //==============================================================================================================
     183             : 
     184           0 : LicenseDialogImpl::LicenseDialogImpl(
     185             :     Window * pParent,
     186             :     cssu::Reference< cssu::XComponentContext > const & xContext,
     187             :     const ::rtl::OUString & sExtensionName,
     188             :     const ::rtl::OUString & sLicenseText):
     189             :         ModalDialog(pParent, DpGuiResId(RID_DLG_LICENSE))
     190             :         ,m_xComponentContext(xContext)
     191             :         ,m_ftHead(this, DpGuiResId(FT_LICENSE_HEADER))
     192             :         ,m_ftBody1(this, DpGuiResId(FT_LICENSE_BODY_1))
     193             :         ,m_ftBody1Txt(this, DpGuiResId(FT_LICENSE_BODY_1_TXT))
     194             :         ,m_ftBody2(this, DpGuiResId(FT_LICENSE_BODY_2))
     195             :         ,m_ftBody2Txt(this, DpGuiResId(FT_LICENSE_BODY_2_TXT))
     196             :         ,m_fiArrow1(this, DpGuiResId(FI_LICENSE_ARROW1))
     197             :         ,m_fiArrow2(this, DpGuiResId(FI_LICENSE_ARROW2))
     198             :         ,m_mlLicense(this, DpGuiResId(ML_LICENSE))
     199             :         ,m_pbDown(this, DpGuiResId(PB_LICENSE_DOWN))
     200             :         ,m_flBottom(this, DpGuiResId(FL_LICENSE))
     201             :         ,m_acceptButton(this, DpGuiResId(BTN_LICENSE_ACCEPT))
     202             :         ,m_declineButton(this, DpGuiResId(BTN_LICENSE_DECLINE))
     203           0 :         ,m_bLicenseRead(false)
     204             : 
     205             : {
     206             : 
     207           0 :     FreeResource();
     208             : 
     209           0 :     m_acceptButton.SetUniqueId(UID_BTN_LICENSE_ACCEPT);
     210           0 :     m_fiArrow1.Show(true);
     211           0 :     m_fiArrow2.Show(false);
     212           0 :     m_mlLicense.SetText(sLicenseText);
     213           0 :     m_ftHead.SetText(m_ftHead.GetText() + OUString('\n') + sExtensionName);
     214             : 
     215           0 :     m_mlLicense.SetEndReachedHdl( LINK(this, LicenseDialogImpl, EndReachedHdl) );
     216           0 :     m_mlLicense.SetScrolledHdl( LINK(this, LicenseDialogImpl, ScrolledHdl) );
     217           0 :     m_pbDown.SetClickHdl( LINK(this, LicenseDialogImpl, PageDownHdl) );
     218             : 
     219             :     // We want a automatic repeating page down button
     220           0 :     WinBits aStyle = m_pbDown.GetStyle();
     221           0 :     aStyle |= WB_REPEAT;
     222           0 :     m_pbDown.SetStyle( aStyle );
     223           0 : }
     224             : 
     225           0 : LicenseDialogImpl::~LicenseDialogImpl()
     226             : {
     227           0 : }
     228             : 
     229           0 : void LicenseDialogImpl::Activate()
     230             : {
     231           0 :     if (!m_bLicenseRead)
     232             :     {
     233             :         //Only enable the scroll down button if the license text does not fit into the window
     234           0 :         if (m_mlLicense.IsEndReached())
     235             :         {
     236           0 :             m_pbDown.Disable();
     237           0 :             m_acceptButton.Enable();
     238           0 :             m_acceptButton.GrabFocus();
     239             :         }
     240             :         else
     241             :         {
     242           0 :             m_pbDown.Enable();
     243           0 :             m_pbDown.GrabFocus();
     244           0 :             m_acceptButton.Disable();
     245             :         }
     246             :     }
     247           0 : }
     248             : 
     249           0 : IMPL_LINK_NOARG(LicenseDialogImpl, ScrolledHdl)
     250             : {
     251             : 
     252           0 :     if (m_mlLicense.IsEndReached())
     253           0 :         m_pbDown.Disable();
     254             :     else
     255           0 :         m_pbDown.Enable();
     256             : 
     257           0 :     return 0;
     258             : }
     259             : 
     260           0 : IMPL_LINK_NOARG(LicenseDialogImpl, PageDownHdl)
     261             : {
     262           0 :     m_mlLicense.ScrollDown( SCROLL_PAGEDOWN );
     263           0 :     return 0;
     264             : }
     265             : 
     266           0 : IMPL_LINK_NOARG(LicenseDialogImpl, EndReachedHdl)
     267             : {
     268           0 :     m_acceptButton.Enable();
     269           0 :     m_acceptButton.GrabFocus();
     270           0 :     m_fiArrow1.Show(false);
     271           0 :     m_fiArrow2.Show(true);
     272           0 :     m_bLicenseRead = true;
     273           0 :     return 0;
     274             : }
     275             : 
     276             : //=================================================================================
     277             : 
     278             : 
     279             : 
     280             : 
     281           0 : LicenseDialog::LicenseDialog( Sequence<Any> const& args,
     282             :                           Reference<XComponentContext> const& xComponentContext)
     283           0 :     : m_xComponentContext(xComponentContext)
     284             : {
     285           0 :     comphelper::unwrapArgs( args, m_parent, m_sExtensionName, m_sLicenseText );
     286           0 : }
     287             : 
     288             : // XExecutableDialog
     289             : //______________________________________________________________________________
     290           0 : void LicenseDialog::setTitle( OUString const & ) throw (RuntimeException)
     291             : {
     292             : 
     293           0 : }
     294             : 
     295             : //______________________________________________________________________________
     296           0 : sal_Int16 LicenseDialog::execute() throw (RuntimeException)
     297             : {
     298             :     return vcl::solarthread::syncExecute(
     299           0 :         boost::bind( &LicenseDialog::solar_execute, this));
     300             : }
     301             : 
     302           0 : sal_Int16 LicenseDialog::solar_execute()
     303             : {
     304             :     std::auto_ptr<LicenseDialogImpl> dlg(
     305             :         new LicenseDialogImpl(
     306           0 :             VCLUnoHelper::GetWindow(m_parent),
     307           0 :             m_xComponentContext, m_sExtensionName, m_sLicenseText));
     308             : 
     309           0 :     return dlg->Execute();
     310             : }
     311             : 
     312           0 : } // namespace dp_gui
     313             : 
     314             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10