zoukankan      html  css  js  c++  java
  • SAP HTLM Control

    HTML 事件

    效果

    代码

    *&---------------------------------------------------------------------*
    *& Report SAPHTML_EVENTS_DEMO                                          *
    *&---------------------------------------------------------------------*
    REPORT  saphtml_events_demo.
    
    DATA: html_control TYPE REF TO cl_gui_html_viewer,
              my_container TYPE REF TO cl_gui_custom_container,
          prog_repid LIKE sy-repid,                             "#EC NEEDED
          edurl(2048),
          edframe(255),
          edaction(256),
          edgetdata(2048),
          edpostdataline(1024),
          ok_code LIKE sy-ucomm,
          myevent_tab TYPE cntl_simple_events,
          myevent TYPE cntl_simple_event,
          postdata_tab TYPE cnht_post_data_tab,
          edquery_table TYPE cnht_query_table.                  "#EC NEEDED
    
    
    *****************************************************
    *              CLASS cl_myevent_handler             *
    *****************************************************
    CLASS cl_myevent_handler DEFINITION.
    
      PUBLIC SECTION.
        METHODS: on_sapevent
                   FOR EVENT sapevent OF cl_gui_html_viewer
                     IMPORTING action frame getdata postdata query_table.
    
    ENDCLASS.
    
    SET SCREEN 100.
    
    DATA: evt_receiver TYPE REF TO cl_myevent_handler.
    
    * CLASS CL_GUI_CFW DEFINITION LOAD.
    
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'TESTHTM1'.
      SET TITLEBAR '001'.
    
      IF html_control IS INITIAL.
        prog_repid = sy-repid.
    
        CREATE OBJECT my_container
            EXPORTING
                container_name = 'HTML_CONTROL'.
    
        CREATE OBJECT html_control
             EXPORTING
                  parent    = my_container.
        IF sy-subrc NE 0.
    *
        ENDIF.
    
    * register event
        myevent-eventid = html_control->m_id_sapevent.
        myevent-appl_event = 'x'.
        APPEND myevent TO myevent_tab.
        CALL METHOD html_control->set_registered_events
            EXPORTING
               events = myevent_tab.
    
        CREATE OBJECT evt_receiver.
    
        SET HANDLER evt_receiver->on_sapevent
                    FOR html_control.
    
        PERFORM load_graphics.
        PERFORM load_home_page.
      ENDIF.
    ENDMODULE.                             " STATUS_0100  OUTPUT
    
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    MODULE user_command_0100 INPUT.
      CASE ok_code.
        WHEN 'BACK'.                       "Beenden
          IF NOT html_control IS INITIAL.
            CALL METHOD html_control->free.
            FREE html_control.
          ENDIF.
          LEAVE TO SCREEN 0.
    
        WHEN 'HHOM'.                       " show the home page
          PERFORM load_home_page.
    
        WHEN 'HBAK'.
          CALL METHOD html_control->go_back.
    
        WHEN 'HFWD'.
          CALL METHOD html_control->go_forward.
    
        WHEN 'HRFR'.
          CALL METHOD html_control->do_refresh.
    
        WHEN OTHERS.
          CALL METHOD cl_gui_cfw=>dispatch.
      ENDCASE.
      CLEAR ok_code.
    ENDMODULE.                             " USER_COMMAND_0100  INPUT
    
    
    *&---------------------------------------------------------------------*
    *&      Form  LOAD_HOME_PAGE
    *&---------------------------------------------------------------------*
    FORM load_home_page.
      DATA: doc_url(80).
    
      CALL METHOD html_control->load_html_document
           EXPORTING
                document_id  = 'SAPHTML_EVENTS_DEMO_HOME'
           IMPORTING
                assigned_url = doc_url
           EXCEPTIONS
                OTHERS       = 1.
    
      IF sy-subrc EQ 0.
        CALL METHOD html_control->show_url
             EXPORTING
                  url = doc_url.
      ENDIF.
    ENDFORM.                               " LOAD_HOME_PAGE
    
    
    *&---------------------------------------------------------------------*
    *&      Form  LOAD_FRAME_SET
    *&---------------------------------------------------------------------*
    FORM load_frame_set.
      DATA: doc_url(80).
    
      CALL METHOD html_control->load_html_document
           EXPORTING
                document_id  = 'SAPHTML_EVENTS_DEMO_FRAME1'
                document_url = 'HTMLFrame1.htm'
           EXCEPTIONS
                OTHERS       = 1.
    
      CALL METHOD html_control->load_html_document
           EXPORTING
                document_id  = 'SAPHTML_EVENTS_DEMO_HOME'
                document_url = 'HTMLFrame2.htm'
           EXCEPTIONS
                OTHERS       = 1.
    
      CALL METHOD html_control->load_html_document
           EXPORTING
                document_id  = 'SAPHTML_EVENTS_DEMO_FRAMESET'
           IMPORTING
                assigned_url = doc_url
           EXCEPTIONS
                OTHERS       = 1.
    
      IF sy-subrc EQ 0.
        CALL METHOD html_control->show_url
             EXPORTING
                  url = doc_url.
      ENDIF.
    ENDFORM.                               " LOAD_FRAME_SET
    
    
    *&---------------------------------------------------------------------*
    *&      Form  LOAD_GRAPHICS
    *&---------------------------------------------------------------------*
    FORM load_graphics.
      CALL METHOD html_control->load_mime_object
         EXPORTING
              object_id  = 'HTMLCNTL_TESTHTM2_SAPLOGO'
              object_url = 'SAPLOGO.GIF'
         EXCEPTIONS
              OTHERS     = 1.
      CALL METHOD html_control->load_mime_object
           EXPORTING
                object_id  = 'HTMLCNTL_TESTHTM2_SAP_AG'
                object_url = 'SAP_AG.GIF'
           EXCEPTIONS
                OTHERS     = 1.
      CALL METHOD html_control->load_mime_object
           EXPORTING
                object_id  = 'HTMLCNTL_TESTHTM2_BACKGROUND'
                object_url = 'HOME_BACKGROUND.GIF'
           EXCEPTIONS
                OTHERS     = 1.
    ENDFORM.                               " LOAD_GRAPHICS
    
    ****************************************************
    *    cl_myevent_handler implementation             *
    ****************************************************
    CLASS cl_myevent_handler IMPLEMENTATION.
    
      METHOD on_sapevent.
    
        CLEAR edaction.
        CLEAR edframe.
        CLEAR edgetdata.
        CLEAR edpostdataline.
    
        edaction       = action.
        edframe        = frame.
        edgetdata      = getdata.
        postdata_tab   = postdata.
        IF NOT postdata_tab IS INITIAL.
          READ TABLE postdata_tab INDEX 1 INTO edpostdataline.
        ENDIF.
        edquery_table  = query_table.
    
        CASE action.
          WHEN 'SHOW_FRAMESET'.
            PERFORM load_frame_set.
          WHEN OTHERS.
        ENDCASE.
      ENDMETHOD.
    
    ENDCLASS.

    屏幕

    PBO

    *&---------------------------------------------------------------------*
    *& Report  RSDEMO_HTML_VIEWER                                          *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    *&                                                                     *
    *&                                                                     *
    *&---------------------------------------------------------------------*
    
    REPORT  rsdemo_html_viewer            .
    DATA container TYPE REF TO cl_gui_custom_container.
    DATA html_viewer TYPE REF TO cl_gui_html_viewer.
    
    DATA ok_code TYPE sy-ucomm.
    DATA init.
    DATA  save_ok TYPE sy-ucomm.
    DATA  url(255) VALUE 'HTTP://WWW.SAP-AG.DE'.
    DATA frame(255).
    DATA  align TYPE i.
    DATA  document_id(255) VALUE 'HTMLCNTL_TESTEVNT_HOME'.
    DATA  document_textpool TYPE sy-repid.
    DATA document_url(255).
    DATA assigned_url(255).
    DATA merge_table TYPE swww_t_merge_table.
    DATA  object_id(255) VALUE 'HTMLCNTL_TESTHTM2_SAPLOGO'.
    DATA object_url(255) VALUE 'SAPLOGO.GIF'.
    DATA  type(4) VALUE 'text'.
    DATA subtype(4) VALUE 'html'.
    DATA size TYPE i.
    DATA data_table TYPE c OCCURS 0.
    
    SET SCREEN 100.
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS'.
      IF init is initial.
        CREATE OBJECT container
                EXPORTING container_name = 'CUSTOM'.
        CREATE OBJECT html_viewer
                EXPORTING  parent              = container
                EXCEPTIONS cntl_error         = 1
                           cntl_install_error = 2
                           dp_install_error   = 3
                           dp_error           = 4.
        IF sy-subrc ne 0.
    * Fehlerbehandlung
        ENDIF.
        CALL METHOD cl_gui_cfw=>flush
             EXCEPTIONS cntl_system_error = 1
                        cntl_error        = 2.
        IF sy-subrc ne 0.
    * Fehlerbehandlung
        ENDIF.
        init = 'X'.
      ENDIF.
    ENDMODULE.                             " STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE user_command_0100 INPUT.
      save_ok = ok_code.
      CLEAR ok_code.
      CASE save_ok.
        WHEN 'SHOW_URL'.
          CALL METHOD html_viewer->show_url
                    EXPORTING url   = url
                              frame = frame
                    EXCEPTIONS cntl_error = 1.
        WHEN 'STOP'.
          CALL METHOD html_viewer->stop
                    EXCEPTIONS cntl_error = 1.
        WHEN 'GO_BACK'.
          CALL METHOD html_viewer->go_back
                    EXCEPTIONS cntl_error = 1.
        WHEN 'GO_FORWARD'.
          CALL METHOD html_viewer->go_forward
                    EXCEPTIONS cntl_error = 1.
        WHEN 'GO_HOME'.
          CALL METHOD html_viewer->go_home
                    EXCEPTIONS cntl_error = 1.
        WHEN 'DO_REFRESH'.
          CALL METHOD html_viewer->do_refresh
                    EXCEPTIONS cntl_error = 1.
        WHEN 'GET_CURRENT_URL'.
          CALL METHOD html_viewer->get_current_url
                    IMPORTING url = url
                    EXCEPTIONS cntl_error = 1.
          call method cl_gui_cfw=>flush
                    exceptions cntl_error = 1
                               cntl_system_error = 2.
        WHEN 'LOAD_DATABASE'.
          CALL METHOD html_viewer->load_html_document
               EXPORTING document_id       = 'HTMLCNTL_TESTHTM2_FRAME1'
    *                    document_textpool = document_textpool
                         document_url      = 'HTMLFrame1.htm'
    *          IMPORTING assigned_url      = assigned_url
    *          CHANGING  merge_table       = merge_table
               EXCEPTIONS document_not_found   = 1
                          dp_error_general     = 2
                          dp_invalid_parameter = 3.
          CALL METHOD html_viewer->load_html_document
               EXPORTING document_id       = 'HTMLCNTL_TESTEVNT_HOME'
    *                    document_textpool = document_textpool
                         document_url      = 'HTMLFrame2.htm'
    *          IMPORTING assigned_url      = assigned_url
    *          CHANGING  merge_table       = merge_table
               EXCEPTIONS document_not_found   = 1
                          dp_error_general     = 2
                          dp_invalid_parameter = 3.
          CALL METHOD html_viewer->load_html_document
               EXPORTING document_id       = 'HTMLCNTL_TESTHTM2_FRAMESET'
    *                    document_textpool = document_textpool
    *                    document_url      = document_url
               IMPORTING assigned_url      = assigned_url
    *          CHANGING  merge_table       = merge_table
               EXCEPTIONS document_not_found   = 1
                          dp_error_general     = 2
                          dp_invalid_parameter = 3.
          CALL METHOD html_viewer->load_mime_object
             EXPORTING
                  object_id  = 'HTMLCNTL_TESTHTM2_SAPLOGO'
                  object_url = 'SAPLOGO.GIF'
    *           IMPORTING assigned_url = assigned_url
                    EXCEPTIONS object_not_found     = 1
                               dp_error_general     = 2
                               dp_invalid_parameter = 3.
          CALL METHOD html_viewer->load_mime_object
               EXPORTING
                    object_id  = 'HTMLCNTL_TESTHTM2_SAP_AG'
                    object_url = 'SAP_AG.GIF'
    *           IMPORTING assigned_url = assigned_url
                    EXCEPTIONS object_not_found     = 1
                               dp_error_general     = 2
                               dp_invalid_parameter = 3.
          CALL METHOD html_viewer->load_mime_object
               EXPORTING
                    object_id  = 'HTMLCNTL_TESTHTM2_BACKGROUND'
                    object_url = 'HOME_BACKGROUND.GIF'
    *           IMPORTING assigned_url = assigned_url
                    EXCEPTIONS object_not_found     = 1
                               dp_error_general     = 2
                               dp_invalid_parameter = 3.
    
          CALL METHOD html_viewer->show_data
               EXPORTING url   = assigned_url
    *                    frame = frame
               EXCEPTIONS cntl_error = 1.
    
      ENDCASE.
    ENDMODULE.                             " USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *&      Module  EXIT  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE exit INPUT.
      CALL METHOD html_viewer->free.
      CALL METHOD container->free.
      FREE html_viewer.
      FREE container.
      LEAVE PROGRAM.
    ENDMODULE.                             " EXIT  INPUT
  • 相关阅读:
    linux下 C++ 读取mat文件 MATLAB extern cyphon scipy 未完待续
    mshadow笔记
    mem_fun 例子
    gedit embeded terminal 设置字体 颜色
    decltype typename
    gcc4.9.1新特性
    C++开发者都应该使用的10个C++11特性 转
    如何加快C++代码的编译速度 转 ccache
    cout关闭输出缓冲,调试用
    boost range zhuan
  • 原文地址:https://www.cnblogs.com/JackeyLove/p/14609251.html
Copyright © 2011-2022 走看看