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

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

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

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

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

	gtk_entry_set_text (entry (m), to UTF8 (text))

end
//[cf]
//[cf]
//[of]:selection
//[of]:select (start, stop)
public func select (m: 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: edit box)

	return gtk_editable_get_selection_bounds (editable (m), nil, nil) == FALSE

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

	// Create the widget before initializing super class
	// The super class needs widget to connect signals
	def e = gtk_entry_new
	widget (m) = e
	gtk_widget_show (e)
	connect (m, "changed", ^changed (GtkEntry, edit box))

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

end
//[cf]
//[c]
//[of]:actual cut
public func actual cut (m: edit box)

	gtk_editable_cut_clipboard (editable (m))
	return true

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

	gtk_editable_copy_clipboard (editable (m))
	return false

end
//[cf]
//[of]:actual paste
public func actual paste (m: edit box)

	gtk_editable_paste_clipboard (editable (m))
	return true

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

	gtk_editable_delete_selection (editable (m))
	return true

end
//[cf]
//[of]:actual select all
public func actual select all (m: edit box)

	select (m, 0, -1)
	return true

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

	return ~ is selection empty (m)

end
//[cf]
//[of]:actual can paste
private func actual can paste (m: 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: 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: edit box)

	return gtk_editable_get_editable (editable (m)) == FALSE

end
//[cf]
//[of]:actual set read only
public func actual set read only (m: 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: edit box) = 
	
	widget (m) : GtkEntry
//[cf]
//[of]:editable
private equ editable (m: edit box) = 

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

	on value changed (m)

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

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

end

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

⌨️ 快捷键说明

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