1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "linkwarn.hrc"
21 #include "svx/linkwarn.hxx"
22 #include "svx/dialogs.hrc"
23 #include "svx/dialmgr.hxx"
24 #include <vcl/msgbox.hxx>
25 #include <sfx2/basedlgs.hxx>
26 #include <svtools/miscopt.hxx>
28 SvxLinkWarningDialog::SvxLinkWarningDialog( Window
* pParent
, const String
& _rFileName
) :
29 SfxModalDialog( pParent
, SVX_RES( RID_SVXDLG_LINK_WARNING
) ),
30 m_aQueryImage ( this, SVX_RES( FI_QUERY
) ),
31 m_aInfoText ( this, SVX_RES( FT_INFOTEXT
) ),
32 m_aLinkGraphicBtn ( this, SVX_RES( PB_OK
) ),
33 m_aEmbedGraphicBtn ( this, SVX_RES( PB_NO
) ),
34 m_aOptionLine ( this, SVX_RES( FL_OPTION
) ),
35 m_aWarningOnBox ( this, SVX_RES( CB_WARNING_OFF
) )
39 // set questionmark image
40 m_aQueryImage
.SetImage( QueryBox::GetStandardImage() );
43 String sInfoText
= m_aInfoText
.GetText();
44 sInfoText
.SearchAndReplaceAll(OUString("%FILENAME"), _rFileName
);
45 m_aInfoText
.SetText( sInfoText
);
47 // load state of "warning on" checkbox from misc options
48 SvtMiscOptions aMiscOpt
;
49 m_aWarningOnBox
.Check( aMiscOpt
.ShowLinkWarningDialog() == sal_True
);
50 if( aMiscOpt
.IsShowLinkWarningDialogReadOnly() )
51 m_aWarningOnBox
.Disable();
53 // set focus to Cancel button
54 m_aEmbedGraphicBtn
.GrabFocus();
56 // calculate and set the size of the dialog and its controls
60 // -----------------------------------------------------------------------
62 SvxLinkWarningDialog::~SvxLinkWarningDialog()
64 // save value of "warning off" checkbox, if necessary
65 SvtMiscOptions aMiscOpt
;
66 sal_Bool bChecked
= m_aWarningOnBox
.IsChecked();
67 if ( aMiscOpt
.ShowLinkWarningDialog() != bChecked
)
68 aMiscOpt
.SetShowLinkWarningDialog( bChecked
);
71 // -----------------------------------------------------------------------
73 void SvxLinkWarningDialog::InitSize()
75 // text of checkbox to wide -> add new line
76 long nTxtW
= m_aWarningOnBox
.GetCtrlTextWidth( m_aWarningOnBox
.GetText() ) + IMPL_EXTRA_BUTTON_WIDTH
;
77 long nCtrlW
= m_aWarningOnBox
.GetSizePixel().Width();
78 if ( nTxtW
>= nCtrlW
)
80 long nTextHeight
= m_aWarningOnBox
.GetTextHeight();
81 Size aNewSize
= m_aWarningOnBox
.GetSizePixel();
82 aNewSize
.Height() += nTextHeight
;
83 m_aWarningOnBox
.SetSizePixel( aNewSize
);
84 aNewSize
= GetSizePixel();
85 aNewSize
.Height() += nTextHeight
;
86 SetSizePixel( aNewSize
);
89 // align the size of the information text control (FixedText) to its content
90 Size aMinSize
= m_aInfoText
.CalcMinimumSize( m_aInfoText
.GetSizePixel().Width() );
91 long nTxtH
= aMinSize
.Height();
92 long nCtrlH
= m_aInfoText
.GetSizePixel().Height();
93 long nDelta
= ( nCtrlH
- nTxtH
);
94 Size aNewSize
= m_aInfoText
.GetSizePixel();
95 aNewSize
.Height() -= nDelta
;
96 m_aInfoText
.SetSizePixel( aNewSize
);
98 // new position for the succeeding windows
101 &m_aLinkGraphicBtn
, &m_aEmbedGraphicBtn
, &m_aOptionLine
, &m_aWarningOnBox
103 Window
** pCurrent
= pWins
;
104 for ( sal_uInt32 i
= 0; i
< SAL_N_ELEMENTS(pWins
); ++i
, ++pCurrent
)
106 Point aNewPos
= (*pCurrent
)->GetPosPixel();
107 aNewPos
.Y() -= nDelta
;
108 (*pCurrent
)->SetPosPixel( aNewPos
);
111 // new size of the dialog
112 aNewSize
= GetSizePixel();
113 aNewSize
.Height() -= nDelta
;
114 SetSizePixel( aNewSize
);
116 // recalculate the size and position of the buttons
117 nTxtW
= m_aLinkGraphicBtn
.GetCtrlTextWidth( m_aLinkGraphicBtn
.GetText() );
118 long nTemp
= m_aEmbedGraphicBtn
.GetCtrlTextWidth( m_aEmbedGraphicBtn
.GetText() );
121 nTxtW
+= IMPL_EXTRA_BUTTON_WIDTH
;
122 Size a3Size
= LogicToPixel( Size( 3, 3 ), MAP_APPFONT
);
123 Point aPos
= m_aLinkGraphicBtn
.GetPosPixel();
124 aPos
.X() = ( aNewSize
.Width() - (2*nTxtW
) - a3Size
.Width() ) / 2;
125 long nDefX
= m_aWarningOnBox
.GetPosPixel().X();
126 if ( nDefX
< aPos
.X() )
128 aNewSize
= m_aLinkGraphicBtn
.GetSizePixel();
129 aNewSize
.Width() = nTxtW
;
130 m_aLinkGraphicBtn
.SetPosSizePixel( aPos
, aNewSize
);
131 aPos
.X() += nTxtW
+ a3Size
.Width();
132 m_aEmbedGraphicBtn
.SetPosSizePixel( aPos
, aNewSize
);
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */