LibreOffice Module sc (master) 1
simpref.cxx
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#include <reffact.hxx>
21#include <document.hxx>
22#include <simpref.hxx>
23
25 : ScAnyRefDlgController(pB, pCW, pParent, "modules/scalc/ui/simplerefdialog.ui", "SimpleRefDialog")
26 , bAutoReOpen(true)
27 , bCloseOnButtonUp(false)
28 , bSingleCell(false)
29 , bMultiSelection(false)
30 , m_xFtAssign(m_xBuilder->weld_label("area"))
31 , m_xEdAssign(new formula::RefEdit(m_xBuilder->weld_entry("assign")))
32 , m_xRbAssign(new formula::RefButton(m_xBuilder->weld_button("assignref")))
33 , m_xBtnOk(m_xBuilder->weld_button("ok"))
34 , m_xBtnCancel(m_xBuilder->weld_button("cancel"))
35{
36 m_xEdAssign->SetReferences(this, m_xFtAssign.get());
37 m_xRbAssign->SetReferences(this, m_xEdAssign.get());
38
39 // in order to keep the Strings with the FixedTexts in the resource:
40 Init();
41 SetDispatcherLock( true ); // activate modal mode
42}
43
45{
46 SetDispatcherLock( false ); // deactivate modal mode
47}
48
50{
52 rWinInfo.bVisible = bAutoReOpen;
53}
54
55void ScSimpleRefDlg::SetRefString(const OUString &rStr)
56{
57 m_xEdAssign->SetText(rStr);
58}
59
61{
62 m_xBtnOk->connect_clicked( LINK( this, ScSimpleRefDlg, OkBtnHdl ) );
63 m_xBtnCancel->connect_clicked( LINK( this, ScSimpleRefDlg, CancelBtnHdl ) );
64 bCloseFlag=false;
65}
66
67// Set the reference to a cell range selected with the mouse. This is then
68// shown as the new selection in the reference field.
70{
71 if (!m_xEdAssign->GetWidget()->get_sensitive())
72 return;
73
74 if ( rRef.aStart != rRef.aEnd )
76
77 theCurArea = rRef;
78 OUString aRefStr;
79 if ( bSingleCell )
80 {
81 ScAddress aAdr = rRef.aStart;
82 aRefStr = aAdr.Format(ScRefFlags::ADDR_ABS_3D, &rDocP, rDocP.GetAddressConvention());
83 }
84 else
86
87 if ( bMultiSelection )
88 {
89 OUString aVal = m_xEdAssign->GetText();
90 Selection aSel = m_xEdAssign->GetSelection();
91 aSel.Normalize();
92 aVal = aVal.replaceAt( aSel.Min(), aSel.Len(), aRefStr );
93 Selection aNewSel( aSel.Min(), aSel.Min()+aRefStr.getLength() );
94 m_xEdAssign->SetRefString( aVal );
95 m_xEdAssign->SetSelection( aNewSel );
96 }
97 else
98 m_xEdAssign->SetRefString( aRefStr );
99
100 aChangeHdl.Call( aRefStr );
101}
102
104{
105 CancelBtnHdl(*m_xBtnCancel);
106}
107
109{
110 m_xEdAssign->GrabFocus();
111
112 // no NameModifyHdl. Otherwise ranges could not be altered
113 // (after marking the reference, the old field content would be shown)
114 // (also, the selected DB name has also not been altered)
115
116 RefInputDone();
117}
118
120{
121 return true;
122}
123
125{
126 aCloseHdl=rLink;
127}
128
130 const Link<const OUString&,void>& rAbort,
131 const Link<const OUString&,void>& rChange )
132{
133 aDoneHdl = rDone;
134 aAbortedHdl = rAbort;
135 aChangeHdl = rChange;
136}
137
138void ScSimpleRefDlg::SetFlags( bool bSetCloseOnButtonUp, bool bSetSingleCell, bool bSetMultiSelection )
139{
140 bCloseOnButtonUp = bSetCloseOnButtonUp;
141 bSingleCell = bSetSingleCell;
142 bMultiSelection = bSetMultiSelection;
143}
144
146{
147 if ( bMultiSelection )
148 {
149 // initially select the whole string, so it gets replaced by default
150 m_xEdAssign->SelectAll();
151 }
152
153 m_xRbAssign->DoRef();
154 bCloseFlag = true;
155}
156
158{
160 if ( (bForced || bCloseOnButtonUp) && bCloseFlag )
161 OkBtnHdl(*m_xBtnOk);
162}
163
164// Handler:
165
167{
168 if (IsClosing())
169 return;
170 bAutoReOpen = false;
171 OUString aResult=m_xEdAssign->GetText();
172 aCloseHdl.Call(&aResult);
173 Link<const OUString&,void> aUnoLink = aDoneHdl; // stack var because this is deleted in DoClose
174 DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
175 aUnoLink.Call( aResult );
176}
177
179{
180 if (IsClosing())
181 return;
182 bAutoReOpen = false;
183 OUString aResult=m_xEdAssign->GetText();
184 aCloseHdl.Call(nullptr);
185 Link<const OUString&,void> aUnoLink = aAbortedHdl; // stack var because this is deleted in DoClose
186 DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
187 aUnoLink.Call( aResult );
188}
189
190/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
Definition: address.cxx:2074
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:500
OUString Format(const ScDocument &rDocument, ScRefFlags nFlags=ScRefFlags::ZERO, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, bool bFullAddressNotation=false) const
Returns string with formatted cell range from aStart to aEnd, according to provided address conventio...
Definition: address.cxx:2170
ScAddress aEnd
Definition: address.hxx:498
ScAddress aStart
Definition: address.hxx:497
virtual void RefInputStart(formula::RefEdit *pEdit, formula::RefButton *pButton=nullptr) override
Definition: anyrefdg.cxx:749
virtual void RefInputDone(bool bForced=false) override
Definition: anyrefdg.cxx:779
void SetDispatcherLock(bool bLock)
Definition: anyrefdg.cxx:724
std::unique_ptr< weld::Label > m_xFtAssign
Definition: simpref.hxx:41
std::unique_ptr< weld::Button > m_xBtnCancel
Definition: simpref.hxx:45
void Init()
Definition: simpref.cxx:60
Link< const OUString &, void > aChangeHdl
Definition: simpref.hxx:32
ScRange theCurArea
Definition: simpref.hxx:34
std::unique_ptr< weld::Button > m_xBtnOk
Definition: simpref.hxx:44
std::unique_ptr< formula::RefButton > m_xRbAssign
Definition: simpref.hxx:43
virtual bool IsRefInputMode() const override
Definition: simpref.cxx:119
void SetFlags(bool bSetCloseOnButtonUp, bool bSetSingleCell, bool bSetMultiSelection)
Definition: simpref.cxx:138
Link< const OUString *, void > aCloseHdl
Definition: simpref.hxx:29
void SetCloseHdl(const Link< const OUString *, void > &rLink)
Definition: simpref.cxx:124
bool bAutoReOpen
Definition: simpref.hxx:36
ScSimpleRefDlg(SfxBindings *pB, SfxChildWindow *pCW, weld::Window *pParent)
Definition: simpref.cxx:24
bool bCloseFlag
Definition: simpref.hxx:35
void SetUnoLinks(const Link< const OUString &, void > &rDone, const Link< const OUString &, void > &rAbort, const Link< const OUString &, void > &rChange)
Definition: simpref.cxx:129
void StartRefInput()
Definition: simpref.cxx:145
bool bMultiSelection
Definition: simpref.hxx:39
Link< const OUString &, void > aDoneHdl
Definition: simpref.hxx:30
bool bSingleCell
Definition: simpref.hxx:38
virtual void RefInputDone(bool bForced=false) override
Definition: simpref.cxx:157
std::unique_ptr< formula::RefEdit > m_xEdAssign
Definition: simpref.hxx:42
void SetRefString(const OUString &rStr)
Definition: simpref.cxx:55
virtual void SetReference(const ScRange &rRef, ScDocument &rDoc) override
Definition: simpref.cxx:69
bool bCloseOnButtonUp
Definition: simpref.hxx:37
Link< const OUString &, void > aAbortedHdl
Definition: simpref.hxx:31
virtual ~ScSimpleRefDlg() override
Definition: simpref.cxx:44
virtual void Close() override
Definition: simpref.cxx:103
virtual void SetActive() override
Definition: simpref.cxx:108
virtual void FillInfo(SfxChildWinInfo &) const override
Definition: simpref.cxx:49
tools::Long Min() const
tools::Long Len() const
void Normalize()
virtual void FillInfo(SfxChildWinInfo &) const
static bool bAutoReOpen
Definition: reffact.cxx:125
IMPL_LINK_NOARG(ScSimpleRefDlg, OkBtnHdl, weld::Button &, void)
Definition: simpref.cxx:166