/*
 * Java-Gnome Bindings Library
 *
 * Copyright 1998-2004 the Java-Gnome Team, all rights reserved.
 *
 * The Java-Gnome bindings library is free software distributed under
 * the terms of the GNU Library General Public License version 2.
 */

package org.gnu.gtk;

import org.gnu.glib.GObject;
import org.gnu.glib.Type;

/**
 * A RadioMenuItem is a CheckMenuItem that belongs to a group.
 * At each instant exactly one of the RadioMenuItems from the
 * group is selected.
 */
public class RadioMenuItem extends CheckMenuItem {

	public RadioMenuItem(RadioMenuItem[] group) {
		super(init1(group));
	}
	
	private static int init1(RadioMenuItem[] group) {
		int[] groupHandle;
		if (null != group) {
			groupHandle = new int[group.length];
			for (int i = 0; i < group.length; i++) {
				groupHandle[i] = group[i].getHandle();
			}
		} else
			groupHandle = null;
		return gtk_radio_menu_item_new(groupHandle);
	}
	
	/**
	 * Create a new RadioMenuItem object adding it to the same <i>group</i>
	 * as the provided RadioMenuItem.  If this is the first RadioMenuItem
	 * pass <code>null</code> for this parameter.
	 * 
	 * @param group A RadioMenuItem that belongs to the group that we wish
	 * to add this newly constructed RadioMenuItem to.  If this is the first
	 * RadioMenuItem in the group just pass <code>null</code>.
	 * @param label The text label to assign to this RadioButton.
	 * @param hasMnemonic An indicator to inform the widget if the label
	 * contains a mnemonic.
	 */
	public RadioMenuItem(RadioMenuItem[] group, String label, boolean hasMnemonic) {
		super(init2(group, label, hasMnemonic));
	}
	
	private static int init2(RadioMenuItem[] group, String label, boolean hasMnemonic) {
		int[] groupHandle;
		if (null != group) {
			groupHandle = new int[group.length];
			for (int i = 0; i < group.length; i++) {
				groupHandle[i] = group[i].getHandle();
			}
		} else
			groupHandle = null;
		if (hasMnemonic) {
			return gtk_radio_menu_item_new_with_mnemonic(groupHandle, label);
		} else {
			return gtk_radio_menu_item_new_with_label(groupHandle, label);
		}
	}
	
	public RadioMenuItem(RadioMenuItem group) {
		super(init3(group));
	}
	
	private static int init3(RadioMenuItem group) {
		int hndl;
		if (null == group)
			hndl = 0;
		else
			hndl = group.getHandle();
		return gtk_radio_menu_item_new_from_widget(hndl);
	}
	
	public RadioMenuItem(RadioMenuItem group, String label, boolean hasMnemonic) {
		super(init4(group, label, hasMnemonic));
	}
	
	private static int init4(RadioMenuItem group, String label, boolean hasMnemonic) {
		int hndl;
		if (null == group)
			hndl = 0;
		else
			hndl = group.getHandle();
		if (hasMnemonic) {
			return gtk_radio_menu_item_new_with_mnemonic_from_widget(hndl, label);
		} else {
			return gtk_radio_menu_item_new_with_label_from_widget(hndl, label);
		}
	}

	/**
	 * Construct a RadioMenuItem using a handle to a native resource.
	 */
	RadioMenuItem(int handle) {
	    super(handle);
	}

	public RadioMenuItem[] getGroup() {
		int[] hndls = gtk_radio_menu_item_get_group(getHandle());
		RadioMenuItem[] items = new RadioMenuItem[hndls.length];
		for (int i = 0; i < hndls.length; i++) {
			GObject obj = retrieveGObject(hndls[i]);
			if (null != obj)
				items[i] = (RadioMenuItem)obj;
			else
				items[i] = new RadioMenuItem(hndls[i]);
		}
		return items;
	}
	
	public void setGroup(RadioMenuItem[] group) {
		int[] hndls = new int[group.length];
		for (int i = 0; i < group.length; i++) {
			hndls[i] = group[i].getHandle();
		}
		gtk_radio_menu_item_set_group(getHandle(), hndls);
	}
	
	/**
	 * Retrieve the runtime type used by the GLib library.
	 */
	public static Type getType() {
		return new Type(gtk_radio_menu_item_get_type());
	}

	
	/****************************************
	 * BEGINNING OF GENERATED CODE
	 ****************************************/
	native static final protected int gtk_radio_menu_item_get_type();
	native static final protected int gtk_radio_menu_item_new(int[] group);
	native static final protected int gtk_radio_menu_item_new_with_label(int[] group, String label);
	native static final protected int gtk_radio_menu_item_new_with_mnemonic(int[] group, String label);
	native static final protected int gtk_radio_menu_item_new_from_widget(int group);
	native static final protected int gtk_radio_menu_item_new_with_mnemonic_from_widget(int group, String label);
	native static final protected int gtk_radio_menu_item_new_with_label_from_widget(int group, String label);
	native static final protected int[] gtk_radio_menu_item_get_group(int menu);
	native static final protected void gtk_radio_menu_item_set_group(int menu, int[] group);
	/****************************************
	 * END OF GENERATED CODE
	 ****************************************/
}
