LCOV - code coverage report
Current view: top level - libreoffice/sfx2/source/dialog - alienwarn.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 73 0.0 %
Date: 2012-12-27 Functions: 0 4 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include <sal/macros.h>
      22             : #include "alienwarn.hxx"
      23             : #include "sfx2/sfxresid.hxx"
      24             : #include <sfx2/sfxuno.hxx>
      25             : 
      26             : #include "alienwarn.hrc"
      27             : #include "dialog.hrc"
      28             : #include <vcl/msgbox.hxx>
      29             : #include <unotools/saveopt.hxx>
      30             : 
      31             : // class SfxAlienWarningDialog -------------------------------------------
      32             : 
      33           0 : SfxAlienWarningDialog::SfxAlienWarningDialog( Window* pParent, const String& _rFormatName ) :
      34             : 
      35             :     SfxModalDialog( pParent, SfxResId( RID_DLG_ALIEN_WARNING ) ),
      36             : 
      37             :     m_aKeepCurrentBtn   ( this, SfxResId( PB_NO ) ),
      38             :     m_aSaveODFBtn       ( this, SfxResId( PB_YES ) ),
      39             :     m_aMoreInfoBtn      ( this, SfxResId( PB_MOREINFO ) ),
      40             :     m_aOptionLine       ( this, SfxResId( FL_OPTION ) ),
      41             :     m_aWarningOnBox     ( this, SfxResId( CB_WARNING_OFF ) ),
      42             :     m_aQueryImage       ( this, SfxResId( FI_QUERY ) ),
      43           0 :     m_aInfoText         ( this, SfxResId( FT_INFOTEXT ) )
      44             : 
      45             : {
      46           0 :     FreeResource();
      47             : 
      48             :     // set questionmark image
      49           0 :     m_aQueryImage.SetImage( QueryBox::GetStandardImage() );
      50             : 
      51             :     // replace formatname (text)
      52           0 :     String sInfoText = m_aInfoText.GetText();
      53           0 :     sInfoText.SearchAndReplaceAll( DEFINE_CONST_UNICODE("%FORMATNAME"), _rFormatName );
      54           0 :     m_aInfoText.SetText( sInfoText );
      55             : 
      56             :     // replace formatname (button)
      57           0 :     sInfoText = m_aKeepCurrentBtn.GetText();
      58           0 :     sInfoText.SearchAndReplaceAll( DEFINE_CONST_UNICODE("%FORMATNAME"), _rFormatName );
      59           0 :     m_aKeepCurrentBtn.SetText( sInfoText );
      60             : 
      61             :     // load value of "warning on" checkbox from save options
      62           0 :     m_aWarningOnBox.Check( SvtSaveOptions().IsWarnAlienFormat() == sal_True );
      63             : 
      64             :     // set focus to "Keep Current Format" button
      65           0 :     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           0 :     InitSize();
      73           0 : }
      74             : 
      75             : // -----------------------------------------------------------------------
      76             : 
      77           0 : SfxAlienWarningDialog::~SfxAlienWarningDialog()
      78             : {
      79             :     // save value of "warning off" checkbox, if necessary
      80           0 :     SvtSaveOptions aSaveOpt;
      81           0 :     sal_Bool bChecked = m_aWarningOnBox.IsChecked();
      82           0 :     if ( aSaveOpt.IsWarnAlienFormat() != bChecked )
      83           0 :         aSaveOpt.SetWarnAlienFormat( bChecked );
      84           0 : }
      85             : 
      86             : // -----------------------------------------------------------------------
      87             : 
      88           0 : void SfxAlienWarningDialog::InitSize()
      89             : {
      90           0 :     const long nExtraButtonWidth = LogicToPixel( Size(IMPL_EXTRA_BUTTON_WIDTH,1), MapMode(MAP_APPFONT) ).getWidth();
      91           0 :     const long nAwCol2 = LogicToPixel( Size(AW_COL_2,1), MapMode(MAP_APPFONT) ).getWidth();
      92             :     long nTxtW, nCtrlW;
      93             : 
      94             :     // layout calculations should be re-done, when More Info button is enabled
      95           0 :     m_aMoreInfoBtn.Hide();
      96             : 
      97             :     // recalculate the size and position of the buttons
      98           0 :     nTxtW = m_aKeepCurrentBtn.GetCtrlTextWidth( m_aKeepCurrentBtn.GetText() );
      99           0 :     nTxtW += nExtraButtonWidth;
     100           0 :     Size aNewSize = m_aKeepCurrentBtn.GetSizePixel();
     101           0 :     aNewSize.Width() = nTxtW;
     102           0 :     m_aKeepCurrentBtn.SetSizePixel( aNewSize );
     103           0 :     Point aPos = m_aSaveODFBtn.GetPosPixel();
     104           0 :     aPos.X() = nAwCol2 + nTxtW + nExtraButtonWidth;
     105           0 :     m_aSaveODFBtn.SetPosPixel( aPos );
     106           0 :     nTxtW = m_aSaveODFBtn.GetCtrlTextWidth( m_aSaveODFBtn.GetText() );
     107           0 :     nTxtW += nExtraButtonWidth;
     108           0 :     aNewSize = m_aSaveODFBtn.GetSizePixel();
     109           0 :     aNewSize.Width() = nTxtW;
     110           0 :     m_aSaveODFBtn.SetSizePixel( aNewSize );
     111           0 :     long nBtnsWidthSize = m_aKeepCurrentBtn.GetSizePixel().Width() + m_aSaveODFBtn.GetSizePixel().Width() + nAwCol2 + 2*nExtraButtonWidth;
     112             : 
     113             :     // resize + text of checkbox too wide -> add new line
     114           0 :     aNewSize = m_aWarningOnBox.GetSizePixel();
     115           0 :     aNewSize.Width() = nBtnsWidthSize - 2*nExtraButtonWidth;
     116           0 :     m_aWarningOnBox.SetSizePixel( aNewSize );
     117           0 :     nTxtW = m_aWarningOnBox.GetCtrlTextWidth( m_aWarningOnBox.GetText() );
     118           0 :     nCtrlW = m_aWarningOnBox.GetSizePixel().Width();
     119           0 :     if ( nTxtW >= nCtrlW )
     120             :     {
     121           0 :         long nTextHeight = m_aWarningOnBox.GetTextHeight();
     122           0 :         aNewSize.Height() += nTextHeight;
     123           0 :         m_aWarningOnBox.SetSizePixel( aNewSize );
     124           0 :         aNewSize = GetSizePixel();
     125           0 :         aNewSize.Height() += nTextHeight;
     126           0 :         SetSizePixel( aNewSize );
     127             :     }
     128             : 
     129             :     // resize + align the size of the information text control (FixedText) to its content
     130           0 :     aNewSize = m_aInfoText.GetSizePixel();
     131           0 :     aNewSize.Width() = nBtnsWidthSize - 2*nExtraButtonWidth;
     132           0 :     m_aInfoText.SetSizePixel( aNewSize );
     133           0 :     Size aMinSize = m_aInfoText.CalcMinimumSize( m_aInfoText.GetSizePixel().Width() );
     134           0 :     long nTxtH = aMinSize.Height();
     135           0 :     long nCtrlH = m_aInfoText.GetSizePixel().Height();
     136           0 :     long nDelta = ( nCtrlH - nTxtH );
     137           0 :     aNewSize.Height() -= nDelta;
     138           0 :     m_aInfoText.SetSizePixel( aNewSize );
     139             : 
     140             : 
     141             :     // new position for the succeeding windows
     142             :     Window* pWins[] =
     143             :     {
     144             :         &m_aSaveODFBtn, &m_aKeepCurrentBtn, &m_aMoreInfoBtn, &m_aOptionLine, &m_aWarningOnBox
     145           0 :     };
     146           0 :     Window** pCurrent = pWins;
     147           0 :     for ( sal_uInt32 i = 0; i < sizeof( pWins ) / sizeof( pWins[ 0 ] ); ++i, ++pCurrent )
     148             :     {
     149           0 :         Point aNewPos = (*pCurrent)->GetPosPixel();
     150           0 :         aNewPos.Y() -= nDelta;
     151           0 :         (*pCurrent)->SetPosPixel( aNewPos );
     152             :     }
     153             : 
     154             :     // new size of the dialog
     155           0 :     aNewSize = GetSizePixel();
     156           0 :     aNewSize.Height() -= nDelta;
     157           0 :     aNewSize.Width() = nBtnsWidthSize;
     158           0 :     SetSizePixel( aNewSize );
     159             : 
     160             :     // resize the FixedLine
     161           0 :     aNewSize = m_aOptionLine.GetSizePixel();
     162           0 :     aNewSize.Width() = GetSizePixel().Width();
     163           0 :     m_aOptionLine.SetSizePixel( aNewSize );
     164             : 
     165           0 : }
     166             : 
     167             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10