mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-11 20:59:10 +02:00
LCL-GTK1: Fix menu item drawing for menus without icons
When a menu does not have any icons set, the existing code drew checkboxes over the menu icons. This patch fixes that. The previous code relied on a function that apparently became noop in Gtk 1.2.9 but the underlying code and private field it modified were not changed, so this fix now changes the private field directly (this change was made in 2001 so the chances of this breaking are a bit low :-P). It also removes the unnecessary left side padding when no menu has any icon or is checkable so that the menu appearance matches other (non-Lazarus made) Gtk 1.2 programs.
This commit is contained in:
parent
e5831fc959
commit
9b8f434368
@ -403,7 +403,6 @@ begin
|
||||
LCLMenuItem := TMenuItem(AData);
|
||||
// some sanity checks
|
||||
if LCLMenuItem = nil then Exit;
|
||||
if not LCLMenuItem.IsCheckItem then Exit; // ???
|
||||
|
||||
// the gtk always toggles the check flag
|
||||
// -> restore 'checked' flag if needed
|
||||
|
@ -361,7 +361,6 @@ type
|
||||
const
|
||||
OldCheckMenuItemDrawProc: TCheckMenuItemDrawProc = nil;
|
||||
OldMenuSizeRequestProc: TMenuSizeRequestProc = nil;
|
||||
OldCheckMenuItemToggleSize: integer = 0;
|
||||
|
||||
|
||||
{ Accelerators }
|
||||
|
@ -5964,7 +5964,7 @@ begin
|
||||
MenuItem:=PGtkMenuItem(ListItem^.Data);
|
||||
if GTK_IS_CHECK_MENU_ITEM(PGtkWidget(MenuItem)) then begin
|
||||
CheckMenuItem:=MenuItem;
|
||||
CurToggleSize:=OldCheckMenuItemToggleSize;
|
||||
CurToggleSize:=1;
|
||||
LCLMenuItem:=TMenuItem(GetLCLObject(MenuItem));
|
||||
if LCLMenuItem<>nil then begin
|
||||
IconSize:=LCLMenuItem.GetIconSize(0);
|
||||
@ -6113,11 +6113,6 @@ var
|
||||
bm_show_toggle_indicator;
|
||||
{$ENDIF}
|
||||
|
||||
// set our own draw handler
|
||||
if OldCheckMenuItemDrawProc = nil then
|
||||
OldCheckMenuItemDrawProc := CHECK_MENU_ITEM_CLASS(MenuItemWidget)^.draw_indicator;
|
||||
CHECK_MENU_ITEM_CLASS(MenuItemWidget)^.draw_indicator := @DrawMenuItemIcon;
|
||||
|
||||
{$IFNDEF Gtk2}
|
||||
// add a dummy widget for the icon height
|
||||
MinHeightWidget := gtk_label_new('');
|
||||
|
@ -170,15 +170,23 @@ begin
|
||||
|
||||
if GtkWidgetIsA(Widget, GTK_TYPE_CHECK_MENU_ITEM) then
|
||||
begin
|
||||
// set 'ShowAlwaysCheckable'
|
||||
gtk_check_menu_item_set_show_toggle(PGtkCheckMenuItem(Widget),
|
||||
AMenuItem.ShowAlwaysCheckable);
|
||||
// set 'ShowAlwaysCheckable' (this modifies the always_show_toggle bitfield
|
||||
// in the private _GtkCheckMenuItem - it used to be modifiable by a function
|
||||
// call but in Gtk 1.2.9 and 1.2.10 it became a noop, however aside from
|
||||
// that the rest of the code didn't change
|
||||
if AMenuItem.ShowAlwaysCheckable then
|
||||
PGtkCheckMenuItem(Widget)^.flag0:=PGtkCheckMenuItem(Widget)^.flag0 or 2
|
||||
else
|
||||
PGtkCheckMenuItem(Widget)^.flag0:=PGtkCheckMenuItem(Widget)^.flag0 and not 2;
|
||||
// set 'Checked'
|
||||
gtk_check_menu_item_set_active(PGtkCheckMenuItem(Widget),
|
||||
AMenuItem.Checked);
|
||||
|
||||
if (OldCheckMenuItemToggleSize=0) then
|
||||
OldCheckMenuItemToggleSize := MENU_ITEM_CLASS(Widget)^.toggle_size;
|
||||
// always set our own indicator draw handler to ensure the check box is not
|
||||
// drawn for non-checkable menu items
|
||||
if OldCheckMenuItemDrawProc = nil then
|
||||
OldCheckMenuItemDrawProc := CHECK_MENU_ITEM_CLASS(Widget)^.draw_indicator;
|
||||
CHECK_MENU_ITEM_CLASS(Widget)^.draw_indicator := @DrawMenuItemIcon;
|
||||
|
||||
g_signal_connect_after(PGTKObject(Widget), 'toggled',
|
||||
TGTKSignalFunc(@GTKCheckMenuToggeledCB), Pointer(AMenuItem));
|
||||
|
Loading…
Reference in New Issue
Block a user