[gtkada] Getting Toplevel for Gtk_Entry
Rick Duley
30294025 at student.murdoch.edu.au
Mon Jun 13 03:50:38 CEST 2005
Hi folks
I have a Gtk_Entry within a Box, within a Frame, within a Box, within a Toplevel
Window thus:
+---------- Window ------------+
| +--------- VBox -----------+ |
| | +---- Frame&Label -----+ | |
| | | +----- HBox -------+ | | |
| | | | +--------------+ | | | |
| | | | | Entry | | | | |
| | | | +--------------+ | | | |
| | | +------------------+ | | |
| | +----------------------+ | |
| +--------------------------+ |
+------------------------------+
Here is a code segment:
procedure On_Analyse60_Source_Folder_Entry_Changed
(Object : access Gtk_Entry_Record'Class)
is
Main_Window : Gtk_Window := Get_Parent_Window(Widget => Object);
begin
. . .
Any attempt to compile using GPS 2.1.0 (20041129) hosted on pentium-mingw32msv
with GNAT GAP 1.1.0 (20041209-323) fails with the following error message:
analyse60_window_pkg-callbacks.adb:69:29: expected type "Gtk_Window" defined at
gtk-window.ads:64
analyse60_window_pkg-callbacks.adb:69:29: found type "Gdk_Drawable" defined at
gdk.ads:46
*Q.1. Why would Get_Parent_Window return a Gdk_Drawable in this case?*
The only thing I can get to work is:
procedure On_Analyse60_Source_Folder_Entry_Changed
(Object : access Gtk_Entry_Record'Class)
is
Main_Window : constant Gtk_Widget := Get_Toplevel(Widget => Object);
begin
-- debug
Put_Line("Widget is "
& Get_Name(Widget => Main_Window));
Put_Line("Entry contains "
& Get_Text(The_Entry => Object));
-- debug
end On_Analyse60_Source_Folder_Entry_Changed;
This prints the name I set in the Gtk_Window_Record and the text I type into the
entry. My problem is that, when the content of the Entry is changed, I wish to
save the text in the Entry into an Unbounded String identified as
"Source_Folder" contained in a record called "Arguments" to which I have an
access in the Gtk_Window_Record (now represented by Main_Window). This access
is allocated memory in the Initialize procedure.
Given the code:
procedure On_Analyse60_Source_Folder_Entry_Changed
(Object : access Gtk_Entry_Record'Class)
is
Main_Window : constant Gtk_Widget := Get_Toplevel(Widget => Object);
begin
Main_Window.Arguments.Source_Folder := -- line 79
To_Unbounded_String(Get_Text(The_Entry => Object));
-- debug
Put_Line(To_String(Main_Window.Arguments.Source_Folder)); -- line 83
-- debug
end On_Analyse60_Source_Folder_Entry_Changed;
I get the error messages:
analyse60_window_pkg-callbacks.adb:79:18: no selector "Arguments" for type
"Gtk_Widget_Record'Class" defined at gtk-widget.ads:74
analyse60_window_pkg-callbacks.adb:83:37: no selector "Arguments" for type
"Gtk_Widget_Record'Class" defined at gtk-widget.ads:74
That's fair enough. Main_Window _is_ declared as a Gtk_Widget. It has to be -
Get_Toplevel returns a Gtk_Widget - but this particular Widget is a Gtk_Window.
Not only that, it's a Window I know as a named Gtk_Window_Record which has
something named "Arguments" in it! Here it is:
type Analyse60_Window_Record is new Gtk_Window_Record with record
Arguments : Analyst.Arguments_Access_Type;
-- Storage access for the user-defined arguments.
Analyse60_Base_Box : Gtk_Vbox;
. . .
Analyse60_Source_Folder_Frame : Gtk_Frame;
Analyse60_Source_Folder_Hbox : Gtk_Hbox;
Analyse60_Source_Folder_Entry : Gtk_Entry;
Analyse60_Source_Folder_Label : Gtk_Label;
. . .
end record;
According to my way of thinking the procedure
On_Analyse60_Source_Folder_Entry_Changed above should, when the content of
Object is changed, store the text in Object in the Unbounded String in the
record within the window_record. Then the debug line should read that
Unbounded String and print it. But it don't!
*Q.2. What have I done wrong?*
Please, don't just tell me what's wrong - please show me what's right!
Thanks
-------------------------------------------
"Professional qualitative judgement
consists in knowing the rules
for using (or occasionally breaking)
the rules."
D. Royce Sadler
-------------------------------------------
Rick Duley
Murdoch University
School of Engineering Science
Perth, Western Australia
http://eng.murdoch.edu.au/~rick
aussie : 040 910 6049 .-_|\
o'seas : + 61 40 910 6049 / \
perth *_.-._/
v
More information about the gtkada
mailing list