LCOV - code coverage report
Current view: top level - sc/source/ui/inc - anyrefdg.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 38 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 53 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             : #ifndef INCLUDED_SC_SOURCE_UI_INC_ANYREFDG_HXX
      21             : #define INCLUDED_SC_SOURCE_UI_INC_ANYREFDG_HXX
      22             : 
      23             : #include <vcl/button.hxx>
      24             : #include <vcl/edit.hxx>
      25             : #include <vcl/accel.hxx>
      26             : #include <sfx2/basedlgs.hxx>
      27             : #include <sfx2/tabdlg.hxx>
      28             : #include "address.hxx"
      29             : #include "compiler.hxx"
      30             : #include <formula/funcutl.hxx>
      31             : #include "IAnyRefDialog.hxx"
      32             : #include "scresid.hxx"
      33             : #include "scmod.hxx"
      34             : 
      35             : #include <memory>
      36             : 
      37             : class SfxObjectShell;
      38             : class ScRange;
      39             : class ScDocument;
      40             : class ScTabViewShell;
      41             : class ScRefHandler;
      42             : class ScRangeList;
      43             : 
      44             : class ScFormulaReferenceHelper
      45             : {
      46             :     IAnyRefDialog*      m_pDlg;
      47             :     ::std::unique_ptr<ScCompiler>         pRefComp;
      48             :     VclPtr<formula::RefEdit>    pRefEdit;               // active input field
      49             :     VclPtr<formula::RefButton>  pRefBtn;                // associated button
      50             :     VclPtr<vcl::Window>         m_pWindow;
      51             :     SfxBindings*        m_pBindings;
      52             :     ::std::unique_ptr<Accelerator>
      53             :                         pAccel;                 // for Enter/Escape
      54             :     ::std::vector<VclPtr<vcl::Window> > m_aHiddenWidgets;    // vector of hidden Controls
      55             :     sal_Int32           m_nOldBorderWidth;      // border width for expanded dialog
      56             :     SCTAB               nRefTab;                // used for ShowReference
      57             : 
      58             :     OUString            sOldDialogText;         // Original title of the dialog window
      59             :     Size                aOldDialogSize;         // Original size of the dialog window
      60             :     Point               aOldEditPos;            // Original position of the input field
      61             :     Size                aOldEditSize;           // Original size of the input field
      62             :     long                mnOldEditWidthReq;
      63             :     Point               aOldButtonPos;          // Original position of the button
      64             :     VclPtr<vcl::Window> mpOldEditParent;        // Original parent of the edit field and the button
      65             :     bool                mbOldDlgLayoutEnabled;  // Original layout state of parent dialog
      66             :     bool                mbOldEditParentLayoutEnabled;  // Original layout state of edit widget parent
      67             : 
      68             :     bool                bEnableColorRef;
      69             :     bool                bHighlightRef;
      70             :     bool                bAccInserted;
      71             : 
      72             :     DECL_LINK( AccelSelectHdl, Accelerator* );
      73             : 
      74             : public:
      75             :     ScFormulaReferenceHelper(IAnyRefDialog* _pDlg,SfxBindings* _pBindings);
      76             :     ~ScFormulaReferenceHelper();
      77             : 
      78             :     void                ShowSimpleReference(const OUString& rStr);
      79             :     void                ShowFormulaReference(const OUString& rStr);
      80             :     bool                ParseWithNames( ScRangeList& rRanges, const OUString& rStr, ScDocument* pDoc );
      81             :     void                Init();
      82             : 
      83             :     void                ShowReference(const OUString& rStr);
      84             :     void                ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
      85             :     void                HideReference( bool bDoneRefMode = true );
      86             :     void                RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
      87             :     void                RefInputDone( bool bForced = false );
      88             :     void                ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL );
      89             : 
      90           0 :     inline void         SetWindow(vcl::Window* _pWindow) { m_pWindow = _pWindow; }
      91             :     bool                DoClose( sal_uInt16 nId );
      92             :     static void         SetDispatcherLock( bool bLock );
      93             :     static void         EnableSpreadsheets( bool bFlag = true, bool bChildren = true );
      94             :     static void         ViewShellChanged();
      95             : 
      96             :     static              void enableInput(bool _bInput);
      97             : 
      98             : protected:
      99             :     vcl::Window*        GetWindow(){ return m_pWindow; }
     100             : 
     101             : public:
     102           0 :     static bool         CanInputStart( const formula::RefEdit *pEdit ){ return !!pEdit; }
     103           0 :     bool                CanInputDone( bool bForced ){   return pRefEdit && (bForced || !pRefBtn);   }
     104             : };
     105             : 
     106             : class SC_DLLPUBLIC ScRefHandler :
     107             :                     public IAnyRefDialog
     108             : {
     109             :     VclPtr<vcl::Window>  m_rWindow;
     110             :     bool                 m_bInRefMode;
     111             : 
     112             : public:
     113           0 :     operator vcl::Window *(){ return m_rWindow.get(); }
     114             :     vcl::Window* operator ->() { return static_cast<vcl::Window *>(*this); }
     115             :     friend class        formula::RefButton;
     116             :     friend class        formula::RefEdit;
     117             : 
     118             : private:
     119             :     ScFormulaReferenceHelper
     120             :                         m_aHelper;
     121             :     SfxBindings*        pMyBindings;
     122             : 
     123             :     VclPtr<vcl::Window> pActiveWin;
     124             :     Idle                aIdle;
     125             :     OUString            aDocName;               // document on which the dialog was opened
     126             : 
     127             :     DECL_LINK_TYPED( UpdateFocusHdl, Idle*, void );
     128             : 
     129             : protected:
     130             :     void                disposeRefHandler();
     131             :     bool                DoClose( sal_uInt16 nId );
     132             : 
     133             :     static void         SetDispatcherLock( bool bLock );
     134             : 
     135             :     virtual void        RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL ) SAL_OVERRIDE;
     136             :     virtual void        RefInputDone( bool bForced = false ) SAL_OVERRIDE;
     137             :     void                ShowSimpleReference(const OUString& rStr);
     138             :     void                ShowFormulaReference(const OUString& rStr);
     139             : 
     140             :     bool                ParseWithNames( ScRangeList& rRanges, const OUString& rStr, ScDocument* pDoc );
     141             : 
     142             :     void preNotify(const NotifyEvent& rEvent, const bool bBindRef);
     143             :     void stateChanged(const StateChangedType nStateChange, const bool bBindRef);
     144             : 
     145             : public:
     146             :                         ScRefHandler( vcl::Window &rWindow, SfxBindings* pB, bool bBindRef );
     147             :     virtual             ~ScRefHandler();
     148             : 
     149             :     virtual void        SetReference( const ScRange& rRef, ScDocument* pDoc ) SAL_OVERRIDE = 0;
     150             :     virtual void        AddRefEntry() SAL_OVERRIDE;
     151             : 
     152             :     virtual bool        IsRefInputMode() const SAL_OVERRIDE;
     153             :     virtual bool        IsTableLocked() const SAL_OVERRIDE;
     154             :     virtual bool        IsDocAllowed( SfxObjectShell* pDocSh ) const SAL_OVERRIDE;
     155             : 
     156             :     virtual void        ShowReference(const OUString& rStr) SAL_OVERRIDE;
     157             :     virtual void        HideReference( bool bDoneRefMode = true ) SAL_OVERRIDE;
     158             : 
     159             :     virtual void        ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL ) SAL_OVERRIDE;
     160             :     virtual void        ReleaseFocus( formula::RefEdit* pEdit, formula::RefButton* pButton = NULL ) SAL_OVERRIDE;
     161             : 
     162             :     virtual void        ViewShellChanged() SAL_OVERRIDE;
     163             :     void                SwitchToDocument();
     164             : 
     165             :     virtual void        SetActive() SAL_OVERRIDE = 0;
     166             : 
     167             : public:
     168             :     bool                EnterRefMode();
     169             :     bool                LeaveRefMode();
     170             :     static inline bool  CanInputStart( const formula::RefEdit *pEdit );
     171             :     inline  bool        CanInputDone( bool bForced );
     172             : };
     173             : 
     174             : template<  class TWindow, bool bBindRef = true >
     175             : class ScRefHdlrImplBase: public TWindow, public ScRefHandler
     176             : {
     177             : public:
     178             :     virtual bool        PreNotify( NotifyEvent& rNEvt );
     179             :     virtual void        StateChanged( StateChangedType nStateChange );
     180             : 
     181             : private:
     182             :     template<class TBindings, class TChildWindow, class TParentWindow, class TResId>
     183             :     ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
     184             :         TParentWindow* pParent, TResId nResId );
     185             : 
     186             :     template<class TBindings, class TChildWindow, class TParentWindow >
     187             :     ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
     188             :         TParentWindow* pParent, const OUString& rID, const OUString& rUIXMLDescription );
     189             : 
     190             :     template<class TParentWindow, class TResId, class TArg>
     191             :     ScRefHdlrImplBase( TParentWindow* pParent, TResId nResId, const TArg &rArg, SfxBindings *pB = NULL );
     192             : 
     193             :     template<class TParentWindow, class TArg>
     194             :     ScRefHdlrImplBase( TParentWindow* pParent, const OUString& rID, const OUString& rUIXMLDescription, const TArg &rArg, SfxBindings *pB = NULL );
     195             : 
     196             :     virtual ~ScRefHdlrImplBase();
     197             : 
     198             :     template<class, class, bool> friend struct ScRefHdlrImpl;
     199             : };
     200             : 
     201             : template<class TWindow, bool bBindRef>
     202             : template<class TBindings, class TChildWindow, class TParentWindow, class TResId>
     203             : ScRefHdlrImplBase<TWindow, bBindRef>::ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
     204             :                  TParentWindow* pParent, TResId nResId)
     205             :     : TWindow(pB, pCW, pParent, ScResId(static_cast<sal_uInt16>( nResId ) ) )
     206             :     , ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef )
     207             : {
     208             : }
     209             : 
     210             : template<class TWindow, bool bBindRef>
     211             : template<class TBindings, class TChildWindow, class TParentWindow>
     212           0 : ScRefHdlrImplBase<TWindow, bBindRef>::ScRefHdlrImplBase( TBindings* pB, TChildWindow* pCW,
     213             :                  TParentWindow* pParent, const OUString& rID, const OUString& rUIXMLDescription )
     214             :     : TWindow(pB, pCW, pParent, rID, rUIXMLDescription )
     215           0 :     , ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef )
     216             : {
     217           0 : }
     218             : 
     219             : template<class TWindow, bool bBindRef >
     220             : template<class TParentWindow, class TResId, class TArg>
     221             : ScRefHdlrImplBase<TWindow,bBindRef>::ScRefHdlrImplBase( TParentWindow* pParent, TResId nResIdP, const TArg &rArg, SfxBindings *pB )
     222             :     : TWindow( pParent, ScResId(static_cast<sal_uInt16>( nResIdP )), rArg ),
     223             :     ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef )
     224             : {
     225             : }
     226             : 
     227             : template<class TWindow, bool bBindRef >
     228             : template<class TParentWindow, class TArg>
     229           0 : ScRefHdlrImplBase<TWindow,bBindRef>::ScRefHdlrImplBase( TParentWindow* pParent, const OUString& rID, const OUString& rUIXMLDescription, const TArg &rArg, SfxBindings *pB )
     230             :     : TWindow( pParent, rID, rUIXMLDescription, rArg ),
     231           0 :     ScRefHandler( *static_cast<TWindow*>(this), pB, bBindRef )
     232             : {
     233           0 : }
     234             : 
     235             : template<class TWindow, bool bBindRef >
     236           0 : ScRefHdlrImplBase<TWindow,bBindRef>::~ScRefHdlrImplBase(){}
     237             : 
     238             : template<class TWindow, bool bBindRef>
     239           0 : bool ScRefHdlrImplBase<TWindow, bBindRef>::PreNotify( NotifyEvent& rNEvt )
     240             : {
     241           0 :     ScRefHandler::preNotify( rNEvt, bBindRef );
     242           0 :     return TWindow::PreNotify( rNEvt );
     243             : }
     244             : 
     245             : template<class TWindow, bool bBindRef>
     246           0 : void ScRefHdlrImplBase<TWindow, bBindRef>::StateChanged( StateChangedType nStateChange )
     247             : {
     248           0 :     TWindow::StateChanged( nStateChange );
     249           0 :     ScRefHandler::stateChanged( nStateChange, bBindRef );
     250           0 : }
     251             : 
     252             : template<class TDerived, class TBase, bool bBindRef = true>
     253             : struct ScRefHdlrImpl: ScRefHdlrImplBase< TBase, bBindRef >
     254             : {
     255             :     enum { UNKNOWN_SLOTID = 0U, SLOTID = UNKNOWN_SLOTID };
     256             : 
     257             :     template<class T1, class T2, class T3, class T4>
     258             :     ScRefHdlrImpl( const T1 & rt1, const T2 & rt2, const T3& rt3, const T4& rt4 )
     259             :         : ScRefHdlrImplBase<TBase, bBindRef >(rt1, rt2, rt3, rt4)
     260             :     {
     261             :         SC_MOD()->RegisterRefWindow( static_cast<sal_uInt16>( TDerived::SLOTID ), this );
     262             :     }
     263             : 
     264             :     template<class T1, class T2, class T3, class T4, class T5>
     265           0 :     ScRefHdlrImpl( const T1 & rt1, const T2 & rt2, const T3& rt3, const T4& rt4, const T5& rt5 )
     266           0 :         : ScRefHdlrImplBase<TBase, bBindRef >(rt1, rt2, rt3, rt4, rt5)
     267             :     {
     268           0 :         SC_MOD()->RegisterRefWindow( static_cast<sal_uInt16>( TDerived::SLOTID ), this );
     269           0 :     }
     270             : 
     271           0 :     virtual void dispose() SAL_OVERRIDE
     272             :     {
     273           0 :         SC_MOD()->UnregisterRefWindow( static_cast<sal_uInt16>( TDerived::SLOTID ), this );
     274           0 :         ScRefHdlrImplBase<TBase, bBindRef >::disposeRefHandler();
     275           0 :         TBase::dispose();
     276           0 :     }
     277             : 
     278           0 :     ~ScRefHdlrImpl()
     279             :     {
     280           0 :         dispose();
     281           0 :     }
     282             : };
     283             : 
     284           0 : struct ScAnyRefDlg : ::ScRefHdlrImpl< ScAnyRefDlg, SfxModelessDialog>
     285             : {
     286             :     template<class T1, class T2, class T3, class T4>
     287             :     ScAnyRefDlg( const T1 & rt1, const T2 & rt2, const T3& rt3, const T4& rt4 )
     288             :         : ScRefHdlrImpl< ScAnyRefDlg, SfxModelessDialog>(rt1, rt2, rt3, rt4)
     289             :     {
     290             :     }
     291             : 
     292             :     template<class T1, class T2, class T3, class T4, class T5>
     293           0 :     ScAnyRefDlg( const T1 & rt1, const T2 & rt2, const T3& rt3, const T4& rt4, const T5& rt5 )
     294           0 :         : ScRefHdlrImpl< ScAnyRefDlg, SfxModelessDialog>(rt1, rt2, rt3, rt4, rt5)
     295             :     {
     296           0 :     }
     297             : };
     298             : 
     299           0 : inline bool ScRefHandler::CanInputStart( const formula::RefEdit *pEdit )
     300             : {
     301           0 :     return ScFormulaReferenceHelper::CanInputStart( pEdit );
     302             : }
     303             : 
     304           0 : inline  bool ScRefHandler::CanInputDone( bool bForced )
     305             : {
     306           0 :     return m_aHelper.CanInputDone( bForced );
     307             : }
     308             : 
     309             : #endif // INCLUDED_SC_SOURCE_UI_INC_ANYREFDG_HXX
     310             : 
     311             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11