From: Stalkern 2 Reply-To: stalkern2 at tin.it To: Richard Jones Subject: Re: Toggle button callback question Date: Tue, 6 May 2003 16:50:10 +0200 References: <20030506141056.GB9761 at redhat.com> In-Reply-To: <20030506141056.GB9761 at redhat.com> Cc: lablgtk at kaba.or.jp MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200305061650.10042.stalkern2 at tin.it> Il Tuesday 06 May 2003 16:10, Richard Jones ha scritto: > I think this is a very simple question - but it seems to be defeating > me nevertheless. > > I have code which looks like this: > > let menu_bold () = > (* I want this function to do two different things depending on whether > the toggle button is now active or inactive. *) > > let main () = > (* ..... *) > > (* This is where I create my toolbar containing a toggle button. *) > let toolbar = GButton.toolbar ~packing:vbox#pack () in > toolbar#insert_toggle_button ~text:"Bold" ~callback: menu_bold (); > > > The problem is that > > (a) The menu_bold cannot 'see' the button object, so it can't call > button#active to find the state. associate a change in a ref value to your callback (and do the same for radio buttons) > > (b) I'd do this in C using a global variable to store the button object > or a forward prototype of some sort. Neither of these things seem > to exist in OCaml. (see above...) bye Ernesto