/* * * ProLinga-Run * * Copyright (C) 2002-2009 Xobas Software. * All rights reserved. * * This file is part of ProLinga-Run. * * ProLinga-Run is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * ProLinga-Run 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ProLinga-Run. If not, see . * * More information is available at the following addresses: * * Website : http://www.prolinga.org * * Email : prolinga-list@prolinga.org * * */ #include "RunCommon.h" #include #include #include #include #include #include "RunShare.hpp" #include "RepositoryCommand.hpp" #include "DataRef.hpp" #include "ScreenRef.hpp" #include "CmdList.hpp" /* ListStore */ extern ListStorePtr listStorePtr; /* DataModel (M-) */ extern DataModelPtr dmPtr; /* VariableGroup (G-) */ extern VariableGroupPtr vgrpPtr; /* Table.Record (F-) */ extern TablePtr tablePtr; /* TextDocument */ extern TextDocumentPtr textPtr; /* XmlDocument */ extern XmlDocumentPtr xmlPtr; void ClearWidget(GtkWidget *wdg, const char *wdgName, const bool isMainThread) { GtkWidget *curWdg; GList *wdgList; int i, lengthWdgList; /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); wdgList = gtk_container_get_children(GTK_CONTAINER(wdg)); lengthWdgList = g_list_length(wdgList); for (i = 0; i < lengthWdgList; i++) { curWdg = GTK_WIDGET(g_list_nth_data(wdgList, i)); // printf("WIDGET : %s NAME : %s\n", G_OBJECT_TYPE_NAME(G_OBJECT(curWdg)), gtk_widget_get_name(curWdg)); if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } if (wdgName != NULL) { if (strcmp(wdgName, (char *)gtk_widget_get_name(curWdg)) == 0) putWidgetValue(curWdg, "", isMainThread); } else putWidgetValue(curWdg, "", isMainThread); /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); if (GTK_IS_CONTAINER(curWdg)) ClearWidget(curWdg, wdgName, isMainThread); } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } /* Command : CLEAR */ /* Syntax : CLEAR CONTAINER container_name CLEAR DATAMODEL datamodel_name CLEAR LISTSTORE list_store_name CLEAR PICKLIST picklist_name CLEAR RECORD record_name CLEAR TABLE table_name CLEAR TEXTDOC text_document CLEAR TREESTORE tree_store_name CLEAR VARGROUP variable_group_name CLEAR XMLDOC xml_document */ void CmdClear(const char **argList, int argHits, bool isMainThread, GtkWidget *outputScreen) { //char *screenFieldName, *recordName, tableName[255]; char *recordName, tableName[255]; char objectName[255]; // GladeXML *xml; int j; GtkWidget *wdgToClear, *curWdg; // GtkTextBuffer *textBuffer; /* Determine Clear Option */ if (strcmp(argList[1], "CONTAINER") == 0) { /* Clear Container */ /* Lookup Widget */ getDataRef(argList[2], isMainThread, objectName, false); curWdg = LookupWidget(GTK_WIDGET(outputScreen), objectName); if (curWdg == NULL) return; /* get GTK thread lock */ if (isMainThread == false) gdk_threads_enter(); /* Check if bin contains child */ wdgToClear = gtk_bin_get_child(GTK_BIN(curWdg)); if (wdgToClear != NULL) { /* Remove object from container */ gtk_container_remove(GTK_CONTAINER(curWdg), wdgToClear); } if (isMainThread == false) { /* Sync with X server */ gdk_flush(); /* release GTK thread lock */ gdk_threads_leave(); } } else if (strcmp(argList[1], "DATAMODEL") == 0) { /* Check if all DataModels need to be cleared */ if (strcmp(argList[2], "ALL") == 0) dmPtr->deleteList(&dmPtr); else { getDataRef(argList[2], isMainThread, objectName, false); dmPtr->deleteOne(&dmPtr, objectName); } } else if (strcmp(argList[1], "LISTSTORE") == 0) { /* Check if all List Stores need to be cleared */ if (strcmp(argList[2], "ALL") == 0) listStorePtr->deleteList(&listStorePtr); else { getDataRef(argList[2], isMainThread, objectName, false); listStorePtr->deleteFromList(&listStorePtr, objectName); } } else if (strcmp(argList[1], "RECORD") == 0) { if (strcmp(argList[2], "ALL") == 0) tablePtr->deleteList(&tablePtr); else { getDataRef(argList[2], isMainThread, objectName, false); recordName = strstr(objectName, "."); if (recordName == NULL) tablePtr->deleteOne(&tablePtr, objectName); else { recordName = recordName+1; strcpy(tableName, objectName); tableName[(strlen(objectName)-strlen(recordName)-1)] = '\0'; tablePtr->clearOneRecord(&tablePtr, tableName, recordName); } } } else if (strcmp(argList[1], "SCREENFIELD") == 0) { /* Check if all fields need to be cleared */ if (strcmp(argList[2], "ALL") == 0) ClearWidget(outputScreen, NULL, isMainThread); else if (argHits > 1) { /* Clear certain screen fields only */ for (j = 2; j <= argHits; j++) { getDataRef(argList[j], isMainThread, objectName, false); ClearWidget(outputScreen, objectName, isMainThread); } } } else if (strcmp(argList[1], "TABLE") == 0) { /* Check if all Tables need to be cleared */ if (strcmp(argList[2], "ALL") == 0) tablePtr->deleteList(&tablePtr); else { getDataRef(argList[2], isMainThread, objectName, false); tablePtr->deleteOne(&tablePtr, objectName); } } else if (strcmp(argList[1], "TEXTDOC") == 0) { /* Check if all Text buffers need to be cleared */ if (strcmp(argList[2], "ALL") == 0) textPtr->deleteList(&textPtr); else { getDataRef(argList[2], isMainThread, objectName, false); textPtr->deleteDocument(&textPtr, objectName); } } else if (strcmp(argList[1], "XMLDOC") == 0) { /* Check if all Xml buffers need to be cleared */ if (strcmp(argList[2], "ALL") == 0) xmlPtr->deleteList(&xmlPtr); else { getDataRef(argList[2], isMainThread, objectName, false); xmlPtr->deleteDocument(&xmlPtr, objectName); } } else if (strcmp(argList[1], "VARGROUP") == 0) { /* Check if all Variable Groups need to be cleared */ if (strcmp(argList[2], "ALL") == 0) vgrpPtr->deleteList(&vgrpPtr); else { getDataRef(argList[2], isMainThread, objectName, false); vgrpPtr->deleteOne(&vgrpPtr, objectName); } } else printf("Invalid Clear Option\n"); }