Ejemplo n.º 1
0
char* iupmotConvertString(XmString str)
{
  char* text = (char*)XmStringUnparse(str, NULL, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
  char* buf = iupStrGetMemoryCopy(text);
  XtFree(text);
  return buf;
}
Ejemplo n.º 2
0
static void motListAddSortedItem(Ihandle* ih, const char *value)
{
  char *text;
  XmString *strlist;
  int u_bound, l_bound = 0;

  XtVaGetValues(ih->handle, XmNitemCount, &u_bound, XmNitems, &strlist, NULL);

  u_bound--;
  /* perform binary search */
  while (u_bound >= l_bound) 
  {
    int i = l_bound + (u_bound - l_bound)/2;
    text = (char*)XmStringUnparse(strlist[i], NULL, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
    if (!text)
      break;
    if (strcmp (text, value) > 0)
      u_bound = i-1; /* newtext comes before item */
    else
      l_bound = i+1; /* newtext comes after item */
    XtFree(text);
  }

  motListAddItem(ih, l_bound, value);
}
Ejemplo n.º 3
0
void
saveAsCB( Widget w, XtPointer client_data, 
 		XtPointer call_data)
{
	char *path;
	XmFileSelectionBoxCallbackStruct *res;
	
	res = (XmFileSelectionBoxCallbackStruct *) call_data; 
	path = XmStringUnparse(res->value, 
	    NULL, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
	    
	set_save_path(path);
	if (EXIT_SUCCESS == save_file(w, "saveAsCB")) XtUnmanageChild(w);
	XtFree(path);
}
Ejemplo n.º 4
0
void
fileOpenCB( Widget w, XtPointer client_data, 
 		XtPointer call_data)
{
	char *c_path;
	XmFileSelectionBoxCallbackStruct *res;
	
	res = (XmFileSelectionBoxCallbackStruct *) call_data; 
	c_path = XmStringUnparse(res->value, 
	    NULL, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL); 
	load_file(w, "fileOpenCB", c_path);

	free(c_path);
	XtUnmanageChild(w);
}
Ejemplo n.º 5
0
static void completions_browse_callback(Widget w, XtPointer context, XtPointer info) 
{
  int i, j, old_len, new_len;
  char *text = NULL, *old_text = NULL;
  XmListCallbackStruct *cbs = (XmListCallbackStruct *)info;
  Widget requestor;
  if (ss->sgx->completion_requestor == NULL) 
    requestor = listener_text;
  else requestor = ss->sgx->completion_requestor;
  /* choice = cbs->item_position - 1; */
  text = (char *)XmStringUnparse(cbs->item, NULL, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
  old_text = XmTextGetString(requestor);
  old_len = snd_strlen(old_text);
  new_len = snd_strlen(text);
  for (i = old_len - 1, j = new_len - 1; j >= 0; j--)
    {
      if (old_text[i] != text[j])
	{
	  i = old_len - 1;
	  if (old_text[i] == text[j]) i--;
	  /* this added 15-Apr-02 for case like map-chan(nel) */
	  /*   probably should go back new_len and scan forwards instead */
	}
      else i--;
    }
  if (requestor == listener_text)
    append_listener_text(XmTextGetLastPosition(listener_text), 
			 (char *)(text - 1 + old_len - i));
  else
    {
      /* try to append to who(m?)ever asked for completion help */
      XmTextInsert(requestor, 
		   XmTextGetLastPosition(requestor), 
		   (char *)(text - 1 + old_len - i));
    }
  if (text) XtFree(text);
  if (old_text) XtFree(old_text);
  unpost_completion(requestor);
}
Ejemplo n.º 6
0
void
includeFileCB( Widget w, XtPointer client_data, 
 		XtPointer call_data)
{
	char *file_data, *c_path;
	Widget widget;
	XmFileSelectionBoxCallbackStruct *res;
	XmTextPosition pos;
	
	res = (XmFileSelectionBoxCallbackStruct *) call_data; 
	c_path = XmStringUnparse(res->value, 
	    NULL, XmCHARSET_TEXT, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL); 
	file_data = get_file_contents(w, "fileOpenCB", c_path);
	widget = get_document_text(w, "fileOpenCB");
	pos = XmTextGetInsertionPosition(widget);
	XmTextInsert(widget, pos, file_data);
	
	update_document_linecount(w, "includeFileCB");
	update_message(w, "fileOpenCB", "Included file.");
	
	XtFree(c_path);
	XtFree(file_data);
	XtUnmanageChild(w);
}
Ejemplo n.º 7
0
/* ARGSUSED */
void dslw_groupCb ( Widget w, XtPointer clnt, XtPointer call )
/************************************************************************
 * dslw_groupCb 							*
 *									*
 * This functions display the group products. It is the callback for	*
 * group list.								*
 *									*
 * void dslw_groupCb(w, clnt, call) 					*
 *									*
 * Input parameters:							*
 *  w			Widget						*
 *  clnt 		XtPointer					*
 *  call		XtPointer					*
 *									*
 **									*
 * Log: 								*
 * L. Williams/EAI     06/95						*
 * C. Lin/EAI	       10/95  add comments				*
 * J. Wu/GSC	       05/01  free XmStrings				*
 * T. Piper/GSC		6/01	Freed xmstr				*
 * T. Piper/SAIC	10/06	Replaced XmStringGetLtoR with		*
 *					 XmStringUnparse		*
 ***********************************************************************/
{
struct guid_grp *group_ptr;
XmListCallbackStruct *cbs = (XmListCallbackStruct *) call;

XmString  *xmstr;
char	  str[100];
int	  ii;
int	  prdcnt, nselect;
char	  *selected_item;

/*---------------------------------------------------------------------*/
/*
 * return when no selection was made
 */
	XtVaGetValues(w,
		XmNselectedItemCount, &nselect,
		NULL);
	if ( nselect == 0 )
		return;

	XmListDeselectAllItems(_prodlistW);

/*
 * get the selected group name
 */
	selected_item = XmStringUnparse (cbs->item, NULL, XmCHARSET_TEXT,
                                XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);

/*
 * Search the link list for the selected item
 */
	group_ptr = guid_grp_head;
	while ( group_ptr ) {
	    if (strcmp(group_ptr->grpname, selected_item) == 0) {
		usrSelect.group = group_ptr;
		break;
	    }
	    else
		group_ptr = group_ptr->nextgrp;
	}

/*
 * If products exist move product name into array.
 */
	if (group_ptr->nprod) {
	  xmstr = (XmString *) XtMalloc(sizeof(XmString) * (size_t)group_ptr->nprod);
	  for (ii=0; ii<group_ptr->nprod; ii++) {
	    if ( group_ptr->prod[ii].index == -2 ) {

/*
 * the selected product is not available
 */
		sprintf(str, "%s *", group_ptr->prod[ii].prdname);
		xmstr[ii] = XmStringCreateLocalized(str);
	    }
	    else
		xmstr[ii] = XmStringCreateLocalized(group_ptr->prod[ii].prdname);
	  }
	}
	else {
/*
 * No products exist.
 */
	  xmstr = (XmString *) XtMalloc (sizeof(XmString));
	  xmstr[0] = XmStringCreateLocalized("No products available");
	}

	XtFree( selected_item );

/*
 * display "No products available"
 */
	prdcnt=group_ptr->nprod;
	if (!prdcnt) ++prdcnt;

	XtVaSetValues(_prodlistW,
		XmNitems, xmstr,
		XmNitemCount, prdcnt,
		NULL);
	
	for (ii=0; ii<prdcnt; ii++) {
            XmStringFree( xmstr[ii] );
	}
	XtFree((XtPointer)xmstr);	
}
Ejemplo n.º 8
0
void appIcon_AddRemoveItem(Widget wList, struct Broadcast_Packet* p_Item, char m_Option, XtPointer xtLabel)
{
	XmString xstr_item;
	XmStringTable xstr_list;
	int mFound = 0;
	int mIdx = 0;
	int mCount;	
	char str_Item[150]; 
	char* text;	
	char* test;

	char str_Count[4];	
			
	if(strlen(p_Item->Handlename) == 0)
	{
		sprintf(str_Item, "%s@%s (%s)", p_Item->Username, p_Item->Hostname, p_Item->IP_Address);
	}
	else
	{
		sprintf(str_Item, "%s@%s (%s)", p_Item->Handlename, p_Item->Hostname, p_Item->IP_Address);
	}
	
  	// Get the current entries (and number of entries) from the List
	XtVaGetValues (wList, XmNitemCount, &mCount,	XmNitems, &xstr_list, NULL);
		
	xstr_item = XmStringCreateLocalized (str_Item);
		
	
	
	if(m_Option == 1)
	{
		while(mCount>mIdx)
		{		
			if(XmStringCompare(xstr_item, xstr_list[mIdx]))
			{
				mFound = 1;
				break;
			}	
			mIdx++;
		}	
		
		if(mFound == 0)
		{
			mIdx = 0;
			while(mCount>mIdx)
			{
				text = (char *) XmStringUnparse (xstr_list[mIdx], NULL,XmCHARSET_TEXT, XmCHARSET_TEXT,NULL, 0, XmOUTPUT_ALL);
			
				if (strcmp (text, str_Item) > 0)
				{
					// str_Item comes before item
					XtFree(text);
					break;
				}
				
				XtFree(text);
				mIdx++;
			}
			
			mCount++;
			XmListAddItemUnselected (wList, xstr_item, mIdx+1);
			if(wList != APPICON_List_Users)
			{
				sprintf(str_Count, "%i", mCount);
				XtVaSetValues(*(Widget*)xtLabel, XmNvalue, str_Count, NULL);				
			}	
		}
	}
	else
	{
		while(mCount>mIdx)
		{		
			text = (char *) XmStringUnparse (xstr_list[mIdx], NULL,XmCHARSET_TEXT, XmCHARSET_TEXT,NULL, 0, XmOUTPUT_ALL);
					
			if ((test = strstr(text, p_Item->IP_Address)) != '\0')
			{
				*(strchr(test,')')) = '\0';
				if(strcmp(test, p_Item->IP_Address) == 0)
				{
					mFound = 1;
					XtFree(text);
					break;
				}
			}		
			
			XtFree(text);						
			mIdx++;
		}	
		
		if(mFound == 1)
		{
			mCount--;
			XmListDeletePos(wList, mIdx+1);	
			if(wList != APPICON_List_Users)
			{
				sprintf(str_Count, "%i", mCount);
				XtVaSetValues(*(Widget*)xtLabel, XmNvalue, str_Count, NULL);
			}	
		}
	}
	
	XmStringFree (xstr_item);	
}
Ejemplo n.º 9
0
static int Apply(Widget w)
{
  Widget list_w = XtNameToWidget(XtParent(w),"*interpreters");
  XtPointer  user_data;
  int nid;
  XmString *selections=NULL;
  String   list = 0;
  String   old_list;
  int      num;
  int      i;
  int      status = 1;
  XtVaGetValues(list_w, XmNuserData, &user_data, NULL);
  nid = (intptr_t)user_data;
  old_list = XmdsGetNidText(nid);
  XtVaGetValues(list_w, XmNselectedItems, &selections, XmNselectedItemCount, &num, NULL);
  for (i=0;i<num;i++)
  {
    String item;
    item = XmStringUnparse(selections[i], NULL, 0, XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
    if (item)
    {
      if (list)
      {
        list = XtRealloc(list, strlen(list) + strlen(item) + 2);
        strcat(list,item);
      }
      else
      {
        list = XtMalloc(strlen(item) + 2);
        strcpy(list,item);
      }
      strcat(list,"\n");
      XtFree(item);
    }
  }
  if ( (list && (old_list ? strcmp(old_list,list) : 1)) ||
       (!list && (old_list ? strlen(old_list) : 0)) )
  {
    if (list)
    {
      static struct descriptor list_dsc = {0, DTYPE_T, CLASS_S, 0};
      list_dsc.length = strlen(list);
      list_dsc.pointer = list;
      status = TreePutRecord(nid, &list_dsc,0) & 1;
      if (!status)
        XmdsComplain(XtParent(w), "Error writing interpreter selections");
    }
    else
    {
      struct descriptor list_dsc = {0, DTYPE_T, CLASS_S, 0};
      status = TreePutRecord(nid, &list_dsc,0) & 1;
      if (!status)
        XmdsComplain(XtParent(w), "Error writing interpreter selections");
    }
  }
  XtFree(list);
  XtFree(old_list);
  if (status)
    XmdsApplyAllXds(XtParent(w));
  return status & 1;
}
Ejemplo n.º 10
0
static int
SaveSelectedValues(
      I18nEnv *env)
{
    int ret = NoError;
    char *preeditStr = NULL, *tmpStr;
    int i;
    XtArgVal num_preedit = 0;
    XmStringTable list_preedit;
    static char preeditTypeRes[1024];

    /* Get the values from the UI and update the FileSel structure */
    SetFileSelValues(env);

    /* Write these values in the IMS Selection File */
    ret = _DtI18nWriteImSelectionFile(env);

    /* Save the preeditType resource value if needed */
    if (i18n.preeditHasChanged) {

	if (style.xrdb.writeXrdbImmediate)
	    InfoDialog(MSG_IMMEDIATE, style.shell, False);
	else
	    InfoDialog(MSG_LATER, style.shell, False);

	/* generate a string from the list to set the resource */
	XtVaGetValues(i18n.preeditTypeList,
		      XmNitemCount, &num_preedit,
		      XmNitems, &list_preedit, NULL);

	/* Save this value in case of a Cancel */
	if (i18n.preeditSavedVal) {
	    FreeST(i18n.preeditSavedVal, i18n.preeditSavedNum);
	}

	i18n.preeditSavedVal = CopyST(list_preedit, num_preedit);
	i18n.preeditSavedNum = num_preedit;

	for (i = 0; i < num_preedit; i++) {
	    /* get the text of the XmString */
	    tmpStr = XmStringUnparse(list_preedit[i], NULL, XmCHARSET_TEXT, 
				     XmCHARSET_TEXT, NULL, 0, XmOUTPUT_ALL);
	    /* realloc mallocs the first time */
	    preeditStr = XtRealloc(preeditStr, 
				   strlen(preeditStr) + strlen(tmpStr) + 2);

	    /* insert the comma before the second, third. etc */
	    if (i != 0) {
		strcat(preeditStr, ",");
		strcat(preeditStr, tmpStr);
	    }
	    else
		strcpy(preeditStr, tmpStr);

	    XtFree(tmpStr);
	}

	/* if writeXrdbImmediate true write to Xrdb else send to 
	   session mgr */

	sprintf(preeditTypeRes, "*preeditType: %s\n", preeditStr);

	XtFree(preeditStr);

	if(style.xrdb.writeXrdbImmediate)
	    _DtAddToResource(style.display, preeditTypeRes);

	SmNewPreeditSettings(preeditTypeRes);

	/* Reset the state of the list. */
	i18n.preeditHasChanged = False;
    }

    return (ret);

}