Beispiel #1
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();
  }
}
Beispiel #2
0
/*********************************************************************
*
*       _IsCharsAvailable
*
* Checks weither the maximum number of characters is reached or not.
*
* Returns:
*  1 = requested number of chars is available
*  0 = maximum number of chars have reached
*/
static int _IsCharsAvailable(EDIT_Obj* pObj, int CharsNeeded) {
  if ((CharsNeeded > 0) && (pObj->MaxLen > 0)) {
    int NumChars = 0;
    if (pObj->hpText) {
      NumChars = GUI__GetNumChars((char*)GUI_ALLOC_h2p(pObj->hpText));
    }
    if ((CharsNeeded + NumChars) > pObj->MaxLen) {
      return 0;
    }
  }
  return 1;
}
/*********************************************************************
*
*       EDIT_GetNumChars
*/
int EDIT_GetNumChars(EDIT_Handle hObj) {
  int NumChars = 0;
  if (hObj) {
    EDIT_Obj* pObj;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    if (pObj->hpText) {
      char * pText;
      pText    = (char*) GUI_ALLOC_h2p(pObj->hpText);
      NumChars = GUI__GetNumChars(pText);
    }
    WM_UNLOCK();
  }
  return NumChars;
}
Beispiel #4
0
/*********************************************************************
*
*       EDIT__SetCursorPos
*
* Sets a new cursor position.
*/
void EDIT__SetCursorPos(EDIT_Obj* pObj, int CursorPos) {
  if (pObj->hpText) {
    char* pText;
    int NumChars, Offset;
    pText    = (char*) GUI_ALLOC_h2p(pObj->hpText);
    NumChars = GUI__GetNumChars(pText);
    Offset   = (pObj->EditMode == GUI_EDIT_MODE_INSERT) ? 0 : 1;
    if (CursorPos < 0) {
      CursorPos = 0;
    }
    if (CursorPos > NumChars) {
      CursorPos = NumChars;
    }
    if (CursorPos > (pObj->MaxLen - Offset)) {
      CursorPos = pObj->MaxLen - Offset;
    }
    if (pObj->CursorPos != CursorPos) {
      pObj->CursorPos = CursorPos;
    }
    pObj->SelSize = 0;
  }
}
Beispiel #5
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();
  }
}
/*********************************************************************
*
*       EDIT_GetCursorPixelPos
*/
void EDIT_GetCursorPixelPos(EDIT_Handle hObj, int * pxPos, int * pyPos) {
  if (hObj) {
    int NumChars;
    EDIT_Obj * pObj;
    const char GUI_UNI_PTR * pText;
    GUI_RECT rInside, rText;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    if (pObj->hpText) {
      GUI_SetFont(pObj->Props.pFont);
      WIDGET__GetInsideRect(&pObj->Widget, &rInside);
      pText       = (const char*) GUI_ALLOC_h2p(pObj->hpText);
      NumChars    = GUI__GetNumChars(pText);
      rInside.x0 += pObj->Props.Border + EDIT_XOFF;
      rInside.x1 -= pObj->Props.Border + EDIT_XOFF;
      GUI__CalcTextRect(pText, &rInside, &rText, pObj->Props.Align);
      rText.x0 += GUI__GetCursorPosX(pText, pObj->CursorPos, NumChars);
      *pxPos = rText.x0;
      *pyPos = rText.y0;
    }
    WM_UNLOCK();
  }
}
Beispiel #7
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();
    }
  }
}
Beispiel #8
0
/*********************************************************************
*
*       EDIT_SetCursorAtPixel
*/
void EDIT_SetCursorAtPixel(EDIT_Handle hObj, int xPos) {
  if (hObj) {
    EDIT_Obj* pObj;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    if (pObj->hpText) {    
      const GUI_FONT GUI_UNI_PTR *pOldFont;
      int xSize, TextWidth, NumChars;
      const char GUI_UNI_PTR * pText;
      pText = (char*) GUI_ALLOC_h2p(pObj->hpText);
      pOldFont = GUI_SetFont(pObj->Props.pFont);
      xSize = WM_GetWindowSizeX(hObj);
      TextWidth = GUI_GetStringDistX(pText);
      switch (pObj->Props.Align & GUI_TA_HORIZONTAL) {
      case GUI_TA_HCENTER:
        xPos -= (xSize - TextWidth + 1) / 2;
        break;
      case GUI_TA_RIGHT:
        xPos -= xSize - TextWidth - (pObj->Props.Border + EDIT_XOFF);
        break;
      default:
        xPos -= (pObj->Props.Border + EDIT_XOFF) + pObj->Widget.pEffect->EffectSize;
      }
      NumChars = GUI__GetNumChars(pText);
      if (xPos < 0) {
        EDIT__SetCursorPos(pObj, 0);
      } else if (xPos > TextWidth) {
        EDIT__SetCursorPos(pObj, NumChars);
      } else {
        EDIT__SetCursorPos(pObj, GUI__GetCursorPosChar(pText, xPos, NumChars));
      }
      GUI_SetFont(pOldFont);
      EDIT_Invalidate(hObj);
    }
    WM_UNLOCK();
  }
}
/*********************************************************************
*
*       GUI_GetStringDistX
*/
int GUI_GetStringDistX(const char GUI_UNI_PTR * s) {
  return GUI__GetLineDistX(s, GUI__GetNumChars(s));
}
Beispiel #10
0
/*********************************************************************
*
*       _Paint
*/
static void _Paint(EDIT_Obj* pObj, EDIT_Handle hObj) {
  GUI_RECT rFillRect, rInside, rText, rInvert;
  const char GUI_UNI_PTR * pText = NULL;
  int IsEnabled, CursorWidth = 0;
  IsEnabled = WM__IsEnabled(hObj);
  /* Set colors and font */
  LCD_SetBkColor(pObj->Props.aBkColor[IsEnabled]);
  LCD_SetColor(pObj->Props.aTextColor[0]);
  GUI_SetFont(pObj->Props.pFont);
  /* Calculate size */
  WIDGET__GetInsideRect(&pObj->Widget, &rFillRect);
  if (pObj->hpText) {
    pText = (const char*) GUI_ALLOC_h2p(pObj->hpText);
  }
  rInside = rFillRect;
  rInside.x0 += pObj->Props.Border + EDIT_XOFF;
  rInside.x1 -= pObj->Props.Border + EDIT_XOFF;
  GUI__CalcTextRect(pText, &rInside, &rText, pObj->Props.Align);
  /* Calculate position and size of cursor */
  if (pObj->Widget.State & WIDGET_STATE_FOCUS) {
    int NumChars;
    CursorWidth = ((pObj->XSizeCursor > 0) ? (pObj->XSizeCursor) : (1));
    NumChars    = GUI__GetNumChars(pText);
    if (pText) {
      U16 Char;
      int i, IsRTL = 0;
      if ((pObj->EditMode != GUI_EDIT_MODE_INSERT) || (pObj->SelSize)) {
        if (pObj->CursorPos < NumChars) {
          if (pObj->SelSize) {
            CursorWidth = 0;
            for (i = pObj->CursorPos; i < (int)(pObj->CursorPos + pObj->SelSize); i++) {
              Char = GUI__GetCursorCharacter(pText, i, NumChars, 0);
              CursorWidth += GUI_GetCharDistX(Char);
            }
            if (!CursorWidth) {
              CursorWidth = 1;
            }
          } else {
            Char = GUI__GetCursorCharacter(pText, pObj->CursorPos, NumChars, &IsRTL);
            CursorWidth = GUI_GetCharDistX(Char);
          }
        }
      }
      rInvert = rText;
      if (IsRTL) {
        rInvert.x0 -= CursorWidth;
      }
      rInvert.x0 += GUI__GetCursorPosX(pText, pObj->CursorPos, NumChars);
    }
  }
  /* WM loop */
  WM_ITERATE_START(NULL) {
    /* Set clipping rectangle */
    WM_SetUserClipRect(&rFillRect);
    /* Display text */
    WIDGET__FillStringInRect(pText, &rFillRect, &rInside, &rText);
    /* Display cursor if needed */
    if (pObj->Widget.State & WIDGET_STATE_FOCUS) {
      GUI_InvertRect(rInvert.x0, rInvert.y0, rInvert.x0 + CursorWidth - 1, rInvert.y1);
    }
    WM_SetUserClipRect(NULL);
    /* Draw the 3D effect (if configured) */
    WIDGET__EFFECT_DrawDown(&pObj->Widget);
  } WM_ITERATE_END();
}