summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2020-02-07 13:25:08 +0000
committerCaolán McNamara <caolanm@redhat.com>2020-02-07 20:49:04 +0100
commit75bd1ba4cd4eea179092f3c8fd7aa6b903b17993 (patch)
treed9e335d66aa66fd2e96a13cea0af45d8ed69cc70
parent08695569fd4fccc1722e7e3c7e0a234699199196 (diff)
weld ImplGrafControl ItemWindow
Change-Id: I1c3551ffe510d49ea7ddce9d896f59857f4b2946 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88213 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--solenv/sanitizers/ui/svx.suppr1
-rw-r--r--svx/UIConfig_svx.mk1
-rw-r--r--svx/source/tbxctrls/grafctrl.cxx191
-rw-r--r--svx/uiconfig/ui/grafctrlbox.ui41
4 files changed, 109 insertions, 125 deletions
diff --git a/solenv/sanitizers/ui/svx.suppr b/solenv/sanitizers/ui/svx.suppr
index 0c4cd85cf614..2037cc5c2d90 100644
--- a/solenv/sanitizers/ui/svx.suppr
+++ b/solenv/sanitizers/ui/svx.suppr
@@ -40,6 +40,7 @@ svx/uiconfig/ui/findreplacedialog.ui://GtkLabel[@id='searchdir'] orphan-label
svx/uiconfig/ui/floatingcontour.ui://GtkLabel[@id='statuspos'] orphan-label
svx/uiconfig/ui/floatingcontour.ui://GtkLabel[@id='statussize'] orphan-label
svx/uiconfig/ui/fontworkgallerydialog.ui://GtkLabel[@id='label1'] orphan-label
+svx/uiconfig/ui/grafctrlbox.ui://GtkSpinButton[@id='spinfield'] no-labelled-by
svx/uiconfig/ui/headfootformatpage.ui://GtkLabel[@id='labelHeaderFormat'] orphan-label
svx/uiconfig/ui/headfootformatpage.ui://GtkLabel[@id='labelFooterFormat'] orphan-label
svx/uiconfig/ui/imapdialog.ui://GtkLabel[@id='statusurl'] orphan-label
diff --git a/svx/UIConfig_svx.mk b/svx/UIConfig_svx.mk
index d43fb789f426..69a7e7ea6e92 100644
--- a/svx/UIConfig_svx.mk
+++ b/svx/UIConfig_svx.mk
@@ -68,6 +68,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svx,\
svx/uiconfig/ui/functionmenu \
svx/uiconfig/ui/gallerymenu1 \
svx/uiconfig/ui/gallerymenu2 \
+ svx/uiconfig/ui/grafctrlbox \
svx/uiconfig/ui/grafmodebox \
svx/uiconfig/ui/headfootformatpage \
svx/uiconfig/ui/imapdialog \
diff --git a/svx/source/tbxctrls/grafctrl.cxx b/svx/source/tbxctrls/grafctrl.cxx
index 3f8c084e06f7..dbbea77c8d37 100644
--- a/svx/source/tbxctrls/grafctrl.cxx
+++ b/svx/source/tbxctrls/grafctrl.cxx
@@ -72,78 +72,50 @@ using namespace ::com::sun::star::lang;
#include <svx/svxdlg.hxx>
-#define SYMBOL_TO_FIELD_OFFSET 4
#define TOOLBOX_NAME "colorbar"
#define RID_SVXSTR_UNDO_GRAFCROP RID_SVXSTR_GRAFCROP
namespace {
-class ImplGrafMetricField : public MetricField
+class ImplGrafControl final : public InterimItemWindow
{
- using Window::Update;
-
private:
- Idle maIdle;
- OUString const maCommand;
- Reference< XFrame > mxFrame;
-
- DECL_LINK(ImplModifyHdl, Timer *, void);
-
-protected:
+ Idle maIdle;
+ OUString maCommand;
+ Reference<XFrame> mxFrame;
+ std::unique_ptr<weld::Image> mxImage;
+ std::unique_ptr<weld::MetricSpinButton> mxField;
- virtual void Modify() override;
+ DECL_LINK(ValueChangedHdl, weld::MetricSpinButton&, void);
+ DECL_LINK(KeyInputHdl, const KeyEvent&, bool);
+ DECL_LINK(ImplModifyHdl, Timer*, void);
public:
- ImplGrafMetricField( vcl::Window* pParent, const OUString& aCmd, const Reference< XFrame >& rFrame );
-
- void Update( const SfxPoolItem* pItem );
-};
-
-}
-
-ImplGrafMetricField::ImplGrafMetricField( vcl::Window* pParent, const OUString& rCmd, const Reference< XFrame >& rFrame ) :
- MetricField( pParent, WB_BORDER | WB_SPIN | WB_REPEAT | WB_3DLOOK ),
- maCommand( rCmd ),
- mxFrame( rFrame )
-{
- Size aSize(CalcMinimumSizeForText(unicode::formatPercent(-100, Application::GetSettings().GetUILanguageTag())));
- SetSizePixel(aSize);
-
- if ( maCommand == ".uno:GrafGamma" )
- {
- SetDecimalDigits( 2 );
+ ImplGrafControl( vcl::Window* pParent, const OUString& rCmd, const Reference< XFrame >& rFrame );
+ virtual ~ImplGrafControl() override;
+ virtual void dispose() override;
- SetMin( 10 );
- SetFirst( 10 );
- SetMax( 1000 );
- SetLast( 1000 );
- SetSpinSize( 10 );
- }
- else
+ virtual void GetFocus() override;
+ void Update( const SfxPoolItem* pItem );
+ void set_field_text(const OUString& rStr) { mxField->set_text(rStr); }
+ void set_sensitive(bool bSensitive)
{
- const long nMinVal = maCommand == ".uno:GrafTransparence" ? 0 : -100;
-
- SetUnit(FieldUnit::PERCENT);
- SetDecimalDigits( 0 );
-
- SetMin( nMinVal );
- SetFirst( nMinVal );
- SetMax( 100 );
- SetLast( 100 );
- SetSpinSize( 1 );
+ Enable(bSensitive);
+ mxImage->set_sensitive(bSensitive);
+ mxField->set_sensitive(bSensitive);
}
+};
- maIdle.SetInvokeHandler( LINK( this, ImplGrafMetricField, ImplModifyHdl ) );
}
-void ImplGrafMetricField::Modify()
+IMPL_LINK_NOARG(ImplGrafControl, ValueChangedHdl, weld::MetricSpinButton&, void)
{
maIdle.Start();
}
-IMPL_LINK_NOARG(ImplGrafMetricField, ImplModifyHdl, Timer *, void)
+IMPL_LINK_NOARG(ImplGrafControl, ImplModifyHdl, Timer*, void)
{
- const sal_Int64 nVal = GetValue();
+ const sal_Int64 nVal = mxField->get_value(FieldUnit::NONE);
// Convert value to an any to be usable with dispatch API
Any a;
@@ -172,7 +144,7 @@ IMPL_LINK_NOARG(ImplGrafMetricField, ImplModifyHdl, Timer *, void)
}
}
-void ImplGrafMetricField::Update( const SfxPoolItem* pItem )
+void ImplGrafControl::Update( const SfxPoolItem* pItem )
{
if( pItem )
{
@@ -185,10 +157,10 @@ void ImplGrafMetricField::Update( const SfxPoolItem* pItem )
else
nValue = static_cast<const SfxInt16Item*>( pItem )->GetValue();
- SetValue( nValue );
+ mxField->set_value(nValue, FieldUnit::NONE);
}
else
- SetText( OUString() );
+ mxField->set_text(OUString());
}
namespace {
@@ -231,76 +203,56 @@ static OUString ImplGetRID( const OUString& aCommand )
return sRID;
}
-namespace {
-
-class ImplGrafControl : public Control
-{
- using Window::Update;
-private:
- VclPtr<FixedImage> maImage;
- VclPtr<ImplGrafMetricField> maField;
-
-protected:
-
- virtual void GetFocus() override;
-
-public:
-
- ImplGrafControl( vcl::Window* pParent, const OUString& rCmd, const Reference< XFrame >& rFrame );
- virtual ~ImplGrafControl() override;
- virtual void dispose() override;
-
- void Update( const SfxPoolItem* pItem ) { maField->Update( pItem ); }
- void SetText( const OUString& rStr ) override { maField->SetText( rStr ); }
- virtual void Resize() override;
-};
-
-}
-
ImplGrafControl::ImplGrafControl(
vcl::Window* pParent,
const OUString& rCmd,
- const Reference< XFrame >& rFrame
-) : Control( pParent, WB_TABSTOP )
- , maImage( VclPtr<FixedImage>::Create(this) )
- , maField( VclPtr<ImplGrafMetricField>::Create(this, rCmd, rFrame) )
+ const Reference< XFrame >& rFrame)
+ : InterimItemWindow(pParent, "svx/ui/grafctrlbox.ui", "GrafCtrlBox")
+ , maCommand(rCmd)
+ , mxFrame(rFrame)
+ , mxImage(m_xBuilder->weld_image("image"))
+ , mxField(m_xBuilder->weld_metric_spin_button("spinfield", FieldUnit::NONE))
{
OUString sResId(ImplGetRID(rCmd));
- BitmapEx aBitmapEx(sResId);
-
- Size aImgSize(aBitmapEx.GetSizePixel());
- Size aFldSize(maField->GetSizePixel());
- long nFldY, nImgY;
-
- maImage->SetImage(Image(aBitmapEx));
- maImage->SetSizePixel( aImgSize );
+ mxImage->set_from_icon_name(sResId);
+#if 0
// we want to see the background of the toolbox, not of the FixedImage or Control
maImage->SetBackground( Wallpaper( COL_TRANSPARENT ) );
SetBackground( Wallpaper( COL_TRANSPARENT ) );
+#endif
- if( aImgSize.Height() > aFldSize.Height() )
+ SetBackground( Wallpaper() ); // transparent background
+
+ mxField->set_help_id(OUStringToOString(rCmd, RTL_TEXTENCODING_UTF8));
+ mxField->get_widget().connect_key_press(LINK(this, ImplGrafControl, KeyInputHdl));
+ mxField->connect_value_changed(LINK(this, ImplGrafControl, ValueChangedHdl));
+
+ if (maCommand == ".uno:GrafGamma")
{
- nImgY = 0;
- nFldY = ( aImgSize.Height() - aFldSize.Height() ) >> 1;
+ mxField->set_digits(2);
+
+ mxField->set_range(10, 1000, FieldUnit::NONE);
+ mxField->set_increments(10, 100, FieldUnit::NONE);
}
else
{
- nFldY = 0;
- nImgY = ( aFldSize.Height() - aImgSize.Height() ) >> 1;
- }
+ const long nMinVal = maCommand == ".uno:GrafTransparence" ? 0 : -100;
- long nOffset = SYMBOL_TO_FIELD_OFFSET / 2;
- maImage->SetPosPixel( Point( nOffset, nImgY ) );
- maField->SetPosPixel( Point( aImgSize.Width() + SYMBOL_TO_FIELD_OFFSET, nFldY ) );
- SetSizePixel( Size( aImgSize.Width() + aFldSize.Width() + SYMBOL_TO_FIELD_OFFSET + nOffset,
- std::max( aImgSize.Height(), aFldSize.Height() ) ) );
+ mxField->set_unit(FieldUnit::PERCENT);
+ mxField->set_digits(0);
- SetBackground( Wallpaper() ); // transparent background
+ mxField->set_range(nMinVal, 100, FieldUnit::PERCENT);
+ mxField->set_increments(1, 10, FieldUnit::PERCENT);
+ }
- maImage->Show();
+ maIdle.SetInvokeHandler( LINK( this, ImplGrafControl, ImplModifyHdl ) );
- maField->SetHelpId( OUStringToOString( rCmd, RTL_TEXTENCODING_UTF8 ) );
- maField->Show();
+ SetSizePixel(m_xContainer->get_preferred_size());
+}
+
+IMPL_LINK(ImplGrafControl, KeyInputHdl, const KeyEvent&, rKEvt, bool)
+{
+ return ChildKeyInput(rKEvt);
}
ImplGrafControl::~ImplGrafControl()
@@ -310,24 +262,14 @@ ImplGrafControl::~ImplGrafControl()
void ImplGrafControl::dispose()
{
- maImage.disposeAndClear();
- maField.disposeAndClear();
- Control::dispose();
+ mxImage.reset();
+ mxField.reset();
+ InterimItemWindow::dispose();
}
void ImplGrafControl::GetFocus()
{
- if (maField)
- maField->GrabFocus();
-}
-
-void ImplGrafControl::Resize()
-{
- Size aFldSize(maField->GetSizePixel());
- aFldSize.setWidth( GetSizePixel().Width() - SYMBOL_TO_FIELD_OFFSET - maImage->GetSizePixel().Width() );
- maField->SetSizePixel(aFldSize);
-
- Control::Resize();
+ mxField->grab_focus();
}
namespace {
@@ -467,19 +409,18 @@ SvxGrafToolBoxControl::~SvxGrafToolBoxControl()
}
void SvxGrafToolBoxControl::StateChanged( sal_uInt16, SfxItemState eState, const SfxPoolItem* pState )
-
{
ImplGrafControl* pCtrl = static_cast<ImplGrafControl*>( GetToolBox().GetItemWindow( GetId() ) );
DBG_ASSERT( pCtrl, "Control not found" );
if( eState == SfxItemState::DISABLED )
{
- pCtrl->Disable();
- pCtrl->SetText( OUString() );
+ pCtrl->set_sensitive(false);
+ pCtrl->set_field_text( OUString() );
}
else
{
- pCtrl->Enable();
+ pCtrl->set_sensitive(true);
if( eState == SfxItemState::DEFAULT )
pCtrl->Update( pState );
diff --git a/svx/uiconfig/ui/grafctrlbox.ui b/svx/uiconfig/ui/grafctrlbox.ui
new file mode 100644
index 000000000000..b5088dd3337c
--- /dev/null
+++ b/svx/uiconfig/ui/grafctrlbox.ui
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface domain="svx">
+ <requires lib="gtk+" version="3.18"/>
+ <object class="GtkAdjustment" id="adjustment1">
+ <property name="upper">100</property>
+ <property name="step_increment">1</property>
+ <property name="page_increment">10</property>
+ </object>
+ <object class="GtkBox" id="GrafCtrlBox">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="hexpand">True</property>
+ <property name="spacing">4</property>
+ <child>
+ <object class="GtkImage" id="image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="stock">gtk-missing-image</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="spinfield">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="adjustment">adjustment1</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+</interface>