From cf4b65c75c07142be0fcab5835188a28e839b749 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Thu, 8 Mar 2018 12:17:56 +0000 Subject: [PATCH] weld color picker MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I487b9a0cc13b2b60a0f1e28667773b5d3b5c66cc Reviewed-on: https://gerrit.libreoffice.org/51001 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- compilerplugins/clang/store/fpcomparison.cxx | 2 - cui/inc/bitmaps.hlst | 1 - cui/source/dialogs/colorpicker.cxx | 802 ++++++++---------- cui/uiconfig/ui/colorpickerdialog.ui | 136 +-- .../source/glade/libreoffice-catalog.xml.in | 9 - .../{colorslider.png => colorsliderleft.png} | Bin icon-themes/galaxy/res/colorsliderright.png | Bin 0 -> 203 bytes .../{colorslider.png => colorsliderleft.png} | Bin icon-themes/tango/res/colorsliderright.png | Bin 0 -> 203 bytes include/svx/hexcolorcontrol.hxx | 20 + include/vcl/layout.hxx | 41 +- include/vcl/weld.hxx | 21 +- sfx2/source/doc/new.cxx | 5 +- sfx2/source/inc/preview.hxx | 2 +- svx/source/dialog/hexcolorcontrol.cxx | 63 ++ sw/source/ui/table/autoformatpreview.cxx | 4 +- sw/source/uibase/inc/autoformatpreview.hxx | 2 +- vcl/source/app/salvtables.cxx | 51 +- vcl/unx/gtk3/gtk3gtkinst.cxx | 192 ++++- 19 files changed, 802 insertions(+), 549 deletions(-) rename icon-themes/galaxy/res/{colorslider.png => colorsliderleft.png} (100%) create mode 100644 icon-themes/galaxy/res/colorsliderright.png rename icon-themes/tango/res/{colorslider.png => colorsliderleft.png} (100%) create mode 100644 icon-themes/tango/res/colorsliderright.png diff --git a/compilerplugins/clang/store/fpcomparison.cxx b/compilerplugins/clang/store/fpcomparison.cxx index b914d7084bc4..0e27ed9819f4 100644 --- a/compilerplugins/clang/store/fpcomparison.cxx +++ b/compilerplugins/clang/store/fpcomparison.cxx @@ -231,8 +231,6 @@ bool FpComparison::ignore(FunctionDecl* function) || dc.Function("ApplySpecialItem").Class("TitleItemConverter").Namespace("wrapper").Namespace("chart").GlobalNamespace() || dc.Function("ApplySpecialItem").Class("TextLabelItemConverter").Namespace("wrapper").Namespace("chart").GlobalNamespace() || dc.Function("operate").Class("OOp_COMPARE").Namespace("file").Namespace("connectivity").GlobalNamespace() - || dc.Function("SetValues").Class("ColorFieldControl").Namespace("cui").GlobalNamespace() - || dc.Function("SetValue").Class("ColorSliderControl").Namespace("cui").GlobalNamespace() || dc.Function("Write").Class("ORTFImportExport").Namespace("dbaui").GlobalNamespace() || dc.Function("appendRow").Class("ORTFImportExport").Namespace("dbaui").GlobalNamespace() || dc.Function("WriteCell").Class("OHTMLImportExport").Namespace("dbaui").GlobalNamespace() diff --git a/cui/inc/bitmaps.hlst b/cui/inc/bitmaps.hlst index dc1ce4a6a9e4..2cefabd14611 100644 --- a/cui/inc/bitmaps.hlst +++ b/cui/inc/bitmaps.hlst @@ -63,7 +63,6 @@ #define RID_SVXBMP_FILEOPEN "res/fileopen.png" #define RID_SVXBMP_TARGET "res/target.png" #define RID_SVXBMP_NEWDOC "res/newdoc.png" -#define RID_SVXBMP_COLORSLIDER "res/colorslider.png" #define RID_SVXBMP_COLLAPSEDNODE "res/sx18002.png" #define RID_SVXBMP_EXPANDEDNODE "res/sx18003.png" diff --git a/cui/source/dialogs/colorpicker.cxx b/cui/source/dialogs/colorpicker.cxx index 756c0d5aed6f..70a059a29014 100644 --- a/cui/source/dialogs/colorpicker.cxx +++ b/cui/source/dialogs/colorpicker.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -150,61 +151,85 @@ static void RGBtoCMYK( double dR, double dG, double dB, double& fCyan, double& f } } -class ColorPreviewControl : public Control +class ColorPreviewControl { -public: - ColorPreviewControl( vcl::Window* pParent, WinBits nStyle ); - - virtual void Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle& rRect) override; - - void SetColor(const Color& rColor); - private: - Color maColor; + std::unique_ptr m_xDrawingArea; + Color m_aColor; + Size m_aSize; + + DECL_LINK(DoPaint, weld::DrawingArea::draw_args, void); + DECL_LINK(DoResize, const Size& rSize, void); +public: + ColorPreviewControl(weld::DrawingArea* pDrawingArea) + : m_xDrawingArea(pDrawingArea) + { + m_xDrawingArea->connect_size_allocate(LINK(this, ColorPreviewControl, DoResize)); + m_xDrawingArea->connect_draw(LINK(this, ColorPreviewControl, DoPaint)); + m_xDrawingArea->set_size_request(m_xDrawingArea->get_approximate_char_width() * 10, + m_xDrawingArea->get_text_height() * 2); + + } + + void SetColor(const Color& rCol) + { + if (rCol != m_aColor) + { + m_aColor = rCol; + m_xDrawingArea->queue_draw(); + } + } + + void show() { m_xDrawingArea->show(); } }; -ColorPreviewControl::ColorPreviewControl(vcl::Window* pParent, WinBits nStyle) - : Control(pParent, nStyle) +IMPL_LINK(ColorPreviewControl, DoPaint, weld::DrawingArea::draw_args, aPayload, void) { + vcl::RenderContext& rRenderContext = aPayload.first; + rRenderContext.SetFillColor(m_aColor); + rRenderContext.SetLineColor(m_aColor); + rRenderContext.DrawRect(tools::Rectangle(Point(0, 0), m_aSize)); } -VCL_BUILDER_FACTORY_CONSTRUCTOR(ColorPreviewControl, 0) - -void ColorPreviewControl::SetColor( const Color& rCol ) +IMPL_LINK(ColorPreviewControl, DoResize, const Size&, rSize, void) { - if (rCol != maColor) + if (m_aSize != rSize) { - maColor = rCol; - Invalidate(); + m_aSize = rSize; + m_xDrawingArea->queue_draw(); } } -void ColorPreviewControl::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle& rRect) -{ - rRenderContext.SetFillColor(maColor); - rRenderContext.SetLineColor(maColor); - rRenderContext.DrawRect(rRect); -} - enum ColorMode { HUE, SATURATION, BRIGHTNESS, RED, GREEN, BLUE }; const ColorMode DefaultMode = HUE; -class ColorFieldControl : public Control +class ColorFieldControl { public: - ColorFieldControl(vcl::Window* pParent, WinBits nStyle); - virtual ~ColorFieldControl() override; + ColorFieldControl(weld::DrawingArea* pDrawingArea) + : m_xDrawingArea(pDrawingArea) + , meMode( DefaultMode ) + , mdX( -1.0 ) + , mdY( -1.0 ) + { + m_xDrawingArea->set_size_request(m_xDrawingArea->get_approximate_char_width() * 40, + m_xDrawingArea->get_text_height() * 10); + m_xDrawingArea->connect_size_allocate(LINK(this, ColorFieldControl, DoResize)); + m_xDrawingArea->connect_draw(LINK(this, ColorFieldControl, DoPaint)); + m_xDrawingArea->connect_mouse_press(LINK(this, ColorFieldControl, DoButtonDown)); + m_xDrawingArea->connect_mouse_release(LINK(this, ColorFieldControl, DoButtonUp)); + } - virtual void dispose() override; + ~ColorFieldControl() + { + mxBitmap.disposeAndClear(); + } - virtual void MouseMove( const MouseEvent& rMEvt ) override; - virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; - virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; - virtual void KeyInput( const KeyEvent& rKEvt ) override; - virtual void Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle& rRect) override; - virtual void Resize() override; - - virtual Size GetOptimalSize() const override; + DECL_LINK(DoPaint, weld::DrawingArea::draw_args, void); + DECL_LINK(DoResize, const Size& rSize, void); + DECL_LINK(DoButtonDown, const Point& rMEvt, void); + DECL_LINK(DoMouseMove, const Point& rMEvt, void); + DECL_LINK(DoButtonUp, const Point& rMEvt, void); void UpdateBitmap(); void ShowPosition( const Point& rPos, bool bUpdate ); @@ -215,18 +240,18 @@ public: double GetX() { return mdX;} double GetY() { return mdY;} - void KeyMove(int dx, int dy); - void SetModifyHdl(const Link& rLink) { maModifyHdl = rLink; } private: - Link maModifyHdl; + std::unique_ptr m_xDrawingArea; + Size m_aSize; ColorMode meMode; Color maColor; double mdX; double mdY; Point maPosition; VclPtr mxBitmap; + Link maModifyHdl; std::vector maRGB_Horiz; std::vector maGrad_Horiz; std::vector maPercent_Horiz; @@ -234,36 +259,9 @@ private: std::vector maPercent_Vert; }; -ColorFieldControl::ColorFieldControl( vcl::Window* pParent, WinBits nStyle ) -: Control( pParent, nStyle ) -, meMode( DefaultMode ) -, mdX( -1.0 ) -, mdY( -1.0 ) -{ - SetControlBackground(); -} - -ColorFieldControl::~ColorFieldControl() -{ - disposeOnce(); -} - -void ColorFieldControl::dispose() -{ - mxBitmap.disposeAndClear(); - Control::dispose(); -} - -VCL_BUILDER_FACTORY_CONSTRUCTOR(ColorFieldControl, 0) - -Size ColorFieldControl::GetOptimalSize() const -{ - return LogicToPixel(Size(158, 158), MapMode(MapUnit::MapAppFont)); -} - void ColorFieldControl::UpdateBitmap() { - const Size aSize(GetOutputSizePixel()); + const Size aSize(m_aSize); if (mxBitmap && mxBitmap->GetOutputSizePixel() != aSize) mxBitmap.disposeAndClear(); @@ -405,7 +403,7 @@ void ColorFieldControl::ShowPosition( const Point& rPos, bool bUpdate ) if (!mxBitmap) { UpdateBitmap(); - Invalidate(); + m_xDrawingArea->queue_draw(); } if (!mxBitmap) @@ -428,8 +426,8 @@ void ColorFieldControl::ShowPosition( const Point& rPos, bool bUpdate ) Point aPos = maPosition; maPosition.setX( nX - 5 ); maPosition.setY( nY - 5 ); - Invalidate(::tools::Rectangle(aPos, Size(11, 11))); - Invalidate(::tools::Rectangle(maPosition, Size(11, 11))); + m_xDrawingArea->queue_draw_area(aPos.X(), aPos.Y(), 11, 11); + m_xDrawingArea->queue_draw_area(maPosition.X(), maPosition.Y(), 11, 11); if (bUpdate) { @@ -440,85 +438,32 @@ void ColorFieldControl::ShowPosition( const Point& rPos, bool bUpdate ) } } -void ColorFieldControl::MouseMove( const MouseEvent& rMEvt ) +IMPL_LINK(ColorFieldControl, DoButtonDown, const Point&, rMEvt, void) { - if( rMEvt.IsLeft() ) - { - ShowPosition( rMEvt.GetPosPixel(), true ); - Modify(); - } -} - -void ColorFieldControl::MouseButtonDown( const MouseEvent& rMEvt ) -{ - if( rMEvt.IsLeft() && !rMEvt.IsShift() ) - { - CaptureMouse(); - ShowPosition( rMEvt.GetPosPixel(), true ); - Modify(); - } -} - -void ColorFieldControl::MouseButtonUp( const MouseEvent& ) -{ - if( IsMouseCaptured() ) - ReleaseMouse(); -} - -void ColorFieldControl::KeyMove( int dx, int dy ) -{ - Size aSize(GetOutputSizePixel()); - Point aPos(static_cast(mdX * aSize.Width()), static_cast((1.0 - mdY) * aSize.Height())); - aPos.AdjustX(dx ); - aPos.AdjustY(dy ); - if( aPos.X() < 0 ) - aPos.AdjustX(aSize.Width() ); - else if( aPos.X() >= aSize.Width() ) - aPos.AdjustX( -(aSize.Width()) ); - - if( aPos.Y() < 0 ) - aPos.AdjustY(aSize.Height() ); - else if( aPos.Y() >= aSize.Height() ) - aPos.AdjustY( -(aSize.Height()) ); - - ShowPosition( aPos, true ); + m_xDrawingArea->connect_mouse_move(LINK(this, ColorFieldControl, DoMouseMove)); + ShowPosition(rMEvt, true); Modify(); } -void ColorFieldControl::KeyInput( const KeyEvent& rKEvt ) +IMPL_LINK(ColorFieldControl, DoMouseMove, const Point&, rMEvt, void) { - bool bShift = rKEvt.GetKeyCode().IsShift(); - bool bCtrl = rKEvt.GetKeyCode().IsMod1(); - bool bAlt = rKEvt.GetKeyCode().IsMod2(); - - if (!bAlt && !bShift) - { - switch( rKEvt.GetKeyCode().GetCode() ) - { - case KEY_DOWN: - KeyMove(0, bCtrl ? 5 : 1); - return; - case KEY_UP: - KeyMove(0, bCtrl ? -5 : -1); - return; - case KEY_LEFT: - KeyMove(bCtrl ? -5 : -1, 0); - return; - case KEY_RIGHT: - KeyMove(bCtrl ? 5 : 1, 0); - return; - } - } - Control::KeyInput(rKEvt); + ShowPosition(rMEvt, true); + Modify(); } -void ColorFieldControl::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle& rRect) +IMPL_LINK_NOARG(ColorFieldControl, DoButtonUp, const Point&, void) { + m_xDrawingArea->connect_mouse_move(Link()); +} + +IMPL_LINK(ColorFieldControl, DoPaint, weld::DrawingArea::draw_args, aPayload, void) +{ + vcl::RenderContext& rRenderContext = aPayload.first; if (!mxBitmap) UpdateBitmap(); if (mxBitmap) - rRenderContext.DrawOutDev(rRect.TopLeft(), rRect.GetSize(), rRect.TopLeft(), rRect.GetSize(), *mxBitmap); + rRenderContext.DrawOutDev(Point(0, 0), m_aSize, Point(0, 0), m_aSize, *mxBitmap); // draw circle around current color if (maColor.IsDark()) @@ -531,11 +476,15 @@ void ColorFieldControl::Paint(vcl::RenderContext& rRenderContext, const ::tools: rRenderContext.DrawEllipse(::tools::Rectangle(maPosition, Size(11, 11))); } -void ColorFieldControl::Resize() +IMPL_LINK(ColorFieldControl, DoResize, const Size&, rSize, void) { - UpdateBitmap(); - UpdatePosition(); - Control::Resize(); + if (m_aSize != rSize) + { + m_aSize = rSize; + UpdateBitmap(); + UpdatePosition(); + m_xDrawingArea->queue_draw(); + } } void ColorFieldControl::Modify() @@ -557,29 +506,27 @@ void ColorFieldControl::SetValues( Color aColor, ColorMode eMode, double x, doub UpdateBitmap(); UpdatePosition(); if (bUpdateBitmap) - Invalidate(); + m_xDrawingArea->queue_draw(); } } void ColorFieldControl::UpdatePosition() { - Size aSize(GetOutputSizePixel()); + Size aSize(m_aSize); ShowPosition(Point(static_cast(mdX * aSize.Width()), static_cast((1.0 - mdY) * aSize.Height())), false); } -class ColorSliderControl : public Control +class ColorSliderControl { public: - ColorSliderControl( vcl::Window* pParent, WinBits nStyle ); - virtual ~ColorSliderControl() override; - virtual void dispose() override; + ColorSliderControl(weld::DrawingArea* pDrawingArea); + ~ColorSliderControl(); - virtual void MouseMove( const MouseEvent& rMEvt ) override; - virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; - virtual void MouseButtonUp( const MouseEvent& rMEvt ) override; - virtual void KeyInput( const KeyEvent& rKEvt ) override; - virtual void Paint( vcl::RenderContext& rRenderContext, const ::tools::Rectangle& rRect ) override; - virtual void Resize() override; + DECL_LINK(DoButtonDown, const Point& rMEvt, void); + DECL_LINK(DoMouseMove, const Point& rMEvt, void); + DECL_LINK(DoButtonUp, const Point& rMEvt, void); + DECL_LINK(DoPaint, weld::DrawingArea::draw_args, void); + DECL_LINK(DoResize, const Size& rSize, void); void UpdateBitmap(); void ChangePosition( long nY ); @@ -588,14 +535,17 @@ public: void SetValue( const Color& rColor, ColorMode eMode, double dValue ); double GetValue() const { return mdValue; } - void KeyMove( int dy ); - void SetModifyHdl( const Link& rLink ) { maModifyHdl = rLink; } sal_Int16 GetLevel() const { return mnLevel; } + void set_margin_top(int nMargin) { m_xDrawingArea->set_margin_top(nMargin); } + void set_margin_bottom(int nMargin) { m_xDrawingArea->set_margin_bottom(nMargin); } + private: Link maModifyHdl; + std::unique_ptr m_xDrawingArea; + Size m_aSize; Color maColor; ColorMode meMode; VclPtr mxBitmap; @@ -603,31 +553,27 @@ private: double mdValue; }; -ColorSliderControl::ColorSliderControl( vcl::Window* pParent, WinBits nStyle ) - : Control( pParent, nStyle ) +ColorSliderControl::ColorSliderControl(weld::DrawingArea* pDrawingArea) + : m_xDrawingArea(pDrawingArea) , meMode( DefaultMode ) , mnLevel( 0 ) , mdValue( -1.0 ) { - SetControlBackground(); + m_xDrawingArea->set_size_request(m_xDrawingArea->get_approximate_char_width() * 3, -1); + m_xDrawingArea->connect_size_allocate(LINK(this, ColorSliderControl, DoResize)); + m_xDrawingArea->connect_draw(LINK(this, ColorSliderControl, DoPaint)); + m_xDrawingArea->connect_mouse_press(LINK(this, ColorSliderControl, DoButtonDown)); + m_xDrawingArea->connect_mouse_release(LINK(this, ColorSliderControl, DoButtonUp)); } ColorSliderControl::~ColorSliderControl() -{ - disposeOnce(); -} - -void ColorSliderControl::dispose() { mxBitmap.disposeAndClear(); - Control::dispose(); } -VCL_BUILDER_FACTORY_CONSTRUCTOR(ColorSliderControl, 0) - void ColorSliderControl::UpdateBitmap() { - Size aSize(1, GetOutputSizePixel().Height()); + Size aSize(1, m_aSize.Height()); if (mxBitmap && mxBitmap->GetOutputSizePixel() != aSize) mxBitmap.disposeAndClear(); @@ -704,7 +650,7 @@ void ColorSliderControl::UpdateBitmap() void ColorSliderControl::ChangePosition(long nY) { - const long nHeight = GetOutputSizePixel().Height() - 1; + const long nHeight = m_aSize.Height() - 1; if (nY < 0) nY = 0; @@ -715,75 +661,51 @@ void ColorSliderControl::ChangePosition(long nY) mdValue = double(nHeight - nY) / double(nHeight); } -void ColorSliderControl::MouseMove( const MouseEvent& rMEvt ) +IMPL_LINK(ColorSliderControl, DoButtonDown, const Point&, rMEvt, void) { - if (rMEvt.IsLeft()) - { - ChangePosition(rMEvt.GetPosPixel().Y()); - Modify(); - } -} - -void ColorSliderControl::MouseButtonDown(const MouseEvent& rMEvt) -{ - if (rMEvt.IsLeft() && !rMEvt.IsShift()) - { - CaptureMouse(); - ChangePosition( rMEvt.GetPosPixel().Y() ); - Modify(); - } -} - -void ColorSliderControl::MouseButtonUp(const MouseEvent&) -{ - if (IsMouseCaptured()) - ReleaseMouse(); -} - -void ColorSliderControl::KeyMove(int dy) -{ - ChangePosition( mnLevel + dy ); + m_xDrawingArea->connect_mouse_move(LINK(this, ColorSliderControl, DoMouseMove)); + ChangePosition(rMEvt.Y()); Modify(); } -void ColorSliderControl::KeyInput(const KeyEvent& rKEvt) +IMPL_LINK(ColorSliderControl, DoMouseMove, const Point&, rMEvt, void) { - if (!rKEvt.GetKeyCode().IsMod2() && !rKEvt.GetKeyCode().IsShift()) - { - switch (rKEvt.GetKeyCode().GetCode()) - { - case KEY_DOWN: - KeyMove(rKEvt.GetKeyCode().IsMod1() ? 5 : 1); - return; - case KEY_UP: - KeyMove(rKEvt.GetKeyCode().IsMod1() ? -5 : -1); - return; - } - } - - Control::KeyInput( rKEvt ); + ChangePosition(rMEvt.Y()); + Modify(); } -void ColorSliderControl::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle& /*rRect*/) +IMPL_LINK_NOARG(ColorSliderControl, DoButtonUp, const Point&, void) { + m_xDrawingArea->connect_mouse_move(Link()); +} + + +IMPL_LINK(ColorSliderControl, DoPaint, weld::DrawingArea::draw_args, aPayload, void) +{ + vcl::RenderContext& rRenderContext = aPayload.first; + if (!mxBitmap) UpdateBitmap(); - const Size aSize(GetOutputSizePixel()); + const Size aSize(m_aSize); Point aPos; int x = aSize.Width(); while (x--) { rRenderContext.DrawOutDev(aPos, aSize, Point(0,0), aSize, *mxBitmap); - aPos.AdjustX(1 ); + aPos.AdjustX(1); } } -void ColorSliderControl::Resize() +IMPL_LINK(ColorSliderControl, DoResize, const Size&, rSize, void) { - UpdateBitmap(); - Control::Resize(); + if (m_aSize != rSize) + { + m_aSize = rSize; + UpdateBitmap(); + m_xDrawingArea->queue_draw(); + } } void ColorSliderControl::Modify() @@ -798,30 +720,56 @@ void ColorSliderControl::SetValue(const Color& rColor, ColorMode eMode, double d { maColor = rColor; mdValue = dValue; - mnLevel = static_cast((1.0-dValue) * GetOutputSizePixel().Height()); + mnLevel = static_cast((1.0-dValue) * m_aSize.Height()); meMode = eMode; if (bUpdateBitmap) UpdateBitmap(); - Invalidate(); + m_xDrawingArea->queue_draw(); } } -class ColorPickerDialog : public ModalDialog +class ColorPickerDialog : public weld::GenericDialogController { +private: + std::unique_ptr m_xColorField; + std::unique_ptr m_xColorSlider; + std::unique_ptr m_xColorPreview; + std::unique_ptr m_xColorPrevious; + + std::unique_ptr m_xFISliderLeft; + std::unique_ptr m_xFISliderRight; + std::unique_ptr m_xRBRed; + std::unique_ptr m_xRBGreen; + std::unique_ptr m_xRBBlue; + std::unique_ptr m_xRBHue; + std::unique_ptr m_xRBSaturation; + std::unique_ptr m_xRBBrightness; + + std::unique_ptr m_xMFRed; + std::unique_ptr m_xMFGreen; + std::unique_ptr m_xMFBlue; + std::unique_ptr m_xEDHex; + + std::unique_ptr m_xMFHue; + std::unique_ptr m_xMFSaturation; + std::unique_ptr m_xMFBrightness; + + std::unique_ptr m_xMFCyan; + std::unique_ptr m_xMFMagenta; + std::unique_ptr m_xMFYellow; + std::unique_ptr m_xMFKey; + public: - ColorPickerDialog(vcl::Window* pParent, Color nColor, sal_Int16 nMode); - virtual ~ColorPickerDialog() override - { - disposeOnce(); - } - virtual void dispose() override; + ColorPickerDialog(weld::Window* pParent, Color nColor, sal_Int16 nMode); void update_color(UpdateFlags n = UpdateFlags::All); DECL_LINK(ColorFieldControlModifydl, ColorFieldControl&, void); DECL_LINK(ColorSliderControlModifyHdl, ColorSliderControl&, void); - DECL_LINK(ColorModifyEditHdl, Edit&, void); - DECL_LINK(ModeModifyHdl, RadioButton&, void); + DECL_LINK(ColorModifyMetricHdl, weld::MetricSpinButton&, void); + DECL_LINK(ColorModifySpinHdl, weld::SpinButton&, void); + DECL_LINK(ColorModifyEditHdl, weld::Entry&, void); + DECL_LINK(ModeModifyHdl, weld::ToggleButton&, void); Color GetColor() const; @@ -834,130 +782,84 @@ private: double mdRed, mdGreen, mdBlue; double mdHue, mdSat, mdBri; double mdCyan, mdMagenta, mdYellow, mdKey; - -private: - VclPtr mpColorField; - VclPtr mpColorSlider; - VclPtr mpColorPreview; - VclPtr mpColorPrevious; - - VclPtr mpFISliderLeft; - VclPtr mpFISliderRight; - Image maSliderImage; - - VclPtr mpRBRed; - VclPtr mpRBGreen; - VclPtr mpRBBlue; - VclPtr mpRBHue; - VclPtr mpRBSaturation; - VclPtr mpRBBrightness; - - VclPtr mpMFRed; - VclPtr mpMFGreen; - VclPtr mpMFBlue; - VclPtr mpEDHex; - - VclPtr mpMFHue; - VclPtr mpMFSaturation; - VclPtr mpMFBrightness; - - VclPtr mpMFCyan; - VclPtr mpMFMagenta; - VclPtr mpMFYellow; - VclPtr mpMFKey; }; -ColorPickerDialog::ColorPickerDialog( vcl::Window* pParent, Color nColor, sal_Int16 nMode ) -: ModalDialog( pParent, "ColorPicker", "cui/ui/colorpickerdialog.ui" ) -, mnDialogMode( nMode ) -, meMode( DefaultMode ) -, maSliderImage( BitmapEx( RID_SVXBMP_COLORSLIDER ) ) +ColorPickerDialog::ColorPickerDialog(weld::Window* pParent, Color nColor, sal_Int16 nMode) + : GenericDialogController(pParent, "cui/ui/colorpickerdialog.ui", "ColorPicker") + , m_xColorField(new ColorFieldControl(m_xBuilder->weld_drawing_area("colorField"))) + , m_xColorSlider(new ColorSliderControl(m_xBuilder->weld_drawing_area("colorSlider"))) + , m_xColorPreview(new ColorPreviewControl(m_xBuilder->weld_drawing_area("preview"))) + , m_xColorPrevious(new ColorPreviewControl(m_xBuilder->weld_drawing_area("previous"))) + , m_xFISliderLeft(m_xBuilder->weld_widget("leftImage")) + , m_xFISliderRight(m_xBuilder->weld_widget("rightImage")) + , m_xRBRed(m_xBuilder->weld_radio_button("redRadiobutton")) + , m_xRBGreen(m_xBuilder->weld_radio_button("greenRadiobutton")) + , m_xRBBlue(m_xBuilder->weld_radio_button("blueRadiobutton")) + , m_xRBHue(m_xBuilder->weld_radio_button("hueRadiobutton")) + , m_xRBSaturation(m_xBuilder->weld_radio_button("satRadiobutton")) + , m_xRBBrightness(m_xBuilder->weld_radio_button("brightRadiobutton")) + , m_xMFRed(m_xBuilder->weld_spin_button("redSpinbutton")) + , m_xMFGreen(m_xBuilder->weld_spin_button("greenSpinbutton")) + , m_xMFBlue(m_xBuilder->weld_spin_button("blueSpinbutton")) + , m_xEDHex(new weld::HexColorControl(m_xBuilder->weld_entry("hexEntry"))) + , m_xMFHue(m_xBuilder->weld_metric_spin_button("hueSpinbutton")) + , m_xMFSaturation(m_xBuilder->weld_metric_spin_button("satSpinbutton")) + , m_xMFBrightness(m_xBuilder->weld_metric_spin_button("brightSpinbutton")) + , m_xMFCyan(m_xBuilder->weld_metric_spin_button("cyanSpinbutton")) + , m_xMFMagenta(m_xBuilder->weld_metric_spin_button("magSpinbutton")) + , m_xMFYellow(m_xBuilder->weld_metric_spin_button("yellowSpinbutton")) + , m_xMFKey(m_xBuilder->weld_metric_spin_button("keySpinbutton")) + , mnDialogMode( nMode ) + , meMode( DefaultMode ) { - get(mpColorField, "colorField"); - get(mpColorSlider, "colorSlider"); - get(mpColorPreview, "preview"); - get(mpColorPrevious, "previous"); - get(mpRBRed, "redRadiobutton"); - get(mpRBGreen, "greenRadiobutton"); - get(mpRBBlue, "blueRadiobutton"); - get(mpRBHue, "hueRadiobutton"); - get(mpRBSaturation, "satRadiobutton"); - get(mpRBBrightness, "brightRadiobutton"); - get(mpMFRed, "redSpinbutton"); - get(mpMFGreen, "greenSpinbutton"); - get(mpMFBlue, "blueSpinbutton"); - get(mpEDHex, "hexEntry"); - get(mpMFHue, "hueSpinbutton"); - get(mpMFSaturation, "satSpinbutton"); - get(mpMFBrightness, "brightSpinbutton"); - get(mpMFCyan, "cyanSpinbutton"); - get(mpMFMagenta, "magSpinbutton"); - get(mpMFYellow, "yellowSpinbutton"); - get(mpMFKey, "keySpinbutton"); - get(mpFISliderLeft, "leftImage"); - get(mpFISliderRight, "rightImage"); + m_xMFHue->set_unit(FUNIT_DEGREE); + m_xMFSaturation->set_unit(FUNIT_PERCENT); + m_xMFBrightness->set_unit(FUNIT_PERCENT); - Size aDialogSize = get_preferred_size(); - set_width_request(aDialogSize.Width() + 50); - set_height_request(aDialogSize.Height() + 30); + m_xMFCyan->set_unit(FUNIT_PERCENT); + m_xMFMagenta->set_unit(FUNIT_PERCENT); + m_xMFYellow->set_unit(FUNIT_PERCENT); + m_xMFKey->set_unit(FUNIT_PERCENT); - mpColorField->SetModifyHdl( LINK( this, ColorPickerDialog, ColorFieldControlModifydl ) ); - mpColorSlider->SetModifyHdl( LINK( this, ColorPickerDialog, ColorSliderControlModifyHdl ) ); + m_xColorField->SetModifyHdl( LINK( this, ColorPickerDialog, ColorFieldControlModifydl ) ); + m_xColorSlider->SetModifyHdl( LINK( this, ColorPickerDialog, ColorSliderControlModifyHdl ) ); - Link aLink3( LINK( this, ColorPickerDialog, ColorModifyEditHdl ) ); - mpMFRed->SetModifyHdl( aLink3 ); - mpMFGreen->SetModifyHdl( aLink3 ); - mpMFBlue->SetModifyHdl( aLink3 ); + int nMargin = (m_xFISliderLeft->get_preferred_size().Height() + 1) / 2; + m_xColorSlider->set_margin_top(nMargin); + m_xColorSlider->set_margin_bottom(nMargin); - mpMFCyan->SetModifyHdl( aLink3 ); - mpMFMagenta->SetModifyHdl( aLink3 ); - mpMFYellow->SetModifyHdl( aLink3 ); - mpMFKey->SetModifyHdl( aLink3 ); + Link aLink3( LINK( this, ColorPickerDialog, ColorModifyMetricHdl ) ); + m_xMFCyan->connect_value_changed( aLink3 ); + m_xMFMagenta->connect_value_changed( aLink3 ); + m_xMFYellow->connect_value_changed( aLink3 ); + m_xMFKey->connect_value_changed( aLink3 ); - mpMFHue->SetModifyHdl( aLink3 ); - mpMFSaturation->SetModifyHdl( aLink3 ); - mpMFBrightness->SetModifyHdl( aLink3 ); + m_xMFHue->connect_value_changed( aLink3 ); + m_xMFSaturation->connect_value_changed( aLink3 ); + m_xMFBrightness->connect_value_changed( aLink3 ); - mpEDHex->SetModifyHdl( aLink3 ); + Link aLink4(LINK(this, ColorPickerDialog, ColorModifySpinHdl)); + m_xMFRed->connect_value_changed(aLink4); + m_xMFGreen->connect_value_changed(aLink4); + m_xMFBlue->connect_value_changed(aLink4); - Link aLink2 = LINK( this, ColorPickerDialog, ModeModifyHdl ); - mpRBRed->SetToggleHdl( aLink2 ); - mpRBGreen->SetToggleHdl( aLink2 ); - mpRBBlue->SetToggleHdl( aLink2 ); - mpRBHue->SetToggleHdl( aLink2 ); - mpRBSaturation->SetToggleHdl( aLink2 ); - mpRBBrightness->SetToggleHdl( aLink2 ); + m_xEDHex->connect_changed(LINK(this, ColorPickerDialog, ColorModifyEditHdl)); - Image aSliderImage( maSliderImage ); + Link aLink2 = LINK( this, ColorPickerDialog, ModeModifyHdl ); + m_xRBRed->connect_toggled( aLink2 ); + m_xRBGreen->connect_toggled( aLink2 ); + m_xRBBlue->connect_toggled( aLink2 ); + m_xRBHue->connect_toggled( aLink2 ); + m_xRBSaturation->connect_toggled( aLink2 ); + m_xRBBrightness->connect_toggled( aLink2 ); - mpFISliderLeft->SetImage( aSliderImage ); - mpFISliderLeft->Show(); - - BitmapEx aTmpBmp( maSliderImage.GetBitmapEx() ); - aTmpBmp.Mirror( BmpMirrorFlags::Horizontal ); - mpFISliderRight->SetImage( Image( aTmpBmp ) ); - - Size aSize( maSliderImage.GetSizePixel() ); - mpFISliderLeft->SetSizePixel( aSize ); - mpFISliderRight->SetSizePixel( aSize ); - - Point aPos( mpColorSlider->GetPosPixel() ); - - aPos.AdjustX( -(aSize.Width()) ); - aPos.AdjustY( -(aSize.Height() / 2) ); - mpFISliderLeft->SetPosPixel( aPos ); - - aPos.AdjustX(aSize.Width() + mpColorSlider->GetSizePixel().Width() ); - mpFISliderRight->SetPosPixel( aPos ); - - Color aColor( nColor ); + Color aColor(nColor); // modify - if( mnDialogMode == 2 ) + if (mnDialogMode == 2) { - mpColorPreview->SetSizePixel( mpColorPrevious->GetSizePixel() ); - mpColorPrevious->SetColor( aColor ); - mpColorPrevious->Show(); + m_xColorPrevious->SetColor(aColor); + m_xColorPrevious->show(); } mdRed = static_cast(aColor.GetRed()) / 255.0; @@ -970,34 +872,6 @@ ColorPickerDialog::ColorPickerDialog( vcl::Window* pParent, Color nColor, sal_In update_color(); } -void ColorPickerDialog::dispose() -{ - mpColorField.clear(); - mpColorSlider.clear(); - mpColorPreview.clear(); - mpColorPrevious.clear(); - mpFISliderLeft.clear(); - mpFISliderRight.clear(); - mpRBRed.clear(); - mpRBGreen.clear(); - mpRBBlue.clear(); - mpRBHue.clear(); - mpRBSaturation.clear(); - mpRBBrightness.clear(); - mpMFRed.clear(); - mpMFGreen.clear(); - mpMFBlue.clear(); - mpEDHex.clear(); - mpMFHue.clear(); - mpMFSaturation.clear(); - mpMFBrightness.clear(); - mpMFCyan.clear(); - mpMFMagenta.clear(); - mpMFYellow.clear(); - mpMFKey.clear(); - ModalDialog::dispose(); -} - static int toInt( double dValue, double dRange ) { return static_cast< int >( std::floor((dValue * dRange) + 0.5 ) ); @@ -1018,24 +892,24 @@ void ColorPickerDialog::update_color( UpdateFlags n ) if (n & UpdateFlags::RGB) // update RGB { - mpMFRed->SetValue(nRed); - mpMFGreen->SetValue(nGreen); - mpMFBlue->SetValue(nBlue); + m_xMFRed->set_value(nRed); + m_xMFGreen->set_value(nGreen); + m_xMFBlue->set_value(nBlue); } if (n & UpdateFlags::CMYK) // update CMYK { - mpMFCyan->SetValue(toInt(mdCyan, 100.0)); - mpMFMagenta->SetValue(toInt(mdMagenta, 100.0)); - mpMFYellow->SetValue(toInt(mdYellow, 100.0)); - mpMFKey->SetValue(toInt(mdKey, 100.0)); + m_xMFCyan->set_value(toInt(mdCyan, 100.0), FUNIT_PERCENT); + m_xMFMagenta->set_value(toInt(mdMagenta, 100.0), FUNIT_PERCENT); + m_xMFYellow->set_value(toInt(mdYellow, 100.0), FUNIT_PERCENT); + m_xMFKey->set_value(toInt(mdKey, 100.0), FUNIT_PERCENT); } if (n & UpdateFlags::HSB ) // update HSB { - mpMFHue->SetValue(toInt(mdHue, 1.0)); - mpMFSaturation->SetValue(toInt( mdSat, 100.0)); - mpMFBrightness->SetValue(toInt( mdBri, 100.0)); + m_xMFHue->set_value(toInt(mdHue, 1.0), FUNIT_DEGREE); + m_xMFSaturation->set_value(toInt( mdSat, 100.0), FUNIT_PERCENT); + m_xMFBrightness->set_value(toInt( mdBri, 100.0), FUNIT_PERCENT); } if (n & UpdateFlags::ColorChooser ) // update Color Chooser 1 @@ -1043,22 +917,22 @@ void ColorPickerDialog::update_color( UpdateFlags n ) switch( meMode ) { case HUE: - mpColorField->SetValues(aColor, meMode, mdSat, mdBri); + m_xColorField->SetValues(aColor, meMode, mdSat, mdBri); break; case SATURATION: - mpColorField->SetValues(aColor, meMode, mdHue / 360.0, mdBri); + m_xColorField->SetValues(aColor, meMode, mdHue / 360.0, mdBri); break; case BRIGHTNESS: - mpColorField->SetValues(aColor, meMode, mdHue / 360.0, mdSat); + m_xColorField->SetValues(aColor, meMode, mdHue / 360.0, mdSat); break; case RED: - mpColorField->SetValues(aColor, meMode, mdBlue, mdGreen); + m_xColorField->SetValues(aColor, meMode, mdBlue, mdGreen); break; case GREEN: - mpColorField->SetValues(aColor, meMode, mdBlue, mdRed); + m_xColorField->SetValues(aColor, meMode, mdBlue, mdRed); break; case BLUE: - mpColorField->SetValues(aColor, meMode, mdRed, mdGreen); + m_xColorField->SetValues(aColor, meMode, mdRed, mdGreen); break; } } @@ -1068,51 +942,39 @@ void ColorPickerDialog::update_color( UpdateFlags n ) switch (meMode) { case HUE: - mpColorSlider->SetValue(aColor, meMode, mdHue / 360.0); + m_xColorSlider->SetValue(aColor, meMode, mdHue / 360.0); break; case SATURATION: - mpColorSlider->SetValue(aColor, meMode, mdSat); + m_xColorSlider->SetValue(aColor, meMode, mdSat); break; case BRIGHTNESS: - mpColorSlider->SetValue(aColor, meMode, mdBri); + m_xColorSlider->SetValue(aColor, meMode, mdBri); break; case RED: - mpColorSlider->SetValue(aColor, meMode, mdRed); + m_xColorSlider->SetValue(aColor, meMode, mdRed); break; case GREEN: - mpColorSlider->SetValue(aColor, meMode, mdGreen); + m_xColorSlider->SetValue(aColor, meMode, mdGreen); break; case BLUE: - mpColorSlider->SetValue(aColor, meMode, mdBlue); + m_xColorSlider->SetValue(aColor, meMode, mdBlue); break; } } if (n & UpdateFlags::Hex) // update hex { - mpEDHex->SetColor(aColor); + m_xFISliderLeft->set_margin_top(m_xColorSlider->GetLevel()); + m_xFISliderRight->set_margin_top(m_xColorSlider->GetLevel()); + m_xEDHex->SetColor(aColor); } - - { - Point aPos(0, mpColorSlider->GetLevel() + mpColorSlider->GetPosPixel().Y() - 1); - - aPos.setX( mpFISliderLeft->GetPosPixel().X() ); - if (aPos != mpFISliderLeft->GetPosPixel()) - { - mpFISliderLeft->SetPosPixel(aPos); - - aPos.setX( mpFISliderRight->GetPosPixel().X() ); - mpFISliderRight->SetPosPixel(aPos); - } - } - - mpColorPreview->SetColor(aColor); + m_xColorPreview->SetColor(aColor); } IMPL_LINK_NOARG(ColorPickerDialog, ColorFieldControlModifydl, ColorFieldControl&, void) { - double x = mpColorField->GetX(); - double y = mpColorField->GetY(); + double x = m_xColorField->GetX(); + double y = m_xColorField->GetY(); switch( meMode ) { @@ -1147,7 +1009,7 @@ IMPL_LINK_NOARG(ColorPickerDialog, ColorFieldControlModifydl, ColorFieldControl& IMPL_LINK_NOARG(ColorPickerDialog, ColorSliderControlModifyHdl, ColorSliderControl&, void) { - double dValue = mpColorSlider->GetValue(); + double dValue = m_xColorSlider->GetValue(); switch (meMode) { case HUE: @@ -1173,101 +1035,117 @@ IMPL_LINK_NOARG(ColorPickerDialog, ColorSliderControlModifyHdl, ColorSliderContr update_color(UpdateFlags::All & ~UpdateFlags::ColorSlider); } -IMPL_LINK(ColorPickerDialog, ColorModifyEditHdl, Edit&, rEdit, void) +IMPL_LINK(ColorPickerDialog, ColorModifyMetricHdl, weld::MetricSpinButton&, rEdit, void) { UpdateFlags n = UpdateFlags::NONE; - if (&rEdit == mpMFRed) + if (&rEdit == m_xMFHue.get()) { - setColorComponent( ColorComponent::Red, static_cast(mpMFRed->GetValue()) / 255.0 ); - n = UpdateFlags::All & ~UpdateFlags::RGB; - } - else if (&rEdit == mpMFGreen) - { - setColorComponent( ColorComponent::Green, static_cast(mpMFGreen->GetValue()) / 255.0 ); - n = UpdateFlags::All & ~UpdateFlags::RGB; - } - else if (&rEdit == mpMFBlue) - { - setColorComponent( ColorComponent::Blue, static_cast(mpMFBlue->GetValue()) / 255.0 ); - n = UpdateFlags::All & ~UpdateFlags::RGB; - } - else if (&rEdit == mpMFHue) - { - setColorComponent( ColorComponent::Hue, static_cast(mpMFHue->GetValue()) ); + setColorComponent( ColorComponent::Hue, static_cast(m_xMFHue->get_value(FUNIT_DEGREE)) ); n = UpdateFlags::All & ~UpdateFlags::HSB; } - else if (&rEdit == mpMFSaturation) + else if (&rEdit == m_xMFSaturation.get()) { - setColorComponent( ColorComponent::Saturation, static_cast(mpMFSaturation->GetValue()) / 100.0 ); + setColorComponent( ColorComponent::Saturation, static_cast(m_xMFSaturation->get_value(FUNIT_PERCENT)) / 100.0 ); n = UpdateFlags::All & ~UpdateFlags::HSB; } - else if (&rEdit == mpMFBrightness) + else if (&rEdit == m_xMFBrightness.get()) { - setColorComponent( ColorComponent::Brightness, static_cast(mpMFBrightness->GetValue()) / 100.0 ); + setColorComponent( ColorComponent::Brightness, static_cast(m_xMFBrightness->get_value(FUNIT_PERCENT)) / 100.0 ); n = UpdateFlags::All & ~UpdateFlags::HSB; } - else if (&rEdit == mpMFCyan) + else if (&rEdit == m_xMFCyan.get()) { - setColorComponent( ColorComponent::Cyan, static_cast(mpMFCyan->GetValue()) / 100.0 ); + setColorComponent( ColorComponent::Cyan, static_cast(m_xMFCyan->get_value(FUNIT_PERCENT)) / 100.0 ); n = UpdateFlags::All & ~UpdateFlags::CMYK; } - else if (&rEdit == mpMFMagenta) + else if (&rEdit == m_xMFMagenta.get()) { - setColorComponent( ColorComponent::Magenta, static_cast(mpMFMagenta->GetValue()) / 100.0 ); + setColorComponent( ColorComponent::Magenta, static_cast(m_xMFMagenta->get_value(FUNIT_PERCENT)) / 100.0 ); n = UpdateFlags::All & ~UpdateFlags::CMYK; } - else if (&rEdit == mpMFYellow) + else if (&rEdit == m_xMFYellow.get()) { - setColorComponent( ColorComponent::Yellow, static_cast(mpMFYellow->GetValue()) / 100.0 ); + setColorComponent( ColorComponent::Yellow, static_cast(m_xMFYellow->get_value(FUNIT_PERCENT)) / 100.0 ); n = UpdateFlags::All & ~UpdateFlags::CMYK; } - else if (&rEdit == mpMFKey) + else if (&rEdit == m_xMFKey.get()) { - setColorComponent( ColorComponent::Key, static_cast(mpMFKey->GetValue()) / 100.0 ); + setColorComponent( ColorComponent::Key, static_cast(m_xMFKey->get_value(FUNIT_PERCENT)) / 100.0 ); n = UpdateFlags::All & ~UpdateFlags::CMYK; } - else if (&rEdit == mpEDHex) - { - Color aColor = mpEDHex->GetColor(); - - if (aColor != Color(0xffffffff) && aColor != GetColor()) - { - mdRed = static_cast(aColor.GetRed()) / 255.0; - mdGreen = static_cast(aColor.GetGreen()) / 255.0; - mdBlue = static_cast(aColor.GetBlue()) / 255.0; - - RGBtoHSV( mdRed, mdGreen, mdBlue, mdHue, mdSat, mdBri ); - RGBtoCMYK( mdRed, mdGreen, mdBlue, mdCyan, mdMagenta, mdYellow, mdKey ); - n = UpdateFlags::All & ~UpdateFlags::Hex; - } - } if (n != UpdateFlags::NONE) update_color(n); } -IMPL_LINK_NOARG(ColorPickerDialog, ModeModifyHdl, RadioButton&, void) +IMPL_LINK_NOARG(ColorPickerDialog, ColorModifyEditHdl, weld::Entry&, void) +{ + UpdateFlags n = UpdateFlags::NONE; + + Color aColor = m_xEDHex->GetColor(); + + if (aColor != Color(0xffffffff) && aColor != GetColor()) + { + mdRed = static_cast(aColor.GetRed()) / 255.0; + mdGreen = static_cast(aColor.GetGreen()) / 255.0; + mdBlue = static_cast(aColor.GetBlue()) / 255.0; + + RGBtoHSV( mdRed, mdGreen, mdBlue, mdHue, mdSat, mdBri ); + RGBtoCMYK( mdRed, mdGreen, mdBlue, mdCyan, mdMagenta, mdYellow, mdKey ); + n = UpdateFlags::All & ~UpdateFlags::Hex; + } + + if (n != UpdateFlags::NONE) + update_color(n); +} + +IMPL_LINK(ColorPickerDialog, ColorModifySpinHdl, weld::SpinButton&, rEdit, void) +{ + UpdateFlags n = UpdateFlags::NONE; + + if (&rEdit == m_xMFRed.get()) + { + setColorComponent( ColorComponent::Red, static_cast(m_xMFRed->get_value()) / 255.0 ); + n = UpdateFlags::All & ~UpdateFlags::RGB; + } + else if (&rEdit == m_xMFGreen.get()) + { + setColorComponent( ColorComponent::Green, static_cast(m_xMFGreen->get_value()) / 255.0 ); + n = UpdateFlags::All & ~UpdateFlags::RGB; + } + else if (&rEdit == m_xMFBlue.get()) + { + setColorComponent( ColorComponent::Blue, static_cast(m_xMFBlue->get_value()) / 255.0 ); + n = UpdateFlags::All & ~UpdateFlags::RGB; + } + + if (n != UpdateFlags::NONE) + update_color(n); +} + + +IMPL_LINK_NOARG(ColorPickerDialog, ModeModifyHdl, weld::ToggleButton&, void) { ColorMode eMode = HUE; - if (mpRBRed->IsChecked()) + if (m_xRBRed->get_active()) { eMode = RED; } - else if (mpRBGreen->IsChecked()) + else if (m_xRBGreen->get_active()) { eMode = GREEN; } - else if (mpRBBlue->IsChecked()) + else if (m_xRBBlue->get_active()) { eMode = BLUE; } - else if (mpRBSaturation->IsChecked()) + else if (m_xRBSaturation->get_active()) { eMode = SATURATION; } - else if (mpRBBrightness->IsChecked()) + else if (m_xRBBrightness->get_active()) { eMode = BRIGHTNESS; } @@ -1445,13 +1323,13 @@ void SAL_CALL ColorPicker::setTitle( const OUString& sTitle ) msTitle = sTitle; } -sal_Int16 SAL_CALL ColorPicker::execute( ) +sal_Int16 SAL_CALL ColorPicker::execute() { - ScopedVclPtrInstance< ColorPickerDialog > aDlg( VCLUnoHelper::GetWindow( mxParent ), mnColor, mnMode ); - sal_Int16 ret = aDlg->Execute(); - if( ret ) - mnColor = aDlg->GetColor(); - + VclPtr xWin(VCLUnoHelper::GetWindow(mxParent)); + std::unique_ptr xDlg(new ColorPickerDialog(xWin ? xWin->GetFrameWeld() : nullptr, mnColor, mnMode)); + sal_Int16 ret = xDlg->run(); + if (ret) + mnColor = xDlg->GetColor(); return ret; } diff --git a/cui/uiconfig/ui/colorpickerdialog.ui b/cui/uiconfig/ui/colorpickerdialog.ui index 9fd22b3f1c29..660ff5cea3ef 100644 --- a/cui/uiconfig/ui/colorpickerdialog.ui +++ b/cui/uiconfig/ui/colorpickerdialog.ui @@ -1,19 +1,53 @@ - + - - + 255 1 10 - + + 100 + 1 + 10 + + + 100 + 1 + 10 + + + 255 + 1 + 10 + + 360 1 10 - + + 100 + 1 + 10 + + + 100 + 1 + 10 + + + 255 + 1 + 10 + + + 100 + 1 + 10 + + 100 1 10 @@ -26,6 +60,8 @@ Pick a Color False True + 0 + 0 dialog @@ -115,7 +151,7 @@ False True - + True False True @@ -127,8 +163,7 @@ - - True + False True @@ -145,9 +180,10 @@ - + True False + GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK True True @@ -157,9 +193,10 @@ - + True False + GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_STRUCTURE_MASK True @@ -172,7 +209,7 @@ True False start - gtk-missing-image + res/colorsliderright.png 3 @@ -184,7 +221,7 @@ True False start - gtk-missing-image + res/colorsliderleft.png 1 @@ -248,9 +285,8 @@ False True 0 - True True - greenRadiobutton + hueRadiobutton 0 @@ -267,7 +303,7 @@ True 0 True - redRadiobutton + hueRadiobutton 0 @@ -284,7 +320,7 @@ True 0 True - redRadiobutton + hueRadiobutton 0 @@ -292,11 +328,11 @@ - + True True True - adjustment1 + adjustmentred 1 @@ -304,11 +340,11 @@ - + True True True - adjustment1 + adjustmentgreen 1 @@ -316,11 +352,11 @@ - + True True True - adjustment1 + adjustmentblue 1 @@ -331,10 +367,10 @@ True False - 0 Hex _#: True hexEntry + 0 0 @@ -342,7 +378,7 @@ - + True True True @@ -408,7 +444,6 @@ 0 True True - redRadiobutton 0 @@ -425,7 +460,7 @@ True 0 True - redRadiobutton + hueRadiobutton 0 @@ -442,7 +477,7 @@ True 0 True - redRadiobutton + hueRadiobutton 0 @@ -450,11 +485,11 @@ - + True True True - adjustment2 + adjustmenthue 1 @@ -462,11 +497,11 @@ - + True True True - adjustment3 + adjustmentsat 1 @@ -474,11 +509,11 @@ - + True True True - adjustment3 + adjustmentbright 1 @@ -533,10 +568,10 @@ True False start - 0 _Cyan: True - cyanSpinbutton:% + cyanSpinbutton + 0 0 @@ -548,10 +583,10 @@ True False start - 0 _Magenta: True - magSpinbutton:% + magSpinbutton + 0 0 @@ -563,10 +598,10 @@ True False start - 0 _Yellow: True - yellowSpinbutton:% + yellowSpinbutton + 0 0 @@ -578,10 +613,10 @@ True False start - 0 _Key: True - keySpinbutton:% + keySpinbutton + 0 0 @@ -589,11 +624,11 @@ - + True True True - adjustment3 + adjustmentcyan 1 @@ -601,11 +636,11 @@ - + True True True - adjustment3 + adjustmentmag 1 @@ -613,11 +648,11 @@ - + True True True - adjustment3 + adjustmentyellow 1 @@ -625,11 +660,11 @@ - + True True True - adjustment3 + adjustmentkey 1 @@ -678,6 +713,9 @@ cancel help + + + diff --git a/extras/source/glade/libreoffice-catalog.xml.in b/extras/source/glade/libreoffice-catalog.xml.in index c0a89747cb8a..71f2c260b26a 100644 --- a/extras/source/glade/libreoffice-catalog.xml.in +++ b/extras/source/glade/libreoffice-catalog.xml.in @@ -281,15 +281,6 @@ - - - diff --git a/icon-themes/galaxy/res/colorslider.png b/icon-themes/galaxy/res/colorsliderleft.png similarity index 100% rename from icon-themes/galaxy/res/colorslider.png rename to icon-themes/galaxy/res/colorsliderleft.png diff --git a/icon-themes/galaxy/res/colorsliderright.png b/icon-themes/galaxy/res/colorsliderright.png new file mode 100644 index 0000000000000000000000000000000000000000..09259107566bf303b335478d991fe2f2144346cf GIT binary patch literal 203 zcmeAS@N?(olHy`uVBq!ia0vp^96-#;!3HGxgLCzO6kC$Fy9>jA5L~c#`DBoEfk$L9 z0|U1(2s1Lwnj--eWH0gbb!C6V%*ms~SQ5W#Ay6p7)5S4F;&SVRgS-a}IGB04QzrBr z_|r4NHi7B8YwM*gUypl~^E+%fdN*?O%#+M+ES^S6FWz0@dp<`Znc=|QswUfCtc(t4 teXd2FII}t6_CC*B{;z_z{`vcmDJ9(6^~4qHcR)KBJYD@<);T3K0RX^mME?K) literal 0 HcmV?d00001 diff --git a/icon-themes/tango/res/colorslider.png b/icon-themes/tango/res/colorsliderleft.png similarity index 100% rename from icon-themes/tango/res/colorslider.png rename to icon-themes/tango/res/colorsliderleft.png diff --git a/icon-themes/tango/res/colorsliderright.png b/icon-themes/tango/res/colorsliderright.png new file mode 100644 index 0000000000000000000000000000000000000000..25afe492a8c101ac82b53e31daf0a9efbef54c49 GIT binary patch literal 203 zcmeAS@N?(olHy`uVBq!ia0vp^96-#;!3HGxgLCzO6kC$Fy9>jA5L~c#`DBoEfk$L9 z0|U1(2s1Lwnj--eWH0gbb!C6V%*mt7-8-@9A5bX5)5S4F;&SVRgS-a}IGB04QzrBr z_|r4NHi7B8YwM*gUypl~^E+%fdN*?O%#+M+ES^S6FWz0@dp<`Znc=|QswUfCtc(t4 teXd2FII}t6_CC*B{;z_z{`vcmDJ9(6^~4qHcR)KBJYD@<);T3K0RZ=1MS1`L literal 0 HcmV?d00001 diff --git a/include/svx/hexcolorcontrol.hxx b/include/svx/hexcolorcontrol.hxx index 22d7cf2df540..a39bb5941626 100644 --- a/include/svx/hexcolorcontrol.hxx +++ b/include/svx/hexcolorcontrol.hxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,25 @@ private: static bool ImplProcessKeyInput( const KeyEvent& rKEv ); }; +namespace weld { + +class SVX_DLLPUBLIC HexColorControl +{ +private: + std::unique_ptr m_xEntry; + + DECL_LINK(ImplProcessInputHdl, OUString&, bool); +public: + HexColorControl(weld::Entry* pEdit); + + void connect_changed(const Link& rLink) { m_xEntry->connect_changed(rLink); } + + void SetColor( ::Color nColor ); + ::Color GetColor(); +}; + +} + #endif // INCLUDED_SVX_HEXCOLOR_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/layout.hxx b/include/vcl/layout.hxx index f20bc18cac8a..d1488ba77e77 100644 --- a/include/vcl/layout.hxx +++ b/include/vcl/layout.hxx @@ -613,14 +613,39 @@ public: class VCL_DLLPUBLIC VclDrawingArea : public vcl::Window { private: - Link m_aPaintHdl; + Link, void> m_aPaintHdl; Link m_aResizeHdl; + Link m_aMousePressHdl; + Link m_aMouseMotionHdl; + Link m_aMouseReleaseHdl; + + virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override + { + m_aPaintHdl.Call(std::pair(rRenderContext, rRect)); + } + virtual void Resize() override + { + m_aResizeHdl.Call(GetOutputSizePixel()); + } + virtual void MouseMove(const MouseEvent& rMEvt) override + { + m_aMouseMotionHdl.Call(rMEvt.GetPosPixel()); + } + virtual void MouseButtonDown(const MouseEvent& rMEvt) override + { + m_aMousePressHdl.Call(rMEvt.GetPosPixel()); + } + virtual void MouseButtonUp(const MouseEvent& rMEvt) override + { + m_aMouseReleaseHdl.Call(rMEvt.GetPosPixel()); + } + public: VclDrawingArea(vcl::Window *pParent, WinBits nStyle) : vcl::Window(pParent, nStyle) { } - void SetPaintHdl(const Link& rLink) + void SetPaintHdl(const Link, void>& rLink) { m_aPaintHdl = rLink; } @@ -628,13 +653,17 @@ public: { m_aResizeHdl = rLink; } - virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/) override + void SetMousePressHdl(const Link& rLink) { - m_aPaintHdl.Call(rRenderContext); + m_aMousePressHdl = rLink; } - virtual void Resize() override + void SetMouseMoveHdl(const Link& rLink) { - m_aResizeHdl.Call(GetOutputSizePixel()); + m_aMouseMotionHdl = rLink; + } + void SetMouseReleaseHdl(const Link& rLink) + { + m_aMouseReleaseHdl = rLink; } }; diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 7a82cfb2c6df..86a61b75f194 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -54,6 +54,9 @@ public: virtual void set_grid_top_attach(int nAttach) = 0; virtual int get_grid_top_attach() const = 0; + virtual void set_margin_top(int nMargin) = 0; + virtual void set_margin_bottom(int nMargin) = 0; + virtual Container* weld_parent() const = 0; virtual ~Widget() {} @@ -307,6 +310,7 @@ public: virtual void set_text(const OUString& rText) = 0; virtual OUString get_text() const = 0; virtual void set_width_chars(int nChars) = 0; + virtual void set_max_length(int nChars) = 0; virtual void select_region(int nStartPos, int nEndPos) = 0; virtual void set_position(int nCursorPos) = 0; @@ -493,14 +497,27 @@ public: class VCL_DLLPUBLIC DrawingArea : virtual public Widget { +public: + typedef std::pair draw_args; + protected: - Link m_aDrawHdl; + Link m_aDrawHdl; Link m_aSizeAllocateHdl; + Link m_aMousePressHdl; + Link m_aMouseMotionHdl; + Link m_aMouseReleaseHdl; public: - void connect_draw(const Link& rLink) { m_aDrawHdl = rLink; } + void connect_draw(const Link& rLink) { m_aDrawHdl = rLink; } void connect_size_allocate(const Link& rLink) { m_aSizeAllocateHdl = rLink; } + void connect_mouse_press(const Link& rLink) { m_aMousePressHdl = rLink; } + void connect_mouse_move(const Link& rLink) { m_aMouseMotionHdl = rLink; } + void connect_mouse_release(const Link& rLink) + { + m_aMouseReleaseHdl = rLink; + } virtual void queue_draw() = 0; + virtual void queue_draw_area(int x, int y, int width, int height) = 0; }; class VCL_DLLPUBLIC Builder diff --git a/sfx2/source/doc/new.cxx b/sfx2/source/doc/new.cxx index eed042b7d60e..be99751c9a05 100644 --- a/sfx2/source/doc/new.cxx +++ b/sfx2/source/doc/new.cxx @@ -105,9 +105,9 @@ void SfxPreviewWin_Impl::ImpPaint(vcl::RenderContext& rRenderContext, GDIMetaFil } } -IMPL_LINK(SfxPreviewWin_Impl, DoPaint, vcl::RenderContext&, rRenderContext, void) +IMPL_LINK(SfxPreviewWin_Impl, DoPaint, weld::DrawingArea::draw_args, aPayload, void) { - ImpPaint(rRenderContext, xMetaFile.get()); + ImpPaint(aPayload.first, xMetaFile.get()); } IMPL_LINK_NOARG(SfxNewFileDialog, Update, Timer*, void) @@ -193,6 +193,7 @@ IMPL_LINK( SfxNewFileDialog, RegionSelect, weld::TreeView&, rBox, void ) m_xTemplateLb->append(m_aTemplates.GetName(nRegion, i)); m_xTemplateLb->thaw(); m_xTemplateLb->select(0); + TemplateSelect(*m_xTemplateLb); } IMPL_LINK_NOARG(SfxNewFileDialog, Expand, weld::Expander&, void) diff --git a/sfx2/source/inc/preview.hxx b/sfx2/source/inc/preview.hxx index 3a747db969f2..8b39231c31a8 100644 --- a/sfx2/source/inc/preview.hxx +++ b/sfx2/source/inc/preview.hxx @@ -32,7 +32,7 @@ protected: public: SfxPreviewWin_Impl(weld::DrawingArea* pArea); void SetObjectShell( SfxObjectShell const * pObj ); - DECL_LINK(DoPaint, vcl::RenderContext&, void); + DECL_LINK(DoPaint, weld::DrawingArea::draw_args, void); DECL_LINK(DoResize, const Size& rSize, void); void queue_draw() { m_xDrawingArea->queue_draw(); } void show() { m_xDrawingArea->show(); } diff --git a/svx/source/dialog/hexcolorcontrol.cxx b/svx/source/dialog/hexcolorcontrol.cxx index 61d38bdeb619..51927caa5202 100644 --- a/svx/source/dialog/hexcolorcontrol.cxx +++ b/svx/source/dialog/hexcolorcontrol.cxx @@ -126,4 +126,67 @@ bool HexColorControl::ImplProcessKeyInput( const KeyEvent& rKEv ) return false; } +namespace weld { + +HexColorControl::HexColorControl(weld::Entry* pEntry) + : m_xEntry(pEntry) +{ + m_xEntry->set_max_length(6); + m_xEntry->set_width_chars(6); + m_xEntry->connect_insert_text(LINK(this, HexColorControl, ImplProcessInputHdl)); +} + +void HexColorControl::SetColor(Color nColor) +{ + OUStringBuffer aBuffer; + sax::Converter::convertColor(aBuffer, nColor); + m_xEntry->set_text(aBuffer.makeStringAndClear().copy(1)); +} + +Color HexColorControl::GetColor() +{ + sal_Int32 nColor = -1; + + OUString aStr("#"); + aStr += m_xEntry->get_text(); + sal_Int32 nLen = aStr.getLength(); + + if (nLen < 7) + { + static const sal_Char* const pNullStr = "000000"; + aStr += OUString::createFromAscii( &pNullStr[nLen-1] ); + } + + sax::Converter::convertColor(nColor, aStr); + +#if 0 + if (nColor == -1) + SetControlBackground(COL_RED); + else + SetControlBackground(); +#endif + + return Color(nColor); +} + +IMPL_LINK(HexColorControl, ImplProcessInputHdl, OUString&, rTest, bool) +{ + const sal_Unicode* pTest = rTest.getStr(); + sal_Int32 nLen = rTest.getLength(); + + OUStringBuffer aFilter(nLen); + for (sal_Int32 i = 0; i < nLen; ++i) + { + if (rtl::isAsciiHexDigit(*pTest)) + aFilter.append(*pTest); + ++pTest; + } + + rTest = aFilter.makeStringAndClear(); + return true; +} + + +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/ui/table/autoformatpreview.cxx b/sw/source/ui/table/autoformatpreview.cxx index 27f5a4c0705c..83aa97e90970 100644 --- a/sw/source/ui/table/autoformatpreview.cxx +++ b/sw/source/ui/table/autoformatpreview.cxx @@ -842,8 +842,10 @@ void AutoFormatPreview::NotifyChange(const SwTableAutoFormat& rNewData) mxDrawingArea->queue_draw(); } -IMPL_LINK(AutoFormatPreview, DoPaint, vcl::RenderContext&, rRenderContext, void) +IMPL_LINK(AutoFormatPreview, DoPaint, weld::DrawingArea::draw_args, aPayload, void) { + vcl::RenderContext& rRenderContext = aPayload.first; + rRenderContext.Push(PushFlags::ALL); DrawModeFlags nOldDrawMode = rRenderContext.GetDrawMode(); diff --git a/sw/source/uibase/inc/autoformatpreview.hxx b/sw/source/uibase/inc/autoformatpreview.hxx index 3854e8b74090..50bf28074edc 100644 --- a/sw/source/uibase/inc/autoformatpreview.hxx +++ b/sw/source/uibase/inc/autoformatpreview.hxx @@ -67,7 +67,7 @@ private: uno::Reference m_xBreak; void Init(); - DECL_LINK(DoPaint, vcl::RenderContext&, void); + DECL_LINK(DoPaint, weld::DrawingArea::draw_args, void); DECL_LINK(DoResize, const Size& rSize, void); void CalcCellArray(bool bFitWidth); void CalcLineMap(); diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index d1faaadd5cdb..0d5dee9c3fbf 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -289,6 +289,16 @@ public: return m_xWidget->get_grid_top_attach(); } + virtual void set_margin_top(int nMargin) override + { + m_xWidget->set_margin_top(nMargin); + } + + virtual void set_margin_bottom(int nMargin) override + { + m_xWidget->set_margin_bottom(nMargin); + } + virtual weld::Container* weld_parent() const override; virtual ~SalInstanceWidget() override @@ -795,6 +805,11 @@ public: m_xEntry->SetWidthInChars(nChars); } + virtual void set_max_length(int nChars) override + { + m_xEntry->SetMaxTextLen(nChars); + } + virtual void select_region(int nStartPos, int nEndPos) override { m_xEntry->SetSelection(Selection(nStartPos, nEndPos < 0 ? SELECTION_MAX : nEndPos)); @@ -884,7 +899,6 @@ public: m_xTreeView->SetNoSelection(); else m_xTreeView->SelectEntryPos(pos); - m_xTreeView->Select(); } virtual OUString get_selected() override @@ -1122,8 +1136,12 @@ class SalInstanceDrawingArea : public SalInstanceWidget, public virtual weld::Dr private: VclPtr m_xDrawingArea; - DECL_LINK(PaintHdl, vcl::RenderContext&, void); + typedef std::pair target_and_area; + DECL_LINK(PaintHdl, target_and_area, void); DECL_LINK(ResizeHdl, const Size&, void); + DECL_LINK(MousePressHdl, const Point&, void); + DECL_LINK(MouseMoveHdl, const Point&, void); + DECL_LINK(MouseReleaseHdl, const Point&, void); public: SalInstanceDrawingArea(VclDrawingArea* pDrawingArea, bool bTakeOwnership) @@ -1132,6 +1150,9 @@ public: { m_xDrawingArea->SetPaintHdl(LINK(this, SalInstanceDrawingArea, PaintHdl)); m_xDrawingArea->SetResizeHdl(LINK(this, SalInstanceDrawingArea, ResizeHdl)); + m_xDrawingArea->SetMousePressHdl(LINK(this, SalInstanceDrawingArea, MousePressHdl)); + m_xDrawingArea->SetMouseMoveHdl(LINK(this, SalInstanceDrawingArea, MouseMoveHdl)); + m_xDrawingArea->SetMouseReleaseHdl(LINK(this, SalInstanceDrawingArea, MouseReleaseHdl)); } virtual void queue_draw() override @@ -1139,16 +1160,21 @@ public: m_xDrawingArea->Invalidate(); } + virtual void queue_draw_area(int x, int y, int width, int height) override + { + m_xDrawingArea->Invalidate(tools::Rectangle(Point(x, y), Size(width, height))); + } + virtual ~SalInstanceDrawingArea() override { m_xDrawingArea->SetResizeHdl(Link()); - m_xDrawingArea->SetPaintHdl(Link()); + m_xDrawingArea->SetPaintHdl(Link, void>()); } }; -IMPL_LINK(SalInstanceDrawingArea, PaintHdl, vcl::RenderContext&, rDevice, void) +IMPL_LINK(SalInstanceDrawingArea, PaintHdl, target_and_area, aPayload, void) { - m_aDrawHdl.Call(rDevice); + m_aDrawHdl.Call(aPayload); } IMPL_LINK(SalInstanceDrawingArea, ResizeHdl, const Size&, rSize, void) @@ -1156,6 +1182,21 @@ IMPL_LINK(SalInstanceDrawingArea, ResizeHdl, const Size&, rSize, void) m_aSizeAllocateHdl.Call(rSize); } +IMPL_LINK(SalInstanceDrawingArea, MousePressHdl, const Point&, rPos, void) +{ + m_aMousePressHdl.Call(rPos); +} + +IMPL_LINK(SalInstanceDrawingArea, MouseMoveHdl, const Point&, rPos, void) +{ + m_aMouseMotionHdl.Call(rPos); +} + +IMPL_LINK(SalInstanceDrawingArea, MouseReleaseHdl, const Point&, rPos, void) +{ + m_aMouseReleaseHdl.Call(rPos); +} + //ComboBox and ListBox have the same apis, ComboBoxes in LibreOffice have an edit box and ListBoxes //don't. This distinction isn't there in Gtk. Use a template to sort this problem out. template diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 031f012c8152..4a24e5d03357 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -1300,6 +1300,16 @@ public: return nAttach; } + virtual void set_margin_top(int nMargin) override + { + gtk_widget_set_margin_top(m_pWidget, nMargin); + } + + virtual void set_margin_bottom(int nMargin) override + { + gtk_widget_set_margin_bottom(m_pWidget, nMargin); + } + virtual weld::Container* weld_parent() const override; virtual OString get_buildable_name() const override @@ -1336,6 +1346,14 @@ public: if (m_bTakeOwnership) gtk_widget_destroy(m_pWidget); } + + virtual void disable_notify_events() + { + } + + virtual void enable_notify_events() + { + } }; class GtkInstanceContainer : public GtkInstanceWidget, public virtual weld::Container @@ -1851,7 +1869,9 @@ public: virtual void set_active(bool active) override { + disable_notify_events(); gtk_toggle_button_set_active(m_pToggleButton, active); + enable_notify_events(); } virtual bool get_active() const override @@ -1869,6 +1889,18 @@ public: return gtk_toggle_button_get_inconsistent(m_pToggleButton); } + virtual void disable_notify_events() override + { + g_signal_handler_block(m_pToggleButton, m_nSignalId); + GtkInstanceButton::disable_notify_events(); + } + + virtual void enable_notify_events() override + { + GtkInstanceButton::enable_notify_events(); + g_signal_handler_unblock(m_pToggleButton, m_nSignalId); + } + virtual ~GtkInstanceToggleButton() override { g_signal_handler_disconnect(m_pToggleButton, m_nSignalId); @@ -1939,7 +1971,9 @@ public: virtual void set_text(const OUString& rText) override { + disable_notify_events(); gtk_entry_set_text(m_pEntry, OUStringToOString(rText, RTL_TEXTENCODING_UTF8).getStr()); + enable_notify_events(); } virtual OUString get_text() const override @@ -1951,7 +1985,16 @@ public: virtual void set_width_chars(int nChars) override { + disable_notify_events(); gtk_entry_set_width_chars(m_pEntry, nChars); + enable_notify_events(); + } + + virtual void set_max_length(int nChars) override + { + disable_notify_events(); + gtk_entry_set_max_length(m_pEntry, nChars); + enable_notify_events(); } virtual void select_region(int nStartPos, int nEndPos) override @@ -1964,6 +2007,20 @@ public: gtk_editable_set_position(GTK_EDITABLE(m_pEntry), nCursorPos); } + virtual void disable_notify_events() override + { + g_signal_handler_block(m_pEntry, m_nInsertTextSignalId); + g_signal_handler_block(m_pEntry, m_nChangedSignalId); + GtkInstanceWidget::disable_notify_events(); + } + + virtual void enable_notify_events() override + { + GtkInstanceWidget::disable_notify_events(); + g_signal_handler_unblock(m_pEntry, m_nChangedSignalId); + g_signal_handler_unblock(m_pEntry, m_nInsertTextSignalId); + } + virtual ~GtkInstanceEntry() override { g_signal_handler_disconnect(m_pEntry, m_nInsertTextSignalId); @@ -2034,18 +2091,22 @@ public: virtual void insert(const OUString& rText, int pos) override { + disable_notify_events(); GtkTreeIter iter; gtk_list_store_insert(m_pListStore, &iter, pos); gtk_list_store_set(m_pListStore, &iter, 0, OUStringToOString(rText, RTL_TEXTENCODING_UTF8).getStr(), -1); + enable_notify_events(); } using GtkInstanceContainer::remove; virtual void remove(int pos) override { + disable_notify_events(); GtkTreeIter iter; gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_pListStore), &iter, nullptr, pos); gtk_list_store_remove(m_pListStore, &iter); + enable_notify_events(); } virtual int find(const OUString& rText) const override @@ -2060,6 +2121,7 @@ public: if (pos == before) return; + disable_notify_events(); GtkTreeIter iter; gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_pListStore), &iter, nullptr, pos); @@ -2067,16 +2129,21 @@ public: gtk_tree_model_iter_nth_child(GTK_TREE_MODEL(m_pListStore), &position, nullptr, before); gtk_list_store_move_before(m_pListStore, &iter, &position); + enable_notify_events(); } virtual void set_top_entry(int pos) override { + disable_notify_events(); move_before(pos, 0); + enable_notify_events(); } virtual void clear() override { + disable_notify_events(); gtk_list_store_clear(m_pListStore); + enable_notify_events(); } virtual int n_children() const override @@ -2087,6 +2154,7 @@ public: virtual void select(int pos) override { assert(gtk_tree_view_get_model(m_pTreeView) && "don't select when frozen"); + disable_notify_events(); if (pos != -1) { GtkTreePath* path = gtk_tree_path_new_from_indices(pos, -1); @@ -2097,6 +2165,7 @@ public: { gtk_tree_selection_unselect_all(gtk_tree_view_get_selection(m_pTreeView)); } + enable_notify_events(); } virtual OUString get_selected() override @@ -2141,14 +2210,18 @@ public: virtual void freeze() override { + disable_notify_events(); g_object_ref(m_pListStore); gtk_tree_view_set_model(m_pTreeView, nullptr); + enable_notify_events(); } virtual void thaw() override { + disable_notify_events(); gtk_tree_view_set_model(m_pTreeView, GTK_TREE_MODEL(m_pListStore)); g_object_unref(m_pListStore); + enable_notify_events(); } virtual int get_height_rows(int nRows) const override @@ -2175,6 +2248,20 @@ public: gtk_widget_set_size_request(m_pWidget, nWidth, nHeight); } + virtual void disable_notify_events() override + { + g_signal_handler_block(gtk_tree_view_get_selection(m_pTreeView), m_nChangedSignalId); + g_signal_handler_block(m_pTreeView, m_nRowActivatedSignalId); + GtkInstanceContainer::disable_notify_events(); + } + + virtual void enable_notify_events() override + { + GtkInstanceContainer::disable_notify_events(); + g_signal_handler_unblock(m_pTreeView, m_nRowActivatedSignalId); + g_signal_handler_unblock(gtk_tree_view_get_selection(m_pTreeView), m_nChangedSignalId); + } + virtual ~GtkInstanceTreeView() override { g_signal_handler_disconnect(gtk_tree_view_get_selection(m_pTreeView), m_nChangedSignalId); @@ -2228,12 +2315,16 @@ public: virtual void set_value(int value) override { + disable_notify_events(); gtk_spin_button_set_value(m_pButton, toGtk(value)); + enable_notify_events(); } virtual void set_range(int min, int max) override { + disable_notify_events(); gtk_spin_button_set_range(m_pButton, toGtk(min), toGtk(max)); + enable_notify_events(); } virtual void get_range(int& min, int& max) const override @@ -2246,7 +2337,9 @@ public: virtual void set_increments(int step, int page) override { + disable_notify_events(); gtk_spin_button_set_increments(m_pButton, toGtk(step), toGtk(page)); + enable_notify_events(); } virtual void get_increments(int& step, int& page) const override @@ -2259,7 +2352,9 @@ public: virtual void set_digits(unsigned int digits) override { + disable_notify_events(); gtk_spin_button_set_digits(m_pButton, digits); + enable_notify_events(); } virtual unsigned int get_digits() const override @@ -2267,6 +2362,18 @@ public: return gtk_spin_button_get_digits(m_pButton); } + virtual void disable_notify_events() override + { + g_signal_handler_block(m_pButton, m_nValueChangedSignalId); + GtkInstanceEntry::disable_notify_events(); + } + + virtual void enable_notify_events() override + { + GtkInstanceEntry::disable_notify_events(); + g_signal_handler_unblock(m_pButton, m_nValueChangedSignalId); + } + virtual ~GtkInstanceSpinButton() override { g_signal_handler_disconnect(m_pButton, m_nOutputSignalId); @@ -2356,12 +2463,27 @@ private: cairo_surface_t* m_pSurface; gulong m_nDrawSignalId; gulong m_nSizeAllocateSignalId; + gulong m_nButtonPressSignalId; + gulong m_nMotionSignalId; + gulong m_nButtonReleaseSignalId; static gboolean signalDraw(GtkWidget*, cairo_t* cr, gpointer widget) { GtkInstanceDrawingArea* pThis = static_cast(widget); pThis->signal_draw(cr); return false; } + void signal_draw(cairo_t* cr) + { + GdkRectangle rect; + if (!gdk_cairo_get_clip_rectangle(cr, &rect)) + return; + tools::Rectangle aRect(Point(rect.x, rect.y), Size(rect.width, rect.height)); + m_aDrawHdl.Call(std::pair(*m_xDevice, aRect)); + cairo_surface_mark_dirty(m_pSurface); + + cairo_set_source_surface(cr, m_pSurface, 0, 0); + cairo_paint(cr); + } static void signalSizeAllocate(GtkWidget*, GdkRectangle* allocation, gpointer widget) { GtkInstanceDrawingArea* pThis = static_cast(widget); @@ -2384,22 +2506,52 @@ private: #endif m_aSizeAllocateHdl.Call(Size(nWidth, nHeight)); } - void signal_draw(cairo_t* cr) + static gboolean signalButton(GtkWidget*, GdkEventButton* pEvent, gpointer widget) { - m_aDrawHdl.Call(*m_xDevice); - cairo_surface_mark_dirty(m_pSurface); - - cairo_set_source_surface(cr, m_pSurface, 0, 0); - cairo_paint(cr); + GtkInstanceDrawingArea* pThis = static_cast(widget); + return pThis->signal_button(pEvent); } + bool signal_button(GdkEventButton* pEvent) + { + Point aEvent(pEvent->x, pEvent->y); + + switch (pEvent->type) + { + case GDK_BUTTON_PRESS: + m_aMousePressHdl.Call(aEvent); + break; + case GDK_BUTTON_RELEASE: + m_aMouseReleaseHdl.Call(aEvent); + break; + default: + return false; + } + + return true; + } + static gboolean signalMotion(GtkWidget*, GdkEventMotion* pEvent, gpointer widget) + { + GtkInstanceDrawingArea* pThis = static_cast(widget); + return pThis->signal_motion(pEvent); + } + bool signal_motion(GdkEventMotion* pEvent) + { + Point aEvent(pEvent->x, pEvent->y); + m_aMouseMotionHdl.Call(aEvent); + return true; + } + public: GtkInstanceDrawingArea(GtkDrawingArea* pDrawingArea, bool bTakeOwnership) : GtkInstanceWidget(GTK_WIDGET(pDrawingArea), bTakeOwnership) , m_pDrawingArea(pDrawingArea) , m_xDevice(nullptr, Size(1, 1), DeviceFormat::DEFAULT) , m_pSurface(nullptr) - , m_nDrawSignalId(g_signal_connect(pDrawingArea, "draw", G_CALLBACK(signalDraw), this)) - , m_nSizeAllocateSignalId(g_signal_connect(pDrawingArea, "size_allocate", G_CALLBACK(signalSizeAllocate), this)) + , m_nDrawSignalId(g_signal_connect(m_pDrawingArea, "draw", G_CALLBACK(signalDraw), this)) + , m_nSizeAllocateSignalId(g_signal_connect(m_pDrawingArea, "size_allocate", G_CALLBACK(signalSizeAllocate), this)) + , m_nButtonPressSignalId(g_signal_connect(m_pDrawingArea, "button-press-event", G_CALLBACK(signalButton), this)) + , m_nMotionSignalId(g_signal_connect(m_pDrawingArea, "motion-notify-event", G_CALLBACK(signalMotion), this)) + , m_nButtonReleaseSignalId(g_signal_connect(m_pDrawingArea, "button-release-event", G_CALLBACK(signalButton), this)) { } @@ -2408,10 +2560,18 @@ public: gtk_widget_queue_draw(GTK_WIDGET(m_pDrawingArea)); } + virtual void queue_draw_area(int x, int y, int width, int height) override + { + gtk_widget_queue_draw_area(GTK_WIDGET(m_pDrawingArea), x, y, width, height); + } + virtual ~GtkInstanceDrawingArea() override { if (m_pSurface) cairo_surface_destroy(m_pSurface); + g_signal_handler_disconnect(m_pDrawingArea, m_nButtonPressSignalId); + g_signal_handler_disconnect(m_pDrawingArea, m_nMotionSignalId); + g_signal_handler_disconnect(m_pDrawingArea, m_nButtonReleaseSignalId); g_signal_handler_disconnect(m_pDrawingArea, m_nSizeAllocateSignalId); g_signal_handler_disconnect(m_pDrawingArea, m_nDrawSignalId); } @@ -2483,13 +2643,17 @@ public: virtual void set_active_id(const OUString& rStr) override { + disable_notify_events(); OString aId(OUStringToOString(rStr, RTL_TEXTENCODING_UTF8)); gtk_combo_box_set_active_id(GTK_COMBO_BOX(m_pComboBoxText), aId.getStr()); + enable_notify_events(); } virtual void set_active(int pos) override { + disable_notify_events(); gtk_combo_box_set_active(GTK_COMBO_BOX(m_pComboBoxText), pos); + enable_notify_events(); } virtual OUString get_active_text() const override @@ -2581,6 +2745,18 @@ public: gtk_tree_sortable_set_sort_column_id(pSortable, 0, GTK_SORT_ASCENDING); } + virtual void disable_notify_events() override + { + g_signal_handler_block(m_pComboBoxText, m_nSignalId); + GtkInstanceContainer::disable_notify_events(); + } + + virtual void enable_notify_events() override + { + GtkInstanceContainer::disable_notify_events(); + g_signal_handler_unblock(m_pComboBoxText, m_nSignalId); + } + virtual ~GtkInstanceComboBoxText() override { g_signal_handler_disconnect(m_pComboBoxText, m_nSignalId);