LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/dialogs - dlg_DataEditor.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 122 0.0 %
Date: 2012-12-27 Functions: 0 19 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             : 
      21             : #include "dlg_DataEditor.hxx"
      22             : #include "dlg_DataEditor.hrc"
      23             : #include "Strings.hrc"
      24             : #include "DataBrowser.hxx"
      25             : 
      26             : #include "ResId.hxx"
      27             : #include <sfx2/dispatch.hxx>
      28             : #include <vcl/msgbox.hxx>
      29             : #include <vcl/taskpanelist.hxx>
      30             : #include <svtools/miscopt.hxx>
      31             : #include <unotools/pathoptions.hxx>
      32             : 
      33             : // for SfxBoolItem
      34             : #include <svl/eitem.hxx>
      35             : 
      36             : #include <vcl/edit.hxx>
      37             : 
      38             : #include <com/sun/star/frame/XStorable.hpp>
      39             : #include <com/sun/star/chart2/XChartDocument.hpp>
      40             : 
      41             : using namespace ::com::sun::star;
      42             : using ::com::sun::star::uno::Reference;
      43             : using ::rtl::OUString;
      44             : 
      45             : 
      46             : namespace chart
      47             : {
      48             : 
      49           0 : DataEditor::DataEditor(
      50             :     Window* pParent,
      51             :     const Reference< chart2::XChartDocument > & xChartDoc,
      52             :     const Reference< uno::XComponentContext > & xContext ) :
      53             :         ModalDialog( pParent, SchResId( DLG_DIAGRAM_DATA )),
      54             :         m_bReadOnly( false ),
      55           0 :         m_apBrwData( new DataBrowser( this, SchResId( CTL_DATA ), true /* bLiveUpdate */)),
      56             :         m_aTbxData( this, SchResId( TBX_DATA )),
      57             :         m_xChartDoc( xChartDoc ),
      58             :         m_xContext( xContext ),
      59           0 :         m_aToolboxImageList( SchResId( IL_DIAGRAM_DATA ))
      60             : {
      61           0 :     FreeResource();
      62             : 
      63             :     // set min size to current size
      64           0 :     SetMinOutputSizePixel( GetOutputSizePixel() );
      65             : 
      66           0 :     ApplyImageList();
      67             : 
      68           0 :     m_aTbxData.SetSizePixel( m_aTbxData.CalcWindowSizePixel() );
      69           0 :     m_aTbxData.SetSelectHdl( LINK( this, DataEditor, ToolboxHdl ));
      70             : 
      71           0 :     m_apBrwData->SetCursorMovedHdl( LINK( this, DataEditor,   BrowserCursorMovedHdl ));
      72           0 :     m_apBrwData->SetCellModifiedHdl( LINK( this, DataEditor,  CellModified ));
      73             : 
      74           0 :     UpdateData();
      75           0 :     GrabFocus();
      76           0 :     m_apBrwData->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_aTbxData.SetOutStyle( nStyle );
      90             : 
      91             :     // set good window width
      92           0 :     Size aWinSize( GetOutputSizePixel());
      93           0 :     Size aWinSizeWithBorder( GetSizePixel());
      94           0 :     Point aWinPos( OutputToAbsoluteScreenPixel( GetPosPixel()));
      95           0 :     sal_Int32 nMinWidth = aWinSize.getWidth();
      96           0 :     sal_Int32 nMaxWidth = GetDesktopRectPixel().getWidth() -
      97           0 :         (aWinSizeWithBorder.getWidth() - aWinSize.getWidth() + aWinPos.getX()) - 10; // leave some space
      98           0 :     sal_Int32 nBrowserWidth = m_apBrwData->GetTotalWidth() + 12 + 16; // plus padding + 16?
      99           0 :     sal_Int32 nWindowWidth = ::std::max( nMinWidth, nBrowserWidth );
     100           0 :     nWindowWidth = ::std::min( nMaxWidth, nBrowserWidth );
     101           0 :     aWinSize.setWidth( nWindowWidth );
     102           0 :     SetOutputSizePixel( aWinSize );
     103           0 :     AdaptBrowseBoxSize();
     104             : 
     105             :     // allow travelling to toolbar with F6
     106           0 :     notifySystemWindow( this, & m_aTbxData, ::comphelper::mem_fun( & TaskPaneList::AddWindow ));
     107           0 : }
     108             : 
     109           0 : DataEditor::~DataEditor()
     110             : {
     111           0 :     notifySystemWindow( this, & m_aTbxData, ::comphelper::mem_fun( & TaskPaneList::RemoveWindow ));
     112             : 
     113           0 :     SvtMiscOptions aMiscOptions;
     114           0 :     aMiscOptions.RemoveListenerLink( LINK( this, DataEditor, MiscHdl ) );
     115             : 
     116           0 :     OSL_TRACE( "DataEditor: DTOR" );
     117           0 : }
     118             : 
     119             : // react on click (or keypress) on toolbar icon
     120           0 : IMPL_LINK_NOARG(DataEditor, ToolboxHdl)
     121             : {
     122           0 :     switch( m_aTbxData.GetCurItemId() )
     123             :     {
     124             :         case TBI_DATA_INSERT_ROW:
     125           0 :             m_apBrwData->InsertRow();
     126           0 :             break;
     127             :         case TBI_DATA_INSERT_COL:
     128           0 :             m_apBrwData->InsertColumn();
     129           0 :             break;
     130             :         case TBI_DATA_INSERT_TEXT_COL:
     131           0 :             m_apBrwData->InsertTextColumn();
     132           0 :             break;
     133             :         case TBI_DATA_DELETE_ROW:
     134           0 :             m_apBrwData->RemoveRow();
     135           0 :             break;
     136             :         case TBI_DATA_DELETE_COL:
     137           0 :             m_apBrwData->RemoveColumn();
     138           0 :             break;
     139             :         case TBI_DATA_SWAP_COL :
     140           0 :             m_apBrwData->SwapColumn ();
     141           0 :             break;
     142             :         case TBI_DATA_SWAP_ROW :
     143           0 :             m_apBrwData->SwapRow ();
     144           0 :             break;
     145             :     }
     146             : 
     147           0 :     return 0;
     148             : }
     149             : 
     150             : // refresh toolbar icons according to currently selected cell in brwose box
     151           0 : IMPL_LINK_NOARG(DataEditor, BrowserCursorMovedHdl)
     152             : {
     153           0 :     if( m_bReadOnly )
     154           0 :         return 0;
     155             : 
     156           0 :     bool bIsDataValid = m_apBrwData->IsEnableItem();
     157             : 
     158           0 :     m_aTbxData.EnableItem( TBI_DATA_INSERT_ROW, bIsDataValid && m_apBrwData->MayInsertRow() );
     159           0 :     m_aTbxData.EnableItem( TBI_DATA_INSERT_COL, bIsDataValid && m_apBrwData->MayInsertColumn() );
     160           0 :     m_aTbxData.EnableItem( TBI_DATA_INSERT_TEXT_COL, bIsDataValid && m_apBrwData->MayInsertColumn() );
     161           0 :     m_aTbxData.EnableItem( TBI_DATA_DELETE_ROW, m_apBrwData->MayDeleteRow() );
     162           0 :     m_aTbxData.EnableItem( TBI_DATA_DELETE_COL, m_apBrwData->MayDeleteColumn() );
     163             : 
     164           0 :     m_aTbxData.EnableItem( TBI_DATA_SWAP_COL,   bIsDataValid && m_apBrwData->MaySwapColumns() );
     165           0 :     m_aTbxData.EnableItem( TBI_DATA_SWAP_ROW,   bIsDataValid && m_apBrwData->MaySwapRows() );
     166             : 
     167           0 :     return 0;
     168             : }
     169             : 
     170             : // disable all modifying controls
     171           0 : void DataEditor::SetReadOnly( bool bReadOnly )
     172             : {
     173           0 :     m_bReadOnly = bReadOnly;
     174           0 :     if( m_bReadOnly )
     175             :     {
     176           0 :         m_aTbxData.EnableItem( TBI_DATA_INSERT_ROW, sal_False );
     177           0 :         m_aTbxData.EnableItem( TBI_DATA_INSERT_COL, sal_False );
     178           0 :         m_aTbxData.EnableItem( TBI_DATA_INSERT_TEXT_COL, sal_False );
     179           0 :         m_aTbxData.EnableItem( TBI_DATA_DELETE_ROW, sal_False );
     180           0 :         m_aTbxData.EnableItem( TBI_DATA_DELETE_COL, sal_False );
     181           0 :         m_aTbxData.EnableItem( TBI_DATA_SWAP_COL, sal_False );
     182           0 :         m_aTbxData.EnableItem( TBI_DATA_SWAP_ROW, sal_False );
     183             :     }
     184             : 
     185           0 :     m_apBrwData->SetReadOnly( m_bReadOnly );
     186           0 : }
     187             : 
     188           0 : IMPL_LINK_NOARG(DataEditor, MiscHdl)
     189             : {
     190           0 :     SvtMiscOptions aMiscOptions;
     191           0 :     sal_Int16 nStyle( aMiscOptions.GetToolboxStyle() );
     192             : 
     193           0 :     m_aTbxData.SetOutStyle( nStyle );
     194             : 
     195           0 :     return 0L;
     196             : }
     197             : 
     198           0 : IMPL_LINK_NOARG(DataEditor, CellModified)
     199             : {
     200           0 :     return 0;
     201             : }
     202             : 
     203           0 : void DataEditor::UpdateData()
     204             : {
     205           0 :     m_apBrwData->SetDataFromModel( m_xChartDoc, m_xContext );
     206           0 : }
     207             : 
     208           0 : void DataEditor::AdaptBrowseBoxSize()
     209             : {
     210           0 :     Size aSize( PixelToLogic( GetResizeOutputSizePixel(), MAP_APPFONT ));
     211           0 :     Size aDataSize;
     212             : 
     213           0 :     aDataSize.setWidth( aSize.getWidth() - 12 );
     214           0 :     aDataSize.setHeight( aSize.getHeight() - 31 -24 );
     215             : 
     216           0 :     m_apBrwData->SetSizePixel( LogicToPixel( aDataSize, MAP_APPFONT ));
     217           0 : }
     218             : 
     219           0 : void DataEditor::Resize()
     220             : {
     221           0 :     Dialog::Resize();
     222           0 :     AdaptBrowseBoxSize();
     223           0 : }
     224             : 
     225           0 : sal_Bool DataEditor::Close()
     226             : {
     227           0 :     if( ApplyChangesToModel() )
     228           0 :         return ModalDialog::Close();
     229             :     else
     230           0 :         return sal_True;
     231             : }
     232             : 
     233           0 : bool DataEditor::ApplyChangesToModel()
     234             : {
     235           0 :     return m_apBrwData->EndEditing();
     236             : }
     237             : 
     238             : // sets the correct toolbar icons depending on the current mode (e.g. high contrast)
     239           0 : void DataEditor::ApplyImageList()
     240             : {
     241           0 :     m_aTbxData.SetImageList( m_aToolboxImageList );
     242           0 : }
     243             : 
     244             : // add/remove a window (the toolbar) to/from the global list, so that F6
     245             : // travels/no longer travels over this window.  _rMemFunc may be
     246             : // TaskPaneList::AddWindow or TaskPaneList::RemoveWindow
     247           0 : void DataEditor::notifySystemWindow(
     248             :     Window* pWindow, Window* pToRegister,
     249             :     ::comphelper::mem_fun1_t< TaskPaneList, Window* > rMemFunc )
     250             : {
     251             :     OSL_ENSURE( pWindow, "Window must not be null!" );
     252           0 :     if( !pWindow )
     253           0 :         return;
     254           0 :     Window* pParent = pWindow->GetParent();
     255           0 :     while( pParent && ! pParent->IsSystemWindow() )
     256             :     {
     257           0 :         pParent = pParent->GetParent();
     258             :     }
     259           0 :     if ( pParent && pParent->IsSystemWindow())
     260             :     {
     261           0 :         SystemWindow* pSystemWindow = static_cast< SystemWindow* >( pParent );
     262           0 :         rMemFunc( pSystemWindow->GetTaskPaneList(),( pToRegister ));
     263             :     }
     264             : }
     265             : 
     266             : } // namespace chart
     267             : 
     268             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10