日期:2011-08-23  浏览次数:21121 次

公司采用Seskin控件包来开发。却发现SeskinEdit在使用汉字是有问题。主要是由汉字时光标定位不准。鼠标选字也选不准。
于是看了其代码。发现它在计算文本长度时采用的函数TextLength有问题。
其实TCanvas提供了一个TextLength方法,在去文本长度时汉字没有问题。
所以把这里替换下来就行了。
替换后的se_controls单元中的TSeCustomEdit的代码如下
TSeCustomEdit = class(TSeCustomControl)
private
FText: WideString;
FLMouseSelecting: boolean;
FCaretPosition: integer;
FSelStart: integer;
FSelLength: integer;
FFirstVisibleChar: integer;
FPopupMenu: TSeCustomPopupMenu;
FAutoSelect: boolean;
FCharCase: TEditCharCase;
FHideSelection: Boolean;
FMaxLength: Integer;
FReadOnly: Boolean;
FOnChange: TNotifyEvent;
FPasswordChar: WideChar;
FPasswordKind: TPasswordKind;
FTextAlignment: TAlignment;
FActionStack: TEditActionStack;
FPopupMenuDropShadow: boolean;
FPopupMenuShowAnimationTime: integer;
FPopupMenuBlendValue: integer;
FPopupMenuShadowWidth: integer;
FPopupMenuShowAnimation: TSeAnimationRec;
FPopupMenuBlend: boolean;
FContextMenuOptions: TSePopupMenuOptions;
procedure UpdateFirstVisibleChar;
procedure UpdateCaretePosition;
procedure UpdateCarete;

procedure WMGetDlgCode(var Msg: TWMGetDlgCode); message WM_GETDLGCODE;
procedure WMCopy(var Message: TMessage); message WM_COPY;
procedure WMPaste(var Message: TMessage); message WM_PASTE;
procedure WMCut(var Message: TMessage); message WM_CUT;
procedure WMUnDo(var Message: TMessage); message WM_UNDO;
procedure WMContexMenu(var Message: TMessage); message WM_CONTEXTMENU;
procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message
WM_LBUTTONDBLCLK;
{ unicode }
procedure WMImeStartComposition(var Message: TMessage); message
WM_IME_STARTCOMPOSITION;
procedure WMImeComposition(var Msg: TMessage); message WM_IME_COMPOSITION;
{ VCL messages }
procedure CMEnabledChanged(var Msg: TMessage); message CM_ENABLEDCHANGED;
procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
procedure CMTextChanged(var Msg: TMessage); message CM_TEXTCHANGED;

function GetSelText: WideString;
function GetVisibleSelText: WideString;
function GetNextWordBeging(StartPosition: integer): integer;
function GetPrivWordBeging(StartPosition: integer): integer;
function GetSelStart: integer;
function GetSelLength: integer;
function GetText: WideString;
procedure SetText(const Value: WideString);
procedure SetFont(Value: TFont);
procedure SetCaretPosition(const Value: integer);
procedure SetSelLength(const Value: integer);
procedure SetSelStart(const Value: integer);
procedure SetAutoSelect(const Value: boolean);
procedure SetCharCase(const Value: TEditCharCase);
procedure SetHideSelection(const Value: Boolean);
procedure SetMaxLength(const Value: Integer);
procedure SetPasswordChar(const Value: WideChar);
procedure SetCursor(const Value: TCursor);
procedure SetTextAlignment(const Value: TAlignment);
procedure SetPasswordKind(const Value: TPasswordKind);
procedure SetPopupMenuBlendValue(const Value: integer);
procedure SetPopupMenuDropShadow(const Value: boolean);
procedure SetPopupMenuShadowWidth(const Value: integer);
procedure SetPopupMenuShowAnimation(const Value: TSeAnimationRec);
procedure SetPopupMenuShowAnimationTime(const Value: integer);
procedure SetPopupMenuBlend(const Value: boolean);
procedure SetContextMenuOptions(const Value: TSePopupMenuOptions);
protected
function GetEditRect: TRect; virtual;
function GetPasswordCharWidth: integer; virtual;
function GetCharX(A: integer): integer;
function GetCoordinatePosition(x: integer): integer;
function GetSelRect: TRect; virtual;