LCOV - code coverage report
Current view: top level - sw/source/ui/ribbar - inputwin.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 325 0.3 %
Date: 2012-08-25 Functions: 2 29 6.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 627 0.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "sal/config.h"
      30                 :            : 
      31                 :            : #include <comphelper/string.hxx>
      32                 :            : #include <officecfg/Office/Common.hxx>
      33                 :            : #include <tools/gen.hxx>
      34                 :            : #include <sfx2/imgmgr.hxx>
      35                 :            : #include <sfx2/viewfrm.hxx>
      36                 :            : #include <sfx2/dispatch.hxx>
      37                 :            : #include <svx/ruler.hxx>
      38                 :            : #include <svl/zforlist.hxx>
      39                 :            : #include <svl/stritem.hxx>
      40                 :            : 
      41                 :            : #include "swtypes.hxx"
      42                 :            : #include "cmdid.h"
      43                 :            : #include "swmodule.hxx"
      44                 :            : #include "wrtsh.hxx"
      45                 :            : #include "view.hxx"
      46                 :            : #include "calc.hxx"
      47                 :            : #include "inputwin.hxx"
      48                 :            : #include "fldbas.hxx"
      49                 :            : #include "fldmgr.hxx"
      50                 :            : #include "frmfmt.hxx"
      51                 :            : #include "cellatr.hxx"
      52                 :            : #include "edtwin.hxx"
      53                 :            : #include "helpid.h"
      54                 :            : 
      55                 :            : // nur fuers UpdateRange - Box in dem der gestackte Cursor sthet loeschen
      56                 :            : #include "pam.hxx"
      57                 :            : 
      58                 :            : #include "swundo.hxx"
      59                 :            : #include "ribbar.hrc"
      60                 :            : #include "inputwin.hrc"
      61                 :            : 
      62                 :            : #include <IDocumentContentOperations.hxx>
      63                 :            : 
      64 [ +  - ][ #  # ]:       2535 : SFX_IMPL_POS_CHILDWINDOW_WITHID( SwInputChild, FN_EDIT_FORMULA, SFX_OBJECTBAR_OBJECT )
      65                 :            : 
      66                 :            : //==================================================================
      67                 :            : 
      68                 :          0 : SwInputWindow::SwInputWindow( Window* pParent, SfxBindings* pBind )
      69                 :            :     : ToolBox(  pParent ,   SW_RES( RID_TBX_FORMULA )),
      70                 :            :     aPos(       this,       SW_RES(ED_POS)),
      71                 :            :     aEdit(      this, WB_3DLOOK|WB_TABSTOP|WB_BORDER|WB_NOHIDESELECTION),
      72                 :            :     aPopMenu(   SW_RES(MN_CALC_POPUP)),
      73                 :            :     pMgr(0),
      74                 :            :     pWrtShell(0),
      75                 :            :     pView(0),
      76                 :            :     pBindings(pBind),
      77                 :            :     aAktTableName(aEmptyStr)
      78                 :            :     , m_bDoesUndo(true)
      79                 :            :     , m_bResetUndo(false)
      80 [ #  # ][ #  # ]:          0 :     , m_bCallUndo(false)
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      81                 :            : {
      82                 :          0 :     bFirst = sal_True;
      83                 :          0 :     bActive = bIsTable = bDelSel = sal_False;
      84                 :            : 
      85         [ #  # ]:          0 :     FreeResource();
      86                 :            : 
      87 [ #  # ][ #  # ]:          0 :     aEdit.SetSizePixel( aEdit.CalcMinimumSize() );
      88                 :            : 
      89 [ #  # ][ #  # ]:          0 :     SfxImageManager* pManager = SfxImageManager::GetImageManager( SW_MOD() );
      90         [ #  # ]:          0 :     pManager->RegisterToolBox(this);
      91                 :            : 
      92         [ #  # ]:          0 :     pView = ::GetActiveView();
      93         [ #  # ]:          0 :     pWrtShell = pView ? pView->GetWrtShellPtr() : 0;
      94                 :            : 
      95         [ #  # ]:          0 :     InsertWindow( ED_POS, &aPos, 0, 0);
      96         [ #  # ]:          0 :     InsertSeparator ( 1 );
      97         [ #  # ]:          0 :     InsertSeparator ();
      98         [ #  # ]:          0 :     InsertWindow( ED_FORMULA, &aEdit);
      99         [ #  # ]:          0 :     SetHelpId(ED_FORMULA, HID_EDIT_FORMULA);
     100                 :            : 
     101 [ #  # ][ #  # ]:          0 :     SetItemImage( FN_FORMULA_CALC,   pManager->GetImage(FN_FORMULA_CALC   ));
                 [ #  # ]
     102 [ #  # ][ #  # ]:          0 :     SetItemImage( FN_FORMULA_CANCEL, pManager->GetImage(FN_FORMULA_CANCEL ));
                 [ #  # ]
     103 [ #  # ][ #  # ]:          0 :     SetItemImage( FN_FORMULA_APPLY,  pManager->GetImage(FN_FORMULA_APPLY  ));
                 [ #  # ]
     104                 :            : 
     105 [ #  # ][ #  # ]:          0 :     SetItemBits( FN_FORMULA_CALC, GetItemBits( FN_FORMULA_CALC ) | TIB_DROPDOWNONLY );
     106 [ #  # ][ #  # ]:          0 :     SetDropdownClickHdl( LINK( this, SwInputWindow, DropdownClickHdl ));
     107                 :            : 
     108         [ #  # ]:          0 :     Size    aSizeTbx = CalcWindowSizePixel();
     109         [ #  # ]:          0 :     Size    aEditSize = aEdit.GetSizePixel();
     110         [ #  # ]:          0 :     Rectangle aItemRect( GetItemRect(FN_FORMULA_CALC) );
     111 [ #  # ][ #  # ]:          0 :     long nMaxHeight = (aEditSize.Height() > aItemRect.GetHeight()) ? aEditSize.Height() : aItemRect.GetHeight();
                 [ #  # ]
     112         [ #  # ]:          0 :     if( nMaxHeight+2 > aSizeTbx.Height() )
     113                 :          0 :         aSizeTbx.Height() = nMaxHeight+2;
     114         [ #  # ]:          0 :     Size aSize = GetSizePixel();
     115                 :          0 :     aSize.Height() = aSizeTbx.Height();
     116         [ #  # ]:          0 :     SetSizePixel( aSize );
     117                 :            : 
     118                 :            :     // align edit and item vcentered
     119         [ #  # ]:          0 :     Size    aPosSize = aPos.GetSizePixel();
     120                 :          0 :     aPosSize.Height()  = nMaxHeight;
     121                 :          0 :     aEditSize.Height() = nMaxHeight;
     122         [ #  # ]:          0 :     Point aPosPos  = aPos.GetPosPixel();
     123         [ #  # ]:          0 :     Point aEditPos = aEdit.GetPosPixel();
     124                 :          0 :     aPosPos.Y()    = (aSize.Height() - nMaxHeight)/2 + 1;
     125                 :          0 :     aEditPos.Y()   = (aSize.Height() - nMaxHeight)/2 + 1;
     126         [ #  # ]:          0 :     aPos.SetPosSizePixel( aPosPos, aPosSize );
     127         [ #  # ]:          0 :     aEdit.SetPosSizePixel( aEditPos, aEditSize );
     128                 :            : 
     129         [ #  # ]:          0 :     aPopMenu.SetSelectHdl(LINK( this, SwInputWindow, MenuHdl ));
     130                 :          0 : }
     131                 :            : 
     132                 :            : //==================================================================
     133                 :            : 
     134 [ #  # ][ #  # ]:          0 : SwInputWindow::~SwInputWindow()
         [ #  # ][ #  # ]
                 [ #  # ]
     135                 :            : {
     136 [ #  # ][ #  # ]:          0 :     SfxImageManager::GetImageManager( SW_MOD() )->ReleaseToolBox(this);
                 [ #  # ]
     137                 :            : 
     138                 :            :     //Lineale aufwecken
     139         [ #  # ]:          0 :     if(pView)
     140                 :            :     {
     141         [ #  # ]:          0 :         pView->GetHLineal().SetActive( sal_True );
     142         [ #  # ]:          0 :         pView->GetVLineal().SetActive( sal_True );
     143                 :            :     }
     144 [ #  # ][ #  # ]:          0 :     delete pMgr;
     145         [ #  # ]:          0 :     if(pWrtShell)
     146                 :          0 :         pWrtShell->EndSelTblCells();
     147                 :            : 
     148         [ #  # ]:          0 :     CleanupUglyHackWithUndo();
     149         [ #  # ]:          0 : }
     150                 :            : 
     151                 :          0 : void SwInputWindow::CleanupUglyHackWithUndo()
     152                 :            : {
     153         [ #  # ]:          0 :     if (m_bResetUndo)
     154                 :            :     {
     155                 :          0 :         DelBoxCntnt();
     156                 :          0 :         pWrtShell->DoUndo(m_bDoesUndo);
     157         [ #  # ]:          0 :         if (m_bCallUndo)
     158                 :            :         {
     159                 :          0 :             pWrtShell->Undo();
     160                 :            :         }
     161                 :          0 :         m_bResetUndo = false; // #i117122# once is enough :)
     162                 :            :     }
     163                 :          0 : }
     164                 :            : 
     165                 :            : 
     166                 :            : //==================================================================
     167                 :            : 
     168                 :          0 : void SwInputWindow::DataChanged( const DataChangedEvent& rDCEvt )
     169                 :            : {
     170 [ #  # ][ #  # ]:          0 :     if ( rDCEvt.GetType() == DATACHANGED_SETTINGS && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
                 [ #  # ]
     171                 :            :     {
     172                 :            :         //      update item images
     173                 :          0 :         SwModule *pMod  = SW_MOD();
     174                 :          0 :         SfxImageManager *pImgMgr = SfxImageManager::GetImageManager( pMod );
     175         [ #  # ]:          0 :         SetItemImage( FN_FORMULA_CALC,   pImgMgr->GetImage(FN_FORMULA_CALC   ));
     176         [ #  # ]:          0 :         SetItemImage( FN_FORMULA_CANCEL, pImgMgr->GetImage(FN_FORMULA_CANCEL ));
     177         [ #  # ]:          0 :         SetItemImage( FN_FORMULA_APPLY,  pImgMgr->GetImage(FN_FORMULA_APPLY  ));
     178                 :            :     }
     179                 :            : 
     180                 :          0 :     ToolBox::DataChanged( rDCEvt );
     181                 :          0 : }
     182                 :            : 
     183                 :            : //==================================================================
     184                 :            : 
     185                 :          0 : void SwInputWindow::Resize()
     186                 :            : {
     187         [ #  # ]:          0 :     ToolBox::Resize();
     188                 :            : 
     189         [ #  # ]:          0 :     long    nWidth      = GetSizePixel().Width();
     190         [ #  # ]:          0 :     long    nLeft       = aEdit.GetPosPixel().X();
     191         [ #  # ]:          0 :     Size    aEditSize   = aEdit.GetSizePixel();
     192                 :            : 
     193                 :          0 :     aEditSize.Width() = Max( ((long)(nWidth - nLeft - 5)), (long)0 );
     194         [ #  # ]:          0 :     aEdit.SetSizePixel( aEditSize );
     195         [ #  # ]:          0 :     aEdit.Invalidate();
     196                 :          0 : }
     197                 :            : 
     198                 :            : //==================================================================
     199                 :            : 
     200                 :          0 : void SwInputWindow::ShowWin()
     201                 :            : {
     202                 :          0 :     bIsTable = sal_False;
     203                 :            :     //Lineale anhalten
     204         [ #  # ]:          0 :     if(pView)
     205                 :            :     {
     206         [ #  # ]:          0 :         pView->GetHLineal().SetActive( sal_False );
     207         [ #  # ]:          0 :         pView->GetVLineal().SetActive( sal_False );
     208                 :            : 
     209                 :            :         OSL_ENSURE(pWrtShell, "no WrtShell!");
     210                 :            :         // Cursor in Tabelle
     211 [ #  # ][ #  # ]:          0 :         bIsTable = pWrtShell->IsCrsrInTbl() ? sal_True : sal_False;
     212                 :            : 
     213         [ #  # ]:          0 :         if( bFirst )
     214                 :            :             pWrtShell->SelTblCells( LINK( this, SwInputWindow,
     215         [ #  # ]:          0 :                                                 SelTblCellsNotify) );
     216         [ #  # ]:          0 :         if( bIsTable )
     217                 :            :         {
     218         [ #  # ]:          0 :             const String& rPos = pWrtShell->GetBoxNms();
     219                 :          0 :             sal_uInt16 nPos = 0;
     220                 :          0 :             short nSrch = -1;
     221 [ #  # ][ #  # ]:          0 :             while( (nPos = rPos.Search( ':',nPos + 1 ) ) != STRING_NOTFOUND )
     222                 :          0 :                 nSrch = (short) nPos;
     223 [ #  # ][ #  # ]:          0 :             aPos.SetText( rPos.Copy( ++nSrch ) );
                 [ #  # ]
     224 [ #  # ][ #  # ]:          0 :             aAktTableName = pWrtShell->GetTableFmt()->GetName();
                 [ #  # ]
     225                 :            :         }
     226                 :            :         else
     227 [ #  # ][ #  # ]:          0 :             aPos.SetText(SW_RESSTR(STR_TBL_FORMULA));
         [ #  # ][ #  # ]
     228                 :            : 
     229                 :            :         // Aktuelles Feld bearbeiten
     230                 :            :         OSL_ENSURE(pMgr == 0, "FieldManager not deleted");
     231 [ #  # ][ #  # ]:          0 :         pMgr = new SwFldMgr;
     232                 :            : 
     233                 :            :         // Formel soll immer mit einem "=" beginnen, hier
     234                 :            :         // also setzen
     235         [ #  # ]:          0 :         String sEdit = rtl::OUString('=');
     236 [ #  # ][ #  # ]:          0 :         if( pMgr->GetCurFld() && TYP_FORMELFLD == pMgr->GetCurTypeId() )
         [ #  # ][ #  # ]
                 [ #  # ]
     237                 :            :         {
     238         [ #  # ]:          0 :             sEdit += pMgr->GetCurFldPar2();
     239                 :            :         }
     240         [ #  # ]:          0 :         else if( bFirst )
     241                 :            :         {
     242         [ #  # ]:          0 :             if( bIsTable )
     243                 :            :             {
     244                 :          0 :                 m_bResetUndo = true;
     245                 :            :                 SAL_WARN_IF(
     246                 :            :                     officecfg::Office::Common::Undo::Steps::get() <= 0,
     247                 :            :                     "sw", "/org.openoffice.Office.Common/Undo/Steps <= 0");
     248                 :            : 
     249         [ #  # ]:          0 :                 m_bDoesUndo = pWrtShell->DoesUndo();
     250         [ #  # ]:          0 :                 if( !m_bDoesUndo )
     251                 :            :                 {
     252         [ #  # ]:          0 :                     pWrtShell->DoUndo( sal_True );
     253                 :            :                 }
     254                 :            : 
     255 [ #  # ][ #  # ]:          0 :                 if( !pWrtShell->SwCrsrShell::HasSelection() )
     256                 :            :                 {
     257         [ #  # ]:          0 :                     pWrtShell->MoveSection( fnSectionCurr, fnSectionStart );
     258         [ #  # ]:          0 :                     pWrtShell->SetMark();
     259         [ #  # ]:          0 :                     pWrtShell->MoveSection( fnSectionCurr, fnSectionEnd );
     260                 :            :                 }
     261 [ #  # ][ #  # ]:          0 :                 if( pWrtShell->SwCrsrShell::HasSelection() )
     262                 :            :                 {
     263         [ #  # ]:          0 :                     pWrtShell->StartUndo( UNDO_DELETE );
     264         [ #  # ]:          0 :                     pWrtShell->Delete();
     265 [ #  # ][ #  # ]:          0 :                     if( 0 != pWrtShell->EndUndo( UNDO_DELETE ))
     266                 :            :                     {
     267                 :          0 :                         m_bCallUndo = true;
     268                 :            :                     }
     269                 :            :                 }
     270         [ #  # ]:          0 :                 pWrtShell->DoUndo(false);
     271                 :            : 
     272 [ #  # ][ #  # ]:          0 :                 SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_BOXATR_FORMULA, RES_BOXATR_FORMULA );
     273 [ #  # ][ #  # ]:          0 :                 if( pWrtShell->GetTblBoxFormulaAttrs( aSet ))
     274 [ #  # ][ #  # ]:          0 :                     sEdit += ((SwTblBoxFormula&)aSet.Get( RES_BOXATR_FORMULA )).GetFormula();
                 [ #  # ]
     275                 :            :             }
     276                 :            :         }
     277                 :            : 
     278         [ #  # ]:          0 :         if( bFirst )
     279                 :            :         {
     280                 :            :             // WrtShell Flags richtig setzen
     281         [ #  # ]:          0 :             pWrtShell->SttSelect();
     282         [ #  # ]:          0 :             pWrtShell->EndSelect();
     283                 :            :         }
     284                 :            : 
     285                 :          0 :         bFirst = sal_False;
     286                 :            : 
     287         [ #  # ]:          0 :         aEdit.SetModifyHdl( LINK( this, SwInputWindow, ModifyHdl ));
     288                 :            : 
     289         [ #  # ]:          0 :         aEdit.SetText( sEdit );
     290         [ #  # ]:          0 :         aEdit.SetSelection( Selection( sEdit.Len(), sEdit.Len() ) );
     291         [ #  # ]:          0 :         sOldFml = sEdit;
     292                 :            : 
     293         [ #  # ]:          0 :         aEdit.Invalidate();
     294         [ #  # ]:          0 :         aEdit.Update();
     295         [ #  # ]:          0 :         aEdit.GrabFocus();
     296                 :            :         // UserInterface fuer die Eingabe abklemmen
     297                 :            : 
     298                 :          0 :         pView->GetEditWin().LockKeyInput(sal_True);
     299         [ #  # ]:          0 :         pView->GetViewFrame()->GetDispatcher()->Lock(sal_True);
     300 [ #  # ][ #  # ]:          0 :         pWrtShell->Push();
     301                 :            :     }
     302                 :          0 :     ToolBox::Show();
     303                 :          0 : }
     304                 :            : //==================================================================
     305                 :            : 
     306                 :          0 : IMPL_LINK( SwInputWindow, MenuHdl, Menu *, pMenu )
     307                 :            : {
     308                 :            : static const char * const aStrArr[] = {
     309                 :            :     sCalc_Phd,
     310                 :            :     sCalc_Sqrt,
     311                 :            :     sCalc_Or,
     312                 :            :     sCalc_Xor,
     313                 :            :     sCalc_And,
     314                 :            :     sCalc_Not,
     315                 :            :     sCalc_Eq,
     316                 :            :     sCalc_Neq,
     317                 :            :     sCalc_Leq,
     318                 :            :     sCalc_Geq,
     319                 :            :     sCalc_L,
     320                 :            :     sCalc_G,
     321                 :            :     sCalc_Sum,
     322                 :            :     sCalc_Mean,
     323                 :            :     sCalc_Min,
     324                 :            :     sCalc_Max,
     325                 :            :     sCalc_Sin,
     326                 :            :     sCalc_Cos,
     327                 :            :     sCalc_Tan,
     328                 :            :     sCalc_Asin,
     329                 :            :     sCalc_Acos,
     330                 :            :     sCalc_Atan,
     331                 :            :     sCalc_Pow,
     332                 :            :     "|",
     333                 :            :     sCalc_Round
     334                 :            : };
     335                 :            : 
     336                 :          0 :     sal_uInt16 nId = pMenu->GetCurItemId();
     337         [ #  # ]:          0 :     if ( nId <= MN_CALC_ROUND )
     338                 :            :     {
     339         [ #  # ]:          0 :         String aTmp( rtl::OUString::createFromAscii(aStrArr[nId - 1]) );
     340         [ #  # ]:          0 :         aTmp += ' ';
     341 [ #  # ][ #  # ]:          0 :         aEdit.ReplaceSelected( aTmp );
     342                 :            :     }
     343                 :          0 :     return 0;
     344                 :            : }
     345                 :            : 
     346                 :          0 : IMPL_LINK_NOARG(SwInputWindow, DropdownClickHdl)
     347                 :            : {
     348                 :          0 :     sal_uInt16 nCurID = GetCurItemId();
     349                 :          0 :     EndSelection(); // setzt CurItemId zurueck !
     350         [ #  # ]:          0 :     switch ( nCurID )
     351                 :            :     {
     352                 :            :         case FN_FORMULA_CALC :
     353                 :            :         {
     354         [ #  # ]:          0 :             aPopMenu.Execute( this, GetItemRect( FN_FORMULA_CALC ), POPUPMENU_NOMOUSEUPCLOSE );
     355                 :          0 :             break;
     356                 :            :         default:
     357                 :          0 :             break;
     358                 :            :         }
     359                 :            :     }
     360                 :            : 
     361                 :          0 :     return sal_True;
     362                 :            : }
     363                 :            : 
     364                 :            : //==================================================================
     365                 :            : 
     366                 :            : 
     367                 :          0 : void SwInputWindow::Click( )
     368                 :            : {
     369                 :          0 :     sal_uInt16 nCurID = GetCurItemId();
     370                 :          0 :     EndSelection(); // setzt CurItemId zurueck !
     371      [ #  #  # ]:          0 :     switch ( nCurID )
     372                 :            :     {
     373                 :            :         case FN_FORMULA_CANCEL:
     374                 :            :         {
     375                 :          0 :             CancelFormula();
     376                 :            :         }
     377                 :          0 :         break;
     378                 :            :         case FN_FORMULA_APPLY:
     379                 :            :         {
     380                 :          0 :             ApplyFormula();
     381                 :            :         }
     382                 :          0 :         break;
     383                 :            :    }
     384                 :          0 : }
     385                 :            : 
     386                 :            : //==================================================================
     387                 :            : 
     388                 :          0 : void  SwInputWindow::ApplyFormula()
     389                 :            : {
     390         [ #  # ]:          0 :     pView->GetViewFrame()->GetDispatcher()->Lock(sal_False);
     391                 :          0 :     pView->GetEditWin().LockKeyInput(sal_False);
     392         [ #  # ]:          0 :     CleanupUglyHackWithUndo();
     393         [ #  # ]:          0 :     pWrtShell->Pop( sal_False );
     394                 :            : 
     395                 :            :     // Formel soll immer mit einem "=" beginnen, hier
     396                 :            :     // also wieder entfernen
     397 [ #  # ][ #  # ]:          0 :     String sEdit(comphelper::string::strip(aEdit.GetText(), ' '));
         [ #  # ][ #  # ]
                 [ #  # ]
     398 [ #  # ][ #  # ]:          0 :     if( sEdit.Len() && '=' == sEdit.GetChar( 0 ) )
                 [ #  # ]
     399         [ #  # ]:          0 :         sEdit.Erase( 0, 1 );
     400         [ #  # ]:          0 :     SfxStringItem aParam(FN_EDIT_FORMULA, sEdit);
     401                 :            : 
     402                 :          0 :     pWrtShell->EndSelTblCells();
     403         [ #  # ]:          0 :     pView->GetEditWin().GrabFocus();
     404                 :            :     const SfxPoolItem* aArgs[2];
     405                 :          0 :     aArgs[0] = &aParam;
     406                 :          0 :     aArgs[1] = 0;
     407 [ #  # ][ #  # ]:          0 :     pView->GetViewFrame()->GetBindings().Execute( FN_EDIT_FORMULA, aArgs, 0, SFX_CALLMODE_ASYNCHRON );
                 [ #  # ]
     408                 :          0 : }
     409                 :            : 
     410                 :            : //==================================================================
     411                 :            : 
     412                 :          0 : void  SwInputWindow::CancelFormula()
     413                 :            : {
     414         [ #  # ]:          0 :     if(pView)
     415                 :            :     {
     416                 :          0 :         pView->GetViewFrame()->GetDispatcher()->Lock( sal_False );
     417                 :          0 :         pView->GetEditWin().LockKeyInput(sal_False);
     418                 :          0 :         CleanupUglyHackWithUndo();
     419                 :          0 :         pWrtShell->Pop( sal_False );
     420                 :            : 
     421         [ #  # ]:          0 :         if( bDelSel )
     422                 :          0 :             pWrtShell->EnterStdMode();
     423                 :            : 
     424                 :          0 :         pWrtShell->EndSelTblCells();
     425                 :            : 
     426                 :          0 :         pView->GetEditWin().GrabFocus();
     427                 :            :     }
     428                 :          0 :     pView->GetViewFrame()->GetDispatcher()->Execute( FN_EDIT_FORMULA, SFX_CALLMODE_ASYNCHRON);
     429                 :          0 : }
     430                 :            : //==================================================================
     431                 :            : 
     432                 :            : const xub_Unicode CH_LRE = 0x202a;
     433                 :            : const xub_Unicode CH_PDF = 0x202c;
     434                 :            : 
     435                 :          0 : IMPL_LINK( SwInputWindow, SelTblCellsNotify, SwWrtShell *, pCaller )
     436                 :            : {
     437         [ #  # ]:          0 :     if(bIsTable)
     438                 :            :     {
     439         [ #  # ]:          0 :         SwFrmFmt* pTblFmt = pCaller->GetTableFmt();
     440         [ #  # ]:          0 :         String sBoxNms( pCaller->GetBoxNms() );
     441         [ #  # ]:          0 :         String sTblNm;
     442 [ #  # ][ #  # ]:          0 :         if( pTblFmt && aAktTableName != pTblFmt->GetName() )
         [ #  # ][ #  # ]
     443         [ #  # ]:          0 :             sTblNm = pTblFmt->GetName();
     444                 :            : 
     445         [ #  # ]:          0 :         aEdit.UpdateRange( sBoxNms, sTblNm );
     446                 :            : 
     447         [ #  # ]:          0 :         String sNew;
     448         [ #  # ]:          0 :         sNew += CH_LRE;
     449 [ #  # ][ #  # ]:          0 :         sNew += aEdit.GetText();
                 [ #  # ]
     450         [ #  # ]:          0 :         sNew += CH_PDF;
     451                 :            : 
     452 [ #  # ][ #  # ]:          0 :         if( sNew != sOldFml )
     453                 :            :         {
     454                 :            :             // Die WrtShell ist in der Tabellen Selektion
     455                 :            :             // dann die Tabellen Selektion wieder aufheben, sonst steht der
     456                 :            :             // Cursor "im Wald" und das LiveUpdate funktioniert nicht!
     457         [ #  # ]:          0 :             pWrtShell->StartAllAction();
     458                 :            : 
     459         [ #  # ]:          0 :             SwPaM aPam( *pWrtShell->GetStkCrsr()->GetPoint() );
     460         [ #  # ]:          0 :             aPam.Move( fnMoveBackward, fnGoSection );
     461         [ #  # ]:          0 :             aPam.SetMark();
     462         [ #  # ]:          0 :             aPam.Move( fnMoveForward, fnGoSection );
     463                 :            : 
     464         [ #  # ]:          0 :             IDocumentContentOperations* pIDCO = pWrtShell->getIDocumentContentOperations();
     465         [ #  # ]:          0 :             pIDCO->DeleteRange( aPam );
     466         [ #  # ]:          0 :             pIDCO->InsertString( aPam, sNew );
     467         [ #  # ]:          0 :             pWrtShell->EndAllAction();
     468 [ #  # ][ #  # ]:          0 :             sOldFml = sNew;
     469 [ #  # ][ #  # ]:          0 :         }
                 [ #  # ]
     470                 :            :     }
     471                 :            :     else
     472                 :          0 :         aEdit.GrabFocus();
     473                 :          0 :     return 0;
     474                 :            : }
     475                 :            : 
     476                 :            : 
     477                 :          0 : void SwInputWindow::SetFormula( const String& rFormula, sal_Bool bDelFlag )
     478                 :            : {
     479         [ #  # ]:          0 :     String sEdit = rtl::OUString('=');
     480         [ #  # ]:          0 :     if( rFormula.Len() )
     481                 :            :     {
     482         [ #  # ]:          0 :         if( '=' == rFormula.GetChar( 0 ) )
     483         [ #  # ]:          0 :             sEdit = rFormula;
     484                 :            :         else
     485         [ #  # ]:          0 :             sEdit += rFormula;
     486                 :            :     }
     487         [ #  # ]:          0 :     aEdit.SetText( sEdit );
     488         [ #  # ]:          0 :     aEdit.SetSelection( Selection( sEdit.Len(), sEdit.Len() ) );
     489         [ #  # ]:          0 :     aEdit.Invalidate();
     490         [ #  # ]:          0 :     bDelSel = bDelFlag;
     491                 :          0 : }
     492                 :            : 
     493                 :          0 : IMPL_LINK_NOARG(SwInputWindow, ModifyHdl)
     494                 :            : {
     495 [ #  # ][ #  # ]:          0 :     if (bIsTable && m_bResetUndo)
     496                 :            :     {
     497         [ #  # ]:          0 :         pWrtShell->StartAllAction();
     498         [ #  # ]:          0 :         DelBoxCntnt();
     499         [ #  # ]:          0 :         String sNew;
     500         [ #  # ]:          0 :         sNew += CH_LRE;
     501 [ #  # ][ #  # ]:          0 :         sNew += aEdit.GetText();
                 [ #  # ]
     502         [ #  # ]:          0 :         sNew += CH_PDF;
     503         [ #  # ]:          0 :         pWrtShell->SwEditShell::Insert2( sNew );
     504         [ #  # ]:          0 :         pWrtShell->EndAllAction();
     505 [ #  # ][ #  # ]:          0 :         sOldFml = sNew;
     506                 :            :     }
     507                 :          0 :     return 0;
     508                 :            : }
     509                 :            : 
     510                 :            : 
     511                 :          0 : void SwInputWindow::DelBoxCntnt()
     512                 :            : {
     513         [ #  # ]:          0 :     if( bIsTable )
     514                 :            :     {
     515                 :          0 :         pWrtShell->StartAllAction();
     516                 :          0 :         pWrtShell->ClearMark();
     517                 :          0 :         pWrtShell->Pop( sal_False );
     518                 :          0 :         pWrtShell->Push();
     519                 :          0 :         pWrtShell->MoveSection( fnSectionCurr, fnSectionStart );
     520                 :          0 :         pWrtShell->SetMark();
     521                 :          0 :         pWrtShell->MoveSection( fnSectionCurr, fnSectionEnd );
     522                 :          0 :         pWrtShell->SwEditShell::Delete();
     523                 :          0 :         pWrtShell->EndAllAction();
     524                 :            :     }
     525                 :          0 : }
     526                 :            : 
     527                 :            : //==================================================================
     528                 :            : 
     529                 :          0 : void InputEdit::KeyInput(const KeyEvent& rEvent)
     530                 :            : {
     531                 :          0 :     const KeyCode aCode = rEvent.GetKeyCode();
     532 [ #  # ][ #  # ]:          0 :     if(aCode == KEY_RETURN || aCode == KEY_F2 )
         [ #  # ][ #  # ]
         [ #  # ][ #  #  
             #  #  #  # ]
                 [ #  # ]
     533 [ #  # ][ #  # ]:          0 :         ((SwInputWindow*)GetParent())->ApplyFormula();
     534 [ #  # ][ #  # ]:          0 :     else if(aCode == KEY_ESCAPE )
     535 [ #  # ][ #  # ]:          0 :         ((SwInputWindow*)GetParent())->CancelFormula();
     536                 :            :     else
     537         [ #  # ]:          0 :         Edit::KeyInput(rEvent);
     538                 :          0 : }
     539                 :            : 
     540                 :            : //==================================================================
     541                 :            : 
     542                 :          0 : void InputEdit::UpdateRange(const String& rBoxes,
     543                 :            :                                     const String& rName )
     544                 :            : {
     545         [ #  # ]:          0 :     if( !rBoxes.Len() )
     546                 :            :     {
     547         [ #  # ]:          0 :         GrabFocus();
     548                 :          0 :         return;
     549                 :            :     }
     550                 :          0 :     const sal_Unicode   cOpen = '<', cClose = '>',
     551                 :          0 :                 cOpenBracket = '(';
     552         [ #  # ]:          0 :     String aPrefix = rName;
     553         [ #  # ]:          0 :     if(rName.Len())
     554         [ #  # ]:          0 :         aPrefix += '.';
     555         [ #  # ]:          0 :     String aBoxes = aPrefix;
     556         [ #  # ]:          0 :     aBoxes += rBoxes;
     557         [ #  # ]:          0 :     Selection aSelection(GetSelection());
     558                 :          0 :     sal_uInt16 nSel = (sal_uInt16) aSelection.Len();
     559                 :            :     //OS: mit dem folgenden Ausdruck wird sichergestellt, dass im overwrite-Modus
     560                 :            :     //die selektierte schliessende Klammer nicht geloescht wird
     561   [ #  #  #  # ]:          0 :     if( nSel && ( nSel > 1 ||
         [ #  # ][ #  # ]
     562 [ #  # ][ #  # ]:          0 :         GetText().GetChar( (sal_uInt16)aSelection.Min() ) != cClose ) )
         [ #  # ][ #  # ]
     563         [ #  # ]:          0 :         Cut();
     564                 :            :     else
     565                 :          0 :         aSelection.Max() = aSelection.Min();
     566         [ #  # ]:          0 :     String aActText(GetText());
     567                 :          0 :     const sal_uInt16 nLen = aActText.Len();
     568         [ #  # ]:          0 :     if( !nLen )
     569                 :            :     {
     570                 :            :         String aStr = rtl::OUStringBuffer().
     571 [ #  # ][ #  # ]:          0 :             append(cOpen).append(aBoxes).append(cClose).
         [ #  # ][ #  # ]
     572 [ #  # ][ #  # ]:          0 :             makeStringAndClear();
     573         [ #  # ]:          0 :         SetText(aStr);
     574         [ #  # ]:          0 :         sal_uInt16 nPos = aStr.Search( cClose );
     575                 :            :         OSL_ENSURE(nPos < aStr.Len(), "delimiter not found");
     576                 :          0 :         ++nPos;
     577 [ #  # ][ #  # ]:          0 :         SetSelection( Selection( nPos, nPos ));
     578                 :            :     }
     579                 :            :     else
     580                 :            :     {
     581                 :          0 :         sal_Bool bFound = sal_False;
     582                 :            :         sal_Unicode cCh;
     583                 :          0 :         sal_uInt16 nPos, nEndPos = 0, nStartPos = (sal_uInt16) aSelection.Min();
     584         [ #  # ]:          0 :         if( nStartPos-- )
     585                 :            :         {
     586         [ #  # ]:          0 :             do {
     587 [ #  # ][ #  # ]:          0 :                 if( cOpen  == (cCh = aActText.GetChar( nStartPos ) ) ||
                 [ #  # ]
     588                 :            :                     cOpenBracket == cCh )
     589                 :            :                 {
     590                 :          0 :                     bFound = cCh == cOpen;
     591                 :          0 :                     break;
     592                 :            :                 }
     593                 :            :             } while( nStartPos-- > 0 );
     594                 :            :         }
     595         [ #  # ]:          0 :         if( bFound )
     596                 :            :         {
     597                 :          0 :             bFound = sal_False;
     598                 :          0 :             nEndPos = nStartPos;
     599         [ #  # ]:          0 :             while( nEndPos < nLen )
     600                 :            :             {
     601         [ #  # ]:          0 :                 if( cClose == (cCh = aActText.GetChar( nEndPos )))
     602                 :            :                 {
     603                 :          0 :                     bFound = sal_True;
     604                 :          0 :                     break;
     605                 :            :                 }
     606                 :          0 :                 ++nEndPos;
     607                 :            :             }
     608                 :            :             // nur wenn akt. Pos im Breich oder direkt dahinter liegt
     609 [ #  # ][ #  # ]:          0 :             if( bFound && !( nStartPos < (sal_uInt16)aSelection.Max() &&
                 [ #  # ]
     610         [ #  # ]:          0 :                              (sal_uInt16)aSelection.Max() <= nEndPos + 1 ))
     611                 :          0 :                 bFound = sal_False;
     612                 :            :         }
     613         [ #  # ]:          0 :         if( bFound )
     614                 :            :         {
     615                 :          0 :             nPos = ++nStartPos + 1; // wir wollen dahinter
     616         [ #  # ]:          0 :             aActText.Erase( nStartPos, nEndPos - nStartPos );
     617         [ #  # ]:          0 :             aActText.Insert( aBoxes, nStartPos );
     618                 :          0 :             nPos = nPos + aBoxes.Len();
     619                 :            :         }
     620                 :            :         else
     621                 :            :         {
     622                 :            :             rtl::OUString aTmp = rtl::OUStringBuffer().
     623 [ #  # ][ #  # ]:          0 :                 append(cOpen).append(aBoxes).append(cClose).
         [ #  # ][ #  # ]
     624         [ #  # ]:          0 :                 makeStringAndClear();
     625                 :          0 :             nPos = (sal_uInt16)aSelection.Min();
     626 [ #  # ][ #  # ]:          0 :             aActText.Insert( aTmp, nPos );
                 [ #  # ]
     627                 :          0 :             nPos = nPos + aTmp.getLength();
     628                 :            :         }
     629 [ #  # ][ #  # ]:          0 :         if( GetText() != aActText )
         [ #  # ][ #  # ]
     630                 :            :         {
     631         [ #  # ]:          0 :             SetText( aActText );
     632         [ #  # ]:          0 :             SetSelection( Selection( nPos, nPos ) );
     633                 :            :         }
     634                 :            :     }
     635 [ #  # ][ #  # ]:          0 :     GrabFocus();
         [ #  # ][ #  # ]
     636                 :            : 
     637                 :            : }
     638                 :            : //==================================================================
     639                 :            : 
     640                 :          0 : SwInputChild::SwInputChild(Window* _pParent,
     641                 :            :                                 sal_uInt16 nId,
     642                 :            :                                 SfxBindings* pBindings,
     643                 :            :                                 SfxChildWinInfo* ) :
     644                 :          0 :                                 SfxChildWindow( _pParent, nId )
     645                 :            : {
     646                 :          0 :     pDispatch = pBindings->GetDispatcher();
     647 [ #  # ][ #  # ]:          0 :     pWindow = new SwInputWindow( _pParent, pBindings );
     648         [ #  # ]:          0 :     ((SwInputWindow*)pWindow)->ShowWin();
     649                 :          0 :     eChildAlignment = SFX_ALIGN_LOWESTTOP;
     650                 :          0 : }
     651                 :            : 
     652                 :            : 
     653                 :          0 : SwInputChild::~SwInputChild()
     654                 :            : {
     655         [ #  # ]:          0 :     if(pDispatch)
     656         [ #  # ]:          0 :         pDispatch->Lock(sal_False);
     657         [ #  # ]:          0 : }
     658                 :            : 
     659                 :            : 
     660                 :          0 : SfxChildWinInfo SwInputChild::GetInfo() const
     661                 :            : {
     662                 :          0 :     SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();     \
     663                 :          0 :     return aInfo;
     664                 :            : }
     665                 :            : 
     666                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10