mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-05-21 01:23:50 +02:00

------------------------------------------------------------------------ r19294 | paul | 2009-04-10 11:17:35 +0800 (Птн, 10 Апр 2009) | 1 line lcl, win32: start optimizations: imglist (all), controls (all), combtrls (statubar) ------------------------------------------------------------------------ r19305 | martin | 2009-04-10 21:53:27 +0800 (Птн, 10 Апр 2009) | 1 line Moved "DoneRegisterCheck" to global LCL ------------------------------------------------------------------------ r19306 | martin | 2009-04-10 22:14:57 +0800 (Птн, 10 Апр 2009) | 1 line Moved "DoneRegisterCheck" to global LCL (more) ------------------------------------------------------------------------ r19307 | martin | 2009-04-10 22:22:44 +0800 (Птн, 10 Апр 2009) | 1 line changed case true => True ------------------------------------------------------------------------ r19308 | paul | 2009-04-10 22:28:28 +0800 (Птн, 10 Апр 2009) | 1 line fix file case ------------------------------------------------------------------------ r19311 | martin | 2009-04-10 23:09:16 +0800 (Птн, 10 Апр 2009) | 1 line Moved Registration of TCustomCalendar ------------------------------------------------------------------------ r19312 | martin | 2009-04-10 23:28:03 +0800 (Птн, 10 Апр 2009) | 1 line Moved PropertyToSkip for TCalender ------------------------------------------------------------------------ r19314 | paul | 2009-04-10 23:50:30 +0800 (Птн, 10 Апр 2009) | 1 line merge r13913 #999e8b059d ------------------------------------------------------------------------ r19315 | paul | 2009-04-10 23:53:07 +0800 (Птн, 10 Апр 2009) | 1 line cleanup WSCalendar ------------------------------------------------------------------------ r19316 | paul | 2009-04-11 00:37:44 +0800 (Сбт, 11 Апр 2009) | 1 line finish with ComCtrls ------------------------------------------------------------------------ r19318 | martin | 2009-04-11 01:37:40 +0800 (Сбт, 11 Апр 2009) | 1 line Moved dialogs ------------------------------------------------------------------------ r19319 | martin | 2009-04-11 01:47:30 +0800 (Сбт, 11 Апр 2009) | 1 line Moved dialogs ------------------------------------------------------------------------ r19320 | martin | 2009-04-11 02:47:52 +0800 (Сбт, 11 Апр 2009) | 1 line Moved ExtCtrls, ExtDlgs ------------------------------------------------------------------------ r19321 | martin | 2009-04-11 03:23:32 +0800 (Сбт, 11 Апр 2009) | 1 line Moved PropertyToSkip ------------------------------------------------------------------------ r19322 | martin | 2009-04-11 03:37:39 +0800 (Сбт, 11 Апр 2009) | 1 line Moved StdCtrls ------------------------------------------------------------------------ r19323 | martin | 2009-04-11 04:05:50 +0800 (Сбт, 11 Апр 2009) | 1 line Moved Buttons ------------------------------------------------------------------------ r19325 | paul | 2009-04-11 11:02:26 +0800 (Сбт, 11 Апр 2009) | 1 line remove DirSel ------------------------------------------------------------------------ r19326 | paul | 2009-04-11 11:11:37 +0800 (Сбт, 11 Апр 2009) | 1 line RegisterArrow ------------------------------------------------------------------------ r19327 | paul | 2009-04-11 11:32:09 +0800 (Сбт, 11 Апр 2009) | 1 line register WS classes only for TCustomXXX classes if they are available (like TCustomScrollBar instead of TScrollBar) and only for those descendants which really differ (like TRadioButton, TToggleButton) ------------------------------------------------------------------------ r19328 | paul | 2009-04-11 11:40:00 +0800 (Сбт, 11 Апр 2009) | 1 line RegisterCustomCheckBox ------------------------------------------------------------------------ r19329 | paul | 2009-04-11 11:57:22 +0800 (Сбт, 11 Апр 2009) | 1 line RegisterXXX for Forms ------------------------------------------------------------------------ r19330 | paul | 2009-04-11 12:13:05 +0800 (Сбт, 11 Апр 2009) | 1 line RegisterCustomGrid + move of RegisterPropertyToSkip ------------------------------------------------------------------------ r19331 | paul | 2009-04-11 12:24:29 +0800 (Сбт, 11 Апр 2009) | 1 line RegisterXXX for Menus ------------------------------------------------------------------------ r19332 | paul | 2009-04-11 12:35:16 +0800 (Сбт, 11 Апр 2009) | 1 line RegisterXXX for PairSplitter ------------------------------------------------------------------------ r19333 | paul | 2009-04-11 12:47:39 +0800 (Сбт, 11 Апр 2009) | 1 line RegisterXXX for Spin ------------------------------------------------------------------------ r19334 | paul | 2009-04-11 12:58:55 +0800 (Сбт, 11 Апр 2009) | 1 line RegisterCustomRubberBand ------------------------------------------------------------------------ r19335 | paul | 2009-04-11 13:31:43 +0800 (Сбт, 11 Апр 2009) | 1 line remove 2 initialization sections ------------------------------------------------------------------------ r19336 | paul | 2009-04-11 13:46:26 +0800 (Сбт, 11 Апр 2009) | 1 line remove TPopupNotifier.png from LCL ------------------------------------------------------------------------ r19338 | paul | 2009-04-11 13:54:03 +0800 (Сбт, 11 Апр 2009) | 1 line cleanup ------------------------------------------------------------------------ r19341 | paul | 2009-04-11 14:59:27 +0800 (Сбт, 11 Апр 2009) | 1 line cleanup ------------------------------------------------------------------------ r19343 | martin | 2009-04-11 19:59:18 +0800 (Сбт, 11 Апр 2009) | 1 line Reduced Unit-Circles, by moving Register* into WS* units ------------------------------------------------------------------------ r19344 | martin | 2009-04-11 20:22:49 +0800 (Сбт, 11 Апр 2009) | 1 line Dummy file for gtk ------------------------------------------------------------------------ r19345 | martin | 2009-04-11 21:06:55 +0800 (Сбт, 11 Апр 2009) | 1 line Initial move of gtk1 register ------------------------------------------------------------------------ r19346 | martin | 2009-04-11 21:19:48 +0800 (Сбт, 11 Апр 2009) | 1 line Missing dependencies in gtk1 wsfactory ------------------------------------------------------------------------ r19347 | martin | 2009-04-11 22:36:42 +0800 (Сбт, 11 Апр 2009) | 1 line Declare register* in interface, to keep external linker happy ------------------------------------------------------------------------ r19348 | martin | 2009-04-11 23:34:16 +0800 (Сбт, 11 Апр 2009) | 1 line Declare register* in interface, to keep external linker happy ------------------------------------------------------------------------ r19349 | martin | 2009-04-11 23:39:20 +0800 (Сбт, 11 Апр 2009) | 1 line moved uses for factory ------------------------------------------------------------------------ r19350 | martin | 2009-04-11 23:41:57 +0800 (Сбт, 11 Апр 2009) | 1 line corrected a few accidental "Result := False" ------------------------------------------------------------------------ r19351 | paul | 2009-04-12 00:04:15 +0800 (Вск, 12 Апр 2009) | 1 line removed unused units ------------------------------------------------------------------------ r19352 | paul | 2009-04-12 00:05:26 +0800 (Вск, 12 Апр 2009) | 1 line qt: move RegisterWS calls to qtwsfactory ------------------------------------------------------------------------ r19354 | paul | 2009-04-12 01:04:04 +0800 (Вск, 12 Апр 2009) | 1 line wince: move RegisterWS calls to WinCEWSFactory ------------------------------------------------------------------------ r19356 | martin | 2009-04-12 01:39:56 +0800 (Вск, 12 Апр 2009) | 1 line moved GTK2 ------------------------------------------------------------------------ r19357 | martin | 2009-04-12 01:45:31 +0800 (Вск, 12 Апр 2009) | 1 line moved GTK2 / missing units ------------------------------------------------------------------------ r19358 | martin | 2009-04-12 01:57:43 +0800 (Вск, 12 Апр 2009) | 1 line Fixed one return value from register ------------------------------------------------------------------------ r19360 | martin | 2009-04-12 02:47:42 +0800 (Вск, 12 Апр 2009) | 1 line Gtk2 , needs 2 registrations for WinControl ------------------------------------------------------------------------ r19361 | martin | 2009-04-12 02:57:58 +0800 (Вск, 12 Апр 2009) | 1 line Gtk2 , needs 2nd registrations ------------------------------------------------------------------------ r19368 | paul | 2009-04-12 13:09:59 +0800 (Вск, 12 Апр 2009) | 1 line cleanup ------------------------------------------------------------------------ r19373 | paul | 2009-04-12 13:45:17 +0800 (Вск, 12 Апр 2009) | 1 line wince: forgotten file ------------------------------------------------------------------------ r19374 | paul | 2009-04-12 14:04:04 +0800 (Вск, 12 Апр 2009) | 1 line carbon: move RegisterWSComponent to CarbonWSFactory ------------------------------------------------------------------------ r19375 | paul | 2009-04-12 14:27:47 +0800 (Вск, 12 Апр 2009) | 1 line cleanup ------------------------------------------------------------------------ git-svn-id: trunk@19376 -
272 lines
9.0 KiB
ObjectPascal
272 lines
9.0 KiB
ObjectPascal
{ $Id$}
|
|
{
|
|
*****************************************************************************
|
|
* WSImgList.pp *
|
|
* ------------ *
|
|
* *
|
|
* *
|
|
*****************************************************************************
|
|
|
|
*****************************************************************************
|
|
* *
|
|
* This file is part of the Lazarus Component Library (LCL) *
|
|
* *
|
|
* See the file COPYING.modifiedLGPL.txt, 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. *
|
|
* *
|
|
*****************************************************************************
|
|
}
|
|
unit WSImgList;
|
|
|
|
{$mode objfpc}{$H+}
|
|
|
|
interface
|
|
////////////////////////////////////////////////////
|
|
// I M P O R T A N T
|
|
////////////////////////////////////////////////////
|
|
// 1) Only class methods allowed
|
|
// 2) Class methods have to be published and virtual
|
|
// 3) To get as little as posible circles, the uses
|
|
// clause should contain only those LCL units
|
|
// needed for registration. WSxxx units are OK
|
|
// 4) To improve speed, register only classes in the
|
|
// initialization section which actually
|
|
// implement something
|
|
// 5) To enable your XXX widgetset units, look at
|
|
// the uses clause of the XXXintf.pp
|
|
////////////////////////////////////////////////////
|
|
uses
|
|
Classes, GraphType, Graphics, IntfGraphics, ImgList, LCLType, LCLIntf,
|
|
WSLCLClasses, WSProc, WSReferences, WSFactory;
|
|
|
|
type
|
|
{ TWSCustomImageList }
|
|
|
|
TWSCustomImageList = class(TWSLCLReferenceComponent)
|
|
published
|
|
class procedure Clear(AList: TCustomImageList); virtual;
|
|
class function CreateReference(AList: TCustomImageList; ACount, AGrow, AWidth,
|
|
AHeight: Integer; AData: PRGBAQuad): TWSCustomImageListReference; virtual;
|
|
|
|
class procedure Delete(AList: TCustomImageList; AIndex: Integer); virtual;
|
|
class procedure DestroyReference(AComponent: TComponent); override;
|
|
class procedure Draw(AList: TCustomImageList; AIndex: Integer; ACanvas: TCanvas;
|
|
ABounds: TRect; ABkColor, ABlendColor: TColor; ADrawEffect: TGraphicsDrawEffect; AStyle: TDrawingStyle; AImageType: TImageType); virtual;
|
|
|
|
class procedure Insert(AList: TCustomImageList; AIndex: Integer; AData: PRGBAQuad); virtual;
|
|
|
|
class procedure Move(AList: TCustomImageList; ACurIndex, ANewIndex: Integer); virtual;
|
|
|
|
class procedure Replace(AList: TCustomImageList; AIndex: Integer; AData: PRGBAQuad); virtual;
|
|
end;
|
|
TWSCustomImageListClass = class of TWSCustomImageList;
|
|
|
|
procedure RegisterCustomImageList;
|
|
|
|
implementation
|
|
|
|
type
|
|
|
|
{ TDefaultImageListImplementor }
|
|
|
|
// Dont use TObjectList due to a bug in it (fixed in fpc > 2.2.2)
|
|
TDefaultImageListImplementor = class(TList)
|
|
private
|
|
FList: TCustomImageList;
|
|
protected
|
|
procedure Notify(Ptr: Pointer; Action: TListNotification); override;
|
|
public
|
|
constructor Create(AList: TCustomImageList); reintroduce;
|
|
procedure Draw(AIndex: Integer; ACanvas: TCanvas; ABounds: TRect; ADrawEffect: TGraphicsDrawEffect; AStyle: TDrawingStyle);
|
|
end;
|
|
|
|
{ TDefaultImageListImplementor }
|
|
|
|
procedure TDefaultImageListImplementor.Notify(Ptr: Pointer;
|
|
Action: TListNotification);
|
|
begin
|
|
if Action = lnDeleted then
|
|
TBitmap(Ptr).Free;
|
|
inherited Notify(Ptr, Action);
|
|
end;
|
|
|
|
constructor TDefaultImageListImplementor.Create(AList: TCustomImageList);
|
|
begin
|
|
inherited Create;
|
|
FList := AList;
|
|
end;
|
|
|
|
procedure TDefaultImageListImplementor.Draw(AIndex: Integer; ACanvas: TCanvas;
|
|
ABounds: TRect; ADrawEffect: TGraphicsDrawEffect; AStyle: TDrawingStyle);
|
|
var
|
|
ABitmap: TBitmap;
|
|
RawImg: TRawImage;
|
|
ListImg, DeviceImg: TLazIntfImage;
|
|
ImgHandle, MskHandle: HBitmap;
|
|
begin
|
|
if (AIndex < 0) or (AIndex >= Count) then Exit;
|
|
if ADrawEffect = gdeNormal then
|
|
begin
|
|
ABitmap := TBitmap(Items[AIndex]);
|
|
ACanvas.Draw(ABounds.Left, ABounds.Top, ABitmap);
|
|
end
|
|
else
|
|
begin
|
|
FList.GetRawImage(AIndex, RawImg);
|
|
RawImg.PerformEffect(ADrawEffect, True);
|
|
|
|
ABitmap := TBitmap.Create;
|
|
if not RawImage_CreateBitmaps(RawImg, ImgHandle, MskHandle, True)
|
|
then begin
|
|
// bummer, the widgetset doesn't support our 32bit format, try device
|
|
ListImg := TLazIntfImage.Create(RawImg, False);
|
|
DeviceImg := TLazIntfImage.Create(0, 0, []);
|
|
DeviceImg.DataDescription := GetDescriptionFromDevice(0, FList.Width, FList.Height);
|
|
DeviceImg.CopyPixels(ListImg);
|
|
DeviceImg.GetRawImage(RawImg);
|
|
RawImage_CreateBitmaps(RawImg, ImgHandle, MskHandle);
|
|
DeviceImg.Free;
|
|
ListImg.Free;
|
|
end;
|
|
ABitmap.SetHandles(ImgHandle, MskHandle);
|
|
ACanvas.Draw(ABounds.Left, ABounds.Top, ABitmap);
|
|
ABitmap.Free;
|
|
RawImg.FreeData;
|
|
end;
|
|
end;
|
|
|
|
function InternalCreateBitmap(AList: TCustomImageList; AWidth, AHeight: Integer; AData: PRGBAQuad): TBitmap;
|
|
var
|
|
hbmImage, hbmMask: HBitmap;
|
|
RawImg: TRawImage;
|
|
begin
|
|
FillChar(RawImg, SizeOf(RawImg), 0);
|
|
AList.FillDescription(RawImg.Description);
|
|
RawImg.DataSize := AWidth * AHeight * SizeOF(AData[0]);
|
|
RawImg.Data := PByte(AData);
|
|
|
|
RawImage_CreateBitmaps(RawImg, hbmImage, hbmMask);
|
|
Result := TBitmap.Create;
|
|
Result.SetHandles(hbmImage, hbmMask);
|
|
end;
|
|
|
|
|
|
{ TWSCustomImageList }
|
|
|
|
class procedure TWSCustomImageList.Clear(AList: TCustomImageList);
|
|
begin
|
|
if not WSCheckReferenceAllocated(AList, 'Clear')
|
|
then Exit;
|
|
TDefaultImageListImplementor(AList.Reference.Ptr).Clear;
|
|
end;
|
|
|
|
class function TWSCustomImageList.CreateReference(AList: TCustomImageList; ACount,
|
|
AGrow, AWidth, AHeight: Integer; AData: PRGBAQuad): TWSCustomImageListReference;
|
|
var
|
|
impl: TDefaultImageListImplementor;
|
|
|
|
ABitmap: TBitmap;
|
|
i: integer;
|
|
begin
|
|
impl := TDefaultImageListImplementor.Create(AList);
|
|
Result._Init(impl);
|
|
|
|
if AData <> nil then
|
|
begin
|
|
// this is very slow method :(
|
|
for i := 0 to ACount - 1 do
|
|
begin
|
|
ABitmap := InternalCreateBitmap(AList, AWidth, AHeight, @AData[AWidth * AHeight * i]);
|
|
impl.Add(ABitmap);
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
class procedure TWSCustomImageList.Delete(AList: TCustomImageList;
|
|
AIndex: Integer);
|
|
begin
|
|
if not WSCheckReferenceAllocated(AList, 'Delete')
|
|
then Exit;
|
|
TDefaultImageListImplementor(AList.Reference.Ptr).Delete(AIndex);
|
|
end;
|
|
|
|
class procedure TWSCustomImageList.DestroyReference(AComponent: TComponent);
|
|
begin
|
|
if not WSCheckReferenceAllocated(TCustomImageList(AComponent), 'DestroyReference')
|
|
then Exit;
|
|
TObject(TCustomImageList(AComponent).Reference.Ptr).Free;
|
|
end;
|
|
|
|
class procedure TWSCustomImageList.Draw(AList: TCustomImageList; AIndex: Integer;
|
|
ACanvas: TCanvas; ABounds: TRect; ABkColor, ABlendColor: TColor; ADrawEffect: TGraphicsDrawEffect; AStyle: TDrawingStyle; AImageType: TImageType);
|
|
begin
|
|
if not WSCheckReferenceAllocated(AList, 'Draw')
|
|
then Exit;
|
|
|
|
TDefaultImageListImplementor(AList.Reference.Ptr).Draw(AIndex, ACanvas, ABounds, ADrawEffect, AStyle);
|
|
end;
|
|
|
|
class procedure TWSCustomImageList.Insert(AList: TCustomImageList;
|
|
AIndex: Integer; AData: PRGBAQuad);
|
|
var
|
|
AImageList: TDefaultImageListImplementor;
|
|
ACount: Integer;
|
|
ABitmap: TBitmap;
|
|
begin
|
|
if not WSCheckReferenceAllocated(AList, 'Insert')
|
|
then Exit;
|
|
|
|
AImageList := TDefaultImageListImplementor(AList.Reference.Ptr);
|
|
ACount := AImageList.Count;
|
|
|
|
if (AIndex <= ACount) and (AIndex >= 0) then
|
|
begin
|
|
ABitmap := InternalCreateBitmap(AList, AList.Width, AList.Height, AData);
|
|
AImageList.Add(ABitmap);
|
|
if AIndex <> ACount then
|
|
Move(AList, ACount, AIndex);
|
|
end;
|
|
end;
|
|
|
|
class procedure TWSCustomImageList.Move(AList: TCustomImageList; ACurIndex,
|
|
ANewIndex: Integer);
|
|
begin
|
|
if not WSCheckReferenceAllocated(AList, 'Move')
|
|
then Exit;
|
|
|
|
if ACurIndex = ANewIndex
|
|
then Exit;
|
|
|
|
TDefaultImageListImplementor(AList.Reference.Ptr).Move(ACurIndex, ANewIndex);
|
|
end;
|
|
|
|
class procedure TWSCustomImageList.Replace(AList: TCustomImageList;
|
|
AIndex: Integer; AData: PRGBAQuad);
|
|
var
|
|
ABitmap: TBitmap;
|
|
begin
|
|
if not WSCheckReferenceAllocated(AList, 'Replace')
|
|
then Exit;
|
|
|
|
ABitmap := InternalCreateBitmap(AList, AList.Width, AList.Height, AData);
|
|
TDefaultImageListImplementor(AList.Reference.Ptr)[AIndex] := ABitmap;
|
|
end;
|
|
|
|
{ WidgetSetRegistration }
|
|
|
|
procedure RegisterCustomImageList;
|
|
const
|
|
Done: Boolean = False;
|
|
begin
|
|
if Done then exit;
|
|
if not WSRegisterCustomImageList then
|
|
RegisterWSComponent(TCustomImageList, TWSCustomImageList);
|
|
Done := True;
|
|
end;
|
|
|
|
end.
|