---++!! !CommonCtrl.MultilineEditbox %TOC{title="Contents:"}% %STARTINCLUDE% ---++ multiline textbox from a treeview. It supports readonly, show line number and syntax highlighting | *Title* | multiline textbox from a treeview. It supports readonly, show line number and syntax highlighting | | *Author(s)* | LiXizhi | | *Date* | 2007/3/7 | | *File* | script/ide/MultilineEditbox.lua | ---+++ Description %T% __Sample Code__ <verbatim> NPL.load("(gl)script/ide/MultiLineEditbox.lua"); local ctl = CommonCtrl.MultiLineEditbox:new{ name = "MultiLineEditbox1", alignment = "_lt",left=0, top=0,width = 256,height = 90, parent = nil, WordWrap = false, }; ctl:Show(true); ctl:SetText("line 1\r\nline2"); log(ctl:GetText()); </verbatim> ---+++ Member Functions ---++++ !MultiLineEditbox:Show <verbatim> common control library NPL.load("(gl)script/ide/common_control.lua"); NPL.load("(gl)script/ide/TreeView.lua"); define a new control in the common control libary default member attributes local MultiLineEditbox = commonlib.inherit(CommonCtrl.TreeView, { -- the top level control name name = "MultiLineEditbox1", -- normal window size alignment = "_lt", left = 0, top = 0, width = 512, height = 390, parent = nil, -- whether it is readonly. ReadOnly = nil, -- TODO: boolean: NOT implemented yet. WordWrap = nil, -- this is space between each line. DefaultNodeHeight = 20, -- spacing from top for each line. linetop_spacing = 3, -- max number of lines. If nil there are no limit. max_lines = nil, -- boolean: whether to show line number ShowLineNumber = nil, -- the width of grey area to display line number. Only used when ShowLineNumber is true. LineNumberWidth = 20, -- appearance container_bg = "Texture/3DMapSystem/common/ThemeLightBlue/container_bg.png: 4 4 4 4", -- the background of each line. the texture height should be height of each line. line_bg = "", -- called when user right click on the text. function(self, lineNode) or string. -- Use CommonCtrl.MultiLineEditbox.OnContextMenuDefault for common copy and paste. OnContextMenu = nil, -- nil or the syntax highlighting map. Use CommonCtrl.MultiLineEditbox.syntax_map_NPL syntax_map = nil, --+++++++++++++++++++ AutoHorizontalScrollBar=false; HorizontalScrollBarHeight=20, --+++++++++++++++++++ }) CommonCtrl.MultiLineEditbox = MultiLineEditbox; NPL syntax highlighting rules MultiLineEditbox.syntax_map_NPL = { {"\t", [[ ]]}, {"^ ", [[ ]]}, {" ", [[ ]]}, {"<", [[<]]}, {">", [[>]]}, {"\"", [["]]}, {"'", [[']]}, {"^(.*)(function)(%W?.*)$", [[%1<font style="color: #0000CC">%2</font>%3]]}, {"^(.*)(end)(%W?.*)$", [[%1<font style="color: #0000CC">%2</font>%3]]}, {"(%-%-.*)$", [[<font style="color: #00AA00">%1</font>]]}, } pure text, just replace tab with space MultiLineEditbox.syntax_map_PureText = { {"\t", [[ ]]} }</verbatim> --------------------------------------- public functions * _param_ __bShow__ : boolean to show or hide. if nil, it will toggle current setting. __syntax__ <verbatim>function MultiLineEditbox:Show(bShow)</verbatim> __parameters__ | *bShow* | boolean to show or hide. if nil, it will toggle current setting. | ---++++ !MultiLineEditbox:GetLineCount get line count of the text. __syntax__ <verbatim>function MultiLineEditbox:GetLineCount()</verbatim> ---++++ !MultiLineEditbox:SetText set the text, we will reuse the treenode as necessary. __syntax__ <verbatim>function MultiLineEditbox:SetText(text, bForceNoUpdate)</verbatim> __parameters__ | *text* | | | *bForceNoUpdate* | | ---++++ !MultiLineEditbox:GetText return the concartenated text __syntax__ <verbatim>function MultiLineEditbox:GetText()</verbatim> ---++++ !MultiLineEditbox.DrawNodeHandler ------------------------------------------- below are all private functions: ------------------------------------------- draw each line treenode handler __syntax__ <verbatim>function MultiLineEditbox.DrawNodeHandler(_parent, treeNode)</verbatim> __parameters__ | *parent* | | | *treeNode* | | ---++++ !MultiLineEditbox.SetCaretPosition Set Caret Position __syntax__ <verbatim>function MultiLineEditbox.SetCaretPosition(sCtrlName, nLineIndex,caretPosition)</verbatim> __parameters__ | *sCtrlName* | | | *nLineIndex* | | | *caretPosition* | | ---++++ !MultiLineEditbox.OnEditLineKeyUp process user key strokes inside the editbox. __syntax__ <verbatim>function MultiLineEditbox.OnEditLineKeyUp(sCtrlName, nLineIndex)</verbatim> __parameters__ | *sCtrlName* | | | *nLineIndex* | | ---++++ !MultiLineEditbox:ProcessLine update the given line; if necessary, it will also update subsequent lines recursively. * _param_ __nLineIndex__ : line index * _param_ __command__ : 0: update the line. If param1 is nil, it will not change the focus, otherwise change the focus if necessary. 1: prepend text(param1) to the given line 4: append text(param1) to the given line 2: insert return key at the current caret position.If param1 is nil, it will not change the focus, otherwise change the focus if necessary. 3: insert a new line of text(param1) at the current line 5: delete a given line * _return_ ____ : return true if needs to update __syntax__ <verbatim>function MultiLineEditbox:ProcessLine(nLineIndex, command, param1)</verbatim> __parameters__ | *nLineIndex* | line index | | *command* | | | *param1* | | | *return* | return true if needs to update | ---++++ !MultiLineEditbox.OnClick_private private: user click. call the user handler if any. __syntax__ <verbatim>function MultiLineEditbox.OnClick_private(sCtrlName, nLineIndex, nCaretPos)</verbatim> __parameters__ | *sCtrlName* | | | *nLineIndex* | | | *nCaretPos* | | ---++++ !MultiLineEditbox.onmouseup_parent called when user clicks the empty space to begin editing __syntax__ <verbatim>function MultiLineEditbox.onmouseup_parent(self)</verbatim> __parameters__ | *self* | | ---++++ !MultiLineEditbox:GenTextMarkup generate the markup text to display text with syntax highlighting (using mcml). __syntax__ <verbatim>function MultiLineEditbox:GenTextMarkup(text, map)</verbatim> __parameters__ | *text* | | | *map* | | ---++++ !MultiLineEditbox.OnContextMenuDefault TODO: default context menu handler __syntax__ <verbatim>function MultiLineEditbox.OnContextMenuDefault(self, lineNode)</verbatim> __parameters__ | *self* | | | *lineNode* | | %STOPINCLUDE%
E
dit
|
A
ttach
|
P
rint version
|
H
istory
: r1
|
B
acklinks
|
V
iew topic
|
Ra
w
edit
|
M
ore topic actions
Topic revision: r1 - 2008-02-29
-
LiXizhi
Home
Site map
CCWeb web
HaqiTeen web
Main web
ParaEngine web
TWiki web
Main Web
Users
Groups
Index
Search
Changes
Notifications
RSS Feed
Statistics
导航页WebTopMenu
Preferences
开发指南
Getting Started
ParacraftSDK
NPL
MCML
NPL Reference Manual
美术Mod
Account
Log In
English
简体中文
簡體中文
E
dit
A
ttach
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback