⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 box.zc

📁 实现树形结构
💻 ZC
📖 第 1 页 / 共 4 页
字号:
//[cf]
//[of]:acutal activate
//[c]
public func actual activate (m: box)

	// The parent is already active
	if not nil (parent (m)) && activated (parent (m))
		gtk_container_add (widget (parent (m)): GtkContainer, widget (m))
	end
	
	// activate all children
	each child (m) ? c
		activate (c)
		gtk_container_add (widget (m): GtkContainer, widget (c))
	end

end
//[cf]
//[of]:popup menu (point)
//[c]
public func popup menu (m: box, p: point)

	def e: local popup event
	type (e) = popup event type
	x (position (e)) = x (p)
	y (position (e)) = y (p)
	return on popup (m, e)
	
end
//[cf]
//[of]:ancestor window
//[c]Return the GtkWindow container
//[c]
public func ancestor window (m: box)

	def parent = widget (m)
	repeat
		if is nil (parent) || gtk_widget_type (parent) == gtk_window_get_type
			break
		end
		parent = gtk_widget_get_parent (parent)
	end

	return parent:GtkWindow
end	
//[cf]
//[cf]
//[c]
//[of]:Utility functions
//[of]:append caption (caption, string buffer)
//[c]Convert a windows caption (&) to a gtk caption (_)
//[c]
public func append caption (s: string, t: string buffer)

	def p = s
	repeat
		def c = p++ []
		if is nul (c)
			break
		end
		if c == $&
			t << $_
		elsif c == $_
			t << "__"
		else
			t << c
		end
	end

end
//[cf]
//[of]:bool to gboolean (bool)
public equ bool to gboolean (b: bool) = b -> TRUE, FALSE
//[cf]
//[of]:get key state (state)
public func get key state (state: guint)

	def status = 0

	if (state & GDK_SHIFT_MASK:guint) <> 0
		status |= SHIFT
	end
	if (state & GDK_CONTROL_MASK:guint) <> 0
		status |= CTRL
	end
	if (state & GDK_MOD1_MASK:guint) <> 0
		status |= ALT
	end
	
	return status
end
//[cf]
//[cf]
//[cf]
//[c]
//[of]:constants
//[c]Identifier for the platform
//[c]
public def user interface name := "x11"
//[cf]
//[of]:basic types
//[c]
public typedef interface = object
public typedef interface id = object
public typedef resource id = int
//[c]
//[c]Use this type to declare a new type of event for other event
//[c]
public typedef local event type = [1] byte
public typedef event type = -> local event type
//[c]
public enum border style
	border none
	border single
	border sunken
end
//[c]
public enum mouse button
	left mouse button
	middle mouse button
	right mouse button
end
//[cf]
//[of]:events
//[of]:event types
public def destroy event type : local event type
public def focus event type : local event type
public def blur event type : local event type
public def key down event type : local event type
public def key up event type : local event type
public def char event type : local event type
public def mouse down event type : local event type
public def mouse up event type : local event type
public def mouse move event type : local event type
public def mouse wheel event type : local event type
public def mouse cancel event type : local event type
public def mouse double click event type : local event type
public def popup event type : local event type
public def enter menu event type : local event type
public def leave menu event type : local event type

public def value changed event type : local event type
public def selection changed event type : local event type
public def index changed event type : local event type
public def click event type : local event type
//[cf]
//[of]:event
public struct event
	type: event type
end
//[c]
public func event (t: event type, return e: event)
	type (e) = t
end
//[cf]
//[c]
//[of]:key event
public struct key event : local event
	key: int
	status: int
end
//[c]
public func key event (type: event type, key: int, status: int, return e: key event)
	e . type = type
	e . key = key
	e . status = status
end
//[cf]
//[of]:char event
public struct char event : local event
	char code: char
	private _pad: [3] byte // ### compiler bug
	status: int
end
//[c]
public func char event (c: char, s: int, return e: char event)
	e . type = char event type
	e . char code = c
	e . status = s
end
//[cf]
//[of]:mouse button event
public struct mouse button event : local event
	button: mouse button
	status: int
	position: local point
end
//[cf]
//[of]:mouse move event
public struct mouse move event : local event
	status: int
	position: local point
end
//[cf]
//[of]:mouse wheel event
public struct mouse wheel event : local event
	status: int
	delta: int
	position: local point
end
//[cf]
//[of]:popup event
public struct popup event : local event
	position: local point
end
//[cf]
//[c]
//[of]:drop files event
public struct drop files event : local sys drop files event
	// empty
end
//[c]
//[of]:each file (m)
//[c]Enumerates all files of a drop files event.
//[c]
//[c]	This method must be invoked when handling a "on drop files" event.
//[c]
public equ each file (m: drop files event)

	each (list (m)) ? s
		yield (s)
	end

end
//[cf]
//[cf]
//[of]:receive primary selection event
public struct receive primary selection event
	format: clipboard format
	buffer: [] byte
	size: size
end
//[cf]
//[of]:query primary selection event
public struct query primary selection event
	format: clipboard format
	data: object
end
//[cf]
//[cf]
//[of]:box style
//[of]:type
//[c]Every box has a a style. A box uses this object's attributes to 
//[c]display itself.
//[c]
public struct box style

	// style for edits
	edit color: color
	edit background: color
	edit font: font
	edit border: border style
	
	// style for labels
	label color: color
	label background: color
	label font: font
	label alignment: alignment

	button highlight color: color
	button shadow color: color

end
//[cf]
//[cf]
//[of]:box
//[of]:type
public struct box : local sys box

	class: box class
	parent: box
	style: box style
	first child: box
	last child: box
	next sibling: box
	prev sibling: box
	
	client rect: local rectangle
	min size: local area

	private being destroyed: bool
	private valid min size: bool
	private valid size: bool

end
//[cf]
//[of]:instance creation
//[of]:Notes
//[c]This is an abstract class, there is no constructor for this class.
//[cf]
//[of]:delete
//[c]
public func delete (m: box)
	release (class (m)) {m}
	free memory (m : mem)
end
//[cf]
//[c]
//[cf]
//[of]:hierarchy
//[of]:each child
//[c]
public equ each child (b: box)
	def box = first child (b)
	while not nil (box)
		yield (box)
		box = next sibling (box)
	end
end
//[cf]
//[of]:each ancestor with self
//[c]
public equ each ancestor with self (b: box)
	def box = b
	while not nil (box)
		yield (box)
		box = parent (box)
	end
end
//[cf]
//[of]:each descendant
//[c]Iterates on all the tree
//[c]the initial box must be the root
//[c]
public equ each descendant (box: box)
	def b = box
	while not nil (b)
		yield (b)
		b = next in tree (b, false)
	end
end
//[cf]
//[c]
//[of]:next in tree (cycle)
//[c]
public func next in tree (m: box, cycle: bool)

	def n = first child (m)
	if not nil (n)
		return n
	end

	def c = m
	repeat
		n = next sibling (c)
		if not nil (n); return n; end
		
		n = parent (c)
		if is nil (n)
			return cycle -> c, nil
		end
		
		c = n
	end

	// never executed - make compiler happy
	return nil

end
//[cf]
//[of]:prev in tree
//[c]
public func prev in tree (m: box)

	def c = m
	def p = parent (m)
	if not nil (p)
		c = prev sibling (c)
		if is nil (c)
			return p
		end
	end
	
	repeat
		def n = last child (c)
		if is nil (n)
			return c
		end
		c = n
	end

	// never executed - make compiler happy
	return nil

end
//[cf]
//[of]:find child (box)
//[c]Find the child containing box
//[c]
public func find child (m: box, box: box)

	while not nil (box)
		def parent = parent (box)
		if parent == m
			return box
		end
		box = parent
	end

	return nil

end
//[cf]
//[cf]
//[of]:geometry
//[of]:move (rectangle, repaint)
//[c]Move the box
//[c]
//[c]The position of a box should be changed only by its parent from
//[c]the on size or adjust event.
//[c]
public func move (m: box, r: rectangle, repaint: bool)
	gtk_widget_size_allocate (widget (m), r)
end
//[cf]
//[of]:move (rectangle)
//[c]Move the box
//[c]
//[c]The position of a box should be changed only by its parent from
//[c]the on size or adjust event.
//[c]
public func move (m: box, r: rectangle)
	move (m, r, true)
end
//[cf]
//[of]:validate size
//[c]Validates the size
//[c]
//[c]	This method should be invoked only from the toplevel window
//[c]	before re-entering into the message loop wait event.
//[c]	
//[c]	Note: with GTK+, the validation of size is automatically handled
//[c]	so this method is useless for this platform.
//[c]
public func validate size (m: box)

	validate min size (m)
	adjust content (m)

end
//[c]
//[c]SUB-FUNCTIONS
//[of]:	validate min size
//[c]Validates the min size of the box
//[c]
//[c]Min size of all children are validated, then the min size of the
//[c]box is computed by invoking compute min size.
//[c]
private func validate min size (m: box) : void

	// Returns immediately if the min size is valid
	if valid min size (m)
		return
	end
	
	// Validate the children's min size
	each child (m) ? c
		validate min size (c)
	end

  	// Compute the min size according to the minsize of children
  	compute min size (m)
  	
  	// Now the minsize is valid
  	valid min size (m) = true
  	
	// but content is invalid
	valid size (m) = false
	
end
//[cf]
//[of]:	adjust content
private func adjust content (m: box) : void

	if valid size (m)
		return
	end

	adjust (m)
	
	// adjust the children's content
	each child (m) ? c
		adjust content (c)
	end
	
	// but content is invalid
	valid size (m) = true

end
//[c]
//[of]:adjust
//[c]
//[c]Adjust is invoked after the min size of the control or
//[c]a child has just been fixed.
//[c]
//[c]A top-level box must check if it has to resize itself since it can be too small.
//[c]A child box is not responsible of its size but it must compute the
//[c]layout of its children.
//[c]
//[c]This method is invoked during the validation of sizes (validate size ()).
//[c]
//[c]Remark: this method is not invoked is the control has just been resized
//[c]by the parent.
//[c]
private func adjust (m: box)
	adjust (class (m)) {m}
end
//[cf]
//[cf]
//[cf]
//[c]
//[of]:invalidate min size
//[c]Invalidates the minsize
//[c]
public func invalidate min size (m: box): void

	// nothing to do if already invalidated
	if ~ valid min size (m)
		return
	end
	
	// now the min size is invalid
	valid min size (m) = false
	
	// the minsize of the parent is also invalid
	if not nil (parent (m))
		invalidate min size (parent (m))
	end

end
//[cf]
//[of]:min width
//[c]
public equ min width (m: box) = w (min size (m))
//[cf]
//[of]:min height
//[c]
public equ min height (m: box) = h (min size (m))
//[cf]
//[of]:set min width (w)
//[c]
public equ set min width (m: box, w: int) =
	w (min size (m)) = w
//[cf]
//[of]:set min height (h)
//[c]
public equ set min height (m: box, h: int) = 
	h (min size (m)) = h
//[cf]
//[of]:set min size (w, h)
//[c]Changes the min size
//[c]
public func set min size (m: box, w:int, h: int)
	set (min size (m), w, h)
end

⌨️ 快捷键说明

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