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

📄 drop-down-edit-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/vector-of-strings"
import "text/string-buffer"
//[c]
import "graphics/geometry"
import "user/box"
//[c]
import "glib/glib"
import "glib/glib-object"
import "gdk/gdk"
import "gtk/gtk"
//[cf]
//[c]
//[of]:drop down edit box
//[of]:type
public struct drop down edit box : local box
end
//[cf]
//[of]:instance creation
//[of]:new drop down edit box (parent)
public func new drop down edit box (parent: box)

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

end
//[cf]
//[cf]
//[of]:text
//[of]:text
public func text (m: drop down edit box)

	def s = gtk_entry_get_text (entry (m))
	return from UTF8 (s)
	
end
//[cf]
//[of]:set text (text)
public func set text (m: drop down edit box, text: string)

	def s = to UTF8 (text)
	gtk_entry_set_text (entry (m), s)

end
//[cf]
//[cf]
//[of]:selection
//[of]:select (start, stop)
public func select (m: drop down edit box, start: int, stop: int)
	gtk_editable_select_region (editable (m), start, stop)
end
//[cf]
//[of]:is selection empty
public func is selection empty (m: drop down edit box)
	return gtk_editable_get_selection_bounds (editable (m), nil, nil) == FALSE
end
//[cf]
//[cf]
//[of]:list
public func set list (m: drop down edit box, v: vector of strings)

	each (v) ? s
		gtk_combo_box_append_text (widget (m) : GtkComboBoxEntry, s)
	end

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

	// Create the widget before initializing super class
	// The super class needs widget to connect signals
	def e = gtk_combo_box_entry_new_text
	widget (m) = e
	gtk_widget_show (e)
	g_signal_connect (entry (m),  
		"changed", 
		^changed (GtkComboBoxEntry, drop down edit box):GCallback, m)

	g_signal_connect (entry (m),  
		"key-press-event", 
		^key press event (GtkWidget, GdkEventKey, box):GCallback, m)
		
	g_signal_connect (entry (m),  
		"key-release-event", 
		^key release event (GtkWidget, GdkEventKey, box):GCallback, m)

	g_signal_connect (entry (m),  
		"focus-in-event", 
		^focus in event (GtkWidget, GdkEventFocus, box):GCallback, m)

	g_signal_connect (entry (m),  
		"focus-out-event", 
		^focus out event (GtkWidget, GdkEventFocus, box):GCallback, m)

	initialize (super (m), parent)
	class (m) = drop down edit box class

end
//[cf]
//[c]
//[of]:actual cut
public func actual cut (m: drop down edit box)
	gtk_editable_cut_clipboard (editable (m))
	return true
end
//[cf]
//[of]:actual copy
public func actual copy (m: drop down edit box)
	gtk_editable_copy_clipboard (editable (m))
	return false
end
//[cf]
//[of]:actual paste
public func actual paste (m: drop down edit box)
	gtk_editable_paste_clipboard (editable (m))
	return true
end
//[cf]
//[of]:actual clear
public func actual clear (m: drop down edit box)
	gtk_editable_delete_selection (editable (m))
	return true
end
//[cf]
//[of]:actual select all
public func actual select all (m: drop down edit box)

	select (m, 0, -1)
	return true

end
//[cf]
//[of]:actual can copy
public func actual can copy (m: drop down edit box)

	return ~ is selection empty (m)

end
//[cf]
//[of]:actual can paste
private func actual can paste (m: drop down edit box)

	if is read only (m)
		return false
	end
	
	/*def result = false
	def fmt = 0:UINT
	
	// If the clipboard contains some CF_TEXT data, allow paste
	if OpenClipboard (hwnd (m)) == 0
		return result
	end
	
	repeat
		fmt = EnumClipboardFormats (fmt)
		if fmt == 0(d)
			break
		end
		
		if fmt == CF_TEXT
			result = true
			break
		end
	end
	
	CloseClipboard
	
	return result*/
	return false

end
//[cf]
//[of]:actual can clear
public func actual can clear (m: drop down edit box)

	return ~ is read only (m) && ~ is selection empty (m)

end
//[cf]
//[c]
//[of]:actual is read only
public func actual is read only (m: drop down edit box)
	return gtk_editable_get_editable (editable (m)) == FALSE
end
//[cf]
//[of]:actual set read only
public func actual set read only (m: drop down edit box, ro: bool)

	if is read only (m) == ro
		return
	end
	
	gtk_editable_set_editable (editable (m), ro -> FALSE, TRUE)
	
end
//[cf]
//[cf]
//[of]:private
//[of]:entry
private equ entry (m: drop down edit box) = 
	
	gtk_bin_get_child (widget (m) : GtkBin) : GtkEntry
//[cf]
//[of]:editable
private equ editable (m: drop down edit box) = 

	entry (m) : GtkEditable
//[cf]
//[c]
//[of]:changed (entry, drop down edit box)
//[c]This method is invoked by gtk when the value has changed
//[c]
private func changed (e: GtkComboBoxEntry, m: drop down edit box)

	on value changed (m)

end
//[cf]
//[cf]
//[cf]
//[of]:drop down edit box class
//[of]:type
public struct drop down edit box class : local box class
end
//[cf]
//[of]:drop down edit box class
public func drop down edit box class

	def c = the drop down edit box class
	if ~ initialized
		initialized = true
		c . copy (box class)
		c . cut = ^actual cut (drop down edit box)
		c . copy = ^actual copy (drop down edit box)
		c . paste = ^actual paste (drop down edit box)
		c . clear = ^actual clear (drop down edit box)
		c . select all = ^actual select all (drop down edit box)
		c . can copy = ^actual can copy (drop down edit box)
		c . can paste = ^actual can paste (drop down edit box)
		c . can clear = ^actual can clear (drop down edit box)
		c . can select all = ^yes (box)
		c . set read only = ^actual set read only (drop down edit box, bool)
		c . is read only = ^actual is read only (drop down edit box)
		c . accept focus = ^yes (box)
	end
	return c

end

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

⌨️ 快捷键说明

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