[gitg/vala: 6/35] Make ChildInfo a class so we get rid of the by-value semantics
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/vala: 6/35] Make ChildInfo a class so we get rid of the by-value semantics
- Date: Wed, 11 Jul 2012 15:17:57 +0000 (UTC)
commit 8d7860761c382ffd2c123ee5d948acca051f3484
Author: Alexander Larsson <alexl redhat com>
Date: Wed May 16 12:14:28 2012 +0200
Make ChildInfo a class so we get rid of the by-value semantics
We were comparing equality by value, etc, and we had to use "?" everywhere to
work around value copying. Better just use a class.
egg-list-box.vala | 103 +++++++++++++++++++++++++++-------------------------
1 files changed, 53 insertions(+), 50 deletions(-)
---
diff --git a/egg-list-box.vala b/egg-list-box.vala
index 8bd82e3..9b97374 100644
--- a/egg-list-box.vala
+++ b/egg-list-box.vala
@@ -22,24 +22,28 @@ public class Egg.ListBox : Container {
public delegate bool FilterFunc (Widget child);
public delegate void UpdateSeparatorFunc (ref Widget? separator, Widget child, Widget? before);
- private struct ChildInfo {
- Widget widget;
- Widget? separator;
- SequenceIter<ChildInfo?> iter;
- int y;
- int height;
+ private class ChildInfo {
+ public Widget widget;
+ public Widget? separator;
+ public SequenceIter<ChildInfo> iter;
+ public int y;
+ public int height;
+
+ public ChildInfo (Widget widget) {
+ this.widget = widget;
+ }
}
- private Sequence<ChildInfo?> children;
- private HashTable<unowned Widget, unowned ChildInfo?> child_hash;
+ private Sequence<ChildInfo> children;
+ private HashTable<unowned Widget, unowned ChildInfo> child_hash;
private CompareDataFunc<Widget>? sort_func;
private FilterFunc? filter_func;
private UpdateSeparatorFunc? update_separator_func;
- private unowned ChildInfo? selected_child;
- private unowned ChildInfo? prelight_child;
- private unowned ChildInfo? cursor_child;
+ private unowned ChildInfo selected_child;
+ private unowned ChildInfo prelight_child;
+ private unowned ChildInfo cursor_child;
bool active_child_active;
- private unowned ChildInfo? active_child;
+ private unowned ChildInfo active_child;
private SelectionMode selection_mode;
@@ -50,11 +54,11 @@ public class Egg.ListBox : Container {
selection_mode = SelectionMode.SINGLE;
- children = new Sequence<ChildInfo?>();
- child_hash = new HashTable<unowned Widget, unowned ChildInfo?> (GLib.direct_hash, GLib.direct_equal);
+ children = new Sequence<ChildInfo>();
+ child_hash = new HashTable<unowned Widget, unowned ChildInfo> (GLib.direct_hash, GLib.direct_equal);
}
- public Widget? get_selected_child (){
+ public unowned Widget? get_selected_child (){
if (selected_child != null)
return selected_child.widget;
@@ -64,7 +68,7 @@ public class Egg.ListBox : Container {
public void select_child (Widget? child) {
unowned ChildInfo? info = null;
if (child != null)
- info = child_hash.get (child);
+ info = lookup_info (child);
update_selected (info);
}
@@ -139,7 +143,7 @@ public class Egg.ListBox : Container {
/****** Implementation ***********/
- private int do_sort (ChildInfo? a, ChildInfo? b) {
+ private int do_sort (ChildInfo a, ChildInfo b) {
return sort_func (a.widget, b.widget);
}
@@ -172,7 +176,7 @@ public class Egg.ListBox : Container {
modify_selection_pressed = true;
}
- unowned ChildInfo? child = null;
+ ChildInfo? child = null;
switch (step) {
case MovementStep.BUFFER_ENDS:
if (count < 0)
@@ -182,7 +186,7 @@ public class Egg.ListBox : Container {
break;
case MovementStep.DISPLAY_LINES:
if (cursor_child != null) {
- SequenceIter<ChildInfo?>? iter = cursor_child.iter;
+ SequenceIter<ChildInfo>? iter = cursor_child.iter;
while (count < 0 && iter != null) {
iter = get_previous_visible (iter);
@@ -206,7 +210,7 @@ public class Egg.ListBox : Container {
if (cursor_child != null) {
int start_y = cursor_child.y;
int end_y = start_y;
- SequenceIter<ChildInfo?>? iter = cursor_child.iter;
+ SequenceIter<ChildInfo>? iter = cursor_child.iter;
child = cursor_child;
if (count < 0) {
@@ -216,7 +220,7 @@ public class Egg.ListBox : Container {
iter = get_previous_visible (iter);
if (iter == null)
break;
- unowned ChildInfo? prev = iter.get ();
+ ChildInfo prev = iter.get ();
if (prev.y < start_y - page_size)
break;
child = prev;
@@ -228,7 +232,7 @@ public class Egg.ListBox : Container {
iter = get_next_visible (iter);
if (iter.is_end ())
break;
- unowned ChildInfo? next = iter.get ();
+ ChildInfo next = iter.get ();
if (next.y > start_y + page_size)
break;
child = next;
@@ -314,7 +318,7 @@ public class Egg.ListBox : Container {
unowned ChildInfo? find_child_at_y (int y) {
unowned ChildInfo? child_info = null;
for (var iter = children.get_begin_iter (); !iter.is_end (); iter = iter.next ()) {
- unowned ChildInfo? info = iter.get ();
+ unowned ChildInfo info = iter.get ();
if (y >= info.y && y < info.y + info.height) {
child_info = info;
break;
@@ -327,7 +331,7 @@ public class Egg.ListBox : Container {
cursor_child = child;
this.grab_focus ();
this.queue_draw ();
- var vadj = get_focus_vadjustment ();
+ unowned Adjustment? vadj = get_focus_vadjustment ();
if (child != null && vadj != null)
vadj.clamp_page (cursor_child.y,
cursor_child.y + cursor_child.height);
@@ -345,7 +349,7 @@ public class Egg.ListBox : Container {
}
private void select_and_activate (ChildInfo? child) {
- Widget? w = null;
+ unowned Widget? w = null;
if (child != null)
w = child.widget;
update_selected (child);
@@ -431,7 +435,7 @@ public class Egg.ListBox : Container {
public override bool focus (DirectionType direction) {
bool had_focus;
bool focus_into;
- Widget recurse_into = null;
+ unowned Widget recurse_into = null;
focus_into = true;
had_focus = has_focus;
@@ -542,10 +546,10 @@ public class Egg.ListBox : Container {
}
private struct ChildFlags {
- unowned ChildInfo? child;
+ unowned ChildInfo child;
StateFlags state;
- public static ChildFlags *find_or_add (ref ChildFlags[] array, ChildInfo? to_find) {
+ public static ChildFlags *find_or_add (ref ChildFlags[] array, ChildInfo to_find) {
for (int i = 0; i < array.length; i++) {
if (array[i].child == to_find)
return &array[i];
@@ -561,7 +565,7 @@ public class Egg.ListBox : Container {
Allocation allocation;
this.get_allocation (out allocation);
- var context = this.get_style_context ();
+ unowned StyleContext context = this.get_style_context ();
context.render_background (cr,
0, 0, allocation.width, allocation.height);
@@ -638,14 +642,14 @@ public class Egg.ListBox : Container {
private void apply_filter_all () {
for (var iter = children.get_begin_iter (); !iter.is_end (); iter = iter.next ()) {
- unowned ChildInfo? child_info = iter.get ();
+ unowned ChildInfo child_info = iter.get ();
apply_filter (child_info.widget);
}
}
private unowned ChildInfo? get_first_visible () {
for (var iter = children.get_begin_iter (); !iter.is_end (); iter = iter.next ()) {
- unowned ChildInfo? child_info = iter.get ();
+ unowned ChildInfo child_info = iter.get ();
unowned Widget widget = child_info.widget;
if (widget.get_visible () && widget.get_child_visible ())
return child_info;
@@ -657,7 +661,7 @@ public class Egg.ListBox : Container {
var iter = children.get_end_iter ();
while (!iter.is_begin ()) {
iter = iter.prev ();
- unowned ChildInfo? child_info = iter.get ();
+ unowned ChildInfo child_info = iter.get ();
unowned Widget widget = child_info.widget;
if (widget.get_visible () && widget.get_child_visible ())
return child_info;
@@ -665,7 +669,7 @@ public class Egg.ListBox : Container {
return null;
}
- private SequenceIter<ChildInfo?>? get_previous_visible (SequenceIter<ChildInfo?> _iter) {
+ private SequenceIter<ChildInfo>? get_previous_visible (SequenceIter<ChildInfo> _iter) {
if (_iter.is_begin())
return null;
var iter = _iter;
@@ -673,7 +677,7 @@ public class Egg.ListBox : Container {
do {
iter = iter.prev ();
- unowned ChildInfo? child_info = iter.get ();
+ unowned ChildInfo child_info = iter.get ();
unowned Widget widget = child_info.widget;
if (widget.get_visible () && widget.get_child_visible ())
return iter;
@@ -682,7 +686,7 @@ public class Egg.ListBox : Container {
return null;
}
- private SequenceIter<ChildInfo?>? get_next_visible (SequenceIter<ChildInfo?> _iter) {
+ private SequenceIter<ChildInfo>? get_next_visible (SequenceIter<ChildInfo> _iter) {
if (_iter.is_end())
return _iter;
@@ -691,7 +695,7 @@ public class Egg.ListBox : Container {
iter = iter.next ();
if (!iter.is_end ()) {
- unowned ChildInfo? child_info = iter.get ();
+ unowned ChildInfo child_info = iter.get ();
unowned Widget widget = child_info.widget;
if (widget.get_visible () && widget.get_child_visible ())
return iter;
@@ -701,16 +705,16 @@ public class Egg.ListBox : Container {
return iter;
}
- private void update_separator (SequenceIter<ChildInfo?>? iter) {
+ private void update_separator (SequenceIter<ChildInfo>? iter) {
if (iter == null || iter.is_end ())
return;
- unowned ChildInfo? info = iter.get ();
+ unowned ChildInfo info = iter.get ();
var before_iter = get_previous_visible (iter);
var widget = info.widget;
Widget? before_widget = null;
if (before_iter != null) {
- unowned ChildInfo? before_info = before_iter.get ();
+ unowned ChildInfo before_info = before_iter.get ();
before_widget = before_info.widget;
}
@@ -740,16 +744,15 @@ public class Egg.ListBox : Container {
}
public override void add (Widget widget) {
- ChildInfo? the_info = { widget };
- unowned ChildInfo? info = the_info;
- SequenceIter<ChildInfo?> iter;
+ ChildInfo info = new ChildInfo (widget);
+ SequenceIter<ChildInfo> iter;
child_hash.set (widget, info);
if (sort_func != null)
- iter = children.insert_sorted ((owned) the_info, do_sort);
+ iter = children.insert_sorted (info, do_sort);
else
- iter = children.append ((owned) the_info);
+ iter = children.append (info);
apply_filter (widget);
@@ -796,7 +799,7 @@ public class Egg.ListBox : Container {
public override void forall_internal (bool include_internals,
Gtk.Callback callback) {
for (var iter = children.get_begin_iter (); !iter.is_end (); iter = iter.next ()) {
- unowned ChildInfo? child_info = iter.get ();
+ unowned ChildInfo child_info = iter.get ();
if (child_info.separator != null && include_internals)
callback (child_info.separator);
callback (child_info.widget);
@@ -825,12 +828,12 @@ public class Egg.ListBox : Container {
public override void get_preferred_height_for_width (int width, out int minimum_height, out int natural_height) {
minimum_height = 0;
- var context = this.get_style_context ();
+ unowned StyleContext context = this.get_style_context ();
int focus_width, focus_pad;
context.get_style ("focus-line-width", out focus_width,
"focus-padding", out focus_pad);
for (var iter = children.get_begin_iter (); !iter.is_end (); iter = iter.next ()) {
- unowned ChildInfo? child_info = iter.get ();
+ unowned ChildInfo child_info = iter.get ();
unowned Widget widget = child_info.widget;
int child_min;
@@ -856,14 +859,14 @@ public class Egg.ListBox : Container {
}
public override void get_preferred_width (out int minimum_width, out int natural_width) {
- var context = this.get_style_context ();
+ unowned StyleContext context = this.get_style_context ();
int focus_width, focus_pad;
context.get_style ("focus-line-width", out focus_width,
"focus-padding", out focus_pad);
minimum_width = 0;
natural_width = 0;
for (var iter = children.get_begin_iter (); !iter.is_end (); iter = iter.next ()) {
- unowned ChildInfo? child_info = iter.get ();
+ unowned ChildInfo child_info = iter.get ();
unowned Widget widget = child_info.widget;
int child_min, child_nat;
@@ -912,7 +915,7 @@ public class Egg.ListBox : Container {
separator_allocation.width = allocation.width;
for (var iter = children.get_begin_iter (); !iter.is_end (); iter = iter.next ()) {
- unowned ChildInfo? child_info = iter.get ();
+ unowned ChildInfo child_info = iter.get ();
unowned Widget widget = child_info.widget;
int child_min;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]