예제 #1
0
static char* motTextGetSelectionAttrib(Ihandle* ih)
{
  XmTextPosition start = 0, end = 0;
  char* str;

  if (!XmTextGetSelectionPosition(ih->handle, &start, &end) || start==end)
    return NULL;

  str = iupStrGetMemory(100);

  /* end is inside the selection, in IUP is outside */
  end++;

  if (ih->data->is_multiline)
  {
    int start_col, start_lin, end_col, end_lin;

    char *value = XmTextGetString(ih->handle);
    motTextGetLinColFromPosition(value, start, &start_lin, &start_col);
    motTextGetLinColFromPosition(value, end,   &end_lin,   &end_col);
    XtFree(value);

    sprintf(str,"%d,%d:%d,%d", start_lin, start_col, end_lin, end_col);
  }
  else
  {
    start++; /* IUP starts at 1 */
    end++;
    sprintf(str, "%d:%d", (int)start, (int)end);
  }

  return str;
}
예제 #2
0
static char* motTextGetSelectionAttrib(Ihandle* ih)
{
  XmTextPosition start = 0, end = 0;

  if (!XmTextGetSelectionPosition(ih->handle, &start, &end) || start==end)
    return NULL;

  if (ih->data->is_multiline)
  {
    int start_col, start_lin, end_col, end_lin;

    char *value = XmTextGetString(ih->handle);
    motTextGetLinColFromPosition(value, start, &start_lin, &start_col);
    motTextGetLinColFromPosition(value, end,   &end_lin,   &end_col);
    XtFree(value);

    return iupStrReturnStrf("%d,%d:%d,%d", start_lin, start_col, end_lin, end_col);
  }
  else
  {
    start++; /* IUP starts at 1 */
    end++;
    return iupStrReturnIntInt((int)start, (int)end, ':');
  }
}
예제 #3
0
static void motTextMotionVerifyCallback(Widget w, Ihandle* ih, XmTextVerifyCallbackStruct* textverify)
{
  int col, lin, pos;

  IFniii cb = (IFniii)IupGetCallback(ih, "CARET_CB");
  if (!cb) return;

  pos = textverify->newInsert;

  if (ih->data->is_multiline)
  {
    char *value = XmTextGetString(ih->handle);
    motTextGetLinColFromPosition(value, pos, &lin, &col);
    XtFree(value);
  }
  else
  {
    col = pos;
    col++; /* IUP starts at 1 */
    lin = 1;
  }

  if (pos != ih->data->last_caret_pos)
  {
    ih->data->last_caret_pos = pos;
    cb(ih, lin, col, pos);
  }

  (void)w;
}
예제 #4
0
static char* motTextGetLineValueAttrib(Ihandle* ih)
{
  if (ih->data->is_multiline)
  {
    int lin, col, start, end;
    char* str = iupStrGetMemory(200);
    char *value = XmTextGetString(ih->handle);
    XmTextPosition pos = XmTextGetInsertionPosition(ih->handle);
    motTextGetLinColFromPosition(value, pos, &lin, &col);
    start = motTextSetLinColToPosition(value, lin, 1);
    end = motTextSetLinColToPosition(value, lin, 20000);
    XtFree(value);
    XmTextGetSubstring(ih->handle, start, end-start, 200, str);  /* do not include the EOL */
    return str;
  }
  else
    return motTextGetValueAttrib(ih);
}
예제 #5
0
static char* motTextGetCaretAttrib(Ihandle* ih)
{
  XmTextPosition pos = XmTextGetInsertionPosition(ih->handle);

  if (ih->data->is_multiline)
  {
    int col, lin;

    char *value = XmTextGetString(ih->handle);
    motTextGetLinColFromPosition(value, pos, &lin, &col);
    XtFree(value);

    return iupStrReturnIntInt(lin, col, ',');
  }
  else
  {
    pos++; /* IUP starts at 1 */
    return iupStrReturnInt((int)pos);
  }
}
예제 #6
0
static char* motTextGetCaretAttrib(Ihandle* ih)
{
  char* str = iupStrGetMemory(50);

  XmTextPosition pos = XmTextGetInsertionPosition(ih->handle);

  if (ih->data->is_multiline)
  {
    int col, lin;

    char *value = XmTextGetString(ih->handle);
    motTextGetLinColFromPosition(value, pos, &lin, &col);
    XtFree(value);

    sprintf(str, "%d,%d", lin, col);
  }
  else
  {
    pos++; /* IUP starts at 1 */
    sprintf(str, "%d", (int)pos);
  }

  return str;
}
예제 #7
0
void iupdrvTextConvertPosToLinCol(Ihandle* ih, int pos, int *lin, int *col)
{
  char *str = XmTextGetString(ih->handle);
  motTextGetLinColFromPosition(str, pos, lin, col);
  XtFree(str);
}