1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <sfx2/basedlgs.hxx>
23 #include <address.hxx>
24 #include <formula/funcutl.hxx>
25 #include "IAnyRefDialog.hxx"
34 class ScFormulaReferenceHelper
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
40 weld::Dialog
* m_pDialog
;
41 SfxBindings
* m_pBindings
;
42 SCTAB m_nRefTab
; // used for ShowReference
44 OUString m_sOldDialogText
; // Original title of the dialog window
46 bool m_bEnableColorRef
;
49 DECL_LINK( ActivateHdl
, weld::Widget
&, bool );
52 ScFormulaReferenceHelper(IAnyRefDialog
* _pDlg
, SfxBindings
* _pBindings
);
53 ~ScFormulaReferenceHelper() COVERITY_NOEXCEPT_FALSE
;
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
);
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
);
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();
74 static void enableInput(bool _bInput
);
77 static bool CanInputStart( const formula::RefEdit
*pEdit
){ return !!pEdit
; }
78 bool CanInputDone(bool bForced
) const { return m_pRefEdit
&& (bForced
|| !m_pRefBtn
); }
81 class ScRefHandler
: public IAnyRefDialog
83 weld::DialogController
* m_pController
;
87 ScFormulaReferenceHelper
89 SfxBindings
* m_pMyBindings
;
91 OUString m_aDocName
; // document on which the dialog was opened
94 void disposeRefHandler();
95 bool DoClose( sal_uInt16 nId
);
97 void SetDispatcherLock( bool bLock
);
99 virtual void RefInputStart( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
= nullptr ) override
;
100 virtual void RefInputDone( bool bForced
= false ) override
;
102 bool ParseWithNames( ScRangeList
& rRanges
, std::u16string_view rStr
, const ScDocument
& pDoc
);
105 ScRefHandler(SfxDialogController
&rController
, SfxBindings
* pB
, bool bBindRef
);
106 virtual ~ScRefHandler() COVERITY_NOEXCEPT_FALSE override
;
108 virtual void SetReference( const ScRange
& rRef
, ScDocument
& rDoc
) override
= 0;
109 virtual void AddRefEntry() override
;
111 virtual bool IsRefInputMode() const override
;
112 virtual bool IsTableLocked() const override
;
113 virtual bool IsDocAllowed( SfxObjectShell
* pDocSh
) const override
;
115 virtual void ShowReference(const OUString
& rStr
) override
;
116 virtual void HideReference( bool bDoneRefMode
= true ) override
;
118 virtual void ToggleCollapsed( formula::RefEdit
* pEdit
, formula::RefButton
* pButton
) override
;
119 virtual void ReleaseFocus( formula::RefEdit
* pEdit
) override
;
121 virtual void ViewShellChanged() override
;
122 void SwitchToDocument();
124 virtual void SetActive() override
= 0;
129 static bool CanInputStart( const formula::RefEdit
*pEdit
)
131 return ScFormulaReferenceHelper::CanInputStart( pEdit
);
133 bool CanInputDone( bool bForced
)
135 return m_aHelper
.CanInputDone( bForced
);
139 template<class TBase
, bool bBindRef
= true>
140 struct ScRefHdlrControllerImpl
: public TBase
, public ScRefHandler
142 enum { UNKNOWN_SLOTID
= 0U, SLOTID
= UNKNOWN_SLOTID
};
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
)
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
)
157 struct ScAnyRefDlgController
: ScRefHdlrControllerImpl
<SfxModelessDialogController
>
159 ScAnyRefDlgController(SfxBindings
* rt1
, SfxChildWindow
* rt2
, weld::Window
* rt3
, const OUString
& rt4
, const OUString
& rt5
)
160 : ScRefHdlrControllerImpl
<SfxModelessDialogController
>(rt1
, rt2
, rt3
, rt4
, rt5
)
165 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */