LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/pagedlg - tphfedit.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 1 207 0.5 %
Date: 2013-07-09 Functions: 2 36 5.6 %
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 "scitems.hxx"
      21             : #include <editeng/eeitem.hxx>
      22             : 
      23             : 
      24             : #include <editeng/editobj.hxx>
      25             : #include <editeng/editstat.hxx>
      26             : #include <editeng/editview.hxx>
      27             : #include <editeng/flditem.hxx>
      28             : #include <editeng/adjustitem.hxx>
      29             : #include <sfx2/basedlgs.hxx>
      30             : #include <sfx2/objsh.hxx>
      31             : #include <vcl/msgbox.hxx>
      32             : #include <vcl/svapp.hxx>
      33             : 
      34             : #include "tphfedit.hxx"
      35             : #include "editutil.hxx"
      36             : #include "global.hxx"
      37             : #include "attrib.hxx"
      38             : #include "patattr.hxx"
      39             : #include "scresid.hxx"
      40             : #include "sc.hrc"
      41             : #include "globstr.hrc"
      42             : #include "tabvwsh.hxx"
      43             : #include "prevwsh.hxx"
      44             : #include "AccessibleEditObject.hxx"
      45             : 
      46             : #include "scabstdlg.hxx"
      47             : 
      48             : 
      49             : // STATIC DATA -----------------------------------------------------------
      50             : static ScEditWindow* pActiveEdWnd = NULL;
      51             : 
      52           0 : ScEditWindow* GetScEditWindow ()
      53             : {
      54           0 :     return pActiveEdWnd;
      55             : }
      56             : 
      57             : //========================================================================
      58             : 
      59           0 : static void lcl_GetFieldData( ScHeaderFieldData& rData )
      60             : {
      61           0 :     SfxViewShell* pShell = SfxViewShell::Current();
      62           0 :     if (pShell)
      63             :     {
      64           0 :         if (pShell->ISA(ScTabViewShell))
      65           0 :             ((ScTabViewShell*)pShell)->FillFieldData(rData);
      66           0 :         else if (pShell->ISA(ScPreviewShell))
      67           0 :             ((ScPreviewShell*)pShell)->FillFieldData(rData);
      68             :     }
      69           0 : }
      70             : 
      71             : //========================================================================
      72             : // class ScEditWindow
      73             : //========================================================================
      74             : 
      75           0 : ScEditWindow::ScEditWindow( Window* pParent, WinBits nBits, ScEditWindowLocation eLoc )
      76             :     :   Control( pParent, nBits ),
      77             :     eLocation(eLoc),
      78           0 :     pAcc(NULL)
      79             : {
      80           0 :     EnableRTL(false);
      81             : 
      82           0 :     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
      83           0 :     Color aBgColor = rStyleSettings.GetWindowColor();
      84             : 
      85           0 :     SetMapMode( MAP_TWIP );
      86           0 :     SetPointer( POINTER_TEXT );
      87           0 :     SetBackground( aBgColor );
      88             : 
      89           0 :     Size aSize( GetOutputSize() );
      90           0 :     aSize.Height() *= 4;
      91             : 
      92           0 :     pEdEngine = new ScHeaderEditEngine( EditEngine::CreatePool(), sal_True );
      93           0 :     pEdEngine->SetPaperSize( aSize );
      94           0 :     pEdEngine->SetRefDevice( this );
      95             : 
      96           0 :     ScHeaderFieldData aData;
      97           0 :     lcl_GetFieldData( aData );
      98             : 
      99             :         //  Feldbefehle:
     100           0 :     pEdEngine->SetData( aData );
     101           0 :     pEdEngine->SetControlWord( pEdEngine->GetControlWord() | EE_CNTRL_MARKFIELDS );
     102           0 :     mbRTL = ScGlobal::IsSystemRTL();
     103           0 :     if (mbRTL)
     104           0 :         pEdEngine->SetDefaultHorizontalTextDirection(EE_HTEXTDIR_R2L);
     105             : 
     106           0 :     pEdView = new EditView( pEdEngine, this );
     107           0 :     pEdView->SetOutputArea( Rectangle( Point(0,0), GetOutputSize() ) );
     108             : 
     109           0 :     pEdView->SetBackgroundColor( aBgColor );
     110           0 :     pEdEngine->InsertView( pEdView );
     111           0 : }
     112             : 
     113           0 : void ScEditWindow::Resize()
     114             : {
     115           0 :     Size aOutputSize(GetOutputSize());
     116           0 :     Size aSize(aOutputSize);
     117           0 :     aSize.Height() *= 4;
     118           0 :     pEdEngine->SetPaperSize(aSize);
     119           0 :     pEdView->SetOutputArea(Rectangle(Point(0,0), aOutputSize));
     120           0 :     Control::Resize();
     121           0 : }
     122             : 
     123             : // -----------------------------------------------------------------------
     124             : 
     125           0 : ScEditWindow::~ScEditWindow()
     126             : {
     127             :     // delete Accessible object before deleting EditEngine and EditView
     128           0 :     if (pAcc)
     129             :     {
     130           0 :         ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
     131           0 :         if (xTemp.is())
     132           0 :             pAcc->dispose();
     133             :     }
     134           0 :     delete pEdEngine;
     135           0 :     delete pEdView;
     136           0 : }
     137             : 
     138           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeScEditWindow(Window *pParent, VclBuilder::stringmap &)
     139             : {
     140           0 :     return new ScEditWindow (pParent, WB_BORDER|WB_TABSTOP, Left);
     141             : }
     142             : 
     143             : // -----------------------------------------------------------------------
     144             : 
     145           0 : void ScEditWindow::SetNumType(SvxNumType eNumType)
     146             : {
     147           0 :     pEdEngine->SetNumType(eNumType);
     148           0 :     pEdEngine->UpdateFields();
     149           0 : }
     150             : 
     151             : // -----------------------------------------------------------------------
     152             : 
     153           0 : EditTextObject* ScEditWindow::CreateTextObject()
     154             : {
     155             :     //  Absatzattribute zuruecksetzen
     156             :     //  (GetAttribs beim Format-Dialog-Aufruf gibt immer gesetzte Items zurueck)
     157             : 
     158           0 :     const SfxItemSet& rEmpty = pEdEngine->GetEmptyItemSet();
     159           0 :     sal_Int32 nParCnt = pEdEngine->GetParagraphCount();
     160           0 :     for (sal_Int32 i=0; i<nParCnt; i++)
     161           0 :         pEdEngine->SetParaAttribs( i, rEmpty );
     162             : 
     163           0 :     return pEdEngine->CreateTextObject();
     164             : }
     165             : 
     166             : // -----------------------------------------------------------------------
     167             : 
     168           0 : void ScEditWindow::SetFont( const ScPatternAttr& rPattern )
     169             : {
     170           0 :     SfxItemSet* pSet = new SfxItemSet( pEdEngine->GetEmptyItemSet() );
     171           0 :     rPattern.FillEditItemSet( pSet );
     172             :     //  FillEditItemSet adjusts font height to 1/100th mm,
     173             :     //  but for header/footer twips is needed, as in the PatternAttr:
     174           0 :     pSet->Put( rPattern.GetItem(ATTR_FONT_HEIGHT), EE_CHAR_FONTHEIGHT );
     175           0 :     pSet->Put( rPattern.GetItem(ATTR_CJK_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CJK );
     176           0 :     pSet->Put( rPattern.GetItem(ATTR_CTL_FONT_HEIGHT), EE_CHAR_FONTHEIGHT_CTL );
     177           0 :     if (mbRTL)
     178           0 :         pSet->Put( SvxAdjustItem( SVX_ADJUST_RIGHT, EE_PARA_JUST ) );
     179           0 :     pEdEngine->SetDefaults( pSet );
     180           0 : }
     181             : 
     182             : // -----------------------------------------------------------------------
     183             : 
     184           0 : void ScEditWindow::SetText( const EditTextObject& rTextObject )
     185             : {
     186           0 :     pEdEngine->SetText( rTextObject );
     187           0 : }
     188             : 
     189             : // -----------------------------------------------------------------------
     190             : 
     191           0 : void ScEditWindow::InsertField( const SvxFieldItem& rFld )
     192             : {
     193           0 :     pEdView->InsertField( rFld );
     194           0 : }
     195             : 
     196             : // -----------------------------------------------------------------------
     197             : 
     198           0 : void ScEditWindow::SetCharAttriutes()
     199             : {
     200           0 :     SfxObjectShell* pDocSh  = SfxObjectShell::Current();
     201             : 
     202           0 :     SfxViewShell*       pViewSh = SfxViewShell::Current();
     203             : 
     204           0 :     ScTabViewShell* pTabViewSh = PTR_CAST(ScTabViewShell, SfxViewShell::Current());
     205             : 
     206             : 
     207             :     OSL_ENSURE( pDocSh,  "Current DocShell not found" );
     208             :     OSL_ENSURE( pViewSh, "Current ViewShell not found" );
     209             : 
     210           0 :     if ( pDocSh && pViewSh )
     211             :     {
     212           0 :         if(pTabViewSh!=NULL) pTabViewSh->SetInFormatDialog(sal_True);
     213             : 
     214           0 :         SfxItemSet aSet( pEdView->GetAttribs() );
     215             : 
     216           0 :         ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
     217             :         OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
     218             : 
     219             :         SfxAbstractTabDialog* pDlg = pFact->CreateScCharDlg(  GetParent(),  &aSet,
     220           0 :                                                             pDocSh,RID_SCDLG_CHAR );
     221             :         OSL_ENSURE(pDlg, "Dialog create fail!");
     222           0 :         pDlg->SetText( ScGlobal::GetRscString( STR_TEXTATTRS ) );
     223           0 :         if ( pDlg->Execute() == RET_OK )
     224             :         {
     225           0 :             aSet.ClearItem();
     226           0 :             aSet.Put( *pDlg->GetOutputItemSet() );
     227           0 :             pEdView->SetAttribs( aSet );
     228             :         }
     229             : 
     230           0 :         if(pTabViewSh!=NULL) pTabViewSh->SetInFormatDialog(false);
     231           0 :         delete pDlg;
     232             :     }
     233           0 : }
     234             : 
     235             : // -----------------------------------------------------------------------
     236             : 
     237           0 : void ScEditWindow::Paint( const Rectangle& rRect )
     238             : {
     239           0 :     const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
     240           0 :     Color aBgColor = rStyleSettings.GetWindowColor();
     241             : 
     242           0 :     pEdView->SetBackgroundColor( aBgColor );
     243             : 
     244           0 :     SetBackground( aBgColor );
     245             : 
     246           0 :     Control::Paint( rRect );
     247             : 
     248           0 :     pEdView->Paint( rRect );
     249           0 : }
     250             : 
     251             : // -----------------------------------------------------------------------
     252             : 
     253           0 : void ScEditWindow::MouseMove( const MouseEvent& rMEvt )
     254             : {
     255           0 :     pEdView->MouseMove( rMEvt );
     256           0 : }
     257             : 
     258             : // -----------------------------------------------------------------------
     259             : 
     260           0 : void ScEditWindow::MouseButtonDown( const MouseEvent& rMEvt )
     261             : {
     262           0 :     if ( !HasFocus() )
     263           0 :         GrabFocus();
     264             : 
     265           0 :     pEdView->MouseButtonDown( rMEvt );
     266           0 : }
     267             : 
     268             : // -----------------------------------------------------------------------
     269             : 
     270           0 : void ScEditWindow::MouseButtonUp( const MouseEvent& rMEvt )
     271             : {
     272           0 :     pEdView->MouseButtonUp( rMEvt );
     273           0 : }
     274             : 
     275             : // -----------------------------------------------------------------------
     276             : 
     277           0 : void ScEditWindow::KeyInput( const KeyEvent& rKEvt )
     278             : {
     279           0 :     sal_uInt16 nKey =  rKEvt.GetKeyCode().GetModifier()
     280           0 :                  + rKEvt.GetKeyCode().GetCode();
     281             : 
     282           0 :     if ( nKey == KEY_TAB || nKey == KEY_TAB + KEY_SHIFT )
     283             :     {
     284           0 :         Control::KeyInput( rKEvt );
     285             :     }
     286           0 :     else if ( !pEdView->PostKeyEvent( rKEvt ) )
     287             :     {
     288           0 :         Control::KeyInput( rKEvt );
     289             :     }
     290           0 : }
     291             : 
     292             : // -----------------------------------------------------------------------
     293             : 
     294           0 : void ScEditWindow::Command( const CommandEvent& rCEvt )
     295             : {
     296           0 :     pEdView->Command( rCEvt );
     297           0 : }
     298             : 
     299             : // -----------------------------------------------------------------------
     300             : 
     301           0 : void ScEditWindow::GetFocus()
     302             : {
     303           0 :     pActiveEdWnd = this;
     304             : 
     305           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
     306           0 :     if (xTemp.is() && pAcc)
     307             :     {
     308           0 :         pAcc->GotFocus();
     309             :     }
     310             :     else
     311           0 :         pAcc = NULL;
     312           0 : }
     313             : 
     314           0 : void ScEditWindow::LoseFocus()
     315             : {
     316           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xTemp = xAcc;
     317           0 :     if (xTemp.is() && pAcc)
     318             :     {
     319           0 :         pAcc->LostFocus();
     320             :     }
     321             :     else
     322           0 :         pAcc = NULL;
     323           0 : }
     324             : 
     325             : // -----------------------------------------------------------------------
     326             : 
     327           0 : ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > ScEditWindow::CreateAccessible()
     328             : {
     329           0 :     String sName;
     330           0 :     String sDescription(GetHelpText());
     331           0 :     switch (eLocation)
     332             :     {
     333             :     case Left:
     334             :         {
     335           0 :             sName = String(ScResId(STR_ACC_LEFTAREA_NAME));
     336             :         }
     337           0 :         break;
     338             :     case Center:
     339             :         {
     340           0 :             sName = String(ScResId(STR_ACC_CENTERAREA_NAME));
     341             :         }
     342           0 :         break;
     343             :     case Right:
     344             :         {
     345           0 :             sName = String(ScResId(STR_ACC_RIGHTAREA_NAME));
     346             :         }
     347           0 :         break;
     348             :     }
     349             :     pAcc = new ScAccessibleEditObject(GetAccessibleParentWindow()->GetAccessible(), pEdView, this,
     350           0 :         OUString(sName), OUString(sDescription), ScAccessibleEditObject::EditControl);
     351           0 :     ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAccessible = pAcc;
     352           0 :     xAcc = xAccessible;
     353           0 :     return pAcc;
     354             : }
     355             : 
     356           0 : ScExtIButton::ScExtIButton(Window* pParent, WinBits nBits )
     357           0 :     : ImageButton(pParent,nBits), pPopupMenu(NULL)
     358             : {
     359           0 :     nSelected=0;
     360           0 :     aTimer.SetTimeout(600);
     361           0 :     SetDropDown( true);
     362           0 : }
     363             : 
     364           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeScExtIButton(Window *pParent, VclBuilder::stringmap &)
     365             : {
     366           0 :     return new ScExtIButton (pParent, 0);// WB_BORDER|WB_TABSTOP);
     367             : }
     368             : 
     369           0 : void ScExtIButton::SetPopupMenu(PopupMenu* pPopUp)
     370             : {
     371           0 :     pPopupMenu=pPopUp;
     372           0 : }
     373             : 
     374           0 : sal_uInt16 ScExtIButton::GetSelected() const
     375             : {
     376           0 :     return nSelected;
     377             : }
     378             : 
     379           0 : OString ScExtIButton::GetSelectedIdent() const
     380             : {
     381           0 :     return aSelectedIdent;
     382             : }
     383             : 
     384           0 : void ScExtIButton::MouseButtonDown( const MouseEvent& rMEvt )
     385             : {
     386           0 :     if(!aTimer.IsActive())
     387             :     {
     388           0 :         aTimer.Start();
     389           0 :         aTimer.SetTimeoutHdl(LINK( this, ScExtIButton, TimerHdl));
     390             :     }
     391             : 
     392           0 :     ImageButton::MouseButtonDown(rMEvt );
     393           0 : }
     394             : 
     395           0 : void ScExtIButton::MouseButtonUp( const MouseEvent& rMEvt)
     396             : {
     397           0 :     aTimer.Stop();
     398           0 :     aTimer.SetTimeoutHdl(Link());
     399           0 :     ImageButton::MouseButtonUp(rMEvt );
     400           0 : }
     401             : 
     402           0 : void ScExtIButton::Click()
     403             : {
     404           0 :     aTimer.Stop();
     405           0 :     aTimer.SetTimeoutHdl(Link());
     406           0 :     ImageButton::Click();
     407           0 : }
     408             : 
     409           0 : void ScExtIButton::StartPopup()
     410             : {
     411           0 :     nSelected=0;
     412           0 :     aSelectedIdent = OString();
     413             : 
     414           0 :     if(pPopupMenu!=NULL)
     415             :     {
     416           0 :         SetPressed( sal_True );
     417           0 :         EndSelection();
     418           0 :         Point aPoint(0,0);
     419           0 :         aPoint.Y()=GetOutputSizePixel().Height();
     420             : 
     421           0 :         nSelected = pPopupMenu->Execute( this, aPoint );
     422             : 
     423           0 :         if(nSelected)
     424             :         {
     425           0 :             aSelectedIdent = pPopupMenu->GetItemIdent(nSelected);
     426           0 :             aMLink.Call(this);
     427             :         }
     428             : 
     429           0 :         SetPressed( false);
     430             :     }
     431           0 : }
     432             : 
     433           0 : long ScExtIButton::PreNotify( NotifyEvent& rNEvt )
     434             : {
     435           0 :     sal_uInt16 nSwitch=rNEvt.GetType();
     436           0 :     if(nSwitch==EVENT_MOUSEBUTTONUP)
     437             :     {
     438           0 :         MouseButtonUp(*rNEvt.GetMouseEvent());
     439             :     }
     440             : 
     441           0 :     return ImageButton::PreNotify(rNEvt );
     442             : }
     443             : 
     444           0 : IMPL_LINK_NOARG(ScExtIButton, TimerHdl)
     445             : {
     446           0 :     StartPopup();
     447           0 :     return 0;
     448          93 : }
     449             : 
     450             : 
     451             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10