代码拉取完成,页面将自动刷新
// 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)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。