//--------------------------------------------------------------------------- #ifndef LineEditH #define LineEditH //--------------------------------------------------------------------------- #include //--------------------------------------------------------------------------- class PACKAGE TLineEdit : public TWinControl { private: TEditCharCase FCharCase; TColor FBorderColor, // 边框颜色 FShadowColor; // 阴影颜色 TAlignment FAlignment; WideChar FPasswordChar; String FText; String FHintText; TColor FHintColor; bool FHideSelection, FNumbersOnly, FOEMConvert, FReadOnly; int FMaxLength, FNumberMax, FNumberMin; TNotifyEvent FOnChange; TControlCanvas *m_Canvas; int m_ShadowColorArray[4]; // 阴影颜色数组 int m_FontHeight; // 备份字体高度 bool m_IsCreated; TLabel *m_HintLabel; TColor m_FontColor; // 备份字体颜色 TRect m_TextRect; WCHAR m_TextBuf[512]; void __fastcall AdjustThisSize(); int __fastcall CalcColorValue(TColor BgColor, TColor FrColor, int Level, int Alpha); int __fastcall CalcFontHeight(); void __fastcall CreateShadowColor(); // 创建阴影颜色 void __fastcall SetBorderColor(TColor Color); void __fastcall SetOnChange(TNotifyEvent OnChange); void __fastcall SetShadowColor(TColor Color); void __fastcall ShowHintText(); /******************************************************************************/ // 编辑框操作 /******************************************************************************/ void __fastcall DoHintLabelMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y); UnicodeString __fastcall GetText(); bool __fastcall GetCanUndo(); int __fastcall GetSelLength(); int __fastcall GetSelStart(); String __fastcall GetSelText(); void __fastcall SetAlignment(TAlignment Value); void __fastcall SetCharCase(TEditCharCase Value); void __fastcall SetHideSelection(bool Value); void __fastcall SetHintText(String Value); void __fastcall SetHintColor(TColor Value); void __fastcall SetNumbersOnly(bool Value); void __fastcall SetOEMConvert(bool Value); void __fastcall SetPasswordChar(WideChar Value); void __fastcall SetReadOnly(bool Value); void __fastcall SetText(UnicodeString Value); void __fastcall SetMaxLength(int Value); void __fastcall SetSelLength(int Value); void __fastcall SetSelStart(int Value); void __fastcall SetNumberMax(int Value); void __fastcall SetNumberMin(int Value); /******************************************************************************/ MESSAGE void __fastcall CMColorChanged(TMessage &Message); MESSAGE void __fastcall CMFontChanged(TWMFontChange &Message); MESSAGE void __fastcall WMChar(TWMChar &Message); MESSAGE void __fastcall WMCommand(TWMCommand &Message); MESSAGE void __fastcall WMCtlColorEdit(TWMCtlColorEdit &Message); MESSAGE void __fastcall WMCtlColorStatic(TWMCtlColorStatic &Message); MESSAGE void __fastcall WMEraseBkgnd(TWMEraseBkgnd &Message); MESSAGE void __fastcall WMKeyDown(TWMKeyDown &Message); MESSAGE void __fastcall WMKillFocus(TWMKillFocus &Message); MESSAGE void __fastcall WMPaint(TWMPaint &Message); MESSAGE void __fastcall WMSetFocus(TWMSetFocus &Message); MESSAGE void __fastcall WMSize(TWMSize &Message); BEGIN_MESSAGE_MAP MESSAGE_HANDLER(CM_COLORCHANGED, TMessage, CMColorChanged) MESSAGE_HANDLER(CM_FONTCHANGED, TWMFontChange, CMFontChanged) MESSAGE_HANDLER(CN_COMMAND, TWMCommand, WMCommand) MESSAGE_HANDLER(CN_CTLCOLOREDIT, TWMCtlColorEdit, WMCtlColorEdit) MESSAGE_HANDLER(CN_CTLCOLORSTATIC, TWMCtlColorStatic, WMCtlColorStatic) MESSAGE_HANDLER(WM_CHAR, TWMChar, WMChar) MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd) MESSAGE_HANDLER(WM_KEYDOWN, TWMKeyDown, WMKeyDown) MESSAGE_HANDLER(WM_KILLFOCUS, TWMKillFocus, WMKillFocus) MESSAGE_HANDLER(WM_PAINT, TWMPaint, WMPaint) MESSAGE_HANDLER(WM_SETFOCUS, TWMSetFocus, WMSetFocus) MESSAGE_HANDLER(WM_SIZE, TWMSize, WMSize) END_MESSAGE_MAP(TWinControl) __property Hint; protected: virtual void __fastcall CreateParams(TCreateParams &Params); virtual void __fastcall CreateWindowHandle(const TCreateParams &Params); virtual void __fastcall CreateWnd(); public: __fastcall TLineEdit(TComponent* Owner); __fastcall ~TLineEdit(); void __fastcall SetFocus(); void __fastcall SetCursorPos(int Pos); void __fastcall SetTextFont(String name, int size); /******************************************************************************/ // 编辑框操作 /******************************************************************************/ void __fastcall Clear(); void __fastcall ClearSelection(); void __fastcall CopyToClipboard(); void __fastcall CutToClipboard(); void __fastcall PasteFromClipboard(); void __fastcall Undo(); void __fastcall ClearUndo(); void __fastcall SelectAll(); __property bool CanUndo = {read = GetCanUndo, nodefault}; __property int SelLength = {read = GetSelLength, write = SetSelLength, nodefault}; __property int SelStart = {read = GetSelStart, write = SetSelStart, nodefault}; __property String SelText = {read = GetSelText}; __property AlignWithMargins = {default = false}; __property HelpContext; __property HelpKeyword; __property HelpType; __property Margins; __property Cursor; /******************************************************************************/ __published: __property TColor BorderColor = {read = FBorderColor, write = SetBorderColor, default = TColor(0x5F5954)}; __property TColor ShadowColor = {read = FShadowColor, write = SetShadowColor, default = TColor(0x4C463F)}; __property TNotifyEvent OnChange = {read = FOnChange, write = SetOnChange}; __property TAlignment Alignment = {read = FAlignment, write = SetAlignment}; __property TEditCharCase CharCase = {read = FCharCase, write = SetCharCase}; __property bool HideSelection = {read = FHideSelection, write = SetHideSelection}; __property String HintText = {read = FHintText, write = SetHintText}; __property TColor HintColor = {read = FHintColor, write = SetHintColor, default = TColor(0x594D43)}; __property int MaxLength = {read = FMaxLength, write = SetMaxLength, default = 500}; __property bool NumbersOnly = {read = FNumbersOnly, write = SetNumbersOnly}; __property bool OEMConvert = {read = FOEMConvert, write = SetOEMConvert}; __property WideChar PasswordChar = {read = FPasswordChar, write = SetPasswordChar}; __property bool ReadOnly = {read = FReadOnly, write = SetReadOnly}; __property int NumberMax = {read = FNumberMax, write = SetNumberMax}; __property int NumberMin = {read = FNumberMin, write = SetNumberMin}; __property UnicodeString Text = {read = GetText, write = SetText}; __property Color = {default = TColor(0xC4B4A8)}; __property Font; __property TabOrder = {default = -1}; __property TabStop = {default = true}; __property OnKeyDown; __property OnKeyPress; __property OnKeyUp; }; //--------------------------------------------------------------------------- #endif