From 498897ff72589eeb7107d59650dccc9b66640679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Mon, 8 Feb 2016 15:59:22 +0000 Subject: [PATCH] gtk3: adapt to 3.20 style changes todo: get rid of the rest of the getStyleContext foo in favour of additional createStyleContext entries. This appears to now render fine on f23 and f24. upstream gtk now has a foreign drawing demo in gtk-demo. Stuff we are trying to do here can be found in a cleaner single-version state there. And additional demos can be added to keep a reference of how to do this crap up-to-date. (cherry picked from commit 03c33a2521421415c4fcbbe1491dc92a1943269b) Change-Id: I5ae1a52a2cacc6d8178ed1af30a12536ba828050 --- vcl/inc/unx/gtk/gtkgdi.hxx | 75 +- vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx | 1085 +++++++++++++++++++---------- 2 files changed, 792 insertions(+), 368 deletions(-) diff --git a/vcl/inc/unx/gtk/gtkgdi.hxx b/vcl/inc/unx/gtk/gtkgdi.hxx index e559385..13ac198 100644 --- a/vcl/inc/unx/gtk/gtkgdi.hxx +++ b/vcl/inc/unx/gtk/gtkgdi.hxx @@ -33,6 +33,43 @@ #include #include "textrender.hxx" +enum class GtkControlPart +{ + Button, + CheckButton, + CheckButtonCheck, + RadioButton, + RadioButtonRadio, + Entry, + SpinButton, + SpinButtonUpButton, + SpinButtonDownButton, + ScrollbarVertical, + ScrollbarHorizontal, + ScrollbarTrough, + ScrollbarSlider, + ScrollbarButton, + ProgressBar, + ProgressBarTrough, + ProgressBarProgress, + MenuBar, + MenuItem, + MenuItemArrow, + Menu, + CheckMenuItem, + CheckMenuItemCheck, + RadioMenuItem, + RadioMenuItemRadio, + SeparatorMenuItem, + SeparatorMenuItemSeparator, + Notebook, + NotebookHeader, + NotebookStack, + NotebookHeaderTabs, + NotebookHeaderTabsTab, + FrameBorder, +}; + class GtkSalGraphics : public SvpSalGraphics { GtkSalFrame *mpFrame; @@ -66,27 +103,47 @@ private: static GtkStyleContext *mpEntryStyle; static GtkStyleContext *mpTextViewStyle; static GtkStyleContext *mpVScrollbarStyle; + static GtkStyleContext *mpVScrollbarTroughStyle; + static GtkStyleContext *mpVScrollbarSliderStyle; + static GtkStyleContext *mpVScrollbarButtonStyle; static GtkStyleContext *mpHScrollbarStyle; + static GtkStyleContext *mpHScrollbarTroughStyle; + static GtkStyleContext *mpHScrollbarSliderStyle; + static GtkStyleContext *mpHScrollbarButtonStyle; static GtkStyleContext *mpToolbarStyle; static GtkStyleContext *mpToolButtonStyle; static GtkStyleContext *mpToolbarSeperatorStyle; static GtkStyleContext *mpCheckButtonStyle; + static GtkStyleContext *mpRadioButtonStyle; static GtkStyleContext *mpMenuBarStyle; static GtkStyleContext *mpMenuBarItemStyle; static GtkStyleContext *mpMenuStyle; static GtkStyleContext *mpSpinStyle; + static GtkStyleContext *mpSpinUpStyle; + static GtkStyleContext *mpSpinDownStyle; + static GtkStyleContext *mpMenuItemStyle; + static GtkStyleContext *mpMenuItemArrowStyle; static GtkStyleContext *mpCheckMenuItemStyle; + static GtkStyleContext *mpRadioMenuItemStyle; + static GtkStyleContext *mpSeparatorMenuItemStyle; static GtkStyleContext *mpComboboxStyle; static GtkStyleContext *mpComboboxButtonStyle; static GtkStyleContext *mpListboxStyle; static GtkStyleContext *mpListboxButtonStyle; - static GtkStyleContext *mpNoteBookStyle; static GtkStyleContext *mpFrameInStyle; static GtkStyleContext *mpFrameOutStyle; static GtkStyleContext *mpFixedHoriLineStyle; static GtkStyleContext *mpFixedVertLineStyle; static GtkStyleContext *mpTreeHeaderButtonStyle; static GtkStyleContext *mpProgressBarStyle; + static GtkStyleContext *mpProgressBarTroughStyle; + static GtkStyleContext *mpProgressBarProgressStyle; + static GtkStyleContext *mpNotebookStyle; + static GtkStyleContext *mpNotebookStackStyle; + static GtkStyleContext *mpNotebookHeaderStyle; + static GtkStyleContext *mpNotebookHeaderTabsStyle; + static GtkStyleContext *mpNotebookHeaderTabsTabStyle; + static GtkStyleContext *mpNotebookHeaderTabsTabLabelStyle; static Rectangle NWGetScrollButtonRect( ControlPart nPart, Rectangle aAreaRect ); static Rectangle NWGetSpinButtonRect( ControlPart nPart, Rectangle aAreaRect); @@ -116,10 +173,16 @@ private: ControlType nType, ControlPart nPart, const ImplControlValue& aValue); - static void PaintCheckOrRadio(GtkStyleContext *context, - cairo_t *cr, - const Rectangle& rControlRectangle, - ControlType nType); + static void PaintCheckOrRadio(cairo_t *cr, GtkStyleContext *context, + const Rectangle& rControlRectangle, + bool bIsCheck, bool bInMenu); + + static void PaintCheck(cairo_t *cr, GtkStyleContext *context, + const Rectangle& rControlRectangle, bool bInMenu); + + static void PaintRadio(cairo_t *cr, GtkStyleContext *context, + const Rectangle& rControlRectangle, bool bInMenu); + static bool style_loaded; }; diff --git a/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx b/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx index a28938e..a6b235b 100644 --- a/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx +++ b/vcl/unx/gtk3/gtk3salnativewidgets-gtk.cxx @@ -25,64 +25,86 @@ GtkStyleContext* GtkSalGraphics::mpButtonStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpEntryStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpTextViewStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpVScrollbarStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpVScrollbarTroughStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpVScrollbarSliderStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpVScrollbarButtonStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpHScrollbarStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpHScrollbarTroughStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpHScrollbarSliderStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpHScrollbarButtonStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpToolbarStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpToolButtonStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpToolbarSeperatorStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpCheckButtonStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpRadioButtonStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpMenuBarStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpMenuBarItemStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpMenuStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpMenuItemStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpMenuItemArrowStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpCheckMenuItemStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpRadioMenuItemStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpSeparatorMenuItemStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpSpinStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpSpinUpStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpSpinDownStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpComboboxStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpComboboxButtonStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpListboxStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpListboxButtonStyle = nullptr; -GtkStyleContext* GtkSalGraphics::mpNoteBookStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpFrameInStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpFrameOutStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpFixedHoriLineStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpFixedVertLineStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpTreeHeaderButtonStyle = nullptr; GtkStyleContext* GtkSalGraphics::mpProgressBarStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpProgressBarTroughStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpProgressBarProgressStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpNotebookStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpNotebookStackStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpNotebookHeaderStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpNotebookHeaderTabsStyle = nullptr; +GtkStyleContext* GtkSalGraphics::mpNotebookHeaderTabsTabStyle = nullptr; bool GtkSalGraphics::style_loaded = false; /************************************************************************ * State conversion ************************************************************************/ -static void NWConvertVCLStateToGTKState( ControlState nVCLState, - GtkStateFlags* nGTKState, GtkShadowType* nGTKShadow ) +static GtkStateFlags NWConvertVCLStateToGTKState(ControlState nVCLState) { - *nGTKShadow = GTK_SHADOW_OUT; - *nGTKState = GTK_STATE_FLAG_NORMAL; + GtkStateFlags nGTKState = GTK_STATE_FLAG_NORMAL; if (!( nVCLState & ControlState::ENABLED )) { - *nGTKState = GTK_STATE_FLAG_INSENSITIVE; + nGTKState = GTK_STATE_FLAG_INSENSITIVE; } if ( nVCLState & ControlState::PRESSED ) { - *nGTKState = (GtkStateFlags) (*nGTKState | GTK_STATE_FLAG_ACTIVE); - *nGTKShadow = GTK_SHADOW_IN; + nGTKState = (GtkStateFlags) (nGTKState | GTK_STATE_FLAG_ACTIVE); } if ( nVCLState & ControlState::ROLLOVER ) { - *nGTKState = (GtkStateFlags) (*nGTKState | GTK_STATE_FLAG_PRELIGHT); + nGTKState = (GtkStateFlags) (nGTKState | GTK_STATE_FLAG_PRELIGHT); } if ( nVCLState & ControlState::SELECTED ) - *nGTKState = (GtkStateFlags) (*nGTKState | GTK_STATE_FLAG_SELECTED); + nGTKState = (GtkStateFlags) (nGTKState | GTK_STATE_FLAG_SELECTED); if ( nVCLState & ControlState::FOCUSED ) - *nGTKState = (GtkStateFlags) (*nGTKState | GTK_STATE_FLAG_FOCUSED); + nGTKState = (GtkStateFlags) (nGTKState | GTK_STATE_FLAG_FOCUSED); if (AllSettings::GetLayoutRTL()) { - *nGTKState = (GtkStateFlags) (*nGTKState | GTK_STATE_FLAG_DIR_RTL); + nGTKState = (GtkStateFlags) (nGTKState | GTK_STATE_FLAG_DIR_RTL); } + else + { + nGTKState = (GtkStateFlags) (nGTKState | GTK_STATE_FLAG_DIR_LTR); + } + + return nGTKState; } enum { @@ -117,16 +139,13 @@ static void NWCalcArrowRect( const Rectangle& rButton, Rectangle& rArrow ) Rectangle GtkSalGraphics::NWGetSpinButtonRect( ControlPart nPart, Rectangle aAreaRect) { - gtk_style_context_save(mpSpinStyle); - gtk_style_context_add_class(mpSpinStyle, GTK_STYLE_CLASS_BUTTON); - gint w, h; gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h); gint icon_size = std::max(w, h); GtkBorder padding, border; - gtk_style_context_get_padding(mpSpinStyle, GTK_STATE_FLAG_NORMAL, &padding); - gtk_style_context_get_border(mpSpinStyle, GTK_STATE_FLAG_NORMAL, &border); + gtk_style_context_get_padding(mpSpinUpStyle, gtk_style_context_get_state(mpSpinUpStyle), &padding); + gtk_style_context_get_border(mpSpinUpStyle, gtk_style_context_get_state(mpSpinUpStyle), &border); gint buttonWidth = icon_size + padding.left + padding.right + border.left + border.right; @@ -169,8 +188,6 @@ Rectangle GtkSalGraphics::NWGetSpinButtonRect( ControlPart nPart, Rectangle aAre partRect.Bottom() = aAreaRect.Bottom(); } - gtk_style_context_restore(mpSpinStyle); - return partRect; } @@ -271,7 +288,6 @@ void GtkSalGraphics::PaintScrollbar(GtkStyleContext *context, const ScrollbarValue& rScrollbarVal = static_cast(rValue); Rectangle scrollbarRect; GtkStateFlags stateFlags; - GtkShadowType shadowType; GtkOrientation scrollbarOrientation; Rectangle thumbRect = rScrollbarVal.maThumbRect; Rectangle button11BoundRect = rScrollbarVal.maButton1Rect; // backward @@ -281,8 +297,6 @@ void GtkSalGraphics::PaintScrollbar(GtkStyleContext *context, gdouble arrow1Angle; // backward gdouble arrow2Angle; // forward Rectangle arrowRect; - const gchar* button1StyleClass = nullptr; - const gchar* button2StyleClass = nullptr; gint slider_width = 0; gint stepper_size = 0; gint stepper_spacing = 0; @@ -332,8 +346,6 @@ void GtkSalGraphics::PaintScrollbar(GtkStyleContext *context, scrollbarOrientation = GTK_ORIENTATION_HORIZONTAL; arrow1Angle = G_PI * 3 / 2; arrow2Angle = G_PI / 2; - button1StyleClass = GTK_STYLE_CLASS_LEFT; - button2StyleClass = GTK_STYLE_CLASS_RIGHT; if ( has_backward ) { @@ -374,8 +386,6 @@ void GtkSalGraphics::PaintScrollbar(GtkStyleContext *context, scrollbarOrientation = GTK_ORIENTATION_VERTICAL; arrow1Angle = 0; arrow2Angle = G_PI; - button1StyleClass = GTK_STYLE_CLASS_TOP; - button2StyleClass = GTK_STYLE_CLASS_BOTTOM; if ( has_backward ) { @@ -409,37 +419,34 @@ void GtkSalGraphics::PaintScrollbar(GtkStyleContext *context, bool has_slider = ( thumbRect.GetWidth() > 0 && thumbRect.GetHeight() > 0 ); // ----------------- TROUGH - gtk_style_context_save(context); - gtk_style_context_add_class(context, GTK_STYLE_CLASS_TROUGH); - gtk_render_background(context, cr, 0, 0, + GtkStyleContext* pScrollbarTroughStyle = scrollbarOrientation == GTK_ORIENTATION_VERTICAL ? + mpVScrollbarTroughStyle : mpHScrollbarTroughStyle; + gtk_render_background(pScrollbarTroughStyle, cr, 0, 0, scrollbarRect.GetWidth(), scrollbarRect.GetHeight() ); - gtk_render_frame(context, cr, 0, 0, + gtk_render_frame(pScrollbarTroughStyle, cr, 0, 0, scrollbarRect.GetWidth(), scrollbarRect.GetHeight() ); - gtk_style_context_restore(context); - // ----------------- THUMB if ( has_slider ) { - NWConvertVCLStateToGTKState( rScrollbarVal.mnThumbState, &stateFlags, &shadowType ); + stateFlags = NWConvertVCLStateToGTKState(rScrollbarVal.mnThumbState); if ( rScrollbarVal.mnThumbState & ControlState::PRESSED ) stateFlags = (GtkStateFlags) (stateFlags | GTK_STATE_PRELIGHT); - gtk_style_context_save(context); - gtk_style_context_set_state(context, stateFlags); - gtk_style_context_add_class(context, GTK_STYLE_CLASS_SLIDER); + GtkStyleContext* pScrollbarSliderStyle = scrollbarOrientation == GTK_ORIENTATION_VERTICAL ? + mpVScrollbarSliderStyle : mpHScrollbarSliderStyle; + + gtk_style_context_set_state(pScrollbarSliderStyle, stateFlags); GtkBorder margin; - gtk_style_context_get_margin(context, stateFlags, &margin); + gtk_style_context_get_margin(pScrollbarSliderStyle, stateFlags, &margin); - gtk_render_slider(context, cr, + gtk_render_slider(pScrollbarSliderStyle, cr, thumbRect.Left() + margin.left, thumbRect.Top() + margin.top, thumbRect.GetWidth() - margin.left - margin.right, thumbRect.GetHeight() - margin.top - margin.bottom, scrollbarOrientation); - - gtk_style_context_restore(context); } bool backwardButtonInsensitive = @@ -450,112 +457,104 @@ void GtkSalGraphics::PaintScrollbar(GtkStyleContext *context, // ----------------- BUTTON 1 if ( has_backward ) { - NWConvertVCLStateToGTKState( rScrollbarVal.mnButton1State, &stateFlags, &shadowType ); + stateFlags = NWConvertVCLStateToGTKState(rScrollbarVal.mnButton1State); if ( backwardButtonInsensitive ) stateFlags = GTK_STATE_FLAG_INSENSITIVE; - gtk_style_context_save(context); - gtk_style_context_set_state(context, stateFlags); - gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON); - gtk_style_context_add_class(context, button1StyleClass); + GtkStyleContext* pScrollbarButtonStyle = scrollbarOrientation == GTK_ORIENTATION_VERTICAL ? + mpVScrollbarButtonStyle : mpHScrollbarButtonStyle; - gtk_render_background(context, cr, + gtk_style_context_set_state(pScrollbarButtonStyle, stateFlags); + + gtk_render_background(pScrollbarButtonStyle, cr, button11BoundRect.Left(), button11BoundRect.Top(), button11BoundRect.GetWidth(), button11BoundRect.GetHeight() ); - gtk_render_frame(context, cr, + gtk_render_frame(pScrollbarButtonStyle, cr, button11BoundRect.Left(), button11BoundRect.Top(), button11BoundRect.GetWidth(), button11BoundRect.GetHeight() ); // ----------------- ARROW 1 NWCalcArrowRect( button11BoundRect, arrowRect ); - gtk_render_arrow(context, cr, + gtk_render_arrow(pScrollbarButtonStyle, cr, arrow1Angle, arrowRect.Left(), arrowRect.Top(), MIN(arrowRect.GetWidth(), arrowRect.GetHeight()) ); - - gtk_style_context_restore(context); } if ( has_forward2 ) { - NWConvertVCLStateToGTKState( rScrollbarVal.mnButton2State, &stateFlags, &shadowType ); + stateFlags = NWConvertVCLStateToGTKState(rScrollbarVal.mnButton2State); if ( forwardButtonInsensitive ) stateFlags = GTK_STATE_FLAG_INSENSITIVE; - gtk_style_context_save(context); - gtk_style_context_set_state(context, stateFlags); - gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON); - gtk_style_context_add_class(context, button1StyleClass); + GtkStyleContext* pScrollbarButtonStyle = scrollbarOrientation == GTK_ORIENTATION_VERTICAL ? + mpVScrollbarButtonStyle : mpHScrollbarButtonStyle; + + gtk_style_context_set_state(pScrollbarButtonStyle, stateFlags); - gtk_render_background(context, cr, + gtk_render_background(pScrollbarButtonStyle, cr, button12BoundRect.Left(), button12BoundRect.Top(), button12BoundRect.GetWidth(), button12BoundRect.GetHeight() ); - gtk_render_frame(context, cr, + gtk_render_frame(pScrollbarButtonStyle, cr, button12BoundRect.Left(), button12BoundRect.Top(), button12BoundRect.GetWidth(), button12BoundRect.GetHeight() ); // ----------------- ARROW 1 NWCalcArrowRect( button12BoundRect, arrowRect ); - gtk_render_arrow(context, cr, + gtk_render_arrow(pScrollbarButtonStyle, cr, arrow2Angle, arrowRect.Left(), arrowRect.Top(), MIN(arrowRect.GetWidth(), arrowRect.GetHeight()) ); - - gtk_style_context_restore(context); } // ----------------- BUTTON 2 if ( has_backward2 ) { - NWConvertVCLStateToGTKState( rScrollbarVal.mnButton1State, &stateFlags, &shadowType ); + stateFlags = NWConvertVCLStateToGTKState(rScrollbarVal.mnButton1State); if ( backwardButtonInsensitive ) stateFlags = GTK_STATE_FLAG_INSENSITIVE; - gtk_style_context_save(context); - gtk_style_context_set_state(context, stateFlags); - gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON); - gtk_style_context_add_class(context, button2StyleClass); + GtkStyleContext* pScrollbarButtonStyle = scrollbarOrientation == GTK_ORIENTATION_VERTICAL ? + mpVScrollbarButtonStyle : mpHScrollbarButtonStyle; + + gtk_style_context_set_state(pScrollbarButtonStyle, stateFlags); - gtk_render_background(context, cr, + gtk_render_background(pScrollbarButtonStyle, cr, button21BoundRect.Left(), button21BoundRect.Top(), button21BoundRect.GetWidth(), button21BoundRect.GetHeight() ); - gtk_render_frame(context, cr, + gtk_render_frame(pScrollbarButtonStyle, cr, button21BoundRect.Left(), button21BoundRect.Top(), button21BoundRect.GetWidth(), button21BoundRect.GetHeight() ); // ----------------- ARROW 2 NWCalcArrowRect( button21BoundRect, arrowRect ); - gtk_render_arrow(context, cr, + gtk_render_arrow(pScrollbarButtonStyle, cr, arrow1Angle, arrowRect.Left(), arrowRect.Top(), MIN(arrowRect.GetWidth(), arrowRect.GetHeight()) ); - - gtk_style_context_restore(context); } if ( has_forward ) { - NWConvertVCLStateToGTKState( rScrollbarVal.mnButton2State, &stateFlags, &shadowType ); + stateFlags = NWConvertVCLStateToGTKState(rScrollbarVal.mnButton2State); if ( forwardButtonInsensitive ) stateFlags = GTK_STATE_FLAG_INSENSITIVE; - gtk_style_context_save(context); - gtk_style_context_set_state(context, stateFlags); - gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON); - gtk_style_context_add_class(context, button2StyleClass); + GtkStyleContext* pScrollbarButtonStyle = scrollbarOrientation == GTK_ORIENTATION_VERTICAL ? + mpVScrollbarButtonStyle : mpHScrollbarButtonStyle; - gtk_render_background(context, cr, + gtk_style_context_set_state(pScrollbarButtonStyle, stateFlags); + + gtk_render_background(pScrollbarButtonStyle, cr, button22BoundRect.Left(), button22BoundRect.Top(), button22BoundRect.GetWidth(), button22BoundRect.GetHeight() ); - gtk_render_frame(context, cr, + gtk_render_frame(pScrollbarButtonStyle, cr, button22BoundRect.Left(), button22BoundRect.Top(), button22BoundRect.GetWidth(), button22BoundRect.GetHeight() ); // ----------------- ARROW 2 NWCalcArrowRect( button22BoundRect, arrowRect ); - gtk_render_arrow(context, cr, + gtk_render_arrow(pScrollbarButtonStyle, cr, arrow2Angle, arrowRect.Left(), arrowRect.Top(), MIN(arrowRect.GetWidth(), arrowRect.GetHeight()) ); - - gtk_style_context_restore(context); } } @@ -567,20 +566,15 @@ void GtkSalGraphics::PaintOneSpinButton( GtkStyleContext *context, ControlState nState ) { (void)nType; - Rectangle buttonRect; - GtkStateFlags stateFlags; - GtkShadowType shadowType; GtkBorder padding, border; - NWConvertVCLStateToGTKState( nState, &stateFlags, &shadowType ); - buttonRect = NWGetSpinButtonRect( nPart, aAreaRect ); + GtkStateFlags stateFlags = NWConvertVCLStateToGTKState(nState); + Rectangle buttonRect = NWGetSpinButtonRect( nPart, aAreaRect ); - gtk_style_context_save(context); gtk_style_context_set_state(context, stateFlags); - gtk_style_context_add_class(context, GTK_STYLE_CLASS_BUTTON); - gtk_style_context_get_padding(context, GTK_STATE_FLAG_NORMAL, &padding); - gtk_style_context_get_border(context, GTK_STATE_FLAG_NORMAL, &border); + gtk_style_context_get_padding(context, gtk_style_context_get_state(context), &padding); + gtk_style_context_get_border(context, gtk_style_context_get_state(context), &border); gtk_render_background(context, cr, buttonRect.Left(), buttonRect.Top(), @@ -613,8 +607,6 @@ void GtkSalGraphics::PaintOneSpinButton( GtkStyleContext *context, gtk_render_icon(context, cr, pixbuf, arrowRect.Left(), arrowRect.Top()); g_object_unref(pixbuf); gtk_icon_info_free(info); - - gtk_style_context_restore(context); } void GtkSalGraphics::PaintSpinButton(GtkStyleContext *context, @@ -668,14 +662,12 @@ Rectangle GtkSalGraphics::NWGetComboBoxButtonRect( ControlType nType, (void)nType; (void)nPart; Rectangle aButtonRect; - gint nArrowWidth; - gint nButtonWidth; - GtkBorder padding; - gtk_style_context_get_padding( mpButtonStyle, GTK_STATE_FLAG_NORMAL, &padding); + GtkBorder padding; + gtk_style_context_get_padding( mpButtonStyle, gtk_style_context_get_state(mpButtonStyle), &padding); - nArrowWidth = ARROW_SIZE; - nButtonWidth = nArrowWidth + padding.left + padding.right; + gint nArrowWidth = ARROW_SIZE; + gint nButtonWidth = nArrowWidth + padding.left + padding.right; if( nPart == PART_BUTTON_DOWN ) { Point aPos = Point(aAreaRect.Left() + aAreaRect.GetWidth() - nButtonWidth, aAreaRect.Top()); @@ -741,7 +733,7 @@ void GtkSalGraphics::PaintCombobox( GtkStateFlags flags, cairo_t *cr, if( nPart == PART_ENTIRE_CONTROL ) { - gtk_style_context_save(mpEntryStyle); + GtkJunctionSides eJuncSides = gtk_style_context_get_junction_sides(mpEntryStyle); gtk_style_context_set_state(mpEntryStyle, flags); if (AllSettings::GetLayoutRTL()) gtk_style_context_set_junction_sides(mpEntryStyle, GTK_JUNCTION_LEFT); @@ -762,8 +754,7 @@ void GtkSalGraphics::PaintCombobox( GtkStateFlags flags, cairo_t *cr, (aEditBoxRect.Left() - areaRect.Left()), (aEditBoxRect.Top() - areaRect.Top()), aEditBoxRect.GetWidth(), aEditBoxRect.GetHeight() ); - - gtk_style_context_restore(mpEntryStyle); + gtk_style_context_set_junction_sides(mpEntryStyle, eJuncSides); } gtk_render_background(mpComboboxButtonStyle, cr, @@ -820,30 +811,327 @@ void GtkSalGraphics::PaintCombobox( GtkStateFlags flags, cairo_t *cr, } } -void GtkSalGraphics::PaintCheckOrRadio(GtkStyleContext *context, - cairo_t *cr, - const Rectangle& rControlRectangle, - ControlType nType) +static GtkStyleContext* createStyleContext(GtkControlPart ePart, GtkStyleContext* parent = nullptr) +{ + GtkWidgetPath *path = parent ? gtk_widget_path_copy(gtk_style_context_get_path(parent)) : gtk_widget_path_new(); + switch (ePart) + { + case GtkControlPart::Button: + gtk_widget_path_append_type(path, GTK_TYPE_BUTTON); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "button"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_BUTTON); +#endif + break; + case GtkControlPart::CheckButton: + gtk_widget_path_append_type(path, GTK_TYPE_CHECK_BUTTON); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "checkbutton"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_CHECK); +#endif + break; + case GtkControlPart::CheckButtonCheck: + gtk_widget_path_append_type(path, GTK_TYPE_CHECK_BUTTON); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "check"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_CHECK); +#endif + break; + case GtkControlPart::RadioButton: + gtk_widget_path_append_type(path, GTK_TYPE_RADIO_BUTTON); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "radiobutton"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_RADIO); +#endif + break; + case GtkControlPart::RadioButtonRadio: + gtk_widget_path_append_type(path, GTK_TYPE_RADIO_BUTTON); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "radio"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_RADIO); +#endif + break; + case GtkControlPart::Entry: + gtk_widget_path_append_type(path, GTK_TYPE_ENTRY); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "entry"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_ENTRY); +#endif + break; + case GtkControlPart::SpinButton: + gtk_widget_path_append_type(path, GTK_TYPE_SPIN_BUTTON); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "spinbutton"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_SPINBUTTON); +#endif + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_HORIZONTAL); + break; + case GtkControlPart::SpinButtonUpButton: + case GtkControlPart::SpinButtonDownButton: + gtk_widget_path_append_type(path, GTK_TYPE_SPIN_BUTTON); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "button"); + gtk_widget_path_iter_add_class(path, -1, ePart == GtkControlPart::SpinButtonUpButton ? "up" : "down"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_SPINBUTTON); + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_BUTTON); +#endif + break; + case GtkControlPart::ScrollbarVertical: + case GtkControlPart::ScrollbarHorizontal: + gtk_widget_path_append_type(path, GTK_TYPE_SCROLLBAR); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "scrollbar"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_SCROLLBAR); +#endif + gtk_widget_path_iter_add_class(path, -1, ePart == GtkControlPart::ScrollbarVertical ? "vertical" : "horizontal"); + break; + case GtkControlPart::ScrollbarTrough: + gtk_widget_path_append_type(path, GTK_TYPE_SCROLLBAR); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "trough"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_SCROLLBAR); + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_TROUGH); +#endif + break; + case GtkControlPart::ScrollbarSlider: + gtk_widget_path_append_type(path, GTK_TYPE_SCROLLBAR); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "slider"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_SCROLLBAR); + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_SLIDER); +#endif + break; + case GtkControlPart::ScrollbarButton: + gtk_widget_path_append_type(path, GTK_TYPE_SCROLLBAR); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "button"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_SCROLLBAR); + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_BUTTON); +#endif + break; + case GtkControlPart::ProgressBar: + gtk_widget_path_append_type(path, GTK_TYPE_PROGRESS_BAR); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "progressbar"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_PROGRESSBAR); +#endif + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_HORIZONTAL); + break; + case GtkControlPart::ProgressBarTrough: + gtk_widget_path_append_type(path, GTK_TYPE_PROGRESS_BAR); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "trough"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_PROGRESSBAR); + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_TROUGH); +#endif + break; + case GtkControlPart::ProgressBarProgress: + gtk_widget_path_append_type(path, GTK_TYPE_PROGRESS_BAR); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "progress"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_PROGRESSBAR); +#endif + break; + case GtkControlPart::MenuBar: + gtk_widget_path_append_type(path, GTK_TYPE_MENU_BAR); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "menubar"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_MENUBAR); +#endif + break; + case GtkControlPart::MenuItem: + gtk_widget_path_append_type(path, GTK_TYPE_MENU_ITEM); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "menuitem"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_MENUITEM); +#endif + break; + case GtkControlPart::MenuItemArrow: + gtk_widget_path_append_type(path, GTK_TYPE_MENU_ITEM); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "arrow"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_ARROW); +#endif + break; + case GtkControlPart::Menu: + gtk_widget_path_append_type(path, GTK_TYPE_MENU); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "menu"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_MENU); +#endif + break; + case GtkControlPart::CheckMenuItem: + gtk_widget_path_append_type(path, GTK_TYPE_CHECK_MENU_ITEM); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "menuitem"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_MENUITEM); +#endif + break; + case GtkControlPart::CheckMenuItemCheck: + gtk_widget_path_append_type(path, GTK_TYPE_CHECK_MENU_ITEM); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "check"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_CHECK); +#endif + break; + case GtkControlPart::RadioMenuItem: + gtk_widget_path_append_type(path, GTK_TYPE_RADIO_MENU_ITEM); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "menuitem"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_MENUITEM); +#endif + break; + case GtkControlPart::RadioMenuItemRadio: + gtk_widget_path_append_type(path, GTK_TYPE_RADIO_MENU_ITEM); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "radio"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_RADIO); +#endif + break; + case GtkControlPart::SeparatorMenuItem: + gtk_widget_path_append_type(path, GTK_TYPE_SEPARATOR_MENU_ITEM); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "menuitem"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_MENUITEM); +#endif + break; + case GtkControlPart::SeparatorMenuItemSeparator: + gtk_widget_path_append_type(path, GTK_TYPE_SEPARATOR_MENU_ITEM); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "separator"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_SEPARATOR); +#endif + break; + case GtkControlPart::Notebook: + gtk_widget_path_append_type(path, GTK_TYPE_NOTEBOOK); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "notebook"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_NOTEBOOK); +#endif + gtk_widget_path_iter_add_class(path, -1, "frame"); + break; + case GtkControlPart::NotebookStack: + gtk_widget_path_append_type(path, GTK_TYPE_NOTEBOOK); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "stack"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_NOTEBOOK); +#endif + break; + case GtkControlPart::NotebookHeader: + gtk_widget_path_append_type(path, GTK_TYPE_NOTEBOOK); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "header"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_HEADER); +#endif + gtk_widget_path_iter_add_class(path, -1, "frame"); + gtk_widget_path_iter_add_class(path, -1, "top"); + break; + case GtkControlPart::NotebookHeaderTabs: + gtk_widget_path_append_type(path, GTK_TYPE_NOTEBOOK); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "tabs"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_HEADER); +#endif + gtk_widget_path_iter_add_class(path, -1, "top"); + break; + case GtkControlPart::NotebookHeaderTabsTab: + gtk_widget_path_append_type(path, GTK_TYPE_NOTEBOOK); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "tab"); +#else + gtk_widget_path_iter_add_class(path, -1, GTK_STYLE_CLASS_HEADER); +#endif + gtk_widget_path_iter_add_class(path, -1, "top"); + break; + case GtkControlPart::FrameBorder: + gtk_widget_path_append_type(path, GTK_TYPE_FRAME); +#if GTK_CHECK_VERSION(3, 19, 2) + gtk_widget_path_iter_set_object_name(path, -1, "frame"); +#endif + gtk_widget_path_iter_add_class(path, -1, "frame"); + break; + } + + GtkStyleContext* context = gtk_style_context_new(); + gtk_style_context_set_path(context, path); + gtk_style_context_set_parent(context, parent); + gtk_widget_path_unref (path); + +#if !GTK_CHECK_VERSION(3, 19, 2) + if (ePart == GtkControlPart::NotebookHeaderTabsTab) + { + gtk_style_context_add_region(context, GTK_STYLE_REGION_TAB, GTK_REGION_ONLY); + } +#endif + + return context; +} + +#if GTK_CHECK_VERSION(3,13,7) +# define CHECKED GTK_STATE_FLAG_CHECKED +#else +# define CHECKED GTK_STATE_FLAG_ACTIVE +#endif + +void GtkSalGraphics::PaintCheckOrRadio(cairo_t *cr, GtkStyleContext *context, + const Rectangle& rControlRectangle, bool bIsCheck, bool bInMenu) { gint indicator_size; - gtk_style_context_get_style(mpCheckButtonStyle, - "indicator-size", &indicator_size, - NULL); + gtk_style_context_get_style(context, "indicator-size", &indicator_size, nullptr); gint x = (rControlRectangle.GetWidth() - indicator_size) / 2; gint y = (rControlRectangle.GetHeight() - indicator_size) / 2; - if (nType == CTRL_CHECKBOX) + if (!bInMenu) + gtk_render_background(context, cr, x, y, indicator_size, indicator_size); + gtk_render_frame(context, cr, x, y, indicator_size, indicator_size); + + if (bIsCheck) gtk_render_check(context, cr, x, y, indicator_size, indicator_size); - else if (nType == CTRL_RADIOBUTTON) + else gtk_render_option(context, cr, x, y, indicator_size, indicator_size); } -#if GTK_CHECK_VERSION(3,14,0) -# define CHECKED GTK_STATE_FLAG_CHECKED -#else -# define CHECKED GTK_STATE_FLAG_ACTIVE -#endif +void GtkSalGraphics::PaintCheck(cairo_t *cr, GtkStyleContext *context, + const Rectangle& rControlRectangle, bool bInMenu) +{ + PaintCheckOrRadio(cr, context, rControlRectangle, true, bInMenu); +} + +void GtkSalGraphics::PaintRadio(cairo_t *cr, GtkStyleContext *context, + const Rectangle& rControlRectangle, bool bInMenu) +{ + PaintCheckOrRadio(cr, context, rControlRectangle, false, bInMenu); +} static GtkWidget* gCacheWindow; static GtkWidget* gDumbContainer; @@ -854,31 +1142,46 @@ static GtkWidget* gComboBoxButtonWidget; static GtkWidget* gComboBoxEntryWidget; static GtkWidget* gListBox; static GtkWidget* gListBoxButtonWidget; -static GtkWidget* gFrameIn; -static GtkWidget* gFrameOut; static GtkWidget* gMenuBarWidget; static GtkWidget* gMenuItemMenuBarWidget; static GtkWidget* gCheckMenuItemWidget; static GtkWidget* gTreeViewWidget; +void parent_styles_context_set_state(GtkStyleContext* context, GtkStateFlags flags) +{ + while ((context = gtk_style_context_get_parent(context))) + { + gtk_style_context_set_state(context, flags); + } +} + +static gfloat getArrowSize(GtkStyleContext* context) +{ + gfloat arrow_scaling = 1.0; + gtk_style_context_get_style(context, "arrow-scaling", &arrow_scaling, nullptr); + gfloat arrow_size = 11 * arrow_scaling; + return arrow_size; +} + bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, const Rectangle& rControlRegion, ControlState nState, const ImplControlValue& rValue, const OUString& ) { - GtkStateFlags flags; - GtkShadowType shadow; gint renderType = nPart == PART_FOCUS ? RENDER_FOCUS : RENDER_BACKGROUND_AND_FRAME; GtkStyleContext *context = nullptr; +#if !GTK_CHECK_VERSION(3,19,2) const gchar *styleClass = nullptr; +#endif GdkPixbuf *pixbuf = nullptr; + bool bInMenu = false; - NWConvertVCLStateToGTKState(nState, &flags, &shadow); + GtkStateFlags flags = NWConvertVCLStateToGTKState(nState); switch(nType) { case CTRL_SPINBOX: case CTRL_SPINBUTTONS: - context = mpSpinStyle; + context = mpEntryStyle; renderType = RENDER_SPINBUTTON; break; case CTRL_EDITBOX: @@ -896,42 +1199,58 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co renderType = nPart == PART_FOCUS ? RENDER_FOCUS : RENDER_COMBOBOX; break; case CTRL_MENU_POPUP: + bInMenu = true; // map selected menu entries in vcl parlance to gtk prelight if (nPart >= PART_MENU_ITEM && nPart <= PART_MENU_SUBMENU_ARROW && (nState & ControlState::SELECTED)) flags = (GtkStateFlags) (flags | GTK_STATE_FLAG_PRELIGHT); - + flags = (GtkStateFlags)(flags & ~GTK_STATE_FLAG_ACTIVE); switch(nPart) { case PART_MENU_ITEM: - styleClass = GTK_STYLE_CLASS_MENUITEM; - context = mpCheckMenuItemStyle; + context = mpMenuItemStyle; renderType = RENDER_BACKGROUND_AND_FRAME; break; case PART_MENU_ITEM_CHECK_MARK: - styleClass = GTK_STYLE_CLASS_CHECK; +#if GTK_CHECK_VERSION(3,19,2) context = mpCheckMenuItemStyle; +#else + context = gtk_widget_get_style_context(gCheckMenuItemWidget); + styleClass = GTK_STYLE_CLASS_CHECK; +#endif renderType = RENDER_CHECK; nType = CTRL_CHECKBOX; if (nState & ControlState::PRESSED) + { flags = (GtkStateFlags)(flags | CHECKED); + } break; case PART_MENU_ITEM_RADIO_MARK: +#if GTK_CHECK_VERSION(3,19,2) + context = mpRadioMenuItemStyle; +#else + context = gtk_widget_get_style_context(gCheckMenuItemWidget); styleClass = GTK_STYLE_CLASS_RADIO; - context = mpCheckMenuItemStyle; +#endif renderType = RENDER_RADIO; nType = CTRL_RADIOBUTTON; if (nState & ControlState::PRESSED) + { flags = (GtkStateFlags)(flags | CHECKED); + } break; case PART_MENU_SEPARATOR: - styleClass = GTK_STYLE_CLASS_SEPARATOR; - context = mpCheckMenuItemStyle; + context = mpSeparatorMenuItemStyle; + flags = (GtkStateFlags)(GTK_STATE_FLAG_BACKDROP | GTK_STATE_FLAG_INSENSITIVE); //GTK_STATE_FLAG_BACKDROP hack ? renderType = RENDER_MENU_SEPERATOR; break; case PART_MENU_SUBMENU_ARROW: +#if GTK_CHECK_VERSION(3,19,2) + context = mpMenuItemArrowStyle; +#else + context = gtk_widget_get_style_context(gCheckMenuItemWidget); styleClass = GTK_STYLE_CLASS_ARROW; - context = mpCheckMenuItemStyle; +#endif renderType = RENDER_ARROW; break; case PART_ENTIRE_CONTROL: @@ -961,22 +1280,20 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co return false; } break; + case CTRL_RADIOBUTTON: + flags = (GtkStateFlags)(flags | + ( (rValue.getTristateVal() == BUTTONVALUE_ON) ? CHECKED : GTK_STATE_FLAG_NORMAL)); + context = mpRadioButtonStyle; + renderType = nPart == PART_FOCUS ? RENDER_FOCUS : RENDER_RADIO; + break; case CTRL_CHECKBOX: flags = (GtkStateFlags)(flags | ( (rValue.getTristateVal() == BUTTONVALUE_ON) ? CHECKED : (rValue.getTristateVal() == BUTTONVALUE_MIXED) ? GTK_STATE_FLAG_INCONSISTENT : GTK_STATE_FLAG_NORMAL)); context = mpCheckButtonStyle; - styleClass = GTK_STYLE_CLASS_CHECK; renderType = nPart == PART_FOCUS ? RENDER_FOCUS : RENDER_CHECK; break; - case CTRL_RADIOBUTTON: - flags = (GtkStateFlags)(flags | - ( (rValue.getTristateVal() == BUTTONVALUE_ON) ? CHECKED : GTK_STATE_FLAG_NORMAL)); - context = mpCheckButtonStyle; - styleClass = GTK_STYLE_CLASS_RADIO; - renderType = nPart == PART_FOCUS ? RENDER_FOCUS : RENDER_RADIO; - break; case CTRL_PUSHBUTTON: context = mpButtonStyle; break; @@ -992,21 +1309,20 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co } break; case CTRL_LISTNET: - case CTRL_TAB_BODY: - return true; break; case CTRL_TAB_PANE: - context = mpNoteBookStyle; + context = mpNotebookStyle; + break; + case CTRL_TAB_BODY: + context = mpNotebookStackStyle; break; case CTRL_TAB_HEADER: - context = mpNoteBookStyle; - styleClass = GTK_STYLE_CLASS_HEADER; + context = mpNotebookHeaderStyle; break; case CTRL_TAB_ITEM: - context = mpNoteBookStyle; + context = mpNotebookHeaderTabsTabStyle; if (nState & ControlState::SELECTED) flags = (GtkStateFlags) (flags | GTK_STATE_FLAG_ACTIVE); - break; case CTRL_WINDOW_BACKGROUND: context = gtk_widget_get_style_context(mpWindow); @@ -1024,7 +1340,6 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co if (nPart == PART_MENU_ITEM) { context = mpMenuBarItemStyle; - styleClass = GTK_STYLE_CLASS_MENUBAR; flags = (!(nState & ControlState::ENABLED)) ? GTK_STATE_FLAG_INSENSITIVE : GTK_STATE_FLAG_NORMAL; if (nState & ControlState::SELECTED) @@ -1032,8 +1347,8 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co } else { - context = gtk_widget_get_style_context(gMenuBarWidget); - styleClass = GTK_STYLE_CLASS_BACKGROUND; + // context = mpMenuBarStyle; why does this not work + context = gtk_widget_get_style_context(mpWindow); } break; case CTRL_FIXEDLINE: @@ -1047,7 +1362,6 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co if (aButtonValue == BUTTONVALUE_ON) flags = (GtkStateFlags) (flags | CHECKED); renderType = RENDER_EXPANDER; - styleClass = GTK_STYLE_CLASS_EXPANDER; break; } case CTRL_LISTHEADER: @@ -1061,13 +1375,11 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co static_cast(0), nullptr); flags = GTK_STATE_FLAG_SELECTED; renderType = RENDER_ICON; - styleClass = GTK_STYLE_CLASS_ARROW; } break; case CTRL_PROGRESS: - context = mpProgressBarStyle; + context = mpProgressBarProgressStyle; renderType = RENDER_PROGRESS; - styleClass = GTK_STYLE_CLASS_TROUGH; break; default: return false; @@ -1077,45 +1389,38 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co clipRegion(cr); cairo_translate(cr, rControlRegion.Left(), rControlRegion.Top()); + Rectangle aDamageRect(rControlRegion); + long nX = 0; long nY = 0; long nWidth = rControlRegion.GetWidth(); long nHeight = rControlRegion.GetHeight(); - gtk_style_context_save(context); gtk_style_context_set_state(context, flags); + parent_styles_context_set_state(context, flags); if (nType == CTRL_TAB_ITEM) { - - const TabitemValue& rTabitemValue = static_cast(rValue); - - GtkRegionFlags eFlags(GTK_REGION_EVEN); - if (rTabitemValue.isFirst() && rTabitemValue.isLast()) - eFlags = GTK_REGION_ONLY; - else if (rTabitemValue.isFirst()) - eFlags = GTK_REGION_FIRST; - else if (rTabitemValue.isLast()) - eFlags = GTK_REGION_LAST; - - gtk_style_context_add_region(mpNoteBookStyle, GTK_STYLE_REGION_TAB, eFlags); - gtk_style_context_add_class(context, GTK_STYLE_CLASS_TOP); - + GtkBorder margin; +#if GTK_CHECK_VERSION(3,19,2) + gtk_style_context_get_margin(mpNotebookHeaderTabsTabStyle, gtk_style_context_get_state(mpNotebookHeaderTabsTabStyle), &margin); +#else gint initial_gap(0); - gtk_style_context_get_style(mpNoteBookStyle, + gtk_style_context_get_style(mpNotebookStyle, "initial-gap", &initial_gap, NULL); - nX += initial_gap/2; - nWidth -= initial_gap; + margin.left = margin.right = initial_gap/2; +#endif + nX += margin.left; + nWidth -= (margin.left + margin.right); } + +#if !GTK_CHECK_VERSION(3,19,2) if (styleClass) { gtk_style_context_add_class(context, styleClass); } - if (nType == CTRL_TAB_HEADER || nType == CTRL_TAB_PANE) - { - gtk_style_context_add_class(context, GTK_STYLE_CLASS_FRAME); - } +#endif switch(renderType) { @@ -1128,13 +1433,19 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co } break; case RENDER_CHECK: + { + PaintCheck(cr, context, rControlRegion, bInMenu); + break; + } case RENDER_RADIO: - PaintCheckOrRadio(context, cr, rControlRegion, nType); + { + PaintRadio(cr, context, rControlRegion, bInMenu); break; + } case RENDER_MENU_SEPERATOR: gtk_render_line(context, cr, - 3, rControlRegion.GetHeight() / 2, - rControlRegion.GetWidth() - 3, rControlRegion.GetHeight() / 2); + 0, rControlRegion.GetHeight() / 2, + rControlRegion.GetWidth() - 1, rControlRegion.GetHeight() / 2); break; case RENDER_TOOLBAR_SEPERATOR: gtk_render_line(context, cr, @@ -1188,17 +1499,14 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co } case RENDER_PROGRESS: { - gtk_render_background(context, cr, nX, nY, nWidth, nHeight); - gtk_render_frame(context, cr, nX, nY, nWidth, nHeight); + gtk_render_background(mpProgressBarTroughStyle, cr, nX, nY, nWidth, nHeight); + gtk_render_frame(mpProgressBarTroughStyle, cr, nX, nY, nWidth, nHeight); long nProgressWidth = rValue.getNumericVal(); if (nProgressWidth) { GtkBorder padding; - gtk_style_context_get_padding(context, GTK_STATE_FLAG_NORMAL, &padding); + gtk_style_context_get_padding(context, gtk_style_context_get_state(context), &padding); - gtk_style_context_remove_class(context, GTK_STYLE_CLASS_TROUGH); - gtk_style_context_add_class(context, GTK_STYLE_CLASS_PROGRESSBAR); - gtk_style_context_add_class(context, GTK_STYLE_CLASS_PULSE); nX += padding.left; nY += padding.top; nHeight -= (padding.top + padding.bottom); @@ -1213,10 +1521,18 @@ bool GtkSalGraphics::drawNativeControl( ControlType nType, ControlPart nPart, co break; } - gtk_style_context_restore(context); +#if !GTK_CHECK_VERSION(3,19,2) + if (styleClass) + { + gtk_style_context_remove_class(context, styleClass); + } +#endif + cairo_surface_flush(cairo_get_target(cr)); cairo_destroy(cr); // unref - mpFrame->damaged(basegfx::B2IBox(rControlRegion.Left(), rControlRegion.Top(), rControlRegion.Right(), rControlRegion.Bottom())); + + if (!aDamageRect.IsEmpty()) + mpFrame->damaged(basegfx::B2IBox(aDamageRect.Left(), aDamageRect.Top(), aDamageRect.Right(), aDamageRect.Bottom())); return true; } @@ -1231,24 +1547,20 @@ Rectangle GetWidgetSize(const Rectangle& rControlRegion, GtkWidget* widget) Rectangle AdjustRectForTextBordersPadding(GtkStyleContext* pStyle, long nContentWidth, long nContentHeight, const Rectangle& rControlRegion) { - gtk_style_context_save(pStyle); - GtkBorder border; - gtk_style_context_get_border(pStyle, GTK_STATE_FLAG_NORMAL, &border); + gtk_style_context_get_border(pStyle, gtk_style_context_get_state(pStyle), &border); GtkBorder padding; - gtk_style_context_get_padding(pStyle, GTK_STATE_FLAG_NORMAL, &padding); + gtk_style_context_get_padding(pStyle, gtk_style_context_get_state(pStyle), &padding); gint nWidgetHeight = nContentHeight + padding.top + padding.bottom + border.top + border.bottom; - nWidgetHeight = std::max(nWidgetHeight, rControlRegion.GetHeight()); + nWidgetHeight = std::max(std::max(nWidgetHeight, rControlRegion.GetHeight()), 34); gint nWidgetWidth = nContentWidth + padding.left + padding.right + border.left + border.right; nWidgetWidth = std::max(nWidgetWidth, rControlRegion.GetWidth()); Rectangle aEditRect(rControlRegion.TopLeft(), Size(nWidgetWidth, nWidgetHeight)); - gtk_style_context_restore(pStyle); - return aEditRect; } @@ -1265,16 +1577,19 @@ bool GtkSalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPar { rNativeBoundingRegion = rControlRegion; - gtk_style_context_get_style( mpCheckButtonStyle, + GtkStyleContext *pButtonStyle = (nType == CTRL_CHECKBOX) ? mpCheckButtonStyle : mpRadioButtonStyle; + + + gtk_style_context_get_style( pButtonStyle, "indicator-size", &indicator_size, "indicator-spacing", &indicator_spacing, nullptr ); GtkBorder border; - gtk_style_context_get_border(mpCheckButtonStyle, GTK_STATE_FLAG_NORMAL, &border); + gtk_style_context_get_border(pButtonStyle, gtk_style_context_get_state(pButtonStyle), &border); GtkBorder padding; - gtk_style_context_get_padding(mpCheckButtonStyle, GTK_STATE_FLAG_NORMAL, &padding); + gtk_style_context_get_padding(pButtonStyle, gtk_style_context_get_state(pButtonStyle), &padding); indicator_size += 2*indicator_spacing + border.left + padding.left + border.right + padding.right; @@ -1292,7 +1607,9 @@ bool GtkSalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPar { indicator_size = 0; - gtk_style_context_get_style( mpCheckMenuItemStyle, + GtkStyleContext *pMenuItemStyle = (nType == PART_MENU_ITEM_CHECK_MARK ) ? mpCheckMenuItemStyle : mpRadioMenuItemStyle; + + gtk_style_context_get_style( pMenuItemStyle, "indicator-size", &indicator_size, nullptr ); @@ -1304,7 +1621,7 @@ bool GtkSalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPar { gint separator_height, separator_width, wide_separators; - gtk_style_context_get_style (mpCheckMenuItemStyle, + gtk_style_context_get_style (mpSeparatorMenuItemStyle, "wide-separators", &wide_separators, "separator-width", &separator_width, "separator-height", &separator_height, @@ -1315,14 +1632,7 @@ bool GtkSalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPar } else if (nPart == PART_MENU_SUBMENU_ARROW) { - gfloat arrow_scaling, arrow_size; - - arrow_scaling = 0; - gtk_style_context_get_style (mpCheckMenuItemStyle, - "arrow-scaling", &arrow_scaling, - NULL); - - arrow_size = 11 * arrow_scaling; + gfloat arrow_size = getArrowSize(mpMenuItemArrowStyle); aEditRect = Rectangle( aEditRect.TopLeft(), Size( arrow_size, arrow_size ) ); } @@ -1380,18 +1690,11 @@ bool GtkSalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPar } else if (nType == CTRL_TAB_ITEM && nPart == PART_ENTIRE_CONTROL) { - gtk_style_context_save(mpNoteBookStyle); - - gtk_style_context_add_region(mpNoteBookStyle, GTK_STYLE_REGION_TAB, GTK_REGION_ONLY); - gtk_style_context_add_class(mpNoteBookStyle, GTK_STYLE_CLASS_TOP); - const TabitemValue& rTabitemValue = static_cast(rValue); const Rectangle& rTabitemRect = rTabitemValue.getContentRect(); - aEditRect = AdjustRectForTextBordersPadding(mpNoteBookStyle, rTabitemRect.GetWidth(), + aEditRect = AdjustRectForTextBordersPadding(mpNotebookHeaderTabsTabStyle, rTabitemRect.GetWidth(), rTabitemRect.GetHeight(), rControlRegion); - - gtk_style_context_restore(mpNoteBookStyle); } else if (nType == CTRL_FRAME && nPart == PART_BORDER) { @@ -1399,14 +1702,11 @@ bool GtkSalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPar DrawFrameFlags nStyle = static_cast(rValue.getNumericVal() & 0xfff0); if (nStyle & DrawFrameFlags::NoDraw) { - gtk_style_context_save(mpFrameInStyle); - gtk_style_context_add_class(mpFrameInStyle, GTK_STYLE_CLASS_FRAME); - GtkBorder padding; - gtk_style_context_get_padding(mpFrameInStyle, GTK_STATE_FLAG_NORMAL, &padding); + gtk_style_context_get_padding(mpFrameInStyle, gtk_style_context_get_state(mpFrameInStyle), &padding); GtkBorder border; - gtk_style_context_get_border(mpFrameInStyle, GTK_STATE_FLAG_NORMAL, &border); + gtk_style_context_get_border(mpFrameInStyle, gtk_style_context_get_state(mpFrameInStyle), &border); int x1 = aEditRect.Left(); int y1 = aEditRect.Top(); @@ -1419,7 +1719,6 @@ bool GtkSalGraphics::getNativeControlRegion( ControlType nType, ControlPart nPar x2 - (padding.right + border.right), y2 - (padding.bottom + border.bottom)); - gtk_style_context_restore(mpFrameInStyle); return true; } else @@ -1457,7 +1756,8 @@ void GtkSalGraphics::updateSettings( AllSettings& rSettings ) // text colors GdkRGBA text_color; - gtk_style_context_get_color(pStyle, GTK_STATE_FLAG_NORMAL, &text_color); + gtk_style_context_set_state(pStyle, GTK_STATE_FLAG_NORMAL); + gtk_style_context_get_color(pStyle, gtk_style_context_get_state(pStyle), &text_color); ::Color aTextColor = getColor( text_color ); aStyleSet.SetDialogTextColor( aTextColor ); aStyleSet.SetButtonTextColor( aTextColor ); @@ -1468,15 +1768,9 @@ void GtkSalGraphics::updateSettings( AllSettings& rSettings ) aStyleSet.SetWindowTextColor( aTextColor ); aStyleSet.SetFieldTextColor( aTextColor ); - // mouse over text colors - gtk_style_context_get_color(pStyle, GTK_STATE_FLAG_PRELIGHT, &text_color); - aTextColor = getColor( text_color ); - aStyleSet.SetButtonRolloverTextColor( aTextColor ); - aStyleSet.SetFieldRolloverTextColor( aTextColor ); - // background colors GdkRGBA background_color; - gtk_style_context_get_background_color(pStyle, GTK_STATE_FLAG_NORMAL, &background_color); + gtk_style_context_get_background_color(pStyle, gtk_style_context_get_state(pStyle), &background_color); ::Color aBackColor = getColor( background_color ); aStyleSet.Set3DColors( aBackColor ); @@ -1485,6 +1779,106 @@ void GtkSalGraphics::updateSettings( AllSettings& rSettings ) aStyleSet.SetWorkspaceColor( aBackColor ); aStyleSet.SetCheckedColorSpecialCase( ); + // UI font + const PangoFontDescription* font = gtk_style_context_get_font(pStyle, gtk_style_context_get_state(pStyle)); + OString aFamily = pango_font_description_get_family( font ); + int nPangoHeight = pango_font_description_get_size( font ); + PangoStyle eStyle = pango_font_description_get_style( font ); + PangoWeight eWeight = pango_font_description_get_weight( font ); + PangoStretch eStretch = pango_font_description_get_stretch( font ); + + psp::FastPrintFontInfo aInfo; + // set family name + aInfo.m_aFamilyName = OStringToOUString( aFamily, RTL_TEXTENCODING_UTF8 ); + // set italic + switch( eStyle ) + { + case PANGO_STYLE_NORMAL: aInfo.m_eItalic = ITALIC_NONE;break; + case PANGO_STYLE_ITALIC: aInfo.m_eItalic = ITALIC_NORMAL;break; + case PANGO_STYLE_OBLIQUE: aInfo.m_eItalic = ITALIC_OBLIQUE;break; + } + // set weight + if( eWeight <= PANGO_WEIGHT_ULTRALIGHT ) + aInfo.m_eWeight = WEIGHT_ULTRALIGHT; + else if( eWeight <= PANGO_WEIGHT_LIGHT ) + aInfo.m_eWeight = WEIGHT_LIGHT; + else if( eWeight <= PANGO_WEIGHT_NORMAL ) + aInfo.m_eWeight = WEIGHT_NORMAL; + else if( eWeight <= PANGO_WEIGHT_BOLD ) + aInfo.m_eWeight = WEIGHT_BOLD; + else + aInfo.m_eWeight = WEIGHT_ULTRABOLD; + // set width + switch( eStretch ) + { + case PANGO_STRETCH_ULTRA_CONDENSED: aInfo.m_eWidth = WIDTH_ULTRA_CONDENSED;break; + case PANGO_STRETCH_EXTRA_CONDENSED: aInfo.m_eWidth = WIDTH_EXTRA_CONDENSED;break; + case PANGO_STRETCH_CONDENSED: aInfo.m_eWidth = WIDTH_CONDENSED;break; + case PANGO_STRETCH_SEMI_CONDENSED: aInfo.m_eWidth = WIDTH_SEMI_CONDENSED;break; + case PANGO_STRETCH_NORMAL: aInfo.m_eWidth = WIDTH_NORMAL;break; + case PANGO_STRETCH_SEMI_EXPANDED: aInfo.m_eWidth = WIDTH_SEMI_EXPANDED;break; + case PANGO_STRETCH_EXPANDED: aInfo.m_eWidth = WIDTH_EXPANDED;break; + case PANGO_STRETCH_EXTRA_EXPANDED: aInfo.m_eWidth = WIDTH_EXTRA_EXPANDED;break; + case PANGO_STRETCH_ULTRA_EXPANDED: aInfo.m_eWidth = WIDTH_ULTRA_EXPANDED;break; + } + +#if OSL_DEBUG_LEVEL > 1 + fprintf( stderr, "font name BEFORE system match: \"%s\"\n", aFamily.getStr() ); +#endif + + // match font to e.g. resolve "Sans" + psp::PrintFontManager::get().matchFont( aInfo, rSettings.GetUILanguageTag().getLocale() ); + +#if OSL_DEBUG_LEVEL > 1 + fprintf( stderr, "font match %s, name AFTER: \"%s\"\n", + aInfo.m_nID != 0 ? "succeeded" : "failed", + OUStringToOString( aInfo.m_aFamilyName, RTL_TEXTENCODING_ISO_8859_1 ).getStr() ); +#endif + + int nPointHeight = 0; + /*sal_Int32 nDispDPIY = GetDisplay()->GetResolution().B(); + static gboolean(*pAbso)(const PangoFontDescription*) = + (gboolean(*)(const PangoFontDescription*))osl_getAsciiFunctionSymbol( GetSalData()->m_pPlugin, "pango_font_description_get_size_is_absolute" ); + + if( pAbso && pAbso( font ) ) + nPointHeight = (nPangoHeight * 72 + nDispDPIY*PANGO_SCALE/2) / (nDispDPIY * PANGO_SCALE); + else*/ + nPointHeight = nPangoHeight/PANGO_SCALE; + + vcl::Font aFont( aInfo.m_aFamilyName, Size( 0, nPointHeight ) ); + if( aInfo.m_eWeight != WEIGHT_DONTKNOW ) + aFont.SetWeight( aInfo.m_eWeight ); + if( aInfo.m_eWidth != WIDTH_DONTKNOW ) + aFont.SetWidthType( aInfo.m_eWidth ); + if( aInfo.m_eItalic != ITALIC_DONTKNOW ) + aFont.SetItalic( aInfo.m_eItalic ); + if( aInfo.m_ePitch != PITCH_DONTKNOW ) + aFont.SetPitch( aInfo.m_ePitch ); + + aStyleSet.SetAppFont( aFont ); + aStyleSet.SetHelpFont( aFont ); + aStyleSet.SetMenuFont( aFont ); + aStyleSet.SetToolFont( aFont ); + aStyleSet.SetLabelFont( aFont ); + aStyleSet.SetInfoFont( aFont ); + aStyleSet.SetRadioCheckFont( aFont ); + aStyleSet.SetPushButtonFont( aFont ); + aStyleSet.SetFieldFont( aFont ); + aStyleSet.SetIconFont( aFont ); + aStyleSet.SetGroupFont( aFont ); + + aFont.SetWeight( WEIGHT_BOLD ); + aStyleSet.SetTabFont( aFont ); //pull from notebook style + GTK_STYLE_REGION_TAB ? + aStyleSet.SetTitleFont( aFont ); + aStyleSet.SetFloatTitleFont( aFont ); + + // mouse over text colors + gtk_style_context_set_state(pStyle, GTK_STATE_FLAG_PRELIGHT); + gtk_style_context_get_color(pStyle, gtk_style_context_get_state(pStyle), &text_color); + aTextColor = getColor( text_color ); + aStyleSet.SetButtonRolloverTextColor( aTextColor ); + aStyleSet.SetFieldRolloverTextColor( aTextColor ); + // tooltip colors { GtkStyleContext *pCStyle = gtk_style_context_new(); @@ -1501,8 +1895,9 @@ void GtkSalGraphics::updateSettings( AllSettings& rSettings ) gtk_widget_path_free(pCPath); GdkRGBA tooltip_bg_color, tooltip_fg_color; - gtk_style_context_get_color(pCStyle, GTK_STATE_FLAG_NORMAL, &tooltip_fg_color); - gtk_style_context_get_background_color(pCStyle, GTK_STATE_FLAG_NORMAL, &tooltip_bg_color); + gtk_style_context_set_state(pCStyle, GTK_STATE_FLAG_NORMAL); + gtk_style_context_get_color(pCStyle, gtk_style_context_get_state(pCStyle), &tooltip_fg_color); + gtk_style_context_get_background_color(pCStyle, gtk_style_context_get_state(pCStyle), &tooltip_bg_color); g_object_unref( pCStyle ); aStyleSet.SetHelpColor( getColor( tooltip_bg_color )); @@ -1520,16 +1915,18 @@ void GtkSalGraphics::updateSettings( AllSettings& rSettings ) gtk_widget_path_free( pCPath ); // highlighting colors - gtk_style_context_get_background_color(pCStyle, GTK_STATE_FLAG_SELECTED, &text_color); + gtk_style_context_set_state(pCStyle, GTK_STATE_FLAG_SELECTED); + gtk_style_context_get_background_color(pCStyle, gtk_style_context_get_state(pCStyle), &text_color); ::Color aHighlightColor = getColor( text_color ); - gtk_style_context_get_color(pCStyle, GTK_STATE_FLAG_SELECTED, &text_color); + gtk_style_context_get_color(pCStyle, gtk_style_context_get_state(pCStyle), &text_color); ::Color aHighlightTextColor = getColor( text_color ); aStyleSet.SetHighlightColor( aHighlightColor ); aStyleSet.SetHighlightTextColor( aHighlightTextColor ); // field background color GdkRGBA field_background_color; - gtk_style_context_get_background_color(pCStyle, GTK_STATE_FLAG_NORMAL, &field_background_color); + gtk_style_context_set_state(pCStyle, GTK_STATE_FLAG_NORMAL); + gtk_style_context_get_background_color(pCStyle, gtk_style_context_get_state(pCStyle), &field_background_color); g_object_unref( pCStyle ); ::Color aBackFieldColor = getColor( field_background_color ); @@ -1543,30 +1940,34 @@ void GtkSalGraphics::updateSettings( AllSettings& rSettings ) aStyleSet.SetAcceleratorsInContextMenus( false ); // menu colors - gtk_style_context_get_background_color( mpMenuStyle, GTK_STATE_FLAG_NORMAL, &background_color ); + gtk_style_context_set_state(mpMenuStyle, GTK_STATE_FLAG_NORMAL); + gtk_style_context_get_background_color( mpMenuStyle, gtk_style_context_get_state(mpMenuStyle), &background_color ); aBackColor = getColor( background_color ); aStyleSet.SetMenuColor( aBackColor ); + // menu items + gtk_style_context_get_color( mpMenuStyle, gtk_style_context_get_state(mpMenuStyle), &color ); + aTextColor = getColor( color ); + aStyleSet.SetMenuTextColor( aTextColor ); + // menu bar - gtk_style_context_get_background_color( mpMenuBarStyle, GTK_STATE_FLAG_NORMAL, &background_color ); + gtk_style_context_set_state(mpMenuBarStyle, GTK_STATE_FLAG_NORMAL); + gtk_style_context_get_background_color( mpMenuBarStyle, gtk_style_context_get_state(mpMenuBarStyle), &background_color ); aBackColor = getColor( background_color ); aStyleSet.SetMenuBarColor( aBackColor ); aStyleSet.SetMenuBarRolloverColor( aBackColor ); - gtk_style_context_get_color( mpMenuBarItemStyle, GTK_STATE_FLAG_NORMAL, &text_color ); + gtk_style_context_set_state(mpMenuBarItemStyle, GTK_STATE_FLAG_NORMAL); + gtk_style_context_get_color( mpMenuBarItemStyle, gtk_style_context_get_state(mpMenuBarItemStyle), &text_color ); aTextColor = aStyleSet.GetPersonaMenuBarTextColor().get_value_or( getColor( text_color ) ); aStyleSet.SetMenuBarTextColor( aTextColor ); aStyleSet.SetMenuBarRolloverTextColor( aTextColor ); - gtk_style_context_get_color( mpMenuBarItemStyle, GTK_STATE_FLAG_PRELIGHT, &text_color ); + gtk_style_context_set_state(mpMenuBarItemStyle, GTK_STATE_FLAG_PRELIGHT); + gtk_style_context_get_color( mpMenuBarItemStyle, gtk_style_context_get_state(mpMenuBarItemStyle), &text_color ); aTextColor = aStyleSet.GetPersonaMenuBarTextColor().get_value_or( getColor( text_color ) ); aStyleSet.SetMenuBarHighlightTextColor( aTextColor ); - // menu items - gtk_style_context_get_color( mpMenuStyle, GTK_STATE_FLAG_NORMAL, &color ); - aTextColor = getColor( color ); - aStyleSet.SetMenuTextColor( aTextColor ); - // Awful hack for menu separators in the Sonar and similar themes. // If the menu color is not too dark, and the menu text color is lighter, // make the "light" color lighter than the menu color and the "shadow" @@ -1582,11 +1983,12 @@ void GtkSalGraphics::updateSettings( AllSettings& rSettings ) aStyleSet.SetShadowColor( temp ); } - gtk_style_context_get_background_color( mpCheckMenuItemStyle, GTK_STATE_FLAG_PRELIGHT, &background_color ); + gtk_style_context_set_state(mpMenuItemStyle, GTK_STATE_FLAG_PRELIGHT); + gtk_style_context_get_background_color( mpMenuItemStyle, gtk_style_context_get_state(mpMenuItemStyle), &background_color ); ::Color aHighlightColor = getColor( background_color ); aStyleSet.SetMenuHighlightColor( aHighlightColor ); - gtk_style_context_get_color( mpCheckMenuItemStyle, GTK_STATE_FLAG_PRELIGHT, &color ); + gtk_style_context_get_color( mpMenuItemStyle, gtk_style_context_get_state(mpMenuItemStyle), &color ); ::Color aHighlightTextColor = getColor( color ); aStyleSet.SetMenuHighlightTextColor( aHighlightTextColor ); @@ -1609,6 +2011,27 @@ void GtkSalGraphics::updateSettings( AllSettings& rSettings ) gdk_color_free(link_color); } +#if GTK_CHECK_VERSION(3, 19, 2) + { + GtkStyleContext *pCStyle = mpNotebookHeaderTabsTabStyle; + + gtk_style_context_set_state(pCStyle, GTK_STATE_FLAG_NORMAL); + gtk_style_context_get_color(pCStyle, gtk_style_context_get_state(pCStyle), &text_color); + aTextColor = getColor( text_color ); + aStyleSet.SetTabTextColor(aTextColor); + + // mouse over text colors + gtk_style_context_set_state(pCStyle, GTK_STATE_FLAG_PRELIGHT); + gtk_style_context_get_color(pCStyle, gtk_style_context_get_state(pCStyle), &text_color); + aTextColor = getColor( text_color ); + aStyleSet.SetTabRolloverTextColor(aTextColor); + + gtk_style_context_set_state(pCStyle, GTK_STATE_FLAG_ACTIVE); + gtk_style_context_get_color(pCStyle, gtk_style_context_get_state(pCStyle), &text_color); + aTextColor = getColor( text_color ); + aStyleSet.SetTabHighlightTextColor(aTextColor); + } +#else { GtkStyleContext *pCStyle = gtk_style_context_new(); gtk_style_context_set_screen( pCStyle, gtk_window_get_screen( GTK_WINDOW( mpWindow ) ) ); @@ -1624,118 +2047,30 @@ void GtkSalGraphics::updateSettings( AllSettings& rSettings ) gtk_style_context_set_path(pCStyle, pCPath); gtk_widget_path_free(pCPath); - gtk_style_context_get_color(pCStyle, GTK_STATE_FLAG_NORMAL, &text_color); + gtk_style_context_set_state(pCStyle, GTK_STATE_FLAG_NORMAL); + gtk_style_context_get_color(pCStyle, gtk_style_context_get_state(pCStyle), &text_color); aTextColor = getColor( text_color ); aStyleSet.SetTabTextColor(aTextColor); // mouse over text colors gtk_style_context_add_class(pCStyle, "prelight-page"); - gtk_style_context_get_color(pCStyle, GTK_STATE_FLAG_PRELIGHT, &text_color); + gtk_style_context_set_state(pCStyle, GTK_STATE_FLAG_PRELIGHT); + gtk_style_context_get_color(pCStyle, gtk_style_context_get_state(pCStyle), &text_color); gtk_style_context_remove_class(pCStyle, "prelight-page"); aTextColor = getColor( text_color ); aStyleSet.SetTabRolloverTextColor(aTextColor); gtk_style_context_add_class(pCStyle, "active-page"); - gtk_style_context_get_color(pCStyle, GTK_STATE_FLAG_ACTIVE, &text_color); + gtk_style_context_set_state(pCStyle, GTK_STATE_FLAG_ACTIVE); + gtk_style_context_get_color(pCStyle, gtk_style_context_get_state(pCStyle), &text_color); gtk_style_context_remove_class(pCStyle, "active-page"); aTextColor = getColor( text_color ); aStyleSet.SetTabHighlightTextColor(aTextColor); g_object_unref( pCStyle ); - } - - // UI font - const PangoFontDescription* font = gtk_style_context_get_font(pStyle, GTK_STATE_FLAG_NORMAL); - OString aFamily = pango_font_description_get_family( font ); - int nPangoHeight = pango_font_description_get_size( font ); - PangoStyle eStyle = pango_font_description_get_style( font ); - PangoWeight eWeight = pango_font_description_get_weight( font ); - PangoStretch eStretch = pango_font_description_get_stretch( font ); - - psp::FastPrintFontInfo aInfo; - // set family name - aInfo.m_aFamilyName = OStringToOUString( aFamily, RTL_TEXTENCODING_UTF8 ); - // set italic - switch( eStyle ) - { - case PANGO_STYLE_NORMAL: aInfo.m_eItalic = ITALIC_NONE;break; - case PANGO_STYLE_ITALIC: aInfo.m_eItalic = ITALIC_NORMAL;break; - case PANGO_STYLE_OBLIQUE: aInfo.m_eItalic = ITALIC_OBLIQUE;break; - } - // set weight - if( eWeight <= PANGO_WEIGHT_ULTRALIGHT ) - aInfo.m_eWeight = WEIGHT_ULTRALIGHT; - else if( eWeight <= PANGO_WEIGHT_LIGHT ) - aInfo.m_eWeight = WEIGHT_LIGHT; - else if( eWeight <= PANGO_WEIGHT_NORMAL ) - aInfo.m_eWeight = WEIGHT_NORMAL; - else if( eWeight <= PANGO_WEIGHT_BOLD ) - aInfo.m_eWeight = WEIGHT_BOLD; - else - aInfo.m_eWeight = WEIGHT_ULTRABOLD; - // set width - switch( eStretch ) - { - case PANGO_STRETCH_ULTRA_CONDENSED: aInfo.m_eWidth = WIDTH_ULTRA_CONDENSED;break; - case PANGO_STRETCH_EXTRA_CONDENSED: aInfo.m_eWidth = WIDTH_EXTRA_CONDENSED;break; - case PANGO_STRETCH_CONDENSED: aInfo.m_eWidth = WIDTH_CONDENSED;break; - case PANGO_STRETCH_SEMI_CONDENSED: aInfo.m_eWidth = WIDTH_SEMI_CONDENSED;break; - case PANGO_STRETCH_NORMAL: aInfo.m_eWidth = WIDTH_NORMAL;break; - case PANGO_STRETCH_SEMI_EXPANDED: aInfo.m_eWidth = WIDTH_SEMI_EXPANDED;break; - case PANGO_STRETCH_EXPANDED: aInfo.m_eWidth = WIDTH_EXPANDED;break; - case PANGO_STRETCH_EXTRA_EXPANDED: aInfo.m_eWidth = WIDTH_EXTRA_EXPANDED;break; - case PANGO_STRETCH_ULTRA_EXPANDED: aInfo.m_eWidth = WIDTH_ULTRA_EXPANDED;break; - } - -#if OSL_DEBUG_LEVEL > 1 - fprintf( stderr, "font name BEFORE system match: \"%s\"\n", aFamily.getStr() ); + } #endif - // match font to e.g. resolve "Sans" - psp::PrintFontManager::get().matchFont( aInfo, rSettings.GetUILanguageTag().getLocale() ); - -#if OSL_DEBUG_LEVEL > 1 - fprintf( stderr, "font match %s, name AFTER: \"%s\"\n", - aInfo.m_nID != 0 ? "succeeded" : "failed", - OUStringToOString( aInfo.m_aFamilyName, RTL_TEXTENCODING_ISO_8859_1 ).getStr() ); -#endif - - int nPointHeight = 0; - /*sal_Int32 nDispDPIY = GetDisplay()->GetResolution().B(); - static gboolean(*pAbso)(const PangoFontDescription*) = - (gboolean(*)(const PangoFontDescription*))osl_getAsciiFunctionSymbol( GetSalData()->m_pPlugin, "pango_font_description_get_size_is_absolute" ); - - if( pAbso && pAbso( font ) ) - nPointHeight = (nPangoHeight * 72 + nDispDPIY*PANGO_SCALE/2) / (nDispDPIY * PANGO_SCALE); - else*/ - nPointHeight = nPangoHeight/PANGO_SCALE; - - vcl::Font aFont( aInfo.m_aFamilyName, Size( 0, nPointHeight ) ); - if( aInfo.m_eWeight != WEIGHT_DONTKNOW ) - aFont.SetWeight( aInfo.m_eWeight ); - if( aInfo.m_eWidth != WIDTH_DONTKNOW ) - aFont.SetWidthType( aInfo.m_eWidth ); - if( aInfo.m_eItalic != ITALIC_DONTKNOW ) - aFont.SetItalic( aInfo.m_eItalic ); - if( aInfo.m_ePitch != PITCH_DONTKNOW ) - aFont.SetPitch( aInfo.m_ePitch ); - - aStyleSet.SetAppFont( aFont ); - aStyleSet.SetHelpFont( aFont ); - aStyleSet.SetMenuFont( aFont ); - aStyleSet.SetToolFont( aFont ); - aStyleSet.SetLabelFont( aFont ); - aStyleSet.SetInfoFont( aFont ); - aStyleSet.SetRadioCheckFont( aFont ); - aStyleSet.SetPushButtonFont( aFont ); - aStyleSet.SetFieldFont( aFont ); - aStyleSet.SetIconFont( aFont ); - aStyleSet.SetGroupFont( aFont ); - - aFont.SetWeight( WEIGHT_BOLD ); - aStyleSet.SetTabFont( aFont ); //pull from notebook style + GTK_STYLE_REGION_TAB ? - aStyleSet.SetTitleFont( aFont ); - aStyleSet.SetFloatTitleFont( aFont ); // get cursor blink time gboolean blink = false; @@ -2007,9 +2342,12 @@ GtkSalGraphics::GtkSalGraphics( GtkSalFrame *pFrame, GtkWidget *pWindow ) gtk_widget_realize(gCacheWindow); gEntryBox = gtk_entry_new(); - getStyleContext(&mpEntryStyle, gEntryBox); + gtk_container_add(GTK_CONTAINER(gDumbContainer), gEntryBox); + mpEntryStyle = createStyleContext(GtkControlPart::Entry); + getStyleContext(&mpTextViewStyle, gtk_text_view_new()); - getStyleContext(&mpButtonStyle, gtk_button_new()); + + mpButtonStyle = createStyleContext(GtkControlPart::Button); GtkWidget* pToolbar = gtk_toolbar_new(); mpToolbarStyle = gtk_widget_get_style_context(pToolbar); @@ -2025,36 +2363,64 @@ GtkSalGraphics::GtkSalGraphics( GtkSalFrame *pFrame, GtkWidget *pWindow ) gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), item, -1); mpToolButtonStyle = gtk_widget_get_style_context(GTK_WIDGET(pButton)); - getStyleContext(&mpVScrollbarStyle, gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, nullptr)); - gtk_style_context_add_class(mpVScrollbarStyle, GTK_STYLE_CLASS_SCROLLBAR); - getStyleContext(&mpHScrollbarStyle, gtk_scrollbar_new(GTK_ORIENTATION_HORIZONTAL, nullptr)); - gtk_style_context_add_class(mpHScrollbarStyle, GTK_STYLE_CLASS_SCROLLBAR); + mpVScrollbarStyle = createStyleContext(GtkControlPart::ScrollbarVertical); + mpVScrollbarTroughStyle = createStyleContext(GtkControlPart::ScrollbarTrough, mpVScrollbarStyle); + mpVScrollbarSliderStyle = createStyleContext(GtkControlPart::ScrollbarSlider, mpVScrollbarTroughStyle); + mpVScrollbarButtonStyle = createStyleContext(GtkControlPart::ScrollbarButton, mpVScrollbarStyle); + mpHScrollbarStyle = createStyleContext(GtkControlPart::ScrollbarHorizontal); + mpHScrollbarTroughStyle = createStyleContext(GtkControlPart::ScrollbarTrough, mpHScrollbarStyle); + mpHScrollbarSliderStyle = createStyleContext(GtkControlPart::ScrollbarSlider, mpHScrollbarTroughStyle); + mpHScrollbarButtonStyle = createStyleContext(GtkControlPart::ScrollbarButton, mpHScrollbarStyle); - getStyleContext(&mpCheckButtonStyle, gtk_check_button_new()); + { + GtkStyleContext* parentContext = createStyleContext(GtkControlPart::CheckButton); + mpCheckButtonStyle = createStyleContext(GtkControlPart::CheckButtonCheck, parentContext); + g_object_unref(parentContext); + } + + { + GtkStyleContext* parentContext = createStyleContext(GtkControlPart::RadioButton); + mpRadioButtonStyle = createStyleContext(GtkControlPart::RadioButtonRadio, parentContext); + g_object_unref(parentContext); + } /* Menu bar */ gMenuBarWidget = gtk_menu_bar_new(); gMenuItemMenuBarWidget = gtk_menu_item_new_with_label( "b" ); gtk_menu_shell_append(GTK_MENU_SHELL(gMenuBarWidget), gMenuItemMenuBarWidget); - getStyleContext(&mpMenuBarStyle, gMenuBarWidget); - mpMenuBarItemStyle = gtk_widget_get_style_context(gMenuItemMenuBarWidget); + gtk_container_add(GTK_CONTAINER(gDumbContainer), gMenuBarWidget); + + mpMenuBarStyle = createStyleContext(GtkControlPart::MenuBar, gtk_widget_get_style_context(mpWindow)); + mpMenuBarItemStyle = createStyleContext(GtkControlPart::MenuItem, mpMenuBarStyle); /* Menu */ + mpMenuStyle = createStyleContext(GtkControlPart::Menu, gtk_widget_get_style_context(mpWindow)); GtkWidget *menu = gtk_menu_new(); - mpMenuStyle = gtk_widget_get_style_context(menu); gtk_menu_item_set_submenu(GTK_MENU_ITEM(gMenuItemMenuBarWidget), menu); /* Menu Items */ gCheckMenuItemWidget = gtk_check_menu_item_new_with_label("M"); gtk_menu_shell_append(GTK_MENU_SHELL(menu), gCheckMenuItemWidget); - mpCheckMenuItemStyle = gtk_widget_get_style_context(gCheckMenuItemWidget); + + mpMenuItemStyle = createStyleContext(GtkControlPart::MenuItem, mpMenuStyle); + mpMenuItemArrowStyle = createStyleContext(GtkControlPart::MenuItemArrow, mpMenuItemStyle); + mpCheckMenuItemStyle = createStyleContext(GtkControlPart::CheckMenuItemCheck, mpMenuItemStyle); + mpRadioMenuItemStyle = createStyleContext(GtkControlPart::RadioMenuItemRadio, mpMenuItemStyle); + mpSeparatorMenuItemStyle = createStyleContext(GtkControlPart::SeparatorMenuItemSeparator, mpMenuItemStyle); /* Spinbutton */ gSpinBox = gtk_spin_button_new(nullptr, 0, 0); - getStyleContext(&mpSpinStyle, gSpinBox); + gtk_container_add(GTK_CONTAINER(gDumbContainer), gSpinBox); + mpSpinStyle = createStyleContext(GtkControlPart::SpinButton); + mpSpinUpStyle = createStyleContext(GtkControlPart::SpinButtonUpButton, mpSpinStyle); + mpSpinDownStyle = createStyleContext(GtkControlPart::SpinButtonDownButton, mpSpinStyle); /* NoteBook */ - getStyleContext(&mpNoteBookStyle, gtk_notebook_new()); + mpNotebookStyle = createStyleContext(GtkControlPart::Notebook); + mpNotebookStackStyle = createStyleContext(GtkControlPart::NotebookStack, mpNotebookStyle); + mpNotebookHeaderStyle = createStyleContext(GtkControlPart::NotebookHeader, mpNotebookStyle); + mpNotebookHeaderTabsStyle = createStyleContext(GtkControlPart::NotebookHeaderTabs, mpNotebookHeaderStyle); + mpNotebookHeaderTabsTabStyle = createStyleContext(GtkControlPart::NotebookHeaderTabsTab, mpNotebookHeaderTabsStyle); /* Combobox */ gComboBox = gtk_combo_box_text_new_with_entry(); @@ -2076,14 +2442,7 @@ GtkSalGraphics::GtkSalGraphics( GtkSalFrame *pFrame, GtkWidget *pWindow ) mpListboxButtonStyle = gtk_widget_get_style_context(gListBoxButtonWidget); /* Frames */ - gFrameIn = gtk_frame_new(nullptr); - gtk_frame_set_shadow_type(GTK_FRAME(gFrameIn), GTK_SHADOW_IN); - - gFrameOut = gtk_frame_new(nullptr); - gtk_frame_set_shadow_type(GTK_FRAME(gFrameOut), GTK_SHADOW_OUT); - - getStyleContext(&mpFrameInStyle, gFrameIn); - getStyleContext(&mpFrameOutStyle, gFrameOut); + mpFrameOutStyle = mpFrameInStyle = createStyleContext(GtkControlPart::FrameBorder); getStyleContext(&mpFixedHoriLineStyle, gtk_separator_new(GTK_ORIENTATION_HORIZONTAL)); getStyleContext(&mpFixedVertLineStyle, gtk_separator_new(GTK_ORIENTATION_VERTICAL)); @@ -2110,7 +2469,9 @@ GtkSalGraphics::GtkSalGraphics( GtkSalFrame *pFrame, GtkWidget *pWindow ) mpTreeHeaderButtonStyle = gtk_widget_get_style_context(pTreeHeaderCellWidget); /* Progress Bar */ - getStyleContext(&mpProgressBarStyle, gtk_progress_bar_new()); + mpProgressBarStyle = createStyleContext(GtkControlPart::ProgressBar); + mpProgressBarTroughStyle = createStyleContext(GtkControlPart::ProgressBar, mpProgressBarStyle); + mpProgressBarProgressStyle = createStyleContext(GtkControlPart::ProgressBarProgress, mpProgressBarTroughStyle); gtk_widget_show_all(gDumbContainer); } -- 2.7.0