From aa7e7747f4296b3b92379c3c7703b80ad8af6a8b Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 25 Sep 2019 14:15:38 +0100 Subject: weld DataEditor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I8b59140d2e2b0892f17159282a1aeb1a47008ba0 Reviewed-on: https://gerrit.libreoffice.org/79561 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- chart2/source/controller/dialogs/DataBrowser.cxx | 295 ++++++++++++--------- chart2/source/controller/dialogs/DataBrowser.hxx | 14 +- .../source/controller/dialogs/dlg_DataEditor.cxx | 162 ++++------- chart2/source/controller/inc/dlg_DataEditor.hxx | 62 ++--- .../controller/main/ChartController_EditData.cxx | 7 +- 5 files changed, 252 insertions(+), 288 deletions(-) (limited to 'chart2/source') diff --git a/chart2/source/controller/dialogs/DataBrowser.cxx b/chart2/source/controller/dialogs/DataBrowser.cxx index a698262eb61f..7252684f8109 100644 --- a/chart2/source/controller/dialogs/DataBrowser.cxx +++ b/chart2/source/controller/dialogs/DataBrowser.cxx @@ -37,13 +37,14 @@ #include #include #include +#include #include #include +#include #include #include #include - #include #include @@ -90,27 +91,60 @@ namespace chart namespace impl { -class SeriesHeaderEdit : public Edit +class SeriesHeaderEdit { public: - explicit SeriesHeaderEdit( vcl::Window * pParent ); - virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; + explicit SeriesHeaderEdit(std::unique_ptr xControl); void setStartColumn( sal_Int32 nStartColumn ); sal_Int32 getStartColumn() const { return m_nStartColumn;} void SetShowWarningBox( bool bShowWarning ); + OUString GetText() const { return m_xControl->get_text(); } + void SetText(const OUString& rText) { m_xControl->set_text(rText); } + + bool HasFocus() const { return m_xControl->has_focus(); } + + void Hide() { m_xControl->hide(); } + void Show() { m_xControl->show(); } + + void set_size_request(int nWidth, int nHeight) { m_xControl->set_size_request(nWidth, nHeight); } + void set_margin_left(int nLeft) { m_xControl->set_margin_left(nLeft); } + + void SetModifyHdl(const Link& rLink) { m_aModifyHdl = rLink; } + void SetGetFocusHdl(const Link& rLink) { m_aFocusInHdl = rLink; } + private: + DECL_LINK(NameEdited, weld::Entry&, void); + DECL_LINK(NameFocusIn, weld::Widget&, void); + DECL_LINK(MousePressHdl, const MouseEvent&, bool); + + std::unique_ptr m_xControl; + Link m_aModifyHdl; + Link m_aFocusInHdl; sal_Int32 m_nStartColumn; bool m_bShowWarningBox; }; -SeriesHeaderEdit::SeriesHeaderEdit( vcl::Window * pParent ) : - Edit( pParent ), - m_nStartColumn( 0 ), - m_bShowWarningBox( false ) +SeriesHeaderEdit::SeriesHeaderEdit(std::unique_ptr xControl) + : m_xControl(std::move(xControl)) + , m_nStartColumn(0) + , m_bShowWarningBox(false) +{ + m_xControl->set_help_id(HID_SCH_DATA_SERIES_LABEL); + m_xControl->connect_changed(LINK(this, SeriesHeaderEdit, NameEdited)); + m_xControl->connect_focus_in(LINK(this, SeriesHeaderEdit, NameFocusIn)); + m_xControl->connect_mouse_press(LINK(this, SeriesHeaderEdit, MousePressHdl)); +} + +IMPL_LINK_NOARG(SeriesHeaderEdit, NameEdited, weld::Entry&, void) +{ + m_aModifyHdl.Call(*this); +} + +IMPL_LINK_NOARG(SeriesHeaderEdit, NameFocusIn, weld::Widget&, void) { - SetHelpId(HID_SCH_DATA_SERIES_LABEL); + m_aFocusInHdl.Call(*this); } void SeriesHeaderEdit::setStartColumn( sal_Int32 nStartColumn ) @@ -123,27 +157,27 @@ void SeriesHeaderEdit::SetShowWarningBox( bool bShowWarning ) m_bShowWarningBox = bShowWarning; } -void SeriesHeaderEdit::MouseButtonDown( const MouseEvent& rMEvt ) +IMPL_LINK_NOARG(SeriesHeaderEdit, MousePressHdl, const MouseEvent&, bool) { - Edit::MouseButtonDown( rMEvt ); - - if( m_bShowWarningBox ) + if (m_bShowWarningBox) { - std::unique_ptr xWarn(Application::CreateMessageDialog(GetFrameWeld(), + std::unique_ptr xWarn(Application::CreateMessageDialog(m_xControl.get(), VclMessageType::Warning, VclButtonsType::Ok, SchResId(STR_INVALID_NUMBER))); xWarn->run(); } + + return false; } class SeriesHeader { public: - explicit SeriesHeader(vcl::Window * pParent, vcl::Window *pColorParent); + explicit SeriesHeader(weld::Container* pParent, weld::Container* pColorParent); ~SeriesHeader(); void SetColor( const Color & rCol ); - void SetPos( const Point & rPos ); + void SetPos(); void SetWidth( sal_Int32 nWidth ); void SetChartType( const Reference< chart2::XChartType > & xChartType, bool bSwapXAndYAxis ); @@ -168,61 +202,75 @@ public: */ void applyChanges(); - void SetGetFocusHdl( const Link& rLink ); + void SetGetFocusHdl(const Link& rLink); - void SetEditChangedHdl( const Link & rLink ); + void SetEditChangedHdl( const Link & rLink ); bool HasFocus() const; private: - VclPtr< FixedImage > m_spSymbol; - VclPtr< SeriesHeaderEdit > m_spSeriesName; - VclPtr< FixedText > m_spColorBar; - VclPtr< OutputDevice> m_pDevice; - Link m_aChangeLink; + Timer m_aUpdateDataTimer; + + std::unique_ptr m_xBuilder1; + std::unique_ptr m_xBuilder2; + + std::unique_ptr m_xContainer1; + std::unique_ptr m_xContainer2; + std::unique_ptr m_spSymbol; + std::unique_ptr m_spSeriesName; + std::unique_ptr m_spColorBar; + VclPtr< OutputDevice> m_xDevice; + Link m_aChangeLink; + Color m_aColor; void notifyChanges(); - DECL_LINK( SeriesNameChanged, Edit&, void ); - DECL_LINK( SeriesNameEdited, Edit&, void ); + DECL_LINK( ImplUpdateDataHdl, Timer*, void ); + DECL_LINK( SeriesNameEdited, SeriesHeaderEdit&, void ); - static Image GetChartTypeImage( + static OUString GetChartTypeImage( const Reference< chart2::XChartType > & xChartType, bool bSwapXAndYAxis ); sal_Int32 m_nStartCol, m_nEndCol; sal_Int32 m_nWidth; - Point m_aPos; bool m_bSeriesNameChangePending; }; -SeriesHeader::SeriesHeader( vcl::Window * pParent, vcl::Window *pColorParent ) : - m_spSymbol( VclPtr::Create( pParent, WB_NOBORDER )), - m_spSeriesName( VclPtr::Create( pParent )), - m_spColorBar( VclPtr::Create( pColorParent, WB_NOBORDER )), - m_pDevice( pParent ), - m_nStartCol( 0 ), - m_nEndCol( 0 ), - m_nWidth( 42 ), - m_aPos( 0, 22 ), - m_bSeriesNameChangePending( false ) -{ - m_spSeriesName->EnableUpdateData( 4 * EDIT_UPDATEDATA_TIMEOUT ); // define is in vcl/edit.hxx - m_spSeriesName->SetUpdateDataHdl( LINK( this, SeriesHeader, SeriesNameChanged )); - m_spSeriesName->SetModifyHdl( LINK( this, SeriesHeader, SeriesNameEdited )); +SeriesHeader::SeriesHeader(weld::Container* pParent, weld::Container* pColorParent) + : m_aUpdateDataTimer("UpdateDataTimer") + , m_xBuilder1(Application::CreateBuilder(pParent, "modules/schart/ui/columnfragment.ui")) + , m_xBuilder2(Application::CreateBuilder(pColorParent, "modules/schart/ui/imagefragment.ui")) + , m_xContainer1(m_xBuilder1->weld_container("container")) + , m_xContainer2(m_xBuilder2->weld_container("container")) + , m_spSymbol(m_xBuilder1->weld_image("image")) + , m_spSeriesName(new SeriesHeaderEdit(m_xBuilder1->weld_entry("entry"))) + , m_spColorBar(m_xBuilder2->weld_image("image")) + , m_xDevice(Application::GetDefaultDevice()) + , m_nStartCol( 0 ) + , m_nEndCol( 0 ) + , m_nWidth( 42 ) + , m_bSeriesNameChangePending( false ) +{ + m_aUpdateDataTimer.SetInvokeHandler(LINK(this, SeriesHeader, ImplUpdateDataHdl)); + m_aUpdateDataTimer.SetDebugName( "SeriesHeader UpdateDataTimer" ); + m_aUpdateDataTimer.SetTimeout(4 * EDIT_UPDATEDATA_TIMEOUT); + + m_spSeriesName->SetModifyHdl(LINK(this, SeriesHeader, SeriesNameEdited)); Show(); } SeriesHeader::~SeriesHeader() { - m_spSymbol.disposeAndClear(); - m_spSeriesName.disposeAndClear(); - m_spColorBar.disposeAndClear(); + m_aUpdateDataTimer.Stop(); + m_xDevice.clear(); + m_xBuilder2.reset(); + m_xBuilder1.reset(); } void SeriesHeader::notifyChanges() { - m_aChangeLink.Call( m_spSeriesName.get()); + m_aChangeLink.Call(*m_spSeriesName); m_bSeriesNameChangePending = false; } @@ -236,51 +284,53 @@ void SeriesHeader::applyChanges() void SeriesHeader::SetColor( const Color & rCol ) { - m_spColorBar->SetControlBackground( rCol ); + m_aColor = rCol; } -void SeriesHeader::SetPos( const Point & rPos ) +void SeriesHeader::SetPos() { - m_aPos = rPos; - // chart type symbol Size aSize( nSymbolHeight, nSymbolHeight ); - aSize = m_pDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); - m_spSymbol->set_width_request(aSize.Width()); - m_spSymbol->set_height_request(aSize.Height()); + aSize = m_xDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); + m_spSymbol->set_size_request(aSize.Width(), aSize.Height()); // series name edit field aSize.setWidth(nSymbolDistance); - aSize = m_pDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); + aSize = m_xDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); m_spSeriesName->set_margin_left(aSize.Width() + 2); aSize.setWidth( m_nWidth - nSymbolHeight - nSymbolDistance ); sal_Int32 nHeight = 12; aSize.setHeight( nHeight ); - aSize = m_pDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); - m_spSeriesName->set_width_request(aSize.Width()); - m_spSeriesName->set_height_request(aSize.Height()); + aSize = m_xDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); + m_spSeriesName->set_size_request(aSize.Width(), aSize.Height()); // color bar aSize.setWidth(1); - aSize = m_pDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); + aSize = m_xDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); m_spColorBar->set_margin_left(aSize.Width() + 2); nHeight = 3; aSize.setWidth( m_nWidth - 1 ); aSize.setHeight( nHeight ); - aSize = m_pDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); - m_spColorBar->set_width_request(aSize.Width()); - m_spColorBar->set_height_request(aSize.Height()); + aSize = m_xDevice->LogicToPixel(aSize, MapMode(MapUnit::MapAppFont)); + m_spColorBar->set_size_request(aSize.Width(), aSize.Height()); + + auto xVirDev(m_spColorBar->create_virtual_device()); + xVirDev->SetOutputSizePixel(aSize); + xVirDev->SetFillColor(m_aColor); + xVirDev->SetLineColor(m_aColor); + xVirDev->DrawRect(tools::Rectangle(Point(0, 0), aSize)); + m_spColorBar->set_image(xVirDev.get()); } void SeriesHeader::SetWidth( sal_Int32 nWidth ) { m_nWidth = nWidth; - SetPos( m_aPos ); + SetPos(); } void SeriesHeader::SetPixelWidth( sal_Int32 nWidth ) { - SetWidth( m_pDevice->PixelToLogic(Size(nWidth, 0), MapMode(MapUnit::MapAppFont)).getWidth()); + SetWidth( m_xDevice->PixelToLogic(Size(nWidth, 0), MapMode(MapUnit::MapAppFont)).getWidth()); } void SeriesHeader::SetChartType( @@ -288,12 +338,12 @@ void SeriesHeader::SetChartType( bool bSwapXAndYAxis ) { - m_spSymbol->SetImage( GetChartTypeImage( xChartType, bSwapXAndYAxis ) ); + m_spSymbol->set_from_icon_name( GetChartTypeImage( xChartType, bSwapXAndYAxis ) ); } void SeriesHeader::SetSeriesName( const OUString & rName ) { - m_spSeriesName->SetText( rName ); + m_spSeriesName->SetText(rName); } void SeriesHeader::SetRange( sal_Int32 nStartCol, sal_Int32 nEndCol ) @@ -305,34 +355,35 @@ void SeriesHeader::SetRange( sal_Int32 nStartCol, sal_Int32 nEndCol ) void SeriesHeader::Show() { - m_spSymbol->Show(); + m_spSymbol->show(); m_spSeriesName->Show(); - m_spColorBar->Show(); + m_spColorBar->show(); } void SeriesHeader::Hide() { - m_spSymbol->Hide(); + m_spSymbol->hide(); m_spSeriesName->Hide(); - m_spColorBar->Hide(); + m_spColorBar->hide(); } -void SeriesHeader::SetEditChangedHdl( const Link & rLink ) +void SeriesHeader::SetEditChangedHdl( const Link & rLink ) { m_aChangeLink = rLink; } -IMPL_LINK_NOARG(SeriesHeader, SeriesNameChanged, Edit&, void) +IMPL_LINK_NOARG(SeriesHeader, ImplUpdateDataHdl, Timer*, void) { notifyChanges(); } -IMPL_LINK_NOARG(SeriesHeader, SeriesNameEdited, Edit&, void) +IMPL_LINK_NOARG(SeriesHeader, SeriesNameEdited, SeriesHeaderEdit&, void) { m_bSeriesNameChangePending = true; + m_aUpdateDataTimer.Start(); } -void SeriesHeader::SetGetFocusHdl( const Link& rLink ) +void SeriesHeader::SetGetFocusHdl( const Link& rLink ) { m_spSeriesName->SetGetFocusHdl( rLink ); } @@ -342,52 +393,52 @@ bool SeriesHeader::HasFocus() const return m_spSeriesName->HasFocus(); } -Image SeriesHeader::GetChartTypeImage( +OUString SeriesHeader::GetChartTypeImage( const Reference< chart2::XChartType > & xChartType, bool bSwapXAndYAxis ) { - Image aResult; + OUString aResult; if( !xChartType.is()) return aResult; OUString aChartTypeName( xChartType->getChartType()); if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_AREA ) { - aResult = Image(StockImage::Yes, BMP_TYPE_AREA); + aResult = BMP_TYPE_AREA; } else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ) { if( bSwapXAndYAxis ) - aResult = Image(StockImage::Yes, BMP_TYPE_BAR); + aResult = BMP_TYPE_BAR; else - aResult = Image(StockImage::Yes, BMP_TYPE_COLUMN); + aResult = BMP_TYPE_COLUMN; } else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_LINE ) { - aResult = Image(StockImage::Yes, BMP_TYPE_LINE); + aResult = BMP_TYPE_LINE; } else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_SCATTER ) { - aResult = Image(StockImage::Yes, BMP_TYPE_XY); + aResult = BMP_TYPE_XY; } else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_PIE ) { - aResult = Image(StockImage::Yes, BMP_TYPE_PIE); + aResult = BMP_TYPE_PIE; } else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_NET || aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET ) { - aResult = Image(StockImage::Yes, BMP_TYPE_NET); + aResult = BMP_TYPE_NET; } else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK ) { // @todo: correct image for candle-stick type - aResult = Image(StockImage::Yes, BMP_TYPE_STOCK); + aResult = BMP_TYPE_STOCK; } else if( aChartTypeName == CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE ) { - aResult = Image(StockImage::Yes, BMP_TYPE_BUBBLE); + aResult = BMP_TYPE_BUBBLE; } return aResult; @@ -437,14 +488,19 @@ sal_Int32 lcl_getColumnInDataOrHeader( } // anonymous namespace -DataBrowser::DataBrowser( vcl::Window* pParent, WinBits nStyle, bool bLiveUpdate ) : - ::svt::EditBrowseBox( pParent, EditBrowseBoxFlags::SMART_TAB_TRAVEL | EditBrowseBoxFlags::HANDLE_COLUMN_TEXT, nStyle, BrowserStdFlags ), +DataBrowser::DataBrowser(const css::uno::Reference &rParent, + weld::Container* pColumns, weld::Container* pColors) : + ::svt::EditBrowseBox(VCLUnoHelper::GetWindow(rParent), + EditBrowseBoxFlags::SMART_TAB_TRAVEL | EditBrowseBoxFlags::HANDLE_COLUMN_TEXT, + WB_BORDER | WB_TABSTOP, BrowserStdFlags ), m_nSeekRow( 0 ), m_bIsReadOnly( false ), - m_bLiveUpdate( bLiveUpdate ), + m_bLiveUpdate( true ), m_bDataValid( true ), m_aNumberEditField( VclPtr::Create( & EditBrowseBox::GetDataWindow(), WB_NOBORDER ) ), m_aTextEditField( VclPtr::Create( & EditBrowseBox::GetDataWindow(), WB_NOBORDER ) ), + m_pColumnsWin(pColumns), + m_pColorsWin(pColors), m_rNumberEditController( new ::svt::FormattedFieldCellController( m_aNumberEditField.get() )), m_rTextEditController( new ::svt::EditCellController( m_aTextEditField.get() )) { @@ -580,7 +636,7 @@ void DataBrowser::RenewTable() OUString aDefaultSeriesName(SchResId(STR_COLUMN_LABEL)); replaceParamterInString( aDefaultSeriesName, "%COLUMNNUMBER", OUString::number( 24 ) ); sal_Int32 nColumnWidth = GetDataWindow().GetTextWidth( aDefaultSeriesName ) - + GetDataWindow().LogicToPixel(Point(4 + impl::SeriesHeader::GetRelativeAppFontXPosForNameField(), 0), MapMode(MapUnit::MapAppFont)).X(); + + GetDataWindow().LogicToPixel(Point(8 + impl::SeriesHeader::GetRelativeAppFontXPosForNameField(), 0), MapMode(MapUnit::MapAppFont)).X(); sal_Int32 nColumnCount = m_apDataBrowserModel->getColumnCount(); // nRowCount is a member of a base class sal_Int32 nRowCountLocal = m_apDataBrowserModel->getMaxRowCount(); @@ -593,19 +649,15 @@ void DataBrowser::RenewTable() GoToRow( std::min( nOldRow, GetRowCount() - 1 )); GoToColumnId( std::min( nOldColId, static_cast< sal_uInt16 >( ColCount() - 1 ))); - Dialog* pDialog = GetParentDialog(); - vcl::Window* pWin = pDialog->get("columns"); - vcl::Window* pColorWin = pDialog->get("colorcolumns"); - // fill series headers clearHeaders(); const DataBrowserModel::tDataHeaderVector& aHeaders( m_apDataBrowserModel->getDataHeaders()); - Link aFocusLink( LINK( this, DataBrowser, SeriesHeaderGotFocus )); - Link aSeriesHeaderChangedLink( LINK( this, DataBrowser, SeriesHeaderChanged )); + Link aFocusLink( LINK( this, DataBrowser, SeriesHeaderGotFocus )); + Link aSeriesHeaderChangedLink( LINK( this, DataBrowser, SeriesHeaderChanged )); for (auto const& elemHeader : aHeaders) { - std::shared_ptr< impl::SeriesHeader > spHeader( new impl::SeriesHeader( pWin, pColorWin )); + std::shared_ptr< impl::SeriesHeader > spHeader( new impl::SeriesHeader( m_pColumnsWin, m_pColorsWin )); Reference< beans::XPropertySet > xSeriesProp( elemHeader.m_xDataSeries, uno::UNO_QUERY ); sal_Int32 nColor = 0; // @todo: Set "DraftColor", i.e. interpolated colors for gradients, bitmaps, etc. @@ -1242,18 +1294,14 @@ void DataBrowser::EndScroll() void DataBrowser::RenewSeriesHeaders() { - Dialog* pDialog = GetParentDialog(); - vcl::Window* pWin = pDialog->get("columns"); - vcl::Window* pColorWin = pDialog->get("colorcolumns"); - clearHeaders(); DataBrowserModel::tDataHeaderVector aHeaders( m_apDataBrowserModel->getDataHeaders()); - Link aFocusLink( LINK( this, DataBrowser, SeriesHeaderGotFocus )); - Link aSeriesHeaderChangedLink( LINK( this, DataBrowser, SeriesHeaderChanged )); + Link aFocusLink( LINK( this, DataBrowser, SeriesHeaderGotFocus )); + Link aSeriesHeaderChangedLink( LINK( this, DataBrowser, SeriesHeaderChanged )); for (auto const& elemHeader : aHeaders) { - std::shared_ptr< impl::SeriesHeader > spHeader( new impl::SeriesHeader( pWin, pColorWin )); + std::shared_ptr< impl::SeriesHeader > spHeader( new impl::SeriesHeader( m_pColumnsWin, m_pColorsWin )); Reference< beans::XPropertySet > xSeriesProp(elemHeader.m_xDataSeries, uno::UNO_QUERY); sal_Int32 nColor = 0; if( xSeriesProp.is() && @@ -1285,9 +1333,8 @@ void DataBrowser::ImplAdjustHeaderControls() // width of header column nCurrentPos += GetColumnWidth( 0 ); - Dialog* pDialog = GetParentDialog(); - vcl::Window* pWin = pDialog->get("columns"); - vcl::Window* pColorWin = pDialog->get("colorcolumns"); + weld::Container* pWin = m_pColumnsWin; + weld::Container* pColorWin = m_pColorsWin; pWin->set_margin_left(nCurrentPos); pColorWin->set_margin_left(nCurrentPos); @@ -1327,43 +1374,39 @@ void DataBrowser::ImplAdjustHeaderControls() } } -IMPL_LINK( DataBrowser, SeriesHeaderGotFocus, Control&, rControl, void ) +IMPL_LINK( DataBrowser, SeriesHeaderGotFocus, impl::SeriesHeaderEdit&, rEdit, void ) { - impl::SeriesHeaderEdit* pEdit = static_cast(&rControl); - pEdit->SetShowWarningBox( !m_bDataValid ); + rEdit.SetShowWarningBox( !m_bDataValid ); if( !m_bDataValid ) GoToCell( 0, 0 ); else { - MakeFieldVisible( GetCurRow(), static_cast< sal_uInt16 >( pEdit->getStartColumn()) ); + MakeFieldVisible( GetCurRow(), static_cast< sal_uInt16 >( rEdit.getStartColumn()) ); ActivateCell(); m_aCursorMovedHdlLink.Call( this ); } } -IMPL_LINK( DataBrowser, SeriesHeaderChanged, impl::SeriesHeaderEdit*, pEdit, void ) +IMPL_LINK( DataBrowser, SeriesHeaderChanged, impl::SeriesHeaderEdit&, rEdit, void ) { - if( pEdit ) + Reference< chart2::XDataSeries > xSeries( + m_apDataBrowserModel->getDataSeriesByColumn( rEdit.getStartColumn() - 1 )); + Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY ); + if( xSource.is()) { - Reference< chart2::XDataSeries > xSeries( - m_apDataBrowserModel->getDataSeriesByColumn( pEdit->getStartColumn() - 1 )); - Reference< chart2::data::XDataSource > xSource( xSeries, uno::UNO_QUERY ); - if( xSource.is()) + Reference< chart2::XChartType > xChartType( + m_apDataBrowserModel->getHeaderForSeries( xSeries ).m_xChartType ); + if( xChartType.is()) { - Reference< chart2::XChartType > xChartType( - m_apDataBrowserModel->getHeaderForSeries( xSeries ).m_xChartType ); - if( xChartType.is()) + Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( + DataSeriesHelper::getDataSequenceByRole( xSource, xChartType->getRoleOfSequenceForSeriesLabel())); + if( xLabeledSeq.is()) { - Reference< chart2::data::XLabeledDataSequence > xLabeledSeq( - DataSeriesHelper::getDataSequenceByRole( xSource, xChartType->getRoleOfSequenceForSeriesLabel())); - if( xLabeledSeq.is()) - { - Reference< container::XIndexReplace > xIndexReplace( xLabeledSeq->getLabel(), uno::UNO_QUERY ); - if( xIndexReplace.is()) - xIndexReplace->replaceByIndex( - 0, uno::Any( pEdit->GetText())); - } + Reference< container::XIndexReplace > xIndexReplace( xLabeledSeq->getLabel(), uno::UNO_QUERY ); + if( xIndexReplace.is()) + xIndexReplace->replaceByIndex( + 0, uno::Any( rEdit.GetText())); } } } diff --git a/chart2/source/controller/dialogs/DataBrowser.hxx b/chart2/source/controller/dialogs/DataBrowser.hxx index ad359ce769cf..db41c117f688 100644 --- a/chart2/source/controller/dialogs/DataBrowser.hxx +++ b/chart2/source/controller/dialogs/DataBrowser.hxx @@ -22,11 +22,15 @@ #include #include +#include #include #include namespace com { namespace sun { namespace star { + namespace awt { + class XWindow; + } namespace chart2 { class XChartDocument; } @@ -66,7 +70,9 @@ protected: virtual void MouseButtonDown( const BrowserMouseEvent& rEvt ) override; public: - DataBrowser( vcl::Window* pParent, WinBits nStyle, bool bLiveUpdate ); + DataBrowser(const css::uno::Reference &rParent, + weld::Container* pColumns, weld::Container* pColors); + virtual ~DataBrowser() override; virtual void dispose() override; @@ -157,6 +163,8 @@ private: VclPtr m_aNumberEditField; VclPtr m_aTextEditField; + weld::Container* m_pColumnsWin; + weld::Container* m_pColorsWin; /// note: m_aNumberEditField must precede this member! ::svt::CellControllerRef m_rNumberEditController; @@ -171,8 +179,8 @@ private: OUString GetColString( sal_Int32 nColumnId ) const; - DECL_LINK( SeriesHeaderGotFocus, Control&, void ); - DECL_LINK( SeriesHeaderChanged, impl::SeriesHeaderEdit*, void ); + DECL_LINK( SeriesHeaderGotFocus, impl::SeriesHeaderEdit&, void ); + DECL_LINK( SeriesHeaderChanged, impl::SeriesHeaderEdit&, void ); DataBrowser( const DataBrowser & ) = delete; }; diff --git a/chart2/source/controller/dialogs/dlg_DataEditor.cxx b/chart2/source/controller/dialogs/dlg_DataEditor.cxx index cc65860c3746..03f78205da25 100644 --- a/chart2/source/controller/dialogs/dlg_DataEditor.cxx +++ b/chart2/source/controller/dialogs/dlg_DataEditor.cxx @@ -25,6 +25,7 @@ #include #include +#include #include using namespace ::com::sun::star; @@ -33,100 +34,70 @@ using ::com::sun::star::uno::Reference; namespace chart { -DataEditor::DataEditor(vcl::Window* pParent, +DataEditor::DataEditor(weld::Window* pParent, const Reference< chart2::XChartDocument > & xChartDoc, const Reference< uno::XComponentContext > & xContext) - : ModalDialog(pParent, "ChartDataDialog", - "modules/schart/ui/chartdatadialog.ui") + : GenericDialogController(pParent, "modules/schart/ui/chartdatadialog.ui", "ChartDataDialog") , m_bReadOnly(false) , m_xChartDoc(xChartDoc) , m_xContext(xContext) + , m_xTbxData(m_xBuilder->weld_toolbar("toolbar")) + , m_xCloseBtn(m_xBuilder->weld_button("close")) + , m_xTable(m_xBuilder->weld_container("datawindow")) + , m_xColumns(m_xBuilder->weld_container("columns")) + , m_xColors(m_xBuilder->weld_container("colorcolumns")) + , m_xTableCtrlParent(m_xTable->CreateChildFrame()) + , m_xBrwData(VclPtr::Create(m_xTableCtrlParent, m_xColumns.get(), m_xColors.get())) { - m_xBrwData.reset(VclPtr::Create(get("datawindow"), WB_BORDER | WB_TABSTOP, true /* bLiveUpdate */)); - m_xBrwData->set_hexpand(true); - m_xBrwData->set_vexpand(true); - m_xBrwData->set_expand(true); - Size aSize(m_xBrwData->LogicToPixel(Size(232, 121), MapMode(MapUnit::MapAppFont))); - m_xBrwData->set_width_request(aSize.Width()); - m_xBrwData->set_height_request(aSize.Height()); - m_xBrwData->Show(); + m_xCloseBtn->connect_clicked(LINK(this, DataEditor, CloseHdl)); - get(m_pTbxData, "toolbar"); + Size aSize(m_xTable->get_approximate_digit_width() * 75, m_xTable->get_text_height() * 15); + m_xTable->set_size_request(aSize.Width(), aSize.Height()); - TBI_DATA_INSERT_ROW = m_pTbxData->GetItemId("InsertRow"); - TBI_DATA_INSERT_COL = m_pTbxData->GetItemId("InsertColumn"); - TBI_DATA_INSERT_TEXT_COL = m_pTbxData->GetItemId("InsertTextColumn"); - TBI_DATA_DELETE_ROW = m_pTbxData->GetItemId("RemoveRow"); - TBI_DATA_DELETE_COL = m_pTbxData->GetItemId("RemoveColumn"); - TBI_DATA_MOVE_LEFT_COL = m_pTbxData->GetItemId("MoveLeftColumn"); - TBI_DATA_MOVE_RIGHT_COL = m_pTbxData->GetItemId("MoveRightColumn"); - TBI_DATA_MOVE_UP_ROW = m_pTbxData->GetItemId("MoveUpRow"); - TBI_DATA_MOVE_DOWN_ROW = m_pTbxData->GetItemId("MoveDownRow"); + m_xBrwData->Show(); - m_pTbxData->SetSelectHdl( LINK( this, DataEditor, ToolboxHdl )); + m_xTbxData->connect_clicked(LINK(this, DataEditor, ToolboxHdl)); m_xBrwData->SetCursorMovedHdl( LINK( this, DataEditor, BrowserCursorMovedHdl )); m_xBrwData->SetDataFromModel( m_xChartDoc, m_xContext ); - GrabFocus(); - m_xBrwData->GrabFocus(); +// m_xDialog->grab_focus(); +// m_xBrwData->GrabFocus(); bool bReadOnly = true; Reference< frame::XStorable > xStor( m_xChartDoc, uno::UNO_QUERY ); if( xStor.is()) bReadOnly = xStor->isReadonly(); SetReadOnly( bReadOnly ); - - // change buttons to flat-look if set so by user - SvtMiscOptions aMiscOptions; - const sal_Int16 nStyle( aMiscOptions.GetToolboxStyle() ); - // react on changes - aMiscOptions.AddListenerLink( LINK( this, DataEditor, MiscHdl ) ); - m_pTbxData->SetOutStyle( nStyle ); - - // allow travelling to toolbar with F6 - notifySystemWindow( this, m_pTbxData, ::comphelper::mem_fun( & TaskPaneList::AddWindow )); } DataEditor::~DataEditor() { - disposeOnce(); -} - -void DataEditor::dispose() -{ - notifySystemWindow( this, m_pTbxData, ::comphelper::mem_fun( & TaskPaneList::RemoveWindow )); - - SvtMiscOptions aMiscOptions; - aMiscOptions.RemoveListenerLink( LINK( this, DataEditor, MiscHdl ) ); - - m_pTbxData.clear(); m_xBrwData.disposeAndClear(); - ModalDialog::dispose(); + m_xTableCtrlParent->dispose(); + m_xTableCtrlParent.clear(); } // react on click (or keypress) on toolbar icon -IMPL_LINK_NOARG(DataEditor, ToolboxHdl, ToolBox *, void) +IMPL_LINK(DataEditor, ToolboxHdl, const OString&, rId, void) { - sal_uInt16 nId = m_pTbxData->GetCurItemId(); - - if (nId == TBI_DATA_INSERT_ROW) + if (rId == "InsertRow") m_xBrwData->InsertRow(); - else if (nId == TBI_DATA_INSERT_COL) + else if (rId == "InsertColumn") m_xBrwData->InsertColumn(); - else if (nId == TBI_DATA_INSERT_TEXT_COL) + else if (rId == "InsertTextColumn") m_xBrwData->InsertTextColumn(); - else if (nId == TBI_DATA_DELETE_ROW) + else if (rId == "RemoveRow") m_xBrwData->RemoveRow(); - else if (nId == TBI_DATA_DELETE_COL) + else if (rId == "RemoveColumn") m_xBrwData->RemoveColumn(); - else if (nId == TBI_DATA_MOVE_LEFT_COL) + else if (rId == "MoveLeftColumn") m_xBrwData->MoveLeftColumn(); - else if (nId == TBI_DATA_MOVE_RIGHT_COL) + else if (rId == "MoveRightColumn") m_xBrwData->MoveRightColumn(); - else if (nId == TBI_DATA_MOVE_UP_ROW) + else if (rId == "MoveUpRow") m_xBrwData->MoveUpRow(); - else if (nId == TBI_DATA_MOVE_DOWN_ROW) + else if (rId == "MoveDownRow") m_xBrwData->MoveDownRow(); } @@ -138,16 +109,16 @@ IMPL_LINK_NOARG(DataEditor, BrowserCursorMovedHdl, DataBrowser*, void) bool bIsDataValid = m_xBrwData->IsEnableItem(); - m_pTbxData->EnableItem( TBI_DATA_INSERT_ROW, bIsDataValid && m_xBrwData->MayInsertRow() ); - m_pTbxData->EnableItem( TBI_DATA_INSERT_COL, bIsDataValid && m_xBrwData->MayInsertColumn() ); - m_pTbxData->EnableItem( TBI_DATA_INSERT_TEXT_COL, bIsDataValid && m_xBrwData->MayInsertColumn() ); - m_pTbxData->EnableItem( TBI_DATA_DELETE_ROW, m_xBrwData->MayDeleteRow() ); - m_pTbxData->EnableItem( TBI_DATA_DELETE_COL, m_xBrwData->MayDeleteColumn() ); + m_xTbxData->set_item_sensitive("InsertRow", bIsDataValid && m_xBrwData->MayInsertRow() ); + m_xTbxData->set_item_sensitive("InsertColumn", bIsDataValid && m_xBrwData->MayInsertColumn() ); + m_xTbxData->set_item_sensitive("InsertTextColumn", bIsDataValid && m_xBrwData->MayInsertColumn() ); + m_xTbxData->set_item_sensitive("RemoveRow", m_xBrwData->MayDeleteRow() ); + m_xTbxData->set_item_sensitive("RemoveColumn", m_xBrwData->MayDeleteColumn() ); - m_pTbxData->EnableItem( TBI_DATA_MOVE_LEFT_COL, bIsDataValid && m_xBrwData->MayMoveLeftColumns() ); - m_pTbxData->EnableItem( TBI_DATA_MOVE_RIGHT_COL, bIsDataValid && m_xBrwData->MayMoveRightColumns() ); - m_pTbxData->EnableItem( TBI_DATA_MOVE_DOWN_ROW, bIsDataValid && m_xBrwData->MayMoveDownRows() ); - m_pTbxData->EnableItem( TBI_DATA_MOVE_UP_ROW, bIsDataValid && m_xBrwData->MayMoveUpRows() ); + m_xTbxData->set_item_sensitive("MoveLeftColumn", bIsDataValid && m_xBrwData->MayMoveLeftColumns() ); + m_xTbxData->set_item_sensitive("MoveRightColumn", bIsDataValid && m_xBrwData->MayMoveRightColumns() ); + m_xTbxData->set_item_sensitive("MoveUpRow", bIsDataValid && m_xBrwData->MayMoveDownRows() ); + m_xTbxData->set_item_sensitive("MoveDownRow", bIsDataValid && m_xBrwData->MayMoveUpRows() ); } // disable all modifying controls @@ -156,34 +127,25 @@ void DataEditor::SetReadOnly( bool bReadOnly ) m_bReadOnly = bReadOnly; if( m_bReadOnly ) { - m_pTbxData->EnableItem( TBI_DATA_INSERT_ROW, false ); - m_pTbxData->EnableItem( TBI_DATA_INSERT_COL, false ); - m_pTbxData->EnableItem( TBI_DATA_INSERT_TEXT_COL, false ); - m_pTbxData->EnableItem( TBI_DATA_DELETE_ROW, false ); - m_pTbxData->EnableItem( TBI_DATA_DELETE_COL, false ); - m_pTbxData->EnableItem( TBI_DATA_MOVE_LEFT_COL, false ); - m_pTbxData->EnableItem( TBI_DATA_MOVE_RIGHT_COL, false ); - m_pTbxData->EnableItem( TBI_DATA_MOVE_UP_ROW, false ); - m_pTbxData->EnableItem( TBI_DATA_MOVE_DOWN_ROW, false ); + m_xTbxData->set_item_sensitive("InsertRow", false); + m_xTbxData->set_item_sensitive("InsertColumn", false); + m_xTbxData->set_item_sensitive("InsertTextColumn", false); + m_xTbxData->set_item_sensitive("RemoveRow", false); + m_xTbxData->set_item_sensitive("RemoveColumn", false); + m_xTbxData->set_item_sensitive("MoveLeftColumn", false); + m_xTbxData->set_item_sensitive("MoveRightColumn", false); + m_xTbxData->set_item_sensitive("MoveUpRow", false); + m_xTbxData->set_item_sensitive("MoveDownRow", false); } m_xBrwData->SetReadOnly( m_bReadOnly ); } -IMPL_LINK_NOARG(DataEditor, MiscHdl, LinkParamNone*, void) -{ - SvtMiscOptions aMiscOptions; - sal_Int16 nStyle( aMiscOptions.GetToolboxStyle() ); - - m_pTbxData->SetOutStyle( nStyle ); -} - -bool DataEditor::Close() +IMPL_LINK_NOARG(DataEditor, CloseHdl, weld::Button&, void) { - if( ApplyChangesToModel() ) - return ModalDialog::Close(); - else - return true; + bool bApplied = ApplyChangesToModel(); + if (bApplied) + m_xDialog->response(RET_CLOSE); } bool DataEditor::ApplyChangesToModel() @@ -191,28 +153,6 @@ bool DataEditor::ApplyChangesToModel() return m_xBrwData->EndEditing(); } -// add/remove a window (the toolbar) to/from the global list, so that F6 -// travels/no longer travels over this window. _rMemFunc may be -// TaskPaneList::AddWindow or TaskPaneList::RemoveWindow -void DataEditor::notifySystemWindow( - vcl::Window const * pWindow, vcl::Window* pToRegister, - const ::comphelper::mem_fun1_t& rMemFunc ) -{ - OSL_ENSURE( pWindow, "Window must not be null!" ); - if( !pWindow ) - return; - vcl::Window* pParent = pWindow->GetParent(); - while( pParent && ! pParent->IsSystemWindow() ) - { - pParent = pParent->GetParent(); - } - if ( pParent && pParent->IsSystemWindow()) - { - SystemWindow* pSystemWindow = static_cast< SystemWindow* >( pParent ); - rMemFunc( pSystemWindow->GetTaskPaneList(), pToRegister ); - } -} - } // namespace chart /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/controller/inc/dlg_DataEditor.hxx b/chart2/source/controller/inc/dlg_DataEditor.hxx index 18011859afc7..f4682ab43212 100644 --- a/chart2/source/controller/inc/dlg_DataEditor.hxx +++ b/chart2/source/controller/inc/dlg_DataEditor.hxx @@ -20,8 +20,7 @@ #ifndef INCLUDED_CHART2_SOURCE_CONTROLLER_INC_DLG_DATAEDITOR_HXX #define INCLUDED_CHART2_SOURCE_CONTROLLER_INC_DLG_DATAEDITOR_HXX -#include -#include +#include namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; } } } } namespace comphelper { template class mem_fun1_t; } @@ -37,62 +36,37 @@ namespace chart class DataBrowser; -class DataEditor : public ModalDialog +class DataEditor : public weld::GenericDialogController { public: - DataEditor( vcl::Window* pParent, - const css::uno::Reference< css::chart2::XChartDocument > & xChartDoc, - const css::uno::Reference< css::uno::XComponentContext > & xContext ); + DataEditor(weld::Window* pParent, + const css::uno::Reference & xChartDoc, + const css::uno::Reference & xContext); virtual ~DataEditor() override; - virtual void dispose() override; - // Dialog - virtual bool Close() override; + DECL_LINK(CloseHdl, weld::Button&, void); void SetReadOnly( bool bReadOnly ); bool ApplyChangesToModel(); private: - sal_uInt16 TBI_DATA_INSERT_ROW; - sal_uInt16 TBI_DATA_INSERT_COL; - sal_uInt16 TBI_DATA_INSERT_TEXT_COL; - sal_uInt16 TBI_DATA_DELETE_ROW; - sal_uInt16 TBI_DATA_DELETE_COL; - sal_uInt16 TBI_DATA_MOVE_LEFT_COL; - sal_uInt16 TBI_DATA_MOVE_RIGHT_COL; - sal_uInt16 TBI_DATA_MOVE_UP_ROW; - sal_uInt16 TBI_DATA_MOVE_DOWN_ROW; - bool m_bReadOnly; - VclPtr m_xBrwData; - VclPtr m_pTbxData; - css::uno::Reference< css::chart2::XChartDocument > m_xChartDoc; - css::uno::Reference< css::uno::XComponentContext > - m_xContext; + + css::uno::Reference m_xChartDoc; + css::uno::Reference m_xContext; + + std::unique_ptr m_xTbxData; + std::unique_ptr m_xCloseBtn; + std::unique_ptr m_xTable; + std::unique_ptr m_xColumns; + std::unique_ptr m_xColors; + css::uno::Reference m_xTableCtrlParent; + VclPtr m_xBrwData; /// handles actions of the toolbox - DECL_LINK( ToolboxHdl, ToolBox*, void ); + DECL_LINK( ToolboxHdl, const OString&, void ); /// is called, if the cursor of the table has moved DECL_LINK( BrowserCursorMovedHdl, DataBrowser*, void); - /// this is called if MiscOptions change, esp. High-Contrast mode - DECL_LINK( MiscHdl, LinkParamNone*, void ); - - /** notifySystemWindow adds or remove the given window pToRegister at the Systemwindow found when search pWindow. - @param pWindow - The window which is used to search for the SystemWindow. - @param pToRegister - The window which should be added or removed on the TaskPaneList. - @param rMemFunc - The member function which should be called at the SystemWindow when found. - Possible values are: - ::comphelper::mem_fun(&TaskPaneList::AddWindow) - ::comphelper::mem_fun(&TaskPaneList::RemoveWindow) - - @note this code is taken from dbaccess/source/ui/inc/UITools.hxx - */ - static void notifySystemWindow(vcl::Window const * pWindow, - vcl::Window* pToRegister, - const ::comphelper::mem_fun1_t& rMemFunc); }; } // namespace chart diff --git a/chart2/source/controller/main/ChartController_EditData.cxx b/chart2/source/controller/main/ChartController_EditData.cxx index fb5a5d105708..e9820cab3cce 100644 --- a/chart2/source/controller/main/ChartController_EditData.cxx +++ b/chart2/source/controller/main/ChartController_EditData.cxx @@ -38,15 +38,14 @@ namespace chart void ChartController::executeDispatch_EditData() { Reference< chart2::XChartDocument > xChartDoc( getModel(), uno::UNO_QUERY ); - if( xChartDoc.is()) + if (xChartDoc.is()) { SolarMutexGuard aSolarGuard; UndoLiveUpdateGuardWithData aUndoGuard( SchResId( STR_ACTION_EDIT_CHART_DATA ), m_xUndoManager ); - ScopedVclPtrInstance aDataEditorDialog( GetChartWindow().get(), xChartDoc, m_xCC ); - if (aDataEditorDialog->Execute() == RET_OK) - aDataEditorDialog->ApplyChangesToModel(); + DataEditor aDataEditorDialog(GetChartFrame(), xChartDoc, m_xCC); + aDataEditorDialog.run(); aUndoGuard.commit(); } } -- cgit