LCOV - code coverage report
Current view: top level - chart2/source/controller/dialogs - dlg_DataEditor.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 107 0.0 %
Date: 2014-04-14 Functions: 0 16 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 "dlg_DataEditor.hxx"
      21             : #include "Strings.hrc"
      22             : #include "DataBrowser.hxx"
      23             : 
      24             : #include "ResId.hxx"
      25             : #include <sfx2/dispatch.hxx>
      26             : #include <vcl/msgbox.hxx>
      27             : #include <vcl/taskpanelist.hxx>
      28             : #include <svtools/miscopt.hxx>
      29             : #include <unotools/pathoptions.hxx>
      30             : 
      31             : // for SfxBoolItem
      32             : #include <svl/eitem.hxx>
      33             : 
      34             : #include <vcl/edit.hxx>
      35             : 
      36             : #include <com/sun/star/frame/XStorable.hpp>
      37             : #include <com/sun/star/chart2/XChartDocument.hpp>
      38             : 
      39             : using namespace ::com::sun::star;
      40             : using ::com::sun::star::uno::Reference;
      41             : 
      42             : namespace chart
      43             : {
      44             : 
      45           0 : DataEditor::DataEditor(Window* pParent,
      46             :     const Reference< chart2::XChartDocument > & xChartDoc,
      47             :     const Reference< uno::XComponentContext > & xContext)
      48             :     : ModalDialog(pParent, "ChartDataDialog",
      49             :         "modules/schart/ui/chartdatadialog.ui")
      50             :     , m_bReadOnly(false)
      51             :     , m_xChartDoc(xChartDoc)
      52           0 :     , m_xContext(xContext)
      53             : {
      54           0 :     m_xBrwData.reset(new DataBrowser(get<Window>("datawindow"), WB_BORDER | WB_TABSTOP, true /* bLiveUpdate */));
      55           0 :     m_xBrwData->set_hexpand(true);
      56           0 :     m_xBrwData->set_vexpand(true);
      57           0 :     m_xBrwData->set_expand(true);
      58           0 :     Size aSize(m_xBrwData->LogicToPixel(Size(232, 121), MAP_APPFONT));
      59           0 :     m_xBrwData->set_width_request(aSize.Width());
      60           0 :     m_xBrwData->set_height_request(aSize.Height());
      61           0 :     m_xBrwData->Show();
      62             : 
      63           0 :     get(m_pTbxData, "toolbar");
      64             : 
      65           0 :     TBI_DATA_INSERT_ROW = m_pTbxData->GetItemId("InsertRow");
      66           0 :     TBI_DATA_INSERT_COL = m_pTbxData->GetItemId("InsertColumn");
      67           0 :     TBI_DATA_INSERT_TEXT_COL = m_pTbxData->GetItemId("InsertTextColumn");
      68           0 :     TBI_DATA_DELETE_ROW = m_pTbxData->GetItemId("RemoveRow");
      69           0 :     TBI_DATA_DELETE_COL = m_pTbxData->GetItemId("RemoveColumn");
      70           0 :     TBI_DATA_SWAP_COL = m_pTbxData->GetItemId("SwapColumn");
      71           0 :     TBI_DATA_SWAP_ROW = m_pTbxData->GetItemId("SwapRow");
      72             : 
      73           0 :     m_pTbxData->SetSelectHdl( LINK( this, DataEditor, ToolboxHdl ));
      74             : 
      75           0 :     m_xBrwData->SetCursorMovedHdl( LINK( this, DataEditor,   BrowserCursorMovedHdl ));
      76           0 :     m_xBrwData->SetCellModifiedHdl( LINK( this, DataEditor,  CellModified ));
      77             : 
      78           0 :     UpdateData();
      79           0 :     GrabFocus();
      80           0 :     m_xBrwData->GrabFocus();
      81             : 
      82           0 :     bool bReadOnly = true;
      83           0 :     Reference< frame::XStorable > xStor( m_xChartDoc, uno::UNO_QUERY );
      84           0 :     if( xStor.is())
      85           0 :         bReadOnly = xStor->isReadonly();
      86           0 :     SetReadOnly( bReadOnly );
      87             : 
      88             :     // change buttons to flat-look if set so by user
      89           0 :     SvtMiscOptions aMiscOptions;
      90           0 :     const sal_Int16 nStyle( aMiscOptions.GetToolboxStyle() );
      91             :     // react on changes
      92           0 :     aMiscOptions.AddListenerLink( LINK( this, DataEditor, MiscHdl ) );
      93           0 :     m_pTbxData->SetOutStyle( nStyle );
      94             : 
      95             :     // allow travelling to toolbar with F6
      96           0 :     notifySystemWindow( this, m_pTbxData, ::comphelper::mem_fun( & TaskPaneList::AddWindow ));
      97           0 : }
      98             : 
      99           0 : DataEditor::~DataEditor()
     100             : {
     101           0 :     notifySystemWindow( this, m_pTbxData, ::comphelper::mem_fun( & TaskPaneList::RemoveWindow ));
     102             : 
     103           0 :     SvtMiscOptions aMiscOptions;
     104           0 :     aMiscOptions.RemoveListenerLink( LINK( this, DataEditor, MiscHdl ) );
     105             : 
     106           0 :     OSL_TRACE( "DataEditor: DTOR" );
     107           0 : }
     108             : 
     109             : // react on click (or keypress) on toolbar icon
     110           0 : IMPL_LINK_NOARG(DataEditor, ToolboxHdl)
     111             : {
     112           0 :     sal_uInt16 nId = m_pTbxData->GetCurItemId();
     113             : 
     114           0 :     if (nId == TBI_DATA_INSERT_ROW)
     115           0 :         m_xBrwData->InsertRow();
     116           0 :     else if (nId == TBI_DATA_INSERT_COL)
     117           0 :         m_xBrwData->InsertColumn();
     118           0 :     else if (nId == TBI_DATA_INSERT_TEXT_COL)
     119           0 :         m_xBrwData->InsertTextColumn();
     120           0 :     else if (nId == TBI_DATA_DELETE_ROW)
     121           0 :         m_xBrwData->RemoveRow();
     122           0 :     else if (nId == TBI_DATA_DELETE_COL)
     123           0 :         m_xBrwData->RemoveColumn();
     124           0 :     else if (nId == TBI_DATA_SWAP_COL)
     125           0 :         m_xBrwData->SwapColumn();
     126           0 :     else if (nId == TBI_DATA_SWAP_ROW)
     127           0 :         m_xBrwData->SwapRow();
     128             : 
     129           0 :     return 0;
     130             : }
     131             : 
     132             : // refresh toolbar icons according to currently selected cell in brwose box
     133           0 : IMPL_LINK_NOARG(DataEditor, BrowserCursorMovedHdl)
     134             : {
     135           0 :     if( m_bReadOnly )
     136           0 :         return 0;
     137             : 
     138           0 :     bool bIsDataValid = m_xBrwData->IsEnableItem();
     139             : 
     140           0 :     m_pTbxData->EnableItem( TBI_DATA_INSERT_ROW, bIsDataValid && m_xBrwData->MayInsertRow() );
     141           0 :     m_pTbxData->EnableItem( TBI_DATA_INSERT_COL, bIsDataValid && m_xBrwData->MayInsertColumn() );
     142           0 :     m_pTbxData->EnableItem( TBI_DATA_INSERT_TEXT_COL, bIsDataValid && m_xBrwData->MayInsertColumn() );
     143           0 :     m_pTbxData->EnableItem( TBI_DATA_DELETE_ROW, m_xBrwData->MayDeleteRow() );
     144           0 :     m_pTbxData->EnableItem( TBI_DATA_DELETE_COL, m_xBrwData->MayDeleteColumn() );
     145             : 
     146           0 :     m_pTbxData->EnableItem( TBI_DATA_SWAP_COL,   bIsDataValid && m_xBrwData->MaySwapColumns() );
     147           0 :     m_pTbxData->EnableItem( TBI_DATA_SWAP_ROW,   bIsDataValid && m_xBrwData->MaySwapRows() );
     148             : 
     149           0 :     return 0;
     150             : }
     151             : 
     152             : // disable all modifying controls
     153           0 : void DataEditor::SetReadOnly( bool bReadOnly )
     154             : {
     155           0 :     m_bReadOnly = bReadOnly;
     156           0 :     if( m_bReadOnly )
     157             :     {
     158           0 :         m_pTbxData->EnableItem( TBI_DATA_INSERT_ROW, false );
     159           0 :         m_pTbxData->EnableItem( TBI_DATA_INSERT_COL, false );
     160           0 :         m_pTbxData->EnableItem( TBI_DATA_INSERT_TEXT_COL, false );
     161           0 :         m_pTbxData->EnableItem( TBI_DATA_DELETE_ROW, false );
     162           0 :         m_pTbxData->EnableItem( TBI_DATA_DELETE_COL, false );
     163           0 :         m_pTbxData->EnableItem( TBI_DATA_SWAP_COL, false );
     164           0 :         m_pTbxData->EnableItem( TBI_DATA_SWAP_ROW, false );
     165             :     }
     166             : 
     167           0 :     m_xBrwData->SetReadOnly( m_bReadOnly );
     168           0 : }
     169             : 
     170           0 : IMPL_LINK_NOARG(DataEditor, MiscHdl)
     171             : {
     172           0 :     SvtMiscOptions aMiscOptions;
     173           0 :     sal_Int16 nStyle( aMiscOptions.GetToolboxStyle() );
     174             : 
     175           0 :     m_pTbxData->SetOutStyle( nStyle );
     176             : 
     177           0 :     return 0L;
     178             : }
     179             : 
     180           0 : IMPL_LINK_NOARG(DataEditor, CellModified)
     181             : {
     182           0 :     return 0;
     183             : }
     184             : 
     185           0 : void DataEditor::UpdateData()
     186             : {
     187           0 :     m_xBrwData->SetDataFromModel( m_xChartDoc, m_xContext );
     188           0 : }
     189             : 
     190           0 : bool DataEditor::Close()
     191             : {
     192           0 :     if( ApplyChangesToModel() )
     193           0 :         return ModalDialog::Close();
     194             :     else
     195           0 :         return true;
     196             : }
     197             : 
     198           0 : bool DataEditor::ApplyChangesToModel()
     199             : {
     200           0 :     return m_xBrwData->EndEditing();
     201             : }
     202             : 
     203             : // add/remove a window (the toolbar) to/from the global list, so that F6
     204             : // travels/no longer travels over this window.  _rMemFunc may be
     205             : // TaskPaneList::AddWindow or TaskPaneList::RemoveWindow
     206           0 : void DataEditor::notifySystemWindow(
     207             :     Window* pWindow, Window* pToRegister,
     208             :     ::comphelper::mem_fun1_t< TaskPaneList, Window* > rMemFunc )
     209             : {
     210             :     OSL_ENSURE( pWindow, "Window must not be null!" );
     211           0 :     if( !pWindow )
     212           0 :         return;
     213           0 :     Window* pParent = pWindow->GetParent();
     214           0 :     while( pParent && ! pParent->IsSystemWindow() )
     215             :     {
     216           0 :         pParent = pParent->GetParent();
     217             :     }
     218           0 :     if ( pParent && pParent->IsSystemWindow())
     219             :     {
     220           0 :         SystemWindow* pSystemWindow = static_cast< SystemWindow* >( pParent );
     221           0 :         rMemFunc( pSystemWindow->GetTaskPaneList(),( pToRegister ));
     222             :     }
     223             : }
     224             : 
     225             : } // namespace chart
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10