LCOV - code coverage report
Current view: top level - libreoffice/sw/source/ui/chrdlg - swuiccoll.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 147 0.0 %
Date: 2012-12-27 Functions: 0 17 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 "cmdid.h"
      21             : #include "swmodule.hxx"
      22             : #include "view.hxx"
      23             : #include "wrtsh.hxx"
      24             : #include "globals.hrc"
      25             : #include "helpid.h"
      26             : 
      27             : #include <sfx2/styfitem.hxx>
      28             : 
      29             : #include "uitool.hxx"
      30             : #include "ccoll.hxx"
      31             : #include "fmtcol.hxx"
      32             : #include "hintids.hxx"
      33             : #include "docsh.hxx"
      34             : #include "docstyle.hxx"
      35             : #include "hints.hxx"
      36             : 
      37             : #include "chrdlg.hrc"
      38             : #include "ccoll.hrc"
      39             : #include <vcl/svapp.hxx>
      40             : 
      41             : #include "swuiccoll.hxx"
      42             : 
      43             : static sal_uInt16 aPageRg[] = {
      44             :     FN_COND_COLL, FN_COND_COLL,
      45             :     0
      46             : };
      47             : 
      48             : // Warning! This table is indicated directly in code (0, 1, ...)
      49             : static long nTabs[] =
      50             :     {   2, // Number of Tabs
      51             :         0, 100
      52             :     };
      53             : 
      54           0 : SwCondCollPage::SwCondCollPage(Window *pParent, const SfxItemSet &rSet)
      55             : 
      56             :     : SfxTabPage(pParent, SW_RES(TP_CONDCOLL), rSet),
      57             :     aConditionFL( this, SW_RES( FL_CONDITION )),
      58             :     aConditionCB( this, SW_RES( CB_CONDITION ) ),
      59             :     aContextFT  ( this, SW_RES( FT_CONTEXT  ) ),
      60             :     aUsedFT     ( this, SW_RES( FT_USED         ) ),
      61             :     aTbLinks(     this, SW_RES( TB_CONDCOLLS ) ),
      62             :     aStyleFT    ( this, SW_RES( FT_STYLE    ) ),
      63             :     aStyleLB    ( this, SW_RES( LB_STYLE    ) ),
      64             :     aFilterLB   ( this, SW_RES( LB_FILTER   ) ),
      65             :     aRemovePB   ( this, SW_RES( PB_REMOVE   ) ),
      66             :     aAssignPB   ( this, SW_RES( PB_ASSIGN   ) ),
      67             :     sNoTmpl     (       SW_RES( STR_NOTEMPL  ) ),
      68             :     aStrArr     (       SW_RES( STR_REGIONS  ) ),
      69           0 :     rSh(::GetActiveView()->GetWrtShell()),
      70           0 :     pCmds( SwCondCollItem::GetCmds() ),
      71             :     pFmt(0),
      72             : 
      73           0 :     bNewTemplate(sal_False)
      74             : {
      75           0 :     FreeResource();
      76           0 :     SetExchangeSupport();
      77             : 
      78           0 :     aRemovePB.SetAccessibleRelationMemberOf(&aConditionFL);
      79           0 :     aAssignPB.SetAccessibleRelationMemberOf(&aConditionFL);
      80           0 :     aTbLinks.SetAccessibleRelationLabeledBy(&aConditionCB);
      81             : 
      82             :     // Install handlers
      83           0 :     aConditionCB.SetClickHdl(   LINK(this, SwCondCollPage, OnOffHdl));
      84           0 :     aTbLinks.SetDoubleClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
      85           0 :     aStyleLB.SetDoubleClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
      86           0 :     aRemovePB.SetClickHdl(      LINK(this, SwCondCollPage, AssignRemoveHdl ));
      87           0 :     aAssignPB.SetClickHdl(      LINK(this, SwCondCollPage, AssignRemoveHdl ));
      88           0 :     aTbLinks.SetSelectHdl(      LINK(this, SwCondCollPage, SelectHdl));
      89           0 :     aStyleLB.SetSelectHdl(      LINK(this, SwCondCollPage, SelectHdl));
      90           0 :     aFilterLB.SetSelectHdl(     LINK(this, SwCondCollPage, SelectHdl));
      91             : 
      92           0 :     aTbLinks.SetStyle(aTbLinks.GetStyle()|WB_HSCROLL|WB_CLIPCHILDREN);
      93           0 :     aTbLinks.SetSelectionMode( SINGLE_SELECTION );
      94           0 :     aTbLinks.SetTabs( &nTabs[0], MAP_APPFONT );
      95           0 :     aTbLinks.Resize();  // OS: Hack for the right selection
      96           0 :     aTbLinks.SetSpaceBetweenEntries( 0 );
      97           0 :     aTbLinks.SetHelpId(HID_COND_COLL_TABLIST);
      98             : 
      99           0 :     SfxStyleFamilies aFamilies(SW_RES(DLG_STYLE_DESIGNER));
     100           0 :     const SfxStyleFamilyItem* pFamilyItem = 0;
     101             : 
     102           0 :     size_t nCount = aFamilies.size();
     103           0 :     for( size_t i = 0; i < nCount; ++i )
     104             :     {
     105           0 :         if(SFX_STYLE_FAMILY_PARA == (sal_uInt16)(pFamilyItem = aFamilies.at( i ))->GetFamily())
     106           0 :             break;
     107             :     }
     108             : 
     109           0 :     const SfxStyleFilter& rFilterList = pFamilyItem->GetFilterList();
     110           0 :     for( size_t i = 0; i < rFilterList.size(); ++i )
     111             :     {
     112           0 :         aFilterLB.InsertEntry( rFilterList[ i ]->aName);
     113           0 :         sal_uInt16* pFilter = new sal_uInt16(rFilterList[i]->nFlags);
     114           0 :         aFilterLB.SetEntryData(i, pFilter);
     115             :     }
     116           0 :     aFilterLB.SelectEntryPos(1);
     117             : 
     118           0 :     aTbLinks.Show();
     119             : 
     120           0 : }
     121             : 
     122             : /****************************************************************************
     123             : Page: Dtor
     124             : ****************************************************************************/
     125             : 
     126             : 
     127           0 : SwCondCollPage::~SwCondCollPage()
     128             : {
     129           0 :     for(sal_uInt16 i = 0; i < aFilterLB.GetEntryCount(); ++i)
     130           0 :         delete (sal_uInt16*)aFilterLB.GetEntryData(i);
     131             : 
     132           0 : }
     133             : 
     134             : 
     135           0 : int SwCondCollPage::DeactivatePage(SfxItemSet * _pSet)
     136             : {
     137           0 :     if( _pSet )
     138           0 :         FillItemSet(*_pSet);
     139             : 
     140           0 :     return LEAVE_PAGE;
     141             : }
     142             : 
     143             : /****************************************************************************
     144             : Page: Factory
     145             : ****************************************************************************/
     146             : 
     147             : 
     148           0 : SfxTabPage* SwCondCollPage::Create(Window *pParent, const SfxItemSet &rSet)
     149             : {
     150           0 :     return new SwCondCollPage(pParent, rSet);
     151             : }
     152             : 
     153             : /****************************************************************************
     154             : Page: FillItemSet-Overload
     155             : ****************************************************************************/
     156             : 
     157             : 
     158           0 : sal_Bool SwCondCollPage::FillItemSet(SfxItemSet &rSet)
     159             : {
     160           0 :     sal_Bool bModified = sal_True;
     161           0 :     SwCondCollItem aCondItem;
     162           0 :     for(sal_uInt16 i = 0; i < aStrArr.Count(); i++)
     163             :     {
     164           0 :         String sEntry = aTbLinks.GetEntryText(i, 1);
     165           0 :         aCondItem.SetStyle( &sEntry, i);
     166           0 :     }
     167           0 :     rSet.Put(aCondItem);
     168           0 :     return bModified;
     169             : }
     170             : 
     171             : /****************************************************************************
     172             : Page: Reset-Overload
     173             : ****************************************************************************/
     174             : 
     175             : 
     176           0 : void SwCondCollPage::Reset(const SfxItemSet &/*rSet*/)
     177             : {
     178           0 :     if(bNewTemplate)
     179           0 :         aConditionCB.Enable();
     180           0 :     if(RES_CONDTXTFMTCOLL == pFmt->Which())
     181           0 :         aConditionCB.Check();
     182           0 :     OnOffHdl(&aConditionCB);
     183             : 
     184           0 :     aTbLinks.Clear();
     185             : 
     186           0 :     SfxStyleSheetBasePool* pPool = rSh.GetView().GetDocShell()->GetStyleSheetPool();
     187           0 :     pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL);
     188           0 :     aStyleLB.Clear();
     189           0 :     const SfxStyleSheetBase* pBase = pPool->First();
     190           0 :     while( pBase )
     191             :     {
     192           0 :         if(!pFmt || pBase->GetName() != pFmt->GetName())
     193           0 :             aStyleLB.InsertEntry(pBase->GetName());
     194           0 :         pBase = pPool->Next();
     195             :     }
     196           0 :     aStyleLB.SelectEntryPos(0);
     197             : 
     198           0 :     for( sal_uInt16 n = 0; n < aStrArr.Count(); n++)
     199             :     {
     200           0 :         String aEntry( aStrArr.GetString(n) );
     201           0 :         aEntry += '\t';
     202             : 
     203           0 :         const SwCollCondition* pCond = 0;
     204           0 :         if( pFmt && RES_CONDTXTFMTCOLL == pFmt->Which() &&
     205             :             0 != ( pCond = ((SwConditionTxtFmtColl*)pFmt)->
     206           0 :             HasCondition( SwCollCondition( 0, pCmds[n].nCnd, pCmds[n].nSubCond ) ) )
     207           0 :             && pCond->GetTxtFmtColl() )
     208             :         {
     209           0 :             aEntry += pCond->GetTxtFmtColl()->GetName();
     210             :         }
     211             : 
     212           0 :         SvTreeListEntry* pE = aTbLinks.InsertEntryToColumn( aEntry, n );
     213           0 :         if(0 == n)
     214           0 :             aTbLinks.Select(pE);
     215           0 :     }
     216             : 
     217           0 : }
     218             : 
     219           0 : sal_uInt16* SwCondCollPage::GetRanges()
     220             : {
     221           0 :     return aPageRg;
     222             : }
     223             : 
     224           0 : IMPL_LINK( SwCondCollPage, OnOffHdl, CheckBox*, pBox )
     225             : {
     226           0 :     const sal_Bool bEnable = pBox->IsChecked();
     227           0 :     aContextFT.Enable( bEnable );
     228           0 :     aUsedFT   .Enable( bEnable );
     229           0 :     aTbLinks  .EnableList( bEnable != sal_False );
     230           0 :     aStyleFT  .Enable( bEnable );
     231           0 :     aStyleLB  .Enable( bEnable );
     232           0 :     aFilterLB .Enable( bEnable );
     233           0 :     aRemovePB .Enable( bEnable );
     234           0 :     aAssignPB .Enable( bEnable );
     235           0 :     if( bEnable )
     236           0 :         SelectHdl(0);
     237           0 :     return 0;
     238             : }
     239             : 
     240           0 : IMPL_LINK( SwCondCollPage, AssignRemoveHdl, PushButton*, pBtn)
     241             : {
     242           0 :     SvTreeListEntry* pE = aTbLinks.FirstSelected();
     243             :     sal_uLong nPos;
     244           0 :     if( !pE || LISTBOX_ENTRY_NOTFOUND ==
     245           0 :         ( nPos = aTbLinks.GetModel()->GetAbsPos( pE ) ) )
     246             :     {
     247             :         OSL_ENSURE( pE, "where's the empty entry from?" );
     248           0 :         return 0;
     249             :     }
     250             : 
     251           0 :     String sSel = aStrArr.GetString( sal_uInt16(nPos) );
     252           0 :     sSel += '\t';
     253             : 
     254           0 :     const sal_Bool bAssEnabled = pBtn != &aRemovePB && aAssignPB.IsEnabled();
     255           0 :     aAssignPB.Enable( !bAssEnabled );
     256           0 :     aRemovePB.Enable(  bAssEnabled );
     257           0 :     if ( bAssEnabled )
     258           0 :         sSel += aStyleLB.GetSelectEntry();
     259             : 
     260           0 :     aTbLinks.SetUpdateMode(sal_False);
     261           0 :     aTbLinks.GetModel()->Remove(pE);
     262           0 :     pE = aTbLinks.InsertEntryToColumn(sSel, nPos);
     263           0 :     aTbLinks.Select(pE);
     264           0 :     aTbLinks.MakeVisible(pE);
     265           0 :     aTbLinks.SetUpdateMode(sal_True);
     266           0 :     return 0;
     267             : }
     268             : 
     269           0 : IMPL_LINK( SwCondCollPage, SelectHdl, ListBox*, pBox)
     270             : {
     271           0 :     if(pBox == &aFilterLB)
     272             :     {
     273           0 :         aStyleLB.Clear();
     274           0 :         sal_uInt16 nSearchFlags = pBox->GetSelectEntryPos();
     275           0 :         nSearchFlags = *(sal_uInt16*)aFilterLB.GetEntryData(nSearchFlags);
     276           0 :         SfxStyleSheetBasePool* pPool = rSh.GetView().GetDocShell()->GetStyleSheetPool();
     277           0 :         pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, nSearchFlags);
     278           0 :         const SfxStyleSheetBase* pBase = pPool->First();
     279             : 
     280           0 :         while( pBase )
     281             :         {
     282           0 :             if(!pFmt || pBase->GetName() != pFmt->GetName())
     283           0 :                 aStyleLB.InsertEntry(pBase->GetName());
     284           0 :             pBase = pPool->Next();
     285             :         }
     286           0 :         aStyleLB.SelectEntryPos(0);
     287           0 :         SelectHdl(&aStyleLB);
     288             : 
     289             :     }
     290             :     else
     291             :     {
     292           0 :         String sTbEntry;
     293           0 :         SvTreeListEntry* pE = aTbLinks.FirstSelected();
     294           0 :         if(pE)
     295           0 :             sTbEntry = aTbLinks.GetEntryText(pE);
     296           0 :         sTbEntry = sTbEntry.GetToken(1, '\t');
     297           0 :         String sStyle = aStyleLB.GetSelectEntry();
     298             : 
     299           0 :         aAssignPB.Enable( sStyle != sTbEntry && aConditionCB.IsChecked() );
     300             : 
     301           0 :         if(pBox != &aStyleLB)
     302           0 :             aRemovePB.Enable( aConditionCB.IsChecked() && sTbEntry.Len() );
     303             :     }
     304           0 :     return 0;
     305             : }
     306             : 
     307           0 : void SwCondCollPage::SetCollection( SwFmt* pFormat, sal_Bool bNew )
     308             : {
     309           0 :     pFmt = pFormat;
     310           0 :     bNewTemplate = bNew;
     311           0 : }
     312             : 
     313             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10