-
Notifications
You must be signed in to change notification settings - Fork 0
/
tabpage.go
150 lines (115 loc) · 2.65 KB
/
tabpage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright 2011 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/lxn/win"
"strconv"
)
const tabPageWindowClass = `\o/ Walk_TabPage_Class \o/`
var tabPageBackgroundBrush Brush
func init() {
MustRegisterWindowClass(tabPageWindowClass)
tabPageBackgroundBrush, _ = NewSystemColorBrush(win.COLOR_WINDOW)
}
type TabPage struct {
ContainerBase
image *Bitmap
title string
tabWidget *TabWidget
titleChangedPublisher EventPublisher
imageChangedPublisher EventPublisher
}
func NewTabPage() (*TabPage, error) {
tp := new(TabPage)
if err := InitWindow(
tp,
nil,
tabPageWindowClass,
win.WS_POPUP,
win.WS_EX_CONTROLPARENT); err != nil {
return nil, err
}
tp.children = newWidgetList(tp)
tp.MustRegisterProperty("Title", NewProperty(
func() interface{} {
return tp.Title()
},
func(v interface{}) error {
return tp.SetTitle(v.(string))
},
tp.titleChangedPublisher.Event()))
tp.MustRegisterProperty("Image", NewProperty(
func() interface{} {
return tp.Image()
},
func(v interface{}) error {
var img *Bitmap
switch val := v.(type) {
case *Bitmap:
img = val
case int:
var err error
if img, err = Resources.Bitmap(strconv.Itoa(val)); err != nil {
return err
}
case string:
var err error
if img, err = Resources.Bitmap(val); err != nil {
return err
}
default:
return ErrInvalidType
}
return tp.SetImage(img)
},
tp.imageChangedPublisher.Event()))
return tp, nil
}
func (tp *TabPage) Enabled() bool {
if tp.tabWidget != nil {
return tp.tabWidget.Enabled() && tp.enabled
}
return tp.enabled
}
func (tp *TabPage) Background() Brush {
if tp.background != nil {
return tp.background
} else if tp.tabWidget != nil && tp.tabWidget.background == nullBrushSingleton {
return nullBrushSingleton
}
if win.IsAppThemed() {
return tabPageBackgroundBrush
}
return nil
}
func (tp *TabPage) Font() *Font {
if tp.font != nil {
return tp.font
} else if tp.tabWidget != nil {
return tp.tabWidget.Font()
}
return defaultFont
}
func (tp *TabPage) Image() *Bitmap {
return tp.image
}
func (tp *TabPage) SetImage(value *Bitmap) error {
tp.image = value
if tp.tabWidget == nil {
return nil
}
return tp.tabWidget.onPageChanged(tp)
}
func (tp *TabPage) Title() string {
return tp.title
}
func (tp *TabPage) SetTitle(value string) error {
tp.title = value
tp.titleChangedPublisher.Publish()
if tp.tabWidget == nil {
return nil
}
return tp.tabWidget.onPageChanged(tp)
}