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
|
/* Classic Ladder Project */
/* Copyright (C) 2001-2006 Marc Le Douarain */
/* http://www.multimania.com/mavati/classicladder */
/* http://www.sourceforge.net/projects/classicladder */
/* May 2001 */
/* --------------------------------- */
/* Editor properties - 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 */
#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>
#include "classicladder.h"
#include "global.h"
#include "editproperties_gtk.h"
#include "edit.h"
GtkWidget *PropertiesWindow;
GtkWidget *PropLabelParam[NBR_PARAMS_PER_OBJ],*PropEntryParam[NBR_PARAMS_PER_OBJ];
GtkWidget *PropEntryBaseParam[NBR_PARAMS_PER_OBJ];
GtkWidget *PropEntryTimerModeParam[NBR_PARAMS_PER_OBJ];
GtkWidget *ButtonApplyProperties;
int SavePosX = -1;
int SavePosY = -1;
void SetProperty(int NumParam,char * LblParam,char * ValParam)
{
gtk_label_set_text((GtkLabel *)PropLabelParam[NumParam],LblParam);
if (strcmp(LblParam,"Base")==0)
{
gtk_widget_hide(PropEntryParam[NumParam]);
gtk_widget_show(PropEntryBaseParam[NumParam]);
gtk_widget_hide(PropEntryTimerModeParam[NumParam]);
gtk_entry_set_text((GtkEntry*)((GtkCombo *)PropEntryBaseParam[NumParam])->entry,ValParam);
if (NumParam==0)
gtk_widget_grab_focus( PropEntryBaseParam[0] );
}
else
{
if (strcmp(LblParam,"TimerMode")==0)
{
gtk_widget_hide(PropEntryParam[NumParam]);
gtk_widget_hide(PropEntryBaseParam[NumParam]);
gtk_widget_show(PropEntryTimerModeParam[NumParam]);
gtk_entry_set_text((GtkEntry*)((GtkCombo *)PropEntryTimerModeParam[NumParam])->entry,ValParam);
if (NumParam==0)
gtk_widget_grab_focus( PropEntryTimerModeParam[0] );
}
else
{
// others standard parameters
gtk_widget_show(PropEntryParam[NumParam]);
gtk_widget_hide(PropEntryBaseParam[NumParam]);
gtk_widget_hide(PropEntryTimerModeParam[NumParam]);
gtk_entry_set_text(GTK_ENTRY(PropEntryParam[NumParam]),ValParam);
if (NumParam==0)
gtk_widget_grab_focus( PropEntryParam[0] );
}
}
/* if no first param, means no params at all */
/* so no sense to need to apply ! */
if (NumParam==0)
{
if (strcmp(LblParam,"---")==0)
{
gtk_widget_hide(ButtonApplyProperties);
}
else
{
gtk_widget_show(ButtonApplyProperties);
#ifndef GTK2
// no gtk_window_present() function available with GTK1.2
//not beautiful but it works...
gtk_widget_hide(PropertiesWindow);
gtk_widget_show(PropertiesWindow);
#else
gtk_window_present( GTK_WINDOW(PropertiesWindow) );
#endif
}
}
}
char * GetProperty(int NumParam)
{
static char ValTxtParameter[61];
gchar * TxtParameter;
/* Convert to a number if it is a base */
gtk_label_get(GTK_LABEL(PropLabelParam[NumParam]),&TxtParameter);
if (strcmp(TxtParameter,"Base")==0)
{
strcpy( ValTxtParameter , (char *)gtk_entry_get_text((GtkEntry *)((GtkCombo *)PropEntryBaseParam[NumParam])->entry) );
}
else
{
if (strcmp(TxtParameter,"TimerMode")==0)
{
strcpy( ValTxtParameter , (char *)gtk_entry_get_text((GtkEntry *)((GtkCombo *)PropEntryTimerModeParam[NumParam])->entry) );
}
else
{
// others standard parameters
strncpy( ValTxtParameter , (char *)gtk_entry_get_text((GtkEntry *)PropEntryParam[NumParam]), 60 );
ValTxtParameter[ 60 ] = '\0';
}
}
return ValTxtParameter;
}
gint PropertiesWindowDeleteEvent( GtkWidget * widget, GdkEvent * event, gpointer data )
{
// we do not want that the window be destroyed.
return TRUE;
}
void ShowPropertiesWindow( int Visible )
{
if ( Visible )
{
gtk_widget_show(PropertiesWindow);
if ( SavePosX!=-1 && SavePosY!=-1 )
gtk_window_move( GTK_WINDOW(PropertiesWindow), SavePosX, SavePosY );
}
else
{
gtk_window_get_position( GTK_WINDOW(PropertiesWindow), &SavePosX, &SavePosY );
gtk_widget_hide(PropertiesWindow);
}
}
void PropertiesInitGtk()
{
GtkWidget *vbox;
GtkWidget *hbox[NBR_PARAMS_PER_OBJ + 1];
int NumParam;
GList *BaseItems = NULL;
GList *TimersModesItems = NULL;
int ScanBase = 0;
int ScanTimerMode = 0;
do
{
BaseItems = g_list_append(BaseItems,CorresDatasForBase[ScanBase++].ParamSelect);
}
while(ScanBase<NBR_TIMEBASES);
do
{
TimersModesItems = g_list_append(TimersModesItems,TimersModesStrings[ScanTimerMode++]);
}
while(ScanTimerMode<NBR_TIMERSMODES);
PropertiesWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title ((GtkWindow *)PropertiesWindow, "Properties");
vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (PropertiesWindow), vbox);
gtk_widget_show (vbox);
for (NumParam = 0 ; NumParam<NBR_PARAMS_PER_OBJ ; NumParam++)
{
hbox[NumParam] = gtk_hbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (vbox), hbox[NumParam]);
gtk_widget_show (hbox[NumParam]);
PropLabelParam[NumParam] = gtk_label_new("Parameter");
gtk_widget_set_usize((GtkWidget *)PropLabelParam[NumParam],85,0);
gtk_box_pack_start (GTK_BOX (hbox[NumParam]), PropLabelParam[NumParam], FALSE, FALSE, 0);
gtk_widget_show (PropLabelParam[NumParam]);
/* For numbers */
PropEntryParam[NumParam] = gtk_entry_new();
// gtk_widget_set_usize((GtkWidget *)PropEntryParam[NumParam],85,0);
gtk_box_pack_start (GTK_BOX (hbox[NumParam]), PropEntryParam[NumParam], TRUE, TRUE, 0);
gtk_widget_show (PropEntryParam[NumParam]);
gtk_signal_connect(GTK_OBJECT (PropEntryParam[NumParam]), "activate",
(GtkSignalFunc) SaveElementProperties, NULL);
/* For time base */
PropEntryBaseParam[NumParam] = gtk_combo_new();
gtk_combo_set_value_in_list(GTK_COMBO(PropEntryBaseParam[NumParam]), TRUE /*val*/, FALSE /*ok_if_empty*/);
gtk_combo_set_popdown_strings(GTK_COMBO(PropEntryBaseParam[NumParam]),BaseItems);
// gtk_widget_set_usize((GtkWidget *)PropEntryBaseParam[NumParam],85,0);
gtk_box_pack_start (GTK_BOX (hbox[NumParam]), PropEntryBaseParam[NumParam], FALSE, FALSE, 0);
/* For timer mode */
PropEntryTimerModeParam[NumParam] = gtk_combo_new();
gtk_combo_set_value_in_list(GTK_COMBO(PropEntryTimerModeParam[NumParam]), TRUE /*val*/, FALSE /*ok_if_empty*/);
gtk_combo_set_popdown_strings(GTK_COMBO(PropEntryTimerModeParam[NumParam]),TimersModesItems);
// gtk_widget_set_usize((GtkWidget *)PropEntryTimerModeParam[NumParam],85,0);
gtk_box_pack_start (GTK_BOX (hbox[NumParam]), PropEntryTimerModeParam[NumParam], FALSE, FALSE, 0);
}
/* for apply button... */
hbox[NumParam] = gtk_hbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (vbox), hbox[NumParam]);
gtk_widget_show (hbox[NumParam]);
ButtonApplyProperties = gtk_button_new_with_label("Apply");
gtk_box_pack_start (GTK_BOX (hbox[NumParam]), ButtonApplyProperties, TRUE, FALSE, 0);
gtk_signal_connect(GTK_OBJECT (ButtonApplyProperties), "clicked",
(GtkSignalFunc) SaveElementProperties, 0);
// gtk_widget_show (PropertiesWindow);
gtk_signal_connect( GTK_OBJECT(PropertiesWindow), "delete_event",
(GtkSignalFunc)PropertiesWindowDeleteEvent, 0 );
}
|