Update ooo320-m1
[ooovba.git] / svtools / source / productregistration / registrationdlg.cxx
blobf07e70574069c4ea81a4dd3783c411ab708cdfcc
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: registrationdlg.cxx,v $
10 * $Revision: 1.8 $
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_svtools.hxx"
33 #include "registrationdlg.hxx"
35 #if 0 /* @@@ */
36 #include <svtools/svtdata.hxx>
37 #ifndef _SVTOOLS_HRC
38 #include <svtools/svtools.hrc>
39 #endif
40 #endif /* @@@ */
42 #ifndef SVTOOLS_REGISTRATIONDLG_HRC
43 #include "registrationdlg.hrc"
44 #endif
45 #include <vcl/msgbox.hxx>
46 #include <tools/debug.hxx>
48 //........................................................................
49 namespace svt
51 //........................................................................
53 static void lcl_moveControls( Control** _ppControls, sal_Int32 _nAmount )
55 if ( _ppControls )
56 while ( *_ppControls )
58 Point aPos = (*_ppControls)->GetPosPixel();
59 aPos.Y() += _nAmount;
60 (*_ppControls)->SetPosPixel( aPos );
62 ++_ppControls;
66 //====================================================================
67 //= RegistrationDialog
68 //====================================================================
69 //--------------------------------------------------------------------
70 RegistrationDialog::RegistrationDialog( Window* _pWindow, const ResId& _rResId, bool _bEvalVersion )
71 :ModalDialog( _pWindow, _rResId )
72 ,m_eResponse ( urRegisterLater )
73 ,m_aLogo ( this, ResId( FI_LOGO, *_rResId.GetResMgr() ) )
74 ,m_aIntro ( this, ResId( FT_INTRO, *_rResId.GetResMgr() ) )
75 ,m_aNow ( this, ResId( RB_NOW, *_rResId.GetResMgr() ) )
76 ,m_aLater ( this, ResId( RB_LATER, *_rResId.GetResMgr() ) )
77 ,m_aNever ( this, ResId( RB_NEVER, *_rResId.GetResMgr() ) )
78 ,m_aAlreadyDone ( this, ResId( RB_DONE, *_rResId.GetResMgr() ) )
79 ,m_aSeparator ( this, ResId( FL_SEPARATOR, *_rResId.GetResMgr() ) )
80 ,m_aOK ( this, ResId( BTN_OK, *_rResId.GetResMgr() ) )
81 ,m_aHelp ( this, ResId( BTN_HELP, *_rResId.GetResMgr() ) )
83 if ( _bEvalVersion )
84 { // if we're an eval version, we need to hide two of the options
85 m_aNever.Hide( );
86 m_aAlreadyDone.Hide( );
88 // make the explanatory text somewhat smaller
89 Size aIntroSize = m_aIntro.GetSizePixel();
90 aIntroSize.Height() = LogicToPixel( Size( 0, 18 ), MAP_APPFONT ).Height();
91 sal_Int32 nHeightDifference = m_aIntro.GetSizePixel().Height() - aIntroSize.Height();
92 m_aIntro.SetSizePixel( aIntroSize );
94 // resize the dialog, and move the controls below the ones we just hided
95 sal_Int32 nAlreadyDoneLower = m_aAlreadyDone.GetPosPixel().Y() + m_aAlreadyDone.GetSizePixel().Height();
96 sal_Int32 nLaterLower = m_aLater.GetPosPixel().Y() + m_aLater.GetSizePixel().Height();
97 sal_Int32 nDifference = nAlreadyDoneLower - nLaterLower;
99 sal_Int32 nOverallDifference = nDifference + nHeightDifference;
101 // move
102 Control* pVisibleRadios[] = { &m_aNow, &m_aLater, NULL };
103 lcl_moveControls( pVisibleRadios, -nHeightDifference );
105 Control* pControlsToMove[] = { &m_aSeparator, &m_aOK, &m_aHelp, NULL };
106 lcl_moveControls( pControlsToMove, -nOverallDifference );
108 // resize the dialog
109 Size aSize = GetSizePixel();
110 aSize.Height() -= nOverallDifference;
111 SetSizePixel( aSize );
113 else
115 // the explanatory text needs to be completed
116 String sCompleteIntro = m_aIntro.GetText( );
117 sCompleteIntro += String( ResId( STR_COMPLETE_INTRO, *_rResId.GetResMgr() ) );
118 m_aIntro.SetText( sCompleteIntro );
121 FreeResource();
123 m_aNow.Check( TRUE );
126 //--------------------------------------------------------------------
127 short RegistrationDialog::Execute()
129 short nResult = ModalDialog::Execute();
131 // as a default, assume that the user wants to be reminded
132 m_eResponse = urRegisterLater;
134 if ( RET_OK == nResult )
136 if ( m_aNow.IsChecked() )
137 m_eResponse = urRegisterNow;
138 else if ( m_aLater.IsChecked() )
139 m_eResponse = urRegisterLater;
140 else if ( m_aNever.IsChecked() )
141 m_eResponse = urRegisterNever;
142 else if ( m_aAlreadyDone.IsChecked() )
143 m_eResponse = urAlreadyRegistered;
144 #ifdef DBG_UTIL
145 else
147 DBG_ERROR( "RegistrationDialog::Execute: invalid dialog state!" );
149 #endif
151 return nResult;
153 //--------------------------------------------------------------------
154 long RegistrationDialog::PreNotify( NotifyEvent& rNEvt )
156 long nHandled;
157 if( rNEvt.GetType() == EVENT_KEYINPUT &&
158 rNEvt.GetKeyEvent()->GetCharCode() &&
159 rNEvt.GetKeyEvent()->GetKeyCode().GetCode() == KEY_ESCAPE)
161 EndDialog(RET_CANCEL);
162 nHandled = 1;
164 else
165 nHandled = ModalDialog::PreNotify( rNEvt );
166 return nHandled;
170 //........................................................................
171 } // namespace svt
172 //........................................................................