1*b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*b3f79822SAndrew Rist * distributed with this work for additional information
6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance
9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at
10*b3f79822SAndrew Rist *
11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*b3f79822SAndrew Rist *
13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*b3f79822SAndrew Rist * software distributed under the License is distributed on an
15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the
17*b3f79822SAndrew Rist * specific language governing permissions and limitations
18*b3f79822SAndrew Rist * under the License.
19*b3f79822SAndrew Rist *
20*b3f79822SAndrew Rist *************************************************************/
21*b3f79822SAndrew Rist
22*b3f79822SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir // System - Includes ---------------------------------------------------------
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30cdf0e10cSrcweir
31cdf0e10cSrcweir // INCLUDE -------------------------------------------------------------------
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include <vcl/msgbox.hxx>
34cdf0e10cSrcweir #include <sfx2/app.hxx>
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include "reffact.hxx"
37cdf0e10cSrcweir #include "document.hxx"
38cdf0e10cSrcweir #include "scresid.hxx"
39cdf0e10cSrcweir #include "globstr.hrc"
40cdf0e10cSrcweir #include "simpref.hrc"
41cdf0e10cSrcweir #include "rangenam.hxx" // IsNameValid
42cdf0e10cSrcweir #include "simpref.hxx"
43cdf0e10cSrcweir #include "scmod.hxx"
44cdf0e10cSrcweir
45cdf0e10cSrcweir //============================================================================
46cdf0e10cSrcweir
47cdf0e10cSrcweir #define ABS_SREF SCA_VALID \
48cdf0e10cSrcweir | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
49cdf0e10cSrcweir #define ABS_DREF ABS_SREF \
50cdf0e10cSrcweir | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE
51cdf0e10cSrcweir #define ABS_SREF3D ABS_SREF | SCA_TAB_3D
52cdf0e10cSrcweir #define ABS_DREF3D ABS_DREF | SCA_TAB_3D
53cdf0e10cSrcweir
54cdf0e10cSrcweir //----------------------------------------------------------------------------
55cdf0e10cSrcweir
56cdf0e10cSrcweir #define ERRORBOX(s) ErrorBox(this,WinBits(WB_OK|WB_DEF_OK),s).Execute()
57cdf0e10cSrcweir #define QUERYBOX(m) QueryBox(this,WinBits(WB_YES_NO|WB_DEF_YES),m).Execute()
58cdf0e10cSrcweir
59cdf0e10cSrcweir //============================================================================
60cdf0e10cSrcweir // class ScSimpleRefDlg
61cdf0e10cSrcweir
62cdf0e10cSrcweir //----------------------------------------------------------------------------
ScSimpleRefDlg(SfxBindings * pB,SfxChildWindow * pCW,Window * pParent,ScViewData * ptrViewData)63cdf0e10cSrcweir ScSimpleRefDlg::ScSimpleRefDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
64cdf0e10cSrcweir ScViewData* ptrViewData )
65cdf0e10cSrcweir
66cdf0e10cSrcweir : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_SIMPLEREF ),
67cdf0e10cSrcweir //
68cdf0e10cSrcweir aFtAssign ( this, ScResId( FT_ASSIGN ) ),
69cdf0e10cSrcweir aEdAssign ( this, this, ScResId( ED_ASSIGN ) ),
70cdf0e10cSrcweir aRbAssign ( this, ScResId( RB_ASSIGN ), &aEdAssign, this ),
71cdf0e10cSrcweir
72cdf0e10cSrcweir aBtnOk ( this, ScResId( BTN_OK ) ),
73cdf0e10cSrcweir aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
74cdf0e10cSrcweir aBtnHelp ( this, ScResId( BTN_HELP ) ),
75cdf0e10cSrcweir
76cdf0e10cSrcweir //
77cdf0e10cSrcweir pViewData ( ptrViewData ),
78cdf0e10cSrcweir pDoc ( ptrViewData->GetDocument() ),
79cdf0e10cSrcweir bRefInputMode ( sal_False ),
80cdf0e10cSrcweir bAutoReOpen ( sal_True ),
81cdf0e10cSrcweir bCloseOnButtonUp( sal_False ),
82cdf0e10cSrcweir bSingleCell ( sal_False ),
83cdf0e10cSrcweir bMultiSelection ( sal_False )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir // damit die Strings in der Resource bei den FixedTexten bleiben koennen:
86cdf0e10cSrcweir Init();
87cdf0e10cSrcweir FreeResource();
88cdf0e10cSrcweir SetDispatcherLock( sal_True ); // Modal-Modus einschalten
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
91cdf0e10cSrcweir //----------------------------------------------------------------------------
~ScSimpleRefDlg()92cdf0e10cSrcweir __EXPORT ScSimpleRefDlg::~ScSimpleRefDlg()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir SetDispatcherLock( sal_False ); // Modal-Modus einschalten
95cdf0e10cSrcweir }
96cdf0e10cSrcweir
97cdf0e10cSrcweir //----------------------------------------------------------------------------
FillInfo(SfxChildWinInfo & rWinInfo) const98cdf0e10cSrcweir void ScSimpleRefDlg::FillInfo(SfxChildWinInfo& rWinInfo) const
99cdf0e10cSrcweir {
100cdf0e10cSrcweir ScAnyRefDlg::FillInfo(rWinInfo);
101cdf0e10cSrcweir rWinInfo.bVisible=bAutoReOpen;
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
104cdf0e10cSrcweir //----------------------------------------------------------------------------
SetRefString(const String & rStr)105cdf0e10cSrcweir void ScSimpleRefDlg::SetRefString(const String &rStr)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir aEdAssign.SetText(rStr);
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir //----------------------------------------------------------------------------
Init()111cdf0e10cSrcweir void ScSimpleRefDlg::Init()
112cdf0e10cSrcweir {
113cdf0e10cSrcweir aBtnOk.SetClickHdl ( LINK( this, ScSimpleRefDlg, OkBtnHdl ) );
114cdf0e10cSrcweir aBtnCancel.SetClickHdl ( LINK( this, ScSimpleRefDlg, CancelBtnHdl ) );
115cdf0e10cSrcweir bCloseFlag=sal_False;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
118cdf0e10cSrcweir //----------------------------------------------------------------------------
119cdf0e10cSrcweir // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
120cdf0e10cSrcweir // neue Selektion im Referenz-Fenster angezeigt wird.
SetReference(const ScRange & rRef,ScDocument * pDocP)121cdf0e10cSrcweir void ScSimpleRefDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
122cdf0e10cSrcweir {
123cdf0e10cSrcweir if ( aEdAssign.IsEnabled() )
124cdf0e10cSrcweir {
125cdf0e10cSrcweir if ( rRef.aStart != rRef.aEnd )
126cdf0e10cSrcweir RefInputStart( &aEdAssign );
127cdf0e10cSrcweir
128cdf0e10cSrcweir theCurArea = rRef;
129cdf0e10cSrcweir String aRefStr;
130cdf0e10cSrcweir if ( bSingleCell )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir ScAddress aAdr = rRef.aStart;
133cdf0e10cSrcweir aAdr.Format( aRefStr, SCA_ABS_3D, pDocP, pDocP->GetAddressConvention() );
134cdf0e10cSrcweir }
135cdf0e10cSrcweir else
136cdf0e10cSrcweir theCurArea.Format( aRefStr, ABS_DREF3D, pDocP, pDocP->GetAddressConvention() );
137cdf0e10cSrcweir
138cdf0e10cSrcweir if ( bMultiSelection )
139cdf0e10cSrcweir {
140cdf0e10cSrcweir String aVal = aEdAssign.GetText();
141cdf0e10cSrcweir Selection aSel = aEdAssign.GetSelection();
142cdf0e10cSrcweir aSel.Justify();
143cdf0e10cSrcweir aVal.Erase( (xub_StrLen)aSel.Min(), (xub_StrLen)aSel.Len() );
144cdf0e10cSrcweir aVal.Insert( aRefStr, (xub_StrLen)aSel.Min() );
145cdf0e10cSrcweir Selection aNewSel( aSel.Min(), aSel.Min()+aRefStr.Len() );
146cdf0e10cSrcweir aEdAssign.SetRefString( aVal );
147cdf0e10cSrcweir aEdAssign.SetSelection( aNewSel );
148cdf0e10cSrcweir }
149cdf0e10cSrcweir else
150cdf0e10cSrcweir aEdAssign.SetRefString( aRefStr );
151cdf0e10cSrcweir
152cdf0e10cSrcweir aChangeHdl.Call( &aRefStr );
153cdf0e10cSrcweir }
154cdf0e10cSrcweir }
155cdf0e10cSrcweir
156cdf0e10cSrcweir
157cdf0e10cSrcweir //----------------------------------------------------------------------------
Close()158cdf0e10cSrcweir sal_Bool __EXPORT ScSimpleRefDlg::Close()
159cdf0e10cSrcweir {
160cdf0e10cSrcweir CancelBtnHdl(&aBtnCancel);
161cdf0e10cSrcweir return sal_True;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
164cdf0e10cSrcweir //------------------------------------------------------------------------
SetActive()165cdf0e10cSrcweir void ScSimpleRefDlg::SetActive()
166cdf0e10cSrcweir {
167cdf0e10cSrcweir aEdAssign.GrabFocus();
168cdf0e10cSrcweir
169cdf0e10cSrcweir // kein NameModifyHdl, weil sonst Bereiche nicht geaendert werden koennen
170cdf0e10cSrcweir // (nach dem Aufziehen der Referenz wuerde der alte Inhalt wieder angezeigt)
171cdf0e10cSrcweir // (der ausgewaehlte DB-Name hat sich auch nicht veraendert)
172cdf0e10cSrcweir
173cdf0e10cSrcweir RefInputDone();
174cdf0e10cSrcweir }
175cdf0e10cSrcweir //------------------------------------------------------------------------
IsRefInputMode() const176cdf0e10cSrcweir sal_Bool ScSimpleRefDlg::IsRefInputMode() const
177cdf0e10cSrcweir {
178cdf0e10cSrcweir return sal_True;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir
GetRefString() const181cdf0e10cSrcweir String ScSimpleRefDlg::GetRefString() const
182cdf0e10cSrcweir {
183cdf0e10cSrcweir return aEdAssign.GetText();
184cdf0e10cSrcweir }
185cdf0e10cSrcweir
SetCloseHdl(const Link & rLink)186cdf0e10cSrcweir void ScSimpleRefDlg::SetCloseHdl( const Link& rLink )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir aCloseHdl=rLink;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir
SetUnoLinks(const Link & rDone,const Link & rAbort,const Link & rChange)191cdf0e10cSrcweir void ScSimpleRefDlg::SetUnoLinks( const Link& rDone, const Link& rAbort,
192cdf0e10cSrcweir const Link& rChange )
193cdf0e10cSrcweir {
194cdf0e10cSrcweir aDoneHdl = rDone;
195cdf0e10cSrcweir aAbortedHdl = rAbort;
196cdf0e10cSrcweir aChangeHdl = rChange;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir
SetFlags(sal_Bool bSetCloseOnButtonUp,sal_Bool bSetSingleCell,sal_Bool bSetMultiSelection)199cdf0e10cSrcweir void ScSimpleRefDlg::SetFlags( sal_Bool bSetCloseOnButtonUp, sal_Bool bSetSingleCell, sal_Bool bSetMultiSelection )
200cdf0e10cSrcweir {
201cdf0e10cSrcweir bCloseOnButtonUp = bSetCloseOnButtonUp;
202cdf0e10cSrcweir bSingleCell = bSetSingleCell;
203cdf0e10cSrcweir bMultiSelection = bSetMultiSelection;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir
StartRefInput()206cdf0e10cSrcweir void ScSimpleRefDlg::StartRefInput()
207cdf0e10cSrcweir {
208cdf0e10cSrcweir if ( bMultiSelection )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir // initially select the whole string, so it gets replaced by default
211cdf0e10cSrcweir aEdAssign.SetSelection( Selection( 0, aEdAssign.GetText().Len() ) );
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
214cdf0e10cSrcweir aRbAssign.DoRef();
215cdf0e10cSrcweir bCloseFlag=sal_True;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
RefInputDone(sal_Bool bForced)218cdf0e10cSrcweir void ScSimpleRefDlg::RefInputDone( sal_Bool bForced)
219cdf0e10cSrcweir {
220cdf0e10cSrcweir ScAnyRefDlg::RefInputDone(bForced);
221cdf0e10cSrcweir if ( (bForced || bCloseOnButtonUp) && bCloseFlag )
222cdf0e10cSrcweir OkBtnHdl(&aBtnOk);
223cdf0e10cSrcweir }
224cdf0e10cSrcweir //------------------------------------------------------------------------
225cdf0e10cSrcweir // Handler:
226cdf0e10cSrcweir // ========
IMPL_LINK(ScSimpleRefDlg,OkBtnHdl,void *,EMPTYARG)227cdf0e10cSrcweir IMPL_LINK( ScSimpleRefDlg, OkBtnHdl, void *, EMPTYARG )
228cdf0e10cSrcweir {
229cdf0e10cSrcweir bAutoReOpen=sal_False;
230cdf0e10cSrcweir String aResult=aEdAssign.GetText();
231cdf0e10cSrcweir aCloseHdl.Call(&aResult);
232cdf0e10cSrcweir Link aUnoLink = aDoneHdl; // stack var because this is deleted in DoClose
233cdf0e10cSrcweir DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
234cdf0e10cSrcweir aUnoLink.Call( &aResult );
235cdf0e10cSrcweir return 0;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir
238cdf0e10cSrcweir //------------------------------------------------------------------------
IMPL_LINK(ScSimpleRefDlg,CancelBtnHdl,void *,EMPTYARG)239cdf0e10cSrcweir IMPL_LINK( ScSimpleRefDlg, CancelBtnHdl, void *, EMPTYARG )
240cdf0e10cSrcweir {
241cdf0e10cSrcweir bAutoReOpen=sal_False;
242cdf0e10cSrcweir String aResult=aEdAssign.GetText();
243cdf0e10cSrcweir aCloseHdl.Call(NULL);
244cdf0e10cSrcweir Link aUnoLink = aAbortedHdl; // stack var because this is deleted in DoClose
245cdf0e10cSrcweir DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
246cdf0e10cSrcweir aUnoLink.Call( &aResult );
247cdf0e10cSrcweir return 0;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir
250cdf0e10cSrcweir
251cdf0e10cSrcweir
252cdf0e10cSrcweir //------------------------------------------------------------------------
253cdf0e10cSrcweir
254