61 PangoFontDescription *
pfd;
74 if ( tb->
blink < 2 ) {
120 pango_layout_xy_to_index ( tb->
layout, x * PANGO_SCALE, y * PANGO_SCALE, &i, NULL );
140 if ( tbfc == NULL ) {
142 tbfc->
pfd = pango_font_description_from_string ( font );
145 tbfc->
height = pango_font_metrics_get_ascent ( tbfc->
metrics ) + pango_font_metrics_get_descent ( tbfc->
metrics );
148 g_hash_table_insert (
tbfc_cache, (
char *) font, tbfc );
151 pango_font_description_free ( tbfc->
pfd );
158 pango_layout_set_font_description ( tb->
layout, tbfc->
pfd );
192 pango_layout_set_wrap ( tb->
layout, PANGO_WRAP_WORD_CHAR );
222 {
"normal.normal",
"selected.normal",
"alternate.normal" },
224 {
"normal.urgent",
"selected.urgent",
"alternate.urgent" },
226 {
"normal.active",
"selected.active",
"alternate.active" },
265 pango_layout_set_attributes ( tb->
layout, NULL );
267 size_t l = g_utf8_strlen ( tb->
text, -1 );
269 memset (
string,
'*', l );
271 pango_layout_set_text ( tb->
layout,
string, l );
274 pango_layout_set_markup ( tb->
layout, tb->
text, -1 );
277 pango_layout_set_text ( tb->
layout, tb->
text, -1 );
285 return pango_layout_get_text ( tb->
layout );
292 return pango_layout_get_attributes ( tb->
layout );
299 pango_layout_set_attributes ( tb->
layout, list );
309 const gchar *last_pointer = NULL;
311 if ( g_utf8_validate ( text, -1, &last_pointer ) ) {
312 tb->
text = g_strdup ( text );
315 if ( last_pointer != NULL ) {
317 tb->
text = g_strndup ( text, ( last_pointer - text ) );
320 tb->
text = g_strdup (
"Invalid UTF-8 string." );
326 if (
WIDGET ( tb )->parent ) {
331 tb->
cursor = MAX ( 0, MIN ( (
int ) g_utf8_strlen ( tb->
text, -1 ), tb->
cursor ) );
347 pango_layout_set_width ( tb->
layout, -1 );
353 pango_layout_set_ellipsize ( tb->
layout, PANGO_ELLIPSIZE_MIDDLE );
356 pango_layout_set_ellipsize ( tb->
layout, PANGO_ELLIPSIZE_END );
362 int tw = MAX ( 1, w );
393 if ( tb->
layout != NULL ) {
394 g_object_unref ( tb->
layout );
415 int y = ( pango_font_metrics_get_ascent ( tb->
metrics ) - pango_layout_get_baseline ( tb->
layout ) ) / PANGO_SCALE;
416 int line_width = 0, line_height = 0;
418 pango_layout_get_pixel_size ( tb->
layout, &line_width, &line_height );
420 if ( tb->
yalign > 0.001 ) {
422 top = ( tb->
widget.
h - bottom - line_height - top ) * tb->
yalign + top;
431 int iconh = cairo_image_surface_get_height ( tb->
icon );
432 int iconw = cairo_image_surface_get_width ( tb->
icon );
433 int icons = MAX ( iconh, iconw );
434 double scale = (double) iconheight / icons;
435 cairo_translate ( draw, x + ( iconheight - iconw * scale ) / 2.0, y + ( iconheight - iconh * scale ) / 2.0 );
436 cairo_scale ( draw, scale, scale );
437 cairo_set_source_surface ( draw, tb->
icon, 0, 0 );
438 cairo_paint ( draw );
439 cairo_restore ( draw );
443 if ( tb->
xalign > 0.001 ) {
448 cairo_set_operator ( draw, CAIRO_OPERATOR_OVER );
449 cairo_set_source_rgb ( draw, 0.0, 0.0, 0.0 );
454 const char *text = pango_layout_get_text ( tb->
layout );
456 int cursor_offset = MIN ( tb->
cursor, g_utf8_strlen ( text, -1 ) );
459 char *offset = g_utf8_offset_to_pointer ( text, cursor_offset );
460 pango_layout_get_cursor_pos ( tb->
layout, offset - text, &pos, NULL );
461 int cursor_x = pos.x / PANGO_SCALE;
462 int cursor_y = pos.y / PANGO_SCALE;
463 int cursor_height = pos.height / PANGO_SCALE;
464 int cursor_width = 2;
465 cairo_rectangle ( draw, x + cursor_x, y + cursor_y, cursor_width, cursor_height );
471 cairo_move_to ( draw, x, top );
472 pango_cairo_show_layout ( draw, tb->
layout );
486 int length = ( tb->
text == NULL ) ? 0 : g_utf8_strlen ( tb->
text, -1 );
487 tb->
cursor = MAX ( 0, MIN ( length, pos ) );
524 if ( tb->
text == NULL ) {
528 gchar *c = g_utf8_offset_to_pointer ( tb->
text, tb->
cursor );
529 while ( ( c = g_utf8_next_char ( c ) ) ) {
530 gunichar uc = g_utf8_get_char ( c );
531 GUnicodeBreakType bt = g_unichar_break_type ( uc );
532 if ( ( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
533 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
537 if ( c == NULL || *c ==
'\0' ) {
540 while ( ( c = g_utf8_next_char ( c ) ) ) {
541 gunichar uc = g_utf8_get_char ( c );
542 GUnicodeBreakType bt = g_unichar_break_type ( uc );
543 if ( !( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
544 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
548 int index = g_utf8_pointer_to_offset ( tb->
text, c );
556 gchar *c = g_utf8_offset_to_pointer ( tb->
text, tb->
cursor );
557 while ( ( c = g_utf8_prev_char ( c ) ) && c != tb->
text ) {
558 gunichar uc = g_utf8_get_char ( c );
559 GUnicodeBreakType bt = g_unichar_break_type ( uc );
560 if ( ( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
561 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
565 if ( c != tb->
text ) {
566 while ( ( n = g_utf8_prev_char ( c ) ) ) {
567 gunichar uc = g_utf8_get_char ( n );
568 GUnicodeBreakType bt = g_unichar_break_type ( uc );
569 if ( !( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
570 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
574 if ( n == tb->
text ) {
579 int index = g_utf8_pointer_to_offset ( tb->
text, c );
586 if ( tb->
text == NULL ) {
591 tb->
cursor = ( int ) g_utf8_strlen ( tb->
text, -1 );
603 char *c = g_utf8_offset_to_pointer ( tb->
text, char_pos );
604 int pos = c - tb->
text;
605 int len = ( int ) strlen ( tb->
text );
606 pos = MAX ( 0, MIN ( len, pos ) );
608 tb->
text = g_realloc ( tb->
text, len + slen + 1 );
610 char *at = tb->
text + pos;
611 memmove ( at + slen, at, len - pos + 1 );
613 memmove ( at, str, slen );
627 int len = g_utf8_strlen ( tb->
text, -1 );
631 pos = MAX ( 0, MIN ( len, pos ) );
632 if ( ( pos + dlen ) > len ) {
636 char *start = g_utf8_offset_to_pointer ( tb->
text, pos );
637 char *end = g_utf8_offset_to_pointer ( tb->
text, pos + dlen );
639 memmove ( start, end, ( tb->
text + strlen ( tb->
text ) ) - end + 1 );
640 if ( tb->
cursor >= pos && tb->
cursor < ( pos + dlen ) ) {
643 else if ( tb->
cursor >= ( pos + dlen ) ) {
659 if ( tb == NULL || tb->
text == NULL ) {
672 if ( tb && tb->
cursor > 0 ) {
679 if ( tb && tb->
cursor > 0 ) {
682 if ( cursor > tb->
cursor ) {
689 if ( tb && tb->
cursor >= 0 ) {
690 int length = g_utf8_strlen ( tb->
text, -1 ) - tb->
cursor;
698 if ( tb && tb->
cursor >= 0 ) {
707 if ( tb && tb->
cursor >= 0 ) {
710 if ( cursor < tb->cursor ) {
781 g_return_val_if_reached ( 0 );
796 gboolean used_something = FALSE;
797 const gchar *w, *n, *e;
798 for ( w = pad, n = g_utf8_next_char ( w ), e = w + pad_len; w < e; w = n, n = g_utf8_next_char ( n ) ) {
799 if ( g_unichar_iscntrl ( g_utf8_get_char ( w ) ) ) {
804 used_something = TRUE;
806 return used_something;
811 pango_font_metrics_unref ( tbfc->
metrics );
813 pango_font_description_free ( tbfc->
pfd );
831 tbfc->
height = pango_font_metrics_get_ascent ( tbfc->
metrics ) + pango_font_metrics_get_descent ( tbfc->
metrics );
870 pango_layout_get_pixel_size ( tb->
layout, NULL, &height );
877 pango_layout_get_pixel_extents ( tb->
layout, NULL, &rect );
878 return rect.width + rect.x;
886 int height = pango_font_metrics_get_ascent (
p_metrics ) + pango_font_metrics_get_descent (
p_metrics );
897 int width = pango_font_metrics_get_approximate_char_width (
p_metrics );
898 char_width = ( width ) / (
double) PANGO_SCALE;
907 int width = pango_font_metrics_get_approximate_digit_width (
p_metrics );
908 ch_width = ( width ) / (
double) PANGO_SCALE;
915 int height = pango_font_metrics_get_ascent ( tb->
metrics ) + pango_font_metrics_get_descent ( tb->
metrics );
932 int old_width = pango_layout_get_width ( tb->
layout );
933 pango_layout_set_width ( tb->
layout, -1 );
936 pango_layout_set_width ( tb->
layout, old_width );
937 return width + padding + offset;
static void textbox_cursor_del_eol(textbox *tb)
void textbox_cursor_end(textbox *tb)
static PangoFontMetrics * p_metrics
static void textbox_cursor_dec_word(textbox *tb)
PangoFontMetrics * metrics
static gboolean textbox_blink(gpointer data)
MouseBindingMouseDefaultAction
void textbox_cleanup(void)
void rofi_theme_get_color(const widget *widget, const char *property, cairo_t *d)
void textbox_text(textbox *tb, const char *text)
const char * default_font_name
static void textbox_cursor_del(textbox *tb)
static void textbox_cursor_del_sol(textbox *tb)
void textbox_icon(textbox *tb, cairo_surface_t *icon)
void rofi_view_queue_redraw(void)
static double char_height
double textbox_get_estimated_char_width(void)
static int textbox_get_width(widget *)
const char * rofi_theme_get_string(const widget *widget, const char *property, const char *def)
static int _textbox_get_height(widget *)
static GHashTable * tbfc_cache
double rofi_theme_get_double(const widget *widget, const char *property, double def)
static void textbox_cursor_bkspc(textbox *tb)
void textbox_font(textbox *tb, TextBoxFontType tbft)
RofiDistance rofi_theme_get_distance(const widget *widget, const char *property, int def)
textbox * textbox_create(widget *parent, WidgetType type, const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text, double xalign, double yalign)
void textbox_cursor(textbox *tb, int pos)
int textbox_get_font_width(const textbox *tb)
PangoFontMetrics * metrics
static void textbox_cursor_del_word(textbox *tb)
double textbox_get_estimated_ch(void)
int textbox_keybinding(textbox *tb, KeyBindingAction action)
const char * textbox_get_visible_text(const textbox *tb)
static int textbox_get_desired_height(widget *wid)
static void textbox_draw(widget *, cairo_t *)
static void __textbox_update_pango_text(textbox *tb)
static void tbfc_entry_free(TBFontConfig *tbfc)
void textbox_moveresize(textbox *tb, int x, int y, int w, int h)
static int textbox_cursor_inc(textbox *tb)
static PangoContext * p_context
void textbox_insert(textbox *tb, const int char_pos, const char *str, const int slen)
int textbox_get_height(const textbox *tb)
static void textbox_resize(widget *wid, short w, short h)
static void textbox_free(widget *)
int distance_get_pixel(RofiDistance d, RofiOrientation ori)
static void textbox_initialize_font(textbox *tb)
PangoFontDescription * pfd
PangoAttrList * textbox_get_pango_attributes(textbox *tb)
int textbox_get_estimated_height(const textbox *tb, int eh)
static void textbox_cursor_inc_word(textbox *tb)
int textbox_get_font_height(const textbox *tb)
const char *const theme_prop_names[][3]
int textbox_get_desired_width(widget *wid)
double textbox_get_estimated_char_height(void)
static int textbox_cursor_dec(textbox *tb)
void textbox_set_pango_attributes(textbox *tb, PangoAttrList *list)
struct TBFontConfig TBFontConfig
static WidgetTriggerActionResult textbox_editable_trigger_action(widget *wid, MouseBindingMouseDefaultAction action, gint x, gint y, G_GNUC_UNUSED void *user_data)
void textbox_delete(textbox *tb, int pos, int dlen)
static void textbox_cursor_bkspc_word(textbox *tb)
gboolean textbox_append_text(textbox *tb, const char *pad, const int pad_len)
gboolean helper_validate_font(PangoFontDescription *pfd, const char *font)
void textbox_set_pango_context(const char *font, PangoContext *p)