1*859212d1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*859212d1SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*859212d1SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*859212d1SAndrew Rist * distributed with this work for additional information
6*859212d1SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*859212d1SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*859212d1SAndrew Rist * "License"); you may not use this file except in compliance
9*859212d1SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*859212d1SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*859212d1SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*859212d1SAndrew Rist * software distributed under the License is distributed on an
15*859212d1SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*859212d1SAndrew Rist * KIND, either express or implied. See the License for the
17*859212d1SAndrew Rist * specific language governing permissions and limitations
18*859212d1SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*859212d1SAndrew Rist *************************************************************/
21*859212d1SAndrew Rist
22*859212d1SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include <svtools/filedlg.hxx>
25cdf0e10cSrcweir #include <vcl/msgbox.hxx>
26cdf0e10cSrcweir
27cdf0e10cSrcweir #ifndef UUI_IDS_HRC
28cdf0e10cSrcweir #include <ids.hrc>
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef UUI_MASTERPASSCRTDLG_HRC
31cdf0e10cSrcweir #include <masterpasscrtdlg.hrc>
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #include <masterpasscrtdlg.hxx>
34cdf0e10cSrcweir
35cdf0e10cSrcweir // MasterPasswordCreateDialog---------------------------------------------------
36cdf0e10cSrcweir
37cdf0e10cSrcweir // -----------------------------------------------------------------------
38cdf0e10cSrcweir
IMPL_LINK(MasterPasswordCreateDialog,EditHdl_Impl,Edit *,EMPTYARG)39cdf0e10cSrcweir IMPL_LINK( MasterPasswordCreateDialog, EditHdl_Impl, Edit *, EMPTYARG )
40cdf0e10cSrcweir {
41cdf0e10cSrcweir aOKBtn.Enable( aEDMasterPasswordCrt.GetText().Len() >= nMinLen );
42cdf0e10cSrcweir return 0;
43cdf0e10cSrcweir }
44cdf0e10cSrcweir
45cdf0e10cSrcweir // -----------------------------------------------------------------------
46cdf0e10cSrcweir
IMPL_LINK(MasterPasswordCreateDialog,OKHdl_Impl,OKButton *,EMPTYARG)47cdf0e10cSrcweir IMPL_LINK( MasterPasswordCreateDialog, OKHdl_Impl, OKButton *, EMPTYARG )
48cdf0e10cSrcweir {
49cdf0e10cSrcweir // compare both passwords and show message box if there are not equal!!
50cdf0e10cSrcweir if( aEDMasterPasswordCrt.GetText() == aEDMasterPasswordRepeat.GetText() )
51cdf0e10cSrcweir EndDialog( RET_OK );
52cdf0e10cSrcweir else
53cdf0e10cSrcweir {
54cdf0e10cSrcweir String aErrorMsg( ResId( STR_ERROR_PASSWORDS_NOT_IDENTICAL, *pResourceMgr ));
55cdf0e10cSrcweir ErrorBox aErrorBox( this, WB_OK, aErrorMsg );
56cdf0e10cSrcweir aErrorBox.Execute();
57cdf0e10cSrcweir aEDMasterPasswordCrt.SetText( String() );
58cdf0e10cSrcweir aEDMasterPasswordRepeat.SetText( String() );
59cdf0e10cSrcweir aEDMasterPasswordCrt.GrabFocus();
60cdf0e10cSrcweir }
61cdf0e10cSrcweir return 1;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir
64cdf0e10cSrcweir // -----------------------------------------------------------------------
65cdf0e10cSrcweir
MasterPasswordCreateDialog(Window * pParent,ResMgr * pResMgr)66cdf0e10cSrcweir MasterPasswordCreateDialog::MasterPasswordCreateDialog
67cdf0e10cSrcweir (
68cdf0e10cSrcweir Window* pParent,
69cdf0e10cSrcweir ResMgr* pResMgr
70cdf0e10cSrcweir ) :
71cdf0e10cSrcweir
72cdf0e10cSrcweir ModalDialog( pParent, ResId( DLG_UUI_MASTERPASSWORD_CRT, *pResMgr ) ),
73cdf0e10cSrcweir
74cdf0e10cSrcweir aFTInfoText ( this, ResId( FT_INFOTEXT, *pResMgr ) ),
75cdf0e10cSrcweir aFLInfoText ( this, ResId( FL_INFOTEXT, *pResMgr ) ),
76cdf0e10cSrcweir
77cdf0e10cSrcweir aFTMasterPasswordCrt ( this, ResId( FT_MASTERPASSWORD_CRT, *pResMgr ) ),
78cdf0e10cSrcweir aEDMasterPasswordCrt ( this, ResId( ED_MASTERPASSWORD_CRT, *pResMgr ) ),
79cdf0e10cSrcweir aFTMasterPasswordRepeat ( this, ResId( FT_MASTERPASSWORD_REPEAT, *pResMgr ) ),
80cdf0e10cSrcweir aEDMasterPasswordRepeat ( this, ResId( ED_MASTERPASSWORD_REPEAT, *pResMgr ) ),
81cdf0e10cSrcweir
82cdf0e10cSrcweir aFTCautionText ( this, ResId( FT_CAUTIONTEXT, *pResMgr ) ),
83cdf0e10cSrcweir aFLCautionText ( this, ResId( FL_CAUTIONTEXT, *pResMgr ) ),
84cdf0e10cSrcweir
85cdf0e10cSrcweir aFTMasterPasswordWarning ( this, ResId( FT_MASTERPASSWORD_WARNING, *pResMgr ) ),
86cdf0e10cSrcweir aFL ( this, ResId( FL_FIXED_LINE, *pResMgr ) ),
87cdf0e10cSrcweir aOKBtn ( this, ResId( BTN_MASTERPASSCRT_OK, *pResMgr ) ),
88cdf0e10cSrcweir aCancelBtn ( this, ResId( BTN_MASTERPASSCRT_CANCEL, *pResMgr ) ),
89cdf0e10cSrcweir aHelpBtn ( this, ResId( BTN_MASTERPASSCRT_HELP, *pResMgr ) ),
90cdf0e10cSrcweir
91cdf0e10cSrcweir pResourceMgr ( pResMgr ),
92cdf0e10cSrcweir nMinLen ( 1 )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir FreeResource();
95cdf0e10cSrcweir
96cdf0e10cSrcweir aOKBtn.Enable( sal_False );
97cdf0e10cSrcweir aOKBtn.SetClickHdl( LINK( this, MasterPasswordCreateDialog, OKHdl_Impl ) );
98cdf0e10cSrcweir aEDMasterPasswordCrt.SetModifyHdl( LINK( this, MasterPasswordCreateDialog, EditHdl_Impl ) );
99cdf0e10cSrcweir
100cdf0e10cSrcweir CalculateTextHeight();
101cdf0e10cSrcweir
102cdf0e10cSrcweir long nLableWidth = aFTMasterPasswordWarning.GetSizePixel().Width();
103cdf0e10cSrcweir long nLabelHeight = aFTMasterPasswordWarning.GetSizePixel().Height();
104cdf0e10cSrcweir long nTextWidth = aFTMasterPasswordWarning.GetCtrlTextWidth( aFTMasterPasswordWarning.GetText() );
105cdf0e10cSrcweir long nTextHeight = aFTMasterPasswordWarning.GetTextHeight();
106cdf0e10cSrcweir
107cdf0e10cSrcweir Rectangle aLabelRect( aFTMasterPasswordWarning.GetPosPixel(), aFTMasterPasswordWarning.GetSizePixel() );
108cdf0e10cSrcweir Rectangle aRect = aFTMasterPasswordWarning.GetTextRect( aLabelRect, aFTMasterPasswordWarning.GetText() );
109cdf0e10cSrcweir
110cdf0e10cSrcweir long nNewLabelHeight = 0;
111cdf0e10cSrcweir if ( nTextWidth > 0 )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir for( nNewLabelHeight = ( nTextWidth / nLableWidth + 1 ) * nTextHeight;
114cdf0e10cSrcweir nNewLabelHeight < aRect.GetHeight();
115cdf0e10cSrcweir nNewLabelHeight += nTextHeight ) {};
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
118cdf0e10cSrcweir long nDelta = nNewLabelHeight - nLabelHeight;
119cdf0e10cSrcweir Size aNewDlgSize = GetSizePixel();
120cdf0e10cSrcweir aNewDlgSize.Height() += nDelta;
121cdf0e10cSrcweir SetSizePixel( aNewDlgSize );
122cdf0e10cSrcweir
123cdf0e10cSrcweir Size aNewWarningSize = aFTMasterPasswordWarning.GetSizePixel();
124cdf0e10cSrcweir aNewWarningSize.Height() = nNewLabelHeight;
125cdf0e10cSrcweir aFTMasterPasswordWarning.SetPosSizePixel( aFTMasterPasswordWarning.GetPosPixel(), aNewWarningSize );
126cdf0e10cSrcweir
127cdf0e10cSrcweir Window* pControls[] = { &aFL, &aOKBtn, &aCancelBtn, &aHelpBtn };
128cdf0e10cSrcweir const sal_Int32 nCCount = sizeof( pControls ) / sizeof( pControls[0] );
129cdf0e10cSrcweir for ( int i = 0; i < nCCount; ++i )
130cdf0e10cSrcweir {
131cdf0e10cSrcweir Point aNewPos =(*pControls[i]).GetPosPixel();
132cdf0e10cSrcweir aNewPos.Y() += nDelta;
133cdf0e10cSrcweir pControls[i]->SetPosSizePixel( aNewPos, pControls[i]->GetSizePixel() );
134cdf0e10cSrcweir }
135cdf0e10cSrcweir };
136cdf0e10cSrcweir
CalculateTextHeight()137cdf0e10cSrcweir void MasterPasswordCreateDialog::CalculateTextHeight()
138cdf0e10cSrcweir {
139cdf0e10cSrcweir Size aSize = aFTInfoText.GetSizePixel();
140cdf0e10cSrcweir Size aMinSize = aFTInfoText.CalcMinimumSize( aSize.Width() );
141cdf0e10cSrcweir long nDelta = 0;
142cdf0e10cSrcweir
143cdf0e10cSrcweir if ( aSize.Height() > aMinSize.Height() )
144cdf0e10cSrcweir {
145cdf0e10cSrcweir aFTInfoText.SetSizePixel( aMinSize );
146cdf0e10cSrcweir nDelta = aSize.Height() - aMinSize.Height();
147cdf0e10cSrcweir Window* pWins[] = { &aFLInfoText, &aFTMasterPasswordCrt, &aEDMasterPasswordCrt,
148cdf0e10cSrcweir &aFTMasterPasswordRepeat, &aEDMasterPasswordRepeat, &aFTCautionText,
149cdf0e10cSrcweir &aFLCautionText, &aOKBtn, &aCancelBtn, &aHelpBtn };
150cdf0e10cSrcweir Window** pWindow = pWins;
151cdf0e10cSrcweir const sal_Int32 nCount = sizeof( pWins ) / sizeof( pWins[0] );
152cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; ++i, ++pWindow )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir Point aNewPos = (*pWindow)->GetPosPixel();
155cdf0e10cSrcweir aNewPos.Y() -= nDelta;
156cdf0e10cSrcweir (*pWindow)->SetPosPixel( aNewPos );
157cdf0e10cSrcweir }
158cdf0e10cSrcweir }
159cdf0e10cSrcweir
160cdf0e10cSrcweir aSize = aFTCautionText.GetSizePixel();
161cdf0e10cSrcweir aMinSize = aFTCautionText.CalcMinimumSize( aSize.Width() );
162cdf0e10cSrcweir
163cdf0e10cSrcweir if ( aSize.Height() > aMinSize.Height() )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir aFTCautionText.SetSizePixel( aMinSize );
166cdf0e10cSrcweir long nTemp = aSize.Height() - aMinSize.Height();
167cdf0e10cSrcweir nDelta += nTemp;
168cdf0e10cSrcweir Window* pWins[] = { &aFLCautionText, &aOKBtn, &aCancelBtn, &aHelpBtn };
169cdf0e10cSrcweir Window** pWindow = pWins;
170cdf0e10cSrcweir const sal_Int32 nCount = sizeof( pWins ) / sizeof( pWins[0] );
171cdf0e10cSrcweir for ( sal_Int32 i = 0; i < nCount; ++i, ++pWindow )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir Point aNewPos = (*pWindow)->GetPosPixel();
174cdf0e10cSrcweir aNewPos.Y() -= nTemp;
175cdf0e10cSrcweir (*pWindow)->SetPosPixel( aNewPos );
176cdf0e10cSrcweir }
177cdf0e10cSrcweir }
178cdf0e10cSrcweir
179cdf0e10cSrcweir if ( nDelta > 0 )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir Size aDlgSize = GetOutputSizePixel();
182cdf0e10cSrcweir aDlgSize.Height() -= nDelta;
183cdf0e10cSrcweir SetSizePixel( aDlgSize );
184cdf0e10cSrcweir }
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
187