定义类
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
on_context_menu
FOR EVENT context_menu OF cl_gui_picture
IMPORTING sender,
on_context_menu_selected
FOR EVENT context_menu_selected OF cl_gui_picture
IMPORTING fcode sender.
ENDCLASS. "lcl_event_handler DEFINITION
CLASS lcl_event_handler IMPLEMENTATION.
METHOD on_context_menu.“定义右击内容
DATA:l_it_functions TYPE ui_functions, " optional part
l_wa_func LIKE LINE OF l_it_functions. " optional part
DATA:l_ref_menu TYPE REF TO cl_ctmenu.
* 也可以自定义一个状态,再调用
* CALL METHOD l_ref_menu->load_gui_status
* EXPORTING
* program = sy-cprog
* status = '001'
** DISABLE =
* menu = l_ref_menu
* EXCEPTIONS
* OTHERS = 1.
CREATE OBJECT l_ref_menu.
CALL METHOD l_ref_menu->add_function
EXPORTING
fcode = 'NORMAL'
text = 'NORMAL'.
CALL METHOD l_ref_menu->add_function
EXPORTING
fcode = 'NORMAL_CENTER'
text = 'NORMAL_CENTER'.
CALL METHOD l_ref_menu->add_function
EXPORTING
fcode = 'STRETCH'
text = 'STRETCH'.
CALL METHOD l_ref_menu->add_function
EXPORTING
fcode = 'FIT'
text = 'FIT'.
CALL METHOD l_ref_menu->add_function
EXPORTING
fcode = 'FIT_CENTER'
text = 'FIT_CENTER'.
CALL METHOD sender->display_context_menu
EXPORTING
context_menu = l_ref_menu
EXCEPTIONS
OTHERS = 1.
ENDMETHOD. "on_context_menu
METHOD on_context_menu_selected.”实现方法
CASE fcode.
WHEN 'STRETCH'. "
CALL METHOD sender->set_display_mode
EXPORTING
display_mode = cl_gui_picture=>display_mode_stretch
EXCEPTIONS
OTHERS = 1.
WHEN 'NORMAL'. "
CALL METHOD sender->set_display_mode
EXPORTING
display_mode = cl_gui_picture=>display_mode_normal
EXCEPTIONS
OTHERS = 1.
WHEN 'NORMAL_CENTER'.
CALL METHOD sender->set_display_mode
EXPORTING
display_mode = cl_gui_picture=>display_mode_normal_center
EXCEPTIONS
OTHERS = 1.
WHEN 'FIT'.
CALL METHOD sender->set_display_mode
EXPORTING
display_mode = cl_gui_picture=>display_mode_fit
EXCEPTIONS
OTHERS = 1.
WHEN 'FIT_CENTER'.
CALL METHOD sender->set_display_mode
EXPORTING
display_mode = cl_gui_picture=>display_mode_fit_center
EXCEPTIONS
OTHERS = 1.
ENDCASE.
ENDMETHOD. "on_context_menu_selected
ENDCLASS. "lcl_event_handler IMPLEMETATION
最后再调用这个方法:
IF my_container IS INITIAL.
CREATE OBJECT my_container
EXPORTING
container_name = 'CONTROL_AREA1'
EXCEPTIONS
OTHERS = 1.
wa_events-eventid = cl_gui_picture=>eventid_context_menu.
wa_events-appl_event = ' '.
INSERT wa_events INTO TABLE it_events.
wa_events-eventid = cl_gui_picture=>eventid_context_menu_selected.
wa_events-appl_event = ' '.
INSERT wa_events INTO TABLE it_events.
CALL METHOD ref_pic_left->set_registered_events
EXPORTING
events = it_events
EXCEPTIONS
OTHERS = 1.
* send envent table for picture in right cell to cfw
CALL METHOD ref_pic_right->set_registered_events
EXPORTING
events = it_events
EXCEPTIONS
OTHERS = 1.
SET HANDLER lcl_event_handler=>on_context_menu FOR ref_pic_left.
SET HANDLER lcl_event_handler=>on_context_menu_selected
FOR ref_pic_left.
SET HANDLER lcl_event_handler=>on_context_menu FOR ref_pic_right.
SET HANDLER lcl_event_handler=>on_context_menu_selected
FOR ref_pic_right.
ENDIF.