67 if ( tb->
blink < 2 ) {
113 pango_layout_xy_to_index ( tb->
layout, x * PANGO_SCALE, y * PANGO_SCALE, &i, NULL );
132 if ( tbfc == NULL ) {
134 tbfc->
pfd = pango_font_description_from_string ( font );
138 PangoLayout *layout = pango_layout_new (
p_context );
139 pango_layout_set_text ( layout,
"aAjb", -1 );
141 pango_layout_get_pixel_extents ( layout, NULL, &rect );
142 tbfc->
height = rect.y + rect.height;
143 g_object_unref ( layout );
146 g_hash_table_insert (
tbfc_cache, (
char *) font, tbfc );
149 pango_font_description_free ( tbfc->
pfd );
156 pango_layout_set_font_description ( tb->
layout, tbfc->
pfd );
176 tb->
emode = PANGO_ELLIPSIZE_END;
186 pango_layout_set_wrap ( tb->
layout, PANGO_WRAP_WORD_CHAR );
190 if ( txt == NULL || ( *txt ) ==
'\0' ) {
225 {
"normal.normal",
"selected.normal",
"alternate.normal" },
227 {
"normal.urgent",
"selected.urgent",
"alternate.urgent" },
229 {
"normal.active",
"selected.active",
"alternate.active" },
268 pango_layout_set_attributes ( tb->
layout, NULL );
276 size_t l = g_utf8_strlen ( tb->
text, -1 );
278 memset (
string,
'*', l );
280 pango_layout_set_text ( tb->
layout,
string, l );
283 pango_layout_set_markup ( tb->
layout, tb->
text, -1 );
286 pango_layout_set_text ( tb->
layout, tb->
text, -1 );
294 return pango_layout_get_text ( tb->
layout );
301 return pango_layout_get_attributes ( tb->
layout );
308 pango_layout_set_attributes ( tb->
layout, list );
318 const gchar *last_pointer = NULL;
320 if ( g_utf8_validate ( text, -1, &last_pointer ) ) {
321 tb->
text = g_strdup ( text );
324 if ( last_pointer != NULL ) {
326 tb->
text = g_strndup ( text, ( last_pointer - text ) );
329 tb->
text = g_strdup (
"Invalid UTF-8 string." );
335 if (
WIDGET ( tb )->parent ) {
340 tb->
cursor = MAX ( 0, MIN ( (
int ) g_utf8_strlen ( tb->
text, -1 ), tb->
cursor ) );
349 pango_layout_set_width ( tb->
layout, -1 );
355 pango_layout_set_ellipsize ( tb->
layout, PANGO_ELLIPSIZE_MIDDLE );
358 pango_layout_set_ellipsize ( tb->
layout, tb->
emode );
361 pango_layout_set_ellipsize ( tb->
layout, PANGO_ELLIPSIZE_NONE );
367 int tw = MAX ( 1, w );
398 if ( tb->
layout != NULL ) {
399 g_object_unref ( tb->
layout );
420 int y = ( pango_font_metrics_get_ascent ( tb->
tbfc->
metrics ) - pango_layout_get_baseline ( tb->
layout ) ) / PANGO_SCALE;
421 int line_width = 0, line_height = 0;
423 pango_layout_get_pixel_size ( tb->
layout, &line_width, &line_height );
425 if ( tb->
yalign > 0.001 ) {
427 top = ( tb->
widget.
h - bottom - line_height - top ) * tb->
yalign + top;
433 if ( tb->
xalign > 0.001 ) {
438 cairo_set_operator ( draw, CAIRO_OPERATOR_OVER );
439 cairo_set_source_rgb ( draw, 0.0, 0.0, 0.0 );
447 cairo_move_to ( draw, x, top );
449 cairo_reset_clip ( draw );
450 pango_cairo_show_layout ( draw, tb->
layout );
451 cairo_restore ( draw );
457 const char *text = pango_layout_get_text ( tb->
layout );
459 int cursor_offset = MIN ( tb->
cursor, g_utf8_strlen ( text, -1 ) );
462 char *offset = g_utf8_offset_to_pointer ( text, cursor_offset );
463 pango_layout_get_cursor_pos ( tb->
layout, offset - text, &pos, NULL );
464 int cursor_x = pos.x / PANGO_SCALE;
465 int cursor_y = pos.y / PANGO_SCALE;
466 int cursor_height = pos.height / PANGO_SCALE;
467 int cursor_width = 2;
468 cairo_rectangle ( draw, x + cursor_x, y + cursor_y, cursor_width, cursor_height );
484 int length = ( tb->
text == NULL ) ? 0 : g_utf8_strlen ( tb->
text, -1 );
485 tb->
cursor = MAX ( 0, MIN ( length, pos ) );
522 if ( tb->
text == NULL ) {
526 gchar *c = g_utf8_offset_to_pointer ( tb->
text, tb->
cursor );
527 while ( ( c = g_utf8_next_char ( c ) ) ) {
528 gunichar uc = g_utf8_get_char ( c );
529 GUnicodeBreakType bt = g_unichar_break_type ( uc );
530 if ( ( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
531 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
535 if ( c == NULL || *c ==
'\0' ) {
538 while ( ( c = g_utf8_next_char ( c ) ) ) {
539 gunichar uc = g_utf8_get_char ( c );
540 GUnicodeBreakType bt = g_unichar_break_type ( uc );
541 if ( !( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
542 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
546 int index = g_utf8_pointer_to_offset ( tb->
text, c );
554 gchar *c = g_utf8_offset_to_pointer ( tb->
text, tb->
cursor );
555 while ( ( c = g_utf8_prev_char ( c ) ) && c != tb->
text ) {
556 gunichar uc = g_utf8_get_char ( c );
557 GUnicodeBreakType bt = g_unichar_break_type ( uc );
558 if ( ( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
559 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
563 if ( c != tb->
text ) {
564 while ( ( n = g_utf8_prev_char ( c ) ) ) {
565 gunichar uc = g_utf8_get_char ( n );
566 GUnicodeBreakType bt = g_unichar_break_type ( uc );
567 if ( !( bt == G_UNICODE_BREAK_ALPHABETIC || bt == G_UNICODE_BREAK_HEBREW_LETTER ||
568 bt == G_UNICODE_BREAK_NUMERIC || bt == G_UNICODE_BREAK_QUOTATION ) ) {
572 if ( n == tb->
text ) {
577 int index = g_utf8_pointer_to_offset ( tb->
text, c );
584 if ( tb->
text == NULL ) {
589 tb->
cursor = ( int ) g_utf8_strlen ( tb->
text, -1 );
601 char *c = g_utf8_offset_to_pointer ( tb->
text, char_pos );
602 int pos = c - tb->
text;
603 int len = ( int ) strlen ( tb->
text );
604 pos = MAX ( 0, MIN ( len, pos ) );
606 tb->
text = g_realloc ( tb->
text, len + slen + 1 );
608 char *at = tb->
text + pos;
609 memmove ( at + slen, at, len - pos + 1 );
611 memmove ( at, str, slen );
625 int len = g_utf8_strlen ( tb->
text, -1 );
629 pos = MAX ( 0, MIN ( len, pos ) );
630 if ( ( pos + dlen ) > len ) {
634 char *start = g_utf8_offset_to_pointer ( tb->
text, pos );
635 char *end = g_utf8_offset_to_pointer ( tb->
text, pos + dlen );
637 memmove ( start, end, ( tb->
text + strlen ( tb->
text ) ) - end + 1 );
638 if ( tb->
cursor >= pos && tb->
cursor < ( pos + dlen ) ) {
641 else if ( tb->
cursor >= ( pos + dlen ) ) {
657 if ( tb == NULL || tb->
text == NULL ) {
670 if ( tb && tb->
cursor > 0 ) {
677 if ( tb && tb->
cursor > 0 ) {
680 if ( cursor > tb->
cursor ) {
687 if ( tb && tb->
cursor >= 0 ) {
688 int length = g_utf8_strlen ( tb->
text, -1 ) - tb->
cursor;
696 if ( tb && tb->
cursor >= 0 ) {
705 if ( tb && tb->
cursor >= 0 ) {
708 if ( cursor < tb->cursor ) {
779 g_return_val_if_reached ( 0 );
794 gboolean used_something = FALSE;
795 const gchar *w, *n, *e;
796 for ( w = pad, n = g_utf8_next_char ( w ), e = w + pad_len; w < e; w = n, n = g_utf8_next_char ( n ) ) {
797 if ( g_unichar_iscntrl ( g_utf8_get_char ( w ) ) ) {
802 used_something = TRUE;
804 return used_something;
809 pango_font_metrics_unref ( tbfc->
metrics );
811 pango_font_description_free ( tbfc->
pfd );
830 PangoLayout *layout = pango_layout_new (
p_context );
831 pango_layout_set_text ( layout,
"aAjb", -1 );
833 pango_layout_get_pixel_extents ( layout, NULL, &rect );
834 tbfc->
height = rect.y + rect.height;
835 g_object_unref ( layout );
876 pango_layout_get_pixel_extents ( tb->
layout, NULL, &rect );
877 return rect.height + rect.y;
883 pango_layout_get_pixel_extents ( tb->
layout, NULL, &rect );
884 return rect.width + rect.x;
898 int width = pango_font_metrics_get_approximate_char_width (
p_metrics );
899 char_width = ( width ) / (
double) PANGO_SCALE;
909 int width = pango_font_metrics_get_approximate_digit_width (
p_metrics );
910 ch_width = ( width ) / (
double) PANGO_SCALE;
937 int old_width = pango_layout_get_width ( tb->
layout );
938 pango_layout_set_width ( tb->
layout, -1 );
941 pango_layout_set_width ( tb->
layout, old_width );
942 return width + padding + offset;
951 pango_layout_set_ellipsize ( tb->
layout, tb->
emode );
gboolean helper_validate_font(PangoFontDescription *pfd, const char *font)
MouseBindingMouseDefaultAction
int textbox_get_height(const textbox *tb)
void textbox_insert(textbox *tb, const int char_pos, const char *str, const int slen)
void textbox_font(textbox *tb, TextBoxFontType tbft)
void textbox_delete(textbox *tb, int pos, int dlen)
int textbox_keybinding(textbox *tb, KeyBindingAction action)
void textbox_cleanup(void)
double textbox_get_estimated_char_width(void)
int textbox_get_font_height(const textbox *tb)
void textbox_set_pango_attributes(textbox *tb, PangoAttrList *list)
void textbox_set_ellipsize(textbox *tb, PangoEllipsizeMode mode)
const char * textbox_get_visible_text(const textbox *tb)
double textbox_get_estimated_char_height(void)
int textbox_get_desired_width(widget *wid)
PangoAttrList * textbox_get_pango_attributes(textbox *tb)
textbox * textbox_create(widget *parent, WidgetType type, const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text, double xalign, double yalign)
int textbox_get_estimated_height(const textbox *tb, int eh)
void textbox_cursor(textbox *tb, int pos)
void textbox_set_pango_context(const char *font, PangoContext *p)
int textbox_get_font_width(const textbox *tb)
void textbox_cursor_end(textbox *tb)
gboolean textbox_append_text(textbox *tb, const char *pad, const int pad_len)
void textbox_moveresize(textbox *tb, int x, int y, int w, int h)
void textbox_text(textbox *tb, const char *text)
double textbox_get_estimated_ch(void)
void rofi_view_queue_redraw(void)
@ ROFI_ORIENTATION_HORIZONTAL
PangoFontMetrics * metrics
PangoFontDescription * pfd
TBFontConfig * tbfc_default
static PangoContext * p_context
static int textbox_get_width(widget *)
static int textbox_get_desired_height(widget *wid)
static void textbox_cursor_dec_word(textbox *tb)
static void textbox_cursor_inc_word(textbox *tb)
static gboolean textbox_blink(gpointer data)
static WidgetTriggerActionResult textbox_editable_trigger_action(widget *wid, MouseBindingMouseDefaultAction action, gint x, gint y, G_GNUC_UNUSED void *user_data)
const char *const theme_prop_names[][3]
const char * default_font_name
static int textbox_cursor_inc(textbox *tb)
static void textbox_free(widget *)
static void textbox_initialize_font(textbox *tb)
static void textbox_resize(widget *wid, short w, short h)
static void textbox_cursor_del_sol(textbox *tb)
static void textbox_cursor_bkspc(textbox *tb)
static void textbox_cursor_bkspc_word(textbox *tb)
static void textbox_draw(widget *, cairo_t *)
static void textbox_cursor_del_word(textbox *tb)
static PangoFontMetrics * p_metrics
static void textbox_cursor_del(textbox *tb)
static void __textbox_update_pango_text(textbox *tb)
static int _textbox_get_height(widget *)
static void textbox_cursor_del_eol(textbox *tb)
static int textbox_cursor_dec(textbox *tb)
static void tbfc_entry_free(TBFontConfig *tbfc)
static GHashTable * tbfc_cache
RofiDistance rofi_theme_get_distance(const widget *widget, const char *property, int def)
int rofi_theme_get_boolean(const widget *widget, const char *property, int def)
int distance_get_pixel(RofiDistance d, RofiOrientation ori)
void rofi_theme_get_color(const widget *widget, const char *property, cairo_t *d)
double rofi_theme_get_double(const widget *widget, const char *property, double def)
const char * rofi_theme_get_string(const widget *widget, const char *property, const char *def)