LCOV - code coverage report
Current view: top level - sw/source/ui/chrdlg - swuiccoll.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 158 0.0 %
Date: 2014-04-14 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 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(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(sal_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 :     sal_uInt16 nStrCount = m_pFilterLB->GetEntryCount();
      77           0 :     for (sal_uInt16 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 == (sal_uInt16)(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             : /****************************************************************************
     126             : Page: Dtor
     127             : ****************************************************************************/
     128             : 
     129           0 : SwCondCollPage::~SwCondCollPage()
     130             : {
     131           0 :     for(sal_uInt16 i = 0; i < m_pFilterLB->GetEntryCount(); ++i)
     132           0 :         delete (sal_uInt16*)m_pFilterLB->GetEntryData(i);
     133             : 
     134           0 : }
     135             : 
     136           0 : int SwCondCollPage::DeactivatePage(SfxItemSet * _pSet)
     137             : {
     138           0 :     if( _pSet )
     139           0 :         FillItemSet(*_pSet);
     140             : 
     141           0 :     return LEAVE_PAGE;
     142             : }
     143             : 
     144             : /****************************************************************************
     145             : Page: Factory
     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           0 : bool SwCondCollPage::FillItemSet(SfxItemSet &rSet)
     158             : {
     159           0 :     sal_Bool bModified = sal_True;
     160           0 :     SwCondCollItem aCondItem;
     161           0 :     for (size_t i = 0; i < m_aStrArr.size(); ++i)
     162             :     {
     163           0 :         OUString sEntry = m_pTbLinks->GetEntryText(i, 1);
     164           0 :         aCondItem.SetStyle( &sEntry, i);
     165           0 :     }
     166           0 :     rSet.Put(aCondItem);
     167           0 :     return bModified;
     168             : }
     169             : 
     170             : /****************************************************************************
     171             : Page: Reset-Overload
     172             : ****************************************************************************/
     173             : 
     174           0 : void SwCondCollPage::Reset(const SfxItemSet &/*rSet*/)
     175             : {
     176           0 :     if(bNewTemplate)
     177           0 :         m_pConditionCB->Enable();
     178           0 :     if(RES_CONDTXTFMTCOLL == pFmt->Which())
     179           0 :         m_pConditionCB->Check();
     180           0 :     OnOffHdl(m_pConditionCB);
     181             : 
     182           0 :     m_pTbLinks->Clear();
     183             : 
     184           0 :     SfxStyleSheetBasePool* pPool = rSh.GetView().GetDocShell()->GetStyleSheetPool();
     185           0 :     pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, SFXSTYLEBIT_ALL);
     186           0 :     m_pStyleLB->Clear();
     187           0 :     const SfxStyleSheetBase* pBase = pPool->First();
     188           0 :     while( pBase )
     189             :     {
     190           0 :         if(!pFmt || pBase->GetName() != pFmt->GetName())
     191           0 :             m_pStyleLB->InsertEntry(pBase->GetName());
     192           0 :         pBase = pPool->Next();
     193             :     }
     194           0 :     m_pStyleLB->SelectEntryPos(0);
     195             : 
     196           0 :     for (size_t n = 0; n < m_aStrArr.size(); ++n)
     197             :     {
     198           0 :         OUString aEntry( m_aStrArr[n] + "\t" );
     199             : 
     200           0 :         const SwCollCondition* pCond = 0;
     201           0 :         if( pFmt && RES_CONDTXTFMTCOLL == pFmt->Which() &&
     202             :             0 != ( pCond = ((SwConditionTxtFmtColl*)pFmt)->
     203           0 :             HasCondition( SwCollCondition( 0, pCmds[n].nCnd, pCmds[n].nSubCond ) ) )
     204           0 :             && pCond->GetTxtFmtColl() )
     205             :         {
     206           0 :             aEntry += pCond->GetTxtFmtColl()->GetName();
     207             :         }
     208             : 
     209           0 :         SvTreeListEntry* pE = m_pTbLinks->InsertEntryToColumn( aEntry, n );
     210           0 :         if(0 == n)
     211           0 :             m_pTbLinks->Select(pE);
     212           0 :     }
     213             : 
     214           0 : }
     215             : 
     216           0 : sal_uInt16* SwCondCollPage::GetRanges()
     217             : {
     218           0 :     return aPageRg;
     219             : }
     220             : 
     221           0 : IMPL_LINK( SwCondCollPage, OnOffHdl, CheckBox*, pBox )
     222             : {
     223           0 :     const sal_Bool bEnable = pBox->IsChecked();
     224           0 :     m_pContextFT->Enable( bEnable );
     225           0 :     m_pUsedFT->Enable( bEnable );
     226           0 :     m_pTbLinks->EnableList( bEnable != sal_False );
     227           0 :     m_pStyleFT->Enable( bEnable );
     228           0 :     m_pStyleLB->Enable( bEnable );
     229           0 :     m_pFilterLB->Enable( bEnable );
     230           0 :     m_pRemovePB->Enable( bEnable );
     231           0 :     m_pAssignPB->Enable( bEnable );
     232           0 :     if( bEnable )
     233           0 :         SelectHdl(0);
     234           0 :     return 0;
     235             : }
     236             : 
     237           0 : IMPL_LINK( SwCondCollPage, AssignRemoveHdl, PushButton*, pBtn)
     238             : {
     239           0 :     SvTreeListEntry* pE = m_pTbLinks->FirstSelected();
     240             :     sal_uLong nPos;
     241           0 :     if( !pE || LISTBOX_ENTRY_NOTFOUND ==
     242           0 :         ( nPos = m_pTbLinks->GetModel()->GetAbsPos( pE ) ) )
     243             :     {
     244             :         OSL_ENSURE( pE, "where's the empty entry from?" );
     245           0 :         return 0;
     246             :     }
     247             : 
     248           0 :     OUString sSel = m_aStrArr[nPos];
     249           0 :     sSel += "\t";
     250             : 
     251           0 :     const sal_Bool bAssEnabled = pBtn != m_pRemovePB && m_pAssignPB->IsEnabled();
     252           0 :     m_pAssignPB->Enable( !bAssEnabled );
     253           0 :     m_pRemovePB->Enable(  bAssEnabled );
     254           0 :     if ( bAssEnabled )
     255           0 :         sSel += m_pStyleLB->GetSelectEntry();
     256             : 
     257           0 :     m_pTbLinks->SetUpdateMode(false);
     258           0 :     m_pTbLinks->GetModel()->Remove(pE);
     259           0 :     pE = m_pTbLinks->InsertEntryToColumn(sSel, nPos);
     260           0 :     m_pTbLinks->Select(pE);
     261           0 :     m_pTbLinks->MakeVisible(pE);
     262           0 :     m_pTbLinks->SetUpdateMode(true);
     263           0 :     return 0;
     264             : }
     265             : 
     266           0 : IMPL_LINK( SwCondCollPage, SelectHdl, ListBox*, pBox)
     267             : {
     268           0 :     if (pBox == m_pFilterLB)
     269             :     {
     270           0 :         m_pStyleLB->Clear();
     271           0 :         sal_uInt16 nSearchFlags = pBox->GetSelectEntryPos();
     272           0 :         nSearchFlags = *(sal_uInt16*)m_pFilterLB->GetEntryData(nSearchFlags);
     273           0 :         SfxStyleSheetBasePool* pPool = rSh.GetView().GetDocShell()->GetStyleSheetPool();
     274           0 :         pPool->SetSearchMask(SFX_STYLE_FAMILY_PARA, nSearchFlags);
     275           0 :         const SfxStyleSheetBase* pBase = pPool->First();
     276             : 
     277           0 :         while( pBase )
     278             :         {
     279           0 :             if(!pFmt || pBase->GetName() != pFmt->GetName())
     280           0 :                 m_pStyleLB->InsertEntry(pBase->GetName());
     281           0 :             pBase = pPool->Next();
     282             :         }
     283           0 :         m_pStyleLB->SelectEntryPos(0);
     284           0 :         SelectHdl(m_pStyleLB);
     285             : 
     286             :     }
     287             :     else
     288             :     {
     289           0 :         OUString sTbEntry;
     290           0 :         SvTreeListEntry* pE = m_pTbLinks->FirstSelected();
     291           0 :         if(pE)
     292           0 :             sTbEntry = m_pTbLinks->GetEntryText(pE);
     293           0 :         sTbEntry = sTbEntry.getToken(1, '\t');
     294           0 :         OUString sStyle = m_pStyleLB->GetSelectEntry();
     295             : 
     296           0 :         m_pAssignPB->Enable( sStyle != sTbEntry && m_pConditionCB->IsChecked() );
     297             : 
     298           0 :         if(pBox != m_pStyleLB)
     299           0 :             m_pRemovePB->Enable( m_pConditionCB->IsChecked() && !sTbEntry.isEmpty() );
     300             :     }
     301           0 :     return 0;
     302             : }
     303             : 
     304           0 : void SwCondCollPage::SetCollection( SwFmt* pFormat, sal_Bool bNew )
     305             : {
     306           0 :     pFmt = pFormat;
     307           0 :     bNewTemplate = bNew;
     308           0 : }
     309             : 
     310             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10