示例#1
0
文件: GUI__Wrap.c 项目: silview/C100A
/*********************************************************************
*
*       GUI__WrapGetNumCharsToNextLine
*/
int GUI__WrapGetNumCharsToNextLine(const char GUI_UNI_PTR * pText, int xSize, GUI_WRAPMODE WrapMode) 
{
    int NumChars;
    U16 Char;
    
    NumChars = GUI__WrapGetNumCharsDisp(pText, xSize, WrapMode);
    pText   += GUI_UC__NumChars2NumBytes(pText, NumChars);
    Char     = GUI_UC__GetCharCodeInc(&pText);
    if (Char == '\n') 
    {
        NumChars++;
    }
	else if(Char == '\r')  //modified by Derek 2010.12.02.10:07
	{
		NumChars++;
		Char = GUI_UC__GetCharCodeInc(&pText);

		if(Char == '\n')
		{
			NumChars++;
		}
	}
    else 
    {
        if (WrapMode == GUI_WRAPMODE_WORD) 
		{
      		while (Char == ' ') 
			{
        		NumChars++;
        		Char = GUI_UC__GetCharCodeInc(&pText);
      		}
    	}
    } //end modified
    return NumChars;
}
示例#2
0
/*********************************************************************
*
*       EDIT_SetMaxLen
*/
void EDIT_SetMaxLen(EDIT_Handle  hObj, int MaxLen) {
  if (hObj) {
    EDIT_Obj* pObj;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    if (MaxLen != pObj->MaxLen) {
      if (MaxLen < pObj->MaxLen) {
        if (pObj->hpText) {
          char* pText;
          int   NumChars;
          pText    = (char*) GUI_ALLOC_h2p(pObj->hpText);
          NumChars = GUI__GetNumChars(pText);
          if (NumChars > MaxLen) {
            int NumBytes;
            NumBytes = GUI_UC__NumChars2NumBytes(pText, MaxLen);
            *(pText + NumBytes) = 0;
          }
        }
      }
      _IncrementBuffer(pObj, MaxLen - pObj->BufferSize + 1);
      pObj->MaxLen = MaxLen;
      EDIT_Invalidate(hObj);
    }
    WM_UNLOCK();
  }
}
示例#3
0
文件: GUI__Wrap.c 项目: silview/C100A
/*********************************************************************
*
*       GUI__WrapGetNumBytesToNextLine
*/
int GUI__WrapGetNumBytesToNextLine(const char GUI_UNI_PTR * pText, int xSize, GUI_WRAPMODE WrapMode) 
{
    int NumChars, NumBytes;

    NumChars = GUI__WrapGetNumCharsToNextLine(pText, xSize, WrapMode);
    NumBytes = GUI_UC__NumChars2NumBytes(pText, NumChars);

    return NumBytes;
}
示例#4
0
/*********************************************************************
*
*       GUI_DispString
*/
void GUI_DispString(const char GUI_UNI_PTR *s) {

  int xAdjust, yAdjust, xOrg;
  int FontSizeY;
  if (!s)
    return;
  GUI_LOCK();
  FontSizeY = GUI_GetFontDistY();
  xOrg = GUI_Context.DispPosX;
 /* Adjust vertical position */
  yAdjust = GUI_GetYAdjust();
  GUI_Context.DispPosY -= yAdjust;
  for (; *s; s++) {

    GUI_RECT r;

    int LineNumChars = GUI__GetLineNumChars(s, 0x7fff);

    int xLineSize    = GUI__GetLineDistX(s, LineNumChars);


  /* Check if x-position needs to be changed due to h-alignment */
    switch (GUI_Context.TextAlign & GUI_TA_HORIZONTAL) {
      case GUI_TA_CENTER: xAdjust = xLineSize / 2; break;
      case GUI_TA_RIGHT:  xAdjust = xLineSize; break;
      default:            xAdjust = 0;
    }
    r.x0 = GUI_Context.DispPosX -= xAdjust;
    r.x1 = r.x0 + xLineSize - 1;
    r.y0 = GUI_Context.DispPosY;
    r.y1 = r.y0 + FontSizeY - 1;

    GUI__DispLine(s, LineNumChars, &r);
    GUI_Context.DispPosY = r.y0;
    s += GUI_UC__NumChars2NumBytes(s, LineNumChars);
    if ((*s == '\n') || (*s == '\r')) {
      switch (GUI_Context.TextAlign & GUI_TA_HORIZONTAL) {
      case GUI_TA_CENTER:
      case GUI_TA_RIGHT:
        GUI_Context.DispPosX = xOrg;
        break;
      default:
        GUI_Context.DispPosX = GUI_Context.LBorder;
        break;
      }
      if (*s == '\n')
        GUI_Context.DispPosY += FontSizeY;
    } else {
      GUI_Context.DispPosX = r.x0 + xLineSize;
    }
    if (*s == 0)    /* end of string (last line) reached ? */
      break;
  }
  GUI_Context.DispPosY += yAdjust;
  GUI_Context.TextAlign &= ~GUI_TA_HORIZONTAL;
  GUI_UNLOCK();
}
示例#5
0
/*********************************************************************
*
*       EDIT__GetCurrentChar
*/
U16 EDIT__GetCurrentChar(EDIT_Obj* pObj) {
  U16 Char = 0;
  if (pObj->hpText) {
    const char* pText;
    pText  = (const char*) GUI_ALLOC_h2p(pObj->hpText);
    pText += GUI_UC__NumChars2NumBytes(pText, pObj->CursorPos);
    Char   = GUI_UC_GetCharCode(pText);
  }
  return Char;
}
示例#6
0
/*********************************************************************
*
*       _DeleteChar
*
* Deletes a character at the current cursor position and moves
* all bytes after the cursor position.
*/
static void _DeleteChar(EDIT_Handle hObj, EDIT_Obj* pObj) {
  if (pObj->hpText) {
    unsigned CursorOffset;
    char* pText;
    pText = (char*) GUI_ALLOC_h2p(pObj->hpText);
    CursorOffset = GUI_UC__NumChars2NumBytes(pText, pObj->CursorPos);
    if (CursorOffset < strlen(pText)) {
      int NumBytes;
      pText += CursorOffset;
      NumBytes = GUI_UC_GetCharSize(pText);
      strcpy(pText, pText + NumBytes);
      WM_NotifyParent(hObj, WM_NOTIFICATION_VALUE_CHANGED);
    }
  }
}
示例#7
0
/*********************************************************************
*
*       _InsertChar
*
* Create space at the current cursor position and inserts a character.
*/
static int _InsertChar(EDIT_Handle hObj, EDIT_Obj* pObj, U16 Char) {
  if (_IsCharsAvailable(pObj, 1)) {
    int BytesNeeded;
    BytesNeeded = GUI_UC__CalcSizeOfChar(Char);
    if (_IsSpaceInBuffer(pObj, BytesNeeded)) {
      int CursorOffset;
      char* pText;
      pText = (char*) GUI_ALLOC_h2p(pObj->hpText);
      CursorOffset = GUI_UC__NumChars2NumBytes(pText, pObj->CursorPos);
      pText += CursorOffset;
      memmove(pText + BytesNeeded, pText, strlen(pText) + 1);
      GUI_UC_Encode(pText, Char);
      WM_NotifyParent(hObj, WM_NOTIFICATION_VALUE_CHANGED);
      return 1;
    }
  }
  return 0;
}
示例#8
0
/*********************************************************************
*
*       EDIT_SetText
*/
void EDIT_SetText(EDIT_Handle hObj, const char* s) {
  if (hObj) {
    EDIT_Obj* pObj;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    if (s) {
      int NumBytesNew, NumBytesOld = 0;
      int NumCharsNew;
      if (pObj->hpText) {
        char* pText;
        pText       = (char*) GUI_ALLOC_h2p(pObj->hpText);
        NumBytesOld = strlen(pText) + 1;
      }
      NumCharsNew = GUI__GetNumChars(s);
      if (NumCharsNew > pObj->MaxLen) {
        NumCharsNew = pObj->MaxLen;
      }
      NumBytesNew = GUI_UC__NumChars2NumBytes(s, NumCharsNew) + 1;
      if (_IsSpaceInBuffer(pObj, NumBytesNew - NumBytesOld)) {
        char* pText;
        pText = (char*) GUI_ALLOC_h2p(pObj->hpText);
        memcpy(pText, s, NumBytesNew);
        pObj->CursorPos = NumCharsNew;
        if (pObj->CursorPos == pObj->MaxLen) {
          if (pObj->EditMode == GUI_EDIT_MODE_OVERWRITE) {
            pObj->CursorPos--;
          }
        }
      }
    } else {
      GUI_ALLOC_FreePtr(&pObj->hpText);
      pObj->BufferSize = 0;
      pObj->CursorPos  = 0;
    }
    EDIT_Invalidate(hObj);
    WM_UNLOCK();
  }
}
示例#9
0
/*********************************************************************
*
*       EDIT_GetText
*/
void EDIT_GetText(EDIT_Handle hObj, char* sDest, int MaxLen) {
  if (sDest) {
    *sDest = 0;
    if (hObj) {
      EDIT_Obj* pObj;
      WM_LOCK();
      pObj = EDIT_H2P(hObj);
      if (pObj->hpText) {
        char* pText;
        int NumChars, NumBytes;
        pText = (char*) GUI_ALLOC_h2p(pObj->hpText);
        NumChars = GUI__GetNumChars(pText);
        if (NumChars > MaxLen) {
          NumChars = MaxLen;
        }
        NumBytes = GUI_UC__NumChars2NumBytes(pText, NumChars);
        memcpy(sDest, pText, NumBytes);
        *(sDest + NumBytes) = 0;
      }
      WM_UNLOCK();
    }
  }
}
示例#10
0
/*********************************************************************
*
*       GUI__DispStringInRect
*/
void GUI__DispStringInRect(const char GUI_UNI_PTR *s, GUI_RECT* pRect, int TextAlign, int MaxNumChars) {
  GUI_RECT r;
  GUI_RECT rLine;
  int y = 0;
  const char GUI_UNI_PTR *sOrg =s;
  int FontYSize;
  int xLine = 0;
  int LineLen;
  int NumCharsRem;           /* Number of remaining characters */
  FontYSize = GUI_GetFontSizeY();
  if (pRect) {
    r = *pRect;
  } else {
    GUI_GetClientRect(&r);
  }
  /* handle vertical alignment */
  if ((TextAlign & GUI_TA_VERTICAL) == GUI_TA_TOP) {
		y = r.y0;
  } else {
    int NumLines;
    /* Count the number of lines */
    for (NumCharsRem = MaxNumChars, NumLines = 1; NumCharsRem ;NumLines++) {
        LineLen = GUI__GetLineNumChars(s, NumCharsRem);
        if(LineLen == 0)
        {
            break;
        }
      NumCharsRem -= LineLen;
      s += GUI_UC__NumChars2NumBytes(s, LineLen);
      if (GUI__HandleEOLine(&s))
        break;
    }
    /* Do the vertical alignment */
    switch (TextAlign & GUI_TA_VERTICAL) {
	  case GUI_TA_BASELINE:
	  case GUI_TA_BOTTOM:
	  y = r.y1 -NumLines * FontYSize+1;
      break;
	  case GUI_TA_VCENTER:
		  y = r.y0+(r.y1-r.y0+1 -NumLines * FontYSize) /2;
      break;
	  }
  }
  /* Output string */
  for (NumCharsRem = MaxNumChars, s = sOrg; NumCharsRem;) {
    int xLineSize;
    LineLen = GUI__GetLineNumChars(s, NumCharsRem);
    if(LineLen == 0)
    {
        break;
    }
    NumCharsRem -= LineLen;
    xLineSize = GUI__GetLineDistX(s, LineLen);
    switch (TextAlign & GUI_TA_HORIZONTAL) {
    case GUI_TA_HCENTER:
      xLine = r.x0+(r.x1-r.x0-xLineSize)/2; break;
    case GUI_TA_LEFT:
      xLine = r.x0; break;
    case GUI_TA_RIGHT:
      xLine = r.x1 -xLineSize + 1;
    }
    rLine.x0 = GUI_Context.DispPosX[GUI_Context.SelLayer] = xLine;
    rLine.x1 = rLine.x0 + xLineSize-1;
    rLine.y0 = GUI_Context.DispPosY[GUI_Context.SelLayer] = y;
    rLine.y1 = y + FontYSize-1;
    GUI__DispLine(s, LineLen, &rLine);
    s += GUI_UC__NumChars2NumBytes(s, LineLen);
    y += GUI_GetFontDistY();
    if (GUI__HandleEOLine(&s))
      break;
  }
}
示例#11
0
/*********************************************************************
*
*       EDIT_AddKey
*/
void EDIT_AddKey(EDIT_Handle hObj, int Key) {
  if (hObj) {
    EDIT_Obj* pObj;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    if (pObj) {
      if (pObj->pfAddKeyEx) {
        pObj->pfAddKeyEx(hObj, Key);
      } else {
        switch (Key) {
        case GUI_KEY_UP:
          if (pObj->hpText) {
            char* pText;
            U16 Char;
            pText  = (char*) GUI_ALLOC_h2p(pObj->hpText);
            pText += GUI_UC__NumChars2NumBytes(pText, pObj->CursorPos);
            Char   = GUI_UC_GetCharCode(pText);
            if (Char < 0x7f) {  
              *pText = Char + 1;
              WM_NotifyParent(hObj, WM_NOTIFICATION_VALUE_CHANGED);
            }
          }
          break;
        case GUI_KEY_DOWN:
          if (pObj->hpText) {
            char* pText;
            U16 Char;
            pText  = (char*) GUI_ALLOC_h2p(pObj->hpText);
            pText += GUI_UC__NumChars2NumBytes(pText, pObj->CursorPos);
            Char   = GUI_UC_GetCharCode(pText);
            if (Char > 0x20) {  
              *pText = Char - 1;
              WM_NotifyParent(hObj, WM_NOTIFICATION_VALUE_CHANGED);
            }
          }
          break;
        case GUI_KEY_RIGHT:
          EDIT__SetCursorPos(pObj, pObj->CursorPos + 1);
          break;
        case GUI_KEY_LEFT:
          EDIT__SetCursorPos(pObj, pObj->CursorPos - 1);
          break;
        case GUI_KEY_BACKSPACE:
          EDIT__SetCursorPos(pObj, pObj->CursorPos - 1);
          _DeleteChar(hObj, pObj);
          break;
        case GUI_KEY_DELETE:
          _DeleteChar(hObj, pObj);
          break;
        case GUI_KEY_INSERT:
          if (pObj->EditMode == GUI_EDIT_MODE_OVERWRITE) {
            pObj->EditMode = GUI_EDIT_MODE_INSERT;
          } else {
            pObj->EditMode = GUI_EDIT_MODE_OVERWRITE;
            EDIT__SetCursorPos(pObj, pObj->CursorPos);
          }
          break;
        default:
          if (Key >= 0x20) {
            if (pObj->EditMode != GUI_EDIT_MODE_INSERT) {
              _DeleteChar(hObj, pObj);
            }
            if (_InsertChar(hObj, pObj, Key)) {
              EDIT__SetCursorPos(pObj, pObj->CursorPos + 1);
            }
          }
        }
      }
      EDIT_Invalidate(hObj);
    }
    WM_UNLOCK();
  }
}