xref: /AOO41X/main/sfx2/source/dialog/alienwarn.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "alienwarn.hxx"
32*cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
33*cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include "alienwarn.hrc"
36*cdf0e10cSrcweir #include "dialog.hrc"
37*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
38*cdf0e10cSrcweir #include <unotools/saveopt.hxx>
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir // class SfxAlienWarningDialog -------------------------------------------
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir SfxAlienWarningDialog::SfxAlienWarningDialog( Window* pParent, const String& _rFormatName ) :
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir     SfxModalDialog( pParent, SfxResId( RID_DLG_ALIEN_WARNING ) ),
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir     m_aKeepCurrentBtn   ( this, SfxResId( PB_NO ) ),
47*cdf0e10cSrcweir     m_aSaveODFBtn       ( this, SfxResId( PB_YES ) ),
48*cdf0e10cSrcweir     m_aMoreInfoBtn      ( this, SfxResId( PB_MOREINFO ) ),
49*cdf0e10cSrcweir     m_aOptionLine       ( this, SfxResId( FL_OPTION ) ),
50*cdf0e10cSrcweir     m_aWarningOnBox     ( this, SfxResId( CB_WARNING_OFF ) ),
51*cdf0e10cSrcweir     m_aQueryImage       ( this, SfxResId( FI_QUERY ) ),
52*cdf0e10cSrcweir     m_aInfoText         ( this, SfxResId( FT_INFOTEXT ) )
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir     FreeResource();
56*cdf0e10cSrcweir 
57*cdf0e10cSrcweir     // set questionmark image
58*cdf0e10cSrcweir     m_aQueryImage.SetImage( QueryBox::GetStandardImage() );
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir     // replace formatname
61*cdf0e10cSrcweir     String sInfoText = m_aInfoText.GetText();
62*cdf0e10cSrcweir     sInfoText.SearchAndReplaceAll( DEFINE_CONST_UNICODE("%FORMATNAME"), _rFormatName );
63*cdf0e10cSrcweir     m_aInfoText.SetText( sInfoText );
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir     // load value of "warning on" checkbox from save options
66*cdf0e10cSrcweir     m_aWarningOnBox.Check( SvtSaveOptions().IsWarnAlienFormat() == sal_True );
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir     // set focus to "Keep Current Format" button
69*cdf0e10cSrcweir     m_aKeepCurrentBtn.GrabFocus();
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     // pb: #i43989# we have no online help for this dialog at the moment
72*cdf0e10cSrcweir     // -> hide the "more info" button
73*cdf0e10cSrcweir     //m_aMoreInfoBtn.Hide();
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir     // calculate and set the size of the dialog and its controls
76*cdf0e10cSrcweir     InitSize();
77*cdf0e10cSrcweir }
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir // -----------------------------------------------------------------------
80*cdf0e10cSrcweir 
81*cdf0e10cSrcweir SfxAlienWarningDialog::~SfxAlienWarningDialog()
82*cdf0e10cSrcweir {
83*cdf0e10cSrcweir     // save value of "warning off" checkbox, if necessary
84*cdf0e10cSrcweir     SvtSaveOptions aSaveOpt;
85*cdf0e10cSrcweir     sal_Bool bChecked = m_aWarningOnBox.IsChecked();
86*cdf0e10cSrcweir     if ( aSaveOpt.IsWarnAlienFormat() != bChecked )
87*cdf0e10cSrcweir         aSaveOpt.SetWarnAlienFormat( bChecked );
88*cdf0e10cSrcweir }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir // -----------------------------------------------------------------------
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir void SfxAlienWarningDialog::InitSize()
93*cdf0e10cSrcweir {
94*cdf0e10cSrcweir     // if the button text is too wide, then broaden the button
95*cdf0e10cSrcweir     long nTxtW = m_aMoreInfoBtn.GetCtrlTextWidth( m_aMoreInfoBtn.GetText() );
96*cdf0e10cSrcweir     long nCtrlW = m_aMoreInfoBtn.GetSizePixel().Width();
97*cdf0e10cSrcweir     if ( nTxtW >= nCtrlW )
98*cdf0e10cSrcweir     {
99*cdf0e10cSrcweir         long nDelta = nTxtW - nCtrlW;
100*cdf0e10cSrcweir         nDelta += IMPL_EXTRA_BUTTON_WIDTH;
101*cdf0e10cSrcweir         Point aNextPoint = m_aKeepCurrentBtn.GetPosPixel();
102*cdf0e10cSrcweir         aNextPoint.X() += m_aKeepCurrentBtn.GetSizePixel().Width();
103*cdf0e10cSrcweir         Point aNewPoint = m_aMoreInfoBtn.GetPosPixel();
104*cdf0e10cSrcweir         aNewPoint.X() -= nDelta;
105*cdf0e10cSrcweir         if ( aNextPoint.X() >= aNewPoint.X() )
106*cdf0e10cSrcweir         {
107*cdf0e10cSrcweir             long nSpace = aNextPoint.X() - aNewPoint.X();
108*cdf0e10cSrcweir             nSpace += 2;
109*cdf0e10cSrcweir             nDelta -= nSpace;
110*cdf0e10cSrcweir             aNewPoint.X() += nSpace;
111*cdf0e10cSrcweir         }
112*cdf0e10cSrcweir         Size aNewSize = m_aMoreInfoBtn.GetSizePixel();
113*cdf0e10cSrcweir         aNewSize.Width() += nDelta;
114*cdf0e10cSrcweir         m_aMoreInfoBtn.SetPosSizePixel( aNewPoint, aNewSize );
115*cdf0e10cSrcweir     }
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir     // text of checkbox to wide -> add new line
118*cdf0e10cSrcweir     nTxtW = m_aWarningOnBox.GetCtrlTextWidth( m_aWarningOnBox.GetText() ) + IMPL_EXTRA_BUTTON_WIDTH;
119*cdf0e10cSrcweir     nCtrlW = m_aWarningOnBox.GetSizePixel().Width();
120*cdf0e10cSrcweir     if ( nTxtW >= nCtrlW )
121*cdf0e10cSrcweir     {
122*cdf0e10cSrcweir         long nTextHeight = m_aWarningOnBox.GetTextHeight();
123*cdf0e10cSrcweir         Size aNewSize = m_aWarningOnBox.GetSizePixel();
124*cdf0e10cSrcweir         aNewSize.Height() += nTextHeight;
125*cdf0e10cSrcweir         m_aWarningOnBox.SetSizePixel( aNewSize );
126*cdf0e10cSrcweir         aNewSize = GetSizePixel();
127*cdf0e10cSrcweir         aNewSize.Height() += nTextHeight;
128*cdf0e10cSrcweir         SetSizePixel( aNewSize );
129*cdf0e10cSrcweir     }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     // align the size of the information text control (FixedText) to its content
132*cdf0e10cSrcweir     Size aMinSize = m_aInfoText.CalcMinimumSize( m_aInfoText.GetSizePixel().Width() );
133*cdf0e10cSrcweir     long nTxtH = aMinSize.Height();
134*cdf0e10cSrcweir     long nCtrlH = m_aInfoText.GetSizePixel().Height();
135*cdf0e10cSrcweir     long nDelta = ( nCtrlH - nTxtH );
136*cdf0e10cSrcweir     Size aNewSize = m_aInfoText.GetSizePixel();
137*cdf0e10cSrcweir     aNewSize.Height() -= nDelta;
138*cdf0e10cSrcweir     m_aInfoText.SetSizePixel( aNewSize );
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir     // new position for the succeeding windows
141*cdf0e10cSrcweir     Window* pWins[] =
142*cdf0e10cSrcweir     {
143*cdf0e10cSrcweir         &m_aSaveODFBtn, &m_aKeepCurrentBtn, &m_aMoreInfoBtn, &m_aOptionLine, &m_aWarningOnBox
144*cdf0e10cSrcweir     };
145*cdf0e10cSrcweir     Window** pCurrent = pWins;
146*cdf0e10cSrcweir     for ( sal_uInt32 i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
147*cdf0e10cSrcweir     {
148*cdf0e10cSrcweir         Point aNewPos = (*pCurrent)->GetPosPixel();
149*cdf0e10cSrcweir         aNewPos.Y() -= nDelta;
150*cdf0e10cSrcweir         (*pCurrent)->SetPosPixel( aNewPos );
151*cdf0e10cSrcweir     }
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir     // new size of the dialog
154*cdf0e10cSrcweir     aNewSize = GetSizePixel();
155*cdf0e10cSrcweir     aNewSize.Height() -= nDelta;
156*cdf0e10cSrcweir     SetSizePixel( aNewSize );
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     // recalculate the size and position of the buttons
159*cdf0e10cSrcweir     m_aMoreInfoBtn.Hide();
160*cdf0e10cSrcweir     nTxtW = m_aKeepCurrentBtn.GetCtrlTextWidth( m_aKeepCurrentBtn.GetText() );
161*cdf0e10cSrcweir     long nTemp = m_aSaveODFBtn.GetCtrlTextWidth( m_aSaveODFBtn.GetText() );
162*cdf0e10cSrcweir     if ( nTemp > nTxtW )
163*cdf0e10cSrcweir         nTxtW = nTemp;
164*cdf0e10cSrcweir     nTxtW += IMPL_EXTRA_BUTTON_WIDTH;
165*cdf0e10cSrcweir     Size a3Size = LogicToPixel( Size( 3, 3 ), MAP_APPFONT );
166*cdf0e10cSrcweir     Point aPos = m_aKeepCurrentBtn.GetPosPixel();
167*cdf0e10cSrcweir     aPos.X() = ( aNewSize.Width() - (2*nTxtW) - a3Size.Width() ) / 2;
168*cdf0e10cSrcweir     long nDefX = m_aWarningOnBox.GetPosPixel().X();
169*cdf0e10cSrcweir     if ( nDefX < aPos.X() )
170*cdf0e10cSrcweir         aPos.X() = nDefX;
171*cdf0e10cSrcweir     aNewSize = m_aKeepCurrentBtn.GetSizePixel();
172*cdf0e10cSrcweir     aNewSize.Width() = nTxtW;
173*cdf0e10cSrcweir     m_aKeepCurrentBtn.SetPosSizePixel( aPos, aNewSize );
174*cdf0e10cSrcweir     aPos.X() += nTxtW + a3Size.Width();
175*cdf0e10cSrcweir     m_aSaveODFBtn.SetPosSizePixel( aPos, aNewSize );
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178