Skip to content

Commit 4fda61d

Browse files
committed
Q310-003 Added local Get_Icon method to proper retrieving icon
Change-Id: I4ff85e3d4a79c6e6cafc392622fba24ab6eea84c
1 parent f300278 commit 4fda61d

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

src/gtkada-mdi.adb

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ with GNAT.Strings; use GNAT.Strings;
4949

5050
with Glib.Convert; use Glib.Convert;
5151
with Glib.Error; use Glib.Error;
52+
with Glib.G_Icon; use Glib.G_Icon;
5253
with Glib.Menu; use Glib.Menu;
5354
with Glib.Object; use Glib.Object;
5455
with Glib.Properties; use Glib.Properties;
@@ -677,6 +678,11 @@ package body Gtkada.MDI is
677678

678679
end Close_Button;
679680

681+
function Get_Icon
682+
(Child : not null access MDI_Child_Record'Class)
683+
return Gtk_Image;
684+
-- Retrieve icon. Can return null.
685+
680686
package body Close_Button is separate;
681687

682688
---------------------
@@ -1244,7 +1250,7 @@ package body Gtkada.MDI is
12441250
D.Icon.Set_From_Icon_Name
12451251
(C.Icon_Name.all, Size => Icon_Size_Menu);
12461252
elsif C.Title_Icon /= null then
1247-
Scaled := C.Title_Icon.Get; -- still owned by Title_Icon
1253+
Scaled := Get_Icon (C);
12481254
Set_Child_Visible (D.Icon, Scaled /= null);
12491255
if Scaled /= null then
12501256
Scaled := Scale_Simple (Scaled, 32, 32);
@@ -3173,6 +3179,35 @@ package body Gtkada.MDI is
31733179
return Child.Title_Icon.Get;
31743180
end Get_Icon;
31753181

3182+
--------------
3183+
-- Get_Icon --
3184+
--------------
3185+
3186+
function Get_Icon
3187+
(Child : not null access MDI_Child_Record'Class)
3188+
return Gtk_Image
3189+
is
3190+
Result : Gtk_Image;
3191+
3192+
Pixbuf : Gdk_Pixbuf;
3193+
G_Icon : Glib.G_Icon.G_Icon;
3194+
Size : Gtk.Enums.Gtk_Icon_Size;
3195+
3196+
begin
3197+
Pixbuf := Child.Title_Icon.Get; -- still owned by the image
3198+
if Pixbuf /= null then
3199+
Gtk_New (Result, Pixbuf);
3200+
3201+
else
3202+
Child.Title_Icon.Get (G_Icon, Size);
3203+
if G_Icon /= Null_G_Icon then
3204+
Result := Gtk_Image_New_From_Gicon (G_Icon, Size);
3205+
end if;
3206+
end if;
3207+
3208+
return Result;
3209+
end Get_Icon;
3210+
31763211
-------------------
31773212
-- Get_Icon_Name --
31783213
-------------------
@@ -5531,11 +5566,10 @@ package body Gtkada.MDI is
55315566
Child : MDI_Child;
55325567
It : Gtk_Radio_Menu_Item;
55335568
Box : Gtk_Box;
5534-
Pixbuf : Gdk_Pixbuf;
5535-
Pixmap : Gtk_Image;
55365569
Label : Gtk_Accel_Label;
55375570
Children, L : Widget_List.Glist;
55385571
W : Gtk_Widget;
5572+
Icon : Gtk_Image;
55395573
begin
55405574
-- Remove all items
55415575

@@ -5569,10 +5603,9 @@ package body Gtkada.MDI is
55695603
Gtk_New_Hbox (Box, Homogeneous => False, Spacing => 5);
55705604
It.Add (Box);
55715605

5572-
Pixbuf := Child.Title_Icon.Get; -- still owned by the image
5573-
if Pixbuf /= null then
5574-
Gtk_New (Pixmap, Pixbuf);
5575-
Box.Pack_Start (Pixmap, Expand => False);
5606+
Icon := Get_Icon (Child);
5607+
if Icon /= null then
5608+
Box.Pack_Start (Icon, Expand => False);
55765609
end if;
55775610

55785611
Gtk_New (Label, Child.Short_Title.all);

0 commit comments

Comments
 (0)