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 <vcl/msgbox.hxx>
21 #include <sfx2/app.hxx>
23 #include "reffact.hxx"
24 #include "document.hxx"
25 #include "scresid.hxx"
26 #include "globstr.hrc"
27 #include "rangenam.hxx"
28 #include "simpref.hxx"
31 ScSimpleRefDlg::ScSimpleRefDlg(SfxBindings
* pB
, SfxChildWindow
* pCW
, vcl::Window
* pParent
)
32 : ScAnyRefDlg(pB
, pCW
, pParent
, "SimpleRefDialog", "modules/scalc/ui/simplerefdialog.ui")
36 bCloseOnButtonUp( false ),
37 bSingleCell ( false ),
38 bMultiSelection ( false )
40 get(m_pFtAssign
, "area");
41 get(m_pEdAssign
, "assign");
42 m_pEdAssign
->SetReferences(this, m_pFtAssign
);
43 get(m_pRbAssign
, "assignref");
44 m_pRbAssign
->SetReferences(this, m_pEdAssign
);
47 get(m_pBtnCancel
, "cancel");
49 // in order to keep the Strings with the FixedTexts in the resource:
51 SetDispatcherLock( true ); // activate modal mode
54 ScSimpleRefDlg::~ScSimpleRefDlg()
59 void ScSimpleRefDlg::dispose()
61 SetDispatcherLock( false ); // deactivate modal mode
67 ScAnyRefDlg::dispose();
70 void ScSimpleRefDlg::FillInfo(SfxChildWinInfo
& rWinInfo
) const
72 ScAnyRefDlg::FillInfo(rWinInfo
);
73 rWinInfo
.bVisible
=bAutoReOpen
;
76 void ScSimpleRefDlg::SetRefString(const OUString
&rStr
)
78 m_pEdAssign
->SetText(rStr
);
81 void ScSimpleRefDlg::Init()
83 m_pBtnOk
->SetClickHdl ( LINK( this, ScSimpleRefDlg
, OkBtnHdl
) );
84 m_pBtnCancel
->SetClickHdl ( LINK( this, ScSimpleRefDlg
, CancelBtnHdl
) );
88 // Set the reference to a cell range selected with the mouse. This is then
89 // shown as the new selection in the reference field.
90 void ScSimpleRefDlg::SetReference( const ScRange
& rRef
, ScDocument
* pDocP
)
92 if ( m_pEdAssign
->IsEnabled() )
94 if ( rRef
.aStart
!= rRef
.aEnd
)
95 RefInputStart(m_pEdAssign
);
101 ScAddress aAdr
= rRef
.aStart
;
102 aRefStr
= aAdr
.Format(ScRefFlags::ADDR_ABS_3D
, pDocP
, pDocP
->GetAddressConvention());
105 aRefStr
= theCurArea
.Format(ScRefFlags::RANGE_ABS_3D
, pDocP
, pDocP
->GetAddressConvention());
107 if ( bMultiSelection
)
109 OUString aVal
= m_pEdAssign
->GetText();
110 Selection aSel
= m_pEdAssign
->GetSelection();
112 aVal
= aVal
.replaceAt( aSel
.Min(), aSel
.Len(), aRefStr
);
113 Selection
aNewSel( aSel
.Min(), aSel
.Min()+aRefStr
.getLength() );
114 m_pEdAssign
->SetRefString( aVal
);
115 m_pEdAssign
->SetSelection( aNewSel
);
118 m_pEdAssign
->SetRefString( aRefStr
);
120 aChangeHdl
.Call( aRefStr
);
124 bool ScSimpleRefDlg::Close()
126 CancelBtnHdl(m_pBtnCancel
);
130 void ScSimpleRefDlg::SetActive()
132 m_pEdAssign
->GrabFocus();
134 // no NameModifyHdl. Otherwise ranges could not be altered
135 // (after marking the reference, the old field content would be shown)
136 // (also, the selected DB name has also not been altered)
141 bool ScSimpleRefDlg::IsRefInputMode() const
146 void ScSimpleRefDlg::SetCloseHdl( const Link
<const OUString
*,void>& rLink
)
151 void ScSimpleRefDlg::SetUnoLinks( const Link
<const OUString
&,void>& rDone
,
152 const Link
<const OUString
&,void>& rAbort
,
153 const Link
<const OUString
&,void>& rChange
)
156 aAbortedHdl
= rAbort
;
157 aChangeHdl
= rChange
;
160 void ScSimpleRefDlg::SetFlags( bool bSetCloseOnButtonUp
, bool bSetSingleCell
, bool bSetMultiSelection
)
162 bCloseOnButtonUp
= bSetCloseOnButtonUp
;
163 bSingleCell
= bSetSingleCell
;
164 bMultiSelection
= bSetMultiSelection
;
167 void ScSimpleRefDlg::StartRefInput()
169 if ( bMultiSelection
)
171 // initially select the whole string, so it gets replaced by default
172 m_pEdAssign
->SetSelection( Selection( 0, m_pEdAssign
->GetText().getLength() ) );
175 m_pRbAssign
->DoRef();
179 void ScSimpleRefDlg::RefInputDone( bool bForced
)
181 ScAnyRefDlg::RefInputDone(bForced
);
182 if ( (bForced
|| bCloseOnButtonUp
) && bCloseFlag
)
188 IMPL_LINK_NOARG_TYPED(ScSimpleRefDlg
, OkBtnHdl
, Button
*, void)
191 OUString aResult
=m_pEdAssign
->GetText();
192 aCloseHdl
.Call(&aResult
);
193 Link
<const OUString
&,void> aUnoLink
= aDoneHdl
; // stack var because this is deleted in DoClose
194 DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
195 aUnoLink
.Call( aResult
);
198 IMPL_LINK_NOARG_TYPED(ScSimpleRefDlg
, CancelBtnHdl
, Button
*, void)
201 OUString aResult
=m_pEdAssign
->GetText();
202 aCloseHdl
.Call(nullptr);
203 Link
<const OUString
&,void> aUnoLink
= aAbortedHdl
; // stack var because this is deleted in DoClose
204 DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
205 aUnoLink
.Call( aResult
);
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */