From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,26a21b9e317dc639 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Received: by 10.224.183.16 with SMTP id ce16mr6402137qab.8.1354566105375; Mon, 03 Dec 2012 12:21:45 -0800 (PST) Received: by 10.49.86.106 with SMTP id o10mr2467265qez.14.1354566105308; Mon, 03 Dec 2012 12:21:45 -0800 (PST) Path: gf5ni46692076qab.0!nntp.google.com!c8no84360qao.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Mon, 3 Dec 2012 12:21:45 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=85.227.233.67; posting-account=l8k8IwoAAADeDydswOzwNzmn10qOk9gt NNTP-Posting-Host: 85.227.233.67 References: <9b0bcb37-8ae3-440f-af4f-a796702e4250@googlegroups.com> <6344b2a2-6ce5-4381-ad41-8dc4bf47902f@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: Re: Access type to member procedure of instance (Object Oriented programming in Ada) From: ake.ragnar.dahlgren@gmail.com Cc: mailbox@dmitry-kazakov.de Injection-Date: Mon, 03 Dec 2012 20:21:45 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Date: 2012-12-03T12:21:45-08:00 List-Id: On Monday, December 3, 2012 12:21:00 PM UTC+1, Dmitry A. Kazakov wrote: > On Sun, 2 Dec 2012 12:42:27 -0800 (PST), ake.ragnar.dahlgren@gmail.com >=20 > wrote: >=20 >=20 >=20 > > I gladly provide more details by giving an example of Ada code. The wit= h >=20 > > statements have been omitted and the GUI described by the >=20 > > main_window.glade file is assumed to contain a Label called Main_Label = and >=20 > > the window has a destroy signal called Main_Window_Quit: >=20 >=20 >=20 > 1. I cannot comment on Glade, I don't use it. >=20 >=20 >=20 > 2. What is the problem? >=20 >=20 >=20 > Why handling Quit signal requires MVC, especially, because there is no su= ch >=20 > signal, AFAIK? >=20 >=20 >=20 > 3. Is it about exiting GTK main loop? That does not need MVC at all. >=20 >=20 >=20 > In order to quit Gtk.Main.Main you have to call Gtk.Main.Quit. This is ma= de >=20 > from a handler of the "destroy" event of Gtk_Object_Record, which is call= ed >=20 > when a Gtk object is about to be destroyed. The object here is the main >=20 > window. That is it. >=20 >=20 >=20 > In order to initiate destruction of the main window otherwise than by mea= ns >=20 > of the window manager, the window manager does that when you press the >=20 > button [x] on window title, you should call the Destroy operation of >=20 > Gtk_Object_Record. The main window is Gtk_Window_Record, a descendant of. >=20 >=20 >=20 > Here is a minimal working sample of such application with a button to clo= se >=20 > it: >=20 >=20 >=20 > ----------------- simple.adb ----------------------------- >=20 > with Gtk.Object; use Gtk.Object; >=20 > with Gtk.Button; use Gtk.Button; >=20 > with Gtk.Window; use Gtk.Window; >=20 > with Gtk.Widget; use Gtk.Widget; >=20 > with Gtk.Table; use Gtk.Table; >=20 >=20 >=20 > with Gtk.Handlers; >=20 > with Gtk.Main; >=20 >=20 >=20 > procedure Simple is >=20 >=20 >=20 > package No_Data_Handlers is -- Event handlers with no user parameters >=20 > new Gtk.Handlers.Callback (Gtk_Widget_Record); >=20 > package Killer_Handlers is -- Handlers that take Gtk_Object >=20 > new Gtk.Handlers.User_Callback (Gtk_Widget_Record, Gtk_Object); >=20 >=20 >=20 > procedure Destroy (Widget : access Gtk_Widget_Record'Class) is >=20 > begin >=20 > Gtk.Main.Main_Quit; -- Exit the message loop, we are done >=20 > end Destroy; >=20 >=20 >=20 > procedure Clicked >=20 > ( Widget : access Gtk_Widget_Record'Class; >=20 > Object : Gtk_Object >=20 > ) is >=20 > begin >=20 > Destroy (Object); -- Kill the object passed >=20 > end Clicked; >=20 >=20 >=20 > Window : Gtk_Window; >=20 > Grid : Gtk_Table; >=20 > Button : Gtk_Button; >=20 >=20 >=20 > begin >=20 > Gtk.Main.Init; >=20 > Gtk.Window.Gtk_New (Window); >=20 > Gtk_New (Grid, 1, 1, False); >=20 > Add (Window, Grid); >=20 > Gtk_New (Button, "Clicked to kill"); >=20 > Attach (Grid, Button, 0, 1, 0, 1); >=20 > No_Data_Handlers.Connect >=20 > ( Window, >=20 > "destroy", >=20 > Destroy'Access >=20 > ); >=20 > Killer_Handlers.Connect >=20 > ( Button, >=20 > "clicked", >=20 > Clicked'Access, >=20 > Gtk_Object_Record'Class (Window.all)'Access >=20 > ); >=20 > Show_All (Grid); >=20 > Show (Window); >=20 >=20 >=20 > Gtk.Main.Main; >=20 > end Simple; >=20 > ----------------------------------------------------------- >=20 > As you see it is almost trivial. >=20 >=20 >=20 > 4. Regarding MVC. When deploying it, the first questions to answer are: >=20 >=20 >=20 > 4.1. What is the model? >=20 > 4.2. What is the view? >=20 > 4.3. What is the controller? >=20 >=20 >=20 > http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller >=20 >=20 >=20 > An example of using MVC in Gtk is combo box: >=20 >=20 >=20 > The model is Gtk_List_Store_Record, contains a row per box entry. A >=20 > designated column of the row determines the entry's contents. >=20 >=20 >=20 > The view is Gtk_Combo_Box_Record widget itself >=20 >=20 >=20 > The controller is anything else, which modifies the model, e.g. adds new >=20 > rows to the model. Typically an event callback responding to user actions= . >=20 >=20 >=20 > --=20 >=20 > Regards, >=20 > Dmitry A. Kazakov >=20 > http://www.dmitry-kazakov.de I agree with you that the example is almost trivial and that it is a good d= emonstratiion on how to use Gtkada. However, I am currently toying with the= idea of making Gtkada applications using Glade-3 which is very similiar bu= t a little bit different. > 2. What is the problem? >=20 >=20 >=20 > Why handling Quit signal requires MVC, especially, because there is no su= ch >=20 > signal, AFAIK? There are two problems that together would require one to structure the cod= e as I have done. 1) Automated tests (AUnit). The code should be testable. Perhaps one would = like to have a test that verifies that Gtk.Main.Main_Quit is called when th= e "destroy" event of Gtk_Object_Record is triggered from the main window an= d so on. To make the code testable one needs to separate the GUI code from = the logic somehow. 2) Perhaps one would like two have two views who are "connected" to the sam= e controller instance (code reusability). If one updates a field on the con= troller instance then that change should be reflected in the two views. Som= ething like the following: package body Application is Main_Window_Controller : Controllers.Main_Window.Controller_Ref_Type; Main_Window_1 : Views.Main_Window.Main_Window_Ref_Type; Main_Window_2 : Views.Main_Window.Main_Window_Ref_Type; procedure On_Main_Window_Quit(Object : access Gtkada.Builder.Gtkada_Buil= der_Record'Class) renames Main_Window_Controller.On_Quit; procedure Main is begin Main_Window_Controller :=3D new Controllers.Main_Window.Controller_Ty= pe; Main_Window_1 :=3D Views.Main_Window.Create_Main_Window(Main_Window_C= ontroller, On_Main= _Window_Quit'Access); Main_Window_2 :=3D Views.Main_Window.Create_Main_Window(Main_Window_C= ontroller, On_Main= _Window_Quit'Access); Main_Window_1.Show; Main_Window_2.Show; Gtk.Main.Main; -- Enter the main gtk loop. end Main; begin Gtk.Main.Init; end Application; Not that I have in mind an actual real world application that would require= two identical windows, but of theoretical interest. It is possible in othe= r languages, and I'm thinking why not Ada? Best regards, =C5ke Ragnar Dahlgren