update dev300-m58
[ooovba.git] / svx / source / dialog / linkwarn.cxx
blobf6059d910e15aa40d46c11bdb3632405f57fd322
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: linkwarn.cxx,v $
7 * $Revision: $
9 * last change: $Author: $ $Date: $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_svx.hxx"
39 #include "linkwarn.hrc"
40 #include "svx/linkwarn.hxx"
41 #include "svx/dialogs.hrc"
42 #include "svx/dialmgr.hxx"
43 #include <vcl/msgbox.hxx>
44 #include <sfx2/basedlgs.hxx>
45 #include <svtools/miscopt.hxx>
47 SvxLinkWarningDialog::SvxLinkWarningDialog( Window* pParent, const String& _rFileName ) :
48 SfxModalDialog( pParent, SVX_RES( RID_SVXDLG_LINK_WARNING ) ),
49 m_aQueryImage ( this, SVX_RES( FI_QUERY ) ),
50 m_aInfoText ( this, SVX_RES( FT_INFOTEXT ) ),
51 m_aLinkGraphicBtn ( this, SVX_RES( PB_OK ) ),
52 m_aEmbedGraphicBtn ( this, SVX_RES( PB_NO ) ),
53 m_aOptionLine ( this, SVX_RES( FL_OPTION ) ),
54 m_aWarningOnBox ( this, SVX_RES( CB_WARNING_OFF ) )
56 FreeResource();
58 // set questionmark image
59 m_aQueryImage.SetImage( QueryBox::GetStandardImage() );
61 // replace filename
62 String sInfoText = m_aInfoText.GetText();
63 sInfoText.SearchAndReplaceAll(
64 UniString::CreateFromAscii(
65 RTL_CONSTASCII_STRINGPARAM( "%FILENAME" ) ), _rFileName );
66 m_aInfoText.SetText( sInfoText );
68 // load state of "warning on" checkbox from misc options
69 SvtMiscOptions aMiscOpt;
70 m_aWarningOnBox.Check( aMiscOpt.ShowLinkWarningDialog() == sal_True );
71 if( aMiscOpt.IsShowLinkWarningDialogReadOnly() )
72 m_aWarningOnBox.Disable();
74 // set focus to Cancel button
75 m_aEmbedGraphicBtn.GrabFocus();
77 // calculate and set the size of the dialog and its controls
78 InitSize();
81 // -----------------------------------------------------------------------
83 SvxLinkWarningDialog::~SvxLinkWarningDialog()
85 // save value of "warning off" checkbox, if necessary
86 SvtMiscOptions aMiscOpt;
87 sal_Bool bChecked = m_aWarningOnBox.IsChecked();
88 if ( aMiscOpt.ShowLinkWarningDialog() != bChecked )
89 aMiscOpt.SetShowLinkWarningDialog( bChecked );
92 // -----------------------------------------------------------------------
94 void SvxLinkWarningDialog::InitSize()
96 // text of checkbox to wide -> add new line
97 long nTxtW = m_aWarningOnBox.GetCtrlTextWidth( m_aWarningOnBox.GetText() ) + IMPL_EXTRA_BUTTON_WIDTH;
98 long nCtrlW = m_aWarningOnBox.GetSizePixel().Width();
99 if ( nTxtW >= nCtrlW )
101 long nTextHeight = m_aWarningOnBox.GetTextHeight();
102 Size aNewSize = m_aWarningOnBox.GetSizePixel();
103 aNewSize.Height() += nTextHeight;
104 m_aWarningOnBox.SetSizePixel( aNewSize );
105 aNewSize = GetSizePixel();
106 aNewSize.Height() += nTextHeight;
107 SetSizePixel( aNewSize );
110 // align the size of the information text control (FixedText) to its content
111 Size aMinSize = m_aInfoText.CalcMinimumSize( m_aInfoText.GetSizePixel().Width() );
112 long nTxtH = aMinSize.Height();
113 long nCtrlH = m_aInfoText.GetSizePixel().Height();
114 long nDelta = ( nCtrlH - nTxtH );
115 Size aNewSize = m_aInfoText.GetSizePixel();
116 aNewSize.Height() -= nDelta;
117 m_aInfoText.SetSizePixel( aNewSize );
119 // new position for the succeeding windows
120 Window* pWins[] =
122 &m_aLinkGraphicBtn, &m_aEmbedGraphicBtn, &m_aOptionLine, &m_aWarningOnBox
124 Window** pCurrent = pWins;
125 for ( sal_uInt32 i = 0; i < sizeof(pWins) / sizeof(*pWins); ++i, ++pCurrent )
127 Point aNewPos = (*pCurrent)->GetPosPixel();
128 aNewPos.Y() -= nDelta;
129 (*pCurrent)->SetPosPixel( aNewPos );
132 // new size of the dialog
133 aNewSize = GetSizePixel();
134 aNewSize.Height() -= nDelta;
135 SetSizePixel( aNewSize );
137 // recalculate the size and position of the buttons
138 nTxtW = m_aLinkGraphicBtn.GetCtrlTextWidth( m_aLinkGraphicBtn.GetText() );
139 long nTemp = m_aEmbedGraphicBtn.GetCtrlTextWidth( m_aEmbedGraphicBtn.GetText() );
140 if ( nTemp > nTxtW )
141 nTxtW = nTemp;
142 nTxtW += IMPL_EXTRA_BUTTON_WIDTH;
143 Size a3Size = LogicToPixel( Size( 3, 3 ), MAP_APPFONT );
144 Point aPos = m_aLinkGraphicBtn.GetPosPixel();
145 aPos.X() = ( aNewSize.Width() - (2*nTxtW) - a3Size.Width() ) / 2;
146 long nDefX = m_aWarningOnBox.GetPosPixel().X();
147 if ( nDefX < aPos.X() )
148 aPos.X() = nDefX;
149 aNewSize = m_aLinkGraphicBtn.GetSizePixel();
150 aNewSize.Width() = nTxtW;
151 m_aLinkGraphicBtn.SetPosSizePixel( aPos, aNewSize );
152 aPos.X() += nTxtW + a3Size.Width();
153 m_aEmbedGraphicBtn.SetPosSizePixel( aPos, aNewSize );