View Issue Details

IDProjectCategoryView StatusLast Update
0037740LazarusWidgetsetpublic2020-09-24 17:32
ReporterCudaText man_ Assigned ToJuha Manninen  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
OSUbuntu 20 x64 
Product Version2.1 (SVN) 
Summary0037740: gtk3: menu position and RadioItems
Descriptiondemo
https://github.com/Alexey-T/FreePascal-tests/tree/master/Menu%20RadioItems

gtk3 bugs
- menu pos must be the button's left/bottom point - it's not (it's some left edge of form)
- menu "sub normal" don't show its items as "Checked"
TagsNo tags attached.
Fixed in Revisionr63896
LazTarget-
WidgetsetGTK 3
Attached Files

Activities

Anton Kavalenka

2020-09-12 17:49

reporter   ~0125512

Last edited: 2020-09-12 17:51

View 2 revisions

Maybe this way.

Please note - the menu appears at button coordinates known to LCL. Actual button size allocation should be fixes somewhere else.

Button minimal size is limited by GTK3 theme. It is possible to get this size, but impossible to convince LCL be constrained to these limits.
gtk3origin.diff (2,267 bytes)   
Index: lcl/interfaces/gtk3/gtk3widgets.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3widgets.pas	(revision 63882)
+++ lcl/interfaces/gtk3/gtk3widgets.pas	(working copy)
@@ -1495,7 +1495,7 @@
 
   Msg.SizeType := Msg.SizeType or Size_SourceIsInterface;
 
-  if ACtl.WidgetType*[wtEntry,wtComboBox,wtScrollBar,wtSpinEdit]<>[] then
+  if ACtl.WidgetType*[wtEntry,wtComboBox,wtScrollBar,wtSpinEdit,wtHintWindow]<>[] then
   begin
     Msg.Width := ACtl.LCLObject.Width;//Word(NewSize.cx);
     Msg.Height := ACtl.LCLObject.Height;//Word(NewSize.cy);
@@ -1512,7 +1512,7 @@
   end;
   ACtl.DeliverMessage(Msg);
 
-  if (wtWindow in ACtl.WidgetType) and
+ (* if (wtWindow in ACtl.WidgetType) and
     ((AGdkRect^.x <> ACtl.LCLObject.Left) or (AGdkRect^.y <> ACtl.LCLObject.Top)) then
   begin
     FillChar(MoveMsg, SizeOf(MoveMsg), #0);
@@ -1524,7 +1524,7 @@
     DebugLn('SEND MOVE MESSAGE X=',dbgs(AGdkRect^.x),' Y=',dbgs(AGdkRect^.y),' control ',dbgsName(ACtl.LCLObject));
     {$ENDIF}
     ACtl.DeliverMessage(MoveMsg);
-  end;
+  end;   *)
 end;
 
 function Gtk3ResizeEvent(AWidget: PGtkWidget; AEvent: PGdkEvent; Data: gpointer): gboolean; cdecl;
@@ -4629,10 +4629,14 @@
         end;
       end;
     end;
+    //PGtkRadioMenuItem(Result)^.set_active(MenuItem.Checked);
   end
   else
   if MenuItem.IsCheckItem and not MenuItem.HasIcon then
-    Result := TGtkCheckMenuItem.new
+  begin
+    Result := TGtkCheckMenuItem.new;
+    PGtkCheckMenuItem(Result)^.set_active(MenuItem.Checked);
+  end
   else
     Result := TGtkMenuItem.new;
 
Index: lcl/interfaces/gtk3/gtk3winapi.inc
===================================================================
--- lcl/interfaces/gtk3/gtk3winapi.inc	(revision 63882)
+++ lcl/interfaces/gtk3/gtk3winapi.inc	(working copy)
@@ -116,7 +116,12 @@
       exit;
     end;
     if Gtk3IsGdkWindow(AWidget.Widget^.window) then
-      gdk_window_get_origin(AWidget.Widget^.window, @Pt.X, @Pt.Y)
+    begin
+      gdk_window_get_origin(AWidget.Widget^.window, @Pt.X, @Pt.Y);
+      gtk_widget_get_allocation(AWidget.Widget, @TempAlloc);
+      Pt.X += TempAlloc.x;
+      Pt.Y += TempAlloc.y;
+    end
     else
     begin
       gtk_widget_get_allocation(AWidget.Widget, @TempAlloc);
gtk3origin.diff (2,267 bytes)   

Anton Kavalenka

2020-09-12 17:53

reporter   ~0125513

Deep knowledge of LCL required.
Or should we just directly assign TButton.Constraints?

Anton Kavalenka

2020-09-12 18:01

reporter   ~0125514

Second patch assumes GroupIndex=0 is also valid group
gtk3origin-2.diff (2,709 bytes)   
Index: lcl/interfaces/gtk3/gtk3widgets.pas
===================================================================
--- lcl/interfaces/gtk3/gtk3widgets.pas	(revision 63882)
+++ lcl/interfaces/gtk3/gtk3widgets.pas	(working copy)
@@ -1495,7 +1495,7 @@
 
   Msg.SizeType := Msg.SizeType or Size_SourceIsInterface;
 
-  if ACtl.WidgetType*[wtEntry,wtComboBox,wtScrollBar,wtSpinEdit]<>[] then
+  if ACtl.WidgetType*[wtEntry,wtComboBox,wtScrollBar,wtSpinEdit,wtHintWindow]<>[] then
   begin
     Msg.Width := ACtl.LCLObject.Width;//Word(NewSize.cx);
     Msg.Height := ACtl.LCLObject.Height;//Word(NewSize.cy);
@@ -1512,7 +1512,7 @@
   end;
   ACtl.DeliverMessage(Msg);
 
-  if (wtWindow in ACtl.WidgetType) and
+ (* if (wtWindow in ACtl.WidgetType) and
     ((AGdkRect^.x <> ACtl.LCLObject.Left) or (AGdkRect^.y <> ACtl.LCLObject.Top)) then
   begin
     FillChar(MoveMsg, SizeOf(MoveMsg), #0);
@@ -1524,7 +1524,7 @@
     DebugLn('SEND MOVE MESSAGE X=',dbgs(AGdkRect^.x),' Y=',dbgs(AGdkRect^.y),' control ',dbgsName(ACtl.LCLObject));
     {$ENDIF}
     ACtl.DeliverMessage(MoveMsg);
-  end;
+  end;   *)
 end;
 
 function Gtk3ResizeEvent(AWidget: PGtkWidget; AEvent: PGdkEvent; Data: gpointer): gboolean; cdecl;
@@ -4622,7 +4622,7 @@
       if (ndx>0) then
       begin
         ParentMenu:=menuItem.Parent.Items[ndx-1];
-        if (MenuItem.GroupIndex>0) and (ParentMenu.GroupIndex=MenuItem.GroupIndex) then
+        if (MenuItem.GroupIndex>=0) and (ParentMenu.GroupIndex=MenuItem.GroupIndex) then
         begin
           pl:=PGtkRadioMenuItem(TGtk3MenuItem(ParentMenu.Handle).Widget)^.get_group;
           PGtkRadioMenuItem(Result)^.set_group(pl);
@@ -4629,10 +4629,14 @@
         end;
       end;
     end;
+    //PGtkRadioMenuItem(Result)^.set_active(MenuItem.Checked);
   end
   else
   if MenuItem.IsCheckItem and not MenuItem.HasIcon then
-    Result := TGtkCheckMenuItem.new
+  begin
+    Result := TGtkCheckMenuItem.new;
+    PGtkCheckMenuItem(Result)^.set_active(MenuItem.Checked);
+  end
   else
     Result := TGtkMenuItem.new;
 
Index: lcl/interfaces/gtk3/gtk3winapi.inc
===================================================================
--- lcl/interfaces/gtk3/gtk3winapi.inc	(revision 63882)
+++ lcl/interfaces/gtk3/gtk3winapi.inc	(working copy)
@@ -116,7 +116,12 @@
       exit;
     end;
     if Gtk3IsGdkWindow(AWidget.Widget^.window) then
-      gdk_window_get_origin(AWidget.Widget^.window, @Pt.X, @Pt.Y)
+    begin
+      gdk_window_get_origin(AWidget.Widget^.window, @Pt.X, @Pt.Y);
+      gtk_widget_get_allocation(AWidget.Widget, @TempAlloc);
+      Pt.X += TempAlloc.x;
+      Pt.Y += TempAlloc.y;
+    end
     else
     begin
       gtk_widget_get_allocation(AWidget.Widget, @TempAlloc);
gtk3origin-2.diff (2,709 bytes)   

Anton Kavalenka

2020-09-20 08:40

reporter   ~0125650

ping @Juha Manninen

Juha Manninen

2020-09-20 11:57

developer   ~0125656

Applied, thanks.

CudaText man_

2020-09-20 19:11

reporter   ~0125678

Thanks! I reopen - to tell you that popupmenu on gtk3 DONT show separator lines (demo has 2 separators).

Anton Kavalenka

2020-09-21 08:26

reporter   ~0125695

TGtk3MenuItem widget creates separators properly gtk3widgets.pas:4604

Your theme may not show separators. Mine dark Adwaita shows them very modestly.
separators.png (13,331 bytes)   
separators.png (13,331 bytes)   

Juha Manninen

2020-09-21 10:27

developer   ~0125699

Last edited: 2020-09-21 10:28

View 2 revisions

@CudaText man, your demo in GitHub is crappy.
When trying to open it says :
 Unable to read the project info file "/home/juha/SW/LazTest/MenuRadio/project1.lpi".
 In 'stream:' (line 50 pos 90): Expected "="

Downloading this single project from GitHub was a pain, too. I had to download each file separately. Git pull would get much more stuff.
I would appreciate a compressed attachment here instead.

Anton Kavalenka

2020-09-21 21:59

reporter   ~0125737

My variant of test App
radio_items.zip (3,797 bytes)

Juha Manninen

2020-09-22 11:02

developer   ~0125752

Thanks Anton.
The menu separators show just fine here also with LCL-GTK3. It must be a theme issue.
Resolving.

Issue History

Date Modified Username Field Change
2020-09-12 14:58 CudaText man_ New Issue
2020-09-12 17:49 Anton Kavalenka Note Added: 0125512
2020-09-12 17:49 Anton Kavalenka File Added: gtk3origin.diff
2020-09-12 17:51 Anton Kavalenka Note Edited: 0125512 View Revisions
2020-09-12 17:53 Anton Kavalenka Note Added: 0125513
2020-09-12 18:01 Anton Kavalenka Note Added: 0125514
2020-09-12 18:01 Anton Kavalenka File Added: gtk3origin-2.diff
2020-09-20 08:40 Anton Kavalenka Note Added: 0125650
2020-09-20 08:50 Juha Manninen Assigned To => Juha Manninen
2020-09-20 08:50 Juha Manninen Status new => assigned
2020-09-20 11:57 Juha Manninen Status assigned => resolved
2020-09-20 11:57 Juha Manninen Resolution open => fixed
2020-09-20 11:57 Juha Manninen Fixed in Revision => r63896
2020-09-20 11:57 Juha Manninen LazTarget => -
2020-09-20 11:57 Juha Manninen Widgetset GTK 3 => GTK 3
2020-09-20 11:57 Juha Manninen Note Added: 0125656
2020-09-20 19:11 CudaText man_ Status resolved => assigned
2020-09-20 19:11 CudaText man_ Resolution fixed => open
2020-09-20 19:11 CudaText man_ Note Added: 0125678
2020-09-21 08:26 Anton Kavalenka Note Added: 0125695
2020-09-21 08:26 Anton Kavalenka File Added: separators.png
2020-09-21 10:27 Juha Manninen Note Added: 0125699
2020-09-21 10:28 Juha Manninen Note Edited: 0125699 View Revisions
2020-09-21 21:59 Anton Kavalenka Note Added: 0125737
2020-09-21 21:59 Anton Kavalenka File Added: radio_items.zip
2020-09-22 11:02 Juha Manninen Status assigned => resolved
2020-09-22 11:02 Juha Manninen Resolution open => fixed
2020-09-22 11:02 Juha Manninen Widgetset GTK 3 => GTK 3
2020-09-22 11:02 Juha Manninen Note Added: 0125752
2020-09-24 17:32 CudaText man_ Status resolved => closed