LCOV - code coverage report
Current view: top level - svx/source/dialog - rubydialog.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 2 534 0.4 %
Date: 2014-04-11 Functions: 3 60 5.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <svx/rubydialog.hxx>
      21             : #include <tools/shl.hxx>
      22             : #include <svx/dialmgr.hxx>
      23             : #include <svx/dialogs.hrc>
      24             : #include <sfx2/app.hxx>
      25             : #include <sfx2/dispatch.hxx>
      26             : #include <sfx2/viewfrm.hxx>
      27             : #include <svl/eitem.hxx>
      28             : #include <com/sun/star/frame/XController.hpp>
      29             : #include <com/sun/star/style/XStyle.hpp>
      30             : #include <com/sun/star/text/XRubySelection.hpp>
      31             : #include <com/sun/star/beans/PropertyValues.hpp>
      32             : #include <com/sun/star/beans/XPropertySet.hpp>
      33             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      34             : #include <com/sun/star/container/XNameContainer.hpp>
      35             : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
      36             : #include <com/sun/star/text/RubyAdjust.hpp>
      37             : #include <com/sun/star/view/XSelectionChangeListener.hpp>
      38             : #include <com/sun/star/view/XSelectionSupplier.hpp>
      39             : #include <cppuhelper/implbase1.hxx>
      40             : #include <svtools/colorcfg.hxx>
      41             : #include <vcl/layout.hxx>
      42             : #include <vcl/settings.hxx>
      43             : 
      44             : using namespace com::sun::star::uno;
      45             : using namespace com::sun::star::frame;
      46             : using namespace com::sun::star::text;
      47             : using namespace com::sun::star::beans;
      48             : using namespace com::sun::star::style;
      49             : using namespace com::sun::star::view;
      50             : using namespace com::sun::star::lang;
      51             : using namespace com::sun::star::container;
      52             : 
      53          37 : SFX_IMPL_CHILDWINDOW( SvxRubyChildWindow, SID_RUBY_DIALOG );
      54             : 
      55             : static const sal_Char cRubyBaseText[] = "RubyBaseText";
      56             : static const sal_Char cRubyText[] = "RubyText";
      57             : static const sal_Char cCharacterStyles[] = "CharacterStyles";
      58             : static const sal_Char cRubyAdjust[] = "RubyAdjust";
      59             : static const sal_Char cRubyIsAbove[] = "RubyIsAbove";
      60             : static const sal_Char cDisplayName[] = "DisplayName";
      61             : static const sal_Char cRubyCharStyleName[] = "RubyCharStyleName";
      62             : static const sal_Char cRubies[] = "Rubies";
      63             : 
      64           0 : SvxRubyChildWindow::SvxRubyChildWindow( Window* _pParent, sal_uInt16 nId,
      65             :     SfxBindings* pBindings, SfxChildWinInfo* pInfo) :
      66           0 :     SfxChildWindow(_pParent, nId)
      67             : {
      68           0 :     SvxRubyDialog* pDlg = new SvxRubyDialog(pBindings, this, _pParent);
      69           0 :     pWindow = pDlg;
      70             : 
      71           0 :     if ( pInfo->nFlags & SFX_CHILDWIN_ZOOMIN )
      72           0 :         pDlg->RollUp();
      73             : 
      74           0 :     eChildAlignment = SFX_ALIGN_NOALIGNMENT;
      75             : 
      76           0 :     pDlg->Initialize( pInfo );
      77           0 : }
      78             : 
      79           0 : SfxChildWinInfo SvxRubyChildWindow::GetInfo() const
      80             : {
      81           0 :     return SfxChildWindow::GetInfo();
      82             : }
      83             : 
      84             : class SvxRubyData_Impl : public cppu::WeakImplHelper1
      85             :                                 <  ::com::sun::star::view::XSelectionChangeListener >
      86             : {
      87             :     Reference<XModel>               xModel;
      88             :     Reference<XRubySelection>       xSelection;
      89             :     Sequence<PropertyValues>        aRubyValues;
      90             :     Reference<XController>          xController;
      91             :     bool                            bHasSelectionChanged;
      92             :     public:
      93             :         SvxRubyData_Impl();
      94             :         virtual ~SvxRubyData_Impl();
      95             : 
      96             :     void    SetController(Reference<XController> xCtrl);
      97           0 :     Reference<XModel>               GetModel()
      98             :                                     {
      99           0 :                                         if(!xController.is())
     100           0 :                                             xModel = 0;
     101             :                                         else
     102           0 :                                             xModel = xController->getModel();
     103           0 :                                         return xModel;
     104             :                                     }
     105           0 :     bool                            HasSelectionChanged() const{return bHasSelectionChanged;}
     106           0 :     Reference<XRubySelection>       GetRubySelection()
     107             :                                     {
     108           0 :                                         xSelection = Reference<XRubySelection>(xController, UNO_QUERY);
     109           0 :                                         return xSelection;
     110             :                                     }
     111           0 :     void                            UpdateRubyValues()
     112             :                                     {
     113           0 :                                         if(!xSelection.is())
     114           0 :                                             aRubyValues.realloc(0);
     115             :                                         else
     116           0 :                                             aRubyValues = xSelection->getRubyList(false);
     117           0 :                                         bHasSelectionChanged = false;
     118           0 :                                     }
     119           0 :     Sequence<PropertyValues>&       GetRubyValues() {return aRubyValues;}
     120             :     void                            AssertOneEntry();
     121             : 
     122             :     virtual void SAL_CALL selectionChanged( const ::com::sun::star::lang::EventObject& aEvent ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     123             :     virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
     124             : 
     125             : };
     126             : 
     127           0 : SvxRubyData_Impl::SvxRubyData_Impl() :
     128           0 :     bHasSelectionChanged(false)
     129             : {
     130           0 : }
     131             : 
     132           0 : SvxRubyData_Impl::~SvxRubyData_Impl()
     133             : {
     134           0 : }
     135             : 
     136           0 : void    SvxRubyData_Impl::SetController(Reference<XController> xCtrl)
     137             : {
     138           0 :     if(xCtrl.get() != xController.get())
     139             :     {
     140             :         try
     141             :         {
     142           0 :             Reference<XSelectionSupplier> xSelSupp(xController, UNO_QUERY);
     143           0 :             if(xSelSupp.is())
     144           0 :                 xSelSupp->removeSelectionChangeListener(this);
     145             : 
     146           0 :             bHasSelectionChanged = true;
     147           0 :             xController = xCtrl;
     148           0 :             xSelSupp = Reference<XSelectionSupplier>(xController, UNO_QUERY);
     149           0 :             if(xSelSupp.is())
     150           0 :                 xSelSupp->addSelectionChangeListener(this);
     151             :         }
     152           0 :         catch (const Exception&)
     153             :         {
     154             :         }
     155             :     }
     156           0 : }
     157             : 
     158           0 : void SvxRubyData_Impl::selectionChanged( const EventObject& ) throw (RuntimeException, std::exception)
     159             : {
     160           0 :     bHasSelectionChanged = true;
     161           0 : }
     162             : 
     163           0 : void SvxRubyData_Impl::disposing( const EventObject&) throw (RuntimeException, std::exception)
     164             : {
     165             :     try
     166             :     {
     167           0 :         Reference<XSelectionSupplier> xSelSupp(xController, UNO_QUERY);
     168           0 :         if(xSelSupp.is())
     169           0 :             xSelSupp->removeSelectionChangeListener(this);
     170             :     }
     171           0 :     catch (const Exception&)
     172             :     {
     173             :     }
     174           0 :     xController = 0;
     175           0 : }
     176             : 
     177           0 : void  SvxRubyData_Impl::AssertOneEntry()
     178             : {
     179             :     //create one entry
     180           0 :     if(!aRubyValues.getLength())
     181             :     {
     182           0 :         aRubyValues.realloc(1);
     183           0 :         Sequence<PropertyValue>& rValues = aRubyValues.getArray()[0];
     184           0 :         rValues.realloc(5);
     185           0 :         PropertyValue* pValues = rValues.getArray();
     186           0 :         pValues[0].Name = cRubyBaseText;
     187           0 :         pValues[1].Name = cRubyText;
     188           0 :         pValues[2].Name = cRubyAdjust;
     189           0 :         pValues[3].Name = cRubyIsAbove;
     190           0 :         pValues[4].Name = cRubyCharStyleName;
     191             :     }
     192           0 : }
     193             : 
     194           0 : SvxRubyDialog::SvxRubyDialog(SfxBindings *pBind, SfxChildWindow *pCW,
     195             :                                     Window* _pParent)
     196             :     : SfxModelessDialog(pBind, pCW, _pParent, "AsianPhoneticGuideDialog",
     197             :         "svx/ui/asianphoneticguidedialog.ui")
     198             :     , nLastPos(0)
     199             :     , nCurrentEdit(0)
     200             :     , bModified(false)
     201           0 :     , pBindings(pBind)
     202             : {
     203           0 :     xImpl = pImpl = new SvxRubyData_Impl;
     204           0 :     get(m_pLeftFT, "basetextft");
     205           0 :     get(m_pRightFT, "rubytextft");
     206           0 :     get(m_pAdjustLB, "adjustlb");
     207           0 :     get(m_pPositionLB, "positionlb");
     208           0 :     get(m_pCharStyleFT, "styleft");
     209           0 :     get(m_pCharStyleLB, "stylelb");
     210           0 :     m_pCharStyleLB->SetStyle(m_pCharStyleLB->GetStyle() | WB_SORT);
     211           0 :     get(m_pStylistPB, "styles");
     212           0 :     get(m_pApplyPB, "apply");
     213           0 :     get(m_pClosePB, "close");
     214           0 :     get(m_pPreviewWin, "preview");
     215           0 :     m_pPreviewWin->setRubyDialog(this);
     216           0 :     get(m_pScrolledWindow, "scrolledwindow");
     217           0 :     m_pScrolledWindow->setUserManagedScrolling(true);
     218           0 :     m_pScrollSB = &m_pScrolledWindow->getVertScrollBar();
     219           0 :     get(m_pLeft1ED, "Left1ED");
     220           0 :     get(m_pRight1ED, "Right1ED");
     221           0 :     get(m_pLeft2ED, "Left2ED");
     222           0 :     get(m_pRight2ED, "Right2ED");
     223           0 :     get(m_pLeft3ED, "Left3ED");
     224           0 :     get(m_pRight3ED, "Right3ED");
     225           0 :     get(m_pLeft4ED, "Left4ED");
     226           0 :     get(m_pRight4ED, "Right4ED");
     227           0 :     aEditArr[0] = m_pLeft1ED; aEditArr[1] = m_pRight1ED;
     228           0 :     aEditArr[2] = m_pLeft2ED; aEditArr[3] = m_pRight2ED;
     229           0 :     aEditArr[4] = m_pLeft3ED; aEditArr[5] = m_pRight3ED;
     230           0 :     aEditArr[6] = m_pLeft4ED; aEditArr[7] = m_pRight4ED;
     231             : 
     232           0 :     m_pApplyPB->SetClickHdl(LINK(this, SvxRubyDialog, ApplyHdl_Impl));
     233           0 :     m_pClosePB->SetClickHdl(LINK(this, SvxRubyDialog, CloseHdl_Impl));
     234           0 :     m_pStylistPB->SetClickHdl(LINK(this, SvxRubyDialog, StylistHdl_Impl));
     235           0 :     m_pAdjustLB->SetSelectHdl(LINK(this, SvxRubyDialog, AdjustHdl_Impl));
     236           0 :     m_pPositionLB->SetSelectHdl(LINK(this, SvxRubyDialog, PositionHdl_Impl));
     237           0 :     m_pCharStyleLB->SetSelectHdl(LINK(this, SvxRubyDialog, CharStyleHdl_Impl));
     238             : 
     239           0 :     Link aScrLk(LINK(this, SvxRubyDialog, ScrollHdl_Impl));
     240           0 :     m_pScrollSB->SetScrollHdl( aScrLk );
     241           0 :     m_pScrollSB->SetEndScrollHdl( aScrLk );
     242             : 
     243           0 :     Link aEditLk(LINK(this, SvxRubyDialog, EditModifyHdl_Impl));
     244           0 :     Link aScrollLk(LINK(this, SvxRubyDialog, EditScrollHdl_Impl));
     245           0 :     Link aJumpLk(LINK(this, SvxRubyDialog, EditJumpHdl_Impl));
     246           0 :     for(sal_uInt16 i = 0; i < 8; i++)
     247             :     {
     248           0 :         aEditArr[i]->SetModifyHdl(aEditLk);
     249           0 :         aEditArr[i]->SetJumpHdl(aJumpLk);
     250           0 :         if(!i || 7 == i)
     251           0 :             aEditArr[i]->SetScrollHdl(aScrollLk);
     252             :     }
     253             : 
     254           0 :     UpdateColors();
     255             : 
     256           0 :     OUString leftLabelName = m_pLeftFT->GetText(), rightLabelName = m_pRightFT->GetText();
     257           0 :     m_pLeft2ED->SetAccessibleName(leftLabelName);
     258           0 :     m_pLeft3ED->SetAccessibleName(leftLabelName);
     259           0 :     m_pLeft4ED->SetAccessibleName(leftLabelName);
     260           0 :     m_pRight2ED->SetAccessibleName(rightLabelName);
     261           0 :     m_pRight3ED->SetAccessibleName(rightLabelName);
     262           0 :     m_pRight4ED->SetAccessibleName(rightLabelName);
     263           0 : }
     264             : 
     265           0 : SvxRubyDialog::~SvxRubyDialog()
     266             : {
     267           0 :     ClearCharStyleList();
     268           0 :     EventObject aEvent;
     269           0 :     xImpl->disposing(aEvent);
     270           0 : }
     271             : 
     272           0 : void SvxRubyDialog::ClearCharStyleList()
     273             : {
     274           0 :     for(sal_uInt16 i = 0; i < m_pCharStyleLB->GetEntryCount(); i++)
     275             :     {
     276           0 :         void* pData = m_pCharStyleLB->GetEntryData(i);
     277           0 :         delete (OUString*)pData;
     278             :     }
     279           0 :     m_pCharStyleLB->Clear();
     280           0 : }
     281             : 
     282           0 : bool    SvxRubyDialog::Close()
     283             : {
     284             :     pBindings->GetDispatcher()->Execute( SID_RUBY_DIALOG,
     285             :                               SFX_CALLMODE_ASYNCHRON |
     286           0 :                               SFX_CALLMODE_RECORD);
     287           0 :     return true;
     288             : }
     289             : 
     290           0 : void SvxRubyDialog::Activate()
     291             : {
     292           0 :     SfxModelessDialog::Activate();
     293           0 :     SfxPoolItem* pState = 0;
     294           0 :     SfxItemState    eState = pBindings->QueryState( SID_STYLE_DESIGNER, pState );
     295           0 :     sal_Bool bEnable = (eState < SFX_ITEM_AVAILABLE) || !pState || !((SfxBoolItem*)pState)->GetValue();
     296           0 :     delete pState;
     297           0 :     m_pStylistPB->Enable(bEnable);
     298             :     //get selection from current view frame
     299           0 :     SfxViewFrame* pCurFrm = SfxViewFrame::Current();
     300           0 :     Reference< XController > xCtrl = pCurFrm->GetFrame().GetController();
     301           0 :     pImpl->SetController(xCtrl);
     302           0 :     if(pImpl->HasSelectionChanged())
     303             :     {
     304             : 
     305           0 :         Reference< XRubySelection > xRubySel = pImpl->GetRubySelection();
     306           0 :         pImpl->UpdateRubyValues();
     307           0 :         EnableControls(xRubySel.is());
     308           0 :         if(xRubySel.is())
     309             :         {
     310           0 :             Reference< XModel > xModel = pImpl->GetModel();
     311           0 :             const OUString sCharStyleSelect = m_pCharStyleLB->GetSelectEntry();
     312           0 :             ClearCharStyleList();
     313           0 :             Reference<XStyleFamiliesSupplier> xSupplier(xModel, UNO_QUERY);
     314           0 :             if(xSupplier.is())
     315             :             {
     316             :                 try
     317             :                 {
     318           0 :                     Reference<XNameAccess> xFam = xSupplier->getStyleFamilies();
     319           0 :                     Any aChar = xFam->getByName(cCharacterStyles);
     320           0 :                     Reference<XNameContainer> xChar;
     321           0 :                     aChar >>= xChar;
     322           0 :                     Reference<XIndexAccess> xCharIdx(xChar, UNO_QUERY);
     323           0 :                     if(xCharIdx.is())
     324             :                     {
     325           0 :                         OUString sUIName(cDisplayName);
     326           0 :                         for(sal_Int32 nStyle = 0; nStyle < xCharIdx->getCount(); nStyle++)
     327             :                         {
     328           0 :                             Any aStyle = xCharIdx->getByIndex(nStyle);
     329           0 :                             Reference<XStyle> xStyle;
     330           0 :                             aStyle >>= xStyle;
     331           0 :                             Reference<XPropertySet> xPrSet(xStyle, UNO_QUERY);
     332           0 :                             OUString sName, sCoreName;
     333           0 :                             if(xPrSet.is())
     334             :                             {
     335           0 :                                 Reference<XPropertySetInfo> xInfo = xPrSet->getPropertySetInfo();
     336           0 :                                 if(xInfo->hasPropertyByName(sUIName))
     337             :                                 {
     338           0 :                                     Any aName = xPrSet->getPropertyValue(sUIName);
     339           0 :                                     aName >>= sName;
     340           0 :                                 }
     341             :                             }
     342           0 :                             if(xStyle.is())
     343             :                             {
     344           0 :                                 sCoreName = xStyle->getName();
     345           0 :                                 if(sName.isEmpty())
     346           0 :                                     sName = sCoreName;
     347             :                             }
     348           0 :                             if(!sName.isEmpty())
     349             :                             {
     350           0 :                                 sal_uInt16 nPos = m_pCharStyleLB->InsertEntry(sName);
     351           0 :                                 m_pCharStyleLB->SetEntryData( nPos, new OUString(sCoreName) );
     352             : 
     353             :                             }
     354           0 :                         }
     355           0 :                     }
     356             :                 }
     357           0 :                 catch (const Exception&)
     358             :                 {
     359             :                     OSL_FAIL("exception in style access");
     360             :                 }
     361           0 :                 if(!sCharStyleSelect.isEmpty())
     362           0 :                     m_pCharStyleLB->SelectEntry(sCharStyleSelect);
     363             :             }
     364           0 :             m_pCharStyleLB->Enable(xSupplier.is());
     365           0 :             m_pCharStyleFT->Enable(xSupplier.is());
     366             :         }
     367           0 :         Update();
     368           0 :         m_pPreviewWin->Invalidate();
     369           0 :     }
     370           0 : }
     371             : 
     372           0 : void    SvxRubyDialog::Deactivate()
     373             : {
     374           0 :     SfxModelessDialog::Deactivate();
     375           0 : }
     376             : 
     377           0 : void SvxRubyDialog::SetRubyText(sal_Int32 nPos, Edit& rLeft, Edit& rRight)
     378             : {
     379           0 :     OUString sLeft, sRight;
     380           0 :     const Sequence<PropertyValues>&  aRubyValues = pImpl->GetRubyValues();
     381           0 :     sal_Bool bEnable = aRubyValues.getLength() > nPos;
     382           0 :     if(bEnable)
     383             :     {
     384           0 :         const Sequence<PropertyValue> aProps = aRubyValues.getConstArray()[nPos];
     385           0 :         const PropertyValue* pProps = aProps.getConstArray();
     386           0 :         for(sal_Int32 nProp = 0; nProp < aProps.getLength(); nProp++)
     387             :         {
     388           0 :             if ( pProps[nProp].Name == cRubyBaseText )
     389           0 :                 pProps[nProp].Value >>= sLeft;
     390           0 :             else if ( pProps[nProp].Name == cRubyText )
     391           0 :                 pProps[nProp].Value >>= sRight;
     392           0 :         }
     393             :     }
     394           0 :     else if(!nPos)
     395           0 :         bEnable = sal_True;
     396           0 :     rLeft.Enable(bEnable);
     397           0 :     rRight.Enable(bEnable);
     398           0 :     rLeft.SetText(sLeft);
     399           0 :     rRight.SetText(sRight);
     400           0 :     rLeft.SaveValue();
     401           0 :     rRight.SaveValue();
     402           0 : }
     403             : 
     404           0 : void SvxRubyDialog::GetRubyText()
     405             : {
     406           0 :     long nTempLastPos = GetLastPos();
     407           0 :     for(int i = 0; i < 8; i+=2)
     408             :     {
     409           0 :         if(aEditArr[i]->IsEnabled() &&
     410           0 :            (aEditArr[i]->GetText() != aEditArr[i]->GetSavedValue() ||
     411           0 :             aEditArr[i + 1]->GetText() != aEditArr[i + 1]->GetSavedValue()))
     412             :         {
     413           0 :             Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
     414             :             DBG_ASSERT(aRubyValues.getLength() > (i / 2 + nTempLastPos), "wrong index" );
     415           0 :             SetModified(true);
     416           0 :             Sequence<PropertyValue> &rProps = aRubyValues.getArray()[i / 2 + nTempLastPos];
     417           0 :             PropertyValue* pProps = rProps.getArray();
     418           0 :             for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
     419             :             {
     420           0 :                 if ( pProps[nProp].Name == cRubyBaseText )
     421           0 :                     pProps[nProp].Value <<= OUString(aEditArr[i]->GetText());
     422           0 :                 else if ( pProps[nProp].Name == cRubyText )
     423           0 :                     pProps[nProp].Value <<= OUString(aEditArr[i + 1]->GetText());
     424             :             }
     425             :         }
     426             :     }
     427           0 : }
     428             : 
     429           0 : void SvxRubyDialog::Update()
     430             : {
     431           0 :     const Sequence<PropertyValues>& aRubyValues = pImpl->GetRubyValues();
     432           0 :     sal_Int32 nLen = aRubyValues.getLength();
     433           0 :     m_pScrollSB->Enable(nLen > 4);
     434           0 :     m_pScrollSB->SetRange( Range(0, nLen > 4 ? nLen - 4 : 0));
     435           0 :     m_pScrollSB->SetThumbPos(0);
     436           0 :     SetLastPos(0);
     437           0 :     SetModified(false);
     438             : 
     439           0 :     sal_Int16 nAdjust = -1;
     440           0 :     sal_Int16 nPosition = -1;
     441           0 :     OUString sCharStyleName, sTmp;
     442           0 :     bool bCharStyleEqual = true;
     443           0 :     for(sal_Int32 nRuby = 0; nRuby < nLen; nRuby++)
     444             :     {
     445           0 :         const Sequence<PropertyValue> &rProps = aRubyValues.getConstArray()[nRuby];
     446           0 :         const PropertyValue* pProps = rProps.getConstArray();
     447           0 :         for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
     448             :         {
     449           0 :             if(nAdjust > -2 && pProps[nProp].Name == cRubyAdjust )
     450             :             {
     451           0 :                 sal_Int16 nTmp = sal_Int16();
     452           0 :                 pProps[nProp].Value >>= nTmp;
     453           0 :                 if(!nRuby)
     454           0 :                     nAdjust = nTmp;
     455           0 :                 else if(nAdjust != nTmp)
     456           0 :                     nAdjust = -2;
     457             :             }
     458           0 :             if(nPosition > -2 && pProps[nProp].Name == cRubyIsAbove )
     459             :             {
     460           0 :                 sal_Bool bTmp = *(sal_Bool*)pProps[nProp].Value.getValue();
     461           0 :                 if(!nRuby)
     462           0 :                     nPosition = bTmp ? 0 : 1;
     463           0 :                 else if( (!nPosition && !bTmp) || (nPosition == 1 && bTmp)  )
     464           0 :                     nPosition = -2;
     465             :             }
     466           0 :             if(bCharStyleEqual && pProps[nProp].Name == cRubyCharStyleName )
     467             :             {
     468           0 :                 pProps[nProp].Value >>= sTmp;
     469           0 :                 if(!nRuby)
     470           0 :                     sCharStyleName = sTmp;
     471           0 :                 else if(sCharStyleName != sTmp)
     472           0 :                     bCharStyleEqual = false;
     473             :             }
     474             :         }
     475             :     }
     476           0 :     if(!nLen)
     477             :     {
     478             :         //enable selection if the ruby list is empty
     479           0 :         nAdjust = 0;
     480           0 :         nPosition = 0;
     481             :     }
     482           0 :     if(nAdjust > -1)
     483           0 :         m_pAdjustLB->SelectEntryPos(nAdjust);
     484             :     else
     485           0 :         m_pAdjustLB->SetNoSelection();
     486           0 :     if(nPosition > -1)
     487           0 :         m_pPositionLB->SelectEntryPos(nPosition ? 1 : 0);
     488           0 :     if(!nLen || (bCharStyleEqual && sCharStyleName.isEmpty()))
     489           0 :         sCharStyleName = cRubies;
     490           0 :     if(!sCharStyleName.isEmpty())
     491             :     {
     492           0 :         for(sal_uInt16 i = 0; i < m_pCharStyleLB->GetEntryCount(); i++)
     493             :         {
     494           0 :             const OUString* pCoreName = (const OUString*)m_pCharStyleLB->GetEntryData(i);
     495           0 :             if(pCoreName && sCharStyleName == *pCoreName)
     496             :             {
     497           0 :                 m_pCharStyleLB->SelectEntryPos(i);
     498           0 :                 break;
     499             :             }
     500             :         }
     501             :     }
     502             :     else
     503           0 :         m_pCharStyleLB->SetNoSelection();
     504             : 
     505           0 :     ScrollHdl_Impl(m_pScrollSB);
     506           0 : }
     507             : 
     508           0 : void    SvxRubyDialog::GetCurrentText(OUString& rBase, OUString& rRuby)
     509             : {
     510           0 :     rBase = aEditArr[nCurrentEdit * 2]->GetText();
     511           0 :     rRuby = aEditArr[nCurrentEdit * 2 + 1]->GetText();
     512           0 : }
     513             : 
     514           0 : IMPL_LINK(SvxRubyDialog, ScrollHdl_Impl, ScrollBar*, pScroll)
     515             : {
     516           0 :     long nPos = pScroll->GetThumbPos();
     517           0 :     if(GetLastPos() != nPos)
     518             :     {
     519           0 :         GetRubyText();
     520             :     }
     521           0 :     SetRubyText(nPos++, *m_pLeft1ED, *m_pRight1ED);
     522           0 :     SetRubyText(nPos++, *m_pLeft2ED, *m_pRight2ED);
     523           0 :     SetRubyText(nPos++, *m_pLeft3ED, *m_pRight3ED);
     524           0 :     SetRubyText(nPos, *m_pLeft4ED, *m_pRight4ED);
     525           0 :     SetLastPos(nPos - 3);
     526           0 :     m_pPreviewWin->Invalidate();
     527           0 :     return 0;
     528             : }
     529             : 
     530           0 : IMPL_LINK_NOARG(SvxRubyDialog, ApplyHdl_Impl)
     531             : {
     532           0 :     const Sequence<PropertyValues>&  aRubyValues = pImpl->GetRubyValues();
     533           0 :     if(!aRubyValues.getLength())
     534             :     {
     535           0 :         AssertOneEntry();
     536           0 :         PositionHdl_Impl(m_pPositionLB);
     537           0 :         AdjustHdl_Impl(m_pAdjustLB);
     538           0 :         CharStyleHdl_Impl(m_pCharStyleLB);
     539             :     }
     540           0 :     GetRubyText();
     541             :     //reset all edit fields - SaveValue is called
     542           0 :     ScrollHdl_Impl(m_pScrollSB);
     543             : 
     544           0 :     Reference<XRubySelection>  xSelection = pImpl->GetRubySelection();
     545           0 :     if(IsModified() && xSelection.is())
     546             :     {
     547             :         try
     548             :         {
     549           0 :             xSelection->setRubyList(aRubyValues, false);
     550             :         }
     551           0 :         catch (const Exception&)
     552             :         {
     553             :             OSL_FAIL("Exception caught");
     554             :         }
     555             :     }
     556           0 :     return 0;
     557             : }
     558             : 
     559           0 : IMPL_LINK_NOARG(SvxRubyDialog, CloseHdl_Impl)
     560             : {
     561           0 :     Close();
     562           0 :     return 0;
     563             : }
     564             : 
     565           0 : IMPL_LINK_NOARG(SvxRubyDialog, StylistHdl_Impl)
     566             : {
     567           0 :     SfxPoolItem* pState = 0;
     568           0 :     SfxItemState    eState = pBindings->QueryState( SID_STYLE_DESIGNER, pState );
     569           0 :     if(eState <= SFX_ITEM_SET || !pState || !((SfxBoolItem*)pState)->GetValue())
     570             :     {
     571             :         pBindings->GetDispatcher()->Execute( SID_STYLE_DESIGNER,
     572             :                               SFX_CALLMODE_ASYNCHRON |
     573           0 :                               SFX_CALLMODE_RECORD);
     574             :     }
     575           0 :     delete pState;
     576           0 :     return 0;
     577             : }
     578             : 
     579           0 : IMPL_LINK(SvxRubyDialog, AdjustHdl_Impl, ListBox*, pBox)
     580             : {
     581           0 :     AssertOneEntry();
     582           0 :     sal_Int16 nAdjust = pBox->GetSelectEntryPos();
     583           0 :     Sequence<PropertyValues>&  aRubyValues = pImpl->GetRubyValues();
     584           0 :     for(sal_Int32 nRuby = 0; nRuby < aRubyValues.getLength(); nRuby++)
     585             :     {
     586           0 :         Sequence<PropertyValue> &rProps = aRubyValues.getArray()[nRuby];
     587           0 :         PropertyValue* pProps = rProps.getArray();
     588           0 :         for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
     589             :         {
     590           0 :             if ( pProps[nProp].Name == cRubyAdjust )
     591           0 :                 pProps[nProp].Value <<= nAdjust;
     592             :         }
     593           0 :         SetModified(true);
     594             :     }
     595           0 :     m_pPreviewWin->Invalidate();
     596           0 :     return 0;
     597             : }
     598             : 
     599           0 : IMPL_LINK(SvxRubyDialog, PositionHdl_Impl, ListBox*, pBox)
     600             : {
     601           0 :     AssertOneEntry();
     602           0 :     sal_Bool bAbove = !pBox->GetSelectEntryPos();
     603           0 :     const Type& rType = ::getBooleanCppuType();
     604           0 :     Sequence<PropertyValues>&  aRubyValues = pImpl->GetRubyValues();
     605           0 :     for(sal_Int32 nRuby = 0; nRuby < aRubyValues.getLength(); nRuby++)
     606             :     {
     607           0 :         Sequence<PropertyValue> &rProps = aRubyValues.getArray()[nRuby];
     608           0 :         PropertyValue* pProps = rProps.getArray();
     609           0 :         for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
     610             :         {
     611           0 :             if ( pProps[nProp].Name == cRubyIsAbove )
     612           0 :                 pProps[nProp].Value.setValue(&bAbove, rType);
     613             :         }
     614           0 :         SetModified(true);
     615             :     }
     616           0 :     m_pPreviewWin->Invalidate();
     617           0 :     return 0;
     618             : }
     619             : 
     620           0 : IMPL_LINK_NOARG(SvxRubyDialog, CharStyleHdl_Impl)
     621             : {
     622           0 :     AssertOneEntry();
     623           0 :     OUString sStyleName;
     624           0 :     if(LISTBOX_ENTRY_NOTFOUND != m_pCharStyleLB->GetSelectEntryPos())
     625           0 :         sStyleName = *(OUString*) m_pCharStyleLB->GetEntryData(m_pCharStyleLB->GetSelectEntryPos());
     626           0 :     Sequence<PropertyValues>&  aRubyValues = pImpl->GetRubyValues();
     627           0 :     for(sal_Int32 nRuby = 0; nRuby < aRubyValues.getLength(); nRuby++)
     628             :     {
     629           0 :         Sequence<PropertyValue> &rProps = aRubyValues.getArray()[nRuby];
     630           0 :         PropertyValue* pProps = rProps.getArray();
     631           0 :         for(sal_Int32 nProp = 0; nProp < rProps.getLength(); nProp++)
     632             :         {
     633           0 :             if ( pProps[nProp].Name == cRubyCharStyleName )
     634             :             {
     635           0 :                 pProps[nProp].Value <<= sStyleName;
     636             :             }
     637             :         }
     638           0 :         SetModified(true);
     639             :     }
     640           0 :     return 0;
     641             : }
     642             : 
     643           0 : IMPL_LINK(SvxRubyDialog, EditModifyHdl_Impl, Edit*, pEdit)
     644             : {
     645           0 :     for(sal_uInt16 i = 0; i < 8; i++)
     646             :     {
     647           0 :         if(pEdit == aEditArr[i])
     648             :         {
     649           0 :             nCurrentEdit = i / 2;
     650           0 :             break;
     651             :         }
     652             :     }
     653           0 :     m_pPreviewWin->Invalidate();
     654           0 :     return 0;
     655             : }
     656             : 
     657           0 : IMPL_LINK(SvxRubyDialog, EditScrollHdl_Impl, sal_Int32*, pParam)
     658             : {
     659           0 :     long nRet = 0;
     660           0 :     if(m_pScrollSB->IsEnabled())
     661             :     {
     662             :         //scroll forward
     663           0 :         if(*pParam > 0 && (aEditArr[7]->HasFocus() || aEditArr[6]->HasFocus() ))
     664             :         {
     665           0 :             if(m_pScrollSB->GetRangeMax() > m_pScrollSB->GetThumbPos())
     666             :             {
     667           0 :                 m_pScrollSB->SetThumbPos(m_pScrollSB->GetThumbPos() + 1);
     668           0 :                 aEditArr[6]->GrabFocus();
     669           0 :                 nRet = 1;
     670             :             }
     671             :         }
     672             :         //scroll backward
     673           0 :         else if(m_pScrollSB->GetThumbPos() && (aEditArr[0]->HasFocus()||aEditArr[1]->HasFocus()) )
     674             :         {
     675           0 :             m_pScrollSB->SetThumbPos(m_pScrollSB->GetThumbPos() - 1);
     676           0 :             aEditArr[1]->GrabFocus();
     677           0 :             nRet = 1;
     678             :         }
     679           0 :         if(nRet)
     680           0 :             ScrollHdl_Impl(m_pScrollSB);
     681             :     }
     682           0 :     return nRet;
     683             : }
     684             : 
     685           0 : IMPL_LINK(SvxRubyDialog, EditJumpHdl_Impl, sal_Int32*, pParam)
     686             : {
     687           0 :     sal_uInt16 nIndex = USHRT_MAX;
     688           0 :     for(sal_uInt16 i = 0; i < 8; i++)
     689             :     {
     690           0 :         if(aEditArr[i]->HasFocus())
     691           0 :             nIndex = i;
     692             :     }
     693           0 :     if(nIndex < 8)
     694             :     {
     695           0 :         if(*pParam > 0)
     696             :         {
     697           0 :             if(nIndex < 6)
     698           0 :                 aEditArr[nIndex + 2]->GrabFocus();
     699           0 :             else if( EditScrollHdl_Impl(pParam))
     700           0 :                 aEditArr[nIndex]->GrabFocus();
     701             :         }
     702             :         else
     703             :         {
     704           0 :             if(nIndex > 1)
     705           0 :                 aEditArr[nIndex - 2]->GrabFocus();
     706           0 :             else if( EditScrollHdl_Impl(pParam))
     707           0 :                 aEditArr[nIndex]->GrabFocus();
     708             :         }
     709             :     }
     710           0 :     return 0;
     711             : };
     712             : 
     713           0 : void SvxRubyDialog::AssertOneEntry()
     714             : {
     715           0 :     pImpl->AssertOneEntry();
     716           0 : }
     717             : 
     718             : 
     719             : 
     720           0 : void SvxRubyDialog::UpdateColors( void )
     721             : {
     722           0 :     const StyleSettings&    rStyleSettings = GetSettings().GetStyleSettings();
     723           0 :     svtools::ColorConfig        aColorConfig;
     724             : 
     725           0 :     Font                    aFnt( m_pPreviewWin->GetFont() );
     726             : 
     727           0 :     Color                   aNewTextCol( aColorConfig.GetColorValue( svtools::FONTCOLOR ).nColor );
     728           0 :     Color                   aNewFillCol( rStyleSettings.GetWindowColor() );
     729             : 
     730           0 :     if( aNewFillCol != aFnt.GetFillColor() || aNewTextCol != aFnt.GetColor() )
     731             :     {
     732           0 :         aFnt.SetFillColor( aNewFillCol );
     733           0 :         aFnt.SetColor( aNewTextCol );
     734           0 :         m_pPreviewWin->SetFont( aFnt );
     735             : 
     736           0 :         m_pPreviewWin->Invalidate();
     737           0 :     }
     738           0 : }
     739             : 
     740             : 
     741             : 
     742           0 : void SvxRubyDialog::DataChanged( const DataChangedEvent& rDCEvt )
     743             : {
     744           0 :     SfxModelessDialog::DataChanged( rDCEvt );
     745             : 
     746           0 :     if( ( rDCEvt.GetType() == DATACHANGED_SETTINGS ) && ( rDCEvt.GetFlags() & SETTINGS_STYLE ) )
     747           0 :         UpdateColors();
     748           0 : }
     749             : 
     750           0 : void SvxRubyDialog::EnableControls(bool bEnable)
     751             : {
     752           0 :     get_content_area()->Enable(bEnable);
     753           0 :     m_pApplyPB->Enable(bEnable);
     754           0 : }
     755             : 
     756           0 : RubyPreview::RubyPreview(Window *pParent)
     757             :     : Window(pParent, WB_BORDER)
     758           0 :     , m_pParentDlg(NULL)
     759             : {
     760           0 :     SetMapMode(MAP_TWIP);
     761           0 :     SetBorderStyle( WINDOW_BORDER_MONO );
     762           0 : }
     763             : 
     764           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeRubyPreview(Window *pParent, VclBuilder::stringmap &)
     765             : {
     766           0 :     return new RubyPreview(pParent);
     767             : }
     768             : 
     769           0 : void RubyPreview::Paint( const Rectangle& /* rRect */ )
     770             : {
     771           0 :     Size aWinSize = GetOutputSize();
     772             : 
     773           0 :     Font aSaveFont = GetFont();
     774           0 :     aSaveFont.SetHeight(aWinSize.Height() / 4);
     775           0 :     SetFont(aSaveFont);
     776             : 
     777           0 :     Rectangle aRect(Point(0, 0), aWinSize);
     778           0 :     SetLineColor();
     779           0 :     SetFillColor( aSaveFont.GetFillColor() );
     780           0 :     DrawRect(aRect);
     781             : 
     782           0 :     OUString sBaseText, sRubyText;
     783           0 :     m_pParentDlg->GetCurrentText(sBaseText, sRubyText);
     784             : 
     785           0 :     long nTextHeight = GetTextHeight();
     786           0 :     long nBaseWidth = GetTextWidth(sBaseText);
     787             : 
     788           0 :     Font aRubyFont(aSaveFont);
     789           0 :     aRubyFont.SetHeight(aRubyFont.GetHeight() * 70 / 100);
     790           0 :     SetFont(aRubyFont);
     791           0 :     long nRubyWidth = GetTextWidth(sRubyText);
     792           0 :     SetFont(aSaveFont);
     793             : 
     794           0 :     sal_uInt16 nAdjust = m_pParentDlg->m_pAdjustLB->GetSelectEntryPos();
     795             :     //use center if no adjustment is available
     796           0 :     if(nAdjust > 4)
     797           0 :         nAdjust = 1;
     798             : 
     799             :     //which part is stretched ?
     800           0 :     bool bRubyStretch = nBaseWidth >= nRubyWidth;
     801             : 
     802           0 :     long nCenter = aWinSize.Width() / 2;
     803           0 :     long nLeftStart = nCenter - (bRubyStretch ? (nBaseWidth / 2) : (nRubyWidth / 2));
     804           0 :     long nRightEnd = nCenter + (bRubyStretch ? (nBaseWidth / 2) : (nRubyWidth / 2));
     805             : 
     806           0 :     long nYRuby = aWinSize.Height() / 4 - nTextHeight / 2;
     807           0 :     long nYBase = aWinSize.Height() * 3 / 4 - nTextHeight / 2;
     808             : 
     809             :     //use above also if no selection is set
     810           0 :     bool bAbove = m_pParentDlg->m_pPositionLB->GetSelectEntryPos() != 1;
     811           0 :     if(!bAbove)
     812             :     {
     813           0 :         long nTmp = nYRuby;
     814           0 :         nYRuby = nYBase;
     815           0 :         nYBase = nTmp;
     816             :     }
     817             :     long nYOutput, nOutTextWidth;
     818           0 :     OUString sOutputText;
     819             : 
     820             : 
     821           0 :     if(bRubyStretch)
     822             :     {
     823           0 :         DrawText( Point( nLeftStart , nYBase),  sBaseText );
     824           0 :         nYOutput = nYRuby;
     825           0 :         sOutputText = sRubyText;
     826           0 :         nOutTextWidth = nRubyWidth;
     827           0 :         SetFont(aRubyFont);
     828             :     }
     829             :     else
     830             :     {
     831           0 :         SetFont(aRubyFont);
     832           0 :         DrawText( Point( nLeftStart , nYRuby),  sRubyText );
     833           0 :         nYOutput = nYBase;
     834           0 :         sOutputText = sBaseText;
     835           0 :         nOutTextWidth = nBaseWidth;
     836           0 :         SetFont(aSaveFont);
     837             :     }
     838             : 
     839           0 :     switch(nAdjust)
     840             :     {
     841             :         case RubyAdjust_LEFT:
     842           0 :             DrawText( Point( nLeftStart , nYOutput),  sOutputText );
     843           0 :         break;
     844             :         case RubyAdjust_RIGHT:
     845           0 :             DrawText( Point( nRightEnd - nOutTextWidth, nYOutput),  sOutputText );
     846           0 :         break;
     847             :         case RubyAdjust_INDENT_BLOCK:
     848             :         {
     849           0 :             long nCharWidth = GetTextWidth(OUString("X"));
     850           0 :             if(nOutTextWidth < (nRightEnd - nLeftStart - nCharWidth))
     851             :             {
     852           0 :                 nCharWidth /= 2;
     853           0 :                 nLeftStart += nCharWidth;
     854           0 :                 nRightEnd -= nCharWidth;
     855             :             }
     856             :         }
     857             :         // no break!
     858             :         case RubyAdjust_BLOCK:
     859           0 :         if(sOutputText.getLength() > 1)
     860             :         {
     861           0 :             sal_Int32 nCount = sOutputText.getLength();
     862           0 :             long nSpace = ((nRightEnd - nLeftStart) - GetTextWidth(sOutputText)) / (nCount - 1);
     863           0 :             for(sal_Int32 i = 0; i < nCount; i++)
     864             :             {
     865           0 :                 OUString sChar(sOutputText[i]);
     866           0 :                 DrawText( Point( nLeftStart , nYOutput),  sChar);
     867           0 :                 long nCharWidth = GetTextWidth(sChar);
     868           0 :                 nLeftStart += nCharWidth + nSpace;
     869           0 :             }
     870           0 :             break;
     871             :         }
     872             :         //no break;
     873             :         case RubyAdjust_CENTER:
     874           0 :             DrawText( Point( nCenter - nOutTextWidth / 2 , nYOutput),  sOutputText );
     875           0 :         break;
     876             :     }
     877           0 :     SetFont(aSaveFont);
     878           0 : }
     879             : 
     880           0 : Size RubyPreview::GetOptimalSize() const
     881             : {
     882           0 :     return LogicToPixel(Size(215, 50), MapMode(MAP_APPFONT));
     883             : }
     884             : 
     885           0 : void RubyEdit::GetFocus()
     886             : {
     887           0 :     GetModifyHdl().Call(this);
     888           0 :     Edit::GetFocus();
     889           0 : }
     890             : 
     891           0 : bool RubyEdit::PreNotify( NotifyEvent& rNEvt )
     892             : {
     893           0 :     bool nHandled = false;
     894           0 :     if ( rNEvt.GetType() == EVENT_KEYINPUT )
     895             :     {
     896           0 :         const KeyEvent* pKEvt = rNEvt.GetKeyEvent();
     897           0 :         const KeyCode&  rKeyCode = pKEvt->GetKeyCode();
     898           0 :         sal_uInt16 nMod = rKeyCode.GetModifier();
     899           0 :         sal_uInt16 nCode = rKeyCode.GetCode();
     900           0 :         if( nCode == KEY_TAB && (!nMod || KEY_SHIFT == nMod))
     901             :         {
     902           0 :             sal_Int32 nParam = KEY_SHIFT == nMod ? -1 : 1;
     903           0 :             if(aScrollHdl.IsSet() && aScrollHdl.Call(&nParam))
     904           0 :                 nHandled = true;
     905             :         }
     906           0 :         else if(KEY_UP == nCode || KEY_DOWN == nCode)
     907             :         {
     908           0 :             sal_Int32 nParam = KEY_UP == nCode ? -1 : 1;
     909           0 :             aJumpHdl.Call(&nParam);
     910             :         }
     911             :     }
     912           0 :     if(!nHandled)
     913           0 :         nHandled = Edit::PreNotify(rNEvt);
     914           0 :     return nHandled;
     915             : }
     916             : 
     917           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeRubyEdit(Window *pParent, VclBuilder::stringmap &)
     918             : {
     919           0 :     return new RubyEdit(pParent);
     920         255 : }
     921             : 
     922             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10