[go: up one dir, main page]

Menu

[0a098c]: / gui / WidgetUpdate.h  Maximize  Restore  History

Download this file

224 lines (207 with data), 4.9 kB

  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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#ifndef __WidgetUpdate_h__
#define __WidgetUpdate_h__
#include <gtk/gtk.h>
#include <set>
#include <string>
struct Update
{
std::string id;
long ntrig;
long nwriten;
double eff;
double rate;
double time;
double throughput;
};
void RunManager_update(const std::string &, Update &);
void Module_update(const std::string &, Update &);
void Update_all(int &nRm, Update **, int &nMd, Update **);
class Widget
{
private:
GtkWidget *w;
bool disconnecting;
static void disconnect(GtkWidget *wdgt, gpointer ptr);
public:
Widget(GtkWidget *o) :
w(0), disconnecting(false)
{
set_widget(o);
}
virtual ~Widget();
GtkWidget *wdgt() const
{
return w;
}
operator GtkWidget *()
{
return w;
}
void set_widget(GtkWidget *o);
};
class WidgetUpdate : public Widget
{
public:
WidgetUpdate(GtkWidget *o = 0) :
Widget(o)
{
}
virtual int update(Update & ptr) = 0; // returning !=0 will unsubscribe
};
class WidgetHolder
{
public:
typedef std::set<WidgetUpdate *> updateList;
private:
updateList updates;
public:
virtual ~WidgetHolder()
{
deleteAll();
}
virtual void addUpdate(WidgetUpdate *u)
{
updates.insert(u);
}
virtual void deleteUpdate(WidgetUpdate *u)
{
if (u)
{
updates.erase(u);
gtk_widget_hide(u->wdgt() );
gtk_widget_destroy(u->wdgt() );
}
}
virtual void deleteAll();
virtual int countUpdates()
{
return updates.size();
}
virtual bool empty()
{
return updates.empty();
}
virtual void updateAll(Update & ptr);
};
inline void WidgetHolder::updateAll(Update & ptr)
{
updateList::iterator it;
for (it = updates.begin(); it != updates.end(); ++it)
if ((*it)->update(ptr) )
deleteUpdate( *it);
}
inline void WidgetHolder::deleteAll()
{
updateList::iterator it;
for (it = updates.begin(); it != updates.end(); ++it)
deleteUpdate( *it);
// delete *it;
updates.clear();
}
//---------------------------------------------------------------------
// Some WidgetUpdates
//---------------------------------------------------------------------
class UpdateLabelNtrig : public WidgetUpdate
{
public:
UpdateLabelNtrig(GtkWidget *o) :
WidgetUpdate(o)
{
}
~UpdateLabelNtrig()
{
}
int update(Update & ptr);
};
class UpdateLabelTime : public WidgetUpdate
{
public:
UpdateLabelTime(GtkWidget *o) :
WidgetUpdate(o)
{
}
~UpdateLabelTime()
{
}
int update(Update & ptr);
};
class UpdateGaugeEff : public WidgetUpdate
{
public:
UpdateGaugeEff(GtkWidget *o) :
WidgetUpdate(o)
{
}
~UpdateGaugeEff()
{
}
int update(Update & ptr);
};
class UpdateGaugeRate : public WidgetUpdate
{
public:
UpdateGaugeRate(GtkWidget *o) :
WidgetUpdate(o)
{
}
~UpdateGaugeRate()
{
}
int update(Update & ptr);
};
class UpdateLabelRate : public WidgetUpdate
{
public:
UpdateLabelRate(GtkWidget *o) :
WidgetUpdate(o)
{
}
~UpdateLabelRate()
{
}
int update(Update & ptr);
};
class UpdateThroughPut : public WidgetUpdate
{
private:
double thrp;
double tm0;
public:
UpdateThroughPut(GtkWidget *o) :
WidgetUpdate(o), thrp(0.), tm0(0.)
{
}
int update(Update & ptr);
};
//////////////////////////////////////////////////////////////////////////
// class ToggleButton
//
// Created: Mon May 27 11:53:21 2002 Author: Carlos Lacasta
// Purpose:
//
//////////////////////////////////////////////////////////////////////////
class ToggleButton : public Widget
{
private:
public:
ToggleButton(GtkWidget *o) :
Widget(o)
{
if ( !GTK_IS_TOGGLE_BUTTON(o))
set_widget(0);
}
bool get_state()
{
if ( !wdgt() )
return false;
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(wdgt())) ? true : false;
}
void set_state(bool x)
{
if ( !wdgt() || !GTK_IS_TOGGLE_BUTTON(wdgt()))
return;
gtk_toggle_button_set_active(
GTK_TOGGLE_BUTTON(wdgt()), x ? TRUE : FALSE);
}
};
#endif