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 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 : SetDispatcherLock( false ); // deactivate modal mode
63 0 : }
64 :
65 0 : void ScSimpleRefDlg::FillInfo(SfxChildWinInfo& rWinInfo) const
66 : {
67 0 : ScAnyRefDlg::FillInfo(rWinInfo);
68 0 : rWinInfo.bVisible=bAutoReOpen;
69 0 : }
70 :
71 0 : void ScSimpleRefDlg::SetRefString(const OUString &rStr)
72 : {
73 0 : m_pEdAssign->SetText(rStr);
74 0 : }
75 :
76 0 : void ScSimpleRefDlg::Init()
77 : {
78 0 : m_pBtnOk->SetClickHdl ( LINK( this, ScSimpleRefDlg, OkBtnHdl ) );
79 0 : m_pBtnCancel->SetClickHdl ( LINK( this, ScSimpleRefDlg, CancelBtnHdl ) );
80 0 : bCloseFlag=false;
81 0 : }
82 :
83 : // Set the reference to a cell range selected with the mouse. This is then
84 : // shown as the new selection in the reference field.
85 0 : void ScSimpleRefDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
86 : {
87 0 : if ( m_pEdAssign->IsEnabled() )
88 : {
89 0 : if ( rRef.aStart != rRef.aEnd )
90 0 : RefInputStart(m_pEdAssign);
91 :
92 0 : theCurArea = rRef;
93 0 : OUString aRefStr;
94 0 : if ( bSingleCell )
95 : {
96 0 : ScAddress aAdr = rRef.aStart;
97 0 : aRefStr = aAdr.Format(SCA_ABS_3D, pDocP, pDocP->GetAddressConvention());
98 : }
99 : else
100 0 : aRefStr = theCurArea.Format(ABS_DREF3D, pDocP, pDocP->GetAddressConvention());
101 :
102 0 : if ( bMultiSelection )
103 : {
104 0 : OUString aVal = m_pEdAssign->GetText();
105 0 : Selection aSel = m_pEdAssign->GetSelection();
106 0 : aSel.Justify();
107 0 : aVal = aVal.replaceAt( aSel.Min(), aSel.Len(), aRefStr );
108 0 : Selection aNewSel( aSel.Min(), aSel.Min()+aRefStr.getLength() );
109 0 : m_pEdAssign->SetRefString( aVal );
110 0 : m_pEdAssign->SetSelection( aNewSel );
111 : }
112 : else
113 0 : m_pEdAssign->SetRefString( aRefStr );
114 :
115 0 : aChangeHdl.Call( &aRefStr );
116 : }
117 0 : }
118 :
119 0 : bool ScSimpleRefDlg::Close()
120 : {
121 0 : CancelBtnHdl(m_pBtnCancel);
122 0 : return true;
123 : }
124 :
125 0 : void ScSimpleRefDlg::SetActive()
126 : {
127 0 : m_pEdAssign->GrabFocus();
128 :
129 : // no NameModifyHdl. Otherwise ranges could not be altered
130 : // (after marking the reference, the old field content would be shown)
131 : // (also, the selected DB name has also not been altered)
132 :
133 0 : RefInputDone();
134 0 : }
135 :
136 0 : bool ScSimpleRefDlg::IsRefInputMode() const
137 : {
138 0 : return true;
139 : }
140 :
141 0 : void ScSimpleRefDlg::SetCloseHdl( const Link& rLink )
142 : {
143 0 : aCloseHdl=rLink;
144 0 : }
145 :
146 0 : void ScSimpleRefDlg::SetUnoLinks( const Link& rDone, const Link& rAbort,
147 : const Link& rChange )
148 : {
149 0 : aDoneHdl = rDone;
150 0 : aAbortedHdl = rAbort;
151 0 : aChangeHdl = rChange;
152 0 : }
153 :
154 0 : void ScSimpleRefDlg::SetFlags( bool bSetCloseOnButtonUp, bool bSetSingleCell, bool bSetMultiSelection )
155 : {
156 0 : bCloseOnButtonUp = bSetCloseOnButtonUp;
157 0 : bSingleCell = bSetSingleCell;
158 0 : bMultiSelection = bSetMultiSelection;
159 0 : }
160 :
161 0 : void ScSimpleRefDlg::StartRefInput()
162 : {
163 0 : if ( bMultiSelection )
164 : {
165 : // initially select the whole string, so it gets replaced by default
166 0 : m_pEdAssign->SetSelection( Selection( 0, m_pEdAssign->GetText().getLength() ) );
167 : }
168 :
169 0 : m_pRbAssign->DoRef();
170 0 : bCloseFlag = true;
171 0 : }
172 :
173 0 : void ScSimpleRefDlg::RefInputDone( bool bForced)
174 : {
175 0 : ScAnyRefDlg::RefInputDone(bForced);
176 0 : if ( (bForced || bCloseOnButtonUp) && bCloseFlag )
177 0 : OkBtnHdl(m_pBtnOk);
178 0 : }
179 :
180 : // Handler:
181 :
182 0 : IMPL_LINK_NOARG(ScSimpleRefDlg, OkBtnHdl)
183 : {
184 0 : bAutoReOpen=false;
185 0 : OUString aResult=m_pEdAssign->GetText();
186 0 : aCloseHdl.Call(&aResult);
187 0 : Link aUnoLink = aDoneHdl; // stack var because this is deleted in DoClose
188 0 : DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
189 0 : aUnoLink.Call( &aResult );
190 0 : return 0;
191 : }
192 :
193 0 : IMPL_LINK_NOARG(ScSimpleRefDlg, CancelBtnHdl)
194 : {
195 0 : bAutoReOpen=false;
196 0 : OUString aResult=m_pEdAssign->GetText();
197 0 : aCloseHdl.Call(NULL);
198 0 : Link aUnoLink = aAbortedHdl; // stack var because this is deleted in DoClose
199 0 : DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
200 0 : aUnoLink.Call( &aResult );
201 0 : return 0;
202 228 : }
203 :
204 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|