2007-12-22 15:41:28 +01:00
|
|
|
/*
|
|
|
|
* textbox.c - text box widget
|
|
|
|
*
|
2009-08-25 20:24:38 +02:00
|
|
|
* Copyright © 2007-2009 Julien Danjou <julien@danjou.info>
|
2007-12-22 15:41:28 +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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2009-09-14 20:26:33 +02:00
|
|
|
#include "objects/widget.h"
|
2009-08-17 16:38:56 +02:00
|
|
|
#include "luaa.h"
|
2007-12-15 07:53:53 +01:00
|
|
|
|
2009-08-25 20:24:38 +02:00
|
|
|
/** Padding type */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/** Padding at top */
|
|
|
|
int top;
|
|
|
|
/** Padding at bottom */
|
|
|
|
int bottom;
|
|
|
|
/** Padding at left */
|
|
|
|
int left;
|
|
|
|
/** Padding at right */
|
|
|
|
int right;
|
|
|
|
} padding_t;
|
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/** The textbox private data structure */
|
2007-12-22 15:41:28 +01:00
|
|
|
typedef struct
|
2007-12-17 10:57:17 +01:00
|
|
|
{
|
2010-07-16 18:54:57 +02:00
|
|
|
/** The actual text the textbox is set to */
|
|
|
|
char *text;
|
|
|
|
/** The length of text */
|
|
|
|
size_t text_len;
|
2008-12-03 15:23:10 +01:00
|
|
|
draw_text_context_t data;
|
2009-08-27 15:40:49 +02:00
|
|
|
/** Textbox width and height */
|
|
|
|
int width, height;
|
2008-08-14 00:06:38 +02:00
|
|
|
/** Extents */
|
2008-12-02 11:50:39 +01:00
|
|
|
area_t extents;
|
2008-11-06 17:04:23 +01:00
|
|
|
PangoEllipsizeMode ellip;
|
|
|
|
PangoWrapMode wrap;
|
2008-12-02 16:31:35 +01:00
|
|
|
/** Border */
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
int width;
|
2009-04-17 19:08:04 +02:00
|
|
|
color_t color;
|
2008-12-02 16:31:35 +01:00
|
|
|
} border;
|
2008-12-02 17:29:19 +01:00
|
|
|
/** Text alignment */
|
2009-08-25 17:35:57 +02:00
|
|
|
alignment_t align, valign;
|
2008-12-02 18:14:51 +01:00
|
|
|
/** Margin */
|
|
|
|
padding_t margin;
|
2008-12-03 11:36:52 +01:00
|
|
|
/** Background color */
|
2009-04-17 19:08:04 +02:00
|
|
|
color_t bg;
|
2008-12-03 15:23:10 +01:00
|
|
|
/** Background image */
|
2010-08-20 13:26:45 +02:00
|
|
|
cairo_surface_t *bg_image;
|
2008-12-03 15:23:10 +01:00
|
|
|
/** Background resize to wibox height. */
|
|
|
|
bool bg_resize;
|
|
|
|
/** Background alignment */
|
|
|
|
alignment_t bg_align;
|
2008-06-14 09:18:51 +02:00
|
|
|
} textbox_data_t;
|
2007-12-17 10:57:17 +01:00
|
|
|
|
2009-08-25 20:24:38 +02:00
|
|
|
/** Get an optional padding table from a Lua table.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param idx The table index on the stack.
|
|
|
|
* \param dpadding The default padding value to use.
|
|
|
|
*/
|
|
|
|
static inline padding_t
|
|
|
|
luaA_getopt_padding(lua_State *L, int idx, padding_t *dpadding)
|
|
|
|
{
|
|
|
|
padding_t padding;
|
|
|
|
|
|
|
|
luaA_checktable(L, idx);
|
|
|
|
|
|
|
|
padding.right = luaA_getopt_number(L, idx, "right", dpadding->right);
|
|
|
|
padding.left = luaA_getopt_number(L, idx, "left", dpadding->left);
|
|
|
|
padding.top = luaA_getopt_number(L, idx, "top", dpadding->top);
|
|
|
|
padding.bottom = luaA_getopt_number(L, idx, "bottom", dpadding->bottom);
|
|
|
|
|
|
|
|
return padding;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** Push a padding structure into a table on the Lua stack.
|
|
|
|
* \param L The Lua VM state.
|
|
|
|
* \param padding The padding struct pointer.
|
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
luaA_pushpadding(lua_State *L, padding_t *padding)
|
|
|
|
{
|
|
|
|
lua_createtable(L, 0, 4);
|
|
|
|
lua_pushnumber(L, padding->right);
|
|
|
|
lua_setfield(L, -2, "right");
|
|
|
|
lua_pushnumber(L, padding->left);
|
|
|
|
lua_setfield(L, -2, "left");
|
|
|
|
lua_pushnumber(L, padding->top);
|
|
|
|
lua_setfield(L, -2, "top");
|
|
|
|
lua_pushnumber(L, padding->bottom);
|
|
|
|
lua_setfield(L, -2, "bottom");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-10-22 17:32:17 +02:00
|
|
|
static area_t
|
2009-08-25 18:28:20 +02:00
|
|
|
textbox_extents(lua_State *L, widget_t *widget)
|
2007-12-15 07:53:53 +01:00
|
|
|
{
|
2008-10-22 17:32:17 +02:00
|
|
|
textbox_data_t *d = widget->data;
|
2009-02-10 17:30:57 +01:00
|
|
|
area_t geometry = d->extents;
|
|
|
|
geometry.width += d->margin.left + d->margin.left;
|
|
|
|
geometry.height += d->margin.bottom + d->margin.top;
|
2007-12-22 15:41:28 +01:00
|
|
|
|
2009-08-27 15:39:34 +02:00
|
|
|
if(d->width)
|
|
|
|
geometry.width = d->width;
|
|
|
|
|
2009-08-27 15:40:49 +02:00
|
|
|
if(d->height)
|
|
|
|
geometry.width = d->height;
|
|
|
|
|
2009-02-10 17:30:57 +01:00
|
|
|
if(d->bg_image)
|
2008-06-23 13:09:42 +02:00
|
|
|
{
|
2010-08-20 13:26:45 +02:00
|
|
|
int bgi_height = cairo_image_surface_get_height(d->bg_image);
|
|
|
|
int bgi_width = cairo_image_surface_get_width(d->bg_image);
|
2009-05-04 10:34:54 +02:00
|
|
|
double ratio = d->bg_resize ? (double) geometry.height / bgi_height : 1;
|
2009-02-10 17:30:57 +01:00
|
|
|
geometry.width = MAX(d->extents.width + d->margin.left + d->margin.right, MAX(d->width, bgi_width * ratio));
|
2008-06-23 13:09:42 +02:00
|
|
|
}
|
2007-12-30 14:49:03 +01:00
|
|
|
|
2009-05-24 12:17:15 +02:00
|
|
|
geometry.x = geometry.y = 0;
|
|
|
|
|
2008-10-22 17:32:17 +02:00
|
|
|
return geometry;
|
|
|
|
}
|
2007-12-27 11:22:57 +01:00
|
|
|
|
2008-10-22 17:32:17 +02:00
|
|
|
/** Draw a textbox widget.
|
|
|
|
* \param widget The widget.
|
|
|
|
* \param ctx The draw context.
|
|
|
|
* \param p A pointer to the object we're draw onto.
|
|
|
|
*/
|
|
|
|
static void
|
2009-04-17 16:14:09 +02:00
|
|
|
textbox_draw(widget_t *widget, draw_context_t *ctx, area_t geometry, wibox_t *p)
|
2008-10-22 17:32:17 +02:00
|
|
|
{
|
|
|
|
textbox_data_t *d = widget->data;
|
2009-04-17 18:40:43 +02:00
|
|
|
|
2009-04-17 19:08:04 +02:00
|
|
|
if(d->bg.initialized)
|
|
|
|
draw_rectangle(ctx, geometry, 1.0, true, &d->bg);
|
2008-12-03 11:36:52 +01:00
|
|
|
|
2008-12-02 16:31:35 +01:00
|
|
|
if(d->border.width > 0)
|
2009-04-17 19:08:04 +02:00
|
|
|
draw_rectangle(ctx, geometry, d->border.width, false, &d->border.color);
|
2008-12-02 16:31:35 +01:00
|
|
|
|
2008-12-03 15:23:10 +01:00
|
|
|
if(d->bg_image)
|
|
|
|
{
|
2010-08-20 13:26:45 +02:00
|
|
|
int bgi_height = cairo_image_surface_get_height(d->bg_image);
|
|
|
|
int bgi_width = cairo_image_surface_get_width(d->bg_image);
|
2009-05-04 10:34:54 +02:00
|
|
|
double ratio = d->bg_resize ? (double) geometry.height / bgi_height : 1;
|
2008-12-03 15:23:10 +01:00
|
|
|
/* check there is enough space to draw the image */
|
2009-05-04 10:34:54 +02:00
|
|
|
if(ratio * bgi_width <= geometry.width)
|
2008-12-03 15:23:10 +01:00
|
|
|
{
|
|
|
|
int x = geometry.x;
|
|
|
|
int y = geometry.y;
|
|
|
|
switch(d->bg_align)
|
|
|
|
{
|
|
|
|
case AlignCenter:
|
2009-05-04 10:34:54 +02:00
|
|
|
x += (geometry.width - bgi_width * ratio) / 2;
|
2008-12-03 15:23:10 +01:00
|
|
|
break;
|
|
|
|
case AlignRight:
|
2009-05-04 10:34:54 +02:00
|
|
|
x += geometry.width - bgi_width * ratio;
|
2008-12-03 15:23:10 +01:00
|
|
|
break;
|
2009-03-06 13:44:07 +01:00
|
|
|
case AlignBottom:
|
2009-05-04 10:34:54 +02:00
|
|
|
y += geometry.height - bgi_height * ratio;
|
2009-03-06 13:44:07 +01:00
|
|
|
break;
|
|
|
|
case AlignMiddle:
|
2009-05-04 10:34:54 +02:00
|
|
|
y += (geometry.height - bgi_height * ratio) / 2;
|
2009-03-06 13:44:07 +01:00
|
|
|
break;
|
2008-12-03 15:23:10 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-08-20 13:26:45 +02:00
|
|
|
draw_surface(ctx, x, y, ratio, d->bg_image);
|
2008-12-03 15:23:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-25 20:24:38 +02:00
|
|
|
geometry.x += d->margin.left;
|
|
|
|
geometry.y += d->margin.top;
|
2009-08-27 15:34:05 +02:00
|
|
|
|
|
|
|
int margin_width = d->margin.left + d->margin.right;
|
|
|
|
if(margin_width <= geometry.width)
|
|
|
|
geometry.width -= d->margin.left + d->margin.right;
|
|
|
|
else
|
|
|
|
geometry.width = 0;
|
|
|
|
|
|
|
|
int margin_height = d->margin.top + d->margin.bottom;
|
|
|
|
if(margin_height <= geometry.height)
|
|
|
|
geometry.height -= d->margin.top + d->margin.bottom;
|
|
|
|
else
|
|
|
|
geometry.height = 0;
|
2009-08-25 20:24:38 +02:00
|
|
|
|
2009-08-27 15:38:17 +02:00
|
|
|
draw_text(ctx, &d->data, d->ellip, d->wrap, d->align, d->valign, geometry);
|
2007-12-15 07:53:53 +01:00
|
|
|
}
|
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/** Delete a textbox widget.
|
|
|
|
* \param w The widget to destroy.
|
|
|
|
*/
|
2008-06-14 22:55:17 +02:00
|
|
|
static void
|
|
|
|
textbox_destructor(widget_t *w)
|
|
|
|
{
|
|
|
|
textbox_data_t *d = w->data;
|
2008-12-03 15:23:10 +01:00
|
|
|
draw_text_context_wipe(&d->data);
|
2010-08-20 13:26:45 +02:00
|
|
|
if(d->bg_image)
|
|
|
|
cairo_surface_destroy(d->bg_image);
|
2010-07-16 18:54:57 +02:00
|
|
|
p_delete(&d->text);
|
2008-06-14 22:55:17 +02:00
|
|
|
p_delete(&d);
|
|
|
|
}
|
|
|
|
|
2008-12-02 18:14:51 +01:00
|
|
|
static int
|
|
|
|
luaA_textbox_margin(lua_State *L)
|
|
|
|
{
|
2009-08-17 15:52:41 +02:00
|
|
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
2009-04-09 15:12:17 +02:00
|
|
|
textbox_data_t *d = widget->data;
|
2008-12-02 18:14:51 +01:00
|
|
|
|
|
|
|
if(lua_gettop(L) == 2)
|
|
|
|
{
|
2009-07-30 17:38:50 +02:00
|
|
|
d->margin = luaA_getopt_padding(L, 2, &d->margin);
|
2009-04-09 15:12:17 +02:00
|
|
|
widget_invalidate_bywidget(widget);
|
2008-12-02 18:14:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return luaA_pushpadding(L, &d->margin);
|
|
|
|
}
|
|
|
|
|
2008-07-28 16:03:38 +02:00
|
|
|
/** Textbox widget.
|
2008-06-25 17:47:51 +02:00
|
|
|
* \param L The Lua VM state.
|
2010-09-01 16:11:48 +02:00
|
|
|
* \param prop The property's name.
|
2008-06-25 17:47:51 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
2008-07-02 17:59:06 +02:00
|
|
|
* \luastack
|
|
|
|
* \lfield text The text to display.
|
|
|
|
* \lfield width The width of the textbox. Set to 0 for auto.
|
2008-11-07 16:01:20 +01:00
|
|
|
* \lfield wrap The wrap mode: word, char, word_char.
|
|
|
|
* \lfield ellipsize The ellipsize mode: start, middle or end.
|
2008-12-02 16:31:35 +01:00
|
|
|
* \lfield border_width The border width to draw around.
|
|
|
|
* \lfield border_color The border color.
|
2008-12-02 17:29:19 +01:00
|
|
|
* \lfield align Text alignment, left, center or right.
|
2008-12-02 18:14:51 +01:00
|
|
|
* \lfield margin Method to pass text margin: a table with top, left, right and bottom keys.
|
2008-12-03 11:36:52 +01:00
|
|
|
* \lfield bg Background color.
|
2008-12-03 15:23:10 +01:00
|
|
|
* \lfield bg_image Background image.
|
2009-03-06 13:44:07 +01:00
|
|
|
* \lfield bg_align Background image alignment, left, center, right, bottom, top or middle
|
2008-12-03 15:23:10 +01:00
|
|
|
* \lfield bg_resize Background resize.
|
2008-06-25 17:47:51 +02:00
|
|
|
*/
|
|
|
|
static int
|
2010-09-01 16:11:48 +02:00
|
|
|
luaA_textbox_index(lua_State *L, const char *prop)
|
2008-06-25 17:47:51 +02:00
|
|
|
{
|
2009-08-17 15:52:41 +02:00
|
|
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
2009-04-09 15:12:17 +02:00
|
|
|
textbox_data_t *d = widget->data;
|
2008-06-25 17:47:51 +02:00
|
|
|
|
2010-09-01 16:11:48 +02:00
|
|
|
if(a_strcmp(prop, "bg_resize") == 0)
|
2008-12-03 15:23:10 +01:00
|
|
|
lua_pushboolean(L, d->bg_resize);
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "bg_align") == 0)
|
2008-12-03 15:23:10 +01:00
|
|
|
lua_pushstring(L, draw_align_tostr(d->bg_align));
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "bg_image") == 0)
|
2010-08-20 13:26:45 +02:00
|
|
|
return oocairo_surface_push(L, d->bg_image);
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "bg") == 0)
|
2009-04-17 19:08:04 +02:00
|
|
|
return luaA_pushcolor(L, &d->bg);
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "margin") == 0)
|
2008-12-02 18:14:51 +01:00
|
|
|
lua_pushcfunction(L, luaA_textbox_margin);
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "align") == 0)
|
2008-12-02 17:29:19 +01:00
|
|
|
lua_pushstring(L, draw_align_tostr(d->align));
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "valign") == 0)
|
2009-08-25 17:35:57 +02:00
|
|
|
lua_pushstring(L, draw_align_tostr(d->valign));
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "border_width") == 0)
|
2008-12-02 16:31:35 +01:00
|
|
|
lua_pushnumber(L, d->border.width);
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "border_color") == 0)
|
2009-04-17 19:08:04 +02:00
|
|
|
luaA_pushcolor(L, &d->border.color);
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "text") == 0)
|
|
|
|
{
|
2010-07-16 18:54:57 +02:00
|
|
|
if(d->text_len > 0)
|
2008-12-03 15:23:10 +01:00
|
|
|
{
|
2010-07-16 18:54:57 +02:00
|
|
|
lua_pushlstring(L, d->text, d->text_len);
|
2008-12-03 15:23:10 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2010-09-01 16:11:48 +02:00
|
|
|
}
|
|
|
|
else if(a_strcmp(prop, "width") == 0)
|
2008-06-27 20:24:30 +02:00
|
|
|
lua_pushnumber(L, d->width);
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "height") == 0)
|
2009-08-27 15:40:49 +02:00
|
|
|
lua_pushnumber(L, d->height);
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "wrap") == 0)
|
2008-11-06 17:04:23 +01:00
|
|
|
switch(d->wrap)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
lua_pushliteral(L, "word");
|
|
|
|
break;
|
2010-07-30 14:17:27 +02:00
|
|
|
case PANGO_WRAP_CHAR:
|
2008-11-06 17:04:23 +01:00
|
|
|
lua_pushliteral(L, "char");
|
|
|
|
break;
|
2010-07-30 14:17:27 +02:00
|
|
|
case PANGO_WRAP_WORD_CHAR:
|
2008-11-06 17:04:23 +01:00
|
|
|
lua_pushliteral(L, "word_char");
|
|
|
|
break;
|
|
|
|
}
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "ellipsize") == 0)
|
2008-11-06 17:04:23 +01:00
|
|
|
switch(d->ellip)
|
|
|
|
{
|
2010-07-30 14:17:27 +02:00
|
|
|
case PANGO_ELLIPSIZE_START:
|
2008-11-06 17:04:23 +01:00
|
|
|
lua_pushliteral(L, "start");
|
|
|
|
break;
|
2010-07-30 14:17:27 +02:00
|
|
|
case PANGO_ELLIPSIZE_MIDDLE:
|
2008-11-06 17:04:23 +01:00
|
|
|
lua_pushliteral(L, "middle");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lua_pushliteral(L, "end");
|
|
|
|
break;
|
|
|
|
}
|
2010-09-01 16:11:48 +02:00
|
|
|
else
|
2008-06-25 17:47:51 +02:00
|
|
|
return 0;
|
2010-09-01 16:11:48 +02:00
|
|
|
|
|
|
|
return 1;
|
2008-06-25 17:47:51 +02:00
|
|
|
}
|
|
|
|
|
2008-06-27 12:49:24 +02:00
|
|
|
/** The __newindex method for a textbox object.
|
|
|
|
* \param L The Lua VM state.
|
2008-07-01 15:27:41 +02:00
|
|
|
* \param token The key token.
|
2008-06-27 12:49:24 +02:00
|
|
|
* \return The number of elements pushed on stack.
|
|
|
|
*/
|
|
|
|
static int
|
2010-09-01 16:11:48 +02:00
|
|
|
luaA_textbox_newindex(lua_State *L, const char *prop)
|
2008-06-27 12:49:24 +02:00
|
|
|
{
|
2008-08-12 18:13:23 +02:00
|
|
|
size_t len = 0;
|
2009-08-17 15:52:41 +02:00
|
|
|
widget_t *widget = luaA_checkudata(L, 1, &widget_class);
|
2008-08-12 18:13:23 +02:00
|
|
|
const char *buf = NULL;
|
2009-04-09 15:12:17 +02:00
|
|
|
textbox_data_t *d = widget->data;
|
2008-06-27 12:49:24 +02:00
|
|
|
|
2010-09-01 16:11:48 +02:00
|
|
|
if(a_strcmp(prop, "bg_align") == 0)
|
2008-06-27 12:49:24 +02:00
|
|
|
{
|
2010-09-02 19:04:48 +02:00
|
|
|
buf = luaL_checkstring(L, 3);
|
|
|
|
d->bg_align = draw_align_fromstr(buf);
|
2010-09-01 16:11:48 +02:00
|
|
|
}
|
|
|
|
else if(a_strcmp(prop, "bg_resize") == 0)
|
2008-12-03 15:23:10 +01:00
|
|
|
d->bg_resize = luaA_checkboolean(L, 3);
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "bg_image") == 0)
|
|
|
|
{
|
2010-08-20 13:26:45 +02:00
|
|
|
if(lua_isnil(L, -1))
|
|
|
|
{
|
|
|
|
cairo_surface_destroy(d->bg_image);
|
|
|
|
d->bg_image = NULL;
|
|
|
|
} else {
|
2010-09-29 19:35:59 +02:00
|
|
|
cairo_surface_t **cairo_surface = (cairo_surface_t **)luaL_checkudata(L, -1, OOCAIRO_MT_NAME_SURFACE);
|
2010-08-20 13:26:45 +02:00
|
|
|
cairo_surface_destroy(d->bg_image);
|
2010-09-29 19:35:59 +02:00
|
|
|
d->bg_image = draw_dup_image_surface(*cairo_surface);
|
2010-08-20 13:26:45 +02:00
|
|
|
}
|
2010-09-01 16:11:48 +02:00
|
|
|
}
|
|
|
|
else if(a_strcmp(prop, "bg") == 0)
|
|
|
|
{
|
2008-12-03 11:36:52 +01:00
|
|
|
if(lua_isnil(L, 3))
|
|
|
|
p_clear(&d->bg, 1);
|
|
|
|
else if((buf = luaL_checklstring(L, 3, &len)))
|
2010-09-10 11:27:40 +02:00
|
|
|
color_init_unchecked(&d->bg, buf, len);
|
2010-09-01 16:11:48 +02:00
|
|
|
}
|
|
|
|
else if(a_strcmp(prop, "align") == 0)
|
|
|
|
{
|
2010-09-02 19:04:48 +02:00
|
|
|
if((buf = luaL_checkstring(L, 3)))
|
|
|
|
d->align = draw_align_fromstr(buf);
|
2010-09-01 16:11:48 +02:00
|
|
|
}
|
|
|
|
else if(a_strcmp(prop, "valign") == 0)
|
|
|
|
{
|
2010-09-02 19:04:48 +02:00
|
|
|
if((buf = luaL_checkstring(L, 3)))
|
|
|
|
d->valign = draw_align_fromstr(buf);
|
2010-09-01 16:11:48 +02:00
|
|
|
}
|
|
|
|
else if(a_strcmp(prop, "border_color") == 0)
|
|
|
|
{
|
2008-12-02 16:31:35 +01:00
|
|
|
if((buf = luaL_checklstring(L, 3, &len)))
|
2010-09-10 11:27:40 +02:00
|
|
|
color_init_unchecked(&d->border.color, buf, len);
|
2010-09-01 16:11:48 +02:00
|
|
|
}
|
|
|
|
else if(a_strcmp(prop, "border_width") == 0)
|
2008-12-02 16:31:35 +01:00
|
|
|
d->border.width = luaL_checknumber(L, 3);
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "text") == 0)
|
|
|
|
{
|
2008-08-12 18:13:23 +02:00
|
|
|
if(lua_isnil(L, 3)
|
|
|
|
|| (buf = luaL_checklstring(L, 3, &len)))
|
2008-06-27 12:49:24 +02:00
|
|
|
{
|
2008-08-14 00:06:38 +02:00
|
|
|
/* delete */
|
2008-12-03 15:23:10 +01:00
|
|
|
draw_text_context_wipe(&d->data);
|
2010-07-16 18:54:57 +02:00
|
|
|
p_delete(&d->text);
|
|
|
|
d->text_len = 0;
|
2008-12-03 15:23:10 +01:00
|
|
|
p_clear(&d->data, 1);
|
2008-08-14 00:06:38 +02:00
|
|
|
|
2008-08-12 18:13:23 +02:00
|
|
|
if(buf)
|
2008-08-14 00:06:38 +02:00
|
|
|
{
|
2008-12-03 15:23:10 +01:00
|
|
|
char *text;
|
|
|
|
ssize_t tlen;
|
2010-07-16 18:54:57 +02:00
|
|
|
bool success;
|
|
|
|
|
2008-12-03 15:23:10 +01:00
|
|
|
/* if text has been converted to UTF-8 */
|
|
|
|
if(draw_iso2utf8(buf, len, &text, &tlen))
|
|
|
|
{
|
2010-07-16 18:54:57 +02:00
|
|
|
success = draw_text_context_init(&d->data, text, tlen);
|
|
|
|
if(success)
|
|
|
|
{
|
|
|
|
d->text = p_dup(text, tlen);
|
|
|
|
d->text_len = tlen;
|
|
|
|
}
|
2008-12-03 15:23:10 +01:00
|
|
|
p_delete(&text);
|
|
|
|
}
|
|
|
|
else
|
2010-07-16 18:54:57 +02:00
|
|
|
{
|
|
|
|
success = draw_text_context_init(&d->data, buf, len);
|
|
|
|
if(success)
|
|
|
|
{
|
|
|
|
d->text = p_dup(buf, len);
|
|
|
|
d->text_len = len;
|
|
|
|
}
|
|
|
|
}
|
2008-12-03 15:23:10 +01:00
|
|
|
|
2008-12-03 15:25:44 +01:00
|
|
|
d->extents = draw_text_extents(&d->data);
|
2010-07-16 19:16:04 +02:00
|
|
|
|
|
|
|
if(!success)
|
|
|
|
luaL_error(L, "Invalid markup in '%s'", buf);
|
2008-08-14 00:06:38 +02:00
|
|
|
}
|
2008-08-15 01:11:39 +02:00
|
|
|
else
|
2008-12-02 11:50:39 +01:00
|
|
|
p_clear(&d->extents, 1);
|
2008-06-27 12:49:24 +02:00
|
|
|
}
|
2010-09-01 16:11:48 +02:00
|
|
|
}
|
|
|
|
else if(a_strcmp(prop, "width") == 0)
|
2008-06-27 20:24:30 +02:00
|
|
|
d->width = luaL_checknumber(L, 3);
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "height") == 0)
|
2009-08-27 15:40:49 +02:00
|
|
|
d->height = luaL_checknumber(L, 3);
|
2010-09-01 16:11:48 +02:00
|
|
|
else if(a_strcmp(prop, "wrap") == 0)
|
|
|
|
{
|
2010-09-01 15:52:39 +02:00
|
|
|
if((buf = luaL_checkstring(L, 3)))
|
|
|
|
{
|
|
|
|
if(a_strcmp(buf, "word") == 0)
|
2008-11-06 17:04:23 +01:00
|
|
|
d->wrap = PANGO_WRAP_WORD;
|
2010-09-01 15:52:39 +02:00
|
|
|
else if(a_strcmp(buf, "char") == 0)
|
2008-11-06 17:04:23 +01:00
|
|
|
d->wrap = PANGO_WRAP_CHAR;
|
2010-09-01 15:52:39 +02:00
|
|
|
else if(a_strcmp(buf, "word_char") == 0)
|
2008-11-06 17:04:23 +01:00
|
|
|
d->wrap = PANGO_WRAP_WORD_CHAR;
|
2010-09-01 15:52:39 +02:00
|
|
|
}
|
2010-09-01 16:11:48 +02:00
|
|
|
}
|
|
|
|
else if(a_strcmp(prop, "ellipsize") == 0)
|
|
|
|
{
|
2010-09-01 15:52:39 +02:00
|
|
|
if((buf = luaL_checkstring(L, 3)))
|
|
|
|
{
|
|
|
|
if(a_strcmp(buf, "start") == 0)
|
2008-11-06 17:04:23 +01:00
|
|
|
d->ellip = PANGO_ELLIPSIZE_START;
|
2010-09-01 15:52:39 +02:00
|
|
|
else if(a_strcmp(buf, "middle") == 0)
|
2008-11-06 17:04:23 +01:00
|
|
|
d->ellip = PANGO_ELLIPSIZE_MIDDLE;
|
2010-09-01 15:52:39 +02:00
|
|
|
else if(a_strcmp(buf, "end") == 0)
|
2008-11-06 17:04:23 +01:00
|
|
|
d->ellip = PANGO_ELLIPSIZE_END;
|
2010-09-01 15:52:39 +02:00
|
|
|
}
|
2008-06-27 12:49:24 +02:00
|
|
|
}
|
2010-09-01 16:11:48 +02:00
|
|
|
else
|
|
|
|
return 0;
|
2008-06-27 12:49:24 +02:00
|
|
|
|
2009-04-09 15:12:17 +02:00
|
|
|
widget_invalidate_bywidget(widget);
|
2008-06-27 20:24:30 +02:00
|
|
|
|
2008-06-27 12:49:24 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-06-25 17:47:51 +02:00
|
|
|
/** Create a new textbox widget.
|
2008-11-12 14:55:30 +01:00
|
|
|
* \param w The widget to initialize.
|
2008-06-25 17:47:51 +02:00
|
|
|
* \return A brand new widget.
|
|
|
|
*/
|
2008-04-11 11:26:37 +02:00
|
|
|
widget_t *
|
2008-11-12 14:55:30 +01:00
|
|
|
widget_textbox(widget_t *w)
|
2007-12-15 07:53:53 +01:00
|
|
|
{
|
2007-12-15 16:25:54 +01:00
|
|
|
w->draw = textbox_draw;
|
2008-06-25 17:47:51 +02:00
|
|
|
w->index = luaA_textbox_index;
|
2008-06-27 12:49:24 +02:00
|
|
|
w->newindex = luaA_textbox_newindex;
|
2008-06-14 22:55:17 +02:00
|
|
|
w->destructor = textbox_destructor;
|
2009-05-05 19:55:29 +02:00
|
|
|
w->extents = textbox_extents;
|
2008-11-12 14:55:30 +01:00
|
|
|
|
|
|
|
textbox_data_t *d = w->data = p_new(textbox_data_t, 1);
|
2008-11-06 17:04:23 +01:00
|
|
|
d->ellip = PANGO_ELLIPSIZE_END;
|
2009-08-25 17:35:57 +02:00
|
|
|
d->valign = AlignCenter;
|
2007-12-17 10:57:17 +01:00
|
|
|
|
2007-12-15 07:53:53 +01:00
|
|
|
return w;
|
|
|
|
}
|
2008-06-26 23:32:33 +02:00
|
|
|
|
2007-12-18 09:24:15 +01:00
|
|
|
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|