Changeset 14


Ignore:
Timestamp:
Feb 29, 2016, 5:23:37 PM (9 years ago)
Author:
chronos
Message:
  • Modified: TForm title bar implemented using controls.
Location:
os/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • os/trunk/Applications/TestApplication.pas

    r8 r14  
    3838  Form1.Caption := 'Test application';
    3939  Form1.Screen := Screen;
     40  Form1.Application := Self;
    4041  Form2 := TForm.Create;
    4142  Form2.Owner := Self;
     
    4445  Form2.Caption := 'Some form';
    4546  Form2.Screen := Screen;
     47  Form2.Application := Self;
    4648  Timer1 := TTimer.Create;
    4749  Timer1.Interval := 1000;
  • os/trunk/Applications/UDesktop.pas

    r8 r14  
    8383  MainBar.Caption := 'fdfdfd';
    8484  MainBar.Screen := Screen;
     85  MainBar.Application := Self;
    8586  TaskBar := TPanel.Create;
    8687  TaskBar.Parent := MainBar;
  • os/trunk/Drivers/Driver.VideoVCL.pas

    r6 r14  
    9595  inherited;
    9696  CanvasVCL.Brush.Color := ColorToVCL(Color);
     97  CanvasVCL.Brush.Style := bsSolid;
    9798  CanvasVCL.FillRect(System.Types.Rect(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom));
    9899end;
  • os/trunk/System/LDOS.Kernel.pas

    r13 r14  
    6363    Forms: TList<TForm>;
    6464    VideoDevice: TVideoDevice;
     65    FormMove: TControlMove;
    6566    procedure HandleResize;
    6667    procedure Paint;
     
    8081  TMouse = class
    8182    Kernel: TKernel;
    82     MovedForm: TForm;
    8383    procedure HandleMove(Position: TPoint);
    8484    procedure HandleDown(Position: TPoint);
     
    226226  Canvas := TScreenCanvas.Create;
    227227  Canvas.Screen := Self;
     228  FormMove := TControlMove.Create;
    228229end;
    229230
    230231destructor TScreen.Destroy;
    231232begin
     233  FormMove.Free;
    232234  Canvas.Destroy;
    233235  Forms.Destroy;
     
    371373    for Form in Kernel.Screen.Forms do
    372374    if Form.Bounds.Contains(Position) then begin
    373       MovedForm := Form;
    374375      if Form.HandleMessage(NewMessage) then begin
    375376        Break;
     
    389390  NewMessage.Position := Position;
    390391  try
     392    with Kernel.Screen.FormMove do
     393    if Active then begin
     394      TForm(Control).Bounds.TopLeft := StartControlPos + (Position - StartMousePos);
     395      Kernel.Screen.Paint;
     396    end;
    391397    for Form in Kernel.Screen.Forms do
    392398    if Form.Bounds.Contains(Position) then begin
     
    410416  NewMessage.Position := Position;
    411417  try
     418    Kernel.Screen.FormMove.Active := False;
    412419    for Form in Kernel.Screen.Forms do
    413420    if Form.Bounds.Contains(Position) then begin
     
    416423      end;
    417424    end;
    418     if Assigned(Kernel.Screen.FocusedForm) then
    419       Kernel.Screen.FocusedForm.HandleMessage(NewMessage);
     425//    if Assigned(Kernel.Screen.FocusedForm) then
     426//      Kernel.Screen.FocusedForm.HandleMessage(NewMessage);
    420427  finally
    421428    NewMessage.Destroy;
  • os/trunk/Xvcl/Xvcl.Classes.pas

    r7 r14  
    168168constructor TComponent.Create;
    169169begin
     170  FName := ClassName;
    170171  FComponents := TObjectList<TComponent>.Create;
    171172end;
  • os/trunk/Xvcl/Xvcl.Controls.pas

    r13 r14  
    3333    States: TKeyStateSet;
    3434  end;
     35
     36  TMouseNotifyEvent = procedure (Sender: TObject; Position: TPoint;
     37    Buttons: TMouseButtonSet) of object;
    3538
    3639  TControlCanvas = class(TCanvas)
     
    5760    FOnClick: TNotifyEvent;
    5861    FColor: TColor;
    59     FOnMouseDown: TNotifyEvent;
    60     FOnMouseUp: TNotifyEvent;
     62    FOnMouseDown: TMouseNotifyEvent;
     63    FOnMouseUp: TMouseNotifyEvent;
     64    FOnMouseMove: TMouseNotifyEvent;
    6165    FOnKeyPress: TNotifyEvent;
    6266    FFocused: Boolean;
     
    6973    function HandleMessage(Message: TMessage): Boolean; virtual;
    7074  public
    71     Move: TControlMove;
    7275    function ClientToScreen(Position: TPoint): TPoint; virtual;
    7376    function ScreenToClient(Position: TPoint): TPoint; virtual;
     
    8386    property Focused: Boolean read FFocused write SetFocused;
    8487    property OnClick: TNotifyEvent read FOnClick write FOnClick;
    85     property OnMouseDown: TNotifyEvent read FOnMouseDown write FOnMouseDown;
    86     property OnMouseUp: TNotifyEvent read FOnMouseUp write FOnMouseUp;
     88    property OnMouseDown: TMouseNotifyEvent read FOnMouseDown write FOnMouseDown;
     89    property OnMouseUp: TMouseNotifyEvent read FOnMouseUp write FOnMouseUp;
     90    property OnMouseMove: TMouseNotifyEvent read FOnMouseMove write FOnMouseMove;
    8791    property OnKeyPress: TNotifyEvent read FOnKeyPress write FOnKeyPress;
    8892  end;
     
    119123    procedure Paint; override;
    120124    property Caption: string read FCaption write SetCaption;
     125    constructor Create; override;
    121126  end;
    122127
     
    147152begin
    148153  inherited;
    149   Move := TControlMove.Create;
    150154  FColor := clWhite;
    151155end;
     
    153157destructor TControl.Destroy;
    154158begin
    155   Move.Destroy;
    156159  if Assigned(FCanvas) then FCanvas.Destroy;
    157160  inherited;
     
    176179begin
    177180  Result := False;
     181  if Message is TMessageMouseDown then
     182  with TMessageMouseDown(Message) do begin
     183    if Assigned(FOnMouseDown) then begin
     184      FOnMouseDown(Self, Position, Buttons);
     185      Result := True;
     186    end;
     187  end else
     188  if Message is TMessageMouseUp then
     189  with TMessageMouseUp(Message) do begin
     190    if Assigned(FOnMouseUp) then begin
     191      FOnMouseUp(Self, Position, Buttons);
     192      Result := True;
     193    end;
     194  end else
     195  if Message is TMessageMouseMove then
     196  with TMessageMouseMove(Message) do begin
     197    if Assigned(FOnMouseMove) then begin
     198      FOnMouseMove(Self, Position, Buttons);
     199      Result := True;
     200    end;
     201  end;
    178202end;
    179203
    180204procedure TControl.Paint;
    181205begin
     206  if Color <> clNone then
    182207  with Canvas do begin
    183208    Brush.Color := Color;
     
    189214begin
    190215  Result := Position.Substract(Bounds.TopLeft);
    191   if Assigned(Parent) then Result := Parent.ClientToScreen(Result);
     216  if Assigned(Parent) then Result := Parent.ScreenToClient(Result);
    192217end;
    193218
     
    220245begin
    221246  Result := False;
    222   if Message is TMessageMouseDown then begin
    223     if Assigned(FOnMouseDown) then FOnMouseDown(Self);
     247  if Message is TMessageMouseDown then
     248  with TMessageMouseDown(Message) do begin
     249    if Assigned(FOnMouseDown) then FOnMouseDown(Self, Position, Buttons);
    224250    Color := clGray;
    225251    Paint;
    226252    Result := True;
    227253  end else
    228   if Message is TMessageMouseUp then begin
    229     if Assigned(FOnMouseUp) then FOnMouseUp(Self);
     254  if Message is TMessageMouseUp then
     255  with TMessageMouseUp(Message) do begin
     256    if Assigned(FOnMouseUp) then FOnMouseUp(Self, Position, Buttons);
    230257    Color := clSilver;
    231258    Paint;
     
    321348      end;
    322349  end;
     350  if not Result then inherited;
    323351end;
    324352
     
    332360
    333361{ TLabel }
     362
     363constructor TLabel.Create;
     364begin
     365  inherited;
     366  Color := clNone;
     367end;
    334368
    335369procedure TLabel.Paint;
  • os/trunk/Xvcl/Xvcl.Forms.pas

    r13 r14  
    88type
    99  TBorderStyle = (bsNormal, bsNone);
     10  TPanel = class;
     11  TForm = class;
     12  TApplication = class;
     13
     14  TFormTitleBar = class
     15  private
     16    function GetForm: TForm;
     17    procedure SetForm(const Value: TForm);
     18    procedure DoMaximize(Sender: TObject);
     19    procedure DoClose(Sender: TObject);
     20    procedure DoMouseDown(Sender: TObject; Position: TPoint; Buttons: TMouseButtonSet);
     21  public
     22  const
     23    TitleBarHeight = 24;
     24  var
     25    MainLabel: TLabel;
     26    Panel: TPanel;
     27    MaximizeButton: TButton;
     28    MinimizeButton: TButton;
     29    CloseButton: TButton;
     30    procedure Paint;
     31    constructor Create;
     32    destructor Destroy; override;
     33    property Form: TForm read GetForm write SetForm;
     34  end;
    1035
    1136  TForm = class(TWinControl)
     
    1843    function GetVideoDevice: TVideoDevice; override;
    1944  public
    20   const
    21     TitleBarHeight = 24;
    2245  var
    2346    Screen: TObject; // TScreen;
     47    Application: TApplication;
    2448    Caption: string;
     49    TitleBar: TFormTitleBar;
    2550    function HandleMessage(Message: TMessage): Boolean; override;
    2651    procedure Paint; override;
     52    procedure Close;
     53    constructor Create; override;
     54    destructor Destroy; override;
    2755    property Focused: Boolean read FFocused write SetFocused;
    2856    property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle;
     
    3058
    3159  TPanel = class(TWinControl)
     60  protected
     61    function HandleMessage(Message: TMessage): Boolean; override;
     62  public
    3263    Caption: string;
    3364    procedure Paint; override;
     
    4172    Forms: TList<TForm>;
    4273    MainForm: TForm;
     74    Terminated: Boolean;
    4375    function HandleMessage(Message: TMessage): Boolean; virtual;
    4476    procedure Run; virtual;
     
    6698procedure TApplication.Terminate;
    6799begin
    68 
     100  Terminated := True;
    69101end;
    70102
    71103{ TForm }
     104
     105procedure TForm.Close;
     106begin
     107  if Application.MainForm = Self then
     108    Application.Terminate;
     109end;
     110
     111constructor TForm.Create;
     112begin
     113  inherited;
     114  TitleBar := TFormTitleBar.Create;
     115end;
     116
     117destructor TForm.Destroy;
     118begin
     119  TitleBar.Free;
     120  inherited;
     121end;
    72122
    73123function TForm.GetVideoDevice: TVideoDevice;
     
    78128
    79129function TForm.HandleMessage(Message: TMessage): Boolean;
    80 var
    81   TitleBarBounds: TRectangle;
    82 begin
    83   Result := False;
    84   if Message is TMessageMouseDown then
    85   with TMessageMouseDown(Message) do begin
    86     TitleBarBounds := TRectangle.Create(0, 0, Bounds.Width, TitleBarHeight);
    87     Focused := True;
    88     if (BorderStyle = bsNormal) and TitleBarBounds.Contains(ScreenToClient(Position)) then begin
    89       Move.StartControlPos := Bounds.TopLeft;
    90       Move.StartMousePos := Position;
    91       Move.Active := True;
    92       Result := True;
    93     end;
    94   end else
    95   if Message is TMessageMouseUp then
    96   with TMessageMouseUp(Message) do begin
    97     Move.Active := False;
    98   end else
    99   if Message is TMessageMouseMove then
    100   with TMessageMouseUp(Message) do begin
    101     if Move.Active then begin
    102       Bounds.TopLeft := Move.StartControlPos + (Position - Move.StartMousePos);
    103       TScreen(Screen).Paint;
    104     end;
    105   end;
    106   if not Result then inherited;
     130begin
     131  inherited;
    107132end;
    108133
    109134procedure TForm.Paint;
    110135begin
     136  if BorderStyle = bsNormal then begin
     137    TitleBar.Form := Self;
     138    TitleBar.Paint;
     139  end;
    111140  inherited;
    112141  with Canvas do begin
    113142    if BorderStyle = bsNormal then begin
    114       if Focused then Brush.Color := clLightBlue else
    115         Brush.Color := clSilver;
    116       FillRect(TRectangle.Create(0, 0, Bounds.Width - 1, TitleBarHeight));
    117143      MoveTo(TPoint.Create(0, 0));
    118144      LineTo(TPoint.Create(Bounds.Width - 1, 0));
     
    120146      LineTo(TPoint.Create(0, Bounds.Height - 1));
    121147      LineTo(TPoint.Create(0, 0));
    122       MoveTo(TPoint.Create(0, TitleBarHeight));
    123       LineTo(TPoint.Create(Bounds.Width - 1, TitleBarHeight));
    124       TextOut(TPoint.Create((Bounds.Width - GetTextSize(Caption).X) div 2,
    125         (TitleBarHeight - GetTextSize(Caption).Y) div 2), Caption);
    126148    end;
    127149  end;
     
    142164
    143165{ TPanel }
     166
     167function TPanel.HandleMessage(Message: TMessage): Boolean;
     168begin
     169  inherited;
     170end;
    144171
    145172procedure TPanel.Paint;
     
    152179    LineTo(TPoint.Create(0, Bounds.Height - 1));
    153180    LineTo(TPoint.Create(0, 0));
    154     TextOut(TPoint.Create((Bounds.Width - GetTextSize(Caption).X) div 2,
    155       (Bounds.Height - GetTextSize(Caption).Y) div 2), Caption);
    156   end;
     181    if Caption <> '' then
     182      TextOut(TPoint.Create((Bounds.Width - GetTextSize(Caption).X) div 2,
     183        (Bounds.Height - GetTextSize(Caption).Y) div 2), Caption);
     184  end;
     185end;
     186
     187{ TFormTitleBar }
     188
     189constructor TFormTitleBar.Create;
     190begin
     191  inherited;
     192  Panel := TPanel.Create;
     193  Panel.Visible := True;
     194  Panel.OnMouseDown := DoMouseDown;
     195
     196  MainLabel := TLabel.Create;
     197  MainLabel.Parent := Panel;
     198  MainLabel.Visible := True;
     199
     200  CloseButton := TButton.Create;
     201  CloseButton.Parent := Panel;
     202  CloseButton.Caption := 'X';
     203  CloseButton.Visible := True;
     204  CloseButton.OnClick := DoClose;
     205
     206  MaximizeButton := TButton.Create;
     207  MaximizeButton.Parent := Panel;
     208  MaximizeButton.Caption := 'M';
     209  MaximizeButton.Visible := True;
     210  MaximizeButton.OnClick := DoMaximize;
     211
     212  MinimizeButton := TButton.Create;
     213  MinimizeButton.Parent := Panel;
     214  MinimizeButton.Caption := 'V';
     215  MinimizeButton.Visible := True;
     216end;
     217
     218destructor TFormTitleBar.Destroy;
     219begin
     220  MainLabel.Free;
     221  MinimizeButton.Free;
     222  MaximizeButton.Free;
     223  CloseButton.Free;
     224  Panel.Free;
     225  inherited;
     226end;
     227
     228procedure TFormTitleBar.DoClose(Sender: TObject);
     229begin
     230  Form.Close;
     231end;
     232
     233procedure TFormTitleBar.DoMaximize(Sender: TObject);
     234begin
     235  Form.Bounds := TRectangle.Create(0, 0, TScreen(Form.Screen).Size.X, TScreen(Form.Screen).Size.Y);
     236  Form.Paint;
     237end;
     238
     239procedure TFormTitleBar.DoMouseDown(Sender: TObject; Position: TPoint; Buttons: TMouseButtonSet);
     240begin
     241  Form.Focused := True;
     242  if (Form.BorderStyle = bsNormal) then begin
     243    TScreen(Form.Screen).FormMove.StartControlPos := Form.Bounds.TopLeft;
     244    TScreen(Form.Screen).FormMove.StartMousePos := Position;
     245    TScreen(Form.Screen).FormMove.Control := Form;
     246    TScreen(Form.Screen).FormMove.Active := True;
     247  end;
     248end;
     249
     250function TFormTitleBar.GetForm: TForm;
     251begin
     252  Result := TForm(Panel.Parent);
     253end;
     254
     255procedure TFormTitleBar.Paint;
     256begin
     257  if Assigned(Form) then begin
     258    Panel.Bounds := TRectangle.Create(0, 0, Form.Bounds.Width, TitleBarHeight);
     259    CloseButton.Bounds := TRectangle.Create(Panel.Bounds.Width - TitleBarHeight,
     260      2, TitleBarHeight - 4, TitleBarHeight - 4);
     261    MaximizeButton.Bounds := TRectangle.Create(Panel.Bounds.Width - 2 * TitleBarHeight,
     262      2, TitleBarHeight - 4, TitleBarHeight - 4);
     263    MinimizeButton.Bounds := TRectangle.Create(Panel.Bounds.Width - 3 * TitleBarHeight,
     264      2, TitleBarHeight - 4, TitleBarHeight - 4);
     265   if Form.Focused then Panel.Color := clLightBlue else
     266      Panel.Color := clSilver;
     267    MainLabel.Caption := Form.Caption;
     268    MainLabel.Bounds := TRectangle.Create(0, 0, Panel.Bounds.Width, Panel.Bounds.Height);
     269  end;
     270end;
     271
     272procedure TFormTitleBar.SetForm(const Value: TForm);
     273begin
     274  Panel.Parent := Value;
    157275end;
    158276
Note: See TracChangeset for help on using the changeset viewer.