xref: /AOO41X/main/sfx2/source/dialog/alienwarn.cxx (revision d119d52d53d0b2180f2ae51341d882123be2af2b)
1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "alienwarn.hxx"
28cdf0e10cSrcweir #include "sfx2/sfxresid.hxx"
29cdf0e10cSrcweir #include <sfx2/sfxuno.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "alienwarn.hrc"
32cdf0e10cSrcweir #include "dialog.hrc"
33cdf0e10cSrcweir #include <vcl/msgbox.hxx>
34cdf0e10cSrcweir #include <unotools/saveopt.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // class SfxAlienWarningDialog -------------------------------------------
37cdf0e10cSrcweir 
SfxAlienWarningDialog(Window * pParent,const String & _rFormatName)38cdf0e10cSrcweir SfxAlienWarningDialog::SfxAlienWarningDialog( Window* pParent, const String& _rFormatName ) :
39cdf0e10cSrcweir 
40cdf0e10cSrcweir     SfxModalDialog( pParent, SfxResId( RID_DLG_ALIEN_WARNING ) ),
41cdf0e10cSrcweir 
42cdf0e10cSrcweir     m_aKeepCurrentBtn   ( this, SfxResId( PB_NO ) ),
43cdf0e10cSrcweir     m_aSaveODFBtn       ( this, SfxResId( PB_YES ) ),
44cdf0e10cSrcweir     m_aMoreInfoBtn      ( this, SfxResId( PB_MOREINFO ) ),
45cdf0e10cSrcweir     m_aOptionLine       ( this, SfxResId( FL_OPTION ) ),
46cdf0e10cSrcweir     m_aWarningOnBox     ( this, SfxResId( CB_WARNING_OFF ) ),
47cdf0e10cSrcweir     m_aQueryImage       ( this, SfxResId( FI_QUERY ) ),
48cdf0e10cSrcweir     m_aInfoText         ( this, SfxResId( FT_INFOTEXT ) )
49cdf0e10cSrcweir 
50cdf0e10cSrcweir {
51cdf0e10cSrcweir     FreeResource();
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     // set questionmark image
54cdf0e10cSrcweir     m_aQueryImage.SetImage( QueryBox::GetStandardImage() );
55cdf0e10cSrcweir 
56cdf0e10cSrcweir     // replace formatname
57cdf0e10cSrcweir     String sInfoText = m_aInfoText.GetText();
58cdf0e10cSrcweir     sInfoText.SearchAndReplaceAll( DEFINE_CONST_UNICODE("%FORMATNAME"), _rFormatName );
59cdf0e10cSrcweir     m_aInfoText.SetText( sInfoText );
60cdf0e10cSrcweir 
61cdf0e10cSrcweir     // load value of "warning on" checkbox from save options
62cdf0e10cSrcweir     m_aWarningOnBox.Check( SvtSaveOptions().IsWarnAlienFormat() == sal_True );
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     // set focus to "Keep Current Format" button
65cdf0e10cSrcweir     m_aKeepCurrentBtn.GrabFocus();
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     // pb: #i43989# we have no online help for this dialog at the moment
68cdf0e10cSrcweir     // -> hide the "more info" button
69cdf0e10cSrcweir     //m_aMoreInfoBtn.Hide();
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     // calculate and set the size of the dialog and its controls
72cdf0e10cSrcweir     InitSize();
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir // -----------------------------------------------------------------------
76cdf0e10cSrcweir 
~SfxAlienWarningDialog()77cdf0e10cSrcweir SfxAlienWarningDialog::~SfxAlienWarningDialog()
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     // save value of "warning off" checkbox, if necessary
80cdf0e10cSrcweir     SvtSaveOptions aSaveOpt;
81cdf0e10cSrcweir     sal_Bool bChecked = m_aWarningOnBox.IsChecked();
82cdf0e10cSrcweir     if ( aSaveOpt.IsWarnAlienFormat() != bChecked )
83cdf0e10cSrcweir         aSaveOpt.SetWarnAlienFormat( bChecked );
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir // -----------------------------------------------------------------------
87cdf0e10cSrcweir 
InitSize()88cdf0e10cSrcweir void SfxAlienWarningDialog::InitSize()
89cdf0e10cSrcweir {
90cdf0e10cSrcweir     // if the button text is too wide, then broaden the button
91cdf0e10cSrcweir     long nTxtW = m_aMoreInfoBtn.GetCtrlTextWidth( m_aMoreInfoBtn.GetText() );
92cdf0e10cSrcweir     long nCtrlW = m_aMoreInfoBtn.GetSizePixel().Width();
93cdf0e10cSrcweir     if ( nTxtW >= nCtrlW )
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         long nDelta = nTxtW - nCtrlW;
96cdf0e10cSrcweir         nDelta += IMPL_EXTRA_BUTTON_WIDTH;
97cdf0e10cSrcweir         Point aNextPoint = m_aKeepCurrentBtn.GetPosPixel();
98cdf0e10cSrcweir         aNextPoint.X() += m_aKeepCurrentBtn.GetSizePixel().Width();
99cdf0e10cSrcweir         Point aNewPoint = m_aMoreInfoBtn.GetPosPixel();
100cdf0e10cSrcweir         aNewPoint.X() -= nDelta;
101cdf0e10cSrcweir         if ( aNextPoint.X() >= aNewPoint.X() )
102cdf0e10cSrcweir         {
103cdf0e10cSrcweir             long nSpace = aNextPoint.X() - aNewPoint.X();
104cdf0e10cSrcweir             nSpace += 2;
105cdf0e10cSrcweir             nDelta -= nSpace;
106cdf0e10cSrcweir             aNewPoint.X() += nSpace;
107cdf0e10cSrcweir         }
108cdf0e10cSrcweir         Size aNewSize = m_aMoreInfoBtn.GetSizePixel();
109cdf0e10cSrcweir         aNewSize.Width() += nDelta;
110cdf0e10cSrcweir         m_aMoreInfoBtn.SetPosSizePixel( aNewPoint, aNewSize );
111cdf0e10cSrcweir     }
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     // text of checkbox to wide -> add new line
114cdf0e10cSrcweir     nTxtW = m_aWarningOnBox.GetCtrlTextWidth( m_aWarningOnBox.GetText() ) + IMPL_EXTRA_BUTTON_WIDTH;
115cdf0e10cSrcweir     nCtrlW = m_aWarningOnBox.GetSizePixel().Width();
116cdf0e10cSrcweir     if ( nTxtW >= nCtrlW )
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         long nTextHeight = m_aWarningOnBox.GetTextHeight();
119cdf0e10cSrcweir         Size aNewSize = m_aWarningOnBox.GetSizePixel();
120cdf0e10cSrcweir         aNewSize.Height() += nTextHeight;
121cdf0e10cSrcweir         m_aWarningOnBox.SetSizePixel( aNewSize );
122cdf0e10cSrcweir         aNewSize = GetSizePixel();
123cdf0e10cSrcweir         aNewSize.Height() += nTextHeight;
124cdf0e10cSrcweir         SetSizePixel( aNewSize );
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     // align the size of the information text control (FixedText) to its content
128cdf0e10cSrcweir     Size aMinSize = m_aInfoText.CalcMinimumSize( m_aInfoText.GetSizePixel().Width() );
129cdf0e10cSrcweir     long nTxtH = aMinSize.Height();
130cdf0e10cSrcweir     long nCtrlH = m_aInfoText.GetSizePixel().Height();
131cdf0e10cSrcweir     long nDelta = ( nCtrlH - nTxtH );
132cdf0e10cSrcweir     Size aNewSize = m_aInfoText.GetSizePixel();
133cdf0e10cSrcweir     aNewSize.Height() -= nDelta;
134cdf0e10cSrcweir     m_aInfoText.SetSizePixel( aNewSize );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     // new position for the succeeding windows
137cdf0e10cSrcweir     Window* pWins[] =
138cdf0e10cSrcweir     {
139cdf0e10cSrcweir         &m_aSaveODFBtn, &m_aKeepCurrentBtn, &m_aMoreInfoBtn, &m_aOptionLine, &m_aWarningOnBox
140cdf0e10cSrcweir     };
141cdf0e10cSrcweir     Window** pCurrent = pWins;
142cdf0e10cSrcweir     for ( sal_uInt32 i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
143cdf0e10cSrcweir     {
144cdf0e10cSrcweir         Point aNewPos = (*pCurrent)->GetPosPixel();
145cdf0e10cSrcweir         aNewPos.Y() -= nDelta;
146cdf0e10cSrcweir         (*pCurrent)->SetPosPixel( aNewPos );
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     // new size of the dialog
150cdf0e10cSrcweir     aNewSize = GetSizePixel();
151cdf0e10cSrcweir     aNewSize.Height() -= nDelta;
152cdf0e10cSrcweir     SetSizePixel( aNewSize );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     // recalculate the size and position of the buttons
155cdf0e10cSrcweir     m_aMoreInfoBtn.Hide();
156cdf0e10cSrcweir     nTxtW = m_aKeepCurrentBtn.GetCtrlTextWidth( m_aKeepCurrentBtn.GetText() );
157cdf0e10cSrcweir     long nTemp = m_aSaveODFBtn.GetCtrlTextWidth( m_aSaveODFBtn.GetText() );
158cdf0e10cSrcweir     if ( nTemp > nTxtW )
159cdf0e10cSrcweir         nTxtW = nTemp;
160cdf0e10cSrcweir     nTxtW += IMPL_EXTRA_BUTTON_WIDTH;
161cdf0e10cSrcweir     Size a3Size = LogicToPixel( Size( 3, 3 ), MAP_APPFONT );
162cdf0e10cSrcweir     Point aPos = m_aKeepCurrentBtn.GetPosPixel();
163cdf0e10cSrcweir     aPos.X() = ( aNewSize.Width() - (2*nTxtW) - a3Size.Width() ) / 2;
164cdf0e10cSrcweir     long nDefX = m_aWarningOnBox.GetPosPixel().X();
165cdf0e10cSrcweir     if ( nDefX < aPos.X() )
166cdf0e10cSrcweir         aPos.X() = nDefX;
167cdf0e10cSrcweir     aNewSize = m_aKeepCurrentBtn.GetSizePixel();
168cdf0e10cSrcweir     aNewSize.Width() = nTxtW;
169cdf0e10cSrcweir     m_aKeepCurrentBtn.SetPosSizePixel( aPos, aNewSize );
170cdf0e10cSrcweir     aPos.X() += nTxtW + a3Size.Width();
171cdf0e10cSrcweir     m_aSaveODFBtn.SetPosSizePixel( aPos, aNewSize );
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174