border-box.zc
来自「实现树形结构」· ZC 代码 · 共 159 行
ZC
159 行
//[of]:description
//[c]Display a border around a single child box
//[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"
//[c]
import "graphics/geometry"
import "graphics/graphics"
import "user/box"
//[c]
import "win32/windows"
import "private/sys-graphics"
//[cf]
//[c]
//[of]:border box
//[of]:type
public struct border box : local box
// empty
end
//[cf]
//[of]:instance creation
//[of]:new border box (parent)
//[c]
public func new border box (parent: box)
equ s = sizeof local border box
def b = allocate memory (s): border box
initialize (b, parent)
return b
end
//[cf]
//[cf]
//[c]
//[of]:restricted
//[of]:initialize (parent)
//[c]
public func initialize (m: border box, parent: box)
initialize (super (m), parent)
class (m) = border box class
parent proc (m) = ^DefWindowProcA(HWND, UINT, WPARAM, LPARAM)
create window ex(
m,
WS_EX_CLIENTEDGE,
border box class name,
nil,
base style (m),
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
parent handle (m),
nil,
hinstance,
nil)
end
//[cf]
//[c]
//[of]:handle size (size event)
//[c]The size of the box has changed
//[c]
public func handle size (m: border box)
if not nil (first child (m))
move (first child (m), client rect (m))
end
end
//[cf]
//[of]:actual compute min size
//[c]
public func actual compute min size (m: border box)
def rect: local LPRECT
left (rect) = 0
top (rect) = 0
right (rect) = 100
bottom (rect) = 100
def first child = first child (m)
if not nil (first child)
right (rect) = min width (first child)
bottom (rect) = min height (first child)
end
AdjustWindowRectEx (rect, 0, 0, WS_EX_CLIENTEDGE)
set min size (m, width (rect), height (rect))
end
//[cf]
//[cf]
//[of]:private
//[of]:constants
//[c]
def border box class name := "zc-border"
//[cf]
//[cf]
//[c]
//[cf]
//[of]:border box class
//[of]:type
public struct border box class : local box class
// empty
end
//[cf]
//[of]:border box class
public func border box class
def c = the border box class
if ~ initialized
initialized = true
c . copy (box class)
c . wm size = ^wm size (box, UINT, WPARAM, LPARAM)
c . wm command = ^wm command (box, UINT, WPARAM, LPARAM)
c . wm notify = ^wm notify (box, UINT, WPARAM, LPARAM)
c . on size = ^handle size (border box)
c . compute min size = ^actual compute min size (border box)
def wc: local WNDCLASSA
wc . style = 0:d
wc . lpfnWndProc = ^ route window proc (HWND, UINT, WPARAM, LPARAM)
wc . cbClsExtra = 0
wc . cbWndExtra = 0
wc . hInstance = hinstance
wc . hIcon = nil
wc . hCursor = LoadCursorA (nil, IDC_ARROW)
wc . hbrBackground = nil
wc . lpszMenuName = nil
wc . lpszClassName = border box class name
wc . RegisterClassA
end
return c
end
private def initialized = false
private def the border box class : local border box class
//[cf]
//[cf]
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?