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