xref: /trunk/main/dbaccess/source/ui/tabledesign/TEditControl.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
30*cdf0e10cSrcweir #ifndef DBAUI_TABLEEDITORCONTROL_HXX
31*cdf0e10cSrcweir #include "TEditControl.hxx"
32*cdf0e10cSrcweir #endif
33*cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
34*cdf0e10cSrcweir #include <tools/debug.hxx>
35*cdf0e10cSrcweir #endif
36*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBC_XDATABASEMETADATA_HPP_
37*cdf0e10cSrcweir #include <com/sun/star/sdbc/XDatabaseMetaData.hpp>
38*cdf0e10cSrcweir #endif
39*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XCOLUMNSSUPPLIER_HPP_
40*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
41*cdf0e10cSrcweir #endif
42*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XALTERTABLE_HPP_
43*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAlterTable.hpp>
44*cdf0e10cSrcweir #endif
45*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XDROP_HPP_
46*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XDrop.hpp>
47*cdf0e10cSrcweir #endif
48*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_SDBCX_XAPPEND_HPP_
49*cdf0e10cSrcweir #include <com/sun/star/sdbcx/XAppend.hpp>
50*cdf0e10cSrcweir #endif
51*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
52*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
53*cdf0e10cSrcweir #endif
54*cdf0e10cSrcweir #ifndef _COM_SUN_STAR_UTIL_XNUMBERFORMATTYPES_HPP_
55*cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatTypes.hpp>
56*cdf0e10cSrcweir #endif
57*cdf0e10cSrcweir #ifndef _DBU_TBL_HRC_
58*cdf0e10cSrcweir #include "dbu_tbl.hrc"
59*cdf0e10cSrcweir #endif
60*cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBUSTRINGS_HRC
61*cdf0e10cSrcweir #include "dbustrings.hrc"
62*cdf0e10cSrcweir #endif
63*cdf0e10cSrcweir #ifndef DBACCESS_UI_BROWSER_ID_HXX
64*cdf0e10cSrcweir #include "browserids.hxx"
65*cdf0e10cSrcweir #endif
66*cdf0e10cSrcweir #ifndef _DBA_DBACCESS_HELPID_HRC_
67*cdf0e10cSrcweir #include "dbaccess_helpid.hrc"
68*cdf0e10cSrcweir #endif
69*cdf0e10cSrcweir #ifndef _COMPHELPER_TYPES_HXX_
70*cdf0e10cSrcweir #include <comphelper/types.hxx>
71*cdf0e10cSrcweir #endif
72*cdf0e10cSrcweir #ifndef DBAUI_FIELDDESCRIPTIONCONTROL_HXX
73*cdf0e10cSrcweir #include "FieldDescControl.hxx"
74*cdf0e10cSrcweir #endif
75*cdf0e10cSrcweir #ifndef DBAUI_FIELDDESCRIPTIONS_HXX
76*cdf0e10cSrcweir #include "FieldDescriptions.hxx"
77*cdf0e10cSrcweir #endif
78*cdf0e10cSrcweir #ifndef _SV_MSGBOX_HXX
79*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
80*cdf0e10cSrcweir #endif
81*cdf0e10cSrcweir #ifndef DBAUI_TABLEUNDO_HXX
82*cdf0e10cSrcweir #include "TableUndo.hxx"
83*cdf0e10cSrcweir #endif
84*cdf0e10cSrcweir #ifndef DBUI_TABLECONTROLLER_HXX
85*cdf0e10cSrcweir #include "TableController.hxx"
86*cdf0e10cSrcweir #endif
87*cdf0e10cSrcweir #ifndef _CONNECTIVITY_DBTOOLS_HXX_
88*cdf0e10cSrcweir #include <connectivity/dbtools.hxx>
89*cdf0e10cSrcweir #endif
90*cdf0e10cSrcweir #ifndef DBAUI_SQLNAMEEDIT_HXX
91*cdf0e10cSrcweir #include "SqlNameEdit.hxx"
92*cdf0e10cSrcweir #endif
93*cdf0e10cSrcweir #ifndef DBAUI_TABLEROW_EXCHANGE_HXX
94*cdf0e10cSrcweir #include "TableRowExchange.hxx"
95*cdf0e10cSrcweir #endif
96*cdf0e10cSrcweir #ifndef _SOT_STORAGE_HXX
97*cdf0e10cSrcweir #include <sot/storage.hxx>
98*cdf0e10cSrcweir #endif
99*cdf0e10cSrcweir #ifndef DBAUI_TOOLS_HXX
100*cdf0e10cSrcweir #include "UITools.hxx"
101*cdf0e10cSrcweir #endif
102*cdf0e10cSrcweir #ifndef DBAUI_FIELDDESCRIPTIONCONTROL_HXX
103*cdf0e10cSrcweir #include "FieldDescControl.hxx"
104*cdf0e10cSrcweir #endif
105*cdf0e10cSrcweir #ifndef DBAUI_TABLEFIELDCONTROL_HXX
106*cdf0e10cSrcweir #include "TableFieldControl.hxx"
107*cdf0e10cSrcweir #endif
108*cdf0e10cSrcweir #include "dsntypes.hxx"
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir #include "dbaccess_slotid.hrc"
111*cdf0e10cSrcweir 
112*cdf0e10cSrcweir using namespace ::dbaui;
113*cdf0e10cSrcweir using namespace ::comphelper;
114*cdf0e10cSrcweir using namespace ::svt;
115*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
116*cdf0e10cSrcweir using namespace ::com::sun::star::container;
117*cdf0e10cSrcweir using namespace ::com::sun::star::io;
118*cdf0e10cSrcweir using namespace ::com::sun::star::beans;
119*cdf0e10cSrcweir using namespace ::com::sun::star::frame;
120*cdf0e10cSrcweir using namespace ::com::sun::star::util;
121*cdf0e10cSrcweir using namespace ::com::sun::star::lang;
122*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
123*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
124*cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir namespace dbaui
127*cdf0e10cSrcweir {
128*cdf0e10cSrcweir     extern String GetTypeString( sal_uInt16 nType );
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir //==============================================================================
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir //  TYPEINIT1(OTableEditorCtrl, DBView);
133*cdf0e10cSrcweir DBG_NAME(OTableEditorCtrl)
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir //==============================================================================
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir #define HANDLE_ID       0
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir // default Spaltenbreiten
140*cdf0e10cSrcweir #define FIELDNAME_WIDTH     100
141*cdf0e10cSrcweir #define FIELDTYPE_WIDTH     150
142*cdf0e10cSrcweir #define FIELDDESCR_WIDTH    300
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir // Maximale Eingabelaenge im Beschreibungsfeld
145*cdf0e10cSrcweir #define MAX_DESCR_LEN       256
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir #define CONTROL_SPACING_X   18  // 6
149*cdf0e10cSrcweir #define CONTROL_SPACING_Y   5
150*cdf0e10cSrcweir #define CONTROL_HEIGHT      20
151*cdf0e10cSrcweir #define CONTROL_WIDTH_1     140 // 100
152*cdf0e10cSrcweir #define CONTROL_WIDTH_2     100 // 60
153*cdf0e10cSrcweir #define CONTROL_WIDTH_3     250
154*cdf0e10cSrcweir #define CONTROL_WIDTH_4     (CONTROL_WIDTH_3 - CONTROL_HEIGHT - 5)
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir //==================================================================
158*cdf0e10cSrcweir DBG_NAME(ClipboardInvalidator)
159*cdf0e10cSrcweir //------------------------------------------------------------------
160*cdf0e10cSrcweir OTableEditorCtrl::ClipboardInvalidator::ClipboardInvalidator(sal_uLong nTimeout,OTableEditorCtrl* _pOwner)
161*cdf0e10cSrcweir : m_pOwner(_pOwner)
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir     DBG_CTOR(ClipboardInvalidator,NULL);
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir     m_aInvalidateTimer.SetTimeout(nTimeout);
166*cdf0e10cSrcweir     m_aInvalidateTimer.SetTimeoutHdl(LINK(this, OTableEditorCtrl::ClipboardInvalidator, OnInvalidate));
167*cdf0e10cSrcweir     m_aInvalidateTimer.Start();
168*cdf0e10cSrcweir }
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir //------------------------------------------------------------------
171*cdf0e10cSrcweir OTableEditorCtrl::ClipboardInvalidator::~ClipboardInvalidator()
172*cdf0e10cSrcweir {
173*cdf0e10cSrcweir     m_aInvalidateTimer.Stop();
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir     DBG_DTOR(ClipboardInvalidator,NULL);
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir //------------------------------------------------------------------
179*cdf0e10cSrcweir IMPL_LINK(OTableEditorCtrl::ClipboardInvalidator, OnInvalidate, void*, EMPTYARG)
180*cdf0e10cSrcweir {
181*cdf0e10cSrcweir     m_pOwner->GetView()->getController().InvalidateFeature(SID_CUT);
182*cdf0e10cSrcweir     m_pOwner->GetView()->getController().InvalidateFeature(SID_COPY);
183*cdf0e10cSrcweir     m_pOwner->GetView()->getController().InvalidateFeature(SID_PASTE);
184*cdf0e10cSrcweir     return 0L;
185*cdf0e10cSrcweir }
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir //==================================================================
188*cdf0e10cSrcweir void OTableEditorCtrl::Init()
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
191*cdf0e10cSrcweir     OTableRowView::Init();
192*cdf0e10cSrcweir 
193*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
194*cdf0e10cSrcweir     // Soll der Entwurf ReadOnly geoeffnet werden ?
195*cdf0e10cSrcweir     sal_Bool bRead(GetView()->getController().isReadOnly());
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir     SetReadOnly( bRead );
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
200*cdf0e10cSrcweir     // Spalten einfuegen
201*cdf0e10cSrcweir     String aColumnName( ModuleRes(STR_TAB_FIELD_COLUMN_NAME) );
202*cdf0e10cSrcweir     InsertDataColumn( FIELD_NAME, aColumnName, FIELDNAME_WIDTH );
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir     aColumnName = String( ModuleRes(STR_TAB_FIELD_COLUMN_DATATYPE) );
205*cdf0e10cSrcweir     InsertDataColumn( FIELD_TYPE, aColumnName, FIELDTYPE_WIDTH );
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir     ::dbaccess::ODsnTypeCollection aDsnTypes(GetView()->getController().getORB());
208*cdf0e10cSrcweir     sal_Bool bShowColumnDescription = aDsnTypes.supportsColumnDescription(::comphelper::getString(GetView()->getController().getDataSource()->getPropertyValue(PROPERTY_URL)));
209*cdf0e10cSrcweir     aColumnName = String( ModuleRes(STR_TAB_HELP_TEXT) );
210*cdf0e10cSrcweir     InsertDataColumn( HELP_TEXT, aColumnName, bShowColumnDescription ? FIELDTYPE_WIDTH : FIELDDESCR_WIDTH );
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir     if ( bShowColumnDescription )
213*cdf0e10cSrcweir     {
214*cdf0e10cSrcweir         aColumnName = String( ModuleRes(STR_COLUMN_DESCRIPTION) );
215*cdf0e10cSrcweir         InsertDataColumn( COLUMN_DESCRIPTION, aColumnName, FIELDTYPE_WIDTH );
216*cdf0e10cSrcweir     }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir     InitCellController();
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
221*cdf0e10cSrcweir     // Zeilen einfuegen
222*cdf0e10cSrcweir     RowInserted(0, m_pRowList->size(), sal_True);
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir //==================================================================
226*cdf0e10cSrcweir void OTableEditorCtrl::UpdateAll()
227*cdf0e10cSrcweir {
228*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
229*cdf0e10cSrcweir     RowRemoved(0, GetRowCount(), sal_False);
230*cdf0e10cSrcweir     m_nDataPos = 0;
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir     InvalidateFeatures();
233*cdf0e10cSrcweir     Invalidate();
234*cdf0e10cSrcweir }
235*cdf0e10cSrcweir //==================================================================
236*cdf0e10cSrcweir OTableEditorCtrl::OTableEditorCtrl(Window* pWindow)
237*cdf0e10cSrcweir     :OTableRowView(pWindow)
238*cdf0e10cSrcweir     ,pNameCell(NULL)
239*cdf0e10cSrcweir     ,pTypeCell(NULL)
240*cdf0e10cSrcweir     ,pHelpTextCell(NULL)
241*cdf0e10cSrcweir     ,pDescrCell(NULL)
242*cdf0e10cSrcweir     ,pDescrWin(NULL)
243*cdf0e10cSrcweir     ,nIndexEvent(0)
244*cdf0e10cSrcweir     ,nCutEvent(0)
245*cdf0e10cSrcweir     ,nPasteEvent(0)
246*cdf0e10cSrcweir     ,nDeleteEvent(0)
247*cdf0e10cSrcweir     ,nInsNewRowsEvent(0)
248*cdf0e10cSrcweir     ,nInvalidateTypeEvent(0)
249*cdf0e10cSrcweir     ,nEntryNotFoundEvent(0)
250*cdf0e10cSrcweir     ,m_eChildFocus(NONE)
251*cdf0e10cSrcweir     ,nOldDataPos(-1)
252*cdf0e10cSrcweir     ,bSaveOnMove(sal_True)
253*cdf0e10cSrcweir     ,bReadOnly(sal_True)
254*cdf0e10cSrcweir     ,m_aInvalidate(500,this)
255*cdf0e10cSrcweir {
256*cdf0e10cSrcweir     DBG_CTOR(OTableEditorCtrl,NULL);
257*cdf0e10cSrcweir 
258*cdf0e10cSrcweir     SetHelpId(HID_TABDESIGN_BACKGROUND);
259*cdf0e10cSrcweir     GetDataWindow().SetHelpId(HID_CTL_TABLEEDIT);
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir     m_pRowList = GetView()->getController().getRows();
262*cdf0e10cSrcweir     m_nDataPos = 0;
263*cdf0e10cSrcweir }
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir //------------------------------------------------------------------------------
266*cdf0e10cSrcweir SfxUndoManager& OTableEditorCtrl::GetUndoManager() const
267*cdf0e10cSrcweir {
268*cdf0e10cSrcweir     return GetView()->getController().GetUndoManager();
269*cdf0e10cSrcweir }
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir //------------------------------------------------------------------------------
272*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::IsReadOnly()
273*cdf0e10cSrcweir {
274*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
275*cdf0e10cSrcweir     return bReadOnly;
276*cdf0e10cSrcweir }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir //------------------------------------------------------------------------------
279*cdf0e10cSrcweir void OTableEditorCtrl::SetReadOnly( sal_Bool bRead )
280*cdf0e10cSrcweir {
281*cdf0e10cSrcweir     // nix zu tun ?
282*cdf0e10cSrcweir     if (bRead == IsReadOnly())
283*cdf0e10cSrcweir         // diese Abfrage ist wichtig, da die zugrundeliegende Def sonst im folgenden gelockt oder ge-unlocked wird, obwohl es
284*cdf0e10cSrcweir         // nicht notwendig waere (und was schlimmer ist, das wuerde dann auch nicht wieder rueckgaengig gemacht)
285*cdf0e10cSrcweir         return;
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
288*cdf0e10cSrcweir     bReadOnly = bRead;
289*cdf0e10cSrcweir 
290*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
291*cdf0e10cSrcweir     // Aktive Zelle disablen
292*cdf0e10cSrcweir     long nRow(GetCurRow());
293*cdf0e10cSrcweir     sal_uInt16 nCol(GetCurColumnId());
294*cdf0e10cSrcweir     DeactivateCell();
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
297*cdf0e10cSrcweir     // ::com::sun::star::beans::Property Controls disablen
298*cdf0e10cSrcweir //  if (pDescrWin)
299*cdf0e10cSrcweir //      pDescrWin->SetReadOnly(bReadOnly || !SetDataPtr(nRow) || GetActRow()->IsReadOnly());
300*cdf0e10cSrcweir 
301*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
302*cdf0e10cSrcweir     // Cursor des Browsers anpassen
303*cdf0e10cSrcweir     BrowserMode nMode(BROWSER_COLUMNSELECTION | BROWSER_MULTISELECTION | BROWSER_KEEPSELECTION |
304*cdf0e10cSrcweir                       BROWSER_HLINESFULL      | BROWSER_VLINESFULL|BROWSER_AUTOSIZE_LASTCOL);
305*cdf0e10cSrcweir     if( !bReadOnly )
306*cdf0e10cSrcweir         nMode |= BROWSER_HIDECURSOR;
307*cdf0e10cSrcweir     SetMode(nMode);
308*cdf0e10cSrcweir 
309*cdf0e10cSrcweir     if( !bReadOnly )
310*cdf0e10cSrcweir         ActivateCell( nRow, nCol );
311*cdf0e10cSrcweir }
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir //------------------------------------------------------------------------------
314*cdf0e10cSrcweir void OTableEditorCtrl::InitCellController()
315*cdf0e10cSrcweir {
316*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
317*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
318*cdf0e10cSrcweir     // Zelle Feldname
319*cdf0e10cSrcweir     xub_StrLen nMaxTextLen = EDIT_NOLIMIT;
320*cdf0e10cSrcweir     ::rtl::OUString sExtraNameChars;
321*cdf0e10cSrcweir     Reference<XConnection> xCon;
322*cdf0e10cSrcweir     try
323*cdf0e10cSrcweir     {
324*cdf0e10cSrcweir         xCon = GetView()->getController().getConnection();
325*cdf0e10cSrcweir         Reference< XDatabaseMetaData> xMetaData = xCon.is() ? xCon->getMetaData() : Reference< XDatabaseMetaData>();
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir         nMaxTextLen = ((xub_StrLen)xMetaData.is() ? static_cast<xub_StrLen>(xMetaData->getMaxColumnNameLength()) : 0);
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir         if( nMaxTextLen == 0 )
330*cdf0e10cSrcweir             nMaxTextLen = EDIT_NOLIMIT;
331*cdf0e10cSrcweir         sExtraNameChars = xMetaData.is() ? xMetaData->getExtraNameCharacters() : ::rtl::OUString();
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir     }
334*cdf0e10cSrcweir     catch(SQLException&)
335*cdf0e10cSrcweir     {
336*cdf0e10cSrcweir         OSL_ASSERT(!"getMaxColumnNameLength");
337*cdf0e10cSrcweir     }
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir     pNameCell = new OSQLNameEdit( &GetDataWindow(), sExtraNameChars,WB_LEFT );
340*cdf0e10cSrcweir     pNameCell->SetMaxTextLen( nMaxTextLen );
341*cdf0e10cSrcweir     pNameCell->setCheck( isSQL92CheckEnabled(xCon) );
342*cdf0e10cSrcweir 
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
345*cdf0e10cSrcweir     // Zelle Typ
346*cdf0e10cSrcweir     pTypeCell = new ListBoxControl( &GetDataWindow() );
347*cdf0e10cSrcweir     pTypeCell->SetDropDownLineCount( 15 );
348*cdf0e10cSrcweir 
349*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
350*cdf0e10cSrcweir     // Zelle Beschreibung
351*cdf0e10cSrcweir     pDescrCell = new Edit( &GetDataWindow(), WB_LEFT );
352*cdf0e10cSrcweir     pDescrCell->SetMaxTextLen( MAX_DESCR_LEN );
353*cdf0e10cSrcweir 
354*cdf0e10cSrcweir     pHelpTextCell = new Edit( &GetDataWindow(), WB_LEFT );
355*cdf0e10cSrcweir     pHelpTextCell->SetMaxTextLen( MAX_DESCR_LEN );
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir     pNameCell->SetHelpId(HID_TABDESIGN_NAMECELL);
358*cdf0e10cSrcweir     pTypeCell->SetHelpId(HID_TABDESIGN_TYPECELL);
359*cdf0e10cSrcweir     pDescrCell->SetHelpId(HID_TABDESIGN_COMMENTCELL);
360*cdf0e10cSrcweir     pHelpTextCell->SetHelpId(HID_TABDESIGN_HELPTEXT);
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir     Size aHeight;
363*cdf0e10cSrcweir     const Control* pControls[] = { pTypeCell,pDescrCell,pNameCell,pHelpTextCell};
364*cdf0e10cSrcweir     for(sal_Size i= 0; i < sizeof(pControls)/sizeof(pControls[0]);++i)
365*cdf0e10cSrcweir     {
366*cdf0e10cSrcweir         const Size aTemp( pControls[i]->GetOptimalSize(WINDOWSIZE_PREFERRED) );
367*cdf0e10cSrcweir         if ( aTemp.Height() > aHeight.Height() )
368*cdf0e10cSrcweir             aHeight.Height() = aTemp.Height();
369*cdf0e10cSrcweir     } // for(int i= 0; i < sizeof(pControls)/sizeof(pControls[0]);++i
370*cdf0e10cSrcweir     SetDataRowHeight(aHeight.Height());
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir     ClearModified();
373*cdf0e10cSrcweir }
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir //------------------------------------------------------------------------------
376*cdf0e10cSrcweir void OTableEditorCtrl::ClearModified()
377*cdf0e10cSrcweir {
378*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
379*cdf0e10cSrcweir     pNameCell->ClearModifyFlag();
380*cdf0e10cSrcweir     pDescrCell->ClearModifyFlag();
381*cdf0e10cSrcweir     pHelpTextCell->ClearModifyFlag();
382*cdf0e10cSrcweir     pTypeCell->SaveValue();
383*cdf0e10cSrcweir }
384*cdf0e10cSrcweir 
385*cdf0e10cSrcweir //------------------------------------------------------------------------------
386*cdf0e10cSrcweir OTableEditorCtrl::~OTableEditorCtrl()
387*cdf0e10cSrcweir {
388*cdf0e10cSrcweir     DBG_DTOR(OTableEditorCtrl,NULL);
389*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
390*cdf0e10cSrcweir     // Undo-Manager zuruecksetzen
391*cdf0e10cSrcweir     GetUndoManager().Clear();
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
394*cdf0e10cSrcweir     // Moegliche Events aus Queue entfernen
395*cdf0e10cSrcweir     if( nCutEvent )
396*cdf0e10cSrcweir         Application::RemoveUserEvent( nCutEvent );
397*cdf0e10cSrcweir     if( nPasteEvent )
398*cdf0e10cSrcweir         Application::RemoveUserEvent( nPasteEvent );
399*cdf0e10cSrcweir     if( nDeleteEvent )
400*cdf0e10cSrcweir         Application::RemoveUserEvent( nDeleteEvent );
401*cdf0e10cSrcweir     if( nInsNewRowsEvent )
402*cdf0e10cSrcweir         Application::RemoveUserEvent( nInsNewRowsEvent );
403*cdf0e10cSrcweir     if( nInvalidateTypeEvent )
404*cdf0e10cSrcweir         Application::RemoveUserEvent( nInvalidateTypeEvent );
405*cdf0e10cSrcweir     if( nEntryNotFoundEvent )
406*cdf0e10cSrcweir         Application::RemoveUserEvent( nEntryNotFoundEvent );
407*cdf0e10cSrcweir 
408*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
409*cdf0e10cSrcweir     // Controltypen zerstoeren
410*cdf0e10cSrcweir     delete pNameCell;
411*cdf0e10cSrcweir     delete pTypeCell;
412*cdf0e10cSrcweir     delete pDescrCell;
413*cdf0e10cSrcweir     delete pHelpTextCell;
414*cdf0e10cSrcweir }
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir //------------------------------------------------------------------------------
417*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::SetDataPtr( long nRow )
418*cdf0e10cSrcweir {
419*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
420*cdf0e10cSrcweir     if(nRow == -1)
421*cdf0e10cSrcweir         return sal_False;
422*cdf0e10cSrcweir 
423*cdf0e10cSrcweir     OSL_ENSURE((xub_StrLen)nRow < m_pRowList->size(),"Row is greater than size!");
424*cdf0e10cSrcweir     if(nRow >= (long)m_pRowList->size())
425*cdf0e10cSrcweir         return sal_False;
426*cdf0e10cSrcweir     pActRow = (*m_pRowList)[nRow];
427*cdf0e10cSrcweir     return pActRow != NULL;
428*cdf0e10cSrcweir }
429*cdf0e10cSrcweir 
430*cdf0e10cSrcweir //------------------------------------------------------------------------------
431*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::SeekRow(long _nRow)
432*cdf0e10cSrcweir {
433*cdf0e10cSrcweir     // die Basisklasse braucht den Aufruf, da sie sich dort merkt, welche Zeile gepainted wird
434*cdf0e10cSrcweir     EditBrowseBox::SeekRow(_nRow);
435*cdf0e10cSrcweir 
436*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
437*cdf0e10cSrcweir     m_nCurrentPos = _nRow;
438*cdf0e10cSrcweir     return SetDataPtr(_nRow);
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir //------------------------------------------------------------------------------
442*cdf0e10cSrcweir void OTableEditorCtrl::PaintCell(OutputDevice& rDev, const Rectangle& rRect,
443*cdf0e10cSrcweir                                    sal_uInt16 nColumnId ) const
444*cdf0e10cSrcweir {
445*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
446*cdf0e10cSrcweir     const String aText( GetCellText( m_nCurrentPos, nColumnId ));
447*cdf0e10cSrcweir     const Point aPos(rRect.TopLeft());
448*cdf0e10cSrcweir     const Size TxtSize(GetDataWindow().GetTextWidth(aText), GetDataWindow().GetTextHeight());
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir     rDev.Push( PUSH_CLIPREGION );
451*cdf0e10cSrcweir     rDev.SetClipRegion( rRect );
452*cdf0e10cSrcweir     rDev.DrawText( rRect, aText, TEXT_DRAW_LEFT | TEXT_DRAW_VCENTER );
453*cdf0e10cSrcweir     rDev.Pop();
454*cdf0e10cSrcweir }
455*cdf0e10cSrcweir 
456*cdf0e10cSrcweir //------------------------------------------------------------------------------
457*cdf0e10cSrcweir CellController* OTableEditorCtrl::GetController(long nRow, sal_uInt16 nColumnId)
458*cdf0e10cSrcweir {
459*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
460*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
461*cdf0e10cSrcweir     // Wenn EditorCtrl ReadOnly ist, darf nicht editiert werden
462*cdf0e10cSrcweir     Reference<XPropertySet> xTable = GetView()->getController().getTable();
463*cdf0e10cSrcweir     if (IsReadOnly() || (   xTable.is() &&
464*cdf0e10cSrcweir                             xTable->getPropertySetInfo()->hasPropertyByName(PROPERTY_TYPE) &&
465*cdf0e10cSrcweir                             ::comphelper::getString(xTable->getPropertyValue(PROPERTY_TYPE)) == ::rtl::OUString::createFromAscii("VIEW")))
466*cdf0e10cSrcweir         return NULL;
467*cdf0e10cSrcweir 
468*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
469*cdf0e10cSrcweir     // Wenn Zeile ReadOnly ist, darf sie nicht editiert werden
470*cdf0e10cSrcweir     SetDataPtr( nRow );
471*cdf0e10cSrcweir     if( pActRow->IsReadOnly() )
472*cdf0e10cSrcweir         return NULL;
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir     OFieldDescription* pActFieldDescr = pActRow->GetActFieldDescr();
475*cdf0e10cSrcweir     switch (nColumnId)
476*cdf0e10cSrcweir     {
477*cdf0e10cSrcweir         case FIELD_NAME:
478*cdf0e10cSrcweir             return new EditCellController( pNameCell );
479*cdf0e10cSrcweir         case FIELD_TYPE:
480*cdf0e10cSrcweir             if (pActFieldDescr && (pActFieldDescr->GetName().getLength() != 0))
481*cdf0e10cSrcweir                 return new ListBoxCellController( pTypeCell );
482*cdf0e10cSrcweir             else return NULL;
483*cdf0e10cSrcweir         case HELP_TEXT:
484*cdf0e10cSrcweir             if (pActFieldDescr && (pActFieldDescr->GetName().getLength() != 0))
485*cdf0e10cSrcweir                 return new EditCellController( pHelpTextCell );
486*cdf0e10cSrcweir             else
487*cdf0e10cSrcweir                 return NULL;
488*cdf0e10cSrcweir         case COLUMN_DESCRIPTION:
489*cdf0e10cSrcweir             if (pActFieldDescr && (pActFieldDescr->GetName().getLength() != 0))
490*cdf0e10cSrcweir                 return new EditCellController( pDescrCell );
491*cdf0e10cSrcweir             else
492*cdf0e10cSrcweir                 return NULL;
493*cdf0e10cSrcweir         default:
494*cdf0e10cSrcweir             return NULL;
495*cdf0e10cSrcweir     }
496*cdf0e10cSrcweir }
497*cdf0e10cSrcweir 
498*cdf0e10cSrcweir //------------------------------------------------------------------------------
499*cdf0e10cSrcweir void OTableEditorCtrl::InitController(CellControllerRef&, long nRow, sal_uInt16 nColumnId)
500*cdf0e10cSrcweir {
501*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
502*cdf0e10cSrcweir     SeekRow( nRow == -1 ? GetCurRow() : nRow);
503*cdf0e10cSrcweir     OFieldDescription* pActFieldDescr = pActRow->GetActFieldDescr();
504*cdf0e10cSrcweir     String aInitString;
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir     switch (nColumnId)
507*cdf0e10cSrcweir     {
508*cdf0e10cSrcweir         case FIELD_NAME:
509*cdf0e10cSrcweir             if( pActFieldDescr )
510*cdf0e10cSrcweir                 aInitString = pActFieldDescr->GetName();
511*cdf0e10cSrcweir             pNameCell->SetText( aInitString );
512*cdf0e10cSrcweir             pNameCell->SaveValue();
513*cdf0e10cSrcweir             break;
514*cdf0e10cSrcweir         case FIELD_TYPE:
515*cdf0e10cSrcweir             {
516*cdf0e10cSrcweir                 if ( pActFieldDescr && pActFieldDescr->getTypeInfo() )
517*cdf0e10cSrcweir                     aInitString = pActFieldDescr->getTypeInfo()->aUIName;
518*cdf0e10cSrcweir 
519*cdf0e10cSrcweir                 //////////////////////////////////////////////////////////////
520*cdf0e10cSrcweir                 // Anpassen des ComboBoxInhalts
521*cdf0e10cSrcweir                 pTypeCell->Clear();
522*cdf0e10cSrcweir                 if( !pActFieldDescr )
523*cdf0e10cSrcweir                     break;
524*cdf0e10cSrcweir 
525*cdf0e10cSrcweir                 const OTypeInfoMap* pTypeInfo = GetView()->getController().getTypeInfo();
526*cdf0e10cSrcweir                 OTypeInfoMap::const_iterator aIter = pTypeInfo->begin();
527*cdf0e10cSrcweir                 OTypeInfoMap::const_iterator aEnd = pTypeInfo->end();
528*cdf0e10cSrcweir                 for(;aIter != aEnd;++aIter)
529*cdf0e10cSrcweir                     pTypeCell->InsertEntry( aIter->second->aUIName );
530*cdf0e10cSrcweir                 pTypeCell->SelectEntry( aInitString );
531*cdf0e10cSrcweir             }
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir             break;
534*cdf0e10cSrcweir         case HELP_TEXT:
535*cdf0e10cSrcweir             if( pActFieldDescr )
536*cdf0e10cSrcweir                 aInitString = pActFieldDescr->GetHelpText();
537*cdf0e10cSrcweir             pHelpTextCell->SetText( aInitString );
538*cdf0e10cSrcweir             pHelpTextCell->SaveValue();
539*cdf0e10cSrcweir             break;
540*cdf0e10cSrcweir         case COLUMN_DESCRIPTION:
541*cdf0e10cSrcweir             if( pActFieldDescr )
542*cdf0e10cSrcweir                 aInitString = pActFieldDescr->GetDescription();
543*cdf0e10cSrcweir             pDescrCell->SetText( aInitString );
544*cdf0e10cSrcweir             pDescrCell->SaveValue();
545*cdf0e10cSrcweir             break;
546*cdf0e10cSrcweir 
547*cdf0e10cSrcweir     }
548*cdf0e10cSrcweir }
549*cdf0e10cSrcweir 
550*cdf0e10cSrcweir //------------------------------------------------------------------------------
551*cdf0e10cSrcweir EditBrowseBox::RowStatus OTableEditorCtrl::GetRowStatus(long nRow) const
552*cdf0e10cSrcweir {
553*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
554*cdf0e10cSrcweir     ( (OTableEditorCtrl*)this )->SetDataPtr( nRow );
555*cdf0e10cSrcweir     if( !pActRow )
556*cdf0e10cSrcweir         return EditBrowseBox::CLEAN;
557*cdf0e10cSrcweir     if (nRow >= 0 && nRow == m_nDataPos)
558*cdf0e10cSrcweir     {
559*cdf0e10cSrcweir         if( pActRow->IsPrimaryKey() )
560*cdf0e10cSrcweir             return EditBrowseBox::CURRENT_PRIMARYKEY;
561*cdf0e10cSrcweir         return EditBrowseBox::CURRENT;
562*cdf0e10cSrcweir     }
563*cdf0e10cSrcweir     else
564*cdf0e10cSrcweir     {
565*cdf0e10cSrcweir         if( pActRow->IsPrimaryKey() )
566*cdf0e10cSrcweir             return EditBrowseBox::PRIMARYKEY;
567*cdf0e10cSrcweir         return EditBrowseBox::CLEAN;
568*cdf0e10cSrcweir     }
569*cdf0e10cSrcweir }
570*cdf0e10cSrcweir 
571*cdf0e10cSrcweir //------------------------------------------------------------------------------
572*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::SaveCurRow()
573*cdf0e10cSrcweir {
574*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
575*cdf0e10cSrcweir     if (GetFieldDescr(GetCurRow()) == NULL)
576*cdf0e10cSrcweir         // in der Zeile, in der ich mich i.A. befinde, stehen keine Daten
577*cdf0e10cSrcweir         return sal_True;
578*cdf0e10cSrcweir     if (!SaveModified())
579*cdf0e10cSrcweir         return sal_False;
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir     SetDataPtr(GetCurRow());
582*cdf0e10cSrcweir     pDescrWin->SaveData( pActRow->GetActFieldDescr() );
583*cdf0e10cSrcweir     return sal_True;
584*cdf0e10cSrcweir }
585*cdf0e10cSrcweir 
586*cdf0e10cSrcweir //------------------------------------------------------------------------------
587*cdf0e10cSrcweir void OTableEditorCtrl::DisplayData(long nRow, sal_Bool bGrabFocus)
588*cdf0e10cSrcweir {
589*cdf0e10cSrcweir     // zur richtigen Zelle fahren
590*cdf0e10cSrcweir     SetDataPtr(nRow);
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir     // Editier-Modus temporaer aus
593*cdf0e10cSrcweir     sal_Bool bWasEditing = IsEditing();
594*cdf0e10cSrcweir     if (bWasEditing)
595*cdf0e10cSrcweir         DeactivateCell();
596*cdf0e10cSrcweir 
597*cdf0e10cSrcweir     CellControllerRef aTemp;
598*cdf0e10cSrcweir     InitController(aTemp, nRow, FIELD_NAME);
599*cdf0e10cSrcweir     InitController(aTemp, nRow, FIELD_TYPE);
600*cdf0e10cSrcweir     InitController(aTemp, nRow, COLUMN_DESCRIPTION);
601*cdf0e10cSrcweir     InitController(aTemp, nRow, HELP_TEXT);
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir     GoToRow(nRow);
604*cdf0e10cSrcweir     // das Description-Window aktualisieren
605*cdf0e10cSrcweir     GetView()->GetDescWin()->DisplayData(GetFieldDescr(nRow));
606*cdf0e10cSrcweir     // neu zeichnen
607*cdf0e10cSrcweir     RowModified(nRow);
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir     // wieder an
610*cdf0e10cSrcweir     if (bWasEditing || bGrabFocus)
611*cdf0e10cSrcweir         ActivateCell(nRow, GetCurColumnId(), bGrabFocus);
612*cdf0e10cSrcweir }
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir //------------------------------------------------------------------------------
615*cdf0e10cSrcweir void OTableEditorCtrl::CursorMoved()
616*cdf0e10cSrcweir {
617*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
618*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
619*cdf0e10cSrcweir     // Zeilenwechsel ?
620*cdf0e10cSrcweir     m_nDataPos = GetCurRow();
621*cdf0e10cSrcweir     if( m_nDataPos != nOldDataPos && m_nDataPos != -1)
622*cdf0e10cSrcweir     {
623*cdf0e10cSrcweir         CellControllerRef aTemp;
624*cdf0e10cSrcweir         InitController(aTemp,m_nDataPos,FIELD_NAME);
625*cdf0e10cSrcweir         InitController(aTemp,m_nDataPos,FIELD_TYPE);
626*cdf0e10cSrcweir         InitController(aTemp,m_nDataPos,COLUMN_DESCRIPTION);
627*cdf0e10cSrcweir         InitController(aTemp,m_nDataPos,HELP_TEXT);
628*cdf0e10cSrcweir     }
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir     OTableRowView::CursorMoved();
631*cdf0e10cSrcweir }
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir //------------------------------------------------------------------------------
634*cdf0e10cSrcweir sal_Int32 OTableEditorCtrl::HasFieldName( const String& rFieldName )
635*cdf0e10cSrcweir {
636*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
637*cdf0e10cSrcweir 
638*cdf0e10cSrcweir     Reference<XConnection> xCon = GetView()->getController().getConnection();
639*cdf0e10cSrcweir     Reference< XDatabaseMetaData> xMetaData = xCon.is() ? xCon->getMetaData() : Reference< XDatabaseMetaData>();
640*cdf0e10cSrcweir 
641*cdf0e10cSrcweir     ::comphelper::UStringMixEqual bCase(xMetaData.is() ? xMetaData->supportsMixedCaseQuotedIdentifiers() : sal_True);
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir     ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aIter = m_pRowList->begin();
644*cdf0e10cSrcweir     ::std::vector< ::boost::shared_ptr<OTableRow> >::iterator aEnd = m_pRowList->end();
645*cdf0e10cSrcweir     OFieldDescription* pFieldDescr;
646*cdf0e10cSrcweir     sal_Int32 nCount(0);
647*cdf0e10cSrcweir     for(;aIter != aEnd;++aIter)
648*cdf0e10cSrcweir     {
649*cdf0e10cSrcweir         pFieldDescr = (*aIter)->GetActFieldDescr();
650*cdf0e10cSrcweir         if( pFieldDescr && bCase(rFieldName,pFieldDescr->GetName()))
651*cdf0e10cSrcweir             nCount++;
652*cdf0e10cSrcweir     }
653*cdf0e10cSrcweir     return nCount;
654*cdf0e10cSrcweir }
655*cdf0e10cSrcweir // --------------------------------------------------------------------------------------
656*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::SaveData(long nRow, sal_uInt16 nColId)
657*cdf0e10cSrcweir {
658*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
659*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////
660*cdf0e10cSrcweir     // Zellinhalte in Datenstruktur speichern
661*cdf0e10cSrcweir     SetDataPtr( nRow == -1 ? GetCurRow() : nRow);
662*cdf0e10cSrcweir     OFieldDescription* pActFieldDescr = pActRow->GetActFieldDescr();
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir     switch( nColId)
665*cdf0e10cSrcweir     {
666*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////
667*cdf0e10cSrcweir         // Speichern Inhalt NameCell
668*cdf0e10cSrcweir         case FIELD_NAME:
669*cdf0e10cSrcweir         {
670*cdf0e10cSrcweir             //////////////////////////////////////////////////////////////
671*cdf0e10cSrcweir             // Wenn kein Name, nichts machen
672*cdf0e10cSrcweir             String aName(pNameCell->GetText());
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir             if( !aName.Len() )
675*cdf0e10cSrcweir             {
676*cdf0e10cSrcweir                 //////////////////////////////////////////////////////////////
677*cdf0e10cSrcweir                 // Wenn FieldDescr existiert, wurde Feld geloescht und alter Inhalt wird wiederhergestellt
678*cdf0e10cSrcweir                 if (pActFieldDescr)
679*cdf0e10cSrcweir                 {
680*cdf0e10cSrcweir                     GetUndoManager().AddUndoAction(new OTableEditorTypeSelUndoAct(this, nRow, FIELD_TYPE, pActFieldDescr->getTypeInfo()));
681*cdf0e10cSrcweir                     SwitchType(TOTypeInfoSP());
682*cdf0e10cSrcweir                     pActFieldDescr = pActRow->GetActFieldDescr();
683*cdf0e10cSrcweir                 }
684*cdf0e10cSrcweir                 else
685*cdf0e10cSrcweir                     return sal_True;
686*cdf0e10cSrcweir             }
687*cdf0e10cSrcweir             if(pActFieldDescr)
688*cdf0e10cSrcweir                 pActFieldDescr->SetName( aName );
689*cdf0e10cSrcweir             pNameCell->ClearModifyFlag();
690*cdf0e10cSrcweir 
691*cdf0e10cSrcweir             break;
692*cdf0e10cSrcweir         }
693*cdf0e10cSrcweir 
694*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////
695*cdf0e10cSrcweir         // Speichern Inhalt TypeCell
696*cdf0e10cSrcweir         case FIELD_TYPE:
697*cdf0e10cSrcweir             break;
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////
700*cdf0e10cSrcweir         // Speichern Inhalt DescrCell
701*cdf0e10cSrcweir         case HELP_TEXT:
702*cdf0e10cSrcweir         {
703*cdf0e10cSrcweir             //////////////////////////////////////////////////////////////
704*cdf0e10cSrcweir             // Wenn aktuelle Feldbeschreibung NULL, Default setzen
705*cdf0e10cSrcweir             if( !pActFieldDescr )
706*cdf0e10cSrcweir             {
707*cdf0e10cSrcweir                 pHelpTextCell->SetText(String());
708*cdf0e10cSrcweir                 pHelpTextCell->ClearModifyFlag();
709*cdf0e10cSrcweir             }
710*cdf0e10cSrcweir             else
711*cdf0e10cSrcweir                 pActFieldDescr->SetHelpText( pHelpTextCell->GetText() );
712*cdf0e10cSrcweir             break;
713*cdf0e10cSrcweir         }
714*cdf0e10cSrcweir         case COLUMN_DESCRIPTION:
715*cdf0e10cSrcweir         {
716*cdf0e10cSrcweir             //////////////////////////////////////////////////////////////
717*cdf0e10cSrcweir             // Wenn aktuelle Feldbeschreibung NULL, Default setzen
718*cdf0e10cSrcweir             if( !pActFieldDescr )
719*cdf0e10cSrcweir             {
720*cdf0e10cSrcweir                 pDescrCell->SetText(String());
721*cdf0e10cSrcweir                 pDescrCell->ClearModifyFlag();
722*cdf0e10cSrcweir             }
723*cdf0e10cSrcweir             else
724*cdf0e10cSrcweir                 pActFieldDescr->SetDescription( pDescrCell->GetText() );
725*cdf0e10cSrcweir             break;
726*cdf0e10cSrcweir         }
727*cdf0e10cSrcweir         case FIELD_PROPERTY_DEFAULT:
728*cdf0e10cSrcweir         case FIELD_PROPERTY_REQUIRED:
729*cdf0e10cSrcweir         case FIELD_PROPERTY_TEXTLEN:
730*cdf0e10cSrcweir         case FIELD_PROPERTY_NUMTYPE:
731*cdf0e10cSrcweir         case FIELD_PROPERTY_AUTOINC:
732*cdf0e10cSrcweir         case FIELD_PROPERTY_LENGTH:
733*cdf0e10cSrcweir         case FIELD_PROPERTY_SCALE:
734*cdf0e10cSrcweir         case FIELD_PROPERTY_BOOL_DEFAULT:
735*cdf0e10cSrcweir             pDescrWin->SaveData(pActFieldDescr);
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir             if ( FIELD_PROPERTY_AUTOINC == nColId && pActFieldDescr->IsAutoIncrement() )
738*cdf0e10cSrcweir             {
739*cdf0e10cSrcweir                 OTableController& rController = GetView()->getController();
740*cdf0e10cSrcweir                 if ( rController.isAutoIncrementPrimaryKey() )
741*cdf0e10cSrcweir                 {
742*cdf0e10cSrcweir                     pActFieldDescr->SetPrimaryKey( true );
743*cdf0e10cSrcweir                     InvalidateHandleColumn();
744*cdf0e10cSrcweir                     Invalidate();
745*cdf0e10cSrcweir                 }
746*cdf0e10cSrcweir             }
747*cdf0e10cSrcweir             break;
748*cdf0e10cSrcweir     }
749*cdf0e10cSrcweir     return sal_True;
750*cdf0e10cSrcweir }
751*cdf0e10cSrcweir 
752*cdf0e10cSrcweir //------------------------------------------------------------------------------
753*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::SaveModified()
754*cdf0e10cSrcweir {
755*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
756*cdf0e10cSrcweir     sal_uInt16 nColId = GetCurColumnId();
757*cdf0e10cSrcweir 
758*cdf0e10cSrcweir     switch( nColId )
759*cdf0e10cSrcweir     {
760*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////
761*cdf0e10cSrcweir         // NameCell
762*cdf0e10cSrcweir         case FIELD_NAME:
763*cdf0e10cSrcweir         {
764*cdf0e10cSrcweir             // removed the former duplicate-check. this is done in OTableDocShell::CheckDefConsistency now.
765*cdf0e10cSrcweir             // FS - 07.12.99 - 69575
766*cdf0e10cSrcweir 
767*cdf0e10cSrcweir         } break;
768*cdf0e10cSrcweir 
769*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////
770*cdf0e10cSrcweir         // TypeCell
771*cdf0e10cSrcweir         case FIELD_TYPE:
772*cdf0e10cSrcweir         {
773*cdf0e10cSrcweir             //////////////////////////////////////////////////////////////////////
774*cdf0e10cSrcweir             // Type umstellen
775*cdf0e10cSrcweir             resetType();
776*cdf0e10cSrcweir         } break;
777*cdf0e10cSrcweir     }
778*cdf0e10cSrcweir 
779*cdf0e10cSrcweir     return sal_True;
780*cdf0e10cSrcweir }
781*cdf0e10cSrcweir 
782*cdf0e10cSrcweir //------------------------------------------------------------------------------
783*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::CursorMoving(long nNewRow, sal_uInt16 nNewCol)
784*cdf0e10cSrcweir {
785*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
786*cdf0e10cSrcweir 
787*cdf0e10cSrcweir     if (!EditBrowseBox::CursorMoving(nNewRow, nNewCol))
788*cdf0e10cSrcweir         return sal_False;
789*cdf0e10cSrcweir 
790*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
791*cdf0e10cSrcweir     // Wird nach SaveModified() gerufen, aktuelle Zeile ist noch die alte
792*cdf0e10cSrcweir     m_nDataPos = nNewRow;
793*cdf0e10cSrcweir     nOldDataPos = GetCurRow();
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
796*cdf0e10cSrcweir     // Marker umsetzen
797*cdf0e10cSrcweir     InvalidateStatusCell( nOldDataPos );
798*cdf0e10cSrcweir     InvalidateStatusCell( m_nDataPos );
799*cdf0e10cSrcweir 
800*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
801*cdf0e10cSrcweir     // Daten des Propertyfensters speichern
802*cdf0e10cSrcweir     if( SetDataPtr(nOldDataPos) && pDescrWin)
803*cdf0e10cSrcweir         pDescrWin->SaveData( pActRow->GetActFieldDescr() );
804*cdf0e10cSrcweir 
805*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
806*cdf0e10cSrcweir     // Neue Daten im Propertyfenster anzeigen
807*cdf0e10cSrcweir     if( SetDataPtr(m_nDataPos) && pDescrWin)
808*cdf0e10cSrcweir         pDescrWin->DisplayData( pActRow->GetActFieldDescr() );
809*cdf0e10cSrcweir 
810*cdf0e10cSrcweir     return sal_True;
811*cdf0e10cSrcweir }
812*cdf0e10cSrcweir 
813*cdf0e10cSrcweir //------------------------------------------------------------------------------
814*cdf0e10cSrcweir IMPL_LINK( OTableEditorCtrl, InvalidateFieldType, void*, /*EMPTYTAG*/ )
815*cdf0e10cSrcweir {
816*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
817*cdf0e10cSrcweir     nInvalidateTypeEvent = 0;
818*cdf0e10cSrcweir     Invalidate( GetFieldRectPixel(nOldDataPos, FIELD_TYPE) );
819*cdf0e10cSrcweir 
820*cdf0e10cSrcweir     return 0;
821*cdf0e10cSrcweir }
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir //------------------------------------------------------------------------------
824*cdf0e10cSrcweir IMPL_LINK( OTableEditorCtrl, EntryNotFound, void*, /*EMPTYTAG*/ )
825*cdf0e10cSrcweir {
826*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
827*cdf0e10cSrcweir     nEntryNotFoundEvent = 0;
828*cdf0e10cSrcweir     ErrorBox( this, ModuleRes(ERR_INVALID_LISTBOX_ENTRY) ).Execute();
829*cdf0e10cSrcweir 
830*cdf0e10cSrcweir     return 0;
831*cdf0e10cSrcweir }
832*cdf0e10cSrcweir 
833*cdf0e10cSrcweir //------------------------------------------------------------------------------
834*cdf0e10cSrcweir void OTableEditorCtrl::CellModified( long nRow, sal_uInt16 nColId )
835*cdf0e10cSrcweir {
836*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
837*cdf0e10cSrcweir 
838*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////
839*cdf0e10cSrcweir     // Wenn aktuelle Feldbeschreibung NULL, Default setzen
840*cdf0e10cSrcweir     if(nRow == -1)
841*cdf0e10cSrcweir         nRow = GetCurRow();
842*cdf0e10cSrcweir     SetDataPtr( nRow );
843*cdf0e10cSrcweir     OFieldDescription* pActFieldDescr = pActRow->GetActFieldDescr();
844*cdf0e10cSrcweir 
845*cdf0e10cSrcweir     String sActionDescription;
846*cdf0e10cSrcweir     switch ( nColId )
847*cdf0e10cSrcweir     {
848*cdf0e10cSrcweir     case FIELD_NAME:    sActionDescription = String( ModuleRes( STR_CHANGE_COLUMN_NAME ) ); break;
849*cdf0e10cSrcweir     case FIELD_TYPE:    sActionDescription = String( ModuleRes( STR_CHANGE_COLUMN_TYPE ) ); break;
850*cdf0e10cSrcweir     case HELP_TEXT:
851*cdf0e10cSrcweir     case COLUMN_DESCRIPTION:   sActionDescription = String( ModuleRes( STR_CHANGE_COLUMN_DESCRIPTION ) ); break;
852*cdf0e10cSrcweir     default:            sActionDescription = String( ModuleRes( STR_CHANGE_COLUMN_ATTRIBUTE ) ); break;
853*cdf0e10cSrcweir     }
854*cdf0e10cSrcweir 
855*cdf0e10cSrcweir     GetUndoManager().EnterListAction( sActionDescription, String() );
856*cdf0e10cSrcweir     if (!pActFieldDescr)
857*cdf0e10cSrcweir     {
858*cdf0e10cSrcweir         const OTypeInfoMap* pTypeInfoMap = GetView()->getController().getTypeInfo();
859*cdf0e10cSrcweir         if ( !pTypeInfoMap->empty() )
860*cdf0e10cSrcweir         {
861*cdf0e10cSrcweir             OTypeInfoMap::const_iterator aTypeIter = pTypeInfoMap->find(DataType::VARCHAR);
862*cdf0e10cSrcweir             if ( aTypeIter == pTypeInfoMap->end() )
863*cdf0e10cSrcweir                 aTypeIter = pTypeInfoMap->begin();
864*cdf0e10cSrcweir             pActRow->SetFieldType( aTypeIter->second );
865*cdf0e10cSrcweir         }
866*cdf0e10cSrcweir         else
867*cdf0e10cSrcweir             pActRow->SetFieldType( GetView()->getController().getTypeInfoFallBack() );
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir         nInvalidateTypeEvent = Application::PostUserEvent( LINK(this, OTableEditorCtrl, InvalidateFieldType) );
870*cdf0e10cSrcweir         pActFieldDescr = pActRow->GetActFieldDescr();
871*cdf0e10cSrcweir         pDescrWin->DisplayData( pActFieldDescr );
872*cdf0e10cSrcweir         GetUndoManager().AddUndoAction( new OTableEditorTypeSelUndoAct(this, nRow, nColId+1, TOTypeInfoSP()) );
873*cdf0e10cSrcweir     }
874*cdf0e10cSrcweir 
875*cdf0e10cSrcweir     if( nColId != FIELD_TYPE )
876*cdf0e10cSrcweir         GetUndoManager().AddUndoAction( new OTableDesignCellUndoAct(this, nRow, nColId) );
877*cdf0e10cSrcweir     else
878*cdf0e10cSrcweir     {
879*cdf0e10cSrcweir         GetUndoManager().AddUndoAction(new OTableEditorTypeSelUndoAct(this, GetCurRow(), nColId, GetFieldDescr(GetCurRow())->getTypeInfo()));
880*cdf0e10cSrcweir         resetType();
881*cdf0e10cSrcweir     }
882*cdf0e10cSrcweir 
883*cdf0e10cSrcweir     SaveData(nRow,nColId);
884*cdf0e10cSrcweir     // SaveData could create a undo action as well
885*cdf0e10cSrcweir     GetUndoManager().LeaveListAction();
886*cdf0e10cSrcweir     RowModified(nRow);
887*cdf0e10cSrcweir     CellControllerRef xController(Controller());
888*cdf0e10cSrcweir     if(xController.Is())
889*cdf0e10cSrcweir         xController->SetModified();
890*cdf0e10cSrcweir 
891*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
892*cdf0e10cSrcweir     // Das ModifyFlag setzen
893*cdf0e10cSrcweir     GetView()->getController().setModified( sal_True );
894*cdf0e10cSrcweir     InvalidateFeatures();
895*cdf0e10cSrcweir }
896*cdf0e10cSrcweir // -----------------------------------------------------------------------------
897*cdf0e10cSrcweir void OTableEditorCtrl::resetType()
898*cdf0e10cSrcweir {
899*cdf0e10cSrcweir     sal_uInt16 nPos = pTypeCell->GetSelectEntryPos();
900*cdf0e10cSrcweir     if(nPos != LISTBOX_ENTRY_NOTFOUND)
901*cdf0e10cSrcweir         SwitchType( GetView()->getController().getTypeInfo(nPos) );
902*cdf0e10cSrcweir     else
903*cdf0e10cSrcweir         SwitchType(TOTypeInfoSP());
904*cdf0e10cSrcweir }
905*cdf0e10cSrcweir //------------------------------------------------------------------------------
906*cdf0e10cSrcweir void OTableEditorCtrl::CellModified()
907*cdf0e10cSrcweir {
908*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
909*cdf0e10cSrcweir     CellModified( GetCurRow(), GetCurColumnId() );
910*cdf0e10cSrcweir }
911*cdf0e10cSrcweir // -----------------------------------------------------------------------------
912*cdf0e10cSrcweir void OTableEditorCtrl::InvalidateFeatures()
913*cdf0e10cSrcweir {
914*cdf0e10cSrcweir     GetView()->getController().InvalidateFeature(SID_UNDO);
915*cdf0e10cSrcweir     GetView()->getController().InvalidateFeature(SID_REDO);
916*cdf0e10cSrcweir     GetView()->getController().InvalidateFeature(SID_SAVEDOC);
917*cdf0e10cSrcweir }
918*cdf0e10cSrcweir //------------------------------------------------------------------------------
919*cdf0e10cSrcweir void OTableEditorCtrl::Undo()
920*cdf0e10cSrcweir {
921*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
922*cdf0e10cSrcweir 
923*cdf0e10cSrcweir     InvalidateFeatures();
924*cdf0e10cSrcweir }
925*cdf0e10cSrcweir //------------------------------------------------------------------------------
926*cdf0e10cSrcweir void OTableEditorCtrl::Redo()
927*cdf0e10cSrcweir {
928*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
929*cdf0e10cSrcweir     InvalidateFeatures();
930*cdf0e10cSrcweir }
931*cdf0e10cSrcweir 
932*cdf0e10cSrcweir //------------------------------------------------------------------------------
933*cdf0e10cSrcweir void OTableEditorCtrl::CopyRows()
934*cdf0e10cSrcweir {
935*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
936*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
937*cdf0e10cSrcweir     // set to the right row and save it
938*cdf0e10cSrcweir     if( SetDataPtr(m_nDataPos) )
939*cdf0e10cSrcweir         pDescrWin->SaveData( pActRow->GetActFieldDescr() );
940*cdf0e10cSrcweir 
941*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
942*cdf0e10cSrcweir     // Selektierte Zeilen in die ClipboardListe kopieren
943*cdf0e10cSrcweir      ::boost::shared_ptr<OTableRow>  pClipboardRow;
944*cdf0e10cSrcweir      ::boost::shared_ptr<OTableRow>  pRow;
945*cdf0e10cSrcweir     ::std::vector< ::boost::shared_ptr<OTableRow> > vClipboardList;
946*cdf0e10cSrcweir     vClipboardList.reserve(GetSelectRowCount());
947*cdf0e10cSrcweir 
948*cdf0e10cSrcweir     for( long nIndex=FirstSelectedRow(); nIndex >= 0 && nIndex < static_cast<long>(m_pRowList->size()); nIndex=NextSelectedRow() )
949*cdf0e10cSrcweir     {
950*cdf0e10cSrcweir         pRow = (*m_pRowList)[nIndex];
951*cdf0e10cSrcweir         OSL_ENSURE(pRow,"OTableEditorCtrl::CopyRows: Row is NULL!");
952*cdf0e10cSrcweir         if ( pRow && pRow->GetActFieldDescr() )
953*cdf0e10cSrcweir         {
954*cdf0e10cSrcweir             pClipboardRow.reset(new OTableRow( *pRow ));
955*cdf0e10cSrcweir             vClipboardList.push_back( pClipboardRow);
956*cdf0e10cSrcweir         }
957*cdf0e10cSrcweir     }
958*cdf0e10cSrcweir     if(!vClipboardList.empty())
959*cdf0e10cSrcweir     {
960*cdf0e10cSrcweir         OTableRowExchange* pData = new OTableRowExchange(vClipboardList);
961*cdf0e10cSrcweir         Reference< ::com::sun::star::datatransfer::XTransferable> xRef = pData;
962*cdf0e10cSrcweir         pData->CopyToClipboard(GetParent());
963*cdf0e10cSrcweir     }
964*cdf0e10cSrcweir }
965*cdf0e10cSrcweir 
966*cdf0e10cSrcweir //------------------------------------------------------------------------------
967*cdf0e10cSrcweir String OTableEditorCtrl::GenerateName( const String& rName )
968*cdf0e10cSrcweir {
969*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
970*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
971*cdf0e10cSrcweir     // Basisnamen zum Anhaengen einer Numerierung erstellen
972*cdf0e10cSrcweir     String aBaseName;
973*cdf0e10cSrcweir     Reference<XConnection> xCon = GetView()->getController().getConnection();
974*cdf0e10cSrcweir     Reference< XDatabaseMetaData> xMetaData = xCon.is() ? xCon->getMetaData() : Reference< XDatabaseMetaData>();
975*cdf0e10cSrcweir 
976*cdf0e10cSrcweir     xub_StrLen nMaxTextLen((xub_StrLen)( xMetaData.is() ? xMetaData->getMaxColumnNameLength() : 0));
977*cdf0e10cSrcweir 
978*cdf0e10cSrcweir     if( (rName.Len()+2) >nMaxTextLen )
979*cdf0e10cSrcweir         aBaseName = rName.Copy( 0, nMaxTextLen-2 );
980*cdf0e10cSrcweir     else
981*cdf0e10cSrcweir         aBaseName = rName;
982*cdf0e10cSrcweir 
983*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
984*cdf0e10cSrcweir     // Namen durchnumerieren (bis 99)
985*cdf0e10cSrcweir     String aFieldName( rName);
986*cdf0e10cSrcweir     sal_Int32 i=1;
987*cdf0e10cSrcweir     while( HasFieldName(aFieldName) )
988*cdf0e10cSrcweir     {
989*cdf0e10cSrcweir         aFieldName = aBaseName;
990*cdf0e10cSrcweir         aFieldName += String::CreateFromInt32(i);
991*cdf0e10cSrcweir         i++;
992*cdf0e10cSrcweir     }
993*cdf0e10cSrcweir 
994*cdf0e10cSrcweir     return aFieldName;
995*cdf0e10cSrcweir }
996*cdf0e10cSrcweir 
997*cdf0e10cSrcweir //------------------------------------------------------------------------------
998*cdf0e10cSrcweir void OTableEditorCtrl::InsertRows( long nRow )
999*cdf0e10cSrcweir {
1000*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1001*cdf0e10cSrcweir 
1002*cdf0e10cSrcweir     ::std::vector<  ::boost::shared_ptr<OTableRow> > vInsertedUndoRedoRows; // need for undo/redo handling
1003*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1004*cdf0e10cSrcweir     // get rows from clipboard
1005*cdf0e10cSrcweir     TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
1006*cdf0e10cSrcweir     if(aTransferData.HasFormat(SOT_FORMATSTR_ID_SBA_TABED))
1007*cdf0e10cSrcweir     {
1008*cdf0e10cSrcweir         SotStorageStreamRef aStreamRef;
1009*cdf0e10cSrcweir         aTransferData.GetSotStorageStream(SOT_FORMATSTR_ID_SBA_TABED,aStreamRef);
1010*cdf0e10cSrcweir         if(aStreamRef.Is())
1011*cdf0e10cSrcweir         {
1012*cdf0e10cSrcweir             aStreamRef->Seek(STREAM_SEEK_TO_BEGIN);
1013*cdf0e10cSrcweir             aStreamRef->ResetError();
1014*cdf0e10cSrcweir             long nInsertRow = nRow;
1015*cdf0e10cSrcweir             String aFieldName;
1016*cdf0e10cSrcweir              ::boost::shared_ptr<OTableRow>  pRow;
1017*cdf0e10cSrcweir             sal_Int32 nSize = 0;
1018*cdf0e10cSrcweir             (*aStreamRef) >> nSize;
1019*cdf0e10cSrcweir             vInsertedUndoRedoRows.reserve(nSize);
1020*cdf0e10cSrcweir             for(sal_Int32 i=0;i < nSize;++i)
1021*cdf0e10cSrcweir             {
1022*cdf0e10cSrcweir                 pRow.reset(new OTableRow());
1023*cdf0e10cSrcweir                 (*aStreamRef) >> *pRow;
1024*cdf0e10cSrcweir                 pRow->SetReadOnly( sal_False );
1025*cdf0e10cSrcweir                 sal_Int32 nType = pRow->GetActFieldDescr()->GetType();
1026*cdf0e10cSrcweir                 if ( pRow->GetActFieldDescr() )
1027*cdf0e10cSrcweir                     pRow->GetActFieldDescr()->SetType(GetView()->getController().getTypeInfoByType(nType));
1028*cdf0e10cSrcweir                 //////////////////////////////////////////////////////////////////////
1029*cdf0e10cSrcweir                 // Anpassen des Feldnamens
1030*cdf0e10cSrcweir                 aFieldName = GenerateName( pRow->GetActFieldDescr()->GetName() );
1031*cdf0e10cSrcweir                 pRow->GetActFieldDescr()->SetName( aFieldName );
1032*cdf0e10cSrcweir                 pRow->SetPos(nInsertRow);
1033*cdf0e10cSrcweir                 m_pRowList->insert( m_pRowList->begin()+nInsertRow,pRow );
1034*cdf0e10cSrcweir                 vInsertedUndoRedoRows.push_back(::boost::shared_ptr<OTableRow>(new OTableRow(*pRow)));
1035*cdf0e10cSrcweir                 nInsertRow++;
1036*cdf0e10cSrcweir             }
1037*cdf0e10cSrcweir         }
1038*cdf0e10cSrcweir     }
1039*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1040*cdf0e10cSrcweir     // Beim RowInserted wird CursorMoved gerufen.
1041*cdf0e10cSrcweir     // Die UI-Daten duerfen hier beim CursorMoved nicht gespeichert werden.
1042*cdf0e10cSrcweir     bSaveOnMove = sal_False;
1043*cdf0e10cSrcweir     RowInserted( nRow,vInsertedUndoRedoRows.size(),sal_True );
1044*cdf0e10cSrcweir     bSaveOnMove = sal_True;
1045*cdf0e10cSrcweir 
1046*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1047*cdf0e10cSrcweir     // Undo-Action erzeugen
1048*cdf0e10cSrcweir     GetUndoManager().AddUndoAction( new OTableEditorInsUndoAct(this, nRow,vInsertedUndoRedoRows) );
1049*cdf0e10cSrcweir     GetView()->getController().setModified( sal_True );
1050*cdf0e10cSrcweir     InvalidateFeatures();
1051*cdf0e10cSrcweir }
1052*cdf0e10cSrcweir 
1053*cdf0e10cSrcweir //------------------------------------------------------------------------------
1054*cdf0e10cSrcweir void OTableEditorCtrl::DeleteRows()
1055*cdf0e10cSrcweir {
1056*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1057*cdf0e10cSrcweir     OSL_ENSURE(GetView()->getController().isDropAllowed(),"Call of DeleteRows not valid here. Please check isDropAllowed!");
1058*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1059*cdf0e10cSrcweir     // Undo-Action erzeugen
1060*cdf0e10cSrcweir     GetUndoManager().AddUndoAction( new OTableEditorDelUndoAct(this) );
1061*cdf0e10cSrcweir 
1062*cdf0e10cSrcweir 
1063*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1064*cdf0e10cSrcweir     // Alle markierten Zeilen loeschen
1065*cdf0e10cSrcweir     long nIndex = FirstSelectedRow();
1066*cdf0e10cSrcweir     nOldDataPos = nIndex;
1067*cdf0e10cSrcweir     bSaveOnMove = sal_False;
1068*cdf0e10cSrcweir 
1069*cdf0e10cSrcweir     while( nIndex >= 0 && nIndex < static_cast<long>(m_pRowList->size()) )
1070*cdf0e10cSrcweir     {
1071*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////////
1072*cdf0e10cSrcweir         // Zeile entfernen
1073*cdf0e10cSrcweir         m_pRowList->erase( m_pRowList->begin()+nIndex );
1074*cdf0e10cSrcweir         RowRemoved( nIndex, 1, sal_True );
1075*cdf0e10cSrcweir 
1076*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////////
1077*cdf0e10cSrcweir         // Leerzeile am Ende wieder einfuegen
1078*cdf0e10cSrcweir         m_pRowList->push_back( ::boost::shared_ptr<OTableRow>(new OTableRow()));
1079*cdf0e10cSrcweir         RowInserted( GetRowCount()-1, 1, sal_True );
1080*cdf0e10cSrcweir 
1081*cdf0e10cSrcweir         nIndex = FirstSelectedRow();
1082*cdf0e10cSrcweir     }
1083*cdf0e10cSrcweir 
1084*cdf0e10cSrcweir     bSaveOnMove = sal_True;
1085*cdf0e10cSrcweir 
1086*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1087*cdf0e10cSrcweir     // Erzwingen, dass der aktuelle Datensatz angezeigt wird
1088*cdf0e10cSrcweir     m_nDataPos = GetCurRow();
1089*cdf0e10cSrcweir     InvalidateStatusCell( nOldDataPos );
1090*cdf0e10cSrcweir     InvalidateStatusCell( m_nDataPos );
1091*cdf0e10cSrcweir     SetDataPtr( m_nDataPos );
1092*cdf0e10cSrcweir     ActivateCell();
1093*cdf0e10cSrcweir     pDescrWin->DisplayData( pActRow->GetActFieldDescr() );
1094*cdf0e10cSrcweir     GetView()->getController().setModified( sal_True );
1095*cdf0e10cSrcweir     InvalidateFeatures();
1096*cdf0e10cSrcweir }
1097*cdf0e10cSrcweir 
1098*cdf0e10cSrcweir //------------------------------------------------------------------------------
1099*cdf0e10cSrcweir void OTableEditorCtrl::InsertNewRows( long nRow )
1100*cdf0e10cSrcweir {
1101*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1102*cdf0e10cSrcweir     OSL_ENSURE(GetView()->getController().isAddAllowed(),"Call of InsertNewRows not valid here. Please check isAppendAllowed!");
1103*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1104*cdf0e10cSrcweir     // Undo-Action erzeugen
1105*cdf0e10cSrcweir     long nInsertRows = GetSelectRowCount();
1106*cdf0e10cSrcweir     if( !nInsertRows )
1107*cdf0e10cSrcweir         nInsertRows = 1;
1108*cdf0e10cSrcweir     GetUndoManager().AddUndoAction( new OTableEditorInsNewUndoAct(this, nRow, nInsertRows) );
1109*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1110*cdf0e10cSrcweir     // Zahl der selektierten Zeilen werden neu eingefuegt
1111*cdf0e10cSrcweir     for( long i=nRow; i<(nRow+nInsertRows); i++ )
1112*cdf0e10cSrcweir         m_pRowList->insert( m_pRowList->begin()+i ,::boost::shared_ptr<OTableRow>(new OTableRow()));
1113*cdf0e10cSrcweir     RowInserted( nRow, nInsertRows, sal_True );
1114*cdf0e10cSrcweir 
1115*cdf0e10cSrcweir     GetView()->getController().setModified( sal_True );
1116*cdf0e10cSrcweir     InvalidateFeatures();
1117*cdf0e10cSrcweir }
1118*cdf0e10cSrcweir 
1119*cdf0e10cSrcweir //------------------------------------------------------------------------------
1120*cdf0e10cSrcweir String OTableEditorCtrl::GetControlText( long nRow, sal_uInt16 nColId )
1121*cdf0e10cSrcweir {
1122*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1123*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1124*cdf0e10cSrcweir     // Controls des Browsers auslesen
1125*cdf0e10cSrcweir     if( nColId < FIELD_FIRST_VIRTUAL_COLUMN )
1126*cdf0e10cSrcweir     {
1127*cdf0e10cSrcweir         GoToRow( nRow );
1128*cdf0e10cSrcweir         GoToColumnId( nColId );
1129*cdf0e10cSrcweir         CellControllerRef xController = Controller();
1130*cdf0e10cSrcweir         if(xController.Is())
1131*cdf0e10cSrcweir             return xController->GetWindow().GetText();
1132*cdf0e10cSrcweir         else
1133*cdf0e10cSrcweir             return GetCellText(nRow,nColId);
1134*cdf0e10cSrcweir     }
1135*cdf0e10cSrcweir 
1136*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1137*cdf0e10cSrcweir     // Controls der Tabpage Auslesen
1138*cdf0e10cSrcweir     else
1139*cdf0e10cSrcweir         return pDescrWin->GetControlText( nColId );
1140*cdf0e10cSrcweir }
1141*cdf0e10cSrcweir 
1142*cdf0e10cSrcweir //------------------------------------------------------------------------------
1143*cdf0e10cSrcweir void OTableEditorCtrl::SetControlText( long nRow, sal_uInt16 nColId, const String& rText )
1144*cdf0e10cSrcweir {
1145*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1146*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1147*cdf0e10cSrcweir     // Controls des Browsers setzen
1148*cdf0e10cSrcweir     if( nColId < FIELD_FIRST_VIRTUAL_COLUMN )
1149*cdf0e10cSrcweir     {
1150*cdf0e10cSrcweir         GoToRow( nRow );
1151*cdf0e10cSrcweir         GoToColumnId( nColId );
1152*cdf0e10cSrcweir         CellControllerRef xController = Controller();
1153*cdf0e10cSrcweir         if(xController.Is())
1154*cdf0e10cSrcweir             xController->GetWindow().SetText( rText );
1155*cdf0e10cSrcweir         else
1156*cdf0e10cSrcweir             RowModified(nRow,nColId);
1157*cdf0e10cSrcweir     }
1158*cdf0e10cSrcweir 
1159*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1160*cdf0e10cSrcweir     // Controls der Tabpage setzen
1161*cdf0e10cSrcweir     else
1162*cdf0e10cSrcweir     {
1163*cdf0e10cSrcweir         pDescrWin->SetControlText( nColId, rText );
1164*cdf0e10cSrcweir     }
1165*cdf0e10cSrcweir }
1166*cdf0e10cSrcweir //------------------------------------------------------------------------------
1167*cdf0e10cSrcweir void OTableEditorCtrl::SetCellData( long nRow, sal_uInt16 nColId, const TOTypeInfoSP& _pTypeInfo )
1168*cdf0e10cSrcweir {
1169*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1170*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1171*cdf0e10cSrcweir     // Aktuellen Datenzeiger umsetzen
1172*cdf0e10cSrcweir     if( nRow == -1 )
1173*cdf0e10cSrcweir         nRow = GetCurRow();
1174*cdf0e10cSrcweir     OFieldDescription* pFieldDescr = GetFieldDescr( nRow );
1175*cdf0e10cSrcweir     if( !pFieldDescr && nColId != FIELD_TYPE)
1176*cdf0e10cSrcweir         return;
1177*cdf0e10cSrcweir 
1178*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1179*cdf0e10cSrcweir     // Einzelne Felder setzen
1180*cdf0e10cSrcweir     switch( nColId )
1181*cdf0e10cSrcweir     {
1182*cdf0e10cSrcweir         case FIELD_TYPE:
1183*cdf0e10cSrcweir             SwitchType( _pTypeInfo );
1184*cdf0e10cSrcweir             break;
1185*cdf0e10cSrcweir         default:
1186*cdf0e10cSrcweir             OSL_ENSURE(sal_False, "OTableEditorCtrl::SetCellData: invalid column!");
1187*cdf0e10cSrcweir     }
1188*cdf0e10cSrcweir     SetControlText(nRow,nColId,_pTypeInfo.get() ? _pTypeInfo->aUIName : ::rtl::OUString());
1189*cdf0e10cSrcweir }
1190*cdf0e10cSrcweir //------------------------------------------------------------------------------
1191*cdf0e10cSrcweir void OTableEditorCtrl::SetCellData( long nRow, sal_uInt16 nColId, const ::com::sun::star::uno::Any& _rNewData )
1192*cdf0e10cSrcweir {
1193*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1194*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1195*cdf0e10cSrcweir     // Aktuellen Datenzeiger umsetzen
1196*cdf0e10cSrcweir     if( nRow == -1 )
1197*cdf0e10cSrcweir         nRow = GetCurRow();
1198*cdf0e10cSrcweir     OFieldDescription* pFieldDescr = GetFieldDescr( nRow );
1199*cdf0e10cSrcweir     if( !pFieldDescr && nColId != FIELD_TYPE)
1200*cdf0e10cSrcweir         return;
1201*cdf0e10cSrcweir 
1202*cdf0e10cSrcweir     String sValue;
1203*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1204*cdf0e10cSrcweir     // Einzelne Felder setzen
1205*cdf0e10cSrcweir     switch( nColId )
1206*cdf0e10cSrcweir     {
1207*cdf0e10cSrcweir         case FIELD_NAME:
1208*cdf0e10cSrcweir             sValue = ::comphelper::getString(_rNewData);
1209*cdf0e10cSrcweir             pFieldDescr->SetName( sValue );
1210*cdf0e10cSrcweir             break;
1211*cdf0e10cSrcweir 
1212*cdf0e10cSrcweir         case FIELD_TYPE:
1213*cdf0e10cSrcweir             OSL_ENSURE(sal_False, "OTableEditorCtrl::SetCellData: invalid column!");
1214*cdf0e10cSrcweir             break;
1215*cdf0e10cSrcweir 
1216*cdf0e10cSrcweir         case COLUMN_DESCRIPTION:
1217*cdf0e10cSrcweir             pFieldDescr->SetDescription( sValue = ::comphelper::getString(_rNewData) );
1218*cdf0e10cSrcweir             break;
1219*cdf0e10cSrcweir 
1220*cdf0e10cSrcweir         case FIELD_PROPERTY_DEFAULT:
1221*cdf0e10cSrcweir             pFieldDescr->SetControlDefault( _rNewData );
1222*cdf0e10cSrcweir             sValue = GetView()->GetDescWin()->getGenPage()->getFieldControl()->getControlDefault(pFieldDescr);
1223*cdf0e10cSrcweir             break;
1224*cdf0e10cSrcweir 
1225*cdf0e10cSrcweir         case FIELD_PROPERTY_REQUIRED:
1226*cdf0e10cSrcweir             {
1227*cdf0e10cSrcweir                 sValue = ::comphelper::getString(_rNewData);
1228*cdf0e10cSrcweir                 pFieldDescr->SetIsNullable( sValue.ToInt32() );
1229*cdf0e10cSrcweir             }
1230*cdf0e10cSrcweir             break;
1231*cdf0e10cSrcweir 
1232*cdf0e10cSrcweir         case FIELD_PROPERTY_TEXTLEN:
1233*cdf0e10cSrcweir         case FIELD_PROPERTY_LENGTH:
1234*cdf0e10cSrcweir             {
1235*cdf0e10cSrcweir                 sValue = ::comphelper::getString(_rNewData);
1236*cdf0e10cSrcweir                 pFieldDescr->SetPrecision( sValue.ToInt32() );
1237*cdf0e10cSrcweir             }
1238*cdf0e10cSrcweir             break;
1239*cdf0e10cSrcweir 
1240*cdf0e10cSrcweir         case FIELD_PROPERTY_NUMTYPE:
1241*cdf0e10cSrcweir             //  pFieldDescr->SetNumType( _rNewData );
1242*cdf0e10cSrcweir             OSL_ENSURE(sal_False, "OTableEditorCtrl::SetCellData: invalid column!");
1243*cdf0e10cSrcweir             break;
1244*cdf0e10cSrcweir 
1245*cdf0e10cSrcweir         case FIELD_PROPERTY_AUTOINC:
1246*cdf0e10cSrcweir             {
1247*cdf0e10cSrcweir                 String strYes(ModuleRes(STR_VALUE_YES));
1248*cdf0e10cSrcweir                 sValue = ::comphelper::getString(_rNewData);
1249*cdf0e10cSrcweir                 pFieldDescr->SetAutoIncrement(sValue.Equals(strYes));
1250*cdf0e10cSrcweir             }
1251*cdf0e10cSrcweir             break;
1252*cdf0e10cSrcweir         case FIELD_PROPERTY_SCALE:
1253*cdf0e10cSrcweir             {
1254*cdf0e10cSrcweir                 sValue = ::comphelper::getString(_rNewData);
1255*cdf0e10cSrcweir                 pFieldDescr->SetScale(sValue.ToInt32());
1256*cdf0e10cSrcweir             }
1257*cdf0e10cSrcweir             break;
1258*cdf0e10cSrcweir 
1259*cdf0e10cSrcweir         case FIELD_PROPERTY_BOOL_DEFAULT:
1260*cdf0e10cSrcweir             sValue = GetView()->GetDescWin()->BoolStringPersistent(::comphelper::getString(_rNewData));
1261*cdf0e10cSrcweir             pFieldDescr->SetControlDefault(makeAny(::rtl::OUString(sValue)));
1262*cdf0e10cSrcweir             break;
1263*cdf0e10cSrcweir 
1264*cdf0e10cSrcweir         case FIELD_PROPERTY_FORMAT:
1265*cdf0e10cSrcweir             {
1266*cdf0e10cSrcweir                 sValue = ::comphelper::getString(_rNewData);
1267*cdf0e10cSrcweir                 pFieldDescr->SetFormatKey(sValue.ToInt32());
1268*cdf0e10cSrcweir             }
1269*cdf0e10cSrcweir             break;
1270*cdf0e10cSrcweir     }
1271*cdf0e10cSrcweir 
1272*cdf0e10cSrcweir     SetControlText(nRow,nColId,sValue);
1273*cdf0e10cSrcweir }
1274*cdf0e10cSrcweir 
1275*cdf0e10cSrcweir //------------------------------------------------------------------------------
1276*cdf0e10cSrcweir Any OTableEditorCtrl::GetCellData( long nRow, sal_uInt16 nColId )
1277*cdf0e10cSrcweir {
1278*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1279*cdf0e10cSrcweir     OFieldDescription* pFieldDescr = GetFieldDescr( nRow );
1280*cdf0e10cSrcweir     if( !pFieldDescr )
1281*cdf0e10cSrcweir         return Any();
1282*cdf0e10cSrcweir 
1283*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1284*cdf0e10cSrcweir     // Aktuellen Datenzeiger umsetzen
1285*cdf0e10cSrcweir     if( nRow==-1 )
1286*cdf0e10cSrcweir         nRow = GetCurRow();
1287*cdf0e10cSrcweir     SetDataPtr( nRow );
1288*cdf0e10cSrcweir 
1289*cdf0e10cSrcweir     static const String strYes(ModuleRes(STR_VALUE_YES));
1290*cdf0e10cSrcweir     static const String strNo(ModuleRes(STR_VALUE_NO));
1291*cdf0e10cSrcweir     ::rtl::OUString sValue;
1292*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1293*cdf0e10cSrcweir     // Einzelne Felder auslesen
1294*cdf0e10cSrcweir     switch( nColId )
1295*cdf0e10cSrcweir     {
1296*cdf0e10cSrcweir         case FIELD_NAME:
1297*cdf0e10cSrcweir             sValue = pFieldDescr->GetName();
1298*cdf0e10cSrcweir             break;
1299*cdf0e10cSrcweir 
1300*cdf0e10cSrcweir         case FIELD_TYPE:
1301*cdf0e10cSrcweir             if ( pFieldDescr->getTypeInfo() )
1302*cdf0e10cSrcweir                 sValue = pFieldDescr->getTypeInfo()->aUIName;
1303*cdf0e10cSrcweir             break;
1304*cdf0e10cSrcweir 
1305*cdf0e10cSrcweir         case COLUMN_DESCRIPTION:
1306*cdf0e10cSrcweir             sValue = pFieldDescr->GetDescription();
1307*cdf0e10cSrcweir             break;
1308*cdf0e10cSrcweir         case HELP_TEXT:
1309*cdf0e10cSrcweir             sValue = pFieldDescr->GetHelpText();
1310*cdf0e10cSrcweir             break;
1311*cdf0e10cSrcweir 
1312*cdf0e10cSrcweir         case FIELD_PROPERTY_DEFAULT:
1313*cdf0e10cSrcweir             return pFieldDescr->GetControlDefault();
1314*cdf0e10cSrcweir 
1315*cdf0e10cSrcweir         case FIELD_PROPERTY_REQUIRED:
1316*cdf0e10cSrcweir             sValue = pFieldDescr->GetIsNullable() == ColumnValue::NULLABLE ? strYes : strNo;
1317*cdf0e10cSrcweir             break;
1318*cdf0e10cSrcweir 
1319*cdf0e10cSrcweir         case FIELD_PROPERTY_TEXTLEN:
1320*cdf0e10cSrcweir         case FIELD_PROPERTY_LENGTH:
1321*cdf0e10cSrcweir             sValue = String::CreateFromInt32(pFieldDescr->GetPrecision());
1322*cdf0e10cSrcweir             break;
1323*cdf0e10cSrcweir 
1324*cdf0e10cSrcweir         case FIELD_PROPERTY_NUMTYPE:
1325*cdf0e10cSrcweir             OSL_ENSURE(sal_False, "OTableEditorCtrl::GetCellData: invalid column!");
1326*cdf0e10cSrcweir             //  return pFieldDescr->GetNumType();
1327*cdf0e10cSrcweir 
1328*cdf0e10cSrcweir         case FIELD_PROPERTY_AUTOINC:
1329*cdf0e10cSrcweir             sValue = pFieldDescr->IsAutoIncrement() ? strYes : strNo;
1330*cdf0e10cSrcweir             break;
1331*cdf0e10cSrcweir 
1332*cdf0e10cSrcweir         case FIELD_PROPERTY_SCALE:
1333*cdf0e10cSrcweir             sValue = String::CreateFromInt32(pFieldDescr->GetScale());
1334*cdf0e10cSrcweir             break;
1335*cdf0e10cSrcweir 
1336*cdf0e10cSrcweir         case FIELD_PROPERTY_BOOL_DEFAULT:
1337*cdf0e10cSrcweir             sValue = GetView()->GetDescWin()->BoolStringUI(::comphelper::getString(pFieldDescr->GetControlDefault()));
1338*cdf0e10cSrcweir             break;
1339*cdf0e10cSrcweir 
1340*cdf0e10cSrcweir         case FIELD_PROPERTY_FORMAT:
1341*cdf0e10cSrcweir             sValue = String::CreateFromInt32(pFieldDescr->GetFormatKey());
1342*cdf0e10cSrcweir             break;
1343*cdf0e10cSrcweir     }
1344*cdf0e10cSrcweir 
1345*cdf0e10cSrcweir     return makeAny(sValue);
1346*cdf0e10cSrcweir }
1347*cdf0e10cSrcweir 
1348*cdf0e10cSrcweir //------------------------------------------------------------------------------
1349*cdf0e10cSrcweir String OTableEditorCtrl::GetCellText( long nRow, sal_uInt16 nColId ) const
1350*cdf0e10cSrcweir {
1351*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1352*cdf0e10cSrcweir     ::rtl::OUString sCellText;
1353*cdf0e10cSrcweir     const_cast< OTableEditorCtrl* >( this )->GetCellData( nRow, nColId ) >>= sCellText;
1354*cdf0e10cSrcweir     return sCellText;
1355*cdf0e10cSrcweir }
1356*cdf0e10cSrcweir 
1357*cdf0e10cSrcweir //------------------------------------------------------------------------------
1358*cdf0e10cSrcweir sal_uInt32 OTableEditorCtrl::GetTotalCellWidth(long nRow, sal_uInt16 nColId)
1359*cdf0e10cSrcweir {
1360*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1361*cdf0e10cSrcweir     return GetTextWidth(GetCellText(nRow, nColId)) + 2 * GetTextWidth('0');
1362*cdf0e10cSrcweir }
1363*cdf0e10cSrcweir 
1364*cdf0e10cSrcweir //------------------------------------------------------------------------------
1365*cdf0e10cSrcweir OFieldDescription* OTableEditorCtrl::GetFieldDescr( long nRow )
1366*cdf0e10cSrcweir {
1367*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1368*cdf0e10cSrcweir     std::vector< ::boost::shared_ptr<OTableRow> >::size_type nListCount(
1369*cdf0e10cSrcweir         m_pRowList->size());
1370*cdf0e10cSrcweir     if( (nRow<0) || (sal::static_int_cast< unsigned long >(nRow)>=nListCount) )
1371*cdf0e10cSrcweir     {
1372*cdf0e10cSrcweir         OSL_ENSURE(0,"(nRow<0) || (nRow>=nListCount)");
1373*cdf0e10cSrcweir         return NULL;
1374*cdf0e10cSrcweir     }
1375*cdf0e10cSrcweir      ::boost::shared_ptr<OTableRow>  pRow = (*m_pRowList)[ nRow ];
1376*cdf0e10cSrcweir     if( !pRow )
1377*cdf0e10cSrcweir         return NULL;
1378*cdf0e10cSrcweir     return pRow->GetActFieldDescr();
1379*cdf0e10cSrcweir }
1380*cdf0e10cSrcweir 
1381*cdf0e10cSrcweir //------------------------------------------------------------------------------
1382*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::IsCutAllowed( long nRow )
1383*cdf0e10cSrcweir {
1384*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1385*cdf0e10cSrcweir     sal_Bool bIsCutAllowed = (GetView()->getController().isAddAllowed() && GetView()->getController().isDropAllowed()) ||
1386*cdf0e10cSrcweir                             GetView()->getController().isAlterAllowed();
1387*cdf0e10cSrcweir 
1388*cdf0e10cSrcweir     if(bIsCutAllowed)
1389*cdf0e10cSrcweir     {
1390*cdf0e10cSrcweir         switch(m_eChildFocus)
1391*cdf0e10cSrcweir         {
1392*cdf0e10cSrcweir             case DESCRIPTION:
1393*cdf0e10cSrcweir                 bIsCutAllowed = pDescrCell->GetSelected().Len() != 0;
1394*cdf0e10cSrcweir                 break;
1395*cdf0e10cSrcweir             case HELPTEXT:
1396*cdf0e10cSrcweir                 bIsCutAllowed = pHelpTextCell->GetSelected().Len() != 0;
1397*cdf0e10cSrcweir                 break;
1398*cdf0e10cSrcweir             case NAME:
1399*cdf0e10cSrcweir                 bIsCutAllowed = pNameCell->GetSelected().Len() != 0;
1400*cdf0e10cSrcweir                 break;
1401*cdf0e10cSrcweir             case ROW:
1402*cdf0e10cSrcweir                 bIsCutAllowed = IsCopyAllowed(nRow);
1403*cdf0e10cSrcweir                 break;
1404*cdf0e10cSrcweir             default:
1405*cdf0e10cSrcweir                 bIsCutAllowed = sal_False;
1406*cdf0e10cSrcweir                 break;
1407*cdf0e10cSrcweir         }
1408*cdf0e10cSrcweir     }
1409*cdf0e10cSrcweir 
1410*cdf0e10cSrcweir //  Reference<XPropertySet> xTable = GetView()->getController().getTable();
1411*cdf0e10cSrcweir //  if( !IsCopyAllowed(nRow) || (xTable.is() && ::comphelper::getString(xTable->getPropertyValue(PROPERTY_TYPE)) == ::rtl::OUString::createFromAscii("VIEW")))
1412*cdf0e10cSrcweir //      return sal_False;
1413*cdf0e10cSrcweir 
1414*cdf0e10cSrcweir     //  return bCutAllowed && IsDeleteAllowed( nRow );
1415*cdf0e10cSrcweir     return bIsCutAllowed;
1416*cdf0e10cSrcweir }
1417*cdf0e10cSrcweir 
1418*cdf0e10cSrcweir //------------------------------------------------------------------------------
1419*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::IsCopyAllowed( long /*nRow*/ )
1420*cdf0e10cSrcweir {
1421*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1422*cdf0e10cSrcweir     sal_Bool bIsCopyAllowed = sal_False;
1423*cdf0e10cSrcweir     if(m_eChildFocus == DESCRIPTION )
1424*cdf0e10cSrcweir         bIsCopyAllowed = pDescrCell->GetSelected().Len() != 0;
1425*cdf0e10cSrcweir     else if(HELPTEXT == m_eChildFocus )
1426*cdf0e10cSrcweir         bIsCopyAllowed = pHelpTextCell->GetSelected().Len() != 0;
1427*cdf0e10cSrcweir     else if(m_eChildFocus == NAME)
1428*cdf0e10cSrcweir         bIsCopyAllowed = pNameCell->GetSelected().Len() != 0;
1429*cdf0e10cSrcweir     else if(m_eChildFocus == ROW)
1430*cdf0e10cSrcweir     {
1431*cdf0e10cSrcweir         Reference<XPropertySet> xTable = GetView()->getController().getTable();
1432*cdf0e10cSrcweir         if( !GetSelectRowCount() || (xTable.is() && ::comphelper::getString(xTable->getPropertyValue(PROPERTY_TYPE)) == ::rtl::OUString::createFromAscii("VIEW")))
1433*cdf0e10cSrcweir             return sal_False;
1434*cdf0e10cSrcweir 
1435*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////////
1436*cdf0e10cSrcweir         // Wenn eine der markierten Zeilen leer ist, kein Copy moeglich
1437*cdf0e10cSrcweir          ::boost::shared_ptr<OTableRow>  pRow;
1438*cdf0e10cSrcweir         long nIndex = FirstSelectedRow();
1439*cdf0e10cSrcweir         while( nIndex >= 0 && nIndex < static_cast<long>(m_pRowList->size()) )
1440*cdf0e10cSrcweir         {
1441*cdf0e10cSrcweir             pRow = (*m_pRowList)[nIndex];
1442*cdf0e10cSrcweir             if( !pRow->GetActFieldDescr() )
1443*cdf0e10cSrcweir                 return sal_False;
1444*cdf0e10cSrcweir 
1445*cdf0e10cSrcweir             nIndex = NextSelectedRow();
1446*cdf0e10cSrcweir         }
1447*cdf0e10cSrcweir 
1448*cdf0e10cSrcweir         bIsCopyAllowed = sal_True;
1449*cdf0e10cSrcweir     }
1450*cdf0e10cSrcweir 
1451*cdf0e10cSrcweir     return bIsCopyAllowed;
1452*cdf0e10cSrcweir }
1453*cdf0e10cSrcweir 
1454*cdf0e10cSrcweir //------------------------------------------------------------------------------
1455*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::IsPasteAllowed( long /*nRow*/ )
1456*cdf0e10cSrcweir {
1457*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1458*cdf0e10cSrcweir     sal_Bool bAllowed = GetView()->getController().isAddAllowed();
1459*cdf0e10cSrcweir     if ( bAllowed )
1460*cdf0e10cSrcweir     {
1461*cdf0e10cSrcweir         TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
1462*cdf0e10cSrcweir         sal_Bool bRowFormat = aTransferData.HasFormat(SOT_FORMATSTR_ID_SBA_TABED);
1463*cdf0e10cSrcweir         if ( m_eChildFocus == ROW )
1464*cdf0e10cSrcweir             bAllowed = bRowFormat;
1465*cdf0e10cSrcweir         else
1466*cdf0e10cSrcweir             bAllowed = !bRowFormat && aTransferData.HasFormat(SOT_FORMAT_STRING);
1467*cdf0e10cSrcweir     }
1468*cdf0e10cSrcweir 
1469*cdf0e10cSrcweir     return bAllowed;
1470*cdf0e10cSrcweir }
1471*cdf0e10cSrcweir 
1472*cdf0e10cSrcweir //------------------------------------------------------------------------------
1473*cdf0e10cSrcweir void OTableEditorCtrl::cut()
1474*cdf0e10cSrcweir {
1475*cdf0e10cSrcweir     if(m_eChildFocus == NAME)
1476*cdf0e10cSrcweir     {
1477*cdf0e10cSrcweir         if(GetView()->getController().isAlterAllowed())
1478*cdf0e10cSrcweir         {
1479*cdf0e10cSrcweir             SaveData(-1,FIELD_NAME);
1480*cdf0e10cSrcweir             pNameCell->Cut();
1481*cdf0e10cSrcweir             CellModified(-1,FIELD_NAME);
1482*cdf0e10cSrcweir         }
1483*cdf0e10cSrcweir     }
1484*cdf0e10cSrcweir     else if(m_eChildFocus == DESCRIPTION)
1485*cdf0e10cSrcweir     {
1486*cdf0e10cSrcweir         if(GetView()->getController().isAlterAllowed())
1487*cdf0e10cSrcweir         {
1488*cdf0e10cSrcweir             SaveData(-1,COLUMN_DESCRIPTION);
1489*cdf0e10cSrcweir             pDescrCell->Cut();
1490*cdf0e10cSrcweir             CellModified(-1,COLUMN_DESCRIPTION);
1491*cdf0e10cSrcweir         }
1492*cdf0e10cSrcweir     }
1493*cdf0e10cSrcweir     else if(HELPTEXT == m_eChildFocus )
1494*cdf0e10cSrcweir     {
1495*cdf0e10cSrcweir         if(GetView()->getController().isAlterAllowed())
1496*cdf0e10cSrcweir         {
1497*cdf0e10cSrcweir             SaveData(-1,HELP_TEXT);
1498*cdf0e10cSrcweir             pHelpTextCell->Cut();
1499*cdf0e10cSrcweir             CellModified(-1,HELP_TEXT);
1500*cdf0e10cSrcweir         }
1501*cdf0e10cSrcweir     }
1502*cdf0e10cSrcweir     else if(m_eChildFocus == ROW)
1503*cdf0e10cSrcweir     {
1504*cdf0e10cSrcweir         if (nCutEvent)
1505*cdf0e10cSrcweir             Application::RemoveUserEvent(nCutEvent);
1506*cdf0e10cSrcweir         nCutEvent = Application::PostUserEvent(LINK(this, OTableEditorCtrl, DelayedCut));
1507*cdf0e10cSrcweir     }
1508*cdf0e10cSrcweir }
1509*cdf0e10cSrcweir 
1510*cdf0e10cSrcweir //------------------------------------------------------------------------------
1511*cdf0e10cSrcweir void OTableEditorCtrl::copy()
1512*cdf0e10cSrcweir {
1513*cdf0e10cSrcweir     if(GetSelectRowCount())
1514*cdf0e10cSrcweir         OTableRowView::copy();
1515*cdf0e10cSrcweir     else if(m_eChildFocus == NAME)
1516*cdf0e10cSrcweir         pNameCell->Copy();
1517*cdf0e10cSrcweir     else if(HELPTEXT == m_eChildFocus )
1518*cdf0e10cSrcweir         pHelpTextCell->Copy();
1519*cdf0e10cSrcweir     else if(m_eChildFocus == DESCRIPTION )
1520*cdf0e10cSrcweir         pDescrCell->Copy();
1521*cdf0e10cSrcweir }
1522*cdf0e10cSrcweir 
1523*cdf0e10cSrcweir //------------------------------------------------------------------------------
1524*cdf0e10cSrcweir void OTableEditorCtrl::paste()
1525*cdf0e10cSrcweir {
1526*cdf0e10cSrcweir     TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(GetParent()));
1527*cdf0e10cSrcweir     if(aTransferData.HasFormat(SOT_FORMATSTR_ID_SBA_TABED))
1528*cdf0e10cSrcweir     {
1529*cdf0e10cSrcweir         if( nPasteEvent )
1530*cdf0e10cSrcweir             Application::RemoveUserEvent( nPasteEvent );
1531*cdf0e10cSrcweir         nPasteEvent = Application::PostUserEvent( LINK(this, OTableEditorCtrl, DelayedPaste) );
1532*cdf0e10cSrcweir     }
1533*cdf0e10cSrcweir     else if(m_eChildFocus == NAME)
1534*cdf0e10cSrcweir     {
1535*cdf0e10cSrcweir         if(GetView()->getController().isAlterAllowed())
1536*cdf0e10cSrcweir         {
1537*cdf0e10cSrcweir             pNameCell->Paste();
1538*cdf0e10cSrcweir             CellModified();
1539*cdf0e10cSrcweir         }
1540*cdf0e10cSrcweir     }
1541*cdf0e10cSrcweir     else if(HELPTEXT == m_eChildFocus )
1542*cdf0e10cSrcweir     {
1543*cdf0e10cSrcweir         if(GetView()->getController().isAlterAllowed())
1544*cdf0e10cSrcweir         {
1545*cdf0e10cSrcweir             pHelpTextCell->Paste();
1546*cdf0e10cSrcweir             CellModified();
1547*cdf0e10cSrcweir         }
1548*cdf0e10cSrcweir     }
1549*cdf0e10cSrcweir     else if(m_eChildFocus == DESCRIPTION)
1550*cdf0e10cSrcweir     {
1551*cdf0e10cSrcweir         if(GetView()->getController().isAlterAllowed())
1552*cdf0e10cSrcweir         {
1553*cdf0e10cSrcweir             pDescrCell->Paste();
1554*cdf0e10cSrcweir             CellModified();
1555*cdf0e10cSrcweir         }
1556*cdf0e10cSrcweir     }
1557*cdf0e10cSrcweir }
1558*cdf0e10cSrcweir 
1559*cdf0e10cSrcweir //------------------------------------------------------------------------------
1560*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::IsDeleteAllowed( long /*nRow*/ )
1561*cdf0e10cSrcweir {
1562*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1563*cdf0e10cSrcweir 
1564*cdf0e10cSrcweir     return GetSelectRowCount() != 0 && GetView()->getController().isDropAllowed();
1565*cdf0e10cSrcweir }
1566*cdf0e10cSrcweir 
1567*cdf0e10cSrcweir //------------------------------------------------------------------------------
1568*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::IsInsertNewAllowed( long nRow )
1569*cdf0e10cSrcweir {
1570*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1571*cdf0e10cSrcweir 
1572*cdf0e10cSrcweir     sal_Bool bInsertNewAllowed = GetView()->getController().isAddAllowed();
1573*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////
1574*cdf0e10cSrcweir     // Wenn nur Felder hinzugefuegt werden duerfen, Paste nur in neue Felder
1575*cdf0e10cSrcweir     if (bInsertNewAllowed && !GetView()->getController().isDropAllowed())
1576*cdf0e10cSrcweir     {
1577*cdf0e10cSrcweir         SetDataPtr(nRow);
1578*cdf0e10cSrcweir         if( GetActRow()->IsReadOnly() )
1579*cdf0e10cSrcweir             return sal_False;
1580*cdf0e10cSrcweir     }
1581*cdf0e10cSrcweir 
1582*cdf0e10cSrcweir     return bInsertNewAllowed;
1583*cdf0e10cSrcweir }
1584*cdf0e10cSrcweir 
1585*cdf0e10cSrcweir //------------------------------------------------------------------------------
1586*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::IsPrimaryKeyAllowed( long /*nRow*/ )
1587*cdf0e10cSrcweir {
1588*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1589*cdf0e10cSrcweir     if( !GetSelectRowCount() )
1590*cdf0e10cSrcweir         return sal_False;
1591*cdf0e10cSrcweir 
1592*cdf0e10cSrcweir     OTableController& rController = GetView()->getController();
1593*cdf0e10cSrcweir     if ( !rController.getSdbMetaData().supportsPrimaryKeys() )
1594*cdf0e10cSrcweir         return sal_False;
1595*cdf0e10cSrcweir 
1596*cdf0e10cSrcweir     Reference<XPropertySet> xTable = rController.getTable();
1597*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////
1598*cdf0e10cSrcweir     // Key darf nicht veraendert werden
1599*cdf0e10cSrcweir     // Dies gilt jedoch nur, wenn die Tabelle nicht neu ist und keine ::com::sun::star::sdbcx::View. Ansonsten wird kein DROP ausgef�hrt
1600*cdf0e10cSrcweir 
1601*cdf0e10cSrcweir     if(xTable.is() && ::comphelper::getString(xTable->getPropertyValue(PROPERTY_TYPE)) == ::rtl::OUString::createFromAscii("VIEW"))
1602*cdf0e10cSrcweir         return sal_False;
1603*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////
1604*cdf0e10cSrcweir     // Wenn leeres Feld, kein PrimKey
1605*cdf0e10cSrcweir     // Eintrag wird nur erlaubt, wenn
1606*cdf0e10cSrcweir     // - kein leerer Eintrag in der Selection ist
1607*cdf0e10cSrcweir     // - kein Eintrag vom Typ Memo oder Image ist
1608*cdf0e10cSrcweir     // - kein DROP erlaubt ist (s.o.) und die Spalte noch kein Required (not null) gesetzt hatte.
1609*cdf0e10cSrcweir     long nIndex = FirstSelectedRow();
1610*cdf0e10cSrcweir      ::boost::shared_ptr<OTableRow>  pRow;
1611*cdf0e10cSrcweir     while( nIndex >= 0 && nIndex < static_cast<long>(m_pRowList->size()) )
1612*cdf0e10cSrcweir     {
1613*cdf0e10cSrcweir         pRow = (*m_pRowList)[nIndex];
1614*cdf0e10cSrcweir         OFieldDescription* pFieldDescr = pRow->GetActFieldDescr();
1615*cdf0e10cSrcweir         if(!pFieldDescr)
1616*cdf0e10cSrcweir             return sal_False;
1617*cdf0e10cSrcweir         else
1618*cdf0e10cSrcweir         {
1619*cdf0e10cSrcweir             //////////////////////////////////////////////////////////////
1620*cdf0e10cSrcweir             // Wenn Feldtyp Memo oder Image, kein PrimKey
1621*cdf0e10cSrcweir             // oder wenn Spalten nicht gedroped werden k�nnen und das Required Flag ist nicht gesetzt
1622*cdf0e10cSrcweir             // oder wenn eine ::com::sun::star::sdbcx::View vorhanden ist und das Required Flag nicht gesetzt ist
1623*cdf0e10cSrcweir             TOTypeInfoSP pTypeInfo = pFieldDescr->getTypeInfo();
1624*cdf0e10cSrcweir             if(     pTypeInfo->nSearchType == ColumnSearch::NONE
1625*cdf0e10cSrcweir                 || (pFieldDescr->IsNullable() && pRow->IsReadOnly())
1626*cdf0e10cSrcweir               )
1627*cdf0e10cSrcweir                 return sal_False;
1628*cdf0e10cSrcweir         }
1629*cdf0e10cSrcweir 
1630*cdf0e10cSrcweir         nIndex = NextSelectedRow();
1631*cdf0e10cSrcweir     }
1632*cdf0e10cSrcweir 
1633*cdf0e10cSrcweir     return sal_True;
1634*cdf0e10cSrcweir }
1635*cdf0e10cSrcweir 
1636*cdf0e10cSrcweir //------------------------------------------------------------------------------
1637*cdf0e10cSrcweir void OTableEditorCtrl::Command(const CommandEvent& rEvt)
1638*cdf0e10cSrcweir {
1639*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1640*cdf0e10cSrcweir     switch (rEvt.GetCommand())
1641*cdf0e10cSrcweir     {
1642*cdf0e10cSrcweir         case COMMAND_CONTEXTMENU:
1643*cdf0e10cSrcweir         {
1644*cdf0e10cSrcweir             Point aMenuPos( rEvt.GetMousePosPixel() );
1645*cdf0e10cSrcweir             if (!rEvt.IsMouseEvent())
1646*cdf0e10cSrcweir             {
1647*cdf0e10cSrcweir                 if  ( 1 == GetSelectColumnCount() )
1648*cdf0e10cSrcweir                 {
1649*cdf0e10cSrcweir                     sal_uInt16 nSelId = GetColumnId(
1650*cdf0e10cSrcweir                         sal::static_int_cast< sal_uInt16 >(
1651*cdf0e10cSrcweir                             FirstSelectedColumn() ) );
1652*cdf0e10cSrcweir                     ::Rectangle aColRect( GetFieldRectPixel( 0, nSelId, sal_False ) );
1653*cdf0e10cSrcweir 
1654*cdf0e10cSrcweir                     aMenuPos = aColRect.TopCenter();
1655*cdf0e10cSrcweir                 }
1656*cdf0e10cSrcweir                 else if ( GetSelectRowCount() > 0 )
1657*cdf0e10cSrcweir                 {
1658*cdf0e10cSrcweir                     ::Rectangle aColRect( GetFieldRectPixel( FirstSelectedRow(), HANDLE_ID, sal_True ) );
1659*cdf0e10cSrcweir 
1660*cdf0e10cSrcweir                     aMenuPos = aColRect.TopCenter();
1661*cdf0e10cSrcweir                 }
1662*cdf0e10cSrcweir                 else
1663*cdf0e10cSrcweir                 {
1664*cdf0e10cSrcweir                     OTableRowView::Command(rEvt);
1665*cdf0e10cSrcweir                     return;
1666*cdf0e10cSrcweir                 }
1667*cdf0e10cSrcweir             }
1668*cdf0e10cSrcweir 
1669*cdf0e10cSrcweir             //////////////////////////////////////////////////////////////
1670*cdf0e10cSrcweir             // Kontextmenu einblenden
1671*cdf0e10cSrcweir             if( !IsReadOnly() )
1672*cdf0e10cSrcweir             {
1673*cdf0e10cSrcweir                 sal_uInt16 nColId = GetColumnAtXPosPixel(aMenuPos.X());
1674*cdf0e10cSrcweir                 long   nRow = GetRowAtYPosPixel(aMenuPos.Y());
1675*cdf0e10cSrcweir 
1676*cdf0e10cSrcweir                 if ( HANDLE_ID != nColId )
1677*cdf0e10cSrcweir                 {
1678*cdf0e10cSrcweir                     if ( nRow < 0 && nColId != BROWSER_INVALIDID )
1679*cdf0e10cSrcweir                     {   // hit the header
1680*cdf0e10cSrcweir                         if ( 3 != nColId )
1681*cdf0e10cSrcweir                         {   // 3 would mean the last column, and this last column is auto-sized
1682*cdf0e10cSrcweir                             if ( !IsColumnSelected( nColId ) )
1683*cdf0e10cSrcweir                                 SelectColumnId( nColId );
1684*cdf0e10cSrcweir 
1685*cdf0e10cSrcweir                             PopupMenu aContextMenu( ModuleRes( RID_QUERYCOLPOPUPMENU ) );
1686*cdf0e10cSrcweir                             aContextMenu.EnableItem( SID_DELETE, sal_False );
1687*cdf0e10cSrcweir                             aContextMenu.RemoveDisabledEntries(sal_True, sal_True);
1688*cdf0e10cSrcweir                             switch ( aContextMenu.Execute( this, aMenuPos ) )
1689*cdf0e10cSrcweir                             {
1690*cdf0e10cSrcweir                                 case ID_BROWSER_COLWIDTH:
1691*cdf0e10cSrcweir                                     adjustBrowseBoxColumnWidth( this, nColId );
1692*cdf0e10cSrcweir                                     break;
1693*cdf0e10cSrcweir                             }
1694*cdf0e10cSrcweir                         }
1695*cdf0e10cSrcweir                     }
1696*cdf0e10cSrcweir                 }
1697*cdf0e10cSrcweir                 else
1698*cdf0e10cSrcweir                 {
1699*cdf0e10cSrcweir                     PopupMenu aContextMenu(ModuleRes(RID_TABLEDESIGNROWPOPUPMENU));
1700*cdf0e10cSrcweir 
1701*cdf0e10cSrcweir                     aContextMenu.EnableItem( SID_CUT, IsCutAllowed(nRow) );
1702*cdf0e10cSrcweir                     aContextMenu.EnableItem( SID_COPY, IsCopyAllowed(nRow) );
1703*cdf0e10cSrcweir                     aContextMenu.EnableItem( SID_PASTE, IsPasteAllowed(nRow) );
1704*cdf0e10cSrcweir                     aContextMenu.EnableItem( SID_DELETE, IsDeleteAllowed(nRow) );
1705*cdf0e10cSrcweir                     aContextMenu.EnableItem( SID_TABLEDESIGN_TABED_PRIMARYKEY, IsPrimaryKeyAllowed(nRow) );
1706*cdf0e10cSrcweir                     aContextMenu.EnableItem( SID_TABLEDESIGN_INSERTROWS, IsInsertNewAllowed(nRow) );
1707*cdf0e10cSrcweir                     aContextMenu.CheckItem( SID_TABLEDESIGN_TABED_PRIMARYKEY, IsRowSelected(GetCurRow()) && IsPrimaryKey() );
1708*cdf0e10cSrcweir 
1709*cdf0e10cSrcweir                     // jetzt alles, was disabled wurde, wech
1710*cdf0e10cSrcweir                     aContextMenu.RemoveDisabledEntries(sal_True, sal_True);
1711*cdf0e10cSrcweir 
1712*cdf0e10cSrcweir                     if( SetDataPtr(m_nDataPos) )
1713*cdf0e10cSrcweir                         pDescrWin->SaveData( pActRow->GetActFieldDescr() );
1714*cdf0e10cSrcweir 
1715*cdf0e10cSrcweir                     //////////////////////////////////////////////////////////////
1716*cdf0e10cSrcweir                     // Alle Aktionen, die die Zeilenzahl veraendern, muessen asynchron
1717*cdf0e10cSrcweir                     // ausgefuehrt werden->sonst Probleme zwischen Kontextmenu u. Browser
1718*cdf0e10cSrcweir                     m_nDataPos = GetCurRow();
1719*cdf0e10cSrcweir                     switch (aContextMenu.Execute(this, aMenuPos))
1720*cdf0e10cSrcweir                     {
1721*cdf0e10cSrcweir                         case SID_CUT:
1722*cdf0e10cSrcweir                             cut();
1723*cdf0e10cSrcweir                             break;
1724*cdf0e10cSrcweir                         case SID_COPY:
1725*cdf0e10cSrcweir                             copy();
1726*cdf0e10cSrcweir                             break;
1727*cdf0e10cSrcweir                         case SID_PASTE:
1728*cdf0e10cSrcweir                             paste();
1729*cdf0e10cSrcweir                             break;
1730*cdf0e10cSrcweir                         case SID_DELETE:
1731*cdf0e10cSrcweir                             if( nDeleteEvent )
1732*cdf0e10cSrcweir                                 Application::RemoveUserEvent( nDeleteEvent );
1733*cdf0e10cSrcweir                             nDeleteEvent = Application::PostUserEvent( LINK(this, OTableEditorCtrl, DelayedDelete) );
1734*cdf0e10cSrcweir                             break;
1735*cdf0e10cSrcweir                         case SID_TABLEDESIGN_INSERTROWS:
1736*cdf0e10cSrcweir                             if( nInsNewRowsEvent )
1737*cdf0e10cSrcweir                                 Application::RemoveUserEvent( nInsNewRowsEvent );
1738*cdf0e10cSrcweir                             nInsNewRowsEvent = Application::PostUserEvent( LINK(this, OTableEditorCtrl, DelayedInsNewRows) );
1739*cdf0e10cSrcweir                             break;
1740*cdf0e10cSrcweir                         case SID_TABLEDESIGN_TABED_PRIMARYKEY:
1741*cdf0e10cSrcweir                             SetPrimaryKey( !IsPrimaryKey() );
1742*cdf0e10cSrcweir                             break;
1743*cdf0e10cSrcweir                         default:
1744*cdf0e10cSrcweir                             break;
1745*cdf0e10cSrcweir                     }
1746*cdf0e10cSrcweir                 }
1747*cdf0e10cSrcweir             }
1748*cdf0e10cSrcweir         }
1749*cdf0e10cSrcweir         break;
1750*cdf0e10cSrcweir         default:
1751*cdf0e10cSrcweir             OTableRowView::Command(rEvt);
1752*cdf0e10cSrcweir     }
1753*cdf0e10cSrcweir 
1754*cdf0e10cSrcweir }
1755*cdf0e10cSrcweir 
1756*cdf0e10cSrcweir //------------------------------------------------------------------------------
1757*cdf0e10cSrcweir IMPL_LINK( OTableEditorCtrl, DelayedCut, void*, /*EMPTYTAG*/ )
1758*cdf0e10cSrcweir {
1759*cdf0e10cSrcweir     nCutEvent = 0;
1760*cdf0e10cSrcweir     OTableRowView::cut();
1761*cdf0e10cSrcweir     return 0;
1762*cdf0e10cSrcweir }
1763*cdf0e10cSrcweir 
1764*cdf0e10cSrcweir //------------------------------------------------------------------------------
1765*cdf0e10cSrcweir IMPL_LINK( OTableEditorCtrl, DelayedPaste, void*, /*EMPTYTAG*/ )
1766*cdf0e10cSrcweir {
1767*cdf0e10cSrcweir     nPasteEvent = 0;
1768*cdf0e10cSrcweir 
1769*cdf0e10cSrcweir     sal_Int32 nPastePosition = GetView()->getController().getFirstEmptyRowPosition();
1770*cdf0e10cSrcweir     if ( !GetView()->getController().getTable().is() )
1771*cdf0e10cSrcweir         nPastePosition = GetSelectRowCount() ? FirstSelectedRow() : GetCurRow();
1772*cdf0e10cSrcweir 
1773*cdf0e10cSrcweir     if (!IsInsertNewAllowed(nPastePosition))
1774*cdf0e10cSrcweir     {   // kein Einfuegen erlaubt, sondern nur anhaengen, also testen, ob hinter der PastePosition noch
1775*cdf0e10cSrcweir         // belegte Zeilen erscheinen
1776*cdf0e10cSrcweir 
1777*cdf0e10cSrcweir         sal_Int32 nFreeFromPos; // ab da nur freie Zeilen
1778*cdf0e10cSrcweir         ::std::vector< ::boost::shared_ptr<OTableRow> >::reverse_iterator aIter = m_pRowList->rbegin();
1779*cdf0e10cSrcweir         for(nFreeFromPos = m_pRowList->size();
1780*cdf0e10cSrcweir             aIter != m_pRowList->rend() && (!(*aIter) || !(*aIter)->GetActFieldDescr() || !(*aIter)->GetActFieldDescr()->GetName().getLength());
1781*cdf0e10cSrcweir             --nFreeFromPos, ++aIter)
1782*cdf0e10cSrcweir             ;
1783*cdf0e10cSrcweir         if (nPastePosition < nFreeFromPos)  // es gibt mindestens eine belegte hinter PastePosition -> ganz nach hinten
1784*cdf0e10cSrcweir             nPastePosition = nFreeFromPos;
1785*cdf0e10cSrcweir     }
1786*cdf0e10cSrcweir 
1787*cdf0e10cSrcweir     OTableRowView::Paste( nPastePosition );
1788*cdf0e10cSrcweir     SetNoSelection();
1789*cdf0e10cSrcweir     GoToRow( nPastePosition );
1790*cdf0e10cSrcweir 
1791*cdf0e10cSrcweir     return 0;
1792*cdf0e10cSrcweir }
1793*cdf0e10cSrcweir 
1794*cdf0e10cSrcweir //------------------------------------------------------------------------------
1795*cdf0e10cSrcweir IMPL_LINK( OTableEditorCtrl, DelayedDelete, void*, /*EMPTYTAG*/ )
1796*cdf0e10cSrcweir {
1797*cdf0e10cSrcweir     nDeleteEvent = 0;
1798*cdf0e10cSrcweir     DeleteRows();
1799*cdf0e10cSrcweir     return 0;
1800*cdf0e10cSrcweir }
1801*cdf0e10cSrcweir 
1802*cdf0e10cSrcweir //------------------------------------------------------------------------------
1803*cdf0e10cSrcweir IMPL_LINK( OTableEditorCtrl, DelayedInsNewRows, void*, /*EMPTYTAG*/ )
1804*cdf0e10cSrcweir {
1805*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1806*cdf0e10cSrcweir     nInsNewRowsEvent = 0;
1807*cdf0e10cSrcweir     sal_Int32 nPastePosition = GetView()->getController().getFirstEmptyRowPosition();
1808*cdf0e10cSrcweir     if ( !GetView()->getController().getTable().is() )
1809*cdf0e10cSrcweir         nPastePosition = GetSelectRowCount() ? FirstSelectedRow() : m_nDataPos;
1810*cdf0e10cSrcweir 
1811*cdf0e10cSrcweir     InsertNewRows( nPastePosition );
1812*cdf0e10cSrcweir     SetNoSelection();
1813*cdf0e10cSrcweir     GoToRow( nPastePosition );
1814*cdf0e10cSrcweir 
1815*cdf0e10cSrcweir     return 0;
1816*cdf0e10cSrcweir }
1817*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1818*cdf0e10cSrcweir void OTableEditorCtrl::AdjustFieldDescription(OFieldDescription* _pFieldDesc,
1819*cdf0e10cSrcweir                                          MultiSelection& _rMultiSel,
1820*cdf0e10cSrcweir                                          sal_Int32 _nPos,
1821*cdf0e10cSrcweir                                          sal_Bool _bSet,
1822*cdf0e10cSrcweir                                          sal_Bool _bPrimaryKey)
1823*cdf0e10cSrcweir {
1824*cdf0e10cSrcweir     _pFieldDesc->SetPrimaryKey( _bPrimaryKey );
1825*cdf0e10cSrcweir     if(!_bSet && _pFieldDesc->getTypeInfo()->bNullable)
1826*cdf0e10cSrcweir     {
1827*cdf0e10cSrcweir         _pFieldDesc->SetIsNullable(ColumnValue::NO_NULLS);
1828*cdf0e10cSrcweir         _pFieldDesc->SetControlDefault(Any());
1829*cdf0e10cSrcweir     } // if(!_bSet && _pFieldDesc->getTypeInfo()->bNullable)
1830*cdf0e10cSrcweir     if ( _pFieldDesc->IsAutoIncrement() && !_bPrimaryKey )
1831*cdf0e10cSrcweir     {
1832*cdf0e10cSrcweir         OTableController& rController = GetView()->getController();
1833*cdf0e10cSrcweir         if ( rController.isAutoIncrementPrimaryKey() )
1834*cdf0e10cSrcweir         {
1835*cdf0e10cSrcweir             _pFieldDesc->SetAutoIncrement(false);
1836*cdf0e10cSrcweir         }
1837*cdf0e10cSrcweir     }
1838*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1839*cdf0e10cSrcweir     // update field description
1840*cdf0e10cSrcweir     pDescrWin->DisplayData(_pFieldDesc);
1841*cdf0e10cSrcweir 
1842*cdf0e10cSrcweir     _rMultiSel.Insert( _nPos );
1843*cdf0e10cSrcweir     _rMultiSel.Select( _nPos );
1844*cdf0e10cSrcweir }
1845*cdf0e10cSrcweir //------------------------------------------------------------------------------
1846*cdf0e10cSrcweir void OTableEditorCtrl::SetPrimaryKey( sal_Bool bSet )
1847*cdf0e10cSrcweir {
1848*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1849*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1850*cdf0e10cSrcweir     // Evtl. vorhandene Primary Keys loeschen
1851*cdf0e10cSrcweir     MultiSelection aDeletedPrimKeys;
1852*cdf0e10cSrcweir     aDeletedPrimKeys.SetTotalRange( Range(0,GetRowCount()) );
1853*cdf0e10cSrcweir     long nIndex = 0;
1854*cdf0e10cSrcweir 
1855*cdf0e10cSrcweir     ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aIter = m_pRowList->begin();
1856*cdf0e10cSrcweir     ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aEnd = m_pRowList->end();
1857*cdf0e10cSrcweir     for(sal_Int32 nRow = 0;aIter != aEnd;++aIter,++nRow)
1858*cdf0e10cSrcweir     {
1859*cdf0e10cSrcweir         OFieldDescription* pFieldDescr = (*aIter)->GetActFieldDescr();
1860*cdf0e10cSrcweir         if( pFieldDescr && (*aIter)->IsPrimaryKey() && (!bSet || !IsRowSelected(nRow)) )
1861*cdf0e10cSrcweir         {
1862*cdf0e10cSrcweir             AdjustFieldDescription(pFieldDescr,aDeletedPrimKeys,nRow,bSet,sal_False);
1863*cdf0e10cSrcweir         }
1864*cdf0e10cSrcweir     }
1865*cdf0e10cSrcweir 
1866*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1867*cdf0e10cSrcweir     // Die Primary Keys der markierten Zeilen setzen
1868*cdf0e10cSrcweir     MultiSelection aInsertedPrimKeys;
1869*cdf0e10cSrcweir     aInsertedPrimKeys.SetTotalRange( Range(0,GetRowCount()) );
1870*cdf0e10cSrcweir     if( bSet )
1871*cdf0e10cSrcweir     {
1872*cdf0e10cSrcweir         nIndex = FirstSelectedRow();
1873*cdf0e10cSrcweir         while( nIndex >= 0 && nIndex < static_cast<long>(m_pRowList->size()) )
1874*cdf0e10cSrcweir         {
1875*cdf0e10cSrcweir             //////////////////////////////////////////////////////////////////////
1876*cdf0e10cSrcweir             // Key setzen
1877*cdf0e10cSrcweir              ::boost::shared_ptr<OTableRow>  pRow = (*m_pRowList)[nIndex];
1878*cdf0e10cSrcweir             OFieldDescription* pFieldDescr = pRow->GetActFieldDescr();
1879*cdf0e10cSrcweir             if(pFieldDescr)
1880*cdf0e10cSrcweir                 AdjustFieldDescription(pFieldDescr,aInsertedPrimKeys,nIndex,sal_False,sal_True);
1881*cdf0e10cSrcweir 
1882*cdf0e10cSrcweir             nIndex = NextSelectedRow();
1883*cdf0e10cSrcweir         }
1884*cdf0e10cSrcweir     }
1885*cdf0e10cSrcweir 
1886*cdf0e10cSrcweir     GetUndoManager().AddUndoAction( new OPrimKeyUndoAct(this, aDeletedPrimKeys, aInsertedPrimKeys) );
1887*cdf0e10cSrcweir 
1888*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1889*cdf0e10cSrcweir     // Handle-Spalte invalidieren
1890*cdf0e10cSrcweir     InvalidateHandleColumn();
1891*cdf0e10cSrcweir 
1892*cdf0e10cSrcweir 
1893*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1894*cdf0e10cSrcweir     // Das ModifyFlag der TableDocSh setzen
1895*cdf0e10cSrcweir     GetView()->getController().setModified( sal_True );
1896*cdf0e10cSrcweir     InvalidateFeatures();
1897*cdf0e10cSrcweir }
1898*cdf0e10cSrcweir 
1899*cdf0e10cSrcweir //------------------------------------------------------------------------------
1900*cdf0e10cSrcweir sal_Bool OTableEditorCtrl::IsPrimaryKey()
1901*cdf0e10cSrcweir {
1902*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1903*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1904*cdf0e10cSrcweir     // Gehoeren alle markierten Felder zu einem Primary Key ?
1905*cdf0e10cSrcweir     long nPrimaryKeys = 0;
1906*cdf0e10cSrcweir     ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aIter = m_pRowList->begin();
1907*cdf0e10cSrcweir     ::std::vector< ::boost::shared_ptr<OTableRow> >::const_iterator aEnd = m_pRowList->end();
1908*cdf0e10cSrcweir     for(sal_Int32 nRow=0;aIter != aEnd;++aIter,++nRow)
1909*cdf0e10cSrcweir     {
1910*cdf0e10cSrcweir         if( IsRowSelected(nRow) && !(*aIter)->IsPrimaryKey() )
1911*cdf0e10cSrcweir             return sal_False;
1912*cdf0e10cSrcweir         if( (*aIter)->IsPrimaryKey() )
1913*cdf0e10cSrcweir             ++nPrimaryKeys;
1914*cdf0e10cSrcweir     }
1915*cdf0e10cSrcweir 
1916*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1917*cdf0e10cSrcweir     // Gibt es unselektierte Felder, die noch zu dem Key gehoeren ?
1918*cdf0e10cSrcweir     return GetSelectRowCount() == nPrimaryKeys;
1919*cdf0e10cSrcweir }
1920*cdf0e10cSrcweir 
1921*cdf0e10cSrcweir //------------------------------------------------------------------------------
1922*cdf0e10cSrcweir void OTableEditorCtrl::SwitchType( const TOTypeInfoSP& _pType )
1923*cdf0e10cSrcweir {
1924*cdf0e10cSrcweir     DBG_CHKTHIS(OTableEditorCtrl,NULL);
1925*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1926*cdf0e10cSrcweir     // Wenn noch kein Feldname vergeben wurde
1927*cdf0e10cSrcweir     long nRow(GetCurRow());
1928*cdf0e10cSrcweir     OFieldDescription* pActFieldDescr = GetFieldDescr( nRow );
1929*cdf0e10cSrcweir     if( pActFieldDescr )
1930*cdf0e10cSrcweir         //////////////////////////////////////////////////////////////////////
1931*cdf0e10cSrcweir         // Alte Beschreibung speichern
1932*cdf0e10cSrcweir         pDescrWin->SaveData( pActFieldDescr );
1933*cdf0e10cSrcweir 
1934*cdf0e10cSrcweir     if ( nRow < 0 || nRow > static_cast<long>(m_pRowList->size()) )
1935*cdf0e10cSrcweir         return;
1936*cdf0e10cSrcweir     //////////////////////////////////////////////////////////////////////
1937*cdf0e10cSrcweir     // Neue Beschreibung darstellen
1938*cdf0e10cSrcweir      ::boost::shared_ptr<OTableRow>  pRow = (*m_pRowList)[nRow];
1939*cdf0e10cSrcweir     pRow->SetFieldType( _pType, sal_True );
1940*cdf0e10cSrcweir     if ( _pType.get() )
1941*cdf0e10cSrcweir     {
1942*cdf0e10cSrcweir         const sal_uInt16 nCurrentlySelected = pTypeCell->GetSelectEntryPos();
1943*cdf0e10cSrcweir 
1944*cdf0e10cSrcweir         if  (   ( LISTBOX_ENTRY_NOTFOUND == nCurrentlySelected )
1945*cdf0e10cSrcweir             ||  ( GetView()->getController().getTypeInfo( nCurrentlySelected ) != _pType )
1946*cdf0e10cSrcweir             )
1947*cdf0e10cSrcweir         {
1948*cdf0e10cSrcweir             sal_uInt16 nEntryPos = 0;
1949*cdf0e10cSrcweir             const OTypeInfoMap* pTypeInfo = GetView()->getController().getTypeInfo();
1950*cdf0e10cSrcweir             OTypeInfoMap::const_iterator aIter = pTypeInfo->begin();
1951*cdf0e10cSrcweir             OTypeInfoMap::const_iterator aEnd = pTypeInfo->end();
1952*cdf0e10cSrcweir             for(;aIter != aEnd;++aIter,++nEntryPos)
1953*cdf0e10cSrcweir             {
1954*cdf0e10cSrcweir                 if(aIter->second == _pType)
1955*cdf0e10cSrcweir                     break;
1956*cdf0e10cSrcweir             }
1957*cdf0e10cSrcweir             if (nEntryPos < pTypeCell->GetEntryCount())
1958*cdf0e10cSrcweir                 pTypeCell->SelectEntryPos( nEntryPos );
1959*cdf0e10cSrcweir         }
1960*cdf0e10cSrcweir     }
1961*cdf0e10cSrcweir 
1962*cdf0e10cSrcweir     pActFieldDescr = pRow->GetActFieldDescr();
1963*cdf0e10cSrcweir     if (pActFieldDescr != NULL && !pActFieldDescr->GetFormatKey())
1964*cdf0e10cSrcweir     {
1965*cdf0e10cSrcweir         sal_Int32 nFormatKey = ::dbtools::getDefaultNumberFormat( pActFieldDescr->GetType(),
1966*cdf0e10cSrcweir             pActFieldDescr->GetScale(),
1967*cdf0e10cSrcweir             pActFieldDescr->IsCurrency(),
1968*cdf0e10cSrcweir             Reference< XNumberFormatTypes>(GetView()->getController().getNumberFormatter()->getNumberFormatsSupplier()->getNumberFormats(),UNO_QUERY),
1969*cdf0e10cSrcweir             GetView()->getLocale());
1970*cdf0e10cSrcweir 
1971*cdf0e10cSrcweir         pActFieldDescr->SetFormatKey(nFormatKey);
1972*cdf0e10cSrcweir     }
1973*cdf0e10cSrcweir 
1974*cdf0e10cSrcweir     pDescrWin->DisplayData( pActFieldDescr );
1975*cdf0e10cSrcweir }
1976*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1977*cdf0e10cSrcweir OTableDesignView* OTableEditorCtrl::GetView() const
1978*cdf0e10cSrcweir {
1979*cdf0e10cSrcweir     return static_cast<OTableDesignView*>(GetParent()->GetParent());
1980*cdf0e10cSrcweir }
1981*cdf0e10cSrcweir // -----------------------------------------------------------------------------
1982*cdf0e10cSrcweir void OTableEditorCtrl::DeactivateCell(sal_Bool bUpdate)
1983*cdf0e10cSrcweir {
1984*cdf0e10cSrcweir     OTableRowView::DeactivateCell(bUpdate);
1985*cdf0e10cSrcweir     // now we have to deactivate the field description
1986*cdf0e10cSrcweir     long nRow(GetCurRow());
1987*cdf0e10cSrcweir     if (pDescrWin)
1988*cdf0e10cSrcweir         pDescrWin->SetReadOnly(bReadOnly || !SetDataPtr(nRow) || GetActRow()->IsReadOnly());
1989*cdf0e10cSrcweir }
1990*cdf0e10cSrcweir //------------------------------------------------------------------------------
1991*cdf0e10cSrcweir long OTableEditorCtrl::PreNotify( NotifyEvent& rNEvt )
1992*cdf0e10cSrcweir {
1993*cdf0e10cSrcweir     if (rNEvt.GetType() == EVENT_GETFOCUS)
1994*cdf0e10cSrcweir     {
1995*cdf0e10cSrcweir         if( pHelpTextCell && pHelpTextCell->HasChildPathFocus() )
1996*cdf0e10cSrcweir             m_eChildFocus = HELPTEXT;
1997*cdf0e10cSrcweir         else if( pDescrCell && pDescrCell->HasChildPathFocus() )
1998*cdf0e10cSrcweir             m_eChildFocus = DESCRIPTION;
1999*cdf0e10cSrcweir         else if(pNameCell && pNameCell->HasChildPathFocus() )
2000*cdf0e10cSrcweir             m_eChildFocus = NAME;
2001*cdf0e10cSrcweir         else
2002*cdf0e10cSrcweir             m_eChildFocus = ROW;
2003*cdf0e10cSrcweir     }
2004*cdf0e10cSrcweir 
2005*cdf0e10cSrcweir     return OTableRowView::PreNotify(rNEvt);
2006*cdf0e10cSrcweir }
2007*cdf0e10cSrcweir // -----------------------------------------------------------------------------
2008*cdf0e10cSrcweir 
2009*cdf0e10cSrcweir 
2010*cdf0e10cSrcweir 
2011*cdf0e10cSrcweir 
2012