gtkmm create new gtype

http://comments.gmane.org/gmane.comp.gnome.gtkmm/13677

That is a very GTK+ kind of thing, used to implement GTypes. For a
Gtk::Button it would be an intance of Gtk::Button_Class. That's declared
in gtkmm/gtk/private_p.h. These *_Class types are also typedefed in each
gtkmm widget class as CppClassType.

Gtk::Button's instance of that class, button_class_, is private, which
kind of makes sense to me - an application shouldn't be changing how
Buttons all over the system behave.

To take advantage of this per-GType style information, I guess you have
to define a new GType. gtkmm has some clever ways of doing this, but
everything results in one g_type_register_static() function to register
the GType.

HOWEVER, I suspect it will be enough to call the Glib::ObjectBase
constructor with your custom GType name, like in this unrelated example,
which uses the result of typeid() to get a typename string, because it
also needs its own GType:
http://cvs.gnome.org/viewcvs/gtkmm/examples/cellrenderercustom/cellrendererlist.cc?view=markup

So you'd do 

class MyButton : public Gtk::Button
{
}

MyButton::MyButton()
: Glib::ObjectBase("kentswidgets_mybutton"),
  Gtk::Button()
{
  //This might give you the typename:
  std::cout << "gtypename: " <<G_OBJECT_TYPE_NAME(gobj() << std::endl;

  //This might tell you whether it's still a GtkButton:
  std::cout << "Gtype is a GtkButton?:" << GTK_IS_BUTTON(gobj()) <<
std::endl;

}

I haven't tried compiling that.

> This thread answers some of my other questions but not quite
> everything.
> http://mail.gnome.org/archives/gtk-devel-list/2002-August/msg00129.html
>  
> An example of how this is all done in GTKmm would be greatly
> appreciated.

If you don't have any luck then I'll try to create an example when I
have a chance, or maybe someone has already done this in some open
source code.

Is this in order to make some aspect of your custom widget themeable, or
in order to achieve some other effect that only seems to be possible via
the RC file?

--
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值