mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-15 10:43:53 +02:00
fix menu drawing in form (win32, fixes bug #1249)
git-svn-id: trunk@7860 -
This commit is contained in:
parent
4a7241572d
commit
14919eb9e7
@ -1040,21 +1040,8 @@ end;
|
|||||||
Adds Window to the list of windows which need to redraw the main menu.
|
Adds Window to the list of windows which need to redraw the main menu.
|
||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure AddToChangedMenus(Window: HWnd);
|
procedure AddToChangedMenus(Window: HWnd);
|
||||||
{only add window handle if it does not yet exist in the list}
|
|
||||||
function FindHandle: integer;
|
|
||||||
var i: integer;
|
|
||||||
begin
|
|
||||||
for i := 0 to ChangedMenus.Count - 1 do
|
|
||||||
if HWnd(ChangedMenus[i]) = Window then
|
|
||||||
begin
|
|
||||||
Result := i;
|
|
||||||
exit;
|
|
||||||
end;
|
|
||||||
Result := ChangedMenus.Count;
|
|
||||||
end;
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
if FindHandle = ChangedMenus.Count then // Window handle is not yet in the list
|
if ChangedMenus.IndexOf(Pointer(Window)) = -1 then // Window handle is not yet in the list
|
||||||
ChangedMenus.Add(Pointer(Window));
|
ChangedMenus.Add(Pointer(Window));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -1066,12 +1053,12 @@ end;
|
|||||||
Redraws all changed menus
|
Redraws all changed menus
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
procedure RedrawMenus;
|
procedure RedrawMenus;
|
||||||
|
var
|
||||||
|
I: integer;
|
||||||
begin
|
begin
|
||||||
while ChangedMenus.Count > 0 do
|
for I := 0 to ChangedMenus.Count - 1 do
|
||||||
begin
|
DrawMenuBar(HWND(ChangedMenus[I]));
|
||||||
DrawMenuBar(HWND(ChangedMenus[0]));
|
ChangedMenus.Clear;
|
||||||
ChangedMenus.Delete(0);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function MeasureText(const AWinControl: TWinControl; Text: string; var Width, Height: integer): boolean;
|
function MeasureText(const AWinControl: TWinControl; Text: string; var Width, Height: integer): boolean;
|
||||||
|
@ -87,6 +87,20 @@ type
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
{ helper routines }
|
||||||
|
|
||||||
|
procedure TriggerFormUpdate(const AMenuItem: TMenuItem);
|
||||||
|
var
|
||||||
|
lMenu: TMenu;
|
||||||
|
begin
|
||||||
|
lMenu := AMenuItem.GetParentMenu;
|
||||||
|
if (lMenu<>nil) and (lMenu.Parent<>nil)
|
||||||
|
and (lMenu.Parent is TCustomForm)
|
||||||
|
and TCustomForm(lMenu.Parent).HandleAllocated
|
||||||
|
and not (csDestroying in lMenu.Parent.ComponentState) then
|
||||||
|
AddToChangedMenus(TCustomForm(lMenu.Parent).Handle);
|
||||||
|
end;
|
||||||
|
|
||||||
{ TWin32WSMenuItem }
|
{ TWin32WSMenuItem }
|
||||||
|
|
||||||
procedure UpdateCaption(const AMenuItem: TMenuItem; ACaption: String);
|
procedure UpdateCaption(const AMenuItem: TMenuItem; ACaption: String);
|
||||||
@ -114,12 +128,7 @@ begin
|
|||||||
else fType := MFT_SEPARATOR;
|
else fType := MFT_SEPARATOR;
|
||||||
end;
|
end;
|
||||||
SetMenuItemInfo(AMenuItem.Parent.Handle, AMenuItem.Command, false, @MenuInfo);
|
SetMenuItemInfo(AMenuItem.Parent.Handle, AMenuItem.Command, false, @MenuInfo);
|
||||||
// owner could be a popupmenu too
|
TriggerFormUpdate(AMenuItem);
|
||||||
if (AMenuItem.Owner is TWinControl) and
|
|
||||||
TWinControl(AMenuItem.Owner).HandleAllocated and
|
|
||||||
TWinControl(AMenuItem.Owner).Visible and
|
|
||||||
([csLoading,csDestroying] * TWinControl(AMenuItem.Owner).ComponentState = []) then
|
|
||||||
AddToChangedMenus(TWinControl(AMenuItem.Owner).Handle);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TWin32WSMenuItem.AttachMenu(const AMenuItem: TMenuItem);
|
procedure TWin32WSMenuItem.AttachMenu(const AMenuItem: TMenuItem);
|
||||||
@ -247,12 +256,7 @@ begin
|
|||||||
if dword(InsertMenuItem(ParentMenuHandle,
|
if dword(InsertMenuItem(ParentMenuHandle,
|
||||||
AMenuItem.Parent.VisibleIndexOf(AMenuItem), true, @MenuInfo)) = 0 then
|
AMenuItem.Parent.VisibleIndexOf(AMenuItem), true, @MenuInfo)) = 0 then
|
||||||
DebugLn('InsertMenuItem failed with error: ', IntToStr(Windows.GetLastError));
|
DebugLn('InsertMenuItem failed with error: ', IntToStr(Windows.GetLastError));
|
||||||
// owner could be a popupmenu too
|
TriggerFormUpdate(AMenuItem);
|
||||||
if (AMenuItem.Owner is TWinControl) and
|
|
||||||
TWinControl(AMenuItem.Owner).HandleAllocated and
|
|
||||||
TWinControl(AMenuItem.Owner).Visible and
|
|
||||||
([csLoading,csDestroying] * TWinControl(AMenuItem.Owner).ComponentState = []) then
|
|
||||||
AddToChangedMenus(TWinControl(AMenuItem.Owner).Handle);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWin32WSMenuItem.CreateHandle(const AMenuItem: TMenuItem): HMENU;
|
function TWin32WSMenuItem.CreateHandle(const AMenuItem: TMenuItem): HMENU;
|
||||||
@ -261,19 +265,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TWin32WSMenuItem.DestroyHandle(const AMenuItem: TMenuItem);
|
procedure TWin32WSMenuItem.DestroyHandle(const AMenuItem: TMenuItem);
|
||||||
var
|
|
||||||
AMenu: TMenu;
|
|
||||||
begin
|
begin
|
||||||
{ not assigned when this the menuitem of a TMenu; handle is destroyed above }
|
{ not assigned when this the menuitem of a TMenu; handle is destroyed above }
|
||||||
if Assigned(AMenuItem.Parent) then
|
if Assigned(AMenuItem.Parent) then
|
||||||
DeleteMenu(AMenuItem.Parent.Handle, AMenuItem.Command, MF_BYCOMMAND);
|
DeleteMenu(AMenuItem.Parent.Handle, AMenuItem.Command, MF_BYCOMMAND);
|
||||||
AMenu := AMenuItem.GetParentMenu;
|
TriggerFormUpdate(AMenuItem);
|
||||||
if (AMenu<>nil) and (AMenu.Parent<>nil)
|
|
||||||
and (AMenu.Parent is TCustomForm)
|
|
||||||
and TCustomForm(AMenu.Parent).HandleAllocated
|
|
||||||
and TCustomForm(AMenu.Parent).Visible
|
|
||||||
and not (csDestroying in AMenu.Parent.ComponentState) then
|
|
||||||
AddToChangedMenus(TWinControl(AMenu.Parent).Handle);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TWin32WSMenuItem.SetCaption(const AMenuItem: TMenuItem; const ACaption: string);
|
procedure TWin32WSMenuItem.SetCaption(const AMenuItem: TMenuItem; const ACaption: string);
|
||||||
@ -340,11 +336,7 @@ begin
|
|||||||
else EnableFlag := MF_GRAYED;
|
else EnableFlag := MF_GRAYED;
|
||||||
EnableFlag := EnableFlag or MF_BYCOMMAND;
|
EnableFlag := EnableFlag or MF_BYCOMMAND;
|
||||||
Result := Boolean(Windows.EnableMenuItem(AMenuItem.Parent.Handle, AMenuItem.Command, EnableFlag));
|
Result := Boolean(Windows.EnableMenuItem(AMenuItem.Parent.Handle, AMenuItem.Command, EnableFlag));
|
||||||
if (AMenuItem.Owner is TWinControl) and
|
TriggerFormUpdate(AMenuItem);
|
||||||
TWinControl(AMenuItem.Owner).HandleAllocated and
|
|
||||||
TWinControl(AMenuItem.Owner).Visible and
|
|
||||||
([csLoading,csDestroying] * TWinControl(AMenuItem.Owner).ComponentState = []) then
|
|
||||||
AddToChangedMenus(TWinControl(AMenuItem.Owner).Handle);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TWin32WSMenuItem.SetRightJustify(const AMenuItem: TMenuItem; const Justified: boolean): boolean;
|
function TWin32WSMenuItem.SetRightJustify(const AMenuItem: TMenuItem; const Justified: boolean): boolean;
|
||||||
@ -358,11 +350,7 @@ begin
|
|||||||
else MenuInfo.fType := MenuInfo.fType and (not MFT_RIGHTJUSTIFY);
|
else MenuInfo.fType := MenuInfo.fType and (not MFT_RIGHTJUSTIFY);
|
||||||
MenuInfo.dwTypeData := LPSTR(AMenuItem.Caption);
|
MenuInfo.dwTypeData := LPSTR(AMenuItem.Caption);
|
||||||
Result := SetMenuItemInfo(AMenuItem.Parent.Handle, AMenuItem.Command, false, @MenuInfo);
|
Result := SetMenuItemInfo(AMenuItem.Parent.Handle, AMenuItem.Command, false, @MenuInfo);
|
||||||
if (AMenuItem.Owner is TWinControl) and
|
TriggerFormUpdate(AMenuItem);
|
||||||
TWinControl(AMenuItem.Owner).HandleAllocated and
|
|
||||||
TWinControl(AMenuItem.Owner).Visible and
|
|
||||||
([csLoading,csDestroying] * TWinControl(AMenuItem.Owner).ComponentState = []) then
|
|
||||||
AddToChangedMenus(TWinControl(AMenuItem.Owner).Handle);
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user