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

📄 box.zc

📁 实现树形结构
💻 ZC
📖 第 1 页 / 共 4 页
字号:
//[cf]
//[cf]
//[of]:display
//[of]:invalidate
//[c]
public func invalidate (m: box)
	gtk_widget_queue_draw (widget (m))
end
//[cf]
//[of]:invalidate (rectangle)
//[c]
public func invalidate (m: box, r: rectangle)

	gtk_widget_queue_draw_area (
		widget (m),
		x (r),
		y (r),
		w (r),
		h (r))

end
//[cf]
//[of]:canvas
//[c]Creates a canvas for this box
//[c]
public func canvas (m: box, return c: canvas)
	initialize (c, widget (m))
end
//[cf]
//[cf]
//[of]:cursor
//[of]:set cursor (cursor)
//[c]
public func set cursor (m: box, c: cursor)

	def previous = cursor (m)
	if c <> previous
		def window = gtk_widget_get_window (widget (m))
		if not nil (window)
			cursor (m) = c
			gdk_window_set_cursor (window, id (c))
		end
	end

	return previous

end
//[cf]
//[of]:cursor position
//[c]
public func cursor position (m: box, return pt: point)

	def window = gtk_widget_get_window (widget (m))
	if is nil (window)
		x (pt) = -1
		y (pt) = -1
		return
	end
	
	def x: [1] int
	def y: [1] int
	def mask: [1] GdkModifierType
	gdk_window_get_pointer (window, x, y, mask)
	x (pt) = x[]
	y (pt) = y[]

end
//[cf]
//[of]:start capture
//[c]
public func start capture (m: box)
	gtk_grab_add (widget (m))
end
//[cf]
//[of]:stop capture
//[c]
public func stop capture (m: box)
	gtk_grab_remove (widget (m))
end
//[cf]
//[cf]
//[of]:focus
//[of]:set focus
public func set focus (m: box)
	set focus (class (m)) {m}
end
//[cf]
//[of]:transfer focus (reverse)
//[c]Transfers the focus to the first valid control after self.
//[c]It can be a descendant of self.
//[c]
public func transfer focus (m: box, reverse: bool)

	def first = m
	def c = first
	repeat
		if reverse
			c = prev in tree (c)
		else
			c = next in tree (c, true)
		end
		
		// completed the loop, no box accept focus
		if c==first; return; end
		
		if can get focus (c)
			set focus (c)
			return
		end

	end

end
//[cf]
//[of]:accept focus
//[c]
public func accept focus (m: box)
	return accept focus (class (m)) {m}
end
//[cf]
//[of]:can get focus
//[c]Returns true if the control can get the focus
//[c]
public func can get focus (m: box)

	if ~ accept focus (m)
		return false
	end

	each ancestor with self (m) ? c
		if not visible (c) || not enabled (c) || being destroyed (c)
			return false
		end
	end

	return true

end
//[cf]
//[cf]
//[of]:selection
//[of]:cut
//[c]
public func cut (m: box)
	return cut (class (m)) {m}
end
//[cf]
//[of]:copy
//[c]
public func copy (m: box)
	return copy (class (m)) {m}
end
//[cf]
//[of]:paste
//[c]
public func paste (m: box)
	return paste (class (m)) {m}
end
//[cf]
//[of]:clear
//[c]
public func clear (m: box)
	return clear (class (m)) {m}
end
//[cf]
//[of]:select all
//[c]
public func select all (m: box)
	return select all (class (m)) {m}
end
//[cf]
//[c]
//[of]:can cut
//[c]
public func can cut (m: box)
	return can cut (class (m)) {m}
end
//[cf]
//[of]:can copy
//[c]
public func can copy (m: box)
	return can copy (class (m)) {m}
end
//[cf]
//[of]:can paste
//[c]
public func can paste (m: box)
	return can paste (class (m)) {m}
end
//[cf]
//[of]:can clear
//[c]
public func can clear (m: box)
	return can clear (class (m)) {m}
end
//[cf]
//[of]:can select all
//[c]
public func can select all (m: box)
	return can select all (class (m)) {m}
end
//[cf]
//[c]
//[of]:take primary selection
//[c]The control says that it owns the primary selection
//[c]
public func take primary selection (m: box)

	gtk_selection_owner_set (
		widget (m), 
		GDK_SELECTION_PRIMARY,
		GDK_CURRENT_TIME)

end
//[cf]
//[of]:add primary selection format (clipboard format)
//[c]
public func add primary selection format (m: box, cf: clipboard format)

	gtk_selection_add_target (widget (m), GDK_SELECTION_PRIMARY, cf, 1)

end
//[cf]
//[of]:query primary selection (clipboard format)
//[c]
public func query primary selection (m: box, cf: clipboard format)

	gtk_selection_convert (
		widget (m), 
		GDK_SELECTION_PRIMARY,
		cf,
		GDK_CURRENT_TIME)

end
//[cf]
//[of]:send primary selection (event, buffer, size)
//[c]This method is called from a query primary selection event
//[c]
public func send primary selection (
		m: box, 
		e: query primary selection event, 
		buffer: [] byte,
		size: size)

	def selection data = data (e) : GtkSelectionData
	def type = target (selection data)

	gtk_selection_data_set (
		selection data,
		type,
		8,
		buffer: [] guchar,
		size: gint)

end
//[cf]
//[c]
//[cf]
//[of]:visibility
//[of]:set visible (bool)
//[c]
public func set visible (m: box, vi: bool)

	// exit if unchanged
	if visible (m) == vi
		return
	end

	if vi
		gtk_widget_show (widget (m))
	else
		gtk_widget_hide (widget (m))
	end
	
	visible (m) = vi
	
end
//[cf]
//[of]:show
//[c]
public func show (m: box)
	set visible(m, true)
end
//[cf]
//[of]:hide
//[c]
public func hide (m: box)
	set visible(m, false)
end
//[cf]
//[c]
//[of]:is visible
//[c]
public func is visible (m: box)
	return visible (m)
end
//[cf]
//[of]:not visible
//[c]
public equ not visible (b: box) = ~ is visible (b)
//[cf]
//[cf]
//[of]:enabling
//[of]:set enable (bool)
//[c]
public func set enable (m: box, en: bool)
	set enable (class (m)) {m, en}
end
//[cf]
//[of]:enable
//[c]
public func enable (m: box)
	set enable(m, true)
end
//[cf]
//[of]:disable
//[c]
public func disable (m: box)
	set enable(m, false)
end
//[cf]
//[c]
//[of]:is enabled
//[c]
public func is enabled (m: box)
	return enabled (m)
end
//[cf]
//[of]:not enabled
//[c]
public equ not enabled (b: box) = ~ is enabled (b)
//[cf]
//[cf]
//[of]:read only
//[of]:set read only (bool)
//[c]
public func set read only (m: box, ro: bool)
	set read only (class (m)) {m, ro}
end
//[cf]
//[c]
//[of]:is read only
//[c]
public func is read only (m: box)
	return is read only (class (m)) {m}
end
//[cf]
//[of]:not read only
//[c]
public equ not read only (b: box) = ~ is read only (b)
//[cf]
//[cf]
//[of]:drag and drop
//[of]:set drag accept files (bool)
//[c]
public func set drag accept files (m: box, f: bool)

	if f == accept drop files (m)
		return
	end

	if f
		def targets : [1] local GtkTargetEntry
		targets [0].target = "text/uri-list"
		targets [0].flags = 0
		targets [0].info = 0
		
		gtk_drag_dest_set (
			widget (m), 
			GTK_DEST_DEFAULT_ALL, 
			targets,
			1,
			(GDK_ACTION_COPY:int | GDK_ACTION_MOVE:int):GdkDragAction)
	else
		gtk_drag_dest_unset (widget (m))
	end

	accept drop files (m) = f

end
//[cf]
//[c]
//[cf]
//[of]:style
//[of]:set style (style)
//[c]
public func set style (m: box, style: box style)
	style (m) = style
end
//[cf]
//[c]
//[cf]
//[of]:converting
//[of]:get interface (id)
//[c]
public func get interface (m: box, id: interface id)
	return get interface (class (m)) {m, id}
end
//[cf]
//[c]
//[cf]
//[c]
//[of]:generic functions
//[c]Useful methods for default implementation
//[c]of some methods
//[c]
//[of]:do nothing
//[c]Never does anything
//[c]
public func do nothing (m: box)
	// Do nothing
end
//[cf]
//[of]:do nothing (bool)
//[c]Never does anything
//[c]
public func do nothing (m: box, b: bool)
	// do nothing
end
//[cf]
//[of]:do nothing (clipboard format)
//[c]Never does anything
//[c]
public func do nothing (m: box, o: clipboard format)
	// Do nothing
end
//[cf]
//[of]:yes
//[c]Always answers 'yes'
//[c]
public func yes (m: box)
	return true
end
//[cf]
//[of]:no
//[c]Always answers 'no'
//[c]
public func no (m: box)
	return false
end
//[cf]
//[c]
//[of]:min size of union
public func min size of union (m: box)

	def w = 0
	def h = 0
	each child (m) ? c
		w = max (w, min width (c))
		h = max (h, min height (c))
	end
	set min size (m, w, h)

end
//[cf]
//[of]:adjust to parent
//[c]Moves all the children to the size of the parent
//[c]
public func adjust to parent (m: box)

	each child (m) ? c
		move (c, client rect (m))
	end

end
//[cf]
//[of]:focus to first visible
public func focus to first visible (m: box, e: event)

	// transfer the focus to the first visible child
	each child (m) ? child
		if is visible (child)
			set focus (child)
			return true
		end
	end

	return handle focus (m, e)

end
//[cf]
//[of]:handle single child size
//[c]The size of the box has changed
//[c]
public func handle single child size (m: box)

	if not nil (first child (m))
		move (first child (m), client rect (m))
	end

end
//[cf]
//[of]:actual compute signle child min size
public func actual compute signle child min size (m: box)

	def w = 100
	def h = 100
	
	def first child = first child (m)
	if not nil (first child)
		w = min width (first child)
		h = min height (first child)
	end

	set min size(m, w, h)

end
//[cf]
//[cf]
//[of]:restricted
//[of]:initialize (parent)
//[c]Initializes and inserts a newly created box
//[c]
public func initialize (m: box, parent: box)

	parent (m) = nil
	first child (m) = nil
	last child (m) = nil
	next sibling (m) = nil
	prev sibling (m) = nil

	style (m) = nil
	being destroyed (m) = false
	valid min size (m) = false
	valid size (m) = false
	right pressed (m) = false
	
	empty (client rect (m))
	empty (min size (m))

	if not nil (parent)
		insert child (parent, m)
		
		// the style is inherited from the parent
		style (m) = style (parent)
	end

	key mask (m) = 0
	visible (m) = true
	enabled (m) = true
	accept drop files (m) = false
	cursor (m) = nil
	activated (m) = false
	read only (m) = false
	input method (m) = nil

	def w = widget (m)
	
	connect (m, 
		"size-allocate", 
		^size allocate (GtkWidget, GtkAllocation, box))

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

⌨️ 快捷键说明

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