/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include #include "fmhelp.hrc" #include #include "gridcell.hxx" #include "svx/fmtools.hxx" #include #include #include #include "fmprop.hrc" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "svx/fmresids.hrc" #include #include #include "fmservs.hxx" #include "sdbdatacolumn.hxx" #include #include #include #include #include #include using namespace ::dbtools; using namespace ::dbtools::DBTypeConversion; using namespace ::svxform; using namespace ::svt; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::sdbc; using namespace ::com::sun::star::sdbcx; using namespace ::com::sun::star::sdb; using namespace ::com::sun::star::datatransfer; using namespace ::com::sun::star::container; using namespace com::sun::star::accessibility; #define ROWSTATUS(row) (!row.Is() ? "NULL" : row->GetStatus() == GRS_CLEAN ? "CLEAN" : row->GetStatus() == GRS_MODIFIED ? "MODIFIED" : row->GetStatus() == GRS_DELETED ? "DELETED" : "INVALID") #define DEFAULT_BROWSE_MODE \ BrowserMode::COLUMNSELECTION \ | BrowserMode::MULTISELECTION \ | BrowserMode::KEEPHIGHLIGHT \ | BrowserMode::TRACKING_TIPS \ | BrowserMode::HLINES \ | BrowserMode::VLINES \ | BrowserMode::HEADERBAR_NEW \ class RowSetEventListener : public ::cppu::WeakImplHelper { VclPtr m_pControl; public: explicit RowSetEventListener(DbGridControl* i_pControl) : m_pControl(i_pControl) { } private: // XEventListener virtual void SAL_CALL disposing(const css::lang::EventObject& /*i_aEvt*/) throw ( RuntimeException, std::exception ) override { } virtual void SAL_CALL rowsChanged(const css::sdb::RowsChangeEvent& i_aEvt) throw ( RuntimeException, std::exception ) override { if ( i_aEvt.Action == RowChangeAction::UPDATE ) { ::DbGridControl::GrantControlAccess aAccess; CursorWrapper* pSeek = m_pControl->GetSeekCursor(aAccess); const DbGridRowRef& rSeekRow = m_pControl->GetSeekRow(aAccess); const Any* pIter = i_aEvt.Bookmarks.getConstArray(); const Any* pEnd = pIter + i_aEvt.Bookmarks.getLength(); for(;pIter != pEnd;++pIter) { pSeek->moveToBookmark(*pIter); // get the data rSeekRow->SetState(pSeek, true); sal_Int32 nSeekPos = pSeek->getRow() - 1; m_pControl->SetSeekPos(nSeekPos,aAccess); m_pControl->RowModified(nSeekPos); } } } }; class GridFieldValueListener; typedef std::map ColumnFieldValueListeners; class GridFieldValueListener : protected ::comphelper::OPropertyChangeListener { osl::Mutex m_aMutex; DbGridControl& m_rParent; ::comphelper::OPropertyChangeMultiplexer* m_pRealListener; sal_uInt16 m_nId; sal_Int16 m_nSuspended; bool m_bDisposed : 1; public: GridFieldValueListener(DbGridControl& _rParent, const Reference< XPropertySet >& xField, sal_uInt16 _nId); virtual ~GridFieldValueListener(); virtual void _propertyChanged(const PropertyChangeEvent& evt) throw( RuntimeException ) override; void suspend() { ++m_nSuspended; } void resume() { --m_nSuspended; } void dispose(); }; GridFieldValueListener::GridFieldValueListener(DbGridControl& _rParent, const Reference< XPropertySet >& _rField, sal_uInt16 _nId) :OPropertyChangeListener(m_aMutex) ,m_rParent(_rParent) ,m_pRealListener(nullptr) ,m_nId(_nId) ,m_nSuspended(0) ,m_bDisposed(false) { if (_rField.is()) { m_pRealListener = new ::comphelper::OPropertyChangeMultiplexer(this, _rField); m_pRealListener->addProperty(FM_PROP_VALUE); m_pRealListener->acquire(); } } GridFieldValueListener::~GridFieldValueListener() { dispose(); } void GridFieldValueListener::_propertyChanged(const PropertyChangeEvent& _evt) throw( RuntimeException ) { DBG_ASSERT(m_nSuspended>=0, "GridFieldValueListener::_propertyChanged : resume > suspend !"); if (m_nSuspended <= 0) m_rParent.FieldValueChanged(m_nId, _evt); } void GridFieldValueListener::dispose() { if (m_bDisposed) { DBG_ASSERT(m_pRealListener == nullptr, "GridFieldValueListener::dispose : inconsistent !"); return; } if (m_pRealListener) { m_pRealListener->dispose(); m_pRealListener->release(); m_pRealListener = nullptr; } m_bDisposed = true; m_rParent.FieldListenerDisposing(m_nId); } class DisposeListenerGridBridge : public FmXDisposeListener { DbGridControl& m_rParent; FmXDisposeMultiplexer* m_pRealListener; public: DisposeListenerGridBridge( DbGridControl& _rParent, const Reference< XComponent >& _rxObject, sal_Int16 _rId = -1); virtual ~DisposeListenerGridBridge(); virtual void disposing(const EventObject& _rEvent, sal_Int16 _nId) throw( RuntimeException ) override { m_rParent.disposing(_nId, _rEvent); } }; DisposeListenerGridBridge::DisposeListenerGridBridge(DbGridControl& _rParent, const Reference< XComponent >& _rxObject, sal_Int16 _rId) :FmXDisposeListener() ,m_rParent(_rParent) ,m_pRealListener(nullptr) { if (_rxObject.is()) { m_pRealListener = new FmXDisposeMultiplexer(this, _rxObject, _rId); m_pRealListener->acquire(); } } DisposeListenerGridBridge::~DisposeListenerGridBridge() { if (m_pRealListener) { m_pRealListener->dispose(); m_pRealListener->release(); m_pRealListener = nullptr; } } static const sal_uInt16 ControlMap[] = { DbGridControl::NavigationBar::RECORD_TEXT, DbGridControl::NavigationBar::RECORD_ABSOLUTE, DbGridControl::NavigationBar::RECORD_OF, DbGridControl::NavigationBar::RECORD_COUNT, DbGridControl::NavigationBar::RECORD_FIRST, DbGridControl::NavigationBar::RECORD_NEXT, DbGridControl::NavigationBar::RECORD_PREV, DbGridControl::NavigationBar::RECORD_LAST, DbGridControl::NavigationBar::RECORD_NEW, 0 }; bool CompareBookmark(const Any& aLeft, const Any& aRight) { return aLeft == aRight; } class FmXGridSourcePropListener : public ::comphelper::OPropertyChangeListener { VclPtr m_pParent; // a DbGridControl has no mutex, so we use our own as the base class expects one osl::Mutex m_aMutex; sal_Int16 m_nSuspended; public: explicit FmXGridSourcePropListener(DbGridControl* _pParent); void suspend() { ++m_nSuspended; } void resume() { --m_nSuspended; } virtual void _propertyChanged(const PropertyChangeEvent& evt) throw( RuntimeException, std::exception ) override; }; FmXGridSourcePropListener::FmXGridSourcePropListener(DbGridControl* _pParent) :OPropertyChangeListener(m_aMutex) ,m_pParent(_pParent) ,m_nSuspended(0) { DBG_ASSERT(m_pParent, "FmXGridSourcePropListener::FmXGridSourcePropListener : invalid parent !"); } void FmXGridSourcePropListener::_propertyChanged(const PropertyChangeEvent& evt) throw( RuntimeException, std::exception ) { DBG_ASSERT(m_nSuspended>=0, "FmXGridSourcePropListener::_propertyChanged : resume > suspend !"); if (m_nSuspended <= 0) m_pParent->DataSourcePropertyChanged(evt); } DbGridControl::NavigationBar::AbsolutePos::AbsolutePos(vcl::Window* pParent, WinBits nStyle) :NumericField(pParent, nStyle) { SetMin(1); SetFirst(1); SetSpinSize(1); SetDecimalDigits(0); SetStrictFormat(true); } void DbGridControl::NavigationBar::AbsolutePos::KeyInput(const KeyEvent& rEvt) { if (rEvt.GetKeyCode() == KEY_RETURN && !GetText().isEmpty()) { sal_Int64 nRecord = GetValue(); if (nRecord < GetMin() || nRecord > GetMax()) return; else static_cast(GetParent())->PositionDataSource(static_cast(nRecord)); } else if (rEvt.GetKeyCode() == KEY_TAB) GetParent()->GetParent()->GrabFocus(); else NumericField::KeyInput(rEvt); } void DbGridControl::NavigationBar::AbsolutePos::LoseFocus() { NumericField::LoseFocus(); sal_Int64 nRecord = GetValue(); if (nRecord < GetMin() || nRecord > GetMax()) return; else { static_cast(GetParent())->PositionDataSource(static_cast(nRecord)); static_cast(GetParent())->InvalidateState(NavigationBar::RECORD_ABSOLUTE); } } void DbGridControl::NavigationBar::PositionDataSource(sal_Int32 nRecord) { if (m_bPositioning) return; // the MoveToPosition may cause a LoseFocus which would lead to a second MoveToPosition, // so protect against this recursion m_bPositioning = true; static_cast(GetParent())->MoveToPosition(nRecord - 1); m_bPositioning = false; } DbGridControl::NavigationBar::NavigationBar(vcl::Window* pParent, WinBits nStyle) :Control(pParent, nStyle) ,m_aRecordText(VclPtr::Create(this, WB_VCENTER)) ,m_aAbsolute(VclPtr::Create(this, WB_CENTER | WB_VCENTER)) ,m_aRecordOf(VclPtr::Create(this, WB_VCENTER)) ,m_aRecordCount(VclPtr::Create(this, WB_VCENTER)) ,m_aFirstBtn(VclPtr::Create(this, WB_RECTSTYLE|WB_NOPOINTERFOCUS)) ,m_aPrevBtn(VclPtr::Create(this, WB_REPEAT|WB_RECTSTYLE|WB_NOPOINTERFOCUS)) ,m_aNextBtn(VclPtr::Create(this, WB_REPEAT|WB_RECTSTYLE|WB_NOPOINTERFOCUS)) ,m_aLastBtn(VclPtr::Create(this, WB_RECTSTYLE|WB_NOPOINTERFOCUS)) ,m_aNewBtn(VclPtr::Create(this, WB_RECTSTYLE|WB_NOPOINTERFOCUS)) ,m_nCurrentPos(-1) ,m_bPositioning(false) { m_aFirstBtn->SetSymbol(SymbolType::FIRST); m_aPrevBtn->SetSymbol(SymbolType::PREV); m_aNextBtn->SetSymbol(SymbolType::NEXT); m_aLastBtn->SetSymbol(SymbolType::LAST); m_aNewBtn->SetModeImage(static_cast(pParent)->GetImage(DbGridControl_Base::NEW)); m_aFirstBtn->SetHelpId(HID_GRID_TRAVEL_FIRST); m_aPrevBtn->SetHelpId(HID_GRID_TRAVEL_PREV); m_aNextBtn->SetHelpId(HID_GRID_TRAVEL_NEXT); m_aLastBtn->SetHelpId(HID_GRID_TRAVEL_LAST); m_aNewBtn->SetHelpId(HID_GRID_TRAVEL_NEW); m_aAbsolute->SetHelpId(HID_GRID_TRAVEL_ABSOLUTE); m_aRecordCount->SetHelpId(HID_GRID_NUMBEROFRECORDS); // Handler fuer Buttons einrichten m_aFirstBtn->SetClickHdl(LINK(this,NavigationBar,OnClick)); m_aPrevBtn->SetClickHdl(LINK(this,NavigationBar,OnClick)); m_aNextBtn->SetClickHdl(LINK(this,NavigationBar,OnClick)); m_aLastBtn->SetClickHdl(LINK(this,NavigationBar,OnClick)); m_aNewBtn->SetClickHdl(LINK(this,NavigationBar,OnClick)); m_aRecordText->SetText(SVX_RESSTR(RID_STR_REC_TEXT)); m_aRecordOf->SetText(SVX_RESSTR(RID_STR_REC_FROM_TEXT)); m_aRecordCount->SetText(OUString('?')); m_aFirstBtn->Disable(); m_aPrevBtn->Disable(); m_aNextBtn->Disable(); m_aLastBtn->Disable(); m_aNewBtn->Disable(); m_aRecordText->Disable(); m_aRecordOf->Disable(); m_aRecordCount->Disable(); m_aAbsolute->Disable(); AllSettings aSettings = m_aNextBtn->GetSettings(); MouseSettings aMouseSettings = aSettings.GetMouseSettings(); aMouseSettings.SetButtonRepeat(aMouseSettings.GetButtonRepeat() / 4); aSettings.SetMouseSettings(aMouseSettings); m_aNextBtn->SetSettings(aSettings, true); m_aPrevBtn->SetSettings(aSettings, true); m_aFirstBtn->Show(); m_aPrevBtn->Show(); m_aNextBtn->Show(); m_aLastBtn->Show(); m_aNewBtn->Show(); m_aRecordText->Show(); m_aRecordOf->Show(); m_aRecordCount->Show(); m_aAbsolute->Show(); } DbGridControl::NavigationBar::~NavigationBar() { disposeOnce(); } void DbGridControl::NavigationBar::dispose() { m_aRecordText.disposeAndClear(); m_aAbsolute.disposeAndClear(); m_aRecordOf.disposeAndClear(); m_aRecordCount.disposeAndClear(); m_aFirstBtn.disposeAndClear(); m_aPrevBtn.disposeAndClear(); m_aNextBtn.disposeAndClear(); m_aLastBtn.disposeAndClear(); m_aNewBtn.disposeAndClear(); Control::dispose(); } namespace { void SetPosAndSize(Button& _rButton,Point& _rPos,const Size& _rSize) { _rButton.SetPosPixel( _rPos ); _rButton.SetSizePixel( _rSize ); _rPos.X() += (sal_uInt16)_rSize.Width(); } } sal_uInt16 DbGridControl::NavigationBar::ArrangeControls() { // positioning of the controls // calculate base size Rectangle aRect(static_cast(GetParent())->GetControlArea()); long nH = aRect.GetSize().Height(); long nW = GetParent()->GetOutputSizePixel().Width(); Size aBorder = LogicToPixel(Size(2, 2),MAP_APPFONT); aBorder = Size(CalcZoom(aBorder.Width()), CalcZoom(aBorder.Height())); sal_uInt16 nX = 1; sal_uInt16 nY = 0; // Is the font of this edit larger than the field? if (m_aAbsolute->GetTextHeight() > nH) { vcl::Font aApplFont (m_aAbsolute->GetFont()); const Size pointAbsoluteSize(m_aAbsolute->PixelToLogic( Size( 0, nH - 2 ), MapMode(MAP_POINT) )); aApplFont.SetSize( pointAbsoluteSize ); m_aAbsolute->SetControlFont( aApplFont ); aApplFont.SetTransparent( true ); m_aRecordText->SetControlFont( aApplFont ); m_aRecordOf->SetControlFont( aApplFont ); m_aRecordCount->SetControlFont( aApplFont ); } // set size and position of the control OUString aText = m_aRecordText->GetText(); long nTextWidth = m_aRecordText->GetTextWidth(aText); m_aRecordText->SetPosPixel(Point(nX,nY)); m_aRecordText->SetSizePixel(Size(nTextWidth,nH)); nX = sal::static_int_cast< sal_uInt16 >(nX + nTextWidth + aBorder.Width()); // count an extra hairspace (U+200A) left and right const OUString sevenDigits(m_aAbsolute->CreateFieldText(6000000)); const OUString hairSpace(static_cast(0x200A)); OUString textPattern(hairSpace); textPattern += sevenDigits; textPattern += hairSpace; nTextWidth = m_aAbsolute->GetTextWidth(textPattern); m_aAbsolute->SetPosPixel(Point(nX,nY)); m_aAbsolute->SetSizePixel(Size(nTextWidth, nH)); nX = sal::static_int_cast< sal_uInt16 >(nX + nTextWidth + aBorder.Width()); aText = m_aRecordOf->GetText(); nTextWidth = m_aRecordOf->GetTextWidth(aText); m_aRecordOf->SetPosPixel(Point(nX,nY)); m_aRecordOf->SetSizePixel(Size(nTextWidth,nH)); nX = sal::static_int_cast< sal_uInt16 >(nX + nTextWidth + aBorder.Width()); textPattern = sevenDigits + " * (" + sevenDigits + ")"; nTextWidth = m_aRecordCount->GetTextWidth(textPattern); m_aRecordCount->SetPosPixel(Point(nX,nY)); m_aRecordCount->SetSizePixel(Size(nTextWidth,nH)); nX = sal::static_int_cast< sal_uInt16 >(nX + nTextWidth + aBorder.Width()); Point aButtonPos(nX,nY); const Size aButtonSize(nH,nH); SetPosAndSize(*m_aFirstBtn.get(), aButtonPos, aButtonSize); SetPosAndSize(*m_aPrevBtn.get(), aButtonPos, aButtonSize); SetPosAndSize(*m_aNextBtn.get(), aButtonPos, aButtonSize); SetPosAndSize(*m_aLastBtn.get(), aButtonPos, aButtonSize); SetPosAndSize(*m_aNewBtn.get(), aButtonPos, aButtonSize); nX = sal::static_int_cast< sal_uInt16 >(aButtonPos.X() + 1); nW -= GetSettings().GetStyleSettings().GetScrollBarSize(); if (nX > nW) { aButtonPos.X() = nW-nH; m_aNewBtn->SetPosPixel(aButtonPos); aButtonPos.X() -= nH; m_aLastBtn->SetPosPixel(aButtonPos); aButtonPos.X() -= nH; m_aNextBtn->SetPosPixel(aButtonPos); aButtonPos.X() -= nH; m_aPrevBtn->SetPosPixel(aButtonPos); aButtonPos.X() -= nH; m_aFirstBtn->SetPosPixel(aButtonPos); auto nDiff = nX - nW; Size aSize = m_aAbsolute->GetSizePixel(); aSize.Width() -= nDiff/3.0; m_aAbsolute->SetSizePixel(aSize); aSize = m_aRecordCount->GetSizePixel(); aSize.Width() -= nDiff/3.0*2; m_aRecordCount->SetSizePixel(aSize); Point aPos = m_aRecordOf->GetPosPixel(); aPos.X() -= nDiff/3.0; m_aRecordOf->SetPosPixel(aPos); aPos = m_aRecordCount->GetPosPixel(); aPos.X() -= nDiff/3.0; m_aRecordCount->SetPosPixel(aPos); vcl::Window* pWindows[] = { m_aRecordText.get(), m_aAbsolute.get(), m_aRecordOf.get(), m_aRecordCount.get(), m_aFirstBtn.get(), m_aPrevBtn.get(), m_aNextBtn.get(), m_aLastBtn.get(), m_aNewBtn.get() }; for (size_t i=0; i < (sizeof (pWindows) / sizeof(pWindows[0])); ++i) { if (pWindows[i]->GetPosPixel().X() < 0) pWindows[i]->SetSizePixel(Size(0, nH)); aSize = pWindows[i]->GetSizePixel(); auto nExcess = (pWindows[i]->GetPosPixel().X() + aSize.Width()) - nW; if (nExcess > 0) { aSize.Width() -= nExcess; pWindows[i]->SetSizePixel(aSize); } } nX = nW; } return nX; } IMPL_LINK_TYPED(DbGridControl::NavigationBar, OnClick, Button *, pButton, void ) { DbGridControl* pParent = static_cast(GetParent()); if (pParent->m_aMasterSlotExecutor.IsSet()) { bool lResult = false; if (pButton == m_aFirstBtn.get()) lResult = pParent->m_aMasterSlotExecutor.Call(RECORD_FIRST); else if( pButton == m_aPrevBtn.get() ) lResult = pParent->m_aMasterSlotExecutor.Call(RECORD_PREV); else if( pButton == m_aNextBtn.get() ) lResult = pParent->m_aMasterSlotExecutor.Call(RECORD_NEXT); else if( pButton == m_aLastBtn.get() ) lResult = pParent->m_aMasterSlotExecutor.Call(RECORD_LAST); else if( pButton == m_aNewBtn.get() ) lResult = pParent->m_aMasterSlotExecutor.Call(RECORD_NEW); if (lResult) // the link already handled it return; } if (pButton == m_aFirstBtn.get()) pParent->MoveToFirst(); else if( pButton == m_aPrevBtn.get() ) pParent->MoveToPrev(); else if( pButton == m_aNextBtn.get() ) pParent->MoveToNext(); else if( pButton == m_aLastBtn.get() ) pParent->MoveToLast(); else if( pButton == m_aNewBtn.get() ) pParent->AppendNew(); } void DbGridControl::NavigationBar::InvalidateAll(sal_Int32 nCurrentPos, bool bAll) { if (m_nCurrentPos != nCurrentPos || nCurrentPos < 0 || bAll) { DbGridControl* pParent = static_cast(GetParent()); sal_Int32 nAdjustedRowCount = pParent->GetRowCount() - ((pParent->GetOptions() & DbGridControl::OPT_INSERT) ? 2 : 1); // check if everything needs to be invalidated bAll = bAll || m_nCurrentPos <= 0; bAll = bAll || nCurrentPos <= 0; bAll = bAll || m_nCurrentPos >= nAdjustedRowCount; bAll = bAll || nCurrentPos >= nAdjustedRowCount; if ( bAll ) { m_nCurrentPos = nCurrentPos; int i = 0; while (ControlMap[i]) SetState(ControlMap[i++]); } else // is in the center { m_nCurrentPos = nCurrentPos; SetState(NavigationBar::RECORD_COUNT); SetState(NavigationBar::RECORD_ABSOLUTE); } } } bool DbGridControl::NavigationBar::GetState(sal_uInt16 nWhich) const { DbGridControl* pParent = static_cast(GetParent()); if (!pParent->IsOpen() || pParent->IsDesignMode() || !pParent->IsEnabled() || pParent->IsFilterMode() ) return false; else { // check if we have a master state provider if (pParent->m_aMasterStateProvider.IsSet()) { long nState = pParent->m_aMasterStateProvider.Call( nWhich ); if (nState>=0) return (nState>0); } bool bAvailable = true; switch (nWhich) { case NavigationBar::RECORD_FIRST: case NavigationBar::RECORD_PREV: bAvailable = m_nCurrentPos > 0; break; case NavigationBar::RECORD_NEXT: if(pParent->m_bRecordCountFinal) { bAvailable = m_nCurrentPos < pParent->GetRowCount() - 1; if (!bAvailable && pParent->GetOptions() & DbGridControl::OPT_INSERT) bAvailable = (m_nCurrentPos == pParent->GetRowCount() - 2) && pParent->IsModified(); } break; case NavigationBar::RECORD_LAST: if(pParent->m_bRecordCountFinal) { if (pParent->GetOptions() & DbGridControl::OPT_INSERT) bAvailable = pParent->IsCurrentAppending() ? pParent->GetRowCount() > 1 : m_nCurrentPos != pParent->GetRowCount() - 2; else bAvailable = m_nCurrentPos != pParent->GetRowCount() - 1; } break; case NavigationBar::RECORD_NEW: bAvailable = (pParent->GetOptions() & DbGridControl::OPT_INSERT) && pParent->GetRowCount() && m_nCurrentPos < pParent->GetRowCount() - 1; break; case NavigationBar::RECORD_ABSOLUTE: bAvailable = pParent->GetRowCount() > 0; break; } return bAvailable; } } void DbGridControl::NavigationBar::SetState(sal_uInt16 nWhich) { bool bAvailable = GetState(nWhich); DbGridControl* pParent = static_cast(GetParent()); vcl::Window* pWnd = nullptr; switch (nWhich) { case NavigationBar::RECORD_FIRST: pWnd = m_aFirstBtn.get(); break; case NavigationBar::RECORD_PREV: pWnd = m_aPrevBtn.get(); break; case NavigationBar::RECORD_NEXT: pWnd = m_aNextBtn.get(); break; case NavigationBar::RECORD_LAST: pWnd = m_aLastBtn.get(); break; case NavigationBar::RECORD_NEW: pWnd = m_aNewBtn.get(); break; case NavigationBar::RECORD_ABSOLUTE: pWnd = m_aAbsolute.get(); if (bAvailable) { if (pParent->m_nTotalCount >= 0) { if (pParent->IsCurrentAppending()) m_aAbsolute->SetMax(pParent->m_nTotalCount + 1); else m_aAbsolute->SetMax(pParent->m_nTotalCount); } else m_aAbsolute->SetMax(LONG_MAX); m_aAbsolute->SetValue(m_nCurrentPos + 1); } else m_aAbsolute->SetText(OUString()); break; case NavigationBar::RECORD_TEXT: pWnd = m_aRecordText.get(); break; case NavigationBar::RECORD_OF: pWnd = m_aRecordOf.get(); break; case NavigationBar::RECORD_COUNT: { pWnd = m_aRecordCount.get(); OUString aText; if (bAvailable) { if (pParent->GetOptions() & DbGridControl::OPT_INSERT) { if (pParent->IsCurrentAppending() && !pParent->IsModified()) aText = m_aAbsolute->CreateFieldText(pParent->GetRowCount()); else aText = m_aAbsolute->CreateFieldText(pParent->GetRowCount() - 1); } else aText = m_aAbsolute->CreateFieldText(pParent->GetRowCount()); if(!pParent->m_bRecordCountFinal) aText += " *"; } else aText.clear(); // add the number of selected rows, if applicable if (pParent->GetSelectRowCount()) { OUString aExtendedInfo(aText); aExtendedInfo += " ("; aExtendedInfo += m_aAbsolute->CreateFieldText(pParent->GetSelectRowCount()); aExtendedInfo += ")"; pWnd->SetText(aExtendedInfo); } else pWnd->SetText(aText); pParent->SetRealRowCount(aText); } break; } DBG_ASSERT(pWnd, "kein Fenster"); if (pWnd && (pWnd->IsEnabled() != bAvailable)) // this "pWnd->IsEnabled() != bAvailable" is a little hack : Window::Enable always generates a user // event (ImplGenerateMouseMove) even if nothing happened. This may lead to some unwanted effects, so we // do this check. // For further explanation see Bug 69900. pWnd->Enable(bAvailable); } void DbGridControl::NavigationBar::Resize() { Control::Resize(); ArrangeControls(); } void DbGridControl::NavigationBar::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) { Control::Paint(rRenderContext, rRect); Point aAbsolutePos = m_aAbsolute->GetPosPixel(); Size aAbsoluteSize = m_aAbsolute->GetSizePixel(); rRenderContext.DrawLine(Point(aAbsolutePos.X() - 1, 0 ), Point(aAbsolutePos.X() - 1, aAbsolutePos.Y() + aAbsoluteSize.Height())); rRenderContext.DrawLine(Point(aAbsolutePos.X() + aAbsoluteSize.Width() + 1, 0 ), Point(aAbsolutePos.X() + aAbsoluteSize.Width() + 1, aAbsolutePos.Y() + aAbsoluteSize.Height())); } void DbGridControl::NavigationBar::StateChanged(StateChangedType nType) { Control::StateChanged(nType); vcl::Window* pWindows[] = { m_aRecordText.get(), m_aAbsolute.get(), m_aRecordOf.get(), m_aRecordCount.get(), m_aFirstBtn.get(), m_aPrevBtn.get(), m_aNextBtn.get(), m_aLastBtn.get(), m_aNewBtn.get() }; switch ( nType ) { case StateChangedType::Mirroring: { bool bIsRTLEnabled = IsRTLEnabled(); for (size_t i=0; i < (sizeof (pWindows) / sizeof(pWindows[0])); ++i) pWindows[i]->EnableRTL( bIsRTLEnabled ); } break; case StateChangedType::Zoom: { Fraction aZoom = GetZoom(); // not all of these controls need to know the new zoom, but to be sure ... vcl::Font aFont(GetSettings().GetStyleSettings().GetFieldFont()); if (IsControlFont()) aFont.Merge(GetControlFont()); for (size_t i=0; i < sizeof(pWindows)/sizeof(pWindows[0]); ++i) { pWindows[i]->SetZoom(aZoom); pWindows[i]->SetZoomedPointFont(*pWindows[i], aFont); } SetZoomedPointFont(*this, aFont); // rearrange the controls ArrangeControls(); } break; default:; } } DbGridRow::DbGridRow(CursorWrapper* pCur, bool bPaintCursor) :m_bIsNew(false) { if (pCur && pCur->Is()) { Reference< XIndexAccess > xColumns(pCur->getColumns(), UNO_QUERY); for (sal_Int32 i = 0; i < xColumns->getCount(); ++i) { Reference< XPropertySet > xColSet( xColumns->getByIndex(i), css::uno::UNO_QUERY); DataColumn* pColumn = new DataColumn(xColSet); m_aVariants.push_back( pColumn ); } if (pCur->rowDeleted()) m_eStatus = GRS_DELETED; else { if (bPaintCursor) m_eStatus = (pCur->isAfterLast() || pCur->isBeforeFirst()) ? GRS_INVALID : GRS_CLEAN; else { Reference< XPropertySet > xSet = pCur->getPropertySet(); if (xSet.is()) { m_bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISNEW)); if (!m_bIsNew && (pCur->isAfterLast() || pCur->isBeforeFirst())) m_eStatus = GRS_INVALID; else if (::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISMODIFIED))) m_eStatus = GRS_MODIFIED; else m_eStatus = GRS_CLEAN; } else m_eStatus = GRS_INVALID; } } if (!m_bIsNew && IsValid()) m_aBookmark = pCur->getBookmark(); else m_aBookmark = Any(); } else m_eStatus = GRS_INVALID; } DbGridRow::~DbGridRow() { for ( size_t i = 0, n = m_aVariants.size(); i < n; ++i ) delete m_aVariants[ i ]; m_aVariants.clear(); } void DbGridRow::SetState(CursorWrapper* pCur, bool bPaintCursor) { if (pCur && pCur->Is()) { if (pCur->rowDeleted()) { m_eStatus = GRS_DELETED; m_bIsNew = false; } else { m_eStatus = GRS_CLEAN; if (!bPaintCursor) { Reference< XPropertySet > xSet = pCur->getPropertySet(); DBG_ASSERT(xSet.is(), "DbGridRow::SetState : invalid cursor !"); if (::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISMODIFIED))) m_eStatus = GRS_MODIFIED; m_bIsNew = ::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ISNEW)); } else m_bIsNew = false; } try { if (!m_bIsNew && IsValid()) m_aBookmark = pCur->getBookmark(); else m_aBookmark = Any(); } catch(SQLException&) { DBG_UNHANDLED_EXCEPTION(); m_aBookmark = Any(); m_eStatus = GRS_INVALID; m_bIsNew = false; } } else { m_aBookmark = Any(); m_eStatus = GRS_INVALID; m_bIsNew = false; } } DbGridControl::DbGridControl( Reference< XComponentContext > _rxContext, vcl::Window* pParent, WinBits nBits) :DbGridControl_Base(pParent, EditBrowseBoxFlags::NONE, nBits, DEFAULT_BROWSE_MODE ) ,m_xContext(_rxContext) ,m_aBar(VclPtr::Create(this)) ,m_nAsynAdjustEvent(nullptr) ,m_pDataSourcePropMultiplexer(nullptr) ,m_pDataSourcePropListener(nullptr) ,m_pFieldListeners(nullptr) ,m_pCursorDisposeListener(nullptr) ,m_pGridListener(nullptr) ,m_pDataCursor(nullptr) ,m_pSeekCursor(nullptr) ,m_nSeekPos(-1) ,m_nTotalCount(-1) ,m_aNullDate(::dbtools::DBTypeConversion::getStandardDate()) ,m_nMode(DEFAULT_BROWSE_MODE) ,m_nCurrentPos(-1) ,m_nDeleteEvent(nullptr) ,m_nOptions(OPT_READONLY) ,m_nOptionMask(OPT_INSERT | OPT_UPDATE | OPT_DELETE) ,m_nLastColId((sal_uInt16)-1) ,m_nLastRowId(-1) ,m_bDesignMode(false) ,m_bRecordCountFinal(false) ,m_bMultiSelection(true) ,m_bNavigationBar(true) ,m_bSynchDisplay(true) ,m_bForceROController(false) ,m_bHandle(true) ,m_bFilterMode(false) ,m_bWantDestruction(false) ,m_bInAdjustDataSource(false) ,m_bPendingAdjustRows(false) ,m_bHideScrollbars( false ) ,m_bUpdating(false) { OUString sName(SVX_RESSTR(RID_STR_NAVIGATIONBAR)); m_aBar->SetAccessibleName(sName); m_aBar->Show(); ImplInitWindow( InitAll ); } void DbGridControl::InsertHandleColumn() { // BrowseBox has problems when painting without a handleColumn (hide it here) if (HasHandle()) BrowseBox::InsertHandleColumn(GetDefaultColumnWidth(OUString())); else BrowseBox::InsertHandleColumn(0); } void DbGridControl::Init() { BrowserHeader* pNewHeader = CreateHeaderBar(this); pHeader->SetMouseTransparent(false); SetHeaderBar(pNewHeader); SetMode(m_nMode); SetCursorColor(Color(0xFF, 0, 0)); InsertHandleColumn(); } DbGridControl::~DbGridControl() { disposeOnce(); } void DbGridControl::dispose() { if (!IsDisposed()) { RemoveColumns(); m_bWantDestruction = true; osl::MutexGuard aGuard(m_aDestructionSafety); if (m_pFieldListeners) DisconnectFromFields(); if (m_pCursorDisposeListener) { delete m_pCursorDisposeListener; m_pCursorDisposeListener = nullptr; } } if (m_nDeleteEvent) Application::RemoveUserEvent(m_nDeleteEvent); if (m_pDataSourcePropMultiplexer) { m_pDataSourcePropMultiplexer->dispose(); m_pDataSourcePropMultiplexer->release(); // this should delete the multiplexer delete m_pDataSourcePropListener; m_pDataSourcePropMultiplexer = nullptr; m_pDataSourcePropListener = nullptr; } m_xRowSetListener.clear(); delete m_pDataCursor; m_pDataCursor = nullptr; delete m_pSeekCursor; m_pSeekCursor = nullptr; m_aBar.disposeAndClear(); DbGridControl_Base::dispose(); } void DbGridControl::StateChanged( StateChangedType nType ) { DbGridControl_Base::StateChanged( nType ); switch (nType) { case StateChangedType::Mirroring: ImplInitWindow( InitWritingMode ); Invalidate(); break; case StateChangedType::Zoom: { ImplInitWindow( InitFontFacet ); // and give it a chance to rearrange Point aPoint = GetControlArea().TopLeft(); sal_uInt16 nX = (sal_uInt16)aPoint.X(); ArrangeControls(nX, (sal_uInt16)aPoint.Y()); ReserveControlArea((sal_uInt16)nX); } break; case StateChangedType::ControlFont: ImplInitWindow( InitFontFacet ); Invalidate(); break; case StateChangedType::ControlForeground: ImplInitWindow( InitForeground ); Invalidate(); break; case StateChangedType::ControlBackground: ImplInitWindow( InitBackground ); Invalidate(); break; default:; } } void DbGridControl::DataChanged( const DataChangedEvent& rDCEvt ) { DbGridControl_Base::DataChanged( rDCEvt ); if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS ) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) ) { ImplInitWindow( InitAll ); Invalidate(); } } void DbGridControl::Select() { DbGridControl_Base::Select(); // as the selected rows may have changed, update the according display in our navigation bar m_aBar->InvalidateState(NavigationBar::RECORD_COUNT); if (m_pGridListener) m_pGridListener->selectionChanged(); } void DbGridControl::ImplInitWindow( const InitWindowFacet _eInitWhat ) { for ( size_t i = 0; i < m_aColumns.size(); ++i ) { DbGridColumn* pCol = m_aColumns[ i ]; if (pCol) pCol->ImplInitWindow( GetDataWindow(), _eInitWhat ); } if ( ( _eInitWhat & InitWritingMode ) != 0 ) { if ( m_bNavigationBar ) { m_aBar->EnableRTL( IsRTLEnabled() ); } } if ( ( _eInitWhat & InitFontFacet ) != 0 ) { if ( m_bNavigationBar ) { vcl::Font aFont = m_aBar->GetSettings().GetStyleSettings().GetFieldFont(); if ( IsControlFont() ) m_aBar->SetControlFont( GetControlFont() ); else m_aBar->SetControlFont(); m_aBar->SetZoom( GetZoom() ); } } if ( ( _eInitWhat & InitBackground ) != 0 ) { if (IsControlBackground()) { GetDataWindow().SetBackground(GetControlBackground()); GetDataWindow().SetControlBackground(GetControlBackground()); GetDataWindow().SetFillColor(GetControlBackground()); } else { GetDataWindow().SetControlBackground(); GetDataWindow().SetFillColor(GetFillColor()); } } } void DbGridControl::RemoveRows(bool bNewCursor) { // Did the data cursor change? if (!bNewCursor) { DELETEZ(m_pSeekCursor); m_xPaintRow = m_xDataRow = m_xEmptyRow = m_xCurrentRow = m_xSeekRow = nullptr; m_nCurrentPos = m_nSeekPos = -1; m_nOptions = OPT_READONLY; RowRemoved(0, GetRowCount(), false); m_nTotalCount = -1; } else { RemoveRows(); } } void DbGridControl::RemoveRows() { // we're going to remove all columns and all row, so deactivate the current cell if (IsEditing()) DeactivateCell(); // de-initialize all columns // if there are columns, free all controllers for (size_t i = 0; i < m_aColumns.size(); i++) m_aColumns[ i ]->Clear(); DELETEZ(m_pSeekCursor); DELETEZ(m_pDataCursor); m_xPaintRow = m_xDataRow = m_xEmptyRow = m_xCurrentRow = m_xSeekRow = nullptr; m_nCurrentPos = m_nSeekPos = m_nTotalCount = -1; m_nOptions = OPT_READONLY; // reset number of sentences to zero in the browser DbGridControl_Base::RemoveRows(); m_aBar->InvalidateAll(m_nCurrentPos, true); } void DbGridControl::ArrangeControls(sal_uInt16& nX, sal_uInt16 nY) { // positioning of the controls if (m_bNavigationBar) { Rectangle aRect(GetControlArea()); m_aBar->SetPosSizePixel(Point(0, nY + 1), Size(aRect.GetSize().Width(), aRect.GetSize().Height() - 1)); nX = m_aBar->ArrangeControls(); } } void DbGridControl::EnableHandle(bool bEnable) { if (m_bHandle == bEnable) return; // HandleColumn is only hidden because there are a lot of problems while painting otherwise RemoveColumn( HandleColumnId ); m_bHandle = bEnable; InsertHandleColumn(); } namespace { bool adjustModeForScrollbars( BrowserMode& _rMode, bool _bNavigationBar, bool _bHideScrollbars ) { BrowserMode nOldMode = _rMode; if ( !_bNavigationBar ) { _rMode &= ~BrowserMode::AUTO_HSCROLL; } if ( _bHideScrollbars ) { _rMode |= ( BrowserMode::NO_HSCROLL | BrowserMode::NO_VSCROLL ); _rMode &= ~BrowserMode( BrowserMode::AUTO_HSCROLL | BrowserMode::AUTO_VSCROLL ); } else { _rMode |= ( BrowserMode::AUTO_HSCROLL | BrowserMode::AUTO_VSCROLL ); _rMode &= ~BrowserMode( BrowserMode::NO_HSCROLL | BrowserMode::NO_VSCROLL ); } // note: if we have a navigation bar, we always have a AUTO_HSCROLL. In particular, // _bHideScrollbars is ignored then if ( _bNavigationBar ) { _rMode |= BrowserMode::AUTO_HSCROLL; _rMode &= ~BrowserMode::NO_HSCROLL; } return nOldMode != _rMode; } } void DbGridControl::EnableNavigationBar(bool bEnable) { if (m_bNavigationBar == bEnable) return; m_bNavigationBar = bEnable; if (bEnable) { m_aBar->Show(); m_aBar->Enable(); m_aBar->InvalidateAll(m_nCurrentPos, true); if ( adjustModeForScrollbars( m_nMode, m_bNavigationBar, m_bHideScrollbars ) ) SetMode( m_nMode ); // get size of the reserved ControlArea Point aPoint = GetControlArea().TopLeft(); sal_uInt16 nX = (sal_uInt16)aPoint.X(); ArrangeControls(nX, (sal_uInt16)aPoint.Y()); ReserveControlArea((sal_uInt16)nX); } else { m_aBar->Hide(); m_aBar->Disable(); if ( adjustModeForScrollbars( m_nMode, m_bNavigationBar, m_bHideScrollbars ) ) SetMode( m_nMode ); ReserveControlArea(); } } sal_uInt16 DbGridControl::SetOptions(sal_uInt16 nOpt) { DBG_ASSERT(!m_xCurrentRow || !m_xCurrentRow->IsModified(), "DbGridControl::SetOptions : please do not call when editing a record (things are much easier this way ;) !"); // for the next setDataSource (which is triggered by a refresh, for instance) m_nOptionMask = nOpt; // normalize the new options Reference< XPropertySet > xDataSourceSet = m_pDataCursor->getPropertySet(); if (xDataSourceSet.is()) { // check what kind of options are available sal_Int32 nPrivileges = 0; xDataSourceSet->getPropertyValue(FM_PROP_PRIVILEGES) >>= nPrivileges; if ((nPrivileges & Privilege::INSERT) == 0) nOpt &= ~OPT_INSERT; if ((nPrivileges & Privilege::UPDATE) == 0) nOpt &= ~OPT_UPDATE; if ((nPrivileges & Privilege::DELETE) == 0) nOpt &= ~OPT_DELETE; } else nOpt = OPT_READONLY; // need to do something after that ? if (nOpt == m_nOptions) return m_nOptions; // the 'update' option only affects our BrowserMode (with or w/o focus rect) BrowserMode nNewMode = m_nMode; if (!(m_nMode & BrowserMode::CURSOR_WO_FOCUS)) { if (nOpt & OPT_UPDATE) nNewMode |= BrowserMode::HIDECURSOR; else nNewMode &= ~BrowserMode::HIDECURSOR; } else nNewMode &= ~BrowserMode::HIDECURSOR; // should not be necessary if EnablePermanentCursor is used to change the cursor behaviour, but to be sure ... if (nNewMode != m_nMode) { SetMode(nNewMode); m_nMode = nNewMode; } // _after_ setting the mode because this results in an ActivateCell DeactivateCell(); bool bInsertChanged = (nOpt & OPT_INSERT) != (m_nOptions & OPT_INSERT); m_nOptions = nOpt; // we need to set this before the code below because it indirectly uses m_nOptions // the 'insert' option affects our empty row if (bInsertChanged) { if (m_nOptions & OPT_INSERT) { // the insert option is to be set m_xEmptyRow = new DbGridRow(); RowInserted(GetRowCount()); } else { // the insert option is to be reset m_xEmptyRow = nullptr; if ((GetCurRow() == GetRowCount() - 1) && (GetCurRow() > 0)) GoToRowColumnId(GetCurRow() - 1, GetCurColumnId()); RowRemoved(GetRowCount()); } } // the 'delete' options has no immediate consequences ActivateCell(); Invalidate(); return m_nOptions; } void DbGridControl::ForceHideScrollbars( bool _bForce ) { if ( m_bHideScrollbars == _bForce ) return; m_bHideScrollbars = _bForce; if ( adjustModeForScrollbars( m_nMode, m_bNavigationBar, m_bHideScrollbars ) ) SetMode( m_nMode ); } void DbGridControl::EnablePermanentCursor(bool bEnable) { if (IsPermanentCursorEnabled() == bEnable) return; if (bEnable) { m_nMode &= ~BrowserMode::HIDECURSOR; // without this BrowserMode::CURSOR_WO_FOCUS won't have any affect m_nMode |= BrowserMode::CURSOR_WO_FOCUS; } else { if (m_nOptions & OPT_UPDATE) m_nMode |= BrowserMode::HIDECURSOR; // no cursor at all else m_nMode &= ~BrowserMode::HIDECURSOR; // at least the "non-permanent" cursor m_nMode &= ~BrowserMode::CURSOR_WO_FOCUS; } SetMode(m_nMode); bool bWasEditing = IsEditing(); DeactivateCell(); if (bWasEditing) ActivateCell(); } bool DbGridControl::IsPermanentCursorEnabled() const { return (m_nMode & BrowserMode::CURSOR_WO_FOCUS) && !(m_nMode & BrowserMode::HIDECURSOR); } void DbGridControl::refreshController(sal_uInt16 _nColId, GrantControlAccess /*_aAccess*/) { if ((GetCurColumnId() == _nColId) && IsEditing()) { // the controller which is currently active needs to be refreshed DeactivateCell(); ActivateCell(); } } void DbGridControl::setDataSource(const Reference< XRowSet >& _xCursor, sal_uInt16 nOpts) { if (!_xCursor.is() && !m_pDataCursor) return; if (m_pDataSourcePropMultiplexer) { m_pDataSourcePropMultiplexer->dispose(); m_pDataSourcePropMultiplexer->release(); // this should delete the multiplexer delete m_pDataSourcePropListener; m_pDataSourcePropMultiplexer = nullptr; m_pDataSourcePropListener = nullptr; } m_xRowSetListener.clear(); // is the new cursor valid ? // the cursor is only valid if it contains some columns // if there is no cursor or the cursor is not valid we have to clean up an leave if (!_xCursor.is() || !Reference< XColumnsSupplier > (_xCursor, UNO_QUERY)->getColumns()->hasElements()) { RemoveRows(); return; } // did the data cursor change? sal_uInt16 nCurPos = GetColumnPos(GetCurColumnId()); SetUpdateMode(false); RemoveRows(); DisconnectFromFields(); DELETEZ(m_pCursorDisposeListener); { ::osl::MutexGuard aGuard(m_aAdjustSafety); if (m_nAsynAdjustEvent) { // the adjust was thought to work with the old cursor which we don't have anymore RemoveUserEvent(m_nAsynAdjustEvent); m_nAsynAdjustEvent = nullptr; } } // get a new formatter and data cursor m_xFormatter = nullptr; Reference< css::util::XNumberFormatsSupplier > xSupplier = getNumberFormats(getConnection(_xCursor), true); if (xSupplier.is()) { m_xFormatter.set( css::util::NumberFormatter::create(m_xContext), UNO_QUERY); m_xFormatter->attachNumberFormatsSupplier(xSupplier); // retrieve the datebase of the Numberformatter try { xSupplier->getNumberFormatSettings()->getPropertyValue("NullDate") >>= m_aNullDate; } catch(Exception&) { } } m_pDataCursor = new CursorWrapper(_xCursor); // now create a cursor for painting rows // we need that cursor only if we are not in insert only mode Reference< XResultSet > xClone; Reference< XResultSetAccess > xAccess( _xCursor, UNO_QUERY ); try { xClone = xAccess.is() ? xAccess->createResultSet() : Reference< XResultSet > (); } catch(Exception&) { } if (xClone.is()) m_pSeekCursor = new CursorWrapper(xClone); // property listening on the data source // (Normally one class would be sufficient : the multiplexer which could forward the property change to us. // But for that we would have been derived from ::comphelper::OPropertyChangeListener, which isn't exported. // So we introduce a second class, which is a ::comphelper::OPropertyChangeListener (in the implementation file we know this class) // and forwards the property changes to a our special method "DataSourcePropertyChanged".) if (m_pDataCursor) { m_pDataSourcePropListener = new FmXGridSourcePropListener(this); m_pDataSourcePropMultiplexer = new ::comphelper::OPropertyChangeMultiplexer(m_pDataSourcePropListener, m_pDataCursor->getPropertySet() ); m_pDataSourcePropMultiplexer->acquire(); m_pDataSourcePropMultiplexer->addProperty(FM_PROP_ISMODIFIED); m_pDataSourcePropMultiplexer->addProperty(FM_PROP_ISNEW); } BrowserMode nOldMode = m_nMode; if (m_pSeekCursor) { try { Reference< XPropertySet > xSet(_xCursor, UNO_QUERY); if (xSet.is()) { // check what kind of options are available sal_Int32 nConcurrency = ResultSetConcurrency::READ_ONLY; xSet->getPropertyValue(FM_PROP_RESULTSET_CONCURRENCY) >>= nConcurrency; if ( ResultSetConcurrency::UPDATABLE == nConcurrency ) { sal_Int32 nPrivileges = 0; xSet->getPropertyValue(FM_PROP_PRIVILEGES) >>= nPrivileges; // Insert Option should be set if insert only otherwise you won't see any rows // and no insertion is possible if ((m_nOptionMask & OPT_INSERT) && ((nPrivileges & Privilege::INSERT) == Privilege::INSERT) && (nOpts & OPT_INSERT)) m_nOptions |= OPT_INSERT; if ((m_nOptionMask & OPT_UPDATE) && ((nPrivileges & Privilege::UPDATE) == Privilege::UPDATE) && (nOpts & OPT_UPDATE)) m_nOptions |= OPT_UPDATE; if ((m_nOptionMask & OPT_DELETE) && ((nPrivileges & Privilege::DELETE) == Privilege::DELETE) && (nOpts & OPT_DELETE)) m_nOptions |= OPT_DELETE; } } } catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); } bool bPermanentCursor = IsPermanentCursorEnabled(); m_nMode = DEFAULT_BROWSE_MODE; if ( bPermanentCursor ) { m_nMode |= BrowserMode::CURSOR_WO_FOCUS; m_nMode &= ~BrowserMode::HIDECURSOR; } else { // updates are allowed -> no focus rectangle if ( m_nOptions & OPT_UPDATE ) m_nMode |= BrowserMode::HIDECURSOR; } if ( m_bMultiSelection ) m_nMode |= BrowserMode::MULTISELECTION; else m_nMode &= ~BrowserMode::MULTISELECTION; adjustModeForScrollbars( m_nMode, m_bNavigationBar, m_bHideScrollbars ); Reference< XColumnsSupplier > xSupplyColumns(_xCursor, UNO_QUERY); if (xSupplyColumns.is()) InitColumnsByFields(Reference< XIndexAccess > (xSupplyColumns->getColumns(), UNO_QUERY)); ConnectToFields(); } sal_uInt32 nRecordCount(0); if (m_pSeekCursor) { Reference< XPropertySet > xSet = m_pDataCursor->getPropertySet(); xSet->getPropertyValue(FM_PROP_ROWCOUNT) >>= nRecordCount; m_bRecordCountFinal = ::comphelper::getBOOL(xSet->getPropertyValue(FM_PROP_ROWCOUNTFINAL)); m_xRowSetListener = new RowSetEventListener(this); Reference< XRowsChangeBroadcaster> xChangeBroad(xSet,UNO_QUERY); if ( xChangeBroad.is( ) ) xChangeBroad->addRowsChangeListener(m_xRowSetListener); // insert the currently known rows // and one row if we are able to insert rows if (m_nOptions & OPT_INSERT) { // insert the empty row for insertion m_xEmptyRow = new DbGridRow(); ++nRecordCount; } if (nRecordCount) { m_xPaintRow = m_xSeekRow = new DbGridRow(m_pSeekCursor, true); m_xDataRow = new DbGridRow(m_pDataCursor, false); RowInserted(0, nRecordCount, false); if (m_xSeekRow->IsValid()) try { m_nSeekPos = m_pSeekCursor->getRow() - 1; } catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); m_nSeekPos = -1; } } else { // no rows so we don't need a seekcursor DELETEZ(m_pSeekCursor); } } // go to the old column if (nCurPos == BROWSER_INVALIDID || nCurPos >= ColCount()) nCurPos = 0; // Column zero is a valid choice and guaranteed to exist, // but invisible to the user; if we have at least one // user-visible column, go to that one. if (nCurPos == 0 && ColCount() > 1) nCurPos = 1; // there are rows so go to the selected current column if (nRecordCount) GoToRowColumnId(0, GetColumnId(nCurPos)); // else stop the editing if necessary else if (IsEditing()) DeactivateCell(); // now reset the mode if (m_nMode != nOldMode) SetMode(m_nMode); // RecalcRows was already called while resizing if (!IsResizing() && GetRowCount()) RecalcRows(GetTopRow(), GetVisibleRows(), true); m_aBar->InvalidateAll(m_nCurrentPos, true); SetUpdateMode(true); // start listening on the seek cursor if (m_pSeekCursor) m_pCursorDisposeListener = new DisposeListenerGridBridge(*this, Reference< XComponent > (Reference< XInterface >(*m_pSeekCursor), UNO_QUERY), 0); } void DbGridControl::RemoveColumns() { if ( IsEditing() ) DeactivateCell(); for (size_t i = 0, n = m_aColumns.size(); i < n; i++) delete m_aColumns[ i ]; m_aColumns.clear(); DbGridControl_Base::RemoveColumns(); } DbGridColumn* DbGridControl::CreateColumn(sal_uInt16 nId) const { return new DbGridColumn(nId, *const_cast(this)); } sal_uInt16 DbGridControl::AppendColumn(const OUString& rName, sal_uInt16 nWidth, sal_uInt16 nModelPos, sal_uInt16 nId) { DBG_ASSERT(nId == BROWSER_INVALIDID, "DbGridControl::AppendColumn : I want to set the ID myself ..."); sal_uInt16 nRealPos = nModelPos; if (nModelPos != HEADERBAR_APPEND) { // calc the view pos. we can't use our converting functions because the new column // has no VCL-representation, yet. sal_Int16 nViewPos = nModelPos; while (nModelPos--) { if ( m_aColumns[ nModelPos ]->IsHidden() ) --nViewPos; } // restore nModelPos, we need it later nModelPos = nRealPos; // the position the base class gets is the view pos + 1 (because of the handle column) nRealPos = nViewPos + 1; } // calculate the new id for (nId=1; (GetModelColumnPos(nId) != GRID_COLUMN_NOT_FOUND) && (nId <= m_aColumns.size()); ++nId) ; DBG_ASSERT(GetViewColumnPos(nId) == GRID_COLUMN_NOT_FOUND, "DbGridControl::AppendColumn : inconsistent internal state !"); // my column's models say "there is no column with id nId", but the view (the base class) says "there is a column ..." DbGridControl_Base::AppendColumn(rName, nWidth, nRealPos, nId); if (nModelPos == HEADERBAR_APPEND) m_aColumns.push_back( CreateColumn(nId) ); else { DbGridColumns::iterator it = m_aColumns.begin(); ::std::advance( it, nModelPos ); m_aColumns.insert( it, CreateColumn(nId) ); } return nId; } void DbGridControl::RemoveColumn(sal_uInt16 nId) { DbGridControl_Base::RemoveColumn(nId); const sal_uInt16 nIndex = GetModelColumnPos(nId); if(nIndex != GRID_COLUMN_NOT_FOUND) { delete m_aColumns[nIndex]; m_aColumns.erase( m_aColumns.begin()+nIndex ); } } void DbGridControl::ColumnMoved(sal_uInt16 nId) { DbGridControl_Base::ColumnMoved(nId); // remove the col from the model sal_uInt16 nOldModelPos = GetModelColumnPos(nId); #ifdef DBG_UTIL DbGridColumn* pCol = m_aColumns[ (sal_uInt32)nOldModelPos ]; DBG_ASSERT(!pCol->IsHidden(), "DbGridControl::ColumnMoved : moved a hidden col ? how this ?"); #endif // for the new model pos we can't use GetModelColumnPos because we are altering the model at the moment // so the method won't work (in fact it would return the old model pos) // the new view pos is calculated easily sal_uInt16 nNewViewPos = GetViewColumnPos(nId); // from that we can compute the new model pos sal_uInt16 nNewModelPos; for (nNewModelPos = 0; nNewModelPos < m_aColumns.size(); ++nNewModelPos) { if (!m_aColumns[ nNewModelPos ]->IsHidden()) { if (!nNewViewPos) break; else --nNewViewPos; } } DBG_ASSERT( nNewModelPos < m_aColumns.size(), "DbGridControl::ColumnMoved : could not find the new model position !"); // this will work. of course the model isn't fully consistent with our view right now, but let's // look at the situation : a column has been moved with in the VIEW from pos m to n, say m