sync master with lastest vba changes
[ooovba.git] / sc / source / ui / miscdlgs / simpref.cxx
blob22a6d0adb3af04fcb9b3372c1e6d18b34a880a36
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: simpref.cxx,v $
10 * $Revision: 1.11.30.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // System - Includes ---------------------------------------------------------
38 // INCLUDE -------------------------------------------------------------------
40 #include <vcl/msgbox.hxx>
41 #include <sfx2/app.hxx>
43 #include "reffact.hxx"
44 #include "document.hxx"
45 #include "scresid.hxx"
46 #include "globstr.hrc"
47 #include "simpref.hrc"
48 #include "rangenam.hxx" // IsNameValid
49 #include "simpref.hxx"
50 #include "scmod.hxx"
52 //============================================================================
54 #define ABS_SREF SCA_VALID \
55 | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
56 #define ABS_DREF ABS_SREF \
57 | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE
58 #define ABS_SREF3D ABS_SREF | SCA_TAB_3D
59 #define ABS_DREF3D ABS_DREF | SCA_TAB_3D
61 //----------------------------------------------------------------------------
63 #define ERRORBOX(s) ErrorBox(this,WinBits(WB_OK|WB_DEF_OK),s).Execute()
64 #define QUERYBOX(m) QueryBox(this,WinBits(WB_YES_NO|WB_DEF_YES),m).Execute()
66 //============================================================================
67 // class ScSimpleRefDlg
69 //----------------------------------------------------------------------------
70 ScSimpleRefDlg::ScSimpleRefDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
71 ScViewData* ptrViewData )
73 : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_SIMPLEREF ),
75 aFtAssign ( this, ScResId( FT_ASSIGN ) ),
76 aEdAssign ( this, this, ScResId( ED_ASSIGN ) ),
77 aRbAssign ( this, ScResId( RB_ASSIGN ), &aEdAssign, this ),
79 aBtnOk ( this, ScResId( BTN_OK ) ),
80 aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
81 aBtnHelp ( this, ScResId( BTN_HELP ) ),
84 pViewData ( ptrViewData ),
85 pDoc ( ptrViewData->GetDocument() ),
86 bRefInputMode ( FALSE ),
87 bAutoReOpen ( TRUE ),
88 bCloseOnButtonUp( FALSE ),
89 bSingleCell ( FALSE ),
90 bMultiSelection ( FALSE )
92 // damit die Strings in der Resource bei den FixedTexten bleiben koennen:
93 Init();
94 FreeResource();
95 SetDispatcherLock( TRUE ); // Modal-Modus einschalten
98 //----------------------------------------------------------------------------
99 __EXPORT ScSimpleRefDlg::~ScSimpleRefDlg()
101 SetDispatcherLock( FALSE ); // Modal-Modus einschalten
104 //----------------------------------------------------------------------------
105 void ScSimpleRefDlg::FillInfo(SfxChildWinInfo& rWinInfo) const
107 ScAnyRefDlg::FillInfo(rWinInfo);
108 rWinInfo.bVisible=bAutoReOpen;
111 //----------------------------------------------------------------------------
112 void ScSimpleRefDlg::SetRefString(const String &rStr)
114 aEdAssign.SetText(rStr);
117 //----------------------------------------------------------------------------
118 void ScSimpleRefDlg::Init()
120 aBtnOk.SetClickHdl ( LINK( this, ScSimpleRefDlg, OkBtnHdl ) );
121 aBtnCancel.SetClickHdl ( LINK( this, ScSimpleRefDlg, CancelBtnHdl ) );
122 bCloseFlag=FALSE;
125 //----------------------------------------------------------------------------
126 // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
127 // neue Selektion im Referenz-Fenster angezeigt wird.
128 void ScSimpleRefDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
130 if ( aEdAssign.IsEnabled() )
132 if ( rRef.aStart != rRef.aEnd )
133 RefInputStart( &aEdAssign );
135 theCurArea = rRef;
136 String aRefStr;
137 if ( bSingleCell )
139 ScAddress aAdr = rRef.aStart;
140 aAdr.Format( aRefStr, SCA_ABS_3D, pDocP, pDocP->GetAddressConvention() );
142 else
143 theCurArea.Format( aRefStr, ABS_DREF3D, pDocP, pDocP->GetAddressConvention() );
145 if ( bMultiSelection )
147 String aVal = aEdAssign.GetText();
148 Selection aSel = aEdAssign.GetSelection();
149 aSel.Justify();
150 aVal.Erase( (xub_StrLen)aSel.Min(), (xub_StrLen)aSel.Len() );
151 aVal.Insert( aRefStr, (xub_StrLen)aSel.Min() );
152 Selection aNewSel( aSel.Min(), aSel.Min()+aRefStr.Len() );
153 aEdAssign.SetRefString( aVal );
154 aEdAssign.SetSelection( aNewSel );
156 else
157 aEdAssign.SetRefString( aRefStr );
159 aChangeHdl.Call( &aRefStr );
164 //----------------------------------------------------------------------------
165 BOOL __EXPORT ScSimpleRefDlg::Close()
167 CancelBtnHdl(&aBtnCancel);
168 return TRUE;
171 //------------------------------------------------------------------------
172 void ScSimpleRefDlg::SetActive()
174 aEdAssign.GrabFocus();
176 // kein NameModifyHdl, weil sonst Bereiche nicht geaendert werden koennen
177 // (nach dem Aufziehen der Referenz wuerde der alte Inhalt wieder angezeigt)
178 // (der ausgewaehlte DB-Name hat sich auch nicht veraendert)
180 RefInputDone();
182 //------------------------------------------------------------------------
183 BOOL ScSimpleRefDlg::IsRefInputMode() const
185 return TRUE;
188 String ScSimpleRefDlg::GetRefString() const
190 return aEdAssign.GetText();
193 void ScSimpleRefDlg::SetCloseHdl( const Link& rLink )
195 aCloseHdl=rLink;
198 void ScSimpleRefDlg::SetUnoLinks( const Link& rDone, const Link& rAbort,
199 const Link& rChange )
201 aDoneHdl = rDone;
202 aAbortedHdl = rAbort;
203 aChangeHdl = rChange;
206 void ScSimpleRefDlg::SetFlags( BOOL bSetCloseOnButtonUp, BOOL bSetSingleCell, BOOL bSetMultiSelection )
208 bCloseOnButtonUp = bSetCloseOnButtonUp;
209 bSingleCell = bSetSingleCell;
210 bMultiSelection = bSetMultiSelection;
213 void ScSimpleRefDlg::StartRefInput()
215 if ( bMultiSelection )
217 // initially select the whole string, so it gets replaced by default
218 aEdAssign.SetSelection( Selection( 0, aEdAssign.GetText().Len() ) );
221 aRbAssign.DoRef();
222 bCloseFlag=TRUE;
225 void ScSimpleRefDlg::RefInputDone( BOOL bForced)
227 ScAnyRefDlg::RefInputDone(bForced);
228 if ( (bForced || bCloseOnButtonUp) && bCloseFlag )
229 OkBtnHdl(&aBtnOk);
231 //------------------------------------------------------------------------
232 // Handler:
233 // ========
234 IMPL_LINK( ScSimpleRefDlg, OkBtnHdl, void *, EMPTYARG )
236 bAutoReOpen=FALSE;
237 String aResult=aEdAssign.GetText();
238 aCloseHdl.Call(&aResult);
239 Link aUnoLink = aDoneHdl; // stack var because this is deleted in DoClose
240 DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
241 aUnoLink.Call( &aResult );
242 return 0;
245 //------------------------------------------------------------------------
246 IMPL_LINK( ScSimpleRefDlg, CancelBtnHdl, void *, EMPTYARG )
248 bAutoReOpen=FALSE;
249 String aResult=aEdAssign.GetText();
250 aCloseHdl.Call(NULL);
251 Link aUnoLink = aAbortedHdl; // stack var because this is deleted in DoClose
252 DoClose( ScSimpleRefDlgWrapper::GetChildWindowId() );
253 aUnoLink.Call( &aResult );
254 return 0;
259 //------------------------------------------------------------------------