~ubuntu-branches/ubuntu/trusty/eiciel/trusty-proposed

« back to all changes in this revision

Viewing changes to src/cellrenderer_acl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2010-06-04 02:38:02 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100604023802-jp2v6c9uviiioc5z
* New upstream release.
* debian/patches/02-gio.patch
  - Removed, merged upstream.
* debian/patches/03-no-libgnomeui.patch
  - Removed, merged upstream.
* debian/patches/01-fix-gettext-translations.patch
  - Fix gettext translations by using dgettext and specifying the correct
    domainname.
* debian/patches/02-de-po.patch
  - Update and complete German translation.
* debian/rules
  - Remove de.gmo on clean and rebuild it on build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
    Eiciel - GNOME editor of ACL file permissions.
3
 
    Copyright (C) 2004-2005 Roger Ferrer Ib��ez
 
3
    Copyright (C) 2004-2010 Roger Ferrer Ib��ez
4
4
 
5
5
    This program is free software; you can redistribute it and/or modify
6
6
    it under the terms of the GNU General Public License as published by
14
14
 
15
15
    You should have received a copy of the GNU General Public License
16
16
    along with this program; if not, write to the Free Software
17
 
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,  USA
18
18
*/
19
19
#include "cellrenderer_acl.hpp"
 
20
// #include <iostream>
 
21
#include <algorithm>
20
22
 
 
23
#define MARK_BACKGROUND_PROPERTY ("mark_background")
21
24
 
22
25
CellRendererACL::CellRendererACL()
23
 
        : Glib::ObjectBase (typeid(CellRendererACL)),
24
 
        Gtk::CellRendererToggle(),
25
 
        property_marca_fons_(*this, "marcar_fons", false)
26
 
{
27
 
}
28
 
 
29
 
void CellRendererACL::render_vfunc (const Glib::RefPtr<Gdk::Drawable>& window,
30
 
                Gtk::Widget& widget,
31
 
                const Gdk::Rectangle& background_area,
32
 
                const Gdk::Rectangle& cell_area,
33
 
                const Gdk::Rectangle& expose_area,
34
 
                Gtk::CellRendererState flags
35
 
                )
36
 
{
37
 
        Gtk::CellRendererToggle::render_vfunc(window, widget, background_area, cell_area, expose_area, flags);
38
 
 
39
 
        // Pintem una admiraci�
40
 
        if (property_marca_fons_.get_value() && property_active())
41
 
        {
42
 
                Glib::RefPtr<Pango::Layout> pango = Pango::Layout::create(widget.get_pango_context());
43
 
                pango->set_markup("<span foreground=\"#cc0000\" weight=\"bold\">!</span>");
44
 
 
45
 
                Pango::Rectangle ink_rect = pango->get_pixel_ink_extents();
46
 
 
47
 
                // A GTK els checkboxes sempre son de 12x12 
48
 
                // per tant -> hardcode 6
49
 
                int posicioX = cell_area.get_x() + (cell_area.get_width() / 2) - 6;
50
 
                int posicioY = cell_area.get_y() + (cell_area.get_height() / 2) - 6;
51
 
 
52
 
                Glib::RefPtr<Gdk::GC> context_grafic = Gdk::GC::create(window);
53
 
 
54
 
                window->draw_layout(context_grafic, 
55
 
                                posicioX - ink_rect.get_width() - 4,
56
 
                                posicioY - ink_rect.get_height() / 2,
57
 
                                pango);
58
 
                
59
 
                // estil->paint_layout ( window,
60
 
                //              Gtk::STATE_NORMAL,
61
 
                //              false,
62
 
                //              cell_area,
63
 
                //              widget,
64
 
                //              "",
65
 
                //              posicioX - ink_rect.get_width() - 4, 
66
 
                //              posicioY - ink_rect.get_height() / 2,
67
 
                //              pango);
68
 
        }
69
 
}
70
 
 
71
 
 
72
 
Glib::PropertyProxy<bool> CellRendererACL::property_marcar_fons()
73
 
{
74
 
        return Glib::PropertyProxy<bool>(this, "marcar_fons");
 
26
    : Glib::ObjectBase (typeid(CellRendererACL)),
 
27
    Gtk::CellRendererToggle(),
 
28
    _mark_background(*this, MARK_BACKGROUND_PROPERTY, false)
 
29
{
 
30
}
 
31
 
 
32
// I don't want this in the header
 
33
static int default_indicator_size = 13;
 
34
static const int blank = 4;
 
35
 
 
36
void CellRendererACL::get_size_vfunc(Gtk::Widget& widget,
 
37
        const Gdk::Rectangle* cell_area,
 
38
        int * x_offset,
 
39
        int * y_offset,
 
40
        int * width,
 
41
        int * height) const 
 
42
{
 
43
    Glib::RefPtr<Gdk::Pixbuf> warning_icon = widget.render_icon(Gtk::Stock::DIALOG_WARNING, 
 
44
            Gtk::IconSize(Gtk::ICON_SIZE_SMALL_TOOLBAR), 
 
45
            "default");
 
46
 
 
47
    const int checkbox_width = default_indicator_size;
 
48
    const int checkbox_height = default_indicator_size;
 
49
    const int inner_box_width = warning_icon->get_width() + blank + checkbox_width;
 
50
    const int inner_box_height = std::max(warning_icon->get_height(), checkbox_height);
 
51
 
 
52
    *width = inner_box_width;
 
53
    *height = inner_box_height;
 
54
}
 
55
 
 
56
void CellRendererACL::render_vfunc (const Glib::RefPtr<Gdk::Drawable>& drawable,
 
57
        Gtk::Widget& widget,
 
58
        const Gdk::Rectangle& background_area,
 
59
        const Gdk::Rectangle& cell_area,
 
60
        const Gdk::Rectangle& expose_area,
 
61
        Gtk::CellRendererState flags)
 
62
{
 
63
    Glib::RefPtr<Gtk::Style> style = widget.get_style();
 
64
    Glib::RefPtr<Gdk::Window> window = Glib::RefPtr<Gdk::Window>::cast_dynamic(drawable);
 
65
 
 
66
    Gtk::StateType state = Gtk::STATE_NORMAL; 
 
67
 
 
68
    Glib::RefPtr<Gdk::Pixbuf> warning_icon = widget.render_icon(Gtk::Stock::DIALOG_WARNING, 
 
69
            Gtk::IconSize(Gtk::ICON_SIZE_SMALL_TOOLBAR), 
 
70
            "default");
 
71
 
 
72
    /*
 
73
     * The size of the icon + 4 spacing pixels + checkbox of 13x13
 
74
     */
 
75
 
 
76
    const int checkbox_width = default_indicator_size;
 
77
    const int checkbox_height = default_indicator_size;
 
78
    const int inner_box_width = warning_icon->get_width() + blank + checkbox_width;
 
79
    const int inner_box_height = std::max(warning_icon->get_height(), checkbox_height);
 
80
 
 
81
    // std::cerr 
 
82
    //     << "--->" << std::endl
 
83
    //     << "inner_box_width= " << inner_box_width << std::endl
 
84
    //     << "inner_box_height= " << inner_box_height << std::endl
 
85
    //     << "cell_area_width= " << cell_area.get_width() << std::endl
 
86
    //     << "cell_area_height= " << cell_area.get_height() << std::endl
 
87
    //     << "<---" << std::endl;
 
88
    //     ;
 
89
 
 
90
    /*
 
91
     * Precondition: cell_area.get_width() >= inner_box_width
 
92
     *               cell_area.get_height() >= inner_box_height()
 
93
     *
 
94
     * Enforce this in the widget
 
95
     */
 
96
 
 
97
    int inner_x = (cell_area.get_width() - inner_box_width) / 2;
 
98
    int inner_y = (cell_area.get_height() - inner_box_height) / 2;
 
99
 
 
100
    inner_x = (inner_x < 0) ? 0 : inner_x;
 
101
    inner_y = (inner_y < 0) ? 0 : inner_y;
 
102
 
 
103
    inner_x += cell_area.get_x();
 
104
    inner_y += cell_area.get_y();
 
105
 
 
106
    Gtk::ShadowType shadow = Gtk::SHADOW_OUT;
 
107
    if (property_active())
 
108
    {
 
109
        shadow = Gtk::SHADOW_IN;
 
110
 
 
111
    }
 
112
 
 
113
    int checkbox_x = inner_x + warning_icon->get_width() + blank;
 
114
    int checkbox_y = inner_y + (warning_icon->get_height() - checkbox_height)/2; 
 
115
 
 
116
    style->paint_check(
 
117
            window,
 
118
            state,
 
119
            shadow,
 
120
            cell_area,
 
121
            widget,
 
122
            "checkbutton",
 
123
            checkbox_x, checkbox_y, checkbox_width, checkbox_height
 
124
            );
 
125
 
 
126
    if (property_active() && _mark_background.get_value())
 
127
    {
 
128
        int icon_x = inner_x;
 
129
        int icon_y = inner_y;
 
130
 
 
131
        Glib::RefPtr<Gdk::GC> graphic_context = Gdk::GC::create(drawable);
 
132
 
 
133
        drawable->draw_pixbuf(graphic_context,
 
134
                warning_icon,
 
135
                0, 0,
 
136
                icon_x, icon_y,
 
137
                -1, -1,
 
138
                Gdk::RGB_DITHER_NORMAL,
 
139
                0, 0);
 
140
    }
 
141
}
 
142
 
 
143
 
 
144
Glib::PropertyProxy<bool> CellRendererACL::mark_background()
 
145
{
 
146
    return Glib::PropertyProxy<bool>(this, MARK_BACKGROUND_PROPERTY);
75
147
}
76
148