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

Generated by: LCOV version 1.10