mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-01 02:32:40 +02:00

* Implemented LCL side of imagelist * restructured rawimage to more OO Merged revisions 11289-11617 via svnmerge from http://svn.freepascal.org/svn/lazarus/branches/marc-lcl ........ r11289 | marc | 2007-06-06 22:50:05 +0200 (Wed, 06 Jun 2007) | 1 line private branch for bitmap rework ........ r11290 | marc | 2007-06-06 23:30:09 +0200 (Wed, 06 Jun 2007) | 2 lines * Initial linux and win32 implementation ........ r11291 | paul | 2007-06-07 03:20:11 +0200 (Thu, 07 Jun 2007) | 3 lines - fix compilation with fpc 2.3.1 - remove unneded code for converting cursor mask - enabled loading of standard windows status icons instead of LCL ........ r11292 | paul | 2007-06-07 11:03:27 +0200 (Thu, 07 Jun 2007) | 1 line - some bugs with mask and alpha ........ r11299 | marc | 2007-06-08 00:59:26 +0200 (Fri, 08 Jun 2007) | 2 lines * force alpha channel when PNG has alpha ........ r11302 | paul | 2007-06-09 04:45:12 +0200 (Sat, 09 Jun 2007) | 1 line - fix black rectangles instead of manu item images ........ r11303 | paul | 2007-06-09 04:46:14 +0200 (Sat, 09 Jun 2007) | 1 line formatting ........ r11309 | marc | 2007-06-11 02:25:07 +0200 (Mon, 11 Jun 2007) | 3 lines * Added alpha premultiply * Published Colorbox selection property ........ r11310 | paul | 2007-06-11 19:10:18 +0200 (Mon, 11 Jun 2007) | 1 line misc ........ r11312 | marc | 2007-06-12 01:44:03 +0200 (Tue, 12 Jun 2007) | 2 lines * start with carbon ........ r11313 | paul | 2007-06-12 14:02:48 +0200 (Tue, 12 Jun 2007) | 1 line - BitBtn glyph transparency ........ r11315 | paul | 2007-06-13 05:20:40 +0200 (Wed, 13 Jun 2007) | 1 line - problems with internal bitmap saving/loading (is was 24bpp when 32bpp needed) ........ r11319 | paul | 2007-06-14 06:32:04 +0200 (Thu, 14 Jun 2007) | 1 line - More LCL way of painting images through ThemeServices ........ r11320 | paul | 2007-06-14 06:32:56 +0200 (Thu, 14 Jun 2007) | 1 line - ability to override bitbtn glyph to nothing ........ r11321 | paul | 2007-06-14 06:34:49 +0200 (Thu, 14 Jun 2007) | 1 line painting headercontrol images through ThemeServices ........ r11325 | paul | 2007-06-17 10:14:27 +0200 (Sun, 17 Jun 2007) | 1 line fixing painting of 32bpp bitmaps with no Alpha ........ r11326 | paul | 2007-06-17 10:16:00 +0200 (Sun, 17 Jun 2007) | 1 line missed file ........ r11337 | paul | 2007-06-20 03:44:47 +0200 (Wed, 20 Jun 2007) | 3 lines - revert previous commit - create 24bpp bitmaps by default ........ r11342 | marc | 2007-06-21 01:47:30 +0200 (Thu, 21 Jun 2007) | 3 lines * Added Alpha support on Carbon * Simplified win32 rawimage_fromdevice ........ r11343 | paul | 2007-06-21 04:36:28 +0200 (Thu, 21 Jun 2007) | 1 line - adopt gtk2 code ........ r11344 | paul | 2007-06-21 04:41:41 +0200 (Thu, 21 Jun 2007) | 1 line make gtk2 work ........ r11353 | paul | 2007-06-22 10:12:19 +0200 (Fri, 22 Jun 2007) | 1 line - default WS imagelist implementation ........ r11358 | marc | 2007-06-23 13:29:06 +0200 (Sat, 23 Jun 2007) | 2 lines * Implemented MaskBlit ........ r11359 | paul | 2007-06-23 20:02:52 +0200 (Sat, 23 Jun 2007) | 1 line draw new imagelist bitmap on widget canvas ........ r11371 | marc | 2007-06-25 23:50:13 +0200 (Mon, 25 Jun 2007) | 2 lines * Rawimage rework ........ r11372 | marc | 2007-06-25 23:51:00 +0200 (Mon, 25 Jun 2007) | 2 lines + Added header ........ r11373 | marc | 2007-06-26 00:05:55 +0200 (Tue, 26 Jun 2007) | 2 lines * Swapped RGBA <-> ARGB defualt format since most widgetsets use ARGB ........ r11374 | marc | 2007-06-26 00:09:36 +0200 (Tue, 26 Jun 2007) | 2 lines * added ........ r11462 | marc | 2007-07-12 00:16:02 +0200 (Thu, 12 Jul 2007) | 2 lines + added header ........ r11463 | marc | 2007-07-12 00:18:49 +0200 (Thu, 12 Jul 2007) | 2 lines * Added alpha/masked strechblt support ........ r11464 | marc | 2007-07-12 00:21:27 +0200 (Thu, 12 Jul 2007) | 2 lines * create DIBSection instead of DIBitmap ........ r11502 | marc | 2007-07-14 00:23:42 +0200 (Sat, 14 Jul 2007) | 2 lines * Fixed transparentcolor after loading bitmap ........ r11505 | marc | 2007-07-14 15:10:56 +0200 (Sat, 14 Jul 2007) | 2 lines - Removed ARGB dataconversion, internal format is by default the same now ........ r11531 | marc | 2007-07-17 01:23:34 +0200 (Tue, 17 Jul 2007) | 2 lines * changed TRawImage into object ........ r11533 | paul | 2007-07-17 05:10:31 +0200 (Tue, 17 Jul 2007) | 3 lines - change several occurrence of FillChar(..TRawImageDescription..) with call to Init - change imagelist defines to use old imagelist (new is crashes ide) - change TWin32ThemeServices to use old imagelist ........ r11534 | paul | 2007-07-17 05:19:02 +0200 (Tue, 17 Jul 2007) | 3 lines - change several occurrence of FillChar(..TRawImageDescription..) with call to Init in Qt widgetset - change TRawImageDescription.IsEqual and TRawImage.IsEqual ........ r11535 | paul | 2007-07-17 05:23:53 +0200 (Tue, 17 Jul 2007) | 1 line - change several occurrence of FillChar(..TRawImageDescription..) with call to Init in wince widgetset ........ r11554 | marc | 2007-07-18 00:10:11 +0200 (Wed, 18 Jul 2007) | 2 lines * fixed compilation on 2.0.4 ........ r11555 | marc | 2007-07-18 00:10:44 +0200 (Wed, 18 Jul 2007) | 2 lines * fixed compilation ........ r11556 | marc | 2007-07-18 00:11:43 +0200 (Wed, 18 Jul 2007) | 2 lines * fixed fillchar on TRawImage object ........ r11572 | marc | 2007-07-19 01:41:35 +0200 (Thu, 19 Jul 2007) | 2 lines * fixed crash when object has vmt ........ r11573 | marc | 2007-07-19 01:42:14 +0200 (Thu, 19 Jul 2007) | 2 lines * Made TRawimage compatible with record again ........ r11580 | marc | 2007-07-20 01:33:20 +0200 (Fri, 20 Jul 2007) | 2 lines * enabled newimagelist ........ r11581 | marc | 2007-07-20 01:33:48 +0200 (Fri, 20 Jul 2007) | 2 lines * fixed font ........ git-svn-id: trunk@11861 -
392 lines
9.3 KiB
PHP
392 lines
9.3 KiB
PHP
{%MainUnit ../comctrls.pp}
|
|
|
|
{******************************************************************************
|
|
TCustomHeaderControl
|
|
******************************************************************************
|
|
|
|
*****************************************************************************
|
|
* *
|
|
* This file is part of the Lazarus Component Library (LCL) *
|
|
* *
|
|
* See the file COPYING.modifiedLGPL, included in this distribution, *
|
|
* for details about the copyright. *
|
|
* *
|
|
* This program is distributed in the hope that it will be useful, *
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
|
* *
|
|
*****************************************************************************
|
|
|
|
}
|
|
{ TCustomHeaderControl }
|
|
|
|
procedure TCustomHeaderControl.SetImages(const AValue: TCustomImageList);
|
|
begin
|
|
FImages := AValue;
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.SetSections(const AValue: THeaderSections);
|
|
begin
|
|
FSections := AValue;
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.UpdateSection(Index: Integer);
|
|
begin
|
|
// repaint item
|
|
Repaint;
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.UpdateSections;
|
|
{var
|
|
i: integer;}
|
|
begin
|
|
{ for i := 0 to Sections.Count - 1 do
|
|
UpdateSection(i);
|
|
}
|
|
Repaint;
|
|
end;
|
|
|
|
function TCustomHeaderControl.CreateSection: THeaderSection;
|
|
var
|
|
HeaderSectionClass: THeaderSectionClass;
|
|
begin
|
|
HeaderSectionClass := THeaderSection;
|
|
if Assigned(FOnCreateSectionClass) then
|
|
FOnCreateSectionClass(Self, HeaderSectionClass);
|
|
Result := HeaderSectionClass.Create(Sections);
|
|
end;
|
|
|
|
function TCustomHeaderControl.CreateSections: THeaderSections;
|
|
begin
|
|
Result := THeaderSections.Create(Self);
|
|
end;
|
|
|
|
constructor TCustomHeaderControl.Create(AOwner: TComponent);
|
|
begin
|
|
inherited Create(AOwner);
|
|
FSections := CreateSections;
|
|
ControlStyle := ControlStyle + [csCaptureMouse, csClickEvents, csNoFocus, csOpaque] -
|
|
[csSetCaption];
|
|
SetInitialBounds(0, 0, 170, 30);
|
|
end;
|
|
|
|
destructor TCustomHeaderControl.Destroy;
|
|
begin
|
|
FSections.Free;
|
|
inherited Destroy;
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.Click;
|
|
var
|
|
Index: Integer;
|
|
begin
|
|
inherited Click;
|
|
Index := GetSectionAt(ScreenToClient(Mouse.CursorPos));
|
|
if Index <> -1 then
|
|
SectionClick(Sections[Index]);
|
|
end;
|
|
|
|
function TCustomHeaderControl.GetSectionAt(P: TPoint): Integer;
|
|
var
|
|
i: integer;
|
|
begin
|
|
Result := -1;
|
|
for i := 0 to Sections.Count - 1 do
|
|
if (Sections[i].Left <= P.X) and (Sections[i].Right >= P.X) then
|
|
begin
|
|
Result := i;
|
|
break;
|
|
end;
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.Notification(AComponent: TComponent;
|
|
Operation: TOperation);
|
|
begin
|
|
inherited Notification(AComponent, Operation);
|
|
if (Operation = opRemove) and (AComponent = FImages) then
|
|
Images := nil;
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.SectionClick(Section: THeaderSection);
|
|
begin
|
|
if Assigned(FOnSectionClick) then
|
|
OnSectionClick(Self, Section);
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.MouseEnter;
|
|
begin
|
|
inherited MouseEnter;
|
|
if not (csDesigning in ComponentState) then
|
|
begin
|
|
FMouseInControl := True;
|
|
UpdateState;
|
|
end;
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.MouseLeave;
|
|
begin
|
|
inherited MouseLeave;
|
|
if not (csDesigning in ComponentState) then
|
|
begin
|
|
FMouseInControl := False;
|
|
FDown := False;
|
|
UpdateState;
|
|
end;
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.MouseDown(Button: TMouseButton;
|
|
Shift: TShiftState; X, Y: Integer);
|
|
begin
|
|
inherited MouseDown(Button, Shift, X, Y);
|
|
if not (csDesigning in ComponentState) then
|
|
begin
|
|
FDown := True;
|
|
FDownPoint := Point(X, Y);
|
|
UpdateState;
|
|
end;
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.MouseMove(Shift: TShiftState; X, Y: Integer);
|
|
begin
|
|
inherited MouseMove(Shift, X, Y);
|
|
if not (csDesigning in ComponentState) then
|
|
begin
|
|
if FDown then
|
|
begin
|
|
if GetSectionAt(Point(X, Y)) <> GetSectionAt(FDownPoint) then
|
|
FDown := False;
|
|
end;
|
|
UpdateState;
|
|
end;
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.MouseUp(Button: TMouseButton;
|
|
Shift: TShiftState; X, Y: Integer);
|
|
begin
|
|
inherited MouseUp(Button, Shift, X, Y);
|
|
begin
|
|
FDown := False;
|
|
UpdateState;
|
|
end;
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.UpdateState;
|
|
var
|
|
i, Index: Integer;
|
|
MaxState: THeaderSectionState;
|
|
P: TPoint;
|
|
begin
|
|
MaxState := hsNormal;
|
|
if Enabled then
|
|
if FDown then
|
|
MaxState := hsPressed
|
|
else
|
|
if FMouseInControl then
|
|
MaxState := hsHot;
|
|
|
|
P := ScreenToClient(Mouse.CursorPos);
|
|
Index := GetSectionAt(P);
|
|
for i := 0 to Sections.Count - 1 do
|
|
if (i <> Index) then
|
|
Sections[i].State := hsNormal
|
|
else
|
|
Sections[i].State := MaxState;
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.Paint;
|
|
var
|
|
Details: TThemedElementDetails;
|
|
i: integer;
|
|
begin
|
|
inherited Paint;
|
|
FPaintRect := Rect(0, 0, Width, Height);
|
|
|
|
for i := 0 to Sections.Count - 1 do
|
|
PaintSection(i);
|
|
|
|
if Sections.Count > 0 then
|
|
FPaintRect.Left := Sections[Sections.Count - 1].Right;
|
|
Details := ThemeServices.GetElementDetails(thHeaderItemRightNormal);
|
|
ThemeServices.DrawElement(Canvas.Handle, Details, FPaintRect);
|
|
end;
|
|
|
|
procedure TCustomHeaderControl.PaintSection(Index: Integer);
|
|
const
|
|
AlignmentMap: array[TAlignment] of Cardinal =
|
|
(
|
|
DT_LEFT,
|
|
DT_RIGHT,
|
|
DT_CENTER
|
|
);
|
|
HeaderStateMap: array[THeaderSectionState] of TThemedHeader =
|
|
(
|
|
thHeaderItemNormal,
|
|
thHeaderItemHot,
|
|
thHeaderItemPressed
|
|
);
|
|
var
|
|
ARect: TRect;
|
|
Details: TThemedElementDetails;
|
|
Section: THeaderSection;
|
|
begin
|
|
Section := Sections[Index];
|
|
ARect := FPaintRect;
|
|
ARect.Left := FPaintRect.Left + Section.Left;
|
|
ARect.Right := FPaintRect.Left + Section.Right;
|
|
|
|
Details := ThemeServices.GetElementDetails(HeaderStateMap[Section.State]);
|
|
|
|
ThemeServices.DrawElement(Canvas.Handle, Details, ARect);
|
|
ARect := ThemeServices.ContentRect(Canvas.Handle, Details, ARect);
|
|
|
|
if (Images <> nil) and (Section.ImageIndex <> -1) then
|
|
begin
|
|
inc(ARect.Left);
|
|
ThemeServices.DrawIcon(Canvas, Details,
|
|
Point(ARect.Left, (ARect.Top + ARect.Bottom - Images.Height) div 2),
|
|
Images, Section.ImageIndex);
|
|
inc(ARect.Left, Images.Width + 2);
|
|
end;
|
|
|
|
if Section.Text <> '' then
|
|
ThemeServices.DrawText(Canvas, Details, Section.Text, Arect, AlignmentMap[Section.Alignment] or DT_VCENTER or DT_SINGLELINE, 0);
|
|
end;
|
|
|
|
{ THeaderSections }
|
|
|
|
function THeaderSections.GetItem(Index: Integer): THeaderSection;
|
|
begin
|
|
Result := THeaderSection(inherited GetItem(Index));
|
|
end;
|
|
|
|
procedure THeaderSections.SetItem(Index: Integer; Value: THeaderSection);
|
|
begin
|
|
inherited SetItem(Index, Value);
|
|
end;
|
|
|
|
function THeaderSections.GetOwner: TPersistent;
|
|
begin
|
|
Result := FHeaderControl;
|
|
end;
|
|
|
|
procedure THeaderSections.Update(Item: TCollectionItem);
|
|
begin
|
|
if Item <> nil then
|
|
FHeaderControl.UpdateSection(Item.Index)
|
|
else
|
|
FHeaderControl.UpdateSections;
|
|
end;
|
|
|
|
constructor THeaderSections.Create(HeaderControl: TCustomHeaderControl);
|
|
begin
|
|
inherited Create(THeaderSection);
|
|
FHeaderControl := HeaderControl;
|
|
end;
|
|
|
|
function THeaderSections.Add: THeaderSection;
|
|
begin
|
|
Result := AddItem(nil, -1);
|
|
end;
|
|
|
|
function THeaderSections.AddItem(Item: THeaderSection; Index: Integer): THeaderSection;
|
|
begin
|
|
if Item = nil then
|
|
Result := FHeaderControl.CreateSection;
|
|
|
|
Result.Collection := Self;
|
|
if Index < Count then
|
|
Index := Count - 1;
|
|
Result.Index := Index;
|
|
end;
|
|
|
|
function THeaderSections.Insert(Index: Integer): THeaderSection;
|
|
begin
|
|
Result := AddItem(nil, Index);
|
|
end;
|
|
|
|
{ THeaderSection }
|
|
|
|
function THeaderSection.GetLeft: Integer;
|
|
var
|
|
i: integer;
|
|
begin
|
|
Result := 0;
|
|
for i := 0 to Index - 1 do
|
|
Inc(Result, THeaderSections(Collection).Items[i].Width);
|
|
end;
|
|
|
|
function THeaderSection.GetRight: Integer;
|
|
begin
|
|
Result := GetLeft + Width;
|
|
end;
|
|
|
|
procedure THeaderSection.SetAlignment(const AValue: TAlignment);
|
|
begin
|
|
if FAlignment <> AValue then
|
|
begin
|
|
FAlignment := AValue;
|
|
Changed(False);
|
|
end;
|
|
end;
|
|
|
|
procedure THeaderSection.SetState(const AValue: THeaderSectionState);
|
|
begin
|
|
if FState <> AValue then
|
|
begin
|
|
FState := AValue;
|
|
Changed(False);
|
|
end;
|
|
end;
|
|
|
|
procedure THeaderSection.SetText(const Value: string);
|
|
begin
|
|
if FText <> Value then
|
|
begin
|
|
FText := Value;
|
|
Changed(False);
|
|
end;
|
|
end;
|
|
|
|
procedure THeaderSection.SetWidth(Value: Integer);
|
|
begin
|
|
if FWidth <> Value then
|
|
begin
|
|
FWidth := Value;
|
|
Changed(False);
|
|
end;
|
|
end;
|
|
|
|
procedure THeaderSection.SetImageIndex(const Value: TImageIndex);
|
|
begin
|
|
if FImageIndex <> Value then
|
|
begin
|
|
FImageIndex := Value;
|
|
Changed(False);
|
|
end;
|
|
end;
|
|
|
|
constructor THeaderSection.Create(ACollection: TCollection);
|
|
begin
|
|
inherited Create(ACollection);
|
|
FWidth := 30;
|
|
FImageIndex := -1;
|
|
FText := '';
|
|
FAlignment := taLeftJustify;
|
|
FState := hsNormal;
|
|
end;
|
|
|
|
procedure THeaderSection.Assign(Source: TPersistent);
|
|
var
|
|
SourceSection: THeaderSection absolute Source;
|
|
begin
|
|
if Source is THeaderSection then
|
|
begin
|
|
FImageIndex := SourceSection.ImageIndex;
|
|
FText := SourceSection.Text;
|
|
FWidth := SourceSection.Width;
|
|
Changed(False);
|
|
end
|
|
else
|
|
inherited Assign(Source);
|
|
end;
|