gtk: Make the Group property for Radio* widgets a properly typed array

The Group property for all the Radio* classes (RadioAction, RadioButton,
RadioMenuItem and RadioToolButton) was exposed as a GLib.SList,
with its elements untyped.

We now hide the various Group properties and have custom code to handle
them correctly.
This commit is contained in:
Bertrand Lorentz 2012-11-15 12:05:45 +01:00
parent d8aa4ab275
commit 6809865526
9 changed files with 177 additions and 9 deletions

View File

@ -60,7 +60,7 @@ namespace Gtk {
public void Add (RadioActionEntry[] entries, int value, ChangedHandler changed)
{
GLib.SList group = new GLib.SList (typeof (RadioAction));
RadioAction[] group = null;
RadioAction[] actions = new RadioAction[entries.Length];
for (int i = 0; i < entries.Length; i++) {
actions[i] = new RadioAction (entries[i].name, entries[i].label,

View File

@ -486,19 +486,30 @@
<attr path="/api/namespace/object[@cname='GtkPrintSettings']/method[@name='Foreach']/*/*[@name='func']" name="scope">call</attr>
<attr path="/api/namespace/object[@cname='GtkPrintSettings']/method[@name='ToFile']/*/*[@name='file_name']" name="type">const-gfilename*</attr>
<attr path="/api/namespace/object[@cname='GtkProgressBar']" name="parent">GtkWidget</attr>
<attr path="/api/namespace/object[@cname='GtkRadioAction']/method[@name='GetGroup']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioAction']/method[@name='SetGroup']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioAction']/property[@name='Group']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioButton']/constructor[@cname='gtk_radio_button_new']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioButton']/constructor[@cname='gtk_radio_button_new_with_label_from_widget']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioButton']/constructor[@cname='gtk_radio_button_new_with_label']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioButton']/constructor[@cname='gtk_radio_button_new_with_mnemonic']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioButton']/constructor[@cname='gtk_radio_button_new_from_widget']/*/*[@name='radio_group_member']" name="property_name">group</attr>
<attr path="/api/namespace/object[@cname='GtkRadioButton']/constructor[@cname='gtk_radio_button_new_with_mnemonic_from_widget']/*/*[@name='radio_group_member']" name="property_name">group</attr>
<attr path="/api/namespace/object[@cname='GtkRadioButton']/method[@name='GetGroup']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioButton']/method[@name='SetGroup']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioButton']/property[@name='Group']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioMenuItem']/constructor[@cname='gtk_radio_menu_item_new']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioMenuItem']/constructor[@cname='gtk_radio_menu_item_new_with_label']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioMenuItem']/constructor[@cname='gtk_radio_menu_item_new_with_mnemonic']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioMenuItem']/constructor[@cname='gtk_radio_menu_item_new_with_label_from_widget']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioMenuItem']/method[@name='GetGroup']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioMenuItem']/method[@name='SetGroup']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioMenuItem']/property[@name='Group']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioToolButton']/constructor[@cname='gtk_radio_tool_button_new']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioToolButton']/constructor[@cname='gtk_radio_tool_button_new_from_stock']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioToolButton']/method[@name='GetGroup']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioToolButton']/method[@name='SetGroup']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRadioToolButton']/property[@name='Group']" name="hidden">1</attr>
<attr path="/api/namespace/object[@cname='GtkRcStyle']/field[@name='Name']" name="writeable">true</attr>
<attr path="/api/namespace/object[@cname='GtkRcStyle']/field[@name='BgPixmapName']" name="writeable">true</attr>
<attr path="/api/namespace/object[@cname='GtkRcStyle']/field[@name='FontDesc']" name="writeable">true</attr>

View File

@ -66,6 +66,7 @@ sources = \
PaperSize.cs \
Plug.cs \
Printer.cs \
RadioAction.cs \
RadioActionEntry.cs \
RadioButton.cs \
RadioMenuItem.cs \

54
gtk/RadioAction.cs Normal file
View File

@ -0,0 +1,54 @@
// Gtk.RadioAction.cs - Gtk RadioAction class customizations
//
// Author: Bertrand Lorentz <bertrand.lorentz@gmail.com>
//
// Copyright (c) 2006 Bertrand Lorentz
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
namespace Gtk
{
using System;
using System.Runtime.InteropServices;
public partial class RadioAction
{
[DllImport("libgtk-win32-3.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr gtk_radio_action_get_group(IntPtr raw);
[DllImport ("libgtk-win32-3.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gtk_radio_action_set_group(IntPtr raw, IntPtr list);
[GLib.Property ("group")]
public RadioAction[] Group {
get {
IntPtr raw_ret = gtk_radio_action_get_group(Handle);
RadioAction[] ret = (RadioAction[]) GLib.Marshaller.ListPtrToArray (raw_ret, typeof(GLib.SList), false, false, typeof(RadioAction));
return ret;
}
set {
IntPtr native_group = IntPtr.Zero;
if (value != null) {
GLib.List list = new GLib.List(IntPtr.Zero);
foreach (RadioAction item in value) {
list.Append (item.Handle);
}
native_group = list.Handle;
}
gtk_radio_action_set_group(Handle, native_group);
}
}
}
}

View File

@ -35,5 +35,31 @@ namespace Gtk {
Raw = gtk_radio_button_new_with_mnemonic (IntPtr.Zero, native);
GLib.Marshaller.Free (native);
}
[DllImport("libgtk-win32-3.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr gtk_radio_button_get_group(IntPtr raw);
[DllImport ("libgtk-win32-3.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gtk_radio_button_set_group(IntPtr raw, IntPtr list);
[GLib.Property ("group")]
public RadioButton[] Group {
get {
IntPtr raw_ret = gtk_radio_button_get_group(Handle);
RadioButton[] ret = (RadioButton[]) GLib.Marshaller.ListPtrToArray (raw_ret, typeof(GLib.SList), false, false, typeof(RadioButton));
return ret;
}
set {
IntPtr native_group = IntPtr.Zero;
if (value != null) {
GLib.List list = new GLib.List(IntPtr.Zero);
foreach (RadioButton item in value) {
list.Append (item.Handle);
}
native_group = list.Handle;
}
gtk_radio_button_set_group(Handle, native_group);
}
}
}
}

View File

@ -43,11 +43,10 @@ namespace Gtk {
GLib.Marshaller.Free (label_as_native);
}
[DllImport ("libgtk-win32-3.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr gtk_radio_menu_item_new_with_mnemonic(IntPtr group, IntPtr label);
public RadioMenuItem (GLib.SList group, string label) : base (IntPtr.Zero)
public RadioMenuItem (RadioMenuItem[] group, string label) : base (IntPtr.Zero)
{
if (GetType () != typeof (RadioMenuItem)) {
CreateNativeObject (new string [0], new GLib.Value [0]);
@ -60,8 +59,42 @@ namespace Gtk {
return;
}
IntPtr native_label = GLib.Marshaller.StringToPtrGStrdup (label);
Raw = gtk_radio_menu_item_new_with_mnemonic(group == null ? IntPtr.Zero : group.Handle, native_label);
IntPtr native_group = IntPtr.Zero;
if (group != null) {
GLib.List list = new GLib.List(IntPtr.Zero);
foreach (RadioMenuItem item in group) {
list.Append (item.Handle);
}
native_group = list.Handle;
}
Raw = gtk_radio_menu_item_new_with_mnemonic(native_group, native_label);
GLib.Marshaller.Free (native_label);
}
[DllImport("libgtk-win32-3.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr gtk_radio_menu_item_get_group(IntPtr raw);
[DllImport ("libgtk-win32-3.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gtk_radio_menu_item_set_group(IntPtr raw, IntPtr list);
[GLib.Property ("group")]
public RadioMenuItem[] Group {
get {
IntPtr raw_ret = gtk_radio_menu_item_get_group(Handle);
RadioMenuItem[] ret = (RadioMenuItem[]) GLib.Marshaller.ListPtrToArray (raw_ret, typeof(GLib.SList), false, false, typeof(RadioMenuItem));
return ret;
}
set {
IntPtr native_group = IntPtr.Zero;
if (value != null) {
GLib.List list = new GLib.List(IntPtr.Zero);
foreach (RadioMenuItem item in value) {
list.Append (item.Handle);
}
native_group = list.Handle;
}
gtk_radio_menu_item_set_group(Handle, native_group);
}
}
}
}

View File

@ -28,20 +28,28 @@ namespace Gtk {
[DllImport ("libgtk-win32-3.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr gtk_radio_tool_button_new (IntPtr group);
public RadioToolButton (GLib.SList group) : base (IntPtr.Zero)
public RadioToolButton (RadioToolButton[] group) : base (IntPtr.Zero)
{
if (GetType () != typeof (RadioToolButton)) {
CreateNativeObject (new string [0], new GLib.Value [0]);
Group = group;
return;
}
Raw = gtk_radio_tool_button_new(group == null ? IntPtr.Zero : group.Handle);
IntPtr native_group = IntPtr.Zero;
if (group != null) {
GLib.List list = new GLib.List(IntPtr.Zero);
foreach (RadioToolButton item in group) {
list.Append (item.Handle);
}
native_group = list.Handle;
}
Raw = gtk_radio_tool_button_new(native_group);
}
[DllImport ("libgtk-win32-3.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr gtk_radio_tool_button_new_from_stock (IntPtr group, IntPtr stock_id);
public RadioToolButton (GLib.SList group, string stock_id) : base (IntPtr.Zero)
public RadioToolButton (RadioToolButton[] group, string stock_id) : base (IntPtr.Zero)
{
if (GetType () != typeof (RadioToolButton)) {
GLib.Value[] vals = new GLib.Value [1];
@ -52,8 +60,42 @@ namespace Gtk {
return;
}
IntPtr stock_id_as_native = GLib.Marshaller.StringToPtrGStrdup (stock_id);
Raw = gtk_radio_tool_button_new_from_stock(group == null ? IntPtr.Zero : group.Handle, stock_id_as_native);
IntPtr native_group = IntPtr.Zero;
if (group != null) {
GLib.List list = new GLib.List(IntPtr.Zero);
foreach (RadioToolButton item in group) {
list.Append (item.Handle);
}
native_group = list.Handle;
}
Raw = gtk_radio_tool_button_new_from_stock(native_group, stock_id_as_native);
GLib.Marshaller.Free (stock_id_as_native);
}
[DllImport("libgtk-win32-3.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr gtk_radio_tool_button_get_group(IntPtr raw);
[DllImport ("libgtk-win32-3.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void gtk_radio_tool_button_set_group(IntPtr raw, IntPtr list);
[GLib.Property ("group")]
public RadioToolButton[] Group {
get {
IntPtr raw_ret = gtk_radio_tool_button_get_group(Handle);
RadioToolButton[] ret = (RadioToolButton[]) GLib.Marshaller.ListPtrToArray (raw_ret, typeof(GLib.SList), false, false, typeof(RadioToolButton));
return ret;
}
set {
IntPtr native_group = IntPtr.Zero;
if (value != null) {
GLib.List list = new GLib.List(IntPtr.Zero);
foreach (RadioToolButton item in value) {
list.Append (item.Handle);
}
native_group = list.Handle;
}
gtk_radio_tool_button_set_group(Handle, native_group);
}
}
}
}

View File

@ -935,6 +935,7 @@
<Compile Include="generated\WindowType.cs" />
<Compile Include="generated\WrapMode.cs" />
<Compile Include="generated\XEmbedMessage.cs" />
<Compile Include="RadioAction.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />

View File

@ -76,7 +76,7 @@ namespace GtkDemo
return null;
Menu menu = new Menu ();
GLib.SList group = new GLib.SList (IntPtr.Zero);
RadioMenuItem[] group = null;
if (tearoff) {
TearoffMenuItem menuitem = new TearoffMenuItem ();