1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#undef SC_DLLIMPLEMENTATION
//------------------------------------------------------------------
#include <vcl/msgbox.hxx>
#include "mvtabdlg.hxx"
#include "document.hxx"
#include "docsh.hxx"
#include "miscdlgs.hrc"
#include "global.hxx"
#include "scresid.hxx"
#include "globstr.hrc"
//==================================================================
ScMoveTableDlg::ScMoveTableDlg(Window* pParent, const rtl::OUString& rDefault)
: ModalDialog ( pParent, ScResId( RID_SCDLG_MOVETAB ) ),
//
aFlAction ( this, ScResId( FL_ACTION ) ),
aBtnMove ( this, ScResId( BTN_MOVE ) ),
aBtnCopy ( this, ScResId( BTN_COPY ) ),
aFlLocation ( this, ScResId( FL_LOCATION ) ),
aFtDoc ( this, ScResId( FT_DEST ) ),
aLbDoc ( this, ScResId( LB_DEST ) ),
aFtTable ( this, ScResId( FT_INSERT ) ),
aLbTable ( this, ScResId( LB_INSERT ) ),
aFlName ( this, ScResId( FL_NAME ) ),
aFtTabName ( this, ScResId( FT_TABNAME ) ),
aEdTabName ( this, ScResId( ED_INPUT ) ),
aFtWarn ( this, ScResId( FT_TABNAME_WARN ) ),
aBtnOk ( this, ScResId( BTN_OK ) ),
aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
aBtnHelp ( this, ScResId( BTN_HELP ) ),
maStrTabNameUsed( ResId::toString(ScResId(STR_TABNAME_WARN_USED)) ),
maStrTabNameEmpty( ResId::toString(ScResId(STR_TABNAME_WARN_EMPTY)) ),
maStrTabNameInvalid( ResId::toString(ScResId(STR_TABNAME_WARN_INVALID)) ),
//
maDefaultName( rDefault ),
nDocument ( 0 ),
nTable ( 0 ),
bCopyTable ( false ),
bRenameTable( false ),
mbEverEdited( false )
{
Init();
FreeResource();
}
//------------------------------------------------------------------------
ScMoveTableDlg::~ScMoveTableDlg()
{
}
//------------------------------------------------------------------------
sal_uInt16 ScMoveTableDlg::GetSelectedDocument () const { return nDocument; }
SCTAB ScMoveTableDlg::GetSelectedTable () const { return nTable; }
bool ScMoveTableDlg::GetCopyTable () const { return bCopyTable; }
bool ScMoveTableDlg::GetRenameTable () const { return bRenameTable; }
void ScMoveTableDlg::GetTabNameString( rtl::OUString& rString ) const
{
rString = aEdTabName.GetText();
}
void ScMoveTableDlg::SetForceCopyTable()
{
aBtnCopy.Check(true);
aBtnMove.Disable();
aBtnCopy.Disable();
}
void ScMoveTableDlg::EnableCopyTable(sal_Bool bFlag)
{
if(bFlag)
aBtnCopy.Enable();
else
aBtnCopy.Disable();
}
void ScMoveTableDlg::EnableRenameTable(sal_Bool bFlag)
{
bRenameTable = bFlag;
aEdTabName.Enable(bFlag);
aFtTabName.Enable(bFlag);
ResetRenameInput();
}
void ScMoveTableDlg::ResetRenameInput()
{
if (mbEverEdited)
// Don't reset the name when the sheet name has ever been edited.
return;
if (!aEdTabName.IsEnabled())
{
aEdTabName.SetText(String());
return;
}
bool bVal = aBtnCopy.IsChecked();
if (bVal)
{
// copy
ScDocument* pDoc = GetSelectedDoc();
if (pDoc)
{
rtl::OUString aStr = maDefaultName;
pDoc->CreateValidTabName(aStr);
aEdTabName.SetText(aStr);
}
else
aEdTabName.SetText(maDefaultName);
}
else
// move
aEdTabName.SetText(maDefaultName);
CheckNewTabName();
}
void ScMoveTableDlg::CheckNewTabName()
{
const rtl::OUString aNewName = aEdTabName.GetText();
if (aNewName.isEmpty())
{
// New sheet name is empty. This is not good.
aFtWarn.SetText(maStrTabNameEmpty);
aFtWarn.Show();
aBtnOk.Disable();
return;
}
if (!ScDocument::ValidTabName(aNewName))
{
// New sheet name contains invalid characters.
aFtWarn.SetText(maStrTabNameInvalid);
aFtWarn.Show();
aBtnOk.Disable();
return;
}
bool bFound = false;
sal_uInt16 nLast = aLbTable.GetEntryCount() - 1;
for ( sal_uInt16 i=0; i<=nLast; ++i )
{
if ( aNewName.equals(aLbTable.GetEntry(i)) )
{
if (aBtnMove.IsChecked() &&
aLbDoc.GetSelectEntryPos() == 0 &&
maDefaultName.equals(aEdTabName.GetText()))
// Move inside same document, thus same name is allowed.
bFound = false;
else
bFound = true;
}
}
if ( bFound )
{
aFtWarn.SetText(maStrTabNameUsed);
aFtWarn.Show();
aBtnOk.Disable();
}
else
{
aFtWarn.Hide();
aBtnOk.Enable();
}
}
ScDocument* ScMoveTableDlg::GetSelectedDoc()
{
sal_uInt16 nPos = aLbDoc.GetSelectEntryPos();
return static_cast<ScDocument*>(aLbDoc.GetEntryData(nPos));
}
//------------------------------------------------------------------------
void ScMoveTableDlg::Init()
{
aBtnOk.SetClickHdl ( LINK( this, ScMoveTableDlg, OkHdl ) );
aLbDoc.SetSelectHdl ( LINK( this, ScMoveTableDlg, SelHdl ) );
aBtnCopy.SetToggleHdl( LINK( this, ScMoveTableDlg, CheckBtnHdl ) );
aEdTabName.SetModifyHdl( LINK( this, ScMoveTableDlg, CheckNameHdl ) );
aBtnMove.Check( true );
aBtnCopy.Check( false );
aEdTabName.Enable(false);
aFtWarn.SetControlBackground( Color( COL_YELLOW ) );
aFtWarn.Hide();
InitDocListBox();
SelHdl( &aLbDoc );
}
//------------------------------------------------------------------------
void ScMoveTableDlg::InitDocListBox()
{
SfxObjectShell* pSh = SfxObjectShell::GetFirst();
ScDocShell* pScSh = NULL;
sal_uInt16 nSelPos = 0;
sal_uInt16 i = 0;
String aEntryName;
aLbDoc.Clear();
aLbDoc.SetUpdateMode( false );
while ( pSh )
{
pScSh = PTR_CAST( ScDocShell, pSh );
if ( pScSh )
{
aEntryName = pScSh->GetTitle();
if ( pScSh == SfxObjectShell::Current() )
{
nSelPos = i;
aEntryName += sal_Unicode( ' ' );
aEntryName += String( ScResId( STR_CURRENTDOC ) );
}
aLbDoc.InsertEntry( aEntryName, i );
aLbDoc.SetEntryData( i, (void*)pScSh->GetDocument() );
i++;
}
pSh = SfxObjectShell::GetNext( *pSh );
}
aLbDoc.SetUpdateMode( sal_True );
aLbDoc.InsertEntry( String( ScResId( STR_NEWDOC ) ) );
aLbDoc.SelectEntryPos( nSelPos );
}
//------------------------------------------------------------------------
// Handler:
IMPL_LINK( ScMoveTableDlg, CheckBtnHdl, void *, pBtn )
{
if (pBtn == &aBtnCopy)
ResetRenameInput();
return 0;
}
IMPL_LINK( ScMoveTableDlg, OkHdl, void *, EMPTYARG )
{
sal_uInt16 nDocSel = aLbDoc.GetSelectEntryPos();
sal_uInt16 nDocLast = aLbDoc.GetEntryCount()-1;
sal_uInt16 nTabSel = aLbTable.GetSelectEntryPos();
sal_uInt16 nTabLast = aLbTable.GetEntryCount()-1;
nDocument = (nDocSel != nDocLast) ? nDocSel : SC_DOC_NEW;
nTable = (nTabSel != nTabLast) ? static_cast<SCTAB>(nTabSel) : SC_TAB_APPEND;
bCopyTable = aBtnCopy.IsChecked();
if (bCopyTable)
{
// Return an empty string when the new name is the same as the
// automatic name assigned by the document.
rtl::OUString aCopyName = maDefaultName;
ScDocument* pDoc = GetSelectedDoc();
if (pDoc)
pDoc->CreateValidTabName(aCopyName);
if (aCopyName == rtl::OUString(aEdTabName.GetText()))
aEdTabName.SetText( rtl::OUString() );
}
else
{
// Return an empty string, when the new name is the same as the
// original name.
if (maDefaultName.equals(aEdTabName.GetText()))
aEdTabName.SetText(rtl::OUString());
}
EndDialog( RET_OK );
return 0;
}
IMPL_LINK( ScMoveTableDlg, SelHdl, ListBox *, pLb )
{
if ( pLb == &aLbDoc )
{
ScDocument* pDoc = GetSelectedDoc();
rtl::OUString aName;
aLbTable.Clear();
aLbTable.SetUpdateMode( false );
if ( pDoc )
{
SCTAB nLast = pDoc->GetTableCount()-1;
for ( SCTAB i=0; i<=nLast; i++ )
{
pDoc->GetName( i, aName );
aLbTable.InsertEntry( aName, static_cast<sal_uInt16>(i) );
}
}
aLbTable.InsertEntry( ScGlobal::GetRscString(STR_MOVE_TO_END) );
aLbTable.SetUpdateMode( sal_True );
aLbTable.SelectEntryPos( 0 );
ResetRenameInput();
}
return 0;
}
IMPL_LINK( ScMoveTableDlg, CheckNameHdl, Edit *, pEdt )
{
if ( pEdt == &aEdTabName )
{
mbEverEdited = true;
CheckNewTabName();
}
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|