Многие из Вас видели в стандартных транзакциях кнопки расположенные в заголовке экрана:
Для того чтобы иметь возможность располагать GUI элементы в заголовке есть специальный контейнер называется он cl_gui_gos_container. Пример работы с ним далее.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
DATA: go_toolbar TYPE REF TO cl_gui_toolbar, go_container TYPE REF TO cl_gui_gos_container, gv_icon TYPE iconname, gv_quick TYPE iconquick, gt_event TYPE cntl_simple_events, gs_event TYPE cntl_simple_event. CLASS lcl_handle_event DEFINITION DEFERRED. DATA tool_event TYPE REF TO lcl_handle_event. * CLASS lcl_handle_event DEFINITION. PUBLIC SECTION. METHODS: on_dropdown_clicked FOR EVENT dropdown_clicked OF cl_gui_toolbar IMPORTING fcode posx posy. METHODS: on_function_selected FOR EVENT function_selected OF cl_gui_toolbar IMPORTING fcode. ENDCLASS. "lcl_handle_event DEFINITION * CLASS lcl_handle_event IMPLEMENTATION. METHOD on_dropdown_clicked. DATA: my_menu TYPE REF TO cl_ctmenu, sub_menu TYPE REF TO cl_ctmenu. CREATE OBJECT my_menu. CASE fcode. WHEN 'MY_MENU'. my_menu->add_function( fcode = 'OPTION1' text = 'Do something...1' ). my_menu->add_function( fcode = 'OPTION2' text = 'Do something...2' ). my_menu->add_function( fcode = 'OPTION3' text = 'Do something...3' ). my_menu->add_separator( ). * Create sub menu CREATE OBJECT sub_menu. sub_menu->add_function( fcode = 'SUB1' text = 'Do something...1' ). sub_menu->add_function( fcode = 'SUB2' text = 'Do something...2' ). *-- Add sub menu to the context menu my_menu->add_submenu( menu = sub_menu text = 'Do something else.....' ). WHEN 'MY_MENU2'. my_menu->add_function( fcode = 'OPTION21' text = 'Do something crazy' ). my_menu->add_function( fcode = 'OPTION22' text = 'Do something funny' ). ENDCASE. CALL METHOD go_toolbar->track_context_menu EXPORTING context_menu = my_menu posx = posx posy = posy. ENDMETHOD. "ON_DROPDOWN_CLICKED METHOD on_function_selected. CASE fcode. WHEN 'MY_MENU'. MESSAGE i208(00) WITH 'Press on Icon Plane'. WHEN 'MY_MENU2'. MESSAGE i208(00) WITH 'Press on Icon Truck'. WHEN 'OPTION1'. MESSAGE i208(00) WITH 'Option 1'. WHEN 'OPTION2'. MESSAGE i208(00) WITH 'Option 2'. WHEN 'OPTION3'. MESSAGE i208(00) WITH 'Option 3'. WHEN 'SUB1'. MESSAGE i208(00) WITH 'Sub Option 1'. WHEN 'SUB2'. MESSAGE i208(00) WITH 'Sub Option 2'. WHEN 'OPTION21'. MESSAGE i208(00) WITH 'Option 2/1'. WHEN 'OPTION22'. MESSAGE i208(00) WITH 'Option 2/2'. ENDCASE. ENDMETHOD. "ON_FUNCTION_SELECTED ENDCLASS. "lcl_handle_event IMPLEMENTATION START-OF-SELECTION. CREATE OBJECT go_container EXPORTING width = 160 no_autodef_progid_dynnr = 'X' EXCEPTIONS OTHERS = 5. CHECK sy-subrc = 0. CREATE OBJECT go_toolbar EXPORTING parent = go_container. CALL FUNCTION 'ICON_CREATE' EXPORTING name = 'ICON_WS_PLANE' add_stdinf = space IMPORTING RESULT = gv_icon EXCEPTIONS OTHERS = 0. gv_quick = 'New Menu'. CALL METHOD go_toolbar->add_button EXPORTING fcode = 'MY_MENU' icon = gv_icon butn_type = 1 quickinfo = gv_quick. CLEAR gv_icon. gv_quick = 'New Menu 2'. CALL FUNCTION 'ICON_CREATE' EXPORTING name = 'ICON_TRANSPORT' add_stdinf = space IMPORTING RESULT = gv_icon EXCEPTIONS OTHERS = 0. CALL METHOD go_toolbar->add_button EXPORTING fcode = 'MY_MENU2' icon = gv_icon butn_type = 1 text = 'Go on!' quickinfo = gv_quick. CLEAR gt_event. gs_event-eventid = cl_gui_toolbar=>m_id_function_selected. gs_event-appl_event = space. APPEND gs_event TO gt_event. gs_event-eventid = cl_gui_toolbar=>m_id_dropdown_clicked. gs_event-appl_event = space. APPEND gs_event TO gt_event. CALL METHOD go_toolbar->set_registered_events EXPORTING events = gt_event. CREATE OBJECT tool_event. SET HANDLER tool_event->on_dropdown_clicked FOR go_toolbar. SET HANDLER tool_event->on_function_selected FOR go_toolbar. WRITE 'Hello'. |
Результат: