📄 directory-box.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 "graphics/graphics"
import "user/box"
import "user/grid-box"
import "user/edit-box"
import "user/button"
import "toolbox/clipboard"
//[c]
import "win32/windows"
import "win32/shlobj"
//[cf]
//[c]
//[of]:directory box
//[of]:type
public struct directory box : local grid box
private edit box : edit box
private zoom button : button
private buffer: [MAX_PATH] char
end
//[cf]
//[of]:instance creation
//[of]:new directory box (parent)
public func new directory box (parent: box)
equ s = sizeof local directory box
def e = allocate memory (s): directory box
initialize (e, parent)
return e
end
//[cf]
//[cf]
//[of]:text
//[of]:text
//[c]Returns the content of the directory box
//[c]
public func text (m: directory box)
return text (edit box (m))
end
//[cf]
//[of]:set text (text)
//[c]Changes the content of the directory box
//[c]
public func set text (m: directory box, text: string)
set text (edit box (m), text)
end
//[cf]
//[cf]
//[of]:selection
//[of]:select (starting pos, ending pos)
//[c]Selects a part of the text
//[c]
public func select (m: directory box, starting pos: int, ending pos: int)
select (edit box (m), starting pos, ending pos)
end
//[cf]
//[of]:is selection empty
//[c]Tests if the current selection is empty
//[c]
public func is selection empty (m: directory box)
return is selection empty (edit box (m))
end
//[cf]
//[cf]
//[c]
//[of]:restricted
//[of]:initialize (parent)
public func initialize (m: directory box, parent: box)
initialize (super (m), parent)
class (m) = directory box class
def edit = new edit box (m)
def zoom = new button (m, "...")
set min button width (zoom, 0)
edit box (m) = edit
zoom button (m) = zoom
def v = const [] int (1, -1)
def h = const [] int (1, 0, -1)
def d = new grid cell (nil, zoom, 1, 0, 1, 1)
def c = new grid cell (d, edit, 0, 0, 1, 1)
configure (m, h, v, c)
end
//[cf]
//[c]
//[of]:actual cut
public func actual cut (m: directory box)
return cut (edit box (m))
end
//[cf]
//[of]:actual copy
public func actual copy (m: directory box)
return copy (edit box (m))
end
//[cf]
//[of]:actual paste
public func actual paste (m: directory box)
return paste (edit box (m))
end
//[cf]
//[of]:actual clear
public func actual clear (m: directory box)
return clear (edit box (m))
end
//[cf]
//[of]:actual select all
public func actual select all (m: directory box)
return select all (edit box (m))
end
//[cf]
//[of]:actual can copy
public func actual can copy (m: directory box)
return can copy (edit box (m))
end
//[cf]
//[of]:actual can paste
public func actual can paste (m: directory box)
return can paste (edit box (m))
end
//[cf]
//[of]:actual can clear
func actual can clear (m: directory box)
return can clear (edit box (m))
end
//[cf]
//[of]:actual set read only (ro)
public func actual set read only (m: directory box, ro: bool)
// exit if unchanged
if read only (m) == ro
return
end
read only (m) = ro
set read only (edit box (m), ro)
set enable (zoom button (m), is enabled (m) && ~ ro)
end
//[cf]
//[of]:actual set enable (en)
public func actual set enable (m: directory box, en: bool)
// exit if unchanged
if is enabled (m) == en
return
end
enabled (m) = en
set enable (edit box (m), en)
set enable (zoom button (m), en && ~ is read only (m))
end
//[cf]
//[c]
//[of]:handle child event (f, src box, event)
//[c]
public func handle child event (m: directory box, src: box, evt: event)
def t = type (evt)
if t == click event type
def bi : BROWSEINFOA
hwndOwner (bi) = hwnd (m)
pidlRoot (bi) = nil
pszDisplayName (bi) = buffer (m)
//lpszTitle (bi) = "Directory"
lpszTitle (bi) = nil
ulFlags (bi) = BIF_EDITBOX
lpfn (bi) = ^callback (HWND, UINT, LPARAM, LPARAM)
lParam (bi) = m : LPARAM
iImage (bi) = 0
def id = SHBrowseForFolderA (bi)
if id <> nil
SHGetPathFromIDListA (id, buffer (m))
set text (m, buffer (m))
return true
end
return true
end
return handle child event (super (m), src, evt)
end
//[c]
private [call="__stdcall"] func callback (hwnd: HWND, msg: UINT, lParam: LPARAM, lpData: LPARAM)
equ m = lpData: directory box
if msg == BFFM_INITIALIZED
SendMessageA (hwnd, BFFM_SETSELECTIONA, 1:WPARAM, text (m):LPARAM)
end
return 0
end
//[cf]
//[cf]
//[of]:private
//[cf]
//[cf]
//[of]:directory box class
//[of]:type
public struct directory box class : local grid box class
// empty
end
//[cf]
//[of]:directory box class
public func directory box class
def c = the directory box class
if ~ initialized
initialized = true
c . copy (grid box class)
c . cut = ^actual cut (directory box)
c . copy = ^actual copy (directory box)
c . paste = ^actual paste (directory box)
c . clear = ^actual clear (directory box)
c . select all = ^actual select all (directory box)
c . can copy = ^actual can copy (directory box)
c . can paste = ^actual can paste (directory box)
c . can clear = ^actual can clear (directory box)
c . can select all = ^yes (box)
c . set read only = ^actual set read only (directory box, bool)
c . set enable = ^actual set enable (directory box, bool)
c . on child event = ^handle child event (directory box, box, event)
end
return c
end
def initialized = false
def the directory box class: local directory box class
//[cf]
//[cf]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -