Skip to content

Commit

Permalink
Make gtk.UIManager.UIManager.getWidget return the correct type.
Browse files Browse the repository at this point in the history
This to alloe casting the Returned Widget to the Real Widget Type.
  • Loading branch information
MikeWey committed Feb 1, 2014
1 parent 169f158 commit 88b2757
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 31 deletions.
150 changes: 120 additions & 30 deletions src/gtk/UIManager.d
Expand Up @@ -43,6 +43,7 @@
* omit structs:
* omit prefixes:
* omit code:
* - gtk_ui_manager_get_widget
* omit signals:
* imports:
* - glib.Str
Expand All @@ -54,6 +55,22 @@
* - gtk.Widget
* - glib.ListSG
* - gtk.Action
* - gobject.Type
* - gtk.CheckMenuItem
* - gtk.ImageMenuItem
* - gtk.Menu
* - gtk.MenuBar
* - gtk.MenuItem
* - gtk.MenuToolButton
* - gtk.RadioMenuItem
* - gtk.RadioToolButton
* - gtk.SeparatorMenuItem
* - gtk.SeparatorToolItem
* - gtk.TearoffMenuItem
* - gtk.ToggleToolButton
* - gtk.Toolbar
* - gtk.ToolButton
* - gtk.ToolItem
* - gtk.BuildableIF
* - gtk.BuildableT
* structWrap:
Expand Down Expand Up @@ -88,6 +105,22 @@ private import gtk.AccelGroup;
private import gtk.Widget;
private import glib.ListSG;
private import gtk.Action;
private import gobject.Type;
private import gtk.CheckMenuItem;
private import gtk.ImageMenuItem;
private import gtk.Menu;
private import gtk.MenuBar;
private import gtk.MenuItem;
private import gtk.MenuToolButton;
private import gtk.RadioMenuItem;
private import gtk.RadioToolButton;
private import gtk.SeparatorMenuItem;
private import gtk.SeparatorToolItem;
private import gtk.TearoffMenuItem;
private import gtk.ToggleToolButton;
private import gtk.Toolbar;
private import gtk.ToolButton;
private import gtk.ToolItem;
private import gtk.BuildableIF;
private import gtk.BuildableT;

Expand Down Expand Up @@ -264,6 +297,93 @@ public class UIManager : ObjectG, BuildableIF
// add the Buildable capabilities
mixin BuildableT!(GtkUIManager);

/**
* Looks up a widget by following a path.
* The path consists of the names specified in the XML description of the UI.
* separated by '/'. Elements which don't have a name or action attribute in
* the XML (e.g. <popup>) can be addressed by their XML element name
* (e.g. "popup"). The root element ("/ui") can be omitted in the path.
*
* Note that the widget found by following a path that ends in a <menu>
* element is the menuitem to which the menu is attached, not the menu itself.
*
* Also note that the widgets constructed by a ui manager are not tied to
* the lifecycle of the ui manager. If you add the widgets returned by this
* function to some container or explicitly ref them, they will survive the
* destruction of the ui manager.
*
* Since 2.4
*
* Params:
* path = a path
*
* Returns: the widget found by following the path, or null if no widget was found.
*/
public Widget getWidget(string path)
{
// GtkWidget * gtk_ui_manager_get_widget (GtkUIManager *manager, const gchar *path);
auto p = gtk_ui_manager_get_widget(gtkUIManager, Str.toStringz(path));

if(p is null)
{
return null;
}

string typeName = Type.name((cast(GTypeInstance*)p).gClass.gType);

switch(typeName)
{
case "GtkCheckMenuItem":
return ObjectG.getDObject!(CheckMenuItem)(cast(GtkCheckMenuItem*) p);
break;
case "GtkImageMenuItem":
return ObjectG.getDObject!(ImageMenuItem)(cast(GtkImageMenuItem*) p);
break;
case "GtkMenu":
return ObjectG.getDObject!(Menu)(cast(GtkMenu*) p);
break;
case "GtkMenuBar":
return ObjectG.getDObject!(MenuBar)(cast(GtkMenuBar*) p);
break;
case "GtkMenuItem":
return ObjectG.getDObject!(MenuItem)(cast(GtkMenuItem*) p);
break;
case "GtkMenuToolButton":
return ObjectG.getDObject!(MenuToolButton)(cast(GtkMenuToolButton*) p);
break;
case "GtkRadioMenuItem":
return ObjectG.getDObject!(RadioMenuItem)(cast(GtkRadioMenuItem*) p);
break;
case "GtkRadioToolButton":
return ObjectG.getDObject!(RadioToolButton)(cast(GtkRadioToolButton*) p);
break;
case "GtkSeparatorMenuItem":
return ObjectG.getDObject!(SeparatorMenuItem)(cast(GtkSeparatorMenuItem*) p);
break;
case "GtkSeparatorToolItem":
return ObjectG.getDObject!(SeparatorToolItem)(cast(GtkSeparatorToolItem*) p);
break;
case "GtkTearoffMenuItem":
return ObjectG.getDObject!(TearoffMenuItem)(cast(GtkTearoffMenuItem*) p);
break;
case "GtkToggleToolButton":
return ObjectG.getDObject!(ToggleToolButton)(cast(GtkToggleToolButton*) p);
break;
case "GtkToolbar":
return ObjectG.getDObject!(Toolbar)(cast(GtkToolbar*) p);
break;
case "GtkToolButton":
return ObjectG.getDObject!(ToolButton)(cast(GtkToolButton*) p);
break;
case "GtkToolItem":
return ObjectG.getDObject!(ToolItem)(cast(GtkToolItem*) p);
break;
default:
return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
break;
}
}

/**
*/
int[string] connectedSignals;
Expand Down Expand Up @@ -560,36 +680,6 @@ public class UIManager : ObjectG, BuildableIF
return ObjectG.getDObject!(AccelGroup)(cast(GtkAccelGroup*) p);
}

/**
* Looks up a widget by following a path.
* The path consists of the names specified in the XML description of the UI.
* separated by '/'. Elements which don't have a name or action attribute in
* the XML (e.g. <popup>) can be addressed by their XML element name
* (e.g. "popup"). The root element ("/ui") can be omitted in the path.
* Note that the widget found by following a path that ends in a <menu>
* element is the menuitem to which the menu is attached, not the menu itself.
* Also note that the widgets constructed by a ui manager are not tied to
* the lifecycle of the ui manager. If you add the widgets returned by this
* function to some container or explicitly ref them, they will survive the
* destruction of the ui manager.
* Since 2.4
* Params:
* path = a path
* Returns: the widget found by following the path, or NULL if no widget was found. [transfer none]
*/
public Widget getWidget(string path)
{
// GtkWidget * gtk_ui_manager_get_widget (GtkUIManager *self, const gchar *path);
auto p = gtk_ui_manager_get_widget(gtkUIManager, Str.toStringz(path));

if(p is null)
{
return null;
}

return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
}

/**
* Obtains a list of all toplevel widgets of the requested types.
* Since 2.4
Expand Down
2 changes: 1 addition & 1 deletion src/gtkc/gtktypes.d
Expand Up @@ -8164,4 +8164,4 @@ string[] StockDesc =
"gtk-zoom-in",
"gtk-zoom-out",

];
];
105 changes: 105 additions & 0 deletions wrap/APILookupGtk.txt
Expand Up @@ -6217,14 +6217,119 @@ import: glib.ListSG
structWrap: GSList* ListSG
import: gtk.Action
structWrap: GtkAction* Action
import: gobject.Type
import: gtk.CheckMenuItem
import: gtk.ImageMenuItem
import: gtk.Menu
import: gtk.MenuBar
import: gtk.MenuItem
import: gtk.MenuToolButton
import: gtk.RadioMenuItem
import: gtk.RadioToolButton
import: gtk.SeparatorMenuItem
import: gtk.SeparatorToolItem
import: gtk.TearoffMenuItem
import: gtk.ToggleToolButton
import: gtk.Toolbar
import: gtk.ToolButton
import: gtk.ToolItem

#imports for Buildable Interface.
import: gtk.BuildableIF
import: gtk.BuildableT

nocode: gtk_ui_manager_get_widget

code: start
// add the Buildable capabilities
mixin BuildableT!(GtkUIManager);

/**
* Looks up a widget by following a path.
* The path consists of the names specified in the XML description of the UI.
* separated by '/'. Elements which don't have a name or action attribute in
* the XML (e.g. &lt;popup&gt;) can be addressed by their XML element name
* (e.g. "popup"). The root element ("/ui") can be omitted in the path.
*
* Note that the widget found by following a path that ends in a &lt;menu&gt;
* element is the menuitem to which the menu is attached, not the menu itself.
*
* Also note that the widgets constructed by a ui manager are not tied to
* the lifecycle of the ui manager. If you add the widgets returned by this
* function to some container or explicitly ref them, they will survive the
* destruction of the ui manager.
*
* Since 2.4
*
* Params:
* path = a path
*
* Returns: the widget found by following the path, or null if no widget was found.
*/
public Widget getWidget(string path)
{
// GtkWidget * gtk_ui_manager_get_widget (GtkUIManager *manager, const gchar *path);
auto p = gtk_ui_manager_get_widget(gtkUIManager, Str.toStringz(path));

if(p is null)
{
return null;
}

string typeName = Type.name((cast(GTypeInstance*)p).gClass.gType);

switch(typeName)
{
case "GtkCheckMenuItem":
return ObjectG.getDObject!(CheckMenuItem)(cast(GtkCheckMenuItem*) p);
break;
case "GtkImageMenuItem":
return ObjectG.getDObject!(ImageMenuItem)(cast(GtkImageMenuItem*) p);
break;
case "GtkMenu":
return ObjectG.getDObject!(Menu)(cast(GtkMenu*) p);
break;
case "GtkMenuBar":
return ObjectG.getDObject!(MenuBar)(cast(GtkMenuBar*) p);
break;
case "GtkMenuItem":
return ObjectG.getDObject!(MenuItem)(cast(GtkMenuItem*) p);
break;
case "GtkMenuToolButton":
return ObjectG.getDObject!(MenuToolButton)(cast(GtkMenuToolButton*) p);
break;
case "GtkRadioMenuItem":
return ObjectG.getDObject!(RadioMenuItem)(cast(GtkRadioMenuItem*) p);
break;
case "GtkRadioToolButton":
return ObjectG.getDObject!(RadioToolButton)(cast(GtkRadioToolButton*) p);
break;
case "GtkSeparatorMenuItem":
return ObjectG.getDObject!(SeparatorMenuItem)(cast(GtkSeparatorMenuItem*) p);
break;
case "GtkSeparatorToolItem":
return ObjectG.getDObject!(SeparatorToolItem)(cast(GtkSeparatorToolItem*) p);
break;
case "GtkTearoffMenuItem":
return ObjectG.getDObject!(TearoffMenuItem)(cast(GtkTearoffMenuItem*) p);
break;
case "GtkToggleToolButton":
return ObjectG.getDObject!(ToggleToolButton)(cast(GtkToggleToolButton*) p);
break;
case "GtkToolbar":
return ObjectG.getDObject!(Toolbar)(cast(GtkToolbar*) p);
break;
case "GtkToolButton":
return ObjectG.getDObject!(ToolButton)(cast(GtkToolButton*) p);
break;
case "GtkToolItem":
return ObjectG.getDObject!(ToolItem)(cast(GtkToolItem*) p);
break;
default:
return ObjectG.getDObject!(Widget)(cast(GtkWidget*) p);
break;
}
}
code: end
outFile: UIManager

Expand Down

0 comments on commit 88b2757

Please sign in to comment.