ABAP Control Framework(3): Text Editer

3.Text Editer

          通过cl_gui_textedit类显示一个文本编辑器。

类方法:Get and Set Text

GET_LINE_TEXT

获取对应行文本;

GET_SELECTED_TEXT_AS_R3TABLE

SET_SELECTED_TEXT_AS_R3TABLE

获取或设置Text使用Table;

GET_SELECTED_TEXT_AS_STREAM

SET_SELECTED_TEXT_AS_STREAM

获取或设置Text使用stream;

GET_TEXT_AS_R3TABLE

SET_TEXT_AS_R3TABLE

获取或设置Text使用Table;

GET_TEXT_AS_STREAM

SET_TEXT_AS_STREAM

获取或设置Text使用stream;

OPEN_LOCAL_FILE

SAVE_AS_LOCAL_FILE

打开或保存本地文件;

DELETE_TEXT

删除Text;

GET_FIRST_VISIBLE_LINE

SET_FIRST_VISIBLE_LINE

获取或设置可见行;

GET_SELECTION_POS

SET_SELECTION_POS

获取或设置选择位置;

GO_TO_LINE

移动到指定行;

HIGHLIGHT_LINES

HIGHLIGHT_SELECTION

highlight行或选择;

SET_READONLY_MODE

设置只读模式;

FIND_AND_REPLACE

查找替换字符串;

REPLACE_ALL

替换所有字符串;

SET_TOOLBAR_MODE

设置是否有toolbar

事件示例:SAPTEXTEDIT_TEST_EVENTS

示例:

"cl_gui_textedit
"html编辑器
CLASS c2 DEFINITION.
  PUBLIC SECTION.
    CONSTANTS:line_length TYPE I VALUE 265.
    TYPES:BEGIN OF s_text,
       text TYPE C LENGTH line_length,
      END OF s_text.
    TYPES:t_text TYPE TABLE OF s_text.
    DATA:lo_textedit TYPE REF TO cl_gui_textedit.
    METHODS:m_textedit_init.
    METHODS:m_text_string IMPORTING iv_text TYPE string.
    METHODS:m_text_table IMPORTING it_text TYPE t_text.
    METHODS:m_text_r3table IMPORTING it_text TYPE t_text.
    METHODS:m_get_text RETURNING VALUE(re_text) TYPE string.
    METHODS:m_set_read_only IMPORTING iv_mode TYPE I.
ENDCLASS.
CLASS c2 IMPLEMENTATION.
  METHOD m_textedit_init.
    "初始化类
    CREATE OBJECT lo_textedit
      EXPORTING
        "使用get_text_as_r3table必须设置wordwrap_mode
        "在固定位置自动换行
        wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
        "换行位置,只在wordwrap_at_fixed_position有效
        wordwrap_position = line_length
        parent = cl_gui_container=>default_screen.
  ENDMETHOD.
  "設置text edit內容
  METHOD m_text_string.
    "通過字符串設置
    lo_textedit->set_textstream( text = iv_text ).
  ENDMETHOD.
  METHOD m_text_table.
    "通過內表設置,換行需要特定換行符控制
    lo_textedit->set_text_as_stream( text = it_text ).
  ENDMETHOD.
  METHOD m_text_r3table.
    "通過內表設置,內表每行代表換行
    lo_textedit->set_text_as_r3table( table = it_text ).
  ENDMETHOD.
  "獲取text edit內容
  METHOD m_get_text.
    DATA:lv_text TYPE string.
    TYPES:BEGIN OF s_text,
          text TYPE C LENGTH 200,
         END OF s_text.
    DATA:lt_text TYPE TABLE OF s_text.
    DATA:ls_text LIKE LINE OF lt_text.
    "獲取字符串
    "lo_textedit->get_textstream( IMPORTING text = lv_text ).
    "獲取字符串表
    "lo_textedit->get_text_as_stream( IMPORTING text = lt_text ).
    "獲取r3 table
    lo_textedit->get_text_as_r3table( IMPORTING table = lt_text ).
    LOOP AT lt_text INTO ls_text.
      lv_text = lv_text && ls_text-text.
    ENDLOOP.
    re_text = lv_text.
  ENDMETHOD.
  "設置讀寫
  METHOD m_set_read_only.
    "0:OFF;非0:ON
    lo_textedit->set_readonly_mode( readonly_mode = iv_mode ).
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  PERFORM f_show_textedit.
FORM f_show_textedit. DATA:lo_c2 TYPE REF TO c2. TYPES:BEGIN OF s_text, text TYPE C LENGTH 265, END OF s_text. DATA:lt_text TYPE TABLE OF s_text. DATA:ls_text LIKE LINE OF lt_text. DATA:lv_text TYPE string. ls_text-text = 'hello'. APPEND ls_text TO lt_text. ls_text-text = 'world'. APPEND ls_text TO lt_text. "生成一個默認屏幕 WRITE:/ '1'. CREATE OBJECT lo_c2. lo_c2->m_textedit_init( ). "字符串 "lo_c2->m_text_string( iv_text = 'test' ). "換行控制? "lo_c2->m_text_table( it_text = lt_text ). "r3table lo_c2->m_text_r3table( it_text = lt_text ). "獲取text lv_text = lo_c2->m_get_text( ). "設置是否只讀 lo_c2->m_set_read_only( 1 ). ENDFORM.

 

 

posted @ 2021-05-08 11:53  渔歌晚唱  阅读(572)  评论(0编辑  收藏  举报