source: trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/UI/CheckBox.ab@ 644

Last change on this file since 644 was 644, checked in by イグトランス (egtra), 16 years ago

#222 3状態への対応

File size: 3.1 KB
Line 
1#require <Classes/ActiveBasic/Windows/UI/ButtonBase.ab>
2
3Namespace ActiveBasic
4Namespace Windows
5Namespace UI
6
7Enum CheckState
8 Unchecked = BST_UNCHECKED
9 Checked = BST_CHECKED
10 Indeterminate = BST_INDETERMINATE
11End Enum
12
13/*!
14@date 2008/07/13
15@brief チェックボックスを表すクラス。
16@author Egtra
17*/
18Class CheckBox
19 Inherits ButtonBase
20Protected
21 Override Sub GetCreateStruct(ByRef cs As CREATESTRUCT)
22 Super.GetCreateStruct(cs)
23 cs.style Or= BS_AUTOCHECKBOX
24 End Sub
25Public
26 /*!
27 @brief チェックされているかどうかの取得。
28 @retval true チェックされているもしくは第3状態
29 @retval false チェックされていない
30 */
31 Const Function Checked() As Boolean
32 Checked = SendMessage(BM_GETCHECK) > 0
33 End Function
34
35 /*!
36 @brief チェックされているかどうかの設定。
37 @param[in] check チェックを入れるならtrue, 外すならfalse。
38 */
39 Sub Checked(check As Boolean)
40 SendMessage(BM_SETCHECK, check As WPARAM, 0)
41 End Sub
42
43 /*!
44 @brief チェック状態の取得
45 */
46 Const Function State() As CheckState
47 Dim ret = SendMessage(BM_GETCHECK)
48/*
49 If ret = BST_UNCHECKED Or ret = BST_CHECKED Or ret = BST_INDETERMINATE Then
50 State = ret As CheckState
51*/
52 If ret = BST_CHECKED Then
53 State = CheckState.Checked
54 ElseIf ret = BST_INDETERMINATE Then
55 State = CheckState.Indeterminate
56 Else
57 State = CheckState.Unchecked
58 End If
59 End Function
60
61 /*!
62 @brief チェック状態の設定
63 */
64 Sub State(state As CheckState)
65 SendMessage(BM_SETCHECK, state As WPARAM, 0)
66 End Sub
67
68 /*!
69 @brief クリック時に自動で状態変化するかどうかの取得。
70 @retval true 自動変化する
71 @retval false 自動変化しない
72 */
73 Function AutoCheck() As Boolean
74 AutoCheck = autoCheck(Style)
75 End Function
76
77 /*!
78 @brief クリック時に自動で状態変化するどうかの設定。
79 @param[in] check 自動で変化させるならTrue、そうでないならFalse。
80 */
81 Sub AutoCheck(autoCheck As Boolean)
82 If autoCheck Then
83 Style = Style Or BS_AUTOCHECKBOX
84 Else
85 Style = (Style And (Not BS_AUTOCHECKBOX)) Or BS_CHECKBOX
86 End If
87 End Sub
88
89 /*!
90 @brief 3状態目を使用するどうかの設定。
91 @param[in] useThreeState 3状態目を使用するならTrue、そうでないならFalse。
92 */
93 Sub ThreeState(useThreeState As Boolean)
94 Dim oldStyle = This.Style
95 Dim style = oldStyle And (Not 7)
96 Dim buttonType = oldStyle And 7
97 If useThreeState = threeState(buttonType) Then
98 Exit Sub
99 End If
100 If useThreeState Then
101 If buttonType = BS_AUTOCHECKBOX Then
102 style Or= BS_AUTO3STATE
103 Else
104 style Or= BS_3STATE
105 End If
106 Else
107 If buttonType = BS_AUTO3STATE Then
108 style Or= BS_AUTOCHECKBOX
109 Else
110 style Or= BS_CHECKBOX
111 End If
112 End If
113 Style = style
114 End Sub
115
116 /*!
117 @brief 3状態目を使用しているかどうかの取得。
118 */
119 Function ThreeState() As Boolean
120 ThreeState = threeState(Style)
121 End Function
122Private
123 Static Function threeState(style As DWord) As Boolean
124 style And= 7
125 Return style = BS_3STATE Or style = BS_AUTO3STATE
126 End Function
127
128 Static Function autoCheck(style As DWord) As Boolean
129 style And= 7
130 Return (style = BS_AUTOCHECKBOX Or style = BS_AUTO3STATE)
131 End Function
132End Class
133
134End Namespace 'UI
135End Namespace 'Widnows
136End Namespace 'ActiveBasic
Note: See TracBrowser for help on using the repository browser.