CommonCtrl.MultilineEditbox

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

TIP Sample Code

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());

Member Functions

MultiLineEditbox:Show

 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", [[   ]]},
   {"^ ", [[ ]]},
   {" ", [[ ]]},
   {"<", [[&lt;]]},
   {">", [[&gt;]]},
   {"\"", [[&quot;]]},
   {"'", [[&apos;]]},
   {"^(.*)(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", [[   ]]}
}

public functions
  • param bShow : boolean to show or hide. if nil, it will toggle current setting.

syntax

function MultiLineEditbox:Show(bShow)

parameters

bShow boolean to show or hide. if nil, it will toggle current setting.

MultiLineEditbox:GetLineCount

get line count of the text.

syntax

function MultiLineEditbox:GetLineCount()

MultiLineEditbox:SetText

set the text, we will reuse the treenode as necessary.

syntax

function MultiLineEditbox:SetText(text, bForceNoUpdate)

parameters

text  
bForceNoUpdate  

MultiLineEditbox:GetText

return the concartenated text

syntax

function MultiLineEditbox:GetText()

MultiLineEditbox.DrawNodeHandler


below are all private functions:

draw each line treenode handler

syntax

function MultiLineEditbox.DrawNodeHandler(_parent, treeNode)

parameters

parent  
treeNode  

MultiLineEditbox.SetCaretPosition

Set Caret Position

syntax

function MultiLineEditbox.SetCaretPosition(sCtrlName, nLineIndex,caretPosition)

parameters

sCtrlName  
nLineIndex  
caretPosition  

MultiLineEditbox.OnEditLineKeyUp

process user key strokes inside the editbox.

syntax

function MultiLineEditbox.OnEditLineKeyUp(sCtrlName, nLineIndex)

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

function MultiLineEditbox:ProcessLine(nLineIndex, command, param1)

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

function MultiLineEditbox.OnClick_private(sCtrlName, nLineIndex, nCaretPos)

parameters

sCtrlName  
nLineIndex  
nCaretPos  

MultiLineEditbox.onmouseup_parent

called when user clicks the empty space to begin editing

syntax

function MultiLineEditbox.onmouseup_parent(self)

parameters

self  

MultiLineEditbox:GenTextMarkup

generate the markup text to display text with syntax highlighting (using mcml).

syntax

function MultiLineEditbox:GenTextMarkup(text, map)

parameters

text  
map  

MultiLineEditbox.OnContextMenuDefault

TODO: default context menu handler

syntax

function MultiLineEditbox.OnContextMenuDefault(self, lineNode)

parameters

self  
lineNode  
Topic revision: r1 - 2008-02-29 - LiXizhi
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 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