From: Radek Kintop Date: Tue, 3 Nov 2015 13:58:56 +0000 (+0100) Subject: Mobile native Copy And Paste sample application documentation. X-Git-Tag: tizen_3.0/TD_SYNC/20161201~336^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6af739a128322ec566b85843bf60b831431d8fc5;p=sdk%2Fonline-doc.git Mobile native Copy And Paste sample application documentation. Change-Id: I763d9e5fd653f5316d9a0b72b9579edb261d9937 Signed-off-by: Radek Kintop --- diff --git a/org.tizen.sampledescriptions/html/images/copy_and_paste_drag_sd.png b/org.tizen.sampledescriptions/html/images/copy_and_paste_drag_sd.png new file mode 100644 index 0000000..f76896f Binary files /dev/null and b/org.tizen.sampledescriptions/html/images/copy_and_paste_drag_sd.png differ diff --git a/org.tizen.sampledescriptions/html/images/copy_and_paste_main_view_sd.png b/org.tizen.sampledescriptions/html/images/copy_and_paste_main_view_sd.png new file mode 100644 index 0000000..918bf9d Binary files /dev/null and b/org.tizen.sampledescriptions/html/images/copy_and_paste_main_view_sd.png differ diff --git a/org.tizen.sampledescriptions/html/images/copy_and_paste_pasted_sd.png b/org.tizen.sampledescriptions/html/images/copy_and_paste_pasted_sd.png new file mode 100644 index 0000000..058f6e5 Binary files /dev/null and b/org.tizen.sampledescriptions/html/images/copy_and_paste_pasted_sd.png differ diff --git a/org.tizen.sampledescriptions/html/images/copy_and_paste_widgets.png b/org.tizen.sampledescriptions/html/images/copy_and_paste_widgets.png new file mode 100644 index 0000000..f1674ef Binary files /dev/null and b/org.tizen.sampledescriptions/html/images/copy_and_paste_widgets.png differ diff --git a/org.tizen.sampledescriptions/html/mobile_n/copy_and_paste_sd.htm b/org.tizen.sampledescriptions/html/mobile_n/copy_and_paste_sd.htm new file mode 100644 index 0000000..55c0efc --- /dev/null +++ b/org.tizen.sampledescriptions/html/mobile_n/copy_and_paste_sd.htm @@ -0,0 +1,243 @@ + + + + + + + + + + + + + Copy And Paste documentation + + + + +
+
+ +
+
+

Mobile native

+
+ +

Copy And Paste Sample Overview

+ +

The Copy And Paste sample application demonstrates how to incorporate copy/cut/paste mechanism into an EFL based application. The sample operates on a predefined text block using system clipboard to perform mentioned operations.

+

The figure below illustrates the views of the application.

+

Figure: Copy And Paste screens

+

+ Main view of the Copy And Paste application + Drag operation in the Copy And Paste application + Text paste view in the Copy And Paste application +

+ +

The main screen consists of two widgets:

+
    +
  • elm_label - plays the role of the text source widget;
  • +
  • elm_entry - plays the role of the text sink widget.
  • +
+

Copy-and-paste operation is initiated by a long press on the source widget and performed by a drag and drop operation. The following user actions are supported:

+
    +
  • long press on the source widget - the hover window is shown and the text is copied from the source widget to the clipboard and pasted from the clipboard to the hover window;
  • +
  • drag the hover window - the hover window follows the mouse pointer;
  • +
  • drop to the sink widget - the text is cut from the hover window to the clipboard and pasted from the clipboard to the sink widget. The hover window is hidden.
  • +
+ +

Figure: Widget layout structure

+

+ Widget layout structure +

+ +

Implementation

+

The controller_application_view_create() + function in controller module is responsible for calling view creation specific routines. Also, it attaches all necessary touch (mouse) callbacks. +

+ +
+bool
+controller_application_view_create(void)
+{
+	char full_path_source_extension[FILE_PATH_MAX_LEN] = {0,};
+	char full_path_sink_image[FILE_PATH_MAX_LEN] = {0,};
+
+	_resource_path_compile(SOURCE_THEME_EXTENSION, full_path_source_extension);
+	_resource_path_compile(SINK_IMAGE, full_path_sink_image);
+
+
+	if(!main_window_create())
+	{
+		dlog_print(DLOG_ERROR, LOG_TAG,"View creation failed: on window handle");
+		return false;
+	}
+	if(!main_window_source_wgt_create(full_path_source_extension))
+	{
+		dlog_print(DLOG_ERROR, LOG_TAG,"View creation failed: on source widget");
+		return false;
+	}
+	if(!main_window_sink_entry_wgt_create(full_path_sink_image))
+	{
+		dlog_print(DLOG_ERROR, LOG_TAG,"View creation failed: on sink widget");
+		return false;
+	}
+	if(!main_window_hover_create(full_path_source_extension))
+	{
+		dlog_print(DLOG_ERROR, LOG_TAG,"View creation failed: on hover");
+		return false;
+	}
+
+	_attach_callbacks();
+
+	dlog_print(DLOG_DEBUG, LOG_TAG,"View creation successful");
+
+	return true;
+}
+
+
+ +
+static void
+_attach_callbacks(void)
+{
+	ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, _press_cb, NULL);
+	ecore_event_handler_add(ECORE_EVENT_MOUSE_MOVE, _move_cb, NULL);
+	ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_UP, _unpress_cb, NULL);
+}
+
+ +

Each time user touches the screen + _press_cb() + is called with a hit test. If the hit is in source region, hover window is shown. It uses + evas_object_show() +internally. +

+ +
+static Eina_Bool
+_press_cb(void *data, int type, void *event)
+{
+	Ecore_Event_Mouse_Button *press = (Ecore_Event_Mouse_Button *)event;
+
+				...
+
+	//state test && hit test:
+	if(!(s_controller_data.state == CONTROLLER_STATE_NORMAL &&
+		main_window_source_wgt_hit_test(press->root.x, press->root.y))
+	)
+	{
+		return EINA_TRUE;
+	}
+
+	//paste text from clipboard to hover:
+	main_window_hover_text_paste();
+
+				...
+
+	hover_window_coordinates_set(press->root.x, press->root.y);
+	hover_window_show();
+
+	return EINA_TRUE;
+}
+
+ +

The hover window drag is implemented in controller module's + _move_cb() + function. It is responsible for changing the window's position and uses +evas_object_move() + internally. +

+
+static Eina_Bool
+_move_cb(void *data, int type, void *event)
+{
+	Ecore_Event_Mouse_Move *move = (Ecore_Event_Mouse_Move *)event;
+
+				...
+
+	hover_window_coordinates_set(move->root.x, move->root.y);
+
+	return EINA_TRUE;
+}
+
+ +

The clipboard mechanism is used to copy the text from the source to the hover window.

+ +
+void
+hover_window_text_paste(const char * text_to_paste)
+{
+	//We could just use elm_object_text_set, but for example purpose let's use cnp mechanism:
+
+	//use copy mechanism, fill copy buffer associated with the label:
+	elm_cnp_selection_set(s_view_data.label, ELM_SEL_TYPE_PRIMARY, ELM_SEL_FORMAT_TEXT, text_to_paste, strlen(text_to_paste));
+
+	//get the text from the clipboard and since
+	// we use 'Label' widget type, we have to use custom drop callback: _text_paste_cb
+	elm_cnp_selection_get(s_view_data.label, ELM_SEL_TYPE_PRIMARY, ELM_SEL_FORMAT_TEXT, _text_paste_cb, NULL);
+}
+
+ +

When user releases the mouse or touch, + _unpress_cb() + is called with a hit test. It checks whether the finger/cursor is in the sink widget area. +

+ +
+static Eina_Bool
+_unpress_cb(void *data, int type, void *event)
+{
+	Ecore_Event_Mouse_Button *unpress = (Ecore_Event_Mouse_Button *)event;
+
+			...
+
+	hover_window_hide();
+
+	//state && hit test
+	if(s_controller_data.state == CONTROLLER_STATE_DRAG &&
+		main_window_sink_wgt_hit_test(unpress->root.x, unpress->root.y)
+	)
+	{
+		main_window_sink_wgt_text_paste();
+	}
+
+			...
+}
+
+ +

After that the clipboard mechanism is used again to copy the text to the sink widget.

+ +
+void
+sink_wgt_text_paste(Evas_Object *wgt)
+{
+	//use paste mechanism:
+	//sink widget is of 'Entry' type so callback can be NULL:
+	elm_cnp_selection_get(wgt, ELM_SEL_TYPE_PRIMARY, ELM_SEL_FORMAT_TEXT, NULL, NULL);
+}
+
+ + + +
+ +Go to top + + + + + + + diff --git a/org.tizen.sampledescriptions/html/mobile_n/sd_mn.htm b/org.tizen.sampledescriptions/html/mobile_n/sd_mn.htm index b5316c4..8847f50 100644 --- a/org.tizen.sampledescriptions/html/mobile_n/sd_mn.htm +++ b/org.tizen.sampledescriptions/html/mobile_n/sd_mn.htm @@ -75,6 +75,10 @@ Demonstrates how you can manage contacts. + Copy And Paste + Demonstrates how you can incorporate copy/cut/paste mechanism into an EFL based application. + + Data-Control-Consumer Demonstrates how to implement Data-Control-Consumer application using both sql and map methods.