diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-03-13 10:21:36 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-03-13 22:07:48 +0100 |
commit | 99aaa4b0b88100c8db03b32e072cff0193ad0953 (patch) | |
tree | 7b090b06efbdbffd67ac253c4a4869e85d95210e /sw/source/ui/table | |
parent | 5504dcc6987ffb41e9077d468df42c6af94c38ea (diff) |
weld insert table dialog
Change-Id: I17bdbba38a74ea05b0d6869ee04f01f870a3b17b
Reviewed-on: https://gerrit.libreoffice.org/51219
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw/source/ui/table')
-rw-r--r-- | sw/source/ui/table/autoformatpreview.cxx | 458 | ||||
-rw-r--r-- | sw/source/ui/table/instable.cxx | 191 | ||||
-rw-r--r-- | sw/source/ui/table/tautofmt.cxx | 15 |
3 files changed, 110 insertions, 554 deletions
diff --git a/sw/source/ui/table/autoformatpreview.cxx b/sw/source/ui/table/autoformatpreview.cxx index 83aa97e90970..e4d892b54392 100644 --- a/sw/source/ui/table/autoformatpreview.cxx +++ b/sw/source/ui/table/autoformatpreview.cxx @@ -27,10 +27,9 @@ #define FRAME_OFFSET 4 -AutoFormatPreviewWindow::AutoFormatPreviewWindow(vcl::Window* pParent, WinBits nStyle) - : Window(pParent, nStyle) +AutoFormatPreview::AutoFormatPreview(weld::DrawingArea* pDrawingArea) + : mxDrawingArea(pDrawingArea) , aCurData(OUString()) - , aVD(VclPtr<VirtualDevice>::Create(*this)) , bFitWidth(false) , mbRTL(false) , aStrJan(SwResId(STR_JAN)) @@ -43,16 +42,17 @@ AutoFormatPreviewWindow::AutoFormatPreviewWindow(vcl::Window* pParent, WinBits n { uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext(); m_xBreak = i18n::BreakIterator::create(xContext); - pNumFormat = new SvNumberFormatter(xContext, LANGUAGE_SYSTEM); + mxNumFormat.reset(new SvNumberFormatter(xContext, LANGUAGE_SYSTEM)); Init(); -} -VCL_BUILDER_FACTORY_CONSTRUCTOR(AutoFormatPreviewWindow, 0) + mxDrawingArea->connect_size_allocate(LINK(this, AutoFormatPreview, DoResize)); + mxDrawingArea->connect_draw(LINK(this, AutoFormatPreview, DoPaint)); +} -void AutoFormatPreviewWindow::Resize() +IMPL_LINK(AutoFormatPreview, DoResize, const Size&, rSize, void) { - aPrvSize = Size(GetSizePixel().Width() - 6, GetSizePixel().Height() - 30); + aPrvSize = Size(rSize.Width() - 6, rSize.Height() - 30); nLabelColWidth = (aPrvSize.Width() - 4) / 4 - 12; nDataColWidth1 = (aPrvSize.Width() - 4 - 2 * nLabelColWidth) / 3; nDataColWidth2 = (aPrvSize.Width() - 4 - 2 * nLabelColWidth) / 4; @@ -60,7 +60,7 @@ void AutoFormatPreviewWindow::Resize() NotifyChange(aCurData); } -void AutoFormatPreviewWindow::DetectRTL(SwWrtShell const* pWrtShell) +void AutoFormatPreview::DetectRTL(SwWrtShell const* pWrtShell) { if (!pWrtShell->IsCursorInTable()) // We haven't created the table yet mbRTL = AllSettings::GetLayoutRTL(); @@ -68,14 +68,6 @@ void AutoFormatPreviewWindow::DetectRTL(SwWrtShell const* pWrtShell) mbRTL = pWrtShell->IsTableRightToLeft(); } -AutoFormatPreviewWindow::~AutoFormatPreviewWindow() { disposeOnce(); } - -void AutoFormatPreviewWindow::dispose() -{ - delete pNumFormat; - vcl::Window::dispose(); -} - static void lcl_SetFontProperties(vcl::Font& rFont, const SvxFontItem& rFontItem, const SvxWeightItem& rWeightItem, const SvxPostureItem& rPostureItem) @@ -94,432 +86,6 @@ static void lcl_SetFontProperties(vcl::Font& rFont, const SvxFontItem& rFontItem rCJKFont.MethodName(Value); \ rCTLFont.MethodName(Value); -void AutoFormatPreviewWindow::MakeFonts(sal_uInt8 nIndex, vcl::Font& rFont, vcl::Font& rCJKFont, - vcl::Font& rCTLFont) -{ - const SwBoxAutoFormat& rBoxFormat = aCurData.GetBoxFormat(nIndex); - - rFont = rCJKFont = rCTLFont = GetFont(); - Size aFontSize(rFont.GetFontSize().Width(), 10 * GetDPIScaleFactor()); - - lcl_SetFontProperties(rFont, rBoxFormat.GetFont(), rBoxFormat.GetWeight(), - rBoxFormat.GetPosture()); - lcl_SetFontProperties(rCJKFont, rBoxFormat.GetCJKFont(), rBoxFormat.GetCJKWeight(), - rBoxFormat.GetCJKPosture()); - lcl_SetFontProperties(rCTLFont, rBoxFormat.GetCTLFont(), rBoxFormat.GetCTLWeight(), - rBoxFormat.GetCTLPosture()); - - SETONALLFONTS(SetUnderline, rBoxFormat.GetUnderline().GetValue()); - SETONALLFONTS(SetOverline, rBoxFormat.GetOverline().GetValue()); - SETONALLFONTS(SetStrikeout, rBoxFormat.GetCrossedOut().GetValue()); - SETONALLFONTS(SetOutline, rBoxFormat.GetContour().GetValue()); - SETONALLFONTS(SetShadow, rBoxFormat.GetShadowed().GetValue()); - SETONALLFONTS(SetColor, rBoxFormat.GetColor().GetValue()); - SETONALLFONTS(SetFontSize, aFontSize); - SETONALLFONTS(SetTransparent, true); -} - -sal_uInt8 AutoFormatPreviewWindow::GetFormatIndex(size_t nCol, size_t nRow) const -{ - static const sal_uInt8 pnFormatMap[] - = { 0, 1, 2, 1, 3, 4, 5, 6, 5, 7, 8, 9, 10, 9, 11, 4, 5, 6, 5, 7, 12, 13, 14, 13, 15 }; - return pnFormatMap[maArray.GetCellIndex(nCol, nRow, mbRTL)]; -} - -void AutoFormatPreviewWindow::DrawString(vcl::RenderContext& rRenderContext, size_t nCol, - size_t nRow) -{ - // Output of the cell text: - sal_uLong nNum; - double nVal; - OUString cellString; - sal_uInt8 nIndex = static_cast<sal_uInt8>(maArray.GetCellIndex(nCol, nRow, mbRTL)); - - switch (nIndex) - { - case 1: - cellString = aStrJan; - break; - case 2: - cellString = aStrFeb; - break; - case 3: - cellString = aStrMar; - break; - case 5: - cellString = aStrNorth; - break; - case 10: - cellString = aStrMid; - break; - case 15: - cellString = aStrSouth; - break; - case 4: - case 20: - cellString = aStrSum; - break; - case 6: - case 8: - case 16: - case 18: - nVal = nIndex; - nNum = 5; - goto MAKENUMSTR; - case 17: - case 7: - nVal = nIndex; - nNum = 6; - goto MAKENUMSTR; - case 11: - case 12: - case 13: - nVal = nIndex; - nNum = 12 == nIndex ? 10 : 9; - goto MAKENUMSTR; - case 9: - nVal = 21; - nNum = 7; - goto MAKENUMSTR; - case 14: - nVal = 36; - nNum = 11; - goto MAKENUMSTR; - case 19: - nVal = 51; - nNum = 7; - goto MAKENUMSTR; - case 21: - nVal = 33; - nNum = 13; - goto MAKENUMSTR; - case 22: - nVal = 36; - nNum = 14; - goto MAKENUMSTR; - case 23: - nVal = 39; - nNum = 13; - goto MAKENUMSTR; - case 24: - nVal = 108; - nNum = 15; - goto MAKENUMSTR; - - MAKENUMSTR: - if (aCurData.IsValueFormat()) - { - OUString sFormat; - LanguageType eLng, eSys; - aCurData.GetBoxFormat(sal_uInt8(nNum)).GetValueFormat(sFormat, eLng, eSys); - - SvNumFormatType nType; - bool bNew; - sal_Int32 nCheckPos; - sal_uInt32 nKey = pNumFormat->GetIndexPuttingAndConverting(sFormat, eLng, eSys, - nType, bNew, nCheckPos); - Color* pDummy; - pNumFormat->GetOutputString(nVal, nKey, cellString, &pDummy); - } - else - cellString = OUString::number(sal_Int32(nVal)); - break; - } - - if (cellString.isEmpty()) - return; - - SvtScriptedTextHelper aScriptedText(rRenderContext); - Size aStrSize; - sal_uInt8 nFormatIndex = GetFormatIndex(nCol, nRow); - const basegfx::B2DRange aCellRange(maArray.GetCellRange(nCol, nRow, true)); - const tools::Rectangle cellRect( - basegfx::fround(aCellRange.getMinX()), basegfx::fround(aCellRange.getMinY()), - basegfx::fround(aCellRange.getMaxX()), basegfx::fround(aCellRange.getMaxY())); - Point aPos = cellRect.TopLeft(); - long nRightX = 0; - - Size theMaxStrSize(cellRect.GetWidth() - FRAME_OFFSET, cellRect.GetHeight() - FRAME_OFFSET); - if (aCurData.IsFont()) - { - vcl::Font aFont, aCJKFont, aCTLFont; - MakeFonts(nFormatIndex, aFont, aCJKFont, aCTLFont); - aScriptedText.SetFonts(&aFont, &aCJKFont, &aCTLFont); - } - else - aScriptedText.SetDefaultFont(); - - aScriptedText.SetText(cellString, m_xBreak); - aStrSize = aScriptedText.GetTextSize(); - - if (aCurData.IsFont() && theMaxStrSize.Height() < aStrSize.Height()) - { - // If the string in this font does not - // fit into the cell, the standard font - // is taken again: - aScriptedText.SetDefaultFont(); - aStrSize = aScriptedText.GetTextSize(); - } - - while (theMaxStrSize.Width() <= aStrSize.Width() && cellString.getLength() > 1) - { - cellString = cellString.copy(0, cellString.getLength() - 1); - aScriptedText.SetText(cellString, m_xBreak); - aStrSize = aScriptedText.GetTextSize(); - } - - nRightX = cellRect.GetWidth() - aStrSize.Width() - FRAME_OFFSET; - - // vertical (always centering): - aPos.AdjustY((nRowHeight - aStrSize.Height()) / 2); - - // horizontal - if (mbRTL) - aPos.AdjustX(nRightX); - else if (aCurData.IsJustify()) - { - const SvxAdjustItem& rAdj = aCurData.GetBoxFormat(nFormatIndex).GetAdjust(); - switch (rAdj.GetAdjust()) - { - case SvxAdjust::Left: - aPos.AdjustX(FRAME_OFFSET); - break; - case SvxAdjust::Right: - aPos.AdjustX(nRightX); - break; - default: - aPos.AdjustX((cellRect.GetWidth() - aStrSize.Width()) / 2); - break; - } - } - else - { - // Standard align: - if (nCol == 0 || nIndex == 4) - { - // Text-Label left or sum left aligned - aPos.AdjustX(FRAME_OFFSET); - } - else - { - // numbers/dates right aligned - aPos.AdjustX(nRightX); - } - } - - aScriptedText.DrawText(aPos); -} - -void AutoFormatPreviewWindow::DrawBackground(vcl::RenderContext& rRenderContext) -{ - for (size_t nRow = 0; nRow < 5; ++nRow) - { - for (size_t nCol = 0; nCol < 5; ++nCol) - { - SvxBrushItem aBrushItem( - aCurData.GetBoxFormat(GetFormatIndex(nCol, nRow)).GetBackground()); - - rRenderContext.Push(PushFlags::LINECOLOR | PushFlags::FILLCOLOR); - rRenderContext.SetLineColor(); - rRenderContext.SetFillColor(aBrushItem.GetColor()); - const basegfx::B2DRange aCellRange(maArray.GetCellRange(nCol, nRow, true)); - rRenderContext.DrawRect(tools::Rectangle( - basegfx::fround(aCellRange.getMinX()), basegfx::fround(aCellRange.getMinY()), - basegfx::fround(aCellRange.getMaxX()), basegfx::fround(aCellRange.getMaxY()))); - rRenderContext.Pop(); - } - } -} - -void AutoFormatPreviewWindow::PaintCells(vcl::RenderContext& rRenderContext) -{ - // 1) background - if (aCurData.IsBackground()) - DrawBackground(rRenderContext); - - // 2) values - for (size_t nRow = 0; nRow < 5; ++nRow) - for (size_t nCol = 0; nCol < 5; ++nCol) - DrawString(rRenderContext, nCol, nRow); - - // 3) border - if (aCurData.IsFrame()) - { - const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D; - std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D( - drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice( - rRenderContext, aNewViewInformation2D)); - - if (pProcessor2D) - { - pProcessor2D->process(maArray.CreateB2DPrimitiveArray()); - pProcessor2D.reset(); - } - } -} - -void AutoFormatPreviewWindow::Init() -{ - SetBorderStyle(GetBorderStyle() | WindowBorderStyle::MONO); - maArray.Initialize(5, 5); - nLabelColWidth = 0; - nDataColWidth1 = 0; - nDataColWidth2 = 0; - nRowHeight = 0; - CalcCellArray(false); - CalcLineMap(); -} - -void AutoFormatPreviewWindow::CalcCellArray(bool _bFitWidth) -{ - maArray.SetXOffset(2); - maArray.SetAllColWidths(_bFitWidth ? nDataColWidth2 : nDataColWidth1); - maArray.SetColWidth(0, nLabelColWidth); - maArray.SetColWidth(4, nLabelColWidth); - - maArray.SetYOffset(2); - maArray.SetAllRowHeights(nRowHeight); - - aPrvSize.setWidth(maArray.GetWidth() + 4); - aPrvSize.setHeight(maArray.GetHeight() + 4); -} - -inline void lclSetStyleFromBorder(svx::frame::Style& rStyle, - const ::editeng::SvxBorderLine* pBorder) -{ - rStyle.Set(pBorder, 0.05, 5); -} - -void AutoFormatPreviewWindow::CalcLineMap() -{ - for (size_t nRow = 0; nRow < 5; ++nRow) - { - for (size_t nCol = 0; nCol < 5; ++nCol) - { - svx::frame::Style aStyle; - - const SvxBoxItem& rItem = aCurData.GetBoxFormat(GetFormatIndex(nCol, nRow)).GetBox(); - lclSetStyleFromBorder(aStyle, rItem.GetLeft()); - maArray.SetCellStyleLeft(nCol, nRow, aStyle); - lclSetStyleFromBorder(aStyle, rItem.GetRight()); - maArray.SetCellStyleRight(nCol, nRow, aStyle); - lclSetStyleFromBorder(aStyle, rItem.GetTop()); - maArray.SetCellStyleTop(nCol, nRow, aStyle); - lclSetStyleFromBorder(aStyle, rItem.GetBottom()); - maArray.SetCellStyleBottom(nCol, nRow, aStyle); - - // FIXME - uncomment to draw diagonal borders - // lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, true ).GetLine() ); - // maArray.SetCellStyleTLBR( nCol, nRow, aStyle ); - // lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, false ).GetLine() ); - // maArray.SetCellStyleBLTR( nCol, nRow, aStyle ); - } - } -} - -void AutoFormatPreviewWindow::NotifyChange(const SwTableAutoFormat& rNewData) -{ - aCurData = rNewData; - bFitWidth = aCurData.IsJustify(); // true; //??? - CalcCellArray(bFitWidth); - CalcLineMap(); - Invalidate(tools::Rectangle(Point(0, 0), GetSizePixel())); -} - -void AutoFormatPreviewWindow::DoPaint(vcl::RenderContext& rRenderContext) -{ - DrawModeFlags nOldDrawMode = aVD->GetDrawMode(); - if (rRenderContext.GetSettings().GetStyleSettings().GetHighContrastMode()) - aVD->SetDrawMode(DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill - | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient); - - Bitmap thePreview; - Point aCenterPos; - Size theWndSize = GetSizePixel(); - Color oldColor; - vcl::Font aFont; - - aFont = aVD->GetFont(); - aFont.SetTransparent(true); - - aVD->SetFont(aFont); - aVD->SetLineColor(); - const Color& rWinColor = rRenderContext.GetSettings().GetStyleSettings().GetWindowColor(); - aVD->SetBackground(Wallpaper(rWinColor)); - aVD->SetFillColor(rWinColor); - aVD->SetOutputSizePixel(aPrvSize); - - // Draw cells on virtual device - // and save the result - PaintCells(*aVD.get()); - thePreview = aVD->GetBitmap(Point(0, 0), aPrvSize); - - // Draw the Frame and center the preview: - // (virtual Device for window output) - aVD->SetOutputSizePixel(theWndSize); - oldColor = aVD->GetLineColor(); - aVD->SetLineColor(); - aVD->DrawRect(tools::Rectangle(Point(0, 0), theWndSize)); - - rRenderContext.SetLineColor(oldColor); - - aCenterPos = Point((theWndSize.Width() - aPrvSize.Width()) / 2, - (theWndSize.Height() - aPrvSize.Height()) / 2); - aVD->DrawBitmap(aCenterPos, thePreview); - - // Output in the preview window: - rRenderContext.DrawBitmap(Point(0, 0), aVD->GetBitmap(Point(0, 0), theWndSize)); - - aVD->SetDrawMode(nOldDrawMode); -} - -void AutoFormatPreviewWindow::Paint(vcl::RenderContext& rRenderContext, - const tools::Rectangle& /*rRect*/) -{ - DoPaint(rRenderContext); -} - -AutoFormatPreview::AutoFormatPreview(weld::DrawingArea* pDrawingArea) - : mxDrawingArea(pDrawingArea) - , aCurData(OUString()) - , bFitWidth(false) - , mbRTL(false) - , aStrJan(SwResId(STR_JAN)) - , aStrFeb(SwResId(STR_FEB)) - , aStrMar(SwResId(STR_MAR)) - , aStrNorth(SwResId(STR_NORTH)) - , aStrMid(SwResId(STR_MID)) - , aStrSouth(SwResId(STR_SOUTH)) - , aStrSum(SwResId(STR_SUM)) -{ - uno::Reference<uno::XComponentContext> xContext = comphelper::getProcessComponentContext(); - m_xBreak = i18n::BreakIterator::create(xContext); - mxNumFormat.reset(new SvNumberFormatter(xContext, LANGUAGE_SYSTEM)); - - Init(); - - mxDrawingArea->connect_size_allocate(LINK(this, AutoFormatPreview, DoResize)); - mxDrawingArea->connect_draw(LINK(this, AutoFormatPreview, DoPaint)); -} - -IMPL_LINK(AutoFormatPreview, DoResize, const Size&, rSize, void) -{ - aPrvSize = Size(rSize.Width() - 6, rSize.Height() - 30); - nLabelColWidth = (aPrvSize.Width() - 4) / 4 - 12; - nDataColWidth1 = (aPrvSize.Width() - 4 - 2 * nLabelColWidth) / 3; - nDataColWidth2 = (aPrvSize.Width() - 4 - 2 * nLabelColWidth) / 4; - nRowHeight = (aPrvSize.Height() - 4) / 5; - NotifyChange(aCurData); -} - -void AutoFormatPreview::DetectRTL(SwWrtShell const* pWrtShell) -{ - if (!pWrtShell->IsCursorInTable()) // We haven't created the table yet - mbRTL = AllSettings::GetLayoutRTL(); - else - mbRTL = pWrtShell->IsTableRightToLeft(); -} - void AutoFormatPreview::MakeFonts(vcl::RenderContext& rRenderContext, sal_uInt8 nIndex, vcl::Font& rFont, vcl::Font& rCJKFont, vcl::Font& rCTLFont) { @@ -806,6 +372,12 @@ void AutoFormatPreview::CalcCellArray(bool _bFitWidth) aPrvSize.setHeight(maArray.GetHeight() + 4); } +inline void lclSetStyleFromBorder(svx::frame::Style& rStyle, + const ::editeng::SvxBorderLine* pBorder) +{ + rStyle.Set(pBorder, 0.05, 5); +} + void AutoFormatPreview::CalcLineMap() { for (size_t nRow = 0; nRow < 5; ++nRow) diff --git a/sw/source/ui/table/instable.cxx b/sw/source/ui/table/instable.cxx index 1cb841d5ef01..535ba075a15c 100644 --- a/sw/source/ui/table/instable.cxx +++ b/sw/source/ui/table/instable.cxx @@ -32,17 +32,17 @@ void SwInsTableDlg::GetValues( OUString& rName, sal_uInt16& rRow, sal_uInt16& rC SwTableAutoFormat *& prTAFormat ) { sal_uInt16 nInsMode = 0; - rName = m_pNameEdit->GetText(); - rRow = static_cast<sal_uInt16>(m_pRowNF->GetValue()); - rCol = static_cast<sal_uInt16>(m_pColNF->GetValue()); + rName = m_xNameEdit->get_text(); + rRow = m_xRowNF->get_value(); + rCol = m_xColNF->get_value(); - if (m_pHeaderCB->IsChecked()) + if (m_xHeaderCB->get_active()) nInsMode |= tabopts::HEADLINE; - if (m_pRepeatHeaderCB->IsEnabled() && m_pRepeatHeaderCB->IsChecked()) - rInsTableOpts.mnRowsToRepeat = sal_uInt16( m_pRepeatHeaderNF->GetValue() ); + if (m_xRepeatHeaderCB->get_sensitive() && m_xRepeatHeaderCB->get_active()) + rInsTableOpts.mnRowsToRepeat = m_xRepeatHeaderNF->get_value(); else rInsTableOpts.mnRowsToRepeat = 0; - if (!m_pDontSplitCB->IsChecked()) + if (!m_xDontSplitCB->get_active()) nInsMode |= tabopts::SPLIT_LAYOUT; if( pTAutoFormat ) { @@ -53,35 +53,45 @@ void SwInsTableDlg::GetValues( OUString& rName, sal_uInt16& rRow, sal_uInt16& rC rInsTableOpts.mnInsMode = nInsMode; } -SwInsTableDlg::SwInsTableDlg( SwView& rView ) - : SfxModalDialog(rView.GetWindow(), "InsertTableDialog", "modules/swriter/ui/inserttable.ui") +IMPL_LINK(SwInsTableDlg, TextFilterHdl, OUString&, rTest, bool) +{ + rTest = m_aTextFilter.filter(rTest); + return true; +} + +SwInsTableDlg::SwInsTableDlg(SwView& rView) + : weld::GenericDialogController(rView.GetFrameWeld(), "modules/swriter/ui/inserttable.ui", "InsertTableDialog") + , m_xNameEdit(m_xBuilder->weld_entry("nameedit")) + , m_xColNF(m_xBuilder->weld_spin_button("colspin")) + , m_xRowNF(m_xBuilder->weld_spin_button("rowspin")) + , m_xHeaderCB(m_xBuilder->weld_check_button("headercb")) + , m_xRepeatHeaderCB(m_xBuilder->weld_check_button("repeatcb")) + , m_xRepeatHeaderNF(m_xBuilder->weld_spin_button("repeatheaderspin")) + , m_xRepeatGroup(m_xBuilder->weld_widget("repeatgroup")) + , m_xDontSplitCB(m_xBuilder->weld_check_button("dontsplitcb")) + , m_xInsertBtn(m_xBuilder->weld_button("ok")) + , m_xLbFormat(m_xBuilder->weld_tree_view("formatlbinstable")) + , m_xWndPreview(new AutoFormatPreview(m_xBuilder->weld_drawing_area("previewinstable"))) , m_aTextFilter(" .<>") , pShell(&rView.GetWrtShell()) , pTAutoFormat(nullptr) , nEnteredValRepeatHeaderNF(-1) { - get(m_pNameEdit, "nameedit"); - m_pNameEdit->SetTextFilter(&m_aTextFilter); - get(m_pColNF, "colspin"); - get(m_pRowNF, "rowspin"); - get(m_pHeaderCB, "headercb"); - get(m_pRepeatHeaderCB, "repeatcb"); - get(m_pDontSplitCB, "dontsplitcb"); - get(m_pInsertBtn, "ok"); - get(m_pRepeatGroup, "repeatgroup"); - get(m_pRepeatHeaderNF, "repeatheaderspin"); - get(m_pLbFormat, "formatlbinstable"); - get(m_pWndPreview, "previewinstable"); - - m_pNameEdit->SetText(pShell->GetUniqueTableName()); - m_pNameEdit->SetModifyHdl(LINK(this, SwInsTableDlg, ModifyName)); - m_pColNF->SetModifyHdl(LINK(this, SwInsTableDlg, ModifyRowCol)); - m_pRowNF->SetModifyHdl(LINK(this, SwInsTableDlg, ModifyRowCol)); - - m_pRowNF->SetMax(ROW_COL_PROD/m_pColNF->GetValue()); - m_pColNF->SetMax(ROW_COL_PROD/m_pRowNF->GetValue()); - - m_pInsertBtn->SetClickHdl(LINK(this, SwInsTableDlg, OKHdl)); + const int nWidth = m_xLbFormat->get_approximate_char_width() * 32; + const int nHeight = m_xLbFormat->get_height_rows(8); + m_xLbFormat->set_size_request(nWidth, nHeight); + m_xWndPreview->set_size_request(nWidth, nHeight); + + m_xNameEdit->connect_insert_text(LINK(this, SwInsTableDlg, TextFilterHdl)); + m_xNameEdit->set_text(pShell->GetUniqueTableName()); + m_xNameEdit->connect_changed(LINK(this, SwInsTableDlg, ModifyName)); + m_xColNF->connect_value_changed(LINK(this, SwInsTableDlg, ModifyRowCol)); + m_xRowNF->connect_value_changed(LINK(this, SwInsTableDlg, ModifyRowCol)); + + m_xRowNF->set_max(ROW_COL_PROD/m_xColNF->get_value()); + m_xColNF->set_max(ROW_COL_PROD/m_xRowNF->get_value()); + + m_xInsertBtn->connect_clicked(LINK(this, SwInsTableDlg, OKHdl)); bool bHTMLMode = 0 != (::GetHtmlMode(rView.GetDocShell())&HTMLMODE_ON); const SwModuleOptions* pModOpt = SW_MOD()->GetModuleConfig(); @@ -89,47 +99,47 @@ SwInsTableDlg::SwInsTableDlg( SwView& rView ) SwInsertTableOptions aInsOpts = pModOpt->GetInsTableFlags(bHTMLMode); sal_uInt16 nInsTableFlags = aInsOpts.mnInsMode; - m_pHeaderCB->Check( 0 != (nInsTableFlags & tabopts::HEADLINE) ); - m_pRepeatHeaderCB->Check(aInsOpts.mnRowsToRepeat > 0); - if(bHTMLMode) - m_pDontSplitCB->Hide(); + m_xHeaderCB->set_active(0 != (nInsTableFlags & tabopts::HEADLINE)); + m_xRepeatHeaderCB->set_active(aInsOpts.mnRowsToRepeat > 0); + if (bHTMLMode) + m_xDontSplitCB->hide(); else - m_pDontSplitCB->Check( 0 == (nInsTableFlags & tabopts::SPLIT_LAYOUT) ); + m_xDontSplitCB->set_active(0 == (nInsTableFlags & tabopts::SPLIT_LAYOUT)); - m_pRepeatHeaderNF->SetModifyHdl( LINK( this, SwInsTableDlg, ModifyRepeatHeaderNF_Hdl ) ); - m_pHeaderCB->SetClickHdl( LINK( this, SwInsTableDlg, CheckBoxHdl ) ); - m_pRepeatHeaderCB->SetClickHdl( LINK( this, SwInsTableDlg, ReapeatHeaderCheckBoxHdl ) ); - ReapeatHeaderCheckBoxHdl(nullptr); - CheckBoxHdl(nullptr); + m_xRepeatHeaderNF->connect_value_changed( LINK( this, SwInsTableDlg, ModifyRepeatHeaderNF_Hdl ) ); + m_xHeaderCB->connect_toggled( LINK( this, SwInsTableDlg, CheckBoxHdl ) ); + m_xRepeatHeaderCB->connect_toggled( LINK( this, SwInsTableDlg, RepeatHeaderCheckBoxHdl ) ); + RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB); + CheckBoxHdl(*m_xHeaderCB); - sal_Int64 nMax = m_pRowNF->GetValue(); + sal_Int64 nMax = m_xRowNF->get_value(); if( nMax <= 1 ) nMax = 1; else --nMax; - m_pRepeatHeaderNF->SetMax( nMax ); + m_xRepeatHeaderNF->set_max( nMax ); InitAutoTableFormat(); } void SwInsTableDlg::InitAutoTableFormat() { - m_pWndPreview->DetectRTL(pShell); + m_xWndPreview->DetectRTL(pShell); - m_pLbFormat->SetSelectHdl( LINK( this, SwInsTableDlg, SelFormatHdl ) ); + m_xLbFormat->connect_changed(LINK(this, SwInsTableDlg, SelFormatHdl)); pTableTable = new SwTableAutoFormatTable; pTableTable->Load(); // Add "- none -" style autoformat table. - m_pLbFormat->InsertEntry( SwViewShell::GetShellRes()->aStrNone ); // Insert to listbox + m_xLbFormat->append( SwViewShell::GetShellRes()->aStrNone ); // Insert to listbox // Add other styles of autoformat tables. for (sal_uInt8 i = 0, nCount = static_cast<sal_uInt8>(pTableTable->size()); i < nCount; i++) { SwTableAutoFormat const& rFormat = (*pTableTable)[ i ]; - m_pLbFormat->InsertEntry(rFormat.GetName()); + m_xLbFormat->append(rFormat.GetName()); if (pTAutoFormat && rFormat.GetName() == pTAutoFormat->GetName()) lbIndex = i; } @@ -138,10 +148,10 @@ void SwInsTableDlg::InitAutoTableFormat() minTableIndexInLb = 1; maxTableIndexInLb = minTableIndexInLb + static_cast<sal_uInt8>(pTableTable->size()); lbIndex = 1; - m_pLbFormat->SelectEntryPos( lbIndex ); + m_xLbFormat->select( lbIndex ); tbIndex = lbIndexToTableIndex(lbIndex); - SelFormatHdl( *m_pLbFormat ); + SelFormatHdl( *m_xLbFormat ); } sal_uInt8 SwInsTableDlg::lbIndexToTableIndex( const sal_uInt8 listboxIndex ) @@ -156,30 +166,6 @@ sal_uInt8 SwInsTableDlg::lbIndexToTableIndex( const sal_uInt8 listboxIndex ) return 255; } -SwInsTableDlg::~SwInsTableDlg() -{ - disposeOnce(); -} - -void SwInsTableDlg::dispose() -{ - delete pTAutoFormat; - m_pLbFormat.clear(); - m_pNameEdit.clear(); - m_pColNF.clear(); - m_pRowNF.clear(); - m_pHeaderCB.clear(); - m_pRepeatHeaderCB.clear(); - m_pRepeatHeaderNF.clear(); - m_pRepeatGroup.clear(); - m_pDontSplitCB.clear(); - m_pInsertBtn.clear(); - m_pWndPreview.clear(); - pTableTable->Save(); - delete pTableTable; - SfxModalDialog::dispose(); -} - static void lcl_SetProperties( SwTableAutoFormat* pTableAutoFormat, bool bVal ) { pTableAutoFormat->SetFont( bVal ); @@ -190,27 +176,26 @@ static void lcl_SetProperties( SwTableAutoFormat* pTableAutoFormat, bool bVal ) pTableAutoFormat->SetWidthHeight( bVal ); } - -IMPL_LINK_NOARG(SwInsTableDlg, SelFormatHdl, ListBox&, void) +IMPL_LINK_NOARG(SwInsTableDlg, SelFormatHdl, weld::TreeView&, void) { // Get index of selected item from the listbox - lbIndex = static_cast<sal_uInt8>(m_pLbFormat->GetSelectedEntryPos()); + lbIndex = static_cast<sal_uInt8>(m_xLbFormat->get_selected_index()); tbIndex = lbIndexToTableIndex( lbIndex ); // To understand this index maping, look InitAutoTableFormat function to // see how listbox item is implemented. if( tbIndex < 255 ) - m_pWndPreview->NotifyChange( (*pTableTable)[tbIndex] ); + m_xWndPreview->NotifyChange( (*pTableTable)[tbIndex] ); else { SwTableAutoFormat aTmp( SwViewShell::GetShellRes()->aStrNone ); lcl_SetProperties( &aTmp, false ); - m_pWndPreview->NotifyChange( aTmp ); + m_xWndPreview->NotifyChange( aTmp ); } } -IMPL_LINK_NOARG(SwInsTableDlg, OKHdl, Button*, void) +IMPL_LINK_NOARG(SwInsTableDlg, OKHdl, weld::Button&, void) { if( tbIndex < 255 ) pShell->SetTableStyle((*pTableTable)[tbIndex]); @@ -229,64 +214,58 @@ IMPL_LINK_NOARG(SwInsTableDlg, OKHdl, Button*, void) lcl_SetProperties( pTAutoFormat, false ); } - EndDialog(RET_OK); + m_xDialog->response(RET_OK); } -IMPL_LINK( SwInsTableDlg, ModifyName, Edit&, rEdit, void ) +IMPL_LINK( SwInsTableDlg, ModifyName, weld::Entry&, rEdit, void ) { - OUString sTableName = rEdit.GetText(); - if (sTableName.indexOf(' ') != -1) - { - sTableName = sTableName.replaceAll(" ", ""); - rEdit.SetText(sTableName); - } - - m_pInsertBtn->Enable(pShell->GetTableStyle( sTableName ) == nullptr); + OUString sTableName = rEdit.get_text(); + m_xInsertBtn->set_sensitive(pShell->GetTableStyle(sTableName) == nullptr); } -IMPL_LINK( SwInsTableDlg, ModifyRowCol, Edit&, rEdit, void ) +IMPL_LINK( SwInsTableDlg, ModifyRowCol, weld::SpinButton&, rEdit, void ) { - if(&rEdit == m_pColNF) + if(&rEdit == m_xColNF.get()) { - sal_Int64 nCol = m_pColNF->GetValue(); + sal_Int64 nCol = m_xColNF->get_value(); if(!nCol) nCol = 1; - m_pRowNF->SetMax(ROW_COL_PROD/nCol); + m_xRowNF->set_max(ROW_COL_PROD/nCol); } else { - sal_Int64 nRow = m_pRowNF->GetValue(); + sal_Int64 nRow = m_xRowNF->get_value(); if(!nRow) nRow = 1; - m_pColNF->SetMax(ROW_COL_PROD/nRow); + m_xColNF->set_max(ROW_COL_PROD/nRow); // adjust depending NF for repeated rows sal_Int64 nMax = ( nRow == 1 )? 1 : nRow - 1 ; - sal_Int64 nActVal = m_pRepeatHeaderNF->GetValue(); + sal_Int64 nActVal = m_xRepeatHeaderNF->get_value(); - m_pRepeatHeaderNF->SetMax( nMax ); + m_xRepeatHeaderNF->set_max( nMax ); if( nActVal > nMax ) - m_pRepeatHeaderNF->SetValue( nMax ); + m_xRepeatHeaderNF->set_value( nMax ); else if( nActVal < nEnteredValRepeatHeaderNF ) - m_pRepeatHeaderNF->SetValue( std::min( nEnteredValRepeatHeaderNF, nMax ) ); + m_xRepeatHeaderNF->set_value(std::min(nEnteredValRepeatHeaderNF, nMax)); } } -IMPL_LINK_NOARG(SwInsTableDlg, CheckBoxHdl, Button*, void) +IMPL_LINK_NOARG(SwInsTableDlg, CheckBoxHdl, weld::ToggleButton&, void) { - m_pRepeatHeaderCB->Enable(m_pHeaderCB->IsChecked()); - ReapeatHeaderCheckBoxHdl(nullptr); + m_xRepeatHeaderCB->set_sensitive(m_xHeaderCB->get_active()); + RepeatHeaderCheckBoxHdl(*m_xRepeatHeaderCB); } -IMPL_LINK_NOARG(SwInsTableDlg, ReapeatHeaderCheckBoxHdl, Button*, void) +IMPL_LINK_NOARG(SwInsTableDlg, RepeatHeaderCheckBoxHdl, weld::ToggleButton&, void) { - m_pRepeatGroup->Enable(m_pHeaderCB->IsChecked() && m_pRepeatHeaderCB->IsChecked()); + m_xRepeatGroup->set_sensitive(m_xHeaderCB->get_active() && m_xRepeatHeaderCB->get_active()); } -IMPL_LINK_NOARG(SwInsTableDlg, ModifyRepeatHeaderNF_Hdl, Edit&, void) +IMPL_LINK_NOARG(SwInsTableDlg, ModifyRepeatHeaderNF_Hdl, weld::SpinButton&, void) { - nEnteredValRepeatHeaderNF = m_pRepeatHeaderNF->GetValue(); + nEnteredValRepeatHeaderNF = m_xRepeatHeaderNF->get_value(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/table/tautofmt.cxx b/sw/source/ui/table/tautofmt.cxx index 5adc8ca51fcd..d66969e539cb 100644 --- a/sw/source/ui/table/tautofmt.cxx +++ b/sw/source/ui/table/tautofmt.cxx @@ -65,7 +65,7 @@ SwAutoFormatDlg::SwAutoFormatDlg(weld::Window* pParent, SwWrtShell* pWrtShell, , m_xBtnAdd(m_xBuilder->weld_button("add")) , m_xBtnRemove(m_xBuilder->weld_button("remove")) , m_xBtnRename(m_xBuilder->weld_button("rename")) - , m_aWndPreview(m_xBuilder->weld_drawing_area("preview")) + , m_xWndPreview(new AutoFormatPreview(m_xBuilder->weld_drawing_area("preview"))) , m_xTableTable(new SwTableAutoFormatTable) , aStrTitle(SwResId(STR_ADD_AUTOFORMAT_TITLE)) , aStrLabel(SwResId(STR_ADD_AUTOFORMAT_LABEL)) @@ -80,9 +80,14 @@ SwAutoFormatDlg::SwAutoFormatDlg(weld::Window* pParent, SwWrtShell* pWrtShell, , bCoreDataChanged(false) , bSetAutoFormat(bAutoFormat) { - m_aWndPreview.DetectRTL(pWrtShell); + m_xWndPreview->DetectRTL(pWrtShell); m_xTableTable->Load(); + const int nWidth = m_xLbFormat->get_approximate_char_width() * 32; + const int nHeight = m_xLbFormat->get_height_rows(8); + m_xLbFormat->set_size_request(nWidth, nHeight); + m_xWndPreview->set_size_request(nWidth, nHeight); + Init(pSelFormat); } @@ -201,7 +206,7 @@ IMPL_LINK(SwAutoFormatDlg, CheckHdl, weld::ToggleButton&, rBtn, void) bCoreDataChanged = true; } - m_aWndPreview.NotifyChange(rData); + m_xWndPreview->NotifyChange(rData); } } @@ -370,7 +375,7 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, SelFormatHdl, weld::TreeView&, void) if (nSelPos >= nDfltStylePos) { m_nIndex = nSelPos - nDfltStylePos; - m_aWndPreview.NotifyChange((*m_xTableTable)[m_nIndex]); + m_xWndPreview->NotifyChange((*m_xTableTable)[m_nIndex]); bBtnEnable = 0 != m_nIndex; UpdateChecks( (*m_xTableTable)[m_nIndex], true ); } @@ -382,7 +387,7 @@ IMPL_LINK_NOARG(SwAutoFormatDlg, SelFormatHdl, weld::TreeView&, void) lcl_SetProperties( &aTmp, false ); if (nOldIdx != m_nIndex) - m_aWndPreview.NotifyChange(aTmp); + m_xWndPreview->NotifyChange(aTmp); UpdateChecks( aTmp, false ); } |