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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* Version: MPL 1.1 / GPLv3+ / LGPLv3+
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (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.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Initial Developer of the Original Code is
* Novell Inc.
* Portions created by the Initial Developer are Copyright (C) 2010 the
* Initial Developer. All Rights Reserved.
*
* Contributor(s): Amelia Wang <amwang@novell.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 3 or later (the "GPLv3+"), or
* the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
* in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
* instead of those above.
*/
#undef SC_DLLIMPLEMENTATION
//------------------------------------------------------------------
#include "datafdlg.hxx"
#include "scresid.hxx"
#include "datafdlg.hrc"
#include "viewdata.hxx"
#include "docsh.hxx"
#include "refundo.hxx"
#include "undodat.hxx"
#include "rtl/ustrbuf.hxx"
#define HDL(hdl) LINK( this, ScDataFormDlg, hdl )
using ::rtl::OUStringBuffer;
//zhangyun
ScDataFormDlg::ScDataFormDlg( Window* pParent, ScTabViewShell* pTabViewShellOri) :
ModalDialog ( pParent, ScResId( RID_SCDLG_DATAFORM ) ),
aBtnNew ( this, ScResId( BTN_DATAFORM_NEW ) ),
aBtnDelete ( this, ScResId( BTN_DATAFORM_DELETE ) ),
aBtnRestore ( this, ScResId( BTN_DATAFORM_RESTORE ) ),
aBtnPrev ( this, ScResId( BTN_DATAFORM_PREV ) ),
aBtnNext ( this, ScResId( BTN_DATAFORM_NEXT ) ),
aBtnClose ( this, ScResId( BTN_DATAFORM_CLOSE ) ),
aSlider ( this, ScResId( WND_DATAFORM_SCROLLBAR ) ),
aFixedText ( this, ScResId( LAB_DATAFORM_RECORDNO ) )
{
pTabViewShell = pTabViewShellOri;
FreeResource();
//read header form current document, and add new controls
OSL_ENSURE( pTabViewShell, "pTabViewShell is NULL! :-/" );
ScViewData* pViewData = pTabViewShell->GetViewData();
pDoc = pViewData->GetDocument();
if (pDoc)
{
ScRange aRange;
pViewData->GetSimpleArea( aRange );
ScAddress aStart = aRange.aStart;
ScAddress aEnd = aRange.aEnd;
nStartCol = aStart.Col();
nEndCol = aEnd.Col();
nStartRow = aStart.Row();
nEndRow = aEnd.Row();
nTab = pViewData->GetTabNo();
//if there is no selection
if ((nStartCol == nEndCol) && (nStartRow == nEndRow))
bNoSelection = true;
if (bNoSelection)
{
//find last not blank cell in row
for (int i=1;i<=MAX_DATAFORM_COLS;i++)
{
String aColName;
nEndCol++;
pDoc->GetString( nEndCol, nStartRow, nTab, aColName );
int nColWidth = pDoc->GetColWidth( nEndCol, nTab );
if ( aColName.Len() == 0 && nColWidth)
{
nEndCol--;
break;
}
}
//find first not blank cell in row
for (int i=1;i<=MAX_DATAFORM_COLS;i++)
{
String aColName;
if (nStartCol <= 0)
break;
nStartCol--;
pDoc->GetString( nStartCol, nStartRow, nTab, aColName );
int nColWidth = pDoc->GetColWidth( nEndCol, nTab );
if ( aColName.Len() == 0 && nColWidth)
{
nStartCol++;
break;
}
}
//skip leading hide column
for (int i=1;i<=MAX_DATAFORM_COLS;i++)
{
int nColWidth = pDoc->GetColWidth( nStartCol, nTab );
if (nColWidth)
break;
nStartCol++;
}
if (nEndCol < nStartCol)
nEndCol = nStartCol;
//find last not blank cell in row
for (int i=1;i<=MAX_DATAFORM_ROWS;i++)
{
String aColName;
nEndRow++;
pDoc->GetString( nStartCol, nEndRow, nTab, aColName );
if ( aColName.Len() == 0 )
{
nEndRow--;
break;
}
}
//find first not blank cell in row
for (int i=1;i<=MAX_DATAFORM_ROWS;i++)
{
String aColName;
if (nStartRow <= 0)
break;
nStartRow--;
pDoc->GetString( nStartCol, nStartRow, nTab, aColName );
if ( aColName.Len() == 0 )
{
nStartRow++;
break;
}
}
if (nEndRow < nStartRow)
nEndRow = nStartRow;
}
nCurrentRow = nStartRow + 1;
String aFieldName;
int nTop = 12;
Size nFixedSize(FIXED_WIDTH, CTRL_HEIGHT );
Size nEditSize(EDIT_WIDTH, CTRL_HEIGHT );
aColLength = nEndCol - nStartCol + 1;
//new the controls
maFixedTexts.reserve(aColLength);
maEdits.reserve(aColLength);
for(sal_uInt16 nIndex = 0; nIndex < aColLength; nIndex++)
{
pDoc->GetString( nIndex + nStartCol, nStartRow, nTab, aFieldName );
int nColWidth = pDoc->GetColWidth( nIndex + nStartCol, nTab );
if (nColWidth)
{
maFixedTexts.push_back( new FixedText(this) );
maEdits.push_back( new Edit(this, WB_BORDER) );
maFixedTexts[nIndex].SetSizePixel(nFixedSize);
maEdits[nIndex].SetSizePixel(nEditSize);
maFixedTexts[nIndex].SetPosPixel(Point(FIXED_LEFT, nTop));
maEdits[nIndex].SetPosPixel(Point(EDIT_LEFT, nTop));
maFixedTexts[nIndex].SetText(aFieldName);
maFixedTexts[nIndex].Show();
maEdits[nIndex].Show();
nTop += LINE_HEIGHT;
}
else
{
maFixedTexts.push_back( NULL );
maEdits.push_back( NULL );
}
if (!maEdits.is_null(nIndex))
maEdits[nIndex].SetModifyHdl( HDL(Impl_DataModifyHdl) );
}
Size nDialogSize = this->GetSizePixel();
if (nTop > nDialogSize.Height())
{
nDialogSize.setHeight(nTop);
this->SetSizePixel(nDialogSize);
}
Size nScrollSize = aSlider.GetSizePixel();
nScrollSize.setHeight(nDialogSize.Height()-20);
aSlider.SetSizePixel(nScrollSize);
}
FillCtrls(nCurrentRow);
aSlider.SetPageSize( 10 );
aSlider.SetVisibleSize( 1 );
aSlider.SetLineSize( 1 );
aSlider.SetRange( Range( 0, nEndRow - nStartRow + 1) );
aSlider.Show();
aBtnNew.SetClickHdl ( HDL(Impl_NewHdl) );
aBtnPrev.SetClickHdl ( HDL(Impl_PrevHdl) );
aBtnNext.SetClickHdl ( HDL(Impl_NextHdl) );
aBtnRestore.SetClickHdl ( HDL(Impl_RestoreHdl) );
aBtnDelete.SetClickHdl ( HDL(Impl_DeleteHdl) );
aBtnClose.SetClickHdl ( HDL(Impl_CloseHdl) );
aSlider.SetEndScrollHdl( HDL( Impl_ScrollHdl ) );
SetButtonState();
}
ScDataFormDlg::~ScDataFormDlg()
{
}
void ScDataFormDlg::FillCtrls(SCROW /*nCurrentRow*/)
{
String aFieldName;
for (sal_uInt16 i = 0; i < aColLength; ++i)
{
if (!maEdits.is_null(i))
{
if (nCurrentRow<=nEndRow)
{
pDoc->GetString( i + nStartCol, nCurrentRow, nTab, aFieldName );
maEdits[i].SetText(aFieldName);
}
else
maEdits[i].SetText(String());
}
}
if (nCurrentRow <= nEndRow)
{
OUStringBuffer aBuf;
aBuf.append(static_cast<sal_Int32>(nCurrentRow - nStartRow));
aBuf.appendAscii(" / ");
aBuf.append(static_cast<sal_Int32>(nEndRow - nStartRow));
aFixedText.SetText(aBuf.makeStringAndClear());
}
else
aFixedText.SetText(String(ScResId(STR_NEW_RECORD)));
aSlider.SetThumbPos(nCurrentRow-nStartRow-1);
}
IMPL_LINK( ScDataFormDlg, Impl_DataModifyHdl, Edit*, pEdit)
{
if ( pEdit->IsModified() )
aBtnRestore.Enable( true );
return 0;
}
IMPL_LINK_NOARG(ScDataFormDlg, Impl_NewHdl)
{
ScViewData* pViewData = pTabViewShell->GetViewData();
ScDocShell* pDocSh = pViewData->GetDocShell();
if ( pDoc )
{
bool bHasData = false;
boost::ptr_vector<Edit>::iterator itr = maEdits.begin(), itrEnd = maEdits.end();
for(; itr != itrEnd; ++itr)
if (!boost::is_null(itr))
if ( (*itr).GetText().Len() != 0 )
{
bHasData = true;
break;
}
if ( bHasData )
{
pTabViewShell->DataFormPutData( nCurrentRow , nStartRow , nStartCol , nEndRow , nEndCol , maEdits , aColLength );
nCurrentRow++;
if (nCurrentRow >= nEndRow + 2)
{
nEndRow ++ ;
aSlider.SetRange( Range( 0, nEndRow - nStartRow + 1) );
}
SetButtonState();
FillCtrls(nCurrentRow);
pDocSh->SetDocumentModified();
pDocSh->PostPaintGridAll();
}
}
return 0;
}
IMPL_LINK_NOARG(ScDataFormDlg, Impl_PrevHdl)
{
if (pDoc)
{
if ( nCurrentRow > nStartRow +1 )
nCurrentRow--;
SetButtonState();
FillCtrls(nCurrentRow);
}
return 0;
}
IMPL_LINK_NOARG(ScDataFormDlg, Impl_NextHdl)
{
if (pDoc)
{
if ( nCurrentRow <= nEndRow)
nCurrentRow++;
SetButtonState();
FillCtrls(nCurrentRow);
}
return 0;
}
IMPL_LINK_NOARG(ScDataFormDlg, Impl_RestoreHdl)
{
if (pDoc)
{
FillCtrls(nCurrentRow);
}
return 0;
}
IMPL_LINK_NOARG(ScDataFormDlg, Impl_DeleteHdl)
{
ScViewData* pViewData = pTabViewShell->GetViewData();
ScDocShell* pDocSh = pViewData->GetDocShell();
if (pDoc)
{
ScRange aRange(nStartCol, nCurrentRow, nTab, nEndCol, nCurrentRow, nTab);
pDoc->DeleteRow(aRange);
nEndRow--;
SetButtonState();
pDocSh->GetUndoManager()->Clear();
FillCtrls(nCurrentRow);
pDocSh->SetDocumentModified();
pDocSh->PostPaintGridAll();
}
return 0;
}
IMPL_LINK_NOARG(ScDataFormDlg, Impl_CloseHdl)
{
EndDialog( );
return 0;
}
IMPL_LINK_NOARG(ScDataFormDlg, Impl_ScrollHdl)
{
long nOffset = aSlider.GetThumbPos();
nCurrentRow = nStartRow + nOffset + 1;
SetButtonState();
FillCtrls(nCurrentRow);
return 0;
}
void ScDataFormDlg::SetButtonState()
{
if (nCurrentRow > nEndRow)
{
aBtnDelete.Enable( false );
aBtnNext.Enable( false );
}
else
{
aBtnDelete.Enable( true );
aBtnNext.Enable( true );
}
if (nCurrentRow == nStartRow + 1)
aBtnPrev.Enable( false );
else
aBtnPrev.Enable( true );
aBtnRestore.Enable( false );
if ( maEdits.size()>=1 && !maEdits.is_null(0) )
maEdits[0].GrabFocus();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|