Line data Source code
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 <vcl/msgbox.hxx>
21 : #include <sfx2/app.hxx>
22 :
23 : #include "reffact.hxx"
24 : #include "document.hxx"
25 : #include "scresid.hxx"
26 : #include "globstr.hrc"
27 : #include "rangenam.hxx"
28 : #include "simpref.hxx"
29 : #include "scmod.hxx"
30 :
31 : #define ABS_SREF SCA_VALID \
32 : | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
33 : #define ABS_DREF ABS_SREF \
34 : | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE
35 : #define ABS_DREF3D ABS_DREF | SCA_TAB_3D
36 :
37 0 : ScSimpleRefDlg::ScSimpleRefDlg(SfxBindings* pB, SfxChildWindow* pCW, vcl::Window* pParent)
38 : : ScAnyRefDlg(pB, pCW, pParent, "SimpleRefDialog", "modules/scalc/ui/simplerefdialog.ui")
39 : ,
40 :
41 : bAutoReOpen ( true ),
42 : bCloseOnButtonUp( false ),
43 : bSingleCell ( false ),
44 0 : bMultiSelection ( false )
45 : {
46 0 : get(m_pFtAssign, "area");
47 0 : get(m_pEdAssign, "assign");
48 0 : m_pEdAssign->SetReferences(this, m_pFtAssign);
49 0 : get(m_pRbAssign, "assignref");
50 0 : m_pRbAssign->SetReferences(this, m_pEdAssign);
51 :
52 0 : get(m_pBtnOk, "ok");
53 0 : get(m_pBtnCancel, "cancel");
54 :
55 : // in order to keep the Strings with the FixedTexts in the resource:
56 0 : Init();
57 0 : SetDispatcherLock( true ); // activate modal mode
58 0 : }
59 :
60 0 : ScSimpleRefDlg::~ScSimpleRefDlg()
61 : {
62 0 : disposeOnce();
63 0 : }
64 :
65 0 : void ScSimpleRefDlg::dispose()
66 : {
67 0 : SetDispatcherLock( false ); // deactivate modal mode
68 0 : m_pFtAssign.clear();
69 0 : m_pEdAssign.clear();
70 0 : m_pRbAssign.clear();
71 0 : m_pBtnOk.clear();
72 0 : m_pBtnCancel.clear();
73 0 : ScAnyRefDlg::dispose();
74 0 : }
75 :
76 0 : void ScSimpleRefDlg::FillInfo(SfxChildWinInfo& rWinInfo) const
77 : {
78 0 : ScAnyRefDlg::FillInfo(rWinInfo);
79 0 : rWinInfo.bVisible=bAutoReOpen;
80 0 : }
81 :
82 0 : void ScSimpleRefDlg::SetRefString(const OUString &rStr)
83 : {
84 0 : m_pEdAssign->SetText(rStr);
85 0 : }
86 :
87 0 : void ScSimpleRefDlg::Init()
88 : {
89 0 : m_pBtnOk->SetClickHdl ( LINK( this, ScSimpleRefDlg, OkBtnHdl ) );
90 0 : m_pBtnCancel->SetClickHdl ( LINK( this, ScSimpleRefDlg, CancelBtnHdl ) );
91 0 : bCloseFlag=false;
92 0 : }
93 :
94 : // Set the reference to a cell range selected with the mouse. This is then
95 : // shown as the new selection in the reference field.
96 0 : void ScSimpleRefDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
97 : {
98 0 : if ( m_pEdAssign->IsEnabled() )
99 : {
100 0 : if ( rRef.aStart != rRef.aEnd )
101 0 : RefInputStart(m_pEdAssign);
102 :
103 0 : theCurArea = rRef;
104 0 : OUString aRefStr;
105 0 : if ( bSingleCell )
106 : {
107 0 : ScAddress aAdr = rRef.aStart;
108 0 : aRefStr = aAdr.Format(SCA_ABS_3D, pDocP, pDocP->GetAddressConvention());
109 : }
110 : else
111 0 : aRefStr = theCurArea.Format(ABS_DREF3D, pDocP, pDocP->GetAddressConvention());
112 :
113 0 : if ( bMultiSelection )
114 : {
115 0 : OUString aVal = m_pEdAssign->GetText();
116 0 : Selection aSel = m_pEdAssign->GetSelection();
117 0 : aSel.Justify();
118 0 : aVal = aVal.replaceAt( aSel.Min(), aSel.Len(), aRefStr );
119 0 : Selection aNewSel( aSel.Min(), aSel.Min()+aRefStr.getLength() );
120 0 : m_pEdAssign->SetRefString( aVal );
121 0 : m_pEdAssign->SetSelection( aNewSel );
122 : }
123 : else
124 0 : m_pEdAssign->SetRefString( aRefStr );
125 :
126 0 : aChangeHdl.Call( &aRefStr );
127 : }
128 0 : }
129 :
130 0 : bool ScSimpleRefDlg::Close()
131 : {
132 0 : CancelBtnHdl(m_pBtnCancel);
133 0 : return true;
134 : }
135 :
136 0 : void ScSimpleRefDlg::SetActive()
137 : {
138 0 : m_pEdAssign->GrabFocus();
139 :
140 : // no NameModifyHdl. Otherwise ranges could not be altered
141 : // (after marking the reference, the old field content would be shown)
142 : // (also, the selected DB name has also not been altered)
143 :
144 0 : RefInputDone();
145 0 : }
146 :
147 0 : bool ScSimpleRefDlg::IsRefInputMode() const
148 : {
149 0 : return true;
150 : }
151 :
152 0 : void ScSimpleRefDlg::SetCloseHdl( const Link<>& rLink )
153 : {
154 0 : aCloseHdl=rLink;
155 0 : }
156 :
157 0 : void ScSimpleRefDlg::SetUnoLinks( const Link<>& rDone, const Link<>& rAbort,
158 : const Link<>& rChange )
159 : {
160 0 : aDoneHdl = rDone;
161 0 : aAbortedHdl = rAbort;
162 0 : aChangeHdl = rChange;
163 0 : }
164 :
165 0 : void ScSimpleRefDlg::SetFlags( bool bSetCloseOnButtonUp, bool bSetSingleCell, bool bSetMultiSelection )
166 : {
167 0 : bCloseOnButtonUp = bSetCloseOnButtonUp;
168 0 : bSingleCell = bSetSingleCell;
169 0 : bMultiSelection = bSetMultiSelection;
170 0 : }
171 :
172 0 : void ScSimpleRefDlg::StartRefInput()
173 : {
174 0 : if ( bMultiSelection )
175 : {
176 : // initially select the whole string, so it gets replaced by default
177 0 : m_pEdAssign->SetSelection( Selection( 0, m_pEdAssign->GetText().getLength() ) );
178 : }
179 :
180 0 : m_pRbAssign->DoRef();
181 0 : bCloseFlag = true;
182 0 : }
183 :
184 0 : void ScSimpleRefDlg::RefInputDone( bool bForced)
185 : {
186 0 : ScAnyRefDlg::RefInputDone(bForced);
187 0 : if ( (bForced || bCloseOnButtonUp) && bCloseFlag )
188 0 : OkBtnHdl(m_pBtnOk);
189 0 : }
190 :
191 : // Handler:
192 :
193 0 : IMPL_LINK_NOARG(ScSimpleRefDlg, OkBtnHdl)
194 : {
195 0 : bAutoReOpen=false;
196 0 : OUString aResult=m_pEdAssign->GetText();
197 0 : aCloseHdl.Call(&aResult);
198 0 : Link<> aUnoLink = aDoneHdl; // stack var because this is deleted in DoClose
199 0 : DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
200 0 : aUnoLink.Call( &aResult );
201 0 : return 0;
202 : }
203 :
204 0 : IMPL_LINK_NOARG(ScSimpleRefDlg, CancelBtnHdl)
205 : {
206 0 : bAutoReOpen=false;
207 0 : OUString aResult=m_pEdAssign->GetText();
208 0 : aCloseHdl.Call(NULL);
209 0 : Link<> aUnoLink = aAbortedHdl; // stack var because this is deleted in DoClose
210 0 : DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
211 0 : aUnoLink.Call( &aResult );
212 0 : return 0;
213 156 : }
214 :
215 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|