Bump version to 4.1-6
[LibreOffice.git] / sfx2 / source / dialog / alienwarn.cxx
blob99275f4d50b68c47df7b4ff85282140e47b23ef4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <sal/macros.h>
22 #include "alienwarn.hxx"
23 #include "sfx2/sfxresid.hxx"
24 #include <sfx2/sfxuno.hxx>
26 #include "alienwarn.hrc"
27 #include "dialog.hrc"
28 #include <vcl/msgbox.hxx>
29 #include <unotools/saveopt.hxx>
31 // class SfxAlienWarningDialog -------------------------------------------
33 SfxAlienWarningDialog::SfxAlienWarningDialog( Window* pParent, const String& _rFormatName ) :
35 SfxModalDialog( pParent, SfxResId( RID_DLG_ALIEN_WARNING ) ),
37 m_aKeepCurrentBtn ( this, SfxResId( PB_NO ) ),
38 m_aSaveODFBtn ( this, SfxResId( PB_YES ) ),
39 m_aMoreInfoBtn ( this, SfxResId( PB_MOREINFO ) ),
40 m_aOptionLine ( this, SfxResId( FL_OPTION ) ),
41 m_aWarningOnBox ( this, SfxResId( CB_WARNING_OFF ) ),
42 m_aQueryImage ( this, SfxResId( FI_QUERY ) ),
43 m_aInfoText ( this, SfxResId( FT_INFOTEXT ) )
46 FreeResource();
48 // set questionmark image
49 m_aQueryImage.SetImage( QueryBox::GetStandardImage() );
51 // replace formatname (text)
52 OUString sInfoText = m_aInfoText.GetText();
53 sInfoText = sInfoText.replaceAll( "%FORMATNAME", _rFormatName );
54 m_aInfoText.SetText( sInfoText );
56 // replace formatname (button)
57 sInfoText = m_aKeepCurrentBtn.GetText();
58 sInfoText = sInfoText.replaceAll( "%FORMATNAME", _rFormatName );
59 m_aKeepCurrentBtn.SetText( sInfoText );
61 // load value of "warning on" checkbox from save options
62 m_aWarningOnBox.Check( SvtSaveOptions().IsWarnAlienFormat() == sal_True );
64 // set focus to "Keep Current Format" button
65 m_aKeepCurrentBtn.GrabFocus();
67 // pb: #i43989# we have no online help for this dialog at the moment
68 // -> hide the "more info" button
69 //m_aMoreInfoBtn.Hide();
71 // calculate and set the size of the dialog and its controls
72 InitSize();
75 // -----------------------------------------------------------------------
77 SfxAlienWarningDialog::~SfxAlienWarningDialog()
79 // save value of "warning off" checkbox, if necessary
80 SvtSaveOptions aSaveOpt;
81 sal_Bool bChecked = m_aWarningOnBox.IsChecked();
82 if ( aSaveOpt.IsWarnAlienFormat() != bChecked )
83 aSaveOpt.SetWarnAlienFormat( bChecked );
86 // -----------------------------------------------------------------------
88 void SfxAlienWarningDialog::InitSize()
90 const long nExtraButtonWidth = LogicToPixel( Size(IMPL_EXTRA_BUTTON_WIDTH,1), MapMode(MAP_APPFONT) ).getWidth();
91 const long nAwCol2 = LogicToPixel( Size(AW_COL_2,1), MapMode(MAP_APPFONT) ).getWidth();
92 long nTxtW, nCtrlW;
94 // layout calculations should be re-done, when More Info button is enabled
95 m_aMoreInfoBtn.Hide();
97 // recalculate the size and position of the buttons
98 nTxtW = m_aKeepCurrentBtn.GetCtrlTextWidth( m_aKeepCurrentBtn.GetText() );
99 nTxtW += nExtraButtonWidth;
100 Size aNewSize = m_aKeepCurrentBtn.GetSizePixel();
101 aNewSize.Width() = nTxtW;
102 m_aKeepCurrentBtn.SetSizePixel( aNewSize );
103 Point aPos = m_aSaveODFBtn.GetPosPixel();
104 aPos.X() = nAwCol2 + nTxtW + nExtraButtonWidth;
105 m_aSaveODFBtn.SetPosPixel( aPos );
106 nTxtW = m_aSaveODFBtn.GetCtrlTextWidth( m_aSaveODFBtn.GetText() );
107 nTxtW += nExtraButtonWidth;
108 aNewSize = m_aSaveODFBtn.GetSizePixel();
109 aNewSize.Width() = nTxtW;
110 m_aSaveODFBtn.SetSizePixel( aNewSize );
111 long nBtnsWidthSize = m_aKeepCurrentBtn.GetSizePixel().Width() + m_aSaveODFBtn.GetSizePixel().Width() + nAwCol2 + 2*nExtraButtonWidth;
113 // resize + text of checkbox too wide -> add new line
114 aNewSize = m_aWarningOnBox.GetSizePixel();
115 aNewSize.Width() = nBtnsWidthSize - 2*nExtraButtonWidth;
116 m_aWarningOnBox.SetSizePixel( aNewSize );
117 nTxtW = m_aWarningOnBox.GetCtrlTextWidth( m_aWarningOnBox.GetText() );
118 nCtrlW = m_aWarningOnBox.GetSizePixel().Width();
119 if ( nTxtW >= nCtrlW )
121 long nTextHeight = m_aWarningOnBox.GetTextHeight();
122 aNewSize.Height() += nTextHeight;
123 m_aWarningOnBox.SetSizePixel( aNewSize );
124 aNewSize = GetSizePixel();
125 aNewSize.Height() += nTextHeight;
126 SetSizePixel( aNewSize );
129 // resize + align the size of the information text control (FixedText) to its content
130 aNewSize = m_aInfoText.GetSizePixel();
131 aNewSize.Width() = nBtnsWidthSize - 2*nExtraButtonWidth;
132 m_aInfoText.SetSizePixel( aNewSize );
133 Size aMinSize = m_aInfoText.CalcMinimumSize( m_aInfoText.GetSizePixel().Width() );
134 long nTxtH = aMinSize.Height();
135 long nCtrlH = m_aInfoText.GetSizePixel().Height();
136 long nDelta = ( nCtrlH - nTxtH );
137 aNewSize.Height() -= nDelta;
138 m_aInfoText.SetSizePixel( aNewSize );
141 // new position for the succeeding windows
142 Window* pWins[] =
144 &m_aSaveODFBtn, &m_aKeepCurrentBtn, &m_aMoreInfoBtn, &m_aOptionLine, &m_aWarningOnBox
146 Window** pCurrent = pWins;
147 for ( sal_uInt32 i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
149 Point aNewPos = (*pCurrent)->GetPosPixel();
150 aNewPos.Y() -= nDelta;
151 (*pCurrent)->SetPosPixel( aNewPos );
154 // new size of the dialog
155 aNewSize = GetSizePixel();
156 aNewSize.Height() -= nDelta;
157 aNewSize.Width() = nBtnsWidthSize;
158 SetSizePixel( aNewSize );
160 // resize the FixedLine
161 aNewSize = m_aOptionLine.GetSizePixel();
162 aNewSize.Width() = GetSizePixel().Width();
163 m_aOptionLine.SetSizePixel( aNewSize );
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */