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 .
20 #include <sfx2/basedlgs.hxx>
21 #include <sfx2/bindings.hxx>
22 #include <sfx2/dispatch.hxx>
23 #include <sfx2/viewfrm.hxx>
25 #include <reffact.hxx>
26 #include <tabvwsh.hxx>
28 #include <acredlin.hxx>
29 #include <simpref.hxx>
32 #include <validate.hxx>
34 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScNameDlgWrapper
, FID_DEFINE_NAME
)
35 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScNameDefDlgWrapper
, FID_ADD_NAME
)
36 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScSolverDlgWrapper
, SID_OPENDLG_SOLVE
)
37 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScOptSolverDlgWrapper
, SID_OPENDLG_OPTSOLVER
)
38 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScXMLSourceDlgWrapper
, SID_MANAGE_XML_SOURCE
)
39 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScPivotLayoutWrapper
, SID_OPENDLG_PIVOTTABLE
)
40 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScTabOpDlgWrapper
, SID_OPENDLG_TABOP
)
41 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScFilterDlgWrapper
, SID_FILTER
)
42 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScSpecialFilterDlgWrapper
, SID_SPECIAL_FILTER
)
43 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScDbNameDlgWrapper
, SID_DEFINE_DBNAME
)
44 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScConsolidateDlgWrapper
, SID_OPENDLG_CONSOLIDATE
)
45 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScPrintAreasDlgWrapper
, SID_OPENDLG_EDIT_PRINTAREA
)
46 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScColRowNameRangesDlgWrapper
, SID_DEFINE_COLROWNAMERANGES
)
47 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScFormulaDlgWrapper
, SID_OPENDLG_FUNCTION
)
48 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScAcceptChgDlgWrapper
, FID_CHG_ACCEPT
)
49 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScHighlightChgDlgWrapper
, FID_CHG_SHOW
)
50 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScSimpleRefDlgWrapper
, WID_SIMPLE_REF
)
51 SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(ScCondFormatDlgWrapper
, WID_CONDFRMT_REF
)
53 SFX_IMPL_CHILDWINDOW_WITHID(ScValidityRefChildWin
, SID_VALIDITY_REFERENCE
)
55 SfxChildWinInfo
ScValidityRefChildWin::GetInfo() const
57 SfxChildWinInfo aInfo
= SfxChildWindow::GetInfo();
63 ScTabViewShell
* lcl_GetTabViewShell( const SfxBindings
* pBindings
);
66 #define IMPL_CONTROLLER_CHILD_CTOR(Class,sid) \
67 Class::Class( vcl::Window* pParentP, \
70 SfxChildWinInfo* pInfo ) \
71 : SfxChildWindow(pParentP, nId) \
73 /************************************************************************************/\
74 /* When a new document is creating, the SfxViewFrame may be ready, */\
75 /* But the ScTabViewShell may have not been activated yet. In this */\
76 /* situation, SfxViewShell::Current() does not get the correct shell, */\
77 /* and we should lcl_GetTabViewShell( p ) instead of SfxViewShell::Current() */\
78 /************************************************************************************/\
79 ScTabViewShell* pViewShell = lcl_GetTabViewShell( p ); \
81 pViewShell = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() ); \
82 OSL_ENSURE( pViewShell, "missing view shell :-(" ); \
83 SetController( pViewShell ? \
84 pViewShell->CreateRefDialogController( p, this, pInfo, pParentP->GetFrameWeld(), sid ) : nullptr ); \
85 if (pViewShell && !GetController()) \
86 pViewShell->GetViewFrame().SetChildWindow( nId, false ); \
90 IMPL_CONTROLLER_CHILD_CTOR( ScNameDlgWrapper
, FID_DEFINE_NAME
)
92 IMPL_CONTROLLER_CHILD_CTOR( ScNameDefDlgWrapper
, FID_ADD_NAME
)
94 IMPL_CONTROLLER_CHILD_CTOR( ScSolverDlgWrapper
, SID_OPENDLG_SOLVE
)
96 IMPL_CONTROLLER_CHILD_CTOR( ScOptSolverDlgWrapper
, SID_OPENDLG_OPTSOLVER
)
98 IMPL_CONTROLLER_CHILD_CTOR( ScXMLSourceDlgWrapper
, SID_MANAGE_XML_SOURCE
)
100 IMPL_CONTROLLER_CHILD_CTOR( ScPivotLayoutWrapper
, SID_OPENDLG_PIVOTTABLE
)
102 IMPL_CONTROLLER_CHILD_CTOR( ScTabOpDlgWrapper
, SID_OPENDLG_TABOP
)
104 IMPL_CONTROLLER_CHILD_CTOR( ScFilterDlgWrapper
, SID_FILTER
)
106 IMPL_CONTROLLER_CHILD_CTOR( ScSpecialFilterDlgWrapper
, SID_SPECIAL_FILTER
)
108 IMPL_CONTROLLER_CHILD_CTOR( ScDbNameDlgWrapper
, SID_DEFINE_DBNAME
)
110 IMPL_CONTROLLER_CHILD_CTOR( ScColRowNameRangesDlgWrapper
, SID_DEFINE_COLROWNAMERANGES
)
112 IMPL_CONTROLLER_CHILD_CTOR( ScConsolidateDlgWrapper
, SID_OPENDLG_CONSOLIDATE
)
114 IMPL_CONTROLLER_CHILD_CTOR( ScPrintAreasDlgWrapper
, SID_OPENDLG_EDIT_PRINTAREA
)
116 IMPL_CONTROLLER_CHILD_CTOR( ScFormulaDlgWrapper
, SID_OPENDLG_FUNCTION
)
119 // ScSimpleRefDlgWrapper
121 static bool bScSimpleRefFlag
;
122 static tools::Long nScSimpleRefHeight
;
123 static tools::Long nScSimpleRefWidth
;
124 static tools::Long nScSimpleRefX
;
125 static tools::Long nScSimpleRefY
;
126 static bool bAutoReOpen
= true;
128 ScSimpleRefDlgWrapper::ScSimpleRefDlgWrapper( vcl::Window
* pParentP
,
131 SfxChildWinInfo
* pInfo
)
132 : SfxChildWindow(pParentP
, nId
)
135 ScTabViewShell
* pViewShell
= nullptr;
136 SfxDispatcher
* pDisp
= p
->GetDispatcher();
139 SfxViewFrame
* pViewFrm
= pDisp
->GetFrame();
141 pViewShell
= dynamic_cast<ScTabViewShell
*>( pViewFrm
->GetViewShell() );
144 OSL_ENSURE( pViewShell
, "missing view shell :-(" );
146 if(pInfo
!=nullptr && bScSimpleRefFlag
)
148 pInfo
->aPos
.setX(nScSimpleRefX
);
149 pInfo
->aPos
.setY(nScSimpleRefY
);
150 pInfo
->aSize
.setHeight(nScSimpleRefHeight
);
151 pInfo
->aSize
.setWidth(nScSimpleRefWidth
);
153 SetController(nullptr);
155 if (bAutoReOpen
&& pViewShell
)
156 SetController(pViewShell
->CreateRefDialogController(p
, this, pInfo
, pParentP
->GetFrameWeld(), WID_SIMPLE_REF
));
158 if (!GetController())
160 ScModule::get()->SetRefDialog(nId
, false);
164 void ScSimpleRefDlgWrapper::SetAutoReOpen(bool bFlag
)
169 void ScSimpleRefDlgWrapper::SetRefString(const OUString
& rStr
)
171 auto xDlgController
= GetController();
174 static_cast<ScSimpleRefDlg
*>(xDlgController
.get())->SetRefString(rStr
);
178 void ScSimpleRefDlgWrapper::SetCloseHdl( const Link
<const OUString
*,void>& rLink
)
180 auto xDlgController
= GetController();
183 static_cast<ScSimpleRefDlg
*>(xDlgController
.get())->SetCloseHdl(rLink
);
187 void ScSimpleRefDlgWrapper::SetUnoLinks( const Link
<const OUString
&,void>& rDone
,
188 const Link
<const OUString
&,void>& rAbort
, const Link
<const OUString
&,void>& rChange
)
190 auto xDlgController
= GetController();
193 static_cast<ScSimpleRefDlg
*>(xDlgController
.get())->SetUnoLinks( rDone
, rAbort
, rChange
);
197 void ScSimpleRefDlgWrapper::SetFlags( bool bCloseOnButtonUp
, bool bSingleCell
, bool bMultiSelection
)
199 auto xDlgController
= GetController();
202 static_cast<ScSimpleRefDlg
*>(xDlgController
.get())->SetFlags( bCloseOnButtonUp
, bSingleCell
, bMultiSelection
);
206 void ScSimpleRefDlgWrapper::StartRefInput()
208 auto xDlgController
= GetController();
211 static_cast<ScSimpleRefDlg
*>(xDlgController
.get())->StartRefInput();
215 // ScAcceptChgDlgWrapper //FIXME: should be moved into ViewShell
217 ScAcceptChgDlgWrapper::ScAcceptChgDlgWrapper(vcl::Window
* pParentP
,
219 SfxBindings
* pBindings
,
220 SfxChildWinInfo
* pInfo
) :
221 SfxChildWindow( pParentP
, nId
)
223 ScTabViewShell
* pViewShell
=
224 dynamic_cast<ScTabViewShell
*>( SfxViewShell::Current() );
225 OSL_ENSURE( pViewShell
, "missing view shell :-(" );
228 auto xDlg
= std::make_shared
<ScAcceptChgDlg
>(pBindings
, this, pParentP
->GetFrameWeld(), &pViewShell
->GetViewData());
230 pInfo
->nFlags
= SfxChildWindowFlags::NEVERHIDE
;
231 xDlg
->Initialize( pInfo
);
234 SetController( nullptr );
235 if (pViewShell
&& !GetController())
236 pViewShell
->GetViewFrame().SetChildWindow( nId
, false );
239 void ScAcceptChgDlgWrapper::ReInitDlg()
241 ScTabViewShell
* pViewShell
=
242 dynamic_cast<ScTabViewShell
*>( SfxViewShell::Current() );
243 OSL_ENSURE( pViewShell
, "missing view shell :-(" );
245 if (GetController() && pViewShell
)
247 static_cast<ScAcceptChgDlg
*>(GetController().get())->ReInit(&pViewShell
->GetViewData());
251 // ScHighlightChgDlgWrapper
253 IMPL_CONTROLLER_CHILD_CTOR(ScHighlightChgDlgWrapper
, FID_CHG_SHOW
)
257 ScTabViewShell
* lcl_GetTabViewShell( const SfxBindings
*pBindings
)
260 if( SfxDispatcher
* pDisp
= pBindings
->GetDispatcher() )
261 if( SfxViewFrame
*pFrm
= pDisp
->GetFrame() )
262 if( SfxViewShell
* pViewSh
= pFrm
->GetViewShell() )
263 return dynamic_cast<ScTabViewShell
*>( pViewSh
);
269 ScValidityRefChildWin::ScValidityRefChildWin(vcl::Window
* pParentP
,
271 const SfxBindings
* p
,
272 SAL_UNUSED_PARAMETER SfxChildWinInfo
* /*pInfo*/ )
273 : SfxChildWindow(pParentP
, nId
)
274 , m_bVisibleLock(false)
275 , m_bFreeWindowLock(false)
277 SetWantsFocus( false );
278 std::shared_ptr
<SfxDialogController
> xDlg(ScValidationDlg::Find1AliveObject(pParentP
->GetFrameWeld()));
280 ScTabViewShell
* pViewShell
;
282 pViewShell
= static_cast<ScValidationDlg
*>(xDlg
.get())->GetTabViewShell();
284 pViewShell
= lcl_GetTabViewShell( p
);
286 pViewShell
= dynamic_cast<ScTabViewShell
*>( SfxViewShell::Current() );
287 OSL_ENSURE( pViewShell
, "missing view shell :-(" );
288 if (pViewShell
&& !xDlg
)
289 pViewShell
->GetViewFrame().SetChildWindow( nId
, false );
292 ScValidityRefChildWin::~ScValidityRefChildWin()
294 if (m_bFreeWindowLock
)
295 SetController(nullptr);
298 IMPL_CONTROLLER_CHILD_CTOR( ScCondFormatDlgWrapper
, WID_CONDFRMT_REF
)
300 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */