update dev300-m58
[ooovba.git] / sfx2 / source / dialog / alienwarn.cxx
blob5ed5569ea3360d1fb93b9d69473fcf020d7166a1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: alienwarn.cxx,v $
10 * $Revision: 1.14 $
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_sfx2.hxx"
34 #include "alienwarn.hxx"
35 #include "sfxresid.hxx"
36 #include <sfx2/sfxuno.hxx>
38 #include "alienwarn.hrc"
39 #include "dialog.hrc"
40 #include <vcl/msgbox.hxx>
41 #include <svtools/saveopt.hxx>
43 // class SfxAlienWarningDialog -------------------------------------------
45 SfxAlienWarningDialog::SfxAlienWarningDialog( Window* pParent, const String& _rFormatName ) :
47 SfxModalDialog( pParent, SfxResId( RID_DLG_ALIEN_WARNING ) ),
49 m_aKeepCurrentBtn ( this, SfxResId( PB_NO ) ),
50 m_aSaveODFBtn ( this, SfxResId( PB_YES ) ),
51 m_aMoreInfoBtn ( this, SfxResId( PB_MOREINFO ) ),
52 m_aOptionLine ( this, SfxResId( FL_OPTION ) ),
53 m_aWarningOnBox ( this, SfxResId( CB_WARNING_OFF ) ),
54 m_aQueryImage ( this, SfxResId( FI_QUERY ) ),
55 m_aInfoText ( this, SfxResId( FT_INFOTEXT ) )
58 FreeResource();
60 // set questionmark image
61 m_aQueryImage.SetImage( QueryBox::GetStandardImage() );
63 // replace formatname
64 String sInfoText = m_aInfoText.GetText();
65 sInfoText.SearchAndReplaceAll( DEFINE_CONST_UNICODE("%FORMATNAME"), _rFormatName );
66 m_aInfoText.SetText( sInfoText );
68 // load value of "warning on" checkbox from save options
69 m_aWarningOnBox.Check( SvtSaveOptions().IsWarnAlienFormat() == sal_True );
71 // set focus to "Keep Current Format" button
72 m_aKeepCurrentBtn.GrabFocus();
74 // pb: #i43989# we have no online help for this dialog at the moment
75 // -> hide the "more info" button
76 //m_aMoreInfoBtn.Hide();
78 // calculate and set the size of the dialog and its controls
79 InitSize();
82 // -----------------------------------------------------------------------
84 SfxAlienWarningDialog::~SfxAlienWarningDialog()
86 // save value of "warning off" checkbox, if necessary
87 SvtSaveOptions aSaveOpt;
88 sal_Bool bChecked = m_aWarningOnBox.IsChecked();
89 if ( aSaveOpt.IsWarnAlienFormat() != bChecked )
90 aSaveOpt.SetWarnAlienFormat( bChecked );
93 // -----------------------------------------------------------------------
95 void SfxAlienWarningDialog::InitSize()
97 // if the button text is too wide, then broaden the button
98 long nTxtW = m_aMoreInfoBtn.GetCtrlTextWidth( m_aMoreInfoBtn.GetText() );
99 long nCtrlW = m_aMoreInfoBtn.GetSizePixel().Width();
100 if ( nTxtW >= nCtrlW )
102 long nDelta = nTxtW - nCtrlW;
103 nDelta += IMPL_EXTRA_BUTTON_WIDTH;
104 Point aNextPoint = m_aKeepCurrentBtn.GetPosPixel();
105 aNextPoint.X() += m_aKeepCurrentBtn.GetSizePixel().Width();
106 Point aNewPoint = m_aMoreInfoBtn.GetPosPixel();
107 aNewPoint.X() -= nDelta;
108 if ( aNextPoint.X() >= aNewPoint.X() )
110 long nSpace = aNextPoint.X() - aNewPoint.X();
111 nSpace += 2;
112 nDelta -= nSpace;
113 aNewPoint.X() += nSpace;
115 Size aNewSize = m_aMoreInfoBtn.GetSizePixel();
116 aNewSize.Width() += nDelta;
117 m_aMoreInfoBtn.SetPosSizePixel( aNewPoint, aNewSize );
120 // text of checkbox to wide -> add new line
121 nTxtW = m_aWarningOnBox.GetCtrlTextWidth( m_aWarningOnBox.GetText() ) + IMPL_EXTRA_BUTTON_WIDTH;
122 nCtrlW = m_aWarningOnBox.GetSizePixel().Width();
123 if ( nTxtW >= nCtrlW )
125 long nTextHeight = m_aWarningOnBox.GetTextHeight();
126 Size aNewSize = m_aWarningOnBox.GetSizePixel();
127 aNewSize.Height() += nTextHeight;
128 m_aWarningOnBox.SetSizePixel( aNewSize );
129 aNewSize = GetSizePixel();
130 aNewSize.Height() += nTextHeight;
131 SetSizePixel( aNewSize );
134 // align the size of the information text control (FixedText) to its content
135 Size aMinSize = m_aInfoText.CalcMinimumSize( m_aInfoText.GetSizePixel().Width() );
136 long nTxtH = aMinSize.Height();
137 long nCtrlH = m_aInfoText.GetSizePixel().Height();
138 long nDelta = ( nCtrlH - nTxtH );
139 Size aNewSize = m_aInfoText.GetSizePixel();
140 aNewSize.Height() -= nDelta;
141 m_aInfoText.SetSizePixel( aNewSize );
143 // new position for the succeeding windows
144 Window* pWins[] =
146 &m_aSaveODFBtn, &m_aKeepCurrentBtn, &m_aMoreInfoBtn, &m_aOptionLine, &m_aWarningOnBox
148 Window** pCurrent = pWins;
149 for ( sal_uInt32 i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
151 Point aNewPos = (*pCurrent)->GetPosPixel();
152 aNewPos.Y() -= nDelta;
153 (*pCurrent)->SetPosPixel( aNewPos );
156 // new size of the dialog
157 aNewSize = GetSizePixel();
158 aNewSize.Height() -= nDelta;
159 SetSizePixel( aNewSize );
161 // recalculate the size and position of the buttons
162 m_aMoreInfoBtn.Hide();
163 nTxtW = m_aKeepCurrentBtn.GetCtrlTextWidth( m_aKeepCurrentBtn.GetText() );
164 long nTemp = m_aSaveODFBtn.GetCtrlTextWidth( m_aSaveODFBtn.GetText() );
165 if ( nTemp > nTxtW )
166 nTxtW = nTemp;
167 nTxtW += IMPL_EXTRA_BUTTON_WIDTH;
168 Size a3Size = LogicToPixel( Size( 3, 3 ), MAP_APPFONT );
169 Point aPos = m_aKeepCurrentBtn.GetPosPixel();
170 aPos.X() = ( aNewSize.Width() - (2*nTxtW) - a3Size.Width() ) / 2;
171 long nDefX = m_aWarningOnBox.GetPosPixel().X();
172 if ( nDefX < aPos.X() )
173 aPos.X() = nDefX;
174 aNewSize = m_aKeepCurrentBtn.GetSizePixel();
175 aNewSize.Width() = nTxtW;
176 m_aKeepCurrentBtn.SetPosSizePixel( aPos, aNewSize );
177 aPos.X() += nTxtW + a3Size.Width();
178 m_aSaveODFBtn.SetPosSizePixel( aPos, aNewSize );