LCOV - code coverage report
Current view: top level - sw/source/ui/chrdlg - swuiccoll.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 155 0.0 %
Date: 2014-11-03 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 <vcl/svapp.hxx>
      39             : 
      40             : #include "swuiccoll.hxx"
      41             : 
      42             : static const sal_uInt16 aPageRg[] = {
      43             :     FN_COND_COLL, FN_COND_COLL,
      44             :     0
      45             : };
      46             : 
      47             : // Warning! This table is indicated directly in code (0, 1, ...)
      48             : static long nTabs[] =
      49             :     {   2, // Number of Tabs
      50             :         0, 100
      51             :     };
      52             : 
      53           0 : SwCondCollPage::SwCondCollPage(vcl::Window *pParent, const SfxItemSet &rSet)
      54             :     : SfxTabPage(pParent, "ConditionPage",
      55             :         "modules/swriter/ui/conditionpage.ui", &rSet)
      56             :     ,
      57           0 :     rSh(::GetActiveView()->GetWrtShell()),
      58           0 :     pCmds( SwCondCollItem::GetCmds() ),
      59             :     pFmt(0),
      60             : 
      61           0 :     bNewTemplate(false)
      62             : {
      63           0 :     get(m_pConditionCB, "condstyle");
      64           0 :     get(m_pContextFT, "contextft");
      65           0 :     get(m_pUsedFT, "usedft");
      66           0 :     get(m_pStyleFT, "styleft");
      67           0 :     get(m_pTbLinks, "links");
      68           0 :     get(m_pStyleLB, "styles");
      69           0 :     m_pStyleLB->SetStyle(m_pStyleLB->GetStyle() | WB_SORT);
      70           0 :     m_pStyleLB->SetDropDownLineCount(12);
      71           0 :     m_pTbLinks->set_height_request(m_pStyleLB->GetOptimalSize().Height());
      72           0 :     get(m_pFilterLB, "filter");
      73           0 :     get(m_pRemovePB, "remove");
      74           0 :     get(m_pAssignPB, "apply");
      75             : 
      76           0 :     const sal_Int32 nStrCount = m_pFilterLB->GetEntryCount();
      77           0 :     for (sal_Int32 i = 0; i < nStrCount; ++i)
      78           0 :         m_aStrArr.push_back(m_pFilterLB->GetEntry(i));
      79           0 :     m_pFilterLB->Clear();
      80             : 
      81           0 :     SetExchangeSupport();
      82             : 
      83             :     // Install handlers
      84           0 :     m_pConditionCB->SetClickHdl(   LINK(this, SwCondCollPage, OnOffHdl));
      85           0 :     m_pTbLinks->SetDoubleClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
      86           0 :     m_pStyleLB->SetDoubleClickHdl( LINK(this, SwCondCollPage, AssignRemoveHdl ));
      87           0 :     m_pRemovePB->SetClickHdl(      LINK(this, SwCondCollPage, AssignRemoveHdl ));
      88           0 :     m_pAssignPB->SetClickHdl(      LINK(this, SwCondCollPage, AssignRemoveHdl ));
      89           0 :     m_pTbLinks->SetSelectHdl(      LINK(this, SwCondCollPage, SelectHdl));
      90           0 :     m_pStyleLB->SetSelectHdl(      LINK(this, SwCondCollPage, SelectHdl));
      91           0 :     m_pFilterLB->SetSelectHdl(     LINK(this, SwCondCollPage, SelectHdl));
      92             : 
      93           0 :     m_pTbLinks->SetStyle(m_pTbLinks->GetStyle()|WB_HSCROLL|WB_CLIPCHILDREN);
      94           0 :     m_pTbLinks->SetSelectionMode( SINGLE_SELECTION );
      95           0 :     m_pTbLinks->SetTabs( &nTabs[0], MAP_APPFONT );
      96           0 :     m_pTbLinks->Resize();  // OS: Hack for the right selection
      97           0 :     m_pTbLinks->SetSpaceBetweenEntries( 0 );
      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 == (pFamilyItem = aFamilies.at( i ))->GetFamily())
     106           0 :             break;
     107             :     }
     108             : 
     109           0 :     if (pFamilyItem)
     110             :     {
     111           0 :         const SfxStyleFilter& rFilterList = pFamilyItem->GetFilterList();
     112           0 :         for( size_t i = 0; i < rFilterList.size(); ++i )
     113             :         {
     114           0 :             m_pFilterLB->InsertEntry( rFilterList[ i ]->aName);
     115           0 :             sal_uInt16* pFilter = new sal_uInt16(rFilterList[i]->nFlags);
     116           0 :             m_pFilterLB->SetEntryData(i, pFilter);
     117             :         }
     118             :     }
     119           0 :     m_pFilterLB->SelectEntryPos(1);
     120             : 
     121           0 :     m_pTbLinks->Show();
     122             : 
     123           0 : }
     124             : 
     125           0 : SwCondCollPage::~SwCondCollPage()
     126             : {
     127           0 :     for(sal_Int32 i = 0; i < m_pFilterLB->GetEntryCount(); ++i)
     128           0 :         delete (sal_uInt16*)m_pFilterLB->GetEntryData(i);
     129             : 
     130           0 : }
     131             : 
     132           0 : int SwCondCollPage::DeactivatePage(SfxItemSet * _pSet)
     133             : {
     134           0 :     if( _pSet )
     135           0 :         FillItemSet(_pSet);
     136             : 
     137           0 :     return LEAVE_PAGE;
     138             : }
     139             : 
     140           0 : SfxTabPage* SwCondCollPage::Create(vcl::Window *pParent, const SfxItemSet *rSet)
     141             : {
     142           0 :     return new SwCondCollPage(pParent, *rSet);
     143             : }
     144             : 
     145           0 : bool SwCondCollPage::FillItemSet(SfxItemSet *rSet)
     146             : {
     147           0 :     bool bModified = true;
     148           0 :     SwCondCollItem aCondItem;
     149           0 :     for (size_t i = 0; i < m_aStrArr.size(); ++i)
     150             :     {
     151           0 :         const OUString sEntry = m_pTbLinks->GetEntryText(i, 1);
     152           0 :         aCondItem.SetStyle( &sEntry, i);
     153           0 :     }
     154           0 :     rSet->Put(aCondItem);
     155           0 :     return bModified;
     156             : }
     157             : 
     158           0 : void SwCondCollPage::Reset(const SfxItemSet *)
     159             : {
     160           0 :     if(bNewTemplate)
     161           0 :         m_pConditionCB->Enable();
     162           0 :     if(RES_CONDTXTFMTCOLL == pFmt->Which())
     163           0 :         m_pConditionCB->Check();
     164           0 :     OnOffHdl(m_pConditionCB);
     165             : 
     166           0 :     m_pTbLinks->Clear();
     167             : 
     168           0 :     SfxStyleSheetBasePool* pPool = rSh.GetView().GetDocShell()->GetStyleSheetPool();
     169           0 :     pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL);
     170           0 :     m_pStyleLB->Clear();
     171           0 :     const SfxStyleSheetBase* pBase = pPool->First();
     172           0 :     while( pBase )
     173             :     {
     174           0 :         if(!pFmt || pBase->GetName() != pFmt->GetName())
     175           0 :             m_pStyleLB->InsertEntry(pBase->GetName());
     176           0 :         pBase = pPool->Next();
     177             :     }
     178           0 :     m_pStyleLB->SelectEntryPos(0);
     179             : 
     180           0 :     for (size_t n = 0; n < m_aStrArr.size(); ++n)
     181             :     {
     182           0 :         OUString aEntry( m_aStrArr[n] + "\t" );
     183             : 
     184           0 :         const SwCollCondition* pCond = 0;
     185           0 :         if( pFmt && RES_CONDTXTFMTCOLL == pFmt->Which() &&
     186             :             0 != ( pCond = ((SwConditionTxtFmtColl*)pFmt)->
     187           0 :             HasCondition( SwCollCondition( 0, pCmds[n].nCnd, pCmds[n].nSubCond ) ) )
     188           0 :             && pCond->GetTxtFmtColl() )
     189             :         {
     190           0 :             aEntry += pCond->GetTxtFmtColl()->GetName();
     191             :         }
     192             : 
     193           0 :         SvTreeListEntry* pE = m_pTbLinks->InsertEntryToColumn( aEntry, n );
     194           0 :         if(0 == n)
     195           0 :             m_pTbLinks->Select(pE);
     196           0 :     }
     197             : 
     198           0 : }
     199             : 
     200           0 : const sal_uInt16* SwCondCollPage::GetRanges()
     201             : {
     202           0 :     return aPageRg;
     203             : }
     204             : 
     205           0 : IMPL_LINK( SwCondCollPage, OnOffHdl, CheckBox*, pBox )
     206             : {
     207           0 :     const bool bEnable = pBox->IsChecked();
     208           0 :     m_pContextFT->Enable( bEnable );
     209           0 :     m_pUsedFT->Enable( bEnable );
     210           0 :     m_pTbLinks->EnableList( bEnable );
     211           0 :     m_pStyleFT->Enable( bEnable );
     212           0 :     m_pStyleLB->Enable( bEnable );
     213           0 :     m_pFilterLB->Enable( bEnable );
     214           0 :     m_pRemovePB->Enable( bEnable );
     215           0 :     m_pAssignPB->Enable( bEnable );
     216           0 :     if( bEnable )
     217           0 :         SelectHdl(0);
     218           0 :     return 0;
     219             : }
     220             : 
     221           0 : IMPL_LINK( SwCondCollPage, AssignRemoveHdl, PushButton*, pBtn)
     222             : {
     223           0 :     SvTreeListEntry* pE = m_pTbLinks->FirstSelected();
     224             :     sal_uLong nPos;
     225           0 :     if( !pE || LISTBOX_ENTRY_NOTFOUND ==
     226           0 :         ( nPos = m_pTbLinks->GetModel()->GetAbsPos( pE ) ) )
     227             :     {
     228             :         OSL_ENSURE( pE, "where's the empty entry from?" );
     229           0 :         return 0;
     230             :     }
     231             : 
     232           0 :     OUString sSel = m_aStrArr[nPos] + "\t";
     233             : 
     234           0 :     const bool bAssEnabled = pBtn != m_pRemovePB && m_pAssignPB->IsEnabled();
     235           0 :     m_pAssignPB->Enable( !bAssEnabled );
     236           0 :     m_pRemovePB->Enable(  bAssEnabled );
     237           0 :     if ( bAssEnabled )
     238           0 :         sSel += m_pStyleLB->GetSelectEntry();
     239             : 
     240           0 :     m_pTbLinks->SetUpdateMode(false);
     241           0 :     m_pTbLinks->GetModel()->Remove(pE);
     242           0 :     pE = m_pTbLinks->InsertEntryToColumn(sSel, nPos);
     243           0 :     m_pTbLinks->Select(pE);
     244           0 :     m_pTbLinks->MakeVisible(pE);
     245           0 :     m_pTbLinks->SetUpdateMode(true);
     246           0 :     return 0;
     247             : }
     248             : 
     249           0 : IMPL_LINK( SwCondCollPage, SelectHdl, ListBox*, pBox)
     250             : {
     251           0 :     if (pBox == m_pFilterLB)
     252             :     {
     253           0 :         m_pStyleLB->Clear();
     254           0 :         const sal_Int32 nSelPos = pBox->GetSelectEntryPos();
     255           0 :         const sal_uInt16 nSearchFlags = *(sal_uInt16*)m_pFilterLB->GetEntryData(nSelPos);
     256           0 :         SfxStyleSheetBasePool* pPool = rSh.GetView().GetDocShell()->GetStyleSheetPool();
     257           0 :         pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, nSearchFlags);
     258           0 :         const SfxStyleSheetBase* pBase = pPool->First();
     259             : 
     260           0 :         while( pBase )
     261             :         {
     262           0 :             if(!pFmt || pBase->GetName() != pFmt->GetName())
     263           0 :                 m_pStyleLB->InsertEntry(pBase->GetName());
     264           0 :             pBase = pPool->Next();
     265             :         }
     266           0 :         m_pStyleLB->SelectEntryPos(0);
     267           0 :         SelectHdl(m_pStyleLB);
     268             : 
     269             :     }
     270             :     else
     271             :     {
     272           0 :         SvTreeListEntry* pE = m_pTbLinks->FirstSelected();
     273             :         const OUString sTbEntry = pE
     274           0 :             ? m_pTbLinks->GetEntryText(pE).getToken(1, '\t')
     275           0 :             : OUString();
     276           0 :         const OUString sStyle = m_pStyleLB->GetSelectEntry();
     277             : 
     278           0 :         m_pAssignPB->Enable( sStyle != sTbEntry && m_pConditionCB->IsChecked() );
     279             : 
     280           0 :         if(pBox != m_pStyleLB)
     281           0 :             m_pRemovePB->Enable( m_pConditionCB->IsChecked() && !sTbEntry.isEmpty() );
     282             :     }
     283           0 :     return 0;
     284             : }
     285             : 
     286           0 : void SwCondCollPage::SetCollection( SwFmt* pFormat, bool bNew )
     287             : {
     288           0 :     pFmt = pFormat;
     289           0 :     bNewTemplate = bNew;
     290           0 : }
     291             : 
     292             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10