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

« back to all changes in this revision

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