comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Access type to member procedure of instance (Object Oriented programming in Ada)
Date: Mon, 3 Dec 2012 12:21:00 +0100
Date: 2012-12-03T12:21:00+01:00	[thread overview]
Message-ID: <agc909hka7hk$.offs8wrgrm0x$.dlg@40tude.net> (raw)
In-Reply-To: 6344b2a2-6ce5-4381-ad41-8dc4bf47902f@googlegroups.com

On Sun, 2 Dec 2012 12:42:27 -0800 (PST), ake.ragnar.dahlgren@gmail.com
wrote:

> I gladly provide more details by giving an example of Ada code. The with
> statements have been omitted and the GUI described by the
> main_window.glade file is assumed to contain a Label called Main_Label and
> the window has a destroy signal called Main_Window_Quit:

1. I cannot comment on Glade, I don't use it.

2. What is the problem?

Why handling Quit signal requires MVC, especially, because there is no such
signal, AFAIK?

3. Is it about exiting GTK main loop? That does not need MVC at all.

In order to quit Gtk.Main.Main you have to call Gtk.Main.Quit. This is made
from a handler of the "destroy" event of Gtk_Object_Record, which is called
when a Gtk object is about to be destroyed. The object here is the main
window. That is it.

In order to initiate destruction of the main window otherwise than by means
of the window manager, the window manager does that when you press the
button [x] on window title, you should call the Destroy operation of
Gtk_Object_Record. The main window is Gtk_Window_Record, a descendant of.

Here is a minimal working sample of such application with a button to close
it:

----------------- simple.adb -----------------------------
with Gtk.Object;  use Gtk.Object;
with Gtk.Button;  use Gtk.Button;
with Gtk.Window;  use Gtk.Window;
with Gtk.Widget;  use Gtk.Widget;
with Gtk.Table;   use Gtk.Table;

with Gtk.Handlers;
with Gtk.Main;

procedure Simple is

   package No_Data_Handlers is -- Event handlers with no user parameters
      new Gtk.Handlers.Callback (Gtk_Widget_Record);
   package Killer_Handlers is -- Handlers that take Gtk_Object
      new Gtk.Handlers.User_Callback (Gtk_Widget_Record, Gtk_Object);

   procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
   begin
     Gtk.Main.Main_Quit; -- Exit the message loop, we are done
   end Destroy;

   procedure Clicked
             (  Widget : access Gtk_Widget_Record'Class;
                Object : Gtk_Object
             )  is
   begin
      Destroy (Object); -- Kill the object passed
   end Clicked;

   Window : Gtk_Window;
   Grid   : Gtk_Table;
   Button : Gtk_Button;

begin
   Gtk.Main.Init;
   Gtk.Window.Gtk_New (Window);
   Gtk_New (Grid, 1, 1, False);
   Add (Window, Grid);
   Gtk_New (Button, "Clicked to kill");
   Attach (Grid, Button, 0, 1, 0, 1);
   No_Data_Handlers.Connect
   (  Window,
      "destroy",
      Destroy'Access
   );
   Killer_Handlers.Connect
   (  Button,
      "clicked",
      Clicked'Access,
      Gtk_Object_Record'Class (Window.all)'Access
   );
   Show_All (Grid);
   Show (Window);

   Gtk.Main.Main;
end Simple;
-----------------------------------------------------------
As you see it is almost trivial.

4. Regarding MVC. When deploying it, the first questions to answer are:

4.1. What is the model?
4.2. What is the view?
4.3. What is the controller?

http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

An example of using MVC in Gtk is combo box:

The model is Gtk_List_Store_Record, contains a row per box entry. A
designated column of the row determines the entry's contents.

The view is Gtk_Combo_Box_Record widget itself

The controller is anything else, which modifies the model, e.g. adds new
rows to the model. Typically an event callback responding to user actions.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2012-12-05  3:17 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-19  9:59 Access type to member procedure of instance (Object Oriented programming in Ada) ake.ragnar.dahlgren
2012-11-19 11:13 ` Georg Bauhaus
2012-11-19 11:39 ` Brian Drummond
2012-11-20 11:43   ` Brian Drummond
2012-11-20 21:57     ` Randy Brukardt
2012-11-19 13:03 ` sbelmont700
2012-11-19 16:18 ` Adam Beneschan
2012-11-19 17:02   ` Peter C. Chapin
2012-11-19 18:23     ` Adam Beneschan
2012-11-19 20:57       ` Peter C. Chapin
2012-11-19 21:26       ` Dmitry A. Kazakov
2012-11-19 22:19         ` Adam Beneschan
2012-11-20 10:12           ` Dmitry A. Kazakov
2012-11-20 21:51             ` Randy Brukardt
2012-11-21  8:24               ` Dmitry A. Kazakov
2012-11-21 22:19                 ` Randy Brukardt
2012-11-20 10:59     ` Brian Drummond
2012-11-19 20:22 ` ake.ragnar.dahlgren
2012-11-20 11:16   ` Brian Drummond
2012-11-19 20:52 ` ake.ragnar.dahlgren
2012-11-19 21:56   ` Dmitry A. Kazakov
2012-11-22  9:49     ` ake.ragnar.dahlgren
2012-11-19 22:13   ` sbelmont700
2012-11-19 23:59 ` Randy Brukardt
2012-11-20  0:05   ` Randy Brukardt
2012-11-20  1:00     ` Adam Beneschan
2012-11-20 21:38       ` Randy Brukardt
2012-11-20 23:43         ` Adam Beneschan
2012-11-21 22:12           ` Randy Brukardt
2012-11-22  1:59             ` Adam Beneschan
2012-11-29  2:43               ` Randy Brukardt
2012-11-20  0:52   ` Adam Beneschan
2012-11-20 21:34     ` Randy Brukardt
2012-11-20 11:28   ` Brian Drummond
2012-11-20 14:27     ` Georg Bauhaus
2012-11-20 15:52     ` Adam Beneschan
2012-11-22  9:47 ` ake.ragnar.dahlgren
2012-11-22 10:25   ` Dmitry A. Kazakov
2012-12-02 20:42     ` ake.ragnar.dahlgren
2012-12-03 11:21       ` Dmitry A. Kazakov [this message]
2012-12-03 20:21         ` ake.ragnar.dahlgren
2012-12-03 22:15           ` Dmitry A. Kazakov
2012-12-25 21:51           ` Gustaf Thorslund
2012-12-26 18:11             ` ake.ragnar.dahlgren
2012-11-22 12:13   ` Brian Drummond
2012-12-03 16:17     ` ake.ragnar.dahlgren
2012-12-03 21:56       ` Brian Drummond
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox