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

Generated by: LCOV version 1.11