Commit 458f43a4aaff9b2cbd8d00382764a063238003d5
1 parent
30b68cb1
Exists in
master
and in
5 other branches
Iniciando atualizacao do controle de toggle
Showing
2 changed files
with
33 additions
and
44 deletions
Show diff stats
src/include/lib3270.h
@@ -449,7 +449,7 @@ | @@ -449,7 +449,7 @@ | ||
449 | * @param h Session handle. | 449 | * @param h Session handle. |
450 | * @param ix Toggle id. | 450 | * @param ix Toggle id. |
451 | * | 451 | * |
452 | - * @return 0 if the toggle was changed, errno code if not. | 452 | + * @return Toggle status. |
453 | */ | 453 | */ |
454 | LIB3270_EXPORT int lib3270_toggle(H3270 *h, LIB3270_TOGGLE ix); | 454 | LIB3270_EXPORT int lib3270_toggle(H3270 *h, LIB3270_TOGGLE ix); |
455 | 455 |
src/lib3270/toggles.c
@@ -78,37 +78,6 @@ static const char *toggle_names[LIB3270_TOGGLE_COUNT] = | @@ -78,37 +78,6 @@ static const char *toggle_names[LIB3270_TOGGLE_COUNT] = | ||
78 | "beep", /**< Beep on errors */ | 78 | "beep", /**< Beep on errors */ |
79 | }; | 79 | }; |
80 | 80 | ||
81 | - | ||
82 | -/* | ||
83 | -static void no_callback(H3270 *h, int value, LIB3270_TOGGLE_TYPE reason) | ||
84 | -{ | ||
85 | -} | ||
86 | - | ||
87 | -LIB3270_EXPORT int lib3270_register_tchange(H3270 *h, LIB3270_TOGGLE_ID ix, void (*func)(H3270 *, int, LIB3270_TOGGLE_TYPE)) | ||
88 | -{ | ||
89 | - struct toggle *t; | ||
90 | - | ||
91 | - CHECK_SESSION_HANDLE(h); | ||
92 | - | ||
93 | - if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) | ||
94 | - return EINVAL; | ||
95 | - | ||
96 | - t = &appres.toggle[ix]; | ||
97 | - | ||
98 | - if(func) | ||
99 | - { | ||
100 | - t->callback = func; | ||
101 | - t->callback(h, t->value, (int) TT_INITIAL); | ||
102 | - } | ||
103 | - else | ||
104 | - { | ||
105 | - t->callback = no_callback; | ||
106 | - } | ||
107 | - | ||
108 | - return 0; | ||
109 | -} | ||
110 | -*/ | ||
111 | - | ||
112 | LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE ix) | 81 | LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE ix) |
113 | { | 82 | { |
114 | CHECK_SESSION_HANDLE(session); | 83 | CHECK_SESSION_HANDLE(session); |
@@ -124,7 +93,6 @@ LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE i | @@ -124,7 +93,6 @@ LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE i | ||
124 | static void toggle_notify(H3270 *session, struct toggle *t, LIB3270_TOGGLE ix) | 93 | static void toggle_notify(H3270 *session, struct toggle *t, LIB3270_TOGGLE ix) |
125 | { | 94 | { |
126 | t->upcall(session, t, TT_INTERACTIVE); | 95 | t->upcall(session, t, TT_INTERACTIVE); |
127 | -// t->callback(session,t->value, (int) TT_INTERACTIVE); | ||
128 | 96 | ||
129 | if(session->update_toggle) | 97 | if(session->update_toggle) |
130 | session->update_toggle(session,ix,t->value,TT_INTERACTIVE,toggle_names[ix]); | 98 | session->update_toggle(session,ix,t->value,TT_INTERACTIVE,toggle_names[ix]); |
@@ -133,7 +101,8 @@ static void toggle_notify(H3270 *session, struct toggle *t, LIB3270_TOGGLE ix) | @@ -133,7 +101,8 @@ static void toggle_notify(H3270 *session, struct toggle *t, LIB3270_TOGGLE ix) | ||
133 | 101 | ||
134 | LIB3270_EXPORT void lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE ix, int value) | 102 | LIB3270_EXPORT void lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE ix, int value) |
135 | { | 103 | { |
136 | - struct toggle *t; | 104 | + char v = value ? True : False; |
105 | + struct toggle * t; | ||
137 | 106 | ||
138 | CHECK_SESSION_HANDLE(session); | 107 | CHECK_SESSION_HANDLE(session); |
139 | 108 | ||
@@ -141,7 +110,11 @@ LIB3270_EXPORT void lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE ix, int va | @@ -141,7 +110,11 @@ LIB3270_EXPORT void lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE ix, int va | ||
141 | return; | 110 | return; |
142 | 111 | ||
143 | t = &appres.toggle[ix]; | 112 | t = &appres.toggle[ix]; |
144 | - t->value = (value != 0); | 113 | + |
114 | + if(v == t->value) | ||
115 | + return; | ||
116 | + | ||
117 | + t->value = v; | ||
145 | 118 | ||
146 | toggle_notify(session,t,ix); | 119 | toggle_notify(session,t,ix); |
147 | } | 120 | } |
@@ -153,14 +126,14 @@ LIB3270_EXPORT int lib3270_toggle(H3270 *session, LIB3270_TOGGLE ix) | @@ -153,14 +126,14 @@ LIB3270_EXPORT int lib3270_toggle(H3270 *session, LIB3270_TOGGLE ix) | ||
153 | CHECK_SESSION_HANDLE(session); | 126 | CHECK_SESSION_HANDLE(session); |
154 | 127 | ||
155 | if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) | 128 | if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) |
156 | - return; | 129 | + return 0; |
157 | 130 | ||
158 | t = &appres.toggle[ix]; | 131 | t = &appres.toggle[ix]; |
159 | 132 | ||
160 | - t->value = !t->value; | 133 | + t->value = t->value ? False : True; |
161 | toggle_notify(session,t,ix); | 134 | toggle_notify(session,t,ix); |
162 | 135 | ||
163 | - return 0; | 136 | + return (int) t->value; |
164 | } | 137 | } |
165 | 138 | ||
166 | static void toggle_monocase(H3270 *session, struct toggle *t, LIB3270_TOGGLE_TYPE tt) | 139 | static void toggle_monocase(H3270 *session, struct toggle *t, LIB3270_TOGGLE_TYPE tt) |
@@ -176,10 +149,7 @@ void initialize_toggles(H3270 *session, struct toggle *toggle) | @@ -176,10 +149,7 @@ void initialize_toggles(H3270 *session, struct toggle *toggle) | ||
176 | int f; | 149 | int f; |
177 | 150 | ||
178 | for(f=0;f<LIB3270_TOGGLE_COUNT;f++) | 151 | for(f=0;f<LIB3270_TOGGLE_COUNT;f++) |
179 | - { | ||
180 | -// toggle[f].callback = no_callback; | ||
181 | toggle[f].upcall = toggle_nop; | 152 | toggle[f].upcall = toggle_nop; |
182 | - } | ||
183 | 153 | ||
184 | toggle[LIB3270_TOGGLE_RECTANGLE_SELECT].upcall = toggle_rectselect; | 154 | toggle[LIB3270_TOGGLE_RECTANGLE_SELECT].upcall = toggle_rectselect; |
185 | toggle[LIB3270_TOGGLE_MONOCASE].upcall = toggle_monocase; | 155 | toggle[LIB3270_TOGGLE_MONOCASE].upcall = toggle_monocase; |
@@ -199,11 +169,9 @@ void initialize_toggles(H3270 *session, struct toggle *toggle) | @@ -199,11 +169,9 @@ void initialize_toggles(H3270 *session, struct toggle *toggle) | ||
199 | LIB3270_TOGGLE_CURSOR_BLINK, | 169 | LIB3270_TOGGLE_CURSOR_BLINK, |
200 | LIB3270_TOGGLE_CURSOR_POS, | 170 | LIB3270_TOGGLE_CURSOR_POS, |
201 | LIB3270_TOGGLE_BEEP, | 171 | LIB3270_TOGGLE_BEEP, |
202 | - | ||
203 | - (LIB3270_TOGGLE) -1 | ||
204 | }; | 172 | }; |
205 | 173 | ||
206 | - for(f=0;active_by_default[f] != (LIB3270_TOGGLE) -1; f++) | 174 | + for(f=0;f< (sizeof(active_by_default)/sizeof(active_by_default[0])); f++) |
207 | { | 175 | { |
208 | toggle[active_by_default[f]].value = True; | 176 | toggle[active_by_default[f]].value = True; |
209 | } | 177 | } |
@@ -223,6 +191,26 @@ void initialize_toggles(H3270 *session, struct toggle *toggle) | @@ -223,6 +191,26 @@ void initialize_toggles(H3270 *session, struct toggle *toggle) | ||
223 | void shutdown_toggles(H3270 *session, struct toggle *toggle) | 191 | void shutdown_toggles(H3270 *session, struct toggle *toggle) |
224 | { | 192 | { |
225 | #if defined(X3270_TRACE) | 193 | #if defined(X3270_TRACE) |
194 | + static const LIB3270_TOGGLE disable_on_shutdown[] = {DS_TRACE, EVENT_TRACE, SCREEN_TRACE}; | ||
195 | + | ||
196 | + int f; | ||
197 | + | ||
198 | + for(f=0;f< (sizeof(disable_on_shutdown)/sizeof(disable_on_shutdown[0])); f++) | ||
199 | + { | ||
200 | + LIB3270_TOGGLE ix = disable_on_shutdown[f]; | ||
201 | + struct toggle * t = &toggle[ix]; | ||
202 | + | ||
203 | + if(t->value) | ||
204 | + { | ||
205 | + t->value = False; | ||
206 | + t->upcall(session,&toggle[f],TT_FINAL); | ||
207 | + | ||
208 | + if(session->update_toggle) | ||
209 | + session->update_toggle(session,ix,t->value,TT_FINAL,toggle_names[ix]); | ||
210 | + } | ||
211 | + } | ||
212 | + | ||
213 | +/* | ||
226 | // Clean up the data stream trace monitor window. | 214 | // Clean up the data stream trace monitor window. |
227 | if(toggle[DS_TRACE].value) | 215 | if(toggle[DS_TRACE].value) |
228 | { | 216 | { |
@@ -242,6 +230,7 @@ void shutdown_toggles(H3270 *session, struct toggle *toggle) | @@ -242,6 +230,7 @@ void shutdown_toggles(H3270 *session, struct toggle *toggle) | ||
242 | toggle[SCREEN_TRACE].value = False; | 230 | toggle[SCREEN_TRACE].value = False; |
243 | toggle_screenTrace(session, &toggle[SCREEN_TRACE], TT_FINAL); | 231 | toggle_screenTrace(session, &toggle[SCREEN_TRACE], TT_FINAL); |
244 | } | 232 | } |
233 | +*/ | ||
245 | #endif | 234 | #endif |
246 | } | 235 | } |
247 | 236 |