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

📄 qcomboedits.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
  end;
end;

procedure TCustomComboEdit.AdjustClientRect(var Rect: TRect);
begin
 // act as the edit where the client area
  FClientArea.AdjustClientRect(Rect);
end;

function TCustomComboEdit.GetClientRect: TRect;
begin
  Result := FClientArea.ClientRect;
end;

procedure TCustomComboEdit.RequestAlign;
var
  Value: TAlign;
begin
 // redirect Align to FBorder. Align must be alNone before setting FBorder.Align
  Value := Align;
  Align := alNone;
  FBorder.Align := Value;
  AdjustClientArea;
end;

procedure TCustomComboEdit.ChangeBounds(ALeft, ATop, AWidth, AHeight: Integer);
var
  R: TRect;
begin
 // Do not use QWidget_setGeomentry because we only need the values but not the
 // widget at this position.
  R := BoundsRect;
  FLeft := ALeft;
  FTop := ATop;
  FWidth := AWidth;
  FHeight := AHeight;

 // set the border panel's bounds rect to the requested rect
  if Parent <> nil then
  begin
    FBorder.SetBounds(Left, Top, Width, Height);
   // update because the above could be invalid
    FLeft := FBorder.Left;
    FTop := FBorder.Top;
    FWidth := FBorder.Width;
    FHeight := FBorder.Height;
  end;

  AdjustClientArea;
  if (R.Left <> FLeft) or (R.Top <> FTop) or
     (R.Right - R.Left <> FWidth) or (R.Bottom - R.Top <> FHeight) then
    BoundsChanged;
end;

procedure TCustomComboEdit.SetParent(const Value: TWidgetControl);
var
  Pt: TPoint;
  R: TRect;
begin
  if Value <> Parent then
  begin
    R := BoundsRect;
    try
      FBorder.Parent := Value;
      FClientArea.Parent := FBorder;

      inherited SetParent(Value);
      if Value <> nil then
      begin
        QWidget_pos(Handle, @Pt);
        QWidget_reparent(Handle, FClientArea.Handle, WidgetFlags, @Pt, True);
      end;
    finally
      BoundsRect := R; // calls AdjustClientArea
    end;
  end;
end;

procedure TCustomComboEdit.SetZOrder(TopMost: Boolean);
begin
  FBorder.SetZOrder(TopMost);
end;

function TCustomComboEdit.EventFilter(Sender: QObjectH; Event: QEventH): Boolean;
var
  AAnchors: TAnchors;
begin
 // redirect the anchors to FBorder
  if Anchors <> [akLeft, akTop] then
  begin
    AAnchors := Anchors;
    Anchors := [akLeft, akTop];
    if Assigned(FBorder) then
      if FBorder.Align = alNone then
        FBorder.Anchors := AAnchors;
  end;

 // ignore all CLX handling for reparent, move and resize events 
  Result := False;
  case QEvent_type(Event) of
    QEventType_Reparent,
    QEventType_Move,
    QEventType_Resize:
      Exit;
  end;
  Result := inherited EventFilter(Sender, Event);
end;

procedure TCustomComboEdit.CreateWidget;
begin
  inherited CreateWidget;
  inherited BorderStyle := bsNone;
  AdjustClientArea;
end;

procedure TCustomComboEdit.DoFlatChanged;
begin
end;

{ TCustomComboMaskEdit }

constructor TCustomComboMaskEdit.Create(AOwner: TComponent);
begin
  FBorder := TComboEditBorder.Create(nil);
  FBorder.FEdit := Self;
  FClientArea := TComboEditClientArea.Create(nil);
  FClientArea.FEdit := Self;
  inherited Create(AOwner); // needs FBorder and FClientArea
  FWidth := 101;
  FHeight := 21;
  FBorder.Color := Color;
  FClientArea.Color := Color;
  FEditClientColor := True;
  BorderStyle := bsSingle;
  SetEditorRect(nil);
end;

destructor TCustomComboMaskEdit.Destroy;
begin
  SetParent(nil); // prevent the release of needed controls
  inherited Destroy;
 // some methods in inherited Destroy may access the client area and border 
  if not (csDestroying in FClientArea.ComponentState) then
    FClientArea.Free;
  if not (csDestroying in FBorder.ComponentState) then
    FBorder.Free;
end;

procedure TCustomComboMaskEdit.CursorChanged;
begin
  inherited CursorChanged;
  FBorder.Cursor := Cursor;
  FClientArea.Cursor := Cursor;
end;

procedure TCustomComboMaskEdit.EnabledChanged;
begin
  inherited EnabledChanged;
  FBorder.Enabled := Enabled;
  FClientArea.Enabled := Enabled;
end;

procedure TCustomComboMaskEdit.VisibleChanged;
begin
  inherited VisibleChanged;
  FBorder.Visible := Visible;
  FClientArea.Visible := Visible;
end;

procedure TCustomComboMaskEdit.ColorChanged;
begin
  inherited ColorChanged;
  if FEditClientColor then
    FClientArea.Color := Color;
end;

function TCustomComboMaskEdit.GetClientColor: TColor;
begin
  Result := FClientArea.Color;
end;

procedure TCustomComboMaskEdit.SetClientColor(const Value: TColor);
begin
  if Value <> ClientColor then
  begin
    FEditClientColor := False;
    FClientArea.Color := Value;
  end;
end;

procedure TCustomComboMaskEdit.SetEditClientColor(const Value: Boolean);
begin
  FEditClientColor := Value;
  if FEditClientColor then
    ColorChanged;
end;

function TCustomComboMaskEdit.GetBevelInner: TPanelBevel;
begin
  Result := FBorder.BevelInner;
end;

function TCustomComboMaskEdit.GetBevelOuter: TPanelBevel;
begin
  Result := FBorder.BevelOuter;
end;

function TCustomComboMaskEdit.GetBevelWidth: TBevelWidth;
begin
  Result := FBorder.BevelWidth;
end;

function TCustomComboMaskEdit.GetBorderHandle: QWidgetH;
begin
  Result := FBorder.Handle;
end;

function TCustomComboMaskEdit.GetBorderStyle: TControlBorderStyle;
begin
  Result := bsSingle;
  if FBorder.BevelInner = FBorder.BevelOuter then
  begin
    if FBorder.BevelInner = bvLowered then
      Result := bsSingle
    else if FBorder.BevelInner = bvNone then
      Result := bsNone;
  end;
  if FBorder.BorderWidth < 2 then
    Result := bsNone;
end;

procedure TCustomComboMaskEdit.SetBevelInner(const Value: TPanelBevel);
begin
  FBorder.BevelInner := Value;
  AdjustClientArea;
end;

procedure TCustomComboMaskEdit.SetBevelOuter(const Value: TPanelBevel);
begin
  FBorder.BevelOuter := Value;
  AdjustClientArea;
end;

procedure TCustomComboMaskEdit.SetBevelWidth(const Value: TBevelWidth);
begin
  FBorder.BevelWidth := Value;
  AdjustClientArea;
end;

procedure TCustomComboMaskEdit.SetBorderStyle(Value: TControlBorderStyle);
begin
  FBorder.BorderStyle := Value;
  if Value = bsNone then
    FBorder.BorderWidth := 0
  else
  if FFlat then
    FBorder.BorderWidth := 1
  else
    FBorder.BorderWidth := 2;
  AdjustClientArea;
end;

function TCustomComboMaskEdit.GetFlat: Boolean;
begin
  Result := FFlat;
end;

procedure TCustomComboMaskEdit.SetFlat(const Value: Boolean);
begin
  if Value <> FFlat then
  begin
    FFlat := Value;
    if FBorder.BorderStyle = bsSingle then
    begin
      if FFlat then
        FBorder.BorderWidth := 1
      else
        FBorder.BorderWidth := 2;
    end;
    FBorder.Invalidate;
    DoFlatChanged;
  end;
end;

function TCustomComboMaskEdit.GetClientArea: TComboEditClientArea;
begin
  Result := FClientArea;
end;

function TCustomComboMaskEdit.GetEditorRect: TRect;
begin
  Result := FEditRect;
end;

procedure TCustomComboMaskEdit.SetEditorRect(Value: PRect);
begin
  FUseEditRect := Value <> nil;
  if FUseEditRect then
    FEditRect := Value^;
  AdjustClientArea;
end;

procedure TCustomComboMaskEdit.EMGetRect(var Mesg: TMessage);
begin
  with TEMRect(Mesg) do
  begin
    Rect^ := GetEditorRect;
    Handled := True;
  end;
end;

procedure TCustomComboMaskEdit.EMSetRect(var Mesg: TMessage);
begin
  with TEMRect(Mesg) do
  begin
    Self.SetEditorRect(Rect);
    Handled := True;
  end;
end;

procedure TCustomComboMaskEdit.AdjustClientArea;
var
  R: TRect;
begin
  if Parent <> nil then
  begin
    FClientArea.Align := alClient;
    if not FUseEditRect then
      FEditRect := FClientArea.ClientRect;

    R := FEditRect;
    with R do
    begin
     // Qt will move the Top value if the Height is too high.
      if Bottom > Top + ClientHeight then
        Dec(Top, Bottom - ClientHeight);
      QWidget_setGeometry(Handle, Left, Top, Right - Left, Bottom - Top);
    end;
  end;
end;

procedure TCustomComboMaskEdit.AdjustClientRect(var Rect: TRect);
begin
 // act as the edit where the client area
  FClientArea.AdjustClientRect(Rect);
end;

function TCustomComboMaskEdit.GetClientRect: TRect;
begin
  Result := FClientArea.ClientRect;
end;

procedure TCustomComboMaskEdit.RequestAlign;
var
  Value: TAlign;
begin
 // redirect Align to FBorder. Align must be alNone before setting FBorder.Align
  Value := Align;
  Align := alNone;
  FBorder.Align := Value;
  AdjustClientArea;
end;

procedure TCustomComboMaskEdit.ChangeBounds(ALeft, ATop, AWidth, AHeight: Integer);
var
  R: TRect;
begin
 // Do not use QWidget_setGeomentry because we only need the values but not the
 // widget at this position.
  R := BoundsRect;
  FLeft := ALeft;
  FTop := ATop;
  FWidth := AWidth;
  FHeight := AHeight;

 // set the border panel's bounds rect to the requested rect  
  if Parent <> nil then
  begin
    FBorder.SetBounds(Left, Top, Width, Height);
   // update because the above could be invalid 
    FLeft := FBorder.Left;
    FTop := FBorder.Top;
    FWidth := FBorder.Width;
    FHeight := FBorder.Height;
  end;

  AdjustClientArea;
  if (R.Left <> FLeft) or (R.Top <> FTop) or
     (R.Right - R.Left <> FWidth) or (R.Bottom - R.Top <> FHeight) then
    BoundsChanged;
end;

procedure TCustomComboMaskEdit.SetParent(const Value: TWidgetControl);
var
  Pt: TPoint;
  R: TRect;
begin
  if Value <> Parent then
  begin
    R := BoundsRect;
    try
      FBorder.Parent := Value;
      FClientArea.Parent := FBorder;

      inherited SetParent(Value);
      if Value <> nil then
      begin
        QWidget_pos(Handle, @Pt);
        QWidget_reparent(Handle, FClientArea.Handle, WidgetFlags, @Pt, True);
      end;
    finally
      BoundsRect := R; // calls AdjustClientArea
    end;
  end;
end;

procedure TCustomComboMaskEdit.SetZOrder(TopMost: Boolean);
begin
  FBorder.SetZOrder(TopMost);
end;

function TCustomComboMaskEdit.EventFilter(Sender: QObjectH; Event: QEventH): Boolean;
var
  AAnchors: TAnchors;
begin
 // redirect the anchors to FBorder
  if Anchors <> [akLeft, akTop] then
  begin
    AAnchors := Anchors;
    Anchors := [akLeft, akTop];
    if Assigned(FBorder) then
      if FBorder.Align = alNone then
        FBorder.Anchors := AAnchors;
  end;

 // ignore all CLX handling for reparent, move and resize events 
  Result := False;
  case QEvent_type(Event) of
    QEventType_Reparent,
    QEventType_Move,
    QEventType_Resize:
      Exit;
  end;
  Result := inherited EventFilter(Sender, Event);
end;

procedure TCustomComboMaskEdit.CreateWidget;
begin
  inherited CreateWidget;
  inherited BorderStyle := bsNone;
  AdjustClientArea;
end;

procedure TCustomComboMaskEdit.DoFlatChanged;
begin
end;

{ TEditBorder }

procedure TComboEditBorder.AdjustClientRect(var Rect: TRect);
var
  BevelSize: Integer;
begin
  inherited AdjustClientRect(Rect);

 // undo TCustomPanel changes
  InflateRect(Rect, BorderWidth, BorderWidth);
  BevelSize := 0;
  if BevelOuter <> bvNone then
    Inc(BevelSize, BevelWidth);
  if BevelInner <> bvNone then
    Inc(BevelSize, BevelWidth);
  InflateRect(Rect, BevelSize, BevelSize);

 // do out changes
  if BorderStyle = bsSingle then
    InflateRect(Rect, -BorderWidth, -BorderWidth)
  else
    InflateRect(Rect, -BevelSize, -BevelSize);
end;

procedure TComboEditBorder.BoundsChanged;
begin
  inherited BoundsChanged;
  if Assigned(FEdit) then
    if (FEdit.Left <> Left) or (FEdit.Top <> Top) or
       (FEdit.Width <> Width) or (FEdit.Height <> Height) then
      FEdit.SetBounds(Left, Top, Width, Height);
end;

procedure TComboEditBorder.Paint;
var
  Rect: TRect;
begin
  Rect := ClientRect;
  if BorderStyle = bsSingle then
  begin
    if (FEdit as IComboEditHelper).GetFlat then
      Frame3D(Canvas, Rect, cl3DDkShadow, cl3DDkShadow, 1)
    else
    begin
      Canvas.Start;
      QStyle_drawPanel(QWidget_style(Handle), Canvas.Handle,
        Rect.Left, Rect.Top, Rect.Right - Rect.Left, Rect.Bottom - Rect.Top,
        QWidget_colorGroup(Handle), True,
        QStyle_defaultFrameWidth(QWidget_style(Handle)), nil);
      Canvas.Stop;
    end;
  end
  else
    inherited Paint;
end;

{ TComboEditClient }

procedure TComboEditClientArea.Click;
begin
  if Assigned(FEdit) and FEdit.CanFocus and FEdit.Showing then
    FEdit.SetFocus;
  inherited Click;
end;

end.

⌨️ 快捷键说明

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