LCOV - code coverage report
Current view: top level - sc/source/ui/condformat - condformatmgr.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 107 0.0 %
Date: 2012-08-25 Functions: 0 20 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * Version: MPL 1.1 / GPLv3+ / LGPLv3+
       4                 :            :  *
       5                 :            :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :            :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :            :  * the License or as specified alternatively below. You may obtain a copy of
       8                 :            :  * the License at http://www.mozilla.org/MPL/
       9                 :            :  *
      10                 :            :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :            :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :            :  * for the specific language governing rights and limitations under the
      13                 :            :  * License.
      14                 :            :  *
      15                 :            :  * Major Contributor(s):
      16                 :            :  * Copyright (C) 2012 Markus Mohrhard <markus.mohrhard@googlemail.com> (initial developer)
      17                 :            :  *
      18                 :            :  * All Rights Reserved.
      19                 :            :  *
      20                 :            :  * For minor contributions see the git repository.
      21                 :            :  *
      22                 :            :  * Alternatively, the contents of this file may be used under the terms of
      23                 :            :  * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
      24                 :            :  * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
      25                 :            :  * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
      26                 :            :  * instead of those above.
      27                 :            :  */
      28                 :            : 
      29                 :            : #include "condformatmgr.hxx"
      30                 :            : #include "condformatmgr.hrc"
      31                 :            : #include "scresid.hxx"
      32                 :            : #include "globstr.hrc"
      33                 :            : #include "condformatdlg.hxx"
      34                 :            : #include "vcl/msgbox.hxx"
      35                 :            : 
      36                 :            : #define ITEMID_RANGE 1
      37                 :            : #define ITEMID_CONDITION 2
      38                 :            : 
      39                 :            : 
      40                 :          0 : ScCondFormatManagerWindow::ScCondFormatManagerWindow(Window* pParent, ScDocument* pDoc, ScConditionalFormatList* pFormatList, const ScAddress& rPos):
      41                 :            :     SvTabListBox(pParent, WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP),
      42                 :            :     maHeaderBar( pParent, WB_BUTTONSTYLE | WB_BOTTOMBORDER ),
      43                 :            :     mpDoc(pDoc),
      44                 :            :     mpFormatList(pFormatList),
      45                 :          0 :     mrPos(rPos)
      46                 :            : {
      47                 :          0 :     Size aBoxSize( pParent->GetOutputSizePixel() );
      48                 :            : 
      49                 :          0 :     maHeaderBar.SetPosSizePixel( Point(0, 0), Size( aBoxSize.Width(), 16 ) );
      50                 :            : 
      51                 :          0 :     String aConditionStr(ScGlobal::GetRscString(STR_HEADER_COND));
      52                 :          0 :     String aRangeStr(ScGlobal::GetRscString(STR_HEADER_RANGE));
      53                 :            : 
      54                 :          0 :     long nTabSize = aBoxSize.Width()/2;
      55                 :          0 :     maHeaderBar.InsertItem( ITEMID_RANGE, aRangeStr, nTabSize, HIB_LEFT| HIB_VCENTER );
      56                 :          0 :     maHeaderBar.InsertItem( ITEMID_CONDITION, aConditionStr, nTabSize, HIB_LEFT| HIB_VCENTER );
      57                 :            : 
      58                 :          0 :     static long nTabs[] = {2, 0, nTabSize };
      59                 :          0 :     Size aHeadSize( maHeaderBar.GetSizePixel() );
      60                 :            : 
      61                 :            :     //pParent->SetFocusControl( this );
      62                 :          0 :     SetPosSizePixel( Point( 0, aHeadSize.Height() ), Size( aBoxSize.Width(), aBoxSize.Height() - aHeadSize.Height() ) );
      63                 :          0 :     SetTabs( &nTabs[0], MAP_PIXEL );
      64                 :            : 
      65                 :          0 :     maHeaderBar.SetEndDragHdl( LINK(this, ScCondFormatManagerWindow, HeaderEndDragHdl ) );
      66                 :          0 :     HeaderEndDragHdl(NULL);
      67                 :            : 
      68                 :          0 :     Init();
      69                 :          0 :     Show();
      70                 :          0 :     maHeaderBar.Show();
      71                 :          0 :     SetSelectionMode(MULTIPLE_SELECTION);
      72                 :          0 : }
      73                 :            : 
      74                 :          0 : String ScCondFormatManagerWindow::createEntryString(const ScConditionalFormat& rFormat)
      75                 :            : {
      76                 :          0 :     ScRangeList aRange = rFormat.GetRange();
      77                 :          0 :     String aStr;
      78                 :          0 :     aRange.Format(aStr, SCA_VALID, mpDoc, mpDoc->GetAddressConvention());
      79                 :          0 :     aStr += '\t';
      80                 :          0 :     aStr += ScCondFormatHelper::GetExpression(rFormat, mrPos);
      81                 :          0 :     return aStr;
      82                 :            : }
      83                 :            : 
      84                 :          0 : void ScCondFormatManagerWindow::Init()
      85                 :            : {
      86                 :          0 :     SetUpdateMode(false);
      87                 :            : 
      88                 :          0 :     for(ScConditionalFormatList::iterator itr = mpFormatList->begin(); itr != mpFormatList->end(); ++itr)
      89                 :            :     {
      90                 :          0 :         SvLBoxEntry* pEntry = InsertEntryToColumn( createEntryString(*itr), LIST_APPEND, 0xffff );
      91                 :          0 :         maMapLBoxEntryToCondIndex.insert(std::pair<SvLBoxEntry*,sal_Int32>(pEntry,itr->GetKey()));
      92                 :            :     }
      93                 :          0 :     SetUpdateMode(true);
      94                 :          0 : }
      95                 :            : 
      96                 :          0 : void ScCondFormatManagerWindow::DeleteSelection()
      97                 :            : {
      98                 :          0 :     if(GetSelectionCount())
      99                 :            :     {
     100                 :          0 :         for(SvLBoxEntry* pEntry = FirstSelected(); pEntry != NULL; pEntry = NextSelected(pEntry))
     101                 :            :         {
     102                 :          0 :             sal_Int32 nIndex = maMapLBoxEntryToCondIndex.find(pEntry)->second;
     103                 :          0 :             mpFormatList->erase(nIndex);
     104                 :            :         }
     105                 :          0 :         RemoveSelection();
     106                 :            :     }
     107                 :          0 : }
     108                 :            : 
     109                 :          0 : ScConditionalFormat* ScCondFormatManagerWindow::GetSelection()
     110                 :            : {
     111                 :          0 :     SvLBoxEntry* pEntry = FirstSelected();
     112                 :          0 :     if(!pEntry)
     113                 :          0 :         return NULL;
     114                 :            : 
     115                 :          0 :     sal_Int32 nIndex = maMapLBoxEntryToCondIndex.find(pEntry)->second;
     116                 :          0 :     return mpFormatList->GetFormat(nIndex);
     117                 :            : }
     118                 :            : 
     119                 :          0 : void ScCondFormatManagerWindow::Update()
     120                 :            : {
     121                 :          0 :     Clear();
     122                 :          0 :     maMapLBoxEntryToCondIndex.clear();
     123                 :          0 :     Init();
     124                 :          0 : }
     125                 :            : 
     126                 :          0 : IMPL_LINK_NOARG(ScCondFormatManagerWindow, HeaderEndDragHdl)
     127                 :            : {
     128                 :          0 :     long aTableSize = maHeaderBar.GetSizePixel().Width();
     129                 :          0 :     long aItemRangeSize = maHeaderBar.GetItemSize(ITEMID_RANGE);
     130                 :            : 
     131                 :            :     //calculate column size based on user input and minimum size
     132                 :          0 :     long aItemCondSize = aTableSize - aItemRangeSize;
     133                 :            : 
     134                 :          0 :     Size aSz;
     135                 :          0 :     aSz.Width() = aItemRangeSize;
     136                 :          0 :     SetTab( ITEMID_RANGE, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
     137                 :          0 :     maHeaderBar.SetItemSize(ITEMID_RANGE, aItemRangeSize);
     138                 :          0 :     aSz.Width() += aItemCondSize;
     139                 :          0 :     SetTab( ITEMID_CONDITION, PixelToLogic( aSz, MapMode(MAP_APPFONT) ).Width(), MAP_APPFONT );
     140                 :          0 :     maHeaderBar.SetItemSize(ITEMID_CONDITION, aItemCondSize);
     141                 :            : 
     142                 :          0 :     return 0;
     143                 :            : }
     144                 :            : 
     145                 :          0 : ScCondFormatManagerCtrl::ScCondFormatManagerCtrl(Window* pParent, ScDocument* pDoc, ScConditionalFormatList* pFormatList, const ScAddress& rPos):
     146                 :            :     Control(pParent, ScResId(CTRL_TABLE)),
     147                 :          0 :     maWdManager(this, pDoc, pFormatList, rPos)
     148                 :            : {
     149                 :          0 : }
     150                 :            : 
     151                 :          0 : ScConditionalFormat* ScCondFormatManagerCtrl::GetSelection()
     152                 :            : {
     153                 :          0 :     return maWdManager.GetSelection();
     154                 :            : }
     155                 :            : 
     156                 :          0 : void ScCondFormatManagerCtrl::DeleteSelection()
     157                 :            : {
     158                 :          0 :     maWdManager.DeleteSelection();
     159                 :          0 : }
     160                 :            : 
     161                 :          0 : void ScCondFormatManagerCtrl::Update()
     162                 :            : {
     163                 :          0 :     maWdManager.Update();
     164                 :          0 : }
     165                 :            : 
     166                 :          0 : ScCondFormatManagerDlg::ScCondFormatManagerDlg(Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList, const ScRangeList& rList, const ScAddress& rPos):
     167                 :            :     ModalDialog(pParent, ScResId(RID_SCDLG_COND_FORMAT_MANAGER)),
     168                 :            :     maBtnAdd(this, ScResId(BTN_ADD)),
     169                 :            :     maBtnRemove(this, ScResId(BTN_REMOVE)),
     170                 :            :     maBtnEdit(this, ScResId(BTN_EDIT)),
     171                 :            :     maBtnOk(this, ScResId(BTN_OK)),
     172                 :            :     maBtnCancel(this, ScResId(BTN_CANCEL)),
     173                 :            :     maFlLine(this, ScResId(FL_LINE)),
     174                 :          0 :     mpFormatList( pFormatList ? new ScConditionalFormatList(*pFormatList) : NULL),
     175                 :            :     maCtrlManager(this, pDoc, mpFormatList, rPos),
     176                 :            :     mpDoc(pDoc),
     177                 :            :     mrRangeList(rList),
     178                 :          0 :     maPos(rPos)
     179                 :            : {
     180                 :          0 :     FreeResource();
     181                 :            : 
     182                 :          0 :     maBtnRemove.SetClickHdl(LINK(this, ScCondFormatManagerDlg, RemoveBtnHdl));
     183                 :          0 :     maBtnEdit.SetClickHdl(LINK(this, ScCondFormatManagerDlg, EditBtnHdl));
     184                 :          0 :     maBtnAdd.Hide();
     185                 :          0 : }
     186                 :            : 
     187                 :          0 : ScCondFormatManagerDlg::~ScCondFormatManagerDlg()
     188                 :            : {
     189                 :          0 :     delete mpFormatList;
     190                 :          0 : }
     191                 :            : 
     192                 :          0 : ScConditionalFormatList* ScCondFormatManagerDlg::GetConditionalFormatList()
     193                 :            : {
     194                 :          0 :     ScConditionalFormatList* pList = mpFormatList;
     195                 :          0 :     mpFormatList = NULL;
     196                 :          0 :     return pList;
     197                 :            : }
     198                 :            : 
     199                 :          0 : IMPL_LINK_NOARG(ScCondFormatManagerDlg, RemoveBtnHdl)
     200                 :            : {
     201                 :          0 :     maCtrlManager.DeleteSelection();
     202                 :          0 :     return 0;
     203                 :            : }
     204                 :            : 
     205                 :          0 : IMPL_LINK_NOARG(ScCondFormatManagerDlg, EditBtnHdl)
     206                 :            : {
     207                 :          0 :     ScConditionalFormat* pFormat = maCtrlManager.GetSelection();
     208                 :            : 
     209                 :          0 :     if(!pFormat)
     210                 :          0 :         return 0;
     211                 :            : 
     212                 :          0 :     ScCondFormatDlg* pDlg = new ScCondFormatDlg(this, mpDoc, pFormat, pFormat->GetRange(), maPos);
     213                 :          0 :     if(pDlg->Execute() == RET_OK)
     214                 :            :     {
     215                 :          0 :         sal_Int32 nKey = pFormat->GetKey();
     216                 :          0 :         mpFormatList->erase(nKey);
     217                 :          0 :         ScConditionalFormat* pNewFormat = pDlg->GetConditionalFormat();
     218                 :          0 :         pNewFormat->SetKey(nKey);
     219                 :          0 :         mpFormatList->InsertNew(pNewFormat);
     220                 :          0 :         maCtrlManager.Update();
     221                 :            :     }
     222                 :          0 :     delete pDlg;
     223                 :            : 
     224                 :          0 :     return 0;
     225                 :            : }
     226                 :            : 
     227                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10