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

📄 label-box.zc

📁 实现树形结构
💻 ZC
字号:
//[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 "base/memory-allocator"
import "text/string"
import "text/string-buffer"
//[c]
import "graphics/geometry"
import "graphics/graphics"
import "user/box"
//[c]
import "glib/glib"
import "glib/glib-object"
import "gdk/gdk"
import "gtk/gtk"
//[cf]
//[c]
//[of]:label box
//[of]:type
public struct label box : local box

	private handler: gulong
	private can be truncated : bool

end
//[cf]
//[of]:instance creation
//[of]:new label box (parent, caption)
public func new label box (parent: box, caption: string)

	equ s = sizeof local label box
	def b = allocate memory (s) : label box
	initialize (b, parent, caption)
	return b

end
//[cf]
//[cf]
//[of]:accessing
//[of]:set text (caption)
public func set text (m: label box, caption: string)
	gtk_label_set_text (label (m), to UTF8 (caption))
end
//[cf]
//[of]:set font (font)
public func set font (m: label box, font: font)

	//font (m) = font

end
//[cf]
//[of]:set alignment (alignment)
public func set alignment (m: label box, alignment: alignment)

	def xalign : gint

	switch alignment
	case align left
		xalign = 0
	case align right
		xalign = 100
	else
		xalign = 50
	end
	
	gtk_misc_set_align (label (m), xalign, 50)

end
//[cf]
//[of]:set can be truncated (bool)
//[c]
public func set can be truncated (m: label box, t: bool)

	// unchanged ?
	if t == can be truncated (m)
		return
	end
	
	can be truncated (m) = t

	if t
		handler (m) = 
			connect (m, 
				"size-request", 
				^size request (GtkWidget, GtkRequisition, label box))
	else
		disconnect (m, handler (m))
	end
	
end
//[cf]
//[of]:set mnemonic box (box)
//[c]Sets the box to activate when the mnemonic is activated
//[c]
public func set mnemonic box (m: label box, box: box)
	gtk_label_set_mnemonic_widget (label (m), widget (box))
end
//[cf]
//[cf]
//[c]
//[of]:restricted
//[of]:initialize (parent, caption)
public func initialize (m: label box, parent: box, caption: string)

	def t := temp string buffer
	append caption (caption, t)
	def p = gtk_label_new_with_mnemonic(as string (t))
	release (t)
	widget (m) = p
	gtk_misc_set_align (p:GtkLabel, 100, 50)
	gtk_widget_show (p)

	initialize (super (m), parent)
	class (m) = label box class
	can be truncated (m) = false

end
//[cf]
//[cf]
//[of]:private
//[of]:label
private equ label (m: label box) = 
	widget (m) : GtkLabel
//[cf]
//[c]
//[of]:size request (GtkWidget, GtkRequisition, label box)
//[c]
private func size request (
		w: GtkWidget, 
		r: GtkRequisition, 
		m: label box) : void

	// disconnect to get the real size
	disconnect (m, handler (m))

	// ask for real size request
	def req : local GtkRequisition
	gtk_widget_size_request (widget (m), req)

	// reconnect
	handler (m) = 
		connect (m, 
			"size-request", 
			^size request (GtkWidget, GtkRequisition, label box))

	// reuse height, but width reset
	width (r) = 1
	height (r) = height (req)

end
//[cf]
//[cf]
//[cf]
//[of]:label box class
//[of]:type
public struct label box class : local box class
	// empty
end
//[cf]
//[of]:label box class
public func label box class

	def c = the label box class
	if ~ initialized
		initialized = true
		c . copy (box class)
		c . mem size = sizeof local label box class
	end
	return c

end

private def initialized = false
private def the label box class: local label box class
//[cf]
//[cf]

⌨️ 快捷键说明

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