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 #pragma once
21 
22 #include <sfx2/basedlgs.hxx>
23 #include <address.hxx>
24 #include <formula/funcutl.hxx>
25 #include "IAnyRefDialog.hxx"
26 
27 #include <memory>
28 
29 class SfxObjectShell;
30 class ScDocument;
31 class ScRangeList;
32 class ScCompiler;
33 
35 {
37  ::std::unique_ptr<ScCompiler> m_pRefComp;
38  formula::RefEdit* m_pRefEdit; // active input field
39  formula::RefButton* m_pRefBtn; // associated button
42  SCTAB m_nRefTab; // used for ShowReference
43 
44  OUString m_sOldDialogText; // Original title of the dialog window
45 
48 
49  DECL_LINK( ActivateHdl, weld::Widget&, bool );
50 
51 public:
53  ~ScFormulaReferenceHelper() COVERITY_NOEXCEPT_FALSE;
54  void dispose();
55 
56  void ShowSimpleReference(const OUString& rStr);
57  void ShowFormulaReference(const OUString& rStr);
58  bool ParseWithNames( ScRangeList& rRanges, const OUString& rStr, const ScDocument& rDoc );
59  void Init();
60 
61  void ShowReference(const OUString& rStr);
62  void ReleaseFocus( formula::RefEdit* pEdit );
63  void HideReference( bool bDoneRefMode = true );
64  void RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton );
65  void RefInputDone( bool bForced );
66  void ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton );
67 
68  void SetDialog(weld::Dialog* pDialog) { m_pDialog = pDialog; }
69  void DoClose( sal_uInt16 nId );
70  void SetDispatcherLock( bool bLock );
71  static void EnableSpreadsheets( bool bFlag = true );
72  static void ViewShellChanged();
73 
74  static void enableInput(bool _bInput);
75 
76 public:
77  static bool CanInputStart( const formula::RefEdit *pEdit ){ return !!pEdit; }
78  bool CanInputDone(bool bForced) { return m_pRefEdit && (bForced || !m_pRefBtn); }
79 };
80 
82 {
85 
86 private:
90 
91  OUString m_aDocName; // document on which the dialog was opened
92 
93 protected:
94  void disposeRefHandler();
95  bool DoClose( sal_uInt16 nId );
96 
97  void SetDispatcherLock( bool bLock );
98 
99  virtual void RefInputStart( formula::RefEdit* pEdit, formula::RefButton* pButton = nullptr ) override;
100  virtual void RefInputDone( bool bForced = false ) override;
101 
102  bool ParseWithNames( ScRangeList& rRanges, const OUString& rStr, const ScDocument& pDoc );
103 
104 public:
105  ScRefHandler(SfxDialogController &rController, SfxBindings* pB, bool bBindRef);
106  virtual ~ScRefHandler() COVERITY_NOEXCEPT_FALSE override;
107 
108  virtual void SetReference( const ScRange& rRef, ScDocument& rDoc ) override = 0;
109  virtual void AddRefEntry() override;
110 
111  virtual bool IsRefInputMode() const override;
112  virtual bool IsTableLocked() const override;
113  virtual bool IsDocAllowed( SfxObjectShell* pDocSh ) const override;
114 
115  virtual void ShowReference(const OUString& rStr) override;
116  virtual void HideReference( bool bDoneRefMode = true ) override;
117 
118  virtual void ToggleCollapsed( formula::RefEdit* pEdit, formula::RefButton* pButton ) override;
119  virtual void ReleaseFocus( formula::RefEdit* pEdit ) override;
120 
121  virtual void ViewShellChanged() override;
122  void SwitchToDocument();
123 
124  virtual void SetActive() override = 0;
125 
126 public:
127  bool EnterRefMode();
128  bool LeaveRefMode();
129  static bool CanInputStart( const formula::RefEdit *pEdit )
130  {
132  }
133  bool CanInputDone( bool bForced )
134  {
135  return m_aHelper.CanInputDone( bForced );
136  }
137 };
138 
139 template<class TBase, bool bBindRef = true>
140 struct ScRefHdlrControllerImpl : public TBase, public ScRefHandler
141 {
143 
144  ScRefHdlrControllerImpl(weld::Window* pParent, const OUString& rUIXMLDescription, const OString& rID, const SfxItemSet* pArg, SfxBindings *pB)
145  : TBase(pParent, rUIXMLDescription, rID, pArg)
146  , ScRefHandler(*static_cast<TBase*>(this), pB, bBindRef)
147  {
148  }
149 
150  ScRefHdlrControllerImpl(SfxBindings* pB, SfxChildWindow* pCW, weld::Window* pParent, const OUString& rUIXMLDescription, const OString& rID)
151  : TBase(pB, pCW, pParent, rUIXMLDescription, rID)
152  , ScRefHandler(*static_cast<TBase*>(this), pB, bBindRef)
153  {
154  }
155 };
156 
157 struct ScAnyRefDlgController : ScRefHdlrControllerImpl<SfxModelessDialogController>
158 {
159  ScAnyRefDlgController(SfxBindings* rt1, SfxChildWindow* rt2, weld::Window* rt3, const OUString& rt4, const OString& rt5)
160  : ScRefHdlrControllerImpl<SfxModelessDialogController>(rt1, rt2, rt3, rt4, rt5)
161  {
162  }
163 };
164 
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:422
bool ParseWithNames(ScRangeList &rRanges, const OUString &rStr, const ScDocument &rDoc)
Definition: anyrefdg.cxx:140
virtual bool IsTableLocked() const override
Definition: anyrefdg.cxx:716
virtual bool IsRefInputMode() const override
Definition: anyrefdg.cxx:690
formula::RefEdit * m_pRefEdit
Definition: anyrefdg.hxx:38
bool m_bInRefMode
Definition: anyrefdg.hxx:84
static bool CanInputStart(const formula::RefEdit *pEdit)
Definition: anyrefdg.hxx:77
IAnyRefDialog * m_pDlg
Definition: anyrefdg.hxx:36
void SetDialog(weld::Dialog *pDialog)
Definition: anyrefdg.hxx:68
void SetDispatcherLock(bool bLock)
Definition: anyrefdg.cxx:701
virtual void SetActive() override=0
void disposeRefHandler()
Definition: anyrefdg.cxx:625
OUString m_aDocName
Definition: anyrefdg.hxx:91
virtual bool IsDocAllowed(SfxObjectShell *pDocSh) const override
Definition: anyrefdg.cxx:677
void ReleaseFocus(formula::RefEdit *pEdit)
Definition: anyrefdg.cxx:284
bool EnterRefMode()
Definition: anyrefdg.cxx:569
void ToggleCollapsed(formula::RefEdit *pEdit, formula::RefButton *pButton)
Definition: anyrefdg.cxx:402
~ScFormulaReferenceHelper() COVERITY_NOEXCEPT_FALSE
Definition: anyrefdg.cxx:59
static void EnableSpreadsheets(bool bFlag=true)
Definition: anyrefdg.cxx:483
void ShowSimpleReference(const OUString &rStr)
Definition: anyrefdg.cxx:111
::std::unique_ptr< ScCompiler > m_pRefComp
Definition: anyrefdg.hxx:37
virtual void ReleaseFocus(formula::RefEdit *pEdit) override
Definition: anyrefdg.cxx:751
weld::DialogController * m_pController
Definition: anyrefdg.hxx:83
virtual void RefInputDone(bool bForced=false) override
Definition: anyrefdg.cxx:756
ScRefHdlrControllerImpl(weld::Window *pParent, const OUString &rUIXMLDescription, const OString &rID, const SfxItemSet *pArg, SfxBindings *pB)
Definition: anyrefdg.hxx:144
virtual void HideReference(bool bDoneRefMode=true) override
Definition: anyrefdg.cxx:741
virtual void AddRefEntry() override
Definition: anyrefdg.cxx:711
void HideReference(bool bDoneRefMode=true)
Definition: anyrefdg.cxx:232
SfxBindings * m_pBindings
Definition: anyrefdg.hxx:41
virtual void ShowReference(const OUString &rStr) override
Definition: anyrefdg.cxx:746
bool CanInputDone(bool bForced)
Definition: anyrefdg.hxx:78
static void enableInput(bool _bInput)
Definition: anyrefdg.cxx:77
bool CanInputDone(bool bForced)
Definition: anyrefdg.hxx:133
virtual void ViewShellChanged() override
Definition: anyrefdg.cxx:706
formula::RefButton * m_pRefBtn
Definition: anyrefdg.hxx:39
void SetDispatcherLock(bool bLock)
Definition: anyrefdg.cxx:459
virtual void ToggleCollapsed(formula::RefEdit *pEdit, formula::RefButton *pButton) override
Definition: anyrefdg.cxx:731
ScFormulaReferenceHelper(IAnyRefDialog *_pDlg, SfxBindings *_pBindings)
Definition: anyrefdg.cxx:46
void SwitchToDocument()
Definition: anyrefdg.cxx:650
ScRefHdlrControllerImpl(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, const OUString &rUIXMLDescription, const OString &rID)
Definition: anyrefdg.hxx:150
void RefInputStart(formula::RefEdit *pEdit, formula::RefButton *pButton)
Definition: anyrefdg.cxx:371
SfxBindings * m_pMyBindings
Definition: anyrefdg.hxx:89
void RefInputDone(bool bForced)
Definition: anyrefdg.cxx:344
DECL_LINK(ActivateHdl, weld::Widget &, bool)
static void ViewShellChanged()
Definition: anyrefdg.cxx:477
virtual ~ScRefHandler() COVERITY_NOEXCEPT_FALSE override
Definition: anyrefdg.cxx:620
ScRefHandler(SfxDialogController &rController, SfxBindings *pB, bool bBindRef)
Definition: anyrefdg.cxx:558
void ShowReference(const OUString &rStr)
Definition: anyrefdg.cxx:260
bool LeaveRefMode()
Definition: anyrefdg.cxx:632
bool DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:695
bool ParseWithNames(ScRangeList &rRanges, const OUString &rStr, const ScDocument &pDoc)
Definition: anyrefdg.cxx:736
static bool CanInputStart(const formula::RefEdit *pEdit)
Definition: anyrefdg.hxx:129
void ShowFormulaReference(const OUString &rStr)
Definition: anyrefdg.cxx:175
ScAnyRefDlgController(SfxBindings *rt1, SfxChildWindow *rt2, weld::Window *rt3, const OUString &rt4, const OString &rt5)
Definition: anyrefdg.hxx:159
weld::Dialog * m_pDialog
Definition: anyrefdg.hxx:40
ScFormulaReferenceHelper m_aHelper
Definition: anyrefdg.hxx:88
sal_Int16 SCTAB
Definition: types.hxx:22
virtual void SetReference(const ScRange &rRef, ScDocument &rDoc) override=0
virtual void RefInputStart(formula::RefEdit *pEdit, formula::RefButton *pButton=nullptr) override
Definition: anyrefdg.cxx:726