summaryrefslogtreecommitdiff
path: root/svx/source/tbxctrls/tbcontrl.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'svx/source/tbxctrls/tbcontrl.cxx')
-rw-r--r--svx/source/tbxctrls/tbcontrl.cxx793
1 files changed, 427 insertions, 366 deletions
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index 5ab016dc50fa..cf5541622150 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -27,7 +27,6 @@
#include <vcl/commandinfoprovider.hxx>
#include <vcl/combobox.hxx>
#include <vcl/event.hxx>
-#include <vcl/menubtn.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/customweld.hxx>
#include <vcl/vclptr.hxx>
@@ -106,8 +105,7 @@
#define MAX_MRU_FONTNAME_ENTRIES 5
-// don't make more than 15 entries visible at once
-#define MAX_STYLES_ENTRIES 15
+#define COMBO_WIDTH_IN_CHARS 16
// namespaces
using namespace ::editeng;
@@ -117,44 +115,105 @@ using namespace ::com::sun::star::frame;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::lang;
-SFX_IMPL_TOOLBOX_CONTROL( SvxStyleToolBoxControl, SfxTemplateItem );
-
-class SvxStyleBox_Impl : public ComboBox
+namespace
+{
+class SvxStyleBox_Base
{
- using Window::IsVisible;
public:
- SvxStyleBox_Impl( vcl::Window* pParent, const OUString& rCommand, SfxStyleFamily eFamily, const Reference< XDispatchProvider >& rDispatchProvider,
- const Reference< XFrame >& _xFrame,const OUString& rClearFormatKey, const OUString& rMoreKey, bool bInSpecialMode );
- virtual ~SvxStyleBox_Impl() override;
- virtual void dispose() override;
+ SvxStyleBox_Base(std::unique_ptr<weld::ComboBox> xWidget, const OUString& rCommand, SfxStyleFamily eFamily,
+ const Reference<XDispatchProvider>& rDispatchProvider,
+ const Reference<XFrame>& _xFrame,const OUString& rClearFormatKey,
+ const OUString& rMoreKey, bool bInSpecialMode, SvxStyleToolBoxControl& rCtrl);
+
+ virtual ~SvxStyleBox_Base()
+ {
+ }
void SetFamily( SfxStyleFamily eNewFamily );
- bool IsVisible() const { return bVisible; }
- virtual bool PreNotify( NotifyEvent& rNEvt ) override;
- virtual bool EventNotify( NotifyEvent& rNEvt ) override;
- virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
- virtual void StateChanged( StateChangedType nStateChange ) override;
+ void SetDefaultStyle( const OUString& rDefault ) { sDefaultStyle = rDefault; }
- virtual void UserDraw( const UserDrawEvent& rUDEvt ) override;
+ int get_count() const { return m_xWidget->get_count(); }
+ OUString get_text(int nIndex) const { return m_xWidget->get_text(nIndex); }
+ OUString get_active_text() const { return m_xWidget->get_active_text(); }
- void SetVisibilityListener( const Link<SvxStyleBox_Impl&,void>& aVisListener ) { aVisibilityListener = aVisListener; }
+ void append_text(const OUString& rStr)
+ {
+ OUString sId(OUString::number(m_xWidget->get_count()));
+ m_xWidget->append(sId, rStr);
+ }
- void SetDefaultStyle( const OUString& rDefault ) { sDefaultStyle = rDefault; }
- virtual boost::property_tree::ptree DumpAsPropertyTree() override;
+ void insert_separator(int pos, const OUString& rId)
+ {
+ m_xWidget->insert_separator(pos, rId);
+ }
-protected:
- /// Calculate the optimal width of the dropdown. Very expensive operation, triggers lots of font measurement.
- DECL_LINK(CalcOptimalExtraUserWidth, VclWindowEvent&, void);
+ virtual void set_sensitive(bool bSensitive)
+ {
+ m_xWidget->set_sensitive(bSensitive);
+ }
+
+ void set_active_or_entry_text(const OUString& rText)
+ {
+ const int nFound = m_xWidget->find_text(rText);
+ if (nFound != -1)
+ m_xWidget->set_active(nFound);
+ else
+ m_xWidget->set_entry_text(rText);
+ }
+
+ void set_active(int nActive)
+ {
+ m_xWidget->set_active(nActive);
+ }
+
+ void freeze()
+ {
+ m_xWidget->freeze();
+ }
+
+ void save_value()
+ {
+ m_xWidget->save_value();
+ }
- virtual void Select() override;
+ void clear()
+ {
+ m_xWidget->clear();
+ m_nMaxUserDrawFontWidth = 0;
+ }
+
+ void thaw()
+ {
+ m_xWidget->thaw();
+ }
+
+ virtual bool DoKeyInput(const KeyEvent& rKEvt);
private:
+ DECL_LINK(SelectHdl, weld::ComboBox&, void);
+ DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
+ DECL_LINK(ActivateHdl, weld::ComboBox&, bool);
+ DECL_LINK(FocusOutHdl, weld::Widget&, void);
+ DECL_LINK(DumpAsPropertyTreeHdl, boost::property_tree::ptree&, void);
+ DECL_LINK(CustomRenderHdl, weld::ComboBox::render_args, void);
+ DECL_LINK(CustomGetSizeHdl, OutputDevice&, Size);
+
+ /// Calculate the optimal width of the dropdown. Very expensive operation, triggers lots of font measurement.
+ void CalcOptimalExtraUserWidth(vcl::RenderContext& rRenderContext);
+
+ void Select(bool bNonTravelSelect);
+
+protected:
+ SvxStyleToolBoxControl& m_rCtrl;
+
+ std::unique_ptr<weld::Builder> m_xMenuBuilder;
+ std::unique_ptr<weld::Menu> m_xMenu;
+ std::unique_ptr<weld::ComboBox> m_xWidget;
+
SfxStyleFamily eStyleFamily;
- sal_Int32 nCurSel;
+ int m_nMaxUserDrawFontWidth;
bool bRelease;
- Size aLogicalSize;
- Link<SvxStyleBox_Impl&,void> aVisibilityListener;
bool bVisible;
Reference< XDispatchProvider > m_xDispatchProvider;
Reference< XFrame > m_xFrame;
@@ -163,27 +222,58 @@ private:
OUString aMoreKey;
OUString sDefaultStyle;
bool bInSpecialMode;
- VclPtr<MenuButton> m_pButtons[MAX_STYLES_ENTRIES];
- VclBuilder m_aBuilder;
- VclPtr<PopupMenu> m_pMenu;
void ReleaseFocus();
static Color TestColorsVisible(const Color &FontCol, const Color &BackCol);
- static void UserDrawEntry(const UserDrawEvent& rUDEvt, const OUString &rStyleName);
- void SetupEntry(vcl::RenderContext& rRenderContext, vcl::Window* pParent, sal_Int32 nItem, const tools::Rectangle& rRect, const OUString& rStyleName, bool bIsNotSelected);
- static bool AdjustFontForItemHeight(OutputDevice* pDevice, tools::Rectangle const & rTextRect, long nHeight);
- void SetOptimalSize();
- DECL_LINK( MenuSelectHdl, Menu *, bool );
- DECL_STATIC_LINK(SvxStyleBox_Impl, ShowMoreHdl, void*, void);
+ static void UserDrawEntry(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, const OUString &rStyleName);
+ void SetupEntry(vcl::RenderContext& rRenderContext, sal_Int32 nItem, const tools::Rectangle& rRect, const OUString& rStyleName, bool bIsNotSelected);
+ static bool AdjustFontForItemHeight(OutputDevice& rDevice, tools::Rectangle const & rTextRect, long nHeight);
+ DECL_LINK(MenuSelectHdl, const OString&, void);
+ DECL_STATIC_LINK(SvxStyleBox_Base, ShowMoreHdl, void*, void);
};
-namespace {
+class SvxStyleBox_Impl final : public InterimItemWindow
+ , public SvxStyleBox_Base
+{
+public:
+ SvxStyleBox_Impl(vcl::Window* pParent, const OUString& rCommand, SfxStyleFamily eFamily, const Reference< XDispatchProvider >& rDispatchProvider,
+ const Reference< XFrame >& _xFrame,const OUString& rClearFormatKey, const OUString& rMoreKey, bool bInSpecialMode, SvxStyleToolBoxControl& rCtrl);
+
+ virtual ~SvxStyleBox_Impl() override
+ {
+ disposeOnce();
+ }
+
+ virtual void dispose() override
+ {
+ m_xWidget.reset();
+ m_xMenu.reset();
+ m_xMenuBuilder.reset();
+ InterimItemWindow::dispose();
+ }
+
+ virtual bool DoKeyInput(const KeyEvent& rKEvt) override;
+
+private:
+
+ virtual void set_sensitive(bool bSensitive) override
+ {
+ m_xWidget->set_sensitive(bSensitive);
+ if (bSensitive)
+ InterimItemWindow::Enable();
+ else
+ InterimItemWindow::Disable();
+ }
+
+ virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
+ void SetOptimalSize();
+};
class SvxFontNameBox_Impl;
class SvxFontNameBox_Base;
-class SvxFontNameToolBoxControl : public cppu::ImplInheritanceHelper< svt::ToolboxController,
- css::lang::XServiceInfo >
+class SvxFontNameToolBoxControl final : public cppu::ImplInheritanceHelper<svt::ToolboxController,
+ css::lang::XServiceInfo>
{
public:
SvxFontNameToolBoxControl();
@@ -192,7 +282,7 @@ public:
virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
// XToolbarController
- virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createItemWindow( const css::uno::Reference< css::awt::XWindow >& rParent ) override;
+ virtual css::uno::Reference<css::awt::XWindow> SAL_CALL createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent) override;
// XComponent
virtual void SAL_CALL dispose() override;
@@ -218,7 +308,6 @@ protected:
const FontList* pFontList;
::std::unique_ptr<FontList> m_aOwnFontList;
vcl::Font aCurFont;
- OUString aCurText;
sal_uInt16 nFtCount;
bool bRelease;
Reference< XDispatchProvider > m_xDispatchProvider;
@@ -477,7 +566,7 @@ private:
Color aColor1, Color aColor2, Color aColorDist,
SvxBorderLineStyle nStyle, BitmapEx& rBmp )
{
- auto nMinWidth = GetDrawingArea()->get_ref_device().approximate_digit_width() * 15;
+ auto nMinWidth = GetDrawingArea()->get_ref_device().approximate_digit_width() * COMBO_WIDTH_IN_CHARS;
Size aSize(nMinWidth, aTxtSize.Height());
aSize.AdjustWidth( -(aTxtSize.Width()) );
aSize.AdjustWidth( -6 );
@@ -728,23 +817,24 @@ class SfxStyleControllerItem_Impl : public SfxStatusListener
SvxStyleToolBoxControl& rControl;
};
-#define BUTTON_WIDTH 20
#define BUTTON_PADDING 10
#define ITEM_HEIGHT 30
-SvxStyleBox_Impl::SvxStyleBox_Impl(vcl::Window* pParent,
+SvxStyleBox_Base::SvxStyleBox_Base(std::unique_ptr<weld::ComboBox> xWidget,
const OUString& rCommand,
SfxStyleFamily eFamily,
const Reference< XDispatchProvider >& rDispatchProvider,
const Reference< XFrame >& _xFrame,
const OUString& rClearFormatKey,
const OUString& rMoreKey,
- bool bInSpec)
- : ComboBox(pParent, WB_SORT | WB_BORDER | WB_HIDE | WB_DROPDOWN | WB_AUTOHSCROLL)
+ bool bInSpec, SvxStyleToolBoxControl& rCtrl)
+ : m_rCtrl(rCtrl)
+ , m_xMenuBuilder(Application::CreateBuilder(nullptr, "svx/ui/stylemenu.ui"))
+ , m_xMenu(m_xMenuBuilder->weld_menu("menu"))
+ , m_xWidget(std::move(xWidget))
, eStyleFamily( eFamily )
- , nCurSel(0)
+ , m_nMaxUserDrawFontWidth(0)
, bRelease( true )
- , aLogicalSize(60, 86)
, bVisible(false)
, m_xDispatchProvider( rDispatchProvider )
, m_xFrame(_xFrame)
@@ -752,42 +842,49 @@ SvxStyleBox_Impl::SvxStyleBox_Impl(vcl::Window* pParent,
, aClearFormatKey( rClearFormatKey )
, aMoreKey( rMoreKey )
, bInSpecialMode( bInSpec )
- , m_aBuilder(nullptr, VclBuilderContainer::getUIRootDir(), "svx/ui/stylemenu.ui", "")
- , m_pMenu(m_aBuilder.get_menu("menu"))
{
- SetHelpId(HID_STYLE_LISTBOX);
- m_pMenu->SetSelectHdl( LINK( this, SvxStyleBox_Impl, MenuSelectHdl ) );
- for(VclPtr<MenuButton> & rpButton : m_pButtons)
- rpButton = nullptr;
- SetOptimalSize();
- EnableAutocomplete( true );
- EnableUserDraw( true );
- AddEventListener(LINK(this, SvxStyleBox_Impl, CalcOptimalExtraUserWidth));
- SetUserItemSize( Size( 0, ITEM_HEIGHT ) );
- set_id("applystyle");
+ m_xWidget->connect_changed(LINK(this, SvxStyleBox_Base, SelectHdl));
+ m_xWidget->connect_key_press(LINK(this, SvxStyleBox_Base, KeyInputHdl));
+ m_xWidget->connect_entry_activate(LINK(this, SvxStyleBox_Base, ActivateHdl));
+ m_xWidget->connect_focus_out(LINK(this, SvxStyleBox_Base, FocusOutHdl));
+ m_xWidget->connect_get_property_tree(LINK(this, SvxStyleBox_Base, DumpAsPropertyTreeHdl));
+ m_xWidget->set_help_id(HID_STYLE_LISTBOX);
+ m_xWidget->set_entry_completion(true);
+ m_xMenu->connect_activate(LINK(this, SvxStyleBox_Base, MenuSelectHdl));
+
+ m_xWidget->connect_custom_get_size(LINK(this, SvxStyleBox_Base, CustomGetSizeHdl));
+ m_xWidget->connect_custom_render(LINK(this, SvxStyleBox_Base, CustomRenderHdl));
+ m_xWidget->set_custom_renderer();
+
+ int nCharWidth = m_xWidget->get_approximate_digit_width() * COMBO_WIDTH_IN_CHARS;
+ // set width in chars low so the size request will not be overridden
+ m_xWidget->set_entry_width_chars(1);
+ m_xWidget->set_size_request(nCharWidth, -1);
}
-SvxStyleBox_Impl::~SvxStyleBox_Impl()
+IMPL_LINK(SvxStyleBox_Base, CustomGetSizeHdl, OutputDevice&, rArg, Size)
{
- disposeOnce();
+ CalcOptimalExtraUserWidth(rArg);
+ return Size(m_nMaxUserDrawFontWidth, ITEM_HEIGHT);
}
-void SvxStyleBox_Impl::dispose()
+SvxStyleBox_Impl::SvxStyleBox_Impl(vcl::Window* pParent,
+ const OUString& rCommand,
+ SfxStyleFamily eFamily,
+ const Reference< XDispatchProvider >& rDispatchProvider,
+ const Reference< XFrame >& _xFrame,
+ const OUString& rClearFormatKey,
+ const OUString& rMoreKey,
+ bool bInSpec, SvxStyleToolBoxControl& rCtrl)
+ : InterimItemWindow(pParent, "svx/ui/applystylebox.ui", "ApplyStyleBox")
+ , SvxStyleBox_Base(m_xBuilder->weld_combo_box("applystyle"), rCommand, eFamily,
+ rDispatchProvider, _xFrame, rClearFormatKey, rMoreKey, bInSpec, rCtrl)
{
- RemoveEventListener(LINK(this, SvxStyleBox_Impl, CalcOptimalExtraUserWidth));
-
- for (VclPtr<MenuButton>& rButton : m_pButtons)
- {
- rButton.disposeAndClear();
- }
-
- m_pMenu.clear();
- m_aBuilder.disposeBuilder();
-
- ComboBox::dispose();
+ set_id("applystyle");
+ SetOptimalSize();
}
-void SvxStyleBox_Impl::ReleaseFocus()
+void SvxStyleBox_Base::ReleaseFocus()
{
if ( !bRelease )
{
@@ -798,56 +895,60 @@ void SvxStyleBox_Impl::ReleaseFocus()
m_xFrame->getContainerWindow()->setFocus();
}
-IMPL_LINK( SvxStyleBox_Impl, MenuSelectHdl, Menu*, pMenu, bool)
+IMPL_LINK(SvxStyleBox_Base, MenuSelectHdl, const OString&, rMenuIdent, void)
{
- OUString sEntry = GetSelectedEntry();
- OString sMenuIdent = pMenu->GetCurItemIdent();
+ OUString sEntry = m_xWidget->get_active_text();
+
ReleaseFocus(); // It must be after getting entry pos!
- if (IsInDropDown())
- ToggleDropDown();
- Sequence< PropertyValue > aArgs( 2 );
+ Sequence<PropertyValue> aArgs(2);
aArgs[0].Name = "Param";
aArgs[0].Value <<= sEntry;
aArgs[1].Name = "Family";
aArgs[1].Value <<= sal_Int16( eStyleFamily );
- if (sMenuIdent == "update")
+ if (rMenuIdent == "update")
{
SfxToolBoxControl::Dispatch( m_xDispatchProvider,
".uno:StyleUpdateByExample", aArgs );
}
- else if (sMenuIdent == "edit")
+ else if (rMenuIdent == "edit")
{
SfxToolBoxControl::Dispatch( m_xDispatchProvider,
".uno:EditStyle", aArgs );
}
-
- return false;
}
-IMPL_STATIC_LINK_NOARG(SvxStyleBox_Impl, ShowMoreHdl, void*, void)
+IMPL_STATIC_LINK_NOARG(SvxStyleBox_Base, ShowMoreHdl, void*, void)
{
SfxViewFrame* pViewFrm = SfxViewFrame::Current();
- DBG_ASSERT( pViewFrm, "SvxStyleBox_Impl::Select(): no viewframe" );
+ DBG_ASSERT( pViewFrm, "SvxStyleBox_Base::Select(): no viewframe" );
if (!pViewFrm)
return;
pViewFrm->ShowChildWindow(SID_SIDEBAR);
::sfx2::sidebar::Sidebar::ShowPanel("StyleListPanel", pViewFrm->GetFrame().GetFrameInterface(), true);
}
-void SvxStyleBox_Impl::Select()
+IMPL_LINK(SvxStyleBox_Base, SelectHdl, weld::ComboBox&, rCombo, void)
+{
+ Select(rCombo.changed_by_direct_pick()); // only when picked from the list
+}
+
+IMPL_LINK_NOARG(SvxStyleBox_Base, ActivateHdl, weld::ComboBox&, bool)
{
- // Tell base class about selection so that AT get informed about it.
- ComboBox::Select();
+ Select(true);
+ return true;
+}
- if ( IsTravelSelect() )
+void SvxStyleBox_Base::Select(bool bNonTravelSelect)
+{
+ if (!bNonTravelSelect)
return;
- OUString aSearchEntry( GetText() );
+ OUString aSearchEntry(m_xWidget->get_active_text());
bool bDoIt = true, bClear = false;
if( bInSpecialMode )
{
- if( aSearchEntry == aClearFormatKey && GetSelectedEntryPos() == 0 )
+ if( aSearchEntry == aClearFormatKey && m_xWidget->get_active() == 0 )
{
aSearchEntry = sDefaultStyle;
bClear = true;
@@ -856,11 +957,11 @@ void SvxStyleBox_Impl::Select()
SfxToolBoxControl::Dispatch( m_xDispatchProvider, ".uno:ResetAttributes",
aEmptyVals);
}
- else if( aSearchEntry == aMoreKey && GetSelectedEntryPos() == ( GetEntryCount() - 1 ) )
+ else if (aSearchEntry == aMoreKey && m_xWidget->get_active() == (m_xWidget->get_count() - 1))
{
- Application::PostUserEvent(LINK(nullptr, SvxStyleBox_Impl, ShowMoreHdl));
+ Application::PostUserEvent(LINK(nullptr, SvxStyleBox_Base, ShowMoreHdl));
//tdf#113214 change text back to previous entry
- SetText(GetSavedValue());
+ set_active_or_entry_text(m_xWidget->get_saved_value());
bDoIt = false;
}
}
@@ -896,8 +997,8 @@ void SvxStyleBox_Impl::Select()
if( bDoIt )
{
if ( bClear )
- SetText( aSearchEntry );
- SaveValue();
+ set_active_or_entry_text(aSearchEntry);
+ m_xWidget->save_value();
Sequence< PropertyValue > aArgs( 2 );
aArgs[0].Value <<= aSearchEntry;
@@ -916,67 +1017,50 @@ void SvxStyleBox_Impl::Select()
}
}
-void SvxStyleBox_Impl::SetFamily( SfxStyleFamily eNewFamily )
+void SvxStyleBox_Base::SetFamily( SfxStyleFamily eNewFamily )
{
eStyleFamily = eNewFamily;
}
-bool SvxStyleBox_Impl::PreNotify( NotifyEvent& rNEvt )
+IMPL_LINK_NOARG(SvxStyleBox_Base, FocusOutHdl, weld::Widget&, void)
{
- MouseNotifyEvent nType = rNEvt.GetType();
+ if (!m_xWidget->has_focus()) // a combobox can be comprised of different subwidget so double-check if none of those has focus
+ set_active_or_entry_text(m_xWidget->get_saved_value());
+}
- if ( MouseNotifyEvent::MOUSEBUTTONDOWN == nType || MouseNotifyEvent::GETFOCUS == nType )
- nCurSel = GetSelectedEntryPos();
- else if ( MouseNotifyEvent::LOSEFOCUS == nType )
- {
- // don't handle before our Select() is called
- if (!HasFocus() && !HasChildPathFocus() && !IsChild(rNEvt.GetWindow()))
- SetText( GetSavedValue() );
- }
- return ComboBox::PreNotify( rNEvt );
+IMPL_LINK(SvxStyleBox_Base, KeyInputHdl, const KeyEvent&, rKEvt, bool)
+{
+ return DoKeyInput(rKEvt);
}
-bool SvxStyleBox_Impl::EventNotify( NotifyEvent& rNEvt )
+bool SvxStyleBox_Base::DoKeyInput(const KeyEvent& rKEvt)
{
bool bHandled = false;
- if ( rNEvt.GetType() == MouseNotifyEvent::KEYINPUT )
- {
- sal_uInt16 nCode = rNEvt.GetKeyEvent()->GetKeyCode().GetCode();
+ sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode();
- switch ( nCode )
- {
- case KEY_CONTEXTMENU:
- {
- if(IsInDropDown())
- {
- const sal_Int32 nItem = GetSelectedEntryPos() - 1;
- if(nItem < MAX_STYLES_ENTRIES)
- m_pButtons[nItem]->ExecuteMenu();
- bHandled = true;
- }
- break;
- }
- case KEY_RETURN:
- case KEY_TAB:
+ switch (nCode)
+ {
+ case KEY_TAB:
+ bRelease = false;
+ Select(true);
+ break;
+ case KEY_ESCAPE:
+ set_active_or_entry_text(m_xWidget->get_saved_value());
+ if (!m_rCtrl.IsInSidebar())
{
- if ( KEY_TAB == nCode )
- bRelease = false;
- else
- bHandled = true;
- Select();
- break;
- }
-
- case KEY_ESCAPE:
- SelectEntryPos( nCurSel );
- if ( typeid( *GetParent() ) != typeid( sfx2::sidebar::SidebarToolBox ) )
- ReleaseFocus();
+ ReleaseFocus();
bHandled = true;
- break;
- }
+ }
+ break;
}
- return bHandled || ComboBox::EventNotify( rNEvt );
+
+ return bHandled;
+}
+
+bool SvxStyleBox_Impl::DoKeyInput(const KeyEvent& rKEvt)
+{
+ return SvxStyleBox_Base::DoKeyInput(rKEvt) || ChildKeyInput(rKEvt);
}
void SvxStyleBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
@@ -987,37 +1071,21 @@ void SvxStyleBox_Impl::DataChanged( const DataChangedEvent& rDCEvt )
SetOptimalSize();
}
- ComboBox::DataChanged( rDCEvt );
-}
-
-void SvxStyleBox_Impl::StateChanged( StateChangedType nStateChange )
-{
- ComboBox::StateChanged( nStateChange );
-
- if ( nStateChange == StateChangedType::Visible )
- {
- bVisible = IsReallyVisible();
- aVisibilityListener.Call( *this );
- }
- else if ( nStateChange == StateChangedType::InitShow )
- {
- bVisible = true;
- aVisibilityListener.Call( *this );
- }
+ InterimItemWindow::DataChanged( rDCEvt );
}
-bool SvxStyleBox_Impl::AdjustFontForItemHeight(OutputDevice* pDevice, tools::Rectangle const & rTextRect, long nHeight)
+bool SvxStyleBox_Base::AdjustFontForItemHeight(OutputDevice& rDevice, tools::Rectangle const & rTextRect, long nHeight)
{
if (rTextRect.Bottom() > nHeight)
{
// the text does not fit, adjust the font size
double ratio = static_cast< double >( nHeight ) / rTextRect.Bottom();
- vcl::Font aFont(pDevice->GetFont());
+ vcl::Font aFont(rDevice.GetFont());
Size aPixelSize(aFont.GetFontSize());
aPixelSize.setWidth( aPixelSize.Width() * ratio );
aPixelSize.setHeight( aPixelSize.Height() * ratio );
aFont.SetFontSize(aPixelSize);
- pDevice->SetFont(aFont);
+ rDevice.SetFont(aFont);
return true;
}
return false;
@@ -1025,42 +1093,46 @@ bool SvxStyleBox_Impl::AdjustFontForItemHeight(OutputDevice* pDevice, tools::Rec
void SvxStyleBox_Impl::SetOptimalSize()
{
- Size aSize(LogicToPixel(aLogicalSize, MapMode(MapUnit::MapAppFont)));
- set_width_request(aSize.Width());
- set_height_request(aSize.Height());
- SetSizePixel(aSize);
+ SetSizePixel(get_preferred_size());
}
-void SvxStyleBox_Impl::UserDrawEntry(const UserDrawEvent& rUDEvt, const OUString &rStyleName)
+void SvxStyleBox_Base::UserDrawEntry(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect, const OUString &rStyleName)
{
- vcl::RenderContext *pDevice = rUDEvt.GetRenderContext();
-
// IMG_TXT_DISTANCE in ilstbox.hxx is 6, then 1 is added as
// nBorder, and we are adding 1 in order to look better when
// italics is present
const int nLeftDistance = 8;
tools::Rectangle aTextRect;
- pDevice->GetTextBoundRect(aTextRect, rStyleName);
+ rRenderContext.GetTextBoundRect(aTextRect, rStyleName);
- Point aPos( rUDEvt.GetRect().TopLeft() );
+ Point aPos(rRect.TopLeft());
aPos.AdjustX(nLeftDistance );
- if (!AdjustFontForItemHeight(pDevice, aTextRect, rUDEvt.GetRect().GetHeight()))
- aPos.AdjustY(( rUDEvt.GetRect().GetHeight() - aTextRect.Bottom() ) / 2 );
+ if (!AdjustFontForItemHeight(rRenderContext, aTextRect, rRect.GetHeight()))
+ aPos.AdjustY((rRect.GetHeight() - aTextRect.Bottom() ) / 2);
- pDevice->DrawText(aPos, rStyleName);
+ rRenderContext.DrawText(aPos, rStyleName);
}
-void SvxStyleBox_Impl::SetupEntry(vcl::RenderContext& rRenderContext, vcl::Window* pParent, sal_Int32 nItem, const tools::Rectangle& rRect, const OUString& rStyleName, bool bIsNotSelected)
+void SvxStyleBox_Base::SetupEntry(vcl::RenderContext& rRenderContext, sal_Int32 nItem, const tools::Rectangle& rRect, const OUString& rStyleName, bool bIsNotSelected)
{
- unsigned int nId = rRect.GetHeight() != 0 ? (rRect.getY() / rRect.GetHeight()) : MAX_STYLES_ENTRIES;
- if (nItem == 0 || nItem == GetEntryCount() - 1)
+ const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
+ if (!bIsNotSelected)
+ rRenderContext.SetTextColor(rStyleSettings.GetHighlightTextColor());
+ else
+ rRenderContext.SetTextColor(rStyleSettings.GetDialogTextColor());
+
+ // handle the push-button
+ if (!bIsNotSelected)
{
- if(nId < MAX_STYLES_ENTRIES && m_pButtons[nId])
- m_pButtons[nId]->Hide();
+ if (nItem == 0 || nItem == m_xWidget->get_count() - 1)
+ m_xWidget->set_item_menu(OString::number(nItem), nullptr);
+ else
+ m_xWidget->set_item_menu(OString::number(nItem), m_xMenu.get());
}
- else
+
+ if (nItem > 0 && nItem < m_xWidget->get_count() - 1)
{
SfxObjectShell *pShell = SfxObjectShell::Current();
SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool();
@@ -1181,93 +1253,69 @@ void SvxStyleBox_Impl::SetupEntry(vcl::RenderContext& rRenderContext, vcl::Windo
// set text color
if ( aFontCol != COL_AUTO )
rRenderContext.SetTextColor(aFontCol);
-
- // handle the push-button
- if (bIsNotSelected)
- {
- if (nId < MAX_STYLES_ENTRIES && m_pButtons[nId])
- m_pButtons[nId]->Hide();
- }
- else
- {
- if (nId < MAX_STYLES_ENTRIES)
- {
- if (!m_pButtons[nId] && pParent)
- {
- m_pButtons[nId] = VclPtr<MenuButton>::Create(pParent, WB_FLATBUTTON | WB_NOPOINTERFOCUS);
- m_pButtons[nId]->SetSizePixel(Size(BUTTON_WIDTH, rRect.GetHeight()));
- m_pButtons[nId]->SetPopupMenu(m_pMenu);
- }
- m_pButtons[nId]->SetPosPixel(Point(rRect.GetWidth() - BUTTON_WIDTH, rRect.getY()));
- m_pButtons[nId]->Show();
- }
- }
}
}
}
}
-void SvxStyleBox_Impl::UserDraw( const UserDrawEvent& rUDEvt )
+IMPL_LINK(SvxStyleBox_Base, CustomRenderHdl, weld::ComboBox::render_args, aPayload, void)
{
- sal_uInt16 nItem = rUDEvt.GetItemId();
- OUString aStyleName( GetEntry( nItem ) );
+ vcl::RenderContext& rRenderContext = std::get<0>(aPayload);
+ const ::tools::Rectangle& rRect = std::get<1>(aPayload);
+ bool bSelected = std::get<2>(aPayload);
+ const OUString& rId = std::get<3>(aPayload);
- vcl::RenderContext *pDevice = rUDEvt.GetRenderContext();
- pDevice->Push(PushFlags::FILLCOLOR | PushFlags::FONT | PushFlags::TEXTCOLOR);
+ sal_uInt32 nIndex = rId.toUInt32();
- const tools::Rectangle& rRect(rUDEvt.GetRect());
- bool bIsNotSelected = rUDEvt.GetItemId() != GetSelectedEntryPos();
+ OUString aStyleName(m_xWidget->get_text(nIndex));
- SetupEntry(*pDevice, rUDEvt.GetWindow(), nItem, rRect, aStyleName, bIsNotSelected);
+ rRenderContext.Push(PushFlags::FILLCOLOR | PushFlags::FONT | PushFlags::TEXTCOLOR);
- UserDrawEntry(rUDEvt, aStyleName);
+ SetupEntry(rRenderContext, nIndex, rRect, aStyleName, !bSelected);
- pDevice->Pop();
- // draw separator, if present
- DrawEntry( rUDEvt, false, false );
+ UserDrawEntry(rRenderContext, rRect, aStyleName);
+
+ rRenderContext.Pop();
}
-IMPL_LINK(SvxStyleBox_Impl, CalcOptimalExtraUserWidth, VclWindowEvent&, event, void)
+void SvxStyleBox_Base::CalcOptimalExtraUserWidth(vcl::RenderContext& rRenderContext)
{
- // perform the calculation only when we are opening the dropdown
- if (event.GetId() != VclEventId::DropdownPreOpen)
+ if (m_nMaxUserDrawFontWidth)
return;
long nMaxNormalFontWidth = 0;
- sal_Int32 nEntryCount = GetEntryCount();
+ sal_Int32 nEntryCount = m_xWidget->get_count();
for (sal_Int32 i = 0; i < nEntryCount; ++i)
{
- OUString sStyleName(GetEntry(i));
+ OUString sStyleName(get_text(i));
tools::Rectangle aTextRectForDefaultFont;
- GetTextBoundRect(aTextRectForDefaultFont, sStyleName);
+ rRenderContext.GetTextBoundRect(aTextRectForDefaultFont, sStyleName);
const long nWidth = aTextRectForDefaultFont.GetWidth();
nMaxNormalFontWidth = std::max(nWidth, nMaxNormalFontWidth);
}
- long nMaxUserDrawFontWidth = nMaxNormalFontWidth;
+ m_nMaxUserDrawFontWidth = nMaxNormalFontWidth;
for (sal_Int32 i = 1; i < nEntryCount-1; ++i)
{
- OUString sStyleName(GetEntry(i));
+ OUString sStyleName(get_text(i));
- Push(PushFlags::FILLCOLOR | PushFlags::FONT | PushFlags::TEXTCOLOR);
- SetupEntry(*this /*FIXME rendercontext*/, this, i, tools::Rectangle(0, 0, RECT_MAX, ITEM_HEIGHT), sStyleName, true);
+ rRenderContext.Push(PushFlags::FILLCOLOR | PushFlags::FONT | PushFlags::TEXTCOLOR);
+ SetupEntry(rRenderContext, i, tools::Rectangle(0, 0, RECT_MAX, ITEM_HEIGHT), sStyleName, true);
tools::Rectangle aTextRectForActualFont;
- GetTextBoundRect(aTextRectForActualFont, sStyleName);
- if (AdjustFontForItemHeight(this, aTextRectForActualFont, ITEM_HEIGHT))
+ rRenderContext.GetTextBoundRect(aTextRectForActualFont, sStyleName);
+ if (AdjustFontForItemHeight(rRenderContext, aTextRectForActualFont, ITEM_HEIGHT))
{
//Font didn't fit, so it was changed, refetch with final font size
- GetTextBoundRect(aTextRectForActualFont, sStyleName);
+ rRenderContext.GetTextBoundRect(aTextRectForActualFont, sStyleName);
}
- Pop();
+ rRenderContext.Pop();
- const long nWidth = aTextRectForActualFont.GetWidth() + BUTTON_WIDTH + BUTTON_PADDING;
+ const int nWidth = aTextRectForActualFont.GetWidth() + m_xWidget->get_menu_button_width() + BUTTON_PADDING;
- nMaxUserDrawFontWidth = std::max(nWidth, nMaxUserDrawFontWidth);
+ m_nMaxUserDrawFontWidth = std::max(nWidth, m_nMaxUserDrawFontWidth);
}
-
- SetUserItemSize(Size(nMaxUserDrawFontWidth, ITEM_HEIGHT));
}
// test is the color between Font- and background-color to be identify
@@ -1275,7 +1323,7 @@ IMPL_LINK(SvxStyleBox_Impl, CalcOptimalExtraUserWidth, VclWindowEvent&, event, v
// when both light or dark, change the Contrast
// in other case do not change the origin color
// when the color is R=G=B=128 the DecreaseContrast make 128 the need an exception
-Color SvxStyleBox_Impl::TestColorsVisible(const Color &FontCol, const Color &BackCol)
+Color SvxStyleBox_Base::TestColorsVisible(const Color &FontCol, const Color &BackCol)
{
const sal_uInt8 ChgVal = 60; // increase/decrease the Contrast
@@ -1293,38 +1341,35 @@ Color SvxStyleBox_Impl::TestColorsVisible(const Color &FontCol, const Color &Bac
return retCol;
}
-boost::property_tree::ptree SvxStyleBox_Impl::DumpAsPropertyTree()
+IMPL_LINK(SvxStyleBox_Base, DumpAsPropertyTreeHdl, boost::property_tree::ptree&, rTree, void)
{
- boost::property_tree::ptree aTree(ComboBox::DumpAsPropertyTree());
-
boost::property_tree::ptree aEntries;
- for (int i = 0; i < GetEntryCount(); ++i)
+ for (int i = 0, nEntryCount = m_xWidget->get_count(); i < nEntryCount; ++i)
{
boost::property_tree::ptree aEntry;
- aEntry.put("", GetEntry(i));
+ aEntry.put("", m_xWidget->get_text(i));
aEntries.push_back(std::make_pair("", aEntry));
}
- aTree.add_child("entries", aEntries);
+ rTree.add_child("entries", aEntries);
boost::property_tree::ptree aSelected;
- for (int i = 0; i < GetSelectedEntryCount(); ++i)
+ int nActive = m_xWidget->get_active();
+
+ if (nActive != -1)
{
boost::property_tree::ptree aEntry;
- aEntry.put("", GetSelectedEntryPos(i));
+ aEntry.put("", nActive);
aSelected.push_back(std::make_pair("", aEntry));
}
- aTree.put("selectedCount", GetSelectedEntryCount());
- aTree.add_child("selectedEntries", aSelected);
- aTree.put("command", ".uno:StyleApply");
-
- return aTree;
+ rTree.put("selectedCount", nActive == -1 ? 0 : 1);
+ rTree.add_child("selectedEntries", aSelected);
+ rTree.put("command", ".uno:StyleApply");
}
-
static bool lcl_GetDocFontList(const FontList** ppFontList, SvxFontNameBox_Base* pBox)
{
bool bChanged = false;
@@ -1400,7 +1445,7 @@ SvxFontNameBox_Base::SvxFontNameBox_Base(std::unique_ptr<weld::ComboBox> xWidget
const Reference<XFrame>& rFrame,
SvxFontNameToolBoxControl& rCtrl)
: m_rCtrl(rCtrl)
- , m_nCharWidth(xWidget->get_approximate_digit_width() * 16)
+ , m_nCharWidth(xWidget->get_approximate_digit_width() * COMBO_WIDTH_IN_CHARS)
, m_xWidget(new FontNameBox(std::move(xWidget)))
, pFontList(nullptr)
, nFtCount(0)
@@ -1443,7 +1488,6 @@ void SvxFontNameBox_Base::FillList()
// Did Doc-Fontlist change?
lcl_GetDocFontList(&pFontList, this);
- aCurText = m_xWidget->get_active_text();
m_xWidget->select_entry_region(nStartPos, nEndPos);
}
@@ -1524,7 +1568,7 @@ bool SvxFontNameBox_Base::DoKeyInput(const KeyEvent& rKEvt)
break;
case KEY_ESCAPE:
- set_active_or_entry_text(aCurText);
+ set_active_or_entry_text(m_xWidget->get_saved_value());
if (!m_rCtrl.IsInSidebar())
{
ReleaseFocus_Impl();
@@ -2464,17 +2508,24 @@ struct SvxStyleToolBoxControl::Impl
bool bSpecModeWriter;
bool bSpecModeCalc;
+ VclPtr<SvxStyleBox_Impl> m_xVclBox;
+ std::unique_ptr<SvxStyleBox_Base> m_xWeldBox;
+ SvxStyleBox_Base* m_pBox;
+
Impl()
:aClearForm ( SvxResId( RID_SVXSTR_CLEARFORM ) )
,aMore ( SvxResId( RID_SVXSTR_MORE_STYLES ) )
,bSpecModeWriter ( false )
,bSpecModeCalc ( false )
+ ,m_pBox ( nullptr )
{
}
void InitializeStyles(const Reference < frame::XModel >& xModel)
{
+ aDefaultStyles.clear();
+
//now convert the default style names to the localized names
try
{
@@ -2564,14 +2615,12 @@ static const char* StyleSlotToStyleCommand[MAX_FAMILIES] =
".uno:TemplateFamily5"
};
-SvxStyleToolBoxControl::SvxStyleToolBoxControl(
- sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx )
- : SfxToolBoxControl ( nSlotId, nId, rTbx ),
- pImpl ( new Impl ),
- pStyleSheetPool ( nullptr ),
- nActFamily ( 0xffff )
+SvxStyleToolBoxControl::SvxStyleToolBoxControl()
+ : pImpl(new Impl)
+ , pStyleSheetPool(nullptr)
+ , nActFamily(0xffff)
{
- for ( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
+ for (sal_uInt16 i = 0; i < MAX_FAMILIES; ++i)
{
pBoundItems[i] = nullptr;
m_xBoundItems[i].clear();
@@ -2583,9 +2632,9 @@ SvxStyleToolBoxControl::~SvxStyleToolBoxControl()
{
}
-void SAL_CALL SvxStyleToolBoxControl::initialize( const Sequence< Any >& aArguments )
+void SAL_CALL SvxStyleToolBoxControl::initialize(const Sequence<Any>& rArguments)
{
- SfxToolBoxControl::initialize( aArguments );
+ svt::ToolboxController::initialize(rArguments);
// After initialize we should have a valid frame member where we can retrieve our
// dispatch provider.
@@ -2608,7 +2657,20 @@ void SAL_CALL SvxStyleToolBoxControl::initialize( const Sequence< Any >& aArgume
// XComponent
void SAL_CALL SvxStyleToolBoxControl::dispose()
{
- SfxToolBoxControl::dispose();
+ svt::ToolboxController::dispose();
+
+ SolarMutexGuard aSolarMutexGuard;
+ pImpl->m_xVclBox.disposeAndClear();
+ pImpl->m_xWeldBox.reset();
+ pImpl->m_pBox = nullptr;
+
+ for (SfxStyleControllerItem_Impl* pBoundItem : pBoundItems)
+ {
+ if (!pBoundItem)
+ continue;
+ pBoundItem->UnBind();
+ }
+ unbindListener();
for( sal_uInt16 i=0; i<MAX_FAMILIES; i++ )
{
@@ -2631,18 +2693,34 @@ void SAL_CALL SvxStyleToolBoxControl::dispose()
pImpl.reset();
}
-void SAL_CALL SvxStyleToolBoxControl::update()
+OUString SvxStyleToolBoxControl::getImplementationName()
{
- // Do nothing, we will start binding our listener when we are visible.
- // See link SvxStyleToolBoxControl::VisibilityNotification.
- SvxStyleBox_Impl* pBox = static_cast<SvxStyleBox_Impl*>(GetToolBox().GetItemWindow( GetId() ));
- if ( pBox->IsVisible() )
- {
- for (SfxStyleControllerItem_Impl* pBoundItem : pBoundItems)
- pBoundItem->ReBind();
+ return "com.sun.star.comp.svx.StyleToolBoxControl";
+}
- bindListener();
- }
+sal_Bool SvxStyleToolBoxControl::supportsService( const OUString& rServiceName )
+{
+ return cppu::supportsService( this, rServiceName );
+}
+
+css::uno::Sequence< OUString > SvxStyleToolBoxControl::getSupportedServiceNames()
+{
+ return { "com.sun.star.frame.ToolbarController" };
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
+com_sun_star_comp_svx_StyleToolBoxControl_get_implementation(
+ css::uno::XComponentContext*,
+ css::uno::Sequence<css::uno::Any> const & )
+{
+ return cppu::acquire( new SvxStyleToolBoxControl() );
+}
+
+void SAL_CALL SvxStyleToolBoxControl::update()
+{
+ for (SfxStyleControllerItem_Impl* pBoundItem : pBoundItems)
+ pBoundItem->ReBind();
+ bindListener();
}
SfxStyleFamily SvxStyleToolBoxControl::GetActFamily() const
@@ -2663,7 +2741,7 @@ SfxStyleFamily SvxStyleToolBoxControl::GetActFamily() const
void SvxStyleToolBoxControl::FillStyleBox()
{
- SvxStyleBox_Impl* pBox = static_cast<SvxStyleBox_Impl*>(GetToolBox().GetItemWindow( GetId() ));
+ SvxStyleBox_Base* pBox = pImpl->m_pBox;
DBG_ASSERT( pStyleSheetPool, "StyleSheetPool not found!" );
DBG_ASSERT( pBox, "Control not found!" );
@@ -2681,7 +2759,7 @@ void SvxStyleToolBoxControl::FillStyleBox()
pStyle = pStyleSheetPool->First();
//!!! TODO: This condition isn't right any longer, because we always show some default entries
//!!! so the list doesn't show the count
- if ( nCount != pBox->GetEntryCount() )
+ if ( nCount != pBox->get_count() )
{
bDoFill = true;
}
@@ -2690,7 +2768,7 @@ void SvxStyleToolBoxControl::FillStyleBox()
sal_uInt16 i= 0;
while ( pStyle && !bDoFill )
{
- bDoFill = ( pBox->GetEntry(i) != pStyle->GetName() );
+ bDoFill = ( pBox->get_text(i) != pStyle->GetName() );
pStyle = pStyleSheetPool->Next();
i++;
}
@@ -2698,8 +2776,11 @@ void SvxStyleToolBoxControl::FillStyleBox()
if ( bDoFill )
{
- pBox->SetUpdateMode( false );
- pBox->Clear();
+ OUString aStrSel(pBox->get_active_text());
+ pBox->freeze();
+ pBox->clear();
+
+ std::vector<OUString> aStyles;
{
pStyle = pStyleSheetPool->Next();
@@ -2721,7 +2802,7 @@ void SvxStyleToolBoxControl::FillStyleBox()
}
if( bInsert )
- pBox->InsertEntry( aName );
+ aStyles.push_back(aName);
pStyle = pStyleSheetPool->Next();
}
}
@@ -2729,64 +2810,54 @@ void SvxStyleToolBoxControl::FillStyleBox()
{
while ( pStyle )
{
- pBox->InsertEntry( pStyle->GetName() );
+ aStyles.push_back(pStyle->GetName());
pStyle = pStyleSheetPool->Next();
}
}
}
- if( pImpl->bSpecModeWriter || pImpl->bSpecModeCalc )
+ if (pImpl->bSpecModeWriter || pImpl->bSpecModeCalc)
{
- // disable sort to preserve special order
- WinBits nWinBits = pBox->GetStyle();
- nWinBits &= ~WB_SORT;
- pBox->SetStyle( nWinBits );
+ pBox->append_text(pImpl->aClearForm);
+ pBox->insert_separator(1, "separator");
// insert default styles
- sal_uInt16 nPos = 1;
- for( auto const & _i: pImpl->aDefaultStyles )
- {
- pBox->InsertEntry( _i, nPos );
- ++nPos;
- }
+ for (const auto &rStyle : pImpl->aDefaultStyles)
+ pBox->append_text(rStyle);
+ }
- pBox->InsertEntry( pImpl->aClearForm, 0 );
- pBox->SetSeparatorPos( 0 );
+ std::sort(aStyles.begin(), aStyles.end());
- pBox->InsertEntry( pImpl->aMore );
+ for (const auto& rStyle : aStyles)
+ pBox->append_text(rStyle);
- // enable sort again
- nWinBits |= WB_SORT;
- pBox->SetStyle( nWinBits );
- }
+ if (pImpl->bSpecModeWriter || pImpl->bSpecModeCalc)
+ pBox->append_text(pImpl->aMore);
- pBox->SetUpdateMode( true );
+ pBox->thaw();
+ pBox->set_active_or_entry_text(aStrSel);
pBox->SetFamily( eFamily );
-
- sal_uInt16 nLines = static_cast<sal_uInt16>(
- std::min( pBox->GetEntryCount(), static_cast<sal_Int32>(MAX_STYLES_ENTRIES)));
- pBox->SetDropDownLineCount( nLines );
}
}
}
void SvxStyleToolBoxControl::SelectStyle( const OUString& rStyleName )
{
- SvxStyleBox_Impl* pBox = static_cast<SvxStyleBox_Impl*>(GetToolBox().GetItemWindow( GetId() ));
+ SvxStyleBox_Base* pBox = pImpl->m_pBox;
DBG_ASSERT( pBox, "Control not found!" );
if ( pBox )
{
- OUString aStrSel( pBox->GetText() );
+ OUString aStrSel(pBox->get_active_text());
if ( !rStyleName.isEmpty() )
{
if ( rStyleName != aStrSel )
- pBox->SetText( rStyleName );
+ pBox->set_active_or_entry_text( rStyleName );
}
else
- pBox->SetNoSelection();
- pBox->SaveValue();
+ pBox->set_active(-1);
+ pBox->save_value();
}
}
@@ -2841,81 +2912,71 @@ void SvxStyleToolBoxControl::SetFamilyState( sal_uInt16 nIdx,
Update();
}
-IMPL_LINK_NOARG(SvxStyleToolBoxControl, VisibilityNotification, SvxStyleBox_Impl&, void)
+void SvxStyleToolBoxControl::statusChanged( const css::frame::FeatureStateEvent& rEvent )
{
- // Call ReBind() && UnBind() according to visibility
- SvxStyleBox_Impl* pBox = static_cast<SvxStyleBox_Impl*>( GetToolBox().GetItemWindow( GetId() ));
-
- if ( pBox && pBox->IsVisible() && !isBound() )
- {
- for (SfxStyleControllerItem_Impl* pBoundItem : pBoundItems)
- pBoundItem->ReBind();
+ SolarMutexGuard aGuard;
- bindListener();
- }
- else if ( (!pBox || !pBox->IsVisible()) && isBound() )
+ if (m_pToolbar)
+ m_pToolbar->set_item_sensitive(m_aCommandURL.toUtf8(), rEvent.IsEnabled);
+ else
{
- for (SfxStyleControllerItem_Impl* pBoundItem : pBoundItems)
- pBoundItem->UnBind();
- unbindListener();
+ ToolBox* pToolBox = nullptr;
+ sal_uInt16 nId = 0;
+ if (!getToolboxId( nId, &pToolBox ) )
+ return;
+ pToolBox->EnableItem( nId, rEvent.IsEnabled );
}
+
+ if (rEvent.IsEnabled)
+ Update();
}
-void SvxStyleToolBoxControl::StateChanged(
- sal_uInt16 , SfxItemState eState, const SfxPoolItem* pState )
+css::uno::Reference<css::awt::XWindow> SvxStyleToolBoxControl::createItemWindow(const css::uno::Reference< css::awt::XWindow>& rParent)
{
- sal_uInt16 nId = GetId();
- ToolBox& rTbx = GetToolBox();
- SvxStyleBox_Impl* pBox = static_cast<SvxStyleBox_Impl*>(rTbx.GetItemWindow( nId ));
- TriState eTri = TRISTATE_FALSE;
+ uno::Reference< awt::XWindow > xItemWindow;
- DBG_ASSERT( pBox, "Control not found!" );
+ if (m_pBuilder)
+ {
+ SolarMutexGuard aSolarMutexGuard;
- if ( SfxItemState::DISABLED == eState )
- pBox->Disable();
- else
- pBox->Enable();
+ std::unique_ptr<weld::ComboBox> xWidget(m_pBuilder->weld_combo_box("applystyle"));
- rTbx.EnableItem( nId, SfxItemState::DISABLED != eState );
+ xItemWindow = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get()));
- switch ( eState )
+ pImpl->m_xWeldBox.reset(new SvxStyleBox_Base(std::move(xWidget),
+ ".uno:StyleApply",
+ SfxStyleFamily::Para,
+ Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ),
+ m_xFrame,
+ pImpl->aClearForm,
+ pImpl->aMore,
+ pImpl->bSpecModeWriter || pImpl->bSpecModeCalc, *this));
+ pImpl->m_pBox = pImpl->m_xWeldBox.get();
+ }
+ else
{
- case SfxItemState::DEFAULT:
- eTri = static_cast<const SfxTemplateItem*>(pState)->GetValue() != SfxStyleSearchBits::Auto
- ? TRISTATE_TRUE
- : TRISTATE_FALSE;
- break;
-
- case SfxItemState::DONTCARE:
- eTri = TRISTATE_INDET;
- break;
+ VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent);
+ if ( pParent )
+ {
+ SolarMutexGuard aSolarMutexGuard;
- default:
- break;
+ pImpl->m_xVclBox = VclPtr<SvxStyleBox_Impl>::Create(pParent,
+ ".uno:StyleApply",
+ SfxStyleFamily::Para,
+ Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ),
+ m_xFrame,
+ pImpl->aClearForm,
+ pImpl->aMore,
+ pImpl->bSpecModeWriter || pImpl->bSpecModeCalc, *this);
+ pImpl->m_pBox = pImpl->m_xVclBox.get();
+ xItemWindow = VCLUnoHelper::GetInterface(pImpl->m_xVclBox);
+ }
}
- rTbx.SetItemState( nId, eTri );
-
- if ( SfxItemState::DISABLED != eState )
- Update();
-}
-
-VclPtr<vcl::Window> SvxStyleToolBoxControl::CreateItemWindow( vcl::Window *pParent )
-{
- VclPtrInstance<SvxStyleBox_Impl> pBox( pParent,
- OUString( ".uno:StyleApply" ),
- SfxStyleFamily::Para,
- Reference< XDispatchProvider >( m_xFrame->getController(), UNO_QUERY ),
- m_xFrame,
- pImpl->aClearForm,
- pImpl->aMore,
- pImpl->bSpecModeWriter || pImpl->bSpecModeCalc );
- if( !pImpl->aDefaultStyles.empty())
- pBox->SetDefaultStyle( pImpl->aDefaultStyles[0] );
- // Set visibility listener to bind/unbind controller
- pBox->SetVisibilityListener( LINK( this, SvxStyleToolBoxControl, VisibilityNotification ));
+ if (pImpl->m_pBox && !pImpl->aDefaultStyles.empty())
+ pImpl->m_pBox->SetDefaultStyle(pImpl->aDefaultStyles[0]);
- return pBox.get();
+ return xItemWindow;
}
SvxFontNameToolBoxControl::SvxFontNameToolBoxControl()
@@ -2960,7 +3021,7 @@ void SvxFontNameToolBoxControl::statusChanged( const css::frame::FeatureStateEve
}
}
-css::uno::Reference< css::awt::XWindow > SvxFontNameToolBoxControl::createItemWindow( const css::uno::Reference< css::awt::XWindow >& rParent )
+css::uno::Reference<css::awt::XWindow> SvxFontNameToolBoxControl::createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent)
{
uno::Reference< awt::XWindow > xItemWindow;