2007-12-22 15:38:14 +01:00
|
|
|
/*
|
|
|
|
* iconbox.c - icon widget
|
|
|
|
*
|
2008-01-02 16:59:43 +01:00
|
|
|
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
|
2007-12-22 15:38:14 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "widget.h"
|
2008-01-21 18:14:59 +01:00
|
|
|
#include "common/util.h"
|
2007-12-22 15:38:14 +01:00
|
|
|
|
2008-01-02 14:59:15 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
char *image;
|
2008-03-21 16:50:17 +01:00
|
|
|
bool resize;
|
2008-01-02 14:59:15 +01:00
|
|
|
} Data;
|
|
|
|
|
2007-12-22 15:38:14 +01:00
|
|
|
static int
|
2008-05-20 15:39:47 +02:00
|
|
|
iconbox_draw(widget_node_t *w, statusbar_t *statusbar, int offset,
|
2007-12-22 15:38:14 +01:00
|
|
|
int used __attribute__ ((unused)))
|
|
|
|
{
|
2008-05-20 15:39:47 +02:00
|
|
|
Data *d = w->widget->data;
|
2008-03-19 17:51:12 +01:00
|
|
|
area_t area = draw_get_image_size(d->image);
|
2008-01-02 14:59:15 +01:00
|
|
|
|
2008-01-17 13:45:24 +01:00
|
|
|
/* image not valid */
|
|
|
|
if(area.width < 0 || area.height < 0)
|
2008-05-20 15:39:47 +02:00
|
|
|
return (w->area.width = 0);
|
2008-01-17 13:45:24 +01:00
|
|
|
|
2008-01-02 14:59:15 +01:00
|
|
|
if(d->resize)
|
2008-05-20 15:39:47 +02:00
|
|
|
w->area.width = ((double) statusbar->height / area.height) * area.width;
|
2008-01-02 14:59:15 +01:00
|
|
|
else
|
2008-05-20 15:39:47 +02:00
|
|
|
w->area.width = area.width;
|
2007-12-29 21:44:44 +01:00
|
|
|
|
2008-05-24 09:07:56 +02:00
|
|
|
if(w->area.width > statusbar->width - used)
|
|
|
|
return (w->area.width = 0);
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
w->area.height = statusbar->height;
|
2008-01-05 12:44:14 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
w->area.x = widget_calculate_offset(statusbar->width,
|
|
|
|
w->area.width,
|
|
|
|
offset,
|
|
|
|
w->widget->align);
|
2007-12-22 15:38:14 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
w->area.y = 0;
|
2008-01-04 22:05:52 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
draw_image(statusbar->ctx, w->area.x, w->area.y,
|
|
|
|
d->resize ? statusbar->height : 0, d->image);
|
2007-12-22 15:38:14 +01:00
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
return w->area.width;
|
2007-12-22 15:38:14 +01:00
|
|
|
}
|
|
|
|
|
2008-03-04 19:06:04 +01:00
|
|
|
static widget_tell_status_t
|
2008-05-20 15:39:47 +02:00
|
|
|
iconbox_tell(widget_t *widget, const char *property, const char *new_value)
|
2007-12-22 15:38:14 +01:00
|
|
|
{
|
2008-01-02 14:59:15 +01:00
|
|
|
Data *d = widget->data;
|
|
|
|
|
2008-05-20 15:39:47 +02:00
|
|
|
if(!new_value)
|
2008-04-23 05:35:55 +02:00
|
|
|
return WIDGET_ERROR_NOVALUE;
|
2008-02-17 08:16:40 +01:00
|
|
|
|
2008-02-17 08:36:58 +01:00
|
|
|
if(!a_strcmp(property, "image"))
|
|
|
|
{
|
2008-05-02 10:31:51 +02:00
|
|
|
p_delete(&d->image);
|
2008-04-23 23:44:55 +02:00
|
|
|
d->image = a_strdup(new_value);
|
2008-02-17 08:36:58 +01:00
|
|
|
}
|
2008-03-04 19:06:04 +01:00
|
|
|
else if(!a_strcmp(property, "resize"))
|
2008-05-11 16:20:58 +02:00
|
|
|
d->resize = a_strtobool(new_value);
|
2008-02-17 08:36:58 +01:00
|
|
|
else
|
2008-03-04 19:06:04 +01:00
|
|
|
return WIDGET_ERROR;
|
|
|
|
|
|
|
|
return WIDGET_NOERROR;
|
2007-12-22 15:38:14 +01:00
|
|
|
}
|
|
|
|
|
2008-04-11 11:26:37 +02:00
|
|
|
widget_t *
|
2008-05-20 15:39:47 +02:00
|
|
|
iconbox_new(alignment_t align)
|
2007-12-22 15:38:14 +01:00
|
|
|
{
|
2008-04-11 11:26:37 +02:00
|
|
|
widget_t *w;
|
2008-01-02 14:59:15 +01:00
|
|
|
Data *d;
|
2007-12-22 15:38:14 +01:00
|
|
|
|
2008-04-11 11:26:37 +02:00
|
|
|
w = p_new(widget_t, 1);
|
2008-05-20 15:39:47 +02:00
|
|
|
widget_common_new(w);
|
|
|
|
w->align = align;
|
2007-12-22 15:38:14 +01:00
|
|
|
w->draw = iconbox_draw;
|
|
|
|
w->tell = iconbox_tell;
|
2008-01-02 14:59:15 +01:00
|
|
|
w->data = d = p_new(Data, 1);
|
2008-05-20 15:39:47 +02:00
|
|
|
d->resize = true;
|
2008-02-13 06:53:08 +01:00
|
|
|
|
2007-12-22 15:38:14 +01:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|