Languages

Menu
Sites
Language
Show URL link in label or entry widget

Hi All,

In my application I have put terms of use screen where I have kept a URL to open full description in web browser.

I want to show that link in label or entry widget (Which has scroller) and when user clicks on that link text, Link should be opened in default browser.

How can I do that?

Thank you!!

Responses

3 Replies
Alex Dem

Hi,
For simplest case:
If you entry should not be editable and should contain only your url,  you could try to perform something like this when you creates entry:
 

 elm_entry_scrollable_set(entry, EINA_TRUE);
 elm_entry_entry_set(entry,"http://www.google.com");
 elm_entry_editable_set(entry,EINA_FALSE);
 evas_object_smart_callback_add(entry, "clicked", entry_click_cb, NULL);

and inside entry_click_cb you could try to perform this:
 

    const char* url= elm_entry_entry_get();
    app_control_h app_control;
                
    app_control_create(&app_control);
    app_control_set_operation(app_control, APP_CONTROL_OPERATION_DEFAULT);
    app_control_set_app_id(app_control, "com.samsung.browser");
    app_control_set_uri(app_control, url);

    if (app_control_send_launch_request(app_control, NULL, NULL) == APP_CONTROL_ERROR_NONE)      {              }
    else        {              }

    app_control_destroy(app_control);

with http://tizen.org/privilege/appmanager.launch in manifest of course 

Also you could try to add sryle with underline for your entry ( as it was described in another topic).

Of course if you entry shoul contains text mixed with urls it looks difficultly.
You urls should be marked as

 elm_entry_entry_set(entry,"<link>http://www.google.com</link> Some text <link>http://www.google.com</link>");

and you will need to detect that you have clicked exactly on first or on second url and parse string... etc
But maybe someone know better way...
Alexey.

pius lee

Yes, just use signal "anchor,clicked".

Anchors

Anchors are similar to HTML anchors. Text can be surrounded by <a> and </a> and an event is generated when this text is clicked, for example:

 This text is outside <a href=anc-01>but this one is an anchor</a>

The href attribute in the opening tag gives the name that is used to identify the anchor. It can be any valid UTF8 string.

When an anchor is clicked, an "anchor,clicked" signal is emitted with Elm_Entry_Anchor_Info in the event_info parameter for the callback function. The same applies for the "anchor,in" (mouse in), "anchor,out" (mouse out), "anchor,down" (mouse down), and "anchor,up" (mouse up) events on an anchor.

  • "anchor,clicked": An anchor has been clicked. The event_info parameter for the callback is Elm_Entry_Anchor_Info.
  • "anchor,in": The mouse cursor has moved into an anchor. The event_info parameter for the callback is Elm_Entry_Anchor_Info.
  • "anchor,out": The mouse cursor has moved out of an anchor. The event_info parameter for the callback is Elm_Entry_Anchor_Info.
  • "anchor,up": The mouse button has been unpressed on an anchor. The event_info parameter for the callback is Elm_Entry_Anchor_Info.
  • "anchor,down": The muse button has been pressed on an anchor. The event_info parameter for the callback is Elm_Entry_Anchor_Info.

 

You can make it easy like next code.

static void anchor_clicked_cb(void *data, Evas_Object *obj, void *event_info)
{
    Elm_Entry_Anchor_Info *ai = event_info;
	app_control_h ac;
    app_control_create(&ac);
    app_control_set_operation(ac, APP_CONTROL_OPERATION_VIEW);
    app_control_set_uri(ac, ai->name);
    int r = app_control_send_launch_request(ac, NULL, NULL);
    app_control_destroy(ac);
}

Evas_Object *entry = elm_entry_add(ad->conform);
elm_object_text_set(entry, "This <a href=http://google.com>google.com</a> is linked!");
evas_object_smart_callback_add(entry, "anchor,clicked", anchor_clicked_cb, ad);
elm_entry_editable_set(entry, EINA_FALSE);
evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_object_content_set(ad->conform, entry);

 

Dharmesh Guna

Hi,

Thank you Alex and Pius Lee. 

Your suggestions helped me a lot. By default url appeared without underline. I wrapped <a>...</a> anchor tag with <link>...</link> to show the underline in url text. Also now I am able to launch url in browser using anchor, clicked event.

Thanks a lot.