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