lok: calc: fix needed when position caching is disabled
[LibreOffice.git] / sc / source / ui / view / reffact.cxx
blob8a7bb28adec9d9321f19c998f0d30b44dc19eed6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/app.hxx>
21 #include <sfx2/basedlgs.hxx>
22 #include <sfx2/bindings.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <sfx2/viewfrm.hxx>
26 #include <reffact.hxx>
27 #include <tabvwsh.hxx>
28 #include <sc.hrc>
29 #include <acredlin.hxx>
30 #include <simpref.hxx>
31 #include <scmod.hxx>
32 #include <scres.hrc>
33 #include <validate.hxx>
35 SFX_IMPL_MODELESSDIALOG_WITHID(ScNameDlgWrapper, FID_DEFINE_NAME )
36 SFX_IMPL_MODELESSDIALOG_WITHID(ScNameDefDlgWrapper, FID_ADD_NAME )
37 SFX_IMPL_MODELESSDIALOG_WITHID(ScSolverDlgWrapper, SID_OPENDLG_SOLVE )
38 SFX_IMPL_MODELESSDIALOG_WITHID(ScOptSolverDlgWrapper, SID_OPENDLG_OPTSOLVER )
39 SFX_IMPL_MODELESSDIALOG_WITHID(ScXMLSourceDlgWrapper, SID_MANAGE_XML_SOURCE)
40 SFX_IMPL_MODELESSDIALOG_WITHID(ScPivotLayoutWrapper, SID_OPENDLG_PIVOTTABLE )
41 SFX_IMPL_MODELESSDIALOG_WITHID(ScTabOpDlgWrapper, SID_OPENDLG_TABOP )
42 SFX_IMPL_MODELESSDIALOG_WITHID(ScFilterDlgWrapper, SID_FILTER )
43 SFX_IMPL_MODELESSDIALOG_WITHID(ScSpecialFilterDlgWrapper, SID_SPECIAL_FILTER )
44 SFX_IMPL_MODELESSDIALOG_WITHID(ScDbNameDlgWrapper, SID_DEFINE_DBNAME )
45 SFX_IMPL_MODELESSDIALOG_WITHID(ScConsolidateDlgWrapper, SID_OPENDLG_CONSOLIDATE )
46 SFX_IMPL_MODELESSDIALOG_WITHID(ScPrintAreasDlgWrapper, SID_OPENDLG_EDIT_PRINTAREA )
47 SFX_IMPL_MODELESSDIALOG_WITHID(ScColRowNameRangesDlgWrapper, SID_DEFINE_COLROWNAMERANGES )
48 SFX_IMPL_MODELESSDIALOG_WITHID(ScFormulaDlgWrapper, SID_OPENDLG_FUNCTION )
49 SFX_IMPL_MODELESSDIALOG_WITHID(ScAcceptChgDlgWrapper, FID_CHG_ACCEPT )
50 SFX_IMPL_MODELESSDIALOG_WITHID(ScHighlightChgDlgWrapper, FID_CHG_SHOW )
51 SFX_IMPL_MODELESSDIALOG_WITHID(ScSimpleRefDlgWrapper, WID_SIMPLE_REF )
52 SFX_IMPL_MODELESSDIALOG_WITHID(ScCondFormatDlgWrapper, WID_CONDFRMT_REF )
54 SFX_IMPL_CHILDWINDOW_WITHID(ScValidityRefChildWin, SID_VALIDITY_REFERENCE)
56 SfxChildWinInfo ScValidityRefChildWin::GetInfo() const
58 SfxChildWinInfo anInfo = SfxChildWindow::GetInfo();
60 if( vcl::Window *pWnd = GetWindow() )
62 anInfo.aSize = pWnd->GetSizePixel();
64 if( pWnd->IsDialog() )
65 if ( static_cast<Dialog*>(pWnd)->IsRollUp() )
66 anInfo.nFlags |= SfxChildWindowFlags::ZOOMIN;
69 return anInfo;
72 namespace
74 ScTabViewShell* lcl_GetTabViewShell( const SfxBindings* pBindings );
77 #define IMPL_CHILD_CTOR(Class,sid) \
78 Class::Class( vcl::Window* pParentP, \
79 sal_uInt16 nId, \
80 SfxBindings* p, \
81 SfxChildWinInfo* pInfo ) \
82 : SfxChildWindow(pParentP, nId) \
83 { \
84 /************************************************************************************/\
85 /* When a new document is creating, the SfxViewFrame may be ready, */\
86 /* But the ScTabViewShell may have not been activated yet. In this */\
87 /* situation, SfxViewShell::Current() does not get the correct shell, */\
88 /* and we should lcl_GetTabViewShell( p ) instead of SfxViewShell::Current() */\
89 /************************************************************************************/\
90 ScTabViewShell* pViewShell = lcl_GetTabViewShell( p ); \
91 if (!pViewShell) \
92 pViewShell = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() ); \
93 OSL_ENSURE( pViewShell, "missing view shell :-(" ); \
94 SetWindow( pViewShell ? \
95 pViewShell->CreateRefDialog( p, this, pInfo, pParentP, sid ) : nullptr ); \
96 if (pViewShell && !GetWindow()) \
97 pViewShell->GetViewFrame()->SetChildWindow( nId, false ); \
100 IMPL_CHILD_CTOR( ScNameDlgWrapper, FID_DEFINE_NAME )
102 IMPL_CHILD_CTOR( ScNameDefDlgWrapper, FID_ADD_NAME )
104 IMPL_CHILD_CTOR( ScSolverDlgWrapper, SID_OPENDLG_SOLVE )
106 IMPL_CHILD_CTOR( ScOptSolverDlgWrapper, SID_OPENDLG_OPTSOLVER )
108 IMPL_CHILD_CTOR( ScXMLSourceDlgWrapper, SID_MANAGE_XML_SOURCE)
110 IMPL_CHILD_CTOR( ScPivotLayoutWrapper, SID_OPENDLG_PIVOTTABLE )
112 IMPL_CHILD_CTOR( ScTabOpDlgWrapper, SID_OPENDLG_TABOP )
114 IMPL_CHILD_CTOR( ScFilterDlgWrapper, SID_FILTER )
116 IMPL_CHILD_CTOR( ScSpecialFilterDlgWrapper, SID_SPECIAL_FILTER )
118 IMPL_CHILD_CTOR( ScDbNameDlgWrapper, SID_DEFINE_DBNAME )
120 IMPL_CHILD_CTOR( ScColRowNameRangesDlgWrapper, SID_DEFINE_COLROWNAMERANGES )
122 IMPL_CHILD_CTOR( ScConsolidateDlgWrapper, SID_OPENDLG_CONSOLIDATE )
124 IMPL_CHILD_CTOR( ScPrintAreasDlgWrapper, SID_OPENDLG_EDIT_PRINTAREA )
126 IMPL_CHILD_CTOR( ScFormulaDlgWrapper, SID_OPENDLG_FUNCTION )
128 // ScSimpleRefDlgWrapper
130 static bool bScSimpleRefFlag;
131 static long nScSimpleRefHeight;
132 static long nScSimpleRefWidth;
133 static long nScSimpleRefX;
134 static long nScSimpleRefY;
135 static bool bAutoReOpen = true;
137 ScSimpleRefDlgWrapper::ScSimpleRefDlgWrapper( vcl::Window* pParentP,
138 sal_uInt16 nId,
139 SfxBindings* p,
140 SfxChildWinInfo* pInfo )
141 : SfxChildWindow(pParentP, nId)
144 ScTabViewShell* pViewShell = nullptr;
145 SfxDispatcher* pDisp = p->GetDispatcher();
146 if ( pDisp )
148 SfxViewFrame* pViewFrm = pDisp->GetFrame();
149 if ( pViewFrm )
150 pViewShell = dynamic_cast<ScTabViewShell*>( pViewFrm->GetViewShell() );
153 OSL_ENSURE( pViewShell, "missing view shell :-(" );
155 if(pInfo!=nullptr && bScSimpleRefFlag)
157 pInfo->aPos.X()=nScSimpleRefX;
158 pInfo->aPos.Y()=nScSimpleRefY;
159 pInfo->aSize.Height()=nScSimpleRefHeight;
160 pInfo->aSize.Width()=nScSimpleRefWidth;
162 SetWindow(nullptr);
164 if(bAutoReOpen && pViewShell)
165 SetWindow( pViewShell->CreateRefDialog( p, this, pInfo, pParentP, WID_SIMPLE_REF) );
167 if (!GetWindow())
169 SC_MOD()->SetRefDialog( nId, false );
173 void ScSimpleRefDlgWrapper::SetDefaultPosSize(Point aPos, Size aSize)
175 bScSimpleRefFlag=true;
176 nScSimpleRefX=aPos.X();
177 nScSimpleRefY=aPos.Y();
178 nScSimpleRefHeight=aSize.Height();
179 nScSimpleRefWidth=aSize.Width();
182 void ScSimpleRefDlgWrapper::SetAutoReOpen(bool bFlag)
184 bAutoReOpen=bFlag;
187 void ScSimpleRefDlgWrapper::SetRefString(const OUString& rStr)
189 if(GetWindow())
191 static_cast<ScSimpleRefDlg*>(GetWindow())->SetRefString(rStr);
195 void ScSimpleRefDlgWrapper::SetCloseHdl( const Link<const OUString*,void>& rLink )
197 if(GetWindow())
199 static_cast<ScSimpleRefDlg*>(GetWindow())->SetCloseHdl( rLink );
203 void ScSimpleRefDlgWrapper::SetUnoLinks( const Link<const OUString&,void>& rDone,
204 const Link<const OUString&,void>& rAbort, const Link<const OUString&,void>& rChange )
206 if(GetWindow())
208 static_cast<ScSimpleRefDlg*>(GetWindow())->SetUnoLinks( rDone, rAbort, rChange );
212 void ScSimpleRefDlgWrapper::SetFlags( bool bCloseOnButtonUp, bool bSingleCell, bool bMultiSelection )
214 if(GetWindow())
216 static_cast<ScSimpleRefDlg*>(GetWindow())->SetFlags( bCloseOnButtonUp, bSingleCell, bMultiSelection );
220 void ScSimpleRefDlgWrapper::StartRefInput()
222 if(GetWindow())
224 static_cast<ScSimpleRefDlg*>(GetWindow())->StartRefInput();
228 // ScAcceptChgDlgWrapper //FIXME: should be moved into ViewShell
230 ScAcceptChgDlgWrapper::ScAcceptChgDlgWrapper( vcl::Window* pParentP,
231 sal_uInt16 nId,
232 SfxBindings* pBindings,
233 SfxChildWinInfo* pInfo ) :
234 SfxChildWindow( pParentP, nId )
236 ScTabViewShell* pViewShell =
237 dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() );
238 OSL_ENSURE( pViewShell, "missing view shell :-(" );
239 if (pViewShell)
241 SetWindow( VclPtr<ScAcceptChgDlg>::Create( pBindings, this, pParentP, &pViewShell->GetViewData() ) );
242 static_cast<ScAcceptChgDlg*>(GetWindow())->Initialize( pInfo );
244 else
245 SetWindow( nullptr );
246 if (pViewShell && !GetWindow())
247 pViewShell->GetViewFrame()->SetChildWindow( nId, false );
250 void ScAcceptChgDlgWrapper::ReInitDlg()
252 ScTabViewShell* pViewShell =
253 dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() );
254 OSL_ENSURE( pViewShell, "missing view shell :-(" );
256 if(GetWindow() && pViewShell)
258 static_cast<ScAcceptChgDlg*>(GetWindow())->ReInit(&pViewShell->GetViewData());
262 // ScHighlightChgDlgWrapper
264 IMPL_CHILD_CTOR( ScHighlightChgDlgWrapper, FID_CHG_SHOW )
266 namespace
268 ScTabViewShell * lcl_GetTabViewShell( const SfxBindings *pBindings )
270 if( pBindings )
271 if( SfxDispatcher* pDisp = pBindings ->GetDispatcher() )
272 if( SfxViewFrame *pFrm = pDisp->GetFrame() )
273 if( SfxViewShell* pViewSh = pFrm->GetViewShell() )
274 return dynamic_cast<ScTabViewShell*>( pViewSh );
276 return nullptr;
280 ScValidityRefChildWin::ScValidityRefChildWin( vcl::Window* pParentP,
281 sal_uInt16 nId,
282 const SfxBindings* p,
283 SAL_UNUSED_PARAMETER SfxChildWinInfo* /*pInfo*/ )
284 : SfxChildWindow(pParentP, nId),
285 m_bVisibleLock( false ),
286 m_bFreeWindowLock( false ),
287 m_pSavedWndParent( nullptr )
289 SetWantsFocus( false );
290 VclPtr<ScValidationDlg> pDlg = ScValidationDlg::Find1AliveObject( pParentP );
291 SetWindow(pDlg);
292 ScTabViewShell* pViewShell;
293 if (pDlg)
294 pViewShell = static_cast<ScValidationDlg*>(GetWindow())->GetTabViewShell();
295 else
296 pViewShell = lcl_GetTabViewShell( p );
297 if (!pViewShell)
298 pViewShell = dynamic_cast<ScTabViewShell*>( SfxViewShell::Current() );
299 OSL_ENSURE( pViewShell, "missing view shell :-(" );
300 if (pViewShell && !GetWindow())
301 pViewShell->GetViewFrame()->SetChildWindow( nId, false );
303 if( GetWindow() ) m_pSavedWndParent = GetWindow()->GetParent();
306 ScValidityRefChildWin::~ScValidityRefChildWin()
308 if( GetWindow() ) GetWindow()->SetParent( m_pSavedWndParent );
310 if( m_bFreeWindowLock )
311 SetWindow(nullptr);
314 IMPL_CHILD_CTOR( ScCondFormatDlgWrapper, WID_CONDFRMT_REF )
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */