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=1.0 required=5.0 tests=BAYES_00,DATE_IN_PAST_24_48, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,26a21b9e317dc639 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit Received: by 10.14.173.136 with SMTP id v8mr16838361eel.2.1354677423630; Tue, 04 Dec 2012 19:17:03 -0800 (PST) Path: ha8ni145744wib.1!nntp.google.com!feeder2.cambriumusenet.nl!feed.tweaknews.nl!81.171.88.16.MISMATCH!eweka.nl!hq-usenetpeers.eweka.nl!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!border4.nntp.ams.giganews.com!border2.nntp.ams.giganews.com!nntp.giganews.com!rt.uk.eu.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Access type to member procedure of instance (Object Oriented programming in Ada) Date: Mon, 3 Dec 2012 12:21:00 +0100 Organization: cbb software GmbH Message-ID: References: <9b0bcb37-8ae3-440f-af4f-a796702e4250@googlegroups.com> <6344b2a2-6ce5-4381-ad41-8dc4bf47902f@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: kWJV5lTRAyCzy8lsfOrlcw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2012-12-03T12:21:00+01:00 List-Id: 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