mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-01 14:20:41 +02:00
TMenu, TMenuItem:
- update icon on changes of imagelist and bitmap - fix HasIcon - now it looks at Bitmap.IsEmpty too (issue #0010313) git-svn-id: trunk@13125 -
This commit is contained in:
parent
835912fdc8
commit
6dd71e054c
@ -35,7 +35,7 @@ begin
|
||||
FBidiMode := bdLeftToRight;
|
||||
FParentBidiMode := True;
|
||||
ParentBidiModeChanged(AOwner);
|
||||
Inherited Create(AOwner);
|
||||
inherited Create(AOwner);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -45,8 +45,8 @@ end;
|
||||
------------------------------------------------------------------------------}
|
||||
procedure TMenu.SetImages(const AValue: TCustomImageList);
|
||||
begin
|
||||
// ToDo
|
||||
FImages:=AValue;
|
||||
FImages := AValue;
|
||||
FItems.UpdateImages;
|
||||
end;
|
||||
|
||||
procedure TMenu.SetBidiMode(const AValue: TBidiMode);
|
||||
@ -267,6 +267,17 @@ begin
|
||||
DoChange(Source, Rebuild);
|
||||
end;
|
||||
|
||||
procedure TMenu.Notification(AComponent: TComponent; Operation: TOperation);
|
||||
begin
|
||||
inherited Notification(AComponent, Operation);
|
||||
if Operation = opRemove then
|
||||
if AComponent = FImages then
|
||||
begin
|
||||
FImages := nil;
|
||||
FItems.UpdateImages;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMenu.SetChildOrder(Child: TComponent; Order: Integer);
|
||||
begin
|
||||
(Child as TMenuItem).MenuIndex := Order;
|
||||
|
@ -371,21 +371,17 @@ begin
|
||||
if FBitmap = nil then
|
||||
begin
|
||||
FBitmap := TBitmap.Create;
|
||||
FBitmapIsValid := False;
|
||||
end;
|
||||
|
||||
if not FBitmapIsValid then
|
||||
begin
|
||||
if ImageIndex >= 0
|
||||
then begin
|
||||
iml := GetImageList;
|
||||
if (iml <> nil) and (ImageIndex < iml.Count)
|
||||
then iml.GetBitmap(ImageIndex, FBitmap);
|
||||
end;
|
||||
FBitmap.Transparent := True;
|
||||
FBitmapIsValid := True;
|
||||
|
||||
FBitmap.OnChange := @BitmapChange;
|
||||
end;
|
||||
|
||||
|
||||
Result := FBitmap;
|
||||
end;
|
||||
|
||||
@ -441,8 +437,10 @@ end;
|
||||
|
||||
function TMenuItem.IsBitmapStored: boolean;
|
||||
begin
|
||||
Result:=(FBitmap<>nil) and (not FBitmap.Empty)
|
||||
and (FBitmap.Width>0) and (FBitmap.Height>0);
|
||||
Result :=
|
||||
FBitmapIsValid and
|
||||
(FBitmap<>nil) and (not FBitmap.Empty) and
|
||||
(FBitmap.Width>0) and (FBitmap.Height>0);
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -594,12 +592,10 @@ function TMenuItem.HasIcon: boolean;
|
||||
var
|
||||
AImageList: TCustomImageList;
|
||||
begin
|
||||
Result := (FBitmap <> nil);
|
||||
AImageList := GetImageList;
|
||||
Result := (AImageList <> nil) and (ImageIndex >= 0) and (ImageIndex < AImageList.Count);
|
||||
if not Result then
|
||||
begin
|
||||
AImageList := GetImageList;
|
||||
Result := (AImageList <> nil) and (ImageIndex >= 0) and (ImageIndex < AImageList.Count);
|
||||
end;
|
||||
Result := (FBitmap <> nil) and not FBitmap.Empty;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -1026,17 +1022,13 @@ begin
|
||||
if (FBitmap = AValue) or ((GetImageList <> nil) and (ImageIndex <> -1)) then
|
||||
exit;
|
||||
|
||||
if AValue <> nil then
|
||||
FBitmapIsValid := True;
|
||||
if (AValue <> nil) then
|
||||
Bitmap.Assign(AValue)
|
||||
else
|
||||
FreeAndNil(FBitmap);
|
||||
|
||||
if HandleAllocated then
|
||||
if HasIcon then // prevent creating bitmap
|
||||
TWSMenuItemClass(WidgetSetClass).UpdateMenuIcon(Self, HasIcon, Bitmap)
|
||||
else
|
||||
TWSMenuItemClass(WidgetSetClass).UpdateMenuIcon(Self, HasIcon, nil);
|
||||
|
||||
UpdateWSIcon;
|
||||
MenuChanged(False);
|
||||
end;
|
||||
|
||||
@ -1140,9 +1132,6 @@ begin
|
||||
FSubMenuImages.FreeNotification(Self);
|
||||
end;
|
||||
UpdateImages;
|
||||
if HandleAllocated and ([csLoading,csDestroying]*ComponentState=[]) then begin
|
||||
// ToDo: Update images
|
||||
end;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -1156,22 +1145,19 @@ procedure TMenuItem.SetImageIndex(Value: Integer);
|
||||
var
|
||||
AImageList: TCustomImageList;
|
||||
begin
|
||||
if FImageIndex = Value then
|
||||
if (FImageIndex = Value) then
|
||||
exit;
|
||||
//debugln('TMenuItem.SetImageIndex A ',Name,' Old=',FImageIndex,' New=',Value);
|
||||
FBitmapIsValid := False;
|
||||
FImageIndex := Value;
|
||||
|
||||
AImageList := GetImageList;
|
||||
FImageIndex := Value;
|
||||
if AImageList = nil then
|
||||
exit;
|
||||
|
||||
FBitmapIsValid := False;
|
||||
if (FImageIndex < 0) or (AImageList = nil) or (FImageIndex >= AImageList.Count) then
|
||||
FreeAndNil(FBitmap);
|
||||
|
||||
if HandleAllocated then
|
||||
if HasIcon then // prevent creating bitmap
|
||||
TWSMenuItemClass(WidgetSetClass).UpdateMenuIcon(Self, HasIcon, Bitmap)
|
||||
else
|
||||
TWSMenuItemClass(WidgetSetClass).UpdateMenuIcon(Self, HasIcon, nil);
|
||||
|
||||
UpdateWSIcon;
|
||||
MenuChanged(False);
|
||||
end;
|
||||
|
||||
@ -1268,16 +1254,58 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMenuItem.UpdateImages;
|
||||
procedure TMenuItem.UpdateImage;
|
||||
var
|
||||
ImgList: TCustomImageList;
|
||||
begin
|
||||
if HandleAllocated and ([csLoading,csDestroying]*ComponentState=[]) then begin
|
||||
// ToDo: Update images
|
||||
if HandleAllocated and ([csLoading,csDestroying]*ComponentState=[]) then
|
||||
begin
|
||||
ImgList := GetImageList;
|
||||
if FBitmapIsValid then // Bitmap is assigned through Bitmap property
|
||||
begin
|
||||
if (ImgList <> nil) and (ImageIndex <> -1) then
|
||||
begin
|
||||
FreeAndNil(FBitmap);
|
||||
FBitmapIsValid := False;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
if (ImgList = nil) or (ImageIndex = -1) then
|
||||
begin
|
||||
FreeAndNil(FBitmap);
|
||||
FBitmapIsValid := True;
|
||||
end;
|
||||
end;
|
||||
UpdateWSIcon;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMenuItem.UpdateImages;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
if HandleAllocated and ([csLoading,csDestroying]*ComponentState=[]) then
|
||||
begin
|
||||
UpdateImage;
|
||||
for i := 0 to Count - 1 do
|
||||
Items[i].UpdateImages;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMenuItem.UpdateWSIcon;
|
||||
begin
|
||||
if HandleAllocated then
|
||||
if HasIcon then // prevent creating bitmap
|
||||
TWSMenuItemClass(WidgetSetClass).UpdateMenuIcon(Self, HasIcon, Bitmap)
|
||||
else
|
||||
TWSMenuItemClass(WidgetSetClass).UpdateMenuIcon(Self, HasIcon, nil);
|
||||
end;
|
||||
|
||||
procedure TMenuItem.ImageListChange(Sender: TObject);
|
||||
begin
|
||||
if Sender = SubMenuImages then UpdateImages;
|
||||
if Sender = SubMenuImages then
|
||||
UpdateImages;
|
||||
end;
|
||||
|
||||
{------------------------------------------------------------------------------
|
||||
@ -1359,4 +1387,9 @@ begin
|
||||
inherited AssignTo(Dest);
|
||||
end;
|
||||
|
||||
procedure TMenuItem.BitmapChange(Sender: TObject);
|
||||
begin
|
||||
UpdateImage;
|
||||
end;
|
||||
|
||||
// included by menus.pp
|
||||
|
@ -27,13 +27,14 @@ unit GtkWSMenus;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, InterfaceBase, Types, LCLProc, LCLType, WSMenus, WSLCLClasses,
|
||||
{$IFDEF gtk2}
|
||||
glib2, gdk2pixbuf, gdk2, gtk2, Pango,
|
||||
{$ELSE}
|
||||
glib, gdk, gtk, gdkpixbuf,
|
||||
{$ENDIF}
|
||||
GtkInt, gtkProc, gtkglobals, GTKExtra, Menus;
|
||||
GtkInt, gtkProc, gtkglobals, GTKExtra,
|
||||
Classes, InterfaceBase, Types, LCLProc, LCLType, WSMenus, WSLCLClasses,
|
||||
Graphics, Menus;
|
||||
|
||||
type
|
||||
{ TGtkWSMenuItem }
|
||||
@ -52,6 +53,7 @@ type
|
||||
class function SetEnable(const AMenuItem: TMenuItem; const Enabled: boolean): boolean; override;
|
||||
class function SetRadioItem(const AMenuItem: TMenuItem; const RadioItem: boolean): boolean; override;
|
||||
class function SetRightJustify(const AMenuItem: TMenuItem; const Justified: boolean): boolean; override;
|
||||
class procedure UpdateMenuIcon(const AMenuItem: TMenuItem; const HasIcon: Boolean; const AIcon: TBitmap); override;
|
||||
end;
|
||||
|
||||
{ TGtkWSMenu }
|
||||
@ -257,6 +259,12 @@ begin
|
||||
Result:=false;
|
||||
end;
|
||||
|
||||
class procedure TGtkWSMenuItem.UpdateMenuIcon(const AMenuItem: TMenuItem;
|
||||
const HasIcon: Boolean; const AIcon: TBitmap);
|
||||
begin
|
||||
// TODO
|
||||
end;
|
||||
|
||||
{ TGtkWSMenu }
|
||||
|
||||
class function TGtkWSMenu.CreateHandle(const AMenu: TMenu): HMENU;
|
||||
|
@ -1194,7 +1194,7 @@ procedure RedrawMenus;
|
||||
var
|
||||
I: integer;
|
||||
begin
|
||||
for I := 0 to ChangedMenus.Count - 1 do
|
||||
for I := 0 to ChangedMenus.Count - 1 do
|
||||
DrawMenuBar(HWND(ChangedMenus[I]));
|
||||
ChangedMenus.Clear;
|
||||
end;
|
||||
|
@ -55,6 +55,7 @@ type
|
||||
class procedure SetShortCut(const AMenuItem: TMenuItem; const OldShortCut, NewShortCut: TShortCut); override;
|
||||
class function SetEnable(const AMenuItem: TMenuItem; const Enabled: boolean): boolean; override;
|
||||
class function SetRightJustify(const AMenuItem: TMenuItem; const Justified: boolean): boolean; override;
|
||||
class procedure UpdateMenuIcon(const AMenuItem: TMenuItem; const HasIcon: Boolean; const AIcon: Graphics.TBitmap); override;
|
||||
end;
|
||||
|
||||
{ TWin32WSMenu }
|
||||
@ -624,6 +625,8 @@ procedure UpdateCaption(const AMenuItem: TMenuItem; ACaption: String);
|
||||
var
|
||||
MenuInfo: MENUITEMINFO;
|
||||
begin
|
||||
if (AMenuItem.Parent = nil) or not AMenuItem.Parent.HandleAllocated then
|
||||
exit;
|
||||
with MenuInfo do
|
||||
begin
|
||||
cbsize := menuiteminfosize;
|
||||
@ -759,6 +762,11 @@ begin
|
||||
Result := ChangeMenuFlag(AMenuItem, MFT_RIGHTJUSTIFY, Justified);
|
||||
end;
|
||||
|
||||
class procedure TWin32WSMenuItem.UpdateMenuIcon(const AMenuItem: TMenuItem;
|
||||
const HasIcon: Boolean; const AIcon: Graphics.TBitmap);
|
||||
begin
|
||||
UpdateCaption(AMenuItem, aMenuItem.Caption);
|
||||
end;
|
||||
|
||||
{ TWin32WSMenu }
|
||||
|
||||
|
@ -123,6 +123,8 @@ type
|
||||
FShowAlwaysCheckable: boolean;
|
||||
FSubMenuImages: TCustomImageList;
|
||||
FVisible: Boolean;
|
||||
// True => Bitmap property indicates assigned Bitmap.
|
||||
// False => Bitmap property is not assigned but can represent imagelist bitmap
|
||||
FBitmapIsValid: Boolean;
|
||||
FMenuItemHandlers: array[TMenuItemHandlerType] of TMethodList;
|
||||
function GetBitmap: TBitmap;
|
||||
@ -159,6 +161,7 @@ type
|
||||
protected
|
||||
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); dynamic;
|
||||
procedure AssignTo(Dest: TPersistent); override;
|
||||
procedure BitmapChange(Sender: TObject);
|
||||
function GetAction: TBasicAction;
|
||||
function GetActionLinkClass: TMenuActionLinkClass; dynamic;
|
||||
function GetHandle: HMenu;
|
||||
@ -178,7 +181,9 @@ type
|
||||
procedure SetParentComponent(AValue : TComponent); override;
|
||||
procedure SetShortCut(const AValue : TShortCut);
|
||||
procedure SetVisible(AValue: Boolean);
|
||||
procedure UpdateImage;
|
||||
procedure UpdateImages;
|
||||
procedure UpdateWSIcon;
|
||||
procedure ImageListChange(Sender: TObject);
|
||||
protected
|
||||
property ActionLink: TMenuActionLink read FActionLink write FActionLink;
|
||||
@ -294,6 +299,8 @@ type
|
||||
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
|
||||
procedure MenuChanged(Sender: TObject; Source: TMenuItem;
|
||||
Rebuild: Boolean); virtual;
|
||||
procedure Notification(AComponent: TComponent;
|
||||
Operation: TOperation); override;
|
||||
procedure ParentBidiModeChanged;
|
||||
procedure ParentBidiModeChanged(AOwner:TComponent);//used in Create constructor
|
||||
procedure SetChildOrder(Child: TComponent; Order: Integer); override;
|
||||
|
Loading…
Reference in New Issue
Block a user