Exemple #1
0
void
MenuBar::removeCommands(
    Widget pulldown,
    CmdList *redundant_list
)
{
    // if(isValidMenuPane(pulldown) == FALSE)
    //	return;

    int    i, j, num_children;
    WidgetList children;
    
    XtVaGetValues(pulldown,
	XmNnumChildren, &num_children,
	NULL);
    
    children = (WidgetList)XtMalloc(sizeof(Widget) * num_children);
    
    XtVaGetValues(pulldown,
	XmNchildren, &children,
	NULL);
     
    // Loop through widget list.  Destroy those widgets that map to those
    // in the redundant list.

    for (i=0; i<num_children; i++) {

	Widget wid = (Widget) children[i];

	if (XtIsSubclass(wid, xmSeparatorWidgetClass)) {
	    XtUnmanageChild(wid);
	}
	else if (XtIsSubclass(wid, xmPushButtonWidgetClass)) {

	    for (j=0; j<redundant_list->size(); j++) {
		XmString str=NULL;
		String label=NULL;
		XtVaGetValues(wid, XmNlabelString, &str, NULL);
		if (str == NULL) continue;
	        label = NULL;
        	label = (char *) _XmStringUngenerate(
					str, NULL,
					XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
		XmStringFree(str);
		if (label == NULL) continue;
		if (strcmp(label, (*redundant_list)[j]->getLabel()) == 0) {
		    // The redundant item has been found.
		    XtUnmanageChild(wid);
		}
                XtFree(label);
	    }
	}
    }
}
Exemple #2
0
static  void    okCallback_OpenFile( Widget UxWidget,
                                    XtPointer UxClientData,
                                    XtPointer UxCallbackArg )

{
        _UxCOpenFile                     *UxSaveCtx, *UxContext;
        XmFileSelectionBoxCallbackStruct *cbs;
        /*char        *text;*/
        int         rc;
        ActionData  ADTmp;

        UxSaveCtx = UxOpenFileContext;
        UxOpenFileContext = UxContext =
                        (_UxCOpenFile *) UxGetContext( UxWidget );
        {

        /********************************************************************/
        /* Call file parsing code here!                                     */
        /********************************************************************/
        cbs = (XmFileSelectionBoxCallbackStruct *)UxCallbackArg;
        if (pszFileToEdit) {
           XtFree(pszFileToEdit);
        }
	pszFileToEdit =
	    _XmStringUngenerate(cbs->value, NULL,
				XmCHARSET_TEXT, XmCHARSET_TEXT);
        if (pszFileToEdit != (char *)NULL) {
           memset(&ADTmp, 0, sizeof(ActionData));
           rc = OpenDefinitionFile(pszFileToEdit, &ADTmp);
           /*XtFree(text);*/
           /*****************************************************************/
           /* If everything ok, then clear out data from action structure   */
           /* and store new data.                                           */
           /*****************************************************************/
           if (!rc) {
              FreeAndClearAD(&AD);
              memcpy(&AD, &ADTmp, sizeof(ActionData));
           }
        }
        UxPopdownInterface (UxWidget);

        /********************************************************************/
        /* If successfully opened and parsed file, then init the fields of  */
        /* the main window.                                                 */
        /********************************************************************/
        if (!rc) {
           clear_CreateActionAppShell_fields();
           writeCAToGUI(&AD);
        }
        }
        UxOpenFileContext = UxSaveCtx;
}
Exemple #3
0
Boolean
XmStringUngenerate(XmString string, XmStringCharSet tag, char** ret)
{

    *ret = (char *)_XmStringUngenerate(string, NULL, XmCHARSET_TEXT, XmCHARSET_TEXT);
    if (*ret) {
	return True;
    }
    else {
	return False;
    }
    
#if 0
  XmStringContext context;

  if (! XmStringInitContext(&context, string)) {
    *ret = NULL;
    return False;
  }

  int bufsize, buflen;
  char* buf = XtMalloc(bufsize = 128);
  buf[0] = 0;
  buflen  = 1;

  char* text = NULL;
  XmStringDirection dir;
  Boolean sep;

  while (XmStringGetNextSegment(context, &text, &tag, &dir, &sep)) {
    if (text) {
      len = strlen(text);
      int textlen = len + (sep? 1 : 0);
      { // buffer size adjustment
	int bufsize_required = bufsize;
	while (buflen + textlen > bufsize_required)
	  bufsize_required += 128;
	if (bufsize_required > bufsize) {
	  buf = XtRealloc(buf, bufsize_required);
	  bufsize = bufsize_required;
	}
      }
      slen = strlen(buf);
      *((char *) memcpy(buf + slen, text, len) + len) = '\0';
      if (sep)
	*((char *) memcpy(buf + slen + 1, "\n", 1) + 1) = '\0';
      buflen += textlen;

      XtFree(text);
    }
    text = NULL;
  }

  XmStringFreeContext(context);

  *ret = buf;

  return True;

#endif
}
Exemple #4
0
void filesbokCB(Widget widget, Exc_data * ed, XtPointer call_data)
{
    XmFileSelectionBoxCallbackStruct	*ptr;
    char				*file = NULL, *dir = NULL, *tmpfile;
    int					r, ans = 0;
    char				*msg1;
    char				*msg2;

    msg1 = GETMESSAGE(2, 4, "The selected file exists. Overwrite?");
    msg2 = GETMESSAGE(2, 6, "Failed to open the selected file.");

    ptr = (XmFileSelectionBoxCallbackStruct *) call_data;

    file = (char *)  _XmStringUngenerate((XmString) ptr->value, NULL,
					  XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
    if (!file) {
	return;
    }

    dir = (char *)  _XmStringUngenerate((XmString) ptr->dir, NULL,
					  XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
    if (!dir) {
	return;
    } else {
	if (*file != '/') {
	    if ((tmpfile = XtMalloc(strlen(dir) + 1 + strlen(file) + 1))
		== NULL) {
		excerror(ed, EXCERRMALLOC, "filesbokCB", "exit");
	    }
	    sprintf(tmpfile, "%s/%s", dir, file);
	    XtFree(file);
	    file = tmpfile;
	}
    }

    r = fopencheck(file, dir, ed->bdfmode);
    if (r == 0) {/* no problem */
	/*fprintf(stderr, "%s will be opened\n", file);*/
    } else if (r == 1) { /* file exist at export function */
	AskUser(widget, ed, msg1, &ans, "warning");
	if (ans != 1) { /* overwrite cancel */
	    freeStrings(dir, file);
	    return;
	}
    } else { /* file will not be opened */
	AskUser(widget, ed, msg2, &ans, "error");
	freeStrings(dir, file);
	return;
    }
    ed->bdffile = (char *) malloc(strlen(file) + 1);
    strcpy(ed->bdffile, file);
    freeStrings(dir, file);
    XtUnmanageChild(widget);
    if (ed->function == EXPORT)
    {
	createbdf(ed);
    } else if (ed->function == IMPORT)
    {
	PopupSelectXLFD(ed->toplevel);
    }
}
Exemple #5
0
void AttachArea::setAttachmentsLabel( )
{
    char *c = new char[256];
    XmString xmstr;
    String str;
    unsigned int last_displayCount, last_selectedCount;
    unsigned int displayCount = _iconCount - _deleteCount;
    unsigned int attachmentsSize;

    if((displayCount) == 0) {
	XtUnmanageChild(_no_attachments_label);
	XtUnmanageChild(_attachments_label);
	XtUnmanageChild(_size_attachments_label);
	XtUnmanageChild(_no_selected_label);
	XtUnmanageChild(_selected_label);
	XtUnmanageChild(_size_selected_label);
    } else {
	CalcAttachmentsSize();
	attachmentsSize = getAttachmentsSize();

	// Number of Attachments
	XtVaGetValues(_no_attachments_label,
		XmNlabelString, &xmstr,
		NULL);
	str = NULL;
        str = (char *) _XmStringUngenerate(
					xmstr, NULL,
					XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
	if (NULL == str) return; // internal error
	last_displayCount = (unsigned int)strtol(str, NULL, 10);
	XtFree(str);

	// Number of Attachments Selected
	XtVaGetValues(_no_selected_label,
		XmNlabelString, &xmstr,
		NULL);
	str = NULL;
        str = (char *) _XmStringUngenerate(
					xmstr, NULL,
					XmMULTIBYTE_TEXT, XmMULTIBYTE_TEXT);
	if (NULL == str) return; // internal error
	last_selectedCount = (unsigned int)strtol(str, NULL, 10);
	XtFree(str);

	if((last_displayCount == 0 && displayCount == 1) ||
	   (last_displayCount == 2 && displayCount == 1)) {
	    sprintf(c, GETMSG(DT_catd, 12, 1, "Attachment"));
	    XtVaSetValues(_attachments_label,
		XtVaTypedArg, XmNlabelString, XtRString, c, strlen(c)+1,
		NULL);
	} else if(last_displayCount == 1 && displayCount == 2) {
	    sprintf(c, GETMSG(DT_catd, 12, 2, "Attachments"));
	    XtVaSetValues(_attachments_label,
		XtVaTypedArg, XmNlabelString, XtRString, c, strlen(c)+1,
		NULL);
	}
	if(last_displayCount != displayCount) {
	    sprintf(c, GETMSG(DT_catd, 12, 3, "displayCount"));
	    XtVaSetValues(_no_attachments_label,
		XtVaTypedArg, XmNlabelString, XtRString, c, strlen(c)+1,
		NULL);
	}
	sprintf(c, "(%s),", calcKbytes(attachmentsSize));
	XtVaSetValues(_size_attachments_label,
	    XtVaTypedArg, XmNlabelString, XtRString, c, strlen(c)+1,
	    NULL);

	if(last_selectedCount != _iconSelectedCount) {
	    sprintf(c, "%d", _iconSelectedCount); 
	    XtVaSetValues(_no_selected_label,
		XtVaTypedArg, XmNlabelString, XtRString, c, strlen(c)+1,
		NULL);
	    sprintf(c, "(%s)", calcKbytes(getSelectedAttachmentsSize())); 
	    XtVaSetValues(_size_selected_label,
		XtVaTypedArg, XmNlabelString, XtRString, c, strlen(c)+1,
		NULL);
	}
	if(!XtIsManaged(_no_attachments_label)) {
	    XtManageChild(_no_attachments_label);
	    XtManageChild(_attachments_label);
	    XtManageChild(_size_attachments_label);
	    XtManageChild(_no_selected_label);
	    XtManageChild(_selected_label);
	    XtManageChild(_size_selected_label);
	}
    }
    delete [] c;
}
Exemple #6
0
static void
OkCallback(
        Widget selection_box,
        ChangeDirApply *apply_data,
        XmSelectionBoxCallbackStruct *callback_data )
{
   DialogData * dialog_data;
   ChangeDirData * change_dir_data;
   FileMgrRec * file_mgr_rec;
   FileMgrData * file_mgr_data;
   char *strValue;
   char *value = NULL;
   int result;
   char message_buf[MAX_PATH + 100];
   char * tmpStr;
   char * title;
   char * msg;


   /*  Get the change dir data record  */

   dialog_data = _DtGetInstanceData (apply_data->change_dir_rec);
   change_dir_data = (ChangeDirData *) dialog_data->data;

   file_mgr_rec = (FileMgrRec *) change_dir_data->file_mgr_rec;
   dialog_data = _DtGetInstanceData ((XtPointer)file_mgr_rec);
   file_mgr_data = (FileMgrData *) dialog_data->data;

   value = (char *) _XmStringUngenerate((XmString)callback_data->value,
                                        XmFONTLIST_DEFAULT_TAG,
                                        XmCHARSET_TEXT, XmCHARSET_TEXT);

   if ( value == NULL)
   {
       tmpStr = GetSharedMessage(CHANGE_DIR_ERROR_TITLE);
      title = XtNewString(tmpStr);
      tmpStr = (char *) GETMESSAGE(2, 11, "Cannot get the new folder name.");
      msg = XtNewString(tmpStr);

      _DtMessage(selection_box, title, message_buf, NULL, HelpRequestCB);

      XtFree(title);
      XtFree(msg);
      return;
   }

   strValue = XtNewString(value);
   if(file_mgr_data->toolbox && strValue[0] != '/')
      result = CheckRestrictedDir(file_mgr_rec, file_mgr_data, &strValue, True);
   else
      result = CheckRestrictedDir(file_mgr_rec, file_mgr_data, &strValue,False);

   /*  Process the string representing a directory to verify  */
   /*  that it is a valid path.                               */
   if (result == 0)
   {
      TryToChangeDir(True, (char *)strValue, file_mgr_data,
                     file_mgr_rec, change_dir_data, selection_box, apply_data,
                     callback_data, apply_data->callback);
   }

   XtFree(value);
   XtFree(strValue);
}