1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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:
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
) );
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
);
111 ScAddress aAdr
= rRef
.aStart
;
112 aAdr
.Format( aRefStr
, SCA_ABS_3D
, pDocP
, pDocP
->GetAddressConvention() );
115 theCurArea
.Format( aRefStr
, ABS_DREF3D
, pDocP
, pDocP
->GetAddressConvention() );
117 if ( bMultiSelection
)
119 String aVal
= aEdAssign
.GetText();
120 Selection aSel
= aEdAssign
.GetSelection();
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
);
129 aEdAssign
.SetRefString( aRefStr
);
131 aChangeHdl
.Call( &aRefStr
);
136 //----------------------------------------------------------------------------
137 sal_Bool
ScSimpleRefDlg::Close()
139 CancelBtnHdl(&aBtnCancel
);
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)
154 //------------------------------------------------------------------------
155 sal_Bool
ScSimpleRefDlg::IsRefInputMode() const
160 String
ScSimpleRefDlg::GetRefString() const
162 return aEdAssign
.GetText();
165 void ScSimpleRefDlg::SetCloseHdl( const Link
& rLink
)
170 void ScSimpleRefDlg::SetUnoLinks( const Link
& rDone
, const Link
& rAbort
,
171 const Link
& rChange
)
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() ) );
197 void ScSimpleRefDlg::RefInputDone( sal_Bool bForced
)
199 ScAnyRefDlg::RefInputDone(bForced
);
200 if ( (bForced
|| bCloseOnButtonUp
) && bCloseFlag
)
203 //------------------------------------------------------------------------
206 IMPL_LINK_NOARG(ScSimpleRefDlg
, OkBtnHdl
)
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
);
217 //------------------------------------------------------------------------
218 IMPL_LINK_NOARG(ScSimpleRefDlg
, CancelBtnHdl
)
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
);
231 //------------------------------------------------------------------------
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */