edit_gtk.c

来自「CNC 的开放码,EMC2 V2.2.8版」· C语言 代码 · 共 412 行 · 第 1/2 页

C
412
字号
/* 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 - GTK interface part *//* --------------------------- *//* 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 "classicladder.h"#include "global.h"#include "drawing.h"#include "edit.h"#include "classicladder_gtk.h"#include "edit_gtk.h"#include "editproperties_gtk.h"static GtkWidget *EditorButtonOk,*EditorButtonCancel;static GtkWidget *EditorButtonAdd,*EditorButtonIns,*EditorButtonDel;static GtkWidget *EditorButtonModify;#define NBR_ELE_IN_TOOLBAR 50#define NBR_ELE_TOOLBAR_Y_MAX 15 // used for each GtkTable#define NBR_ELE_TOOLBAR_X_MAX 4static GtkWidget * ToolbarBtnRadio[ NBR_ELE_IN_TOOLBAR ];static GtkWidget * ToolbarImage[ NBR_ELE_IN_TOOLBAR ];static GdkPixmap * ToolbarPixmap[ NBR_ELE_IN_TOOLBAR ];#define NUM_TOOLBAR_FOR_RUNGS 0#define NUM_TOOLBAR_FOR_SEQ 1static GtkWidget * ToolbarTable[ 2 ];static int NumWidgetEditPointer[ 2 ];GtkTooltips * TheTooltips;#define PIXELS_SIZE_IN_TOOLBAR 32static short int ToolBarElementsLadder[ ][NBR_ELE_TOOLBAR_X_MAX] =            { {EDIT_POINTER , EDIT_ERASER, 0 , 0} ,              {ELE_INPUT , ELE_INPUT_NOT , ELE_RISING_INPUT , ELE_FALLING_INPUT} ,              {ELE_CONNECTION , EDIT_CNX_WITH_TOP, EDIT_LONG_CONNECTION , 0} ,              {ELE_TIMER , ELE_MONOSTABLE , ELE_COUNTER , ELE_COMPAR} ,              {ELE_OUTPUT , ELE_OUTPUT_NOT, ELE_OUTPUT_SET , ELE_OUTPUT_RESET} ,              {ELE_OUTPUT_JUMP, ELE_OUTPUT_CALL , ELE_OUTPUT_OPERATE , 0} ,              {-1,-1}/*end*/ };#ifdef SEQUENTIAL_SUPPORT#include "drawing_sequential.h"#include "edit_sequential.h"static short int ToolBarElementsSequential[ ][NBR_ELE_TOOLBAR_X_MAX] =            { {EDIT_POINTER , EDIT_ERASER , 0 , 0} ,              {ELE_SEQ_STEP , EDIT_SEQ_INIT_STEP , 0 , 0} ,              {ELE_SEQ_TRANSITION , EDIT_SEQ_STEP_AND_TRANS , 0 , 0} ,              {EDIT_SEQ_START_MANY_TRANS , EDIT_SEQ_END_MANY_TRANS , 0 , 0} ,              {EDIT_SEQ_START_MANY_STEPS , EDIT_SEQ_END_MANY_STEPS , 0 , 0} ,              {EDIT_SEQ_LINK , 0 , 0 , 0} ,              {ELE_SEQ_COMMENT , 0 , 0 , 0} ,              {-1,-1}/*end*/ };#endifGtkWidget *EditWindow;void ButtonsForStart(){	gtk_widget_hide (EditorButtonAdd);	gtk_widget_hide (EditorButtonIns);	gtk_widget_hide (EditorButtonDel);	gtk_widget_hide (EditorButtonModify);	gtk_widget_show (EditorButtonOk);	gtk_widget_show (EditorButtonCancel);	ShowPropertiesWindow( TRUE );	// select directly the pointer in toolbar per default...	EditDatas.NumElementSelectedInToolBar = EDIT_POINTER;	// ...in rung toolbar	if ( NumWidgetEditPointer[ NUM_TOOLBAR_FOR_RUNGS ]!=-1 )	{		gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(ToolbarBtnRadio[ NumWidgetEditPointer[ NUM_TOOLBAR_FOR_RUNGS ] ]), TRUE );		gtk_widget_set_sensitive( ToolbarTable[ NUM_TOOLBAR_FOR_RUNGS ], TRUE );	}	// ...in sequential toolbar	if ( NumWidgetEditPointer[ NUM_TOOLBAR_FOR_SEQ ]!=-1 )	{		gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON(ToolbarBtnRadio[ NumWidgetEditPointer[ NUM_TOOLBAR_FOR_SEQ ] ]), TRUE );		gtk_widget_set_sensitive( ToolbarTable[ NUM_TOOLBAR_FOR_SEQ ], TRUE );	}}void ButtonsForEnd( char ForRung ){	if ( ForRung )	{		gtk_widget_show (EditorButtonAdd);		gtk_widget_show (EditorButtonIns);		gtk_widget_show (EditorButtonDel);		gtk_widget_set_sensitive( ToolbarTable[ NUM_TOOLBAR_FOR_RUNGS ], FALSE );	}	else	{		gtk_widget_hide (EditorButtonAdd);		gtk_widget_hide (EditorButtonIns);		gtk_widget_hide (EditorButtonDel);		gtk_widget_set_sensitive( ToolbarTable[ NUM_TOOLBAR_FOR_SEQ ], FALSE );	}	gtk_widget_show (EditorButtonModify);	gtk_widget_hide (EditorButtonOk);	gtk_widget_hide (EditorButtonCancel);	ShowPropertiesWindow( FALSE );}void EditorButtonsAccordingSectionType( ){	int iCurrentLanguage = SectionArray[ InfosGene->CurrentSection ].Language;	ButtonsForEnd( iCurrentLanguage==SECTION_IN_LADDER );#ifdef SEQUENTIAL_SUPPORT	if ( iCurrentLanguage==SECTION_IN_SEQUENTIAL )	{		gtk_widget_hide( ToolbarTable[ NUM_TOOLBAR_FOR_RUNGS ] );		gtk_widget_show( ToolbarTable[ NUM_TOOLBAR_FOR_SEQ ] );	}    else	{		gtk_widget_hide( ToolbarTable[ NUM_TOOLBAR_FOR_SEQ ] );		gtk_widget_show( ToolbarTable[ NUM_TOOLBAR_FOR_RUNGS ] );	}#endif}void ButtonAddRung(){	AddRung();	ButtonsForStart();}void ButtonInsertRung(){	InsertRung();	ButtonsForStart();}void ButtonDeleteCurrentRung(){	ShowConfirmationBox("Delete","Do you really want to delete the current rung ?",DeleteCurrentRung);}void ButtonModifyCurrentRung(){	int iCurrentLanguage = SectionArray[ InfosGene->CurrentSection ].Language;	if ( iCurrentLanguage==SECTION_IN_LADDER )	{		ModifyCurrentRung();		ButtonsForStart();	}#ifdef SEQUENTIAL_SUPPORT	if ( iCurrentLanguage==SECTION_IN_SEQUENTIAL )	{		ModifyCurrentSeqPage();		ButtonsForStart();	}#endif}void ButtonOkCurrentRung(){	int iCurrentLanguage = SectionArray[ InfosGene->CurrentSection ].Language;	if ( iCurrentLanguage==SECTION_IN_LADDER )		ApplyRungEdited();#ifdef SEQUENTIAL_SUPPORT	if ( iCurrentLanguage==SECTION_IN_SEQUENTIAL )		ApplySeqPageEdited();#endif	ButtonsForEnd( iCurrentLanguage==SECTION_IN_LADDER );}void ButtonCancelCurrentRung(){	int iCurrentLanguage = SectionArray[ InfosGene->CurrentSection ].Language;	if ( iCurrentLanguage==SECTION_IN_LADDER )		CancelRungEdited();#ifdef SEQUENTIAL_SUPPORT	if ( iCurrentLanguage==SECTION_IN_SEQUENTIAL )		CancelSeqPageEdited();#endif	ButtonsForEnd( iCurrentLanguage==SECTION_IN_LADDER );}gint EditorWindowDeleteEvent( GtkWidget * widget, GdkEvent * event, gpointer data ){	gtk_widget_hide( EditWindow );	// we do not want that the window be destroyed.	return TRUE;}void ButtonToolbarSignal( GtkWidget * widget, gpointer data ){	EditDatas.NumElementSelectedInToolBar = GPOINTER_TO_INT( data );}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?