LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/condformat - condformatmgr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 143 0.0 %
Date: 2013-07-09 Functions: 0 27 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             : 
      10             : #include "condformatmgr.hxx"
      11             : #include "condformatmgr.hrc"
      12             : #include "scresid.hxx"
      13             : #include "globstr.hrc"
      14             : #include "condformatdlg.hxx"
      15             : #include "vcl/msgbox.hxx"
      16             : #include "document.hxx"
      17             : 
      18             : #define ITEMID_RANGE 1
      19             : #define ITEMID_CONDITION 2
      20             : 
      21             : 
      22           0 : ScCondFormatManagerWindow::ScCondFormatManagerWindow(Window* pParent, ScDocument* pDoc, ScConditionalFormatList* pFormatList):
      23             :     SvTabListBox(pParent, WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP),
      24             :     maHeaderBar( pParent, WB_BUTTONSTYLE | WB_BOTTOMBORDER ),
      25             :     mpDoc(pDoc),
      26           0 :     mpFormatList(pFormatList)
      27             : {
      28           0 :     Size aBoxSize( pParent->GetOutputSizePixel() );
      29             : 
      30           0 :     maHeaderBar.SetPosSizePixel( Point(0, 0), Size( aBoxSize.Width(), 16 ) );
      31             : 
      32           0 :     String aConditionStr(ScGlobal::GetRscString(STR_HEADER_COND));
      33           0 :     String aRangeStr(ScGlobal::GetRscString(STR_HEADER_RANGE));
      34             : 
      35           0 :     long nTabSize = aBoxSize.Width()/2;
      36           0 :     maHeaderBar.InsertItem( ITEMID_RANGE, aRangeStr, nTabSize, HIB_LEFT| HIB_VCENTER );
      37           0 :     maHeaderBar.InsertItem( ITEMID_CONDITION, aConditionStr, nTabSize, HIB_LEFT| HIB_VCENTER );
      38             : 
      39           0 :     static long nTabs[] = {2, 0, nTabSize };
      40           0 :     Size aHeadSize( maHeaderBar.GetSizePixel() );
      41             : 
      42             :     //pParent->SetFocusControl( this );
      43           0 :     SetPosSizePixel( Point( 0, aHeadSize.Height() ), Size( aBoxSize.Width(), aBoxSize.Height() - aHeadSize.Height() ) );
      44           0 :     SetTabs( &nTabs[0], MAP_PIXEL );
      45             : 
      46           0 :     maHeaderBar.SetEndDragHdl( LINK(this, ScCondFormatManagerWindow, HeaderEndDragHdl ) );
      47           0 :     HeaderEndDragHdl(NULL);
      48             : 
      49           0 :     Init();
      50           0 :     Show();
      51           0 :     maHeaderBar.Show();
      52           0 :     SetSelectionMode(MULTIPLE_SELECTION);
      53           0 : }
      54             : 
      55           0 : String ScCondFormatManagerWindow::createEntryString(const ScConditionalFormat& rFormat)
      56             : {
      57           0 :     ScRangeList aRange = rFormat.GetRange();
      58           0 :     String aStr;
      59           0 :     aRange.Format(aStr, SCA_VALID, mpDoc, mpDoc->GetAddressConvention());
      60           0 :     aStr += '\t';
      61           0 :     aStr += ScCondFormatHelper::GetExpression(rFormat, aRange.GetTopLeftCorner());
      62           0 :     return aStr;
      63             : }
      64             : 
      65           0 : void ScCondFormatManagerWindow::Init()
      66             : {
      67           0 :     SetUpdateMode(false);
      68             : 
      69           0 :     for(ScConditionalFormatList::iterator itr = mpFormatList->begin(); itr != mpFormatList->end(); ++itr)
      70             :     {
      71           0 :         SvTreeListEntry* pEntry = InsertEntryToColumn( createEntryString(*itr), LIST_APPEND, 0xffff );
      72           0 :         maMapLBoxEntryToCondIndex.insert(std::pair<SvTreeListEntry*,sal_Int32>(pEntry,itr->GetKey()));
      73             :     }
      74           0 :     SetUpdateMode(true);
      75           0 : }
      76             : 
      77           0 : void ScCondFormatManagerWindow::DeleteSelection()
      78             : {
      79           0 :     if(GetSelectionCount())
      80             :     {
      81           0 :         for(SvTreeListEntry* pEntry = FirstSelected(); pEntry != NULL; pEntry = NextSelected(pEntry))
      82             :         {
      83           0 :             sal_Int32 nIndex = maMapLBoxEntryToCondIndex.find(pEntry)->second;
      84           0 :             mpFormatList->erase(nIndex);
      85             :         }
      86           0 :         RemoveSelection();
      87             :     }
      88           0 : }
      89             : 
      90           0 : ScConditionalFormat* ScCondFormatManagerWindow::GetSelection()
      91             : {
      92           0 :     SvTreeListEntry* pEntry = FirstSelected();
      93           0 :     if(!pEntry)
      94           0 :         return NULL;
      95             : 
      96           0 :     sal_Int32 nIndex = maMapLBoxEntryToCondIndex.find(pEntry)->second;
      97           0 :     return mpFormatList->GetFormat(nIndex);
      98             : }
      99             : 
     100           0 : void ScCondFormatManagerWindow::Update()
     101             : {
     102           0 :     Clear();
     103           0 :     maMapLBoxEntryToCondIndex.clear();
     104           0 :     Init();
     105           0 : }
     106             : 
     107           0 : IMPL_LINK_NOARG(ScCondFormatManagerWindow, HeaderEndDragHdl)
     108             : {
     109           0 :     long aTableSize = maHeaderBar.GetSizePixel().Width();
     110           0 :     long aItemRangeSize = maHeaderBar.GetItemSize(ITEMID_RANGE);
     111             : 
     112             :     //calculate column size based on user input and minimum size
     113           0 :     long aItemCondSize = aTableSize - aItemRangeSize;
     114             : 
     115           0 :     Size aSz;
     116           0 :     aSz.Width() = aItemRangeSize;
     117           0 :     SetTab( ITEMID_RANGE, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
     118           0 :     maHeaderBar.SetItemSize(ITEMID_RANGE, aItemRangeSize);
     119           0 :     aSz.Width() += aItemCondSize;
     120           0 :     SetTab( ITEMID_CONDITION, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
     121           0 :     maHeaderBar.SetItemSize(ITEMID_CONDITION, aItemCondSize);
     122             : 
     123           0 :     return 0;
     124             : }
     125             : 
     126           0 : ScCondFormatManagerCtrl::ScCondFormatManagerCtrl(Window* pParent, ScDocument* pDoc, ScConditionalFormatList* pFormatList):
     127             :     Control(pParent, ScResId(CTRL_TABLE)),
     128           0 :     maWdManager(this, pDoc, pFormatList)
     129             : {
     130           0 : }
     131             : 
     132           0 : ScConditionalFormat* ScCondFormatManagerCtrl::GetSelection()
     133             : {
     134           0 :     return maWdManager.GetSelection();
     135             : }
     136             : 
     137           0 : void ScCondFormatManagerCtrl::DeleteSelection()
     138             : {
     139           0 :     maWdManager.DeleteSelection();
     140           0 : }
     141             : 
     142           0 : void ScCondFormatManagerCtrl::Update()
     143             : {
     144           0 :     maWdManager.Update();
     145           0 : }
     146             : 
     147           0 : ScCondFormatManagerDlg::ScCondFormatManagerDlg(Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList, const ScAddress& rPos):
     148             :     ModalDialog(pParent, ScResId(RID_SCDLG_COND_FORMAT_MANAGER)),
     149             :     maBtnAdd(this, ScResId(BTN_ADD)),
     150             :     maBtnRemove(this, ScResId(BTN_REMOVE)),
     151             :     maBtnEdit(this, ScResId(BTN_EDIT)),
     152             :     maBtnOk(this, ScResId(BTN_OK)),
     153             :     maBtnCancel(this, ScResId(BTN_CANCEL)),
     154             :     maFlLine(this, ScResId(FL_LINE)),
     155           0 :     mpFormatList( pFormatList ? new ScConditionalFormatList(*pFormatList) : NULL),
     156             :     maCtrlManager(this, pDoc, mpFormatList),
     157             :     mpDoc(pDoc),
     158             :     maPos(rPos),
     159           0 :     mbModified(false)
     160             : {
     161           0 :     FreeResource();
     162             : 
     163           0 :     maBtnRemove.SetClickHdl(LINK(this, ScCondFormatManagerDlg, RemoveBtnHdl));
     164           0 :     maBtnEdit.SetClickHdl(LINK(this, ScCondFormatManagerDlg, EditBtnHdl));
     165           0 :     maBtnAdd.SetClickHdl(LINK(this, ScCondFormatManagerDlg, AddBtnHdl));
     166           0 :     maCtrlManager.GetListControl().SetDoubleClickHdl(LINK(this, ScCondFormatManagerDlg, EditBtnHdl));
     167           0 : }
     168             : 
     169           0 : ScCondFormatManagerDlg::~ScCondFormatManagerDlg()
     170             : {
     171           0 :     delete mpFormatList;
     172           0 : }
     173             : 
     174           0 : bool ScCondFormatManagerDlg::IsInRefMode() const
     175             : {
     176           0 :     return true;
     177             : }
     178             : 
     179           0 : ScConditionalFormatList* ScCondFormatManagerDlg::GetConditionalFormatList()
     180             : {
     181           0 :     ScConditionalFormatList* pList = mpFormatList;
     182           0 :     mpFormatList = NULL;
     183           0 :     return pList;
     184             : }
     185             : 
     186           0 : bool ScCondFormatManagerDlg::CondFormatsChanged()
     187             : {
     188           0 :     return mbModified;
     189             : }
     190             : 
     191           0 : IMPL_LINK_NOARG(ScCondFormatManagerDlg, RemoveBtnHdl)
     192             : {
     193           0 :     maCtrlManager.DeleteSelection();
     194           0 :     mbModified = true;
     195           0 :     return 0;
     196             : }
     197             : 
     198           0 : IMPL_LINK_NOARG(ScCondFormatManagerDlg, EditBtnHdl)
     199             : {
     200           0 :     ScConditionalFormat* pFormat = maCtrlManager.GetSelection();
     201             : 
     202           0 :     if(!pFormat)
     203           0 :         return 0;
     204             : 
     205           0 :     sal_uInt16 nId = 1;
     206           0 :     ScModule* pScMod = SC_MOD();
     207           0 :     pScMod->SetRefDialog( nId, true );
     208             :     boost::scoped_ptr<ScCondFormatDlg> pDlg(new ScCondFormatDlg(this, mpDoc, pFormat, pFormat->GetRange(),
     209           0 :                                                pFormat->GetRange().GetTopLeftCorner(), condformat::dialog::NONE));
     210           0 :     Show(false, 0);
     211           0 :     if(pDlg->Execute() == RET_OK)
     212             :     {
     213           0 :         sal_Int32 nKey = pFormat->GetKey();
     214           0 :         mpFormatList->erase(nKey);
     215           0 :         ScConditionalFormat* pNewFormat = pDlg->GetConditionalFormat();
     216           0 :         if(pNewFormat)
     217             :         {
     218           0 :             pNewFormat->SetKey(nKey);
     219           0 :             mpFormatList->InsertNew(pNewFormat);
     220             :         }
     221             : 
     222           0 :         maCtrlManager.Update();
     223           0 :         mbModified = true;
     224             :     }
     225           0 :     Show(true, 0);
     226             : 
     227           0 :     pScMod->SetRefDialog( nId, false );
     228             : 
     229           0 :     return 0;
     230             : }
     231             : 
     232             : namespace {
     233             : 
     234           0 : sal_uInt32 FindKey(ScConditionalFormatList* pFormatList)
     235             : {
     236           0 :     sal_uInt32 nKey = 0;
     237           0 :     for(ScConditionalFormatList::const_iterator itr = pFormatList->begin(), itrEnd = pFormatList->end();
     238             :             itr != itrEnd; ++itr)
     239             :     {
     240           0 :         if(itr->GetKey() > nKey)
     241           0 :             nKey = itr->GetKey();
     242             :     }
     243             : 
     244           0 :     return nKey + 1;
     245             : }
     246             : 
     247             : }
     248             : 
     249           0 : IMPL_LINK_NOARG(ScCondFormatManagerDlg, AddBtnHdl)
     250             : {
     251           0 :     sal_uInt16 nId = 1;
     252           0 :     ScModule* pScMod = SC_MOD();
     253           0 :     pScMod->SetRefDialog( nId, true );
     254             :     boost::scoped_ptr<ScCondFormatDlg> pDlg(new ScCondFormatDlg(this, mpDoc, NULL, ScRangeList(),
     255           0 :                                                maPos, condformat::dialog::CONDITION));
     256           0 :     Show(false, 0);
     257           0 :     if(pDlg->Execute() == RET_OK)
     258             :     {
     259           0 :         ScConditionalFormat* pNewFormat = pDlg->GetConditionalFormat();
     260           0 :         if(pNewFormat)
     261             :         {
     262           0 :             mpFormatList->InsertNew(pNewFormat);
     263           0 :             pNewFormat->SetKey(FindKey(mpFormatList));
     264           0 :             maCtrlManager.Update();
     265             : 
     266           0 :             mbModified = true;
     267             :         }
     268             :     }
     269           0 :     Show(true, 0);
     270           0 :     pScMod->SetRefDialog( nId, false );
     271             : 
     272           0 :     return 0;
     273           0 : }
     274             : 
     275             : 
     276             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10