LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/fldui - inpdlg.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 70 0.0 %
Date: 2012-12-27 Functions: 0 7 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             : #include <comphelper/string.hxx>
      21             : #include <vcl/msgbox.hxx>
      22             : #include <unotools/charclass.hxx>
      23             : #include <editeng/unolingu.hxx>
      24             : #include <wrtsh.hxx>
      25             : #include <fldbas.hxx>
      26             : #include <expfld.hxx>
      27             : #include <usrfld.hxx>
      28             : #include <inpdlg.hxx>
      29             : #include <fldmgr.hxx>
      30             : 
      31             : #include <fldui.hrc>
      32             : #include <inpdlg.hrc>
      33             : 
      34             : 
      35             : /*--------------------------------------------------------------------
      36             :     Description: edit field-insert
      37             :  --------------------------------------------------------------------*/
      38             : 
      39           0 : SwFldInputDlg::SwFldInputDlg( Window *pParent, SwWrtShell &rS,
      40             :                               SwField* pField, sal_Bool bNextButton ) :
      41             : 
      42             :     SvxStandardDialog(pParent,  SW_RES(DLG_FLD_INPUT)),
      43             : 
      44             :     rSh( rS ),
      45             :     pInpFld(0),
      46             :     pSetFld(0),
      47             :     pUsrType(0),
      48             : 
      49             :     aLabelED    (this, SW_RES(ED_LABEL  )),
      50             :     aEditED     (this, SW_RES(ED_EDIT   )),
      51             :     aEditFL     (this, SW_RES(FL_EDIT       )),
      52             : 
      53             :     aOKBT       (this, SW_RES(BT_OK     )),
      54             :     aCancelBT   (this, SW_RES(BT_CANCEL )),
      55             :     aNextBT     (this, SW_RES(PB_NEXT   )),
      56           0 :     aHelpBT     (this, SW_RES(PB_HELP    ))
      57             : {
      58             :     // switch font for Edit
      59           0 :     Font aFont(aEditED.GetFont());
      60           0 :     aFont.SetWeight(WEIGHT_LIGHT);
      61           0 :     aEditED.SetFont(aFont);
      62             : 
      63           0 :     if( bNextButton )
      64             :     {
      65           0 :         aNextBT.Show();
      66           0 :         aNextBT.SetClickHdl(LINK(this, SwFldInputDlg, NextHdl));
      67             :     }
      68             :     else
      69             :     {
      70           0 :         long nDiff = aCancelBT.GetPosPixel().Y() - aOKBT.GetPosPixel().Y();
      71           0 :         Point aPos = aHelpBT.GetPosPixel();
      72           0 :         aPos.Y() -= nDiff;
      73           0 :         aHelpBT.SetPosPixel(aPos);
      74             :     }
      75             : 
      76             :     // evaluation here
      77           0 :     String aStr;
      78           0 :     if( RES_INPUTFLD == pField->GetTyp()->Which() )
      79             :     {   // it is an input field
      80             :         //
      81           0 :         pInpFld = (SwInputField*)pField;
      82           0 :         aLabelED.SetText( pInpFld->GetPar2() );
      83           0 :         sal_uInt16 nSubType = pInpFld->GetSubType();
      84             : 
      85           0 :         switch(nSubType & 0xff)
      86             :         {
      87             :             case INP_TXT:
      88           0 :                 aStr = pInpFld->GetPar1();
      89           0 :                 break;
      90             : 
      91             :             case INP_USR:
      92             :                 // user field
      93           0 :                 if( 0 != ( pUsrType = (SwUserFieldType*)rSh.GetFldType(
      94           0 :                             RES_USERFLD, pInpFld->GetPar1() ) ) )
      95           0 :                     aStr = pUsrType->GetContent();
      96           0 :                 break;
      97             :         }
      98             :     }
      99             :     else
     100             :     {
     101             :         // it is a SetExpression
     102           0 :         pSetFld = (SwSetExpField*)pField;
     103           0 :         String sFormula(pSetFld->GetFormula());
     104             :         //values are formatted - formulas are not
     105           0 :         CharClass aCC( LanguageTag( pSetFld->GetLanguage() ));
     106           0 :         if( aCC.isNumeric( sFormula ))
     107             :         {
     108           0 :             aStr = pSetFld->ExpandField(true);
     109             :         }
     110             :         else
     111           0 :             aStr = sFormula;
     112           0 :         aLabelED.SetText( pSetFld->GetPromptText() );
     113             :     }
     114             : 
     115             :     // JP 31.3.00: Inputfields in readonly regions must be allowed to
     116             :     //              input any content. - 74639
     117           0 :     sal_Bool bEnable = !rSh.IsCrsrReadonly();
     118             : 
     119           0 :     aOKBT.Enable( bEnable );
     120           0 :     aEditED.SetReadOnly( !bEnable );
     121             : 
     122           0 :     if( aStr.Len() )
     123           0 :         aEditED.SetText(convertLineEnd(aStr, GetSystemLineEnd()));
     124           0 :     FreeResource();
     125           0 : }
     126             : 
     127           0 : SwFldInputDlg::~SwFldInputDlg()
     128             : {
     129           0 : }
     130             : 
     131           0 : void SwFldInputDlg::StateChanged( StateChangedType nType )
     132             : {
     133           0 :     if ( nType == STATE_CHANGE_INITSHOW )
     134           0 :         aEditED.GrabFocus();
     135           0 :     SvxStandardDialog::StateChanged( nType );
     136           0 : }
     137             : 
     138             : /*--------------------------------------------------------------------
     139             :      Description:   Close
     140             :  --------------------------------------------------------------------*/
     141             : 
     142           0 : void SwFldInputDlg::Apply()
     143             : {
     144           0 :     rtl::OUString aTmp(comphelper::string::remove(aEditED.GetText(), '\r'));
     145             : 
     146           0 :     rSh.StartAllAction();
     147           0 :     sal_Bool bModified = sal_False;
     148           0 :     if(pInpFld)
     149             :     {
     150           0 :         if(pUsrType)
     151             :         {
     152           0 :             if( !aTmp.equals(pUsrType->GetContent()) )
     153             :             {
     154           0 :                 pUsrType->SetContent(aTmp);
     155           0 :                 pUsrType->UpdateFlds();
     156           0 :                 bModified = sal_True;
     157             :             }
     158             :         }
     159           0 :         else if( !aTmp.equals(pInpFld->GetPar1()) )
     160             :         {
     161           0 :             pInpFld->SetPar1(aTmp);
     162           0 :             rSh.SwEditShell::UpdateFlds(*pInpFld);
     163           0 :             bModified = sal_True;
     164             :         }
     165             :     }
     166           0 :     else if( !aTmp.equals(pSetFld->GetPar2()) )
     167             :     {
     168           0 :         pSetFld->SetPar2(aTmp);
     169           0 :         rSh.SwEditShell::UpdateFlds(*pSetFld);
     170           0 :         bModified = sal_True;
     171             :     }
     172             : 
     173           0 :     if( bModified )
     174           0 :         rSh.SetUndoNoResetModified();
     175             : 
     176           0 :     rSh.EndAllAction();
     177           0 : }
     178             : 
     179             : 
     180           0 : IMPL_LINK_NOARG(SwFldInputDlg, NextHdl)
     181             : {
     182           0 :     EndDialog(RET_OK);
     183           0 :     return 0;
     184             : }
     185             : 
     186             : 
     187             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10