1*2722ceddSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2722ceddSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2722ceddSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2722ceddSAndrew Rist * distributed with this work for additional information 6*2722ceddSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2722ceddSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2722ceddSAndrew Rist * "License"); you may not use this file except in compliance 9*2722ceddSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2722ceddSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2722ceddSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2722ceddSAndrew Rist * software distributed under the License is distributed on an 15*2722ceddSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2722ceddSAndrew Rist * KIND, either express or implied. See the License for the 17*2722ceddSAndrew Rist * specific language governing permissions and limitations 18*2722ceddSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2722ceddSAndrew Rist *************************************************************/ 21*2722ceddSAndrew Rist 22*2722ceddSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_desktop.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "cppuhelper/implbase2.hxx" 28cdf0e10cSrcweir #include "cppuhelper/implementationentry.hxx" 29cdf0e10cSrcweir #include "unotools/configmgr.hxx" 30cdf0e10cSrcweir #include "comphelper/servicedecl.hxx" 31cdf0e10cSrcweir #include "comphelper/unwrapargs.hxx" 32cdf0e10cSrcweir #include "i18npool/mslangid.hxx" 33cdf0e10cSrcweir #include "vcl/svapp.hxx" 34cdf0e10cSrcweir #include "vcl/msgbox.hxx" 35cdf0e10cSrcweir #include "toolkit/helper/vclunohelper.hxx" 36cdf0e10cSrcweir #include "com/sun/star/lang/XServiceInfo.hpp" 37cdf0e10cSrcweir #include "com/sun/star/task/XJobExecutor.hpp" 38cdf0e10cSrcweir #include "svtools/svmedit.hxx" 39cdf0e10cSrcweir #include "svl/lstner.hxx" 40cdf0e10cSrcweir #include "svtools/xtextedt.hxx" 41cdf0e10cSrcweir #include <vcl/scrbar.hxx> 42cdf0e10cSrcweir #include "vcl/threadex.hxx" 43cdf0e10cSrcweir 44cdf0e10cSrcweir 45cdf0e10cSrcweir 46cdf0e10cSrcweir #include "boost/bind.hpp" 47cdf0e10cSrcweir #include "dp_gui_shared.hxx" 48cdf0e10cSrcweir #include "license_dialog.hxx" 49cdf0e10cSrcweir #include "dp_gui.hrc" 50cdf0e10cSrcweir 51cdf0e10cSrcweir using namespace ::dp_misc; 52cdf0e10cSrcweir namespace cssu = ::com::sun::star::uno; 53cdf0e10cSrcweir using namespace ::com::sun::star; 54cdf0e10cSrcweir using namespace ::com::sun::star::uno; 55cdf0e10cSrcweir using ::rtl::OUString; 56cdf0e10cSrcweir 57cdf0e10cSrcweir namespace dp_gui { 58cdf0e10cSrcweir 59cdf0e10cSrcweir class LicenseView : public MultiLineEdit, public SfxListener 60cdf0e10cSrcweir { 61cdf0e10cSrcweir sal_Bool mbEndReached; 62cdf0e10cSrcweir Link maEndReachedHdl; 63cdf0e10cSrcweir Link maScrolledHdl; 64cdf0e10cSrcweir 65cdf0e10cSrcweir public: 66cdf0e10cSrcweir LicenseView( Window* pParent, const ResId& rResId ); 67cdf0e10cSrcweir ~LicenseView(); 68cdf0e10cSrcweir 69cdf0e10cSrcweir void ScrollDown( ScrollType eScroll ); 70cdf0e10cSrcweir 71cdf0e10cSrcweir sal_Bool IsEndReached() const; 72cdf0e10cSrcweir sal_Bool EndReached() const { return mbEndReached; } 73cdf0e10cSrcweir void SetEndReached( sal_Bool bEnd ) { mbEndReached = bEnd; } 74cdf0e10cSrcweir 75cdf0e10cSrcweir void SetEndReachedHdl( const Link& rHdl ) { maEndReachedHdl = rHdl; } 76cdf0e10cSrcweir const Link& GetAutocompleteHdl() const { return maEndReachedHdl; } 77cdf0e10cSrcweir 78cdf0e10cSrcweir void SetScrolledHdl( const Link& rHdl ) { maScrolledHdl = rHdl; } 79cdf0e10cSrcweir const Link& GetScrolledHdl() const { return maScrolledHdl; } 80cdf0e10cSrcweir 81cdf0e10cSrcweir virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); 82cdf0e10cSrcweir 83cdf0e10cSrcweir protected: 84cdf0e10cSrcweir using MultiLineEdit::Notify; 85cdf0e10cSrcweir }; 86cdf0e10cSrcweir 87cdf0e10cSrcweir struct LicenseDialogImpl : public ModalDialog 88cdf0e10cSrcweir { 89cdf0e10cSrcweir cssu::Reference<cssu::XComponentContext> m_xComponentContext; 90cdf0e10cSrcweir FixedText m_ftHead; 91cdf0e10cSrcweir FixedText m_ftBody1; 92cdf0e10cSrcweir FixedText m_ftBody1Txt; 93cdf0e10cSrcweir FixedText m_ftBody2; 94cdf0e10cSrcweir FixedText m_ftBody2Txt; 95cdf0e10cSrcweir FixedImage m_fiArrow1; 96cdf0e10cSrcweir FixedImage m_fiArrow2; 97cdf0e10cSrcweir LicenseView m_mlLicense; 98cdf0e10cSrcweir PushButton m_pbDown; 99cdf0e10cSrcweir FixedLine m_flBottom; 100cdf0e10cSrcweir 101cdf0e10cSrcweir OKButton m_acceptButton; 102cdf0e10cSrcweir CancelButton m_declineButton; 103cdf0e10cSrcweir 104cdf0e10cSrcweir DECL_LINK(PageDownHdl, PushButton*); 105cdf0e10cSrcweir DECL_LINK(ScrolledHdl, LicenseView*); 106cdf0e10cSrcweir DECL_LINK(EndReachedHdl, LicenseView*); 107cdf0e10cSrcweir 108cdf0e10cSrcweir bool m_bLicenseRead; 109cdf0e10cSrcweir 110cdf0e10cSrcweir virtual ~LicenseDialogImpl(); 111cdf0e10cSrcweir 112cdf0e10cSrcweir LicenseDialogImpl( 113cdf0e10cSrcweir Window * pParent, 114cdf0e10cSrcweir css::uno::Reference< css::uno::XComponentContext > const & xContext, 115cdf0e10cSrcweir const ::rtl::OUString & sExtensionName, 116cdf0e10cSrcweir const ::rtl::OUString & sLicenseText); 117cdf0e10cSrcweir 118cdf0e10cSrcweir virtual void Activate(); 119cdf0e10cSrcweir 120cdf0e10cSrcweir }; 121cdf0e10cSrcweir 122cdf0e10cSrcweir LicenseView::LicenseView( Window* pParent, const ResId& rResId ) 123cdf0e10cSrcweir : MultiLineEdit( pParent, rResId ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir SetLeftMargin( 5 ); 126cdf0e10cSrcweir mbEndReached = IsEndReached(); 127cdf0e10cSrcweir StartListening( *GetTextEngine() ); 128cdf0e10cSrcweir } 129cdf0e10cSrcweir 130cdf0e10cSrcweir LicenseView::~LicenseView() 131cdf0e10cSrcweir { 132cdf0e10cSrcweir maEndReachedHdl = Link(); 133cdf0e10cSrcweir maScrolledHdl = Link(); 134cdf0e10cSrcweir EndListeningAll(); 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir void LicenseView::ScrollDown( ScrollType eScroll ) 138cdf0e10cSrcweir { 139cdf0e10cSrcweir ScrollBar* pScroll = GetVScrollBar(); 140cdf0e10cSrcweir if ( pScroll ) 141cdf0e10cSrcweir pScroll->DoScrollAction( eScroll ); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir sal_Bool LicenseView::IsEndReached() const 145cdf0e10cSrcweir { 146cdf0e10cSrcweir sal_Bool bEndReached; 147cdf0e10cSrcweir 148cdf0e10cSrcweir ExtTextView* pView = GetTextView(); 149cdf0e10cSrcweir ExtTextEngine* pEdit = GetTextEngine(); 150cdf0e10cSrcweir sal_uLong nHeight = pEdit->GetTextHeight(); 151cdf0e10cSrcweir Size aOutSize = pView->GetWindow()->GetOutputSizePixel(); 152cdf0e10cSrcweir Point aBottom( 0, aOutSize.Height() ); 153cdf0e10cSrcweir 154cdf0e10cSrcweir if ( (sal_uLong) pView->GetDocPos( aBottom ).Y() >= nHeight - 1 ) 155cdf0e10cSrcweir bEndReached = sal_True; 156cdf0e10cSrcweir else 157cdf0e10cSrcweir bEndReached = sal_False; 158cdf0e10cSrcweir 159cdf0e10cSrcweir return bEndReached; 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir void LicenseView::Notify( SfxBroadcaster&, const SfxHint& rHint ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir if ( rHint.IsA( TYPE(TextHint) ) ) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir sal_Bool bLastVal = EndReached(); 167cdf0e10cSrcweir sal_uLong nId = ((const TextHint&)rHint).GetId(); 168cdf0e10cSrcweir 169cdf0e10cSrcweir if ( nId == TEXT_HINT_PARAINSERTED ) 170cdf0e10cSrcweir { 171cdf0e10cSrcweir if ( bLastVal ) 172cdf0e10cSrcweir mbEndReached = IsEndReached(); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir else if ( nId == TEXT_HINT_VIEWSCROLLED ) 175cdf0e10cSrcweir { 176cdf0e10cSrcweir if ( ! mbEndReached ) 177cdf0e10cSrcweir mbEndReached = IsEndReached(); 178cdf0e10cSrcweir maScrolledHdl.Call( this ); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir if ( EndReached() && !bLastVal ) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir maEndReachedHdl.Call( this ); 184cdf0e10cSrcweir } 185cdf0e10cSrcweir } 186cdf0e10cSrcweir } 187cdf0e10cSrcweir 188cdf0e10cSrcweir //============================================================================================================== 189cdf0e10cSrcweir 190cdf0e10cSrcweir LicenseDialogImpl::LicenseDialogImpl( 191cdf0e10cSrcweir Window * pParent, 192cdf0e10cSrcweir cssu::Reference< cssu::XComponentContext > const & xContext, 193cdf0e10cSrcweir const ::rtl::OUString & sExtensionName, 194cdf0e10cSrcweir const ::rtl::OUString & sLicenseText): 195cdf0e10cSrcweir ModalDialog(pParent, DpGuiResId(RID_DLG_LICENSE)) 196cdf0e10cSrcweir ,m_xComponentContext(xContext) 197cdf0e10cSrcweir ,m_ftHead(this, DpGuiResId(FT_LICENSE_HEADER)) 198cdf0e10cSrcweir ,m_ftBody1(this, DpGuiResId(FT_LICENSE_BODY_1)) 199cdf0e10cSrcweir ,m_ftBody1Txt(this, DpGuiResId(FT_LICENSE_BODY_1_TXT)) 200cdf0e10cSrcweir ,m_ftBody2(this, DpGuiResId(FT_LICENSE_BODY_2)) 201cdf0e10cSrcweir ,m_ftBody2Txt(this, DpGuiResId(FT_LICENSE_BODY_2_TXT)) 202cdf0e10cSrcweir ,m_fiArrow1(this, DpGuiResId(FI_LICENSE_ARROW1)) 203cdf0e10cSrcweir ,m_fiArrow2(this, DpGuiResId(FI_LICENSE_ARROW2)) 204cdf0e10cSrcweir ,m_mlLicense(this, DpGuiResId(ML_LICENSE)) 205cdf0e10cSrcweir ,m_pbDown(this, DpGuiResId(PB_LICENSE_DOWN)) 206cdf0e10cSrcweir ,m_flBottom(this, DpGuiResId(FL_LICENSE)) 207cdf0e10cSrcweir ,m_acceptButton(this, DpGuiResId(BTN_LICENSE_ACCEPT)) 208cdf0e10cSrcweir ,m_declineButton(this, DpGuiResId(BTN_LICENSE_DECLINE)) 209cdf0e10cSrcweir ,m_bLicenseRead(false) 210cdf0e10cSrcweir 211cdf0e10cSrcweir { 212cdf0e10cSrcweir 213cdf0e10cSrcweir if (GetSettings().GetStyleSettings().GetHighContrastMode()) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir // high contrast mode needs other images 216cdf0e10cSrcweir m_fiArrow1.SetImage(Image(DpGuiResId(IMG_LICENCE_ARROW_HC))); 217cdf0e10cSrcweir m_fiArrow2.SetImage(Image(DpGuiResId(IMG_LICENCE_ARROW_HC))); 218cdf0e10cSrcweir } 219cdf0e10cSrcweir 220cdf0e10cSrcweir FreeResource(); 221cdf0e10cSrcweir 222cdf0e10cSrcweir m_acceptButton.SetUniqueId(UID_BTN_LICENSE_ACCEPT); 223cdf0e10cSrcweir m_fiArrow1.Show(true); 224cdf0e10cSrcweir m_fiArrow2.Show(false); 225cdf0e10cSrcweir m_mlLicense.SetText(sLicenseText); 226cdf0e10cSrcweir m_ftHead.SetText(m_ftHead.GetText() + OUString('\n') + sExtensionName); 227cdf0e10cSrcweir 228cdf0e10cSrcweir m_mlLicense.SetEndReachedHdl( LINK(this, LicenseDialogImpl, EndReachedHdl) ); 229cdf0e10cSrcweir m_mlLicense.SetScrolledHdl( LINK(this, LicenseDialogImpl, ScrolledHdl) ); 230cdf0e10cSrcweir m_pbDown.SetClickHdl( LINK(this, LicenseDialogImpl, PageDownHdl) ); 231cdf0e10cSrcweir 232cdf0e10cSrcweir // We want a automatic repeating page down button 233cdf0e10cSrcweir WinBits aStyle = m_pbDown.GetStyle(); 234cdf0e10cSrcweir aStyle |= WB_REPEAT; 235cdf0e10cSrcweir m_pbDown.SetStyle( aStyle ); 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir LicenseDialogImpl::~LicenseDialogImpl() 239cdf0e10cSrcweir { 240cdf0e10cSrcweir } 241cdf0e10cSrcweir 242cdf0e10cSrcweir void LicenseDialogImpl::Activate() 243cdf0e10cSrcweir { 244cdf0e10cSrcweir if (!m_bLicenseRead) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir //Only enable the scroll down button if the license text does not fit into the window 247cdf0e10cSrcweir if (m_mlLicense.IsEndReached()) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir m_pbDown.Disable(); 250cdf0e10cSrcweir m_acceptButton.Enable(); 251cdf0e10cSrcweir m_acceptButton.GrabFocus(); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir else 254cdf0e10cSrcweir { 255cdf0e10cSrcweir m_pbDown.Enable(); 256cdf0e10cSrcweir m_pbDown.GrabFocus(); 257cdf0e10cSrcweir m_acceptButton.Disable(); 258cdf0e10cSrcweir } 259cdf0e10cSrcweir } 260cdf0e10cSrcweir } 261cdf0e10cSrcweir 262cdf0e10cSrcweir IMPL_LINK( LicenseDialogImpl, ScrolledHdl, LicenseView *, EMPTYARG ) 263cdf0e10cSrcweir { 264cdf0e10cSrcweir 265cdf0e10cSrcweir if (m_mlLicense.IsEndReached()) 266cdf0e10cSrcweir m_pbDown.Disable(); 267cdf0e10cSrcweir else 268cdf0e10cSrcweir m_pbDown.Enable(); 269cdf0e10cSrcweir 270cdf0e10cSrcweir return 0; 271cdf0e10cSrcweir } 272cdf0e10cSrcweir 273cdf0e10cSrcweir IMPL_LINK( LicenseDialogImpl, PageDownHdl, PushButton *, EMPTYARG ) 274cdf0e10cSrcweir { 275cdf0e10cSrcweir m_mlLicense.ScrollDown( SCROLL_PAGEDOWN ); 276cdf0e10cSrcweir return 0; 277cdf0e10cSrcweir } 278cdf0e10cSrcweir 279cdf0e10cSrcweir IMPL_LINK( LicenseDialogImpl, EndReachedHdl, LicenseView *, EMPTYARG ) 280cdf0e10cSrcweir { 281cdf0e10cSrcweir m_acceptButton.Enable(); 282cdf0e10cSrcweir m_acceptButton.GrabFocus(); 283cdf0e10cSrcweir m_fiArrow1.Show(false); 284cdf0e10cSrcweir m_fiArrow2.Show(true); 285cdf0e10cSrcweir m_bLicenseRead = true; 286cdf0e10cSrcweir return 0; 287cdf0e10cSrcweir } 288cdf0e10cSrcweir 289cdf0e10cSrcweir //================================================================================= 290cdf0e10cSrcweir 291cdf0e10cSrcweir 292cdf0e10cSrcweir 293cdf0e10cSrcweir 294cdf0e10cSrcweir LicenseDialog::LicenseDialog( Sequence<Any> const& args, 295cdf0e10cSrcweir Reference<XComponentContext> const& xComponentContext) 296cdf0e10cSrcweir : m_xComponentContext(xComponentContext) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir comphelper::unwrapArgs( args, m_parent, m_sExtensionName, m_sLicenseText ); 299cdf0e10cSrcweir } 300cdf0e10cSrcweir 301cdf0e10cSrcweir // XExecutableDialog 302cdf0e10cSrcweir //______________________________________________________________________________ 303cdf0e10cSrcweir void LicenseDialog::setTitle( OUString const & ) throw (RuntimeException) 304cdf0e10cSrcweir { 305cdf0e10cSrcweir 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir //______________________________________________________________________________ 309cdf0e10cSrcweir sal_Int16 LicenseDialog::execute() throw (RuntimeException) 310cdf0e10cSrcweir { 311cdf0e10cSrcweir return vcl::solarthread::syncExecute( 312cdf0e10cSrcweir boost::bind( &LicenseDialog::solar_execute, this)); 313cdf0e10cSrcweir } 314cdf0e10cSrcweir 315cdf0e10cSrcweir sal_Int16 LicenseDialog::solar_execute() 316cdf0e10cSrcweir { 317cdf0e10cSrcweir std::auto_ptr<LicenseDialogImpl> dlg( 318cdf0e10cSrcweir new LicenseDialogImpl( 319cdf0e10cSrcweir VCLUnoHelper::GetWindow(m_parent), 320cdf0e10cSrcweir m_xComponentContext, m_sExtensionName, m_sLicenseText)); 321cdf0e10cSrcweir 322cdf0e10cSrcweir return dlg->Execute(); 323cdf0e10cSrcweir } 324cdf0e10cSrcweir 325cdf0e10cSrcweir } // namespace dp_gui 326cdf0e10cSrcweir 327