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