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
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#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(vcl::Window* pParent, const OUString& rDefault)
: ModalDialog ( pParent, "MoveCopySheetDialog", "modules/scalc/ui/movecopysheet.ui" ),
maDefaultName( rDefault ),
mnCurrentDocPos( 0 ),
nDocument ( 0 ),
nTable ( 0 ),
bCopyTable ( false ),
bRenameTable( false ),
mbEverEdited( false )
{
get(pBtnMove, "move");
get(pBtnCopy, "copy");
get(pLbDoc, "toDocument");
assert(pLbDoc->GetEntryCount() == 2);
msCurrentDoc = pLbDoc->GetEntry(0);
msNewDoc = pLbDoc->GetEntry(1);
pLbDoc->Clear();
assert(pLbDoc->GetEntryCount() == 0);
get(pLbTable, "insertBefore");
pLbTable->set_height_request(pLbTable->GetTextHeight() * 8);
get(pEdTabName, "newName");
get(pFtWarn, "newNameWarn");
get(pBtnOk, "ok");
msStrTabNameUsed = get<FixedText>("warnunused")->GetText();
msStrTabNameEmpty = get<FixedText>("warnempty")->GetText();
msStrTabNameInvalid = get<FixedText>("warninvalid")->GetText();
Init();
}
ScMoveTableDlg::~ScMoveTableDlg()
{
disposeOnce();
}
void ScMoveTableDlg::dispose()
{
pBtnMove.clear();
pBtnCopy.clear();
pLbDoc.clear();
pLbTable.clear();
pEdTabName.clear();
pFtWarn.clear();
pBtnOk.clear();
ModalDialog::dispose();
}
void ScMoveTableDlg::GetTabNameString( OUString& rString ) const
{
rString = pEdTabName->GetText();
}
void ScMoveTableDlg::SetForceCopyTable()
{
pBtnCopy->Check();
pBtnMove->Disable();
pBtnCopy->Disable();
}
void ScMoveTableDlg::EnableRenameTable(bool bFlag)
{
bRenameTable = bFlag;
pEdTabName->Enable(bFlag);
ResetRenameInput();
}
void ScMoveTableDlg::ResetRenameInput()
{
if (mbEverEdited)
{
// Don't reset the name when the sheet name has ever been edited.
// But check the name, as this is also called for change of copy/move
// buttons and document listbox selection.
CheckNewTabName();
return;
}
if (!pEdTabName->IsEnabled())
{
pEdTabName->SetText(OUString());
return;
}
bool bVal = pBtnCopy->IsChecked();
if (bVal)
{
// copy
ScDocument* pDoc = GetSelectedDoc();
if (pDoc)
{
OUString aStr = maDefaultName;
pDoc->CreateValidTabName(aStr);
pEdTabName->SetText(aStr);
}
else
pEdTabName->SetText(maDefaultName);
}
else
// move
pEdTabName->SetText(maDefaultName);
CheckNewTabName();
}
void ScMoveTableDlg::CheckNewTabName()
{
const OUString aNewName = pEdTabName->GetText();
if (aNewName.isEmpty())
{
// New sheet name is empty. This is not good.
pFtWarn->Show(true);
pFtWarn->SetControlBackground(Color(COL_YELLOW));
pFtWarn->SetText(msStrTabNameEmpty);
pBtnOk->Disable();
return;
}
if (!ScDocument::ValidTabName(aNewName))
{
// New sheet name contains invalid characters.
pFtWarn->Show(true);
pFtWarn->SetControlBackground(Color(COL_YELLOW));
pFtWarn->SetText(msStrTabNameInvalid);
pBtnOk->Disable();
return;
}
bool bMoveInCurrentDoc = (pBtnMove->IsChecked() && IsCurrentDocSelected());
bool bFound = false;
sal_uInt16 nLast = pLbTable->GetEntryCount() - 1;
for ( sal_uInt16 i=0; i<=nLast && !bFound; ++i )
{
if ( aNewName.equals(pLbTable->GetEntry(i)) )
{
// Only for move within same document the same name is allowed.
if (!bMoveInCurrentDoc || !maDefaultName.equals( pEdTabName->GetText()))
bFound = true;
}
}
if ( bFound )
{
pFtWarn->Show(true);
pFtWarn->SetControlBackground(Color(COL_YELLOW));
pFtWarn->SetText(msStrTabNameUsed);
pBtnOk->Disable();
}
else
{
pFtWarn->Hide();
pFtWarn->SetControlBackground();
pFtWarn->SetText(OUString());
pBtnOk->Enable();
}
}
ScDocument* ScMoveTableDlg::GetSelectedDoc()
{
sal_Int32 nPos = pLbDoc->GetSelectEntryPos();
return static_cast<ScDocument*>(pLbDoc->GetEntryData(nPos));
}
bool ScMoveTableDlg::IsCurrentDocSelected() const
{
return pLbDoc->GetSelectEntryPos() == mnCurrentDocPos;
}
void ScMoveTableDlg::Init()
{
pBtnOk->SetClickHdl ( LINK( this, ScMoveTableDlg, OkHdl ) );
pLbDoc->SetSelectHdl ( LINK( this, ScMoveTableDlg, SelHdl ) );
pBtnCopy->SetToggleHdl( LINK( this, ScMoveTableDlg, CheckBtnHdl ) );
pEdTabName->SetModifyHdl( LINK( this, ScMoveTableDlg, CheckNameHdl ) );
pBtnMove->Check();
pBtnCopy->Check( false );
pEdTabName->Enable(false);
pFtWarn->Hide();
InitDocListBox();
SelHdl( pLbDoc );
}
void ScMoveTableDlg::InitDocListBox()
{
SfxObjectShell* pSh = SfxObjectShell::GetFirst();
ScDocShell* pScSh = NULL;
sal_uInt16 nSelPos = 0;
sal_uInt16 i = 0;
OUString aEntryName;
pLbDoc->Clear();
pLbDoc->SetUpdateMode( false );
while ( pSh )
{
pScSh = PTR_CAST( ScDocShell, pSh );
if ( pScSh )
{
aEntryName = pScSh->GetTitle();
if ( pScSh == SfxObjectShell::Current() )
{
mnCurrentDocPos = nSelPos = i;
aEntryName += " ";
aEntryName += msCurrentDoc;
}
pLbDoc->InsertEntry( aEntryName, i );
pLbDoc->SetEntryData( i, static_cast<void*>(&pScSh->GetDocument()) );
i++;
}
pSh = SfxObjectShell::GetNext( *pSh );
}
pLbDoc->SetUpdateMode( true );
pLbDoc->InsertEntry(msNewDoc);
pLbDoc->SelectEntryPos( nSelPos );
}
// Handler:
IMPL_LINK( ScMoveTableDlg, CheckBtnHdl, void *, pBtn )
{
if (pBtn == pBtnCopy)
ResetRenameInput();
return 0;
}
IMPL_LINK_NOARG(ScMoveTableDlg, OkHdl)
{
sal_uInt16 nDocSel = pLbDoc->GetSelectEntryPos();
sal_uInt16 nDocLast = pLbDoc->GetEntryCount()-1;
sal_uInt16 nTabSel = pLbTable->GetSelectEntryPos();
sal_uInt16 nTabLast = pLbTable->GetEntryCount()-1;
nDocument = (nDocSel != nDocLast) ? nDocSel : SC_DOC_NEW;
nTable = (nTabSel != nTabLast) ? static_cast<SCTAB>(nTabSel) : SC_TAB_APPEND;
bCopyTable = pBtnCopy->IsChecked();
if (bCopyTable)
{
// Return an empty string when the new name is the same as the
// automatic name assigned by the document.
OUString aCopyName = maDefaultName;
ScDocument* pDoc = GetSelectedDoc();
if (pDoc)
pDoc->CreateValidTabName(aCopyName);
if (aCopyName == pEdTabName->GetText())
pEdTabName->SetText( OUString() );
}
else
{
// Return an empty string, when the new name is the same as the
// original name.
if (maDefaultName.equals(pEdTabName->GetText()))
pEdTabName->SetText(OUString());
}
EndDialog( RET_OK );
return 0;
}
IMPL_LINK( ScMoveTableDlg, SelHdl, ListBox *, pLb )
{
if ( pLb == pLbDoc )
{
ScDocument* pDoc = GetSelectedDoc();
OUString aName;
pLbTable->Clear();
pLbTable->SetUpdateMode( false );
if ( pDoc )
{
SCTAB nLast = pDoc->GetTableCount()-1;
for ( SCTAB i=0; i<=nLast; i++ )
{
pDoc->GetName( i, aName );
pLbTable->InsertEntry( aName, static_cast<sal_uInt16>(i) );
}
}
pLbTable->InsertEntry( ScGlobal::GetRscString(STR_MOVE_TO_END) );
pLbTable->SetUpdateMode( true );
pLbTable->SelectEntryPos( 0 );
ResetRenameInput();
}
return 0;
}
IMPL_LINK( ScMoveTableDlg, CheckNameHdl, Edit *, pEdt )
{
if ( pEdt == pEdTabName )
{
mbEverEdited = true;
CheckNewTabName();
}
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|