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