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

📄 box.zc

📁 实现树形结构
💻 ZC
📖 第 1 页 / 共 4 页
字号:

	connect (m,
		"focus-out-event", 
		^focus out event (GtkWidget, GdkEventFocus, box))

	connect (m, 
		"destroy", 
		^destroy (GtkWidget, box))

	connect (m, 
		"key-press-event", 
		^key press event (GtkWidget, GdkEventKey, box))
		
	connect (m, 
		"key-release-event", 
		^key release event (GtkWidget, GdkEventKey, box))

	connect (m,
		"drag-data-received",
		^drag data received (
			GtkWidget, 
			GdkDragContext, 
			gint, 
			gint, 
			GtkSelectionData, 
			guint,
			guint,
			box))

	connect (m, 
		"popup-menu", 
		^popup menu (GtkWidget, box))

end	
//[cf]
//[c]
//[of]:default method handling
//[of]:actual release
//[c]
public func actual release (m: box)

	// Release the input method
	def im = input method (m)
	if not nil (im)
		g_object_unref (im)
	end

	// 1. Mark this box as being destroyed.
	// It prevents to reassign the focus for each child being
	// destroyed: can get focus (box) check this flags for all its ancestors.
	being destroyed (m) = true

	// 2. Deletes all children
	// do not use iterator here since the object
	// is deleted before getting its next sibling
	def c = first child (m)
	while not nil (c)
		def n = next sibling (c)
		delete (c)
		c = n
	end

	// 3. Destroy the window
	def w = widget (m)
	if not nil (w)
		gtk_widget_destroy (w)
	end

	def parent = parent (m)
	if is nil (parent)
		return
	end

	// 4. Detach from parent
	remove child (parent, m)
	
	// 5. Notify parent
	// the parent has been resetted, need to call on child event
	// explicitely
	def e := event (destroy event type)
	on child event (parent, m, e)

end
//[cf]
//[of]:actual get interface (id)
//[c]
public func actual get interface (m: box, id: interface id)
	return nil
end
//[cf]
//[of]:actual cut
//[c]Default implementation for the cut command
//[c]
//[c]	Just performs a copy, then a clear if the copy method
//[c]	returned true.
//[c]
public func actual cut (m: box)
	return copy(m) && clear(m)
end
//[cf]
//[of]:actual can cut
//[c]
public func actual can cut (m: box)
	return can copy (m) && can clear (m)
end
//[cf]
//[cf]
//[of]:default event handling
//[of]:handle size
//[c]
public equ handle size (m: box) = do nothing (m)
public equ default size function = ^do nothing (box)
//[cf]
//[of]:handle paint (canvas, clip rectangle)
//[c]
public func handle paint (m: box, c: canvas, clip: rectangle)
	// sub-class responsibility
end
//[cf]
//[of]:handle drop files (event)
//[c]The control recieves files
//[c]
public func handle drop files (m: box, e: drop files event)
	// empty
end
//[cf]
//[of]:handle query primary selection (event)
public func handle query primary selection (m: box, e: query primary selection event)
	// empty
end
//[cf]
//[of]:handle receive primary selection (event)
public func handle receive primary selection (m: box, e: receive primary selection event)
	// empty
end
//[cf]
//[c]
//[of]:handle focus (event)
//[c]The control has gained the focus
//[c]
public equ handle focus (m: box, e: event) = notify parent (m, e)
private equ default focus function = ^notify parent (box, event)
//[cf]
//[of]:handle blur (event)
//[c]The control has lost the focus
//[c]
public equ handle blur (m: box, e: event) = notify parent (m, e)
private equ default blur function = ^notify parent (box, event)
//[cf]
//[of]:handle key down (event)
public equ handle key down (m: box, e: event) = notify parent (m, e)
private equ default key down function = ^notify parent (box, event)
//[cf]
//[of]:handle key up (event)
public equ handle key up (m: box, e: event) = notify parent (m, e)
private equ default key up function = ^notify parent (box, event)
//[cf]
//[of]:handle char (event)
public equ handle char (m: box, e: event) = notify parent (m, e)
private equ default char function = ^notify parent (box, event)
//[cf]
//[of]:handle mouse down (event)
//[c]The control receives a mouse button event 
//[c]
public equ handle mouse down (m: box, e: event) = notify parent (m, e)
private equ default mouse down function = ^notify parent (box, event)
//[cf]
//[of]:handle mouse up (event)
//[c]The control receives a mouse button event 
//[c]
public equ handle mouse up (m: box, e: event) = notify parent (m, e)
private equ default mouse up function = ^notify parent (box, event)
//[cf]
//[of]:handle mouse move (event)
//[c]The control receives a mouse move event 
//[c]
public equ handle mouse move (m: box, e: event) = notify parent (m, e)
private equ default mouse move function = ^notify parent (box, event)
//[cf]
//[of]:handle mouse wheel (event)
//[c]The control receives a mouse wheel event 
//[c]
public equ handle mouse wheel (m: box, e: event) = notify parent (m, e)
private equ default mouse wheel function = ^notify parent (box, event)
//[cf]
//[of]:handle mouse cancel
//[c]The control receives a mouse cancel event 
//[c]
public equ handle mouse cancel (m: box, e: event) = notify parent (m, e)
private equ default mouse cancel function = ^notify parent (box, event)
//[cf]
//[of]:handle mouse double click
//[c]The control receives a mouse button event 
//[c]
public equ handle mouse double click (m: box, e: event) = notify parent (m, e)
private equ default mouse double click function = ^notify parent (box, event)
//[cf]
//[of]:handle popup (event)
//[c]The control receives a mouse wheel event 
//[c]
public equ handle popup (m: box, e: event) = notify parent (m, e)
private equ default popup function = ^notify parent (box, event)
//[cf]
//[of]:handle enter menu (event)
//[c]Notifies the focused widget that the window menu has been activated
//[c]
public equ handle enter menu (m: box, e: event) = notify parent (m, e)
private equ default enter menu function = ^notify parent (box, event)
//[cf]
//[of]:handle leave menu (event)
//[c]Notifies the focused widget that the window menu has been deactivated
//[c]
public equ handle leave menu (m: box, e: event) = notify parent (m, e)
private equ default leave menu function = ^notify parent (box, event)
//[cf]
//[c]
//[of]:handle value changed (event)
//[c]Notifies the parent that the value of the widget has changed
//[c]
public equ handle value changed (m: box, e: event) = notify parent (m, e)
private equ default value changed function = ^notify parent (box, event)
//[cf]
//[of]:handle index changed (event)
//[c]Notifies the parent that the index of the widget has changed
//[c]
public equ handle index changed (m: box, e: event) = notify parent (m, e)
private equ default index changed function = ^notify parent (box, event)
//[cf]
//[of]:handle selection changed (event)
//[c]Notifies the parent that the selection of the widget has changed
//[c]
public equ handle selection changed (m: box, e: event) = notify parent (m, e)
private equ default selection changed function = ^notify parent (box, event)
//[cf]
//[of]:handle click (event)
//[c]Notifies the parent that the widget has been clicked
//[c]
public equ handle click (m: box, e: event) = notify parent (m, e)
private equ default click function = ^notify parent (box, event)
//[cf]
//[c]
//[of]:handle child event (child, event)
//[c]A custom event has been emitted by a child
//[c]
//[c]The default implementation forwards the event to the parent.
//[c]
public func handle child event (m: box, child: box, e: event)

	def parent = parent (m)
	if is nil (parent)
		return false
	end
	
	return on child event (parent, child, e)

end
//[cf]
//[cf]
//[of]:send events
//[of]:compute min size
public func compute min size (m: box)
	compute min size (class (m)) {m}
end
//[cf]
//[c]
//[of]:on size
private func on size (m: box)
	on size (class (m)) {m}
end
//[cf]
//[of]:on paint (canvas, clip rectangle)
public func on paint (m: box, c: canvas, clip: rectangle)
	on paint (class (m)) {m, c, clip}
end
//[cf]
//[of]:on drop files (drop files event)
private func on drop files (m: box, e: drop files event)
	on drop files (class (m)) {m, e}
end
//[cf]
//[of]:on receive primary selection (event)
public func on receive primary selection (m: box, e: receive primary selection event)
	on receive primary selection (class (m)) {m, e}
end
//[cf]
//[of]:on query primary selection (event)
public func on query primary selection (m: box, e: query primary selection event)
	on query primary selection (class (m)) {m, e}
end
//[cf]
//[c]
//[of]:on focus
private func on focus (m: box)
	def e := event (focus event type)
	return on focus (class (m)) {m, e}
end
//[cf]
//[of]:on blur
private func on blur (m: box)
	def e := event (blur event type)
	return on blur (class (m)) {m, e}
end
//[cf]
//[of]:on key down (key event)
private func on key down (m: box, e: key event)
	return on key down (class (m)) {m, e}
end
//[cf]
//[of]:on key up (key event)
private func on key up (m: box, e: key event)
	return on key up (class (m)) {m, e}
end
//[cf]
//[of]:on char (char event)
private func on char (m: box, e: char event)
	return on char (class (m)) {m, e}
end
//[cf]
//[of]:on mouse down (mouse button event)
public func on mouse down (m: box, e: mouse button event)
	return on mouse down (class (m)) {m, e}
end
//[cf]
//[of]:on mouse up (mouse button event)
public func on mouse up (m: box, e: mouse button event)
	return on mouse up (class (m)) {m, e}
end
//[cf]
//[of]:on mouse move (mouse move event)
public func on mouse move (m: box, e: mouse move event)
	return on mouse move (class (m)) {m, e}
end
//[cf]
//[of]:on mouse wheel (mouse wheel event)
public func on mouse wheel (m: box, e: mouse wheel event)
	return on mouse wheel (class (m)) {m, e}
end
//[cf]
//[of]:on mouse cancel (event)
public func on mouse cancel (m: box)
	def e := event (mouse cancel event type)
	return on mouse cancel (class (m)) {m, e}
end
//[cf]
//[of]:on mouse double click (mouse button event)
public func on mouse double click (m: box, e: mouse button event)
	return on mouse double click (class (m)) {m, e}
end
//[cf]
//[of]:on popup (popup event)
public func on popup (m: box, e: popup event)
	return on popup (class (m)) {m, e}
end
//[cf]
//[of]:on enter menu
private func on enter menu (m: box)
	def e := event (enter menu event type)
	return on enter menu (class (m)) {m, e}
end
//[cf]
//[of]:on leave menu
private func on leave menu (m: box)
	def e := event (leave menu event type)
	return on leave menu (class (m)) {m, e}
end
//[cf]
//[c]
//[of]:on value changed
public func on value changed (m: box)
	def e := event (value changed event type)
	return on value changed (class (m)) {m, e}
end
//[cf]
//[of]:on index changed
public func on index changed (m: box)
	def e := event (index changed event type)
	return on index changed (class (m)) {m, e}
end
//[cf]
//[of]:on selection changed
public func on selection changed (m: box)
	def e := event (selection changed event type)
	return on selection changed (class (m)) {m, e}
end
//[cf]
//[of]:on click
public func on click (m: box)
	def e := event (click event type)
	return on click (class (m)) {m, e}
end
//[cf]
//[c]
//[of]:on child event (child, event)
public func on child event (m: box, child: box, e: event)
	return on child event (class (m)) {m, child, e}
end
//[cf]
//[of]:notify parent (event)
//[c]Sends the event to the parent with self as the source of the event
//[c]
public func notify parent (m: box, e: event)

	def parent = parent (m)
	if is nil (parent)
		return false
	end
	
	return on child event (parent, m, e)

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

	// Initialize-Release
	release: {box} void
	get interface: {box, interface id} interface

	// Geometry
	compute min size: {box} void
	adjust: {box} void
	
	// Focus
	accept focus: {box} bool
	
	// Selection
	cut: {box} bool
	copy: {box} bool
	paste: {box} bool
	clear: {box} bool
	select all: {box} bool
	can cut: {box} bool
	can copy: {box} bool
	can paste: {box} bool
	can clear: {box} bool
	can select all: {box} bool

	// Events
	on size: {box} void
	on paint: {box, canvas, rectangle} void
	on drop files : {box, drop files event} void
	on receive primary selection: {box, receive primary selection event} void
	on query primary selection: {box, query primary selection event} void

	on focus: {box, event} bool
	on blur: {box, event} bool
	on key down: {box, event} bool
	on key up: {box, event} bool
	on char: {box, event} bool
	on mouse down: {box, event} bool
	on mouse up: {box, event} bool
	on mouse move: {box, event} bool
	on mouse wheel: {box, event} bool
	on mouse cancel: {box, event} bool
	on mouse double click: {box, event} bool
	on popup: {box, event} bool
	on enter menu: {box, event} bool
	on leave menu: {box, event} bool
	
	on value changed: {box, event} bool
	on selection changed: {box, event} bool
	on index changed: {box, event} bool
	on click: {box, event} bool

	on child event: {box, box, event} bool

end
//[cf]
//[of]:box class
//[c]Initializes the box class
//[c]
public func box class
	def c = the box class
	if ~ initialized
		initialized = true

		equ notify parent = ^notify parent (box, event)
		equ do nothing = ^do nothing (box)
		equ yes = ^yes (box)
		equ no = ^no (box)

		c . mem size = sizeof local box class
		c . release = ^actual release (box)
		c . get interface = ^actual get interface (box, interface id)
		c . adjust = do nothing

		c . compute min size = do nothing
		c . accept focus = no
		c . cut = ^actual cut (box)
		c . copy = no
		c . paste = no
		c . clear = no
		c . select all = no
		c . can cut = ^actual can cut (box)
		c . can copy = no
		c . can paste = no
		c . can clear = no
		c . can select all = no
		
		c . on size = default size function
		c . on paint = ^handle paint (box, canvas, rectangle)
		c . on drop files = ^handle drop files (box, drop files event)
		c . on query primary selection = ^handle query primary selection (box, query primary selection event)
		c . on receive primary selection = ^handle receive primary selection (box, receive primary selection event)

		c . on focus = default focus function
		c . on blur = default blur function
		c . on key down = default key down function
		c . on key up = default key up function
		c . on char = default char function
		c . on mouse down = default mouse down function
		c . on mouse up = default mouse up function
		c . on mouse move = default mouse move function
		c . on mouse wheel = default mouse wheel function
		c . on mouse cancel = default mouse cancel function
		c . on mouse double click = default mouse double click function
		c . on popup  = default popup function
		c . on enter menu = default enter menu function
		c . on leave menu = default leave menu function

		c . on value changed = default value changed function
		c . on selection changed = default selection changed function
		c . on index changed = default index changed function
		c . on click = default click function

		c . on child event = ^handle child event (box, box, event)

		// GTK+ methods
		c . activate = ^actual activate (box)
		c . set focus = ^actual set focus (box)
		c . set read only = ^do nothing (box, bool)
		c . set enable = ^actual set enable (box, bool)
		c . is read only = ^actual is read only (box)
	end
	return c
end

private def initialized = false
private def the box class: local box class
//[cf]
//[of]:copy (src class)
//[c]
public func copy (dst: box class, src: box class)
	copy (dst:mem, src:mem, mem size (src))
end
//[cf]
//[cf]

⌨️ 快捷键说明

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