Update ooo320-m1
[ooovba.git] / extensions / source / preload / oemwiz.cxx
blob49b305e70c92be0a2f25f0dddf735919a41ea95a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: oemwiz.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_extensions.hxx"
33 #include "oemwiz.hxx"
34 #include "componentmodule.hxx"
35 #include <tools/debug.hxx>
36 #include <sfx2/docfile.hxx>
37 #include <svtools/itemset.hxx>
38 #include <svtools/itempool.hxx>
39 #include <vcl/msgbox.hxx>
40 #include <svtools/pathoptions.hxx>
41 #ifndef _EXTENSIONS_PRELOAD_PRELOAD_HRC_
42 #include "preload.hrc"
43 #endif
44 #ifndef _SVX_SVXIDS_HRC
45 #include <svx/svxids.hrc>
46 #endif
47 #include <sfx2/app.hxx>
48 #include <svtools/xtextedt.hxx>
49 #include "osl/diagnose.h"
50 #include "tools/urlobj.hxx"
52 #include <sfx2/sfxdlg.hxx>
53 #include <sfx2/tabdlg.hxx>
54 #include <svx/dialogs.hrc>
56 //.........................................................................
57 namespace preload
59 //.........................................................................
61 using namespace ::com::sun::star::uno;
62 using namespace ::com::sun::star::lang;
63 using namespace ::com::sun::star::beans;
64 //.........................................................................
66 struct OEMPreloadDialog_Impl
68 SfxItemSet* pSet;
69 TabPage* pWelcomePage;
70 TabPage* pLicensePage;
71 TabPage* pUserDataPage;
73 OEMPreloadDialog_Impl(OEMPreloadDialog* pDialog);
74 ~OEMPreloadDialog_Impl()
76 delete pWelcomePage;
77 delete pLicensePage;
78 delete pUserDataPage;
79 delete pSet;
81 void WriteUserData();
83 /* -----------------------------14.11.2001 11:33------------------------------
85 ---------------------------------------------------------------------------*/
86 OEMPreloadDialog_Impl::OEMPreloadDialog_Impl(OEMPreloadDialog* pDialog)
88 SfxItemPool& rPool = SFX_APP()->GetPool();
89 pSet = new SfxItemSet(rPool, SID_FIELD_GRABFOCUS, SID_FIELD_GRABFOCUS);
90 SfxAbstractDialogFactory* pFact = SfxAbstractDialogFactory::Create();
91 if ( pFact )
93 CreateTabPage pFunc = pFact->GetTabPageCreatorFunc(RID_SFXPAGE_GENERAL);
94 pUserDataPage = (*pFunc)(pDialog, *pSet);
95 ((SfxTabPage*)pUserDataPage)->Reset(*pSet);
97 else
98 pUserDataPage = NULL;
99 pWelcomePage = new OEMWelcomeTabPage(pDialog);
100 pLicensePage = new OEMLicenseTabPage(pDialog);
102 /* -----------------------------14.11.2001 11:33------------------------------
104 ---------------------------------------------------------------------------*/
105 void OEMPreloadDialog_Impl::WriteUserData()
107 if ( pUserDataPage )
108 ((SfxTabPage*)pUserDataPage)->FillItemSet(*pSet);
111 /* -----------------------------14.11.2001 11:33------------------------------
113 ---------------------------------------------------------------------------*/
114 //=====================================================================
115 //= OEMPreloadDialog
116 //=====================================================================
117 //---------------------------------------------------------------------
118 OEMPreloadDialog::OEMPreloadDialog( Window* _pParent,
119 const Reference< XPropertySet >& /*_rxObjectModel*/, const Reference< XMultiServiceFactory >& /*_rxORB*/ )
120 :WizardDialog(_pParent, ModuleRes(RID_DLG_OEMWIZARD)/*, _rxObjectModel, _rxORB*/)
121 ,aPrevPB(this, ModuleRes(PB_PREV ))
122 ,aNextPB(this, ModuleRes(PB_NEXT ))
123 ,aCancelPB(this, ModuleRes(PB_CANCEL ))
124 ,aAcceptST(ModuleRes(ST_ACCEPT))
125 ,aFinishST(ModuleRes(ST_FINISH))
126 ,aLicense(ModuleRes(ST_LICENSE_AGREEMENT))
127 ,aUserData(ModuleRes(ST_INSERT_USER_DATA))
128 ,pImpl(new OEMPreloadDialog_Impl(this))
130 FreeResource();
131 aDlgTitle = GetText();
132 aPrevPB.Enable(FALSE);
133 aNextST = aNextPB.GetText();
134 aPrevPB.SetClickHdl(LINK(this, OEMPreloadDialog, NextPrevPageHdl));
135 aNextPB.SetClickHdl(LINK(this, OEMPreloadDialog, NextPrevPageHdl));
136 AddButton( &aPrevPB, WIZARDDIALOG_BUTTON_STDOFFSET_X );
137 AddButton( &aNextPB, WIZARDDIALOG_BUTTON_STDOFFSET_X );
138 AddButton( &aCancelPB, WIZARDDIALOG_BUTTON_STDOFFSET_X );
140 SetPrevButton(&aPrevPB);
141 SetNextButton(&aNextPB);
143 AddPage( pImpl->pWelcomePage );
144 AddPage( pImpl->pLicensePage );
145 if ( pImpl->pUserDataPage )
146 AddPage( pImpl->pUserDataPage );
147 SetPage( OEM_WELCOME, pImpl->pWelcomePage );
148 SetPage( OEM_LICENSE, pImpl->pLicensePage );
149 if ( pImpl->pUserDataPage )
150 SetPage( OEM_USERDATA, pImpl->pUserDataPage );
151 ShowPage( OEM_WELCOME );
153 /* -----------------------------14.11.2001 11:33------------------------------
155 ---------------------------------------------------------------------------*/
156 OEMPreloadDialog::~OEMPreloadDialog( )
158 delete pImpl;
160 /* -----------------------------14.11.2001 11:33------------------------------
162 ---------------------------------------------------------------------------*/
163 IMPL_LINK(OEMPreloadDialog, NextPrevPageHdl, PushButton*, pButton)
165 if(pButton == &aPrevPB)
167 if(GetCurLevel())
168 ShowPage(GetCurLevel() - 1);
170 else if(OEM_USERDATA > GetCurLevel())
171 ShowPage(GetCurLevel() + 1);
172 else
174 pImpl->WriteUserData();
175 Finnish(RET_OK);
178 String sTitle(aDlgTitle);
180 switch(GetCurLevel())
182 case OEM_WELCOME:
183 aNextPB.SetText(aNextST);
184 aNextPB.Enable(TRUE);
185 break;
186 case OEM_LICENSE:
187 sTitle += aLicense;
188 aNextPB.SetText(aNextST);
189 aCancelPB.GrabFocus();
190 break;
191 case OEM_USERDATA:
192 sTitle += aUserData;
193 aNextPB.SetText(aFinishST);
194 break;
196 SetText(sTitle);
197 aPrevPB.Enable(GetCurLevel() != OEM_WELCOME);
198 return 0;
200 /* -----------------------------14.11.2001 11:33------------------------------
202 ---------------------------------------------------------------------------*/
203 sal_Bool OEMPreloadDialog::LoadFromLocalFile(const String& rFileName, String& rContent)
205 SvtPathOptions aPathOpt;
206 String sFileName = aPathOpt.GetUserConfigPath();//GetModulePath();
207 INetURLObject aURLObject(sFileName);
208 OSL_ASSERT(aURLObject.getSegmentCount() >= 2);
209 aURLObject.removeSegment(); //remove '/config'
210 aURLObject.removeSegment(); //remove '/user'
211 sFileName = aURLObject.GetMainURL(INetURLObject::DECODE_TO_IURI);
212 sFileName += rFileName;
214 SfxMedium aMedium( sFileName,STREAM_READ, TRUE );
215 SvStream* pInStream = aMedium.GetInStream();
216 if( !pInStream )
217 return sal_False;
219 pInStream->ReadCString( rContent, RTL_TEXTENCODING_UTF8 );
221 xub_StrLen nPos;
222 while ( ( nPos = rContent.Search( 12 )) != STRING_NOTFOUND )
223 rContent.Erase( nPos, 1 );
224 return sal_True;
228 void OEMPreloadDialog::SetCancelString( const String& rText )
230 aCancelPB.SetText(rText);
233 /* -----------------------------13.11.2001 12:29------------------------------
235 ---------------------------------------------------------------------------*/
236 OEMWelcomeTabPage::OEMWelcomeTabPage(Window* pParent) :
237 TabPage(pParent, ModuleRes(RID_TP_WELCOME)),
238 aInfoFT(this, ModuleRes(FT_INFO))
240 FreeResource();
242 /* -----------------------------13.11.2001 12:30------------------------------
244 ---------------------------------------------------------------------------*/
245 OEMWelcomeTabPage::~OEMWelcomeTabPage()
248 /* -----------------------------13.11.2001 12:29------------------------------
250 ---------------------------------------------------------------------------*/
251 OEMLicenseTabPage::OEMLicenseTabPage(OEMPreloadDialog* pParent) :
252 TabPage(pParent, ModuleRes(RID_TP_LICENSE)),
253 aLicenseML(this, ModuleRes(ML_LICENSE)),
254 aInfo1FT(this, ModuleRes(FT_INFO1)),
255 aInfo2FT(this, ModuleRes(FT_INFO2)),
256 aInfo3FT(this, ModuleRes(FT_INFO3)),
257 aInfo2_1FT(this, ModuleRes(FT_INFO2_1)),
258 aInfo3_1FT(this, ModuleRes(FT_INFO3_1)),
259 aCBAccept(this, ModuleRes(CB_ACCEPT)),
260 aPBPageDown(this, ModuleRes(PB_PAGEDOWN)),
261 aArrow(this, ModuleRes(IMG_ARROW)),
262 aStrAccept( ModuleRes(LICENCE_ACCEPT) ),
263 aStrNotAccept( ModuleRes(LICENCE_NOTACCEPT) ),
264 bEndReached(FALSE),
265 pPreloadDialog(pParent)
267 FreeResource();
269 aLicenseML.SetEndReachedHdl( LINK(this, OEMLicenseTabPage, EndReachedHdl) );
270 aLicenseML.SetScrolledHdl( LINK(this, OEMLicenseTabPage, ScrolledHdl) );
272 aPBPageDown.SetClickHdl( LINK(this, OEMLicenseTabPage, PageDownHdl) );
273 aCBAccept.SetClickHdl( LINK(this, OEMLicenseTabPage, AcceptHdl) );
275 // We want a automatic repeating page down button
276 WinBits aStyle = aPBPageDown.GetStyle();
277 aStyle |= WB_REPEAT;
278 aPBPageDown.SetStyle( aStyle );
280 aOldCancelText = pPreloadDialog->GetCancelString();
281 pPreloadDialog->SetCancelString( aStrNotAccept );
283 String aText = aInfo2FT.GetText();
284 aText.SearchAndReplaceAll( UniString::CreateFromAscii("%PAGEDOWN"), aPBPageDown.GetText() );
285 aInfo2FT.SetText( aText );
287 /* -----------------------------13.11.2001 12:30------------------------------
289 ---------------------------------------------------------------------------*/
290 OEMLicenseTabPage::~OEMLicenseTabPage()
293 /* ---------------------------14.11.2001 11:24----------------------------
295 -----------------------------------------------------------------------*/
296 void OEMLicenseTabPage::ActivatePage()
298 if(!aLicenseML.GetText().Len())
300 aLicenseML.SetLeftMargin( 5 );
301 String sLicense;
302 #ifdef UNX
303 OEMPreloadDialog::LoadFromLocalFile(String::CreateFromAscii("LICENSE"), sLicense);
304 #else
305 OEMPreloadDialog::LoadFromLocalFile(String::CreateFromAscii("license.txt"), sLicense);
306 #endif
307 aLicenseML.SetText( sLicense );
310 EnableControls();
313 //------------------------------------------------------------------------
314 IMPL_LINK( OEMLicenseTabPage, AcceptHdl, CheckBox *, EMPTYARG )
316 EnableControls();
317 return 0;
320 //------------------------------------------------------------------------
321 IMPL_LINK( OEMLicenseTabPage, PageDownHdl, PushButton *, EMPTYARG )
323 aLicenseML.ScrollDown( SCROLL_PAGEDOWN );
324 return 0;
327 //------------------------------------------------------------------------
328 IMPL_LINK( OEMLicenseTabPage, EndReachedHdl, LicenceView *, EMPTYARG )
330 bEndReached = TRUE;
332 EnableControls();
333 aCBAccept.GrabFocus();
335 return 0;
338 //------------------------------------------------------------------------
339 IMPL_LINK( OEMLicenseTabPage, ScrolledHdl, LicenceView *, EMPTYARG )
341 EnableControls();
343 return 0;
346 //------------------------------------------------------------------------
347 void OEMLicenseTabPage::EnableControls()
349 if( !bEndReached &&
350 ( aLicenseML.IsEndReached() || !aLicenseML.GetText().Len() ) )
351 bEndReached = TRUE;
353 if ( bEndReached )
355 Point aPos( 0, aInfo3_1FT.GetPosPixel().Y() );
356 aArrow.SetPosPixel( aPos );
357 aCBAccept.Enable();
359 else
361 Point aPos( 0, aInfo2_1FT.GetPosPixel().Y() );
362 aArrow.SetPosPixel( aPos );
363 aCBAccept.Disable();
366 if ( aLicenseML.IsEndReached() )
367 aPBPageDown.Disable();
368 else
369 aPBPageDown.Enable();
371 if ( aCBAccept.IsChecked() )
373 PushButton *pNext = pPreloadDialog->GetNextButton();
374 if ( ! pNext->IsEnabled() )
376 pPreloadDialog->SetCancelString( aOldCancelText );
377 pNext->Enable(TRUE);
380 else
382 PushButton *pNext = pPreloadDialog->GetNextButton();
383 if ( pNext->IsEnabled() )
385 pPreloadDialog->SetCancelString( aStrNotAccept );
386 pNext->Enable(FALSE);
391 //------------------------------------------------------------------------
392 //------------------------------------------------------------------------
393 //------------------------------------------------------------------------
394 LicenceView::LicenceView( Window* pParent, const ResId& rResId )
395 : MultiLineEdit( pParent, rResId )
397 SetLeftMargin( 5 );
399 mbEndReached = IsEndReached();
401 StartListening( *GetTextEngine() );
404 //------------------------------------------------------------------------
405 LicenceView::~LicenceView()
407 maEndReachedHdl = Link();
408 maScrolledHdl = Link();
410 EndListeningAll();
413 //------------------------------------------------------------------------
414 void LicenceView::ScrollDown( ScrollType eScroll )
416 ScrollBar* pScroll = GetVScrollBar();
418 if ( pScroll )
419 pScroll->DoScrollAction( eScroll );
422 //------------------------------------------------------------------------
423 BOOL LicenceView::IsEndReached() const
425 BOOL bEndReached;
427 ExtTextView* pView = GetTextView();
428 ExtTextEngine* pEdit = GetTextEngine();
429 ULONG nHeight = pEdit->GetTextHeight();
430 Size aOutSize = pView->GetWindow()->GetOutputSizePixel();
431 Point aBottom( 0, aOutSize.Height() );
433 if ( (ULONG) pView->GetDocPos( aBottom ).Y() >= nHeight - 1 )
434 bEndReached = TRUE;
435 else
436 bEndReached = FALSE;
438 return bEndReached;
441 //------------------------------------------------------------------------
442 void LicenceView::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
444 if ( rHint.IsA( TYPE(TextHint) ) )
446 BOOL bLastVal = EndReached();
447 ULONG nId = ((const TextHint&)rHint).GetId();
449 if ( nId == TEXT_HINT_PARAINSERTED )
451 if ( bLastVal )
452 mbEndReached = IsEndReached();
454 else if ( nId == TEXT_HINT_VIEWSCROLLED )
456 if ( ! mbEndReached )
457 mbEndReached = IsEndReached();
458 maScrolledHdl.Call( this );
461 if ( EndReached() && !bLastVal )
463 maEndReachedHdl.Call( this );
468 //------------------------------------------------------------------------
470 //.........................................................................
471 } // namespace preload
472 //.........................................................................