Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / dialog / alienwarn.cxx
blobe9f7852669c5689f77846a7e5772ac8964546ceb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <sal/macros.h>
31 #include "alienwarn.hxx"
32 #include "sfx2/sfxresid.hxx"
33 #include <sfx2/sfxuno.hxx>
35 #include "alienwarn.hrc"
36 #include "dialog.hrc"
37 #include <vcl/msgbox.hxx>
38 #include <unotools/saveopt.hxx>
40 // class SfxAlienWarningDialog -------------------------------------------
42 SfxAlienWarningDialog::SfxAlienWarningDialog( Window* pParent, const String& _rFormatName ) :
44 SfxModalDialog( pParent, SfxResId( RID_DLG_ALIEN_WARNING ) ),
46 m_aKeepCurrentBtn ( this, SfxResId( PB_NO ) ),
47 m_aSaveODFBtn ( this, SfxResId( PB_YES ) ),
48 m_aMoreInfoBtn ( this, SfxResId( PB_MOREINFO ) ),
49 m_aOptionLine ( this, SfxResId( FL_OPTION ) ),
50 m_aWarningOnBox ( this, SfxResId( CB_WARNING_OFF ) ),
51 m_aQueryImage ( this, SfxResId( FI_QUERY ) ),
52 m_aInfoText ( this, SfxResId( FT_INFOTEXT ) )
55 FreeResource();
57 // set questionmark image
58 m_aQueryImage.SetImage( QueryBox::GetStandardImage() );
60 // replace formatname (text)
61 String sInfoText = m_aInfoText.GetText();
62 sInfoText.SearchAndReplaceAll( DEFINE_CONST_UNICODE("%FORMATNAME"), _rFormatName );
63 m_aInfoText.SetText( sInfoText );
65 // replace formatname (button)
66 sInfoText = m_aKeepCurrentBtn.GetText();
67 sInfoText.SearchAndReplaceAll( DEFINE_CONST_UNICODE("%FORMATNAME"), _rFormatName );
68 m_aKeepCurrentBtn.SetText( sInfoText );
70 // load value of "warning on" checkbox from save options
71 m_aWarningOnBox.Check( SvtSaveOptions().IsWarnAlienFormat() == sal_True );
73 // set focus to "Keep Current Format" button
74 m_aKeepCurrentBtn.GrabFocus();
76 // pb: #i43989# we have no online help for this dialog at the moment
77 // -> hide the "more info" button
78 //m_aMoreInfoBtn.Hide();
80 // calculate and set the size of the dialog and its controls
81 InitSize();
84 // -----------------------------------------------------------------------
86 SfxAlienWarningDialog::~SfxAlienWarningDialog()
88 // save value of "warning off" checkbox, if necessary
89 SvtSaveOptions aSaveOpt;
90 sal_Bool bChecked = m_aWarningOnBox.IsChecked();
91 if ( aSaveOpt.IsWarnAlienFormat() != bChecked )
92 aSaveOpt.SetWarnAlienFormat( bChecked );
95 // -----------------------------------------------------------------------
97 void SfxAlienWarningDialog::InitSize()
99 const long nExtraButtonWidth = LogicToPixel( Size(IMPL_EXTRA_BUTTON_WIDTH,1), MapMode(MAP_APPFONT) ).getWidth();
100 const long nAwCol2 = LogicToPixel( Size(AW_COL_2,1), MapMode(MAP_APPFONT) ).getWidth();
101 long nTxtW, nCtrlW;
103 // layout calculations should be re-done, when More Info button is enabled
104 m_aMoreInfoBtn.Hide();
106 // recalculate the size and position of the buttons
107 nTxtW = m_aKeepCurrentBtn.GetCtrlTextWidth( m_aKeepCurrentBtn.GetText() );
108 nTxtW += nExtraButtonWidth;
109 Size aNewSize = m_aKeepCurrentBtn.GetSizePixel();
110 aNewSize.Width() = nTxtW;
111 m_aKeepCurrentBtn.SetSizePixel( aNewSize );
112 Point aPos = m_aSaveODFBtn.GetPosPixel();
113 aPos.X() = nAwCol2 + nTxtW + nExtraButtonWidth;
114 m_aSaveODFBtn.SetPosPixel( aPos );
115 nTxtW = m_aSaveODFBtn.GetCtrlTextWidth( m_aSaveODFBtn.GetText() );
116 nTxtW += nExtraButtonWidth;
117 aNewSize = m_aSaveODFBtn.GetSizePixel();
118 aNewSize.Width() = nTxtW;
119 m_aSaveODFBtn.SetSizePixel( aNewSize );
120 long nBtnsWidthSize = m_aKeepCurrentBtn.GetSizePixel().Width() + m_aSaveODFBtn.GetSizePixel().Width() + nAwCol2 + 2*nExtraButtonWidth;
122 // resize + text of checkbox too wide -> add new line
123 aNewSize = m_aWarningOnBox.GetSizePixel();
124 aNewSize.Width() = nBtnsWidthSize - 2*nExtraButtonWidth;
125 m_aWarningOnBox.SetSizePixel( aNewSize );
126 nTxtW = m_aWarningOnBox.GetCtrlTextWidth( m_aWarningOnBox.GetText() );
127 nCtrlW = m_aWarningOnBox.GetSizePixel().Width();
128 if ( nTxtW >= nCtrlW )
130 long nTextHeight = m_aWarningOnBox.GetTextHeight();
131 aNewSize.Height() += nTextHeight;
132 m_aWarningOnBox.SetSizePixel( aNewSize );
133 aNewSize = GetSizePixel();
134 aNewSize.Height() += nTextHeight;
135 SetSizePixel( aNewSize );
138 // resize + align the size of the information text control (FixedText) to its content
139 aNewSize = m_aInfoText.GetSizePixel();
140 aNewSize.Width() = nBtnsWidthSize - 2*nExtraButtonWidth;
141 m_aInfoText.SetSizePixel( aNewSize );
142 Size aMinSize = m_aInfoText.CalcMinimumSize( m_aInfoText.GetSizePixel().Width() );
143 long nTxtH = aMinSize.Height();
144 long nCtrlH = m_aInfoText.GetSizePixel().Height();
145 long nDelta = ( nCtrlH - nTxtH );
146 aNewSize.Height() -= nDelta;
147 m_aInfoText.SetSizePixel( aNewSize );
150 // new position for the succeeding windows
151 Window* pWins[] =
153 &m_aSaveODFBtn, &m_aKeepCurrentBtn, &m_aMoreInfoBtn, &m_aOptionLine, &m_aWarningOnBox
155 Window** pCurrent = pWins;
156 for ( sal_uInt32 i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
158 Point aNewPos = (*pCurrent)->GetPosPixel();
159 aNewPos.Y() -= nDelta;
160 (*pCurrent)->SetPosPixel( aNewPos );
163 // new size of the dialog
164 aNewSize = GetSizePixel();
165 aNewSize.Height() -= nDelta;
166 aNewSize.Width() = nBtnsWidthSize;
167 SetSizePixel( aNewSize );
169 // resize the FixedLine
170 aNewSize = m_aOptionLine.GetSizePixel();
171 aNewSize.Width() = GetSizePixel().Width();
172 m_aOptionLine.SetSizePixel( aNewSize );
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */