static void
test_editable_text (AccessibleEditableText *etext)
{
	char *str;
	AccessibleText *text;

	fprintf (stderr, "Testing editable text ...\n");
	
	g_assert (Accessible_isText (etext));
	text = Accessible_getText (etext);

	AccessibleEditableText_setTextContents (
		etext, TEST_STRING_B);

	str = AccessibleText_getText (text, 0, WHOLE_STRING);
	g_assert (!strcmp (str, TEST_STRING_B));

	SPI_freeString (str);

	/* FIXME: lots more editing here */

	AccessibleEditableText_setTextContents (
		etext, TEST_STRING_A);

	AccessibleText_unref (text);
}
示例#2
0
文件: screen.c 项目: Feechka/UOBP
static void restartTerm(Accessible *newTerm, AccessibleText *newTextTerm) {
  char *c,*d;
  const char *e;
  long i,len;
  char *text;

  if (curFocus)
    finiTerm();
  Accessible_ref(curFocus = newTerm);
  curTerm = newTextTerm;
  logMessage(LOG_DEBUG,"new term %p",curTerm);
  text = AccessibleText_getText(curTerm,0,LONG_MAX);
  curNumRows = 0;
  if (curRows) {
    for (i=0;i<curNumRows;i++)
      free(curRows[i]);
    free(curRows);
  }
  free(curRowLengths);
  c = text;
  while (*c) {
    curNumRows++;
    if (!(c = strchr(c,'\n')))
      break;
    c++;
  }
  logMessage(LOG_DEBUG,"%ld rows",curNumRows);
  curRows = malloc(curNumRows * sizeof(*curRows));
  curRowLengths = malloc(curNumRows * sizeof(*curRowLengths));
  i = 0;
  curNumCols = 0;
  for (c = text; *c; c = d+1) {
    d = strchr(c,'\n');
    if (d)
      *d = 0;
    e = c;
    curRowLengths[i] = (len = my_mbsrtowcs(NULL,&e,0,NULL)) + (d != NULL);
    if (len > curNumCols)
      curNumCols = len;
    else if (len < 0) {
      if (len==-2)
	logMessage(LOG_ERR,"unterminated sequence %s",c);
      else if (len==-1)
	logSystemError("mbrlen");
      curRowLengths[i] = (len = -1) + (d != NULL);
    }
    curRows[i] = malloc((len + (d!=NULL)) * sizeof(*curRows[i]));
    e = c;
    my_mbsrtowcs(curRows[i],&e,len,NULL);
    if (d)
      curRows[i][len]='\n';
    else
      break;
    i++;
  }
  logMessage(LOG_DEBUG,"%ld cols",curNumCols);
  SPI_freeString(text);
  caretPosition(AccessibleText_getCaretOffset(curTerm));
}
static void
test_text (AccessibleText *text)
{
	char *str;

	fprintf (stderr, "Testing text ...\n");

	g_assert (AccessibleText_getCharacterCount (text) ==
		  strlen (TEST_STRING_A));

	str = AccessibleText_getText (text, 0, WHOLE_STRING);
	g_assert (!strcmp (str, TEST_STRING_A));
	SPI_freeString (str);

	str = AccessibleText_getText (text, 0, 5);
	g_assert (!strncmp (str, TEST_STRING_A, 5));
	SPI_freeString (str);

	AccessibleText_setCaretOffset (text, 7);
	g_assert (AccessibleText_getCaretOffset (text) == 7);

	/* FIXME: lots more tests - selections etc. etc. */
}
char * windows_text ( SQByteArray * _pointer )
{
   char * text = NULL;
   Accessible * accessibleObject = windows_to_accessible(_pointer);
   if ( Accessible_isText(accessibleObject) == SPI_TRUE )
   {
       AccessibleText * textObj = Accessible_getText(accessibleObject);
       long count = AccessibleText_getCharacterCount ( textObj );
       text = AccessibleText_getText ( textObj, 0, count );
       AccessibleText_unref ( textObj );
       return windows_string(text);
   }
   else if ( Accessible_isValue(accessibleObject) == SPI_TRUE )
   {
       AccessibleValue * valueObj = Accessible_getValue(accessibleObject);

       double current = AccessibleValue_getCurrentValue ( valueObj );
       text = malloc(SQ_MAX_VALUE_LENGTH);
       SNPRINTF_FUNCTION ( text, SQ_MAX_VALUE_LENGTH, "%f", current );
       return text;
   }
   return SQ_STRDUP_FUNCTION("");
}