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

📄 fcframe.pas

📁 一套及时通讯的原码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
      finally
        ReleaseDC(Control.Handle, DC);
        DeleteObject(brush);
      end
   end
   else
      InvalidateRect(Control.parent.handle, @r, TransparentClearsBackground);

end;

procedure TfcEditFrame.RefreshControl;
var r:TRect;
begin
//   AdjustEditRect;
   r:= Control.BoundsRect;
   if Enabled and Transparent then
      InvalidateRect(Control.parent.handle, @r, false)
   else Control.Invalidate;
end;

{procedure TfcEditFrame.AdjustEditRect;
var TempEditRect:TRect;
begin
   if not Control.HandleAllocated then exit;
   SendMessage(Control.handle,em_getrect, 0, Integer(@TempEditRect));
   GetEditRectForFrame(TempEditRect);
   SendMessage(Control.Handle, EM_SETRECTNP, 0, LongInt(@TempEditRect));
end;
}

function TfcEditFrame.IsSingleBorderStyle(Style: TfcEditFocusStyle): boolean;
begin
  result:= Style in [efsFrameBox, efsFrameSingle];
end;

procedure TfcEditFrame.GetEditRectForFrame(var Loc: TRect);
begin
     if IsSingleBorderStyle(FocusStyle) then
//     if (FocusStyle = efsFrameBox) then
     begin
        Loc.Top := 2;
        Loc.Left := 2;
        //6/22/01 - Copy change from IP wwframe - PYW - Correct problem where editrect is 1 pixel too large when RightBorder is showing for FrameBox.
        if (efRightBorder in FocusBorders) and (FocusStyle = efsFrameBox) then
          Loc.Right:= Loc.Right - 1
     end
     else begin
        Loc.Top := 3;
        if efLeftBorder in FocusBorders then
        begin
           if FocusStyle in [efsFrameSunken, efsFrameBump] then
              Loc.Left := 3
           else Loc.Left:= 2;
        end
        else Loc.Left:=1;

        Loc.Right:= Loc.Right -2
     end
end;

procedure TfcEditFrame.AdjustHeight;
var
  DC: HDC;
  SaveFont: HFont;
  I: Integer;
  SysMetrics, Metrics: TTextMetric;
begin
  DC := GetDC(0);
  GetTextMetrics(DC, SysMetrics);
  SaveFont := SelectObject(DC, TEdit(Control).Font.Handle);
  GetTextMetrics(DC, Metrics);
  SelectObject(DC, SaveFont);
  ReleaseDC(0, DC);
  if NewStyleControls then
  begin
    if TEdit(Control).Ctl3D then I := 8 else I := 6;
    I := GetSystemMetrics(SM_CYBORDER) * I;
    if TEdit(Control).BorderStyle=bsNone  then i:= 6;
    if self.enabled then i:= i + AutoSizeHeightAdjust;;
  end else
  begin
    I := SysMetrics.tmHeight;
    if I > Metrics.tmHeight then I := Metrics.tmHeight;
    I := I div 4 + GetSystemMetrics(SM_CYBORDER) * 4;
  end;
  if Control.Height=Metrics.tmHeight+i then begin
     Control.Height := Metrics.tmHeight + I - 1; { Force wmsize to take place to call setEditRect }
     Control.Height := Metrics.tmHeight + I;
  end
  else
     Control.Height := Metrics.tmHeight + I;
end;

{Function GetBooleanProp(control: TControl; PropertyName: string): boolean;
var PropInfo: PPropInfo;
begin
   Result:= False;
   PropInfo:= Typinfo.GetPropInfo(Control.ClassInfo, PropertyName);
   if PropInfo<>Nil then
      result:= Boolean(GetOrdProp(Control, PropInfo));
end;
}
procedure SetBooleanProp(control: TControl; PropertyName: string; val: boolean);
var PropInfo: PPropInfo;
begin
   PropInfo:= Typinfo.GetPropInfo(Control.ClassInfo, PropertyName);
   if PropInfo<>Nil then
      SetOrdProp(control, PropInfo, ord(val));
end;

procedure TfcButtonEffects.SetTransparent(val: boolean);
begin
   if FTransparent<>val then
   begin
      FTransparent:= val;
      SetBooleanProp(Button, 'Transparent', FFlat or FTransparent);
      SetBooleanProp(Button, 'Flat', FFlat or FTransparent);
      Refresh;  //      FButton.Glyph.Handle:= LoadComboGlyph;
      Button.Invalidate;
   end;
end;

procedure TfcButtonEffects.SetFlat(val: boolean);
begin
   if FFlat<>val then
   begin
      FFlat:= val;
      SetBooleanProp(Button, 'Flat', FFlat or FTransparent);
      Refresh;  //      FButton.Glyph.Handle:= LoadComboGlyph;
      Button.Invalidate;
   end;
end;

constructor TfcButtonEffects.Create(Owner: TComponent; AButton: TControl);
begin
   inherited Create;
   button:= TControl(AButton);
   control:= TControl(Owner);
end;

Procedure TfcButtonEffects.Refresh;
begin
end;

class Function TfcEditFrame.Get(Control: TControl): TfcEditFrame;
var PropInfo: PPropInfo;
begin
   Result:= Nil;
   PropInfo:= Typinfo.GetPropInfo(Control.ClassInfo,'Frame');
   if PropInfo<>Nil then
      result:= TfcEditFrame(GetOrdProp(Control, PropInfo));
end;

class Function TfcButtonEffects.Get(Control: TControl): TfcButtonEffects;
var PropInfo: PPropInfo;
begin
   Result:= Nil;
   PropInfo:= Typinfo.GetPropInfo(Control.ClassInfo,'ButtonEffects');
   if PropInfo<>Nil then
      result:= TfcButtonEffects(GetOrdProp(Control, PropInfo));
end;

Function TfcEditFrame.IsFrameEffective: boolean;
begin
   result:= enabled and (control<>nil) and not (control.parent is TCustomGrid);
end;

Procedure TfcButtonEffects.Assign(Source: TPersistent);
var s: TfcButtonEffects;
begin
  if fcIsClass(Source.classtype, 'TwwButtonEffects') or (Source is TfcButtonEffects) then
  begin
     s:= TfcButtonEffects(source);
     Flat:= s.Flat;
     Transparent:= s.Transparent;
  end
  else inherited Assign(Source);
end;

procedure TfcEditFrame.Assign(Source: TPersistent);
var s: TfcEditFrame;
begin
  if fcIsClass(Source.classtype, 'TwwEditFrame') or (Source is TfcEditFrame) then
  begin
     s:= TfcEditFrame(source);
     FocusStyle:= s.FocusStyle;
     Enabled:= s.Enabled;
     Transparent:= s.Transparent;
     if not Enabled then exit; {Optimization }
     TransparentClearsBackground:= s.TransparentClearsBackground;
     AutoSizeHeightAdjust:= s.AutoSizeHeightAdjust;
     FocusBorders:= s.FocusBorders;
     NonFocusBorders:= s.NonFocusBorders;
     NonFocusStyle:= s.NonFocusStyle;
     NonFocusTextOffsetX:= s.NonFocusTextOffsetX;
     NonFocusTextOffsetY:= s.NonFocusTextOffsetY;
     NonFocusTransparentFontColor:= s.NonFocusTransparentFontColor;
     NonFocusColor:= s.NonFocusColor;
     NonFocusFontColor:= s.NonFocusFontColor;
     MouseEnterSameAsFocus:= s.MouseEnterSameAsFocus;
  end
  else inherited Assign(Source);
end;

procedure TfcEditFrame.GetFrameTextPosition(
   var Left, Indent: integer;
   Focused: boolean = False);
var Borders: TfcEditFrameEnabledSet;
    FrameStyle: TfcEditFocusStyle;
begin
   if Focused then
   begin
      Borders:= FocusBorders;
      FrameStyle:= FocusStyle;
   end
   else begin
      Borders:= NonFocusBorders;
      FrameStyle:= NonFocusStyle;
   end;

   Left:= 1;
   if (efLeftBorder in Borders) then begin
//      if FrameStyle=efsFrameBox then Left:= 2
      if IsSingleBorderStyle(FrameStyle) then Left:= 2
      else Left:= 3;
   end;

   Indent:= 2;
   if (efTopBorder in Borders) and
      (not IsSingleBorderStyle(FrameStyle)) then
//      (FrameStyle<>efsFrameBox) then
      Indent:= Indent + 1;

   Left:= Left + NonFocusTextOffsetX;
   Indent:= Indent + NonFocusTextOffsetY;
end;

(*procedure fcInvalidateTransparentArea(control : TControl);
var r: TRect;
   pc: TControl;
   pt: TPoint;
   clearBackground: boolean;
begin
  { Draws any image in the background }
   with Control do  r:= Rect(Left, Top, Left+Width, Top+Height);
   r:= Control.ClientRect;
   pc:= control;
   if pc.parent=nil then exit;

   // If parent is not transparent then just return
//   if not fcIsTransparentParent(control) then exit;
   pc:= Control;
   While (pc.parent<>nil) do begin
//     oldpc:= pc;
     pc:= pc.Parent;
     pt:= Point(0,0);
     // Don't invalidate area outside of control
     if Control.Left<0 then pt.x:= pt.x - Control.Left;
     if Control.Top<0 then pt.y:= pt.y - Control.Top;

     pt:= Control.ClientToScreen(pt);
     ScreenToClient(TWinControl(pc).handle, pt);
     r:= Rect(pt.X, pt.y, pt.x+Control.Width, pt.y+Control.Height);

     // Don't invalidate area outside of control
     if Control.Left<0 then r.Right:= r.Right - Control.Left;
     if Control.Top<0 then r.Top:= r.Top - Control.Top;

     clearBackground:= TransparentClearsBackground;
{
     InvalidateRect(TWinControl(pc).handle, @r, ClearBackground);
     if not wwIsTransparentParent(oldpc) then exit;

     InvalidateRect(TWinControl(pc).handle, @r, True);
     if pc is TCustomForm then begin
        pc.update; // Complete painting as background imager is not painted sometimes otherwise
                   // Later may need to only do this code in cmexit, instead of also
                   // in cmTextChanged
//        Application.ProcessMessages;
        break;
     end;
}
   end;
end;
*)
(*procedure fcInvalidateTransparentArea(control : TControl);
var r: TRect;
   pc: TControl;
begin
  { Draws any image in the background }
  if not fcIsTransparentParent(control) then exit;
  r:= Rect(Control.Left, Control.Top, Control.Left+Control.Width, Control.Top + Control.Height);
  InvalidateRect(Control.Parent.Handle, @r, False);
  exit;
   with Control do  r:= Rect(Left, Top, Left+Width, Top+Height);
   pc:= control;
   if pc.parent=nil then exit;

   // If parent is not transparent then just return
//   if not fcIsTransparentParent(control) then exit;
   repeat
      pc:= pc.parent;
      if (pc<>nil) and (pc.parent=nil) then break;

      r:= Rect(pc.left + r.Left, pc.top+r.top,
           pc.left + r.right, pc.top + r.bottom);
   until pc.parent=nil;

   if pc is TWinControl then
       InvalidateRect(TWinControl(pc).handle, @r, False);
end;
*)

procedure fcInvalidateTransparentArea2(control : TControl;
   TransparentClearsBackground: boolean);
var r: TRect;
   pc, oldpc: TControl;
   pt: TPoint;
   clearBackground: boolean;
begin
  { Draws any image in the background }
   with Control do  r:= Rect(Left, Top, Left+Width, Top+Height);
   r:= Control.ClientRect;
   pc:= control;
   if pc.parent=nil then exit;

   // If parent is not transparent then just return
//   if not fcIsTransparentParent(control) then exit;
   pc:= Control;
   While (pc.parent<>nil) do begin
     oldpc:= pc;
     pc:= pc.Parent;
     pt:= Point(0,0);
     // Don't invalidate area outside of control
     if Control.Left<0 then pt.x:= pt.x - Control.Left;
     if Control.Top<0 then pt.y:= pt.y - Control.Top;

     pt:= Control.ClientToScreen(pt);
     ScreenToClient(TWinControl(pc).handle, pt);
     r:= Rect(pt.X, pt.y, pt.x+Control.Width, pt.y+Control.Height);

     // Don't invalidate area outside of control
     if Control.Left<0 then r.Right:= r.Right - Control.Left;
     if Control.Top<0 then r.Top:= r.Top - Control.Top;

{     if wwIsClass(control.classtype, 'TwwNavButton') and
        (wwIsTransparentParent(oldpc)) then clearBackground:=false
     else }
     clearBackground:= TransparentClearsBackground;

     InvalidateRect(TWinControl(pc).handle, @r, ClearBackground);
     if not fcIsTransparentParent(oldpc) then exit;

   end;
end;

procedure fcInvalidateTransparentArea(control : TControl);
var frame: TfcEditFrame;
    clearBackground: boolean;
begin
   Frame:= TfcEditFrame.Get(Control);

   if ((Frame<>Nil) and Frame.TransparentClearsBackground) then
      ClearBackground:=True
   else clearBackground:= false;

   fcInvalidateTransparentArea2(control, clearBackground);
end;

end.

⌨️ 快捷键说明

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