~midori/midori/trunk

4887 by Christian Dywan
Rewrite Midori.PanedAction in Vala
1
/*
2
 Copyright (C) 2011 Peter Hatina <phatina@redhat.com>
3
4
 This library is free software; you can redistribute it and/or
5
 modify it under the terms of the GNU Lesser General Public
6
 License as published by the Free Software Foundation; either
7
 version 2.1 of the License, or (at your option) any later version.
8
9
 See the file COPYING for the full license text.
10
*/
11
12
namespace Midori {
13
    public class PanedAction : Gtk.Action {
14
        Gtk.HPaned? hpaned = null;
15
        Gtk.ToolItem? toolitem = null;
16
        Child child1 = new Child();
17
        Child child2 = new Child();
18
6954.2.1 by Christian Dywan
Implement Midori.Window class with toolbar/ headerbar
19
        public PanedAction () {
20
            GLib.Object (name: "LocationSearch");
21
        }
22
4887 by Christian Dywan
Rewrite Midori.PanedAction in Vala
23
        private struct Child {
6825.1.1 by Geronimo Bareiro
Fix warning that prevents vala to compile. Change from protected to public a property in PanedAction.
24
            public Gtk.Widget widget;
4887 by Christian Dywan
Rewrite Midori.PanedAction in Vala
25
            string name;
26
            bool resize;
27
            bool shrink;
28
        }
29
30
        public override unowned Gtk.Widget create_tool_item () {
31
            Gtk.Alignment alignment = new Gtk.Alignment (0.0f, 0.5f, 1.0f, 0.1f);
32
            hpaned = new Gtk.HPaned ();
33
            toolitem = new Gtk.ToolItem ();
34
            toolitem.set_expand (true);
35
            toolitem.add (alignment);
36
            alignment.add (hpaned);
37
38
            hpaned.pack1 (child1.widget, child1.resize, child1.shrink);
39
            hpaned.pack2 (child2.widget, child2.resize, child2.shrink);
40
            toolitem.show_all ();
41
            return toolitem;
42
        }
43
44
        public void set_child1 (Gtk.Widget widget, string name, bool resize, bool shrink) {
45
            child1.widget = widget;
46
            child1.name = name;
47
            child1.resize = resize;
48
            child1.shrink = shrink;
49
        }
50
51
        public void set_child2 (Gtk.Widget widget, string name, bool resize, bool shrink) {
52
            child2.widget = widget;
53
            child2.name = name;
54
            child2.resize = resize;
55
            child2.shrink = shrink;
56
        }
57
58
        public Gtk.Widget? get_child1 () {
59
            return child1.widget;
60
        }
61
62
        public Gtk.Widget? get_child2 () {
63
            return child2.widget;
64
        }
65
66
        public Gtk.Widget? get_child_by_name (string name) {
67
            if (name == child1.name)
68
                return child1.widget;
69
            else if (name == child2.name)
70
                return child2.widget;
71
            return null;
72
        }
73
74
        public string get_child1_name () {
75
            return child1.name;
76
        }
77
78
        public string get_child2_name () {
79
            return child2.name;
80
        }
81
    }
82
}
83