* Add password mode to the entry

SVN revision: 24586
This commit is contained in:
moom 2006-08-12 12:21:32 +00:00 committed by moom
parent 4eddbf00ca
commit 1b34e1f692
7 changed files with 172 additions and 86 deletions

View File

@ -28,6 +28,7 @@ struct _E_Editable_Smart_Data
int selection_dragging;
int selection_visible;
int selectable;
int password_mode;
char *text;
int char_length;
@ -46,6 +47,7 @@ static int _e_editable_text_insert(Evas_Object *editable, int pos, const char *t
static int _e_editable_text_delete(Evas_Object *editable, int start, int end);
static void _e_editable_cursor_update(Evas_Object *editable);
static void _e_editable_selection_update(Evas_Object *editable);
static void _e_editable_text_update(Evas_Object *editable);
static void _e_editable_text_position_update(Evas_Object *editable);
static int _e_editable_cursor_pos_get_from_coords(Evas_Object *editable, Evas_Coord canvas_x, Evas_Coord canvas_y);
@ -102,6 +104,45 @@ e_editable_add(Evas *evas)
return evas_object_smart_add(evas, _e_editable_smart);
}
/**
* Sets whether or not the editable object is in password mode. In password
* mode, the editable object displays '*' instead of the characters
*
* @param editable an editable object
* @param password_mode 1 to turn on the password mode of the editable object,
* 0 to turn it off
*/
EAPI void
e_editable_password_set(Evas_Object *editable, int password_mode)
{
E_Editable_Smart_Data *sd;
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
return;
if (sd->password_mode == password_mode)
return;
sd->password_mode = password_mode;
_e_editable_text_update(editable);
_e_editable_cursor_update(editable);
}
/**
* Gets whether or not the editable is in password mode
*
* @param editable an editable object
* @return Returns 1 if the editable object is in the password mode, 0 otherwise
*/
EAPI int
e_editable_password_get(Evas_Object *editable)
{
E_Editable_Smart_Data *sd;
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
return 0;
return sd->password_mode;
}
/**
* Sets the text of the editable object
*
@ -197,12 +238,12 @@ e_editable_text_range_get(Evas_Object *editable, int start, int end)
}
/**
* Gets the unicode length of the text of the entry. The unicode length is not
* always the length returned by strlen() since a UTF-8 char can take several
* bytes
* Gets the unicode length of the text of the editable object. The unicode
* length is not always the length returned by strlen() since a UTF-8 char can
* take several bytes
*
* @param editable an editable object
* @return Returns the unicode length of the text of the entry
* @return Returns the unicode length of the text of the editable object
*/
EAPI int
e_editable_text_length_get(Evas_Object *editable)
@ -693,8 +734,7 @@ e_editable_char_size_get(Evas_Object *editable, int *w, int *h)
/* Private functions */
/* A utility function to insert some text inside the editable object.
* It doesn't update the position of the cursor, nor the selection...
*/
* It doesn't update the position of the cursor, nor the selection... */
static int
_e_editable_text_insert(Evas_Object *editable, int pos, const char *text)
{
@ -745,14 +785,13 @@ _e_editable_text_insert(Evas_Object *editable, int pos, const char *text)
strncpy(&sd->text[index], text, char_length);
sd->text[sd->char_length] = '\0';
evas_object_text_text_set(sd->text_object, sd->text);
_e_editable_text_update(editable);
return unicode_length;
}
/* A utility function to delete a range of text from the editable object.
* It doesn't update the position of the cursor, nor the selection...
*/
* It doesn't update the position of the cursor, nor the selection... */
static int
_e_editable_text_delete(Evas_Object *editable, int start, int end)
{
@ -785,14 +824,13 @@ _e_editable_text_delete(Evas_Object *editable, int start, int end)
sd->unicode_length -= (end - start);
sd->text[sd->char_length] = '\0';
evas_object_text_text_set(sd->text_object, sd->text);
_e_editable_text_update(editable);
return end - start;
}
/* Updates the position of the cursor
* It also updates automatically the text position and the selection
*/
* It also updates automatically the text position and the selection */
static void
_e_editable_cursor_update(Evas_Object *editable)
{
@ -895,7 +933,34 @@ _e_editable_selection_update(Evas_Object *editable)
}
}
/* Updates the position of the text according to the position of the cursor */
/* Updates the text of the text object of the editable object
* (it fills it with '*' if the editable is in password mode)
* It does not update the position of the text */
static void
_e_editable_text_update(Evas_Object *editable)
{
E_Editable_Smart_Data *sd;
if ((!editable) || (!(sd = evas_object_smart_data_get(editable))))
return;
if (sd->password_mode)
{
char *text;
text = malloc((sd->unicode_length + 1) * sizeof(char));
memset(text, '*', sd->unicode_length * sizeof(char));
text[sd->unicode_length] = '\0';
evas_object_text_text_set(sd->text_object, text);
free(text);
}
else
evas_object_text_text_set(sd->text_object, sd->text ? sd->text : "");
}
/* Updates the position of the text object according to the position of the
* cursor (we make sure the cursor is visible) */
static void
_e_editable_text_position_update(Evas_Object *editable)
{
@ -938,8 +1003,7 @@ _e_editable_text_position_update(Evas_Object *editable)
}
/* Returns the position where to place the cursor according to the given coords
* Returns -1 on failure
*/
* Returns -1 on failure */
static int
_e_editable_cursor_pos_get_from_coords(Evas_Object *editable, Evas_Coord canvas_x, Evas_Coord canvas_y)
{
@ -1103,6 +1167,7 @@ _e_editable_smart_add(Evas_Object *object)
sd->selection_dragging = 0;
sd->selection_visible = 1;
sd->selectable = 1;
sd->password_mode = 0;
sd->clip_object = evas_object_rectangle_add(evas);
evas_object_smart_member_add(sd->clip_object, object);

View File

@ -7,6 +7,8 @@
#define E_EDITABLE_H
EAPI Evas_Object *e_editable_add (Evas *evas);
EAPI void e_editable_password_set (Evas_Object *editable, int password_mode);
EAPI int e_editable_password_get (Evas_Object *editable);
EAPI void e_editable_text_set (Evas_Object *editable, const char *text);
EAPI const char *e_editable_text_get (Evas_Object *editable);
EAPI char *e_editable_text_range_get (Evas_Object *editable, int start, int end);

View File

@ -115,6 +115,41 @@ e_entry_clear(Evas_Object *entry)
e_entry_text_set(entry, "");
}
/**
* Gets the editable object used by the entry object. It will allow you to have
* better control on the text, the cursor or the selection of the entry with
* the e_editable_*() functions.
*
* @param entry an entry object
* @return Returns the editable object used by the entry object
*/
EAPI Evas_Object *
e_entry_editable_object_get(Evas_Object *entry)
{
E_Entry_Smart_Data *sd;
if ((!entry) || (!(sd = evas_object_smart_data_get(entry))))
return NULL;
return sd->editable_object;
}
/**
* Sets whether or not the entry object is in password mode. In password mode,
* the entry displays '*' instead of the characters
*
* @param entry an entry object
* @param password_mode 1 to turn on password mode, 0 to turn it off
*/
EAPI void
e_entry_password_set(Evas_Object *entry, int password_mode)
{
E_Entry_Smart_Data *sd;
if ((!entry) || (!(sd = evas_object_smart_data_get(entry))))
return;
e_editable_password_set(sd->editable_object, password_mode);
}
/**
* Gets the minimum size of the entry object
*

View File

@ -6,16 +6,18 @@
#ifndef E_ENTRY_H
#define E_ENTRY_H
EAPI Evas_Object *e_entry_add (Evas *evas);
EAPI void e_entry_text_set (Evas_Object *entry, const char *text);
EAPI const char *e_entry_text_get (Evas_Object *entry);
EAPI void e_entry_clear (Evas_Object *entry);
EAPI Evas_Object *e_entry_add (Evas *evas);
EAPI void e_entry_text_set (Evas_Object *entry, const char *text);
EAPI const char *e_entry_text_get (Evas_Object *entry);
EAPI void e_entry_clear (Evas_Object *entry);
EAPI Evas_Object *e_entry_editable_object_get (Evas_Object *entry);
EAPI void e_entry_min_size_get (Evas_Object *entry, Evas_Coord *minw, Evas_Coord *minh);
EAPI void e_entry_focus (Evas_Object *entry);
EAPI void e_entry_unfocus (Evas_Object *entry);
EAPI void e_entry_enable (Evas_Object *entry);
EAPI void e_entry_disable (Evas_Object *entry);
EAPI void e_entry_password_set (Evas_Object *entry, int password_mode);
EAPI void e_entry_min_size_get (Evas_Object *entry, Evas_Coord *minw, Evas_Coord *minh);
EAPI void e_entry_focus (Evas_Object *entry);
EAPI void e_entry_unfocus (Evas_Object *entry);
EAPI void e_entry_enable (Evas_Object *entry);
EAPI void e_entry_disable (Evas_Object *entry);
#endif
#endif

View File

@ -32,7 +32,6 @@ static int _e_desklock_zone_num_get(void);
static void _load_bgs(E_Config_Dialog_Data *cfdata);
static void _ibg_list_cb_bg_selected(void *data);
static void _e_desklock_passwd_cb_change(void *data, Evas_Object *obj);
static void _e_desklock_cb_show_passwd(void *data, Evas_Object *obj);
static void _e_desklock_cb_lb_show_change(void *data, Evas_Object *obj);
#ifdef HAVE_PAM
@ -236,8 +235,8 @@ _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cf
#ifdef HAVE_PAM
if (cfdata->auth_method == 0) e_widget_disabled_set(ob, 1);
#endif
_e_desklock_passwd_cb_change(cfdata, ob);
e_widget_on_change_hook_set(ob, _e_desklock_passwd_cb_change, cfdata);
e_widget_entry_password_set(ob, !cfdata->show_password);
e_widget_min_size_set(ob, 200, 25);
e_widget_framelist_object_append(of, ob);
@ -423,8 +422,7 @@ _advanced_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data
if (cfdata->auth_method == 0) e_widget_disabled_set(ob, 1);
#endif
_e_desklock_passwd_cb_change(cfdata, ob);
e_widget_on_change_hook_set(ob, _e_desklock_passwd_cb_change, cfdata);
e_widget_entry_password_set(ob, !cfdata->show_password);
e_widget_min_size_set(ob, 200, 25);
e_widget_framelist_object_append(of, ob);
@ -481,7 +479,7 @@ _e_desklock_cb_show_passwd(void *data, Evas_Object *obj)
E_Config_Dialog_Data *cfdata;
cfdata = data;
_e_desklock_passwd_cb_change(cfdata, cfdata->gui.passwd_field);
e_widget_entry_password_set(cfdata->gui.passwd_field, !cfdata->show_password);
}
static int
@ -674,55 +672,6 @@ _ibg_list_cb_bg_selected(void *data)
}
}
static void
_e_desklock_passwd_cb_change(void *data, Evas_Object *obj)
{
E_Config_Dialog_Data *cfdata;
int i;
cfdata = data;
// here goes the hack to have e_widget_entry look like
// password entry. However, I think, this should be implemented
// at least on the e_widget_entry level. The best would be
// e_entry.
if (!cfdata->desklock_passwd[0])
{
E_FREE(cfdata->desklock_passwd_cp);
cfdata->desklock_passwd_cp = strdup("");
return;
}
if (strlen(cfdata->desklock_passwd) > strlen(cfdata->desklock_passwd_cp))
{
for (i = 0; i < strlen(cfdata->desklock_passwd_cp); i++)
cfdata->desklock_passwd[i] = cfdata->desklock_passwd_cp[i];
E_FREE(cfdata->desklock_passwd_cp);
cfdata->desklock_passwd_cp = strdup(cfdata->desklock_passwd);
}
else if (strlen(cfdata->desklock_passwd) < strlen(cfdata->desklock_passwd_cp))
{
cfdata->desklock_passwd_cp[strlen(cfdata->desklock_passwd)] = 0;
E_FREE(cfdata->desklock_passwd);
cfdata->desklock_passwd = strdup(cfdata->desklock_passwd_cp);
}
else
{
E_FREE(cfdata->desklock_passwd);
cfdata->desklock_passwd = strdup(cfdata->desklock_passwd_cp);
}
if (cfdata->show_password)
{
e_widget_entry_text_set(obj, cfdata->desklock_passwd);
return;
}
// FIXME: this is a hack. disable. see e_widget_entry.c for doing this right.
// for (ptr = cfdata->desklock_passwd; *ptr; ptr++) *ptr = '*';
// e_widget_entry_text_set(obj, cfdata->desklock_passwd);
}
static void
_e_desklock_cb_lb_show_change(void *data, Evas_Object *obj)
{

View File

@ -17,6 +17,7 @@ static void _e_wid_disable_hook(Evas_Object *obj);
static void _e_wid_focus_steal(void *data, Evas *e, Evas_Object *obj, void *event_info);
static void _e_wid_changed_cb(void *data, Evas_Object *obj, void *event_info);
/* externally accessible functions */
/**
@ -94,13 +95,44 @@ e_widget_entry_text_get(Evas_Object *entry)
return e_entry_text_get(wd->o_entry);
}
/* TODO, TODOC */
/**
* Sets whether or not the entry widget is in password mode. In password mode,
* the entry displays '*' instead of the characters
*
* @param entry an entry widget
* @param password_mode 1 to turn on password mode, 0 to turn it off
*/
EAPI void
e_widget_entry_password_set(Evas_Object *obj, int password)
e_widget_entry_password_set(Evas_Object *entry, int password_mode)
{
E_Widget_Data *wd;
if (!(entry) || (!(wd = e_widget_data_get(entry))))
return;
e_entry_password_set(wd->o_entry, password_mode);
}
/**
* Gets the editable object of the entry widget. It will allow you to have
* better control on the text, the cursor or the selection of the entry with
* the e_editable_*() functions.
*
* @param entry an entry widget
* @return Returns the editable object of the entry widget
*/
EAPI Evas_Object *
e_widget_entry_editable_object_get(Evas_Object *entry)
{
E_Widget_Data *wd;
if (!(entry) || (!(wd = e_widget_data_get(entry))))
return NULL;
return e_entry_editable_object_get(wd->o_entry);
}
/* Private functions */
static void
_e_wid_del_hook(Evas_Object *obj)
{

View File

@ -6,11 +6,12 @@
#ifndef E_WIDGET_ENTRY_H
#define E_WIDGET_ENTRY_H
EAPI Evas_Object *e_widget_entry_add (Evas *evas, char **text_location);
EAPI void e_widget_entry_text_set (Evas_Object *entry, const char *text);
EAPI const char *e_widget_entry_text_get (Evas_Object *entry);
EAPI void e_widget_entry_clear (Evas_Object *entry);
EAPI void e_widget_entry_password_set (Evas_Object *entry, int password);
EAPI Evas_Object *e_widget_entry_add (Evas *evas, char **text_location);
EAPI void e_widget_entry_text_set (Evas_Object *entry, const char *text);
EAPI const char *e_widget_entry_text_get (Evas_Object *entry);
EAPI void e_widget_entry_clear (Evas_Object *entry);
EAPI void e_widget_entry_password_set (Evas_Object *entry, int password_mode);
EAPI Evas_Object *e_widget_entry_editable_object_get (Evas_Object *entry);
#endif
#endif