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

📄 drop-down-list-box.zc

📁 实现树形结构
💻 ZC
字号:
//[of]:description
//[c]Select an item from a drop-down list.
//[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/vector-of-strings"
import "text/string"
import "text/string-buffer"
//[c]
import "graphics/geometry"
import "graphics/graphics"
import "user/box"
//[c]
import "glib/glib"
import "gdk/gdk"
import "gtk/gtk"
//[cf]
//[c]
//[of]:drop down list box
//[of]:type
public struct drop down list box : local box

	private
		read only : bool
		number of items : int
		list of strings: vector of strings

end
//[cf]
//[of]:instance creation
//[of]:new drop down list box (parent)
public func new drop down list box (parent: box)

	equ s = sizeof local drop down list box
	def e = allocate memory (s): drop down list box
	initialize (e, parent)
	return e

end
//[cf]
//[cf]
//[of]:index
//[of]:index
//[c]Returns the index of the currently selected item, 
//[c]if any, in the list box of a drop down list box.
//[c]Returns -1 if no selected item
//[c]
public func index (m: drop down list box)

	return gtk_option_menu_get_history (option menu (m))

end
//[cf]
//[of]:set index (index)
//[c]Specifies the zero-based index of the string to select. 
//[c]If the index parameter is -1, any current selection in the list 
//[c]is removed and the edit control is cleared.
//[c]
public func set index (m: drop down list box, index: int)

	gtk_option_menu_set_history (option menu (m), index)

end
//[cf]
//[cf]
//[of]:drop down list
//[of]:show drop down (bool)
//[c]Shows / Hides the drop down list
//[c]
/*public func show drop down (m: drop down list box, show: bool)
	// ### not yet implemented in GTK+
end*/
//[cf]
//[of]:is dropped down
//[c]Test if the drop down list is visible
//[c]
/*public func is dropped down (m: drop down list box)
	// ### not yet implemented
end*/
//[cf]
//[c]
//[of]:set list (vector of strings)
public func set list (m: drop down list box, list: vector of strings)

	set list (m, list, 0)

end
//[cf]
//[of]:set list (vector of strings, index)
//[c]
public func set list (
		m: drop down list box, 
		list: vector of strings,
		index: int)

	def menu = gtk_menu_new : GtkMenu
	each (list) ? s
		def menu item = gtk_menu_item_new_with_label (s)
		gtk_menu_shell_append (menu, menu item)
		gtk_widget_show (menu item)
	end
	gtk_option_menu_set_menu (option menu (m), menu)

	set index (m, index)

end
//[cf]
//[of]:size of list
//[c]Returns the number of items in the list
//[c]
public func size of list (m: drop down list box)

	return number of items (m)

end
//[cf]
//[cf]
//[c]
//[of]:restricted
//[of]:initialize (parent)
public func initialize (m: drop down list box, parent: box)

	def menu = gtk_widget_new_0 (gtk_option_menu_get_type)
	widget (m) = menu
	gtk_widget_show (menu)	
	
	connect (m,
		"changed",
		^ changed (GtkOptionMenu, drop down list box))

	initialize (super (m), parent)
	class (m) = drop down list box class
	number of items (m) = 0
	read only (m) = false
	list of strings (m) = nil

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

	// exit if unchanged
	if read only (m) == ro
		return
	end
	
	read only (m) = ro
	
end
//[cf]
//[of]:actual release (m)
public func actual release (m: drop down list box)

	delete list of strings (m)
	actual release (super (m))

end
//[cf]
//[c]
//[cf]
//[of]:private
//[of]:option menu
//[c]
private equ option menu (m: drop down list box) = 
	
	widget (m) : GtkOptionMenu
//[cf]
//[of]:delete list of strings
//[c]Deletes the list of strings
//[c]
private func delete list of strings (m: drop down list box)

	if is nil (list of strings (m))
		return
	end
	each (list of strings (m)) ? s
		delete (s)
	end
	delete (list of strings (m))

end
//[cf]
//[c]
//[of]:changed (option menu, drop down list box)
//[c]The index has changed
//[c]
private func changed (w: GtkOptionMenu, m: drop down list box)
	on index changed (m)
end
//[cf]
//[cf]
//[cf]
//[of]:drop down list box class
//[of]:type
public struct drop down list box class : local box class
end
//[cf]
//[of]:drop down list box class
public func drop down list box class

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

end

private def initialized = false
private def the drop down list box class: local drop down list box class
//[cf]
//[cf]

⌨️ 快捷键说明

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