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
29class SfxObjectShell;
30class ScDocument;
31class ScRangeList;
32class ScCompiler;
33
35{
36 IAnyRefDialog* m_pDlg;
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
51public:
52 ScFormulaReferenceHelper(IAnyRefDialog* _pDlg, SfxBindings* _pBindings);
53 ~ScFormulaReferenceHelper() COVERITY_NOEXCEPT_FALSE;
54 void dispose();
55
56 void ShowSimpleReference(std::u16string_view rStr);
57 void ShowFormulaReference(const OUString& rStr);
58 bool ParseWithNames( ScRangeList& rRanges, std::u16string_view 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
76public:
77 static bool CanInputStart( const formula::RefEdit *pEdit ){ return !!pEdit; }
78 bool CanInputDone(bool bForced) const { return m_pRefEdit && (bForced || !m_pRefBtn); }
79};
80
81class ScRefHandler : public IAnyRefDialog
82{
85
86private:
90
91 OUString m_aDocName; // document on which the dialog was opened
92
93protected:
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, std::u16string_view rStr, const ScDocument& pDoc );
103
104public:
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
126public:
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
139template<class TBase, bool bBindRef = true>
140struct ScRefHdlrControllerImpl : public TBase, public ScRefHandler
141{
143
144 ScRefHdlrControllerImpl(weld::Window* pParent, const OUString& rUIXMLDescription, const OUString& 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 OUString& rID)
151 : TBase(pB, pCW, pParent, rUIXMLDescription, rID)
152 , ScRefHandler(*static_cast<TBase*>(this), pB, bBindRef)
153 {
154 }
155};
156
157struct ScAnyRefDlgController : ScRefHdlrControllerImpl<SfxModelessDialogController>
158{
159 ScAnyRefDlgController(SfxBindings* rt1, SfxChildWindow* rt2, weld::Window* rt3, const OUString& rt4, const OUString& rt5)
160 : ScRefHdlrControllerImpl<SfxModelessDialogController>(rt1, rt2, rt3, rt4, rt5)
161 {
162 }
163};
164
165/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
weld::Dialog * m_pDialog
Definition: anyrefdg.hxx:40
void HideReference(bool bDoneRefMode=true)
Definition: anyrefdg.cxx:233
::std::unique_ptr< ScCompiler > m_pRefComp
Definition: anyrefdg.hxx:37
void ShowFormulaReference(const OUString &rStr)
Definition: anyrefdg.cxx:176
static void ViewShellChanged()
Definition: anyrefdg.cxx:496
static void enableInput(bool _bInput)
Definition: anyrefdg.cxx:78
bool ParseWithNames(ScRangeList &rRanges, std::u16string_view rStr, const ScDocument &rDoc)
Definition: anyrefdg.cxx:141
SfxBindings * m_pBindings
Definition: anyrefdg.hxx:41
void ToggleCollapsed(formula::RefEdit *pEdit, formula::RefButton *pButton)
Definition: anyrefdg.cxx:399
static void EnableSpreadsheets(bool bFlag=true)
Definition: anyrefdg.cxx:502
DECL_LINK(ActivateHdl, weld::Widget &, bool)
void SetDispatcherLock(bool bLock)
Definition: anyrefdg.cxx:456
formula::RefButton * m_pRefBtn
Definition: anyrefdg.hxx:39
void DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:419
void SetDialog(weld::Dialog *pDialog)
Definition: anyrefdg.hxx:68
void RefInputStart(formula::RefEdit *pEdit, formula::RefButton *pButton)
Definition: anyrefdg.cxx:368
IAnyRefDialog * m_pDlg
Definition: anyrefdg.hxx:36
formula::RefEdit * m_pRefEdit
Definition: anyrefdg.hxx:38
void ShowSimpleReference(std::u16string_view rStr)
Definition: anyrefdg.cxx:112
bool CanInputDone(bool bForced) const
Definition: anyrefdg.hxx:78
ScFormulaReferenceHelper(IAnyRefDialog *_pDlg, SfxBindings *_pBindings)
Definition: anyrefdg.cxx:47
static bool CanInputStart(const formula::RefEdit *pEdit)
Definition: anyrefdg.hxx:77
void ReleaseFocus(formula::RefEdit *pEdit)
Definition: anyrefdg.cxx:281
~ScFormulaReferenceHelper() COVERITY_NOEXCEPT_FALSE
Definition: anyrefdg.cxx:60
void ShowReference(const OUString &rStr)
Definition: anyrefdg.cxx:261
void RefInputDone(bool bForced)
Definition: anyrefdg.cxx:341
virtual void RefInputStart(formula::RefEdit *pEdit, formula::RefButton *pButton=nullptr) override
Definition: anyrefdg.cxx:745
weld::DialogController * m_pController
Definition: anyrefdg.hxx:83
bool ParseWithNames(ScRangeList &rRanges, std::u16string_view rStr, const ScDocument &pDoc)
Definition: anyrefdg.cxx:755
virtual bool IsRefInputMode() const override
Definition: anyrefdg.cxx:709
virtual void RefInputDone(bool bForced=false) override
Definition: anyrefdg.cxx:775
virtual void ToggleCollapsed(formula::RefEdit *pEdit, formula::RefButton *pButton) override
Definition: anyrefdg.cxx:750
OUString m_aDocName
Definition: anyrefdg.hxx:91
ScRefHandler(SfxDialogController &rController, SfxBindings *pB, bool bBindRef)
Definition: anyrefdg.cxx:577
virtual void AddRefEntry() override
Definition: anyrefdg.cxx:730
static bool CanInputStart(const formula::RefEdit *pEdit)
Definition: anyrefdg.hxx:129
bool EnterRefMode()
Definition: anyrefdg.cxx:588
ScFormulaReferenceHelper m_aHelper
Definition: anyrefdg.hxx:88
void disposeRefHandler()
Definition: anyrefdg.cxx:644
virtual void SetActive() override=0
void SwitchToDocument()
Definition: anyrefdg.cxx:669
virtual bool IsTableLocked() const override
Definition: anyrefdg.cxx:735
bool DoClose(sal_uInt16 nId)
Definition: anyrefdg.cxx:714
bool m_bInRefMode
Definition: anyrefdg.hxx:84
bool LeaveRefMode()
Definition: anyrefdg.cxx:651
virtual void ShowReference(const OUString &rStr) override
Definition: anyrefdg.cxx:765
virtual void SetReference(const ScRange &rRef, ScDocument &rDoc) override=0
virtual ~ScRefHandler() COVERITY_NOEXCEPT_FALSE override
Definition: anyrefdg.cxx:639
virtual bool IsDocAllowed(SfxObjectShell *pDocSh) const override
Definition: anyrefdg.cxx:696
virtual void ViewShellChanged() override
Definition: anyrefdg.cxx:725
SfxBindings * m_pMyBindings
Definition: anyrefdg.hxx:89
virtual void ReleaseFocus(formula::RefEdit *pEdit) override
Definition: anyrefdg.cxx:770
virtual void HideReference(bool bDoneRefMode=true) override
Definition: anyrefdg.cxx:760
void SetDispatcherLock(bool bLock)
Definition: anyrefdg.cxx:720
bool CanInputDone(bool bForced)
Definition: anyrefdg.hxx:133
ScAnyRefDlgController(SfxBindings *rt1, SfxChildWindow *rt2, weld::Window *rt3, const OUString &rt4, const OUString &rt5)
Definition: anyrefdg.hxx:159
ScRefHdlrControllerImpl(weld::Window *pParent, const OUString &rUIXMLDescription, const OUString &rID, const SfxItemSet *pArg, SfxBindings *pB)
Definition: anyrefdg.hxx:144
ScRefHdlrControllerImpl(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent, const OUString &rUIXMLDescription, const OUString &rID)
Definition: anyrefdg.hxx:150
sal_Int16 SCTAB
Definition: types.hxx:22