1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
31 #include "componentmodule.hxx"
32 #include <tools/debug.hxx>
33 #include <sfx2/docfile.hxx>
34 #include <svl/itemset.hxx>
35 #include <svl/itempool.hxx>
36 #include <vcl/msgbox.hxx>
37 #include <unotools/pathoptions.hxx>
38 #ifndef _EXTENSIONS_PRELOAD_PRELOAD_HRC_
39 #include "preload.hrc"
41 #ifndef _SVX_SVXIDS_HRC
42 #include <svx/svxids.hrc>
44 #include <sfx2/app.hxx>
45 #include <svtools/xtextedt.hxx>
46 #include "osl/diagnose.h"
47 #include "tools/urlobj.hxx"
49 #include <sfx2/sfxdlg.hxx>
50 #include <sfx2/tabdlg.hxx>
51 #include <svx/dialogs.hrc>
53 //.........................................................................
56 //.........................................................................
58 using namespace ::com::sun::star::uno
;
59 using namespace ::com::sun::star::lang
;
60 using namespace ::com::sun::star::beans
;
61 //.........................................................................
63 struct OEMPreloadDialog_Impl
66 TabPage
* pWelcomePage
;
67 TabPage
* pLicensePage
;
68 TabPage
* pUserDataPage
;
70 OEMPreloadDialog_Impl(OEMPreloadDialog
* pDialog
);
71 ~OEMPreloadDialog_Impl()
80 /* -----------------------------14.11.2001 11:33------------------------------
82 ---------------------------------------------------------------------------*/
83 OEMPreloadDialog_Impl::OEMPreloadDialog_Impl(OEMPreloadDialog
* pDialog
)
85 SfxItemPool
& rPool
= SFX_APP()->GetPool();
86 pSet
= new SfxItemSet(rPool
, SID_FIELD_GRABFOCUS
, SID_FIELD_GRABFOCUS
);
87 SfxAbstractDialogFactory
* pFact
= SfxAbstractDialogFactory::Create();
90 CreateTabPage pFunc
= pFact
->GetTabPageCreatorFunc(RID_SFXPAGE_GENERAL
);
91 pUserDataPage
= (*pFunc
)(pDialog
, *pSet
);
92 ((SfxTabPage
*)pUserDataPage
)->Reset(*pSet
);
96 pWelcomePage
= new OEMWelcomeTabPage(pDialog
);
97 pLicensePage
= new OEMLicenseTabPage(pDialog
);
99 /* -----------------------------14.11.2001 11:33------------------------------
101 ---------------------------------------------------------------------------*/
102 void OEMPreloadDialog_Impl::WriteUserData()
105 ((SfxTabPage
*)pUserDataPage
)->FillItemSet(*pSet
);
108 /* -----------------------------14.11.2001 11:33------------------------------
110 ---------------------------------------------------------------------------*/
111 //=====================================================================
113 //=====================================================================
114 //---------------------------------------------------------------------
115 OEMPreloadDialog::OEMPreloadDialog( Window
* _pParent
,
116 const Reference
< XPropertySet
>& /*_rxObjectModel*/, const Reference
< XMultiServiceFactory
>& /*_rxORB*/ )
117 :WizardDialog(_pParent
, ModuleRes(RID_DLG_OEMWIZARD
)/*, _rxObjectModel, _rxORB*/)
118 ,aPrevPB(this, ModuleRes(PB_PREV
))
119 ,aNextPB(this, ModuleRes(PB_NEXT
))
120 ,aCancelPB(this, ModuleRes(PB_CANCEL
))
121 ,aAcceptST(ModuleRes(ST_ACCEPT
))
122 ,aFinishST(ModuleRes(ST_FINISH
))
123 ,aLicense(ModuleRes(ST_LICENSE_AGREEMENT
))
124 ,aUserData(ModuleRes(ST_INSERT_USER_DATA
))
125 ,pImpl(new OEMPreloadDialog_Impl(this))
128 aDlgTitle
= GetText();
129 aPrevPB
.Enable(FALSE
);
130 aNextST
= aNextPB
.GetText();
131 aPrevPB
.SetClickHdl(LINK(this, OEMPreloadDialog
, NextPrevPageHdl
));
132 aNextPB
.SetClickHdl(LINK(this, OEMPreloadDialog
, NextPrevPageHdl
));
133 AddButton( &aPrevPB
, WIZARDDIALOG_BUTTON_STDOFFSET_X
);
134 AddButton( &aNextPB
, WIZARDDIALOG_BUTTON_STDOFFSET_X
);
135 AddButton( &aCancelPB
, WIZARDDIALOG_BUTTON_STDOFFSET_X
);
137 SetPrevButton(&aPrevPB
);
138 SetNextButton(&aNextPB
);
140 AddPage( pImpl
->pWelcomePage
);
141 AddPage( pImpl
->pLicensePage
);
142 if ( pImpl
->pUserDataPage
)
143 AddPage( pImpl
->pUserDataPage
);
144 SetPage( OEM_WELCOME
, pImpl
->pWelcomePage
);
145 SetPage( OEM_LICENSE
, pImpl
->pLicensePage
);
146 if ( pImpl
->pUserDataPage
)
147 SetPage( OEM_USERDATA
, pImpl
->pUserDataPage
);
148 ShowPage( OEM_WELCOME
);
150 /* -----------------------------14.11.2001 11:33------------------------------
152 ---------------------------------------------------------------------------*/
153 OEMPreloadDialog::~OEMPreloadDialog( )
157 /* -----------------------------14.11.2001 11:33------------------------------
159 ---------------------------------------------------------------------------*/
160 IMPL_LINK(OEMPreloadDialog
, NextPrevPageHdl
, PushButton
*, pButton
)
162 if(pButton
== &aPrevPB
)
165 ShowPage(GetCurLevel() - 1);
167 else if(OEM_USERDATA
> GetCurLevel())
168 ShowPage(GetCurLevel() + 1);
171 pImpl
->WriteUserData();
175 String
sTitle(aDlgTitle
);
177 switch(GetCurLevel())
180 aNextPB
.SetText(aNextST
);
181 aNextPB
.Enable(TRUE
);
185 aNextPB
.SetText(aNextST
);
186 aCancelPB
.GrabFocus();
190 aNextPB
.SetText(aFinishST
);
194 aPrevPB
.Enable(GetCurLevel() != OEM_WELCOME
);
197 /* -----------------------------14.11.2001 11:33------------------------------
199 ---------------------------------------------------------------------------*/
200 sal_Bool
OEMPreloadDialog::LoadFromLocalFile(const String
& rFileName
, String
& rContent
)
202 SvtPathOptions aPathOpt
;
203 String sFileName
= aPathOpt
.GetUserConfigPath();//GetModulePath();
204 INetURLObject
aURLObject(sFileName
);
205 OSL_ASSERT(aURLObject
.getSegmentCount() >= 2);
206 aURLObject
.removeSegment(); //remove '/config'
207 aURLObject
.removeSegment(); //remove '/user'
208 sFileName
= aURLObject
.GetMainURL(INetURLObject::DECODE_TO_IURI
);
209 sFileName
+= rFileName
;
211 SfxMedium
aMedium( sFileName
,STREAM_READ
, TRUE
);
212 SvStream
* pInStream
= aMedium
.GetInStream();
216 pInStream
->ReadCString( rContent
, RTL_TEXTENCODING_UTF8
);
219 while ( ( nPos
= rContent
.Search( 12 )) != STRING_NOTFOUND
)
220 rContent
.Erase( nPos
, 1 );
225 void OEMPreloadDialog::SetCancelString( const String
& rText
)
227 aCancelPB
.SetText(rText
);
230 /* -----------------------------13.11.2001 12:29------------------------------
232 ---------------------------------------------------------------------------*/
233 OEMWelcomeTabPage::OEMWelcomeTabPage(Window
* pParent
) :
234 TabPage(pParent
, ModuleRes(RID_TP_WELCOME
)),
235 aInfoFT(this, ModuleRes(FT_INFO
))
239 /* -----------------------------13.11.2001 12:30------------------------------
241 ---------------------------------------------------------------------------*/
242 OEMWelcomeTabPage::~OEMWelcomeTabPage()
245 /* -----------------------------13.11.2001 12:29------------------------------
247 ---------------------------------------------------------------------------*/
248 OEMLicenseTabPage::OEMLicenseTabPage(OEMPreloadDialog
* pParent
) :
249 TabPage(pParent
, ModuleRes(RID_TP_LICENSE
)),
250 aLicenseML(this, ModuleRes(ML_LICENSE
)),
251 aInfo1FT(this, ModuleRes(FT_INFO1
)),
252 aInfo2FT(this, ModuleRes(FT_INFO2
)),
253 aInfo3FT(this, ModuleRes(FT_INFO3
)),
254 aInfo2_1FT(this, ModuleRes(FT_INFO2_1
)),
255 aInfo3_1FT(this, ModuleRes(FT_INFO3_1
)),
256 aCBAccept(this, ModuleRes(CB_ACCEPT
)),
257 aPBPageDown(this, ModuleRes(PB_PAGEDOWN
)),
258 aArrow(this, ModuleRes(IMG_ARROW
)),
259 aStrAccept( ModuleRes(LICENCE_ACCEPT
) ),
260 aStrNotAccept( ModuleRes(LICENCE_NOTACCEPT
) ),
262 pPreloadDialog(pParent
)
266 aLicenseML
.SetEndReachedHdl( LINK(this, OEMLicenseTabPage
, EndReachedHdl
) );
267 aLicenseML
.SetScrolledHdl( LINK(this, OEMLicenseTabPage
, ScrolledHdl
) );
269 aPBPageDown
.SetClickHdl( LINK(this, OEMLicenseTabPage
, PageDownHdl
) );
270 aCBAccept
.SetClickHdl( LINK(this, OEMLicenseTabPage
, AcceptHdl
) );
272 // We want a automatic repeating page down button
273 WinBits aStyle
= aPBPageDown
.GetStyle();
275 aPBPageDown
.SetStyle( aStyle
);
277 aOldCancelText
= pPreloadDialog
->GetCancelString();
278 pPreloadDialog
->SetCancelString( aStrNotAccept
);
280 String aText
= aInfo2FT
.GetText();
281 aText
.SearchAndReplaceAll( UniString::CreateFromAscii("%PAGEDOWN"), aPBPageDown
.GetText() );
282 aInfo2FT
.SetText( aText
);
284 /* -----------------------------13.11.2001 12:30------------------------------
286 ---------------------------------------------------------------------------*/
287 OEMLicenseTabPage::~OEMLicenseTabPage()
290 /* ---------------------------14.11.2001 11:24----------------------------
292 -----------------------------------------------------------------------*/
293 void OEMLicenseTabPage::ActivatePage()
295 if(!aLicenseML
.GetText().Len())
297 aLicenseML
.SetLeftMargin( 5 );
300 OEMPreloadDialog::LoadFromLocalFile(String::CreateFromAscii("LICENSE"), sLicense
);
302 OEMPreloadDialog::LoadFromLocalFile(String::CreateFromAscii("license.txt"), sLicense
);
304 aLicenseML
.SetText( sLicense
);
310 //------------------------------------------------------------------------
311 IMPL_LINK( OEMLicenseTabPage
, AcceptHdl
, CheckBox
*, EMPTYARG
)
317 //------------------------------------------------------------------------
318 IMPL_LINK( OEMLicenseTabPage
, PageDownHdl
, PushButton
*, EMPTYARG
)
320 aLicenseML
.ScrollDown( SCROLL_PAGEDOWN
);
324 //------------------------------------------------------------------------
325 IMPL_LINK( OEMLicenseTabPage
, EndReachedHdl
, LicenceView
*, EMPTYARG
)
330 aCBAccept
.GrabFocus();
335 //------------------------------------------------------------------------
336 IMPL_LINK( OEMLicenseTabPage
, ScrolledHdl
, LicenceView
*, EMPTYARG
)
343 //------------------------------------------------------------------------
344 void OEMLicenseTabPage::EnableControls()
347 ( aLicenseML
.IsEndReached() || !aLicenseML
.GetText().Len() ) )
352 Point
aPos( 0, aInfo3_1FT
.GetPosPixel().Y() );
353 aArrow
.SetPosPixel( aPos
);
358 Point
aPos( 0, aInfo2_1FT
.GetPosPixel().Y() );
359 aArrow
.SetPosPixel( aPos
);
363 if ( aLicenseML
.IsEndReached() )
364 aPBPageDown
.Disable();
366 aPBPageDown
.Enable();
368 if ( aCBAccept
.IsChecked() )
370 PushButton
*pNext
= pPreloadDialog
->GetNextButton();
371 if ( ! pNext
->IsEnabled() )
373 pPreloadDialog
->SetCancelString( aOldCancelText
);
379 PushButton
*pNext
= pPreloadDialog
->GetNextButton();
380 if ( pNext
->IsEnabled() )
382 pPreloadDialog
->SetCancelString( aStrNotAccept
);
383 pNext
->Enable(FALSE
);
388 //------------------------------------------------------------------------
389 //------------------------------------------------------------------------
390 //------------------------------------------------------------------------
391 LicenceView::LicenceView( Window
* pParent
, const ResId
& rResId
)
392 : MultiLineEdit( pParent
, rResId
)
396 mbEndReached
= IsEndReached();
398 StartListening( *GetTextEngine() );
401 //------------------------------------------------------------------------
402 LicenceView::~LicenceView()
404 maEndReachedHdl
= Link();
405 maScrolledHdl
= Link();
410 //------------------------------------------------------------------------
411 void LicenceView::ScrollDown( ScrollType eScroll
)
413 ScrollBar
* pScroll
= GetVScrollBar();
416 pScroll
->DoScrollAction( eScroll
);
419 //------------------------------------------------------------------------
420 BOOL
LicenceView::IsEndReached() const
424 ExtTextView
* pView
= GetTextView();
425 ExtTextEngine
* pEdit
= GetTextEngine();
426 ULONG nHeight
= pEdit
->GetTextHeight();
427 Size aOutSize
= pView
->GetWindow()->GetOutputSizePixel();
428 Point
aBottom( 0, aOutSize
.Height() );
430 if ( (ULONG
) pView
->GetDocPos( aBottom
).Y() >= nHeight
- 1 )
438 //------------------------------------------------------------------------
439 void LicenceView::Notify( SfxBroadcaster
& /*rBC*/, const SfxHint
& rHint
)
441 if ( rHint
.IsA( TYPE(TextHint
) ) )
443 BOOL bLastVal
= EndReached();
444 ULONG nId
= ((const TextHint
&)rHint
).GetId();
446 if ( nId
== TEXT_HINT_PARAINSERTED
)
449 mbEndReached
= IsEndReached();
451 else if ( nId
== TEXT_HINT_VIEWSCROLLED
)
453 if ( ! mbEndReached
)
454 mbEndReached
= IsEndReached();
455 maScrolledHdl
.Call( this );
458 if ( EndReached() && !bLastVal
)
460 maEndReachedHdl
.Call( this );
465 //------------------------------------------------------------------------
467 //.........................................................................
468 } // namespace preload
469 //.........................................................................