1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_extensions.hxx" 26 #include "oemwiz.hxx" 27 #include "componentmodule.hxx" 28 #include <tools/debug.hxx> 29 #include <sfx2/docfile.hxx> 30 #include <svl/itemset.hxx> 31 #include <svl/itempool.hxx> 32 #include <vcl/msgbox.hxx> 33 #include <unotools/pathoptions.hxx> 34 #ifndef _EXTENSIONS_PRELOAD_PRELOAD_HRC_ 35 #include "preload.hrc" 36 #endif 37 #ifndef _SVX_SVXIDS_HRC 38 #include <svx/svxids.hrc> 39 #endif 40 #include <sfx2/app.hxx> 41 #include <svtools/xtextedt.hxx> 42 #include "osl/diagnose.h" 43 #include "tools/urlobj.hxx" 44 45 #include <sfx2/sfxdlg.hxx> 46 #include <sfx2/tabdlg.hxx> 47 #include <svx/dialogs.hrc> 48 49 //......................................................................... 50 namespace preload 51 { 52 //......................................................................... 53 54 using namespace ::com::sun::star::uno; 55 using namespace ::com::sun::star::lang; 56 using namespace ::com::sun::star::beans; 57 //......................................................................... 58 59 struct OEMPreloadDialog_Impl 60 { 61 SfxItemSet* pSet; 62 TabPage* pWelcomePage; 63 TabPage* pLicensePage; 64 TabPage* pUserDataPage; 65 66 OEMPreloadDialog_Impl(OEMPreloadDialog* pDialog); ~OEMPreloadDialog_Implpreload::OEMPreloadDialog_Impl67 ~OEMPreloadDialog_Impl() 68 { 69 delete pWelcomePage; 70 delete pLicensePage; 71 delete pUserDataPage; 72 delete pSet; 73 } 74 void WriteUserData(); 75 }; 76 /* -----------------------------14.11.2001 11:33------------------------------ 77 78 ---------------------------------------------------------------------------*/ OEMPreloadDialog_Impl(OEMPreloadDialog * pDialog)79 OEMPreloadDialog_Impl::OEMPreloadDialog_Impl(OEMPreloadDialog* pDialog) 80 { 81 SfxItemPool& rPool = SFX_APP()->GetPool(); 82 pSet = new SfxItemSet(rPool, SID_FIELD_GRABFOCUS, SID_FIELD_GRABFOCUS); 83 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create(); 84 if ( pFact ) 85 { 86 CreateTabPage pFunc = pFact->GetTabPageCreatorFunc(RID_SFXPAGE_GENERAL); 87 pUserDataPage = (*pFunc)(pDialog, *pSet); 88 ((SfxTabPage*)pUserDataPage)->Reset(*pSet); 89 } 90 else 91 pUserDataPage = NULL; 92 pWelcomePage = new OEMWelcomeTabPage(pDialog); 93 pLicensePage = new OEMLicenseTabPage(pDialog); 94 } 95 /* -----------------------------14.11.2001 11:33------------------------------ 96 97 ---------------------------------------------------------------------------*/ WriteUserData()98 void OEMPreloadDialog_Impl::WriteUserData() 99 { 100 if ( pUserDataPage ) 101 ((SfxTabPage*)pUserDataPage)->FillItemSet(*pSet); 102 } 103 104 /* -----------------------------14.11.2001 11:33------------------------------ 105 106 ---------------------------------------------------------------------------*/ 107 //===================================================================== 108 //= OEMPreloadDialog 109 //===================================================================== 110 //--------------------------------------------------------------------- OEMPreloadDialog(Window * _pParent,const Reference<XPropertySet> &,const Reference<XMultiServiceFactory> &)111 OEMPreloadDialog::OEMPreloadDialog( Window* _pParent, 112 const Reference< XPropertySet >& /*_rxObjectModel*/, const Reference< XMultiServiceFactory >& /*_rxORB*/ ) 113 :WizardDialog(_pParent, ModuleRes(RID_DLG_OEMWIZARD)/*, _rxObjectModel, _rxORB*/) 114 ,aPrevPB(this, ModuleRes(PB_PREV )) 115 ,aNextPB(this, ModuleRes(PB_NEXT )) 116 ,aCancelPB(this, ModuleRes(PB_CANCEL )) 117 ,aAcceptST(ModuleRes(ST_ACCEPT)) 118 ,aFinishST(ModuleRes(ST_FINISH)) 119 ,aLicense(ModuleRes(ST_LICENSE_AGREEMENT)) 120 ,aUserData(ModuleRes(ST_INSERT_USER_DATA)) 121 ,pImpl(new OEMPreloadDialog_Impl(this)) 122 { 123 FreeResource(); 124 aDlgTitle = GetText(); 125 aPrevPB.Enable(sal_False); 126 aNextST = aNextPB.GetText(); 127 aPrevPB.SetClickHdl(LINK(this, OEMPreloadDialog, NextPrevPageHdl)); 128 aNextPB.SetClickHdl(LINK(this, OEMPreloadDialog, NextPrevPageHdl)); 129 AddButton( &aPrevPB, WIZARDDIALOG_BUTTON_STDOFFSET_X ); 130 AddButton( &aNextPB, WIZARDDIALOG_BUTTON_STDOFFSET_X ); 131 AddButton( &aCancelPB, WIZARDDIALOG_BUTTON_STDOFFSET_X ); 132 133 SetPrevButton(&aPrevPB); 134 SetNextButton(&aNextPB); 135 136 AddPage( pImpl->pWelcomePage ); 137 AddPage( pImpl->pLicensePage ); 138 if ( pImpl->pUserDataPage ) 139 AddPage( pImpl->pUserDataPage ); 140 SetPage( OEM_WELCOME, pImpl->pWelcomePage ); 141 SetPage( OEM_LICENSE, pImpl->pLicensePage ); 142 if ( pImpl->pUserDataPage ) 143 SetPage( OEM_USERDATA, pImpl->pUserDataPage ); 144 ShowPage( OEM_WELCOME ); 145 } 146 /* -----------------------------14.11.2001 11:33------------------------------ 147 148 ---------------------------------------------------------------------------*/ ~OEMPreloadDialog()149 OEMPreloadDialog::~OEMPreloadDialog( ) 150 { 151 delete pImpl; 152 } 153 /* -----------------------------14.11.2001 11:33------------------------------ 154 155 ---------------------------------------------------------------------------*/ IMPL_LINK(OEMPreloadDialog,NextPrevPageHdl,PushButton *,pButton)156 IMPL_LINK(OEMPreloadDialog, NextPrevPageHdl, PushButton*, pButton) 157 { 158 if(pButton == &aPrevPB) 159 { 160 if(GetCurLevel()) 161 ShowPage(GetCurLevel() - 1); 162 } 163 else if(OEM_USERDATA > GetCurLevel()) 164 ShowPage(GetCurLevel() + 1); 165 else 166 { 167 pImpl->WriteUserData(); 168 Finnish(RET_OK); 169 } 170 171 String sTitle(aDlgTitle); 172 173 switch(GetCurLevel()) 174 { 175 case OEM_WELCOME: 176 aNextPB.SetText(aNextST); 177 aNextPB.Enable(sal_True); 178 break; 179 case OEM_LICENSE: 180 sTitle += aLicense; 181 aNextPB.SetText(aNextST); 182 aCancelPB.GrabFocus(); 183 break; 184 case OEM_USERDATA: 185 sTitle += aUserData; 186 aNextPB.SetText(aFinishST); 187 break; 188 } 189 SetText(sTitle); 190 aPrevPB.Enable(GetCurLevel() != OEM_WELCOME); 191 return 0; 192 } 193 /* -----------------------------14.11.2001 11:33------------------------------ 194 195 ---------------------------------------------------------------------------*/ LoadFromLocalFile(const String & rFileName,String & rContent)196 sal_Bool OEMPreloadDialog::LoadFromLocalFile(const String& rFileName, String& rContent) 197 { 198 SvtPathOptions aPathOpt; 199 String sFileName = aPathOpt.GetUserConfigPath();//GetModulePath(); 200 INetURLObject aURLObject(sFileName); 201 OSL_ASSERT(aURLObject.getSegmentCount() >= 2); 202 aURLObject.removeSegment(); //remove '/config' 203 aURLObject.removeSegment(); //remove '/user' 204 sFileName = aURLObject.GetMainURL(INetURLObject::DECODE_TO_IURI); 205 sFileName += rFileName; 206 207 SfxMedium aMedium( sFileName,STREAM_READ, sal_True ); 208 SvStream* pInStream = aMedium.GetInStream(); 209 if( !pInStream ) 210 return sal_False; 211 212 pInStream->ReadCString( rContent, RTL_TEXTENCODING_UTF8 ); 213 214 xub_StrLen nPos; 215 while ( ( nPos = rContent.Search( 12 )) != STRING_NOTFOUND ) 216 rContent.Erase( nPos, 1 ); 217 return sal_True; 218 } 219 220 SetCancelString(const String & rText)221 void OEMPreloadDialog::SetCancelString( const String& rText ) 222 { 223 aCancelPB.SetText(rText); 224 } 225 226 /* -----------------------------13.11.2001 12:29------------------------------ 227 228 ---------------------------------------------------------------------------*/ OEMWelcomeTabPage(Window * pParent)229 OEMWelcomeTabPage::OEMWelcomeTabPage(Window* pParent) : 230 TabPage(pParent, ModuleRes(RID_TP_WELCOME)), 231 aInfoFT(this, ModuleRes(FT_INFO)) 232 { 233 FreeResource(); 234 } 235 /* -----------------------------13.11.2001 12:30------------------------------ 236 237 ---------------------------------------------------------------------------*/ ~OEMWelcomeTabPage()238 OEMWelcomeTabPage::~OEMWelcomeTabPage() 239 { 240 } 241 /* -----------------------------13.11.2001 12:29------------------------------ 242 243 ---------------------------------------------------------------------------*/ OEMLicenseTabPage(OEMPreloadDialog * pParent)244 OEMLicenseTabPage::OEMLicenseTabPage(OEMPreloadDialog* pParent) : 245 TabPage(pParent, ModuleRes(RID_TP_LICENSE)), 246 aLicenseML(this, ModuleRes(ML_LICENSE)), 247 aInfo1FT(this, ModuleRes(FT_INFO1)), 248 aInfo2FT(this, ModuleRes(FT_INFO2)), 249 aInfo3FT(this, ModuleRes(FT_INFO3)), 250 aInfo2_1FT(this, ModuleRes(FT_INFO2_1)), 251 aInfo3_1FT(this, ModuleRes(FT_INFO3_1)), 252 aCBAccept(this, ModuleRes(CB_ACCEPT)), 253 aPBPageDown(this, ModuleRes(PB_PAGEDOWN)), 254 aArrow(this, ModuleRes(IMG_ARROW)), 255 aStrAccept( ModuleRes(LICENCE_ACCEPT) ), 256 aStrNotAccept( ModuleRes(LICENCE_NOTACCEPT) ), 257 bEndReached(sal_False), 258 pPreloadDialog(pParent) 259 { 260 FreeResource(); 261 262 aLicenseML.SetEndReachedHdl( LINK(this, OEMLicenseTabPage, EndReachedHdl) ); 263 aLicenseML.SetScrolledHdl( LINK(this, OEMLicenseTabPage, ScrolledHdl) ); 264 265 aPBPageDown.SetClickHdl( LINK(this, OEMLicenseTabPage, PageDownHdl) ); 266 aCBAccept.SetClickHdl( LINK(this, OEMLicenseTabPage, AcceptHdl) ); 267 268 // We want a automatic repeating page down button 269 WinBits aStyle = aPBPageDown.GetStyle(); 270 aStyle |= WB_REPEAT; 271 aPBPageDown.SetStyle( aStyle ); 272 273 aOldCancelText = pPreloadDialog->GetCancelString(); 274 pPreloadDialog->SetCancelString( aStrNotAccept ); 275 276 String aText = aInfo2FT.GetText(); 277 aText.SearchAndReplaceAll( UniString::CreateFromAscii("%PAGEDOWN"), aPBPageDown.GetText() ); 278 aInfo2FT.SetText( aText ); 279 } 280 /* -----------------------------13.11.2001 12:30------------------------------ 281 282 ---------------------------------------------------------------------------*/ ~OEMLicenseTabPage()283 OEMLicenseTabPage::~OEMLicenseTabPage() 284 { 285 } 286 /* ---------------------------14.11.2001 11:24---------------------------- 287 288 -----------------------------------------------------------------------*/ ActivatePage()289 void OEMLicenseTabPage::ActivatePage() 290 { 291 if(!aLicenseML.GetText().Len()) 292 { 293 aLicenseML.SetLeftMargin( 5 ); 294 String sLicense; 295 #ifdef UNX 296 OEMPreloadDialog::LoadFromLocalFile(String::CreateFromAscii("LICENSE"), sLicense); 297 #else 298 OEMPreloadDialog::LoadFromLocalFile(String::CreateFromAscii("license.txt"), sLicense); 299 #endif 300 aLicenseML.SetText( sLicense ); 301 } 302 303 EnableControls(); 304 } 305 306 //------------------------------------------------------------------------ IMPL_LINK(OEMLicenseTabPage,AcceptHdl,CheckBox *,EMPTYARG)307 IMPL_LINK( OEMLicenseTabPage, AcceptHdl, CheckBox *, EMPTYARG ) 308 { 309 EnableControls(); 310 return 0; 311 } 312 313 //------------------------------------------------------------------------ IMPL_LINK(OEMLicenseTabPage,PageDownHdl,PushButton *,EMPTYARG)314 IMPL_LINK( OEMLicenseTabPage, PageDownHdl, PushButton *, EMPTYARG ) 315 { 316 aLicenseML.ScrollDown( SCROLL_PAGEDOWN ); 317 return 0; 318 } 319 320 //------------------------------------------------------------------------ IMPL_LINK(OEMLicenseTabPage,EndReachedHdl,LicenceView *,EMPTYARG)321 IMPL_LINK( OEMLicenseTabPage, EndReachedHdl, LicenceView *, EMPTYARG ) 322 { 323 bEndReached = sal_True; 324 325 EnableControls(); 326 aCBAccept.GrabFocus(); 327 328 return 0; 329 } 330 331 //------------------------------------------------------------------------ IMPL_LINK(OEMLicenseTabPage,ScrolledHdl,LicenceView *,EMPTYARG)332 IMPL_LINK( OEMLicenseTabPage, ScrolledHdl, LicenceView *, EMPTYARG ) 333 { 334 EnableControls(); 335 336 return 0; 337 } 338 339 //------------------------------------------------------------------------ EnableControls()340 void OEMLicenseTabPage::EnableControls() 341 { 342 if( !bEndReached && 343 ( aLicenseML.IsEndReached() || !aLicenseML.GetText().Len() ) ) 344 bEndReached = sal_True; 345 346 if ( bEndReached ) 347 { 348 Point aPos( 0, aInfo3_1FT.GetPosPixel().Y() ); 349 aArrow.SetPosPixel( aPos ); 350 aCBAccept.Enable(); 351 } 352 else 353 { 354 Point aPos( 0, aInfo2_1FT.GetPosPixel().Y() ); 355 aArrow.SetPosPixel( aPos ); 356 aCBAccept.Disable(); 357 } 358 359 if ( aLicenseML.IsEndReached() ) 360 aPBPageDown.Disable(); 361 else 362 aPBPageDown.Enable(); 363 364 if ( aCBAccept.IsChecked() ) 365 { 366 PushButton *pNext = pPreloadDialog->GetNextButton(); 367 if ( ! pNext->IsEnabled() ) 368 { 369 pPreloadDialog->SetCancelString( aOldCancelText ); 370 pNext->Enable(sal_True); 371 } 372 } 373 else 374 { 375 PushButton *pNext = pPreloadDialog->GetNextButton(); 376 if ( pNext->IsEnabled() ) 377 { 378 pPreloadDialog->SetCancelString( aStrNotAccept ); 379 pNext->Enable(sal_False); 380 } 381 } 382 } 383 384 //------------------------------------------------------------------------ 385 //------------------------------------------------------------------------ 386 //------------------------------------------------------------------------ LicenceView(Window * pParent,const ResId & rResId)387 LicenceView::LicenceView( Window* pParent, const ResId& rResId ) 388 : MultiLineEdit( pParent, rResId ) 389 { 390 SetLeftMargin( 5 ); 391 392 mbEndReached = IsEndReached(); 393 394 StartListening( *GetTextEngine() ); 395 } 396 397 //------------------------------------------------------------------------ ~LicenceView()398 LicenceView::~LicenceView() 399 { 400 maEndReachedHdl = Link(); 401 maScrolledHdl = Link(); 402 403 EndListeningAll(); 404 } 405 406 //------------------------------------------------------------------------ ScrollDown(ScrollType eScroll)407 void LicenceView::ScrollDown( ScrollType eScroll ) 408 { 409 ScrollBar* pScroll = GetVScrollBar(); 410 411 if ( pScroll ) 412 pScroll->DoScrollAction( eScroll ); 413 } 414 415 //------------------------------------------------------------------------ IsEndReached() const416 sal_Bool LicenceView::IsEndReached() const 417 { 418 sal_Bool bEndReached; 419 420 ExtTextView* pView = GetTextView(); 421 ExtTextEngine* pEdit = GetTextEngine(); 422 sal_uLong nHeight = pEdit->GetTextHeight(); 423 Size aOutSize = pView->GetWindow()->GetOutputSizePixel(); 424 Point aBottom( 0, aOutSize.Height() ); 425 426 if ( (sal_uLong) pView->GetDocPos( aBottom ).Y() >= nHeight - 1 ) 427 bEndReached = sal_True; 428 else 429 bEndReached = sal_False; 430 431 return bEndReached; 432 } 433 434 //------------------------------------------------------------------------ Notify(SfxBroadcaster &,const SfxHint & rHint)435 void LicenceView::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint ) 436 { 437 if ( rHint.IsA( TYPE(TextHint) ) ) 438 { 439 sal_Bool bLastVal = EndReached(); 440 sal_uLong nId = ((const TextHint&)rHint).GetId(); 441 442 if ( nId == TEXT_HINT_PARAINSERTED ) 443 { 444 if ( bLastVal ) 445 mbEndReached = IsEndReached(); 446 } 447 else if ( nId == TEXT_HINT_VIEWSCROLLED ) 448 { 449 if ( ! mbEndReached ) 450 mbEndReached = IsEndReached(); 451 maScrolledHdl.Call( this ); 452 } 453 454 if ( EndReached() && !bLastVal ) 455 { 456 maEndReachedHdl.Call( this ); 457 } 458 } 459 } 460 461 //------------------------------------------------------------------------ 462 463 //......................................................................... 464 } // namespace preload 465 //......................................................................... 466 467 468