diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-03-31 21:02:32 +0200 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-03-31 21:02:32 +0200 |
| commit | 6b1b5196384ad11a2e5d90afb323153fe0305187 (patch) | |
| tree | a8405e1a9ef22df355acd5d26256f17fee12660e | |
| parent | 18b2fb6c9342853fe1efc4ce9a90a0db1ae1528a (diff) | |
DecorationStyle: allow to use a different style context in DrawTitle
Panel will need to use a different one (bzr r3748.2.8)
| -rw-r--r-- | unity-shared/DecorationStyle.cpp | 32 | ||||
| -rw-r--r-- | unity-shared/DecorationStyle.h | 4 |
2 files changed, 19 insertions, 17 deletions
diff --git a/unity-shared/DecorationStyle.cpp b/unity-shared/DecorationStyle.cpp index 6d3dbbec2..1cab6e8c3 100644 --- a/unity-shared/DecorationStyle.cpp +++ b/unity-shared/DecorationStyle.cpp @@ -324,12 +324,13 @@ struct Style::Impl return GTK_STATE_FLAG_NORMAL; } - void AddContextClasses(Side s, WidgetState ws) + void AddContextClasses(Side s, WidgetState ws, GtkStyleContext* ctx = nullptr) { - gtk_style_context_add_class(ctx_, "gnome-panel-menu-bar"); - if (s == Side::TOP) { gtk_style_context_add_class(ctx_, "header-bar"); } - gtk_style_context_add_class(ctx_, GetBorderClass(s).c_str()); - gtk_style_context_set_state(ctx_, GtkStateFromWidgetState(ws)); + ctx = ctx ? ctx : ctx_; + gtk_style_context_add_class(ctx, "gnome-panel-menu-bar"); + if (s == Side::TOP) { gtk_style_context_add_class(ctx, "header-bar"); } + gtk_style_context_add_class(ctx, GetBorderClass(s).c_str()); + gtk_style_context_set_state(ctx, GtkStateFromWidgetState(ws)); } void DrawSide(Side s, WidgetState ws, cairo_t* cr, double w, double h) @@ -506,7 +507,6 @@ struct Style::Impl // We need to render the background under the text glyphs, or the edge // of the text won't be correctly anti-aliased. See bug #723167 - cairo_push_group(cr); gtk_render_layout(ctx, cr, 0, 0, layout); std::shared_ptr<cairo_pattern_t> pat(cairo_pop_group(cr), cairo_pattern_destroy); @@ -517,10 +517,10 @@ struct Style::Impl cairo_mask(cr, pat.get()); } - void DrawTitle(std::string const& text, WidgetState ws, cairo_t* cr, double w, double h, nux::Rect const& bg_geo) + void DrawTitle(std::string const& text, WidgetState ws, cairo_t* cr, double w, double h, nux::Rect const& bg_geo, GtkStyleContext* ctx) { - gtk_style_context_save(ctx_); - AddContextClasses(Side::TOP, ws); + gtk_style_context_save(ctx); + AddContextClasses(Side::TOP, ws, ctx); auto const& layout = BuildPangoLayout(title_pango_ctx_, text); @@ -534,8 +534,8 @@ struct Style::Impl double fading_width = std::min<double>(title_fade_, out_pixels); cairo_push_group(cr); - DrawTextBackground(ctx_, cr, layout, bg_geo); - gtk_render_layout(ctx_, cr, 0, 0, layout); + DrawTextBackground(ctx, cr, layout, bg_geo); + gtk_render_layout(ctx, cr, 0, 0, layout); cairo_pop_group_to_source(cr); std::shared_ptr<cairo_pattern_t> linpat(cairo_pattern_create_linear(w - fading_width, 0, w, 0), @@ -548,11 +548,11 @@ struct Style::Impl else { pango_layout_set_width(layout, (w >= 0) ? w * PANGO_SCALE : -1); - DrawTextBackground(ctx_, cr, layout, bg_geo); - gtk_render_layout(ctx_, cr, 0, 0, layout); + DrawTextBackground(ctx, cr, layout, bg_geo); + gtk_render_layout(ctx, cr, 0, 0, layout); } - gtk_style_context_restore(ctx_); + gtk_style_context_restore(ctx); } inline void AddContextClassesForMenuItem(WidgetState ws) @@ -680,9 +680,9 @@ void Style::DrawSide(Side s, WidgetState ws, cairo_t* cr, double w, double h) impl_->DrawSide(s, ws, cr, w, h); } -void Style::DrawTitle(std::string const& t, WidgetState ws, cairo_t* cr, double w, double h, nux::Rect const& bg_geo) +void Style::DrawTitle(std::string const& t, WidgetState ws, cairo_t* cr, double w, double h, nux::Rect const& bg_geo, GtkStyleContext* ctx) { - impl_->DrawTitle(t, ws, cr, w, h, bg_geo); + impl_->DrawTitle(t, ws, cr, w, h, bg_geo, ctx ? ctx : impl_->ctx_); } void Style::DrawMenuItem(WidgetState ws, cairo_t* cr, double w, double h) diff --git a/unity-shared/DecorationStyle.h b/unity-shared/DecorationStyle.h index e71beb2f2..7febd9b8d 100644 --- a/unity-shared/DecorationStyle.h +++ b/unity-shared/DecorationStyle.h @@ -24,6 +24,8 @@ #include <NuxCore/Rect.h> #include <cairo/cairo.h> +struct _GtkStyleContext; + namespace unity { namespace decoration @@ -129,7 +131,7 @@ public: int DoubleClickMaxTimeDelta() const; void DrawSide(Side, WidgetState, cairo_t*, double width, double height); - void DrawTitle(std::string const&, WidgetState, cairo_t*, double width, double height, nux::Rect const& bg_geo = nux::Rect()); + void DrawTitle(std::string const&, WidgetState, cairo_t*, double width, double height, nux::Rect const& bg_geo = nux::Rect(), _GtkStyleContext* ctx = nullptr); void DrawMenuItem(WidgetState, cairo_t*, double width, double height); void DrawMenuItemEntry(std::string const&, WidgetState, cairo_t*, double width, double height, nux::Rect const& bg_geo = nux::Rect()); void DrawMenuItemIcon(std::string const&, WidgetState, cairo_t*, int size); |
