LCOV - code coverage report
Current view: top level - sc/source/ui/condformat - condformatmgr.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 101 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 21 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 "scresid.hxx"
      12             : #include "globstr.hrc"
      13             : #include "condformatdlg.hxx"
      14             : #include <vcl/msgbox.hxx>
      15             : #include "document.hxx"
      16             : 
      17           0 : ScCondFormatManagerWindow::ScCondFormatManagerWindow(SvSimpleTableContainer& rParent,
      18             :     ScDocument* pDoc, ScConditionalFormatList* pFormatList)
      19             :     : SvSimpleTable(rParent, WB_HSCROLL | WB_SORT | WB_TABSTOP)
      20             :     , mpDoc(pDoc)
      21           0 :     , mpFormatList(pFormatList)
      22             : {
      23           0 :     OUString aConditionStr(ScGlobal::GetRscString(STR_HEADER_COND));
      24           0 :     OUString aRangeStr(ScGlobal::GetRscString(STR_HEADER_RANGE));
      25             : 
      26           0 :     OUStringBuffer sHeader;
      27           0 :     sHeader.append(aRangeStr).append("\t").append(aConditionStr);
      28           0 :     InsertHeaderEntry(sHeader.makeStringAndClear(), HEADERBAR_APPEND, HeaderBarItemBits::LEFT | HeaderBarItemBits::VCENTER);
      29           0 :     setColSizes();
      30             : 
      31           0 :     Init();
      32           0 :     Show();
      33           0 :     SetSelectionMode(MULTIPLE_SELECTION);
      34           0 : }
      35             : 
      36           0 : OUString ScCondFormatManagerWindow::createEntryString(const ScConditionalFormat& rFormat)
      37             : {
      38           0 :     ScRangeList aRange = rFormat.GetRange();
      39           0 :     OUString aStr;
      40           0 :     aRange.Format(aStr, SCA_VALID, mpDoc, mpDoc->GetAddressConvention());
      41           0 :     aStr += "\t";
      42           0 :     aStr += ScCondFormatHelper::GetExpression(rFormat, aRange.GetTopLeftCorner());
      43           0 :     return aStr;
      44             : }
      45             : 
      46           0 : void ScCondFormatManagerWindow::Init()
      47             : {
      48           0 :     SetUpdateMode(false);
      49             : 
      50           0 :     if (mpFormatList)
      51             :     {
      52           0 :         for(ScConditionalFormatList::iterator itr = mpFormatList->begin(); itr != mpFormatList->end(); ++itr)
      53             :         {
      54           0 :             SvTreeListEntry* pEntry = InsertEntryToColumn( createEntryString(*itr), TREELIST_APPEND, 0xffff );
      55           0 :             maMapLBoxEntryToCondIndex.insert(std::pair<SvTreeListEntry*,sal_Int32>(pEntry,itr->GetKey()));
      56             :         }
      57             :     }
      58             : 
      59           0 :     SetUpdateMode(true);
      60             : 
      61           0 :     if (mpFormatList && mpFormatList->size())
      62           0 :         SelectRow(0);
      63           0 : }
      64             : 
      65           0 : void ScCondFormatManagerWindow::Resize()
      66             : {
      67           0 :     SvSimpleTable::Resize();
      68           0 :     if (GetParentDialog()->isCalculatingInitialLayoutSize())
      69           0 :         setColSizes();
      70           0 : }
      71             : 
      72           0 : void ScCondFormatManagerWindow::DeleteSelection()
      73             : {
      74           0 :     if(GetSelectionCount())
      75             :     {
      76           0 :         for(SvTreeListEntry* pEntry = FirstSelected(); pEntry != NULL; pEntry = NextSelected(pEntry))
      77             :         {
      78           0 :             sal_Int32 nIndex = maMapLBoxEntryToCondIndex.find(pEntry)->second;
      79           0 :             mpFormatList->erase(nIndex);
      80             :         }
      81           0 :         RemoveSelection();
      82             :     }
      83           0 : }
      84             : 
      85           0 : ScConditionalFormat* ScCondFormatManagerWindow::GetSelection()
      86             : {
      87           0 :     SvTreeListEntry* pEntry = FirstSelected();
      88           0 :     if(!pEntry)
      89           0 :         return NULL;
      90             : 
      91           0 :     sal_Int32 nIndex = maMapLBoxEntryToCondIndex.find(pEntry)->second;
      92           0 :     return mpFormatList->GetFormat(nIndex);
      93             : }
      94             : 
      95           0 : void ScCondFormatManagerWindow::setColSizes()
      96             : {
      97           0 :     HeaderBar &rBar = GetTheHeaderBar();
      98           0 :     if (rBar.GetItemCount() < 2)
      99           0 :         return;
     100           0 :     long aStaticTabs[]= { 2, 0, 0 };
     101           0 :     aStaticTabs[2] = rBar.GetSizePixel().Width() / 2;
     102           0 :     SvSimpleTable::SetTabs(aStaticTabs, MAP_PIXEL);
     103             : }
     104             : 
     105           0 : ScCondFormatManagerDlg::ScCondFormatManagerDlg(vcl::Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList, const ScAddress& rPos):
     106             :     ModalDialog(pParent, "CondFormatManager", "modules/scalc/ui/condformatmanager.ui"),
     107           0 :     mpFormatList( pFormatList ? new ScConditionalFormatList(*pFormatList) : NULL),
     108             :     mpDoc(pDoc),
     109             :     maPos(rPos),
     110           0 :     mbModified(false)
     111             : {
     112           0 :     SvSimpleTableContainer *pContainer = get<SvSimpleTableContainer>("CONTAINER");
     113           0 :     Size aSize(LogicToPixel(Size(290, 220), MAP_APPFONT));
     114           0 :     pContainer->set_width_request(aSize.Width());
     115           0 :     pContainer->set_height_request(aSize.Height());
     116           0 :     m_pCtrlManager = VclPtr<ScCondFormatManagerWindow>::Create(*pContainer, mpDoc, mpFormatList);
     117           0 :     get(m_pBtnAdd, "add");
     118           0 :     get(m_pBtnRemove, "remove");
     119           0 :     get(m_pBtnEdit, "edit");
     120             : 
     121           0 :     m_pBtnRemove->SetClickHdl(LINK(this, ScCondFormatManagerDlg, RemoveBtnHdl));
     122           0 :     m_pBtnEdit->SetClickHdl(LINK(this, ScCondFormatManagerDlg, EditBtnHdl));
     123           0 :     m_pBtnAdd->SetClickHdl(LINK(this, ScCondFormatManagerDlg, AddBtnHdl));
     124           0 :     m_pCtrlManager->SetDoubleClickHdl(LINK(this, ScCondFormatManagerDlg, EditBtnHdl));
     125           0 : }
     126             : 
     127           0 : ScCondFormatManagerDlg::~ScCondFormatManagerDlg()
     128             : {
     129           0 :     disposeOnce();
     130           0 : }
     131             : 
     132           0 : void ScCondFormatManagerDlg::dispose()
     133             : {
     134           0 :     delete mpFormatList;
     135           0 :     m_pBtnAdd.clear();
     136           0 :     m_pBtnRemove.clear();
     137           0 :     m_pBtnEdit.clear();
     138           0 :     m_pCtrlManager.disposeAndClear();
     139           0 :     ModalDialog::dispose();
     140           0 : }
     141             : 
     142             : 
     143           0 : ScConditionalFormatList* ScCondFormatManagerDlg::GetConditionalFormatList()
     144             : {
     145           0 :     ScConditionalFormatList* pList = mpFormatList;
     146           0 :     mpFormatList = NULL;
     147           0 :     return pList;
     148             : }
     149             : 
     150             : // ---------------------------------------------------------------
     151             : // Get the current conditional format selected.
     152             : //
     153           0 : ScConditionalFormat* ScCondFormatManagerDlg::GetCondFormatSelected()
     154             : {
     155           0 :     return m_pCtrlManager->GetSelection();
     156             : }
     157             : 
     158           0 : IMPL_LINK_NOARG(ScCondFormatManagerDlg, RemoveBtnHdl)
     159             : {
     160           0 :     m_pCtrlManager->DeleteSelection();
     161           0 :     mbModified = true;
     162           0 :     return 0;
     163             : }
     164             : 
     165           0 : IMPL_LINK_NOARG(ScCondFormatManagerDlg, EditBtnHdl)
     166             : {
     167           0 :     ScConditionalFormat* pFormat = m_pCtrlManager->GetSelection();
     168             : 
     169           0 :     if(!pFormat)
     170           0 :         return 0;
     171             : 
     172           0 :     EndDialog( DLG_RET_EDIT );
     173             : 
     174           0 :     return 0;
     175             : }
     176             : 
     177           0 : IMPL_LINK_NOARG(ScCondFormatManagerDlg, AddBtnHdl)
     178             : {
     179           0 :     EndDialog( DLG_RET_ADD );
     180             : 
     181           0 :     return 0;
     182           0 : }
     183             : 
     184             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11