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

Generated by: LCOV version 1.10