Merge lp:~victored/granite/decorated-window-api-fixes into lp:~elementary-pantheon/granite/granite

Proposed by Victor Martinez
Status: Merged
Approved by: xapantu
Approved revision: 265
Merged at revision: 295
Proposed branch: lp:~victored/granite/decorated-window-api-fixes
Merge into: lp:~elementary-pantheon/granite/granite
Diff against target: 217 lines (+67/-63)
1 file modified
lib/Widgets/DecoratedWindow.vala (+67/-63)
To merge this branch: bzr merge lp:~victored/granite/decorated-window-api-fixes
Reviewer Review Type Date Requested Status
xapantu (community) Approve
Review via email: mp+112688@code.launchpad.net

Description of the change

Modify DecoratedWindow to use the GtkWindow API as much as possible.

To post a comment you must log in.
Revision history for this message
xapantu (xapantu) wrote :

Looks fine, using more Gtk apis can only work better :) Thanks :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/Widgets/DecoratedWindow.vala'
--- lib/Widgets/DecoratedWindow.vala 2012-06-13 22:35:33 +0000
+++ lib/Widgets/DecoratedWindow.vala 2012-06-29 03:00:32 +0000
@@ -27,7 +27,7 @@
2727
28 public class DecoratedWindow : CompositedWindow {28 public class DecoratedWindow : CompositedWindow {
2929
30 const string DECORATED_WINDOW_FALLBACK_STYLESHEET = """30 static const string DECORATED_WINDOW_FALLBACK_STYLESHEET = """
31 .decorated-window {31 .decorated-window {
32 border-style:solid;32 border-style:solid;
33 border-color:alpha (#000, 0.35);33 border-color:alpha (#000, 0.35);
@@ -38,7 +38,7 @@
38 """;38 """;
3939
40 // Currently not overridable40 // Currently not overridable
41 const string DECORATED_WINDOW_STYLESHEET = """41 static const string DECORATED_WINDOW_STYLESHEET = """
42 .decorated-window { border-width:1px; }42 .decorated-window { border-width:1px; }
43 """;43 """;
4444
@@ -55,34 +55,13 @@
5555
56 ref_window.get_style_context ().add_class (STYLE_CLASS_DECORATED_WINDOW);56 ref_window.get_style_context ().add_class (STYLE_CLASS_DECORATED_WINDOW);
5757
58 ref_window.get_style_context ().add_provider (normal_style, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);58 ref_window.get_style_context ().add_provider (normal_style,
59 ref_window.get_style_context ().add_provider (fallback_style, Gtk.STYLE_PROVIDER_PRIORITY_FALLBACK);59 Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
60 }60 ref_window.get_style_context ().add_provider (fallback_style,
6161 Gtk.STYLE_PROVIDER_PRIORITY_FALLBACK);
62 bool _show_close_button = true;62 }
63 public bool show_close_button {63
64 get {64 public bool show_title { get; set; default = true; }
65 return _show_close_button;
66 }
67 set {
68 _show_close_button = value;
69 w = -1; h = -1; // get it to redraw the buffer
70 Gtk.Allocation alloc;
71 this.get_allocation (out alloc);
72 this.size_allocate (alloc);
73
74 this.queue_draw ();
75 }
76 }
77
78 /**
79 * Whether to hide or destroy the window when the close button is clicked.
80 * By default, the window is destroyed. You can change that by changing this
81 * property to 'true'.
82 *
83 * Default: false;
84 */
85 public bool hide_on_close { get; set; default = false; }
8665
87 protected Gtk.Box box { get; private set; }66 protected Gtk.Box box { get; private set; }
88 protected Gtk.Window draw_ref { get; private set; }67 protected Gtk.Window draw_ref { get; private set; }
@@ -104,55 +83,70 @@
10483
105 private Gtk.Label _title;84 private Gtk.Label _title;
10685
107 public new string title {
108 get { return _title.label; }
109 set { _title.label = value; }
110 }
111
112 public DecoratedWindow (string title = "", string? window_style = null, string? content_style = null) {86 public DecoratedWindow (string title = "", string? window_style = null, string? content_style = null) {
113 this.resizable = true;87 this.resizable = false;
114 this.has_resize_grip = false;88 this.has_resize_grip = false;
115 this.window_position = Gtk.WindowPosition.CENTER_ON_PARENT;89 this.window_position = Gtk.WindowPosition.CENTER_ON_PARENT;
11690
117 this._title = new Gtk.Label (title);91 this.close_img = get_close_pixbuf ();
118 this._title.margin_top = 5;92
93 this._title = new Gtk.Label (null);
94 this._title.halign = Gtk.Align.CENTER;
95 this._title.hexpand = false;
96 this._title.ellipsize = Pango.EllipsizeMode.MIDDLE;
97 this._title.single_line_mode = true;
98 this._title.margin = 6;
99 this._title.margin_left = this._title.margin_right = 6 + this.close_img.get_width () / 3;
119 var attr = new Pango.AttrList ();100 var attr = new Pango.AttrList ();
120 attr.insert (new Pango.AttrFontDesc (Pango.FontDescription.from_string ("bold")));101 attr.insert (new Pango.AttrFontDesc (Pango.FontDescription.from_string ("bold")));
121 this._title.attributes = attr;102 this._title.attributes = attr;
122103
104 this.notify["title"].connect ( () => {
105 this._title.label = this.title;
106 });
107
108 this.notify["show-title"].connect ( () => {
109 this._title.visible = this.show_title;
110 });
111
112 this.notify["deletable"].connect ( () => {
113 w = -1; h = -1; // get it to redraw the buffer
114 this.queue_resize ();
115 this.queue_draw ();
116 });
117
118 this.title = title;
119 this.deletable = true;
120
123 this.box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);121 this.box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0);
122 this.box.margin = SHADOW_BLUR + 1; // SHADOW_BLUR + border_width
123
124 this.draw_ref = new Gtk.Window ();124 this.draw_ref = new Gtk.Window ();
125125
126 // set theming126 // set theming
127 set_default_theming (draw_ref);127 set_default_theming (this.draw_ref);
128128
129 // extra theming129 // extra theming
130 if (window_style != null && window_style != "")130 if (window_style != null && window_style != "")
131 draw_ref.get_style_context ().add_class (window_style);131 this.draw_ref.get_style_context ().add_class (window_style);
132132
133 if (content_style != null && content_style != "")133 if (content_style != null && content_style != "")
134 box.get_style_context ().add_class (content_style);134 this.box.get_style_context ().add_class (content_style);
135135
136 close_img = get_close_pixbuf ();136 this.box.pack_start (this._title, false);
137137 base.add (this.box);
138 this.size_allocate.connect (on_size_allocate);
139 this.draw.connect (draw_widget);
140138
141 this.add_events (Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK);139 this.add_events (Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.POINTER_MOTION_MASK);
142
143 this.motion_notify_event.connect (on_motion_notify);140 this.motion_notify_event.connect (on_motion_notify);
144 this.button_press_event.connect (on_button_press);141 this.button_press_event.connect (on_button_press);
145142 this.delete_event.connect_after (on_delete_event);
146 box.pack_start (_title, false);143 this.size_allocate.connect (on_size_allocate);
147144 this.draw.connect (draw_widget);
148 box.margin = SHADOW_BLUR + 1; // SHADOW_BLUR + border_width
149
150 base.add (this.box);
151 }145 }
152146
153147
154 public new void add (Gtk.Widget w) {148 public new void add (Gtk.Widget w) {
155 this.box.pack_start (w);149 this.box.pack_start (w, true, true);
156 }150 }
157151
158 public new void remove (Gtk.Widget w) {152 public new void remove (Gtk.Widget w) {
@@ -185,17 +179,19 @@
185 this.buffer.context.fill ();179 this.buffer.context.fill ();
186 this.buffer.exponential_blur (SHADOW_BLUR / 2);180 this.buffer.exponential_blur (SHADOW_BLUR / 2);
187181
188 draw_ref.get_style_context ().render_activity (this.buffer.context, x, y, width, height);182 draw_ref.get_style_context ().render_activity (this.buffer.context,
183 x, y, width, height);
189184
190 if (this.show_close_button) {185 if (this.deletable) {
191 Gdk.cairo_set_source_pixbuf (this.buffer.context, close_img, SHADOW_BLUR / 2 + CLOSE_BUTTON_X,186 Gdk.cairo_set_source_pixbuf (this.buffer.context, close_img,
187 SHADOW_BLUR / 2 + CLOSE_BUTTON_X,
192 SHADOW_BLUR / 2 + CLOSE_BUTTON_Y);188 SHADOW_BLUR / 2 + CLOSE_BUTTON_Y);
193 this.buffer.context.paint ();189 this.buffer.context.paint ();
194 }190 }
195 }191 }
196192
197 private bool on_motion_notify (Gdk.EventMotion e) {193 private bool on_motion_notify (Gdk.EventMotion e) {
198 if (show_close_button && coords_over_close_button (e.x, e.y))194 if (coords_over_close_button (e.x, e.y))
199 this.get_window ().set_cursor (new Gdk.Cursor (Gdk.CursorType.HAND1));195 this.get_window ().set_cursor (new Gdk.Cursor (Gdk.CursorType.HAND1));
200 else196 else
201 this.get_window ().set_cursor (null);197 this.get_window ().set_cursor (null);
@@ -205,10 +201,10 @@
205201
206 private bool on_button_press (Gdk.EventButton e) {202 private bool on_button_press (Gdk.EventButton e) {
207 if (coords_over_close_button (e.x, e.y)) {203 if (coords_over_close_button (e.x, e.y)) {
208 if (hide_on_close)204 var event = new Gdk.Event (Gdk.EventType.DELETE);
209 this.hide ();205 event.any.window = e.window;
210 else206 event.any.send_event = e.send_event;
211 this.destroy ();207 this.delete_event (event.any);
212 }208 }
213 else {209 else {
214 this.begin_move_drag ((int)e.button, (int)e.x_root, (int)e.y_root, e.time);210 this.begin_move_drag ((int)e.button, (int)e.x_root, (int)e.y_root, e.time);
@@ -218,10 +214,18 @@
218 }214 }
219215
220 private bool coords_over_close_button (double x, double y) {216 private bool coords_over_close_button (double x, double y) {
221 return x > (SHADOW_BLUR / 2 + CLOSE_BUTTON_X) &&217 return this.deletable &&
218 x > (SHADOW_BLUR / 2 + CLOSE_BUTTON_X) &&
222 x < (close_img.get_width () + SHADOW_BLUR / 2 + CLOSE_BUTTON_X) &&219 x < (close_img.get_width () + SHADOW_BLUR / 2 + CLOSE_BUTTON_X) &&
223 y > (SHADOW_BLUR / 2 + CLOSE_BUTTON_Y) &&220 y > (SHADOW_BLUR / 2 + CLOSE_BUTTON_Y) &&
224 y < (close_img.get_height () + SHADOW_BLUR / 2 + CLOSE_BUTTON_Y);221 y < (close_img.get_height () + SHADOW_BLUR / 2 + CLOSE_BUTTON_Y);
225 }222 }
223
224 private bool on_delete_event (Gdk.EventAny event) {
225 if (this.deletable)
226 this.destroy ();
227
228 return false;
229 }
226 }230 }
227}231}

Subscribers

People subscribed via source and target branches