Changeset 436 for CoolBar


Ignore:
Timestamp:
Nov 19, 2012, 2:32:37 PM (12 years ago)
Author:
chronos
Message:
  • Modified: Better handlig of TCoolBar resize.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • CoolBar/UCoolBar.pas

    r422 r436  
    66
    77uses
    8   Classes, SysUtils, Contnrs, Controls, SpecializedList;
     8  Classes, SysUtils, Controls, SpecializedList, Dialogs, ComCtrls, Forms;
    99
    1010type
     
    3636    FBands: TListObject;
    3737    FRowSize: Integer;
     38    DisableResize: Boolean;
    3839    function GetBand(Index: Integer): TCoolBand;
    3940    procedure SetBand(Index: Integer; AValue: TCoolBand);
    4041    procedure BandsUpdate(Sender: TObject);
     42    procedure AsyncResize(Param: PtrInt);
     43    procedure ControlResize(Sender: TObject);
    4144    procedure SetRowSize(AValue: Integer);
     45    function SearchBand(Control: TControl): TCoolBand;
     46  protected
    4247    procedure Paint; override;
    43     function SearchBand(Control: TControl): TCoolBand;
    4448    procedure Resize; override;
    4549  public
     
    5660    property Color;
    5761    property RowSize: Integer read FRowSize write SetRowSize;
     62    property OnResize;
    5863  end;
    5964
     
    116121end;
    117122
     123procedure TCoolBar.AsyncResize(Param: PtrInt);
     124begin
     125  Arrange;
     126end;
     127
     128procedure TCoolBar.ControlResize(Sender: TObject);
     129begin
     130  Application.QueueAsyncCall(AsyncResize, 0);
     131end;
     132
    118133procedure TCoolBar.SetRowSize(AValue: Integer);
    119134begin
     
    133148begin
    134149  inherited InsertControl(AControl, Index);
    135   NewBand := TCoolBand(FBands.AddNew(TCoolBand.Create));
     150  AControl.Align := alCustom;
     151  NewBand := TCoolBand.Create;
    136152  NewBand.FCoolBar := Self;
    137153  NewBand.Control := AControl;
     154  NewBand.Control.OnResize := ControlResize;
     155  FBands.Insert(Index, NewBand);
    138156  Arrange;
    139157end;
     
    145163  Band := SearchBand(AControl);
    146164  FBands.Remove(Band);
     165  AControl.OnResize := nil;
    147166  inherited RemoveControl(AControl);
    148167  Arrange;
     
    162181begin
    163182  inherited Resize;
    164 // Arrange;
     183  //if not DisableResize then Arrange;
    165184end;
    166185
     
    178197destructor TCoolBar.Destroy;
    179198begin
    180   FBands.Free;
     199  FreeAndNil(FBands);
    181200  inherited;
    182201end;
     
    188207  NewHeight: Integer;
    189208begin
     209  try
     210    DisableResize := True;
    190211  X := 0;
    191212  Y := 0;
     
    194215    if Assigned(Control) and Control.Visible then begin
    195216      if (CoolBar.Width - X) > Control.Width then begin
     217        // Place CoolBand right to the previous
    196218        if (Control.Left <> X) or (Control.Top <> Y) or
    197219          (Control.Width <> Control.Width) or (Control.Height <> RowSize) then
     
    199221        Inc(X, Control.Width);
    200222      end else begin
     223        // CoolBand do not fit in gap, place to next row
     224        if I > 0 then begin
     225          // Enlarge previous band
     226          with TCoolBand(FBands[I - 1]).Control do begin
     227            SetBounds(Left, Top, CoolBar.Width - Left, Height);
     228          end;
     229        end;
    201230        Inc(Y, RowSize);
    202231        X := 0;
     
    212241    else NewHeight := RowSize;
    213242  if NewHeight <> Height then Height := NewHeight;
     243  finally
     244    DisableResize := False;
     245  end;
    214246end;
    215247
Note: See TracChangeset for help on using the changeset viewer.