zoukankan      html  css  js  c++  java
  • TEXT文本编辑框3 点击按钮添加文本至文本输入框

    In this exercise a function that loads the texts of an internal table into the text window, is implemented.

    Steps:

    Define anoterh pushbutton on the screen, that activates the method that fills the TextEdit control. Give itname PUSHBUTTON_IMPORT and function code IMP.

    Define a form CREATE_TEXTS that carries out the text import.

    Only changes to the code in example 2 is show.

    Code:

    *&---------------------------------------------------------------------*
    *& Report  ZTEST_CWBK
    *&
    *&---------------------------------------------------------------------*
    *&
    *&
    *&---------------------------------------------------------------------*
    
    REPORT  ztest_cwbk.
    CONSTANTS:
      line_length TYPE i VALUE 100.
    DATA: ok_code LIKE sy-ucomm.
    DATA:
    * Create reference to the custom container
      custom_container TYPE REF TO cl_gui_custom_container,
    * Create reference to the TextEdit control
      editor TYPE REF TO cl_gui_textedit,
      repid LIKE sy-repid.
    
    
    **********************************************************************
    
    
    * Impmenting events
    **********************************************************************
    DATA:
      event_type(20) TYPE c,
    
    
    * Internal table for events that should be registred
    
    
      i_events TYPE cntl_simple_events,
    
    
    * Structure for oneline of the table
    
    
      wa_events TYPE cntl_simple_event.
    *---------------------------------------------------------------------*
    *       CLASS lcl_event_handler DEFINITION
    *---------------------------------------------------------------------*
    
    
    CLASS lcl_event_handler DEFINITION.
    
    
      PUBLIC SECTION.
    
    
        CLASS-METHODS:
    
    
          catch_dblclick FOR EVENT dblclick
    
    
             OF cl_gui_textedit IMPORTING sender.
    ENDCLASS.
    CLASS lcl_event_handler IMPLEMENTATION.
    
    
      METHOD catch_dblclick.
    
    
    *    event_type = 'Event DBLCLICK raised'.
    
    * Reacting to the system event
      call method cl_gui_cfw=>set_new_ok_code
    
    
        exporting new_code = 'SHOW'.
    
    
      ENDMETHOD.
    
    
    ENDCLASS.
    
    
    
    
    START-OF-SELECTION.
      SET SCREEN '100'.
    *&---------------------------------------------------------------------*
    *&      Module  USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE user_command_0100 INPUT.
      DATA str TYPE c.
      DATA sline(100) TYPE i.
      CASE ok_code.
        WHEN 'EXIT'.
          LEAVE TO SCREEN 0.
        WHEN 'IMP'.
    *      event_type = 'System dblclick'.
          perform load_texts.
      ENDCASE.
    *   Call the Dispacth method to initiate application event handling
    *    call method cl_gui_cfw=>Dispatch.
    
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&---------------------------------------------------------------------*
    *&      Module  STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'MAIN100'.
      IF editor IS INITIAL.
        repid = sy-repid.
    *   Create obejct for custom container
        CREATE OBJECT custom_container
          EXPORTING
            container_name              = 'MYCONTAINER1'
          EXCEPTIONS
            cntl_error                  = 1
            cntl_system_error           = 2
            create_error                = 3
            lifetime_error              = 4
            lifetime_dynpro_dynpro_link = 5
            OTHERS                      = 6.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
                     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
    *   Create obejct for the TextEditor control
        CREATE OBJECT editor
          EXPORTING
            wordwrap_mode              = cl_gui_textedit=>wordwrap_at_fixed_position
            wordwrap_position          = line_length
            wordwrap_to_linebreak_mode = cl_gui_textedit=>true
            parent                     = custom_container
          EXCEPTIONS
            error_cntl_create          = 1
            error_cntl_init            = 2
            error_cntl_link            = 3
            error_dp_create            = 4
            gui_type_not_supported     = 5
            OTHERS                     = 6.
        IF sy-subrc <> 0.
          MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno
                     WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
        ENDIF.
    
    *   Link the event handler method to the event and the
    *   TextEdit control
        SET HANDLER lcl_event_handler=>catch_dblclick FOR editor.
    *   Register the event in the internal table i_events
        wa_events-eventid = cl_gui_textedit=>event_double_click.
    *    wa_events-appl_event = 'X'. "This is an application event
        wa_events-appl_event = space. "This is a system event
        append wa_events to i_events.
    *   Pass the table to the TextEdit control using method
    *   set_registred_events
        call method editor->set_registered_events
           exporting events = i_events.
      ENDIF.
    
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&---------------------------------------------------------------------*
    *&      Form  LOAD_TEXTS
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *  -->  p1        text
    *  <--  p2        text
    *----------------------------------------------------------------------*
    form LOAD_TEXTS .
      TYPES:
       BEGIN OF t_texttable,
         line(line_length) TYPE c,
       END OF t_texttable.
      DATA
        i_texttable TYPE TABLE OF t_texttable.
    * Create internal table with texts
      APPEND 'This a method that fills the TextEdit control' TO i_texttable.
      APPEND 'with a text.' TO i_texttable.
      DO 10 TIMES.
        APPEND 'hallo world !' TO i_texttable.
      ENDDO.
    * Load TextEdit control with texts
      CALL METHOD editor->set_text_as_r3table
        EXPORTING table = i_texttable.
      IF sy-subrc > 0.
    *   Display an error message
        EXIT.
      ENDIF.
    * All methods that operates on controls are transferred to the frontend
    
    
    * by a RFC calls. the method FLUSH is used to determine when this is done.
      CALL METHOD cl_gui_cfw=>flush.
      IF sy-subrc > 0.
    *   Display an error message
      ENDIF.
    
    endform.                    " LOAD_TEXTS
  • 相关阅读:
    美的觉醒
    jquery中ajax使用error调试错误的方法
    VC项目开发之单文档多视图实现-非分割窗口[转]
    MFC常见问题解惑[转]
    计算机视觉、机器学习相关领域论文和源代码大集合[转]
    C++成员变量、构造函数的初始化顺序 [转]
    VC中常用的宏[转]
    (VC)解决绘图时闪烁问题的一点经验[转]
    C++的辅助工具介绍 [转]
    [GUI]界面开发类库-Ribbon风格 [转]
  • 原文地址:https://www.cnblogs.com/caizjian/p/4360181.html
Copyright © 2011-2022 走看看