Ignore:
Timestamp:
May 8, 2013, 1:52:33 PM (12 years ago)
Author:
chronos
Message:
  • Added: Support for mouse move handling. Now forms can be moved by dragging title bar.
  • Fixed: Clearing background during painting in screen and forms.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/Xvcl/Xvcl.Forms.pas

    r22 r23  
    88type
    99  TForm = class(TWinControl)
     10  private
     11    FFocused: Boolean;
     12    procedure SetFocused(const Value: Boolean);
    1013  protected
    1114    function GetVideoDevice: TVideoDevice; override;
    1215  public
     16  const
     17    TitleBarHeight = 24;
     18  var
    1319    Screen: TObject; // TScreen;
    1420    Caption: string;
     21    function HandleMessage(Message: TMessage): Boolean; override;
    1522    procedure Paint; override;
     23    property Focused: Boolean read FFocused write SetFocused;
    1624  end;
    1725
     
    5058end;
    5159
     60function TForm.HandleMessage(Message: TMessage): Boolean;
     61var
     62  TitleBarBounds: TRectangle;
     63begin
     64  Result := False;
     65  if Message is TMessageMouseDown then
     66  with TMessageMouseDown(Message) do begin
     67    TitleBarBounds := TRectangle.Create(0, 0, Bounds.Width, TitleBarHeight);
     68    if TitleBarBounds.Contains(ScreenToClient(Position)) then begin
     69      Focused := True;
     70      Result := True;
     71      Move.StartControlPos := Bounds.TopLeft;
     72      Move.StartMousePos := Position;
     73      Move.Active := True;
     74    end;
     75  end else
     76  if Message is TMessageMouseUp then
     77  with TMessageMouseUp(Message) do begin
     78    Move.Active := False;
     79  end else
     80  if Message is TMessageMouseMove then
     81  with TMessageMouseUp(Message) do begin
     82    if Move.Active then begin
     83      Bounds.TopLeft := Move.StartControlPos + (Position - Move.StartMousePos);
     84      TScreen(Screen).Paint;
     85    end;
     86  end;
     87  if not Result then inherited;
     88end;
     89
    5290procedure TForm.Paint;
    53 const
    54   TitleBarHeight = 24;
    5591begin
    56   inherited;
    5792  with Canvas do begin
     93    Canvas.Brush.Color := clWhite;
     94    Canvas.FillRect(TRectangle.Create(0, TitleBarHeight, Size.X, Size.Y));
     95    if Focused then Brush.Color := clLightBlue else
     96      Brush.Color := clSilver;
     97    FillRect(TRectangle.Create(0, 0, Bounds.Width - 1, TitleBarHeight));
    5898    MoveTo(TPoint.Create(0, 0));
    5999    LineTo(TPoint.Create(Bounds.Width - 1, 0));
     
    66106      (TitleBarHeight - GetTextSize(Caption).Y) div 2), Caption);
    67107  end;
     108  inherited;
     109end;
     110
     111procedure TForm.SetFocused(const Value: Boolean);
     112begin
     113  FFocused := Value;
     114  Paint;
    68115end;
    69116
Note: See TracChangeset for help on using the changeset viewer.