From 0380a6408030ad9db85b4be81095219d5572749b Mon Sep 17 00:00:00 2001 From: Susobhan Ghosh Date: Sat, 30 Jul 2016 02:42:50 +0530 Subject: tdf#93845: Style Preview Checkbox for Styles & Formatting sidebar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Id5862339bbe0c80002dfd99cbf19d981d1d42682 Reviewed-on: https://gerrit.libreoffice.org/27706 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- sfx2/source/dialog/dialog.hrc | 1 + sfx2/source/dialog/dialog.src | 5 ++++ sfx2/source/dialog/templdlg.cxx | 63 ++++++++++++++++++++++++++++++++++------- sfx2/source/inc/templdgi.hxx | 4 ++- 4 files changed, 61 insertions(+), 12 deletions(-) (limited to 'sfx2') diff --git a/sfx2/source/dialog/dialog.hrc b/sfx2/source/dialog/dialog.hrc index 2bfd1af5ea5b..551478a34e85 100644 --- a/sfx2/source/dialog/dialog.hrc +++ b/sfx2/source/dialog/dialog.hrc @@ -61,6 +61,7 @@ #define SFX_ST_EDIT ( RC_DIALOG_BEGIN + 124 ) #define STR_STYLE_ELEMTLIST ( RC_DIALOG_BEGIN + 125 ) #define STR_FONT_TABPAGE ( RC_DIALOG_BEGIN + 126 ) +#define STR_PREVIEW_CHECKBOX ( RC_DIALOG_BEGIN + 127 ) #endif diff --git a/sfx2/source/dialog/dialog.src b/sfx2/source/dialog/dialog.src index c66f4475858a..732a716b1ecd 100644 --- a/sfx2/source/dialog/dialog.src +++ b/sfx2/source/dialog/dialog.src @@ -121,6 +121,11 @@ String STR_FONT_TABPAGE Text [ en-US ] = "Font" ; }; +String STR_PREVIEW_CHECKBOX +{ + Text [ en-US ] = "Show Previews"; +}; + Menu RID_MENU_NOTEBOOKBAR { ItemList = diff --git a/sfx2/source/dialog/templdlg.cxx b/sfx2/source/dialog/templdlg.cxx index 5fc64430d176..e185487513a7 100644 --- a/sfx2/source/dialog/templdlg.cxx +++ b/sfx2/source/dialog/templdlg.cxx @@ -68,6 +68,9 @@ #include #include #include + +#define STD_ENTRY_HEIGHT 17 + using namespace css; using namespace css::beans; using namespace css::frame; @@ -322,10 +325,10 @@ SfxActionListBox::SfxActionListBox(SfxCommonTemplateDialog_Impl* pParent, WinBit void SfxActionListBox::Recalc() { if (officecfg::Office::Common::StylesAndFormatting::Preview::get()) - { SetEntryHeight(32 * GetDPIScaleFactor()); - RecalcViewData(); - } + else + SetEntryHeight(STD_ENTRY_HEIGHT, true); + RecalcViewData(); } VclPtr SfxActionListBox::CreateContextMenu() @@ -509,10 +512,10 @@ StyleTreeListBox_Impl::StyleTreeListBox_Impl(SfxCommonTemplateDialog_Impl* pPare void StyleTreeListBox_Impl::Recalc() { if (officecfg::Office::Common::StylesAndFormatting::Preview::get()) - { SetEntryHeight(32 * GetDPIScaleFactor()); - RecalcViewData(); - } + else + SetEntryHeight(STD_ENTRY_HEIGHT, true); + RecalcViewData(); } /** Internal structure for the establishment of the hierarchical view */ @@ -653,6 +656,7 @@ SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, vcl , aFmtLb( VclPtr::Create(this, WB_BORDER | WB_TABSTOP | WB_SORT | WB_QUICK_SEARCH) ) , aFilterLb( VclPtr::Create(pW, WB_BORDER | WB_DROPDOWN | WB_TABSTOP) ) + , aPreviewCheckbox( VclPtr::Create( pW, WB_VCENTER )) , nActFamily(0xffff) , nActFilter(0) @@ -682,6 +686,8 @@ SfxCommonTemplateDialog_Impl::SfxCommonTemplateDialog_Impl( SfxBindings* pB, vcl vcl::Font aFont = aFmtLb->GetFont(); aFont.SetWeight( WEIGHT_NORMAL ); aFmtLb->SetFont( aFont ); + aPreviewCheckbox->Check(officecfg::Office::Common::StylesAndFormatting::Preview::get()); + aPreviewCheckbox->SetText( SfxResId(STR_PREVIEW_CHECKBOX) ); memset(pBoundItems, 0, sizeof(pBoundItems)); memset(pFamilyState, 0, sizeof(pFamilyState)); @@ -847,11 +853,13 @@ void SfxCommonTemplateDialog_Impl::Initialize() aFmtLb->SetDoubleClickHdl( LINK( this, SfxCommonTemplateDialog_Impl, TreeListApplyHdl ) ); aFmtLb->SetSelectHdl( LINK( this, SfxCommonTemplateDialog_Impl, FmtSelectHdl ) ); aFmtLb->SetSelectionMode(SelectionMode::Multiple); + aPreviewCheckbox->SetClickHdl( LINK(this, SfxCommonTemplateDialog_Impl, PreviewHdl)); aFilterLb->Show(); if (!bHierarchical) aFmtLb->Show(); + aPreviewCheckbox->Show(); } SfxCommonTemplateDialog_Impl::~SfxCommonTemplateDialog_Impl() @@ -874,6 +882,7 @@ SfxCommonTemplateDialog_Impl::~SfxCommonTemplateDialog_Impl() m_pDeletionWatcher->signal(); aFmtLb.disposeAndClear(); aFilterLb.disposeAndClear(); + aPreviewCheckbox.disposeAndClear(); } namespace SfxTemplate @@ -1378,8 +1387,7 @@ void SfxCommonTemplateDialog_Impl::Update_Impl() ppItem+=StyleNrToInfoOffset(n); nAppFilter = (*ppItem)->GetValue(); - FamilySelect( StyleNrToInfoOffset(n)+1 ); - + FamilySelect( StyleNrToInfoOffset(n) + 1 ); pItem = *ppItem; } else if( bDocChanged ) @@ -1687,9 +1695,9 @@ IMPL_LINK_TYPED( SfxCommonTemplateDialog_Impl, FilterSelectHdl, ListBox&, rBox, } // Select-Handler for the Toolbox -void SfxCommonTemplateDialog_Impl::FamilySelect(sal_uInt16 nEntry) +void SfxCommonTemplateDialog_Impl::FamilySelect(sal_uInt16 nEntry, bool bPreviewRefresh) { - if( nEntry != nActFamily ) + if( nEntry != nActFamily || bPreviewRefresh ) { CheckItem( nActFamily, false ); nActFamily = nEntry; @@ -2065,6 +2073,30 @@ IMPL_LINK_NOARG_TYPED( SfxCommonTemplateDialog_Impl, ApplyHdl, LinkParamNone*, v ResetFocus(); } +IMPL_LINK_NOARG_TYPED( SfxCommonTemplateDialog_Impl, PreviewHdl, Button*, void) +{ + std::shared_ptr batch( comphelper::ConfigurationChanges::create() ); + officecfg::Office::Common::StylesAndFormatting::Preview::set( aPreviewCheckbox->IsChecked(), batch ); + batch->commit(); + if(!bHierarchical) + { + sal_uInt16 nSize = aFmtLb->GetEntryCount(); + for (sal_uInt16 nPos = 0; nPos < nSize; ++nPos ) + { + SvTreeListEntry* pTreeListEntry = aFmtLb->GetEntry(nPos); + OUString aEntryStr = aFmtLb->GetEntryText(pTreeListEntry); + const SfxStyleFamily eFam = aPreviewCheckbox->IsChecked() ? GetFamilyItem_Impl()->GetFamily(): SfxStyleFamily::None; + pTreeListEntry->ReplaceItem(o3tl::make_unique(aEntryStr, eFam), 1); + aFmtLb->GetModel()->InvalidateEntry(pTreeListEntry); + aFmtLb->Recalc(); + } + } + else + { + FamilySelect(nActFamily, true); + } +} + // Selection of a template during the Watercan-Status IMPL_LINK_TYPED( SfxCommonTemplateDialog_Impl, FmtSelectHdl, SvTreeListBox *, pListBox, void ) { @@ -2364,6 +2396,13 @@ void SfxTemplateDialog_Impl::Resize() Size aFilterSize( m_pFloat->LogicToPixel(Size(nWidth,SFX_TEMPLDLG_FILTERHEIGHT)) ); + Point aCheckBoxPos( + m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME, + aDlgSize.Height()-SFX_TEMPLDLG_VBOTFRAME-2*nListHeight)) ); + + Size aCheckBoxSize( + m_pFloat->LogicToPixel(Size(nWidth, nListHeight)) ); + Point aFmtPos( m_pFloat->LogicToPixel(Point(SFX_TEMPLDLG_HFRAME, SFX_TEMPLDLG_VTOPFRAME + SFX_TEMPLDLG_MIDVSPACE+aSizeATL.Height())) ); @@ -2371,13 +2410,14 @@ void SfxTemplateDialog_Impl::Resize() m_pFloat->LogicToPixel(Size(nWidth, aDlgSize.Height() - SFX_TEMPLDLG_VBOTFRAME - SFX_TEMPLDLG_VTOPFRAME - 2*SFX_TEMPLDLG_MIDVSPACE- - nListHeight-aSizeATL.Height())) ); + 2*nListHeight-aSizeATL.Height())) ); // only change the position of the listbox, when the window is high enough if(aDlgSize.Height() >= aMinSize.Height()) { aFilterLb->SetPosPixel(aFilterPos); aFmtLb->SetPosPixel( aFmtPos ); + aPreviewCheckbox->SetPosPixel(aCheckBoxPos); if(pTreeBox) pTreeBox->SetPosPixel(aFmtPos); } @@ -2386,6 +2426,7 @@ void SfxTemplateDialog_Impl::Resize() aFilterLb->SetSizePixel(aFilterSize); aFmtLb->SetSizePixel( aFmtSize ); + aPreviewCheckbox->SetSizePixel( aCheckBoxSize ); if(pTreeBox) pTreeBox->SetSizePixel(aFmtSize); } diff --git a/sfx2/source/inc/templdgi.hxx b/sfx2/source/inc/templdgi.hxx index 0ffb548a11c7..385a40a5a1d1 100644 --- a/sfx2/source/inc/templdgi.hxx +++ b/sfx2/source/inc/templdgi.hxx @@ -186,6 +186,7 @@ protected: VclPtr aFmtLb; VclPtr aFilterLb; + VclPtr aPreviewCheckbox; sal_uInt16 nActFamily; // Id in the ToolBox = Position - 1 sal_uInt16 nActFilter; // FilterIdx @@ -214,6 +215,7 @@ protected: DECL_LINK_TYPED( TreeListApplyHdl, SvTreeListBox*, bool ); DECL_LINK_TYPED( DropHdl, StyleTreeListBox_Impl&, bool ); DECL_LINK_TYPED( TimeOut, Idle*, void ); + DECL_LINK_TYPED( PreviewHdl, Button*, void); virtual void EnableItem(sal_uInt16 /*nMesId*/, bool /*bCheck*/ = true) {} @@ -271,7 +273,7 @@ protected: void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override; - void FamilySelect( sal_uInt16 nId ); + void FamilySelect( sal_uInt16 nId, bool bPreviewRefresh = false ); void SetFamily( sal_uInt16 nId ); void ActionSelect( sal_uInt16 nId ); -- cgit