1 Star 0 Fork 0

橙子/lxnWalk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
pushbutton.go 2.30 KB
一键复制 编辑 原始数据 按行查看 历史
橙子 提交于 2020-08-13 10:03 . .
// Copyright 2010 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build windows
package walk
import (
"github.com/xuchengzhi/win"
)
type PushButton struct {
Button
}
func NewPushButton(parent Container) (*PushButton, error) {
pb := new(PushButton)
if err := InitWidget(
pb,
parent,
"BUTTON",
win.WS_TABSTOP|win.WS_VISIBLE|win.BS_PUSHBUTTON,
0); err != nil {
return nil, err
}
pb.Button.init()
pb.GraphicsEffects().Add(InteractionEffect)
pb.GraphicsEffects().Add(FocusEffect)
return pb, nil
}
func (*PushButton) LayoutFlags() LayoutFlags {
return GrowableHorz
}
func (pb *PushButton) SizeHint() Size {
return pb.MinSizeHint()
}
func (pb *PushButton) ImageAboveText() bool {
return pb.hasStyleBits(win.BS_TOP)
}
func (pb *PushButton) SetImageAboveText(value bool) error {
if err := pb.ensureStyleBits(win.BS_TOP, value); err != nil {
return err
}
// We need to set the image again, or Windows will fail to calculate the
// button control size correctly.
return pb.SetImage(pb.image)
}
func (pb *PushButton) ensureProperDialogDefaultButton(hwndFocus win.HWND) {
widget := windowFromHandle(hwndFocus)
if widget == nil {
return
}
if _, ok := widget.(*PushButton); ok {
return
}
form := ancestor(pb)
if form == nil {
return
}
dlg, ok := form.(dialogish)
if !ok {
return
}
defBtn := dlg.DefaultButton()
if defBtn == nil {
return
}
if err := defBtn.setAndClearStyleBits(win.BS_DEFPUSHBUTTON, win.BS_PUSHBUTTON); err != nil {
return
}
if err := defBtn.Invalidate(); err != nil {
return
}
}
func (pb *PushButton) WndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) uintptr {
switch msg {
case win.WM_GETDLGCODE:
hwndFocus := win.GetFocus()
if hwndFocus == pb.hWnd {
form := ancestor(pb)
if form == nil {
break
}
dlg, ok := form.(dialogish)
if !ok {
break
}
defBtn := dlg.DefaultButton()
if defBtn == pb {
pb.setAndClearStyleBits(win.BS_DEFPUSHBUTTON, win.BS_PUSHBUTTON)
return win.DLGC_BUTTON | win.DLGC_DEFPUSHBUTTON
}
break
}
pb.ensureProperDialogDefaultButton(hwndFocus)
case win.WM_KILLFOCUS:
pb.ensureProperDialogDefaultButton(win.HWND(wParam))
}
return pb.Button.WndProc(hwnd, msg, wParam, lParam)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/xuchengzhi/lxnWalk.git
git@gitee.com:xuchengzhi/lxnWalk.git
xuchengzhi
lxnWalk
lxnWalk
6b3f71bcaf88

搜索帮助