~ubuntu-branches/ubuntu/jaunty/beagle/jaunty-security

« back to all changes in this revision

Viewing changes to search/TileCategory.cs

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-04 00:31:32 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20080504003132-2tkm5o8moo5952ri
Tags: 0.3.7-2ubuntu1
 * Merge from Debian unstable. (LP: #225746) Remaining Ubuntu changes:
  - debian/control:
    + Rename ice{weasel,dove}-beagle to {mozilla,thunderbird}-beagle and
      and update the dependencies accordingly.
    + Change Maintainer to Ubuntu Mono Team.
  - debian/rules:
    + Install the mozilla-beagle and thunderbird-beagle extensions.
  - ice{dove,weasel}.dirs:
    + Renamed to {mozilla,thunderbird}-beagle.dirs.
    + Fixed paths to point to usr/lib/{firefox,thunderbird}

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
using Gtk;
2
 
using Gdk;
3
 
using System;
4
 
using System.Collections;
5
 
 
6
 
namespace Search {
7
 
 
8
 
        public class TileCategory : Category {
9
 
 
10
 
                Gtk.SizeGroup sizeGroup;
11
 
 
12
 
                public TileCategory (Tiles.TileGroupInfo info, Gtk.SizeGroup sizeGroup) : base (info, 2)
13
 
                {
14
 
                        this.sizeGroup = sizeGroup;
15
 
                }
16
 
 
17
 
                protected override void OnAdded (Gtk.Widget widget)
18
 
                {
19
 
                        sizeGroup.AddWidget (widget);
20
 
                        base.OnAdded (widget);
21
 
                }
22
 
 
23
 
                protected override void OnRemoved (Gtk.Widget widget)
24
 
                {
25
 
                        base.OnRemoved (widget);
26
 
                        sizeGroup.RemoveWidget (widget);
27
 
                }
28
 
 
29
 
                protected override void OnSizeRequested (ref Requisition req)
30
 
                {
31
 
                        Requisition headerReq, tileReq;
32
 
 
33
 
                        req.Height = req.Width = 0;
34
 
                        headerReq = header.SizeRequest ();
35
 
 
36
 
                        tileReq.Width = tileReq.Height = 0;
37
 
                        foreach (Widget w in AllTiles) {
38
 
                                tileReq = w.SizeRequest ();
39
 
                                req.Width = Math.Max (req.Width, tileReq.Width);
40
 
                                req.Height = Math.Max (req.Height, tileReq.Height);
41
 
                        }
42
 
 
43
 
                        // req is now the max width/height of a single tile. Indent
44
 
                        // req.Width, and use that as our width request, so that the
45
 
                        // minimum width you can resize the category to is wide enough to
46
 
                        // fit a whole column. But request a req.Height that is only tall
47
 
                        // enough to fit PageSize tiles if we get the number of columns
48
 
                        // we'd wanted. (OnSizeAllocated will force a recalculation with
49
 
                        // fewer columns if we don't get enough width.)
50
 
                        req.Width += 2 * headerReq.Height;
51
 
                        req.Height *= (PageSize + Columns - 1) / Columns;
52
 
 
53
 
                        if (!Expanded)
54
 
                                req.Height = 2;  // keep a thin line of background.
55
 
                        
56
 
                        // Add height for the header, and update the width if the header
57
 
                        // is wider than the tile area
58
 
 
59
 
                        req.Height += headerReq.Height;
60
 
                        req.Width = Math.Max (req.Width, headerReq.Width);
61
 
 
62
 
                        // Handle BorderWidth
63
 
                        req.Width += (int)(2 * BorderWidth);
64
 
                        req.Height += (int)(2 * BorderWidth);
65
 
                }
66
 
 
67
 
                protected override void OnSizeAllocated (Rectangle allocation)
68
 
                {
69
 
                        Requisition headerReq, tileReq;
70
 
                        Rectangle childAlloc;
71
 
                        int col, i, tilesWidth, maxcols;
72
 
                        IList tiles = VisibleTiles;
73
 
 
74
 
                        base.OnSizeAllocated (allocation);
75
 
 
76
 
                        headerReq = header.ChildRequisition;
77
 
 
78
 
                        childAlloc.X = allocation.X + (int)BorderWidth;
79
 
                        childAlloc.Width = allocation.Width - (int)BorderWidth;
80
 
                        childAlloc.Y = allocation.Y + (int)BorderWidth;
81
 
                        childAlloc.Height = headerReq.Height;
82
 
                        header.Allocation = childAlloc;
83
 
 
84
 
                        if (tiles.Count == 0)
85
 
                                return;
86
 
 
87
 
                        tileReq = ((Gtk.Widget)tiles[0]).ChildRequisition;
88
 
                        if (tileReq.Width == 0)
89
 
                                return;
90
 
 
91
 
                        tilesWidth = allocation.Width - (int)(2 * BorderWidth) - headerReq.Height;
92
 
                        maxcols = tilesWidth / tileReq.Width;
93
 
                        if (maxcols != Columns) {
94
 
                                Columns = maxcols;
95
 
                                QueueResize ();
96
 
                                return;
97
 
                        }
98
 
 
99
 
                        childAlloc.X += headerReq.Height;
100
 
                        childAlloc.Y += childAlloc.Height;
101
 
                        childAlloc.Width = tileReq.Width;
102
 
                        childAlloc.Height = tileReq.Height;
103
 
 
104
 
                        for (i = col = 0; i < tiles.Count; i++) {
105
 
                                ((Gtk.Widget)tiles[i]).Allocation = childAlloc;
106
 
 
107
 
                                col = (col + 1) % Columns;
108
 
                                if (col == 0) {
109
 
                                        childAlloc.X = (int)BorderWidth + headerReq.Height;
110
 
                                        childAlloc.Y += childAlloc.Height;
111
 
                                } else
112
 
                                        childAlloc.X += childAlloc.Width;
113
 
                        }
114
 
                }
115
 
        }
116
 
}