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