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();
  }
}
/*********************************************************************
*
*       EDIT_SetCursorAtChar
*/
void EDIT_SetCursorAtChar(EDIT_Handle hObj, int Pos) {
  if (hObj) {
    EDIT_Obj* pObj;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    EDIT__SetCursorPos(pObj, Pos);
    EDIT_Invalidate(hObj);
    WM_UNLOCK();
  }
}
Beispiel #3
0
void EDIT_SetTextAlign(EDIT_Handle hObj, int Align) {
    EDIT_Obj* pObj;
    if (hObj == 0)
        return;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    if (pObj) {
        pObj->Align = Align;
        EDIT_Invalidate(hObj);
    }
    WM_UNLOCK();
}
Beispiel #4
0
void EDIT_SetTextColor(EDIT_Handle hObj, int Index, GUI_COLOR color) {
    EDIT_Obj* pObj;
    if (hObj == 0)
        return;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    if (pObj) {
        pObj->aTextColor[Index] = color;
        EDIT_Invalidate(hObj);
    }
    WM_UNLOCK();
}
Beispiel #5
0
void EDIT_SetFont(EDIT_Handle hObj, const GUI_FONT* pfont) {
    EDIT_Obj* pObj;
    if (hObj == 0)
        return;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    if (pObj) {
        pObj->pFont = pfont;
        EDIT_Invalidate(hObj);
    }
    WM_UNLOCK();
}
Beispiel #6
0
/*********************************************************************
*
*       EDIT_SetTextColor
*/
void EDIT_SetTextColor(EDIT_Handle hObj, unsigned int Index, GUI_COLOR color) {
  EDIT_Obj* pObj;
  if (hObj == 0)
    return;
  WM_LOCK();
  pObj = EDIT_H2P(hObj);
  if (pObj) {
    if (Index < GUI_COUNTOF(pObj->Props.aTextColor)) {
      pObj->Props.aTextColor[Index] = color;
      EDIT_Invalidate(hObj);
    }
  }
  WM_UNLOCK();
}
Beispiel #7
0
void EDIT_SetMaxLen(EDIT_Handle  hObj, int MaxLen) {
    EDIT_Obj* pObj;
    WM_HMEM hpText;
    if (hObj) {
        WM_LOCK();
        pObj = EDIT_H2P(hObj);
        if ((hpText = WM_ALLOC(MaxLen+1)) ==0) {
            GUI_DEBUG_ERROROUT("EDIT_SetMaxLen failed to alloc buffer");
        } else {
            WM_FREEPTR(&pObj->hpText);
            pObj->hpText = hpText;
            pObj->MaxLen = MaxLen;
        }
        EDIT_Invalidate(hObj);
        WM_UNLOCK();
    }
}
Beispiel #8
0
void EDIT_SetText     (EDIT_Handle hObj, const char* sNew) {
    EDIT_Obj* pObj;
    if (hObj == 0)
        return;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    if (pObj) {
        char*sDest = (char*) WM_HMEM2Ptr(pObj->hpText);
        int Len = sNew ? (int)strlen(sNew) : 0;
        if (Len > pObj->MaxLen)
            Len = pObj->MaxLen;
        memcpy(sDest, sNew, Len);
        *(sDest+Len) = 0;
        pObj->CursorPos = Len;
        if (pObj->CursorPos == pObj->MaxLen)
            pObj->CursorPos--;
        EDIT_Invalidate(hObj);
    }
    WM_UNLOCK();
}
Beispiel #9
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();
  }
}
Beispiel #10
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();
  }
}
Beispiel #11
0
/*********************************************************************
*
*       _SetCursor
*/
static void _SetCursor(EDIT_Handle hObj, EDIT_Obj* pObj, int x) {
    int xPos, xSize, PixelLen, Len;
    char * s = (char*) WM_HMEM2Ptr(pObj->hpText);
    const GUI_FONT *pOldFont = GUI_SetFont(pObj->pFont);
    xSize = WM_GetWindowSizeX(hObj);
    PixelLen = GUI_GetStringDistX(s);
    xPos = x;
    switch (pObj->Align & GUI_TA_HORIZONTAL) {
    case GUI_TA_CENTER:
        xPos -= (xSize - PixelLen + 1) / 2;
        break;
    case GUI_TA_LEFT:
        xPos -= (pObj->Border + EDIT_XOFF);
        break;
    case GUI_TA_RIGHT:
        xPos -= xSize - PixelLen - (pObj->Border + EDIT_XOFF);
        break;
    }
    Len = (int)strlen(s);
    if (xPos < 0) {
        pObj->CursorPos = 0;
    } else if (xPos > PixelLen) {
        pObj->CursorPos = Len;
    } else {
        int i, x;
        for (i = 0, x = 0; (i < Len) && (x < xPos); i++) {
            int xLenChar = GUI_GetCharDistX(*(s + i));
            if (xPos < (x + xLenChar))
                break;
            x += xLenChar;
        }
        pObj->CursorPos = i;
        EDIT_Invalidate(hObj);
    }
    GUI_SetFont(pOldFont);
}
Beispiel #12
0
void EDIT_AddKey(EDIT_Handle hObj, int Key) {
    EDIT_Obj* pObj;
    if (hObj == 0)
        return;
    WM_LOCK();
    pObj = EDIT_H2P(hObj);
    if (pObj) {
        if (pObj->pfAddKeyEx) {
            pObj->pfAddKeyEx(pObj, hObj, Key);
        } else {
            char*s = (char*) WM_HMEM2Ptr(pObj->hpText);
            int len = (int)strlen(s);
            switch (Key) {
            case GUI_KEY_UP:
            {
                char c = *(s + pObj->CursorPos);
                if (c < 0x7f) {
                    *(s + pObj->CursorPos) = c + 1;
                    WM_NotifyParent(hObj, WM_NOTIFICATION_VALUE_CHANGED);
                }
            }
            break;
            case GUI_KEY_DOWN:
            {
                char c = *(s + pObj->CursorPos);
                if (c > 0x20) {
                    *(s + pObj->CursorPos) = c - 1;
                    WM_NotifyParent(hObj, WM_NOTIFICATION_VALUE_CHANGED);
                }
            }
            break;
            case GUI_KEY_RIGHT:
                if (pObj->CursorPos < (pObj->MaxLen - 1))
                    if (pObj->CursorPos < len)
                        pObj->CursorPos++;
                break;
            case GUI_KEY_LEFT:
                if (pObj->CursorPos > 0)
                    pObj->CursorPos--;
                break;
            case GUI_KEY_BACKSPACE:
                if ((len > 0) && (pObj->CursorPos > 0)) {
                    int CopyLength = pObj->MaxLen - pObj->CursorPos;
                    strncpy(s + pObj->CursorPos - 1, s + pObj->CursorPos, CopyLength);
                    *(s + len - 1) = 0;
                    WM_NotifyParent(hObj, WM_NOTIFICATION_VALUE_CHANGED);
                    pObj->CursorPos--;
                }
                break;
            case GUI_KEY_DELETE:
                if ((len > 0) && (pObj->CursorPos < len)) {
                    if (len > 1) {
                        int CopyLength = pObj->MaxLen - pObj->CursorPos - 1;
                        strncpy(s + pObj->CursorPos, s + pObj->CursorPos + 1, CopyLength);
                    }
                    *(s + len - 1) = 0;
                    WM_NotifyParent(hObj, WM_NOTIFICATION_VALUE_CHANGED);
                }
                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;
                break;
            case GUI_KEY_ENTER:
            case GUI_KEY_ESCAPE:
                break;
            default:
                if ((Key >= 0x20) && (Key <= 0x7f)) {
                    if (pObj->EditMode == GUI_EDIT_MODE_INSERT) {
                        if (len < pObj->MaxLen) {
                            int CopyLength = pObj->MaxLen - pObj->CursorPos - 1;
                            memmove(s + pObj->CursorPos + 1, s + pObj->CursorPos, CopyLength);
                            *(s + pObj->CursorPos) = Key;
                            WM_NotifyParent(hObj, WM_NOTIFICATION_VALUE_CHANGED);
                            if (pObj->CursorPos < (pObj->MaxLen - 1))
                                pObj->CursorPos++;
                        }
                    } else {
                        *(s + pObj->CursorPos) = Key;
                        WM_NotifyParent(hObj, WM_NOTIFICATION_VALUE_CHANGED);
                        if (pObj->CursorPos < (pObj->MaxLen - 1))
                            pObj->CursorPos++;
                    }
                }
                break;
            }
        }
        EDIT_Invalidate(hObj);
    }
    WM_UNLOCK();
}
Beispiel #13
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();
  }
}