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"
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 OUString
&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 aRefStr
= aAdr
.Format(SCA_ABS_3D
, pDocP
, pDocP
->GetAddressConvention());
115 aRefStr
= theCurArea
.Format(ABS_DREF3D
, pDocP
, pDocP
->GetAddressConvention());
117 if ( bMultiSelection
)
119 OUString aVal
= aEdAssign
.GetText();
120 Selection aSel
= aEdAssign
.GetSelection();
122 aVal
= aVal
.replaceAt( aSel
.Min(), aSel
.Len(), aRefStr
);
123 Selection
aNewSel( aSel
.Min(), aSel
.Min()+aRefStr
.getLength() );
124 aEdAssign
.SetRefString( aVal
);
125 aEdAssign
.SetSelection( aNewSel
);
128 aEdAssign
.SetRefString( aRefStr
);
130 aChangeHdl
.Call( &aRefStr
);
135 //----------------------------------------------------------------------------
136 sal_Bool
ScSimpleRefDlg::Close()
138 CancelBtnHdl(&aBtnCancel
);
142 //------------------------------------------------------------------------
143 void ScSimpleRefDlg::SetActive()
145 aEdAssign
.GrabFocus();
147 // kein NameModifyHdl, weil sonst Bereiche nicht geaendert werden koennen
148 // (nach dem Aufziehen der Referenz wuerde der alte Inhalt wieder angezeigt)
149 // (der ausgewaehlte DB-Name hat sich auch nicht veraendert)
153 //------------------------------------------------------------------------
154 sal_Bool
ScSimpleRefDlg::IsRefInputMode() const
159 OUString
ScSimpleRefDlg::GetRefString() const
161 return aEdAssign
.GetText();
164 void ScSimpleRefDlg::SetCloseHdl( const Link
& rLink
)
169 void ScSimpleRefDlg::SetUnoLinks( const Link
& rDone
, const Link
& rAbort
,
170 const Link
& rChange
)
173 aAbortedHdl
= rAbort
;
174 aChangeHdl
= rChange
;
177 void ScSimpleRefDlg::SetFlags( sal_Bool bSetCloseOnButtonUp
, sal_Bool bSetSingleCell
, sal_Bool bSetMultiSelection
)
179 bCloseOnButtonUp
= bSetCloseOnButtonUp
;
180 bSingleCell
= bSetSingleCell
;
181 bMultiSelection
= bSetMultiSelection
;
184 void ScSimpleRefDlg::StartRefInput()
186 if ( bMultiSelection
)
188 // initially select the whole string, so it gets replaced by default
189 aEdAssign
.SetSelection( Selection( 0, aEdAssign
.GetText().getLength() ) );
196 void ScSimpleRefDlg::RefInputDone( sal_Bool bForced
)
198 ScAnyRefDlg::RefInputDone(bForced
);
199 if ( (bForced
|| bCloseOnButtonUp
) && bCloseFlag
)
202 //------------------------------------------------------------------------
205 IMPL_LINK_NOARG(ScSimpleRefDlg
, OkBtnHdl
)
208 OUString aResult
=aEdAssign
.GetText();
209 aCloseHdl
.Call(&aResult
);
210 Link aUnoLink
= aDoneHdl
; // stack var because this is deleted in DoClose
211 DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
212 aUnoLink
.Call( &aResult
);
216 //------------------------------------------------------------------------
217 IMPL_LINK_NOARG(ScSimpleRefDlg
, CancelBtnHdl
)
220 OUString aResult
=aEdAssign
.GetText();
221 aCloseHdl
.Call(NULL
);
222 Link aUnoLink
= aAbortedHdl
; // stack var because this is deleted in DoClose
223 DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
224 aUnoLink
.Call( &aResult
);
230 //------------------------------------------------------------------------
232 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */