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