LibreOffice Module sc (master)  1
anyrefdg.hxx
Go to the documentation of this file.
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 <sfx2/basedlgs.hxx>
24 #include <address.hxx>
25 #include <formula/funcutl.hxx>
26 #include <vcl/accel.hxx>
27 #include "IAnyRefDialog.hxx"
28 #include <scmod.hxx>
29 
30 #include <memory>
31 
32 class SfxObjectShell;
33 class ScDocument;
34 class ScRangeList;
35 class ScCompiler;
36 
38 {
40  ::std::unique_ptr<ScCompiler> m_pRefComp;
41  formula::RefEdit* m_pRefEdit; // active input field
42  formula::RefButton* m_pRefBtn; // associated button
45  SCTAB m_nRefTab; // used for ShowReference
46 
47  OUString m_sOldDialogText; // Original title of the dialog window
48 
51 
52  DECL_LINK( ActivateHdl, weld::Widget&, bool );
53 
54 public:
56  ~ScFormulaReferenceHelper() COVERITY_NOEXCEPT_FALSE;
57  void dispose();
58 
59  void ShowSimpleReference(const OUString& rStr);
60  void ShowFormulaReference(const OUString& rStr);
61  bool ParseWithNames( ScRangeList& rRanges, const OUString& rStr, const ScDocument& rDoc );
62  void Init();
63 
64  void ShowReference(const OUString& rStr);
65  void ReleaseFocus( formula::RefEdit* pEdit );
66  void HideReference( bool bDoneRefMode = true );
67  void RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton );
68  void RefInputDone( bool bForced );
69  void ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton );
70 
71  void SetDialog(weld::Dialog* pDialog) { m_pDialog = pDialog; }
72  void DoClose( sal_uInt16 nId );
73  void SetDispatcherLock( bool bLock );
74  static void EnableSpreadsheets( bool bFlag = true );
75  static void ViewShellChanged();
76 
77  static void enableInput(bool _bInput);
78 
79 public:
80  static bool CanInputStart( const formula::RefEdit *pEdit ){ return !!pEdit; }
81  bool CanInputDone(bool bForced) { return m_pRefEdit && (bForced || !m_pRefBtn); }
82 };
83 
85 {
88 
89 private:
93 
94  OUString m_aDocName; // document on which the dialog was opened
95 
96 protected:
97  void disposeRefHandler();
98  bool DoClose( sal_uInt16 nId );
99 
100  void SetDispatcherLock( bool bLock );
101 
102  virtual void RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = nullptr ) override;
103  virtual void RefInputDone( bool bForced = false ) override;
104 
105  bool ParseWithNames( ScRangeList& rRanges, const OUString& rStr, const ScDocument& pDoc );
106 
107 public:
108  ScRefHandler(SfxDialogController &rController, SfxBindings* pB, bool bBindRef);
109  virtual ~ScRefHandler() COVERITY_NOEXCEPT_FALSE override;
110 
111  virtual void SetReference( const ScRange& rRef, ScDocument& rDoc ) override = 0;
112  virtual void AddRefEntry() override;
113 
114  virtual bool IsRefInputMode() const override;
115  virtual bool IsTableLocked() const override;
116  virtual bool IsDocAllowed( SfxObjectShell* pDocSh ) const override;
117 
118  virtual void ShowReference(const OUString& rStr) override;
119  virtual void HideReference( bool bDoneRefMode = true ) override;
120 
121  virtual void ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton ) override;
122  virtual void ReleaseFocus( formula::RefEdit* pEdit ) override;
123 
124  virtual void ViewShellChanged() override;
125  void SwitchToDocument();
126 
127  virtual void SetActive() override = 0;
128 
129 public:
130  bool EnterRefMode();
131  bool LeaveRefMode();
132  static bool CanInputStart( const formula::RefEdit *pEdit )
133  {
135  }
136  bool CanInputDone( bool bForced )
137  {
138  return m_aHelper.CanInputDone( bForced );
139  }
140 };
141 
142 template<class TBase, bool bBindRef = true>
143 struct ScRefHdlrControllerImpl : public TBase, public ScRefHandler
144 {
146 
147  ScRefHdlrControllerImpl(weld::Window* pParent, const OUString& rUIXMLDescription, const OString& rID, const SfxItemSet* pArg, SfxBindings *pB)
148  : TBase(pParent, rUIXMLDescription, rID, pArg)
149  , ScRefHandler(*static_cast<TBase*>(this), pB, bBindRef)
150  {
151  }
152 
153  ScRefHdlrControllerImpl(SfxBindings* pB, SfxChildWindow* pCW, weld::Window* pParent, const OUString& rUIXMLDescription, const OString& rID)
154  : TBase(pB, pCW, pParent, rUIXMLDescription, rID)
155  , ScRefHandler(*static_cast<TBase*>(this), pB, bBindRef)
156  {
157  }
158 };
159 
160 struct ScAnyRefDlgController : ScRefHdlrControllerImpl<SfxModelessDialogController>
161 {
162  ScAnyRefDlgController(SfxBindings* rt1, SfxChildWindow* rt2, weld::Window* rt3, const OUString& rt4, const OString& rt5)
163  : ScRefHdlrControllerImpl<SfxModelessDialogController>(rt1, rt2, rt3, rt4, rt5)
164  {
165  }
166 };
167 
168 #endif // INCLUDED_SC_SOURCE_UI_INC_ANYREFDG_HXX
169 
170 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:421
bool ParseWithNames(ScRangeList &rRanges, const OUString &rStr, const ScDocument &rDoc)
Definition: anyrefdg.cxx:139
virtual bool IsTableLocked() const override
Definition: anyrefdg.cxx:715
virtual bool IsRefInputMode() const override
Definition: anyrefdg.cxx:689
formula::RefEdit * m_pRefEdit
Definition: anyrefdg.hxx:41
bool m_bInRefMode
Definition: anyrefdg.hxx:87
static bool CanInputStart(const formula::RefEdit *pEdit)
Definition: anyrefdg.hxx:80
IAnyRefDialog * m_pDlg
Definition: anyrefdg.hxx:39
void SetDialog(weld::Dialog *pDialog)
Definition: anyrefdg.hxx:71
void SetDispatcherLock(bool bLock)
Definition: anyrefdg.cxx:700
virtual void SetActive() override=0
void disposeRefHandler()
Definition: anyrefdg.cxx:624
OUString m_aDocName
Definition: anyrefdg.hxx:94
virtual bool IsDocAllowed(SfxObjectShell *pDocSh) const override
Definition: anyrefdg.cxx:676
void ReleaseFocus(formula::RefEdit *pEdit)
Definition: anyrefdg.cxx:283
bool EnterRefMode()
Definition: anyrefdg.cxx:568
void ToggleCollapsed(formula::RefEdit *pEdit, formula::RefButton *pButton)
Definition: anyrefdg.cxx:401
~ScFormulaReferenceHelper() COVERITY_NOEXCEPT_FALSE
Definition: anyrefdg.cxx:58
static void EnableSpreadsheets(bool bFlag=true)
Definition: anyrefdg.cxx:482
void ShowSimpleReference(const OUString &rStr)
Definition: anyrefdg.cxx:110
::std::unique_ptr< ScCompiler > m_pRefComp
Definition: anyrefdg.hxx:40
virtual void ReleaseFocus(formula::RefEdit *pEdit) override
Definition: anyrefdg.cxx:750
weld::DialogController * m_pController
Definition: anyrefdg.hxx:86
virtual void RefInputDone(bool bForced=false) override
Definition: anyrefdg.cxx:755
ScRefHdlrControllerImpl(weld::Window *pParent, const OUString &rUIXMLDescription, const OString &rID, const SfxItemSet *pArg, SfxBindings *pB)
Definition: anyrefdg.hxx:147
virtual void HideReference(bool bDoneRefMode=true) override
Definition: anyrefdg.cxx:740
virtual void AddRefEntry() override
Definition: anyrefdg.cxx:710
void HideReference(bool bDoneRefMode=true)
Definition: anyrefdg.cxx:231
SfxBindings * m_pBindings
Definition: anyrefdg.hxx:44
virtual void ShowReference(const OUString &rStr) override
Definition: anyrefdg.cxx:745
bool CanInputDone(bool bForced)
Definition: anyrefdg.hxx:81
static void enableInput(bool _bInput)
Definition: anyrefdg.cxx:76
bool CanInputDone(bool bForced)
Definition: anyrefdg.hxx:136
virtual void ViewShellChanged() override
Definition: anyrefdg.cxx:705
formula::RefButton * m_pRefBtn
Definition: anyrefdg.hxx:42
void SetDispatcherLock(bool bLock)
Definition: anyrefdg.cxx:458
virtual void ToggleCollapsed(formula::RefEdit *pEdit, formula::RefButton *pButton) override
Definition: anyrefdg.cxx:730
ScFormulaReferenceHelper(IAnyRefDialog *_pDlg, SfxBindings *_pBindings)
Definition: anyrefdg.cxx:45
void SwitchToDocument()
Definition: anyrefdg.cxx:649
ScRefHdlrControllerImpl(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, const OUString &rUIXMLDescription, const OString &rID)
Definition: anyrefdg.hxx:153
void RefInputStart(formula::RefEdit *pEdit, formula::RefButton *pButton)
Definition: anyrefdg.cxx:370
SfxBindings * m_pMyBindings
Definition: anyrefdg.hxx:92
void RefInputDone(bool bForced)
Definition: anyrefdg.cxx:343
DECL_LINK(ActivateHdl, weld::Widget &, bool)
static void ViewShellChanged()
Definition: anyrefdg.cxx:476
virtual ~ScRefHandler() COVERITY_NOEXCEPT_FALSE override
Definition: anyrefdg.cxx:619
ScRefHandler(SfxDialogController &rController, SfxBindings *pB, bool bBindRef)
Definition: anyrefdg.cxx:557
void ShowReference(const OUString &rStr)
Definition: anyrefdg.cxx:259
bool LeaveRefMode()
Definition: anyrefdg.cxx:631
bool DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:694
bool ParseWithNames(ScRangeList &rRanges, const OUString &rStr, const ScDocument &pDoc)
Definition: anyrefdg.cxx:735
static bool CanInputStart(const formula::RefEdit *pEdit)
Definition: anyrefdg.hxx:132
void ShowFormulaReference(const OUString &rStr)
Definition: anyrefdg.cxx:174
ScAnyRefDlgController(SfxBindings *rt1, SfxChildWindow *rt2, weld::Window *rt3, const OUString &rt4, const OString &rt5)
Definition: anyrefdg.hxx:162
weld::Dialog * m_pDialog
Definition: anyrefdg.hxx:43
ScFormulaReferenceHelper m_aHelper
Definition: anyrefdg.hxx:91
sal_Int16 SCTAB
Definition: types.hxx:23
virtual void SetReference(const ScRange &rRef, ScDocument &rDoc) override=0
virtual void RefInputStart(formula::RefEdit *pEdit, formula::RefButton *pButton=nullptr) override
Definition: anyrefdg.cxx:725