二,定义 container_1 以及 PIC_CON。代码如下:
event_handler_context_menu以及 class event_receiver1 definition.
public section.
methods event_handler_picture_dblclick
for event picture_dblclick of cl_gui_picture
importing mouse_pos_x mouse_pos_y sender.
methods event_handler_context_menu
for event context_menu of cl_gui_picture
importing sender.
methods event_handler_context_menu_sel
for event context_menu_selected of cl_gui_picture
importing fcode sender.
endclass. "event_receiver DEFINITION
四,实现class中定义的方法。在方法 cl_ctmenu的实例menu,然后调用menu的 DISPLAY_CONTEXT_MENU方法显示context menu 。在方法 SET_DISPLAY_MODE方法来对图片进行拉伸或者正常显示处理。在方法 class event_receiver1 IMPLEMENTATION.
METHOD event_handler_picture_dblclick.
* for event picture_dblclick of c_picture_control
* importing mouse_pos_x mouse_pos_y.
DATA pos_x(5) type c.
DATA pos_y(5) type c.
pos_x = mouse_pos_x.
pos_y = mouse_pos_y.
IF SENDER = PIC_CON.
MESSAGE I000(0K) WITH
'DoubleClick' 'Upper Picture' POS_X POS_Y. "#EC NOTEXT
endif.
endmethod. "event_handler_picture_dblclick
method event_handler_context_menu.
DATA menu type REF TO cl_ctmenu.
CREATE OBJECT menu.
CALL METHOD menu->ADD_FUNCTION
EXPORTING
FCODE = 'NORMAL'TEXT = 'NORMAL'* ICON =
* FTYPE =
* DISABLED =
* HIDDEN =
* CHECKED =
* ACCELERATOR =
.
CALL METHOD menu->ADD_FUNCTION
EXPORTING
FCODE = 'STRETCH'TEXT = 'STRETCH'* ICON =
* FTYPE =
* DISABLED =
* HIDDEN =
* CHECKED =
* ACCELERATOR =
.
CALL METHOD sender->DISPLAY_CONTEXT_MENU
EXPORTING
CONTEXT_MENU = menu
* EXCEPTIONS
* ERROR = 1
* others = 2
.
endmethod. "event_handler_picture_dblclick
method event_handler_context_menu_sel.
if fcode = 'STRETCH'.CALL METHOD PIC_CON->SET_DISPLAY_MODE
EXPORTING
DISPLAY_MODE = CL_GUI_PICTURE=>DISPLAY_MODE_STRETCH.
endif.
if fcode = 'NORMAL'.CALL METHOD PIC_CON->SET_DISPLAY_MODE
EXPORTING
DISPLAY_MODE = CL_GUI_PICTURE=>DISPLAY_MODE_NORMAL.
endif.
endmethod. "event_handler_context_menu_sel
ENDCLASS. "event_receiver IMPLEMENTATION
五,定义 cntl_simple_events和 data url type cndp_url.
data event_receiver TYPE REF TO event_receiver1.
data event_tab type cntl_simple_events.
data event_tab_line type cntl_simple_event.
六,在PBO的module中创建custom container以及 LOAD_PICTURE_FROM_URL_ASYNC方法显示图片,并进行事件注册。具体代码为:
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'MAIN0001'.* SET TITLEBAR 'xxx'.
IF PIC_CON IS INITIAL.
CREATE OBJECT container_1
exporting container_name = 'PIC_CON'.CREATE OBJECT PIC_CON exporting parent = container_1.
CALL FUNCTION 'DP_PUBLISH_WWW_URL'EXPORTING
OBJID = 'HTMLCNTL_TESTHTM2_SAP_AG'
LIFETIME = cndp_lifetime_transactionIMPORTING
URL = url
EXCEPTIONS
OTHERS = 1.* Load the picture by using the url generated by the data provider.
if sy-subrc = 0.CALL METHOD PIC_CON->LOAD_PICTURE_FROM_URL_ASYNC
EXPORTING
url = url.
endif.
EVENT_TAB_LINE-EVENTID = CL_GUI_PICTURE=>EVENTID_PICTURE_DBLCLICK.
append EVENT_TAB_LINE to EVENT_TAB.
EVENT_TAB_LINE-EVENTID = CL_GUI_PICTURE=>EVENTID_CONTEXT_MENU.
append EVENT_TAB_LINE to EVENT_TAB.
EVENT_TAB_LINE-EVENTID = CL_GUI_PICTURE=>EVENTID_CONTEXT_MENU_SELECTED.
append EVENT_TAB_LINE to EVENT_TAB.
CALL METHOD PIC_CON->SET_REGISTERED_EVENTS
EXPORTING
EVENTS = event_tab.
create object event_receiver.
set handler event_receiver->event_handler_picture_dblclick
FOR PIC_CON.
set handler event_receiver->event_handler_context_menu
FOR PIC_CON.
set handler event_receiver->event_handler_context_menu_sel
FOR PIC_CON.
EndIF.
ENDMODULE. " STATUS_0100 OUTPUT
ok.大功告成,可以F8了!