Changeset 13 for os/trunk/Xvcl


Ignore:
Timestamp:
Feb 29, 2016, 3:09:13 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Allow receive mouse move mesages to focused form even if mouse position is outside of form area.
  • Fixed: Pass key press messages only to focused form and focused TControl like TEdit.
Location:
os/trunk/Xvcl
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • os/trunk/Xvcl/Xvcl.Controls.pas

    r8 r13  
    6060    FOnMouseUp: TNotifyEvent;
    6161    FOnKeyPress: TNotifyEvent;
     62    FFocused: Boolean;
    6263    function GetCanvas: TCanvas;
    6364    procedure SetParent(const Value: TWinControl); virtual;
    6465    procedure SetColor(const Value: TColor);
     66    procedure SetFocused(const Value: Boolean);
    6567  protected
    6668    function GetVideoDevice: TVideoDevice; virtual;
     
    7981    property VideoDevice: TVideoDevice read GetVideoDevice;
    8082    property Color: TColor read FColor write SetColor;
     83    property Focused: Boolean read FFocused write SetFocused;
    8184    property OnClick: TNotifyEvent read FOnClick write FOnClick;
    8285    property OnMouseDown: TNotifyEvent read FOnMouseDown write FOnMouseDown;
     
    8891  protected
    8992    function HandleMessage(Message: TMessage): Boolean; override;
     93  private
     94   procedure ClearFocus;
    9095  public
    9196    Controls: TList<TControl>;
     
    193198    if Visible then Paint;
    194199  end;
     200end;
     201
     202procedure TControl.SetFocused(const Value: Boolean);
     203begin
     204  if Value then FParent.ClearFocus;
     205  FFocused := Value;
    195206end;
    196207
     
    268279
    269280{ TWinControl }
     281
     282procedure TWinControl.ClearFocus;
     283var
     284 Control: TControl;
     285begin
     286  for Control in Controls do
     287    Control.Focused := False;
     288end;
    270289
    271290constructor TWinControl.Create;
     
    342361begin
    343362  Result := False;
    344   if Message is TMessageKeyPress then
     363  if (Message is TMessageMouseDown) then
     364   Focused := True
     365  else
     366  if (Message is TMessageKeyPress) and Focused then
    345367  with TMessageKeyPress(Message) do begin
    346368    if Assigned(FOnKeyPress) then FOnKeyPress(Self);
  • os/trunk/Xvcl/Xvcl.Forms.pas

    r5 r13  
    9090      Move.StartMousePos := Position;
    9191      Move.Active := True;
    92      Result := True;
     92      Result := True;
    9393    end;
    9494  end else
     
    137137  if FFocused <> Value then begin
    138138    FFocused := Value;
    139     if Value then TScreen(Screen).FocusForm(Self);
     139    if Value then TScreen(Screen).FocusedForm := Self;
    140140  end;
    141141end;
Note: See TracChangeset for help on using the changeset viewer.