~hkdb/geary/disco-3.34.1

« back to all changes in this revision

Viewing changes to src/client/conversation-list/conversation-list-cell-renderer.vala

  • Committer: hkdb
  • Date: 2019-10-08 10:54:21 UTC
  • Revision ID: hkdb@3df.io-20191008105421-3dkwnpnhcamm77to
Tags: upstream-3.34.1-disco
ImportĀ upstreamĀ versionĀ 3.34.1-disco

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2016 Software Freedom Conservancy Inc.
 
2
 *
 
3
 * This software is licensed under the GNU Lesser General Public License
 
4
 * (version 2.1 or later).  See the COPYING file in this distribution.
 
5
 */
 
6
 
 
7
public class ConversationListCellRenderer : Gtk.CellRenderer {
 
8
    private static FormattedConversationData? example_data = null;
 
9
    private static bool hover_selected = false;
 
10
 
 
11
    // Mail message data.
 
12
    public FormattedConversationData data { get; set; }
 
13
 
 
14
    public ConversationListCellRenderer() {
 
15
    }
 
16
 
 
17
    ~ConversationListCellRenderer() {
 
18
        example_data = null;
 
19
    }
 
20
 
 
21
    public override void get_preferred_height(Gtk.Widget widget,
 
22
                                              out int minimum_size,
 
23
                                              out int natural_size) {
 
24
        if (example_data == null)
 
25
            style_changed(widget);
 
26
 
 
27
        minimum_size = natural_size = example_data.get_height();
 
28
    }
 
29
 
 
30
    public override void get_preferred_width(Gtk.Widget widget,
 
31
                                              out int minimum_size,
 
32
                                              out int natural_size) {
 
33
        // Set width to 1 (rather than 0) to work around certain
 
34
        // themes that cause the conversation list to be shown as
 
35
        // "squished":
 
36
        // https://bugzilla.gnome.org/show_bug.cgi?id=713954
 
37
        minimum_size = natural_size = 1;
 
38
    }
 
39
 
 
40
    public override void render(Cairo.Context ctx, Gtk.Widget widget, Gdk.Rectangle background_area,
 
41
        Gdk.Rectangle cell_area, Gtk.CellRendererState flags) {
 
42
        if (data != null)
 
43
            data.render(ctx, widget, background_area, cell_area, flags, hover_selected);
 
44
    }
 
45
 
 
46
    // Recalculates size when the style changed.
 
47
    // Note: this must be called by the parent TreeView.
 
48
    public static void style_changed(Gtk.Widget widget) {
 
49
        if (example_data == null) {
 
50
            example_data = new FormattedConversationData.create_example();
 
51
        }
 
52
 
 
53
        example_data.calculate_sizes(widget);
 
54
    }
 
55
 
 
56
    // Shows hover effect on all selected cells.
 
57
    public static void set_hover_selected(bool hover) {
 
58
        hover_selected = hover;
 
59
    }
 
60
 
 
61
    // This is implemented because it's required; ignore it and look at get_preferred_height() instead.
 
62
    public override void get_size(Gtk.Widget widget, Gdk.Rectangle? cell_area, out int x_offset,
 
63
        out int y_offset, out int width, out int height) {
 
64
        // Set values to avoid compiler warning.
 
65
        x_offset = 0;
 
66
        y_offset = 0;
 
67
        width = 0;
 
68
        height = 0;
 
69
    }
 
70
}