2 * textbox.c - text box widget
4 * Copyright © 2007 Aldo Cortesi <aldo@nullcube.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include "common/util.h"
25 #include "common/configopts.h"
27 extern AwesomeConf globalconf
;
38 textbox_draw(Widget
*widget
, DrawCtx
*ctx
, int offset
, int used
)
40 Data
*d
= widget
->data
;
43 widget
->area
.width
= d
->width
;
44 else if(widget
->alignment
== AlignFlex
)
45 widget
->area
.width
= widget
->statusbar
->width
- used
;
47 widget
->area
.width
= MIN(draw_textwidth(ctx
->display
, d
->style
.font
, d
->text
),
48 widget
->statusbar
->width
- used
);
50 widget
->area
.height
= widget
->statusbar
->height
;
52 if(!widget
->user_supplied_x
)
53 widget
->area
.x
= widget_calculate_offset(widget
->statusbar
->width
,
57 if(!widget
->user_supplied_y
)
60 draw_text(ctx
, widget
->area
, d
->align
, 0, d
->text
, d
->style
);
62 return widget
->area
.width
;
65 static widget_tell_status_t
66 textbox_tell(Widget
*widget
, char *property
, char *command
)
68 Data
*d
= widget
->data
;
71 if(!a_strcmp(property
, "text"))
75 d
->text
= a_strdup(command
);
77 /* !command means a not existing string. So return here */
79 return WIDGET_ERROR_NOVALUE
;
80 else if(!a_strcmp(property
, "fg"))
81 if(draw_color_new(globalconf
.display
, widget
->statusbar
->screen
, command
, &d
->style
.fg
))
82 return WIDGET_NOERROR
;
84 return WIDGET_ERROR_FORMAT_COLOR
;
85 else if(!a_strcmp(property
, "bg"))
86 if(draw_color_new(globalconf
.display
, widget
->statusbar
->screen
, command
, &d
->style
.bg
))
87 return WIDGET_NOERROR
;
89 return WIDGET_ERROR_FORMAT_COLOR
;
90 else if(!a_strcmp(property
, "font"))
92 if((newfont
= draw_font_new(globalconf
.display
, command
)))
94 if(d
->style
.font
!= globalconf
.screens
[widget
->statusbar
->screen
].styles
.normal
.font
)
95 draw_font_delete(&d
->style
.font
);
96 d
->style
.font
= newfont
;
99 return WIDGET_ERROR_FORMAT_FONT
;
101 else if(!a_strcmp(property
, "width"))
102 d
->width
= atoi(command
);
103 else if(!a_strcmp(property
, "text_align"))
104 d
->align
= draw_align_get_from_str(command
);
108 return WIDGET_NOERROR
;
112 textbox_new(Statusbar
*statusbar
, cfg_t
*config
)
117 w
= p_new(Widget
, 1);
118 widget_common_new(w
, statusbar
, config
);
119 w
->draw
= textbox_draw
;
120 w
->tell
= textbox_tell
;
121 w
->alignment
= cfg_getalignment(config
, "align");
123 w
->data
= d
= p_new(Data
, 1);
125 draw_style_init(globalconf
.display
, statusbar
->phys_screen
,
126 cfg_getsec(config
, "style"),
128 &globalconf
.screens
[statusbar
->screen
].styles
.normal
);
130 d
->width
= cfg_getint(config
, "width");
131 d
->align
= cfg_getalignment(config
, "text_align");
133 d
->text
= a_strdup(cfg_getstr(config
, "text"));
137 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80