summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2016-01-11 08:36:20 +0100
committerDave Davenport <qball@gmpclient.org>2016-01-11 08:36:20 +0100
commitf080aa2d61d5eaba1dba1d669b0e4306fd26558d (patch)
tree201abe92386c6b6f45bad0e45bcb37090f6215d6
parentb012ec1e8aa1fb2b5b7877da98973834a58fcb9e (diff)
Remove duplicate code, make password right character length.
-rw-r--r--include/textbox.h18
-rw-r--r--source/textbox.c56
2 files changed, 36 insertions, 38 deletions
diff --git a/include/textbox.h b/include/textbox.h
index fe59b02a..ecc52784 100644
--- a/include/textbox.h
+++ b/include/textbox.h
@@ -40,15 +40,15 @@ typedef struct
typedef enum
{
- TB_AUTOHEIGHT = 1 << 0,
- TB_AUTOWIDTH = 1 << 1,
- TB_LEFT = 1 << 16,
- TB_RIGHT = 1 << 17,
- TB_CENTER = 1 << 18,
- TB_EDITABLE = 1 << 19,
- TB_MARKUP = 1 << 20,
- TB_WRAP = 1 << 21,
- TB_PASSWORD = 1 << 22,
+ TB_AUTOHEIGHT = 1 << 0,
+ TB_AUTOWIDTH = 1 << 1,
+ TB_LEFT = 1 << 16,
+ TB_RIGHT = 1 << 17,
+ TB_CENTER = 1 << 18,
+ TB_EDITABLE = 1 << 19,
+ TB_MARKUP = 1 << 20,
+ TB_WRAP = 1 << 21,
+ TB_PASSWORD = 1 << 22,
} TextboxFlags;
typedef enum
diff --git a/source/textbox.c b/source/textbox.c
index 4226c39e..b0e5d58e 100644
--- a/source/textbox.c
+++ b/source/textbox.c
@@ -124,6 +124,31 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft )
tb->tbft = tbft;
}
+/**
+ * @param tb The textbox object.
+ *
+ * Update the pango layout's text. It does this depending on the
+ * textbox flags.
+ */
+static void __textbox_update_pango_text ( textbox *tb )
+{
+ if ( ( tb->flags & TB_PASSWORD ) == TB_PASSWORD ) {
+ size_t l = g_utf8_strlen ( tb->text, -1 );
+ char string [l + 1];
+ memset ( string, '*', l );
+ string[l] = '\0';
+ pango_layout_set_attributes ( tb->layout, NULL );
+ pango_layout_set_text ( tb->layout, string, l );
+ }
+ else if ( tb->flags & TB_MARKUP || tb->tbft & MARKUP ) {
+ pango_layout_set_markup ( tb->layout, tb->text, strlen ( tb->text ) );
+ }
+ else {
+ pango_layout_set_attributes ( tb->layout, NULL );
+ pango_layout_set_text ( tb->layout, tb->text, strlen ( tb->text ) );
+ }
+}
+
// set the default text to display
void textbox_text ( textbox *tb, const char *text )
{
@@ -143,21 +168,7 @@ void textbox_text ( textbox *tb, const char *text )
tb->text = g_strdup ( "Invalid UTF-8 string." );
}
}
- if ( ( tb->flags & TB_PASSWORD ) == TB_PASSWORD ) {
- size_t l = strlen ( tb->text );
- char string [l + 1];
- memset ( string, '*', l );
- string[l] = '\0';
- pango_layout_set_attributes ( tb->layout, NULL );
- pango_layout_set_text ( tb->layout, string, l );
- }
- else if ( tb->flags & TB_MARKUP || tb->tbft & MARKUP ) {
- pango_layout_set_markup ( tb->layout, tb->text, strlen ( tb->text ) );
- }
- else {
- pango_layout_set_attributes ( tb->layout, NULL );
- pango_layout_set_text ( tb->layout, tb->text, strlen ( tb->text ) );
- }
+ __textbox_update_pango_text ( tb );
if ( tb->flags & TB_AUTOWIDTH ) {
textbox_moveresize ( tb, tb->widget.x, tb->widget.y, tb->widget.w, tb->widget.h );
}
@@ -247,20 +258,7 @@ static void texbox_update ( textbox *tb )
int cursor_width = MAX ( 2, font_height / 10 );
if ( tb->changed ) {
- if ( ( tb->flags & TB_PASSWORD ) == TB_PASSWORD ) {
- size_t l = strlen ( tb->text );
- char string [l + 1];
- memset ( string, '*', l );
- string[l] = '\0';
- pango_layout_set_attributes ( tb->layout, NULL );
- pango_layout_set_text ( tb->layout, string, l );
- }
- else if ( tb->flags & TB_MARKUP ) {
- pango_layout_set_markup ( tb->layout, text, text_len );
- }
- else{
- pango_layout_set_text ( tb->layout, text, text_len );
- }
+ __textbox_update_pango_text ( tb );
}
if ( tb->flags & TB_EDITABLE ) {