Esempio n. 1
0
static int motListSetClipboardAttrib(Ihandle *ih, const char *value)
{
  Widget cbedit;
  if (!ih->data->has_editbox)
    return 0;

  XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL);

  if (iupStrEqualNoCase(value, "COPY"))
  {
    Ihandle* clipboard;
    char *str = XmTextFieldGetSelection(cbedit);
    if (!str) return 0;

    clipboard = IupClipboard();
    IupSetAttribute(clipboard, "TEXT", str);
    IupDestroy(clipboard);

    XtFree(str);
  }
  else if (iupStrEqualNoCase(value, "CUT"))
  {
    Ihandle* clipboard;
    char *str = XmTextFieldGetSelection(cbedit);
    if (!str) return 0;

    clipboard = IupClipboard();
    IupSetAttribute(clipboard, "TEXT", str);
    IupDestroy(clipboard);

    XtFree(str);

    /* disable callbacks */
    iupAttribSet(ih, "_IUPMOT_DISABLE_TEXT_CB", "1");
    XmTextFieldRemove(cbedit);
    iupAttribSet(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL);
  }
  else if (iupStrEqualNoCase(value, "PASTE"))
  {
    Ihandle* clipboard;
    char *str;

    clipboard = IupClipboard();
    str = IupGetAttribute(clipboard, "TEXT");

    /* disable callbacks */
    iupAttribSet(ih, "_IUPMOT_DISABLE_TEXT_CB", "1");
    XmTextFieldRemove(cbedit);
    XmTextFieldInsert(cbedit, XmTextFieldGetInsertionPosition(cbedit), str);
    iupAttribSet(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL);
  }
  else if (iupStrEqualNoCase(value, "CLEAR"))
  {
    /* disable callbacks */
    iupAttribSet(ih, "_IUPMOT_DISABLE_TEXT_CB", "1");
    XmTextFieldRemove(cbedit);
    iupAttribSet(ih, "_IUPMOT_DISABLE_TEXT_CB", NULL);
  }
  return 0;
}
Esempio n. 2
0
static char* get_selectedtext(Ihandle *n)
{
   if (type(n) == TEXT_)
     return iupmotGetMemory(XmTextFieldGetSelection( (Widget)handle(n) ) );
   else if (type(n) == MULTILINE_)
     return iupmotGetMemory(XmTextGetSelection( (Widget)handle(n) ) );
   else if (type(n) == LIST_ && iupCheck(n, "EDITBOX")==YES)
     return iupmotGetMemory(XmTextFieldGetSelection( (Widget)IupGetAttribute(n, "_IUPMOT_EDITBOX") ) );

   return NULL;
}
Esempio n. 3
0
static char* motListGetSelectedTextAttrib(Ihandle* ih)
{
  if (ih->data->has_editbox)
  {
    char* selectedtext, *str;
    Widget cbedit;
    XtVaGetValues(ih->handle, XmNtextField, &cbedit, NULL);
    selectedtext = XmTextFieldGetSelection(cbedit);
    str = iupStrReturnStr(selectedtext);
    XtFree(selectedtext);
    return str;
  }
  else
    return NULL;
}
Esempio n. 4
0
void
TextChange(
        Widget text,
        XtPointer client_data,
        XmTextVerifyCallbackStruct * callback_data )
{
   char *homeDir, *homeDirBackup;
   char *selection;

   if (callback_data->reason == XmCR_MODIFYING_TEXT_VALUE ||
       callback_data->reason == XmCR_MOVING_INSERT_CURSOR )
   {
      FileMgrData * file_mgr_data;

      file_mgr_data = (FileMgrData *) client_data;

      selection = XmTextFieldGetSelection(text);

      /* get whats in the text widget */
      homeDir = homeDirBackup = XmTextFieldGetString(text);

      if(selection != NULL)
      {
         if(callback_data->event == NULL)
            XmTextFieldClearSelection(text, CurrentTime);
         else
            XmTextFieldClearSelection(text, callback_data->event->xkey.time);
         callback_data->doit = False;
      }
      else if(callback_data->reason == XmCR_MODIFYING_TEXT_VALUE)
      {
         /* see if the user is trying to back over the 'restricted'
          * text, in this case users_home_dir
          */
         if( strcmp( homeDir, "" ) != 0
             && strcmp( homeDir, file_mgr_data->restricted_directory ) <= 0 )
         {
            if( callback_data->text->length != 0 )
            {
               if( strncmp( file_mgr_data->restricted_directory,
                            callback_data->text->ptr,
                            strlen(file_mgr_data->restricted_directory)) != 0)
               {
                  callback_data->doit = True;
               }
            }
            else
            {
               callback_data->doit = False;
            }
         }
      }
      else
      {
         int maxlength;

         maxlength = strlen( file_mgr_data->restricted_directory );

         if(callback_data->newInsert < maxlength)
         {
            if(callback_data->event == NULL)
               _XmTextFieldSetDestination((Widget)text,
                            (Position)callback_data->currInsert, CurrentTime);
            else
            {
               _XmTextFieldSetDestination((Widget)text,
                                          (Position)callback_data->currInsert,
                                          callback_data->event->xkey.time);
               callback_data->doit = False;
            }
         }
      }

      XtFree(homeDirBackup);
      XtFree(selection);
   }
}