1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: datafdlg.cxx,v $
9 * last change: $Author: kz $ $Date: 2006/07/21 14:04:33 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
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
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.
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.
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,
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_sc.hxx"
39 #undef SC_DLLIMPLEMENTATION
41 //------------------------------------------------------------------
43 #include "datafdlg.hxx"
44 #include "scresid.hxx"
45 #include "datafdlg.hrc"
46 #include "viewdata.hxx"
47 //#include "document.hxx"
49 #include "refundo.hxx"
50 #include "undodat.hxx"
52 #define HDL(hdl) LINK( this, ScDataFormDlg, hdl )
55 ScDataFormDlg::ScDataFormDlg( Window
* pParent
, ScTabViewShell
* pTabViewShellOri
) :
56 ModalDialog ( pParent
, ScResId( RID_SCDLG_DATAFORM
) ),
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 aFixedText ( this, ScResId( LAB_DATAFORM_RECORDNO
) )
67 pTabViewShell
= pTabViewShellOri
;
69 //read header form current document, and add new controls
70 DBG_ASSERT( pTabViewShell
, "pTabViewShell is NULL! :-/" );
71 ScViewData
* pViewData
= pTabViewShell
->GetViewData();
73 pDoc
= pViewData
->GetDocument();
77 pViewData
->GetSimpleArea( aRange
);
78 ScAddress aStart
= aRange
.aStart
;
79 ScAddress aEnd
= aRange
.aEnd
;
81 nStartCol
= aStart
.Col();
83 nStartRow
= aStart
.Row();
86 nTab
= pViewData
->GetTabNo();
87 //if there is no selection
88 if ((nStartCol
== nEndCol
) && (nStartRow
== nEndRow
))
93 //find last not blank cell in row
94 for (int i
=1;i
<=MAX_DATAFORM_COLS
;i
++)
98 pDoc
->GetString( nEndCol
, nStartRow
, nTab
, aColName
);
99 int nColWidth
= pDoc
->GetColWidth( nEndCol
, nTab
);
100 if ( aColName
.Len() == 0 && nColWidth
)
107 //find first not blank cell in row
108 for (int i
=1;i
<=MAX_DATAFORM_COLS
;i
++)
115 pDoc
->GetString( nStartCol
, nStartRow
, nTab
, aColName
);
116 int nColWidth
= pDoc
->GetColWidth( nEndCol
, nTab
);
117 if ( aColName
.Len() == 0 && nColWidth
)
124 //skip leading hide column
125 for (int i
=1;i
<=MAX_DATAFORM_COLS
;i
++)
128 int nColWidth
= pDoc
->GetColWidth( nStartCol
, nTab
);
134 if (nEndCol
< nStartCol
)
137 //find last not blank cell in row
138 for (int i
=1;i
<=MAX_DATAFORM_ROWS
;i
++)
142 pDoc
->GetString( nStartCol
, nEndRow
, nTab
, aColName
);
143 if ( aColName
.Len() == 0 )
150 //find first not blank cell in row
151 for (int i
=1;i
<=MAX_DATAFORM_ROWS
;i
++)
158 pDoc
->GetString( nStartCol
, nStartRow
, nTab
, aColName
);
159 if ( aColName
.Len() == 0 )
166 if (nEndRow
< nStartRow
)
170 aCurrentRow
= nStartRow
+ 1;
176 Size
nFixedSize(FIXED_WIDTH
, CTRL_HEIGHT
);
177 Size
nEditSize(EDIT_WIDTH
, CTRL_HEIGHT
);
179 //pFtArray = new FixedText(this);
180 aColLength
= nEndCol
- nStartCol
+ 1;
183 pFixedTexts
= new FixedText
*[aColLength
];
184 pEdits
= new Edit
*[aColLength
];
186 for(sal_uInt16 nIndex
= 0; nIndex
< aColLength
; nIndex
++)
188 pDoc
->GetString( nIndex
+ nStartCol
, nStartRow
, nTab
, aFieldName
);
189 int nColWidth
= pDoc
->GetColWidth( nIndex
+ nStartCol
, nTab
);
192 pFixedTexts
[nIndex
] = new FixedText(this);
193 pEdits
[nIndex
] = new Edit(this, WB_BORDER
);
195 pFixedTexts
[nIndex
]->SetSizePixel(nFixedSize
);
196 pEdits
[nIndex
]->SetSizePixel(nEditSize
);
197 pFixedTexts
[nIndex
]->SetPosPixel(Point(FIXED_LEFT
, nTop
));
198 pEdits
[nIndex
]->SetPosPixel(Point(EDIT_LEFT
, nTop
));
199 //pFixedTexts[nIndex]->SetText(String::CreateFromAscii("W4W-Filter Nr. "));
200 pFixedTexts
[nIndex
]->SetText(aFieldName
);
201 pFixedTexts
[nIndex
]->Show();
202 pEdits
[nIndex
]->Show();
208 pFixedTexts
[nIndex
] = NULL
;
209 pEdits
[nIndex
] = NULL
;
211 pEdits
[nIndex
]->SetModifyHdl( HDL(Impl_DataModifyHdl
) );
214 Size nDialogSize
= this->GetSizePixel();
215 if (nTop
> nDialogSize
.Height())
217 nDialogSize
.setHeight(nTop
);
218 this->SetSizePixel(nDialogSize
);
220 Size nScrollSize
= aSlider
.GetSizePixel();
221 nScrollSize
.setHeight(nDialogSize
.Height()-20);
222 aSlider
.SetSizePixel(nScrollSize
);
225 FillCtrls(aCurrentRow
);
227 aSlider
.SetPageSize( 10 );
228 aSlider
.SetVisibleSize( 1 );
229 aSlider
.SetLineSize( 1 );
230 aSlider
.SetRange( Range( 0, nEndRow
- nStartRow
+ 1) );
233 aBtnNew
.SetClickHdl ( HDL(Impl_NewHdl
) );
234 aBtnLast
.SetClickHdl ( HDL(Impl_LastHdl
) );
235 aBtnNext
.SetClickHdl ( HDL(Impl_NextHdl
) );
237 aBtnRestore
.SetClickHdl ( HDL(Impl_RestoreHdl
) );
238 aBtnDelete
.SetClickHdl ( HDL(Impl_DeleteHdl
) );
239 aBtnClose
.SetClickHdl ( HDL(Impl_CloseHdl
) );
241 aSlider
.SetEndScrollHdl( HDL( Impl_ScrollHdl
) );
249 ScDataFormDlg::~ScDataFormDlg()
251 for(sal_uInt16 i
= 0; i
< aColLength
; i
++)
256 delete pFixedTexts
[i
];
264 void ScDataFormDlg::FillCtrls(SCROW
/*nCurrentRow*/)
266 //ScViewData* pViewData = pTabViewShell->GetViewData();
268 //pDoc = pViewData->GetDocument();
270 int nRecordNum
= nEndRow
- nStartRow
;
271 for(sal_uInt16 i
= 0; i
< aColLength
; i
++)
275 if (aCurrentRow
<=nEndRow
)
277 pDoc
->GetString( i
+ nStartCol
, aCurrentRow
, nTab
, aFieldName
);
278 pEdits
[i
]->SetText(aFieldName
);
281 pEdits
[i
]->SetText(String());
284 char sRecordStr
[256];
285 if (aCurrentRow
<=nEndRow
)
286 aFixedText
.SetText(String::CreateFromAscii(sRecordStr
));
288 aFixedText
.SetText(String::CreateFromAscii("New Record"));
290 aSlider
.SetThumbPos(aCurrentRow
-nStartRow
-1);
293 IMPL_LINK( ScDataFormDlg
, Impl_DataModifyHdl
, Edit
*, pEdit
)
295 if ( pEdit
->IsModified() )
296 aBtnRestore
.Enable( TRUE
);
300 IMPL_LINK( ScDataFormDlg
, Impl_NewHdl
, PushButton
*, EMPTYARG
)
302 ScViewData
* pViewData
= pTabViewShell
->GetViewData();
303 ScDocShell
* pDocSh
= pViewData
->GetDocShell();
306 sal_Bool bHasData
= sal_False
;
307 for(sal_uInt16 i
= 0; i
< aColLength
; i
++)
309 if ( pEdits
[i
]->GetText().Len() != 0 )
317 pTabViewShell
->DataFormPutData( aCurrentRow
, nStartRow
, nStartCol
, nEndRow
, nEndCol
, pEdits
, aColLength
);
319 if (aCurrentRow
>= nEndRow
+ 2)
322 aSlider
.SetRange( Range( 0, nEndRow
- nStartRow
+ 1) );
325 FillCtrls(aCurrentRow
);
326 pDocSh
->SetDocumentModified();
327 pDocSh
->PostPaintGridAll();
333 IMPL_LINK( ScDataFormDlg
, Impl_LastHdl
, PushButton
*, EMPTYARG
)
337 if ( aCurrentRow
> nStartRow
+1 )
341 FillCtrls(aCurrentRow
);
346 IMPL_LINK( ScDataFormDlg
, Impl_NextHdl
, PushButton
*, EMPTYARG
)
350 if ( aCurrentRow
<= nEndRow
)
354 FillCtrls(aCurrentRow
);
359 IMPL_LINK( ScDataFormDlg
, Impl_RestoreHdl
, PushButton
*, EMPTYARG
)
363 FillCtrls(aCurrentRow
);
368 IMPL_LINK( ScDataFormDlg
, Impl_DeleteHdl
, PushButton
*, EMPTYARG
)
370 ScViewData
* pViewData
= pTabViewShell
->GetViewData();
371 ScDocShell
* pDocSh
= pViewData
->GetDocShell();
374 ScRange
aRange(nStartCol
, aCurrentRow
, nTab
, nEndCol
, aCurrentRow
, nTab
);
375 pDoc
->DeleteRow(aRange
);
379 pDocSh
->GetUndoManager()->Clear();
381 FillCtrls(aCurrentRow
);
382 pDocSh
->SetDocumentModified();
383 pDocSh
->PostPaintGridAll();
388 IMPL_LINK( ScDataFormDlg
, Impl_CloseHdl
, PushButton
*, EMPTYARG
)
394 IMPL_LINK( ScDataFormDlg
, Impl_ScrollHdl
, ScrollBar
*, EMPTYARG
)
396 long nOffset
= aSlider
.GetThumbPos();
397 aCurrentRow
= nStartRow
+ nOffset
+ 1;
399 FillCtrls(aCurrentRow
);
403 void ScDataFormDlg::SetButtonState()
405 if ( aCurrentRow
> nEndRow
)
407 aBtnDelete
.Enable( FALSE
);
408 aBtnLast
.Enable( TRUE
);
409 aBtnNext
.Enable( FALSE
);
413 aBtnDelete
.Enable( TRUE
);
414 aBtnNext
.Enable( TRUE
);
416 if ( 1 == aCurrentRow
)
417 aBtnLast
.Enable( FALSE
);
419 aBtnRestore
.Enable( FALSE
);
421 pEdits
[0]->GrabFocus();