customwidget.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2012 The Walk Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. // +build windows
  5. package declarative
  6. import (
  7. "github.com/lxn/walk"
  8. )
  9. type PaintMode int
  10. const (
  11. PaintNormal PaintMode = iota // erase background before PaintFunc
  12. PaintNoErase // PaintFunc clears background, single buffered
  13. PaintBuffered // PaintFunc clears background, double buffered
  14. )
  15. type CustomWidget struct {
  16. AssignTo **walk.CustomWidget
  17. Name string
  18. Enabled Property
  19. Visible Property
  20. Font Font
  21. ToolTipText Property
  22. MinSize Size
  23. MaxSize Size
  24. StretchFactor int
  25. Row int
  26. RowSpan int
  27. Column int
  28. ColumnSpan int
  29. AlwaysConsumeSpace bool
  30. ContextMenuItems []MenuItem
  31. OnKeyDown walk.KeyEventHandler
  32. OnKeyPress walk.KeyEventHandler
  33. OnKeyUp walk.KeyEventHandler
  34. OnMouseDown walk.MouseEventHandler
  35. OnMouseMove walk.MouseEventHandler
  36. OnMouseUp walk.MouseEventHandler
  37. OnSizeChanged walk.EventHandler
  38. Style uint32
  39. Paint walk.PaintFunc
  40. ClearsBackground bool
  41. InvalidatesOnResize bool
  42. PaintMode PaintMode
  43. }
  44. func (cw CustomWidget) Create(builder *Builder) error {
  45. w, err := walk.NewCustomWidget(builder.Parent(), uint(cw.Style), cw.Paint)
  46. if err != nil {
  47. return err
  48. }
  49. return builder.InitWidget(cw, w, func() error {
  50. if cw.PaintMode != PaintNormal && cw.ClearsBackground {
  51. panic("PaintMode and ClearsBackground are incompatible")
  52. }
  53. w.SetClearsBackground(cw.ClearsBackground)
  54. w.SetInvalidatesOnResize(cw.InvalidatesOnResize)
  55. w.SetPaintMode(walk.PaintMode(cw.PaintMode))
  56. if cw.AssignTo != nil {
  57. *cw.AssignTo = w
  58. }
  59. return nil
  60. })
  61. }
  62. func (w CustomWidget) WidgetInfo() (name string, disabled, hidden bool, font *Font, toolTipText string, minSize, maxSize Size, stretchFactor, row, rowSpan, column, columnSpan int, alwaysConsumeSpace bool, contextMenuItems []MenuItem, OnKeyDown walk.KeyEventHandler, OnKeyPress walk.KeyEventHandler, OnKeyUp walk.KeyEventHandler, OnMouseDown walk.MouseEventHandler, OnMouseMove walk.MouseEventHandler, OnMouseUp walk.MouseEventHandler, OnSizeChanged walk.EventHandler) {
  63. return w.Name, false, false, &w.Font, "", w.MinSize, w.MaxSize, w.StretchFactor, w.Row, w.RowSpan, w.Column, w.ColumnSpan, w.AlwaysConsumeSpace, w.ContextMenuItems, w.OnKeyDown, w.OnKeyPress, w.OnKeyUp, w.OnMouseDown, w.OnMouseMove, w.OnMouseUp, w.OnSizeChanged
  64. }