-
Notifications
You must be signed in to change notification settings - Fork 3
/
vtkKWCheckButtonWithChangeColorButton.cxx
200 lines (152 loc) · 5.81 KB
/
vtkKWCheckButtonWithChangeColorButton.cxx
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*=========================================================================
Module: $RCSfile: vtkKWCheckButtonWithChangeColorButton.cxx,v $
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkKWCheckButtonWithChangeColorButton.h"
#include "vtkKWChangeColorButton.h"
#include "vtkKWCheckButton.h"
#include "vtkObjectFactory.h"
#include <vtksys/ios/sstream>
#include <vtksys/stl/string>
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkKWCheckButtonWithChangeColorButton);
vtkCxxRevisionMacro(vtkKWCheckButtonWithChangeColorButton, "$Revision: 1.5 $");
//----------------------------------------------------------------------------
vtkKWCheckButtonWithChangeColorButton::vtkKWCheckButtonWithChangeColorButton()
{
this->CheckButton = vtkKWCheckButton::New();
this->ChangeColorButton = vtkKWChangeColorButton::New();
this->DisableChangeColorButtonWhenNotChecked = 0;
}
//----------------------------------------------------------------------------
vtkKWCheckButtonWithChangeColorButton::~vtkKWCheckButtonWithChangeColorButton()
{
if (this->CheckButton)
{
this->CheckButton->Delete();
this->CheckButton = NULL;
}
if (this->ChangeColorButton)
{
this->ChangeColorButton->Delete();
this->ChangeColorButton = NULL;
}
}
//----------------------------------------------------------------------------
void vtkKWCheckButtonWithChangeColorButton::CreateWidget()
{
// Check if already created
if (this->IsCreated())
{
vtkErrorMacro(<< this->GetClassName() << " already created");
return;
}
// Call the superclass to create the whole widget
this->Superclass::CreateWidget();
// Create the checkbutton.
this->CheckButton->SetParent(this);
this->CheckButton->Create();
this->CheckButton->SetAnchorToWest();
// Create the change color button
this->ChangeColorButton->SetParent(this);
this->ChangeColorButton->Create();
// Pack the checkbutton and the change color button
this->Pack();
// Update
this->UpdateVariableBindings();
this->Update();
}
// ----------------------------------------------------------------------------
void vtkKWCheckButtonWithChangeColorButton::Pack()
{
if (!this->IsCreated())
{
return;
}
// Unpack everything
this->CheckButton->UnpackSiblings();
// Repack everything
vtksys_ios::ostringstream tk_cmd;
tk_cmd << "pack " << this->CheckButton->GetWidgetName()
<< " -side left -anchor w" << endl
<< "pack " << this->ChangeColorButton->GetWidgetName()
<< " -side left -anchor w -fill x -expand t -padx 2 -pady 2" << endl;
this->Script(tk_cmd.str().c_str());
}
//----------------------------------------------------------------------------
void vtkKWCheckButtonWithChangeColorButton::Update()
{
// Update enable state
this->UpdateEnableState();
// Disable the color change button if not checked
if (this->DisableChangeColorButtonWhenNotChecked &&
this->ChangeColorButton &&
this->CheckButton && this->CheckButton->IsCreated())
{
this->ChangeColorButton->SetEnabled(
this->CheckButton->GetSelectedState() ? this->GetEnabled() : 0);
}
}
// ----------------------------------------------------------------------------
void vtkKWCheckButtonWithChangeColorButton::SetDisableChangeColorButtonWhenNotChecked(
int _arg)
{
if (this->DisableChangeColorButtonWhenNotChecked == _arg)
{
return;
}
this->DisableChangeColorButtonWhenNotChecked = _arg;
this->Modified();
this->UpdateVariableBindings();
this->Update();
}
// ----------------------------------------------------------------------------
void vtkKWCheckButtonWithChangeColorButton::UpdateVariableBindings()
{
if (!this->IsCreated() ||
!this->CheckButton || !this->CheckButton->GetVariableName())
{
return;
}
// If the variable of the checkbutton is changed, i.e. its state has
// changed, then call our Update() so that we are given a chance
// to disable the state of the color change button.
// Nope, we can't use the checkbutton's Command, it might be used
// already (most likely).
vtksys_stl::string cmd(this->GetTclName());
cmd += " UpdateVariableCallback";
this->Script("trace remove variable %s {write} {%s}",
this->CheckButton->GetVariableName(), cmd.c_str());
if (this->DisableChangeColorButtonWhenNotChecked)
{
this->Script("trace add variable %s {write} {%s}",
this->CheckButton->GetVariableName(), cmd.c_str());
}
}
//----------------------------------------------------------------------------
void vtkKWCheckButtonWithChangeColorButton::UpdateVariableCallback(
const char*, const char*, const char*)
{
this->Update();
}
//----------------------------------------------------------------------------
void vtkKWCheckButtonWithChangeColorButton::UpdateEnableState()
{
this->Superclass::UpdateEnableState();
this->PropagateEnableState(this->CheckButton);
this->PropagateEnableState(this->ChangeColorButton);
}
//----------------------------------------------------------------------------
void vtkKWCheckButtonWithChangeColorButton::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
os << indent << "CheckButton: " << this->CheckButton << endl;
os << indent << "ChangeColorButton: " << this->ChangeColorButton << endl;
os << indent << "DisableChangeColorButtonWhenNotChecked: "
<< (this->DisableChangeColorButtonWhenNotChecked ? "On" : "Off") << endl;
}