LCOV - code coverage report
Current view: top level - sw/source/ui/config - optload.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 484 0.0 %
Date: 2014-04-11 Functions: 0 37 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <officecfg/Office/Writer.hxx>
      21             : #include <comphelper/string.hxx>
      22             : #include <tools/shl.hxx>
      23             : #include <swtypes.hxx>
      24             : #include <helpid.h>
      25             : #include <uiitems.hxx>
      26             : #include <modcfg.hxx>
      27             : #include "swmodule.hxx"
      28             : #include "usrpref.hxx"
      29             : #include "wrtsh.hxx"
      30             : #include "linkenum.hxx"
      31             : #include <uitool.hxx>
      32             : #include <view.hxx>
      33             : 
      34             : #include "globals.hrc"
      35             : #include "cmdid.h"
      36             : 
      37             : #include "optload.hxx"
      38             : #include <svx/dlgutil.hxx>
      39             : #include <sfx2/htmlmode.hxx>
      40             : #include <fldmgr.hxx>
      41             : #include <poolfmt.hxx>
      42             : #include <expfld.hxx>
      43             : #include <caption.hxx>
      44             : #include <com/sun/star/document/PrinterIndependentLayout.hpp>
      45             : 
      46             : #include <svtools/insdlg.hxx>
      47             : #include "svtools/treelistentry.hxx"
      48             : #include <vcl/builder.hxx>
      49             : #include <vcl/settings.hxx>
      50             : 
      51             : #include <comphelper/classids.hxx>
      52             : #include <unotools/configmgr.hxx>
      53             : #include <docsh.hxx>
      54             : #include <app.hrc>
      55             : #include <config.hrc>
      56             : #include <SwStyleNameMapper.hxx>
      57             : #include <numrule.hxx>
      58             : #include <SwNodeNum.hxx>
      59             : 
      60             : #include <doc.hxx>
      61             : #include <svl/cjkoptions.hxx>
      62             : 
      63             : using namespace ::com::sun::star;
      64             : 
      65             : #include <svl/eitem.hxx>
      66             : 
      67           0 : SwLoadOptPage::SwLoadOptPage(Window* pParent, const SfxItemSet& rSet)
      68             :     : SfxTabPage(pParent, "OptGeneralPage",
      69             :         "modules/swriter/ui/optgeneralpage.ui", rSet)
      70             :     , m_pWrtShell(NULL)
      71             :     , m_nLastTab(0)
      72           0 :     , m_nOldLinkMode(MANUAL)
      73             : {
      74           0 :     get(m_pAlwaysRB, "always");
      75           0 :     get(m_pRequestRB, "onrequest");
      76           0 :     get(m_pNeverRB, "never");
      77           0 :     get(m_pAutoUpdateFields, "updatefields");
      78           0 :     get(m_pAutoUpdateCharts, "updatecharts");
      79           0 :     get(m_pMetricLB, "metric");
      80           0 :     get(m_pTabFT, "tablabel");
      81           0 :     get(m_pTabMF, "tab");
      82           0 :     get(m_pUseSquaredPageMode, "squaremode");
      83           0 :     get(m_pUseCharUnit, "usecharunit");
      84           0 :     get(m_pWordCountED, "wordcount");
      85             : 
      86           0 :     SvxStringArray aMetricArr( SW_RES( STR_ARR_METRIC ) );
      87           0 :     for ( sal_uInt32 i = 0; i < aMetricArr.Count(); ++i )
      88             :     {
      89           0 :         OUString sMetric = aMetricArr.GetStringByPos( i );
      90           0 :         FieldUnit eFUnit = (FieldUnit)aMetricArr.GetValue( i );
      91             : 
      92           0 :         switch ( eFUnit )
      93             :         {
      94             :             case FUNIT_MM:
      95             :             case FUNIT_CM:
      96             :             case FUNIT_POINT:
      97             :             case FUNIT_PICA:
      98             :             case FUNIT_INCH:
      99             :             {
     100             :                 // use only these metrics
     101           0 :                 sal_Int32 nPos = m_pMetricLB->InsertEntry( sMetric );
     102           0 :                 m_pMetricLB->SetEntryData( nPos, (void*)(sal_IntPtr)eFUnit );
     103             :             }
     104             :             default:; //prevent warning
     105             :         }
     106           0 :     }
     107           0 :     m_pMetricLB->SetSelectHdl(LINK(this, SwLoadOptPage, MetricHdl));
     108             : 
     109             :     const SfxPoolItem* pItem;
     110           0 :     if(SFX_ITEM_SET == rSet.GetItemState(SID_HTML_MODE, false, &pItem )
     111           0 :         && ((SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON)
     112             :     {
     113           0 :         m_pTabFT->Hide();
     114           0 :         m_pTabMF->Hide();
     115             :     }
     116             : 
     117           0 :     SvtCJKOptions aCJKOptions;
     118           0 :     if(!aCJKOptions.IsAsianTypographyEnabled())
     119             :     {
     120           0 :         m_pUseSquaredPageMode->Hide();
     121           0 :         m_pUseCharUnit->Hide();
     122           0 :     }
     123           0 : }
     124             : 
     125           0 : SfxTabPage* SwLoadOptPage::Create( Window* pParent,
     126             :                                 const SfxItemSet& rAttrSet )
     127             : {
     128           0 :     return new SwLoadOptPage(pParent, rAttrSet );
     129             : }
     130             : 
     131           0 : bool SwLoadOptPage::FillItemSet( SfxItemSet& rSet )
     132             : {
     133           0 :     sal_Bool bRet = sal_False;
     134           0 :     SwModule* pMod = SW_MOD();
     135             : 
     136           0 :     sal_uInt16 nNewLinkMode = AUTOMATIC;
     137           0 :     if (m_pNeverRB->IsChecked())
     138           0 :         nNewLinkMode = NEVER;
     139           0 :     else if (m_pRequestRB->IsChecked())
     140           0 :         nNewLinkMode = MANUAL;
     141             : 
     142           0 :     SwFldUpdateFlags eFldFlags = m_pAutoUpdateFields->IsChecked() ?
     143           0 :         m_pAutoUpdateCharts->IsChecked() ? AUTOUPD_FIELD_AND_CHARTS : AUTOUPD_FIELD_ONLY : AUTOUPD_OFF;
     144             : 
     145           0 :     if(TriState(m_pAutoUpdateFields->IsChecked()) != m_pAutoUpdateFields->GetSavedValue() ||
     146           0 :        TriState(m_pAutoUpdateCharts->IsChecked()) != m_pAutoUpdateCharts->GetSavedValue())
     147             :     {
     148           0 :         pMod->ApplyFldUpdateFlags(eFldFlags);
     149           0 :         if(m_pWrtShell)
     150             :         {
     151           0 :             m_pWrtShell->SetFldUpdateFlags(eFldFlags);
     152           0 :             m_pWrtShell->SetModified();
     153             :         }
     154             :     }
     155             : 
     156           0 :     if (nNewLinkMode != m_nOldLinkMode)
     157             :     {
     158           0 :         pMod->ApplyLinkMode(nNewLinkMode);
     159           0 :         if (m_pWrtShell)
     160             :         {
     161           0 :             m_pWrtShell->SetLinkUpdMode( nNewLinkMode );
     162           0 :             m_pWrtShell->SetModified();
     163             :         }
     164             : 
     165           0 :         bRet = sal_True;
     166             :     }
     167             : 
     168           0 :     const sal_Int32 nMPos = m_pMetricLB->GetSelectEntryPos();
     169           0 :     if ( nMPos != m_pMetricLB->GetSavedValue() )
     170             :     {
     171             :         // Double-Cast for VA3.0
     172           0 :         sal_uInt16 nFieldUnit = (sal_uInt16)(sal_IntPtr)m_pMetricLB->GetEntryData( nMPos );
     173           0 :         rSet.Put( SfxUInt16Item( SID_ATTR_METRIC, (sal_uInt16)nFieldUnit ) );
     174           0 :         bRet = sal_True;
     175             :     }
     176             : 
     177           0 :     if(m_pTabMF->IsVisible() && m_pTabMF->GetText() != m_pTabMF->GetSavedValue())
     178             :     {
     179             :         rSet.Put(SfxUInt16Item(SID_ATTR_DEFTABSTOP,
     180           0 :                     (sal_uInt16)m_pTabMF->Denormalize(m_pTabMF->GetValue(FUNIT_TWIP))));
     181           0 :         bRet = sal_True;
     182             :     }
     183             : 
     184           0 :     sal_Bool bIsUseCharUnitFlag = m_pUseCharUnit->IsChecked();
     185           0 :     SvtCJKOptions aCJKOptions;
     186           0 :         bIsUseCharUnitFlag = bIsUseCharUnitFlag && aCJKOptions.IsAsianTypographyEnabled();
     187           0 :     if( bIsUseCharUnitFlag != m_pUseCharUnit->GetSavedValue())
     188             :     {
     189           0 :         rSet.Put(SfxBoolItem(SID_ATTR_APPLYCHARUNIT, bIsUseCharUnitFlag ));
     190           0 :         bRet = sal_True;
     191             :     }
     192             : 
     193           0 :     if (m_pWordCountED->GetText() != m_pWordCountED->GetSavedValue())
     194             :     {
     195             :         boost::shared_ptr< comphelper::ConfigurationChanges > batch(
     196           0 :             comphelper::ConfigurationChanges::create());
     197           0 :         officecfg::Office::Writer::WordCount::AdditionalSeparators::set(m_pWordCountED->GetText(), batch);
     198           0 :         batch->commit();
     199           0 :         bRet = sal_True;
     200             :     }
     201             : 
     202           0 :     sal_Bool bIsSquaredPageModeFlag = m_pUseSquaredPageMode->IsChecked();
     203           0 :     if ( bIsSquaredPageModeFlag != m_pUseSquaredPageMode->GetSavedValue() )
     204             :     {
     205           0 :         pMod->ApplyDefaultPageMode( bIsSquaredPageModeFlag );
     206           0 :         if ( m_pWrtShell )
     207             :         {
     208           0 :             SwDoc* pDoc = m_pWrtShell->GetDoc();
     209           0 :             pDoc->SetDefaultPageMode( bIsSquaredPageModeFlag );
     210           0 :             m_pWrtShell->SetModified();
     211             :         }
     212           0 :         bRet = sal_True;
     213             :     }
     214             : 
     215           0 :     return bRet;
     216             : }
     217             : 
     218           0 : void SwLoadOptPage::Reset( const SfxItemSet& rSet)
     219             : {
     220           0 :     const SwMasterUsrPref* pUsrPref = SW_MOD()->GetUsrPref(sal_False);
     221             :     const SfxPoolItem* pItem;
     222             : 
     223           0 :     if(SFX_ITEM_SET == rSet.GetItemState(FN_PARAM_WRTSHELL, false, &pItem))
     224           0 :         m_pWrtShell = (SwWrtShell*)((const SwPtrItem*)pItem)->GetValue();
     225             : 
     226           0 :     SwFldUpdateFlags eFldFlags = AUTOUPD_GLOBALSETTING;
     227           0 :     m_nOldLinkMode = GLOBALSETTING;
     228           0 :     if (m_pWrtShell)
     229             :     {
     230           0 :         eFldFlags = m_pWrtShell->GetFldUpdateFlags(sal_True);
     231           0 :         m_nOldLinkMode = m_pWrtShell->GetLinkUpdMode(sal_True);
     232             :     }
     233           0 :     if(GLOBALSETTING == m_nOldLinkMode)
     234           0 :         m_nOldLinkMode = pUsrPref->GetUpdateLinkMode();
     235           0 :     if(AUTOUPD_GLOBALSETTING == eFldFlags)
     236           0 :         eFldFlags = pUsrPref->GetFldUpdateFlags();
     237             : 
     238           0 :     m_pAutoUpdateFields->Check(eFldFlags != AUTOUPD_OFF);
     239           0 :     m_pAutoUpdateCharts->Check(eFldFlags == AUTOUPD_FIELD_AND_CHARTS);
     240             : 
     241           0 :     switch (m_nOldLinkMode)
     242             :     {
     243           0 :         case NEVER:     m_pNeverRB->Check();   break;
     244           0 :         case MANUAL:    m_pRequestRB->Check(); break;
     245           0 :         case AUTOMATIC: m_pAlwaysRB->Check();  break;
     246             :     }
     247             : 
     248           0 :     m_pAutoUpdateFields->SaveValue();
     249           0 :     m_pAutoUpdateCharts->SaveValue();
     250           0 :     m_pMetricLB->SetNoSelection();
     251           0 :     if ( rSet.GetItemState( SID_ATTR_METRIC ) >= SFX_ITEM_AVAILABLE )
     252             :     {
     253           0 :         const SfxUInt16Item& rItem = (SfxUInt16Item&)rSet.Get( SID_ATTR_METRIC );
     254           0 :         FieldUnit eFieldUnit = (FieldUnit)rItem.GetValue();
     255             : 
     256           0 :         for ( sal_Int32 i = 0; i < m_pMetricLB->GetEntryCount(); ++i )
     257             :         {
     258           0 :             if ( (int)(sal_IntPtr)m_pMetricLB->GetEntryData( i ) == (int)eFieldUnit )
     259             :             {
     260           0 :                 m_pMetricLB->SelectEntryPos( i );
     261           0 :                 break;
     262             :             }
     263             :         }
     264           0 :         ::SetFieldUnit(*m_pTabMF, eFieldUnit);
     265             :     }
     266           0 :     m_pMetricLB->SaveValue();
     267           0 :     if(SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_DEFTABSTOP, false, &pItem))
     268             :     {
     269           0 :         m_nLastTab = ((SfxUInt16Item*)pItem)->GetValue();
     270           0 :         m_pTabMF->SetValue(m_pTabMF->Normalize(m_nLastTab), FUNIT_TWIP);
     271             :     }
     272           0 :     m_pTabMF->SaveValue();
     273             : 
     274             :     //default page mode loading
     275           0 :     if(m_pWrtShell)
     276             :     {
     277           0 :         bool bSquaredPageMode = m_pWrtShell->GetDoc()->IsSquaredPageMode();
     278           0 :         m_pUseSquaredPageMode->Check( bSquaredPageMode );
     279           0 :         m_pUseSquaredPageMode->SaveValue();
     280             :     }
     281             : 
     282           0 :     if(SFX_ITEM_SET == rSet.GetItemState(SID_ATTR_APPLYCHARUNIT, false, &pItem))
     283             :     {
     284           0 :         bool bUseCharUnit = ((const SfxBoolItem*)pItem)->GetValue();
     285           0 :         m_pUseCharUnit->Check(bUseCharUnit);
     286             :     }
     287             :     else
     288             :     {
     289           0 :         m_pUseCharUnit->Check(pUsrPref->IsApplyCharUnit());
     290             :     }
     291           0 :     m_pUseCharUnit->SaveValue();
     292             : 
     293           0 :     m_pWordCountED->SetText(officecfg::Office::Writer::WordCount::AdditionalSeparators::get());
     294           0 :     m_pWordCountED->SaveValue();
     295           0 : }
     296             : 
     297           0 : IMPL_LINK_NOARG(SwLoadOptPage, MetricHdl)
     298             : {
     299           0 :     const sal_Int32 nMPos = m_pMetricLB->GetSelectEntryPos();
     300           0 :     if(nMPos != LISTBOX_ENTRY_NOTFOUND)
     301             :     {
     302             :         // Double-Cast for VA3.0
     303           0 :         FieldUnit eFieldUnit = (FieldUnit)(sal_IntPtr)m_pMetricLB->GetEntryData( nMPos );
     304           0 :         sal_Bool bModified = m_pTabMF->IsModified();
     305             :         long nVal = bModified ?
     306           0 :             sal::static_int_cast<sal_Int32, sal_Int64 >( m_pTabMF->Denormalize( m_pTabMF->GetValue( FUNIT_TWIP ) )) :
     307           0 :                 m_nLastTab;
     308           0 :         ::SetFieldUnit( *m_pTabMF, eFieldUnit );
     309           0 :         m_pTabMF->SetValue( m_pTabMF->Normalize( nVal ), FUNIT_TWIP );
     310           0 :         if(!bModified)
     311           0 :             m_pTabMF->ClearModifyFlag();
     312             :     }
     313             : 
     314           0 :     return 0;
     315             : }
     316             : 
     317           0 : SwCaptionOptDlg::SwCaptionOptDlg(Window* pParent, const SfxItemSet& rSet)
     318             :     : SfxSingleTabDialog(pParent, rSet, "CaptionDialog",
     319           0 :         "modules/swriter/ui/captiondialog.ui")
     320             : {
     321             :     // create TabPage
     322           0 :     SetTabPage(SwCaptionOptPage::Create(get_content_area(), rSet));
     323           0 : }
     324             : 
     325           0 : SwCaptionPreview::SwCaptionPreview( Window* pParent, WinBits nStyle )
     326           0 :     : Window( pParent, nStyle )
     327             : {
     328           0 :     Init();
     329           0 : }
     330             : 
     331           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeSwCaptionPreview(Window *pParent, VclBuilder::stringmap &rMap)
     332             : {
     333           0 :     WinBits nBits = 0;
     334           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
     335           0 :     if (!sBorder.isEmpty())
     336           0 :        nBits |= WB_BORDER;
     337           0 :     return new SwCaptionPreview(pParent, nBits);
     338             : }
     339             : 
     340           0 : void SwCaptionPreview::Init()
     341             : {
     342           0 :     maDrawPos = Point( 4, 6 );
     343             : 
     344           0 :     Wallpaper   aBack( GetSettings().GetStyleSettings().GetWindowColor() );
     345           0 :     SetBackground( aBack );
     346           0 :     SetFillColor( aBack.GetColor() );
     347           0 :     SetLineColor( aBack.GetColor() );
     348           0 :     SetBorderStyle( WINDOW_BORDER_MONO );
     349           0 :     Font aFont(GetFont());
     350           0 :     aFont.SetHeight(aFont.GetHeight() * 120 / 100 );
     351           0 :     SetFont(aFont);
     352           0 : }
     353             : 
     354           0 : void SwCaptionPreview::SetPreviewText( const OUString& rText )
     355             : {
     356           0 :     if( rText != maText )
     357             :     {
     358           0 :         maText = rText;
     359           0 :         Invalidate();
     360             :     }
     361           0 : }
     362             : 
     363           0 : Size SwCaptionPreview::GetOptimalSize() const
     364             : {
     365           0 :     return LogicToPixel(Size(106 , 20), MapMode(MAP_APPFONT));
     366             : }
     367             : 
     368           0 : void SwCaptionPreview::Paint( const Rectangle& rRect )
     369             : {
     370           0 :     Window::Paint( rRect );
     371             : 
     372           0 :     DrawRect( Rectangle( Point( 0, 0 ), GetSizePixel() ) );
     373           0 :     DrawText( Point( 4, 6 ), maText );
     374           0 : }
     375             : 
     376           0 : SwCaptionOptPage::SwCaptionOptPage( Window* pParent, const SfxItemSet& rSet )
     377             :     : SfxTabPage(pParent, "OptCaptionPage", "modules/swriter/ui/optcaptionpage.ui", rSet)
     378             :     , m_sSWTable(SW_RESSTR(STR_CAPTION_TABLE))
     379             :     , m_sSWFrame(SW_RESSTR(STR_CAPTION_FRAME))
     380             :     , m_sSWGraphic(SW_RESSTR(STR_CAPTION_GRAPHIC))
     381             :     , m_sOLE(SW_RESSTR(STR_CAPTION_OLE))
     382             :     , m_sBegin(SW_RESSTR(STR_CAPTION_BEGINNING))
     383             :     , m_sEnd(SW_RESSTR(STR_CAPTION_END))
     384             :     , m_sAbove(SW_RESSTR(STR_CAPTION_ABOVE))
     385             :     , m_sBelow(SW_RESSTR(STR_CAPTION_BELOW))
     386             :     , m_sNone(SW_RESSTR(STR_CATEGORY_NONE))
     387           0 :     , pMgr(new SwFldMgr())
     388           0 :     , bHTMLMode(false)
     389             : {
     390           0 :     get(m_pCheckLB, "objects");
     391           0 :     get(m_pLbCaptionOrder, "captionorder");
     392           0 :     get(m_pPreview, "preview");
     393           0 :     get(m_pSettingsGroup, "settings");
     394           0 :     get(m_pCategoryBox, "category");
     395           0 :     get(m_pFormatText, "numberingft");
     396           0 :     get(m_pFormatBox, "numbering");
     397           0 :     get(m_pNumberingSeparatorFT, "numseparatorft");
     398           0 :     get(m_pNumberingSeparatorED, "numseparator");
     399           0 :     get(m_pTextText, "separatorft");
     400           0 :     get(m_pTextEdit, "separator");
     401           0 :     get(m_pPosBox, "position");
     402           0 :     get(m_pNumCapt, "numcaption");
     403           0 :     get(m_pLbLevel, "level");
     404           0 :     get(m_pEdDelim, "chapseparator");
     405           0 :     get(m_pCategory, "categoryformat");
     406           0 :     get(m_pCharStyleLB, "charstyle");
     407           0 :     get(m_pApplyBorderCB, "applyborder");
     408             : 
     409           0 :     Wallpaper   aBack( GetSettings().GetStyleSettings().GetWindowColor() );
     410           0 :     m_pPreview->SetBackground( aBack );
     411             : 
     412           0 :     SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_ABB, m_sIllustration);
     413           0 :     SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_TABLE, m_sTable);
     414           0 :     SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_FRAME, m_sText);
     415           0 :     SwStyleNameMapper::FillUIName(RES_POOLCOLL_LABEL_DRAWING, m_sDrawing);
     416             : 
     417             :     sal_uInt16 i, nCount;
     418           0 :     SwWrtShell *pSh = ::GetActiveWrtShell();
     419             : 
     420             :     // m_pFormatBox
     421           0 :     sal_uInt16 nSelFmt = SVX_NUM_ARABIC;
     422           0 :     if (pSh)
     423             :     {
     424           0 :         nCount = pMgr->GetFldTypeCount();
     425             :         SwFieldType* pFldType;
     426           0 :         for ( i = nCount; i; )
     427             :         {
     428           0 :             pFldType = pMgr->GetFldType(USHRT_MAX, --i);
     429           0 :             if (pFldType->GetName().equals(m_pCategoryBox->GetText()))
     430             :             {
     431           0 :                 nSelFmt = (sal_uInt16)((SwSetExpFieldType*)pFldType)->GetSeqFormat();
     432           0 :                 break;
     433             :             }
     434             :         }
     435             : 
     436           0 :         ::FillCharStyleListBox( *m_pCharStyleLB, pSh->GetView().GetDocShell(), true, true );
     437             :     }
     438             : 
     439           0 :     nCount = pMgr->GetFormatCount(TYP_SEQFLD, false);
     440           0 :     for ( i = 0; i < nCount; ++i )
     441             :     {
     442           0 :         m_pFormatBox->InsertEntry( pMgr->GetFormatStr(TYP_SEQFLD, i) );
     443           0 :         sal_uInt16 nFmtId = pMgr->GetFormatId(TYP_SEQFLD, i);
     444           0 :         m_pFormatBox->SetEntryData( i, reinterpret_cast<void*>(nFmtId) );
     445           0 :         if( nFmtId == nSelFmt )
     446           0 :             m_pFormatBox->SelectEntryPos( i );
     447             :     }
     448             : 
     449           0 :     for (i = 0; i < MAXLEVEL; i++)
     450           0 :         m_pLbLevel->InsertEntry(OUString::number(i + 1));
     451             : 
     452           0 :     sal_Unicode nLvl = MAXLEVEL;
     453           0 :     OUString sDelim(": ");
     454             : 
     455           0 :     if (pSh)
     456             :     {
     457             :         SwSetExpFieldType* pFldType = (SwSetExpFieldType*)pMgr->GetFldType(
     458           0 :                                             RES_SETEXPFLD, m_pCategoryBox->GetText() );
     459           0 :         if( pFldType )
     460             :         {
     461           0 :             sDelim = pFldType->GetDelimiter();
     462           0 :             nLvl = pFldType->GetOutlineLvl();
     463             :         }
     464             :     }
     465             : 
     466           0 :     m_pLbLevel->SelectEntryPos( nLvl < MAXLEVEL ? nLvl + 1 : 0 );
     467           0 :     m_pEdDelim->SetText( sDelim );
     468             : 
     469           0 :     Link aLk = LINK( this, SwCaptionOptPage, ModifyHdl );
     470           0 :     m_pCategoryBox->SetModifyHdl( aLk );
     471           0 :     m_pNumberingSeparatorED->SetModifyHdl( aLk );
     472           0 :     m_pTextEdit->SetModifyHdl( aLk );
     473             : 
     474           0 :     aLk = LINK(this, SwCaptionOptPage, SelectHdl);
     475           0 :     m_pCategoryBox->SetSelectHdl( aLk );
     476           0 :     m_pFormatBox->SetSelectHdl( aLk );
     477             : 
     478           0 :     m_pLbCaptionOrder->SetSelectHdl( LINK(this, SwCaptionOptPage, OrderHdl));
     479             : 
     480           0 :     m_pCheckLB->SetSelectHdl( LINK(this, SwCaptionOptPage, ShowEntryHdl) );
     481           0 :     m_pCheckLB->SetCheckButtonHdl( LINK(this, SwCaptionOptPage, ShowEntryHdl) );
     482           0 :     m_pCheckLB->SetDeselectHdl( LINK(this, SwCaptionOptPage, SaveEntryHdl) );
     483           0 : }
     484             : 
     485           0 : SwCaptionOptPage::~SwCaptionOptPage()
     486             : {
     487           0 :     DelUserData();
     488           0 :     delete pMgr;
     489           0 : }
     490             : 
     491           0 : SfxTabPage* SwCaptionOptPage::Create( Window* pParent,
     492             :                                 const SfxItemSet& rAttrSet )
     493             : {
     494           0 :     return new SwCaptionOptPage(pParent, rAttrSet );
     495             : }
     496             : 
     497           0 : bool SwCaptionOptPage::FillItemSet( SfxItemSet&  )
     498             : {
     499           0 :     sal_Bool bRet = sal_False;
     500           0 :     SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
     501             : 
     502           0 :     SaveEntry(m_pCheckLB->FirstSelected());    // apply current entry
     503             : 
     504           0 :     SvTreeListEntry* pEntry = m_pCheckLB->First();
     505             : 
     506           0 :     while (pEntry)
     507             :     {
     508           0 :         InsCaptionOpt* pData = (InsCaptionOpt*)pEntry->GetUserData();
     509           0 :         bRet |= pModOpt->SetCapOption(bHTMLMode, pData);
     510           0 :         pEntry = m_pCheckLB->Next(pEntry);
     511             :     }
     512             : 
     513           0 :     sal_uLong nCheckCount = m_pCheckLB->GetCheckedEntryCount();
     514           0 :     pModOpt->SetInsWithCaption( bHTMLMode, nCheckCount > 0 );
     515             : 
     516           0 :     sal_Int32 nPos = m_pLbCaptionOrder->GetSelectEntryPos();
     517           0 :     pModOpt->SetCaptionOrderNumberingFirst(nPos == 1 ? sal_True : sal_False );
     518             : 
     519           0 :     return bRet;
     520             : }
     521             : 
     522           0 : void SwCaptionOptPage::Reset( const SfxItemSet& rSet)
     523             : {
     524             :     const SfxPoolItem* pItem;
     525           0 :     if(SFX_ITEM_SET == rSet.GetItemState(SID_HTML_MODE, false, &pItem))
     526             :     {
     527           0 :         bHTMLMode = 0 != (((const SfxUInt16Item*)pItem)->GetValue() & HTMLMODE_ON);
     528             :     }
     529             : 
     530           0 :     DelUserData();
     531           0 :     m_pCheckLB->GetModel()->Clear();   // remove all entries
     532             : 
     533             :     // Writer objects
     534           0 :     sal_uLong nPos = 0;
     535           0 :     m_pCheckLB->InsertEntry(m_sSWTable);
     536           0 :     SetOptions(nPos++, TABLE_CAP);
     537           0 :     m_pCheckLB->InsertEntry(m_sSWFrame);
     538           0 :     SetOptions(nPos++, FRAME_CAP);
     539           0 :     m_pCheckLB->InsertEntry(m_sSWGraphic);
     540           0 :     SetOptions(nPos++, GRAPHIC_CAP);
     541             : 
     542             :     // get Productname and -version
     543           0 :     OUString sWithoutVersion( utl::ConfigManager::getProductName() );
     544             :     OUString sComplete(
     545           0 :         sWithoutVersion + " " +
     546           0 :         utl::ConfigManager::getProductVersion() );
     547             : 
     548           0 :     SvObjectServerList aObjS;
     549           0 :     aObjS.FillInsertObjects();
     550           0 :     aObjS.Remove( SvGlobalName( SO3_SW_CLASSID ) ); // remove Writer-ID
     551             : 
     552           0 :     for ( sal_uLong i = 0; i < aObjS.Count(); ++i )
     553             :     {
     554           0 :         const SvGlobalName &rOleId = aObjS[i].GetClassName();
     555           0 :         OUString sClass;
     556           0 :         if (rOleId == SvGlobalName(SO3_OUT_CLASSID))
     557           0 :             sClass = aObjS[i].GetHumanName();
     558             :         else
     559           0 :             sClass = m_sOLE;
     560             :         // don't show product version
     561           0 :         sClass = sClass.replaceFirst( sComplete, sWithoutVersion );
     562           0 :         m_pCheckLB->InsertEntry( sClass );
     563           0 :         SetOptions( nPos++, OLE_CAP, &rOleId );
     564           0 :     }
     565             :     m_pLbCaptionOrder->SelectEntryPos(
     566           0 :         SW_MOD()->GetModuleConfig()->IsCaptionOrderNumberingFirst() ? 1 : 0);
     567           0 :     ModifyHdl();
     568           0 : }
     569             : 
     570           0 : void SwCaptionOptPage::SetOptions(const sal_uLong nPos,
     571             :         const SwCapObjType eObjType, const SvGlobalName *pOleId)
     572             : {
     573           0 :     SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig();
     574           0 :     const InsCaptionOpt* pOpt = pModOpt->GetCapOption(bHTMLMode, eObjType, pOleId);
     575             : 
     576           0 :     if (pOpt)
     577             :     {
     578           0 :         m_pCheckLB->SetEntryData(nPos, new InsCaptionOpt(*pOpt));
     579           0 :         m_pCheckLB->CheckEntryPos(nPos, pOpt->UseCaption());
     580             :     }
     581             :     else
     582           0 :         m_pCheckLB->SetEntryData(nPos, new InsCaptionOpt(eObjType, pOleId));
     583           0 : }
     584             : 
     585           0 : void SwCaptionOptPage::DelUserData()
     586             : {
     587           0 :     SvTreeListEntry* pEntry = m_pCheckLB->First();
     588             : 
     589           0 :     while (pEntry)
     590             :     {
     591           0 :         delete (InsCaptionOpt*)pEntry->GetUserData();
     592           0 :         pEntry->SetUserData(0);
     593           0 :         pEntry = m_pCheckLB->Next(pEntry);
     594             :     }
     595           0 : }
     596             : 
     597           0 : IMPL_LINK_NOARG(SwCaptionOptPage, ShowEntryHdl)
     598             : {
     599           0 :     SvTreeListEntry* pSelEntry = m_pCheckLB->FirstSelected();
     600             : 
     601           0 :     if (pSelEntry)
     602             :     {
     603           0 :         sal_Bool bChecked = m_pCheckLB->IsChecked(m_pCheckLB->GetModel()->GetAbsPos(pSelEntry));
     604             : 
     605           0 :         m_pSettingsGroup->Enable(bChecked);
     606           0 :         bool bNumSep = bChecked && m_pLbCaptionOrder->GetSelectEntryPos() == 1;
     607           0 :         m_pNumberingSeparatorED->Enable( bNumSep );
     608           0 :         m_pNumberingSeparatorFT->Enable( bNumSep );
     609             : 
     610           0 :         m_pNumCapt->Enable(bChecked);
     611           0 :         m_pCategory->Enable(bChecked);
     612           0 :         m_pPreview->Enable(bChecked);
     613             : 
     614           0 :         SwWrtShell *pSh = ::GetActiveWrtShell();
     615             : 
     616           0 :         InsCaptionOpt* pOpt = (InsCaptionOpt*)pSelEntry->GetUserData();
     617             : 
     618           0 :         m_pCategoryBox->Clear();
     619           0 :         m_pCategoryBox->InsertEntry(m_sNone);
     620           0 :         if (pSh)
     621             :         {
     622           0 :             sal_uInt16 nCount = pMgr->GetFldTypeCount();
     623             : 
     624           0 :             for (sal_uInt16 i = 0; i < nCount; i++)
     625             :             {
     626           0 :                 SwFieldType *pType = pMgr->GetFldType( USHRT_MAX, i );
     627           0 :                 if( pType->Which() == RES_SETEXPFLD &&
     628           0 :                     ((SwSetExpFieldType *) pType)->GetType() & nsSwGetSetExpType::GSE_SEQ )
     629           0 :                     m_pCategoryBox->InsertSwEntry(SwBoxEntry(pType->GetName()));
     630             :             }
     631             :         }
     632             :         else
     633             :         {
     634           0 :             m_pCategoryBox->InsertSwEntry(SwBoxEntry(m_sIllustration));
     635           0 :             m_pCategoryBox->InsertSwEntry(SwBoxEntry(m_sTable));
     636           0 :             m_pCategoryBox->InsertSwEntry(SwBoxEntry(m_sText));
     637           0 :             m_pCategoryBox->InsertSwEntry(SwBoxEntry(m_sDrawing));
     638             :         }
     639             : 
     640           0 :         if(!pOpt->GetCategory().isEmpty())
     641           0 :             m_pCategoryBox->SetText(pOpt->GetCategory());
     642             :         else
     643           0 :             m_pCategoryBox->SetText(m_sNone);
     644           0 :         if (!pOpt->GetCategory().isEmpty() &&
     645           0 :             m_pCategoryBox->GetEntryPos(OUString(pOpt->GetCategory())) == COMBOBOX_ENTRY_NOTFOUND)
     646           0 :             m_pCategoryBox->InsertEntry(pOpt->GetCategory());
     647           0 :         if (m_pCategoryBox->GetText().isEmpty())
     648             :         {
     649           0 :             sal_Int32 nPos = 0;
     650           0 :             switch(pOpt->GetObjType())
     651             :             {
     652             :                 case OLE_CAP:
     653           0 :                 case GRAPHIC_CAP:       nPos = 1;   break;
     654           0 :                 case TABLE_CAP:         nPos = 2;   break;
     655           0 :                 case FRAME_CAP:         nPos = 3;   break;
     656             :             }
     657           0 :             m_pCategoryBox->SetText(m_pCategoryBox->GetSwEntry(nPos).GetName());
     658             :         }
     659             : 
     660           0 :         for (sal_Int32 i = 0; i < m_pFormatBox->GetEntryCount(); i++)
     661             :         {
     662           0 :             if (pOpt->GetNumType() == (sal_uInt16)(sal_uLong)m_pFormatBox->GetEntryData(i))
     663             :             {
     664           0 :                 m_pFormatBox->SelectEntryPos(i);
     665           0 :                 break;
     666             :             }
     667             :         }
     668           0 :         m_pTextEdit->SetText(pOpt->GetCaption());
     669             : 
     670           0 :         m_pPosBox->Clear();
     671           0 :         switch (pOpt->GetObjType())
     672             :         {
     673             :             case GRAPHIC_CAP:
     674             :             case TABLE_CAP:
     675             :             case OLE_CAP:
     676           0 :                 m_pPosBox->InsertEntry(m_sAbove);
     677           0 :                 m_pPosBox->InsertEntry(m_sBelow);
     678           0 :                 break;
     679             :             case FRAME_CAP:
     680           0 :                 m_pPosBox->InsertEntry(m_sBegin);
     681           0 :                 m_pPosBox->InsertEntry(m_sEnd);
     682           0 :                 break;
     683             :         }
     684           0 :         m_pPosBox->SelectEntryPos(pOpt->GetPos());
     685           0 :         m_pPosBox->Enable( pOpt->GetObjType() != GRAPHIC_CAP &&
     686           0 :                 pOpt->GetObjType() != OLE_CAP &&
     687           0 :                 m_pPosBox->IsEnabled() );
     688           0 :         m_pPosBox->SelectEntryPos(pOpt->GetPos());
     689             : 
     690           0 :         sal_Int32 nLevelPos = ( pOpt->GetLevel() < MAXLEVEL ) ? pOpt->GetLevel() + 1 : 0;
     691           0 :         m_pLbLevel->SelectEntryPos( nLevelPos );
     692           0 :         m_pEdDelim->SetText(pOpt->GetSeparator());
     693           0 :         m_pNumberingSeparatorED->SetText( pOpt->GetNumSeparator() );
     694           0 :         if(!pOpt->GetCharacterStyle().isEmpty())
     695           0 :             m_pCharStyleLB->SelectEntry( pOpt->GetCharacterStyle() );
     696             :         else
     697           0 :             m_pCharStyleLB->SelectEntryPos( 0 );
     698           0 :         m_pApplyBorderCB->Enable( m_pCategoryBox->IsEnabled() &&
     699           0 :                 pOpt->GetObjType() != TABLE_CAP && pOpt->GetObjType() != FRAME_CAP );
     700           0 :         m_pApplyBorderCB->Check( pOpt->CopyAttributes() );
     701             :     }
     702             : 
     703           0 :     ModifyHdl();
     704             : 
     705           0 :     return 0;
     706             : }
     707             : 
     708           0 : IMPL_LINK_NOARG(SwCaptionOptPage, SaveEntryHdl)
     709             : {
     710           0 :     SvTreeListEntry* pEntry = m_pCheckLB->GetHdlEntry();
     711             : 
     712           0 :     if (pEntry) // save all
     713           0 :         SaveEntry(pEntry);
     714             : 
     715           0 :     return 0;
     716             : }
     717             : 
     718           0 : void SwCaptionOptPage::SaveEntry(SvTreeListEntry* pEntry)
     719             : {
     720           0 :     if (pEntry)
     721             :     {
     722           0 :         InsCaptionOpt* pOpt = (InsCaptionOpt*)pEntry->GetUserData();
     723             : 
     724           0 :         pOpt->UseCaption() = m_pCheckLB->IsChecked(m_pCheckLB->GetModel()->GetAbsPos(pEntry));
     725           0 :         OUString aName( m_pCategoryBox->GetText() );
     726           0 :         if (aName == m_sNone)
     727           0 :             pOpt->SetCategory(aEmptyOUStr);
     728             :         else
     729           0 :             pOpt->SetCategory(comphelper::string::strip(aName, ' '));
     730           0 :         pOpt->SetNumType((sal_uInt16)(sal_uLong)m_pFormatBox->GetEntryData(m_pFormatBox->GetSelectEntryPos()));
     731           0 :         pOpt->SetCaption(m_pTextEdit->IsEnabled() ? m_pTextEdit->GetText() : OUString(aEmptyOUStr) );
     732           0 :         pOpt->SetPos(m_pPosBox->GetSelectEntryPos());
     733           0 :         sal_Int32 nPos = m_pLbLevel->GetSelectEntryPos();
     734           0 :         sal_Int32 nLevel = ( nPos > 0 && nPos != LISTBOX_ENTRY_NOTFOUND ) ? nPos - 1 : MAXLEVEL;
     735           0 :         pOpt->SetLevel(nLevel);
     736           0 :         pOpt->SetSeparator(m_pEdDelim->GetText());
     737           0 :         pOpt->SetNumSeparator( m_pNumberingSeparatorED->GetText());
     738           0 :         if(!m_pCharStyleLB->GetSelectEntryPos())
     739           0 :             pOpt->SetCharacterStyle(aEmptyOUStr);
     740             :         else
     741           0 :             pOpt->SetCharacterStyle(m_pCharStyleLB->GetSelectEntry());
     742           0 :         pOpt->CopyAttributes() = m_pApplyBorderCB->IsChecked();
     743             :     }
     744           0 : }
     745             : 
     746           0 : IMPL_LINK_NOARG(SwCaptionOptPage, ModifyHdl)
     747             : {
     748           0 :     OUString sFldTypeName = m_pCategoryBox->GetText();
     749             : 
     750           0 :     SfxSingleTabDialog *pDlg = dynamic_cast<SfxSingleTabDialog*>(GetParentDialog());
     751           0 :     PushButton *pBtn = pDlg ? pDlg->GetOKButton() : NULL;
     752           0 :     if (pBtn)
     753           0 :         pBtn->Enable(!sFldTypeName.isEmpty());
     754           0 :     bool bEnable = m_pCategoryBox->IsEnabled() && sFldTypeName != m_sNone;
     755             : 
     756           0 :     m_pFormatText->Enable(bEnable);
     757           0 :     m_pFormatBox->Enable(bEnable);
     758           0 :     m_pTextText->Enable(bEnable);
     759           0 :     m_pTextEdit->Enable(bEnable);
     760             : 
     761           0 :     DrawSample();
     762           0 :     return 0;
     763             : }
     764             : 
     765           0 : IMPL_LINK_NOARG_INLINE_START(SwCaptionOptPage, SelectHdl)
     766             : {
     767           0 :     DrawSample();
     768           0 :     return 0;
     769             : }
     770           0 : IMPL_LINK_NOARG_INLINE_END(SwCaptionOptPage, SelectHdl)
     771             : 
     772           0 : IMPL_LINK( SwCaptionOptPage, OrderHdl, ListBox*, pBox )
     773             : {
     774           0 :     DrawSample();
     775             : 
     776           0 :     SvTreeListEntry* pSelEntry = m_pCheckLB->FirstSelected();
     777           0 :     sal_Bool bChecked = sal_False;
     778           0 :     if (pSelEntry)
     779             :     {
     780           0 :         bChecked = m_pCheckLB->IsChecked(m_pCheckLB->GetModel()->GetAbsPos(pSelEntry));
     781             :     }
     782             : 
     783           0 :     sal_Int32 nPos = pBox->GetSelectEntryPos();
     784           0 :     m_pNumberingSeparatorFT->Enable( bChecked && nPos == 1 );
     785           0 :     m_pNumberingSeparatorED->Enable( bChecked && nPos == 1 );
     786           0 :     return 0;
     787             : }
     788             : 
     789           0 : void SwCaptionOptPage::DrawSample()
     790             : {
     791           0 :     OUString aStr;
     792             : 
     793           0 :     if( m_pCategoryBox->GetText() != m_sNone)
     794             :     {
     795             :         //#i61007# order of captions
     796           0 :         bool bOrderNumberingFirst = m_pLbCaptionOrder->GetSelectEntryPos() == 1;
     797             :         // number
     798             :         sal_uInt16 nNumFmt = (sal_uInt16)(sal_uLong)m_pFormatBox->GetEntryData(
     799           0 :                                         m_pFormatBox->GetSelectEntryPos() );
     800           0 :         if( SVX_NUM_NUMBER_NONE != nNumFmt )
     801             :         {
     802             :             //#i61007# order of captions
     803           0 :             if( !bOrderNumberingFirst )
     804             :             {
     805             :                 // category
     806           0 :                 aStr += m_pCategoryBox->GetText();
     807           0 :                 aStr += " ";
     808             :             }
     809             : 
     810           0 :             SwWrtShell *pSh = ::GetActiveWrtShell();
     811           0 :             OUString sFldTypeName( m_pCategoryBox->GetText() );
     812           0 :             if (pSh)
     813             :             {
     814             :                 SwSetExpFieldType* pFldType = (SwSetExpFieldType*)pMgr->GetFldType(
     815           0 :                                                 RES_SETEXPFLD, sFldTypeName );
     816           0 :                 if( pFldType && pFldType->GetOutlineLvl() < MAXLEVEL )
     817             :                 {
     818           0 :                     sal_uInt8 nLvl = pFldType->GetOutlineLvl();
     819           0 :                     SwNumberTree::tNumberVector aNumVector;
     820           0 :                     for( sal_uInt8 i = 0; i <= nLvl; ++i )
     821           0 :                         aNumVector.push_back(1);
     822             : 
     823             :                     OUString sNumber( pSh->GetOutlineNumRule()->MakeNumString(
     824           0 :                                                             aNumVector, sal_False ));
     825           0 :                     if( !sNumber.isEmpty() )
     826           0 :                         (aStr += sNumber) += pFldType->GetDelimiter();
     827             :                 }
     828             :             }
     829             : 
     830           0 :             switch( nNumFmt )
     831             :             {
     832           0 :                 case SVX_NUM_CHARS_UPPER_LETTER:    aStr += "A"; break;
     833           0 :                 case SVX_NUM_CHARS_UPPER_LETTER_N:  aStr += "A"; break;
     834           0 :                 case SVX_NUM_CHARS_LOWER_LETTER:    aStr += "a"; break;
     835           0 :                 case SVX_NUM_CHARS_LOWER_LETTER_N:  aStr += "a"; break;
     836           0 :                 case SVX_NUM_ROMAN_UPPER:           aStr += "I"; break;
     837           0 :                 case SVX_NUM_ROMAN_LOWER:           aStr += "i"; break;
     838             :                 //case ARABIC:
     839           0 :                 default:                    aStr += "1"; break;
     840           0 :             }
     841             :         }
     842             :         //#i61007# order of captions
     843           0 :         if( bOrderNumberingFirst )
     844             :         {
     845           0 :             aStr += m_pNumberingSeparatorED->GetText();
     846           0 :             aStr += m_pCategoryBox->GetText();
     847             :         }
     848           0 :         aStr += m_pTextEdit->GetText();
     849             :     }
     850           0 :     m_pPreview->SetPreviewText( aStr );
     851           0 : }
     852             : 
     853             : // Description: ComboBox without Spaces
     854           0 : void CaptionComboBox::KeyInput(const KeyEvent& rEvt)
     855             : {
     856           0 :     if( rEvt.GetKeyCode().GetCode() != KEY_SPACE )
     857           0 :         SwComboBox::KeyInput(rEvt);
     858           0 : }
     859             : 
     860           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeCaptionComboBox(Window *pParent, VclBuilder::stringmap &rMap)
     861             : {
     862           0 :     WinBits nBits = WB_CLIPCHILDREN|WB_LEFT|WB_VCENTER|WB_3DLOOK;
     863           0 :     bool bDropdown = VclBuilder::extractDropdown(rMap);
     864           0 :     if (bDropdown)
     865           0 :         nBits |= WB_DROPDOWN;
     866           0 :     CaptionComboBox* pComboBox = new CaptionComboBox(pParent, nBits);
     867           0 :     pComboBox->EnableAutoSize(true);
     868           0 :     return pComboBox;
     869           0 : }
     870             : 
     871             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10