This file is indexed.

/usr/share/nickle/nichrome-button.5c is in cairo-5c 1.10.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/*
 * Copyright © 2008 Keith Packard
 *
 * This library is free software; you can redistribute it and/or
 * modify it either under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation
 * (the "LGPL") or, at your option, under the terms of the Mozilla
 * Public License Version 1.1 (the "MPL"). If you do not alter this
 * notice, a recipient may use your version of this file under either
 * the MPL or the LGPL.
 *
 * You should have received a copy of the LGPL along with this library
 * in the file COPYING-LGPL-2.1; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 * You should have received a copy of the MPL along with this library
 * in the file COPYING-MPL-1.1
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
 * OF ANY KIND, either express or implied. See the LGPL or the MPL for
 * the specific language governing rights and limitations.
 *
 * The Original Code is the cairo graphics library.
 *
 * The Initial Developer of the Original Code is Keith Packard
 *
 * Contributor(s):
 *      Keith Packard <keithp@keithp.com>
 */

autoload Nichrome;
autoload Nichrome::Lozenge;

extend namespace Nichrome {
    public namespace Button {

	public typedef button_t;

	protected typedef struct {
	    real x, y;
	    real pad;
	    real width, height;
	    real preferred_width, preferred_height;
	} metrics_t;
	
	protected typedef void (&widget_t widget, bool state) callback_t;
    
	protected typedef metrics_t (cairo_t cr, &button_t widget) get_metrics_t;

	public typedef widget_t + struct {
	    string  label;
	    string  font;
	    bool    pressed;
	    bool    inside;
	    real    pad_ratio;
	    rgba_color_t    color;
	    rgba_color_t    text_color;
	    callback_t	callback;
	    get_metrics_t get_metrics;
	} button_t;
	
	protected metrics_t get_metrics (cairo_t cr, &button_t widget) {
	    set_font (cr, widget.font);
	    text_extents_t text = text_extents (cr, widget.label);
	    text_extents_t m = text_extents (cr, "M");
	    text_extents_t x = text_extents (cr, "x");
	    font_extents_t font = font_extents(cr);
	    metrics_t metrics;
	    
	    real pad = floor (widget.pad_ratio * -m.y_bearing + 0.5);
	    metrics.pad = pad;
	    metrics.preferred_height = floor (pad + m.height + pad + 1.5) & ~1;
	    metrics.preferred_width = floor (widget.pad_ratio * 2.5 * pad +
	    text.width + 0.5);
	    metrics.width = max (widget.geometry.width, metrics.preferred_width);
	    metrics.height = max (widget.geometry.height, metrics.preferred_height);
	    real text_height = (x.height + m.height) / 2;
	    real text_bearing = (x.y_bearing + m.y_bearing) / 2;
	    metrics.y = floor ((metrics.height - text_height) / 2 
			       - text_bearing + 0.5);
	    metrics.x = floor ((metrics.width - text.width) / 2 
			       - text.x_bearing + 0.5);
	    return metrics;
	}
	
	protected void natural (cairo_t cr, &button_t widget) {
	    metrics_t	metrics = widget.get_metrics (cr, &widget);

	    rectangle (cr, 0, 0, metrics.preferred_width, metrics.preferred_height);
	}
	
	protected void outline (cairo_t cr, &button_t widget) {
	    metrics_t	metrics = widget.get_metrics (cr, &widget);

	    save (cr);
	    translate (cr, floor (metrics.pad/2), floor (metrics.pad/2));
	    Lozenge::outline (cr, floor (metrics.width - metrics.pad),
			     floor (metrics.height - metrics.pad));
	    restore (cr);
	}
	
	protected void draw (cairo_t cr, &button_t widget) {
	    metrics_t	metrics = widget.get_metrics (cr, &widget);
	    real    highlight = -floor (metrics.height/20);

	    if (widget.pressed && widget.inside)
		highlight = -highlight;

	    save (cr);
	    translate (cr, floor (metrics.pad/2), floor (metrics.pad/2));
	    Lozenge::draw (cr, floor (metrics.width - metrics.pad),
			   floor (metrics.height - metrics.pad),
			   widget.color, highlight);
	    restore (cr);
	    real text_x = metrics.x + highlight/2;
	    real text_y = metrics.y + highlight/2;
	    
	    int    offset = floor (min (metrics.preferred_height,
					metrics.preferred_width) / 120 +
				   0.5);
	    if (offset > 0)
	    {
		rgba_color_t darker = Lozenge::illum (widget.text_color, -0.2);
		rgba_color_t lighter = Lozenge::illum (widget.text_color, 0.2);
		move_to (cr, text_x - offset, text_y - offset);
		set_source_rgba (cr, darker.red, darker.green,
				 darker.blue, darker.alpha);
		show_text (cr, widget.label);
		
		move_to (cr, text_x + offset, text_y + offset);
		set_source_rgba (cr, lighter.red, lighter.green,
				 lighter.blue, lighter.alpha);
		show_text (cr, widget.label);
	    }
	    move_to (cr, text_x, text_y);
	    set_source_rgba (cr, widget.text_color.red, widget.text_color.green,
			     widget.text_color.blue, widget.text_color.alpha);
	    show_text (cr, widget.label);
	}
	
	protected void relabel (&button_t widget, string label) {
	    widget.label = label;
	    Widget::resize (&widget);
	}

	protected void button (&button_t widget, &button_event_t event) {
	    enum switch (event.type) {
	    case press:
		if (event.button > 3)
		    break;
		widget.pressed = true;
		Widget::redraw (&widget);
		break;
	    case release:
		if (event.button > 3)
		    break;
		Widget::redraw (&widget);
		widget.pressed = false;
		if (widget.inside)
		    widget.callback (&widget, true);
		break;
	    default:
		break;
	    }
	}
	
	protected void motion (&button_t widget, &motion_event_t event) {
	    enum switch (event.type) {
	    case leaving:
		widget.inside = false;
		if (widget.pressed)
		    Widget::redraw (&widget);
		break;
	    case entering:
		widget.inside = true;
		if (widget.pressed)
		    Widget::redraw (&widget);
		break;
	    case inside:
	    case outside:
		break;
	    }
	}

	protected void print(&button_t widget, int indent) {
	    do_indent(indent);
	    printf("button %s %v\n", widget.label, widget.geometry);
	}

	protected void init (&button_t widget,
			     &nichrome_t nichrome,
			     string label,
			     callback_t callback) {
	    Widget::init (&nichrome, &widget);
	    widget.label = label;
	    widget.font = Widget::default_font;
	    widget.draw = draw;
	    widget.pressed = false;
	    widget.inside = false;
	    widget.button = button;
	    widget.motion = motion;
	    widget.callback = callback;
	    widget.outline = outline;
	    widget.natural = natural;
	    widget.get_metrics = get_metrics;
	    widget.pad_ratio = 1;
	    widget.color = Widget::default_color;
	    widget.text_color = (rgba_color_t) {
		red = 0, green = 0, blue = 0, alpha = 1
	    };
	    widget.print = print;
	}
	
	protected *widget_t new (&nichrome_t nichrome,
				 string label,
				 callback_t callback) {
	    button_t	widget;

	    init (&widget, &nichrome, label, callback);
	    return &widget;
	}
    }
}