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