box-initializers.zc

来自「实现树形结构」· ZC 代码 · 共 364 行

ZC
364
字号
//[of]:description
//[c]box-initializers
//[c]
//[c]A set of macros to define composite widgets plus functions 
//[c]to instanciate them.
//[cf]
//[of]:license
//[c]Code Browser - a folding text editor for programmers
//[c]Copyright (C) 2003-07 Marc Kerbiquet
//[c]
//[c]This program is free software; you can redistribute it and/or modify
//[c]it under the terms of the GNU General Public License as published by
//[c]the Free Software Foundation; either version 2 of the License, or
//[c](at your option) any later version.
//[c]
//[c]This program is distributed in the hope that it will be useful,
//[c]but WITHOUT ANY WARRANTY; without even the implied warranty of
//[c]MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//[c]GNU General Public License for more details.
//[c]
//[c]You should have received a copy of the GNU General Public License
//[c]along with this program; if not, write to the Free Software
//[c]Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//[cf]
//[of]:imports
import "base/types"
import "text/string"
//[c]
import "user/menu"
import "user/box"
import "user/container-box"
import "user/border-box"
import "user/shell"
import "user/blank-box"
import "user/label-box"
import "user/grid-box"
import "user/frame"
import "user/edit-box"
import "user/directory-box"
import "user/drop-down-edit-box"
import "user/drop-down-list-box"
import "user/list-box"
import "user/tree-box"
import "user/check-box"
import "user/button"
import "user/stacking-box"
import "user/separator-box"
import "user/multi-view"
import "user/scrollbar"
//[cf]
//[c]
//[of]:base
//[c]
private typedef components = [] object

public struct i box

	// The creation function
	// pass an ibox and a parent box to get a newly created box
	create: {i box, box, components} box
	
end

public equ new (i: i box, parent: box, c: components) = 
	create (i) {i, parent, c}
//[cf]
//[of]:blank box
//[c]
struct i blank box: local i box
	size : int
end

func new (i: i blank box, parent: box, c: components)
	return new blank box (parent, size (i))
end

public equ blank box = const i blank box (^new (i blank box, box, components), 3)
public equ blank box (s: int) = const i blank box (^new (i blank box, box, components), s)
//[cf]
//[of]:multi view
//[c]
struct i multi view: local i box; end

func new (i: i multi view, parent: box, c: components)
	return new multi view (parent)
end

public equ multi view = const i multi view (^new (i multi view, box, components))
//[cf]
//[of]:stacking box
//[c]
struct i stacking box: local i box; end

func new (i: i stacking box, parent: box, c: components)
	return new stacking box (parent)
end

public equ stacking box = const i stacking box (^new (i stacking box, box, components))
//[cf]
//[of]:label box
//[c]
struct i label box: local i box
	label: string
end

func new (i: i label box, parent: box, c: components)
	return new label box (parent, label (i))
end


public equ label box (label: string) = const i label box (^new (i label box, box, components), label)
public equ label box = label box (empty string)
//[cf]
//[of]:separator box
//[c]
struct i separator box: local i box; end

func new (i: i separator box, parent: box, c: components)
	return new separator box (parent)
end

public equ separator box = const i separator box (^new (i separator box, box, components))
//[cf]
//[of]:edit box
//[c]
struct i edit box: local i box; end

func new (i: i edit box, parent: box, c: components)
	return new edit box (parent)
end

public equ edit box = const i edit box (^new (i edit box, box, components))
//[cf]
//[of]:directory box
//[c]
struct i directory box: local i box; end

func new (i: i directory box, parent: box, c: components)
	return new directory box (parent)
end

public equ directory box = const i directory box (^new (i directory box, box, components))
//[cf]
//[of]:drop down edit box
//[c]
struct i drop down edit box: local i box; end

func new (i: i drop down edit box, parent: box, c: components)
	return new drop down edit box (parent)
end

public equ drop down edit box  = 
	const i drop down edit box (^new (i drop down edit box, box, components))
//[cf]
//[of]:drop down list box
//[c]
struct i drop down list box: local i box; end

func new (i: i drop down list box, parent: box, c: components)
	return new drop down list box (parent)
end

public equ drop down list box  = 
	const i drop down list box (^new (i drop down list box, box, components))
//[cf]
//[of]:list box
//[c]
struct i list box: local i box; end

func new (i: i list box, parent: box, c: components)
	return new list box (parent)
end

public equ list box  = 
	const i list box (^new (i list box, box, components))
//[cf]
//[of]:tree box
//[c]
struct i tree box: local i box; end

func new (i: i tree box, parent: box, c: components)
	return new tree box (parent)
end

public equ tree box  = 
	const i tree box (^new (i tree box, box, components))
//[cf]
//[of]:check box
//[c]
struct i check box: local i box
	caption: string
end

func new (i: i check box, parent: box, c: components)
	return new check box (parent, caption (i))
end

public equ check box (caption: string) = 
	const i check box (^new (i check box, box, components), caption)
//[cf]
//[of]:button
//[c]
struct i button: local i box
	caption: string
end

func new (i: i button, parent: box, c: components)
	return new button (parent, caption (i))
end

public equ button (caption: string) = 
	const i button (^new (i button, box, components), caption)
//[cf]
//[of]:scrollbar
//[c]
struct i vertical scrollbar: local i box
end

struct i horizontal scrollbar: local i box
end

func new (i: i vertical scrollbar, parent: box, c: components)
	return new scrollbar (parent, sb vertical)
end

func new (i: i horizontal scrollbar, parent: box, c: components)
	return new scrollbar (parent, sb horizontal)
end

public equ vertical scrollbar = const i vertical scrollbar (^new (i vertical scrollbar, box, components))
public equ horizontal scrollbar = const i horizontal scrollbar (^new (i horizontal scrollbar, box, components))
//[cf]
//[of]:border box
//[c]
struct i border box: local i box
	box: i box
end

func new (i: i border box, parent: box, c: components)
	def b = new border box (parent)
	new (box (i), b, c)
	return b
end

public equ border box (box: i box) = 
	const i border box (^new (i border box, box, components), box)
//[cf]
//[of]:frame box
//[c]
struct i frame box: local i box
	menu: i top menu
	style: box style
	child: i box
end

public func new (i: i frame box, parent: box, c: components)
	def f = new frame box (parent, style (i))
	if not nil (menu (i))
		set menu (f, new (menu (i), f, c))
	end
	create (child (i)) {child (i), f, c}
	return f	
end

public func new (i: i frame box, c: components)
	return new (i, nil, c)
end

public equ frame box (menu: i top menu, child: i box, style: box style) = 
	const i frame box (
		^new (i frame box, box, components), 
		menu,
		style,
		child)
//[cf]
//[of]:grid box
//[c]
struct i grid cell
	box: i box
	left: int
	top: int
	width: int
	height: int
end

public typedef grid cells = [] i grid cell

public equ grid cell (
	box: i box,
	left: int,
	top: int,
	width: int,
	height: int) =
	
	const i grid cell (box, left, top, width, height)

public equ grid cell (
	box: i box,
	left: int,
	top: int) =
	
	const i grid cell (box, left, top, 1, 1)

struct i grid box: local i box

	hor: [] int
	ver: [] int
	cells: [] i grid cell
	extern: int
	intern: int

end

func new (i: i grid box, parent: box, comp: components)

	def grid = new grid box (parent)
	def icell = cells (i)
	def first cell = nil : grid cell
	def last cell = nil : grid cell
	repeat
		def c = icell[]
		if is nil (c)
			break
		end
		def box = new (box (c), grid, comp)
		def cell = new grid cell (last cell, box, left (c), top (c), width (c), height (c))
		last cell = cell
		if is nil (first cell)
			first cell = last cell
		end
		++ icell
	end
	if extern (i) == 0 && intern (i) == 0
		configure (grid, hor (i), ver (i), last cell)
	else
		configure (grid, hor (i), ver (i), last cell, extern (i), intern (i))
	end
	return grid
end

public equ grid box (hor: [] int, ver: [] int, cells: [] i grid cell) = 
	const i grid box (^new (i grid box, box, components), hor, ver, cells, 0, 0)

public equ grid box (extern: int, intern: int, hor: [] int, ver: [] int, cells: [] i grid cell) = 
	const i grid box (^new (i grid box, box, components), hor, ver, cells, extern, intern)
//[cf]
//[c]
//[of]:labelizer
//[c]
struct i labelize : local i box
	box: i box
	label: int
end

func new (i: i labelize, parent: box, c: components)
	def box = new (box (i), parent, c)
	c [label (i)] = box
	return box
end

public equ @shl (label: int, obj: i box) = 
	const i labelize (^new (i labelize, box, components), obj, label)
//[cf]

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?