- create, destroy TIcon.Handle when needed
- repair TCustomForm.SetIcon, TApplication.SetIcon

git-svn-id: trunk@15503 -
This commit is contained in:
paul 2008-06-21 14:23:02 +00:00
parent f4e7288ff8
commit ad0c55e479
5 changed files with 54 additions and 22 deletions

View File

@ -442,6 +442,7 @@ type
procedure WMShowWindow(var message: TLMShowWindow); message LM_SHOWWINDOW; procedure WMShowWindow(var message: TLMShowWindow); message LM_SHOWWINDOW;
procedure WMSize(var message: TLMSize); message LM_Size; procedure WMSize(var message: TLMSize); message LM_Size;
procedure CMBiDiModeChanged(var Message: TLMessage); message CM_BIDIMODECHANGED; procedure CMBiDiModeChanged(var Message: TLMessage); message CM_BIDIMODECHANGED;
procedure CMIconChanged(var Message: TLMessage); message CM_ICONCHANGED;
procedure AddHandler(HandlerType: TFormHandlerType; procedure AddHandler(HandlerType: TFormHandlerType;
const Handler: TMethod; AsLast: Boolean); const Handler: TMethod; AsLast: Boolean);
procedure RemoveHandler(HandlerType: TFormHandlerType; procedure RemoveHandler(HandlerType: TFormHandlerType;

View File

@ -1383,6 +1383,7 @@ type
private private
FImages: TFPList; FImages: TFPList;
protected protected
procedure FreeHandle; override;
class function GetImagesClass: TIconImageClass; virtual; class function GetImagesClass: TIconImageClass; virtual;
public public
constructor Create; override; constructor Create; override;
@ -1434,6 +1435,8 @@ type
} }
{ TCustomIcon }
TCustomIcon = class(TRasterImage) TCustomIcon = class(TRasterImage)
private private
FCurrent: Integer; FCurrent: Integer;
@ -1465,6 +1468,7 @@ type
constructor Create; override; constructor Create; override;
procedure Add(AFormat: TPixelFormat; AHeight, AWidth: Word); procedure Add(AFormat: TPixelFormat; AHeight, AWidth: Word);
procedure Assign(Source: TPersistent); override;
procedure Delete(Aindex: Integer); procedure Delete(Aindex: Integer);
procedure Remove(AFormat: TPixelFormat; AHeight, AWidth: Word); procedure Remove(AFormat: TPixelFormat; AHeight, AWidth: Word);
procedure GetDescription(Aindex: Integer; out AFormat: TPixelFormat; out AHeight, AWidth: Word); procedure GetDescription(Aindex: Integer; out AFormat: TPixelFormat; out AHeight, AWidth: Word);
@ -1485,6 +1489,7 @@ type
function GetIconHandle: HICON; function GetIconHandle: HICON;
procedure SetIconHandle(const AValue: HICON); procedure SetIconHandle(const AValue: HICON);
protected protected
procedure HandleNeeded; override;
public public
function ReleaseHandle: HICON; function ReleaseHandle: HICON;
property Handle: HICON read GetIconHandle write SetIconHandle; property Handle: HICON read GetIconHandle write SetIconHandle;

View File

@ -104,7 +104,8 @@ begin
FShowMainForm := true; FShowMainForm := true;
FFormList := nil; FFormList := nil;
FOnIdle := nil; FOnIdle := nil;
FIcon := nil; FIcon := TIcon.Create;
FIcon.OnChange := @IconChanged;
FNavigation := [anoTabToSelectNext,anoReturnForDefaultControl, FNavigation := [anoTabToSelectNext,anoReturnForDefaultControl,
anoEscapeForCancelControl,anoF1ForHelp]; anoEscapeForCancelControl,anoF1ForHelp];
ApplicationActionComponent:=Self; ApplicationActionComponent:=Self;
@ -347,13 +348,8 @@ begin
ScreenInfo.Initialized:=true; ScreenInfo.Initialized:=true;
Screen.UpdateScreen; Screen.UpdateScreen;
// application icon // application icon
if LazarusResources.Find('MAINICON')<>nil then begin if LazarusResources.Find('MAINICON') <> nil then
if FIcon=nil then begin Icon.LoadFromLazarusResource('MAINICON');
FIcon:=TIcon.Create;
FIcon.OnChange := @IconChanged;
end;
FIcon.LoadFromLazarusResource('MAINICON');
end;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -503,10 +499,6 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TApplication.SetIcon(AValue: TIcon); procedure TApplication.SetIcon(AValue: TIcon);
begin begin
if FIcon=nil then begin
FIcon:=TIcon.Create;
FIcon.OnChange := @IconChanged;
end;
FIcon.Assign(AValue); FIcon.Assign(AValue);
end; end;
@ -874,10 +866,13 @@ end;
Method: TApplication.IconChanged Method: TApplication.IconChanged
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TApplication.IconChanged(Sender: TObject); procedure TApplication.IconChanged(Sender: TObject);
var
i: integer;
begin begin
DebugLn('TApplication.IconChanged - TODO: convert this message...no implementation in gtk or win32'); Widgetset.AppSetIcon(GetIconHandle);
// CNSendMessage(LM_SETFORMICON, Self, Pointer(GetIconHandle)); if FFormList<>nil then
// NotifyForms(CM_ICONCHANGED); for i :=0 to FFormList.Count - 1 do
TForm(FFormList[i]).Perform(CM_ICONCHANGED, 0, 0);
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -886,8 +881,8 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TApplication.GetIconHandle: HICON; function TApplication.GetIconHandle: HICON;
begin begin
if FIcon <> nil then if not Icon.Empty then
Result := FIcon.Handle Result := Icon.Handle
else else
Result := 0; Result := 0;
end; end;

View File

@ -221,10 +221,6 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCustomForm.SetIcon(AValue: TIcon); procedure TCustomForm.SetIcon(AValue: TIcon);
begin begin
if FIcon=nil then begin
FIcon:=TIcon.Create;
FIcon.OnChange := @IconChanged;
end;
FIcon.Assign(AValue); FIcon.Assign(AValue);
end; end;
@ -252,7 +248,7 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
function TCustomForm.GetIconHandle: HICON; function TCustomForm.GetIconHandle: HICON;
begin begin
if (FIcon <> nil) and (not FIcon.Empty) then if not FIcon.Empty then
Result := FIcon.Handle Result := FIcon.Handle
else else
Result := Application.GetIconHandle; Result := Application.GetIconHandle;
@ -554,6 +550,11 @@ begin
end; end;
end; end;
procedure TCustomForm.CMIconChanged(var Message: TLMessage);
begin
IconChanged(Self);
end;
procedure TCustomForm.AddHandler(HandlerType: TFormHandlerType; procedure TCustomForm.AddHandler(HandlerType: TFormHandlerType;
const Handler: TMethod; AsLast: Boolean); const Handler: TMethod; AsLast: Boolean);
begin begin
@ -1432,6 +1433,7 @@ begin
Ctl3D := True; Ctl3D := True;
FWindowState := wsNormal; FWindowState := wsNormal;
FIcon := TIcon.Create; FIcon := TIcon.Create;
FIcon.OnChange := @IconChanged;
FKeyPreview := False; FKeyPreview := False;
Color := clBtnFace; Color := clBtnFace;
FloatingDockSiteClass := TWinControlClass(ClassType); FloatingDockSiteClass := TWinControlClass(ClassType);
@ -1827,6 +1829,8 @@ begin
// set allow drop files // set allow drop files
TWSCustomFormClass(WidgetSetClass).SetAllowDropFiles(Self, FAllowDropFiles); TWSCustomFormClass(WidgetSetClass).SetAllowDropFiles(Self, FAllowDropFiles);
// update icon
Perform(CM_ICONCHANGED, 0, 0);
//DebugLn('TCustomForm.CreateWnd END ',ClassName); //DebugLn('TCustomForm.CreateWnd END ',ClassName);
end; end;

View File

@ -82,6 +82,14 @@ end;
{ TSharedIcon } { TSharedIcon }
procedure TSharedIcon.FreeHandle;
begin
if FHandle = 0 then Exit;
DestroyIcon(FHandle);
FHandle := 0;
end;
class function TSharedIcon.GetImagesClass: TIconImageClass; class function TSharedIcon.GetImagesClass: TIconImageClass;
begin begin
Result := TIconImage; Result := TIconImage;
@ -240,6 +248,13 @@ begin
end; end;
end; end;
procedure TCustomIcon.Assign(Source: TPersistent);
begin
if Source is TCustomIcon then
FCurrent := TCustomIcon(Source).Current;
inherited Assign(Source);
end;
function TCustomIcon.BitmapHandleAllocated: boolean; function TCustomIcon.BitmapHandleAllocated: boolean;
begin begin
Result := (FCurrent <> -1) and (TIconImage(TSharedIcon(FSharedImage).FImages[FCurrent]).FHandle <> 0); Result := (FCurrent <> -1) and (TIconImage(TSharedIcon(FSharedImage).FImages[FCurrent]).FHandle <> 0);
@ -709,4 +724,16 @@ begin
SetHandle(AValue); SetHandle(AValue);
end; end;
procedure TIcon.HandleNeeded;
var
IconInfo: TIconInfo;
begin
if FSharedImage.FHandle <> 0 then Exit;
IconInfo.fIcon := True;
IconInfo.hbmMask := MaskHandle;
IconInfo.hbmColor := BitmapHandle;
FSharedImage.FHandle := WidgetSet.CreateIconIndirect(@IconInfo);
end;