check-box.zc

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

ZC
183
字号
//[of]:description
//[c]Edit a boolean value
//[c]
//[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 "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 "gtk/gtk"
//[cf]
//[c]
//[of]:check box
//[of]:type
public struct check box : local box
	private read only : bool
end
//[cf]
//[of]:instance creation
//[of]:new check box (parent, caption)
public func new check box (parent: box, caption: string)

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

end
//[cf]
//[cf]
//[of]:text
//[of]:text
public func text (m: check box)

	return from UTF8 (gtk_button_get_label (check button (m)))

end
//[cf]
//[of]:set text (caption)
public func set text (m: check box, t: string)

	gtk_button_set_label (check button (m), to UTF8 (t))

end
//[cf]
//[cf]
//[of]:value
//[of]:click
//[c]Simulates a click
//[c]
public func click (m: check box)
	set checked (m, ~ is checked (m))
end
//[cf]
//[of]:set checked (checked)
public func set checked (m: check box, checked: bool)

	if is checked (m) == checked
		return
	end

	gtk_toggle_button_set_active (check button (m), checked -> TRUE, FALSE)

end
//[cf]
//[of]:is checked
public func is checked (m: check box)

	return gtk_toggle_button_get_active (check button (m)) == TRUE

end
//[cf]
//[of]:value
//[c]Just a synonym for "is checked"
//[c]
public equ value (m: check box) = 
	is checked (m)
//[cf]
//[cf]
//[c]
//[of]:restricted
//[of]:initialize (parent, caption)
public func initialize (m: check box, parent: box, caption: string)

	def t := temp string buffer
	append caption (caption, t)
	def p = gtk_check_button_new_with_mnemonic(as string (t))
	release (t)
	widget (m) = p
	gtk_widget_show (p)

	connect (m, 
		"toggled", 
		^toggled (GtkToggleButton, check box))

	initialize (super (m), parent)
	class (m) = check box class
	read only (m) = false

end
//[cf]
//[c]
//[of]:actual set read only (bool)
//[c]Sets the read-only flag
//[c]
public func actual set read only (m: check box, ro: bool)

	// exit if unchanged
	if read only (m) == ro
		return
	end
	
	read only (m) = ro
	
end
//[cf]
//[c]
//[cf]
//[of]:private
//[of]:check button
private equ check button (m: check box) = 
	widget (m) : GtkCheckButton
//[cf]
//[c]
//[of]:toggled (toggle button, check box)
//[c]Convert the GTK+ toggled event to a SWIFT event
//[c]
private func toggled (w: GtkToggleButton, m: check box)

	on value changed (m)

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

	def c = the check box class
	if ~ initialized
		initialized = true
		c . copy (box class)
		c . set read only = ^actual set read only (check box, bool)
		c . accept focus = ^yes (box)
	end
	return c

end

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

⌨️ 快捷键说明

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