⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sxskinedit.pas

📁 skin components for design of your applicastions
💻 PAS
📖 第 1 页 / 共 4 页
字号:

procedure TSXSkinCustomEdit.DoSetMaxLength(Value: Integer);
begin
 SendMessage(FTextControl.Handle,EM_LIMITTEXT,Value,0);
end;

procedure TSXSkinCustomEdit.SetCharCase(Value: TEditCharCase);
begin
 if FCharCase<>Value then
  begin
   FCharCase:=Value;
   RecreateWnd;
  end;
end;

procedure TSXSkinCustomEdit.SetHideSelection(Value: Boolean);
begin
 if FHideSelection<>Value then
  begin
   FHideSelection:=Value;
   RecreateWnd;
  end;
end;

procedure TSXSkinCustomEdit.SetMaxLength(Value: Integer);
begin
 if FMaxLength<>Value then
  begin
   FMaxLength:=Value;
   if FTextControl.HandleAllocated then DoSetMaxLength(Value);
  end;
end;

procedure TSXSkinCustomEdit.SetOEMConvert(Value: Boolean);
begin
 if FOEMConvert<>Value then
  begin
   FOEMConvert:=Value;
   FTextControl.RecreateWnd;
  end;
end;

function TSXSkinCustomEdit.GetModified:Boolean;
begin
 Result:=FTextControl.FModified;
 if FTextControl.HandleAllocated then
  Result:=SendMessage(FTextControl.Handle,EM_GETMODIFY,0,0)<>0;
end;

function TSXSkinCustomEdit.GetCanUndo:Boolean;
begin
  Result:=False;
  if FTextControl.HandleAllocated then
   Result:=SendMessage(FTextControl.Handle,EM_CANUNDO,0,0)<>0;
end;

procedure TSXSkinCustomEdit.SetModified(Value:Boolean);
begin
 if FTextControl.HandleAllocated then
  SendMessage(FTextControl.Handle,EM_SETMODIFY,Byte(Value),0) else
   FTextControl.FModified:=Value;
end;

procedure TSXSkinCustomEdit.SetPassword(Value:Boolean);
begin
 if FPassword<>Value then
  begin
   FPassword:=Value;
   if FTextControl.HandleAllocated then
    FTextControl.RecreateWnd;
  end;
end;

procedure TSXSkinCustomEdit.SetReadOnly(Value:Boolean);
begin
 if FReadOnly<>Value then
  begin
   FReadOnly:=Value;
   if FTextControl.HandleAllocated then
    SendMessage(FTextControl.Handle,EM_SETREADONLY,Ord(Value),0);
  end;
end;

procedure TSXSkinCustomEdit.SetAlignment(Value:TAlignment);
begin
 if FAlignment<>Value then
  begin
   FAlignment:=Value;
   if FTextControl.HandleAllocated then
    FTextControl.RecreateWnd;
  end;
end;

function TSXSkinCustomEdit.GetSelStart:Integer;
begin
 SendMessage(FTextControl.Handle,EM_GETSEL,Longint(@Result),0);
end;

procedure TSXSkinCustomEdit.SetSelStart(Value:Integer);
begin
 SendMessage(FTextControl.Handle,EM_SETSEL,Value,Value);
end;

function TSXSkinCustomEdit.GetSelLength:Integer;
var Selection:TSelection;
begin
 SendMessage(FTextControl.Handle,EM_GETSEL,Longint(@Selection.StartPos),Longint(@Selection.EndPos));
 Result:=Selection.EndPos-Selection.StartPos;
end;

procedure TSXSkinCustomEdit.SetSelLength(Value: Integer);
var Selection: TSelection;
begin
 if FTextControl<>nil then
  begin
   SendMessage(FTextControl.Handle,EM_GETSEL,Longint(@Selection.StartPos),
       Longint(@Selection.EndPos));
   Selection.EndPos:=Selection.StartPos+Value;
   SendMessage(FTextControl.Handle,EM_SETSEL,Selection.StartPos,Selection.EndPos);
   SendMessage(FTextControl.Handle,EM_SCROLLCARET,0,0);
  end;
end;

procedure TSXSkinCustomEdit.Clear;
begin
 if FTextControl<>nil then
  SetWindowText(FTextControl.Handle,'');
end;

procedure TSXSkinCustomEdit.ClearSelection;
begin
 if FTextControl<>nil then
  SendMessage(FTextControl.Handle,WM_CLEAR,0,0);
end;

procedure TSXSkinCustomEdit.CopyToClipboard;
begin
 if FTextControl<>nil then
  SendMessage(FTextControl.Handle,WM_COPY,0,0);
end;

procedure TSXSkinCustomEdit.CutToClipboard;
begin
 if FTextControl<>nil then
  SendMessage(FTextControl.Handle,WM_CUT,0,0);
end;

procedure TSXSkinCustomEdit.PasteFromClipboard;
begin
 if FTextControl<>nil then
  SendMessage(FTextControl.Handle,WM_PASTE,0,0);
end;

procedure TSXSkinCustomEdit.Undo;
begin
 if FTextControl<>nil then
  SendMessage(FTextControl.Handle,WM_UNDO,0,0);
end;

procedure TSXSkinCustomEdit.ClearUndo;
begin
 if FTextControl<>nil then
  SendMessage(FTextControl.Handle,EM_EMPTYUNDOBUFFER,0,0);
end;

procedure TSXSkinCustomEdit.SelectAll;
begin
 if FTextControl<>nil then
  SendMessage(FTextControl.Handle,EM_SETSEL,0,-1);
end;

function TSXSkinCustomEdit.GetSelTextBuf(Buffer:PChar;BufSize:Integer):Integer;
var     P:PChar;
 StartPos:Integer;
begin
 StartPos:=GetSelStart;
 Result:=GetSelLength;
 P:=StrAlloc(GetTextLen+1);
 try
  GetTextBuf(P,StrBufSize(P));
  if Result>=BufSize then Result:=BufSize-1;
  StrLCopy(Buffer,P+StartPos,Result);
 finally
  StrDispose(P);
 end;
end;

procedure TSXSkinCustomEdit.SetSelTextBuf(Buffer: PChar);
begin
 if FTextControl<>nil then
  SendMessage(FTextControl.Handle,EM_REPLACESEL,0,LongInt(Buffer));
end;

function TSXSkinCustomEdit.GetSelText:String;
var SelStart,Len:Integer;
               P:PChar;
begin
 SelStart:=GetSelStart;
 Len:=GetSelLength;
 SetString(Result,PChar(nil),Len);
 if Len<>0 then
  begin
   P:=StrAlloc(GetTextLen+1);
   try
    GetTextBuf(P,StrBufSize(P));
    Move(P[SelStart],Pointer(Result)^,Len);
   finally
    StrDispose(P);
   end;
  end;
end;

procedure TSXSkinCustomEdit.SetSelText(const Value:String);
begin
 if FTextControl<>nil then
  SendMessage(FTextControl.Handle,EM_REPLACESEL,0,Longint(PChar(Value)));
end;

procedure TSXSkinCustomEdit.PaintCurrentEStyle(Bitmap:TBitmap32;X,Y:Integer;Rect:TRect;Rgn:HRGN);
var    A:Integer;
  EState:TSXSkinEditStateParam;
   Style:TSXSkinGeneralStyle;
begin
 if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
  begin
   GetCurrentEState(EState);
   A:=SkinLibrary.Styles.GetGStyleIndex(EState.Style,Width,Height);
   if A>=0 then
    begin
     Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
     Style.DrawToBitmap(Self,CEID_Back,Bitmap,X,Y,Width,Height,Rect,Rgn,SkinLibrary,VComparer);
    end;
  end;
end;

procedure TSXSkinCustomEdit.PaintCurrentBlendedEStyle(Bitmap:TBitmap32;X,Y:Integer;Rect:TRect;Rgn:HRGN);
var   BB:TBitmap32;
 CurEdit:TBitmap32;
    Rgn2:HRGN;
begin
 if HasTransformEffect(FLastEditTransform) and
    (FDoneSteps<FLastEditTransform.StepsNum) and (FLastEdit<>nil) then
  begin
   CurEdit:=TBitmap32.Create;
   BB:=TBitmap32.Create;
   try
    CurEdit.DrawMode:=dmBlend;
    CurEdit.CombineMode:=cmMerge;
    BB.DrawMode:=dmBlend;
    BB.CombineMode:=cmMerge;
    CurEdit.SetSize(Width,Height);
    CurEdit.Clear(0);
    Rgn2:=CreateRectRgn(0,0,Width,Height);
    PaintCurrentEStyle(CurEdit,0,0,Types.Rect(0,0,Width,Height),Rgn2);
    DeleteObject(Rgn2);
    BB.SetSize(Width,Height);
    ApplyTransformEffectToBitmaps(FLastEdit,CurEdit,FLastEditTransform,FDoneSteps,BB);
    BB.DrawTo(Bitmap,X-Rect.Left,Y-Rect.Top);
   finally
    BB.Free;
    CurEdit.Free;
   end;
  end else PaintCurrentEStyle(Bitmap,X,Y,Rect,Rgn);
end;

procedure TSXSkinCustomEdit.PaintRectToBitmap(DestCanvasHandle:HDC;
           DestCanvasRect:TRect;Rect:TRect;Rgn:HRGN;Bitmap:TBitmap32;X,Y:Integer;
           WithSubItems:Boolean);
begin
 if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
  begin
   PaintCurrentBlendedEStyle(Bitmap,X,Y,Rect,Rgn);
  end;
 inherited;
end;

function TSXSkinCustomEdit.OnGetVariable(const VarName:String;var Error:Boolean):Single;
begin
 Result:=0;
 if VarName='W' then
  begin
   Result:=Width; exit;
  end;
 if VarName='H' then
  begin
   Result:=Height; exit;
  end;
 Error:=True;
end;

procedure TSXSkinCustomEdit.SetBounds(ALeft,ATop,AWidth,AHeight:Integer);
begin
 if not (csLoading in ComponentState) and FAutoSizeHeight then
  AHeight:=Height;
 inherited;
 if not (csLoading in ComponentState) then
  ResetEditParams([erpTextControl]);
end;

procedure TSXSkinCustomEdit.InternalSetBounds(ALeft,ATop,AWidth,AHeight:Integer);
begin
 inherited SetBounds(ALeft,ATop,AWidth,AHeight);
end;

function TSXSkinCustomEdit.GetTabStop:Boolean;
begin
 if csDesigning in ComponentState then
  Result:=inherited TabStop else
   begin
    if FTextControl<>nil then
     Result:=FTextControl.TabStop else Result:=False;
   end;
end;

procedure TSXSkinCustomEdit.SetTabStop(Value:Boolean);
begin
 if csDesigning in ComponentState then
  inherited TabStop:=Value else
   begin
    if FTextControl<>nil then
     FTextControl.TabStop:=Value;
    inherited TabStop:=False;
   end;
end;

function TSXSkinCustomEdit.GetTabOrder:Integer;
begin
 if csDesigning in ComponentState then
  Result:=inherited TabOrder else
   begin
    if FTextControl<>nil then
     Result:=FTextControl.TabOrder else Result:=0;
   end;
end;

procedure TSXSkinCustomEdit.SetTabOrder(Value:Integer);
begin
 if csDesigning in ComponentState then
  inherited TabOrder:=Value else
   begin
    if FTextControl<>nil then
     FTextControl.TabOrder:=Value;
   end;
end;

procedure TSXSkinCustomEdit.SetAutoSizeHeight(Value:Boolean);
begin
 if Value<>FAutoSizeHeight then
  begin
   FAutoSizeHeight:=Value;
   if Value and not (csLoading in ComponentState) then
    ResetEditParams([erpTextControl]);
  end;
end;

procedure TSXSkinCustomEdit.GetCurrentEState(var EState:TSXSkinEditStateParam);
var  A:Integer;
 Style:TSXSkinEditStyle;

 procedure SetEStateFrom(const T:TSXSkinEditStateParam);
 begin
  if EState.Style='' then EState.Style:=T.Style;
  AddFontData(EState.FD,T.FD);
 end;

begin
 Finalize(EState);
 FillChar(EState,sizeof(EState),0);
 ClearFontData(EState.FD);
 if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
  begin
   A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
   if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinEditStyle) then
    begin
     Style:=TSXSkinEditStyle(SkinLibrary.Styles[A]);
     if not Enabled then
      begin
       SetEStateFrom(Style.RUState);
       SetEStateFrom(Style.NUState);
      end else
     if FMouseOver then
      begin
       if FTextControl.FLastFocused then
        begin
         SetEStateFrom(Style.HFState);
         SetEStateFrom(Style.HUState);
         SetEStateFrom(Style.NFState);
         SetEStateFrom(Style.NUState);
        end else
         begin
          SetEStateFrom(Style.HUState);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -