Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <comphelper/string.hxx>
30 : : #include <vcl/msgbox.hxx>
31 : :
32 : : #include "reffact.hxx"
33 : : #include "document.hxx"
34 : : #include "scresid.hxx"
35 : : #include "globstr.hrc"
36 : : #include "dbnamdlg.hrc"
37 : : #include "rangenam.hxx" // IsNameValid
38 : : #include "globalnames.hxx"
39 : :
40 : : #define _DBNAMDLG_CXX
41 : : #include "dbnamdlg.hxx"
42 : : #undef _DBNAMDLG_CXX
43 : :
44 : :
45 : : //============================================================================
46 : :
47 : : #define ABS_SREF SCA_VALID \
48 : : | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
49 : : #define ABS_DREF ABS_SREF \
50 : : | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE
51 : : #define ABS_SREF3D ABS_SREF | SCA_TAB_3D
52 : : #define ABS_DREF3D ABS_DREF | SCA_TAB_3D
53 : :
54 : : //----------------------------------------------------------------------------
55 : :
56 : : class DBSaveData;
57 : :
58 : : static DBSaveData* pSaveObj = NULL;
59 : :
60 : : #define ERRORBOX(s) ErrorBox(this,WinBits(WB_OK|WB_DEF_OK),s).Execute()
61 : :
62 : : //============================================================================
63 : : // class DBSaveData
64 : :
65 : 0 : class DBSaveData
66 : : {
67 : : public:
68 : 0 : DBSaveData( Edit& rEd, CheckBox& rHdr, CheckBox& rSize, CheckBox& rFmt,
69 : : CheckBox& rStrip, ScRange& rArea )
70 : : : rEdAssign(rEd),
71 : : rBtnHeader(rHdr), rBtnSize(rSize), rBtnFormat(rFmt), rBtnStrip(rStrip),
72 : : rCurArea(rArea),
73 : 0 : bHeader(false), bSize(false), bFormat(false), bDirty(false) {}
74 : : void Save();
75 : : void Restore();
76 : :
77 : : private:
78 : : Edit& rEdAssign;
79 : : CheckBox& rBtnHeader;
80 : : CheckBox& rBtnSize;
81 : : CheckBox& rBtnFormat;
82 : : CheckBox& rBtnStrip;
83 : : ScRange& rCurArea;
84 : : String aStr;
85 : : ScRange aArea;
86 : : sal_Bool bHeader:1;
87 : : sal_Bool bSize:1;
88 : : sal_Bool bFormat:1;
89 : : sal_Bool bStrip:1;
90 : : sal_Bool bDirty:1;
91 : : };
92 : :
93 : :
94 : :
95 : : //----------------------------------------------------------------------------
96 : :
97 : 0 : void DBSaveData::Save()
98 : : {
99 : 0 : aArea = rCurArea;
100 [ # # ]: 0 : aStr = rEdAssign.GetText();
101 : 0 : bHeader = rBtnHeader.IsChecked();
102 : 0 : bSize = rBtnSize.IsChecked();
103 : 0 : bFormat = rBtnFormat.IsChecked();
104 : 0 : bStrip = rBtnStrip.IsChecked();
105 : 0 : bDirty = sal_True;
106 : 0 : }
107 : :
108 : :
109 : : //----------------------------------------------------------------------------
110 : :
111 : 0 : void DBSaveData::Restore()
112 : : {
113 [ # # ]: 0 : if ( bDirty )
114 : : {
115 : 0 : rCurArea = aArea;
116 : 0 : rEdAssign.SetText( aStr );
117 : 0 : rBtnHeader.Check ( bHeader );
118 : 0 : rBtnSize.Check ( bSize );
119 : 0 : rBtnFormat.Check ( bFormat );
120 : 0 : rBtnStrip.Check ( bStrip );
121 : 0 : bDirty = false;
122 : : }
123 : 0 : }
124 : :
125 : :
126 : : //============================================================================
127 : : // class ScDbNameDlg
128 : :
129 : : //----------------------------------------------------------------------------
130 : :
131 : 0 : ScDbNameDlg::ScDbNameDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
132 : : ScViewData* ptrViewData )
133 : :
134 : : : ScAnyRefDlg ( pB, pCW, pParent, RID_SCDLG_DBNAMES ),
135 : : //
136 : : aFlName ( this, ScResId( FL_NAME ) ),
137 : : aEdName ( this, ScResId( ED_NAME ) ),
138 : :
139 : : aFlAssign ( this, ScResId( FL_ASSIGN ) ),
140 : : aEdAssign ( this, this, ScResId( ED_DBAREA ) ),
141 : : aRbAssign ( this, ScResId( RB_DBAREA ), &aEdAssign, this ),
142 : :
143 : : aFlOptions ( this, ScResId( FL_OPTIONS ) ),
144 : : aBtnHeader ( this, ScResId( BTN_HEADER ) ),
145 : : aBtnDoSize ( this, ScResId( BTN_SIZE ) ),
146 : : aBtnKeepFmt ( this, ScResId( BTN_FORMAT ) ),
147 : : aBtnStripData ( this, ScResId( BTN_STRIPDATA ) ),
148 : : aFTSource ( this, ScResId( FT_SOURCE ) ),
149 : : aFTOperations ( this, ScResId( FT_OPERATIONS ) ),
150 : :
151 : : aBtnOk ( this, ScResId( BTN_OK ) ),
152 : : aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
153 : : aBtnHelp ( this, ScResId( BTN_HELP ) ),
154 : : aBtnAdd ( this, ScResId( BTN_ADD ) ),
155 : : aBtnRemove ( this, ScResId( BTN_REMOVE ) ),
156 : : aBtnMore ( this, ScResId( BTN_MORE ) ),
157 : :
158 : : aStrAdd ( ScResId( STR_ADD ) ),
159 : : aStrModify ( ScResId( STR_MODIFY ) ),
160 : : aStrInvalid ( ScResId( STR_DB_INVALID ) ),
161 : : //
162 : : pViewData ( ptrViewData ),
163 [ # # ]: 0 : pDoc ( ptrViewData->GetDocument() ),
164 : : bRefInputMode ( false ),
165 : : aAddrDetails ( pDoc->GetAddressConvention(), 0, 0 ),
166 [ # # ][ # # ]: 0 : aLocalDbCol ( *(pDoc->GetDBCollection()) )
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
167 : : {
168 : : // WB_NOLABEL can't be set in resource...
169 [ # # ][ # # ]: 0 : aFTSource.SetStyle( aFTSource.GetStyle() | WB_NOLABEL );
170 [ # # ][ # # ]: 0 : aFTOperations.SetStyle( aFTOperations.GetStyle() | WB_NOLABEL );
171 : :
172 : : // damit die Strings in der Resource bei den FixedTexten bleiben koennen:
173 [ # # ][ # # ]: 0 : aStrSource = aFTSource.GetText();
[ # # ]
174 [ # # ][ # # ]: 0 : aStrOperations = aFTOperations.GetText();
[ # # ]
175 : :
176 : : pSaveObj = new DBSaveData( aEdAssign, aBtnHeader,
177 [ # # ][ # # ]: 0 : aBtnDoSize, aBtnKeepFmt, aBtnStripData, theCurArea );
178 [ # # ]: 0 : Init();
179 [ # # ]: 0 : FreeResource();
180 [ # # ]: 0 : aRbAssign.SetAccessibleRelationMemberOf(&aFlAssign);
181 : 0 : }
182 : :
183 : :
184 : : //----------------------------------------------------------------------------
185 : :
186 [ # # ][ # # ]: 0 : ScDbNameDlg::~ScDbNameDlg()
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
187 : : {
188 [ # # ][ # # ]: 0 : DELETEZ( pSaveObj );
189 [ # # ]: 0 : }
190 : :
191 : :
192 : : //----------------------------------------------------------------------------
193 : :
194 : 0 : void ScDbNameDlg::Init()
195 : : {
196 [ # # ]: 0 : aBtnHeader.Check( sal_True ); // Default: mit Spaltenkoepfen
197 : :
198 [ # # ]: 0 : aBtnMore.AddWindow( &aFlOptions );
199 [ # # ]: 0 : aBtnMore.AddWindow( &aBtnHeader );
200 [ # # ]: 0 : aBtnMore.AddWindow( &aBtnDoSize );
201 [ # # ]: 0 : aBtnMore.AddWindow( &aBtnKeepFmt );
202 [ # # ]: 0 : aBtnMore.AddWindow( &aBtnStripData );
203 [ # # ]: 0 : aBtnMore.AddWindow( &aFTSource );
204 [ # # ]: 0 : aBtnMore.AddWindow( &aFTOperations );
205 : :
206 [ # # ]: 0 : aBtnOk.SetClickHdl ( LINK( this, ScDbNameDlg, OkBtnHdl ) );
207 [ # # ]: 0 : aBtnCancel.SetClickHdl ( LINK( this, ScDbNameDlg, CancelBtnHdl ) );
208 [ # # ]: 0 : aBtnAdd.SetClickHdl ( LINK( this, ScDbNameDlg, AddBtnHdl ) );
209 [ # # ]: 0 : aBtnRemove.SetClickHdl ( LINK( this, ScDbNameDlg, RemoveBtnHdl ) );
210 [ # # ]: 0 : aEdName.SetModifyHdl ( LINK( this, ScDbNameDlg, NameModifyHdl ) );
211 [ # # ]: 0 : aEdAssign.SetModifyHdl ( LINK( this, ScDbNameDlg, AssModifyHdl ) );
212 [ # # ]: 0 : UpdateNames();
213 : :
214 [ # # ]: 0 : String theAreaStr;
215 : :
216 [ # # ][ # # ]: 0 : if ( pViewData && pDoc )
217 : : {
218 : 0 : SCCOL nStartCol = 0;
219 : 0 : SCROW nStartRow = 0;
220 : 0 : SCTAB nStartTab = 0;
221 : 0 : SCCOL nEndCol = 0;
222 : 0 : SCROW nEndRow = 0;
223 : 0 : SCTAB nEndTab = 0;
224 : :
225 [ # # ]: 0 : ScDBCollection* pDBColl = pDoc->GetDBCollection();
226 : 0 : ScDBData* pDBData = NULL;
227 : :
228 : : pViewData->GetSimpleArea( nStartCol, nStartRow, nStartTab,
229 [ # # ]: 0 : nEndCol, nEndRow, nEndTab );
230 : :
231 : : theCurArea = ScRange( ScAddress( nStartCol, nStartRow, nStartTab ),
232 : 0 : ScAddress( nEndCol, nEndRow, nEndTab ) );
233 : :
234 [ # # ]: 0 : theCurArea.Format( theAreaStr, ABS_DREF3D, pDoc, aAddrDetails );
235 : :
236 [ # # ]: 0 : if ( pDBColl )
237 : : {
238 : : // Feststellen, ob definierter DB-Bereich markiert wurde:
239 [ # # ]: 0 : pDBData = pDBColl->GetDBAtCursor( nStartCol, nStartRow, nStartTab, sal_True );
240 [ # # ]: 0 : if ( pDBData )
241 : : {
242 : 0 : ScAddress& rStart = theCurArea.aStart;
243 : 0 : ScAddress& rEnd = theCurArea.aEnd;
244 : : SCCOL nCol1;
245 : : SCCOL nCol2;
246 : : SCROW nRow1;
247 : : SCROW nRow2;
248 : : SCTAB nTab;
249 : :
250 [ # # ]: 0 : pDBData->GetArea( nTab, nCol1, nRow1, nCol2, nRow2 );
251 : :
252 [ # # # # : 0 : if ( (rStart.Tab() == nTab)
# # # # #
# ][ # # ]
253 : 0 : && (rStart.Col() == nCol1) && (rStart.Row() == nRow1)
254 : 0 : && (rEnd.Col() == nCol2) && (rEnd.Row() == nRow2 ) )
255 : : {
256 : 0 : rtl::OUString aDBName = pDBData->GetName();
257 [ # # ]: 0 : if ( aDBName != STR_DB_LOCAL_NONAME )
258 [ # # ][ # # ]: 0 : aEdName.SetText(aDBName);
[ # # ]
259 : :
260 [ # # ]: 0 : aBtnHeader.Check( pDBData->HasHeader() );
261 [ # # ]: 0 : aBtnDoSize.Check( pDBData->IsDoSize() );
262 [ # # ]: 0 : aBtnKeepFmt.Check( pDBData->IsKeepFmt() );
263 [ # # ]: 0 : aBtnStripData.Check( pDBData->IsStripData() );
264 [ # # ]: 0 : SetInfoStrings( pDBData );
265 : : }
266 : : }
267 : : }
268 : : }
269 : :
270 [ # # ]: 0 : aEdAssign.SetText( theAreaStr );
271 [ # # ]: 0 : aEdName.GrabFocus();
272 : 0 : bSaved=sal_True;
273 [ # # ]: 0 : pSaveObj->Save();
274 [ # # ][ # # ]: 0 : NameModifyHdl( 0 );
275 : 0 : }
276 : :
277 : :
278 : 0 : void ScDbNameDlg::SetInfoStrings( const ScDBData* pDBData )
279 : : {
280 : 0 : ::rtl::OUStringBuffer aBuf;
281 [ # # ][ # # ]: 0 : aBuf.append(aStrSource);
282 [ # # ]: 0 : if (pDBData)
283 : : {
284 [ # # ]: 0 : aBuf.append(sal_Unicode(' '));
285 [ # # ][ # # ]: 0 : aBuf.append(pDBData->GetSourceString());
286 : : }
287 [ # # ][ # # ]: 0 : aFTSource.SetText(aBuf.makeStringAndClear());
[ # # ][ # # ]
288 : :
289 [ # # ][ # # ]: 0 : aBuf.append(aStrOperations);
290 [ # # ]: 0 : String aOper = aStrOperations;
291 [ # # ]: 0 : if (pDBData)
292 : : {
293 [ # # ]: 0 : aBuf.append(sal_Unicode(' '));
294 [ # # ][ # # ]: 0 : aBuf.append(pDBData->GetOperations());
295 : : }
296 [ # # ][ # # ]: 0 : aFTOperations.SetText(aBuf.makeStringAndClear());
[ # # ][ # # ]
[ # # ]
297 : 0 : }
298 : :
299 : : //----------------------------------------------------------------------------
300 : : // Uebergabe eines mit der Maus selektierten Tabellenbereiches, der dann als
301 : : // neue Selektion im Referenz-Fenster angezeigt wird.
302 : :
303 : 0 : void ScDbNameDlg::SetReference( const ScRange& rRef, ScDocument* pDocP )
304 : : {
305 [ # # ]: 0 : if ( aEdAssign.IsEnabled() )
306 : : {
307 [ # # ]: 0 : if ( rRef.aStart != rRef.aEnd )
308 [ # # ]: 0 : RefInputStart( &aEdAssign );
309 : :
310 : 0 : theCurArea = rRef;
311 : :
312 [ # # ]: 0 : String aRefStr;
313 [ # # ]: 0 : theCurArea.Format( aRefStr, ABS_DREF3D, pDocP, aAddrDetails );
314 [ # # ]: 0 : aEdAssign.SetRefString( aRefStr );
315 [ # # ]: 0 : aBtnHeader.Enable();
316 [ # # ]: 0 : aBtnDoSize.Enable();
317 [ # # ]: 0 : aBtnKeepFmt.Enable();
318 [ # # ]: 0 : aBtnStripData.Enable();
319 [ # # ]: 0 : aFTSource.Enable();
320 [ # # ]: 0 : aFTOperations.Enable();
321 [ # # ]: 0 : aBtnAdd.Enable();
322 : 0 : bSaved=sal_True;
323 [ # # ][ # # ]: 0 : pSaveObj->Save();
324 : : }
325 : 0 : }
326 : :
327 : :
328 : : //----------------------------------------------------------------------------
329 : :
330 : 0 : sal_Bool ScDbNameDlg::Close()
331 : : {
332 : 0 : return DoClose( ScDbNameDlgWrapper::GetChildWindowId() );
333 : : }
334 : :
335 : : //------------------------------------------------------------------------
336 : :
337 : 0 : void ScDbNameDlg::SetActive()
338 : : {
339 : 0 : aEdAssign.GrabFocus();
340 : :
341 : : // kein NameModifyHdl, weil sonst Bereiche nicht geaendert werden koennen
342 : : // (nach dem Aufziehen der Referenz wuerde der alte Inhalt wieder angezeigt)
343 : : // (der ausgewaehlte DB-Name hat sich auch nicht veraendert)
344 : :
345 : 0 : RefInputDone();
346 : 0 : }
347 : :
348 : : //------------------------------------------------------------------------
349 : :
350 : 0 : void ScDbNameDlg::UpdateNames()
351 : : {
352 : : typedef ScDBCollection::NamedDBs DBsType;
353 : :
354 : 0 : const DBsType& rDBs = aLocalDbCol.getNamedDBs();
355 : :
356 : 0 : aEdName.SetUpdateMode( false );
357 : : //-----------------------------------------------------------
358 : 0 : aEdName.Clear();
359 : 0 : aEdAssign.SetText( EMPTY_STRING );
360 : :
361 [ # # ]: 0 : if (!rDBs.empty())
362 : : {
363 [ # # ][ # # ]: 0 : DBsType::const_iterator itr = rDBs.begin(), itrEnd = rDBs.end();
364 [ # # ][ # # ]: 0 : for (; itr != itrEnd; ++itr)
[ # # ]
365 [ # # ][ # # ]: 0 : aEdName.InsertEntry(itr->GetName());
[ # # ][ # # ]
366 : : }
367 : : else
368 : : {
369 : 0 : aBtnAdd.SetText( aStrAdd );
370 : 0 : aBtnAdd.Disable();
371 : 0 : aBtnRemove.Disable();
372 : : }
373 : : //-----------------------------------------------------------
374 : 0 : aEdName.SetUpdateMode( sal_True );
375 : 0 : aEdName.Invalidate();
376 : 0 : }
377 : :
378 : : //------------------------------------------------------------------------
379 : :
380 : 0 : void ScDbNameDlg::UpdateDBData( const String& rStrName )
381 : : {
382 : :
383 [ # # ][ # # ]: 0 : const ScDBData* pData = aLocalDbCol.getNamedDBs().findByName(rStrName);
384 : :
385 [ # # ]: 0 : if ( pData )
386 : : {
387 : 0 : SCCOL nColStart = 0;
388 : 0 : SCROW nRowStart = 0;
389 : 0 : SCCOL nColEnd = 0;
390 : 0 : SCROW nRowEnd = 0;
391 : 0 : SCTAB nTab = 0;
392 : :
393 [ # # ]: 0 : pData->GetArea( nTab, nColStart, nRowStart, nColEnd, nRowEnd );
394 : : theCurArea = ScRange( ScAddress( nColStart, nRowStart, nTab ),
395 : 0 : ScAddress( nColEnd, nRowEnd, nTab ) );
396 : 0 : ::rtl::OUString theArea;
397 [ # # ]: 0 : theCurArea.Format( theArea, ABS_DREF3D, pDoc, aAddrDetails );
398 [ # # ][ # # ]: 0 : aEdAssign.SetText( theArea );
[ # # ]
399 [ # # ]: 0 : aBtnAdd.SetText( aStrModify );
400 [ # # ]: 0 : aBtnHeader.Check( pData->HasHeader() );
401 [ # # ]: 0 : aBtnDoSize.Check( pData->IsDoSize() );
402 [ # # ]: 0 : aBtnKeepFmt.Check( pData->IsKeepFmt() );
403 [ # # ]: 0 : aBtnStripData.Check( pData->IsStripData() );
404 [ # # ]: 0 : SetInfoStrings( pData );
405 : : }
406 : :
407 : 0 : aBtnAdd.SetText( aStrModify );
408 : 0 : aBtnAdd.Enable();
409 : 0 : aBtnRemove.Enable();
410 : 0 : aBtnHeader.Enable();
411 : 0 : aBtnDoSize.Enable();
412 : 0 : aBtnKeepFmt.Enable();
413 : 0 : aBtnStripData.Enable();
414 : 0 : aFTSource.Enable();
415 : 0 : aFTOperations.Enable();
416 : 0 : }
417 : :
418 : : //------------------------------------------------------------------------
419 : :
420 : :
421 : 0 : sal_Bool ScDbNameDlg::IsRefInputMode() const
422 : : {
423 : 0 : return bRefInputMode;
424 : : }
425 : :
426 : : //------------------------------------------------------------------------
427 : : // Handler:
428 : : // ========
429 : :
430 : 0 : IMPL_LINK_NOARG(ScDbNameDlg, OkBtnHdl)
431 : : {
432 : 0 : AddBtnHdl( 0 );
433 : :
434 : : // Der View die Aenderungen und die Remove-Liste uebergeben:
435 : : // beide werden nur als Referenz uebergeben, so dass an dieser
436 : : // Stelle keine Speicherleichen entstehen koennen:
437 [ # # ]: 0 : if ( pViewData )
438 : : pViewData->GetView()->
439 : 0 : NotifyCloseDbNameDlg( aLocalDbCol, aRemoveList );
440 : :
441 : 0 : Close();
442 : 0 : return 0;
443 : : }
444 : :
445 : : //------------------------------------------------------------------------
446 : :
447 : 0 : IMPL_LINK_NOARG_INLINE_START(ScDbNameDlg, CancelBtnHdl)
448 : : {
449 : 0 : Close();
450 : 0 : return 0;
451 : : }
452 : 0 : IMPL_LINK_NOARG_INLINE_END(ScDbNameDlg, CancelBtnHdl)
453 : :
454 : : //------------------------------------------------------------------------
455 : :
456 : 0 : IMPL_LINK_NOARG(ScDbNameDlg, AddBtnHdl)
457 : : {
458 [ # # ][ # # ]: 0 : String aNewName = comphelper::string::strip(aEdName.GetText(), ' ');
[ # # ][ # # ]
[ # # ]
459 [ # # ]: 0 : String aNewArea = aEdAssign.GetText();
460 : :
461 [ # # ][ # # ]: 0 : if ( aNewName.Len() > 0 && aNewArea.Len() > 0 )
[ # # ]
462 : : {
463 [ # # ][ # # ]: 0 : if ( ScRangeData::IsNameValid( aNewName, pDoc ) && !aNewName.EqualsAscii(STR_DB_LOCAL_NONAME) )
[ # # ][ # # ]
[ # # ]
464 : : {
465 : : // weil jetzt editiert werden kann, muss erst geparst werden
466 : 0 : ScRange aTmpRange;
467 [ # # ]: 0 : String aText = aEdAssign.GetText();
468 [ # # ][ # # ]: 0 : if ( aTmpRange.ParseAny( aText, pDoc, aAddrDetails ) & SCA_VALID )
469 : : {
470 : 0 : theCurArea = aTmpRange;
471 : 0 : ScAddress aStart = theCurArea.aStart;
472 : 0 : ScAddress aEnd = theCurArea.aEnd;
473 : :
474 [ # # ][ # # ]: 0 : ScDBData* pOldEntry = aLocalDbCol.getNamedDBs().findByName(aNewName);
[ # # ]
475 [ # # ]: 0 : if (pOldEntry)
476 : : {
477 : : // Bereich veraendern
478 : :
479 : 0 : pOldEntry->MoveTo( aStart.Tab(), aStart.Col(), aStart.Row(),
480 [ # # ]: 0 : aEnd.Col(), aEnd.Row() );
481 : 0 : pOldEntry->SetByRow( sal_True );
482 [ # # ]: 0 : pOldEntry->SetHeader( aBtnHeader.IsChecked() );
483 [ # # ]: 0 : pOldEntry->SetDoSize( aBtnDoSize.IsChecked() );
484 [ # # ]: 0 : pOldEntry->SetKeepFmt( aBtnKeepFmt.IsChecked() );
485 [ # # ]: 0 : pOldEntry->SetStripData( aBtnStripData.IsChecked() );
486 : : }
487 : : else
488 : : {
489 : : // neuen Bereich einfuegen
490 : :
491 : 0 : ScDBData* pNewEntry = new ScDBData( aNewName, aStart.Tab(),
492 : 0 : aStart.Col(), aStart.Row(),
493 : 0 : aEnd.Col(), aEnd.Row(),
494 [ # # # # ]: 0 : sal_True, aBtnHeader.IsChecked() );
[ # # ][ # # ]
495 [ # # ]: 0 : pNewEntry->SetDoSize( aBtnDoSize.IsChecked() );
496 [ # # ]: 0 : pNewEntry->SetKeepFmt( aBtnKeepFmt.IsChecked() );
497 [ # # ]: 0 : pNewEntry->SetStripData( aBtnStripData.IsChecked() );
498 : :
499 [ # # ][ # # ]: 0 : aLocalDbCol.getNamedDBs().insert(pNewEntry);
500 : : }
501 : :
502 [ # # ]: 0 : UpdateNames();
503 : :
504 [ # # ][ # # ]: 0 : aEdName.SetText( EMPTY_STRING );
505 [ # # ]: 0 : aEdName.GrabFocus();
506 [ # # ]: 0 : aBtnAdd.SetText( aStrAdd );
507 [ # # ]: 0 : aBtnAdd.Disable();
508 [ # # ]: 0 : aBtnRemove.Disable();
509 [ # # ][ # # ]: 0 : aEdAssign.SetText( EMPTY_STRING );
510 [ # # ]: 0 : aBtnHeader.Check( sal_True ); // Default: mit Spaltenkoepfen
511 [ # # ]: 0 : aBtnDoSize.Check( false );
512 [ # # ]: 0 : aBtnKeepFmt.Check( false );
513 [ # # ]: 0 : aBtnStripData.Check( false );
514 [ # # ]: 0 : SetInfoStrings( NULL ); // leer
515 : 0 : theCurArea = ScRange();
516 : 0 : bSaved=sal_True;
517 [ # # ]: 0 : pSaveObj->Save();
518 [ # # ]: 0 : NameModifyHdl( 0 );
519 : : }
520 : : else
521 : : {
522 [ # # ][ # # ]: 0 : ERRORBOX( aStrInvalid );
[ # # ]
523 [ # # ]: 0 : aEdAssign.SetSelection( Selection( 0, SELECTION_MAX ) );
524 [ # # ]: 0 : aEdAssign.GrabFocus();
525 [ # # ]: 0 : }
526 : : }
527 : : else
528 : : {
529 [ # # ][ # # ]: 0 : ERRORBOX( ScGlobal::GetRscString(STR_INVALIDNAME) );
[ # # ][ # # ]
530 [ # # ]: 0 : aEdName.SetSelection( Selection( 0, SELECTION_MAX ) );
531 [ # # ]: 0 : aEdName.GrabFocus();
532 : : }
533 : : }
534 [ # # ][ # # ]: 0 : return 0;
535 : : }
536 : :
537 : : namespace {
538 : :
539 : : class FindByName : public ::std::unary_function<ScDBData, bool>
540 : : {
541 : : const ::rtl::OUString& mrName;
542 : : public:
543 : 0 : FindByName(const ::rtl::OUString& rName) : mrName(rName) {}
544 : 0 : bool operator() (const ScDBData& r) const
545 : : {
546 : 0 : return r.GetName().equals(mrName);
547 : : }
548 : : };
549 : :
550 : : }
551 : :
552 : 0 : IMPL_LINK_NOARG(ScDbNameDlg, RemoveBtnHdl)
553 : : {
554 [ # # ][ # # ]: 0 : ::rtl::OUString aStrEntry = aEdName.GetText();
[ # # ]
555 [ # # ]: 0 : ScDBCollection::NamedDBs& rDBs = aLocalDbCol.getNamedDBs();
556 : : ScDBCollection::NamedDBs::iterator itr =
557 [ # # ][ # # ]: 0 : ::std::find_if(rDBs.begin(), rDBs.end(), FindByName(aStrEntry));
[ # # ]
558 : :
559 [ # # ][ # # ]: 0 : if (itr != rDBs.end())
[ # # ]
560 : : {
561 [ # # ][ # # ]: 0 : String aStrDelMsg = ScGlobal::GetRscString( STR_QUERY_DELENTRY );
562 : :
563 : 0 : ::rtl::OUStringBuffer aBuf;
564 [ # # ][ # # ]: 0 : aBuf.append(aStrDelMsg.GetToken(0, '#'));
[ # # ][ # # ]
565 [ # # ]: 0 : aBuf.append(aStrEntry);
566 [ # # ][ # # ]: 0 : aBuf.append(aStrDelMsg.GetToken(1, '#'));
[ # # ][ # # ]
567 [ # # ][ # # ]: 0 : QueryBox aBox(this, WinBits(WB_YES_NO|WB_DEF_YES), aBuf.makeStringAndClear());
[ # # ][ # # ]
568 : :
569 [ # # ][ # # ]: 0 : if (RET_YES == aBox.Execute())
570 : : {
571 : : SCTAB nTab;
572 : : SCCOL nColStart, nColEnd;
573 : : SCROW nRowStart, nRowEnd;
574 [ # # ][ # # ]: 0 : itr->GetArea( nTab, nColStart, nRowStart, nColEnd, nRowEnd );
575 : : aRemoveList.push_back(
576 : : ScRange( ScAddress( nColStart, nRowStart, nTab ),
577 [ # # ]: 0 : ScAddress( nColEnd, nRowEnd, nTab ) ) );
578 : :
579 [ # # ]: 0 : rDBs.erase(itr);
580 : :
581 [ # # ]: 0 : UpdateNames();
582 : :
583 [ # # ][ # # ]: 0 : aEdName.SetText( EMPTY_STRING );
584 [ # # ]: 0 : aEdName.GrabFocus();
585 [ # # ]: 0 : aBtnAdd.SetText( aStrAdd );
586 [ # # ]: 0 : aBtnAdd.Disable();
587 [ # # ]: 0 : aBtnRemove.Disable();
588 [ # # ][ # # ]: 0 : aEdAssign.SetText( EMPTY_STRING );
589 : 0 : theCurArea = ScRange();
590 [ # # ]: 0 : aBtnHeader.Check( sal_True ); // Default: mit Spaltenkoepfen
591 [ # # ]: 0 : aBtnDoSize.Check( false );
592 [ # # ]: 0 : aBtnKeepFmt.Check( false );
593 [ # # ]: 0 : aBtnStripData.Check( false );
594 [ # # ]: 0 : SetInfoStrings( NULL ); // leer
595 : 0 : bSaved=false;
596 [ # # ]: 0 : pSaveObj->Restore();
597 [ # # ]: 0 : NameModifyHdl( 0 );
598 [ # # ][ # # ]: 0 : }
599 : : }
600 : 0 : return 0;
601 : : }
602 : :
603 : : //------------------------------------------------------------------------
604 : :
605 : 0 : IMPL_LINK_NOARG(ScDbNameDlg, NameModifyHdl)
606 : : {
607 [ # # ]: 0 : String theName = aEdName.GetText();
608 : : sal_Bool bNameFound = (COMBOBOX_ENTRY_NOTFOUND
609 [ # # ]: 0 : != aEdName.GetEntryPos( theName ));
610 : :
611 [ # # ]: 0 : if ( theName.Len() == 0 )
612 : : {
613 [ # # ][ # # ]: 0 : if ( aBtnAdd.GetText() != aStrAdd )
[ # # ][ # # ]
614 [ # # ]: 0 : aBtnAdd.SetText( aStrAdd );
615 [ # # ]: 0 : aBtnAdd .Disable();
616 [ # # ]: 0 : aBtnRemove .Disable();
617 [ # # ]: 0 : aFlAssign .Disable();
618 [ # # ]: 0 : aBtnHeader .Disable();
619 [ # # ]: 0 : aBtnDoSize .Disable();
620 [ # # ]: 0 : aBtnKeepFmt .Disable();
621 [ # # ]: 0 : aBtnStripData.Disable();
622 [ # # ]: 0 : aFTSource .Disable();
623 [ # # ]: 0 : aFTOperations.Disable();
624 [ # # ]: 0 : aEdAssign .Disable();
625 [ # # ]: 0 : aRbAssign .Disable();
626 : : //bSaved=sal_False;
627 : : //pSaveObj->Restore();
628 : : //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
629 : : //SFX_APPWINDOW->Disable(sal_False); //! allgemeine Methode im ScAnyRefDlg
630 : 0 : bRefInputMode = false;
631 : : }
632 : : else
633 : : {
634 [ # # ]: 0 : if ( bNameFound )
635 : : {
636 [ # # ][ # # ]: 0 : if ( aBtnAdd.GetText() != aStrModify )
[ # # ][ # # ]
637 [ # # ]: 0 : aBtnAdd.SetText( aStrModify );
638 : :
639 [ # # ]: 0 : if(!bSaved)
640 : : {
641 : 0 : bSaved=sal_True;
642 [ # # ]: 0 : pSaveObj->Save();
643 : : }
644 [ # # ]: 0 : UpdateDBData( theName );
645 : : }
646 : : else
647 : : {
648 [ # # ][ # # ]: 0 : if ( aBtnAdd.GetText() != aStrAdd )
[ # # ][ # # ]
649 [ # # ]: 0 : aBtnAdd.SetText( aStrAdd );
650 : :
651 : 0 : bSaved=false;
652 [ # # ]: 0 : pSaveObj->Restore();
653 : :
654 [ # # ][ # # ]: 0 : if ( aEdAssign.GetText().Len() > 0 )
[ # # ]
655 : : {
656 [ # # ]: 0 : aBtnAdd.Enable();
657 [ # # ]: 0 : aBtnHeader.Enable();
658 [ # # ]: 0 : aBtnDoSize.Enable();
659 [ # # ]: 0 : aBtnKeepFmt.Enable();
660 [ # # ]: 0 : aBtnStripData.Enable();
661 [ # # ]: 0 : aFTSource.Enable();
662 [ # # ]: 0 : aFTOperations.Enable();
663 : : }
664 : : else
665 : : {
666 [ # # ]: 0 : aBtnAdd.Disable();
667 [ # # ]: 0 : aBtnHeader.Disable();
668 [ # # ]: 0 : aBtnDoSize.Disable();
669 [ # # ]: 0 : aBtnKeepFmt.Disable();
670 [ # # ]: 0 : aBtnStripData.Disable();
671 [ # # ]: 0 : aFTSource.Disable();
672 [ # # ]: 0 : aFTOperations.Disable();
673 : : }
674 [ # # ]: 0 : aBtnRemove.Disable();
675 : : }
676 : :
677 [ # # ]: 0 : aFlAssign.Enable();
678 [ # # ]: 0 : aEdAssign.Enable();
679 [ # # ]: 0 : aRbAssign.Enable();
680 : :
681 : : //@BugID 54702 Enablen/Disablen nur noch in Basisklasse
682 : : //SFX_APPWINDOW->Enable();
683 : 0 : bRefInputMode = true;
684 : : }
685 [ # # ]: 0 : return 0;
686 : : }
687 : :
688 : : //------------------------------------------------------------------------
689 : :
690 : 0 : IMPL_LINK_NOARG(ScDbNameDlg, AssModifyHdl)
691 : : {
692 : : // hier parsen fuer Save() etc.
693 : :
694 : 0 : ScRange aTmpRange;
695 [ # # ]: 0 : String aText = aEdAssign.GetText();
696 [ # # ][ # # ]: 0 : if ( aTmpRange.ParseAny( aText, pDoc, aAddrDetails ) & SCA_VALID )
697 : 0 : theCurArea = aTmpRange;
698 : :
699 [ # # ]: 0 : return 0;
700 : : }
701 : :
702 : :
703 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|