bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / miscdlgs / simpref.cxx
blob7afa37cd1b45a2e4f6ef22208f9302a538434866
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/msgbox.hxx>
21 #include <sfx2/app.hxx>
23 #include "reffact.hxx"
24 #include "document.hxx"
25 #include "scresid.hxx"
26 #include "globstr.hrc"
27 #include "simpref.hrc"
28 #include "rangenam.hxx" // IsNameValid
29 #include "simpref.hxx"
30 #include "scmod.hxx"
32 //============================================================================
34 #define ABS_SREF SCA_VALID \
35 | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
36 #define ABS_DREF ABS_SREF \
37 | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE
38 #define ABS_DREF3D ABS_DREF | SCA_TAB_3D
40 //============================================================================
41 // class ScSimpleRefDlg
43 //----------------------------------------------------------------------------
44 ScSimpleRefDlg::ScSimpleRefDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
45 ScViewData* ptrViewData )
47 : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_SIMPLEREF ),
49 aFtAssign ( this, ScResId( FT_ASSIGN ) ),
50 aEdAssign ( this, this, &aFtAssign, ScResId( ED_ASSIGN ) ),
51 aRbAssign ( this, ScResId( RB_ASSIGN ), &aEdAssign, this ),
53 aBtnOk ( this, ScResId( BTN_OK ) ),
54 aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
55 aBtnHelp ( this, ScResId( BTN_HELP ) ),
58 pDoc ( ptrViewData->GetDocument() ),
59 bAutoReOpen ( sal_True ),
60 bCloseOnButtonUp( false ),
61 bSingleCell ( false ),
62 bMultiSelection ( false )
64 // damit die Strings in der Resource bei den FixedTexten bleiben koennen:
65 Init();
66 FreeResource();
67 SetDispatcherLock( sal_True ); // Modal-Modus einschalten
70 //----------------------------------------------------------------------------
71 ScSimpleRefDlg::~ScSimpleRefDlg()
73 SetDispatcherLock( false ); // Modal-Modus einschalten
76 //----------------------------------------------------------------------------
77 void ScSimpleRefDlg::FillInfo(SfxChildWinInfo& rWinInfo) const
79 ScAnyRefDlg::FillInfo(rWinInfo);
80 rWinInfo.bVisible=bAutoReOpen;
83 //----------------------------------------------------------------------------
84 void ScSimpleRefDlg::SetRefString(const String &rStr)
86 aEdAssign.SetText(rStr);
89 //----------------------------------------------------------------------------
90 void ScSimpleRefDlg::Init()
92 aBtnOk.SetClickHdl ( LINK( this, ScSimpleRefDlg, OkBtnHdl ) );
93 aBtnCancel.SetClickHdl ( LINK( this, ScSimpleRefDlg, CancelBtnHdl ) );
94 bCloseFlag=false;
97 //----------------------------------------------------------------------------
98 // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
99 // neue Selektion im Referenz-Fenster angezeigt wird.
100 void ScSimpleRefDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
102 if ( aEdAssign.IsEnabled() )
104 if ( rRef.aStart != rRef.aEnd )
105 RefInputStart( &aEdAssign );
107 theCurArea = rRef;
108 String aRefStr;
109 if ( bSingleCell )
111 ScAddress aAdr = rRef.aStart;
112 aAdr.Format( aRefStr, SCA_ABS_3D, pDocP, pDocP->GetAddressConvention() );
114 else
115 theCurArea.Format( aRefStr, ABS_DREF3D, pDocP, pDocP->GetAddressConvention() );
117 if ( bMultiSelection )
119 String aVal = aEdAssign.GetText();
120 Selection aSel = aEdAssign.GetSelection();
121 aSel.Justify();
122 aVal.Erase( (xub_StrLen)aSel.Min(), (xub_StrLen)aSel.Len() );
123 aVal.Insert( aRefStr, (xub_StrLen)aSel.Min() );
124 Selection aNewSel( aSel.Min(), aSel.Min()+aRefStr.Len() );
125 aEdAssign.SetRefString( aVal );
126 aEdAssign.SetSelection( aNewSel );
128 else
129 aEdAssign.SetRefString( aRefStr );
131 aChangeHdl.Call( &aRefStr );
136 //----------------------------------------------------------------------------
137 sal_Bool ScSimpleRefDlg::Close()
139 CancelBtnHdl(&aBtnCancel);
140 return sal_True;
143 //------------------------------------------------------------------------
144 void ScSimpleRefDlg::SetActive()
146 aEdAssign.GrabFocus();
148 // kein NameModifyHdl, weil sonst Bereiche nicht geaendert werden koennen
149 // (nach dem Aufziehen der Referenz wuerde der alte Inhalt wieder angezeigt)
150 // (der ausgewaehlte DB-Name hat sich auch nicht veraendert)
152 RefInputDone();
154 //------------------------------------------------------------------------
155 sal_Bool ScSimpleRefDlg::IsRefInputMode() const
157 return sal_True;
160 String ScSimpleRefDlg::GetRefString() const
162 return aEdAssign.GetText();
165 void ScSimpleRefDlg::SetCloseHdl( const Link& rLink )
167 aCloseHdl=rLink;
170 void ScSimpleRefDlg::SetUnoLinks( const Link& rDone, const Link& rAbort,
171 const Link& rChange )
173 aDoneHdl = rDone;
174 aAbortedHdl = rAbort;
175 aChangeHdl = rChange;
178 void ScSimpleRefDlg::SetFlags( sal_Bool bSetCloseOnButtonUp, sal_Bool bSetSingleCell, sal_Bool bSetMultiSelection )
180 bCloseOnButtonUp = bSetCloseOnButtonUp;
181 bSingleCell = bSetSingleCell;
182 bMultiSelection = bSetMultiSelection;
185 void ScSimpleRefDlg::StartRefInput()
187 if ( bMultiSelection )
189 // initially select the whole string, so it gets replaced by default
190 aEdAssign.SetSelection( Selection( 0, aEdAssign.GetText().getLength() ) );
193 aRbAssign.DoRef();
194 bCloseFlag=sal_True;
197 void ScSimpleRefDlg::RefInputDone( sal_Bool bForced)
199 ScAnyRefDlg::RefInputDone(bForced);
200 if ( (bForced || bCloseOnButtonUp) && bCloseFlag )
201 OkBtnHdl(&aBtnOk);
203 //------------------------------------------------------------------------
204 // Handler:
205 // ========
206 IMPL_LINK_NOARG(ScSimpleRefDlg, OkBtnHdl)
208 bAutoReOpen=false;
209 String aResult=aEdAssign.GetText();
210 aCloseHdl.Call(&aResult);
211 Link aUnoLink = aDoneHdl; // stack var because this is deleted in DoClose
212 DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
213 aUnoLink.Call( &aResult );
214 return 0;
217 //------------------------------------------------------------------------
218 IMPL_LINK_NOARG(ScSimpleRefDlg, CancelBtnHdl)
220 bAutoReOpen=false;
221 String aResult=aEdAssign.GetText();
222 aCloseHdl.Call(NULL);
223 Link aUnoLink = aAbortedHdl; // stack var because this is deleted in DoClose
224 DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
225 aUnoLink.Call( &aResult );
226 return 0;
231 //------------------------------------------------------------------------
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */