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