summaryrefslogtreecommitdiff
path: root/src/hal/classicladder/spy_vars_gtk.c
blob: 1b7fe304a52da7b1b4755e199ce238453f3a9219 (plain)
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/* Classic Ladder Project */
/* Copyright (C) 2001-2007 Marc Le Douarain */
/* http://membres.lycos.fr/mavati/classicladder/ */
/* http://www.sourceforge.net/projects/classicladder */
/* February 2001 */
/* -------------------------------------------------------------------------------------------- */
/* Spy variables windows (booleans with checkboxes, and any with entry widgets) - GTK interface */
/* -------------------------------------------------------------------------------------------- */
/* This library is free software; you can redistribute it and/or */
/* modify it under the terms of the GNU Lesser General Public */
/* License as published by the Free Software Foundation; either */
/* version 2.1 of the License, or (at your option) any later version. */

/* This library is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU */
/* Lesser General Public License for more details. */

/* You should have received a copy of the GNU Lesser General Public */
/* License along with this library; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */

// modified for EMC
// Chris Morley Feb 08

#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

#include "classicladder.h"
#include "global.h"
#include "vars_access.h"
#include "drawing.h"
#include "edit.h"
#include "classicladder_gtk.h"
#include "vars_names.h"
#include "symbols.h"

#include "spy_vars_gtk.h"

#define NBR_BOOLS_VAR_SPY 15
#define NBR_TYPE_BOOLS_SPY 3
#define NBR_FREE_VAR_SPY 15

static int toggle=0;
GtkWidget *SpyBoolVarsWindow;
GtkWidget *SpyFreeVarsWindow;

GtkWidget *offsetboolvar[ NBR_TYPE_BOOLS_SPY ];
int ValOffsetBoolVar[ NBR_TYPE_BOOLS_SPY ] = { 0, 0, 0 };
GtkWidget *chkvar[ NBR_TYPE_BOOLS_SPY ][ NBR_BOOLS_VAR_SPY ];

GtkWidget *EntryVarSpy[NBR_FREE_VAR_SPY*3], *LabelFreeVars[ NBR_FREE_VAR_SPY];

GtkTooltips * TooltipsEntryVarSpy[ NBR_FREE_VAR_SPY ];
/* defaults vars to spy list */
int VarSpy[NBR_FREE_VAR_SPY][2] = { {VAR_MEM_WORD,0}, {VAR_MEM_WORD,1}, {VAR_MEM_WORD,2}, {VAR_MEM_WORD,3}, {VAR_MEM_WORD,4}, {VAR_MEM_WORD,5}, {VAR_MEM_WORD,6}, {VAR_MEM_WORD,7}, {VAR_MEM_WORD,8}, {VAR_MEM_WORD,9}, {VAR_MEM_WORD,10}, {VAR_MEM_WORD,11}, {VAR_MEM_WORD,12}, {VAR_MEM_WORD,13}, {VAR_MEM_WORD,14} }; 
GtkWidget *DisplayFormatVarSpy[NBR_FREE_VAR_SPY];

static gint chkvar_press_event( GtkWidget      *widget, void * numcheck )
{
	long NumCheckWidget = (long)numcheck;
	int Type = VAR_MEM_BIT;
	int Offset = ValOffsetBoolVar[ 0 ];
	int NumCheck = NumCheckWidget;
	if( NumCheckWidget>=NBR_BOOLS_VAR_SPY && NumCheckWidget<2*NBR_BOOLS_VAR_SPY )
	{
		Type = VAR_PHYS_INPUT;
		Offset = ValOffsetBoolVar[ 1 ];
		NumCheck -= NBR_BOOLS_VAR_SPY;
	} 
	if( NumCheckWidget>=2*NBR_BOOLS_VAR_SPY && NumCheckWidget<3*NBR_BOOLS_VAR_SPY )
	{
		Type = VAR_PHYS_OUTPUT;
		Offset = ValOffsetBoolVar[ 2 ];
		NumCheck -= 2*NBR_BOOLS_VAR_SPY;
	} 
	if (gtk_toggle_button_get_active((GtkToggleButton *)widget))
		WriteVar(Type,Offset+NumCheck,1);
	else
		WriteVar(Type,Offset+NumCheck,0);
	return TRUE;
}

void RefreshOneBoolVar( int Type, int Num, int Val )
{
	int Col = 0;
	switch( Type )
	{
		case VAR_PHYS_INPUT: Col = 1; break;
		case VAR_PHYS_OUTPUT: Col = 2; break;
	}
	if ( Num>=ValOffsetBoolVar[ Col ] && Num<ValOffsetBoolVar[ Col ]+NBR_BOOLS_VAR_SPY )
		gtk_toggle_button_set_active((GtkToggleButton *)chkvar[Col][Num-ValOffsetBoolVar[ Col ]],(Val!=0)?TRUE:FALSE);
}

void RefreshAllBoolsVars( )
{
	int NumVar;
	for (NumVar=0; NumVar<NBR_BOOLS_VAR_SPY; NumVar++)
	{
		gtk_toggle_button_set_active( (GtkToggleButton *)chkvar[0][NumVar], ReadVar(VAR_MEM_BIT,NumVar+ValOffsetBoolVar[ 0 ])?TRUE:FALSE );
		gtk_toggle_button_set_active( (GtkToggleButton *)chkvar[1][NumVar], ReadVar(VAR_PHYS_INPUT,NumVar+ValOffsetBoolVar[ 1 ])?TRUE:FALSE );
		gtk_toggle_button_set_active( (GtkToggleButton *)chkvar[2][NumVar], ReadVar(VAR_PHYS_OUTPUT,NumVar+ValOffsetBoolVar[ 2 ])?TRUE:FALSE );
	}
}

void UpdateAllLabelsBoolsVars( )
{
	int ColumnVar, OffVar;
	for(ColumnVar=0; ColumnVar<NBR_TYPE_BOOLS_SPY; ColumnVar++)
	{
		for(OffVar=0; OffVar<NBR_BOOLS_VAR_SPY; OffVar++)
		{
			char BufNumVar[256];
			switch( ColumnVar )
			{
                        case 0:
                            snprintf(BufNumVar, 256, "<span foreground=\"black\" weight=\"bold\">%cB%d</span>",'%', 
                                    OffVar+ValOffsetBoolVar[ ColumnVar ]); 
                            break;
                        case 1:
                            snprintf(BufNumVar, 256, "<span foreground=\"red\" weight=\"bold\">%cI%d</span>",'%',  
                                    OffVar+ValOffsetBoolVar[ ColumnVar ]); 
                            break;
                        case 2:
                            snprintf(BufNumVar, 256, "<span foreground=\"blue\" weight=\"bold\">%cQ%d</span>",'%', 
                                    OffVar+ValOffsetBoolVar[ ColumnVar ]); 
                            break;
			}
			gtk_label_set_markup (GTK_LABEL (GTK_BIN( chkvar[ ColumnVar ][ OffVar ] )->child),BufNumVar);
		}
	}
}

static gint OffsetBoolVar_activate_event(GtkWidget *widget, void * NumVarSpy)
{
	int Maxi = 0;
	long NumType = (long)NumVarSpy;
	int ValOffset = atoi( gtk_entry_get_text((GtkEntry *)widget) );
	switch( NumType )
	{
		case 0: Maxi = NBR_BITS; break;
		case 1: Maxi = NBR_PHYS_INPUTS; break;
		case 2: Maxi = NBR_PHYS_OUTPUTS; break;
	}
	if ( ValOffset+NBR_BOOLS_VAR_SPY>Maxi || ValOffset<0 )
		ValOffset = 0;
	ValOffsetBoolVar[ NumType ] = ValOffset;
	UpdateAllLabelsBoolsVars( );
	RefreshAllBoolsVars( );
	return TRUE;
}

// return true so window is not destroyed
// set toggle to 3 so hitting vars button again wiil hide everything
// unless we were only showing BoolVars window then start from the beginning
gint BoolVarsWindowDeleteEvent( GtkWidget * widget, GdkEvent * event, gpointer data )
{
	gtk_widget_hide( SpyBoolVarsWindow );
	if (toggle==1) {toggle=0;
	}else{toggle=3;}
	return TRUE;
}



void BoolVarsWindowInitGtk()
{
	GtkWidget *vboxboolvars[ NBR_TYPE_BOOLS_SPY ],*vboxmain,*hboxvars;
	long NumCheckWidget,ColumnVar;
	GtkTooltips * WidgetTooltips[ NBR_TYPE_BOOLS_SPY ];
	
	SpyBoolVarsWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title ((GtkWindow *)SpyBoolVarsWindow, "Bit Status Window");
	vboxmain = gtk_vbox_new (FALSE, 0);
	gtk_container_add (GTK_CONTAINER (SpyBoolVarsWindow), vboxmain);
	gtk_widget_show (vboxmain);
	hboxvars = gtk_hbox_new (FALSE, 0);
	gtk_container_add (GTK_CONTAINER (vboxmain), hboxvars);
	gtk_widget_show (hboxvars);

	for( ColumnVar=0; ColumnVar<NBR_TYPE_BOOLS_SPY; ColumnVar++ )
	{
		vboxboolvars[ ColumnVar ] = gtk_vbox_new (FALSE, 0);
		gtk_container_add (GTK_CONTAINER (hboxvars), vboxboolvars[ ColumnVar ]);
		gtk_widget_show (vboxboolvars[ ColumnVar ]);
	}

	NumCheckWidget = 0;
	for(ColumnVar=0; ColumnVar<NBR_TYPE_BOOLS_SPY; ColumnVar++)
	{
		int OffVar;
		offsetboolvar[ ColumnVar ]  = gtk_entry_new();
		WidgetTooltips[ ColumnVar ] = gtk_tooltips_new();
		gtk_tooltips_set_tip ( WidgetTooltips[ ColumnVar ], offsetboolvar[ ColumnVar ], "Offset for vars displayed below (return to apply)", NULL );
		gtk_widget_set_usize((GtkWidget *)offsetboolvar[ ColumnVar ],40,0);
		gtk_box_pack_start (GTK_BOX(vboxboolvars[ ColumnVar ]),  offsetboolvar[ ColumnVar ] , FALSE, FALSE, 0);
		gtk_widget_show( offsetboolvar[ ColumnVar ] );
		gtk_entry_set_text((GtkEntry *)offsetboolvar[ ColumnVar ],"0");
		gtk_signal_connect(GTK_OBJECT (offsetboolvar[ ColumnVar ]), "activate",
					(GtkSignalFunc) OffsetBoolVar_activate_event, (void *)ColumnVar);
		
		for(OffVar=0; OffVar<NBR_BOOLS_VAR_SPY; OffVar++)
		{
			chkvar[ ColumnVar ][ OffVar ] = gtk_check_button_new_with_label("xxxx");
			gtk_box_pack_start (GTK_BOX(vboxboolvars[ ColumnVar ]), chkvar[ ColumnVar ][ OffVar ], FALSE, FALSE, 0);
			gtk_widget_show(chkvar[ ColumnVar ][ OffVar ]);
			gtk_signal_connect(GTK_OBJECT (chkvar[ ColumnVar ][ OffVar ]), "toggled",
					(GtkSignalFunc) chkvar_press_event, (void*)NumCheckWidget);
			NumCheckWidget++;
		}
	}
	UpdateAllLabelsBoolsVars( );
	
	gtk_signal_connect( GTK_OBJECT(SpyBoolVarsWindow), "delete_event",
		(GtkSignalFunc)BoolVarsWindowDeleteEvent, 0 );

//	gtk_window_set_policy( GTK_WINDOW(SpyBoolVarsWindow), FALSE/*allow_shrink*/, FALSE/*allow_grow*/, TRUE/*auto_shrink*/ );
}



char * ConvToBin( unsigned int Val )
{
	static char TabBin[ 33 ];
	int Pos;
	unsigned int Mask = 0x80000000;
	char First1 = FALSE;
	strcpy( TabBin, "" );
	for ( Pos = 0; Pos<32; Pos++ )
	{
		if ( Val & Mask )
			First1 = TRUE;
		if ( First1 )
		{
			if ( Val & Mask )
				strcat( TabBin, "1" );
			else
				strcat( TabBin, "0" );
		}
		Mask = Mask>>1;
	}
	if ( Val==0 )
		strcpy( TabBin,"0" );
	return TabBin;
}
// This function updates the signed Integer window
// It checks the display format and displays the number in hex,binary or decimal
// It checks to see what type of word variable it represents (Hal s32 pin in or out or an internal memory variable) and displays that label with colour
// If Displays variable names or symbol names depending on the check box in the section display window
void DisplayFreeVarSpy()
{
	static int LastTime;
	int NumVarSpy,i=NBR_FREE_VAR_SPY;
	int Value;
	char BufferValue[50];
	char DisplayFormat[10];
	char  * VarName;
	if ( NBR_WORDS < NBR_FREE_VAR_SPY) { i=NBR_WORDS ;}
	for (NumVarSpy=0; NumVarSpy<i; NumVarSpy++)
	{
		Value = ReadVar(VarSpy[NumVarSpy][0],VarSpy[NumVarSpy][1]);
		strcpy( DisplayFormat , (char *)gtk_entry_get_text((GtkEntry *)((GtkCombo *)DisplayFormatVarSpy[NumVarSpy])->entry) );
		strcpy( BufferValue, "" );
		if (strcmp( DisplayFormat,"Dec" )==0 )
			sprintf(BufferValue,"%d",Value);
		if (strcmp( DisplayFormat,"Hex" )==0 )
			sprintf(BufferValue,"%X",Value);
		if (strcmp( DisplayFormat,"Bin" )==0 )
			strcpy( BufferValue, ConvToBin( Value ) );
		gtk_entry_set_text((GtkEntry *)EntryVarSpy[NumVarSpy+(2*NBR_FREE_VAR_SPY)],BufferValue);
                VarName= "<span foreground=\"gray\" weight=\"bold\" >Other       </span>";
               
                switch (VarSpy[NumVarSpy][0])
                     
                      {
                       case VAR_TIMER_VALUE :
                       case VAR_TIMER_PRESET :
                       case VAR_TIMER_RUNNING :
                       case VAR_TIMER_DONE :
                            VarName= "<span foreground=\"brown\" weight=\"bold\" >Timer       </span>";
                            break;
                       case VAR_TIMER_IEC_VALUE :
                       case VAR_TIMER_IEC_PRESET :
                       case VAR_TIMER_IEC_DONE :
                            VarName= "<span foreground=\"brown\" weight=\"bold\" >IEC Timer   </span>";
                            break;
                       case VAR_COUNTER_VALUE :
                       case VAR_COUNTER_PRESET :
                       case VAR_COUNTER_FULL :
                       case VAR_COUNTER_EMPTY :
                       case VAR_COUNTER_DONE :
                            VarName= "<span foreground=\"brown\" weight=\"bold\" >Counter     </span>";
                            break;
                       case VAR_MONOSTABLE_RUNNING :
                       case VAR_MONOSTABLE_PRESET :
                       case VAR_MONOSTABLE_VALUE :
                            VarName= "<span foreground=\"brown\" weight=\"bold\" >Monostable  </span>";
                            break;
                       case VAR_MEM_WORD :
                            VarName= "<span foreground=\"black\" weight=\"bold\" >Memory      </span>";
                            break;
                       case VAR_PHYS_INPUT :
                            VarName= "<span foreground=\"red\" weight=\"bold\" >Bit In Pin  </span>";
                            break;
                       case VAR_PHYS_OUTPUT :
                            VarName= "<span foreground=\"blue\" weight=\"bold\" >Bit Out Pin </span>";
                            break;
                       case VAR_PHYS_FLOAT_INPUT :
                            VarName= "<span foreground=\"red\" weight=\"bold\" >Floatin Pin </span>";
                            break;
                       case VAR_PHYS_FLOAT_OUTPUT :
                            VarName= "<span foreground=\"blue\" weight=\"bold\" >Floatout Pin</span>";
                            break;
                       case VAR_PHYS_WORD_INPUT :
                            VarName= "<span foreground=\"red\" weight=\"bold\" >S32in Pin   </span>";
                            break;
                       case VAR_PHYS_WORD_OUTPUT :
                            VarName= "<span foreground=\"blue\" weight=\"bold\" >S32out Pin  </span>";
                            break;
                       case VAR_MEM_BIT :
                            VarName= "<span foreground=\"black\" weight=\"bold\" >Bit Memory  </span>";
                            break;
                       case VAR_ERROR_BIT :
                            VarName= "<span foreground=\"gold\" weight=\"bold\" >Error Bit   </span>";
                            break;
                       case VAR_STEP_ACTIVITY :
                            VarName= "<span foreground=\"brown\" weight=\"bold\" >Step Active  </span>";
                            break;
                       case VAR_STEP_TIME :
                            VarName= "<span foreground=\"brown\" weight=\"bold\" >Step Run Time</span>";
                            break;
                      }
		gtk_label_set_markup (GTK_LABEL (LabelFreeVars[NumVarSpy]),VarName);

		if (InfosGene->DisplaySymbols!=LastTime) 
		{		 	
		gtk_entry_set_text((GtkEntry *)EntryVarSpy[ NumVarSpy+(1 *NBR_FREE_VAR_SPY)],CreateVarName(VarSpy[NumVarSpy][0],VarSpy[NumVarSpy][1]));
		}
	}
	// we do this check after the FOR loop
    	// so it does not toggle each time thru loop
        // Toggle LastTime to match InfoGene  
	if (InfosGene->DisplaySymbols!=LastTime) 
		{ LastTime=((LastTime-1)*-1); } 		
}

static gint EntryVarSpy_activate_event(GtkWidget *widget, int NumSpy)
{
	int NewVarType,NewVarOffset;
	int * NumVarSpy = &VarSpy[NumSpy][0];
	char BufferVar[30];
	strcpy(BufferVar, gtk_entry_get_text((GtkEntry *)widget) );
	if (TextParserForAVar(BufferVar , &NewVarType, &NewVarOffset, NULL, FALSE/*PartialNames*/))
	{
		char * OtherVarName = NULL;
		*NumVarSpy++ = NewVarType;
		*NumVarSpy = NewVarOffset;

		if ( BufferVar[ 0 ]=='%' ) 
                       {       OtherVarName = ConvVarNameToSymbol( BufferVar );
                       }else{  
                               OtherVarName = ConvSymbolToVarName( BufferVar );
                            }
		if ( OtherVarName ) {    gtk_tooltips_set_tip ( TooltipsEntryVarSpy[ NumSpy ], widget, OtherVarName, NULL );    }
	}else{
		int OldType,OldOffset;
		/* Error Message */
		if (ErrorMessageVarParser)
                       {       ShowMessageBox("Error",ErrorMessageVarParser,"Ok");
		       }else{
			       ShowMessageBox( "Error", "Unknown variable...", "Ok" );
                            }
		OldType = *NumVarSpy++;
		OldOffset = *NumVarSpy;
		/* put back old correct var */
		gtk_entry_set_text((GtkEntry *)widget,CreateVarName(OldType,OldOffset));
	      }
	return TRUE;
}

//return true so window is not destroyed
//set toggle to 3 so hitting vars button again wiil hide everything
//unless we were only showing FreeVars window then start from the beginning
gint FreeVarsWindowDeleteEvent( GtkWidget * widget, GdkEvent * event, gpointer data )
{
	gtk_widget_hide( SpyFreeVarsWindow );
	if (toggle==2) {  toggle=0;  }else{  toggle=3;  }
	return TRUE;
}

// modified this to have 3 columns so we can display variable type
void FreeVarsWindowInitGtk( )
{
	GtkWidget * hboxfreevars[ NBR_FREE_VAR_SPY ], *vboxMain;
	char * VarName= NULL;
	long ColumnVar;
	int NumVarSpy,NumEntry,i=NBR_FREE_VAR_SPY;
	GList *DisplayFormatItems = NULL;

	SpyFreeVarsWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title ((GtkWindow *)SpyFreeVarsWindow, "Watch Window");
	vboxMain = gtk_vbox_new (FALSE, 0);
	gtk_container_add (GTK_CONTAINER (SpyFreeVarsWindow), vboxMain);
	gtk_widget_show (vboxMain);
	
	DisplayFormatItems = g_list_append(DisplayFormatItems,"Dec");
	DisplayFormatItems = g_list_append(DisplayFormatItems,"Hex");
	DisplayFormatItems = g_list_append(DisplayFormatItems,"Bin");
	if ( NBR_WORDS < NBR_FREE_VAR_SPY) { i=NBR_WORDS ;}
	for(NumVarSpy=0; NumVarSpy<i; NumVarSpy++)
	{
		hboxfreevars[ NumVarSpy ] = gtk_hbox_new (FALSE, 0);
		gtk_container_add (GTK_CONTAINER (vboxMain), hboxfreevars[ NumVarSpy ]);
		gtk_widget_show (hboxfreevars[ NumVarSpy ]);

		for(ColumnVar=0; ColumnVar<3; ColumnVar++)
		{
			NumEntry = NumVarSpy+ColumnVar*NBR_FREE_VAR_SPY;			
			
			if ( ColumnVar==0)
			{
				LabelFreeVars[NumEntry] = gtk_label_new(NULL);				
				gtk_widget_set_usize((GtkWidget *)LabelFreeVars[NumEntry],100,0);
				gtk_box_pack_start (GTK_BOX (hboxfreevars[ NumVarSpy ]), LabelFreeVars[NumEntry], FALSE, FALSE, 0);
				gtk_widget_show (LabelFreeVars[NumEntry]);
			}
			if ( ColumnVar==1)
			{
				EntryVarSpy[ NumEntry ] = gtk_entry_new();
			        gtk_widget_show(EntryVarSpy[NumEntry]);
				gtk_box_pack_start (GTK_BOX( hboxfreevars[ NumVarSpy ] ), EntryVarSpy[ NumEntry ], TRUE, TRUE, 0);
				gtk_widget_set_usize((GtkWidget *)EntryVarSpy[ NumEntry ],(ColumnVar==1)?80:110,0);	
				VarName = CreateVarName(VarSpy[NumVarSpy][0],VarSpy[NumVarSpy][1]);
				TooltipsEntryVarSpy[ NumVarSpy ] = gtk_tooltips_new();
				gtk_entry_set_text((GtkEntry *)EntryVarSpy[ NumEntry ],VarName);
				gtk_signal_connect(GTK_OBJECT (EntryVarSpy[ NumEntry ]), "activate",
                                (GtkSignalFunc) EntryVarSpy_activate_event, (void *)(intptr_t)NumVarSpy);
			}
			if ( ColumnVar==2)
			{
				EntryVarSpy[ NumEntry ] = gtk_entry_new();
			        gtk_widget_show(EntryVarSpy[NumEntry]);
				gtk_box_pack_start (GTK_BOX( hboxfreevars[ NumVarSpy ] ), EntryVarSpy[ NumEntry ], TRUE, TRUE, 0);
				gtk_widget_set_usize((GtkWidget *)EntryVarSpy[ NumEntry ],(ColumnVar==2)?80:110,0);

			}

		}

		DisplayFormatVarSpy[NumVarSpy] = gtk_combo_new();
		gtk_combo_set_value_in_list(GTK_COMBO(DisplayFormatVarSpy[NumVarSpy]), TRUE /*val*/, FALSE /*ok_if_empty*/);
		gtk_combo_set_popdown_strings(GTK_COMBO(DisplayFormatVarSpy[NumVarSpy]), DisplayFormatItems);
		gtk_widget_set_usize((GtkWidget *)DisplayFormatVarSpy[NumVarSpy],65,0);
		gtk_box_pack_start (GTK_BOX(hboxfreevars[ NumVarSpy ]), DisplayFormatVarSpy[NumVarSpy], FALSE, FALSE, 0);
		gtk_widget_show(DisplayFormatVarSpy[NumVarSpy]);
	}
	gtk_signal_connect( GTK_OBJECT(SpyFreeVarsWindow), "delete_event",
		(GtkSignalFunc)FreeVarsWindowDeleteEvent, 0 );
}

void VarsWindowInitGtk()
{
	FreeVarsWindowInitGtk( );
	BoolVarsWindowInitGtk( );
}

// This is modified to toggle the vars windows
// be click the spyvars button multiple times
// one, the other, both, then none of the windows will be shown
void OpenSpyVarsWindow( )
{
	
	switch (toggle)
	{
	case 0 :	gtk_widget_show( SpyBoolVarsWindow ); gtk_widget_hide( SpyFreeVarsWindow );
			MessageInStatusBar("openned BOOL (bit) variable window. press again for WORD window");	
		break;
	case 1 :        gtk_widget_hide( SpyBoolVarsWindow ); gtk_widget_show( SpyFreeVarsWindow );
			MessageInStatusBar("openned WORD (s32) variable window. press again for both windows");
		break;
	case 2 :	gtk_widget_show( SpyBoolVarsWindow ); gtk_widget_show( SpyFreeVarsWindow );
			MessageInStatusBar("openned BOTH variable windows. press again to close them.");
		break;
	case 3 :	gtk_widget_hide( SpyBoolVarsWindow ); gtk_widget_hide( SpyFreeVarsWindow );
			MessageInStatusBar("");
		break;
	default:;
	}
	toggle++;
	if (toggle==4) {toggle=0;}

}