LCOV - code coverage report
Current view: top level - sw/source/core/uibase/ribbar - inputwin.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 1 331 0.3 %
Date: 2014-04-11 Functions: 2 29 6.9 %
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 "sal/config.h"
      21             : 
      22             : #include <comphelper/string.hxx>
      23             : #include <officecfg/Office/Common.hxx>
      24             : #include <tools/gen.hxx>
      25             : #include <sfx2/imgmgr.hxx>
      26             : #include <sfx2/viewfrm.hxx>
      27             : #include <sfx2/dispatch.hxx>
      28             : #include <svx/ruler.hxx>
      29             : #include <svl/zforlist.hxx>
      30             : #include <svl/stritem.hxx>
      31             : #include <vcl/settings.hxx>
      32             : 
      33             : #include "swtypes.hxx"
      34             : #include "cmdid.h"
      35             : #include "swmodule.hxx"
      36             : #include "wrtsh.hxx"
      37             : #include "view.hxx"
      38             : #include "calc.hxx"
      39             : #include "inputwin.hxx"
      40             : #include "fldbas.hxx"
      41             : #include "fldmgr.hxx"
      42             : #include "frmfmt.hxx"
      43             : #include "cellatr.hxx"
      44             : #include "edtwin.hxx"
      45             : #include "helpid.h"
      46             : #include "access.hrc"
      47             : 
      48             : // Only for the UpdateRange: Delete the box in which the stacked cursor is positioned.
      49             : #include "pam.hxx"
      50             : 
      51             : #include "swundo.hxx"
      52             : #include "ribbar.hrc"
      53             : #include "inputwin.hrc"
      54             : 
      55             : #include <IDocumentContentOperations.hxx>
      56             : 
      57        3461 : SFX_IMPL_POS_CHILDWINDOW_WITHID( SwInputChild, FN_EDIT_FORMULA, SFX_OBJECTBAR_OBJECT )
      58             : 
      59           0 : SwInputWindow::SwInputWindow( Window* pParent, SfxBindings* pBind )
      60             :     : ToolBox(  pParent ,   SW_RES( RID_TBX_FORMULA )),
      61             :     aPos(       this,       SW_RES(ED_POS)),
      62             :     aEdit(      this, WB_3DLOOK|WB_TABSTOP|WB_BORDER|WB_NOHIDESELECTION),
      63             :     aPopMenu(   SW_RES(MN_CALC_POPUP)),
      64             :     pMgr(0),
      65             :     pWrtShell(0),
      66             :     pView(0),
      67             :     pBindings(pBind),
      68             :     aAktTableName(aEmptyOUStr)
      69             :     , m_bDoesUndo(true)
      70             :     , m_bResetUndo(false)
      71           0 :     , m_bCallUndo(false)
      72             : {
      73           0 :     bFirst = sal_True;
      74           0 :     bActive = bIsTable = bDelSel = sal_False;
      75             : 
      76           0 :     FreeResource();
      77             : 
      78           0 :     aEdit.SetSizePixel( aEdit.CalcMinimumSize() );
      79             : 
      80           0 :     SfxImageManager* pManager = SfxImageManager::GetImageManager( SW_MOD() );
      81           0 :     pManager->RegisterToolBox(this);
      82             : 
      83           0 :     pView = ::GetActiveView();
      84           0 :     pWrtShell = pView ? pView->GetWrtShellPtr() : 0;
      85             : 
      86           0 :     InsertWindow( ED_POS, &aPos, 0, 0);
      87           0 :     SetItemText(ED_POS, SW_RESSTR(STR_ACCESS_FORMULA_TYPE));
      88           0 :     aPos.SetAccessibleName(SW_RESSTR(STR_ACCESS_FORMULA_TYPE));
      89           0 :     SetAccessibleName(SW_RESSTR(STR_ACCESS_FORMULA_TOOLBAR));
      90           0 :     InsertSeparator ( 1 );
      91           0 :     InsertSeparator ();
      92           0 :     InsertWindow( ED_FORMULA, &aEdit);
      93           0 :     SetItemText(ED_FORMULA, SW_RESSTR(STR_ACCESS_FORMULA_TEXT));
      94           0 :     aEdit.SetAccessibleName(SW_RESSTR(STR_ACCESS_FORMULA_TEXT));
      95           0 :     SetHelpId(ED_FORMULA, HID_EDIT_FORMULA);
      96             : 
      97           0 :     SetItemImage( FN_FORMULA_CALC,   pManager->GetImage(FN_FORMULA_CALC   ));
      98           0 :     SetItemImage( FN_FORMULA_CANCEL, pManager->GetImage(FN_FORMULA_CANCEL ));
      99           0 :     SetItemImage( FN_FORMULA_APPLY,  pManager->GetImage(FN_FORMULA_APPLY  ));
     100             : 
     101           0 :     SetItemBits( FN_FORMULA_CALC, GetItemBits( FN_FORMULA_CALC ) | TIB_DROPDOWNONLY );
     102           0 :     SetDropdownClickHdl( LINK( this, SwInputWindow, DropdownClickHdl ));
     103             : 
     104           0 :     Size    aSizeTbx = CalcWindowSizePixel();
     105           0 :     Size    aEditSize = aEdit.GetSizePixel();
     106           0 :     Rectangle aItemRect( GetItemRect(FN_FORMULA_CALC) );
     107           0 :     long nMaxHeight = (aEditSize.Height() > aItemRect.GetHeight()) ? aEditSize.Height() : aItemRect.GetHeight();
     108           0 :     if( nMaxHeight+2 > aSizeTbx.Height() )
     109           0 :         aSizeTbx.Height() = nMaxHeight+2;
     110           0 :     Size aSize = GetSizePixel();
     111           0 :     aSize.Height() = aSizeTbx.Height();
     112           0 :     SetSizePixel( aSize );
     113             : 
     114             :     // align edit and item vcentered
     115           0 :     Size    aPosSize = aPos.GetSizePixel();
     116           0 :     aPosSize.Height()  = nMaxHeight;
     117           0 :     aEditSize.Height() = nMaxHeight;
     118           0 :     Point aPosPos  = aPos.GetPosPixel();
     119           0 :     Point aEditPos = aEdit.GetPosPixel();
     120           0 :     aPosPos.Y()    = (aSize.Height() - nMaxHeight)/2 + 1;
     121           0 :     aEditPos.Y()   = (aSize.Height() - nMaxHeight)/2 + 1;
     122           0 :     aPos.SetPosSizePixel( aPosPos, aPosSize );
     123           0 :     aEdit.SetPosSizePixel( aEditPos, aEditSize );
     124             : 
     125           0 :     aPopMenu.SetSelectHdl(LINK( this, SwInputWindow, MenuHdl ));
     126           0 : }
     127             : 
     128           0 : SwInputWindow::~SwInputWindow()
     129             : {
     130           0 :     SfxImageManager::GetImageManager( SW_MOD() )->ReleaseToolBox(this);
     131             : 
     132             :     // wake rulers
     133           0 :     if(pView)
     134             :     {
     135           0 :         pView->GetHRuler().SetActive( true );
     136           0 :         pView->GetVRuler().SetActive( true );
     137             :     }
     138           0 :     delete pMgr;
     139           0 :     if(pWrtShell)
     140           0 :         pWrtShell->EndSelTblCells();
     141             : 
     142           0 :     CleanupUglyHackWithUndo();
     143           0 : }
     144             : 
     145           0 : void SwInputWindow::CleanupUglyHackWithUndo()
     146             : {
     147           0 :     if (m_bResetUndo)
     148             :     {
     149           0 :         if (pWrtShell)
     150             :         {
     151           0 :             DelBoxCntnt();
     152           0 :             pWrtShell->DoUndo(m_bDoesUndo);
     153           0 :             if (m_bCallUndo)
     154             :             {
     155           0 :                 pWrtShell->Undo();
     156             :             }
     157             :         }
     158           0 :         m_bResetUndo = false; // #i117122# once is enough :)
     159             :     }
     160           0 : }
     161             : 
     162           0 : void SwInputWindow::DataChanged( const DataChangedEvent& rDCEvt )
     163             : {
     164           0 :     if ( rDCEvt.GetType() == DATACHANGED_SETTINGS && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
     165             :     {
     166             :         // update item images
     167           0 :         SwModule *pMod  = SW_MOD();
     168           0 :         SfxImageManager *pImgMgr = SfxImageManager::GetImageManager( pMod );
     169           0 :         SetItemImage( FN_FORMULA_CALC,   pImgMgr->GetImage(FN_FORMULA_CALC   ));
     170           0 :         SetItemImage( FN_FORMULA_CANCEL, pImgMgr->GetImage(FN_FORMULA_CANCEL ));
     171           0 :         SetItemImage( FN_FORMULA_APPLY,  pImgMgr->GetImage(FN_FORMULA_APPLY  ));
     172             :     }
     173             : 
     174           0 :     ToolBox::DataChanged( rDCEvt );
     175           0 : }
     176             : 
     177           0 : void SwInputWindow::Resize()
     178             : {
     179           0 :     ToolBox::Resize();
     180             : 
     181           0 :     long    nWidth      = GetSizePixel().Width();
     182           0 :     long    nLeft       = aEdit.GetPosPixel().X();
     183           0 :     Size    aEditSize   = aEdit.GetSizePixel();
     184             : 
     185           0 :     aEditSize.Width() = std::max( ((long)(nWidth - nLeft - 5)), (long)0 );
     186           0 :     aEdit.SetSizePixel( aEditSize );
     187           0 :     aEdit.Invalidate();
     188           0 : }
     189             : 
     190           0 : void SwInputWindow::ShowWin()
     191             : {
     192           0 :     bIsTable = sal_False;
     193             :     // stop rulers
     194           0 :     if(pView)
     195             :     {
     196           0 :         pView->GetHRuler().SetActive( false );
     197           0 :         pView->GetVRuler().SetActive( false );
     198             : 
     199             :         OSL_ENSURE(pWrtShell, "no WrtShell!");
     200             :         // Cursor in table
     201           0 :         bIsTable = pWrtShell->IsCrsrInTbl() ? sal_True : sal_False;
     202             : 
     203           0 :         if( bFirst )
     204             :             pWrtShell->SelTblCells( LINK( this, SwInputWindow,
     205           0 :                                                 SelTblCellsNotify) );
     206           0 :         if( bIsTable )
     207             :         {
     208           0 :             const OUString& rPos = pWrtShell->GetBoxNms();
     209           0 :             sal_Int32 nPos = 0;
     210           0 :             short nSrch = -1;
     211           0 :             while( (nPos = rPos.indexOf( ':',nPos + 1 ) ) != -1 )
     212           0 :                 nSrch = (short) nPos;
     213           0 :             aPos.SetText( rPos.copy( ++nSrch ) );
     214           0 :             aAktTableName = pWrtShell->GetTableFmt()->GetName();
     215             :         }
     216             :         else
     217           0 :             aPos.SetText(SW_RESSTR(STR_TBL_FORMULA));
     218             : 
     219             :         // Edit current field
     220             :         OSL_ENSURE(pMgr == 0, "FieldManager not deleted");
     221           0 :         pMgr = new SwFldMgr;
     222             : 
     223             :         // Formular should always begin with "=" , so set here
     224           0 :         OUString sEdit('=');
     225           0 :         if( pMgr->GetCurFld() && TYP_FORMELFLD == pMgr->GetCurTypeId() )
     226             :         {
     227           0 :             sEdit += pMgr->GetCurFldPar2();
     228             :         }
     229           0 :         else if( bFirst )
     230             :         {
     231           0 :             if( bIsTable )
     232             :             {
     233           0 :                 m_bResetUndo = true;
     234             :                 SAL_WARN_IF(
     235             :                     officecfg::Office::Common::Undo::Steps::get() <= 0,
     236             :                     "sw", "/org.openoffice.Office.Common/Undo/Steps <= 0");
     237             : 
     238           0 :                 m_bDoesUndo = pWrtShell->DoesUndo();
     239           0 :                 if( !m_bDoesUndo )
     240             :                 {
     241           0 :                     pWrtShell->DoUndo( sal_True );
     242             :                 }
     243             : 
     244           0 :                 if( !pWrtShell->SwCrsrShell::HasSelection() )
     245             :                 {
     246           0 :                     pWrtShell->MoveSection( fnSectionCurr, fnSectionStart );
     247           0 :                     pWrtShell->SetMark();
     248           0 :                     pWrtShell->MoveSection( fnSectionCurr, fnSectionEnd );
     249             :                 }
     250           0 :                 if( pWrtShell->SwCrsrShell::HasSelection() )
     251             :                 {
     252           0 :                     pWrtShell->StartUndo( UNDO_DELETE );
     253           0 :                     pWrtShell->Delete();
     254           0 :                     if( 0 != pWrtShell->EndUndo( UNDO_DELETE ))
     255             :                     {
     256           0 :                         m_bCallUndo = true;
     257             :                     }
     258             :                 }
     259           0 :                 pWrtShell->DoUndo(false);
     260             : 
     261           0 :                 SfxItemSet aSet( pWrtShell->GetAttrPool(), RES_BOXATR_FORMULA, RES_BOXATR_FORMULA );
     262           0 :                 if( pWrtShell->GetTblBoxFormulaAttrs( aSet ))
     263           0 :                     sEdit += ((SwTblBoxFormula&)aSet.Get( RES_BOXATR_FORMULA )).GetFormula();
     264             :             }
     265             :         }
     266             : 
     267           0 :         if( bFirst )
     268             :         {
     269             :             // Set WrtShell flags correctly
     270           0 :             pWrtShell->SttSelect();
     271           0 :             pWrtShell->EndSelect();
     272             :         }
     273             : 
     274           0 :         bFirst = sal_False;
     275             : 
     276           0 :         aEdit.SetModifyHdl( LINK( this, SwInputWindow, ModifyHdl ));
     277             : 
     278           0 :         aEdit.SetText( sEdit );
     279           0 :         aEdit.SetSelection( Selection( sEdit.getLength(), sEdit.getLength() ) );
     280           0 :         sOldFml = sEdit;
     281             : 
     282           0 :         aEdit.Invalidate();
     283           0 :         aEdit.Update();
     284           0 :         aEdit.GrabFocus();
     285             :         // For input cut the UserInterface
     286             : 
     287           0 :         pView->GetEditWin().LockKeyInput(sal_True);
     288           0 :         pView->GetViewFrame()->GetDispatcher()->Lock(true);
     289           0 :         pWrtShell->Push();
     290             :     }
     291           0 :     ToolBox::Show();
     292           0 : }
     293             : 
     294           0 : IMPL_LINK( SwInputWindow, MenuHdl, Menu *, pMenu )
     295             : {
     296             : static const char * const aStrArr[] = {
     297             :     sCalc_Phd,
     298             :     sCalc_Sqrt,
     299             :     sCalc_Or,
     300             :     sCalc_Xor,
     301             :     sCalc_And,
     302             :     sCalc_Not,
     303             :     sCalc_Eq,
     304             :     sCalc_Neq,
     305             :     sCalc_Leq,
     306             :     sCalc_Geq,
     307             :     sCalc_L,
     308             :     sCalc_G,
     309             :     sCalc_Sum,
     310             :     sCalc_Mean,
     311             :     sCalc_Min,
     312             :     sCalc_Max,
     313             :     sCalc_Sin,
     314             :     sCalc_Cos,
     315             :     sCalc_Tan,
     316             :     sCalc_Asin,
     317             :     sCalc_Acos,
     318             :     sCalc_Atan,
     319             :     sCalc_Pow,
     320             :     "|",
     321             :     sCalc_Round
     322             : };
     323             : 
     324           0 :     sal_uInt16 nId = pMenu->GetCurItemId();
     325           0 :     if ( nId <= MN_CALC_ROUND )
     326             :     {
     327           0 :         OUString aTmp( OUString::createFromAscii(aStrArr[nId - 1]) );
     328           0 :         aTmp += " ";
     329           0 :         aEdit.ReplaceSelected( aTmp );
     330             :     }
     331           0 :     return 0;
     332             : }
     333             : 
     334           0 : IMPL_LINK_NOARG(SwInputWindow, DropdownClickHdl)
     335             : {
     336           0 :     sal_uInt16 nCurID = GetCurItemId();
     337           0 :     EndSelection(); // reset back CurItemId !
     338           0 :     switch ( nCurID )
     339             :     {
     340             :         case FN_FORMULA_CALC :
     341             :         {
     342           0 :             aPopMenu.Execute( this, GetItemRect( FN_FORMULA_CALC ), POPUPMENU_NOMOUSEUPCLOSE );
     343           0 :             break;
     344             :         default:
     345           0 :             break;
     346             :         }
     347             :     }
     348             : 
     349           0 :     return sal_True;
     350             : }
     351             : 
     352           0 : void SwInputWindow::Click( )
     353             : {
     354           0 :     sal_uInt16 nCurID = GetCurItemId();
     355           0 :     EndSelection(); // reset back CurItemId !
     356           0 :     switch ( nCurID )
     357             :     {
     358             :         case FN_FORMULA_CANCEL:
     359             :         {
     360           0 :             CancelFormula();
     361             :         }
     362           0 :         break;
     363             :         case FN_FORMULA_APPLY:
     364             :         {
     365           0 :             ApplyFormula();
     366             :         }
     367           0 :         break;
     368             :    }
     369           0 : }
     370             : 
     371           0 : void  SwInputWindow::ApplyFormula()
     372             : {
     373           0 :     pView->GetViewFrame()->GetDispatcher()->Lock(false);
     374           0 :     pView->GetEditWin().LockKeyInput(sal_False);
     375           0 :     CleanupUglyHackWithUndo();
     376           0 :     pWrtShell->Pop( sal_False );
     377             : 
     378             :     // Formular should always begin with "=", so remove it here again
     379           0 :     OUString sEdit(comphelper::string::strip(aEdit.GetText(), ' '));
     380           0 :     if( !sEdit.isEmpty() && '=' == sEdit[0] )
     381           0 :         sEdit = sEdit.copy( 1 );
     382           0 :     SfxStringItem aParam(FN_EDIT_FORMULA, sEdit);
     383             : 
     384           0 :     pWrtShell->EndSelTblCells();
     385           0 :     pView->GetEditWin().GrabFocus();
     386             :     const SfxPoolItem* aArgs[2];
     387           0 :     aArgs[0] = &aParam;
     388           0 :     aArgs[1] = 0;
     389           0 :     pView->GetViewFrame()->GetBindings().Execute( FN_EDIT_FORMULA, aArgs, 0, SFX_CALLMODE_ASYNCHRON );
     390           0 : }
     391             : 
     392           0 : void  SwInputWindow::CancelFormula()
     393             : {
     394           0 :     if(pView)
     395             :     {
     396           0 :         pView->GetViewFrame()->GetDispatcher()->Lock( false );
     397           0 :         pView->GetEditWin().LockKeyInput(sal_False);
     398           0 :         CleanupUglyHackWithUndo();
     399           0 :         pWrtShell->Pop( sal_False );
     400             : 
     401           0 :         if( bDelSel )
     402           0 :             pWrtShell->EnterStdMode();
     403             : 
     404           0 :         pWrtShell->EndSelTblCells();
     405             : 
     406           0 :         pView->GetEditWin().GrabFocus();
     407             : 
     408           0 :         pView->GetViewFrame()->GetDispatcher()->Execute( FN_EDIT_FORMULA, SFX_CALLMODE_ASYNCHRON);
     409             :     }
     410           0 : }
     411             : 
     412             : const sal_Unicode CH_LRE = 0x202a;
     413             : const sal_Unicode CH_PDF = 0x202c;
     414             : 
     415           0 : IMPL_LINK( SwInputWindow, SelTblCellsNotify, SwWrtShell *, pCaller )
     416             : {
     417           0 :     if(bIsTable)
     418             :     {
     419           0 :         SwFrmFmt* pTblFmt = pCaller->GetTableFmt();
     420           0 :         OUString sBoxNms( pCaller->GetBoxNms() );
     421           0 :         OUString sTblNm;
     422           0 :         if( pTblFmt && aAktTableName != pTblFmt->GetName() )
     423           0 :             sTblNm = pTblFmt->GetName();
     424             : 
     425           0 :         aEdit.UpdateRange( sBoxNms, sTblNm );
     426             : 
     427           0 :         OUString sNew;
     428           0 :         sNew += OUString(CH_LRE);
     429           0 :         sNew += aEdit.GetText();
     430           0 :         sNew += OUString(CH_PDF);
     431             : 
     432           0 :         if( sNew != sOldFml )
     433             :         {
     434             :             // The WrtShell is in the table selection,
     435             :             // then cancel the table selection otherwise, the cursor is
     436             :             // positioned "in the forest" and the live update does not work!
     437           0 :             pWrtShell->StartAllAction();
     438             : 
     439           0 :             SwPaM aPam( *pWrtShell->GetStkCrsr()->GetPoint() );
     440           0 :             aPam.Move( fnMoveBackward, fnGoSection );
     441           0 :             aPam.SetMark();
     442           0 :             aPam.Move( fnMoveForward, fnGoSection );
     443             : 
     444           0 :             IDocumentContentOperations* pIDCO = pWrtShell->getIDocumentContentOperations();
     445           0 :             pIDCO->DeleteRange( aPam );
     446           0 :             pIDCO->InsertString( aPam, sNew );
     447           0 :             pWrtShell->EndAllAction();
     448           0 :             sOldFml = sNew;
     449           0 :         }
     450             :     }
     451             :     else
     452           0 :         aEdit.GrabFocus();
     453           0 :     return 0;
     454             : }
     455             : 
     456           0 : void SwInputWindow::SetFormula( const OUString& rFormula, sal_Bool bDelFlag )
     457             : {
     458           0 :     OUString sEdit('=');
     459           0 :     if( !rFormula.isEmpty() )
     460             :     {
     461           0 :         if( '=' == rFormula[0] )
     462           0 :             sEdit = rFormula;
     463             :         else
     464           0 :             sEdit += rFormula;
     465             :     }
     466           0 :     aEdit.SetText( sEdit );
     467           0 :     aEdit.SetSelection( Selection( sEdit.getLength(), sEdit.getLength() ) );
     468           0 :     aEdit.Invalidate();
     469           0 :     bDelSel = bDelFlag;
     470           0 : }
     471             : 
     472           0 : IMPL_LINK_NOARG(SwInputWindow, ModifyHdl)
     473             : {
     474           0 :     if (bIsTable && m_bResetUndo)
     475             :     {
     476           0 :         pWrtShell->StartAllAction();
     477           0 :         DelBoxCntnt();
     478           0 :         OUString sNew;
     479           0 :         sNew += OUString(CH_LRE);
     480           0 :         sNew += aEdit.GetText();
     481           0 :         sNew += OUString(CH_PDF);
     482           0 :         pWrtShell->SwEditShell::Insert2( sNew );
     483           0 :         pWrtShell->EndAllAction();
     484           0 :         sOldFml = sNew;
     485             :     }
     486           0 :     return 0;
     487             : }
     488             : 
     489           0 : void SwInputWindow::DelBoxCntnt()
     490             : {
     491           0 :     if( bIsTable )
     492             :     {
     493           0 :         pWrtShell->StartAllAction();
     494           0 :         pWrtShell->ClearMark();
     495           0 :         pWrtShell->Pop( sal_False );
     496           0 :         pWrtShell->Push();
     497           0 :         pWrtShell->MoveSection( fnSectionCurr, fnSectionStart );
     498           0 :         pWrtShell->SetMark();
     499           0 :         pWrtShell->MoveSection( fnSectionCurr, fnSectionEnd );
     500           0 :         pWrtShell->SwEditShell::Delete();
     501           0 :         pWrtShell->EndAllAction();
     502             :     }
     503           0 : }
     504             : 
     505           0 : void InputEdit::KeyInput(const KeyEvent& rEvent)
     506             : {
     507           0 :     const KeyCode aCode = rEvent.GetKeyCode();
     508           0 :     if(aCode == KEY_RETURN || aCode == KEY_F2 )
     509           0 :         ((SwInputWindow*)GetParent())->ApplyFormula();
     510           0 :     else if(aCode == KEY_ESCAPE )
     511           0 :         ((SwInputWindow*)GetParent())->CancelFormula();
     512             :     else
     513           0 :         Edit::KeyInput(rEvent);
     514           0 : }
     515             : 
     516           0 : void InputEdit::UpdateRange(const OUString& rBoxes,
     517             :                                     const OUString& rName )
     518             : {
     519           0 :     if( rBoxes.isEmpty() )
     520             :     {
     521           0 :         GrabFocus();
     522           0 :         return;
     523             :     }
     524           0 :     const sal_Unicode   cOpen = '<', cClose = '>',
     525           0 :                 cOpenBracket = '(';
     526           0 :     OUString aPrefix = rName;
     527           0 :     if(!rName.isEmpty())
     528           0 :         aPrefix += ".";
     529           0 :     OUString aBoxes = aPrefix;
     530           0 :     aBoxes += rBoxes;
     531           0 :     Selection aSelection(GetSelection());
     532           0 :     sal_uInt16 nSel = (sal_uInt16) aSelection.Len();
     533             :     // OS: The following expression ensures that in the overwrite mode,
     534             :     // the selected closing parenthesis will be not deleted.
     535           0 :     if( nSel && ( nSel > 1 ||
     536           0 :                   GetText()[ (sal_uInt16)aSelection.Min() ] != cClose ))
     537           0 :         Cut();
     538             :     else
     539           0 :         aSelection.Max() = aSelection.Min();
     540           0 :     OUString aActText(GetText());
     541           0 :     const sal_uInt16 nLen = aActText.getLength();
     542           0 :     if( !nLen )
     543             :     {
     544             :         OUString aStr = OUStringBuffer().
     545           0 :             append(cOpen).append(aBoxes).append(cClose).
     546           0 :             makeStringAndClear();
     547           0 :         SetText(aStr);
     548           0 :         sal_Int32 nPos = aStr.indexOf( cClose );
     549             :         OSL_ENSURE(nPos != -1, "delimiter not found");
     550           0 :         ++nPos;
     551           0 :         SetSelection( Selection( nPos, nPos ));
     552             :     }
     553             :     else
     554             :     {
     555           0 :         bool bFound = false;
     556             :         sal_Unicode cCh;
     557           0 :         sal_uInt16 nPos, nEndPos = 0, nStartPos = (sal_uInt16) aSelection.Min();
     558           0 :         if( nStartPos-- )
     559             :         {
     560           0 :             do {
     561           0 :                 if( cOpen  == (cCh = aActText[ nStartPos ] ) ||
     562             :                     cOpenBracket == cCh )
     563             :                 {
     564           0 :                     bFound = cCh == cOpen;
     565           0 :                     break;
     566             :                 }
     567           0 :             } while( nStartPos-- > 0 );
     568             :         }
     569           0 :         if( bFound )
     570             :         {
     571           0 :             bFound = false;
     572           0 :             nEndPos = nStartPos;
     573           0 :             while( nEndPos < nLen )
     574             :             {
     575           0 :                 if( cClose == (cCh = aActText[ nEndPos ]))
     576             :                 {
     577           0 :                     bFound = true;
     578           0 :                     break;
     579             :                 }
     580           0 :                 ++nEndPos;
     581             :             }
     582             :             // Only if the current position lies in the range or right behind.
     583           0 :             if( bFound && !( nStartPos < (sal_uInt16)aSelection.Max() &&
     584           0 :                              (sal_uInt16)aSelection.Max() <= nEndPos + 1 ))
     585           0 :                 bFound = false;
     586             :         }
     587           0 :         if( bFound )
     588             :         {
     589           0 :             nPos = ++nStartPos + 1; // We want behind
     590           0 :             aActText = aActText.replaceAt( nStartPos, nEndPos - nStartPos, aBoxes );
     591           0 :             nPos = nPos + aBoxes.getLength();
     592             :         }
     593             :         else
     594             :         {
     595             :             OUString aTmp = OUStringBuffer().
     596           0 :                 append(cOpen).append(aBoxes).append(cClose).
     597           0 :                 makeStringAndClear();
     598           0 :             nPos = (sal_uInt16)aSelection.Min();
     599           0 :             aActText = aActText.replaceAt( nPos, 0, aTmp );
     600           0 :             nPos = nPos + aTmp.getLength();
     601             :         }
     602           0 :         if( GetText() != OUString(aActText) )
     603             :         {
     604           0 :             SetText( aActText );
     605           0 :             SetSelection( Selection( nPos, nPos ) );
     606             :         }
     607             :     }
     608           0 :     GrabFocus();
     609             : 
     610             : }
     611             : 
     612           0 : SwInputChild::SwInputChild(Window* _pParent,
     613             :                                 sal_uInt16 nId,
     614             :                                 SfxBindings* pBindings,
     615             :                                 SfxChildWinInfo* ) :
     616           0 :                                 SfxChildWindow( _pParent, nId )
     617             : {
     618           0 :     pDispatch = pBindings->GetDispatcher();
     619           0 :     pWindow = new SwInputWindow( _pParent, pBindings );
     620           0 :     ((SwInputWindow*)pWindow)->ShowWin();
     621           0 :     eChildAlignment = SFX_ALIGN_LOWESTTOP;
     622           0 : }
     623             : 
     624           0 : SwInputChild::~SwInputChild()
     625             : {
     626           0 :     if(pDispatch)
     627           0 :         pDispatch->Lock(false);
     628           0 : }
     629             : 
     630           0 : SfxChildWinInfo SwInputChild::GetInfo() const
     631             : {
     632           0 :     SfxChildWinInfo aInfo = SfxChildWindow::GetInfo();     \
     633           0 :     return aInfo;
     634             : }
     635             : 
     636             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10