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