Commit 691e5a57 authored by claes's avatar claes

Connect function via X selection implemented

parent d9e8fa9f
......@@ -21,21 +21,32 @@
#include <Xm/MainW.h>
#include <Xm/FileSB.h>
#include <Xm/Form.h>
#include <X11/Xatom.h>
#include <X11/Xmu/Atoms.h>
#include <X11/Xmu/StdSel.h>
#include "pwr.h"
#include "co_dcli.h"
#include "co_wow.h"
#include "flow_x.h"
#define WOW_MAXNAMES 400
typedef struct
{
typedef struct {
void *ctx;
void *data;
void (* questionbox_ok) ();
void (* questionbox_cancel) ();
} wow_t_question_cb;
typedef struct {
char str[200];
int len;
int received;
pwr_tStatus sts;
Atom atom;
} wow_sSelection;
static void wow_question_ok_cb (
Widget dialog,
XtPointer data,
......@@ -639,6 +650,60 @@ void wow_GetCSText( XmString ar_value, char *t_buffer)
}
#endif
static void wow_get_selection_cb( Widget w, XtPointer clientdata, Atom *selection,
Atom *type, XtPointer value, unsigned long *len,
int *format)
{
wow_sSelection *data = (wow_sSelection *)clientdata;
if ( *len != 0 && value != NULL) {
if ( *type == data->atom) {
if ( *len > sizeof(data->str) - 1) {
data->sts = 0;
return;
}
strncpy( data->str, (char *)value, *len);
data->str[*len] = 0;
data->len = *len;
data->sts = 1;
}
else
data->sts = 0;
}
else
data->sts = 0;
XtFree( (char *)value);
data->received = 1;
}
int wow_GetSelection( Widget w, char *str, int size, Atom atom)
{
wow_sSelection data;
data.received = 0;
data.atom = atom;
XtGetSelectionValue( w, XA_PRIMARY, atom,
wow_get_selection_cb, &data, CurrentTime);
while( !data.received) {
XEvent e;
XtAppNextEvent( XtWidgetToApplicationContext(w), &e);
XtDispatchEvent( &e);
}
if ( data.sts && data.len < size)
strcpy( str, data.str);
return data.sts;
}
void wow_GetAtoms( Widget w, Atom *graph_atom, Atom *objid_atom, Atom *attrref_atom)
{
if ( graph_atom)
*graph_atom = XInternAtom( flow_Display(w), "PWR_GRAPH", False);
if ( objid_atom)
*objid_atom = XInternAtom( flow_Display(w), "PWR_OBJID", False);
if ( attrref_atom)
*attrref_atom = XInternAtom( flow_Display(w), "PWR_ATTRREF", False);
}
......
......@@ -9,6 +9,11 @@
<Description>. */
#include <Xm/Xm.h>
#include <X11/Xatom.h>
#if defined __cplusplus
extern "C" {
#endif
typedef enum {
wow_eFileSelType_All,
......@@ -71,7 +76,12 @@ void wow_CreateFileSelDia( Widget parent_wid,
void wow_GetLabel( Widget w, char *label);
void wow_GetCSText( XmString ar_value, char *t_buffer);
int wow_GetSelection( Widget w, char *str, int size, Atom atom);
void wow_GetAtoms( Widget w, Atom *graph_atom, Atom *objid_atom, Atom *attrref_atom);
#if defined __cplusplus
}
#endif
#endif
......
......@@ -122,6 +122,7 @@ typedef struct ge_sCtx {
void *focused_component;
grow_tObject recover_object;
char recover_name[80];
Atom graph_atom;
} *ge_tCtx;
// Static variables
......@@ -847,97 +848,122 @@ static int ge_get_plant_select_cb( void *ge_ctx, char *select_name)
char *s;
if ( !gectx->ldhses)
return 0;
if ( !gectx->ldhses) {
sts = wow_GetSelection( gectx->toplevel, str, sizeof(str), gectx->graph_atom);
if ( ODD(sts))
strcpy( select_name, str);
else {
sts = wow_GetSelection( gectx->toplevel, str, sizeof(str), XA_STRING);
if ( ODD(sts))
strcpy( select_name, str);
}
return sts;
}
sts = plant_get_select( gectx->plantctx, &attrref, &is_attrref);
if ( EVEN( sts)) return sts;
if ( is_attrref)
{
if ( ODD( sts)) {
sts = ldh_AttrRefToName( gectx->ldhses, &attrref, ldh_eName_Aref,
&str_p, &size);
if ( EVEN(sts)) return sts;
strcpy( name, str_p);
if ( (s = strrchr( name, '.')))
strcpy( attr_name, s + 1);
else
strcpy( attr_name, "");
if ( is_attrref) {
sts = ldh_GetObjectClass( gectx->ldhses, attrref.Objid, &classid);
if ( EVEN(sts)) return 0;
}
else
{
sts = ldh_ObjidToName( gectx->ldhses, attrref.Objid, ldh_eName_Hierarchy,
str, sizeof(str), &size);
if ( EVEN(sts)) return sts;
sts = ldh_AttrRefToName( gectx->ldhses, &attrref, ldh_eName_Aref,
&str_p, &size);
if ( EVEN(sts)) return sts;
strcpy( name, str_p);
if ( (s = strrchr( name, '.')))
strcpy( attr_name, s + 1);
else
strcpy( attr_name, "");
sts = ldh_GetObjectClass( gectx->ldhses, attrref.Objid, &classid);
if ( EVEN(sts)) return 0;
}
else {
sts = ldh_ObjidToName( gectx->ldhses, attrref.Objid, ldh_eName_Hierarchy,
str, sizeof(str), &size);
if ( EVEN(sts)) return sts;
// Get the debugparameter if there is one else add ActualValue
sts = ldh_GetObjectClass( gectx->ldhses, attrref.Objid, &classid);
if ( EVEN(sts)) return 0;
// Get the debugparameter if there is one else add ActualValue
sts = ldh_GetObjectClass( gectx->ldhses, attrref.Objid, &classid);
if ( EVEN(sts)) return 0;
sts = ldh_GetClassBody( gectx->ldhses, classid,
"GraphPlcNode", &body_class, (char **)&graph_body, &size);
if ( ODD(sts))
{
strcpy( attr_name, graph_body->debugpar);
}
else
strcpy( attr_name, "ActualValue");
sts = ldh_GetClassBody( gectx->ldhses, classid,
"GraphPlcNode", &body_class, (char **)&graph_body, &size);
if ( ODD(sts)) {
strcpy( attr_name, graph_body->debugpar);
}
else
strcpy( attr_name, "ActualValue");
strcpy( name, str);
strcat( name, ".");
strcat( name, attr_name);
}
strcpy( name, str);
strcat( name, ".");
strcat( name, attr_name);
}
strcpy( buff, name);
strcpy( buff, name);
// Check that attribute exists
sts = ldh_NameToAttrRef( gectx->ldhses, name, &attr_ref);
if (ODD(sts))
{
// If attribute is an array element get attribute definition for
// the array.
if ( (p1 = strstr(attr_name, "[")))
*p1 = '\0';
// Check that attribute exists
sts = ldh_NameToAttrRef( gectx->ldhses, name, &attr_ref);
if (ODD(sts)) {
// If attribute is an array element get attribute definition for
// the array.
if ( (p1 = strstr(attr_name, "[")))
*p1 = '\0';
sts = ldh_GetAttrDef( gectx->ldhses, classid, "RtBody", attr_name, &attr_def);
if (EVEN(sts))
sts = ldh_GetAttrDef( gectx->ldhses, classid, "SysBody",
attr_name, &attr_def);
if ( ODD(sts) && gectx->graph->type_to_string( attr_def.Par->Input.Info.Type,
type_buff, NULL))
{
char num[8];
if ( (p2 = strstr(buff, "[")))
*p2 = '\0';
if (attr_def.Par->Input.Info.Type == pwr_eType_String)
{
sprintf(num, "%d", attr_def.Par->Input.Info.Size/attr_def.Par->Input.Info.Elements);
strcat(type_buff, num);
}
strcat(buff, "##");
strcat(buff, type_buff);
// Check if array
if (p1)
{
sprintf(&buff[strlen(buff)], "#%d",
attr_def.Par->Input.Info.Elements);
*p1 = '[';
strcat(buff, p1);
sts = ldh_GetAttrDef( gectx->ldhses, classid, "RtBody", attr_name, &attr_def);
if (EVEN(sts))
sts = ldh_GetAttrDef( gectx->ldhses, classid, "SysBody",
attr_name, &attr_def);
if ( ODD(sts) && gectx->graph->type_to_string( attr_def.Par->Input.Info.Type,
type_buff, NULL)) {
char num[8];
if ( (p2 = strstr(buff, "[")))
*p2 = '\0';
if (attr_def.Par->Input.Info.Type == pwr_eType_String) {
sprintf(num, "%d", attr_def.Par->Input.Info.Size/attr_def.Par->Input.Info.Elements);
strcat(type_buff, num);
}
strcat(buff, "##");
strcat(buff, type_buff);
// Check if array
if (p1) {
sprintf(&buff[strlen(buff)], "#%d",
attr_def.Par->Input.Info.Elements);
*p1 = '[';
strcat(buff, p1);
}
}
}
strcpy( select_name, buff);
return 1;
}
else {
sts = wow_GetSelection( gectx->toplevel, str, sizeof(str), gectx->graph_atom);
if ( ODD(sts))
strcpy( select_name, str);
else {
sts = wow_GetSelection( gectx->toplevel, str, sizeof(str), XA_STRING);
if ( ODD(sts))
strcpy( select_name, str);
}
return sts;
}
strcpy( select_name, buff);
return 1;
#else
return 0;
pwr_tStatus sts;
ge_tCtx gectx = (ge_tCtx)ge_ctx;
sts = wow_GetSelection( gectx->toplevel, str, sizeof(str), gectx->graph_atom);
if ( ODD(sts))
strcpy( select_name, str);
else {
sts = wow_GetSelection( gectx->toplevel, str, sizeof(str), XA_STRING);
if ( ODD(sts))
strcpy( select_name, str);
}
return sts;
#endif
}
......@@ -2912,6 +2938,9 @@ void *ge_new( void *parent_ctx,
flow_AddCloseVMProtocolCb( gectx->toplevel,
(XtCallbackProc)ge_activate_exit, gectx);
// Get proview defined selection atoms
wow_GetAtoms( gectx->toplevel, &gectx->graph_atom, 0, 0);
ge_get_systemname( systemname);
gectx->graph->set_systemname( systemname);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment