/* 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 #include #include #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