ABAP Control Framework(8): Toolbar
8.Toolbar
使用cl_gui_toolbar類,創建顯示一個toolbar。
示例:
"事件處理類 CLASS c_event_handler DEFINITION. PUBLIC SECTION. CLASS-METHODS:m_function_sel FOR EVENT function_selected OF cl_gui_toolbar IMPORTING fcode. CLASS-METHODS:m_dropdown_clk FOR EVENT dropdown_clicked OF cl_gui_toolbar IMPORTING fcode posx posy. ENDCLASS. CLASS c_event_handler IMPLEMENTATION. METHOD:m_function_sel. DATA:lv_str TYPE string. lv_str = 'fcode:' && fcode. MESSAGE lv_str TYPE 'I'. ENDMETHOD. METHOD:m_dropdown_clk. DATA:lv_str TYPE string. lv_str = 'fcode:' && fcode && 'posx:' && posx && 'posy:' && posy. MESSAGE lv_str TYPE 'I'. ENDMETHOD. ENDCLASS. CLASS c7 DEFINITION. PUBLIC SECTION. DATA:lo_toolbar TYPE REF TO cl_gui_toolbar. DATA:lo_menu TYPE REF TO cl_ctmenu. DATA:lt_button TYPE ttb_button. DATA:ls_button LIKE LINE OF lt_button. DATA:lt_menu TYPE ttb_btnmnu. DATA:ls_menu LIKE LINE OF lt_menu. DATA:lt_events TYPE cntl_simple_events. DATA:ls_events TYPE cntl_simple_event. METHODS:m_init_toolbar. METHODS:m_creat_button. METHODS:m_del_button. METHODS:m_set_button. METHODS:m_set_menu. ENDCLASS. CLASS c7 IMPLEMENTATION. METHOD:m_init_toolbar. CREATE OBJECT lo_toolbar EXPORTING parent = cl_gui_container=>default_screen. "註冊事件 ls_events-eventid = cl_gui_toolbar=>m_id_function_selected. ls_events-appl_event = ''. APPEND ls_events TO lt_events. ls_events-eventid = cl_gui_toolbar=>m_id_dropdown_clicked. ls_events-appl_event = ''. APPEND ls_events TO lt_events. lo_toolbar->set_registered_events( EXPORTING events = lt_events ). SET HANDLER c_event_handler=>m_function_sel FOR lo_toolbar. SET HANDLER c_event_handler=>m_dropdown_clk FOR lo_toolbar. me->m_creat_button( ). me->m_set_menu( ). ENDMETHOD. METHOD:m_creat_button. "設置按鈕,按鈕類型 "cntb_btype_button : Pushbutton "cntb_btype_dropdown : Pushbutton with menu "cntb_btype_menu : Menu "cntb_btype_sep : Separator "cntb_btype_group : Pushbutton group "cntb_btype_check : Toggle button ls_button-function = 'FUNC1'. ls_button-icon = '@B1@'. ls_button-disabled = ''. ls_button-butn_type = cntb_btype_button. ls_button-text = '按鈕1'. ls_button-quickinfo = 'button 1'. ls_button-checked = ''. APPEND ls_button TO lt_button. CLEAR ls_button. ls_button-butn_type = cntb_btype_sep. APPEND ls_button TO lt_button. CLEAR ls_button. ls_button-function = 'MENU1'. ls_button-icon = '@B2@'. ls_button-butn_type = cntb_btype_dropdown. ls_button-text = 'menu1'. APPEND ls_button TO lt_button. CLEAR ls_button. ls_button-function = 'MENU2'. ls_button-icon = '@B3@'. ls_button-butn_type = cntb_btype_menu. ls_button-text = 'menu2'. APPEND ls_button TO lt_button. CLEAR ls_button. ls_button-function = 'GROUP1'. ls_button-icon = '@B4@'. ls_button-butn_type = cntb_btype_group. ls_button-text = 'group1'. APPEND ls_button TO lt_button. CLEAR ls_button. ls_button-function = 'CHECK1'. ls_button-icon = '@B5@'. ls_button-butn_type = cntb_btype_check. ls_button-text = 'check1'. APPEND ls_button TO lt_button. "設置單個按鈕 * lo_toolbar->add_button( * EXPORTING * fcode = 'FUNC2' * icon = '@B2@' * is_disabled = '' * butn_type = cntb_btype_button * text = '按鈕2' * quickinfo = 'button 2' * is_checked = '' * ). * "設置按鈕table * lo_toolbar->fill_buttons_data_table( * EXPORTING * fcode = 'GRP1' * icon = '@B3@' * butn_type = cntb_btype_group * text = 'group1' * quickinfo = 'group 1' * CHANGING * data_table = lt_button * ). "通過table,設置多個按鈕 lo_toolbar->add_button_group( EXPORTING data_table = lt_button ). ENDMETHOD. METHOD m_del_button. "刪除指定按鈕 lo_toolbar->delete_button( EXPORTING fcode = '' ). "刪除所有按鈕 lo_toolbar->delete_all_buttons( ). ENDMETHOD. METHOD m_set_button. "設置button狀態 lo_toolbar->set_button_state( EXPORTING enabled = '' checked = '' fcode = '' ). "設置按鈕info lo_toolbar->set_button_info( EXPORTING fcode = '' icon = '' text = '' quickinfo = '' ). ENDMETHOD. METHOD m_set_menu. DATA:lo_sub_menu TYPE REF TO cl_ctmenu. CREATE OBJECT lo_sub_menu. lo_sub_menu->add_function( EXPORTING fcode = 'SUBM1' text ='sub func1' icon = '@B5@' ftype = '' disabled = '' hidden = '' checked = '' ). lo_sub_menu->add_function( EXPORTING fcode = 'SUBM2' text ='sub func2' icon = '@B6@' ftype = '' disabled = '' hidden = '' checked = '' ). "設置menu CREATE OBJECT lo_menu. lo_menu->add_function( EXPORTING fcode = 'MFUNC1' text ='menu func1' icon = '@B4@' ftype = '' disabled = '' hidden = '' checked = '' ). lo_menu->add_submenu( EXPORTING menu = lo_sub_menu text = 'Sub Menu' ). ls_menu-function = 'MENU1'. ls_menu-ctmenu = lo_menu. APPEND ls_menu TO lt_menu. ls_menu-function = 'MENU2'. ls_menu-ctmenu = lo_sub_menu. APPEND ls_menu TO lt_menu. "設置單個menu * lo_toolbar->set_static_ctxmenu( * EXPORTING * fcode = '' * ctxmenu = '' * ). lo_toolbar->assign_static_ctxmenu_table( EXPORTING table_ctxmenu = lt_menu ). ENDMETHOD. ENDCLASS. START-OF-SELECTION. PERFORM f_show_toolbar. FORM f_show_toolbar. DATA:lo_c7 TYPE REF TO c7. CREATE OBJECT lo_c7. WRITE:/ '1'. lo_c7->m_init_toolbar( ). ENDFORM.
本文来自博客园,作者:渔歌晚唱,转载请注明原文链接:https://www.cnblogs.com/tangToms/p/14766236.html