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

📄 button.zc

📁 实现树形结构
💻 ZC
字号:
//[of]:description
//[c]A clickable button
//[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]:button
//[of]:type
public struct button : local box
end
//[cf]
//[of]:instance creation
//[of]:new button (parent, caption)
public func new button (parent: box, caption: string)

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

end
//[cf]
//[cf]
//[of]:actions
//[of]:click
//[c]Click - simulate a button press
//[c]
public func click (m: button)
	gtk_button_clicked (button (m))
end
//[cf]
//[of]:set default (bool)
public func set default (m: button, default: bool)

	// ### GTK+ handles default buttons but it requires
	// ### to have them as direct child of the dialog window.

	/*gtk_widget_set_flags (widget (m), GTK_CAN_DEFAULT:gint)
	gtk_widget_grab_default (widget (m))*/

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

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

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

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

end
//[cf]
//[of]:set min button width (w)
//[c]
public func set min button width (m: button, w: int)
	// this method has no effect in GTK+
end
//[cf]
//[cf]
//[of]:converting
//[of]:as button
//[c]Returns a pointer to a button from a box if the box is a button
//[c]
public equ as button (m: box) = get interface (m, button interface) : button
//[cf]
//[cf]
//[c]
//[of]:restricted
//[of]:initialize (parent, caption)
public func initialize (m: button, parent: box, caption: string)

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

	connect (m, 
		"clicked", 
		^clicked (GtkButton, button))

	initialize (super (m), parent)
	class (m) = button class

end
//[cf]
//[c]
//[of]:actual get interface (interface id)
public func actual get interface (m: button, id: interface id)

	if id == button interface
		return m
	end
	
	return actual get interface (super (m), id)

end
//[c]
private equ button interface = the button class
//[cf]
//[c]
//[cf]
//[of]:private
//[of]:button
//[c]
private equ button (m: button) = 

	widget (m) : GtkButton
//[cf]
//[of]:class
//[c]
private equ class (m: button) = 

	class (super (m)) : button class
//[cf]
//[c]
//[of]:clicked (gtk button, button)
//[c]Catch GTK+ click event, then re-emit as SWIFT event
//[c]
private func clicked (w: GtkButton, m: button)

	on click (m)

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

	def c = the button class
	if ~ initialized
		initialized = true
		c . copy (box class)
		c . mem size = sizeof local button class
		c . get interface = ^actual get interface (button, interface id)
		c . accept focus = ^yes (box)
	end
	return c

end

private def initialized = false
private def the button class: local button class
//[cf]
//[c]
//[cf]

⌨️ 快捷键说明

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