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