Line 0
Link Here
|
|
|
1 |
/************************************************************************* |
2 |
* |
3 |
* OpenOffice.org - a multi-platform office productivity suite |
4 |
* |
5 |
* $RCSfile: datafdlg.cxx,v $ |
6 |
* |
7 |
* $Revision: 1.00 $ |
8 |
* |
9 |
* last change: $Author: kz $ $Date: 2006/07/21 14:04:33 $ |
10 |
* |
11 |
* The Contents of this file are made available subject to |
12 |
* the terms of GNU Lesser General Public License Version 2.1. |
13 |
* |
14 |
* |
15 |
* GNU Lesser General Public License Version 2.1 |
16 |
* ============================================= |
17 |
* Copyright 2005 by Sun Microsystems, Inc. |
18 |
* 901 San Antonio Road, Palo Alto, CA 94303, USA |
19 |
* |
20 |
* This library is free software; you can redistribute it and/or |
21 |
* modify it under the terms of the GNU Lesser General Public |
22 |
* License version 2.1, as published by the Free Software Foundation. |
23 |
* |
24 |
* This library is distributed in the hope that it will be useful, |
25 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
26 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
27 |
* Lesser General Public License for more details. |
28 |
* |
29 |
* You should have received a copy of the GNU Lesser General Public |
30 |
* License along with this library; if not, write to the Free Software |
31 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
32 |
* MA 02111-1307 USA |
33 |
* |
34 |
************************************************************************/ |
35 |
|
36 |
// MARKER(update_precomp.py): autogen include statement, do not remove |
37 |
#include "precompiled_sc.hxx" |
38 |
|
39 |
#undef SC_DLLIMPLEMENTATION |
40 |
|
41 |
//------------------------------------------------------------------ |
42 |
|
43 |
#include "datafdlg.hxx" |
44 |
#include "scresid.hxx" |
45 |
#include "datafdlg.hrc" |
46 |
#include "viewdata.hxx" |
47 |
#include "document.hxx" |
48 |
#include "docsh.hxx" |
49 |
|
50 |
static BYTE nDelItemChecked=0; |
51 |
#define HDL(hdl) LINK( this, ScDataFormDlg, hdl ) |
52 |
|
53 |
//zhangyun |
54 |
ScDataFormDlg::ScDataFormDlg( Window* pParent, ScTabViewShell* pTabViewShellOri) : |
55 |
ModalDialog ( pParent, ScResId( RID_SCDLG_DATAFORM ) ), |
56 |
// |
57 |
aFixedText ( this, ScResId( LAB_DATAFORM_RECORDNO ) ), |
58 |
aBtnNew ( this, ScResId( BTN_DATAFORM_NEW ) ), |
59 |
aBtnDelete ( this, ScResId( BTN_DATAFORM_DELETE ) ), |
60 |
aBtnRestore ( this, ScResId( BTN_DATAFORM_RESTORE ) ), |
61 |
aBtnLast ( this, ScResId( BTN_DATAFORM_LAST ) ), |
62 |
aBtnNext ( this, ScResId( BTN_DATAFORM_NEXT ) ), |
63 |
aBtnClose ( this, ScResId( BTN_DATAFORM_CLOSE ) ), |
64 |
aSlider ( this, ScResId( WND_DATAFORM_SCROLLBAR ) ) |
65 |
//aSlider ( this, ScResId( WND_DATAFORM_SCROLLBAR ) ), |
66 |
//aFixedText1 ( this, ScResId( FT_DATAFORM_FIXEDTEXT1 ) ), |
67 |
//aEdit1 ( this, ScResId( ED_DATAFORM_EDIT1 ) ) |
68 |
{ |
69 |
pTabViewShell = pTabViewShellOri; |
70 |
FreeResource(); |
71 |
//read header form current document, and add new controls |
72 |
DBG_ASSERT( pTabViewShell, "pTabViewShell is NULL! :-/" ); |
73 |
ScViewData* pViewData = pTabViewShell->GetViewData(); |
74 |
|
75 |
//int aColLength=20; |
76 |
//FixedText** pFixedTexts; |
77 |
//Edit** pEdits; |
78 |
//pFixedTexts = new FixedText*[aColLength]; |
79 |
//pEdits = new Edit*[aColLength]; |
80 |
|
81 |
pDoc = pViewData->GetDocument(); |
82 |
if (pDoc) |
83 |
{ |
84 |
ScRange aRange; |
85 |
pViewData->GetSimpleArea( aRange ); |
86 |
ScAddress aStart = aRange.aStart; |
87 |
ScAddress aEnd = aRange.aEnd; |
88 |
|
89 |
nStartCol = aStart.Col(); |
90 |
nEndCol = aEnd.Col(); |
91 |
nStartRow = aStart.Row(); |
92 |
nEndRow = aEnd.Row(); |
93 |
|
94 |
nTab = pViewData->GetTabNo(); |
95 |
//if there is no selection |
96 |
if ((nStartCol == nEndCol) && (nStartRow == nEndRow)) |
97 |
bNoSelection = TRUE; |
98 |
|
99 |
if (bNoSelection) |
100 |
{ |
101 |
//find last not blank cell in row |
102 |
for (int i=1;i<=MAX_DATAFORM_COLS;i++) |
103 |
{ |
104 |
String aColName; |
105 |
nEndCol++; |
106 |
pDoc->GetString( nEndCol, nStartRow, nTab, aColName ); |
107 |
int nColWidth = pDoc->GetColWidth( nEndCol, nTab ); |
108 |
if ( aColName.Len() == 0 && nColWidth) |
109 |
{ |
110 |
nEndCol--; |
111 |
break; |
112 |
} |
113 |
} |
114 |
|
115 |
//find first not blank cell in row |
116 |
for (int i=1;i<=MAX_DATAFORM_COLS;i++) |
117 |
{ |
118 |
String aColName; |
119 |
if (nStartCol <= 0) |
120 |
break; |
121 |
nStartCol--; |
122 |
|
123 |
pDoc->GetString( nStartCol, nStartRow, nTab, aColName ); |
124 |
int nColWidth = pDoc->GetColWidth( nEndCol, nTab ); |
125 |
if ( aColName.Len() == 0 && nColWidth) |
126 |
{ |
127 |
nStartCol++; |
128 |
break; |
129 |
} |
130 |
} |
131 |
|
132 |
//skip leading hide column |
133 |
for (int i=1;i<=MAX_DATAFORM_COLS;i++) |
134 |
{ |
135 |
String aColName; |
136 |
int nColWidth = pDoc->GetColWidth( nStartCol, nTab ); |
137 |
if (nColWidth) |
138 |
break; |
139 |
nStartCol++; |
140 |
} |
141 |
|
142 |
if (nEndCol < nStartCol) |
143 |
nEndCol = nStartCol; |
144 |
|
145 |
//find last not blank cell in row |
146 |
for (int i=1;i<=MAX_DATAFORM_ROWS;i++) |
147 |
{ |
148 |
String aColName; |
149 |
nEndRow++; |
150 |
pDoc->GetString( nStartCol, nEndRow, nTab, aColName ); |
151 |
if ( aColName.Len() == 0 ) |
152 |
{ |
153 |
nEndRow--; |
154 |
break; |
155 |
} |
156 |
} |
157 |
|
158 |
//find first not blank cell in row |
159 |
for (int i=1;i<=MAX_DATAFORM_ROWS;i++) |
160 |
{ |
161 |
String aColName; |
162 |
if (nStartRow <= 0) |
163 |
break; |
164 |
nStartRow--; |
165 |
|
166 |
pDoc->GetString( nStartCol, nStartRow, nTab, aColName ); |
167 |
if ( aColName.Len() == 0 ) |
168 |
{ |
169 |
nStartRow++; |
170 |
break; |
171 |
} |
172 |
} |
173 |
|
174 |
if (nEndRow < nStartRow) |
175 |
nEndRow = nStartRow; |
176 |
} |
177 |
|
178 |
aCurrentRow = nStartRow + 1; |
179 |
|
180 |
SCCOL col; |
181 |
String aFieldName; |
182 |
|
183 |
int nTop = 12; |
184 |
|
185 |
Size nFixedSize(FIXED_WIDTH, CTRL_HEIGHT ); |
186 |
Size nEditSize(EDIT_WIDTH, CTRL_HEIGHT ); |
187 |
|
188 |
//pFtArray = new FixedText(this); |
189 |
aColLength = nEndCol - nStartCol + 1; |
190 |
|
191 |
//new the controls |
192 |
pFixedTexts = new FixedText*[aColLength]; |
193 |
pEdits = new Edit*[aColLength]; |
194 |
|
195 |
for(sal_uInt16 nIndex = 0; nIndex < aColLength; nIndex++) |
196 |
{ |
197 |
pDoc->GetString( nIndex + nStartCol, nStartRow, nTab, aFieldName ); |
198 |
int nColWidth = pDoc->GetColWidth( nIndex + nStartCol, nTab ); |
199 |
if (nColWidth) |
200 |
{ |
201 |
pFixedTexts[nIndex] = new FixedText(this); |
202 |
pEdits[nIndex] = new Edit(this, WB_BORDER); |
203 |
|
204 |
pFixedTexts[nIndex]->SetSizePixel(nFixedSize); |
205 |
pEdits[nIndex]->SetSizePixel(nEditSize); |
206 |
pFixedTexts[nIndex]->SetPosPixel(Point(FIXED_LEFT, nTop)); |
207 |
pEdits[nIndex]->SetPosPixel(Point(EDIT_LEFT, nTop)); |
208 |
//pFixedTexts[nIndex]->SetText(String::CreateFromAscii("W4W-Filter Nr. ")); |
209 |
pFixedTexts[nIndex]->SetText(aFieldName); |
210 |
pFixedTexts[nIndex]->Show(); |
211 |
pEdits[nIndex]->Show(); |
212 |
|
213 |
nTop += LINE_HEIGHT; |
214 |
} |
215 |
else |
216 |
{ |
217 |
pFixedTexts[nIndex] = NULL; |
218 |
pEdits[nIndex] = NULL; |
219 |
} |
220 |
} |
221 |
|
222 |
Size nDialogSize = this->GetSizePixel(); |
223 |
if (nTop > nDialogSize.Height()) |
224 |
{ |
225 |
nDialogSize.setHeight(nTop); |
226 |
this->SetSizePixel(nDialogSize); |
227 |
} |
228 |
Size nScrollSize = aSlider.GetSizePixel(); |
229 |
nScrollSize.setHeight(nDialogSize.Height()-20); |
230 |
aSlider.SetSizePixel(nScrollSize); |
231 |
} |
232 |
|
233 |
FillCtrls(aCurrentRow); |
234 |
|
235 |
aSlider.SetPageSize( 10 ); |
236 |
aSlider.SetVisibleSize( 1 ); |
237 |
aSlider.SetLineSize( 1 ); |
238 |
aSlider.SetRange( Range( 0, nEndRow - nStartRow + 1) ); |
239 |
aSlider.Show(); |
240 |
|
241 |
aBtnNew.SetClickHdl ( HDL(Impl_NewHdl) ); |
242 |
aBtnLast.SetClickHdl ( HDL(Impl_LastHdl) ); |
243 |
aBtnNext.SetClickHdl ( HDL(Impl_NextHdl) ); |
244 |
|
245 |
aBtnRestore.SetClickHdl ( HDL(Impl_RestoreHdl) ); |
246 |
aBtnDelete.SetClickHdl ( HDL(Impl_DeleteHdl) ); |
247 |
aBtnClose.SetClickHdl ( HDL(Impl_CloseHdl) ); |
248 |
|
249 |
aSlider.SetEndScrollHdl( HDL( Impl_ScrollHdl ) ); |
250 |
|
251 |
//end |
252 |
//FreeResource(); |
253 |
} |
254 |
|
255 |
__EXPORT ScDataFormDlg::~ScDataFormDlg() |
256 |
{ |
257 |
for(sal_uInt16 i = 0; i < aColLength; i++) |
258 |
{ |
259 |
if (pEdits[i]) |
260 |
delete pEdits[i]; |
261 |
if (pFixedTexts[i]) |
262 |
delete pFixedTexts[i]; |
263 |
} |
264 |
if (pEdits) |
265 |
delete pEdits; |
266 |
if (pFixedTexts) |
267 |
delete pFixedTexts; |
268 |
} |
269 |
|
270 |
void ScDataFormDlg::FillCtrls(SCROW nCurrentRow) |
271 |
{ |
272 |
//ScViewData* pViewData = pTabViewShell->GetViewData(); |
273 |
|
274 |
//pDoc = pViewData->GetDocument(); |
275 |
String aFieldName; |
276 |
int nRecordNum = nEndRow - nStartRow; |
277 |
for(sal_uInt16 i = 0; i < aColLength; i++) |
278 |
{ |
279 |
if (pEdits[i]) |
280 |
{ |
281 |
if (aCurrentRow<=nEndRow) |
282 |
{ |
283 |
pDoc->GetString( i + nStartCol, aCurrentRow, nTab, aFieldName ); |
284 |
pEdits[i]->SetText(aFieldName); |
285 |
} |
286 |
else |
287 |
pEdits[i]->SetText(String()); |
288 |
} |
289 |
} |
290 |
char sRecordStr[256]; |
291 |
sprintf(sRecordStr, "%i / %i", aCurrentRow-nStartRow, nRecordNum); |
292 |
if (aCurrentRow<=nEndRow) |
293 |
aFixedText.SetText(String::CreateFromAscii(sRecordStr)); |
294 |
else |
295 |
aFixedText.SetText(String::CreateFromAscii("New Record")); |
296 |
|
297 |
aSlider.SetThumbPos(aCurrentRow-nStartRow-1); |
298 |
} |
299 |
|
300 |
IMPL_LINK( ScDataFormDlg, Impl_NewHdl, PushButton*, pBtn) |
301 |
{ |
302 |
ScViewData* pViewData = pTabViewShell->GetViewData(); |
303 |
ScDocShell* pDocSh = pViewData->GetDocShell(); |
304 |
if (pDoc) |
305 |
{ |
306 |
for(sal_uInt16 i = 0; i < aColLength; i++) |
307 |
{ |
308 |
if (pEdits[i]) |
309 |
{ |
310 |
String aFieldName=pEdits[i]->GetText(); |
311 |
pDoc->SetString( nStartCol + i, aCurrentRow, nTab, aFieldName ); |
312 |
} |
313 |
} |
314 |
//String aFieldName=pEdArray->GetText(); |
315 |
|
316 |
//pDoc->SetString( nStartCol, nLastRow, nTab, aFieldName ); |
317 |
aCurrentRow++; |
318 |
if (aCurrentRow >= nEndRow + 2) |
319 |
{ |
320 |
nEndRow ++ ; |
321 |
aSlider.SetRange( Range( 0, nEndRow - nStartRow + 1) ); |
322 |
} |
323 |
FillCtrls(aCurrentRow); |
324 |
pDocSh->SetDocumentModified(); |
325 |
pDocSh->PostPaintGridAll(); |
326 |
|
327 |
} |
328 |
return 0; |
329 |
} |
330 |
|
331 |
IMPL_LINK( ScDataFormDlg, Impl_LastHdl, PushButton*, pBtn) |
332 |
{ |
333 |
if (pDoc) |
334 |
{ |
335 |
if ( aCurrentRow > nStartRow +1 ) |
336 |
aCurrentRow--; |
337 |
|
338 |
FillCtrls(aCurrentRow); |
339 |
} |
340 |
return 0; |
341 |
} |
342 |
|
343 |
IMPL_LINK( ScDataFormDlg, Impl_NextHdl, PushButton*, pBtn) |
344 |
{ |
345 |
if (pDoc) |
346 |
{ |
347 |
if ( aCurrentRow <= nEndRow) |
348 |
aCurrentRow++; |
349 |
|
350 |
FillCtrls(aCurrentRow); |
351 |
} |
352 |
return 0; |
353 |
} |
354 |
|
355 |
IMPL_LINK( ScDataFormDlg, Impl_RestoreHdl, PushButton*, pBtn) |
356 |
{ |
357 |
if (pDoc) |
358 |
{ |
359 |
FillCtrls(aCurrentRow); |
360 |
} |
361 |
return 0; |
362 |
} |
363 |
|
364 |
IMPL_LINK( ScDataFormDlg, Impl_DeleteHdl, PushButton*, pBtn) |
365 |
{ |
366 |
ScViewData* pViewData = pTabViewShell->GetViewData(); |
367 |
ScDocShell* pDocSh = pViewData->GetDocShell(); |
368 |
if (pDoc) |
369 |
{ |
370 |
ScRange aRange(nStartCol, aCurrentRow, nTab, nEndCol, aCurrentRow, nTab); |
371 |
pDoc->DeleteRow(aRange); |
372 |
|
373 |
FillCtrls(aCurrentRow); |
374 |
pDocSh->SetDocumentModified(); |
375 |
pDocSh->PostPaintGridAll(); |
376 |
} |
377 |
return 0; |
378 |
} |
379 |
|
380 |
IMPL_LINK( ScDataFormDlg, Impl_CloseHdl, PushButton*, pBtn) |
381 |
{ |
382 |
EndDialog( ); |
383 |
return 0; |
384 |
} |
385 |
|
386 |
IMPL_LINK( ScDataFormDlg, Impl_ScrollHdl, ScrollBar*, EMPTYARG) |
387 |
{ |
388 |
long nOffset = aSlider.GetThumbPos(); |
389 |
aCurrentRow = nStartRow + nOffset + 1; |
390 |
FillCtrls(aCurrentRow); |
391 |
return 0; |
392 |
} |