Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / sc / source / ui / miscdlgs / simpref.cxx
blob5245fd25d18479493934485388b220af5dabb8ef
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_SREF3D ABS_SREF | SCA_TAB_3D
39 #define ABS_DREF3D ABS_DREF | SCA_TAB_3D
41 //----------------------------------------------------------------------------
43 #define ERRORBOX(s) ErrorBox(this,WinBits(WB_OK|WB_DEF_OK),s).Execute()
44 #define QUERYBOX(m) QueryBox(this,WinBits(WB_YES_NO|WB_DEF_YES),m).Execute()
46 //============================================================================
47 // class ScSimpleRefDlg
49 //----------------------------------------------------------------------------
50 ScSimpleRefDlg::ScSimpleRefDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
51 ScViewData* ptrViewData )
53 : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_SIMPLEREF ),
55 aFtAssign ( this, ScResId( FT_ASSIGN ) ),
56 aEdAssign ( this, this, ScResId( ED_ASSIGN ) ),
57 aRbAssign ( this, ScResId( RB_ASSIGN ), &aEdAssign, this ),
59 aBtnOk ( this, ScResId( BTN_OK ) ),
60 aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
61 aBtnHelp ( this, ScResId( BTN_HELP ) ),
64 pDoc ( ptrViewData->GetDocument() ),
65 bAutoReOpen ( sal_True ),
66 bCloseOnButtonUp( false ),
67 bSingleCell ( false ),
68 bMultiSelection ( false )
70 // damit die Strings in der Resource bei den FixedTexten bleiben koennen:
71 Init();
72 FreeResource();
73 SetDispatcherLock( sal_True ); // Modal-Modus einschalten
76 //----------------------------------------------------------------------------
77 ScSimpleRefDlg::~ScSimpleRefDlg()
79 SetDispatcherLock( false ); // Modal-Modus einschalten
82 //----------------------------------------------------------------------------
83 void ScSimpleRefDlg::FillInfo(SfxChildWinInfo& rWinInfo) const
85 ScAnyRefDlg::FillInfo(rWinInfo);
86 rWinInfo.bVisible=bAutoReOpen;
89 //----------------------------------------------------------------------------
90 void ScSimpleRefDlg::SetRefString(const String &rStr)
92 aEdAssign.SetText(rStr);
95 //----------------------------------------------------------------------------
96 void ScSimpleRefDlg::Init()
98 aBtnOk.SetClickHdl ( LINK( this, ScSimpleRefDlg, OkBtnHdl ) );
99 aBtnCancel.SetClickHdl ( LINK( this, ScSimpleRefDlg, CancelBtnHdl ) );
100 bCloseFlag=false;
103 //----------------------------------------------------------------------------
104 // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
105 // neue Selektion im Referenz-Fenster angezeigt wird.
106 void ScSimpleRefDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
108 if ( aEdAssign.IsEnabled() )
110 if ( rRef.aStart != rRef.aEnd )
111 RefInputStart( &aEdAssign );
113 theCurArea = rRef;
114 String aRefStr;
115 if ( bSingleCell )
117 ScAddress aAdr = rRef.aStart;
118 aAdr.Format( aRefStr, SCA_ABS_3D, pDocP, pDocP->GetAddressConvention() );
120 else
121 theCurArea.Format( aRefStr, ABS_DREF3D, pDocP, pDocP->GetAddressConvention() );
123 if ( bMultiSelection )
125 String aVal = aEdAssign.GetText();
126 Selection aSel = aEdAssign.GetSelection();
127 aSel.Justify();
128 aVal.Erase( (xub_StrLen)aSel.Min(), (xub_StrLen)aSel.Len() );
129 aVal.Insert( aRefStr, (xub_StrLen)aSel.Min() );
130 Selection aNewSel( aSel.Min(), aSel.Min()+aRefStr.Len() );
131 aEdAssign.SetRefString( aVal );
132 aEdAssign.SetSelection( aNewSel );
134 else
135 aEdAssign.SetRefString( aRefStr );
137 aChangeHdl.Call( &aRefStr );
142 //----------------------------------------------------------------------------
143 sal_Bool ScSimpleRefDlg::Close()
145 CancelBtnHdl(&aBtnCancel);
146 return sal_True;
149 //------------------------------------------------------------------------
150 void ScSimpleRefDlg::SetActive()
152 aEdAssign.GrabFocus();
154 // kein NameModifyHdl, weil sonst Bereiche nicht geaendert werden koennen
155 // (nach dem Aufziehen der Referenz wuerde der alte Inhalt wieder angezeigt)
156 // (der ausgewaehlte DB-Name hat sich auch nicht veraendert)
158 RefInputDone();
160 //------------------------------------------------------------------------
161 sal_Bool ScSimpleRefDlg::IsRefInputMode() const
163 return sal_True;
166 String ScSimpleRefDlg::GetRefString() const
168 return aEdAssign.GetText();
171 void ScSimpleRefDlg::SetCloseHdl( const Link& rLink )
173 aCloseHdl=rLink;
176 void ScSimpleRefDlg::SetUnoLinks( const Link& rDone, const Link& rAbort,
177 const Link& rChange )
179 aDoneHdl = rDone;
180 aAbortedHdl = rAbort;
181 aChangeHdl = rChange;
184 void ScSimpleRefDlg::SetFlags( sal_Bool bSetCloseOnButtonUp, sal_Bool bSetSingleCell, sal_Bool bSetMultiSelection )
186 bCloseOnButtonUp = bSetCloseOnButtonUp;
187 bSingleCell = bSetSingleCell;
188 bMultiSelection = bSetMultiSelection;
191 void ScSimpleRefDlg::StartRefInput()
193 if ( bMultiSelection )
195 // initially select the whole string, so it gets replaced by default
196 aEdAssign.SetSelection( Selection( 0, aEdAssign.GetText().Len() ) );
199 aRbAssign.DoRef();
200 bCloseFlag=sal_True;
203 void ScSimpleRefDlg::RefInputDone( sal_Bool bForced)
205 ScAnyRefDlg::RefInputDone(bForced);
206 if ( (bForced || bCloseOnButtonUp) && bCloseFlag )
207 OkBtnHdl(&aBtnOk);
209 //------------------------------------------------------------------------
210 // Handler:
211 // ========
212 IMPL_LINK_NOARG(ScSimpleRefDlg, OkBtnHdl)
214 bAutoReOpen=false;
215 String aResult=aEdAssign.GetText();
216 aCloseHdl.Call(&aResult);
217 Link aUnoLink = aDoneHdl; // stack var because this is deleted in DoClose
218 DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
219 aUnoLink.Call( &aResult );
220 return 0;
223 //------------------------------------------------------------------------
224 IMPL_LINK_NOARG(ScSimpleRefDlg, CancelBtnHdl)
226 bAutoReOpen=false;
227 String aResult=aEdAssign.GetText();
228 aCloseHdl.Call(NULL);
229 Link aUnoLink = aAbortedHdl; // stack var because this is deleted in DoClose
230 DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
231 aUnoLink.Call( &aResult );
232 return 0;
237 //------------------------------------------------------------------------
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */